Java Code Examples for javax.swing.JOptionPane#getFrameForComponent()

The following examples show how to use javax.swing.JOptionPane#getFrameForComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LanguageTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	if (ADD_ID.equals(e.getActionCommand()))
	{
		Frame frame = JOptionPane.getFrameForComponent(table);
		LanguageChooserFacade chooser = choosers.getElementAt(table.getEditingRow() - languages.getSize());
		LanguageChooserDialog dialog = new LanguageChooserDialog(frame, chooser);
		dialog.setLocationRelativeTo(frame);
		dialog.setVisible(true);
	}
	else
	{
		Language lang = (Language) getValueAt(table.getEditingRow(), 0);
		character.removeLanguage(lang);
	}
	cancelCellEditing();
}
 
Example 2
Source File: EditorPanel.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
public boolean showDialog(Editor e, String titleKey, Component cmp, boolean removeActionButtons) {

    if (removeActionButtons && southComponent != null)
      remove(southComponent);

    attachEditor(e, false);

    EditDialog dlg = new EditDialog(options, titleKey, JOptionPane.getFrameForComponent(cmp));
    dlg.getContentPane().add(this, BorderLayout.CENTER);

    if (northComponent != null) {
      Dimension d = dlg.getContentPane().getPreferredSize();
      d.width = northComponent.getPreferredSize().width;
      setPreferredSize(d);
    }

    dlg.showDialog();
    removeEditor(dlg.result);
    return dlg.result;
  }
 
Example 3
Source File: StandardContentDialog.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form StandardDialog.
 *
 * @param parent Die Komponente, zu der der Dialog zentriert wird
 * @param content der Inhalt
 * @param modal ob der Dialog modal sein soll
 * @param options welche Schaltflächen angezeigt werden sollen
 */
public StandardContentDialog(Component parent,
                             DialogContent content,
                             boolean modal,
                             int options) {
  super(JOptionPane.getFrameForComponent(parent), modal);

  initComponents();
  initButtons(options);

  JComponent component = content.getComponent();

  if (component.getBorder() == null) {
    component.setBorder(new EmptyBorder(4, 4, 4, 4));
  }

  getContentPane().add(component, BorderLayout.CENTER);
  setTitle(content.getDialogTitle());
  content.initFields();
  pack();
  setLocationRelativeTo(parent);
  fContent = content;

  getRootPane().setDefaultButton(okButton);
}
 
Example 4
Source File: RotateFilter.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the inspector for this filter.
 *
 * @return the inspector
 */
public synchronized JDialog getInspector() {
	Inspector myInspector = inspector;
  if (myInspector==null) {
  	myInspector = new Inspector();
  }
  if (myInspector.isModal() && vidPanel!=null) {
    frame = JOptionPane.getFrameForComponent(vidPanel);
    myInspector.setVisible(false);
    myInspector.dispose();
    myInspector = new Inspector();
  }
  inspector = myInspector;
  inspector.initialize();
  return inspector;
}
 
Example 5
Source File: ColorPropertyCellEditor.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
  ResourceBundleUtil bundle = ResourceBundleUtil.getBundle(PROPERTIES_PATH);

  Frame parent = JOptionPane.getFrameForComponent(fTable);
  Color newColor = JColorChooser.showDialog(parent,
                                            bundle.getString("colorPropertyCellEditor.dialog_colorSelection.title"),
                                            fColorProperty.getColor());

  if (newColor != null) {
    Color oldColor = fColorProperty.getColor();
    fColorProperty.setColor(newColor);

    if (newColor != oldColor) {
      fColorProperty.markChanged();
    }
  }

  stopCellEditing();
}
 
Example 6
Source File: ChangePasswordPanel.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows this panel in a modal dialog.
 *
 * @param parent The dialog parent window.
 * @return New password entered by user, otherwise null if the window is closed.
 */
private Optional<String> show(final Window parent) {
  dialog = new JDialog(JOptionPane.getFrameForComponent(parent), "", true);
  dialog.getContentPane().add(this);
  SwingKeyBinding.addKeyBinding(this, KeyCode.ESCAPE, this::close);
  dialog.pack();
  dialog.setLocationRelativeTo(parent);
  dialog.setVisible(true);
  dialog.dispose();
  dialog = null;
  if (!validatePasswordsAndUpdateValidationText()) {
    return Optional.empty();
  }

  final char[] password = passwordField.getPassword();
  if (rememberPassword.isSelected()) {
    ClientSetting.lobbySavedPassword.setValueAndFlush(password);
  } else {
    ClientSetting.lobbySavedPassword.resetValue();
  }
  return Optional.of(Sha512Hasher.hashPasswordWithSalt(String.valueOf(password)));
}
 
