use of javax.swing.BoxLayout in project JMRI by JMRI.
the class SwitchboardEditor method init.
/**
* Initialize the newly created SwitchBoard.
*
* @param name name of the switchboard frame
*/
@Override
protected void init(String name) {
//setVisible(false);
// Editor
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// make menus
setGlobalSetsLocalFlag(false);
setUseGlobalFlag(false);
_menuBar = new JMenuBar();
makeOptionMenu();
//makeEditMenu();
makeFileMenu();
setJMenuBar(_menuBar);
addHelpMenu("package.jmri.jmrit.display.SwitchboardEditor", true);
//super.setTargetPanel(null, makeFrame(name)); // original CPE version
//extends JLayeredPane();
switchboardLayeredPane = new TargetPane();
switchboardLayeredPane.setPreferredSize(new Dimension(300, 310));
switchboardLayeredPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(defaultTextColor), Bundle.getMessage("SwitchboardBanner"), TitledBorder.LEADING, TitledBorder.ABOVE_BOTTOM, getFont(), defaultTextColor));
// create contrast with background, should also specify border style
// specify title for turnout, sensor, light, mixed? (wait for the Editor to be created)
switchboardLayeredPane.addMouseMotionListener(this);
//Add control pane and layered pane to this JPanel
JPanel beanSetupPane = new JPanel();
beanSetupPane.setLayout(new FlowLayout(FlowLayout.TRAILING));
JLabel beanTypeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanTypeLabel")));
beanSetupPane.add(beanTypeTitle);
beanTypeList = new JComboBox(beanTypeStrings);
// select Turnout in comboBox
beanTypeList.setSelectedIndex(0);
beanTypeList.setActionCommand(LAYER_COMMAND);
beanTypeList.addActionListener(this);
beanSetupPane.add(beanTypeList);
//Add connection selection comboBox
// translate from selectedIndex to char
beanTypeChar = getSwitchType().charAt(0);
log.debug("beanTypeChar set to [{}]", beanTypeChar);
JLabel beanManuTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ConnectionLabel")));
beanSetupPane.add(beanManuTitle);
beanManuNames = new JComboBox();
if (getManager(beanTypeChar) instanceof jmri.managers.AbstractProxyManager) {
// from abstractTableTabAction
jmri.managers.AbstractProxyManager proxy = (jmri.managers.AbstractProxyManager) getManager(beanTypeChar);
List<jmri.Manager> managerList = proxy.getManagerList();
for (int x = 0; x < managerList.size(); x++) {
String manuPrefix = managerList.get(x).getSystemPrefix();
log.debug("Prefix = [{}]", manuPrefix);
String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
log.debug("Connection name = [{}]", manuName);
// add to comboBox
beanManuNames.addItem(manuName);
// add to list
beanManuPrefixes.add(manuPrefix);
}
} else {
String manuPrefix = getManager(beanTypeChar).getSystemPrefix();
String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
beanManuNames.addItem(manuName);
// add to list (as only item)
beanManuPrefixes.add(manuPrefix);
}
beanManuNames.setSelectedIndex(0);
beanManuNames.setActionCommand(MANU_COMMAND);
beanManuNames.addActionListener(this);
beanSetupPane.add(beanManuNames);
add(beanSetupPane);
// add shape combobox
JPanel switchShapePane = new JPanel();
switchShapePane.setLayout(new FlowLayout(FlowLayout.TRAILING));
JLabel switchShapeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SwitchShape")));
switchShapePane.add(switchShapeTitle);
switchShapeList = new JComboBox(switchShapeStrings);
// select Button in comboBox
switchShapeList.setSelectedIndex(0);
switchShapeList.setActionCommand(SWITCHTYPE_COMMAND);
switchShapeList.addActionListener(this);
switchShapePane.add(switchShapeList);
// add column spinner
JLabel columnLabel = new JLabel(Bundle.getMessage("NumberOfColumns"));
switchShapePane.add(columnLabel);
switchShapePane.add(Columns);
add(switchShapePane);
JCheckBox hideUnconnected = new JCheckBox(Bundle.getMessage("CheckBoxHideUnconnected"));
hideUnconnected.setSelected(hideUnconnected());
hideUnconnected.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setHideUnconnected(hideUnconnected.isSelected());
}
});
add(hideUnconnected);
// Next, add the buttons to the layered pane.
switchboardLayeredPane.setLayout(new GridLayout(java.lang.Math.max(2, _range % ((Integer) Columns.getValue())), (Integer) Columns.getValue()));
// vertical (at least 2 rows), horizontal
// TODO do some calculation from JPanel size, icon size and determine optimal cols/rows
addSwitchRange((Integer) minSpinner.getValue(), (Integer) maxSpinner.getValue(), beanTypeList.getSelectedIndex(), beanManuPrefixes.get(beanManuNames.getSelectedIndex()), switchShapeList.getSelectedIndex());
// provide a JLayeredPane to place the switches on
super.setTargetPanel(switchboardLayeredPane, makeFrame(name));
// width x height
super.getTargetFrame().setSize(550, 330);
// To do: Add component listener to handle frame resizing event
// set scrollbar initial state
setScroll(SCROLL_NONE);
scrollNone.setSelected(true);
super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(this);
}
add(createControlPanel());
JPanel updatePanel = new JPanel();
JButton updateButton = new JButton(Bundle.getMessage("ButtonUpdate"));
updateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
log.debug("Update clicked");
updatePressed();
}
});
updatePanel.add(updateButton);
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
contentPane.add(updatePanel);
//re-layout all the toolbar items
setupToolBar();
// refresh default Switchboard
updatePressed();
pack();
setVisible(true);
// TODO choose your own icons
// class makeCatalog extends SwingWorker<CatalogPanel, Object> {
//
// @Override
// public CatalogPanel doInBackground() {
// return CatalogPanel.makeDefaultCatalog();
// }
// }
// (new makeCatalog()).execute();
// log.debug("Init SwingWorker launched");
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class InputWindowAction method actionPerformed.
/**
* Invoking this action via an event triggers display of a file dialog. If a
* file is selected, it's then invoked as a script.
*
*/
@Override
public void actionPerformed(ActionEvent e) {
f = new JmriJFrame(Bundle.getMessage("TitleInputFrame"));
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), javax.swing.BoxLayout.Y_AXIS));
f.getContentPane().add(new InputWindow());
f.pack();
f.setVisible(true);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class SwitchboardEditor method createControlPanel.
/** Create the setup pane for the top of the frame.
* From layeredpane demo
*/
private JPanel createControlPanel() {
JPanel controls = new JPanel();
// navigation top row and to set range
navBarPanel = new JPanel();
navBarPanel.setLayout(new BoxLayout(navBarPanel, BoxLayout.X_AXIS));
navBarPanel.add(prev);
prev.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int oldMin = (Integer) minSpinner.getValue();
int oldMax = (Integer) maxSpinner.getValue();
_range = oldMax - oldMin;
minSpinner.setValue(Math.max(rangeMin, oldMin - _range - 1));
maxSpinner.setValue(Math.max(oldMax - _range - 1, Math.max(rangeMax, oldMax - _range - 1)));
log.debug("oldMin =" + oldMin + ", oldMax =" + oldMax);
//rangeMin = (Integer) minSpinner.getValue();
//rangeMax = (Integer) maxSpinner.getValue();
}
});
prev.setToolTipText(Bundle.getMessage("PreviousToolTip"));
navBarPanel.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("From"))));
navBarPanel.add(minSpinner);
navBarPanel.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("UpTo"))));
navBarPanel.add(maxSpinner);
navBarPanel.add(next);
next.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int oldMin = (Integer) minSpinner.getValue();
int oldMax = (Integer) maxSpinner.getValue();
_range = oldMax - oldMin;
minSpinner.setValue(oldMax + 1);
maxSpinner.setValue(oldMax + _range + 1);
//rangeMin = (Integer) minSpinner.getValue();
//rangeMax = (Integer) maxSpinner.getValue();
}
});
next.setToolTipText(Bundle.getMessage("NextToolTip"));
navBarPanel.add(Box.createHorizontalGlue());
// put on which Frame?
// on 2nd Editor Panel
controls.add(navBarPanel);
//super.getTargetFrame().add(navBarPanel); // on (top of) Switchboard Frame/Panel
controls.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("SelectRangeTitle")));
return controls;
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class SwitchboardEditor method setupToolBar.
private void setupToolBar() {
//Initial setup for both horizontal and vertical
Container contentPane = getContentPane();
//remove these (if present) so we can add them back (without duplicates)
if (editToolBarContainer != null) {
editToolBarContainer.setVisible(false);
contentPane.remove(editToolBarContainer);
}
// if (helpBarPanel != null) {
// contentPane.remove(helpBarPanel);
// }
editToolBarPanel = new JPanel();
editToolBarPanel.setLayout(new BoxLayout(editToolBarPanel, BoxLayout.PAGE_AXIS));
JPanel innerBorderPanel = new JPanel();
innerBorderPanel.setLayout(new BoxLayout(innerBorderPanel, BoxLayout.PAGE_AXIS));
TitledBorder TitleBorder = BorderFactory.createTitledBorder(Bundle.getMessage("SwitchboardHelpTitle"));
innerBorderPanel.setBorder(TitleBorder);
innerBorderPanel.add(new JTextArea(Bundle.getMessage("Help1")));
if (!hideUnconnected()) {
innerBorderPanel.add(new JTextArea(Bundle.getMessage("Help2")));
// TODO hide this panel when hideUnconnected() is set to false from menu or checkbox
}
contentPane.add(innerBorderPanel);
//Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
editToolBarScroll = new JScrollPane(editToolBarPanel);
//editToolBarScroll.getPreferredSize().height;
height = 60;
editToolBarContainer = new JPanel();
editToolBarContainer.setLayout(new BoxLayout(editToolBarContainer, BoxLayout.PAGE_AXIS));
editToolBarContainer.add(editToolBarScroll);
editToolBarContainer.setMinimumSize(new Dimension(width, height));
editToolBarContainer.setPreferredSize(new Dimension(width, height));
// helpBarPanel = new JPanel();
// helpBarPanel.add(helpBar);
// for (Component c : helpBar.getComponents()) {
// if (c instanceof JTextArea) {
// JTextArea j = (JTextArea) c;
// //j.setSize(new Dimension(width, j.getSize().height));
// j.setLineWrap(true);
// j.setWrapStyleWord(true);
// }
// }
// contentPane.setLayout(new BoxLayout(contentPane, false ? BoxLayout.LINE_AXIS : BoxLayout.PAGE_AXIS));
// contentPane.add(editToolBarContainer);
// contentPane.add(helpBarPanel);
//helpBarPanel.setVisible(isEditable() && showHelpBar);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class WarrantRoute method pickRoute.
/**
* Callback from RouteFinder - several routes found
*
* @param destNodes the destination blocks
* @param routeTree the routes
*/
protected void pickRoute(List<DefaultMutableTreeNode> destNodes, DefaultTreeModel routeTree) {
if (destNodes.size() == 1) {
showRoute(destNodes.get(0), routeTree);
selectedRoute(_orders);
return;
}
_pickRouteDialog = new JDialog(this, Bundle.getMessage("DialogTitle"), false);
_pickRouteDialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
clearTempWarrant();
}
});
_tempWarrant = null;
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout(5, 5));
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new JLabel(Bundle.getMessage("NumberRoutes1", destNodes.size())));
panel.add(new JLabel(Bundle.getMessage("NumberRoutes2")));
mainPanel.add(panel, BorderLayout.NORTH);
ButtonGroup buttons = new ButtonGroup();
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
for (int i = 0; i < destNodes.size(); i++) {
JRadioButton button = new JRadioButton(Bundle.getMessage("RouteSize", i + 1, destNodes.get(i).getLevel() + 1));
button.setActionCommand("" + i);
button.addActionListener((ActionEvent e) -> {
clearTempWarrant();
});
buttons.add(button);
panel.add(button);
}
JScrollPane scrollPane = new JScrollPane(panel);
mainPanel.add(scrollPane, BorderLayout.CENTER);
JButton ok = new JButton(Bundle.getMessage("ButtonSelect"));
ok.addActionListener(new ActionListener() {
ButtonGroup buts;
JDialog dialog;
List<DefaultMutableTreeNode> dNodes;
DefaultTreeModel tree;
@Override
public void actionPerformed(ActionEvent e) {
if (buts.getSelection() != null) {
clearTempWarrant();
int i = Integer.parseInt(buttons.getSelection().getActionCommand());
showRoute(dNodes.get(i), tree);
selectedRoute(_orders);
dialog.dispose();
} else {
showWarning(Bundle.getMessage("SelectRoute"));
}
}
ActionListener init(ButtonGroup bg, JDialog d, List<DefaultMutableTreeNode> dn, DefaultTreeModel t) {
buts = bg;
dialog = d;
dNodes = dn;
tree = t;
return this;
}
}.init(buttons, _pickRouteDialog, destNodes, routeTree));
ok.setMaximumSize(ok.getPreferredSize());
JButton show = new JButton(Bundle.getMessage("ButtonReview"));
show.addActionListener(new ActionListener() {
ButtonGroup buts;
List<DefaultMutableTreeNode> destinationNodes;
DefaultTreeModel tree;
@Override
public void actionPerformed(ActionEvent e) {
if (buts.getSelection() != null) {
clearTempWarrant();
int i = Integer.parseInt(buttons.getSelection().getActionCommand());
showRoute(destinationNodes.get(i), tree);
showTempWarrant(_orders);
} else {
showWarning(Bundle.getMessage("SelectRoute"));
}
}
ActionListener init(ButtonGroup bg, List<DefaultMutableTreeNode> dn, DefaultTreeModel t) {
buts = bg;
destinationNodes = dn;
tree = t;
return this;
}
}.init(buttons, destNodes, routeTree));
show.setMaximumSize(show.getPreferredSize());
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(show);
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(ok);
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
mainPanel.add(panel, BorderLayout.SOUTH);
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(makeRouteTablePanel());
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(mainPanel);
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
_pickRouteDialog.getContentPane().add(panel);
_pickRouteDialog.setLocation(getLocation().x - 20, getLocation().y + 150);
_pickRouteDialog.pack();
_pickRouteDialog.setVisible(true);
}
Aggregations