use of javax.swing.JRootPane in project omegat by omegat-org.
the class ScriptingWindow method addRunShortcutToOmegaT.
private void addRunShortcutToOmegaT() {
JRootPane appliRootPane = Core.getMainWindow().getApplicationFrame().getRootPane();
appliRootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK, false), "RUN_CURRENT_SCRIPT");
appliRootPane.getActionMap().put("RUN_CURRENT_SCRIPT", new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
runScript();
}
});
}
use of javax.swing.JRootPane in project jabref by JabRef.
the class FindUnlinkedFilesDialog method createRootPane.
/**
* Close dialog when pressing escape
*/
@Override
protected JRootPane createRootPane() {
ActionListener actionListener = actionEvent -> setVisible(false);
JRootPane rPane = new JRootPane();
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
return rPane;
}
use of javax.swing.JRootPane in project JMRI by JMRI.
the class JmriJFrame method setEscapeKeyAction.
/**
* Bind an action to the Escape key.
* <p>
* Binds an AbstractAction to the Escape key. If an action is already bound
* to the Escape key, that action will be replaced. Passing
* <code>null</code> unbinds any existing actions from the Escape key.
* <p>
* Note that binding the Escape key to any action may break expected or
* standardized behaviors. See <a
* href="http://java.sun.com/products/jlf/ed2/book/Appendix.A.html">Keyboard
* Shortcuts, Mnemonics, and Other Keyboard Operations</a> in the Java Look
* and Feel Design Guidelines for standardized behaviors.
*
* @param action The AbstractAction to bind to.
* @see #getEscapeKeyAction()
* @see #setEscapeKeyClosesWindow(boolean)
*/
public void setEscapeKeyAction(AbstractAction action) {
JRootPane root = this.getRootPane();
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
// setEscapeKeyClosesWindow will set to true as needed
escapeKeyActionClosesWindow = false;
if (action != null) {
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, escapeKeyAction);
root.getActionMap().put(escapeKeyAction, action);
} else {
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(escape);
root.getActionMap().remove(escapeKeyAction);
}
}
use of javax.swing.JRootPane in project JMRI by JMRI.
the class LayoutTurnout method editLayoutTurnout.
/**
* Edit a Layout Turnout
*/
protected void editLayoutTurnout() {
if (editOpen) {
editLayoutTurnoutFrame.setVisible(true);
return;
}
// Initialize if needed
if (editLayoutTurnoutFrame == null) {
editLayoutTurnoutFrame = new JmriJFrame(rb.getString("EditTurnout"), false, true);
editLayoutTurnoutFrame.addHelpMenu("package.jmri.jmrit.display.EditLayoutTurnout", true);
editLayoutTurnoutFrame.setLocation(50, 30);
Container contentPane = editLayoutTurnoutFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// setup turnout name
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
JLabel turnoutNameLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanNameTurnout")));
panel1.add(turnoutNameLabel);
// add combobox to select turnout
firstTurnoutComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getTurnout(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
layoutEditor.setupComboBox(firstTurnoutComboBox, true, true);
panel1.add(firstTurnoutComboBox);
contentPane.add(panel1);
JPanel panel1a = new JPanel();
panel1a.setLayout(new BoxLayout(panel1a, BoxLayout.Y_AXIS));
secondTurnoutComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getSecondTurnout(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
layoutEditor.setupComboBox(secondTurnoutComboBox, true, false);
additionalTurnout.addActionListener((ActionEvent e) -> {
if (additionalTurnout.isSelected()) {
secondTurnoutLabel.setEnabled(true);
secondTurnoutComboBox.setEnabled(true);
} else {
secondTurnoutLabel.setEnabled(false);
secondTurnoutComboBox.setEnabled(false);
}
});
if ((type != DOUBLE_XOVER) && (type != RH_XOVER) && (type != LH_XOVER)) {
additionalTurnout.setText(rb.getString("ThrowTwoTurnouts"));
}
panel1a.add(additionalTurnout);
contentPane.add(panel1a);
secondTurnoutLabel = new JLabel(Bundle.getMessage("Supporting", Bundle.getMessage("BeanNameTurnout")));
secondTurnoutLabel.setEnabled(false);
secondTurnoutComboBox.setEnabled(false);
JPanel panel1b = new JPanel();
panel1b.add(secondTurnoutLabel);
panel1b.add(secondTurnoutComboBox);
contentPane.add(panel1b);
// add continuing state choice, if not crossover
if ((type != DOUBLE_XOVER) && (type != RH_XOVER) && (type != LH_XOVER)) {
JPanel panel3 = new JPanel();
panel3.setLayout(new FlowLayout());
stateBox.removeAllItems();
stateBox.addItem(InstanceManager.turnoutManagerInstance().getClosedText());
turnoutClosedIndex = 0;
stateBox.addItem(InstanceManager.turnoutManagerInstance().getThrownText());
turnoutThrownIndex = 1;
stateBox.setToolTipText(rb.getString("StateToolTip"));
panel3.add(new JLabel(rb.getString("ContinuingState")));
panel3.add(stateBox);
contentPane.add(panel3);
}
JPanel panel33 = new JPanel();
panel33.setLayout(new FlowLayout());
hiddenBox.setToolTipText(rb.getString("HiddenToolTip"));
panel33.add(hiddenBox);
contentPane.add(panel33);
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
border.setTitle(Bundle.getMessage("BeanNameBlock"));
// setup block name
JPanel panel2 = new JPanel();
panel2.setBorder(border);
panel2.setLayout(new FlowLayout());
panel2.add(blockNameComboBox);
layoutEditor.setupComboBox(blockNameComboBox, false, true);
blockNameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
panel2.add(turnoutEditBlock = new JButton(rb.getString("CreateEdit")));
turnoutEditBlock.addActionListener((ActionEvent e) -> {
turnoutEditBlockPressed(e);
});
contentPane.add(panel2);
if ((type == DOUBLE_XOVER) || (type == RH_XOVER) || (type == LH_XOVER)) {
JPanel panel21 = new JPanel();
panel21.setLayout(new FlowLayout());
TitledBorder borderblk2 = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
borderblk2.setTitle(Bundle.getMessage("BeanNameBlock") + " 2");
panel21.setBorder(borderblk2);
layoutEditor.setupComboBox(blockBNameComboBox, false, true);
blockBNameComboBox.setToolTipText(rb.getString("EditBlockBNameHint"));
panel21.add(blockBNameComboBox);
panel21.add(turnoutEditBlockB = new JButton(rb.getString("CreateEdit")));
turnoutEditBlockB.addActionListener((ActionEvent e) -> {
turnoutEditBlockBPressed(e);
});
turnoutEditBlockB.setToolTipText(Bundle.getMessage("EditBlockHint", "2"));
contentPane.add(panel21);
JPanel panel22 = new JPanel();
panel22.setLayout(new FlowLayout());
TitledBorder borderblk3 = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
borderblk3.setTitle(Bundle.getMessage("BeanNameBlock") + " 3");
panel22.setBorder(borderblk3);
layoutEditor.setupComboBox(blockCNameComboBox, false, true);
blockCNameComboBox.setToolTipText(rb.getString("EditBlockCNameHint"));
panel22.add(blockCNameComboBox);
panel22.add(turnoutEditBlockC = new JButton(rb.getString("CreateEdit")));
turnoutEditBlockC.addActionListener((ActionEvent e) -> {
turnoutEditBlockCPressed(e);
});
turnoutEditBlockC.setToolTipText(Bundle.getMessage("EditBlockHint", "3"));
contentPane.add(panel22);
JPanel panel23 = new JPanel();
panel23.setLayout(new FlowLayout());
TitledBorder borderblk4 = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
borderblk4.setTitle(Bundle.getMessage("BeanNameBlock") + " 4");
panel23.setBorder(borderblk4);
layoutEditor.setupComboBox(blockDNameComboBox, false, true);
blockDNameComboBox.setToolTipText(rb.getString("EditBlockDNameHint"));
panel23.add(blockDNameComboBox);
panel23.add(turnoutEditBlockD = new JButton(rb.getString("CreateEdit")));
turnoutEditBlockD.addActionListener((ActionEvent e) -> {
turnoutEditBlockDPressed(e);
});
turnoutEditBlockD.setToolTipText(Bundle.getMessage("EditBlockHint", "4"));
contentPane.add(panel23);
}
// set up Edit Block, Done and Cancel buttons
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
// Edit Block
// empty value for block 1
turnoutEditBlock.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
// Done
panel5.add(turnoutEditDone = new JButton(Bundle.getMessage("ButtonDone")));
// make this button the default button (return or enter activates)
// Note: We have to invoke this later because we don't currently have a root pane
SwingUtilities.invokeLater(() -> {
JRootPane rootPane = SwingUtilities.getRootPane(turnoutEditDone);
rootPane.setDefaultButton(turnoutEditDone);
});
turnoutEditDone.addActionListener((ActionEvent e) -> {
turnoutEditDonePressed(e);
});
turnoutEditDone.setToolTipText(Bundle.getMessage("DoneHint", Bundle.getMessage("ButtonDone")));
// Cancel
panel5.add(turnoutEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
turnoutEditCancel.addActionListener((ActionEvent e) -> {
turnoutEditCancelPressed(e);
});
turnoutEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
contentPane.add(panel5);
}
hiddenBox.setSelected(hidden);
// Set up for Edit
blockNameComboBox.getEditor().setItem(blockName);
if ((type == DOUBLE_XOVER) || (type == RH_XOVER) || (type == LH_XOVER)) {
blockBNameComboBox.getEditor().setItem(blockBName);
blockCNameComboBox.getEditor().setItem(blockCName);
blockDNameComboBox.getEditor().setItem(blockDName);
}
firstTurnoutComboBox.setSelectedItem(turnoutName);
if (secondNamedTurnout != null) {
additionalTurnout.setSelected(true);
secondTurnoutLabel.setEnabled(true);
secondTurnoutComboBox.setEnabled(true);
}
if ((type != DOUBLE_XOVER) && (type != RH_XOVER) && (type != LH_XOVER)) {
if (continuingSense == Turnout.CLOSED) {
stateBox.setSelectedIndex(turnoutClosedIndex);
} else {
stateBox.setSelectedIndex(turnoutThrownIndex);
}
}
editLayoutTurnoutFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
turnoutEditCancelPressed(null);
}
});
editLayoutTurnoutFrame.pack();
editLayoutTurnoutFrame.setVisible(true);
editOpen = true;
needsBlockUpdate = false;
}
use of javax.swing.JRootPane in project JMRI by JMRI.
the class LayoutTurntable method editTurntable.
/**
* Edit a Turntable
*/
protected void editTurntable(LayoutTurntable x) {
if (editOpen) {
editTurntableFrame.setVisible(true);
return;
}
needsRedraw = false;
// Initialize if needed
if (editTurntableFrame == null) {
editTurntableFrame = new JmriJFrame(rb.getString("EditTurntable"), false, true);
editTurntableFrame.addHelpMenu("package.jmri.jmrit.display.EditTurntable", true);
editTurntableFrame.setLocation(50, 30);
Container contentPane = editTurntableFrame.getContentPane();
JPanel headerPane = new JPanel();
JPanel footerPane = new JPanel();
headerPane.setLayout(new BoxLayout(headerPane, BoxLayout.Y_AXIS));
footerPane.setLayout(new BoxLayout(footerPane, BoxLayout.Y_AXIS));
contentPane.setLayout(new BorderLayout());
contentPane.add(headerPane, BorderLayout.NORTH);
contentPane.add(footerPane, BorderLayout.SOUTH);
// setup radius
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
JLabel radiusLabel = new JLabel(rb.getString("TurntableRadius"));
panel1.add(radiusLabel);
panel1.add(radiusField);
radiusField.setToolTipText(rb.getString("TurntableRadiusHint"));
headerPane.add(panel1);
// setup add ray track
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
JLabel rayAngleLabel = new JLabel(rb.getString("RayAngle"));
panel2.add(rayAngleLabel);
panel2.add(angleField);
angleField.setToolTipText(rb.getString("RayAngleHint"));
headerPane.add(panel2);
JPanel panel3 = new JPanel();
panel3.setLayout(new FlowLayout());
panel3.add(addRayTrack = new JButton(rb.getString("AddRayTrack")));
addRayTrack.setToolTipText(rb.getString("AddRayTrackHint"));
addRayTrack.addActionListener((ActionEvent e) -> {
addRayTrackPressed(e);
updateRayPanel();
});
panel3.add(dccControlled = new JCheckBox(rb.getString("TurntableDCCControlled")));
dccControlled.setSelected(isTurnoutControlled());
dccControlled.addActionListener((ActionEvent e) -> {
setTurnoutControlled(dccControlled.isSelected());
for (RayTrack rt : rayList) {
rt.showTurnoutDetails();
}
editTurntableFrame.pack();
});
headerPane.add(panel3);
// set up Done and Cancel buttons
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
panel5.add(turntableEditDone = new JButton(Bundle.getMessage("ButtonDone")));
turntableEditDone.addActionListener((ActionEvent e) -> {
turntableEditDonePressed(e);
});
// make this button the default button (return or enter activates)
// Note: We have to invoke this later because we don't currently have a root pane
SwingUtilities.invokeLater(() -> {
JRootPane rootPane = SwingUtilities.getRootPane(turntableEditDone);
rootPane.setDefaultButton(turntableEditDone);
});
turntableEditDone.setToolTipText(Bundle.getMessage("DoneHint", Bundle.getMessage("ButtonDone")));
// Cancel
panel5.add(turntableEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
turntableEditCancel.addActionListener((ActionEvent e) -> {
turntableEditCancelPressed(e);
});
turntableEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
footerPane.add(panel5);
rayPanel = new JPanel();
rayPanel.setLayout(new BoxLayout(rayPanel, BoxLayout.Y_AXIS));
for (RayTrack rt : rayList) {
rayPanel.add(rt.getPanel());
}
JScrollPane rayScrollPane = new JScrollPane(rayPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
contentPane.add(rayScrollPane, BorderLayout.CENTER);
} else {
updateRayPanel();
}
// Set up for Edit
radiusField.setText(" " + radius);
oldRadius = radiusField.getText();
angleField.setText("0");
editTurntableFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
turntableEditCancelPressed(null);
}
});
editTurntableFrame.pack();
editTurntableFrame.setVisible(true);
editOpen = true;
}
Aggregations