use of javax.swing.BoxLayout in project JMRI by JMRI.
the class Maintenance method makeDialog.
/**
* Build and display a dialog box with an OK button and optional 2nd button.
*
* @param component Body of message to put in dialog box
* @param button optional second button to add to pane
* @param parent Frame that asked for this dialog
* @param title text do use as title of the dialog box
*/
static void makeDialog(Component component, Component button, Frame parent, String title) {
JDialog dialog = new JDialog(parent, title, true);
JButton ok = new JButton(Bundle.getMessage("ButtonOK"));
class myListener implements ActionListener {
java.awt.Window _w;
myListener(java.awt.Window w) {
_w = w;
}
@Override
public void actionPerformed(ActionEvent e) {
_w.dispose();
}
}
ok.addActionListener(new myListener(dialog));
ok.setMaximumSize(ok.getPreferredSize());
java.awt.Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
contentPane.add(component, BorderLayout.CENTER);
contentPane.add(Box.createVerticalStrut(5));
contentPane.add(Box.createVerticalGlue());
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(ok);
if (button != null) {
panel.add(Box.createHorizontalStrut(5));
panel.add(button);
}
contentPane.add(panel, BorderLayout.SOUTH);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setLocationRelativeTo(parent);
dialog.pack();
dialog.setVisible(true);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class SignalHeadTableAction method addPressed.
/**
* Provide GUI for adding a new SignalHead.
* <p>
* Because there are multiple options, each of which requires different
* inputs, we directly manipulate which parts of the GUI are displayed when
* the selected type is changed.
*
* @param e name of the event heard
*/
@Override
protected void addPressed(ActionEvent e) {
if (addFrame == null) {
for (Object obj : jmri.InstanceManager.getList(jmri.CommandStation.class)) {
jmri.CommandStation station = (jmri.CommandStation) obj;
prefixBox.addItem(station.getUserName());
}
dccSignalPanel();
to1 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to2 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to3 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to4 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to5 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to6 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
to7 = new BeanSelectCreatePanel(InstanceManager.turnoutManagerInstance(), null);
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddSignalHead"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.SignalAddEdit", true);
addFrame.getContentPane().setLayout(new BorderLayout());
JPanel panelHeader = new JPanel();
panelHeader.setLayout(new BoxLayout(panelHeader, BoxLayout.Y_AXIS));
panelHeader.add(typeBox = new JComboBox<String>(new String[] { acelaAspect, dccSignalDecoder, doubleTurnout, lsDec, mergSignalDriver, quadOutput, singleTurnout, se8c4Aspect, tripleTurnout, tripleOutput, virtualHead }));
//If no DCC Comand station is found remove the DCC Signal Decoder option.
if (prefixBox.getItemCount() == 0) {
typeBox.removeItem(dccSignalDecoder);
}
List<jmri.jmrix.grapevine.GrapevineSystemConnectionMemo> memos = InstanceManager.getList(jmri.jmrix.grapevine.GrapevineSystemConnectionMemo.class);
if (!memos.isEmpty()) {
typeBox.addItem(grapevine);
}
typeBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
typeChanged();
}
});
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(prefixBoxLabel);
p.add(prefixBox);
panelHeader.add(p);
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(systemNameLabel);
p.add(systemName);
systemName.setToolTipText(Bundle.getMessage("SignalHeadSysNameTooltip"));
p.add(dccOffSetAddress);
dccOffSetAddress.setToolTipText(Bundle.getMessage("DccOffsetTooltip"));
panelHeader.add(p);
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(userNameLabel);
p.add(userName);
userName.setToolTipText(Bundle.getMessage("SignalHeadUserNameTooltip"));
panelHeader.add(p);
addFrame.getContentPane().add(panelHeader, BorderLayout.PAGE_START);
JPanel panelCentre = new JPanel();
panelCentre.setLayout(new BoxLayout(panelCentre, BoxLayout.Y_AXIS));
//typeBox.setSelectedIndex(7);
//typeChanged();
// create seven boxes for input information, and put into pane
v1Panel = new JPanel();
v1Panel.setLayout(new FlowLayout());
v1Panel.add(ato1);
v1Panel.add(to1);
v1Panel.add(stateLabel1);
v1Panel.add(s1Box);
s1Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v1Panel.add(msaBox);
v1Panel.setBorder(v1Border);
panelCentre.add(v1Panel);
v2Panel = new JPanel();
v2Panel.setLayout(defaultFlow);
v2Panel.add(to2);
v2Panel.add(stateLabel2);
v2Panel.add(s2Box);
s2Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v2Panel.add(s2aBox);
v2Panel.add(mstBox);
v2Panel.add(dccSignalPanel);
v2Panel.setBorder(v2Border);
panelCentre.add(v2Panel);
v3Panel = new JPanel();
v3Panel.setLayout(defaultFlow);
v3Panel.add(to3);
v3Panel.add(stateLabel3);
v3Panel.add(s3Box);
s3Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v3Panel.add(s3aBox);
v3Panel.setBorder(v3Border);
panelCentre.add(v3Panel);
v4Panel = new JPanel();
v4Panel.setLayout(defaultFlow);
v4Panel.add(to4);
v4Panel.add(stateLabel4);
v4Panel.add(s4Box);
s4Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v4Panel.setBorder(v4Border);
panelCentre.add(v4Panel);
v5Panel = new JPanel();
v5Panel.setLayout(defaultFlow);
v5Panel.add(to5);
v5Panel.add(stateLabel5);
v5Panel.add(s5Box);
s5Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v5Panel.setBorder(v5Border);
panelCentre.add(v5Panel);
v6Panel = new JPanel();
v6Panel.setLayout(defaultFlow);
v6Panel.add(to6);
v6Panel.add(stateLabel6);
v6Panel.add(s6Box);
s6Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v6Panel.setBorder(v6Border);
panelCentre.add(v6Panel);
v7Panel = new JPanel();
v7Panel.setLayout(defaultFlow);
v7Panel.add(to7);
v7Panel.add(stateLabel7);
v7Panel.add(s7Box);
s7Box.setToolTipText(Bundle.getMessage("SignalHeadStateTooltip"));
v7Panel.setBorder(v7Border);
panelCentre.add(v7Panel);
p = new JPanel();
p.setLayout(defaultFlow);
p.add(vtLabel);
p.add(stBox);
panelCentre.add(p);
JScrollPane scrollPane = new JScrollPane(panelCentre);
addFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
// buttons at bottom of panel
JPanel panelBottom = new JPanel();
panelBottom.setLayout(new FlowLayout(FlowLayout.TRAILING));
// Cancel button
JButton cancelNew = new JButton(Bundle.getMessage("ButtonCancel"));
panelBottom.add(cancelNew);
cancelNew.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelNewPressed(e);
}
});
//OK button
JButton ok;
panelBottom.add(ok = new JButton(Bundle.getMessage("ButtonCreate")));
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
okPressed(e);
}
});
addFrame.getContentPane().add(panelBottom, BorderLayout.PAGE_END);
} else {
// clear older entries
systemName.setText("");
userName.setText("");
to1.refresh();
to2.refresh();
to3.refresh();
to4.refresh();
to5.refresh();
to6.refresh();
to7.refresh();
}
// force GUI status consistent. Default set to Double Head type
typeBox.setSelectedIndex(2);
addFrame.pack();
addFrame.setVisible(true);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class CatalogPanel method makePreviewPanel.
/**
* Only call when log.isDebugEnabled() is true
*
* public void enumerateTree() { CatalogTreeNode root =
* (CatalogTreeNode)_model.getRoot(); log.debug("enumerateTree called for
* root= "+root.toString()+ ", has "+root.getChildCount()+" children");
* Enumeration e =root.depthFirstEnumeration(); while (e.hasMoreElements())
* { CatalogTreeNode n = (CatalogTreeNode)e.nextElement();
* log.debug("nodeName= "+n.getUserObject()+" has "+n.getLeaves().size()+"
* leaves."); } }
*/
/**
* Setup a display pane for a tree that shows only directory nodes (no file
* leaves) The leaves (icon images) will be displayed in this panel.
*/
private JPanel makePreviewPanel() {
JPanel previewPanel = new JPanel();
previewPanel.setLayout(new BoxLayout(previewPanel, BoxLayout.Y_AXIS));
previewPanel.add(_previewLabel);
_preview = new JPanel();
JScrollPane js = new JScrollPane(_preview);
previewPanel.add(js);
return previewPanel;
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class DispatcherFrame method openDispatcherWindow.
void openDispatcherWindow() {
if (dispatcherFrame == null) {
dispatcherFrame = this;
dispatcherFrame.setTitle(Bundle.getMessage("TitleDispatcher"));
JMenuBar menuBar = new JMenuBar();
optionsMenu = new OptionsMenu(this);
menuBar.add(optionsMenu);
setJMenuBar(menuBar);
dispatcherFrame.addHelpMenu("package.jmri.jmrit.dispatcher.Dispatcher", true);
contentPane = dispatcherFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// set up active trains table
JPanel p11 = new JPanel();
p11.setLayout(new FlowLayout());
p11.add(new JLabel(Bundle.getMessage("ActiveTrainTableTitle")));
contentPane.add(p11);
JPanel p12 = new JPanel();
p12.setLayout(new FlowLayout());
activeTrainsTableModel = new ActiveTrainsTableModel();
JTable activeTrainsTable = new JTable(activeTrainsTableModel);
activeTrainsTable.setRowSelectionAllowed(false);
activeTrainsTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 160));
TableColumnModel activeTrainsColumnModel = activeTrainsTable.getColumnModel();
TableColumn transitColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRANSIT_COLUMN);
transitColumn.setResizable(true);
transitColumn.setMinWidth(140);
transitColumn.setMaxWidth(220);
TableColumn trainColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRAIN_COLUMN);
trainColumn.setResizable(true);
trainColumn.setMinWidth(90);
trainColumn.setMaxWidth(160);
TableColumn typeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TYPE_COLUMN);
typeColumn.setResizable(true);
typeColumn.setMinWidth(130);
typeColumn.setMaxWidth(190);
TableColumn statusColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.STATUS_COLUMN);
statusColumn.setResizable(true);
statusColumn.setMinWidth(90);
statusColumn.setMaxWidth(140);
TableColumn modeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.MODE_COLUMN);
modeColumn.setResizable(true);
modeColumn.setMinWidth(90);
modeColumn.setMaxWidth(140);
TableColumn allocatedColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATED_COLUMN);
allocatedColumn.setResizable(true);
allocatedColumn.setMinWidth(120);
allocatedColumn.setMaxWidth(200);
TableColumn nextSectionColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.NEXTSECTION_COLUMN);
nextSectionColumn.setResizable(true);
nextSectionColumn.setMinWidth(120);
nextSectionColumn.setMaxWidth(200);
TableColumn allocateButtonColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATEBUTTON_COLUMN);
allocateButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
allocateButtonColumn.setMinWidth(110);
allocateButtonColumn.setMaxWidth(190);
allocateButtonColumn.setResizable(false);
ButtonRenderer buttonRenderer = new ButtonRenderer();
activeTrainsTable.setDefaultRenderer(JButton.class, buttonRenderer);
JButton sampleButton = new JButton(Bundle.getMessage("AllocateButtonName"));
activeTrainsTable.setRowHeight(sampleButton.getPreferredSize().height);
allocateButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
JScrollPane activeTrainsTableScrollPane = new JScrollPane(activeTrainsTable);
p12.add(activeTrainsTableScrollPane, BorderLayout.CENTER);
contentPane.add(p12);
JPanel p13 = new JPanel();
p13.setLayout(new FlowLayout());
p13.add(addTrainButton = new JButton(Bundle.getMessage("InitiateTrain") + "..."));
addTrainButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!newTrainActive) {
atFrame.initiateTrain(e);
newTrainActive = true;
} else {
atFrame.showActivateFrame();
}
}
});
addTrainButton.setToolTipText(Bundle.getMessage("InitiateTrainButtonHint"));
p13.add(new JLabel(" "));
p13.add(new JLabel(" "));
p13.add(allocateExtraButton = new JButton(Bundle.getMessage("AllocateExtra") + "..."));
allocateExtraButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
allocateExtraSection(e);
}
});
allocateExtraButton.setToolTipText(Bundle.getMessage("AllocateExtraButtonHint"));
p13.add(new JLabel(" "));
p13.add(cancelRestartButton = new JButton(Bundle.getMessage("CancelRestart") + "..."));
cancelRestartButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!newTrainActive) {
cancelRestart(e);
} else if (restartingTrainsList.size() > 0) {
atFrame.showActivateFrame();
JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message2"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
} else {
atFrame.showActivateFrame();
}
}
});
cancelRestartButton.setToolTipText(Bundle.getMessage("CancelRestartButtonHint"));
p13.add(new JLabel(" "));
p13.add(terminateTrainButton = new JButton(Bundle.getMessage("TerminateTrain") + "..."));
terminateTrainButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!newTrainActive) {
terminateTrain(e);
} else if (activeTrainsList.size() > 0) {
atFrame.showActivateFrame();
JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message1"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
} else {
atFrame.showActivateFrame();
}
}
});
terminateTrainButton.setToolTipText(Bundle.getMessage("TerminateTrainButtonHint"));
contentPane.add(p13);
// set up pending allocations table
contentPane.add(new JSeparator());
JPanel p21 = new JPanel();
p21.setLayout(new FlowLayout());
p21.add(new JLabel(Bundle.getMessage("RequestedAllocationsTableTitle")));
contentPane.add(p21);
JPanel p22 = new JPanel();
p22.setLayout(new FlowLayout());
allocationRequestTableModel = new AllocationRequestTableModel();
JTable allocationRequestTable = new JTable(allocationRequestTableModel);
allocationRequestTable.setRowSelectionAllowed(false);
allocationRequestTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 100));
TableColumnModel allocationRequestColumnModel = allocationRequestTable.getColumnModel();
TableColumn activeColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ACTIVE_COLUMN);
activeColumn.setResizable(true);
activeColumn.setMinWidth(210);
activeColumn.setMaxWidth(260);
TableColumn priorityColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.PRIORITY_COLUMN);
priorityColumn.setResizable(true);
priorityColumn.setMinWidth(40);
priorityColumn.setMaxWidth(60);
TableColumn trainTypColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.TRAINTYPE_COLUMN);
trainTypColumn.setResizable(true);
trainTypColumn.setMinWidth(130);
trainTypColumn.setMaxWidth(190);
TableColumn sectionColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTION_COLUMN);
sectionColumn.setResizable(true);
sectionColumn.setMinWidth(140);
sectionColumn.setMaxWidth(210);
TableColumn secStatusColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.STATUS_COLUMN);
secStatusColumn.setResizable(true);
secStatusColumn.setMinWidth(90);
secStatusColumn.setMaxWidth(150);
TableColumn occupancyColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.OCCUPANCY_COLUMN);
occupancyColumn.setResizable(true);
occupancyColumn.setMinWidth(80);
occupancyColumn.setMaxWidth(130);
TableColumn secLengthColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTIONLENGTH_COLUMN);
secLengthColumn.setResizable(true);
secLengthColumn.setMinWidth(40);
secLengthColumn.setMaxWidth(60);
TableColumn allocateColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ALLOCATEBUTTON_COLUMN);
allocateColumn.setCellEditor(new ButtonEditor(new JButton()));
allocateColumn.setMinWidth(90);
allocateColumn.setMaxWidth(170);
allocateColumn.setResizable(false);
allocationRequestTable.setDefaultRenderer(JButton.class, buttonRenderer);
sampleButton = new JButton(Bundle.getMessage("AllocateButton"));
allocationRequestTable.setRowHeight(sampleButton.getPreferredSize().height);
allocateColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
TableColumn cancelButtonColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.CANCELBUTTON_COLUMN);
cancelButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
cancelButtonColumn.setMinWidth(75);
cancelButtonColumn.setMaxWidth(170);
cancelButtonColumn.setResizable(false);
cancelButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
JScrollPane allocationRequestTableScrollPane = new JScrollPane(allocationRequestTable);
p22.add(allocationRequestTableScrollPane, BorderLayout.CENTER);
contentPane.add(p22);
// set up allocated sections table
contentPane.add(new JSeparator());
JPanel p30 = new JPanel();
p30.setLayout(new FlowLayout());
p30.add(new JLabel(Bundle.getMessage("AllocatedSectionsTitle") + " "));
autoReleaseBox = new JCheckBox(Bundle.getMessage("AutoReleaseBoxLabel"));
p30.add(autoReleaseBox);
autoReleaseBox.setToolTipText(Bundle.getMessage("AutoReleaseBoxHint"));
autoReleaseBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleAutoReleaseChanged(e);
}
});
// initiallize autoRelease to match autoAllocate
autoReleaseBox.setSelected(_AutoAllocate);
autoAllocateBox = new JCheckBox(Bundle.getMessage("AutoDispatchItem"));
p30.add(autoAllocateBox);
autoAllocateBox.setToolTipText(Bundle.getMessage("AutoAllocateBoxHint"));
autoAllocateBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleAutoAllocateChanged(e);
}
});
contentPane.add(p30);
autoAllocateBox.setSelected(_AutoAllocate);
JPanel p31 = new JPanel();
p31.setLayout(new FlowLayout());
allocatedSectionTableModel = new AllocatedSectionTableModel();
JTable allocatedSectionTable = new JTable(allocatedSectionTableModel);
allocatedSectionTable.setRowSelectionAllowed(false);
allocatedSectionTable.setPreferredScrollableViewportSize(new java.awt.Dimension(730, 200));
TableColumnModel allocatedSectionColumnModel = allocatedSectionTable.getColumnModel();
TableColumn activeAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.ACTIVE_COLUMN);
activeAColumn.setResizable(true);
activeAColumn.setMinWidth(250);
activeAColumn.setMaxWidth(350);
TableColumn sectionAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.SECTION_COLUMN);
sectionAColumn.setResizable(true);
sectionAColumn.setMinWidth(200);
sectionAColumn.setMaxWidth(350);
TableColumn occupancyAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.OCCUPANCY_COLUMN);
occupancyAColumn.setResizable(true);
occupancyAColumn.setMinWidth(80);
occupancyAColumn.setMaxWidth(140);
TableColumn useStatusColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.USESTATUS_COLUMN);
useStatusColumn.setResizable(true);
useStatusColumn.setMinWidth(90);
useStatusColumn.setMaxWidth(150);
TableColumn releaseColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.RELEASEBUTTON_COLUMN);
releaseColumn.setCellEditor(new ButtonEditor(new JButton()));
releaseColumn.setMinWidth(90);
releaseColumn.setMaxWidth(170);
releaseColumn.setResizable(false);
allocatedSectionTable.setDefaultRenderer(JButton.class, buttonRenderer);
JButton sampleAButton = new JButton(Bundle.getMessage("ReleaseButton"));
allocatedSectionTable.setRowHeight(sampleAButton.getPreferredSize().height);
releaseColumn.setPreferredWidth((sampleAButton.getPreferredSize().width) + 2);
JScrollPane allocatedSectionTableScrollPane = new JScrollPane(allocatedSectionTable);
p31.add(allocatedSectionTableScrollPane, BorderLayout.CENTER);
contentPane.add(p31);
}
dispatcherFrame.pack();
dispatcherFrame.setVisible(true);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class Editor method makeAddIconFrame.
protected JFrameItem makeAddIconFrame(String name, boolean add, boolean table, IconAdder editor) {
log.debug("makeAddIconFrame for {}, add= {}, table= ", name, add, table);
String txt;
String BundleName;
JFrameItem frame = new JFrameItem(name, editor);
// use NamedBeanBundle property for basic beans like "Turnout" I18N
if ("Sensor".equals(name)) {
BundleName = "BeanNameSensor";
} else if ("SignalHead".equals(name)) {
BundleName = "BeanNameSignalHead";
} else if ("SignalMast".equals(name)) {
BundleName = "BeanNameSignalMast";
} else if ("Memory".equals(name)) {
BundleName = "BeanNameMemory";
} else if ("Reporter".equals(name)) {
BundleName = "BeanNameReporter";
} else if ("Light".equals(name)) {
BundleName = "BeanNameLight";
} else if ("Turnout".equals(name)) {
// called by RightTurnout and LeftTurnout objects in TurnoutIcon.java edit() method
BundleName = "BeanNameTurnout";
} else if ("Block".equals(name)) {
BundleName = "BeanNameBlock";
} else {
BundleName = name;
}
if (editor != null) {
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
if (add) {
txt = java.text.MessageFormat.format(Bundle.getMessage("addItemToPanel"), Bundle.getMessage(BundleName));
} else {
txt = java.text.MessageFormat.format(Bundle.getMessage("editItemInPanel"), Bundle.getMessage(BundleName));
}
p.add(new JLabel(txt));
if (table) {
txt = java.text.MessageFormat.format(Bundle.getMessage("TableSelect"), Bundle.getMessage(BundleName), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
} else {
if ("MultiSensor".equals(name)) {
txt = java.text.MessageFormat.format(Bundle.getMessage("SelectMultiSensor", Bundle.getMessage("ButtonAddIcon")), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
} else {
txt = java.text.MessageFormat.format(Bundle.getMessage("IconSelect"), Bundle.getMessage(BundleName), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
}
}
p.add(new JLabel(txt));
// add a bit of space on pane above icons
p.add(new JLabel(" "));
frame.getContentPane().add(p, BorderLayout.NORTH);
frame.getContentPane().add(editor);
JMenuBar menuBar = new JMenuBar();
JMenu findIcon = new JMenu(Bundle.getMessage("findIconMenu"));
menuBar.add(findIcon);
JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
editItem.addActionListener(new ActionListener() {
Editor editor;
@Override
public void actionPerformed(ActionEvent e) {
ImageIndexEditor ii = ImageIndexEditor.instance(editor);
ii.pack();
ii.setVisible(true);
}
ActionListener init(Editor ed) {
editor = ed;
return this;
}
}.init(this));
findIcon.add(editItem);
findIcon.addSeparator();
JMenuItem searchItem = new JMenuItem(Bundle.getMessage("searchFSMenu"));
searchItem.addActionListener(new ActionListener() {
IconAdder ea;
@Override
public void actionPerformed(ActionEvent e) {
jmri.jmrit.catalog.DirectorySearcher.instance().searchFS();
ea.addDirectoryToCatalog();
}
ActionListener init(IconAdder ed) {
ea = ed;
return this;
}
}.init(editor));
findIcon.add(searchItem);
frame.setJMenuBar(menuBar);
editor.setParent(frame);
// when this window closes, check for saving
if (add) {
frame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
if (log.isDebugEnabled()) {
log.debug("windowClosing: HIDE {}", toString());
}
}
});
}
} else {
//NOI18N
log.error("No icon editor specified for {}", name);
}
if (add) {
txt = java.text.MessageFormat.format(Bundle.getMessage("AddItem"), Bundle.getMessage(BundleName));
_iconEditorFrame.put(name, frame);
} else {
txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage(BundleName));
}
frame.setTitle(txt + " (" + getTitle() + ")");
frame.pack();
return frame;
}
Aggregations