Search in sources :

Example 31 with JDialog

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);
}
Also used : JFrame(javax.swing.JFrame) Point(java.awt.Point) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog)

Example 32 with JDialog

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();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Container(java.awt.Container) FlowLayout(java.awt.FlowLayout) JFrame(javax.swing.JFrame) JEditorPane(javax.swing.JEditorPane) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) Point(java.awt.Point) JDialog(javax.swing.JDialog)

Example 33 with JDialog

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);
    }
}
Also used : Window(java.awt.Window) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Preferences(java.util.prefs.Preferences) JDialog(javax.swing.JDialog)

Example 34 with JDialog

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);
}
Also used : JPanel(javax.swing.JPanel) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) BorderLayout(java.awt.BorderLayout) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 35 with JDialog

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);
}
Also used : KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) NamedCompound(org.jabref.gui.undo.NamedCompound) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) Enumeration(java.util.Enumeration) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) Keyword(org.jabref.model.entry.Keyword) BorderLayout(java.awt.BorderLayout) SpecialFieldsUtils(org.jabref.logic.specialfields.SpecialFieldsUtils) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) JabRefGUI(org.jabref.JabRefGUI) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) JScrollPane(javax.swing.JScrollPane) FieldChange(org.jabref.model.FieldChange) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) Optional(java.util.Optional) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) InputMap(javax.swing.InputMap) KeyBinding(org.jabref.gui.keyboard.KeyBinding) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) JList(javax.swing.JList) List(java.util.List) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) Keyword(org.jabref.model.entry.Keyword) ActionMap(javax.swing.ActionMap) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) KeyListener(java.awt.event.KeyListener) InputMap(javax.swing.InputMap) JList(javax.swing.JList) JDialog(javax.swing.JDialog)

Aggregations

JDialog (javax.swing.JDialog)181 JButton (javax.swing.JButton)70 JPanel (javax.swing.JPanel)61 ActionEvent (java.awt.event.ActionEvent)51 ActionListener (java.awt.event.ActionListener)39 JLabel (javax.swing.JLabel)39 JOptionPane (javax.swing.JOptionPane)34 BorderLayout (java.awt.BorderLayout)30 Dimension (java.awt.Dimension)27 JScrollPane (javax.swing.JScrollPane)27 JFrame (javax.swing.JFrame)23 BoxLayout (javax.swing.BoxLayout)21 FlowLayout (java.awt.FlowLayout)19 JCheckBox (javax.swing.JCheckBox)15 AbstractAction (javax.swing.AbstractAction)14 WindowEvent (java.awt.event.WindowEvent)13 JComponent (javax.swing.JComponent)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 WindowAdapter (java.awt.event.WindowAdapter)11 IOException (java.io.IOException)10