Search in sources :

Example 1 with JmriPanel

use of jmri.util.swing.JmriPanel in project JMRI by JMRI.

the class JmriJFrameInterface method show.

@Override
public void show(final JmriPanel child, JmriAbstractAction act, Hint hint) {
    // display cached frame if available
    JmriJFrame frame = frames.get(child);
    if (frame != null) {
        frame.setVisible(true);
        return;
    }
    // create frame
    frame = new jmri.util.JmriJFrame();
    // cache if single instance
    if (!child.isMultipleInstances()) {
        frames.put(child, frame);
    }
    // add gui object, responsible for own layout
    frame.add(child);
    // add menus if requested
    List<JMenu> list = child.getMenus();
    JMenuBar bar = frame.getJMenuBar();
    if (bar == null) {
        bar = new JMenuBar();
    }
    for (JMenu menu : list) {
        bar.add(menu);
    }
    frame.setJMenuBar(bar);
    // add help menu if requested
    if (child.getHelpTarget() != null) {
        frame.addHelpMenu(child.getHelpTarget(), true);
    }
    // set title if available
    if (child.getTitle() != null) {
        frame.setTitle(child.getTitle());
    }
    // if multi-instance, arrange to run dispose on close
    if (child.isMultipleInstances()) {
        frame.addWindowListener(new java.awt.event.WindowAdapter() {

            jmri.util.swing.JmriPanel c;

            {
                c = child;
            }

            @Override
            public void windowClosed(java.awt.event.WindowEvent e) {
                c.dispose();
            }
        });
    }
    // pack and show
    frame.pack();
    frame.setVisible(true);
}
Also used : JmriJFrame(jmri.util.JmriJFrame) JmriJFrame(jmri.util.JmriJFrame) JmriPanel(jmri.util.swing.JmriPanel) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 2 with JmriPanel

use of jmri.util.swing.JmriPanel in project JMRI by JMRI.

the class LicenseAction method makePanel.

@Override
public jmri.util.swing.JmriPanel makePanel() {
    jmri.util.swing.JmriPanel p = new JmriPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JScrollPane jScrollPane = new JScrollPane();
    JTextPane textPane = new JTextPane();
    // get the file
    // NOI18N
    InputStream is = FileUtil.findInputStream("resources/COPYING", FileUtil.Location.INSTALLED);
    String t;
    try (// file stored as ASCII // NOI18N
    InputStreamReader isr = new InputStreamReader(is, "US-ASCII");
        BufferedReader r = new BufferedReader(isr)) {
        StringBuilder buf = new StringBuilder();
        while (r.ready()) {
            buf.append(r.readLine());
            buf.append("\n");
        }
        t = buf.toString();
    } catch (IOException ex) {
        t = "JMRI is distributed under a license. For license information, see the JMRI website http://jmri.org";
    }
    textPane.setText(t);
    // set up display
    textPane.setEditable(false);
    jScrollPane.getViewport().add(textPane);
    p.add(jScrollPane);
    // start scrolled to top
    JScrollBar b = jScrollPane.getVerticalScrollBar();
    b.setValue(b.getMaximum());
    return p;
}
Also used : JScrollPane(javax.swing.JScrollPane) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BoxLayout(javax.swing.BoxLayout) IOException(java.io.IOException) JScrollBar(javax.swing.JScrollBar) JTextPane(javax.swing.JTextPane) BufferedReader(java.io.BufferedReader) JmriPanel(jmri.util.swing.JmriPanel) JmriPanel(jmri.util.swing.JmriPanel)

Aggregations

JmriPanel (jmri.util.swing.JmriPanel)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 BoxLayout (javax.swing.BoxLayout)1 JMenu (javax.swing.JMenu)1 JMenuBar (javax.swing.JMenuBar)1 JScrollBar (javax.swing.JScrollBar)1 JScrollPane (javax.swing.JScrollPane)1 JTextPane (javax.swing.JTextPane)1 JmriJFrame (jmri.util.JmriJFrame)1