private void addFade(Document doc, Element root, FadeData fade) { Element el = doc.createElement(_cue); Attr attr; attr = doc.createAttribute(_number); attr.setValue(Integer.toString(fade.getCueNumber())); el.setAttributeNode(attr); attr = doc.createAttribute(_uptime); attr.setValue(Integer.toString(fade.getUpTime())); el.setAttributeNode(attr); attr = doc.createAttribute(_downTime); attr.setValue(Integer.toString(fade.getDownTime())); el.setAttributeNode(attr); attr = doc.createAttribute(_upTimeDelay); attr.setValue(Integer.toString(fade.getDelayUpTime())); el.setAttributeNode(attr); attr = doc.createAttribute(_downTimeDelay); attr.setValue(Integer.toString(fade.getDelayDownTime())); el.setAttributeNode(attr); if (fade.getFollowTime() >= 0) { attr = doc.createAttribute(_followtime); attr.setValue(Integer.toString(fade.getFollowTime())); el.setAttributeNode(attr); } if (fade.getNextCue() > 0) { attr = doc.createAttribute(_nextCue); attr.setValue(Integer.toString(fade.getNextCue())); el.setAttributeNode(attr); } CueData cue = fade.getCue(); attr = doc.createAttribute(_discription); attr.setValue(cue.getDescription()); el.setAttributeNode(attr); for (Integer chan : cue.keySet()) addChannel(doc, el, chan, cue.get(chan)); root.appendChild(el); }
public ShowFileData loadShow(String s) { Vector<Pair> links = new Vector<Pair>(); /* ShowFileData show = new ShowFileData(); show.setSettings(new CameoSettings()); show.setPatch(new CameoPatch(0,0)); show.setCueList(new CueList(0)); show.setMagicSheet(new MagicSheet()); */ SettingsData settingsData = new SettingsData(); MagicSheetData magicSheetData = new MagicSheetData(); CueListData cueListData = new CueListData(); PatchData patchData = new PatchData(); Document doc; try { doc = _builder.parse(s); Element root = doc.getDocumentElement(); Element settings = getElement(root, _settings); Element patch = getElement(root, _patch); Element cues = getElement(root, _cues); Element magic = getElement(root, _magicSheet); // TODO test that all of these are non null and report incorrect file missing ... String recordMode = getElement(settings, _recordMode).getTextContent(); settingsData.put(_recordMode, recordMode); /* if(recordMode.equals(RecordMode.TRACKING.toString())) show._settings._mode = RecordMode.TRACKING; else if(recordMode.equals(RecordMode.CUE_ONLY.toString())) show._settings._mode = RecordMode.CUE_ONLY; */ settingsData.put(_totalChannels, getElement(settings, _totalChannels).getTextContent()); settingsData.put(_totalDimmers, getElement(settings, _totalDimmers).getTextContent()); settingsData.put(_dUpTime, getElement(settings, _dUpTime).getTextContent()); settingsData.put(_dDownTime, getElement(settings, _dDownTime).getTextContent()); settingsData.put(_gotoCueTime, getElement(settings, _gotoCueTime).getTextContent()); settingsData.put(_title, getElement(settings, _title).getTextContent()); settingsData.put(_comment, getElement(settings, _comment).getTextContent()); settingsData.put(_channelPerLine, getElement(settings, _channelPerLine).getTextContent()); settingsData.put(_channelHGroup, getElement(settings, _channelHGroup).getTextContent()); settingsData.put(_channelVGroup, getElement(settings, _channelVGroup).getTextContent()); /* show._settings._totalChannels = Integer.parseInt(getElement(settings, _totalChannels).getTextContent()); show._settings._totalDimmers = Integer.parseInt(getElement(settings, _totalDimmers).getTextContent()); show._settings._upTime = Integer.parseInt(getElement(settings, _dUpTime).getTextContent()); show._settings._downTime = Integer.parseInt(getElement(settings, _dDownTime).getTextContent()); show._settings._gotoCueTime = Integer.parseInt(getElement(settings, _gotoCueTime).getTextContent()); show._settings._showTitle = getElement(settings, _title).getTextContent(); show._settings._showComment = getElement(settings, _comment).getTextContent(); show._settings._ChannelsPerLine = Integer.parseInt(getElement(settings, _channelPerLine).getTextContent()); show._settings._ChannelGrouping = Integer.parseInt(getElement(settings, _channelHGroup).getTextContent()); show._settings._LineGrouping = Integer.parseInt(getElement(settings, _channelVGroup).getTextContent()); */ int totalChannels = Integer.parseInt(settingsData.get(_totalChannels)); patchData.setTotalChannels(totalChannels); patchData.setTotalDimmers(Integer.parseInt(settingsData.get(_totalDimmers))); cueListData.setTotalChannels(totalChannels); // show.setPatch(new CameoPatch(show._settings._totalChannels, show._settings._totalDimmers)); // show.setCueList(new CueList(show._settings._totalChannels)); NodeList list = patch.getElementsByTagName(_channel); for (int x = 0; x < list.getLength(); x++) { Element el = (Element) list.item(x); int number = Integer.parseInt(el.getAttribute(_number)); patchDims(patchData, number, el.getTextContent()); } list = cues.getElementsByTagName(_cue); for (int x = 0; x < list.getLength(); x++) { Element el = (Element) list.item(x); CueData cue = new CueData(); cue.setDescription(el.getAttribute(_discription)); NodeList list2 = el.getElementsByTagName(_channel); for (int y = 0; y < list2.getLength(); y++) { Element chan = (Element) list2.item(y); setLevel(cue, chan.getAttribute(_number), chan.getTextContent()); } int number = Integer.parseInt(el.getAttribute(_number)); int upTime = Integer.parseInt(el.getAttribute(_uptime)); int downTime = Integer.parseInt(el.getAttribute(_downTime)); int delayUpTime = Integer.parseInt(el.getAttribute(_upTimeDelay)); int delayDownTime = Integer.parseInt(el.getAttribute(_downTimeDelay)); FadeData fade = new FadeData(number, upTime, downTime, delayUpTime, delayDownTime, cue); if (el.hasAttribute(_followtime)) fade.setFollowTime(Integer.parseInt(el.getAttribute(_followtime))); if (el.hasAttribute(_nextCue)) fade.setNextCue(Integer.parseInt(el.getAttribute(_nextCue))); cueListData.add(fade); } // TODO this needs to be done in the extractor // for(Pair p : links) // show._cuelist.getCueNumbered(p._first).setNextCue(show._cuelist.getCueNumbered(p._second)); list = magic.getElementsByTagName(_channel); for (int x = 0; x < list.getLength(); x++) { Element el = (Element) list.item(x); // Element xval = getElement(el, _x); // Element yval = getElement(el, _y); Integer number = new Integer(Integer.parseInt(el.getAttribute(_number)) - 1); double xpos = Double.parseDouble(el.getAttribute(_x)); double ypos = Double.parseDouble(el.getAttribute(_y)); magicSheetData.put(number, new MagicChannelData(xpos, ypos)); } } catch (DOMException e) { System.err.println(e); } catch (SAXException e) { System.err.println(e); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog( new JFrame(""), "The show file " + s + " was not found, loading default show."); } catch (IOException e) { System.err.println(e); } return new ShowFileData(settingsData, cueListData, patchData, magicSheetData); }