use of javax.swing.JDialog in project jmeter by apache.
the class AboutCommand method about.
/**
* Called by about button. Raises about dialog. Currently the about box has
* the product image and the copyright notice. The dialog box is centered
* over the MainFrame.
*/
void about() {
JFrame mainFrame = GuiPackage.getInstance().getMainFrame();
JDialog dialog = initDialog(mainFrame);
// NOTE: these lines center the about dialog in the current window.
Point p = mainFrame.getLocationOnScreen();
Dimension d1 = mainFrame.getSize();
Dimension d2 = dialog.getSize();
dialog.setLocation(p.x + (d1.width - d2.width) / 2, p.y + (d1.height - d2.height) / 2);
dialog.pack();
dialog.setVisible(true);
}
use of javax.swing.JDialog in project jmeter by apache.
the class TextBoxDialoger method createDialogBox.
private void createDialogBox() {
JFrame mainFrame = GuiPackage.getInstance().getMainFrame();
String title = //$NON-NLS-1$
editable ? //$NON-NLS-1$
JMeterUtils.getResString("textbox_title_edit") : //$NON-NLS-1$
JMeterUtils.getResString("textbox_title_view");
// modal dialog box
dialog = new JDialog(mainFrame, title, true);
// Close action dialog box when tapping Escape key
JPanel content = (JPanel) dialog.getContentPane();
content.registerKeyboardAction(this, KeyStrokes.ESC, JComponent.WHEN_IN_FOCUSED_WINDOW);
textBox = new JEditorPane();
textBox.setEditable(editable);
JScrollPane textBoxScrollPane = GuiUtils.makeScrollPane(textBox);
JPanel btnBar = new JPanel();
btnBar.setLayout(new FlowLayout(FlowLayout.RIGHT));
if (editable) {
//$NON-NLS-1$
JButton cancelBtn = new JButton(JMeterUtils.getResString("textbox_cancel"));
cancelBtn.setActionCommand(CANCEL_COMMAND);
cancelBtn.addActionListener(this);
//$NON-NLS-1$
JButton saveBtn = new JButton(JMeterUtils.getResString("textbox_save_close"));
saveBtn.setActionCommand(SAVE_CLOSE_COMMAND);
saveBtn.addActionListener(this);
btnBar.add(cancelBtn);
btnBar.add(saveBtn);
} else {
//$NON-NLS-1$
JButton closeBtn = new JButton(JMeterUtils.getResString("textbox_close"));
closeBtn.setActionCommand(CLOSE_COMMAND);
closeBtn.addActionListener(this);
btnBar.add(closeBtn);
}
// Prepare dialog box
Container panel = dialog.getContentPane();
dialog.setMinimumSize(new Dimension(400, 250));
panel.add(textBoxScrollPane, BorderLayout.CENTER);
panel.add(btnBar, BorderLayout.SOUTH);
// determine location on screen
Point p = mainFrame.getLocationOnScreen();
Dimension d1 = mainFrame.getSize();
Dimension d2 = dialog.getSize();
dialog.setLocation(p.x + (d1.width - d2.width) / 2, p.y + (d1.height - d2.height) / 2);
dialog.pack();
}
use of javax.swing.JDialog in project jgnash by ccavanaugh.
the class DialogUtils method addBoundsListener.
/**
* Listens to a JDialog to save and restore windows bounds automatically.
* <p>
* {@code setVisible(false)} and {@code dispose()} must not be used
* to close the window. Instead, dispatch a window closing event.
* <PRE>
* dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
* </PRE>
* and the dialog must be set to dispose on close
* <PRE>
* setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
* </PRE>
*
* @param w {@code Window} to listen to
* @param prefNode String identifier to preference node to save and restore from
* @param key the key to save and restore from
*/
private static void addBoundsListener(final Window w, final String prefNode, final String key) {
String bounds = Preferences.userRoot().node(prefNode).get(key, null);
if (bounds != null) {
if (w instanceof JDialog) {
if (((JDialog) w).isResizable()) {
w.setBounds(decodeRectangle(bounds));
} else {
w.setLocation(decodeRectangle(bounds).getLocation());
}
} else {
w.setBounds(decodeRectangle(bounds));
}
Window owner = w.getOwner();
if (owner != null) {
w.setLocationRelativeTo(owner);
}
}
/* listen for a window closing event and deal with it */
w.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
// save position and size
Preferences p = Preferences.userRoot().node(prefNode);
p.put(key, encodeRectangle(w.getBounds()));
// make GC easy
w.removeWindowListener(this);
}
});
if (w instanceof JDialog) {
addEscapeListener((JDialog) w);
}
}
use of javax.swing.JDialog in project jabref by JabRef.
the class BibtexKeyPatternDialog method init.
private void init() {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(bibtexKeyPatternPanel, BorderLayout.CENTER);
JButton ok = new JButton(Localization.lang("OK"));
// label of "cancel" is set later as the label is overwritten by assigning an action to the button
JButton cancel = new JButton();
JPanel lower = new JPanel();
lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
ButtonBarBuilder bb = new ButtonBarBuilder(lower);
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
getContentPane().add(lower, BorderLayout.SOUTH);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setPreferredSize(new Dimension(500, 600));
pack();
ok.addActionListener(e -> {
metaData.setCiteKeyPattern(bibtexKeyPatternPanel.getKeyPatternAsDatabaseBibtexKeyPattern());
panel.markNonUndoableBaseChanged();
dispose();
});
final JDialog dialog = this;
Action cancelAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
}
};
cancel.setAction(cancelAction);
cancel.setText(Localization.lang("Cancel"));
KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);
}
use of javax.swing.JDialog in project jabref by JabRef.
the class ManageKeywordsAction method createDialog.
private void createDialog() {
if (diag != null) {
return;
}
// keyword to add
JTextField keyword = new JTextField();
keywordListModel = new DefaultListModel<>();
JList<Keyword> keywordList = new JList<>(keywordListModel);
keywordList.setVisibleRowCount(8);
JScrollPane kPane = new JScrollPane(keywordList);
diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
JButton add = new JButton(Localization.lang("Add"));
JButton remove = new JButton(Localization.lang("Remove"));
keywordList.setVisibleRowCount(10);
intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
ButtonGroup group = new ButtonGroup();
group.add(intersectKeywords);
group.add(mergeKeywords);
ActionListener stateChanged = e -> fillKeyWordList();
intersectKeywords.addActionListener(stateChanged);
mergeKeywords.addActionListener(stateChanged);
intersectKeywords.setSelected(true);
FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
builder.add(intersectKeywords).xyw(1, 3, 3);
builder.add(mergeKeywords).xyw(1, 5, 3);
builder.add(kPane).xywh(1, 7, 1, 3);
builder.add(remove).xy(3, 9);
builder.add(keyword).xy(1, 11);
builder.add(add).xy(3, 11);
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
ok.addActionListener(e -> {
canceled = false;
diag.dispose();
});
Action cancelAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
canceled = true;
diag.dispose();
}
};
cancel.addActionListener(cancelAction);
final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
add.addActionListener(addActionListener);
final ActionListener removeActionListenter = arg0 -> {
List<Keyword> values = keywordList.getSelectedValuesList();
for (Keyword val : values) {
keywordListModel.removeElement(val);
}
};
remove.addActionListener(removeActionListenter);
keywordList.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent arg0) {
// Do nothing
}
@Override
public void keyReleased(KeyEvent arg0) {
// Do nothing
}
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
removeActionListenter.actionPerformed(null);
}
}
});
AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
AutoCompleteListener acl = new AutoCompleteListener(autoComp);
keyword.addKeyListener(acl);
keyword.addFocusListener(acl);
keyword.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
// Do nothing
}
@Override
public void keyReleased(KeyEvent e) {
// Do nothing
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
addActionListener.actionPerformed(null);
}
}
});
// Key bindings:
ActionMap am = builder.getPanel().getActionMap();
InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", cancelAction);
diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
Aggregations