use of javax.swing.JRootPane in project com.revolsys.open by revolsys.
the class ValueField method showDialog.
@SuppressWarnings("unchecked")
public <V> V showDialog(final Component parent) {
Window window;
if (parent == null) {
window = SwingUtil.getActiveWindow();
} else if (parent instanceof Window) {
window = (Window) parent;
} else {
window = SwingUtilities.windowForComponent(parent);
}
final JDialog dialog = new JDialog(window, this.title, ModalityType.APPLICATION_MODAL);
if (this.iconImage != null) {
dialog.setIconImage(this.iconImage);
}
dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
dialog.setLayout(new BorderLayout());
dialog.addKeyListener(new KeyListener() {
@Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
cancel(dialog);
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
save(dialog);
}
}
@Override
public void keyReleased(final KeyEvent e) {
}
@Override
public void keyTyped(final KeyEvent e) {
}
});
dialog.add(this, BorderLayout.CENTER);
final JRootPane rootPane = dialog.getRootPane();
final InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
final ActionMap actionMap = rootPane.getActionMap();
final JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final Runnable cancelRunnable = () -> cancel(dialog);
buttons.add(RunnableAction.newButton("Cancel", cancelRunnable));
final KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
inputMap.put(escapeStroke, "cancel");
actionMap.put("cancel", new RunnableAction(cancelRunnable));
final Runnable saveRunnable = () -> save(dialog);
buttons.add(RunnableAction.newButton("OK", saveRunnable));
dialog.add(buttons, BorderLayout.SOUTH);
final KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
inputMap.put(enterStroke, "save");
actionMap.put("save", new RunnableAction(saveRunnable));
dialog.pack();
SwingUtil.autoAdjustPosition(window, dialog);
this.saved = false;
dialog.setVisible(true);
final V value = (V) getFieldValue();
SwingUtil.dispose(dialog);
return value;
}
use of javax.swing.JRootPane in project LAN-Messenger by harshitbudhraja.
the class Messaging method messagefieldFocusGained.
// GEN-LAST:event_sendbuttonActionPerformed
private void messagefieldFocusGained(java.awt.event.FocusEvent evt) {
// GEN-FIRST:event_messagefieldFocusGained
// TODO add your handling code here:
JRootPane rootPane = SwingUtilities.getRootPane(sendbutton);
rootPane.setDefaultButton(sendbutton);
}
use of javax.swing.JRootPane in project opennars by opennars.
the class DockingRegionContainer method hideDragControl.
void hideDragControl() {
// System.err.println("hideDragControl()");
JRootPane rootPane = getRootPane();
rootPane.setGlassPane(oldGlass);
oldGlass = null;
// overlayPanel = null;
rootPane.revalidate();
rootPane.repaint();
}
use of javax.swing.JRootPane in project chatty by chatty.
the class GuiUtil method installEscapeCloseOperation.
public static void installEscapeCloseOperation(final JDialog dialog) {
Action closingAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
}
};
JRootPane root = dialog.getRootPane();
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_STROKE, CLOSE_DIALOG_ACTION_MAP_KEY);
root.getActionMap().put(CLOSE_DIALOG_ACTION_MAP_KEY, closingAction);
}
use of javax.swing.JRootPane in project freeplane by freeplane.
the class EditNodeWYSIWYG method createHtmlEditor.
public HTMLDialog createHtmlEditor(final RootPaneContainer frame) throws Exception {
final JRootPane rootPane = ((RootPaneContainer) frame).getRootPane();
HTMLDialog htmlEditorWindow = (HTMLDialog) rootPane.getClientProperty(HTMLDialog.class);
if (htmlEditorWindow == null) {
htmlEditorWindow = new HTMLDialog(this, "", "", frame);
rootPane.putClientProperty(HTMLDialog.class, htmlEditorWindow);
// make sure that SHTML gets notified of relevant config changes!
ResourceController.getResourceController().addPropertyChangeListener(new FreeplaneToSHTMLPropertyChangeAdapter(htmlEditorWindow.getHtmlEditorPanel()));
}
return htmlEditorWindow;
}
Aggregations