Search in sources :

Example 66 with Container

use of java.awt.Container in project JMRI by JMRI.

the class CatalogPanel method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    if (e.isPopupTrigger()) {
        Container con = (Container) e.getSource();
        JLabel label = (JLabel) con.getComponent(0);
        NamedIcon icon = (NamedIcon) label.getIcon();
        showPopUp(e, icon);
    }
}
Also used : Container(java.awt.Container) JLabel(javax.swing.JLabel)

Example 67 with Container

use of java.awt.Container in project JMRI by JMRI.

the class CatalogPanel method setBackground.

public void setBackground(Container container) {
    container.setBackground(_currentBackground);
    Component[] comp = container.getComponents();
    for (Component comp1 : comp) {
        comp1.setBackground(_currentBackground);
        if (comp1 instanceof java.awt.Container) {
            setBackground((Container) comp1);
        }
    }
    container.invalidate();
}
Also used : Container(java.awt.Container) Component(java.awt.Component)

Example 68 with Container

use of java.awt.Container in project JMRI by JMRI.

the class Editor method setTargetPanel.

//
// *************** setting the main panel and frame ***************
//
/**
     * Set the target panel.
     *
     * An Editor may or may not choose to use 'this' as its frame or the
     * interior class 'TargetPane' for its targetPanel.
     *
     * @param targetPanel the panel to be edited
     * @param frame       the frame to embed the panel in
     */
protected void setTargetPanel(JLayeredPane targetPanel, JmriJFrame frame) {
    if (targetPanel == null) {
        _targetPanel = new TargetPane();
    } else {
        _targetPanel = targetPanel;
    }
    // and don't attach mouse and keyboard listeners to the panel
    if (GraphicsEnvironment.isHeadless()) {
        _panelScrollPane = null;
        _targetFrame = null;
        return;
    }
    if (frame == null) {
        _targetFrame = this;
    } else {
        _targetFrame = frame;
    }
    _targetFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    _panelScrollPane = new JScrollPane(_targetPanel);
    Container contentPane = _targetFrame.getContentPane();
    contentPane.add(_panelScrollPane);
    _targetFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            targetWindowClosingEvent(e);
        }
    });
    _targetPanel.addMouseListener(this);
    _targetPanel.addMouseMotionListener(this);
    _targetPanel.setFocusable(true);
    _targetPanel.addKeyListener(this);
//_targetFrame.pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) Container(java.awt.Container)

Example 69 with Container

use of java.awt.Container in project JMRI by JMRI.

the class SwitchboardEditor method init.

/**
     * Initialize the newly created SwitchBoard.
     *
     * @param name name of the switchboard frame
     */
