Subversion Repositories svn.mios

Rev

Rev 628 | Rev 741 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 628 Rev 738
Line 25... Line 25...
25
import java.awt.event.ComponentAdapter;
25
import java.awt.event.ComponentAdapter;
26
import java.awt.event.ComponentEvent;
26
import java.awt.event.ComponentEvent;
27
import java.awt.event.KeyEvent;
27
import java.awt.event.KeyEvent;
28
import java.awt.event.WindowAdapter;
28
import java.awt.event.WindowAdapter;
29
import java.awt.event.WindowEvent;
29
import java.awt.event.WindowEvent;
-
 
30
import java.io.File;
30
import java.util.prefs.Preferences;
31
import java.util.prefs.Preferences;
31
32
32
import javax.swing.JApplet;
33
import javax.swing.JApplet;
33
import javax.swing.JDialog;
34
import javax.swing.JDialog;
34
import javax.swing.JFrame;
35
import javax.swing.JFrame;
35
import javax.swing.JMenuItem;
36
import javax.swing.JMenuItem;
36
import javax.swing.UIManager;
37
import javax.swing.UIManager;
37
38
38
import org.midibox.apps.virtualkeyboard.gui.VirtualKeyboardGUI;
39
import org.midibox.apps.virtualkeyboard.gui.VirtualKeyboardGUI;
-
 
40
import org.midibox.apps.virtualkeyboard.xml.VirtualKeyboardXML;
39
import org.midibox.utils.gui.ImageLoader;
41
import org.midibox.utils.gui.ImageLoader;
40
42
41
public class VirtualKeyboard extends JApplet {
43
public class VirtualKeyboard extends JApplet {
42
44
43
    final static Preferences preferences = Preferences.userRoot().node(
45
    final static Preferences preferences = Preferences.userRoot().node(
44
            "org/midibox/virtualkeyboard/gui");
46
            "org/midibox/virtualkeyboard/gui");
-
 
47
-
 
48
    final static String configFileName = ".virtualkeyboard";
45
49
46
    private org.midibox.apps.virtualkeyboard.VirtualKeyboard virtualKeyboard;
50
    private org.midibox.apps.virtualkeyboard.VirtualKeyboard virtualKeyboard;
47
51
48
    private VirtualKeyboardGUI virtualKeyboardGUI;
52
    private VirtualKeyboardGUI virtualKeyboardGUI;
49
53
50
    public VirtualKeyboard() {
54
    public VirtualKeyboard() {
-
 
55
51
        virtualKeyboard = new org.midibox.apps.virtualkeyboard.VirtualKeyboard();
56
        virtualKeyboard = new org.midibox.apps.virtualkeyboard.VirtualKeyboard();
-
 
57
-
 
58
        loadConfigFile();
52
59
53
        try {
60
        try {
54
            UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
61
            UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
55
                    .getCrossPlatformLookAndFeelClassName()));
62
                    .getCrossPlatformLookAndFeelClassName()));
56
        } catch (Exception e) {
63
        } catch (Exception e) {
Line 69... Line 76...
69
76
70
        setJMenuBar(virtualKeyboardGUI.createMenuBar());
77
        setJMenuBar(virtualKeyboardGUI.createMenuBar());
71
    }
78
    }
72
79
73
    public void init() {
80
    public void init() {
-
 
81
74
        virtualKeyboardGUI.setShowConnections(preferences.getBoolean(
82
        virtualKeyboardGUI.setShowConnections(preferences.getBoolean(
75
                "showConnections", true));
83
                "showConnections", true));
-
 
84
    }
-
 
85
-
 
86
    protected void loadConfigFile() {
-
 
87
-
 
88
        File configFile = new File(System.getProperty("user.home"),
-
 
89
                configFileName);
-
 
90
-
 
91
        if (configFile.exists()) {
-
 
92
-
 
93
            VirtualKeyboardXML virtualKeyboardXML = new VirtualKeyboardXML(
-
 
94
                    virtualKeyboard, VirtualKeyboardXML.TAG_ROOT_ELEMENT);
-
 
95
-
 
96
            virtualKeyboardXML.loadXML(configFile);
-
 
97
        }
76
    }
98
    }
77
99
78
    public void destroy() {
100
    public void destroy() {
-
 
101
-
 
102
        saveConfigFile();
-
 
103
79
        preferences.put("lookAndFeel", virtualKeyboardGUI.getLookAndFeel());
104
        preferences.put("lookAndFeel", virtualKeyboardGUI.getLookAndFeel());
80
105
81
        preferences.putBoolean("defaultDecoratedFrames", virtualKeyboardGUI
106
        preferences.putBoolean("defaultDecoratedFrames", virtualKeyboardGUI
82
                .isDefaultDecoratedFrames());
107
                .isDefaultDecoratedFrames());
83
108
84
        preferences.putBoolean("showConnections", virtualKeyboardGUI
109
        preferences.putBoolean("showConnections", virtualKeyboardGUI
85
                .isShowConnections());
110
                .isShowConnections());
-
 
111
    }
-
 
112
-
 
113
    protected void saveConfigFile() {
-
 
114
-
 
115
        File configFile = new File(System.getProperty("user.home"),
-
 
116
                configFileName);
-
 
117
-
 
118
        if (!configFile.exists()) {
-
 
119
            try {
-
 
120
                configFile.createNewFile();
-
 
121
            } catch (Exception e) {
-
 
122
                e.printStackTrace();
-
 
123
            }
-
 
124
        }
-
 
125
-
 
126
        if (configFile.exists()) {
-
 
127
-
 
128
            VirtualKeyboardXML virtualKeyboardXML = new VirtualKeyboardXML(
-
 
129
                    virtualKeyboard, VirtualKeyboardXML.TAG_ROOT_ELEMENT);
-
 
130
-
 
131
            virtualKeyboardXML.saveXML(configFile);
-
 
132
        }
86
    }
133
    }
87
134
88
    public static void exit(JFrame frame) {
135
    public static void exit(JFrame frame) {
-
 
136
89
        preferences.putInt("mainWindowX", frame.getX());
137
        preferences.putInt("mainWindowX", frame.getX());
90
        preferences.putInt("mainWindowY", frame.getY());
138
        preferences.putInt("mainWindowY", frame.getY());
-
 
139
91
        System.exit(0);
140
        System.exit(0);
92
    }
141
    }
93
142
94
    public static void main(String[] args) {
143
    public static void main(String[] args) {
95
144
96
        final VirtualKeyboard virtualKeyboardGUIDriver = new VirtualKeyboard();
145
        final VirtualKeyboard virtualKeyboardGUIDriver = new VirtualKeyboard();
-
 
146
97
        virtualKeyboardGUIDriver.init();
147
        virtualKeyboardGUIDriver.init();
98
148
99
        final JFrame frame = new JFrame("Virtual Keyboard");
149
        final JFrame frame = new JFrame("Virtual Keyboard");
-
 
150
-
 
151
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-
 
152
100
        frame.setContentPane(virtualKeyboardGUIDriver);
153
        frame.setContentPane(virtualKeyboardGUIDriver);
101
154
102
        frame.setIconImage(ImageLoader.getImageIcon("piano.png").getImage());
155
        frame.setIconImage(ImageLoader.getImageIcon("piano.png").getImage());
103
        frame.pack();
156
        frame.pack();
104
        frame.setResizable(false);
157
        frame.setResizable(false);