Example 7
Source File: DarkGhostFilter.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Implements abstract Filter method.
 *
 * @return the inspector
 */
public synchronized JDialog getInspector() {
	Inspector myInspector = inspector;
  if (myInspector==null) {
  	myInspector = new Inspector();
  }
  if (myInspector.isModal() && vidPanel!=null) {
    frame = JOptionPane.getFrameForComponent(vidPanel);
    myInspector.setVisible(false);
    myInspector.dispose();
    myInspector = new Inspector();
  }
  inspector = myInspector;
  inspector.initialize();
  return inspector;
}
 
Example 8
Source File: Messages.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
public int getFeedback() {
  pack();
  Component cmp = centerOnParent ? parent : JOptionPane.getFrameForComponent(parent);
  if (cmp != null) {
    int pw = cmp.getWidth();
    int ph = cmp.getHeight();
    setLocation((pw - getWidth()) / 2, (ph - getHeight()) / 2);
    setLocationRelativeTo(cmp);
  }
  if (!showDlg(this)) {
    result = CANCEL;
  }
  return result;
}
 
Example 9
Source File: SetMapClientAction.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
public SetMapClientAction(
    final Component parent,
    final IServerStartupRemote serverStartupRemote,
    final Collection<String> games) {
  super("Change Game To");
  this.parent = JOptionPane.getFrameForComponent(parent);
  this.serverStartupRemote = serverStartupRemote;
  this.availableGames = games.stream().sorted().collect(Collectors.toList());
}
 
Example 10
Source File: ChangeToAutosaveClientAction.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
public ChangeToAutosaveClientAction(
    final Component parent,
    final IServerStartupRemote serverStartupRemote,
    final HeadlessAutoSaveType typeOfAutosave) {
  super("Change To " + typeOfAutosave.toString().toLowerCase());
  this.parent = JOptionPane.getFrameForComponent(parent);
  this.serverStartupRemote = serverStartupRemote;
  this.typeOfAutosave = typeOfAutosave;
}
 
