Subversion Repositories svn.mios

Rev

Rev 753 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
741 adamjking 1
package org.midibox.apps.virtualkeyboard.gui.xml;
2
 
3
import java.awt.Point;
4
 
5
import javax.swing.JFrame;
6
import javax.swing.UIManager;
7
 
8
import org.midibox.apps.virtualkeyboard.VirtualKeyboard;
9
import org.midibox.apps.virtualkeyboard.gui.VirtualKeyboardGUI;
10
import org.midibox.apps.virtualkeyboard.xml.VirtualKeyboardXML;
11
import org.midibox.utils.gui.DialogOwner;
12
import org.midibox.utils.xml.XMLUtils;
13
import org.w3c.dom.Element;
14
import org.w3c.dom.Node;
15
 
16
public class VirtualKeyboardGUIXML extends XMLUtils {
17
 
18
    public static final String TAG_ROOT_ELEMENT = "virtualKeyboardGUI";
19
 
20
    public final static String TAG_LOOK_AND_FEEL = "lookAndFeel";
21
 
22
    public final static String TAG_MAIN_WINDOW = "mainWindow";
23
 
24
    public final static String TAG_CONNECTIONS_VISIBLE = "connectionsVisible";
25
 
26
    public final static String ATTR_POS_X = "posX";
27
 
28
    public final static String ATTR_POS_Y = "posY";
29
 
30
    public final static String ATTR_WIDTH = "width";
31
 
32
    public final static String ATTR_HEIGHT = "height";
33
 
34
    public final static String ATTR_ENABLE = "enable";
35
 
36
    protected VirtualKeyboardGUI virtualKeyboardGUI;
37
 
38
    protected VirtualKeyboard virtualKeyboard;
39
 
40
    public VirtualKeyboardGUIXML(VirtualKeyboard virtualKeyboard,
41
            String rootElementTag) {
42
 
43
        this(null, virtualKeyboard, rootElementTag);
44
    }
45
 
46
    public VirtualKeyboardGUIXML(VirtualKeyboardGUI virtualKeyboardGUI,
47
            String rootElementTag) {
48
 
49
        this(virtualKeyboardGUI, virtualKeyboardGUI.getVirtualKeyboard(),
50
                rootElementTag);
51
    }
52
 
53
    public VirtualKeyboardGUIXML(VirtualKeyboardGUI virtualKeyboardGUI,
54
            VirtualKeyboard virtualKeyboard, String rootElementTag) {
55
 
56
        super(rootElementTag);
57
 
58
        this.virtualKeyboard = virtualKeyboard;
59
 
60
        this.virtualKeyboardGUI = virtualKeyboardGUI;
61
 
753 adamjking 62
        addTag(VirtualKeyboardXML.TAG_ROOT_ELEMENT);
63
        addTag(TAG_LOOK_AND_FEEL);
64
        addTag(TAG_MAIN_WINDOW);
65
        addTag(TAG_CONNECTIONS_VISIBLE);
741 adamjking 66
    }
67
 
68
    protected void parseElement(Element element) {
69
 
70
        super.parseElement(element);
71
 
72
        String name = element.getNodeName();
73
 
74
        if (name == rootElementTag) {
75
 
76
        } else if (name == VirtualKeyboardXML.TAG_ROOT_ELEMENT) {
77
 
78
            VirtualKeyboardXML virtualKeyboardXML = new VirtualKeyboardXML(
79
                    virtualKeyboard, VirtualKeyboardXML.TAG_ROOT_ELEMENT);
80
 
81
            virtualKeyboardXML.loadXML(element);
82
 
83
        } else if (name == TAG_MAIN_WINDOW) {
84
 
85
            JFrame mainWindow = DialogOwner.getFrame();
86
 
87
            if (mainWindow != null) {
88
 
89
                mainWindow.setLocation(new Point(stringToInt(element
90
                        .getAttribute(ATTR_POS_X)), stringToInt(element
91
                        .getAttribute(ATTR_POS_Y))));
92
            }
93
 
94
        } else if (name == TAG_LOOK_AND_FEEL) {
95
 
96
            String lookAndFeel = element.getTextContent();
97
 
98
            if (virtualKeyboardGUI == null) {
99
 
100
                try {
101
 
102
                    UIManager.setLookAndFeel(lookAndFeel);
103
 
104
                } catch (Exception e) {
105
 
106
                    e.printStackTrace();
107
                }
108
 
109
                virtualKeyboardGUI = new VirtualKeyboardGUI(virtualKeyboard);
110
            }
111
 
112
            virtualKeyboardGUI.setLookAndFeel(lookAndFeel);
113
 
114
        } else if (name == TAG_CONNECTIONS_VISIBLE) {
115
 
116
            virtualKeyboardGUI.setShowConnections(stringToBoolean(element
117
                    .getAttribute(ATTR_ENABLE)));
118
        }
119
    }
120
 
121
    public void saveXML(Node node) {
122
 
123
        super.saveXML(node);
124
 
125
        VirtualKeyboardXML virtualKeyboardXML = new VirtualKeyboardXML(
126
                virtualKeyboard, VirtualKeyboardXML.TAG_ROOT_ELEMENT);
127
 
128
        virtualKeyboardXML.saveXML(rootElement);
129
 
130
        JFrame mainWindow = DialogOwner.getFrame();
131
 
132
        if (mainWindow != null) {
133
 
134
            Element mainWindowElement = document.createElement(TAG_MAIN_WINDOW);
135
 
136
            rootElement.appendChild(mainWindowElement);
137
 
138
            mainWindowElement.setAttribute(ATTR_POS_X, intToString(mainWindow
139
                    .getX()));
140
 
141
            mainWindowElement.setAttribute(ATTR_POS_Y, intToString(mainWindow
142
                    .getY()));
143
        }
144
 
145
        Element lookAndFeelElement = document.createElement(TAG_LOOK_AND_FEEL);
146
 
147
        rootElement.appendChild(lookAndFeelElement);
148
 
149
        lookAndFeelElement.setTextContent(virtualKeyboardGUI.getLookAndFeel());
150
 
151
        Element connectionsVisibleElement = document
152
                .createElement(TAG_CONNECTIONS_VISIBLE);
153
 
154
        rootElement.appendChild(connectionsVisibleElement);
155
 
156
        connectionsVisibleElement.setAttribute(ATTR_ENABLE,
157
                booleanToString(virtualKeyboardGUI.isShowConnections()));
158
    }
159
 
160
    public VirtualKeyboardGUI getVirtualKeyboardGUI() {
161
        return virtualKeyboardGUI;
162
    }
163
}