@Override
protected void init(String name) {
    //setVisible(false);
    // Editor
    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // make menus
    setGlobalSetsLocalFlag(false);
    setUseGlobalFlag(false);
    _menuBar = new JMenuBar();
    makeOptionMenu();
    //makeEditMenu();
    makeFileMenu();
    setJMenuBar(_menuBar);
    addHelpMenu("package.jmri.jmrit.display.SwitchboardEditor", true);
    //super.setTargetPanel(null, makeFrame(name)); // original CPE version
    //extends JLayeredPane();
    switchboardLayeredPane = new TargetPane();
    switchboardLayeredPane.setPreferredSize(new Dimension(300, 310));
    switchboardLayeredPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(defaultTextColor), Bundle.getMessage("SwitchboardBanner"), TitledBorder.LEADING, TitledBorder.ABOVE_BOTTOM, getFont(), defaultTextColor));
    // create contrast with background, should also specify border style
    // specify title for turnout, sensor, light, mixed? (wait for the Editor to be created)
    switchboardLayeredPane.addMouseMotionListener(this);
    //Add control pane and layered pane to this JPanel
    JPanel beanSetupPane = new JPanel();
    beanSetupPane.setLayout(new FlowLayout(FlowLayout.TRAILING));
    JLabel beanTypeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanTypeLabel")));
    beanSetupPane.add(beanTypeTitle);
    beanTypeList = new JComboBox(beanTypeStrings);
    // select Turnout in comboBox
    beanTypeList.setSelectedIndex(0);
    beanTypeList.setActionCommand(LAYER_COMMAND);
    beanTypeList.addActionListener(this);
    beanSetupPane.add(beanTypeList);
    //Add connection selection comboBox
    // translate from selectedIndex to char
    beanTypeChar = getSwitchType().charAt(0);
    log.debug("beanTypeChar set to [{}]", beanTypeChar);
    JLabel beanManuTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ConnectionLabel")));
    beanSetupPane.add(beanManuTitle);
    beanManuNames = new JComboBox();
    if (getManager(beanTypeChar) instanceof jmri.managers.AbstractProxyManager) {
        // from abstractTableTabAction
        jmri.managers.AbstractProxyManager proxy = (jmri.managers.AbstractProxyManager) getManager(beanTypeChar);
        List<jmri.Manager> managerList = proxy.getManagerList();
        for (int x = 0; x < managerList.size(); x++) {
            String manuPrefix = managerList.get(x).getSystemPrefix();
            log.debug("Prefix = [{}]", manuPrefix);
            String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
            log.debug("Connection name = [{}]", manuName);
            // add to comboBox
            beanManuNames.addItem(manuName);
            // add to list
            beanManuPrefixes.add(manuPrefix);
        }
    } else {
        String manuPrefix = getManager(beanTypeChar).getSystemPrefix();
        String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
        beanManuNames.addItem(manuName);
        // add to list (as only item)
        beanManuPrefixes.add(manuPrefix);
    }
    beanManuNames.setSelectedIndex(0);
    beanManuNames.setActionCommand(MANU_COMMAND);
    beanManuNames.addActionListener(this);
    beanSetupPane.add(beanManuNames);
    add(beanSetupPane);
    // add shape combobox
    JPanel switchShapePane = new JPanel();
    switchShapePane.setLayout(new FlowLayout(FlowLayout.TRAILING));
    JLabel switchShapeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SwitchShape")));
    switchShapePane.add(switchShapeTitle);
    switchShapeList = new JComboBox(switchShapeStrings);
    // select Button in comboBox
    switchShapeList.setSelectedIndex(0);
    switchShapeList.setActionCommand(SWITCHTYPE_COMMAND);
    switchShapeList.addActionListener(this);
    switchShapePane.add(switchShapeList);
    // add column spinner
    JLabel columnLabel = new JLabel(Bundle.getMessage("NumberOfColumns"));
    switchShapePane.add(columnLabel);
    switchShapePane.add(Columns);
    add(switchShapePane);
    JCheckBox hideUnconnected = new JCheckBox(Bundle.getMessage("CheckBoxHideUnconnected"));
    hideUnconnected.setSelected(hideUnconnected());
    hideUnconnected.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            setHideUnconnected(hideUnconnected.isSelected());
        }
    });
    add(hideUnconnected);
    // Next, add the buttons to the layered pane.
    switchboardLayeredPane.setLayout(new GridLayout(java.lang.Math.max(2, _range % ((Integer) Columns.getValue())), (Integer) Columns.getValue()));
    // vertical (at least 2 rows), horizontal
    // TODO do some calculation from JPanel size, icon size and determine optimal cols/rows
    addSwitchRange((Integer) minSpinner.getValue(), (Integer) maxSpinner.getValue(), beanTypeList.getSelectedIndex(), beanManuPrefixes.get(beanManuNames.getSelectedIndex()), switchShapeList.getSelectedIndex());
    // provide a JLayeredPane to place the switches on
    super.setTargetPanel(switchboardLayeredPane, makeFrame(name));
    // width x height
    super.getTargetFrame().setSize(550, 330);
    // To do: Add component listener to handle frame resizing event
    // set scrollbar initial state
    setScroll(SCROLL_NONE);
    scrollNone.setSelected(true);
    super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(this);
    }
    add(createControlPanel());
    JPanel updatePanel = new JPanel();
    JButton updateButton = new JButton(Bundle.getMessage("ButtonUpdate"));
    updateButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            log.debug("Update clicked");
            updatePressed();
        }
    });
    updatePanel.add(updateButton);
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    contentPane.add(updatePanel);
    //re-layout all the toolbar items
    setupToolBar();
    // refresh default Switchboard
    updatePressed();
    pack();
    setVisible(true);