Example 11
Source File: CreateAccountPanel.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows this panel in a modal dialog.
 *
 * @param parent The dialog parent window.
 * @return {@link ReturnValue#OK} if the user confirmed that the lobby account should be
 *     created/updated; otherwise {@link ReturnValue#CANCEL}.
 */
public ReturnValue show(final Window parent) {
  dialog = new JDialog(JOptionPane.getFrameForComponent(parent), "", true);
  dialog.getContentPane().add(this);
  SwingKeyBinding.addKeyBinding(dialog, KeyCode.ESCAPE, this::close);
  dialog.pack();
  dialog.setLocationRelativeTo(parent);
  dialog.setVisible(true);
  dialog.dispose();
  dialog = null;
  return returnValue;
}
 
Example 12
Source File: GetGameSaveClientAction.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
  final Frame frame = JOptionPane.getFrameForComponent(parent);
  final File f = SaveGameFileChooser.getSaveGameLocation(frame, gameDataOnStartup);
  if (f != null) {
    final byte[] bytes = serverRemote.getSaveGame();
    try (var fileOutputStream = new FileOutputStream(f)) {
      fileOutputStream.write(bytes);
    } catch (final IOException exception) {
      log.log(Level.SEVERE, "Failed to download save game from server", exception);
    }
    JOptionPane.showMessageDialog(
        frame, "Game Saved", "Game Saved", JOptionPane.INFORMATION_MESSAGE);
  }
}
 
Example 13
Source File: PostLevelUpDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Display the post levelling dialog for a character. This will display a 
 * list of levels just added along with the hit points and skill points 
 * gained. The hit points gained may be edited.
 * 
 * @param parent The component we should appear above.
 * @param character The character that has been levelled up.
 * @param oldLevel The character's level before the level up action.
 */
public static void showPostLevelUpDialog(Component parent, CharacterFacade character, int oldLevel)
{
	int size = character.getCharacterLevelsFacade().getSize();
	if (size - oldLevel + 1 < 1)
	{
		return;
	}

	Frame frame = JOptionPane.getFrameForComponent(parent);
	PostLevelUpDialog dialog = new PostLevelUpDialog(frame, character, oldLevel);
	dialog.setLocationRelativeTo(frame);
	dialog.setVisible(true);
}
 
Example 14
Source File: Messages.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
InputDlg(Component parent, String titleKey, String buttons, JComponent mainComponent, boolean centerOnParent) {
  // 26-jan-06 - Modified to solve bug #73, reported by Jorda Polo
  // Compile error in gcj 4.0.3:
  // "Can't reference 'this' before the superclass constructor has been called."
  // OLD CODE:
  // super(JOptionPane.getFrameForComponent(parent), titleKey!=null ?
  // get(titleKey) : "", true);
  // NEW CODE:
  // Split in two steps:
  // 1 - call super with 'owner' and 'modal' parameters
  // 2 - if 'titleKey' not null, set title
  super(JOptionPane.getFrameForComponent(parent), true);
  if (titleKey != null) {
    setTitle(get(titleKey));
  }
  // --------

  this.parent = parent;
  this.centerOnParent = centerOnParent;

  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  getContentPane().setLayout(new BorderLayout(10, 10));
  if (mainComponent != null) {
    getContentPane().add(mainComponent, BorderLayout.CENTER);
  }
  JButton[] btn = parseJButtons(buttons);
  JPanel btnPanel = new JPanel();
  JButton defaultBtn = null;
  for (JButton b : btn) {
    btnPanel.add(b);
    b.addActionListener(this);
    String cmd = b.getActionCommand();
    if (defaultBtn == null && (BTN_CODES[OK].equals(cmd) || BTN_CODES[YES].equals(cmd))) {
      defaultBtn = b;
    }
  }
  getContentPane().add(btnPanel, BorderLayout.SOUTH);
  if (defaultBtn != null) {
    getRootPane().setDefaultButton(defaultBtn);
  }
}
 
Example 15
Source File: VerifiedRandomNumbersDialog.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
public VerifiedRandomNumbersDialog(final Component parent) {
  super(JOptionPane.getFrameForComponent(parent), "Verified Random Numbers", false);
  init();
  pack();
}
 
Example 16
Source File: ExtendedJDialog.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public ExtendedJDialog(Component owner, String title, boolean modal) {
  this(JOptionPane.getFrameForComponent(owner), title, modal);
}
 
Example 17
Source File: BanPlayerAction.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
public BanPlayerAction(final Component parent, final IServerMessenger messenger) {
  super("Ban Player From Game");
  this.parent = JOptionPane.getFrameForComponent(parent);
  this.messenger = messenger;
}
 
Example 18
Source File: VizController.java    From ontopia with Apache License 2.0 4 votes vote down vote up
private TopicMapIF importTopicMap(TopicMapReaderIF reader, String name) {
  final JOptionPane pane = new JOptionPane(new Object[] { Messages
      .getString("Viz.LoadingTopicMap") + name },
      JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
      new String[] {}, null);

  Frame frame = JOptionPane.getFrameForComponent(vpanel);
  final JDialog dialog = new JDialog(frame, Messages
      .getString("Viz.Information"), true);

  dialog.setContentPane(pane);
  dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
  dialog.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent we) {
      JOptionPane
          .showMessageDialog(pane,
              Messages.getString("Viz.CannotCancelOperation"), 
              Messages.getString("Viz.Information"),
              JOptionPane.INFORMATION_MESSAGE);
    }
  });

  dialog.pack();
  dialog.setLocationRelativeTo(frame);

  TopicMapIF tm;
  final TopicMapReaderIF r = reader;

  final SwingWorker worker = new SwingWorker() {
    @Override
    public Object construct() {
      TopicMapIF result = null;
      try {
        result = r.read();
      } catch (IOException e) {
        dialog.setVisible(false);
        ErrorDialog.showError(vpanel, e.getMessage());
      }
      return result;
    }

    @Override
    public void finished() {
      dialog.setVisible(false);
    }
  };

  worker.start();
  dialog.setVisible(true);
  tm = (TopicMapIF) worker.getValue();
  return tm;
}
 
Example 19
Source File: StandardDialog.java    From openAGV with Apache License 2.0 3 votes vote down vote up
/**
 * Erzeugt ein neues Exemplar von StandardDialog. Die Größe des Dialogs wird
 * an den Inhalt angepasst.
 *
 * @param parent Die Komponente, zu der der Dialog zentriert wird.
 * @param modal True, wenn der Dialog modal sein soll.
 * @param content Der Inhalt des Dialogs neben den beiden Standardbuttons.
 * @param title Der Titel des Dialogs.
 */
public StandardDialog(Component parent, boolean modal, JComponent content, String title) {
  super(JOptionPane.getFrameForComponent(parent), title, modal);
  initComponents();
  initSize(content);
  setTitle(title);
  setIconImages(Icons.getOpenTCSIcons());
}
 
Example 20
Source File: Filter.java    From osp with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the video panel.
 * 
 * @param panel the video panel
 */
public void setVideoPanel(VideoPanel panel) {
	vidPanel = panel;
	frame = vidPanel==null? null: JOptionPane.getFrameForComponent(vidPanel);
}