Search in sources :

Example 81 with JTable

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

the class PaneProgPane method newRow.

/**
     * Create a single row from the JDOM column Element
     *
     * @param element     element containing row contents
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     * @param modelElem   element containing the decoder model
     * @return a panel containing the group
     */
public JPanel newRow(Element element, boolean showStdName, Element modelElem) {
    // create a panel to add as a new column or row
    final JPanel c = new JPanel();
    panelList.add(c);
    GridBagLayout g = new GridBagLayout();
    GridBagConstraints cs = new GridBagConstraints();
    c.setLayout(g);
    // handle the xml definition
    // for all elements in the column or row
    List<Element> elemList = element.getChildren();
    log.trace("newRow starting with {} elements", elemList.size());
    for (int i = 0; i < elemList.size(); i++) {
        // update the grid position
        cs.gridy = 0;
        cs.gridx++;
        Element e = elemList.get(i);
        String name = e.getName();
        log.trace("newRow processing {} element", name);
        // decode the type
        if (name.equals("display")) {
            // its a variable
            // load the variable
            newVariable(e, c, g, cs, showStdName);
        } else if (name.equals("separator")) {
            // its a separator
            JSeparator j = new JSeparator(javax.swing.SwingConstants.VERTICAL);
            cs.fill = GridBagConstraints.BOTH;
            cs.gridheight = GridBagConstraints.REMAINDER;
            g.setConstraints(j, cs);
            c.add(j);
            cs.fill = GridBagConstraints.NONE;
            cs.gridheight = 1;
        } else if (name.equals("label")) {
            cs.gridheight = GridBagConstraints.REMAINDER;
            makeLabel(e, c, g, cs);
        } else if (name.equals("soundlabel")) {
            cs.gridheight = GridBagConstraints.REMAINDER;
            makeSoundLabel(e, c, g, cs);
        } else if (name.equals("cvtable")) {
            makeCvTable(cs, g, c);
        } else if (name.equals("indxcvtable")) {
            log.debug("starting to build IndexedCvTable pane");
            JTable indxcvTable = new JTable(_indexedCvModel);
            JScrollPane cvScroll = new JScrollPane(indxcvTable);
            indxcvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
            indxcvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
            indxcvTable.setDefaultEditor(JTextField.class, new ValueEditor());
            indxcvTable.setDefaultEditor(JButton.class, new ValueEditor());
            indxcvTable.setRowHeight(new JButton("X").getPreferredSize().height);
            indxcvTable.setPreferredScrollableViewportSize(new Dimension(700, indxcvTable.getRowHeight() * 14));
            cvScroll.setColumnHeaderView(indxcvTable.getTableHeader());
            // don't want a horizontal scroll bar
            // Need to see the whole row at one time
            //                indxcvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            cs.gridwidth = GridBagConstraints.REMAINDER;
            g.setConstraints(cvScroll, cs);
            c.add(cvScroll);
            cs.gridwidth = 1;
            // remember which indexed CVs to read/write
            for (int j = 0; j < _indexedCvModel.getRowCount(); j++) {
                String sz = "CV" + _indexedCvModel.getName(j);
                int in = _varModel.findVarIndex(sz);
                indexedCvList.add(in);
            }
            _cvTable = true;
            log.debug("end of building IndexedCvTable pane");
        } else if (name.equals("fnmapping")) {
            pickFnMapPanel(c, g, cs, modelElem);
        } else if (name.equals("dccaddress")) {
            JPanel l = addDccAddressPanel(e);
            if (l.getComponentCount() > 0) {
                cs.gridheight = GridBagConstraints.REMAINDER;
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridheight = 1;
            }
        } else if (name.equals("column")) {
            // nested "column" elements ...
            cs.gridheight = GridBagConstraints.REMAINDER;
            JPanel l = newColumn(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridheight = 1;
            }
        } else if (name.equals("row")) {
            // nested "row" elements ...
            cs.gridwidth = GridBagConstraints.REMAINDER;
            JPanel l = newRow(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("grid")) {
            // nested "grid" elements ...
            cs.gridwidth = GridBagConstraints.REMAINDER;
            JPanel l = newGrid(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("group")) {
            // nested "group" elements ...
            JPanel l = newGroup(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
            }
        } else if (!name.equals("qualifier")) {
            // its a mistake
            log.error("No code to handle element of type " + e.getName() + " in newRow");
        }
    }
    // add glue to the bottom to allow resize
    if (c.getComponentCount() > 0) {
        c.add(Box.createVerticalGlue());
    }
    // handle qualification if any
    QualifierAdder qa = new QualifierAdder() {

        @Override
        protected Qualifier createQualifier(VariableValue var, String relation, String value) {
            return new JComponentQualifier(c, var, Integer.parseInt(value), relation);
        }

        @Override
        protected void addListener(java.beans.PropertyChangeListener qc) {
            c.addPropertyChangeListener(qc);
        }
    };
    qa.processModifierElements(element, _varModel);
    return c;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) VariableValue(jmri.jmrit.symbolicprog.VariableValue) Element(org.jdom2.Element) JButton(javax.swing.JButton) ValueEditor(jmri.jmrit.symbolicprog.ValueEditor) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) ValueRenderer(jmri.jmrit.symbolicprog.ValueRenderer) JTable(javax.swing.JTable) QualifierAdder(jmri.jmrit.symbolicprog.QualifierAdder)

Example 82 with JTable

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

the class PaneProgPane method makeCvTable.

void makeCvTable(GridBagConstraints cs, GridBagLayout g, JPanel c) {
    log.debug("starting to build CvTable pane");
    TableRowSorter<TableModel> sorter = new TableRowSorter<>(_cvModel);
    JTable cvTable = new JTable(_cvModel);
    sorter.setComparator(CvTableModel.NUMCOLUMN, new jmri.util.PreferNumericComparator());
    List<RowSorter.SortKey> sortKeys = new ArrayList<>();
    sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
    sorter.setSortKeys(sortKeys);
    cvTable.setRowSorter(sorter);
    cvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
    cvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
    cvTable.setDefaultEditor(JTextField.class, new ValueEditor());
    cvTable.setDefaultEditor(JButton.class, new ValueEditor());
    cvTable.setRowHeight(new JButton("X").getPreferredSize().height);
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    // instead of forcing the columns to fill the frame (and only fill)
    cvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JScrollPane cvScroll = new JScrollPane(cvTable);
    cvScroll.setColumnHeaderView(cvTable.getTableHeader());
    cs.gridheight = GridBagConstraints.REMAINDER;
    g.setConstraints(cvScroll, cs);
    c.add(cvScroll);
    cs.gridheight = 1;
    // remember which CVs to read/write
    isCvTablePane = true;
    setCvListFromTable();
    _cvTable = true;
    log.debug("end of building CvTable pane");
}
Also used : JScrollPane(javax.swing.JScrollPane) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ArrayList(java.util.ArrayList) ValueEditor(jmri.jmrit.symbolicprog.ValueEditor) JButton(javax.swing.JButton) ValueRenderer(jmri.jmrit.symbolicprog.ValueRenderer) JTable(javax.swing.JTable) TableRowSorter(javax.swing.table.TableRowSorter) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) TableModel(javax.swing.table.TableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

Example 83 with JTable

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

the class UserInterface method createWindow.

protected void createWindow() {
    panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints con = new GridBagConstraints();
    getContentPane().add(panel);
    con.fill = GridBagConstraints.NONE;
    con.weightx = 0.5;
    con.weighty = 0;
    JLabel label = new JLabel(MessageFormat.format(rb.getString("LabelAdvertising"), new Object[] { DeviceServer.getWiTVersion() }));
    con.gridx = 0;
    con.gridy = 0;
    con.gridwidth = 2;
    panel.add(label, con);
    con.gridx = 0;
    con.gridy = 1;
    con.gridwidth = 2;
    panel.add(portLabel, con);
    con.gridy = 2;
    panel.add(manualPortLabel, con);
    numConnected = new JLabel(rb.getString("LabelClients") + " " + deviceList.size());
    con.weightx = 0;
    con.gridx = 2;
    con.gridy = 2;
    con.ipadx = 5;
    con.gridwidth = 1;
    panel.add(numConnected, con);
    JPanel rgsPanel = new JPanel();
    rgsPanel.add(new JLabel(rb.getString("RosterGroupLabel")));
    rgsPanel.add(rosterGroupSelector);
    rgsPanel.setToolTipText(rb.getString("RosterGroupToolTip"));
    JToolBar withrottleToolBar = new JToolBar();
    withrottleToolBar.setFloatable(false);
    withrottleToolBar.add(new StopAllButton());
    withrottleToolBar.add(new LargePowerManagerButton());
    withrottleToolBar.add(rgsPanel);
    con.weightx = 0.5;
    con.ipadx = 0;
    con.gridx = 1;
    con.gridy = 3;
    con.gridwidth = 2;
    panel.add(withrottleToolBar, con);
    /*
         JLabel vLabel = new JLabel("v"+DeviceServer.getWiTVersion());
         con.weightx = 0;
         con.gridx = 2;
         con.gridy = 3;
         panel.add(vLabel, con);
         */
    JLabel icon;
    java.net.URL imageURL = FileUtil.findURL("resources/IconForWiThrottle.gif");
    if (imageURL != null) {
        ImageIcon image = new ImageIcon(imageURL);
        icon = new JLabel(image);
        con.weightx = 0.5;
        con.gridx = 2;
        con.gridy = 0;
        con.ipady = 5;
        con.gridheight = 2;
        panel.add(icon, con);
    }
    //  Add a list of connected devices and the address they are set to.
    withrottlesListModel = new WiThrottlesListModel(deviceList);
    withrottlesList = new JTable(withrottlesListModel);
    withrottlesList.setPreferredScrollableViewportSize(new Dimension(300, 80));
    withrottlesList.setRowHeight(20);
    scrollTable = new JScrollPane(withrottlesList);
    con.gridx = 0;
    con.gridy = 4;
    con.weighty = 1.0;
    con.ipadx = 10;
    con.ipady = 10;
    con.gridheight = 3;
    con.gridwidth = GridBagConstraints.REMAINDER;
    con.fill = GridBagConstraints.BOTH;
    panel.add(scrollTable, con);
    //  Create the menu to use with WiThrottle window. Has to be before pack() for Windows.
    buildMenu();
    //  Set window size & location
    this.setTitle("WiThrottle");
    this.pack();
    this.setResizable(true);
    Rectangle screenRect = new Rectangle(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    //  Centers on top edge of screen
    this.setLocation((screenRect.width / 2) - (this.getWidth() / 2), 0);
    this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    setVisible(true);
    setMinimumSize(getSize());
    rosterGroupSelector.addActionListener(new ActionListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void actionPerformed(ActionEvent e) {
            userPreferences.addComboBoxLastSelection(rosterGroupSelectorPreferencesName, (String) ((JComboBox<String>) e.getSource()).getSelectedItem());
            //              Send new selected roster group to all devices
            for (DeviceServer device : deviceList) {
                device.sendPacketToDevice(device.sendRoster());
            }
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) LargePowerManagerButton(jmri.jmrit.throttle.LargePowerManagerButton) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) StopAllButton(jmri.jmrit.throttle.StopAllButton)

Example 84 with JTable

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

the class ListFrame method initComponents.

@Override
public void initComponents() throws Exception {
    // set the frame's initial state
    setTitle(rb.getString("WindowTitle"));
    setSize(500, 400);
    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // Set up the node selection panel
    initializeNodes();
    nodeSelBox.setEditable(false);
    if (numConfigNodes > 0) {
        nodeSelBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                displayNodeInfo((String) nodeSelBox.getSelectedItem());
            }
        });
        inputBits.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                if (inputSelected == false) {
                    inputSelected = true;
                    displayNodeInfo(selNodeID);
                }
            }
        });
        outputBits.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                if (inputSelected == true) {
                    inputSelected = false;
                    displayNodeInfo(selNodeID);
                }
            }
        });
    } else {
        nodeInfoText.setText(rb.getString("NoNodesError"));
    }
    nodeSelBox.setToolTipText(rb.getString("NodeBoxTip"));
    inputBits.setToolTipText(rb.getString("ShowInputTip"));
    outputBits.setToolTipText(rb.getString("ShowOutputTip"));
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
    JPanel panel11 = new JPanel();
    panel11.add(nodeLabel);
    panel11.add(nodeSelBox);
    bitTypeGroup.add(outputBits);
    bitTypeGroup.add(inputBits);
    panel11.add(inputBits);
    panel11.add(outputBits);
    JPanel panel12 = new JPanel();
    panel12.add(nodeInfoText);
    panel1.add(panel11);
    panel1.add(panel12);
    Border panel1Border = BorderFactory.createEtchedBorder();
    Border panel1Titled = BorderFactory.createTitledBorder(panel1Border, rb.getString("NodePanelName"));
    panel1.setBorder(panel1Titled);
    contentPane.add(panel1);
    if (numConfigNodes > 0) {
        // Set up the assignment panel
        assignmentPanel = new JPanel();
        assignmentPanel.setLayout(new BoxLayout(assignmentPanel, BoxLayout.Y_AXIS));
        assignmentListModel = new AssignmentTableModel();
        assignmentTable = new JTable(assignmentListModel);
        assignmentTable.setRowSelectionAllowed(false);
        assignmentTable.setPreferredScrollableViewportSize(new java.awt.Dimension(300, 350));
        TableColumnModel assignmentColumnModel = assignmentTable.getColumnModel();
        TableColumn bitColumn = assignmentColumnModel.getColumn(AssignmentTableModel.BIT_COLUMN);
        bitColumn.setMinWidth(20);
        bitColumn.setMaxWidth(40);
        bitColumn.setResizable(true);
        TableColumn addressColumn = assignmentColumnModel.getColumn(AssignmentTableModel.ADDRESS_COLUMN);
        addressColumn.setMinWidth(40);
        addressColumn.setMaxWidth(85);
        addressColumn.setResizable(true);
        TableColumn sysColumn = assignmentColumnModel.getColumn(AssignmentTableModel.SYSNAME_COLUMN);
        sysColumn.setMinWidth(75);
        sysColumn.setMaxWidth(100);
        sysColumn.setResizable(true);
        TableColumn userColumn = assignmentColumnModel.getColumn(AssignmentTableModel.USERNAME_COLUMN);
        userColumn.setMinWidth(90);
        userColumn.setMaxWidth(450);
        userColumn.setResizable(true);
        JScrollPane assignmentScrollPane = new JScrollPane(assignmentTable);
        assignmentPanel.add(assignmentScrollPane, BorderLayout.CENTER);
        if (inputSelected) {
            assignmentPanel.setBorder(inputBorderTitled);
        } else {
            assignmentPanel.setBorder(outputBorderTitled);
        }
        contentPane.add(assignmentPanel);
    }
    // Set up Print button
    JPanel panel3 = new JPanel();
    panel3.setLayout(new FlowLayout());
    printButton.setVisible(true);
    printButton.setToolTipText(rb.getString("PrintButtonTip"));
    if (numConfigNodes > 0) {
        printButton.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                printButtonActionPerformed(e);
            }
        });
    }
    panel3.add(printButton);
    contentPane.add(panel3);
    if (numConfigNodes > 0) {
        // initialize for the first time
        displayNodeInfo((String) nodeSelBox.getSelectedItem());
    }
    addHelpMenu("package.jmri.jmrix.maple.assignment.ListFrame", true);
    // pack for display
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) ActionEvent(java.awt.event.ActionEvent) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) Border(javax.swing.border.Border)

