Example usage for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder

List of usage examples for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder

Introduction

In this page you can find the example usage for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder.

Prototype

public DefaultFormBuilder(FormLayout layout, StringResourceAccessor localizer) 

Source Link

Document

Constructs a DefaultFormBuilder for the given layout and resource bundle.

Usage

From source file:net.sf.jabref.external.DroppedFileHandler.java

License:Open Source License

public DroppedFileHandler(JabRefFrame frame, BasePanel panel) {

    this.frame = frame;
    this.panel = panel;

    ButtonGroup grp = new ButtonGroup();
    grp.add(linkInPlace);// w w w.ja v  a 2 s .c  o m
    grp.add(copyRadioButton);
    grp.add(moveRadioButton);

    FormLayout layout = new FormLayout("left:15dlu,pref,pref,pref", "bottom:14pt,pref,pref,pref,pref");
    layout.setRowGroups(new int[][] { { 1, 2, 3, 4, 5 } });
    DefaultFormBuilder builder = new DefaultFormBuilder(layout, optionsPanel);
    builder.border(Borders.DIALOG);
    CellConstraints cc = new CellConstraints();

    builder.add(linkInPlace, cc.xyw(1, 1, 4));
    builder.add(destDirLabel, cc.xyw(1, 2, 4));
    builder.add(copyRadioButton, cc.xyw(2, 3, 3));
    builder.add(moveRadioButton, cc.xyw(2, 4, 3));
    builder.add(renameCheckBox, cc.xyw(2, 5, 1));
    builder.add(renameToTextBox, cc.xyw(4, 5, 1));

}

From source file:net.sf.jabref.external.FileLinksUpgradeWarning.java

License:Open Source License

/**
 * This method presents a dialog box explaining and offering to make the
 * changes. If the user confirms, the changes are performed.
 * @param panel/*  w  w w. j a  v a2 s. c  o m*/
 * @param pr
 */
@Override
public void performAction(BasePanel panel, ParserResult pr) {
    // Find out which actions should be offered:
    // Only offer to change Preferences if file column is not already visible:
    boolean offerChangeSettings = !Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN)
            || !showsFileInGenFields();
    // Only offer to upgrade links if the pdf/ps fields are used:
    boolean offerChangeDatabase = linksFound(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR);
    // If the "file" directory is not set, offer to migrate pdf/ps dir:
    boolean offerSetFileDir = !Globals.prefs.hasKey(GUIGlobals.FILE_FIELD + "Directory")
            && (Globals.prefs.hasKey("pdfDirectory") || Globals.prefs.hasKey("psDirectory"));

    if (!offerChangeDatabase && !offerChangeSettings && !offerSetFileDir) {
        return; // Nothing to do, just return.
    }

    JCheckBox changeSettings = new JCheckBox(
            Globals.lang("Change table column and General fields settings to use the new feature"),
            offerChangeSettings);
    JCheckBox changeDatabase = new JCheckBox(
            Globals.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase);
    JCheckBox setFileDir = new JCheckBox(Globals.lang("Set main external file directory") + ":",
            offerSetFileDir);
    JTextField fileDir = new JTextField(30);
    JCheckBox doNotShowDialog = new JCheckBox(Globals.lang("Do not show these options in the future"), false);

    JPanel message = new JPanel();
    DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref", ""), message);
    // Keep the formatting of these lines. Otherwise, strings have to be translated again.
    // See updated JabRef_en.properties modifications by python syncLang.py -s -u
    b.append(new JLabel("<html>" + Globals.lang("This database was written using an older version of JabRef.")
            + "<br>"
            + Globals.lang(
                    "The current version features a new way of handling links to external files.<br>To take advantage of this, your links must be changed into the new format, and<br>JabRef must be configured to show the new links.")
            + "<p>" + Globals.lang("Do you want JabRef to do the following operations?") + "</html>"));
    b.nextLine();
    if (offerChangeSettings) {
        b.append(changeSettings);
        b.nextLine();
    }
    if (offerChangeDatabase) {
        b.append(changeDatabase);
        b.nextLine();
    }
    if (offerSetFileDir) {
        if (Globals.prefs.hasKey("pdfDirectory")) {
            fileDir.setText(Globals.prefs.get("pdfDirectory"));
        } else {
            fileDir.setText(Globals.prefs.get("psDirectory"));
        }
        JPanel pan = new JPanel();
        pan.add(setFileDir);
        pan.add(fileDir);
        JButton browse = new JButton(Globals.lang("Browse"));
        browse.addActionListener(BrowseAction.buildForDir(fileDir));
        pan.add(browse);
        b.append(pan);
        b.nextLine();
    }
    b.append("");
    b.nextLine();
    b.append(doNotShowDialog);

    int answer = JOptionPane.showConfirmDialog(panel.frame(), message, Globals.lang("Upgrade file"),
            JOptionPane.YES_NO_OPTION);
    if (doNotShowDialog.isSelected()) {
        Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
    }

    if (answer == JOptionPane.YES_OPTION) {
        makeChanges(panel, pr, changeSettings.isSelected(), changeDatabase.isSelected(),
                setFileDir.isSelected() ? fileDir.getText() : null);
    }
}

