Search in sources :

Example 6 with WindowLocation

use of org.jabref.gui.util.WindowLocation in project jabref by JabRef.

the class ProtectedTermsDialog method init.

private void init() {
    setupPopupMenu();
    loadButton.addActionListener(actionEvent -> {
        AddFileDialog addDialog = new AddFileDialog();
        addDialog.setVisible(true);
        addDialog.getFileName().ifPresent(fileName -> loader.addProtectedTermsListFromFile(fileName, true));
        tableModel.fireTableDataChanged();
    });
    loadButton.setToolTipText(Localization.lang("Add protected terms file"));
    removeButton.addActionListener(removeAction);
    removeButton.setToolTipText(Localization.lang("Remove protected terms file"));
    newButton.addActionListener(actionEvent -> {
        NewProtectedTermsFileDialog newDialog = new NewProtectedTermsFileDialog(diag, loader);
        newDialog.setVisible(true);
        tableModel.fireTableDataChanged();
    });
    newButton.setToolTipText(Localization.lang("New protected terms file"));
    setupTable();
    // Build dialog
    diag = new JDialog(frame, Localization.lang("Manage protected terms files"), true);
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref, 4dlu, left:pref", "100dlu:grow, 4dlu, pref"));
    builder.add(new JScrollPane(table)).xyw(1, 1, 7);
    builder.add(newButton).xy(3, 3);
    builder.add(loadButton).xy(5, 3);
    builder.add(removeButton).xy(7, 3);
    builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
    diag.add(builder.getPanel(), BorderLayout.CENTER);
    AbstractAction okListener = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // Write changes to preferences
            storePreferences();
            diag.dispose();
        }
    };
    ok.addActionListener(okListener);
    Action cancelListener = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // Restore from preferences
            loader.update(Globals.prefs.getProtectedTermsPreferences());
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelListener);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.add(bb.getPanel(), BorderLayout.SOUTH);
    ActionMap am = bb.getPanel().getActionMap();
    InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelListener);
    im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk");
    am.put("enterOk", okListener);
    diag.pack();
    WindowLocation pw = new WindowLocation(diag, JabRefPreferences.TERMS_POS_X, JabRefPreferences.TERMS_POS_Y, JabRefPreferences.TERMS_SIZE_X, JabRefPreferences.TERMS_SIZE_Y);
    pw.displayWindowAtStoredLocation();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) FormBuilder(com.jgoodies.forms.builder.FormBuilder) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) InputMap(javax.swing.InputMap) WindowLocation(org.jabref.gui.util.WindowLocation) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Aggregations

WindowLocation (org.jabref.gui.util.WindowLocation)6 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)4 FormLayout (com.jgoodies.forms.layout.FormLayout)4 JButton (javax.swing.JButton)3 FormBuilder (com.jgoodies.forms.builder.FormBuilder)2 ActionEvent (java.awt.event.ActionEvent)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 AbstractAction (javax.swing.AbstractAction)2 Action (javax.swing.Action)2 ActionMap (javax.swing.ActionMap)2 InputMap (javax.swing.InputMap)2 JDialog (javax.swing.JDialog)2 JScrollPane (javax.swing.JScrollPane)2 JSeparator (javax.swing.JSeparator)2 NamedCompound (org.jabref.gui.undo.NamedCompound)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PreviewPanel (org.jabref.gui.PreviewPanel)1 GroupSidePane (org.jabref.gui.groups.GroupSidePane)1