Search in sources :

Example 1 with Jynstrument

use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.

the class AppsLaunchPane method ynstrument.

public static void ynstrument(String path) {
    Jynstrument it = JynstrumentFactory.createInstrument(path, _jynstrumentSpace);
    if (it == null) {
        log.error("Error while creating Jynstrument {}", path);
        return;
    }
    jmri.jmrit.throttle.ThrottleFrame.setTransparent(it);
    it.setVisible(true);
    _jynstrumentSpace.setVisible(true);
    _jynstrumentSpace.add(it);
}
Also used : Jynstrument(jmri.jmrit.jython.Jynstrument)

Example 2 with Jynstrument

use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.

the class ThrottleFrame method ynstrument.

// #JYNSTRUMENT# here instantiate the Jynstrument, put it in a component, initialize the context and start it
public JInternalFrame ynstrument(String path) {
    if (path == null) {
        return null;
    }
    // everything is there
    Jynstrument it = JynstrumentFactory.createInstrument(path, this);
    if (it == null) {
        log.error("Error while creating Jynstrument " + path);
        return null;
    }
    setTransparentBackground(it);
    JInternalFrame newiFrame = new JInternalFrame(it.getClassName());
    newiFrame.add(it);
    newiFrame.addInternalFrameListener(frameListener);
    newiFrame.setDoubleBuffered(true);
    newiFrame.setResizable(true);
    newiFrame.setClosable(true);
    newiFrame.setIconifiable(true);
    newiFrame.getContentPane().addContainerListener(new ContainerListener() {

        @Override
        public void componentAdded(ContainerEvent e) {
        }

        @Override
        public void componentRemoved(ContainerEvent e) {
            Container c = e.getContainer();
            while ((!(c instanceof JInternalFrame)) && (!(c instanceof TranslucentJPanel))) {
                c = c.getParent();
            }
            c.setVisible(false);
            remove(c);
            repaint();
        }
    });
    newiFrame.pack();
    add(newiFrame, PANEL_LAYER_FRAME);
    newiFrame.setVisible(true);
    return newiFrame;
}
Also used : ContainerEvent(java.awt.event.ContainerEvent) Jynstrument(jmri.jmrit.jython.Jynstrument) Container(java.awt.Container) ContainerListener(java.awt.event.ContainerListener) JInternalFrame(javax.swing.JInternalFrame)

Example 3 with Jynstrument

use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.

the class ThrottleFrame method getXml.

/**
     * Collect the prefs of this object into XML Element
     * <ul>
     * <li> Window prefs
     * <li> ControlPanel
     * <li> FunctionPanel
     * <li> AddressPanel
     * </ul>
     *
     *
     * @return the XML of this object.
     */
public Element getXml() {
    boolean switchAfter = false;
    if (!isEditMode) {
        switchMode();
        switchAfter = true;
    }
    Element me = new Element("ThrottleFrame");
    if (((javax.swing.plaf.basic.BasicInternalFrameUI) getControlPanel().getUI()).getNorthPane() != null) {
        Dimension bDim = ((javax.swing.plaf.basic.BasicInternalFrameUI) getControlPanel().getUI()).getNorthPane().getPreferredSize();
        me.setAttribute("border", Integer.toString(bDim.height));
    }
    java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(1);
    //        children.add(WindowPreferences.getPreferences(this));  // not required as it is in ThrottleWindow
    children.add(controlPanel.getXml());
    children.add(functionPanel.getXml());
    children.add(addressPanel.getXml());
    // Save Jynstruments
    Component[] cmps = getComponents();
    for (int i = 0; i < cmps.length; i++) {
        try {
            if (cmps[i] instanceof JInternalFrame) {
                Component[] cmps2 = ((JInternalFrame) cmps[i]).getContentPane().getComponents();
                int j = 0;
                while ((j < cmps2.length) && (!(cmps2[j] instanceof Jynstrument))) {
                    j++;
                }
                if ((j < cmps2.length) && (cmps2[j] instanceof Jynstrument)) {
                    Jynstrument jyn = (Jynstrument) cmps2[j];
                    Element elt = new Element("Jynstrument");
                    elt.setAttribute("JynstrumentFolder", FileUtil.getPortableFilename(jyn.getFolder()));
                    java.util.ArrayList<Element> jychildren = new java.util.ArrayList<Element>(1);
                    jychildren.add(WindowPreferences.getPreferences((JInternalFrame) cmps[i]));
                    Element je = jyn.getXml();
                    if (je != null) {
                        jychildren.add(je);
                    }
                    elt.setContent(jychildren);
                    children.add(elt);
                }
            }
        } catch (Exception ex) {
            log.debug("Got exception (no panic) " + ex);
        }
    }
    me.setContent(children);
    if (switchAfter) {
        switchMode();
    }
    return me;
}
Also used : Jynstrument(jmri.jmrit.jython.Jynstrument) Element(org.jdom2.Element) Dimension(java.awt.Dimension) Point(java.awt.Point) JComponent(javax.swing.JComponent) Component(java.awt.Component) JInternalFrame(javax.swing.JInternalFrame)

Example 4 with Jynstrument

use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.

the class Apps method ynstrument.

public static void ynstrument(String path) {
    Jynstrument it = JynstrumentFactory.createInstrument(path, _jynstrumentSpace);
    if (it == null) {
        log.error("Error while creating Jynstrument {}", path);
        return;
    }
    ThrottleFrame.setTransparent(it);
    it.setVisible(true);
    _jynstrumentSpace.setVisible(true);
    _jynstrumentSpace.add(it);
}
Also used : Jynstrument(jmri.jmrit.jython.Jynstrument)

Example 5 with Jynstrument

use of jmri.jmrit.jython.Jynstrument in project JMRI by JMRI.

the class ThrottleWindow method ynstrument.

public Jynstrument ynstrument(String path) {
    Jynstrument it = JynstrumentFactory.createInstrument(path, this);
    if (it == null) {
        log.error("Error while creating Jynstrument " + path);
        return null;
    }
    ThrottleFrame.setTransparent(it, true);
    it.setVisible(true);
    throttleToolBar.add(it);
    throttleToolBar.repaint();
    return it;
}
Also used : Jynstrument(jmri.jmrit.jython.Jynstrument)

Aggregations

Jynstrument (jmri.jmrit.jython.Jynstrument)10 Element (org.jdom2.Element)5 Component (java.awt.Component)4 JInternalFrame (javax.swing.JInternalFrame)4 Point (java.awt.Point)3 JComponent (javax.swing.JComponent)3 Dimension (java.awt.Dimension)2 BorderLayout (java.awt.BorderLayout)1 CardLayout (java.awt.CardLayout)1 Container (java.awt.Container)1 ContainerEvent (java.awt.event.ContainerEvent)1 ContainerListener (java.awt.event.ContainerListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 File (java.io.File)1 JFileChooser (javax.swing.JFileChooser)1 JPanel (javax.swing.JPanel)1 JmriException (jmri.JmriException)1 XmlFile (jmri.jmrit.XmlFile)1