Example 85 with JTable

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

the class PacketTableFrame method initComponents.

@Override
public void initComponents() {
    table = new JTable(model);
    table.setRowSorter(new TableRowSorter<>(model));
    scroll = new JScrollPane(table);
    model.configureTable(table);
    // general GUI config
    setTitle("Packet Monitor");
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    getContentPane().add(scroll);
    JPanel p1 = new JPanel();
    JButton b = new JButton(rb.getString("ButtonClear"));
    b.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            model.reset();
        }
    });
    p1.add(b);
    getContentPane().add(p1);
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTable(javax.swing.JTable) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton)

Aggregations

JTable (javax.swing.JTable)584 JScrollPane (javax.swing.JScrollPane)282 JPanel (javax.swing.JPanel)217 Dimension (java.awt.Dimension)145 JButton (javax.swing.JButton)139 BorderLayout (java.awt.BorderLayout)133 JLabel (javax.swing.JLabel)129 ActionEvent (java.awt.event.ActionEvent)109 ActionListener (java.awt.event.ActionListener)81 TableColumn (javax.swing.table.TableColumn)79 DefaultTableModel (javax.swing.table.DefaultTableModel)75 Component (java.awt.Component)66 BoxLayout (javax.swing.BoxLayout)66 FlowLayout (java.awt.FlowLayout)58 MouseEvent (java.awt.event.MouseEvent)58 JTextField (javax.swing.JTextField)57 TableColumnModel (javax.swing.table.TableColumnModel)52 GridBagConstraints (java.awt.GridBagConstraints)46 TableCellRenderer (javax.swing.table.TableCellRenderer)43 Test (org.junit.Test)43