Subversion Repositories svn.mios

Rev

Rev 722 | Rev 738 | 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;
727 adamjking 32
 
33
        tags.add(TAG_MESSAGE_TEXT);
721 adamjking 34
    }
727 adamjking 35
 
36
    protected void parseElement(Element element) {
721 adamjking 37
 
727 adamjking 38
        super.parseElement(element);
39
 
40
        String name = element.getNodeName();
41
 
42
        if (name == rootElementTag) {
43
 
44
            lcdMessage.setDeviceID(stringToInt(element.getAttribute(ATTR_DEVICE_ID)));
45
 
46
            lcdMessage.setMIOS32Mode(stringToBoolean(element.getAttribute(ATTR_MIOS32_MODE)));
47
 
48
            lcdMessage.setLcdWidth(stringToInt(element.getAttribute(ATTR_LCD_WIDTH)));
49
 
50
            lcdMessage.setLcdHeight(stringToInt(element.getAttribute(ATTR_LCD_HEIGHT)));
51
 
52
            lcdMessage.setMode(stringToInt(element.getAttribute(ATTR_MODE)));
53
 
54
            lcdMessage.setPosX(stringToInt(element.getAttribute(ATTR_POS_X)));
55
 
56
            lcdMessage.setPosY(stringToInt(element.getAttribute(ATTR_POS_Y)));
57
 
58
            lcdMessage.setLoop(stringToBoolean(element.getAttribute(ATTR_LOOP)));
59
 
60
        } else if (name == TAG_MESSAGE_TEXT) {
61
 
62
            lcdMessage.setMessageText(element.getTextContent());
63
        }
64
    }
65
 
721 adamjking 66
    public void saveXML(Node node) {
67
 
68
        super.saveXML(node);
69
 
722 adamjking 70
        rootElement.setAttribute(ATTR_LCD_WIDTH, intToString(lcdMessage
71
                .getLcdWidth()));
721 adamjking 72
 
722 adamjking 73
        rootElement.setAttribute(ATTR_LCD_HEIGHT, intToString(lcdMessage
74
                .getLcdHeight()));
721 adamjking 75
 
722 adamjking 76
        rootElement.setAttribute(ATTR_MODE, intToString(lcdMessage.getMode()));
721 adamjking 77
 
722 adamjking 78
        rootElement.setAttribute(ATTR_POS_X, intToString(lcdMessage.getPosX()));
721 adamjking 79
 
722 adamjking 80
        rootElement.setAttribute(ATTR_POS_Y, intToString(lcdMessage.getPosY()));
721 adamjking 81
 
722 adamjking 82
        rootElement.setAttribute(ATTR_LOOP,
83
                booleanToString(lcdMessage.isLoop()));
721 adamjking 84
 
722 adamjking 85
        Element messageTextElement = document.createElement(TAG_MESSAGE_TEXT);
721 adamjking 86
 
87
        rootElement.appendChild(messageTextElement);
88
 
89
        messageTextElement.setTextContent(lcdMessage.getMessageText());
90
    }
709 adamjking 91
}