Subversion Repositories svn.mios

Rev

Rev 727 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
709 adamjking 1
package org.midibox.mios.xml;
2
 
721 adamjking 3
import org.midibox.mios.LCDMessage;
4
import org.w3c.dom.Element;
5
import org.w3c.dom.Node;
709 adamjking 6
 
721 adamjking 7
public class LCDMessageXML extends MIOSSysexSendReceiveXML {
8
 
9
    protected LCDMessage lcdMessage;
10
 
722 adamjking 11
    public static final String TAG_ROOT_ELEMENT = "lcdMessage";
721 adamjking 12
 
722 adamjking 13
    public static final String TAG_MESSAGE_TEXT = "messageText";
721 adamjking 14
 
722 adamjking 15
    public static final String ATTR_LCD_WIDTH = "lcdWidth";
721 adamjking 16
 
722 adamjking 17
    public static final String ATTR_LCD_HEIGHT = "lcdHeight";
721 adamjking 18
 
722 adamjking 19
    public static final String ATTR_MODE = "mode";
721 adamjking 20
 
722 adamjking 21
    public static final String ATTR_POS_X = "posX";
721 adamjking 22
 
722 adamjking 23
    public static final String ATTR_POS_Y = "posY";
721 adamjking 24
 
722 adamjking 25
    public static final String ATTR_LOOP = "loop";
26
 
721 adamjking 27
    public LCDMessageXML(LCDMessage lcdMessage, String rootElementTag) {
28
 
29
        super(lcdMessage, rootElementTag);
30
 
31
        this.lcdMessage = lcdMessage;
738 adamjking 32
 
727 adamjking 33
        tags.add(TAG_MESSAGE_TEXT);
721 adamjking 34
    }
738 adamjking 35
 
727 adamjking 36
    protected void parseElement(Element element) {
721 adamjking 37
 
727 adamjking 38
        super.parseElement(element);
738 adamjking 39
 
727 adamjking 40
        String name = element.getNodeName();
738 adamjking 41
 
727 adamjking 42
        if (name == rootElementTag) {
738 adamjking 43
 
44
            lcdMessage.setDeviceID(stringToInt(element
45
                    .getAttribute(ATTR_DEVICE_ID)));
46
 
47
            lcdMessage.setMIOS32Mode(stringToBoolean(element
48
                    .getAttribute(ATTR_MIOS32_MODE)));
49
 
50
            lcdMessage.setLcdWidth(stringToInt(element
51
                    .getAttribute(ATTR_LCD_WIDTH)));
52
 
53
            lcdMessage.setLcdHeight(stringToInt(element
54
                    .getAttribute(ATTR_LCD_HEIGHT)));
55
 
727 adamjking 56
            lcdMessage.setMode(stringToInt(element.getAttribute(ATTR_MODE)));
738 adamjking 57
 
727 adamjking 58
            lcdMessage.setPosX(stringToInt(element.getAttribute(ATTR_POS_X)));
738 adamjking 59
 
727 adamjking 60
            lcdMessage.setPosY(stringToInt(element.getAttribute(ATTR_POS_Y)));
738 adamjking 61
 
62
            lcdMessage
63
                    .setLoop(stringToBoolean(element.getAttribute(ATTR_LOOP)));
64
 
727 adamjking 65
        } else if (name == TAG_MESSAGE_TEXT) {
738 adamjking 66
 
727 adamjking 67
            lcdMessage.setMessageText(element.getTextContent());
68
        }
69
    }
70
 
721 adamjking 71
    public void saveXML(Node node) {
72
 
73
        super.saveXML(node);
74
 
722 adamjking 75
        rootElement.setAttribute(ATTR_LCD_WIDTH, intToString(lcdMessage
76
                .getLcdWidth()));
721 adamjking 77
 
722 adamjking 78
        rootElement.setAttribute(ATTR_LCD_HEIGHT, intToString(lcdMessage
79
                .getLcdHeight()));
721 adamjking 80
 
722 adamjking 81
        rootElement.setAttribute(ATTR_MODE, intToString(lcdMessage.getMode()));
721 adamjking 82
 
722 adamjking 83
        rootElement.setAttribute(ATTR_POS_X, intToString(lcdMessage.getPosX()));
721 adamjking 84
 
722 adamjking 85
        rootElement.setAttribute(ATTR_POS_Y, intToString(lcdMessage.getPosY()));
721 adamjking 86
 
722 adamjking 87
        rootElement.setAttribute(ATTR_LOOP,
88
                booleanToString(lcdMessage.isLoop()));
721 adamjking 89
 
722 adamjking 90
        Element messageTextElement = document.createElement(TAG_MESSAGE_TEXT);
721 adamjking 91
 
92
        rootElement.appendChild(messageTextElement);
93
 
94
        messageTextElement.setTextContent(lcdMessage.getMessageText());
95
    }
709 adamjking 96
}