Search in sources :

Example 1 with ButtonStackBuilder

use of com.jgoodies.forms.builder.ButtonStackBuilder in project jabref by JabRef.

the class ExternalFileTypeEditor method init.

private void init() {
    ok.addActionListener(e -> {
        storeSettings();
        dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    // The toDefaults resets the entire list to its default values.
    toDefaults.addActionListener(e -> {
        List<ExternalFileType> list = ExternalFileTypes.getDefaultExternalFileTypes();
        fileTypes.clear();
        fileTypes.addAll(list);
        Collections.sort(fileTypes);
        tableModel.fireTableDataChanged();
    });
    add.addActionListener(e -> {
        ExternalFileType type = new ExternalFileType("", "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon());
        getEditor(type).setVisible(true);
        if (entryEditor.okPressed()) {
            fileTypes.add(type);
            tableModel.fireTableDataChanged();
        }
    });
    remove.addActionListener(e -> {
        int[] rows = table.getSelectedRows();
        if (rows.length == 0) {
            return;
        }
        for (int i = rows.length - 1; i >= 0; i--) {
            fileTypes.remove(rows[i]);
        }
        tableModel.fireTableDataChanged();
        if (!fileTypes.isEmpty()) {
            int row = Math.min(rows[0], fileTypes.size() - 1);
            table.setRowSelectionInterval(row, row);
        }
    });
    edit.addActionListener(editListener);
    fileTypes = new ArrayList<>();
    setValues();
    tableModel = new FileTypeTableModel();
    table = new JTable(tableModel);
    table.setDefaultRenderer(ImageIcon.class, new IconRenderer());
    table.addMouseListener(new TableClickListener());
    table.getColumnModel().getColumn(0).setMaxWidth(24);
    table.getColumnModel().getColumn(0).setMinWidth(24);
    table.getColumnModel().getColumn(1).setMinWidth(170);
    table.getColumnModel().getColumn(2).setMinWidth(60);
    table.getColumnModel().getColumn(3).setMinWidth(100);
    table.getColumnModel().getColumn(0).setResizable(false);
    JScrollPane sp = new JScrollPane(table);
    JPanel upper = new JPanel();
    upper.setLayout(new BorderLayout());
    upper.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    upper.add(sp, BorderLayout.CENTER);
    getContentPane().add(upper, BorderLayout.CENTER);
    ButtonStackBuilder bs = new ButtonStackBuilder();
    bs.addButton(add);
    bs.addButton(remove);
    bs.addButton(edit);
    bs.addRelatedGap();
    bs.addButton(toDefaults);
    upper.add(bs.getPanel(), BorderLayout.EAST);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    pack();
    // Key bindings:
    ActionMap am = upper.getActionMap();
    InputMap im = upper.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
    am = bb.getPanel().getActionMap();
    im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
    if (frame == null) {
        setLocationRelativeTo(dialog);
    } else {
        setLocationRelativeTo(frame);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Action(javax.swing.Action) MnemonicAwareAction(org.jabref.gui.actions.MnemonicAwareAction) AbstractAction(javax.swing.AbstractAction) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) BorderLayout(java.awt.BorderLayout) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JTable(javax.swing.JTable) InputMap(javax.swing.InputMap) ButtonStackBuilder(com.jgoodies.forms.builder.ButtonStackBuilder) AbstractAction(javax.swing.AbstractAction)

Example 2 with ButtonStackBuilder

use of com.jgoodies.forms.builder.ButtonStackBuilder in project jgnash by ccavanaugh.

the class BudgetManagerDialog method layoutMainPanel.

private void layoutMainPanel() {
    initComponents();
    // build the button stack
    ButtonStackBuilder buttonStackBuilder = new ButtonStackBuilder();
    buttonStackBuilder.addButton(newAutoButton, newButton, duplicateButton, renameButton);
    buttonStackBuilder.addUnrelatedGap();
    buttonStackBuilder.addButton(deleteButton);
    FormLayout layout = new FormLayout("p:g, $lcgap, f:p", "f:max(35dlu;p):g, $ugap, p");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.border(Borders.DIALOG);
    CellConstraints cc = new CellConstraints();
    builder.add(new JScrollPane(budgetList), cc.xy(1, 1));
    builder.add(buttonStackBuilder.getPanel(), cc.xy(3, 1));
    builder.add(StaticUIMethods.buildCloseBar(closeButton), cc.xyw(1, 3, 3));
    getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    pack();
    setMinimumSize(getSize());
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) ButtonStackBuilder(com.jgoodies.forms.builder.ButtonStackBuilder) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Aggregations

ButtonStackBuilder (com.jgoodies.forms.builder.ButtonStackBuilder)2 JScrollPane (javax.swing.JScrollPane)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)1 CellConstraints (com.jgoodies.forms.layout.CellConstraints)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JPanel (javax.swing.JPanel)1 JTable (javax.swing.JTable)1 MnemonicAwareAction (org.jabref.gui.actions.MnemonicAwareAction)1