use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class LogixTableAction method createSinglePanelPickList.
/**
* Create a single panel picklist JFrame for choosing action and variable names.
* <p>
* Called from {@link #actionItemChanged} and {@link #variableTypeChanged}
* @since 4.7.3
* @param itemType The selected variable or action type
* @param isVariable True if called by variableTypeChanged
*/
void createSinglePanelPickList(int itemType, boolean isVariable) {
if (_pickListener != null) {
int saveType = _pickListener.getItemType();
if (saveType != itemType) {
// The type has changed, need to start over
closeSinglePanelPickList();
} else {
// The pick list has already been created
return;
}
}
switch(itemType) {
case // 1
Conditional.ITEM_TYPE_SENSOR:
_pickSingle = new PickSinglePanel(PickListModel.sensorPickModelInstance());
break;
case // 2
Conditional.ITEM_TYPE_TURNOUT:
_pickSingle = new PickSinglePanel(PickListModel.turnoutPickModelInstance());
break;
case // 3
Conditional.ITEM_TYPE_LIGHT:
_pickSingle = new PickSinglePanel(PickListModel.lightPickModelInstance());
break;
case // 4
Conditional.ITEM_TYPE_SIGNALHEAD:
_pickSingle = new PickSinglePanel(PickListModel.signalHeadPickModelInstance());
break;
case // 5
Conditional.ITEM_TYPE_SIGNALMAST:
_pickSingle = new PickSinglePanel(PickListModel.signalMastPickModelInstance());
break;
case // 6
Conditional.ITEM_TYPE_MEMORY:
_pickSingle = new PickSinglePanel(PickListModel.memoryPickModelInstance());
break;
case // 8
Conditional.ITEM_TYPE_WARRANT:
_pickSingle = new PickSinglePanel(PickListModel.warrantPickModelInstance());
break;
case // 10
Conditional.ITEM_TYPE_OBLOCK:
_pickSingle = new PickSinglePanel(PickListModel.oBlockPickModelInstance());
break;
case // 11
Conditional.ITEM_TYPE_ENTRYEXIT:
_pickSingle = new PickSinglePanel(PickListModel.entryExitPickModelInstance());
break;
// break;
default:
// Skip any other items.
return;
}
// Create the JFrame
_pickSingleFrame = new JmriJFrame(rbx.getString("SinglePickFrame"));
_pickSingleFrame.setContentPane(_pickSingle);
_pickSingleFrame.pack();
_pickSingleFrame.setVisible(true);
_pickSingleFrame.toFront();
// Set the table selection listener
_pickListener = new PickSingleListener();
_pickTable = _pickSingle.getTable();
_pickTable.getSelectionModel().addListSelectionListener(_pickListener);
// Save the current item type
_pickListener.setItemType(itemType);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class SignalGroupTableAction method addPressed.
/**
* Respond to click on Add... button below Signal Group Table.
* <p>
* Create JPanel with options for configuration.
* @param e Event from origin; null when called from Edit button in Signal Group Table row
*/
@Override
protected void addPressed(ActionEvent e) {
if (inEditMode) {
log.debug("Can not open another editing session for Signal Groups.");
// add user warning that a 2nd session not allowed (cf. Logix)
// Already editing a Signal Group, ask for completion of that edit first
String workingTitle = _systemName.getText();
if (workingTitle.isEmpty() || workingTitle == null) {
workingTitle = Bundle.getMessage("NONE");
_systemName.setText(workingTitle);
}
javax.swing.JOptionPane.showMessageDialog(addFrame, Bundle.getMessage("SigGroupEditBusyWarning", workingTitle), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
inEditMode = true;
_mastAspectsList = null;
jmri.SignalHeadManager shm = InstanceManager.getDefault(jmri.SignalHeadManager.class);
List<String> systemNameList = shm.getSystemNameList();
_signalHeadsList = new ArrayList<SignalGroupSignalHead>(systemNameList.size());
// create list of all available Single Output Signal Heads to choose from
Iterator<String> iter = systemNameList.iterator();
// int i = 1; // for debug of iter next
while (iter.hasNext()) {
String systemName = iter.next();
SignalHead sh = shm.getBySystemName(systemName);
// debug using i & sysnamelist.size
if (sh != null) {
if (sh.getClass().getName().contains("SingleTurnoutSignalHead")) {
String userName = sh.getUserName();
// add every single output signal head item to the list
_signalHeadsList.add(new SignalGroupSignalHead(systemName, userName));
} else {
log.debug("Signal Head " + systemName + " is not a Single Output Controlled Signal Head");
}
} else {
// this is not an error and the value of systemName mentioned is actually from the last head that was indeed loaded
log.error("Failed to get signal head {} (SGTA)", systemName);
}
}
// Set up Add/Edit Signal Group window
if (addFrame == null) {
// if it's not yet present, create addFrame
mainSignalComboBox = new JmriBeanComboBox(jmri.InstanceManager.getDefault(jmri.SignalMastManager.class), null, JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
// causes NPE when user selects that 1st line, so do not respond to result null
mainSignalComboBox.setFirstItemBlank(true);
addFrame = new JmriJFrame(Bundle.getMessage("AddSignalGroup"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.SignalGroupAddEdit", true);
addFrame.setLocation(100, 30);
addFrame.getContentPane().setLayout(new BoxLayout(addFrame.getContentPane(), BoxLayout.Y_AXIS));
Container contentPane = addFrame.getContentPane();
// add system name
JPanel ps = new JPanel();
ps.setLayout(new FlowLayout());
ps.add(nameLabel);
ps.add(_systemName);
_systemName.setToolTipText(Bundle.getMessage("SignalGroupSysNameTooltip"));
ps.add(fixedSystemName);
fixedSystemName.setVisible(false);
contentPane.add(ps);
// add user name
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(userLabel);
p.add(_userName);
_userName.setToolTipText(Bundle.getMessage("SignalGroupUserNameTooltip"));
contentPane.add(p);
// add Signal Masts/Heads Display Choice
JPanel py = new JPanel();
py.add(new JLabel(Bundle.getMessage("Show")));
selGroup = new ButtonGroup();
allButton = new JRadioButton(Bundle.getMessage("All"), true);
selGroup.add(allButton);
py.add(allButton);
allButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Setup for display of all Signal Masts & SingleTO Heads, if needed
if (!showAll) {
showAll = true;
_SignalGroupHeadModel.fireTableDataChanged();
_AspectModel.fireTableDataChanged();
}
}
});
includedButton = new JRadioButton(Bundle.getMessage("Included"), false);
selGroup.add(includedButton);
py.add(includedButton);
includedButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Setup for display of included Turnouts only, if needed
if (showAll) {
showAll = false;
initializeIncludedList();
_SignalGroupHeadModel.fireTableDataChanged();
_AspectModel.fireTableDataChanged();
}
}
});
py.add(new JLabel(" " + Bundle.getMessage("_and_", Bundle.getMessage("LabelAspects"), Bundle.getMessage("SignalHeads"))));
contentPane.add(py);
// add main signal mast table
JPanel p3 = new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
JPanel p31 = new JPanel();
p31.add(new JLabel(Bundle.getMessage("EnterMastAttached", Bundle.getMessage("BeanNameSignalMast"))));
p3.add(p31);
JPanel p32 = new JPanel();
p32.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanNameSignalMast"))));
// comboBox to pick a main Signal Mast
p32.add(mainSignalComboBox);
p3.add(p32);
p3xsi = new JPanel();
JPanel p3xsiSpace = new JPanel();
p3xsiSpace.setLayout(new BoxLayout(p3xsiSpace, BoxLayout.Y_AXIS));
p3xsiSpace.add(new JLabel(" "));
p3xsi.add(p3xsiSpace);
JPanel p31si = new JPanel();
p31si.setLayout(new BoxLayout(p31si, BoxLayout.Y_AXIS));
p31si.add(new JLabel(Bundle.getMessage("SelectAppearanceTrigger")));
p3xsi.add(p31si);
_AspectModel = new SignalMastAspectModel();
JTable SignalMastAspectTable = new JTable(_AspectModel);
TableRowSorter<SignalMastAspectModel> smaSorter = new TableRowSorter<>(_AspectModel);
smaSorter.setComparator(SignalMastAspectModel.ASPECT_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(smaSorter, SignalMastAspectModel.ASPECT_COLUMN, SortOrder.ASCENDING);
SignalMastAspectTable.setRowSorter(smaSorter);
SignalMastAspectTable.setRowSelectionAllowed(false);
SignalMastAspectTable.setPreferredScrollableViewportSize(new java.awt.Dimension(200, 80));
TableColumnModel SignalMastAspectColumnModel = SignalMastAspectTable.getColumnModel();
TableColumn includeColumnA = SignalMastAspectColumnModel.getColumn(SignalGroupTableAction.SignalMastAspectModel.INCLUDE_COLUMN);
includeColumnA.setResizable(false);
includeColumnA.setMinWidth(30);
includeColumnA.setMaxWidth(60);
@SuppressWarnings("static-access") TableColumn sNameColumnA = SignalMastAspectColumnModel.getColumn(_AspectModel.ASPECT_COLUMN);
sNameColumnA.setResizable(true);
sNameColumnA.setMinWidth(75);
sNameColumnA.setMaxWidth(140);
_SignalAppearanceScrollPane = new JScrollPane(SignalMastAspectTable);
p3xsi.add(_SignalAppearanceScrollPane, BorderLayout.CENTER);
p3.add(p3xsi);
p3xsi.setVisible(true);
// respond to comboBox selection
mainSignalComboBox.addActionListener(new ActionListener() {
//public void focusGained(FocusEvent e) {
//}
@Override
public void actionPerformed(ActionEvent event) {
if (mainSignalComboBox.getSelectedBean() == null) {
// ie. empty first row was selected or set
log.debug("Empty line in mainSignal comboBox");
//setValidSignalMastAspects(); // clears the Aspect table
} else {
if (curSignalGroup == null || mainSignalComboBox.getSelectedBean() != curSignalGroup.getSignalMast()) {
log.debug("comboBox closed, choice: {}", mainSignalComboBox.getSelectedItem());
// refresh table with signal mast aspects
setValidSignalMastAspects();
} else {
log.debug("Mast {} picked in mainSignal comboBox", mainSignalComboBox.getSelectedItem());
}
}
}
});
// complete this panel
Border p3Border = BorderFactory.createEtchedBorder();
p3.setBorder(p3Border);
contentPane.add(p3);
p2xsi = new JPanel();
JPanel p2xsiSpace = new JPanel();
p2xsiSpace.setLayout(new BoxLayout(p2xsiSpace, BoxLayout.Y_AXIS));
p2xsiSpace.add(new JLabel("XXX"));
p2xsi.add(p2xsiSpace);
JPanel p21si = new JPanel();
p21si.setLayout(new BoxLayout(p21si, BoxLayout.Y_AXIS));
p21si.add(new JLabel(Bundle.getMessage("SelectInGroup", Bundle.getMessage("SignalHeads"))));
p2xsi.add(p21si);
_SignalGroupHeadModel = new SignalGroupSignalHeadModel();
JTable SignalGroupHeadTable = new JTable(_SignalGroupHeadModel);
TableRowSorter<SignalGroupSignalHeadModel> sgsSorter = new TableRowSorter<>(_SignalGroupHeadModel);
sgsSorter.setComparator(SignalGroupSignalHeadModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(sgsSorter, SignalGroupSignalHeadModel.SNAME_COLUMN, SortOrder.ASCENDING);
SignalGroupHeadTable.setRowSorter(sgsSorter);
SignalGroupHeadTable.setRowSelectionAllowed(false);
SignalGroupHeadTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 160));
TableColumnModel SignalGroupSignalColumnModel = SignalGroupHeadTable.getColumnModel();
TableColumn includeColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.INCLUDE_COLUMN);
includeColumnSi.setResizable(false);
includeColumnSi.setMinWidth(30);
includeColumnSi.setMaxWidth(60);
TableColumn sNameColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.SNAME_COLUMN);
sNameColumnSi.setResizable(true);
sNameColumnSi.setMinWidth(75);
sNameColumnSi.setMaxWidth(95);
TableColumn uNameColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.UNAME_COLUMN);
uNameColumnSi.setResizable(true);
uNameColumnSi.setMinWidth(100);
uNameColumnSi.setMaxWidth(260);
TableColumn stateOnColumnSi = SignalGroupSignalColumnModel.getColumn(// a 6 column table
SignalGroupSignalHeadModel.STATE_ON_COLUMN);
stateOnColumnSi.setResizable(false);
// was 50
stateOnColumnSi.setMinWidth(Bundle.getMessage("SignalHeadStateFlashingYellow").length());
stateOnColumnSi.setMaxWidth(100);
TableColumn stateOffColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.STATE_OFF_COLUMN);
stateOffColumnSi.setResizable(false);
stateOffColumnSi.setMinWidth(50);
stateOffColumnSi.setMaxWidth(100);
TableColumn editColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.EDIT_COLUMN);
editColumnSi.setResizable(false);
// was 50
editColumnSi.setMinWidth(Bundle.getMessage("ButtonEdit").length());
editColumnSi.setMaxWidth(100);
JButton editButton = new JButton(Bundle.getMessage("ButtonEdit"));
setColumnToHoldButton(SignalGroupHeadTable, SignalGroupSignalHeadModel.EDIT_COLUMN, editButton);
_SignalGroupHeadScrollPane = new JScrollPane(SignalGroupHeadTable);
p2xsi.add(_SignalGroupHeadScrollPane, BorderLayout.CENTER);
// add tooltip to explain which head types are shown
p2xsi.setToolTipText(Bundle.getMessage("SignalGroupHeadTableTooltip"));
contentPane.add(p2xsi);
p2xsi.setVisible(true);
// add notes panel, may be empty (a dot on the screen)
JPanel pa = new JPanel();
pa.setLayout(new BoxLayout(pa, BoxLayout.Y_AXIS));
Border pBorder = BorderFactory.createEtchedBorder();
pa.setBorder(pBorder);
contentPane.add(pa);
// buttons at bottom of panel
JPanel pb = new JPanel();
pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
pb.add(cancelButton);
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelPressed(e);
}
});
cancelButton.setVisible(true);
pb.add(deleteButton);
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deletePressed(e);
}
});
deleteButton.setToolTipText(Bundle.getMessage("DeleteSignalGroupInSystem"));
// [Update] Signal Group button in Add/Edit SignalGroup pane
pb.add(updateButton);
updateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updatePressed(e, false, true);
}
});
updateButton.setToolTipText(Bundle.getMessage("TooltipUpdate"));
updateButton.setVisible(true);
contentPane.add(pb);
// pack and release space
addFrame.pack();
p2xsiSpace.setVisible(false);
} else // set listener for window closing
{
mainSignalComboBox.setSelectedBean(null);
// reset title for new group
addFrame.setTitle(Bundle.getMessage("AddSignalGroup"));
}
addFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
// remind to save, if Signal Group was created or edited
if (SignalGroupDirty) {
InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ReminderTitle"), Bundle.getMessage("ReminderSaveString", Bundle.getMessage("SignalGroup")), "beantable.SignalGroupTableAction", // NOI18N
"remindSignalGroup");
SignalGroupDirty = false;
}
// hide first, could be gone by the time of the close event,
if (addFrame != null) {
addFrame.setVisible(false);
}
// so prevent NPE
// release editing soon, as long as NPEs occor in the following methods
inEditMode = false;
finishUpdate();
_SignalGroupHeadModel.dispose();
_AspectModel.dispose();
}
});
// display the pane
addFrame.setVisible(true);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class SensorTableAction method addPressed.
@Override
protected void addPressed(ActionEvent e) {
p = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
if (addFrame == null) {
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddSensor"));
addFrame.addHelpMenu("package.jmri.jmrit.beantable.SensorAddEdit", true);
addFrame.getContentPane().setLayout(new BoxLayout(addFrame.getContentPane(), BoxLayout.Y_AXIS));
ActionListener okListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
okPressed(e);
}
};
ActionListener cancelListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelPressed(e);
}
};
ActionListener rangeListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
canAddRange(e);
}
};
if (jmri.InstanceManager.sensorManagerInstance().getClass().getName().contains("ProxySensorManager")) {
jmri.managers.ProxySensorManager proxy = (jmri.managers.ProxySensorManager) jmri.InstanceManager.sensorManagerInstance();
List<Manager> managerList = proxy.getManagerList();
for (int x = 0; x < managerList.size(); x++) {
String manuName = ConnectionNameFromSystemName.getConnectionName(managerList.get(x).getSystemPrefix());
Boolean addToPrefix = true;
//Simple test not to add a system with a duplicate System prefix
for (int i = 0; i < prefixBox.getItemCount(); i++) {
if ((prefixBox.getItemAt(i)).equals(manuName)) {
addToPrefix = false;
}
}
if (addToPrefix) {
prefixBox.addItem(manuName);
}
}
if (p.getComboBoxLastSelection(systemSelectionCombo) != null) {
prefixBox.setSelectedItem(p.getComboBoxLastSelection(systemSelectionCombo));
}
} else {
prefixBox.addItem(ConnectionNameFromSystemName.getConnectionName(jmri.InstanceManager.sensorManagerInstance().getSystemPrefix()));
}
sysName.setName("sysName");
userName.setName("userName");
prefixBox.setName("prefixBox");
addFrame.add(new AddNewHardwareDevicePanel(sysName, userName, prefixBox, numberToAdd, range, "ButtonOK", okListener, cancelListener, rangeListener));
canAddRange(null);
}
addFrame.pack();
addFrame.setVisible(true);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class PackageTest method testAction.
public void testAction() {
JmriJFrame f = new JmriJFrame("SDI test");
JButton b = new JButton(new ButtonTestAction("new frame", new jmri.util.swing.sdi.JmriJFrameInterface()));
f.add(b);
f.pack();
f.setVisible(true);
// }
// test order isn't guaranteed!
// public void testFrameCreation() {
JFrame f2 = jmri.util.JmriJFrame.getFrame("SDI test");
Assert.assertTrue("found frame", f2 != null);
f2.dispose();
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class DispatcherFrame method allocateExtraSection.
// allocate an extra Section to an Active Train
private void allocateExtraSection(ActionEvent e) {
if (extraFrame == null) {
extraFrame = new JmriJFrame(Bundle.getMessage("ExtraTitle"));
extraFrame.addHelpMenu("package.jmri.jmrit.dispatcher.AllocateExtra", true);
extraPane = extraFrame.getContentPane();
extraPane.setLayout(new BoxLayout(extraFrame.getContentPane(), BoxLayout.Y_AXIS));
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(new JLabel(Bundle.getMessage("ActiveColumnTitle") + ":"));
p1.add(atSelectBox);
atSelectBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleATSelectionChanged(e);
}
});
atSelectBox.setToolTipText(Bundle.getMessage("ATBoxHint"));
extraPane.add(p1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(new JLabel(Bundle.getMessage("ExtraBoxLabel") + ":"));
p2.add(extraBox);
extraBox.setToolTipText(Bundle.getMessage("ExtraBoxHint"));
extraPane.add(p2);
JPanel p7 = new JPanel();
p7.setLayout(new FlowLayout());
JButton cancelButton = null;
p7.add(cancelButton = new JButton(Bundle.getMessage("ButtonCancel")));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelExtraRequested(e);
}
});
cancelButton.setToolTipText(Bundle.getMessage("CancelExtraHint"));
p7.add(new JLabel(" "));
JButton aExtraButton = null;
p7.add(aExtraButton = new JButton(Bundle.getMessage("AllocateButton")));
aExtraButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addExtraRequested(e);
}
});
aExtraButton.setToolTipText(Bundle.getMessage("AllocateButtonHint"));
extraPane.add(p7);
}
initializeATComboBox();
initializeExtraComboBox();
extraFrame.pack();
extraFrame.setVisible(true);
}
Aggregations