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;
}
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");
}
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());
}
}
});
}
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();
}
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();
}
Aggregations