Search in sources :

Example 41 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class TableFrames method makeBlockFrame.

/*
     * ********************* BlockFrame *****************************
     */
protected JInternalFrame makeBlockFrame() {
    JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitleBlockTable"), true, false, false, true);
    _oBlockModel = new OBlockTableModel(this);
    _oBlockTable = new JTable(_oBlockModel);
    TableRowSorter<OBlockTableModel> sorter = new TableRowSorter<>(_oBlockModel);
    sorter.setComparator(OBlockTableModel.SYSNAMECOL, new jmri.util.SystemNameComparator());
    _oBlockTable.setRowSorter(sorter);
    _oBlockTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { OBlockTableModel.EDIT_COL, OBlockTableModel.DELETE_COL, OBlockTableModel.REPORT_CURRENTCOL, OBlockTableModel.SPEEDCOL, OBlockTableModel.PERMISSIONCOL, OBlockTableModel.UNITSCOL }));
    _oBlockTable.setDragEnabled(true);
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    _oBlockTable.setColumnModel(tcm);
    _oBlockTable.getTableHeader().setReorderingAllowed(true);
    _oBlockTable.createDefaultColumnsFromModel();
    _oBlockModel.addHeaderListener(_oBlockTable);
    _oBlockTable.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.EDIT_COL).setCellEditor(new ButtonEditor(new JButton()));
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.EDIT_COL).setCellRenderer(new ButtonRenderer());
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.UNITSCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("cm"), Bundle.getMessage("in")));
    JComboBox<String> box = new JComboBox<String>(OBlockTableModel.curveOptions);
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.CURVECOL).setCellEditor(new DefaultCellEditor(box));
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.REPORT_CURRENTCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("Current"), Bundle.getMessage("Last")));
    box = new JComboBox<String>(jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames());
    box.addItem("");
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.SPEEDCOL).setCellEditor(new DefaultCellEditor(box));
    _oBlockTable.getColumnModel().getColumn(OBlockTableModel.PERMISSIONCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("Permissive"), Bundle.getMessage("Absolute")));
    _oBlockTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent me) {
            showPopup(me);
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            showPopup(me);
        }
    });
    for (int i = 0; i < _oBlockModel.getColumnCount(); i++) {
        int width = _oBlockModel.getPreferredWidth(i);
        _oBlockTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    _oBlockTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    ROW_HEIGHT = _oBlockTable.getRowHeight();
    int tableWidth = _desktop.getPreferredSize().width;
    _oBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 10));
    _blockTablePane = new JScrollPane(_oBlockTable);
    tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.REPORTERCOL), false);
    tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.REPORT_CURRENTCOL), false);
    tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.PERMISSIONCOL), false);
    //        tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.SPEEDCOL), false);
    //        tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.ERR_SENSORCOL), false);
    tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.CURVECOL), false);
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout(5, 5));
    JLabel prompt = new JLabel(Bundle.getMessage("AddBlockPrompt"));
    contentPane.add(prompt, BorderLayout.NORTH);
    contentPane.add(_blockTablePane, BorderLayout.CENTER);
    frame.setContentPane(contentPane);
    frame.pack();
    return frame;
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) SignalSpeedMap(jmri.implementation.SignalSpeedMap) BorderLayout(java.awt.BorderLayout) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) Point(java.awt.Point) DefaultCellEditor(javax.swing.DefaultCellEditor) Dimension(java.awt.Dimension) JTable(javax.swing.JTable) JInternalFrame(javax.swing.JInternalFrame) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 42 with JComboBox

use of javax.swing.JComboBox 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 43 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class ScheduleTableModel method getTrackComboBox.

private JComboBox<Track> getTrackComboBox(ScheduleItem si) {
    // log.debug("getTrackComboBox for ScheduleItem "+si.getType());
    JComboBox<Track> cb = new JComboBox<>();
    if (si.getDestination() != null) {
        Location dest = si.getDestination();
        dest.updateComboBox(cb);
        filterTracks(dest, cb, si.getTypeName(), si.getRoadName(), si.getShipLoadName());
        cb.setSelectedItem(si.getDestinationTrack());
        if (si.getDestinationTrack() != null && cb.getSelectedIndex() == -1) {
            // user deleted track at destination, this is self correcting, when user restarts program, track
            // assignment will be gone.
            cb.addItem(si.getDestinationTrack());
            cb.setSelectedItem(si.getDestinationTrack());
        }
    }
    return cb;
}
Also used : JComboBox(javax.swing.JComboBox) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 44 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class TrainPrintUtilities method getPrinterJComboBox.

public static JComboBox<String> getPrinterJComboBox() {
    JComboBox<String> box = new JComboBox<>();
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    for (PrintService printService : services) {
        box.addItem(printService.getName());
    }
    // Set to default printer
    box.setSelectedItem(getDefaultPrinterName());
    return box;
}
Also used : JComboBox(javax.swing.JComboBox) PrintService(javax.print.PrintService)

Example 45 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class RosterGroupTableAction method actionPerformed.

public void actionPerformed() {
    // create the JTable model, with changes for specific NamedBean
    createModel();
    // create the frame
    f = new RosterGroupTableFrame(m, helpTarget()) {

        /**
             * Include an "add" button
             */
        @Override
        void extras() {
            final JComboBox<String> selectCombo = new RosterGroupComboBox();
            selectCombo.insertItemAt("", 0);
            selectCombo.setSelectedIndex(-1);
            JPanel p25 = new JPanel();
            p25.add(new JLabel(Bundle.getMessage("SelectRosterGroup")));
            p25.add(selectCombo);
            addToTopBox(p25);
            selectCombo.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    comboSelected(e, selectCombo.getSelectedItem().toString());
                }
            });
            selectCombo.setVisible(true);
        }
    };
    setTitle();
    addToFrame(f);
    f.pack();
    f.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) RosterGroupComboBox(jmri.jmrit.roster.swing.RosterGroupComboBox) JLabel(javax.swing.JLabel)

Aggregations

JComboBox (javax.swing.JComboBox)226 JLabel (javax.swing.JLabel)97 JPanel (javax.swing.JPanel)88 ActionEvent (java.awt.event.ActionEvent)69 ActionListener (java.awt.event.ActionListener)66 JButton (javax.swing.JButton)55 GridBagLayout (java.awt.GridBagLayout)42 GridBagConstraints (java.awt.GridBagConstraints)41 Insets (java.awt.Insets)40 Dimension (java.awt.Dimension)39 JScrollPane (javax.swing.JScrollPane)37 JTextField (javax.swing.JTextField)36 BoxLayout (javax.swing.BoxLayout)34 JCheckBox (javax.swing.JCheckBox)33 DefaultCellEditor (javax.swing.DefaultCellEditor)27 JTable (javax.swing.JTable)26 BorderLayout (java.awt.BorderLayout)25 Component (java.awt.Component)25 TableColumn (javax.swing.table.TableColumn)23 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)22