List of usage examples for javax.swing JDialog getRootPane
@BeanProperty(bound = false, hidden = true, description = "the RootPane object for this dialog.") public JRootPane getRootPane()
From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java
public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }//from w w w . j ava 2 s . c om }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing); }
From source file:com.sshtools.common.ui.OptionsPanel.java
/** * * * @param parent//from ww w. jav a 2 s . com * @param tabs tabs * * @return */ public static boolean showOptionsDialog(Component parent, OptionsTab[] tabs) { final OptionsPanel opts = new OptionsPanel(tabs); opts.reset(); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Options", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Options", true); } else { d = new JDialog((JFrame) null, "Options", true); } final JDialog dialog = d; // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { opts.cancelled = true; dialog.setVisible(false); } }); final JButton ok = new JButton("Ok"); ok.setMnemonic('o'); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (opts.validateTabs()) { dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(ok); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, ok, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(opts, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(true); UIUtil.positionComponent(SwingConstants.CENTER, dialog); dialog.setVisible(true); if (!opts.cancelled) { opts.applyTabs(); } return !opts.cancelled; }
From source file:com.sshtools.common.ui.SshToolsConnectionPanel.java
/** * * * @param parent//from w ww . jav a 2s .c o m * @param profile * @param optionalTabs * * @return */ public static SshToolsConnectionProfile showConnectionDialog(Component parent, SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) { // If no properties are provided, then use the default if (profile == null) { int port = DEFAULT_PORT; String port_S = Integer.toString(DEFAULT_PORT); port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S); try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ")."); } profile = new SshToolsConnectionProfile(); profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, "")); profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port)); profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, "")); } final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true); if (optionalTabs != null) { for (int i = 0; i < optionalTabs.length; i++) { conx.addTab(optionalTabs[i]); } } conx.setConnectionProfile(profile); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Connection Profile", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Connection Profile", true); } else { d = new JDialog((JFrame) null, "Connection Profile", true); } final JDialog dialog = d; class UserAction { boolean connect; } final UserAction userAction = new UserAction(); // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { userAction.connect = false; dialog.setVisible(false); } }); final JButton connect = new JButton("Connect"); connect.setMnemonic('t'); connect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (conx.validateTabs()) { userAction.connect = true; dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(connect); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(conx, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(false); UIUtil.positionComponent(SwingConstants.CENTER, dialog); //show the simple box and act on the answer. SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance(); StringBuffer sb = new StringBuffer(); userAction.connect = !stscp.getHostname(sb, profile.getHost()); boolean advanced = stscp.getAdvanced(); if (advanced) { userAction.connect = false; profile.setHost(sb.toString()); conx.hosttab.setConnectionProfile(profile); dialog.setVisible(true); } // Make sure we didn't cancel if (!userAction.connect) { return null; } conx.applyTabs(); if (!advanced) profile.setHost(sb.toString()); if (!advanced) { int port = DEFAULT_PORT; String port_S = Integer.toString(DEFAULT_PORT); port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S); try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ")."); } profile.setPort(port); } if (!advanced) profile.setUsername(""); PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost()); // only save user inputed configuration if (advanced) { PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername()); PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort()); } // Return the connection properties return profile; }
From source file:es.emergya.ui.base.Message.java
private void inicializar(final String texto) { log.trace("inicializar(" + texto + ")"); final Message message_ = this; SwingUtilities.invokeLater(new Runnable() { @Override// w w w . j av a2 s. c o m public void run() { log.trace("Sacamos un nuevo mensaje: " + texto); JDialog frame = new JDialog(window.getFrame(), true); frame.setUndecorated(true); frame.getContentPane().setBackground(Color.WHITE); frame.setLocation(150, window.getHeight() - 140); frame.setSize(new Dimension(window.getWidth() - 160, 130)); frame.setName("Incoming Message"); frame.setBackground(Color.WHITE); frame.getRootPane().setBorder(new MatteBorder(4, 4, 4, 4, color)); frame.setLayout(new BorderLayout()); if (font != null) frame.setFont(font); JLabel icon = new JLabel(new ImageIcon(this.getClass().getResource("/images/button-ok.png"))); icon.setToolTipText("Cerrar"); icon.removeMouseListener(null); icon.addMouseListener(new Cerrar(frame, message_)); JLabel text = new JLabel(texto); text.setBackground(Color.WHITE); text.setForeground(Color.BLACK); frame.add(text, BorderLayout.WEST); frame.add(icon, BorderLayout.EAST); frame.setVisible(true); } }); }
From source file:idontwant2see.IDontWant2See.java
public ActionMenu getButtonAction() { final ContextMenuAction baseAction = new ContextMenuAction(mLocalizer.msg("name", "I don't want to see!"), createImageIcon("apps", "idontwant2see", 16)); final ContextMenuAction openExclusionList = new ContextMenuAction( mLocalizer.msg("editExclusionList", "Edit exclusion list"), createImageIcon("apps", "idontwant2see", 16)); openExclusionList.putValue(Plugin.BIG_ICON, createImageIcon("apps", "idontwant2see", 22)); openExclusionList.setActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { final Window w = UiUtilities.getLastModalChildOf(getParentFrame()); JDialog temDlg = null; if (w instanceof JDialog) { temDlg = new JDialog((JDialog) w, true); } else { temDlg = new JDialog((JFrame) w, true); }/*from w w w .j av a 2s . c om*/ final JDialog exclusionListDlg = temDlg; exclusionListDlg.setTitle(mLocalizer.msg("name", "I don't want to see!") + " - " + mLocalizer.msg("editExclusionList", "Edit exclusion list")); UiUtilities.registerForClosing(new WindowClosingIf() { public void close() { exclusionListDlg.dispose(); } public JRootPane getRootPane() { return exclusionListDlg.getRootPane(); } }); final ExclusionTablePanel exclusionPanel = new ExclusionTablePanel(mSettings); final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { exclusionPanel.saveSettings(mSettings); exclusionListDlg.dispose(); } }); final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); cancel.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { exclusionListDlg.dispose(); } }); final FormLayout layout = new FormLayout("0dlu:grow,default,3dlu,default", "fill:500px:grow,2dlu,default,5dlu,default"); layout.setColumnGroups(new int[][] { { 2, 4 } }); final CellConstraints cc = new CellConstraints(); final PanelBuilder pb = new PanelBuilder(layout, (JPanel) exclusionListDlg.getContentPane()); pb.setDefaultDialogBorder(); pb.add(exclusionPanel, cc.xyw(1, 1, 4)); pb.addSeparator("", cc.xyw(1, 3, 4)); pb.add(ok, cc.xy(2, 5)); pb.add(cancel, cc.xy(4, 5)); layoutWindow("exclusionListDlg", exclusionListDlg, new Dimension(600, 450)); exclusionListDlg.setVisible(true); } }); final ContextMenuAction undo = new ContextMenuAction( mLocalizer.msg("undoLastExclusion", "Undo last exclusion"), createImageIcon("actions", "edit-undo", 16)); undo.putValue(Plugin.BIG_ICON, createImageIcon("actions", "edit-undo", 22)); undo.setActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { String lastEnteredExclusionString = mSettings.getLastEnteredExclusionString(); if (lastEnteredExclusionString.length() > 0) { for (int i = mSettings.getSearchList().size() - 1; i >= 0; i--) { if (mSettings.getSearchList().get(i).getSearchText().equals(lastEnteredExclusionString)) { mSettings.getSearchList().remove(i); } } mSettings.setLastEnteredExclusionString(""); updateFilter(true); } } }); return new ActionMenu(baseAction, new Action[] { openExclusionList, undo }); }
From source file:net.sf.taverna.t2.workbench.ui.servicepanel.actions.AddServiceProviderAction.java
@Override public void actionPerformed(ActionEvent e) { if (confProvider instanceof CustomizedConfigurePanelProvider) { final CustomizedConfigurePanelProvider provider = (CustomizedConfigurePanelProvider) confProvider; provider.createCustomizedConfigurePanel(new CustomizedConfigureCallBack() { @Override/*from w w w . j a v a 2 s .co m*/ public Configuration getTemplateConfig() { return (Configuration) provider.getConfiguration().clone(); } @Override public ServiceDescriptionRegistry getServiceDescriptionRegistry() { return AddServiceProviderAction.this.getServiceDescriptionRegistry(); } @Override public void newProviderConfiguration(Configuration providerConfig) { addNewProvider(providerConfig); } }); return; } Configuration configuration; try { configuration = (Configuration) confProvider.getConfiguration().clone(); } catch (Exception ex) { throw new RuntimeException("Can't clone configuration bean", ex); } JPanel buildEditor = buildEditor(configuration); String title = "Add " + confProvider.getName(); JDialog dialog = new HelpEnabledDialog(getMainWindow(), title, true, null); JPanel iconPanel = new JPanel(); iconPanel.add(new JLabel(confProvider.getIcon()), NORTH); dialog.add(iconPanel, WEST); dialog.add(buildEditor, CENTER); JPanel buttonPanel = new JPanel(new BorderLayout()); final AddProviderAction addProviderAction = new AddProviderAction(configuration, dialog); JButton addProviderButton = new JButton(addProviderAction); buttonPanel.add(addProviderButton, WEST); dialog.add(buttonPanel, SOUTH); // When user presses "Return" key fire the action on the "Add" button addProviderButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_ENTER) addProviderAction.actionPerformed(null); } }); dialog.getRootPane().setDefaultButton(addProviderButton); // dialog.setSize(buttonPanel.getPreferredSize()); dialog.pack(); dialog.setLocationRelativeTo(owner); // dialog.setLocation(owner.getLocationOnScreen().x + owner.getWidth(), // owner.getLocationOnScreen().y + owner.getHeight()); dialog.setVisible(true); }
From source file:emailplugin.MailCreator.java
/** * Gives the User the opportunity to specify which Desktop he uses (KDE or * Gnome)/*from w ww .j ava2 s .com*/ * * @param parent * Parent Dialog * @return true if KDE or Gnome has been selected, false if the User wanted to * specify the App */ private boolean showKdeGnomeDialog(Frame parent) { final JDialog dialog = new JDialog(parent, true); dialog.setTitle(mLocalizer.msg("chooseTitle", "Choose")); JPanel panel = (JPanel) dialog.getContentPane(); panel.setLayout(new FormLayout("10dlu, fill:pref:grow", "default, 3dlu, default, 3dlu, default, 3dlu, default, 3dlu:grow, default")); panel.setBorder(Borders.DIALOG_BORDER); CellConstraints cc = new CellConstraints(); panel.add(UiUtilities.createHelpTextArea(mLocalizer.msg("cantConfigure", "Can't configure on your system")), cc.xyw(1, 1, 2)); JRadioButton kdeButton = new JRadioButton(mLocalizer.msg("kde", "I am using KDE")); panel.add(kdeButton, cc.xy(2, 3)); JRadioButton gnomeButton = new JRadioButton(mLocalizer.msg("gnome", "I am using Gnome")); panel.add(gnomeButton, cc.xy(2, 5)); JRadioButton selfButton = new JRadioButton(mLocalizer.msg("self", "I want to configure by myself")); panel.add(selfButton, cc.xy(2, 7)); ButtonGroup group = new ButtonGroup(); group.add(kdeButton); group.add(gnomeButton); group.add(selfButton); selfButton.setSelected(true); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(ok); panel.add(buttonPanel, cc.xy(2, 9)); UiUtilities.registerForClosing(new WindowClosingIf() { public void close() { dialog.setVisible(false); } public JRootPane getRootPane() { return dialog.getRootPane(); } }); dialog.getRootPane().setDefaultButton(ok); dialog.pack(); UiUtilities.centerAndShow(dialog); if (kdeButton.isSelected()) { mSettings.setApplication("kfmclient"); mSettings.setParameter("exec {content}"); } else if (gnomeButton.isSelected()) { mSettings.setApplication("gnome-open"); mSettings.setParameter("{content}"); } else { Plugin.getPluginManager().showSettings(mPlugin); return false; } return true; }
From source file:emailplugin.MailCreator.java
/** * Show the EMail-Open Dialog.// ww w. j a v a 2 s.c o m * * This Dialog says that the EMail should have been opened. It gives the User * a chance to specify another EMail Program if it went wrong. * * @param parent * Parent-Frame */ private void showEMailOpenedDialog(Frame parent) { final JDialog dialog = new JDialog(parent, true); dialog.setTitle(mLocalizer.msg("EMailOpenedTitel", "Email was opened")); JPanel panel = (JPanel) dialog.getContentPane(); panel.setLayout(new FormLayout("fill:200dlu:grow", "default, 3dlu, default, 3dlu, default")); panel.setBorder(Borders.DIALOG_BORDER); CellConstraints cc = new CellConstraints(); panel.add(UiUtilities.createHelpTextArea(mLocalizer.msg("EMailOpened", "Email was opened. Configure it?")), cc.xy(1, 1)); final JCheckBox dontShowAgain = new JCheckBox( mLocalizer.msg("DontShowAgain", "Don't show this Dialog again")); panel.add(dontShowAgain, cc.xy(1, 3)); JButton configure = new JButton(mLocalizer.msg("configure", "Configure")); configure.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Plugin.getPluginManager().showSettings(mPlugin); dialog.setVisible(false); } }); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (dontShowAgain.isSelected()) { mSettings.setShowEmailOpened(false); } dialog.setVisible(false); } }); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(configure); buttonPanel.add(ok); panel.add(buttonPanel, cc.xy(1, 5)); UiUtilities.registerForClosing(new WindowClosingIf() { public void close() { dialog.setVisible(false); } public JRootPane getRootPane() { return dialog.getRootPane(); } }); dialog.getRootPane().setDefaultButton(ok); dialog.pack(); UiUtilities.centerAndShow(dialog); }
From source file:edu.umich.robot.GuiApplication.java
public void createSuperdroidRobotDialog() { final Pose pose = new Pose(); FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu", "pref, 2dlu, pref, 2dlu, pref"); layout.setRowGroups(new int[][] { { 1, 3 } }); final JDialog dialog = new JDialog(frame, "Create Superdroid Robot", true); dialog.setLayout(layout);/* w ww. j a v a 2s. co m*/ final JTextField name = new JTextField(); final JTextField x = new JTextField(Double.toString((pose.getX()))); final JTextField y = new JTextField(Double.toString((pose.getY()))); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(name, cc.xyw(3, 1, 5)); dialog.add(new JLabel("x"), cc.xy(1, 3)); dialog.add(x, cc.xy(3, 3)); dialog.add(new JLabel("y"), cc.xy(5, 3)); dialog.add(y, cc.xy(7, 3)); dialog.add(cancel, cc.xyw(1, 5, 3)); dialog.add(ok, cc.xyw(5, 5, 3)); x.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setX(Double.parseDouble(x.getText())); } catch (NumberFormatException ex) { x.setText(Double.toString(pose.getX())); } } }); y.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setY(Double.parseDouble(y.getText())); } catch (NumberFormatException ex) { y.setText(Double.toString(pose.getX())); } } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = name.getText().trim(); if (robotName.isEmpty()) { logger.error("Create Superdroid: robot name empty"); return; } for (char c : robotName.toCharArray()) if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create Superdroid: illegal robot name"); return; } controller.createSuperdroidRobot(robotName, pose, true); controller.createSimSuperdroid(robotName); dialog.dispose(); } }; name.addActionListener(okListener); x.addActionListener(okListener); y.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }
From source file:edu.umich.robot.GuiApplication.java
/** * <p>/*www . j ava2 s. c o m*/ * Pops up a window to create a new splinter robot to add to the simulation. */ public void createSplinterRobotDialog() { final Pose pose = new Pose(); FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu", "pref, 2dlu, pref, 2dlu, pref"); layout.setRowGroups(new int[][] { { 1, 3 } }); final JDialog dialog = new JDialog(frame, "Create Splinter Robot", true); dialog.setLayout(layout); final JTextField name = new JTextField(); final JTextField x = new JTextField(Double.toString((pose.getX()))); final JTextField y = new JTextField(Double.toString((pose.getY()))); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(name, cc.xyw(3, 1, 5)); dialog.add(new JLabel("x"), cc.xy(1, 3)); dialog.add(x, cc.xy(3, 3)); dialog.add(new JLabel("y"), cc.xy(5, 3)); dialog.add(y, cc.xy(7, 3)); dialog.add(cancel, cc.xyw(1, 5, 3)); dialog.add(ok, cc.xyw(5, 5, 3)); x.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setX(Double.parseDouble(x.getText())); } catch (NumberFormatException ex) { x.setText(Double.toString(pose.getX())); } } }); y.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setY(Double.parseDouble(y.getText())); } catch (NumberFormatException ex) { y.setText(Double.toString(pose.getX())); } } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = name.getText().trim(); if (robotName.isEmpty()) { logger.error("Create splinter: robot name empty"); return; } for (char c : robotName.toCharArray()) if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create splinter: illegal robot name"); return; } controller.createSplinterRobot(robotName, pose, true); controller.createSimSplinter(robotName); controller.createSimLaser(robotName); dialog.dispose(); } }; name.addActionListener(okListener); x.addActionListener(okListener); y.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }