use of jmri.jmrit.roster.swing.GlobalRosterEntryComboBox in project JMRI by JMRI.
the class SpeedoConsoleFrame method initComponents.
// FIXME: Why does the if statement in this method include a direct false?
@SuppressWarnings("unused")
@Override
public void initComponents() throws Exception {
setTitle(title());
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
// What services do we have?
dccServices = BASIC;
if (InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
prog = InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
dccServices |= PROG;
}
if (InstanceManager.getNullableDefault(jmri.ThrottleManager.class) != null) {
// otherwise we'll send speed commands
log.info("Using Throttle interface for profiling");
dccServices |= THROTTLE;
}
if (InstanceManager.getNullableDefault(jmri.PowerManager.class) != null) {
pm = InstanceManager.getDefault(jmri.PowerManager.class);
pm.addPropertyChangeListener(this);
}
/*
* Setup pane for basic operations
*/
JPanel basicPane = new JPanel();
basicPane.setLayout(new BoxLayout(basicPane, BoxLayout.Y_AXIS));
// Scale panel to hold the scale selector
JPanel scalePanel = new JPanel();
scalePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), rb.getString("SelectScale")));
scalePanel.setLayout(new FlowLayout());
scaleList.setToolTipText("Select the scale");
scaleList.setSelectedIndex(defaultScale);
selectedScale = scales[defaultScale];
// Listen to selection of scale
scaleList.addActionListener(new java.awt.event.ActionListener() {
// action semantics pass an Object that must be a JComboBox<String>
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
JComboBox<String> cb = (JComboBox<String>) e.getSource();
selectedScale = scales[cb.getSelectedIndex()];
// *** check if -1 and enable text entry box
}
});
scaleLabel.setText(rb.getString("Scale"));
scaleLabel.setVisible(true);
readerLabel.setText(rb.getString("UnknownReader"));
readerLabel.setVisible(true);
scalePanel.add(scaleLabel);
scalePanel.add(scaleList);
scalePanel.add(readerLabel);
basicPane.add(scalePanel);
// Mode panel for selection of profile mode
JPanel modePanel = new JPanel();
modePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), rb.getString("SelectMode")));
modePanel.setLayout(new FlowLayout());
// Buttons to select the mode
modeGroup.add(progButton);
modeGroup.add(mainButton);
progButton.setSelected(true);
progButton.setToolTipText(rb.getString("TTProg"));
mainButton.setToolTipText(rb.getString("TTMain"));
modePanel.add(progButton);
modePanel.add(mainButton);
// Listen to change of profile mode
progButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (((dccServices & PROG) == PROG)) {
// Programmer is available to read back CVs
readAddressButton.setEnabled(true);
statusLabel.setText(rb.getString("StatProg"));
}
}
});
mainButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// no programmer available to read back CVs
readAddressButton.setEnabled(false);
statusLabel.setText(rb.getString("StatMain"));
}
});
basicPane.add(modePanel);
// Speed panel for the dial or digital speed display
JPanel speedPanel = new JPanel();
speedPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), rb.getString("MeasuredSpeed")));
speedPanel.setLayout(new BoxLayout(speedPanel, BoxLayout.X_AXIS));
// Display Panel which is a card layout with cards to show
// numeric or dial type speed display
final JPanel displayCards = new JPanel();
displayCards.setLayout(new CardLayout());
// Numeric speed card
JPanel numericSpeedPanel = new JPanel();
numericSpeedPanel.setLayout(new BoxLayout(numericSpeedPanel, BoxLayout.X_AXIS));
Font f = new Font("", Font.PLAIN, 96);
speedTextField.setFont(f);
speedTextField.setHorizontalAlignment(JTextField.RIGHT);
speedTextField.setColumns(3);
speedTextField.setText("0.0");
speedTextField.setVisible(true);
speedTextField.setToolTipText(rb.getString("SpeedHere"));
numericSpeedPanel.add(speedTextField);
// Dial speed card
JPanel dialSpeedPanel = new JPanel();
dialSpeedPanel.setLayout(new BoxLayout(dialSpeedPanel, BoxLayout.X_AXIS));
dialSpeedPanel.add(speedoDialDisplay);
speedoDialDisplay.update(0.0F);
// Add cards to panel
displayCards.add(dialSpeedPanel, "DIAL");
displayCards.add(numericSpeedPanel, "NUMERIC");
CardLayout cl = (CardLayout) displayCards.getLayout();
cl.show(displayCards, "DIAL");
// button panel
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
speedGroup.add(mphButton);
speedGroup.add(kphButton);
mphButton.setSelected(true);
mphButton.setToolTipText(rb.getString("TTDisplayMPH"));
kphButton.setToolTipText(rb.getString("TTDisplayKPH"));
displayGroup.add(numButton);
displayGroup.add(dialButton);
dialButton.setSelected(true);
numButton.setToolTipText(rb.getString("TTDisplayNumeric"));
dialButton.setToolTipText(rb.getString("TTDisplayDial"));
buttonPanel.add(mphButton);
buttonPanel.add(kphButton);
buttonPanel.add(numButton);
buttonPanel.add(dialButton);
speedPanel.add(displayCards);
speedPanel.add(buttonPanel);
// Listen to change of units, convert current average and update display
mphButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
profileGraphPane.setUnitsMph();
profileGraphPane.repaint();
speedoDialDisplay.setUnitsMph();
speedoDialDisplay.update(currentSpeed);
speedoDialDisplay.repaint();
}
});
kphButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
profileGraphPane.setUnitsKph();
profileGraphPane.repaint();
speedoDialDisplay.setUnitsKph();
speedoDialDisplay.update(currentSpeed);
speedoDialDisplay.repaint();
}
});
// Listen to change of display
numButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
display = DisplayType.NUMERIC;
CardLayout cl = (CardLayout) displayCards.getLayout();
cl.show(displayCards, "NUMERIC");
}
});
dialButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
display = DisplayType.DIAL;
CardLayout cl = (CardLayout) displayCards.getLayout();
cl.show(displayCards, "DIAL");
}
});
basicPane.add(speedPanel);
/*
* Pane for profiling loco speed curve
*/
JPanel profilePane = new JPanel();
profilePane.setLayout(new BorderLayout());
JPanel addrPane = new JPanel();
GridBagLayout gLayout = new GridBagLayout();
GridBagConstraints gConstraints = new GridBagConstraints();
gConstraints.insets = new Insets(3, 3, 3, 3);
Border addrPaneBorder = javax.swing.BorderFactory.createEtchedBorder();
TitledBorder addrPaneTitle = javax.swing.BorderFactory.createTitledBorder(addrPaneBorder, rb.getString("LocoSelection"));
addrPane.setLayout(gLayout);
addrPane.setBorder(addrPaneTitle);
setButton = new JButton(rb.getString("ButtonSet"));
setButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeOfAddress();
}
});
addrSelector.setAddress(null);
rosterBox = new GlobalRosterEntryComboBox();
rosterBox.setNonSelectedItem(rb.getString("NoLocoSelected"));
rosterBox.setToolTipText(rb.getString("TTSelectLocoFromRoster"));
/*
Using an ActionListener didn't select a loco from the ComboBox properly
so changed it to a PropertyChangeListener approach modeled on the code
in CombinedLocoSelPane class, layoutRosterSelection method, which is known to work.
Not sure why the ActionListener didn't work properly, but this fixes the bug
*/
rosterBox.addPropertyChangeListener(RosterEntrySelector.SELECTED_ROSTER_ENTRIES, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {
if (!disableRosterBoxActions) {
//Have roster box actions been disabled?
rosterItemSelected();
}
}
});
readAddressButton.setToolTipText(rb.getString("ReadLoco"));
addrPane.add(addrSelector.getCombinedJPanel(), gConstraints);
addrPane.add(new JLabel(" "), gConstraints);
addrPane.add(setButton, gConstraints);
addrPane.add(new JLabel(" "), gConstraints);
addrPane.add(rosterBox, gConstraints);
addrPane.add(new JLabel(" "), gConstraints);
addrPane.add(readAddressButton, gConstraints);
if (((dccServices & PROG) != PROG) || (mainButton.isSelected())) {
// No programming facility so user must enter address
addrSelector.setEnabled(false);
readAddressButton.setEnabled(false);
} else {
addrSelector.setEnabled(true);
readAddressButton.setEnabled(true);
}
// Listen to read button
readAddressButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
readAddress();
}
});
profilePane.add(addrPane, BorderLayout.NORTH);
// pane to hold the graph
// 28 step plus step 0
spFwd = new DccSpeedProfile(29);
// 28 step plus step 0
spRev = new DccSpeedProfile(29);
// 28 step plus step 0
spRef = new DccSpeedProfile(29);
profileGraphPane = new GraphPane(spFwd, spRev, spRef);
profileGraphPane.setPreferredSize(new Dimension(600, 300));
profileGraphPane.setXLabel(rb.getString("SpeedStep"));
profileGraphPane.setUnitsMph();
profilePane.add(profileGraphPane, BorderLayout.CENTER);
// pane to hold the buttons
JPanel profileButtonPane = new JPanel();
profileButtonPane.setLayout(new FlowLayout());
profileButtonPane.add(trackPowerButton);
trackPowerButton.setToolTipText(rb.getString("TTPower"));
profileButtonPane.add(startProfileButton);
startProfileButton.setToolTipText(rb.getString("TTStartProfile"));
profileButtonPane.add(stopProfileButton);
stopProfileButton.setToolTipText(rb.getString("TTStopProfile"));
profileButtonPane.add(exportProfileButton);
exportProfileButton.setToolTipText(rb.getString("TTSaveProfile"));
profileButtonPane.add(printProfileButton);
printProfileButton.setToolTipText(rb.getString("TTPrintProfile"));
profileButtonPane.add(resetGraphButton);
resetGraphButton.setToolTipText(rb.getString("TTResetGraph"));
profileButtonPane.add(loadProfileButton);
loadProfileButton.setToolTipText(rb.getString("TTLoadProfile"));
// pane to hold the title
JPanel profileTitlePane = new JPanel();
profileTitlePane.setLayout(new BoxLayout(profileTitlePane, BoxLayout.X_AXIS));
// JTextArea profileTitle = new JTextArea("Title: ");
// profileTitlePane.add(profileTitle);
printTitleText.setToolTipText(rb.getString("TTPrintTitle"));
printTitleText.setText("Bachrus MTS-DCC profile for loco <unknown>");
profileTitlePane.add(printTitleText);
// pane to wrap buttons and title
JPanel profileSouthPane = new JPanel();
profileSouthPane.setLayout(new BoxLayout(profileSouthPane, BoxLayout.Y_AXIS));
profileSouthPane.add(profileButtonPane);
profileSouthPane.add(profileTitlePane);
// Listen to track Power button
trackPowerButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
trackPower();
}
});
// Listen to start button
startProfileButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
startProfile();
}
});
// Listen to stop button
stopProfileButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
stopProfile();
}
});
// Listen to grid button
toggleGridButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
profileGraphPane.showGrid(toggleGridButton.isSelected());
profileGraphPane.repaint();
}
});
// Listen to export button
exportProfileButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (dirFwdButton.isSelected() && dirRevButton.isSelected()) {
DccSpeedProfile[] sp = { spFwd, spRev };
DccSpeedProfile.export(sp, profileAddress, profileGraphPane.getUnits());
} else if (dirFwdButton.isSelected()) {
DccSpeedProfile.export(spFwd, profileAddress, "fwd", profileGraphPane.getUnits());
} else if (dirRevButton.isSelected()) {
DccSpeedProfile.export(spRev, profileAddress, "rev", profileGraphPane.getUnits());
}
}
});
// Listen to print button
printProfileButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
profileGraphPane.printProfile(printTitleText.getText());
}
});
// Listen to reset graph button
resetGraphButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
spFwd.clear();
spRev.clear();
spRef.clear();
speedoDialDisplay.reset();
profileGraphPane.repaint();
}
});
// Listen to Load Reference button
loadProfileButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
spRef.clear();
int response = spRef.importDccProfile(profileGraphPane.getUnits());
if (response == -1) {
statusLabel.setText(rb.getString("StatFileError"));
} else {
statusLabel.setText(rb.getString("StatFileSuccess"));
}
profileGraphPane.repaint();
}
});
profilePane.add(profileSouthPane, BorderLayout.SOUTH);
// Pane to hold controls
JPanel profileControlPane = new JPanel();
profileControlPane.setLayout(new BoxLayout(profileControlPane, BoxLayout.Y_AXIS));
dirFwdButton.setSelected(true);
dirFwdButton.setToolTipText(rb.getString("TTMeasFwd"));
dirRevButton.setToolTipText(rb.getString("TTMeasRev"));
dirFwdButton.setForeground(Color.RED);
dirRevButton.setForeground(Color.BLUE);
profileControlPane.add(dirFwdButton);
profileControlPane.add(dirRevButton);
toggleGridButton.setSelected(true);
profileControlPane.add(toggleGridButton);
profileGraphPane.showGrid(toggleGridButton.isSelected());
profilePane.add(profileControlPane, BorderLayout.EAST);
/*
* Create the tabbed pane and add the panes
*/
// JTabbedPane tabbedPane = new JTabbedPane();
JPanel tabbedPane = new JPanel();
tabbedPane.setLayout(new BoxLayout(tabbedPane, BoxLayout.X_AXIS));
// make basic panel
// tabbedPane.addTab(rb.getString("Setup"), null, basicPane, "Basic Speedo Operation");
tabbedPane.add(basicPane);
if (((dccServices & THROTTLE) == THROTTLE) || ((dccServices & COMMAND) == COMMAND)) {
// tabbedPane.addTab(rb.getString("Profile"), null, profilePane, "Profile Loco");
tabbedPane.add(profilePane);
}
// connect to TrafficController
tc = _memo.getTrafficController();
tc.addSpeedoListener(this);
// add help menu to window
addHelpMenu("package.jmri.jmrix.bachrus.SpeedoConsoleFrame", true);
// Create a wrapper with a status line and add the main content
JPanel statusWrapper = new JPanel();
statusWrapper.setLayout(new BorderLayout());
JPanel statusPanel = new JPanel();
statusPanel.setLayout(new BorderLayout());
statusPanel.add(statusLabel, BorderLayout.WEST);
statusPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
statusWrapper.add(tabbedPane, BorderLayout.CENTER);
statusWrapper.add(statusPanel, BorderLayout.SOUTH);
getContentPane().add(statusWrapper);
// pack for display
pack();
speedoDialDisplay.scaleFace();
}
use of jmri.jmrit.roster.swing.GlobalRosterEntryComboBox in project JMRI by JMRI.
the class NewLocoSelPane method init.
public void init() {
JLabel last;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(last = new JLabel(java.util.ResourceBundle.getBundle("jmri/jmrit/symbolicprog/SymbolicProgBundle").getString("NewLocoProgTrack")));
last.setBorder(new EmptyBorder(6, 0, 6, 0));
add(new JLabel(java.util.ResourceBundle.getBundle("jmri/jmrit/symbolicprog/SymbolicProgBundle").getString("CopySettings")));
locoBox = new GlobalRosterEntryComboBox();
locoBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("Locomotive selected changed");
}
matchDecoderToLoco();
}
});
add(locoBox);
JPanel pane1a = new JPanel();
pane1a.setLayout(new BoxLayout(pane1a, BoxLayout.X_AXIS));
pane1a.add(new JLabel(java.util.ResourceBundle.getBundle("jmri/jmrit/symbolicprog/SymbolicProgBundle").getString("LabelDecoderInstalled")));
JButton iddecoder = new JButton(java.util.ResourceBundle.getBundle("jmri/jmrit/symbolicprog/SymbolicProgBundle").getString("IdentifyDecoder"));
iddecoder.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("identify decoder pressed");
}
startIdentify();
}
});
pane1a.add(iddecoder);
pane1a.setAlignmentX(JLabel.LEFT_ALIGNMENT);
add(pane1a);
decoderBox = DecoderIndexFile.instance().matchingComboBox(null, null, null, null, null, null);
add(decoderBox);
// Open programmer button
JButton go1 = new JButton(java.util.ResourceBundle.getBundle("jmri/jmrit/symbolicprog/SymbolicProgBundle").getString("IdentifyDecoder"));
go1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("Open programmer pressed");
}
openButton();
}
});
add(go1);
setBorder(new EmptyBorder(6, 6, 6, 6));
}
use of jmri.jmrit.roster.swing.GlobalRosterEntryComboBox in project JMRI by JMRI.
the class EcosLocoTableAction method createModel.
@Override
protected void createModel() {
m = new BeanTableDataModel() {
//We have to set a manager first off, but this gets replaced.
@Override
protected EcosLocoAddressManager getManager() {
return locoManager;
}
protected String getRosterAttribute() {
return rosterAttribute;
}
@Override
public String getValue(String s) {
return "Set";
}
@Override
protected String getMasterClassName() {
return getClassName();
}
@Override
public void clickOn(jmri.NamedBean t) {
}
@Override
protected synchronized void updateNameList() {
// first, remove listeners from the individual objects
if (ecosObjectIdList != null) {
for (int i = 0; i < ecosObjectIdList.size(); i++) {
// if object has been deleted, it's not here; ignore it
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(i));
if (b != null) {
b.removePropertyChangeListener(this);
}
}
}
ecosObjectIdList = getManager().getEcosObjectList();
// and add them back in
for (int i = 0; i < ecosObjectIdList.size(); i++) {
getByEcosObject(ecosObjectIdList.get(i)).addPropertyChangeListener(this);
}
}
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
updateNameList();
if (e.getPropertyName().equals("length")) {
// a new jmri.jmrix.ecos.EcosLocoAddressManager is available in the manager
updateNameList();
fireTableDataChanged();
} else if (matchPropertyName(e)) {
// a value changed. Find it, to avoid complete redraw
String object = ((jmri.jmrix.ecos.EcosLocoAddress) e.getSource()).getEcosObject();
// since we can add columns, the entire row is marked as updated
int row = ecosObjectIdList.indexOf(object);
fireTableRowsUpdated(row, row);
}
}
@Override
public int getColumnCount() {
return STOP + 1;
}
@Override
public void setValueAt(Object value, int row, int col) {
if (col == COMMENTCOL) {
RosterEntry re;
String ecosObjectNo = ecosObjectIdList.get(row);
if (value == null) {
return;
} else if (value instanceof RosterEntry) {
re = (RosterEntry) value;
if ((re.getAttribute(getRosterAttribute()) != null && !re.getAttribute(getRosterAttribute()).equals(""))) {
JOptionPane.showMessageDialog(f, ecosObjectNo + " This roster entry already has an ECOS loco assigned to it ");
log.error(ecosObjectNo + " This roster entry already has an ECOS loco assigned to it ");
return;
}
String oldRoster = getByEcosObject(ecosObjectNo).getRosterId();
RosterEntry oldre;
if (oldRoster != null) {
oldre = Roster.getDefault().getEntryForId(oldRoster);
if (oldre != null) {
oldre.deleteAttribute(getRosterAttribute());
}
}
re.putAttribute(getRosterAttribute(), ecosObjectNo);
getByEcosObject(ecosObjectNo).setRosterId(re.getId());
re.updateFile();
} else if (value instanceof String) {
List<RosterEntry> r = Roster.getDefault().getEntriesWithAttributeKeyValue(getRosterAttribute(), ecosObjectNo);
if (r.isEmpty()) {
r.get(0).deleteAttribute(getRosterAttribute());
getByEcosObject(ecosObjectNo).setRosterId(null);
r.get(0).updateFile();
}
}
Roster.getDefault().writeRoster();
} else if (col == ADDTOROSTERCOL) {
addToRoster(row, col);
} else if (col == STOP) {
stopLoco(row, col);
} else if (col == DELETECOL) {
// button fired, delete Bean
deleteLoco(row, col);
} else if (col == USERNAMECOL) {
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(row));
EcosMessage m = new EcosMessage("request(" + b.getEcosObject() + ", control, force)");
adaptermemo.getTrafficController().sendEcosMessage(m, null);
m = new EcosMessage("set(" + b.getEcosObject() + ", name[\"" + (String) value + "\"])");
adaptermemo.getTrafficController().sendEcosMessage(m, null);
m = new EcosMessage("release(" + b.getEcosObject() + ", control)");
adaptermemo.getTrafficController().sendEcosMessage(m, null);
}
}
/**
* {@inheritDoc }
*/
@Override
@Deprecated
public JTable makeJTable(TableSorter sorter) {
return this.makeJTable((TableModel) sorter);
}
@Override
public JTable makeJTable(@Nonnull String name, @Nonnull TableModel model, @Nullable RowSorter sorter) {
JTable table = this.makeJTable(model);
table.setName(name);
table.setRowSorter(sorter);
return table;
}
private JTable makeJTable(@Nonnull TableModel model) {
JTable table = new JTable(model) {
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (column == COMMENTCOL) {
return getRenderer(row);
} else {
return super.getCellRenderer(row, column);
}
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (column == COMMENTCOL) {
return getEditor(row);
} else {
return super.getCellEditor(row, column);
}
}
TableCellRenderer getRenderer(int row) {
TableCellRenderer retval = rendererMap.get(ecosObjectIdList.get(row));
if (retval == null) {
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(row));
RosterEntry re = null;
if (b != null) {
re = Roster.getDefault().getEntryForId(b.getRosterId());
}
retval = new RosterBoxRenderer(re);
rendererMap.put(ecosObjectIdList.get(row), retval);
}
return retval;
}
Hashtable<Object, TableCellRenderer> rendererMap = new Hashtable<>();
TableCellEditor getEditor(int row) {
TableCellEditor retval = editorMap.get(ecosObjectIdList.get(row));
if (retval == null) {
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(row));
RosterEntry re = null;
if (b != null) {
re = Roster.getDefault().getEntryForId(b.getRosterId());
}
GlobalRosterEntryComboBox cb = new GlobalRosterEntryComboBox();
cb.setNonSelectedItem(" ");
if (re == null) {
cb.setSelectedIndex(0);
} else {
cb.setSelectedItem(re);
}
// create a new one with right aspects
retval = new RosterComboBoxEditor(cb);
editorMap.put(ecosObjectIdList.get(row), retval);
}
return retval;
}
Hashtable<Object, TableCellEditor> editorMap = new Hashtable<>();
};
table.getTableHeader().setReorderingAllowed(true);
table.setColumnModel(new XTableColumnModel());
table.createDefaultColumnsFromModel();
addMouseListenerToHeader(table);
return table;
}
/**
* Is this property event announcing a change this table should
* display?
* <P>
* Note that events will come both from the
* jmri.jmrix.ecos.EcosLocoAddressManagers and also from the manager
*/
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
if (!showLocoMonitor && (e.getPropertyName().equals("Speed") || e.getPropertyName().equals("Direction"))) {
return false;
}
return true;
}
@Override
public String getColumnName(int col) {
switch(col) {
case SYSNAMECOL:
return "ECoS Object Id";
case USERNAMECOL:
return "ECoS Descritpion";
case VALUECOL:
return "ECoS Address";
case COMMENTCOL:
return "JMRI Roster Id";
case DELETECOL:
return "Delete";
case PROTOCOL:
return "ECOS Protocol";
case ADDTOROSTERCOL:
return "Add to Roster";
case SPEEDDIR:
return "Speed Direction";
case STOP:
return "Stop";
default:
return "unknown";
}
}
@Override
public Class<?> getColumnClass(int col) {
switch(col) {
case SYSNAMECOL:
case USERNAMECOL:
case VALUECOL:
case PROTOCOL:
case SPEEDDIR:
return String.class;
case ADDTOROSTERCOL:
case DELETECOL:
case STOP:
return JButton.class;
case COMMENTCOL:
return JComboBox.class;
default:
return null;
}
}
@Override
public boolean isCellEditable(int row, int col) {
switch(col) {
case COMMENTCOL:
return true;
case ADDTOROSTERCOL:
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(row));
if (b.getRosterId() == null || b.getRosterId().equals("")) {
return true;
} else {
return false;
}
case USERNAMECOL:
case DELETECOL:
case STOP:
return true;
default:
return false;
}
}
@Override
public int getPreferredWidth(int col) {
switch(col) {
case SYSNAMECOL:
return new JTextField(5).getPreferredSize().width;
case COMMENTCOL:
return new JTextField(20).getPreferredSize().width;
case USERNAMECOL:
return new JTextField(20).getPreferredSize().width;
case // not actually used due to the configureTable, setColumnToHoldButton, configureButton
ADDTOROSTERCOL:
return new JTextField(12).getPreferredSize().width;
case // not actually used due to the configureTable, setColumnToHoldButton, configureButton
STOP:
return new JTextField(6).getPreferredSize().width;
case VALUECOL:
return new JTextField(5).getPreferredSize().width;
case SPEEDDIR:
return new JTextField(10).getPreferredSize().width;
case PROTOCOL:
return new JTextField(5).getPreferredSize().width;
default:
//log.warn("Unexpected column in getPreferredWidth: "+col);
return super.getPreferredWidth(col);
}
}
@Override
public void configureTable(JTable tbl) {
table = tbl;
setColumnToHoldButton(table, ADDTOROSTERCOL, new JButton("Add to Roster"));
setColumnToHoldButton(table, STOP, stopButton());
super.configureTable(table);
XTableColumnModel columnModel = (XTableColumnModel) table.getColumnModel();
TableColumn column = columnModel.getColumnByModelIndex(SPEEDDIR);
columnModel.setColumnVisible(column, false);
column = columnModel.getColumnByModelIndex(STOP);
columnModel.setColumnVisible(column, false);
}
@Override
public NamedBean getBySystemName(String name) {
return null;
}
@Override
public NamedBean getByUserName(String name) {
return null;
}
@Override
public synchronized void dispose() {
showLocoMonitor = false;
getManager().removePropertyChangeListener(this);
if (ecosObjectIdList != null) {
for (int i = 0; i < ecosObjectIdList.size(); i++) {
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(i));
if (b != null) {
b.removePropertyChangeListener(this);
}
}
}
}
protected void deleteLoco(final int row, int col) {
if (row >= ecosObjectIdList.size()) {
log.debug("row is greater than list size");
return;
}
jmri.jmrix.ecos.EcosLocoAddress b = getByEcosObject(ecosObjectIdList.get(row));
final JDialog dialog = new JDialog();
dialog.setTitle("Remove Loco From ECOS");
dialog.setLocation(300, 200);
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel question = new JLabel("Are you sure that you want to remove loco " + b.getEcosDescription() + " from the ECOS ?");
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("No");
JPanel button = new JPanel();
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.add(yesButton);
button.add(noButton);
container.add(button);
noButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
removeObjectFromEcos.removeObjectFromEcos(ecosObjectIdList.get(row), adaptermemo.getTrafficController());
dialog.dispose();
}
});
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
@Override
public int getRowCount() {
return ecosObjectIdList.size();
}
@Override
public Object getValueAt(int row, int col) {
if (row >= ecosObjectIdList.size()) {
log.debug("row is greater than list size");
return null;
}
jmri.jmrix.ecos.EcosLocoAddress b;
switch(col) {
case SYSNAMECOL:
return ecosObjectIdList.get(row);
case // return user name
USERNAMECOL:
// sometimes, the TableSorter invokes this on rows that no longer exist, so we check
b = getByEcosObject(ecosObjectIdList.get(row));
return (b != null) ? b.getEcosDescription() : null;
case //
VALUECOL:
b = getByEcosObject(ecosObjectIdList.get(row));
return (b != null) ? b.getNumber() : null;
case COMMENTCOL:
b = getByEcosObject(ecosObjectIdList.get(row));
RosterEntry re = null;
if (b != null) {
re = Roster.getDefault().getEntryForId(b.getRosterId());
}
GlobalRosterEntryComboBox cb = (GlobalRosterEntryComboBox) table.getCellRenderer(row, col);
if (re == null) {
cb.setSelectedIndex(0);
} else {
cb.setSelectedItem(re);
}
return re;
case PROTOCOL:
b = getByEcosObject(ecosObjectIdList.get(row));
return (b != null) ? b.getECOSProtocol() : null;
case //
ADDTOROSTERCOL:
b = getByEcosObject(ecosObjectIdList.get(row));
if (b.getRosterId() == null || b.getRosterId().equals("")) {
return "Add To Roster";
} else {
return " ";
}
case STOP:
return "Stop";
case SPEEDDIR:
b = getByEcosObject(ecosObjectIdList.get(row));
return (b != null) ? (b.getDirectionAsString() + " : " + b.getSpeed()) : null;
case //
DELETECOL:
return Bundle.getMessage("ButtonDelete");
default:
//log.error("internal state inconsistent with table requst for "+row+" "+col);
return null;
}
}
@Override
protected String getBeanType() {
return "Ecos Loco";
}
@Override
protected void showPopup(MouseEvent e) {
}
};
}
Aggregations