Subversion Repositories svn.mios

Rev

Rev 741 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 741 Rev 762
Line 26... Line 26...
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.io.File;
31
import java.util.prefs.Preferences;
-
 
32
31
33
import javax.swing.JApplet;
32
import javax.swing.JApplet;
34
import javax.swing.JDialog;
-
 
35
import javax.swing.JFrame;
33
import javax.swing.JFrame;
36
import javax.swing.JMenuItem;
34
import javax.swing.JMenuItem;
37
import javax.swing.UIManager;
-
 
38
35
39
import org.midibox.apps.virtualkeyboard.gui.VirtualKeyboardGUI;
36
import org.midibox.apps.virtualkeyboard.gui.VirtualKeyboardGUI;
40
import org.midibox.apps.virtualkeyboard.gui.xml.VirtualKeyboardGUIXML;
37
import org.midibox.apps.virtualkeyboard.gui.xml.VirtualKeyboardGUIXML;
41
import org.midibox.apps.virtualkeyboard.xml.VirtualKeyboardXML;
-
 
42
import org.midibox.utils.gui.DialogOwner;
38
import org.midibox.utils.gui.DialogOwner;
43
import org.midibox.utils.gui.ImageLoader;
39
import org.midibox.utils.gui.ImageLoader;
44
40
45
public class VirtualKeyboard extends JApplet {
41
public class VirtualKeyboard extends JApplet {
46
42
47
    final static String configFileName = ".virtualkeyboard";
43
    final static String oldConfigFileName = ".virtualkeyboard";
-
 
44
-
 
45
    final static String configDirectoryName = ".midibox";
-
 
46
-
 
47
    final static String configFileName = "virtualkeyboard.xml";
48
48
49
    private org.midibox.apps.virtualkeyboard.VirtualKeyboard virtualKeyboard;
49
    private org.midibox.apps.virtualkeyboard.VirtualKeyboard virtualKeyboard;
50
50
51
    private VirtualKeyboardGUI virtualKeyboardGUI;
51
    private VirtualKeyboardGUI virtualKeyboardGUI;
52
52
53
    public VirtualKeyboard() {
53
    public VirtualKeyboard() {
54
54
55
        virtualKeyboard = new org.midibox.apps.virtualkeyboard.VirtualKeyboard();
55
        virtualKeyboard = new org.midibox.apps.virtualkeyboard.VirtualKeyboard();
56
56
57
        File configFile = new File(System.getProperty("user.home"),
57
        File configDirectory = new File(System.getProperty("user.home"),
58
                configFileName);
58
                configDirectoryName);
-
 
59
-
 
60
        File configFile = new File(configDirectory, configFileName);
59
61
60
        if (configFile.exists()) {
62
        if (configFile.exists()) {
61
63
62
            VirtualKeyboardGUIXML virtualKeyboardGUIXML = new VirtualKeyboardGUIXML(
64
            VirtualKeyboardGUIXML virtualKeyboardGUIXML = new VirtualKeyboardGUIXML(
63
                    virtualKeyboard, VirtualKeyboardGUIXML.TAG_ROOT_ELEMENT);
65
                    virtualKeyboard, VirtualKeyboardGUIXML.TAG_ROOT_ELEMENT);
64
66
65
            virtualKeyboardGUIXML.loadXML(configFile);
67
            virtualKeyboardGUIXML.loadXML(configFile);
66
       
68
67
            virtualKeyboardGUI = virtualKeyboardGUIXML.getVirtualKeyboardGUI();
69
            virtualKeyboardGUI = virtualKeyboardGUIXML.getVirtualKeyboardGUI();
68
           
70
-
 
71
        } else {
-
 
72
-
 
73
            // check for old config file
-
 
74
-
 
75
            configFile = new File(System.getProperty("user.home"),
-
 
76
                    oldConfigFileName);
-
 
77
-
 
78
            if (configFile.exists()) {
-
 
79
-
 
80
                VirtualKeyboardGUIXML virtualKeyboardGUIXML = new VirtualKeyboardGUIXML(
-
 
81
                        virtualKeyboard, VirtualKeyboardGUIXML.TAG_ROOT_ELEMENT);
-
 
82
-
 
83
                virtualKeyboardGUIXML.loadXML(configFile);
-
 
84
-
 
85
                virtualKeyboardGUI = virtualKeyboardGUIXML
-
 
86
                        .getVirtualKeyboardGUI();
-
 
87
-
 
88
                configFile.delete();
-
 
89
            }
69
        }
90
        }
70
       
91
71
        if (virtualKeyboardGUI == null) {
92
        if (virtualKeyboardGUI == null) {
72
            virtualKeyboardGUI = new VirtualKeyboardGUI(virtualKeyboard);
93
            virtualKeyboardGUI = new VirtualKeyboardGUI(virtualKeyboard);
73
        }
94
        }
Line 81... Line 102...
81
102
82
    }
103
    }
83
104
84
    public void destroy() {
105
    public void destroy() {
85
       
106
86
        File configFile = new File(System.getProperty("user.home"),
107
        File configDirectory = new File(System.getProperty("user.home"),
87
                configFileName);
108
                configDirectoryName);
-
 
109
-
 
110
        File configFile = new File(configDirectory, configFileName);
-
 
111
-
 
112
        if (!configDirectory.exists()) {
-
 
113
-
 
114
            try {
-
 
115
-
 
116
                configDirectory.mkdir();
-
 
117
-
 
118
            } catch (Exception e) {
-
 
119
-
 
120
                e.printStackTrace();
-
 
121
            }
-
 
122
        }
88
123
89
        if (!configFile.exists()) {
124
        if (!configFile.exists()) {
-
 
125
90
            try {
126
            try {
-
 
127
91
                configFile.createNewFile();
128
                configFile.createNewFile();
-
 
129
92
            } catch (Exception e) {
130
            } catch (Exception e) {
-
 
131
93
                e.printStackTrace();
132
                e.printStackTrace();
94
            }
133
            }
95
        }
134
        }
96
135
97
        if (configFile.exists()) {
136
        if (configFile.exists()) {
Line 136... Line 175...
136
175
137
                System.exit(0);
176
                System.exit(0);
138
            }
177
            }
139
        });
178
        });
140
179
141
        virtualKeyboardGUI.virtualKeyboardGUI.getFileMenu().add(
180
        virtualKeyboardGUI.virtualKeyboardGUI.getFileMenu().add(exitMenuItem);
142
                exitMenuItem);
-
 
143
181
144
        virtualKeyboardGUI.virtualKeyboardGUI.getMidiDeviceRoutingGUI()
182
        virtualKeyboardGUI.virtualKeyboardGUI.getMidiDeviceRoutingGUI()
145
                .addComponentListener(new ComponentAdapter() {
183
                .addComponentListener(new ComponentAdapter() {
146
                    public void componentShown(ComponentEvent arg0) {
184
                    public void componentShown(ComponentEvent arg0) {
147
                        frame.pack();
185
                        frame.pack();