From source file:net.sf.jabref.groups.AutoGroupDialog.java

License:Open Source License

/**
 * @param groupsRoot//from ww w .  ja  v  a 2  s.  c om
 *            The original set of groups, which is required as undo
 *            information when all groups are cleared.
 */
public AutoGroupDialog(JabRefFrame jabrefFrame, BasePanel basePanel, GroupSelector groupSelector,
        GroupTreeNode groupsRoot, String defaultField, String defaultRemove, String defaultDeliminator) {
    super(jabrefFrame, Globals.lang("Automatically create groups"), true);
    frame = jabrefFrame;
    gs = groupSelector;
    panel = basePanel;
    m_groupsRoot = groupsRoot;
    field.setText(defaultField);
    remove.setText(defaultRemove);
    deliminator.setText(defaultDeliminator);
    nd.setSelected(true);
    ActionListener okListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok_pressed = true;
            dispose();

            GroupTreeNode autoGroupsRoot = new GroupTreeNode(new ExplicitGroup(
                    Globals.lang("Automatically created groups"), GroupHierarchyType.INCLUDING));
            Set<String> hs = null;
            String field = field();
            if (keywords.isSelected()) {
                if (nd.isSelected()) {
                    hs = Util.findDeliminatedWordsInField(panel.getDatabase(), field().toLowerCase().trim(),
                            deliminator.getText());
                } else {
                    hs = Util.findAllWordsInField(panel.getDatabase(), field().toLowerCase().trim(), remove());

                }
            } else if (authors.isSelected()) {
                List<String> fields = new ArrayList<String>(2);
                fields.add("author");
                hs = Util.findAuthorLastNames(panel.getDatabase(), fields);
                field = "author";
            } else if (editors.isSelected()) {
                List<String> fields = new ArrayList<String>(2);
                fields.add("editor");
                hs = Util.findAuthorLastNames(panel.getDatabase(), fields);
                field = "editor";
            }

            for (String keyword : hs) {
                KeywordGroup group = new KeywordGroup(keyword, field, keyword, false, false,
                        GroupHierarchyType.INDEPENDENT);
                autoGroupsRoot.add(new GroupTreeNode(group));
            }

            m_groupsRoot.add(autoGroupsRoot);
            NamedCompound ce = new NamedCompound(Globals.lang("Autogenerate groups"));
            UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(gs, m_groupsRoot, autoGroupsRoot,
                    UndoableAddOrRemoveGroup.ADD_NODE);
            undo.setRevalidate(true);
            ce.addEdit(undo);

            panel.markBaseChanged(); // a change always occurs
            gs.revalidateGroups();
            frame.output(Globals.lang("Created groups."));
            ce.end();
            panel.undoManager.addEdit(ce);
        }
    };
    remove.addActionListener(okListener);
    field.addActionListener(okListener);
    field.addCaretListener(this);
    AbstractAction cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    JButton cancel = new JButton(Globals.lang("Cancel"));
    cancel.addActionListener(cancelAction);
    ok.addActionListener(okListener);
    // Key bindings:
    JPanel main = new JPanel();
    ActionMap am = main.getActionMap();
    InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(frame.prefs().getKey("Close dialog"), "close");
    am.put("close", cancelAction);

    ButtonGroup bg = new ButtonGroup();
    bg.add(keywords);
    bg.add(authors);
    bg.add(editors);
    keywords.setSelected(true);
    DefaultFormBuilder b = new DefaultFormBuilder(
            new FormLayout("left:20dlu, 4dlu, left:pref, 4dlu, fill:60dlu, 4dlu, fill:0dlu", ""), main);
    b.append(keywords, 5);
    b.nextLine();
    b.append(new JPanel());
    b.append(Globals.lang("Field to group by") + ":");
    b.append(field);
    b.nextLine();
    b.append(new JPanel());
    b.append(Globals.lang("Characters to ignore") + ":");
    b.append(remove);
    b.nextLine();
    b.append(new JPanel());
    b.append(nd);
    b.append(deliminator);
    b.nextLine();
    b.append(authors, 5);
    b.nextLine();
    b.append(editors, 5);
    b.nextLine();

    JPanel opt = new JPanel();
    ButtonBarBuilder bb = new ButtonBarBuilder(opt);
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();

    // Layout starts here.
    /*main.setLayout(gbl);
    opt.setLayout(gbl);
    main.setBorder(BorderFactory.createTitledBorder(BorderFactory
        .createEtchedBorder(), Globals.lang("Group properties")));
    // Main panel:
    con.weightx = 0;
    con.gridwidth = 1;
    con.insets = new Insets(3, 5, 3, 5);
    con.anchor = GridBagConstraints.EAST;
    con.fill = GridBagConstraints.NONE;
    con.gridx = 0;
    con.gridy = 0;
    gbl.setConstraints(nf, con);
    main.add(nf);
    con.gridy = 1;
    gbl.setConstraints(nr, con);
    main.add(nr);
    con.gridy = 2;
    gbl.setConstraints(nd, con);
    main.add(nd);
    con.weightx = 1;
    con.anchor = GridBagConstraints.WEST;
    con.fill = GridBagConstraints.HORIZONTAL;
    con.gridy = 0;
    con.gridx = 1;
    gbl.setConstraints(field, con);
    main.add(field);
    con.gridy = 1;
    gbl.setConstraints(remove, con);
    main.add(remove);
    con.gridy = 2;
    gbl.setConstraints(deliminator, con);
    main.add(deliminator);
    // Option buttons:
    con.gridx = GridBagConstraints.RELATIVE;
    con.gridy = GridBagConstraints.RELATIVE;
    con.weightx = 1;
    con.gridwidth = 1;
    con.anchor = GridBagConstraints.EAST;
    con.fill = GridBagConstraints.NONE;
    gbl.setConstraints(ok, con);
    opt.add(ok);
    con.anchor = GridBagConstraints.WEST;
    con.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(cancel, con);
    opt.add(cancel);*/
    main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    opt.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(main, BorderLayout.CENTER);
    getContentPane().add(opt, BorderLayout.SOUTH);
    // pack();
    updateComponents();
    pack();
    Util.placeDialog(this, frame);
}

