use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.
the class ThrottleFrame method setXml.
/**
* Set the preferences based on the XML Element.
* <ul>
* <li> Window prefs
* <li> Frame title
* <li> ControlPanel
* <li> FunctionPanel
* <li> AddressPanel
* </ul>
*
*
* @param e The Element for this object.
*/
@SuppressWarnings("unchecked")
public void setXml(Element e) {
if (e == null) {
return;
}
String sfile = e.getAttributeValue("ThrottleXMLFile");
if (sfile != null) {
loadThrottle(FileUtil.getExternalFilename(sfile));
return;
}
boolean switchAfter = false;
if (!isEditMode) {
switchMode();
switchAfter = true;
}
int bSize = 23;
// Get InternalFrame border size
if (e.getAttribute("border") != null) {
bSize = Integer.parseInt((e.getAttribute("border").getValue()));
}
if (// Old format
e.getChild("window") != null) {
throttleWindow.setXml(e);
}
Element controlPanelElement = e.getChild("ControlPanel");
controlPanel.setXml(controlPanelElement);
if (((javax.swing.plaf.basic.BasicInternalFrameUI) controlPanel.getUI()).getNorthPane() != null) {
((javax.swing.plaf.basic.BasicInternalFrameUI) controlPanel.getUI()).getNorthPane().setPreferredSize(new Dimension(0, bSize));
}
Element functionPanelElement = e.getChild("FunctionPanel");
functionPanel.setXml(functionPanelElement);
if (((javax.swing.plaf.basic.BasicInternalFrameUI) controlPanel.getUI()).getNorthPane() != null) {
((javax.swing.plaf.basic.BasicInternalFrameUI) functionPanel.getUI()).getNorthPane().setPreferredSize(new Dimension(0, bSize));
}
Element addressPanelElement = e.getChild("AddressPanel");
addressPanel.setXml(addressPanelElement);
if (((javax.swing.plaf.basic.BasicInternalFrameUI) controlPanel.getUI()).getNorthPane() != null) {
((javax.swing.plaf.basic.BasicInternalFrameUI) addressPanel.getUI()).getNorthPane().setPreferredSize(new Dimension(0, bSize));
}
List<Element> jinsts = e.getChildren("Jynstrument");
if ((jinsts != null) && (jinsts.size() > 0)) {
for (int i = 0; i < jinsts.size(); i++) {
JInternalFrame jif = ynstrument(FileUtil.getExternalFilename(jinsts.get(i).getAttributeValue("JynstrumentFolder")));
Element window = jinsts.get(i).getChild("window");
if (jif != null) {
if (window != null) {
WindowPreferences.setPreferences(jif, window);
}
Component[] cmps2 = jif.getContentPane().getComponents();
int j = 0;
while ((j < cmps2.length) && (!(cmps2[j] instanceof Jynstrument))) {
j++;
}
if ((j < cmps2.length) && (cmps2[j] instanceof Jynstrument) && (jinsts.get(i) != null)) {
((Jynstrument) cmps2[j]).setXml(jinsts.get(i));
}
jif.repaint();
}
}
}
setFrameTitle();
if (switchAfter) {
switchMode();
}
}
use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.
the class ThrottleFrame method loadThrottle.
public void loadThrottle(String sfile) {
if (sfile == null) {
JFileChooser fileChooser = jmri.jmrit.XmlFile.userFileChooser(Bundle.getMessage("PromptXmlFileTypes"), "xml");
fileChooser.setCurrentDirectory(new File(getDefaultThrottleFolder()));
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
java.io.File file = LoadXmlConfigAction.getFile(fileChooser);
if (file == null) {
return;
}
sfile = file.getAbsolutePath();
if (sfile == null) {
return;
}
}
boolean switchAfter = false;
if (!isEditMode) {
switchMode();
switchAfter = true;
}
try {
XmlFile xf = new XmlFile() {
};
// odd syntax is due to XmlFile being abstract
File f = new File(sfile);
Element root = xf.rootFromFile(f);
Element conf = root.getChild("ThrottleFrame");
// File looks ok
setLastUsedSaveFile(sfile);
// close all existing Jynstruments
Component[] cmps = getComponents();
for (int i = 0; i < cmps.length; i++) {
try {
if (cmps[i] instanceof JInternalFrame) {
JInternalFrame jyf = (JInternalFrame) cmps[i];
Component[] cmps2 = jyf.getContentPane().getComponents();
for (int j = 0; j < cmps2.length; j++) {
if (cmps2[j] instanceof Jynstrument) {
((Jynstrument) cmps2[j]).exit();
jyf.dispose();
}
}
}
} catch (Exception ex) {
log.debug("Got exception (no panic) " + ex);
}
}
// and finally load all preferences
setXml(conf);
} catch (Exception ex) {
if (log.isDebugEnabled()) {
log.debug("Loading throttle exception: " + ex.getMessage());
}
}
// checkPosition();
if (switchAfter) {
switchMode();
}
return;
}
use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.
the class ThrottleWindow method getXml.
public Element getXml() {
Element me = new Element("ThrottleWindow");
me.setAttribute("title", titleText);
me.setAttribute("titleType", titleTextType);
java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(1);
children.add(WindowPreferences.getPreferences(this));
if (!throttleFrames.isEmpty()) {
ThrottleFrame cf = this.getCurrentThrottleFrame();
for (Iterator<ThrottleFrame> tfi = throttleFrames.values().iterator(); tfi.hasNext(); ) {
ThrottleFrame tf = tfi.next();
if ((jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle()) && (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isSavingThrottleOnLayoutSave())) {
tf.toFront();
tf.saveThrottle();
}
Element tfe = tf.getXmlFile();
if (tfe == null) {
tfe = tf.getXml();
}
children.add(tfe);
}
if (cf != null) {
cf.toFront();
}
}
// Save Jynstruments
if (throttleToolBar != null) {
Component[] cmps = throttleToolBar.getComponents();
if (cmps != null) {
for (int i = 0; i < cmps.length; i++) {
try {
if (cmps[i] instanceof Jynstrument) {
Jynstrument jyn = (Jynstrument) cmps[i];
Element elt = new Element("Jynstrument");
elt.setAttribute("JynstrumentFolder", FileUtil.getPortableFilename(jyn.getFolder()));
Element je = jyn.getXml();
if (je != null) {
java.util.ArrayList<Element> jychildren = new java.util.ArrayList<Element>(1);
jychildren.add(je);
elt.setContent(jychildren);
}
children.add(elt);
}
} catch (Exception ex) {
log.debug("Got exception (no panic) " + ex);
}
}
}
}
me.setContent(children);
return me;
}
use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.
the class ThrottleWindow method initGUI.
private void initGUI() {
setTitle(Bundle.getMessage("ThrottleFrameTitle"));
setLayout(new BorderLayout());
throttlesLayout = new CardLayout();
throttlesPanel = new JPanel(throttlesLayout);
throttlesPanel.setDoubleBuffered(true);
if ((jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle()) && (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingToolBar())) {
initializeToolbar();
}
/* if ( (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() )
&& ( jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isResizingWindow()))
setResizable(false);*/
initializeMenu();
setCurrentThrottleFrame(new ThrottleFrame(this));
getCurrentThrottleFrame().setTitle("default");
throttlesPanel.add(getCurrentThrottleFrame(), "default");
throttleFrames.put("default", getCurrentThrottleFrame());
add(throttlesPanel, BorderLayout.CENTER);
KeyListenerInstaller.installKeyListenerOnAllComponents(throttlePanelsCyclingKeyListener, getCurrentThrottleFrame());
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
ThrottleWindow me = (ThrottleWindow) e.getSource();
ThrottleFrameManager.instance().requestThrottleWindowDestruction(me);
if (throttleToolBar != null) {
Component[] cmps = throttleToolBar.getComponents();
if (cmps != null) {
for (int i = 0; i < cmps.length; i++) {
if (cmps[i] instanceof Jynstrument) {
((Jynstrument) cmps[i]).exit();
}
}
}
}
}
});
updateGUI();
}
use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.
the class ThrottleWindow method setXml.
@SuppressWarnings("unchecked")
public void setXml(Element e) {
if (e.getAttribute("title") != null) {
setTitle(e.getAttribute("title").getValue());
}
if (e.getAttribute("title") != null) {
setTitleText(e.getAttribute("title").getValue());
}
if (e.getAttribute("titleType") != null) {
setTitleTextType(e.getAttribute("titleType").getValue());
}
Element window = e.getChild("window");
if (window != null) {
WindowPreferences.setPreferences(this, window);
}
List<Element> tfes = e.getChildren("ThrottleFrame");
if ((tfes != null) && (tfes.size() > 0)) {
for (int i = 0; i < tfes.size(); i++) {
ThrottleFrame tf;
if (i == 0) {
tf = getCurrentThrottleFrame();
} else {
tf = addThrottleFrame();
}
tf.setXml(tfes.get(i));
}
}
List<Element> jinsts = e.getChildren("Jynstrument");
if ((jinsts != null) && (jinsts.size() > 0)) {
for (int i = 0; i < jinsts.size(); i++) {
Jynstrument jyn = ynstrument(FileUtil.getExternalFilename(jinsts.get(i).getAttributeValue("JynstrumentFolder")));
if ((jyn != null) && (jinsts.get(i) != null)) {
jyn.setXml(jinsts.get(i));
}
}
}
updateGUI();
}
Aggregations