use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class SystemConsole method createFrame.
/**
* Layout the console frame
*/
private void createFrame() {
// Use a JmriJFrame to ensure that we fit on the screen
frame = new JmriJFrame(Bundle.getMessage("TitleConsole"));
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
// Add Help menu (Windows menu automaitically added)
// NOI18N
frame.addHelpMenu("package.apps.SystemConsole", true);
// Grab a reference to the system clipboard
final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
// Setup the scroll pane
JScrollPane scroll = new JScrollPane(console);
frame.add(scroll, BorderLayout.CENTER);
// Add button to allow copy to clipboard
JPanel p = new JPanel();
JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
copy.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
p.add(copy);
// Add button to allow console window to be closed
JButton close = new JButton(Bundle.getMessage("ButtonClose"));
close.addActionListener((ActionEvent event) -> {
frame.setVisible(false);
frame.dispose();
});
p.add(close);
JButton stackTrace = new JButton(Bundle.getMessage("ButtonStackTrace"));
stackTrace.addActionListener((ActionEvent event) -> {
performStackTrace();
});
p.add(stackTrace);
// Add checkbox to enable/disable auto-scrolling
// Use the inverted SimplePreferenceState to default as enabled
p.add(autoScroll = new JCheckBox(Bundle.getMessage("CheckBoxAutoScroll"), !pref.getSimplePreferenceState(alwaysScrollCheck)));
autoScroll.addActionListener((ActionEvent event) -> {
doAutoScroll(console, autoScroll.isSelected());
pref.setSimplePreferenceState(alwaysScrollCheck, !autoScroll.isSelected());
});
// Add checkbox to enable/disable always on top
p.add(alwaysOnTop = new JCheckBox(Bundle.getMessage("CheckBoxOnTop"), pref.getSimplePreferenceState(alwaysOnTopCheck)));
alwaysOnTop.setVisible(true);
alwaysOnTop.setToolTipText(Bundle.getMessage("ToolTipOnTop"));
alwaysOnTop.addActionListener((ActionEvent event) -> {
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
pref.setSimplePreferenceState(alwaysOnTopCheck, alwaysOnTop.isSelected());
});
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
// Define the pop-up menu
copySelection = new JMenuItem(Bundle.getMessage("MenuItemCopy"));
copySelection.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getSelectedText());
clipboard.setContents(text, text);
});
popup.add(copySelection);
JMenuItem menuItem = new JMenuItem(Bundle.getMessage("ButtonCopyClip"));
menuItem.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
popup.add(menuItem);
popup.add(new JSeparator());
JRadioButtonMenuItem rbMenuItem;
// Define the colour scheme sub-menu
schemeMenu = new JMenu(rbc.getString("ConsoleSchemeMenu"));
schemeGroup = new ButtonGroup();
for (final Scheme s : schemes) {
rbMenuItem = new JRadioButtonMenuItem(s.description);
rbMenuItem.addActionListener((ActionEvent event) -> {
setScheme(schemes.indexOf(s));
});
rbMenuItem.setSelected(getScheme() == schemes.indexOf(s));
schemeMenu.add(rbMenuItem);
schemeGroup.add(rbMenuItem);
}
popup.add(schemeMenu);
// Define the wrap style sub-menu
wrapMenu = new JMenu(rbc.getString("ConsoleWrapStyleMenu"));
wrapGroup = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleNone"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_NONE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_NONE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleLine"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_LINE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_LINE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleWord"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_WORD);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_WORD);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
popup.add(wrapMenu);
// Bind pop-up to objects
MouseListener popupListener = new PopupListener();
console.addMouseListener(popupListener);
frame.addMouseListener(popupListener);
// Add document listener to scroll to end when modified if required
console.getDocument().addDocumentListener(new DocumentListener() {
// References to the JTextArea and JCheckBox
// of this instantiation
JTextArea ta = console;
JCheckBox chk = autoScroll;
@Override
public void insertUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void removeUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void changedUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
});
// Add the button panel to the frame & then arrange everything
frame.add(p, BorderLayout.SOUTH);
frame.pack();
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class SoundPro method main.
// Main entry point
public static void main(String[] args) {
// show splash screen early
splash(true);
Apps.setStartupInfo("SoundPro");
setConfigFilename("SoundProConfig2.xml", args);
JmriJFrame f = new JmriJFrame("SoundPro");
createFrame(new SoundPro(f), f);
log.debug("main initialization done");
splash(false);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class SignalPro method main.
// Main entry point
public static void main(String[] args) {
// show splash screen early
splash(true);
Apps.setStartupInfo("SignalPro");
setConfigFilename("SignalProConfig2.xml", args);
JmriJFrame f = new JmriJFrame("SignalPro");
createFrame(new SignalPro(f), f);
log.debug("main initialization done");
splash(false);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class LightTableAction method addPressed.
@Override
protected void addPressed(ActionEvent e) {
if (inEditMode) {
// cancel Edit and reactivate the edited light
cancelPressed(null);
}
if (addFrame == null) {
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddLight"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.LightAddEdit", true);
addFrame.setLocation(100, 30);
Container contentPane = addFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
initializePrefixCombo();
panel1.add(systemLabel);
panel1.add(prefixBox);
panel1.add(new JLabel(" "));
panel1.add(addRangeBox);
addRangeBox.setToolTipText(Bundle.getMessage("LightAddRangeHint"));
addRangeBox.addActionListener((ActionEvent e1) -> {
addRangeChanged();
});
panel1.add(systemNameLabel);
systemNameLabel.setVisible(false);
panel1.add(fixedSystemName);
fixedSystemName.setVisible(false);
prefixBox.setToolTipText(Bundle.getMessage("LightSystemHint"));
prefixBox.addActionListener((ActionEvent e1) -> {
prefixChanged();
});
contentPane.add(panel1);
panel1a = new JPanel();
panel1a.setLayout(new FlowLayout());
panel1a.add(new JLabel(Bundle.getMessage("LabelHardwareAddress")));
panel1a.add(fieldHardwareAddress);
fieldHardwareAddress.setToolTipText(Bundle.getMessage("LightHardwareAddressHint"));
panel1a.add(labelNumToAdd);
panel1a.add(fieldNumToAdd);
fieldNumToAdd.setToolTipText(Bundle.getMessage("LightNumberToAddHint"));
contentPane.add(panel1a);
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(userNameLabel);
panel2.add(userName);
userName.setToolTipText(Bundle.getMessage("LightUserNameHint"));
contentPane.add(panel2);
// items for variable intensity lights
varPanel = new JPanel();
varPanel.setLayout(new BoxLayout(varPanel, BoxLayout.X_AXIS));
varPanel.add(new JLabel(" "));
varPanel.add(labelMinIntensity);
fieldMinIntensity.setToolTipText(Bundle.getMessage("LightMinIntensityHint"));
fieldMinIntensity.setHorizontalAlignment(JTextField.RIGHT);
fieldMinIntensity.setText(" 0");
varPanel.add(fieldMinIntensity);
varPanel.add(labelMinIntensityTail);
varPanel.add(labelMaxIntensity);
fieldMaxIntensity.setToolTipText(Bundle.getMessage("LightMaxIntensityHint"));
fieldMaxIntensity.setHorizontalAlignment(JTextField.RIGHT);
fieldMaxIntensity.setText("100");
varPanel.add(fieldMaxIntensity);
varPanel.add(labelMaxIntensityTail);
varPanel.add(labelTransitionTime);
fieldTransitionTime.setToolTipText(Bundle.getMessage("LightTransitionTimeHint"));
fieldTransitionTime.setHorizontalAlignment(JTextField.RIGHT);
fieldTransitionTime.setText("0");
varPanel.add(fieldTransitionTime);
varPanel.add(new JLabel(" "));
Border varPanelBorder = BorderFactory.createEtchedBorder();
Border varPanelTitled = BorderFactory.createTitledBorder(varPanelBorder, Bundle.getMessage("LightVariableBorder"));
varPanel.setBorder(varPanelTitled);
contentPane.add(varPanel);
// light control table
JPanel panel3 = new JPanel();
panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
JPanel panel31 = new JPanel();
lightControlTableModel = new LightControlTableModel();
JTable lightControlTable = new JTable(lightControlTableModel);
lightControlTable.setRowSelectionAllowed(false);
lightControlTable.setPreferredScrollableViewportSize(new java.awt.Dimension(550, 100));
TableColumnModel lightControlColumnModel = lightControlTable.getColumnModel();
TableColumn typeColumn = lightControlColumnModel.getColumn(LightControlTableModel.TYPE_COLUMN);
typeColumn.setResizable(true);
typeColumn.setMinWidth(110);
typeColumn.setMaxWidth(150);
TableColumn descriptionColumn = lightControlColumnModel.getColumn(LightControlTableModel.DESCRIPTION_COLUMN);
descriptionColumn.setResizable(true);
descriptionColumn.setMinWidth(270);
descriptionColumn.setMaxWidth(340);
ButtonRenderer buttonRenderer = new ButtonRenderer();
lightControlTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
lightControlTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton(Bundle.getMessage("ButtonDelete"));
lightControlTable.setRowHeight(testButton.getPreferredSize().height);
TableColumn editColumn = lightControlColumnModel.getColumn(LightControlTableModel.EDIT_COLUMN);
editColumn.setResizable(false);
editColumn.setMinWidth(testButton.getPreferredSize().width);
TableColumn removeColumn = lightControlColumnModel.getColumn(LightControlTableModel.REMOVE_COLUMN);
removeColumn.setResizable(false);
removeColumn.setMinWidth(testButton.getPreferredSize().width);
JScrollPane lightControlTableScrollPane = new JScrollPane(lightControlTable);
panel31.add(lightControlTableScrollPane, BorderLayout.CENTER);
panel3.add(panel31);
JPanel panel35 = new JPanel();
panel35.setLayout(new FlowLayout());
panel35.add(addControl = new JButton(Bundle.getMessage("LightAddControlButton")));
addControl.addActionListener(this::addControlPressed);
addControl.setToolTipText(Bundle.getMessage("LightAddControlButtonHint"));
panel3.add(panel35);
Border panel3Border = BorderFactory.createEtchedBorder();
Border panel3Titled = BorderFactory.createTitledBorder(panel3Border, Bundle.getMessage("LightControlBorder"));
panel3.setBorder(panel3Titled);
contentPane.add(panel3);
// message items
JPanel panel4 = new JPanel();
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
JPanel panel41 = new JPanel();
panel41.setLayout(new FlowLayout());
panel41.add(status1);
status1.setText(Bundle.getMessage("LightCreateInst"));
JPanel panel42 = new JPanel();
panel42.setLayout(new FlowLayout());
panel42.add(status2);
status2.setText("");
status2.setVisible(false);
panel4.add(panel41);
panel4.add(panel42);
Border panel4Border = BorderFactory.createEtchedBorder();
panel4.setBorder(panel4Border);
contentPane.add(panel4);
// buttons at bottom of window
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout(FlowLayout.TRAILING));
panel5.add(cancel = new JButton(Bundle.getMessage("ButtonCancel")));
cancel.addActionListener(this::cancelPressed);
cancel.setToolTipText(Bundle.getMessage("LightCancelButtonHint"));
panel5.add(create = new JButton(Bundle.getMessage("ButtonCreate")));
create.addActionListener(this::createPressed);
create.setToolTipText(Bundle.getMessage("LightCreateButtonHint"));
panel5.add(update = new JButton(Bundle.getMessage("ButtonUpdate")));
update.addActionListener(this::updatePressed);
update.setToolTipText(Bundle.getMessage("LightUpdateButtonHint"));
cancel.setVisible(true);
create.setVisible(true);
update.setVisible(false);
contentPane.add(panel5);
}
prefixChanged();
addFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelPressed(null);
}
});
addFrame.pack();
addFrame.setVisible(true);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class LightTableAction method addEditControlWindow.
/**
* Creates the Add/Edit control window
*/
private void addEditControlWindow() {
if (addControlFrame == null) {
addControlFrame = new JmriJFrame(Bundle.getMessage("TitleAddLightControl"), false, true);
addControlFrame.addHelpMenu("package.jmri.jmrit.beantable.LightAddEdit", true);
addControlFrame.setLocation(120, 40);
Container contentPane = addControlFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel3 = new JPanel();
panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
JPanel panel31 = new JPanel();
panel31.setLayout(new FlowLayout());
panel31.add(typeBoxLabel);
panel31.add(typeBox = new JComboBox<>(new String[] { noControl, sensorControl, fastClockControl, turnoutStatusControl, timedOnControl, twoSensorControl }));
noControlIndex = 0;
sensorControlIndex = 1;
fastClockControlIndex = 2;
turnoutStatusControlIndex = 3;
timedOnControlIndex = 4;
twoSensorControlIndex = 5;
typeBox.addActionListener((ActionEvent e) -> {
controlTypeChanged();
});
typeBox.setToolTipText(Bundle.getMessage("LightControlTypeHint"));
JPanel panel32 = new JPanel();
panel32.setLayout(new FlowLayout());
panel32.add(f1Label);
panel32.add(field1a);
panel32.add(field1a2);
panel32.add(field1b);
panel32.add(field1c);
panel32.add(field1d);
field1a.setText("");
field1a2.setText("");
field1b.setText("00:00");
field1c.setText("");
field1d.setText("");
field1b.setVisible(false);
field1c.setVisible(false);
field1d.setVisible(false);
field1a.setToolTipText(Bundle.getMessage("LightSensorHint"));
field1a2.setToolTipText(Bundle.getMessage("LightTwoSensorHint"));
JPanel panel33 = new JPanel();
panel33.setLayout(new FlowLayout());
panel33.add(f2Label);
panel33.add(stateBox = new JComboBox<>(new String[] { Bundle.getMessage("SensorStateActive"), Bundle.getMessage("SensorStateInactive") }));
stateBox.setToolTipText(Bundle.getMessage("LightSensorSenseHint"));
panel33.add(field2a);
panel33.add(field2b);
field2a.setText("00:00");
field2a.setVisible(false);
field2b.setText("0");
field2b.setVisible(false);
panel3.add(panel31);
panel3.add(panel32);
panel3.add(panel33);
Border panel3Border = BorderFactory.createEtchedBorder();
panel3.setBorder(panel3Border);
contentPane.add(panel3);
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout(FlowLayout.TRAILING));
panel5.add(cancelControl = new JButton(Bundle.getMessage("ButtonCancel")));
cancelControl.addActionListener(this::cancelControlPressed);
cancelControl.setToolTipText(Bundle.getMessage("LightCancelButtonHint"));
panel5.add(createControl = new JButton(Bundle.getMessage("ButtonCreate")));
createControl.addActionListener(this::createControlPressed);
createControl.setToolTipText(Bundle.getMessage("LightCreateControlButtonHint"));
panel5.add(updateControl = new JButton(Bundle.getMessage("ButtonUpdate")));
updateControl.addActionListener(this::updateControlPressed);
updateControl.setToolTipText(Bundle.getMessage("LightUpdateControlButtonHint"));
cancelControl.setVisible(true);
updateControl.setVisible(false);
createControl.setVisible(true);
contentPane.add(panel5);
addControlFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelControlPressed(null);
}
});
}
// force GUI status consistent
typeBox.setSelectedIndex(defaultControlIndex);
addControlFrame.pack();
addControlFrame.setVisible(true);
}
Aggregations