From source file:net.sf.jabref.gui.auximport.FromAuxDialog.java

License:Open Source License

private void initPanels() {
    // collect the names of all open databases
    int len = parentTabbedPane.getTabCount();
    int toSelect = -1;
    for (int i = 0; i < len; i++) {
        dbChooser.addItem(parentTabbedPane.getTitleAt(i));
        if (parentFrame.getBasePanelAt(i) == parentFrame.getCurrentBasePanel()) {
            toSelect = i;/*  www  .  j ava  2  s.  c o m*/
        }
    }
    if (toSelect >= 0) {
        dbChooser.setSelectedIndex(toSelect);
    }

    auxFileField = new JTextField("", 25);
    JButton browseAuxFileButton = new JButton(Localization.lang("Browse"));
    browseAuxFileButton.addActionListener(new BrowseAction(auxFileField, parentFrame));
    notFoundList = new JList<>();
    JScrollPane listScrollPane = new JScrollPane(notFoundList);
    statusInfos = new JTextArea("", 5, 20);
    JScrollPane statusScrollPane = new JScrollPane(statusInfos);
    statusInfos.setEditable(false);

    DefaultFormBuilder b = new DefaultFormBuilder(
            new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, left:pref", ""), buttons);
    b.appendSeparator(Localization.lang("Options"));
    b.append(Localization.lang("Reference database") + ":");
    b.append(dbChooser, 3);
    b.nextLine();
    b.append(Localization.lang("LaTeX AUX file") + ":");
    b.append(auxFileField);
    b.append(browseAuxFileButton);
    b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    b = new DefaultFormBuilder(
            new FormLayout("fill:pref:grow, 4dlu, fill:pref:grow", "pref, pref, fill:pref:grow"), statusPanel);
    b.appendSeparator(Localization.lang("Result"));
    b.append(Localization.lang("Unknown bibtex entries") + ":");
    b.append(Localization.lang("Messages") + ":");
    b.nextLine();
    b.append(listScrollPane);
    b.append(statusScrollPane);
    b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:net.sf.jabref.gui.CleanUpAction.java

License:Open Source License

private void initOptionsPanel() {
    cleanUpSuperscrips = new JCheckBox(Globals.lang("Convert 1st, 2nd, ... to real superscripts"));
    cleanUpDOI = new JCheckBox(
            Globals.lang("Move DOIs from note and URL field to DOI field and remove http prefix"));
    cleanUpMonth = new JCheckBox(Globals.lang("Format content of month field to #mon#"));
    cleanUpPageNumbers = new JCheckBox(Globals.lang("Ensure that page ranges are of the form num1--num2"));
    cleanUpMakePathsRelative = new JCheckBox(Globals.lang("Make paths of linked files relative (if possible)"));
    cleanUpRenamePDF = new JCheckBox(Globals.lang("Rename PDFs to given file name format pattern"));
    cleanUpRenamePDF.addChangeListener(new ChangeListener() {

        @Override/*from  w w  w  . ja v  a2  s .co  m*/
        public void stateChanged(ChangeEvent arg0) {
            cleanUpRenamePDFonlyRelativePaths.setEnabled(cleanUpRenamePDF.isSelected());
        }
    });
    cleanUpRenamePDFonlyRelativePaths = new JCheckBox(Globals.lang("Rename only PDFs having a relative path"));
    cleanUpUpgradeExternalLinks = new JCheckBox(
            Globals.lang("Upgrade external PDF/PS links to use the '%0' field.", GUIGlobals.FILE_FIELD));
    cleanUpHTML = new JCheckBox(Globals.lang("Run HTML converter on title"));
    cleanUpCase = new JCheckBox(Globals.lang("Run filter on title keeping the case of selected words"));
    cleanUpLaTeX = new JCheckBox(
            Globals.lang("Remove unneccessary $, {, and } and move adjacent numbers into equations"));
    cleanUpUnits = new JCheckBox(
            Globals.lang("Add brackets and replace separators with their non-breaking version for units"));
    cleanUpUnicode = new JCheckBox(Globals.lang("Run Unicode converter on title, author(s), and abstract"));
    cleanUpBiblatex = new JCheckBox(Globals.lang(
            "Convert to BibLatex format (for example, move the value of the 'journal' field to 'journaltitle')"));
    optionsPanel = new JPanel();
    retrieveSettings();

    FormLayout layout = new FormLayout("left:15dlu,pref:grow",
            "pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout, optionsPanel);
    builder.border(Borders.DIALOG);
    CellConstraints cc = new CellConstraints();
    builder.add(cleanUpHTML, cc.xyw(1, 1, 2));
    builder.add(cleanUpUnicode, cc.xyw(1, 2, 2));
    builder.add(cleanUpCase, cc.xyw(1, 3, 2));
    builder.add(cleanUpLaTeX, cc.xyw(1, 4, 2));
    builder.add(cleanUpUnits, cc.xyw(1, 5, 2));
    builder.add(cleanUpSuperscrips, cc.xyw(1, 6, 2));
    builder.add(cleanUpDOI, cc.xyw(1, 7, 2));
    builder.add(cleanUpMonth, cc.xyw(1, 8, 2));
    builder.add(cleanUpPageNumbers, cc.xyw(1, 9, 2));
    builder.add(cleanUpUpgradeExternalLinks, cc.xyw(1, 10, 2));
    builder.add(cleanUpMakePathsRelative, cc.xyw(1, 11, 2));
    builder.add(cleanUpRenamePDF, cc.xyw(1, 12, 2));
    String currentPattern = Globals.lang("File name format pattern").concat(": ")
            .concat(Globals.prefs.get(ImportSettingsTab.PREF_IMPORT_FILENAMEPATTERN));
    builder.add(new JLabel(currentPattern), cc.xyw(2, 13, 1));
    builder.add(cleanUpRenamePDFonlyRelativePaths, cc.xyw(2, 14, 1));
    builder.add(cleanUpBiblatex, cc.xyw(1, 15, 2));
}

From source file:net.sf.jabref.gui.entryeditor.EntryEditorTab.java

License:Open Source License

private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, boolean compressed,
        String title) {/*from w w  w .j a v a2 s.  c  o m*/

    setupKeyBindings(panel.getInputMap(JComponent.WHEN_FOCUSED), panel.getActionMap());

    panel.setName(title);
    // Use the title for the scrollPane, too.
    // This enables the correct execution of EntryEditor.setVisiblePanel(String name).
    scrollPane.setName(title);

    int fieldsPerRow = compressed ? 2 : 1;

    String colSpec = compressed
            ? "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, "
                    + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref"
            : "fill:pref, 1dlu, fill:pref:grow, 1dlu, fill:pref";
    StringBuilder stringBuilder = new StringBuilder();
    int rows = (int) Math.ceil((double) fields.size() / fieldsPerRow);
    for (int i = 0; i < rows; i++) {
        stringBuilder.append("fill:pref:grow, ");
    }
    if (addKeyField) {
        stringBuilder.append("4dlu, fill:pref");
    } else if (stringBuilder.length() >= 2) {
        stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
    }
    String rowSpec = stringBuilder.toString();

    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel);

    // BibTex edit fields are defined here
    for (int i = 0; i < fields.size(); i++) {
        String field = fields.get(i);

        // Create the text area:
        int editorType = InternalBibtexFields.getEditorType(field);

        FieldEditor fieldEditor;
        int defaultHeight;
        int wHeight = (int) (50.0 * InternalBibtexFields.getFieldWeight(field));
        if (editorType == GUIGlobals.FILE_LIST_EDITOR) {
            fieldEditor = new FileListEditor(frame, bPanel.getBibDatabaseContext().getMetaData(), field, null,
                    parent);
            fileListEditor = (FileListEditor) fieldEditor;
            defaultHeight = 0;
        } else {
            fieldEditor = new TextArea(field, null);
            bPanel.getSearchBar().getSearchQueryHighlightObservable().addSearchListener((TextArea) fieldEditor);
            defaultHeight = fieldEditor.getPane().getPreferredSize().height;
        }

        Optional<JComponent> extra = parent.getExtra(fieldEditor);

        // Add autocompleter listener, if required for this field:
        AutoCompleter<String> autoCompleter = bPanel.getAutoCompleters().get(field);
        AutoCompleteListener autoCompleteListener = null;
        if (autoCompleter != null) {
            autoCompleteListener = new AutoCompleteListener(autoCompleter);
        }
        setupJTextComponent(fieldEditor.getTextComponent(), autoCompleteListener);
        fieldEditor.setAutoCompleteListener(autoCompleteListener);

        // Store the editor for later reference:
        editors.put(field, fieldEditor);
        if (i == 0) {
            activeField = fieldEditor;
        }

        if (!compressed) {
            fieldEditor.getPane().setPreferredSize(new Dimension(100, Math.max(defaultHeight, wHeight)));
        }
        builder.append(fieldEditor.getLabel());
        if (extra.isPresent()) {
            builder.append(fieldEditor.getPane());
            JPanel pan = new JPanel();
            pan.setLayout(new BorderLayout());
            pan.add(extra.get(), BorderLayout.NORTH);
            builder.append(pan);
        } else {
            builder.append(fieldEditor.getPane(), 3);
        }
        if (((i + 1) % fieldsPerRow) == 0) {
            builder.nextLine();
        }
    }

    // Add the edit field for Bibtex-key.
    if (addKeyField) {
        final TextField textField = new TextField(BibEntry.KEY_FIELD, parent.getEntry().getCiteKey(), true);
        setupJTextComponent(textField, null);

        editors.put(BibEntry.KEY_FIELD, textField);
        /*
         * If the key field is the only field, we should have only one
         * editor, and this one should be set as active initially:
         */
        if (editors.size() == 1) {
            activeField = textField;
        }
        builder.nextLine();
        builder.append(textField.getLabel());
        builder.append(textField, 3);
    }
}