// TODO choose your own icons
//        class makeCatalog extends SwingWorker<CatalogPanel, Object> {
//
//            @Override
//            public CatalogPanel doInBackground() {
//                return CatalogPanel.makeDefaultCatalog();
//            }
//        }
//        (new makeCatalog()).execute();
//        log.debug("Init SwingWorker launched");
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) InstanceManager(jmri.InstanceManager) ConfigureManager(jmri.ConfigureManager) Manager(jmri.Manager) Font(java.awt.Font) Container(java.awt.Container) GridLayout(java.awt.GridLayout) ConfigureManager(jmri.ConfigureManager) JComboBox(javax.swing.JComboBox) Color(java.awt.Color) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JMenuBar(javax.swing.JMenuBar)

Example 70 with Container

use of java.awt.Container in project JMRI by JMRI.

the class SwitchboardEditor method setupToolBar.

private void setupToolBar() {
    //Initial setup for both horizontal and vertical
    Container contentPane = getContentPane();
    //remove these (if present) so we can add them back (without duplicates)
    if (editToolBarContainer != null) {
        editToolBarContainer.setVisible(false);
        contentPane.remove(editToolBarContainer);
    }
    //        if (helpBarPanel != null) {
    //            contentPane.remove(helpBarPanel);
    //        }
    editToolBarPanel = new JPanel();
    editToolBarPanel.setLayout(new BoxLayout(editToolBarPanel, BoxLayout.PAGE_AXIS));
    JPanel innerBorderPanel = new JPanel();
    innerBorderPanel.setLayout(new BoxLayout(innerBorderPanel, BoxLayout.PAGE_AXIS));
    TitledBorder TitleBorder = BorderFactory.createTitledBorder(Bundle.getMessage("SwitchboardHelpTitle"));
    innerBorderPanel.setBorder(TitleBorder);
    innerBorderPanel.add(new JTextArea(Bundle.getMessage("Help1")));
    if (!hideUnconnected()) {
        innerBorderPanel.add(new JTextArea(Bundle.getMessage("Help2")));
    // TODO hide this panel when hideUnconnected() is set to false from menu or checkbox
    }
    contentPane.add(innerBorderPanel);
    //Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    editToolBarScroll = new JScrollPane(editToolBarPanel);
    //editToolBarScroll.getPreferredSize().height;
    height = 60;
    editToolBarContainer = new JPanel();
    editToolBarContainer.setLayout(new BoxLayout(editToolBarContainer, BoxLayout.PAGE_AXIS));
    editToolBarContainer.add(editToolBarScroll);
    editToolBarContainer.setMinimumSize(new Dimension(width, height));
    editToolBarContainer.setPreferredSize(new Dimension(width, height));
//        helpBarPanel = new JPanel();
//        helpBarPanel.add(helpBar);
//        for (Component c : helpBar.getComponents()) {
//            if (c instanceof JTextArea) {
//                JTextArea j = (JTextArea) c;
//                //j.setSize(new Dimension(width, j.getSize().height));
//                j.setLineWrap(true);
//                j.setWrapStyleWord(true);
//            }
//        }
//        contentPane.setLayout(new BoxLayout(contentPane, false ? BoxLayout.LINE_AXIS : BoxLayout.PAGE_AXIS));
//        contentPane.add(editToolBarContainer);
//        contentPane.add(helpBarPanel);
//helpBarPanel.setVisible(isEditable() && showHelpBar);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Container(java.awt.Container) JTextArea(javax.swing.JTextArea) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) TitledBorder(javax.swing.border.TitledBorder)

Aggregations

Container (java.awt.Container)250 JPanel (javax.swing.JPanel)70 JLabel (javax.swing.JLabel)65 JButton (javax.swing.JButton)56 JScrollPane (javax.swing.JScrollPane)55 BoxLayout (javax.swing.BoxLayout)50 FlowLayout (java.awt.FlowLayout)49 Component (java.awt.Component)46 BorderLayout (java.awt.BorderLayout)44 Dimension (java.awt.Dimension)39 ActionEvent (java.awt.event.ActionEvent)38 ActionListener (java.awt.event.ActionListener)26 JComponent (javax.swing.JComponent)22 JFrame (javax.swing.JFrame)22 JmriJFrame (jmri.util.JmriJFrame)20 Border (javax.swing.border.Border)18 JTable (javax.swing.JTable)17 JTextArea (javax.swing.JTextArea)17 Frame (java.awt.Frame)16 JTextField (javax.swing.JTextField)16