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

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

Introduction

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

Prototype

public JLabel append(String textWithMnemonic) 

Source Link

Document

Adds a text label to the panel and proceeds to the next column.

Usage

From source file:jgnash.ui.splash.AboutDialog.java

License:Open Source License

private void layoutMainPanel() {
    initComponents();/*from   w ww . ja  v a 2  s  .  c om*/

    FormLayout layout = new FormLayout("200dlu:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();
    builder.appendRow(RowSpec.decode("fill:200dlu:g"));
    builder.append(tabbedPane);

    if (acceptLicense) {
        acceptBox = new JCheckBox(rb.getString("Message.AcceptLicense"));
        closeButton = new JButton(rb.getString("Button.Close"));
        closeButton.addActionListener(this);

        builder.nextLine();
        builder.appendUnrelatedComponentsGapRow();
        builder.nextLine();
        builder.append(acceptBox);
        builder.nextLine();
        builder.appendUnrelatedComponentsGapRow();
        builder.nextLine();
        builder.append(ButtonBarFactory.buildCloseBar(closeButton));
    }

    getContentPane().add(builder.getPanel());
    pack();
}

From source file:jgnash.ui.wizards.file.NewFileThree.java

License:Open Source License

private JPanel buildCenterPanel() {
    FormLayout layout = new FormLayout("d", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    builder.append(addButton);
    builder.append(removeButton);//from ww  w.ja  v  a 2  s.co m
    return builder.getPanel();
}

From source file:net.sf.jabref.AdvancedTab.java

License:Open Source License

public AdvancedTab(JabRefPreferences prefs, HelpDialog diag, JabRef jabRef) {
    this.jabRef = jabRef;
    preferences = prefs;/*from   w w w. j  av a  2  s. c  o m*/
    this.remotePreferences = new RemotePreferences(preferences);

    HelpAction remoteHelp = new HelpAction(diag, GUIGlobals.remoteHelp, "Help",
            GUIGlobals.getIconUrl("helpSmall"));
    useDefault = new JCheckBox(Globals.lang("Use other look and feel"));
    useRemoteServer = new JCheckBox(Globals.lang("Listen for remote operation on port") + ':');
    useNativeFileDialogOnMac = new JCheckBox(Globals.lang("Use native file dialog"));
    filechooserDisableRename = new JCheckBox(Globals.lang("Disable file renaming in non-native file dialog"));
    useIEEEAbrv = new JCheckBox(Globals.lang("Use IEEE LaTeX abbreviations"));
    biblatexMode = new JCheckBox(Globals.lang("BibLaTeX mode"));
    remoteServerPort = new JTextField();
    String[] possibleLookAndFeels = { "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel",
            "com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
            "com.sun.java.swing.plaf.motif.MotifLookAndFeel", "javax.swing.plaf.mac.MacLookAndFeel",
            "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", "javax.swing.plaf.metal.MetalLookAndFeel" };
    // Only list L&F which are available
    List<String> lookAndFeels = new ArrayList<String>();
    for (String lf : possibleLookAndFeels) {
        try {
            // Try to find L&F, throws exception if not successful
            Class.forName(lf);
            lookAndFeels.add(lf);
        } catch (ClassNotFoundException ignored) {
        }
    }
    className = new JComboBox(lookAndFeels.toArray(new String[lookAndFeels.size()]));
    className.setEditable(true);
    final JComboBox clName = className;
    useDefault.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            clName.setEnabled(((JCheckBox) e.getSource()).isSelected());
        }
    });
    useConvertToEquation = new JCheckBox(
            Globals.lang("Prefer converting subscripts and superscripts to equations rather than text"));
    useCaseKeeperOnSearch = new JCheckBox(
            Globals.lang("Add {} to specified title words on search to keep the correct case"));
    useUnitFormatterOnSearch = new JCheckBox(Globals
            .lang("Format units by adding non-breaking separators and keeping the correct case on search"));

    FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:3dlu", //, 4dlu, fill:pref",// 4dlu, left:pref, 4dlu",
            "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    JPanel pan = new JPanel();

    if (!Globals.ON_MAC) {
        builder.appendSeparator(Globals.lang("Look and feel"));
        JLabel lab = new JLabel(
                Globals.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
        builder.nextLine();
        builder.append(pan);
        builder.append(lab);
        builder.nextLine();
        builder.append(pan);
        builder.append(useDefault);
        builder.nextLine();
        builder.append(pan);
        JPanel pan2 = new JPanel();
        lab = new JLabel(Globals.lang("Class name") + ':');
        pan2.add(lab);
        pan2.add(className);
        builder.append(pan2);
        builder.nextLine();
        builder.append(pan);
        lab = new JLabel(Globals
                .lang("Note that you must specify the fully qualified class name for the look and feel,"));
        builder.append(lab);
        builder.nextLine();
        builder.append(pan);
        lab = new JLabel(
                Globals.lang("and the class must be available in your classpath next time you start JabRef."));
        builder.append(lab);
        builder.nextLine();
    }
    builder.appendSeparator(Globals.lang("Remote operation"));
    builder.nextLine();
    builder.append(new JPanel());
    builder.append(new JLabel("<html>"
            + Globals.lang("This feature lets new files be opened or imported into an "
                    + "already running instance of JabRef<BR>instead of opening a new instance. For instance, this "
                    + "is useful when you open a file in JabRef<br>from your web browser."
                    + "<BR>Note that this will prevent you from running more than one instance of JabRef at a time.")
            + "</html>"));
    builder.nextLine();
    builder.append(new JPanel());

    JPanel p = new JPanel();
    p.add(useRemoteServer);
    p.add(remoteServerPort);
    p.add(remoteHelp.getIconButton());
    builder.append(p);

    //if (Globals.ON_MAC) {
    builder.nextLine();
    builder.appendSeparator(Globals.lang("File dialog"));
    builder.nextLine();
    builder.append(new JPanel());
    builder.append(useNativeFileDialogOnMac);
    builder.nextLine();
    builder.append(new JPanel());
    builder.append(filechooserDisableRename);
    //}
    // IEEE
    builder.nextLine();
    builder.appendSeparator(Globals.lang("Search IEEEXplore"));
    builder.nextLine();
    builder.append(new JPanel());
    builder.append(useIEEEAbrv);

    builder.nextLine();
    builder.appendSeparator(Globals.lang("BibLaTeX mode"));
    builder.append(new JPanel());
    builder.append(biblatexMode);

    builder.nextLine();
    builder.appendSeparator(Globals.lang("Import conversions"));
    builder.nextLine();
    builder.append(new JPanel());
    builder.append(useConvertToEquation);
    builder.nextLine();
    builder.append(pan);
    builder.append(useCaseKeeperOnSearch);
    builder.nextLine();
    builder.append(pan);
    builder.append(useUnitFormatterOnSearch);

    pan = builder.getPanel();
    pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BorderLayout());
    add(pan, BorderLayout.CENTER);

}

From source file:net.sf.jabref.AppearancePrefsTab.java

License:Open Source License

/**
 * Customization of appearance parameters.
 *
 * @param prefs a <code>JabRefPreferences</code> value
 *///from w ww .  j  a v a  2  s .  co  m
public AppearancePrefsTab(JabRefPreferences prefs) {
    _prefs = prefs;
    setLayout(new BorderLayout());

    // Font sizes:
    fontSize = new JTextField(5);

    // Row padding size:
    rowPadding = new JTextField(5);

    colorCodes = new JCheckBox(Globals.lang("Color codes for required and optional fields"));
    /*antialias = new JCheckBox(Globals.lang
          ("Use antialiasing font"));*/
    overrideFonts = new JCheckBox(Globals.lang("Override default font settings"));

    showGrid = new JCheckBox(Globals.lang("Show gridlines"));

    //useCustomIconTheme = new JCheckBox(Globals.lang("Use custom icon theme"));
    //customIconThemeFile = new JTextField();
    FormLayout layout = new FormLayout(
            "1dlu, 8dlu, left:pref, 4dlu, fill:pref, 4dlu, fill:60dlu, 4dlu, fill:pref", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.leadingColumnOffset(2);
    JLabel lab;
    builder.appendSeparator(Globals.lang("General"));
    JPanel p1 = new JPanel();
    lab = new JLabel(Globals.lang("Menu and label font size") + ":");
    p1.add(lab);
    p1.add(fontSize);
    builder.append(p1);
    builder.nextLine();
    builder.append(overrideFonts);
    builder.nextLine();
    builder.appendSeparator(Globals.lang("Table appearance"));
    //builder.append(antialias);
    //builder.nextLine();
    JPanel p2 = new JPanel();
    p2.add(new JLabel(Globals.lang("Table row height padding") + ":"));
    p2.add(rowPadding);
    builder.append(p2);
    builder.nextLine();
    builder.append(colorCodes);
    builder.nextLine();
    builder.append(showGrid);
    builder.nextLine();
    JButton fontButton = new JButton(Globals.lang("Set table font"));
    builder.append(fontButton);
    builder.nextLine();
    builder.appendSeparator(Globals.lang("Table and entry editor colors"));
    builder.append(colorPanel);
    //builder.appendSeparator(Globals.lang("Custom icon theme"));
    //builder.append(useCustomIconTheme);
    //builder.nextLine();
    //JPanel p2 = new JPanel();
    //lab = new JLabel(Globals.lang("Custom icon theme file")+":");
    //p2.add(lab);
    //p2.add(customIconThemeFile);
    //BrowseAction browse = new BrowseAction(null, customIconThemeFile, false);
    //JButton browseBut = new JButton(Globals.lang("Browse"));
    //browseBut.addActionListener(browse);
    //p2.add(browseBut);
    //builder.append(p2);

    JPanel upper = new JPanel(), sort = new JPanel(), namesp = new JPanel(), iconCol = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    upper.setLayout(gbl);
    sort.setLayout(gbl);
    namesp.setLayout(gbl);
    iconCol.setLayout(gbl);

    overrideFonts.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            fontSize.setEnabled(overrideFonts.isSelected());
        }
    });

    fontButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Font f = new FontSelectorDialog(null, GUIGlobals.CURRENTFONT).getSelectedFont();
            if (f != null) {
                font = f;
            }
        }
    });
    /*menuFontButton.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {
         Font f=new FontSelectorDialog
             (null, menuFont).getSelectedFont();
         if(f==null)
             return;
         else
             menuFont = f;
     }
     });*/

    JPanel pan = builder.getPanel();
    pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(pan, BorderLayout.CENTER);
}

From source file:net.sf.jabref.BasePanel.java

License:Open Source License

private boolean saveDatabase(File file, boolean selectedOnly, String encoding,
        FileActions.DatabaseSaveType saveType) throws SaveException {
    SaveSession session;//from   w  w  w.  j a v  a2  s. c o m
    frame.block();
    try {
        if (!selectedOnly) {
            session = FileActions.saveDatabase(database, metaData, file, Globals.prefs, false, false, encoding,
                    false);
        } else {
            session = FileActions.savePartOfDatabase(database, metaData, file, Globals.prefs,
                    mainTable.getSelectedEntries(), encoding, saveType);
        }

    } catch (UnsupportedCharsetException ex2) {
        JOptionPane.showMessageDialog(frame,
                Globals.lang("Could not save file. " + "Character encoding '%0' is not supported.", encoding),
                Globals.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex.specificEntry()) {
            // Error occured during processing of
            // be. Highlight it:
            int row = mainTable.findEntry(ex.getEntry()), topShow = Math.max(0, row - 3);
            mainTable.setRowSelectionInterval(row, row);
            mainTable.scrollTo(topShow);
            showEntry(ex.getEntry());
        } else {
            ex.printStackTrace();
        }

        JOptionPane.showMessageDialog(frame, Globals.lang("Could not save file") + ".\n" + ex.getMessage(),
                Globals.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");

    } finally {
        frame.unblock();
    }

    boolean commit = true;
    if (!session.getWriter().couldEncodeAll()) {
        DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref", ""));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.append(Globals.lang("The chosen encoding '%0' could not encode the following characters: ",
                session.getEncoding()));
        builder.append(ta);
        builder.append(Globals.lang("What do you want to do?"));
        String tryDiff = Globals.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Globals.lang("Save database"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
                new String[] { Globals.lang("Save"), tryDiff, Globals.lang("Cancel") }, tryDiff);

        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Globals.lang("Select encoding"),
                    Globals.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null, Globals.ENCODINGS,
                    encoding);
            if (choice != null) {
                String newEncoding = (String) choice;
                return saveDatabase(file, selectedOnly, newEncoding, saveType);
            } else {
                commit = false;
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            commit = false;
        }

    }

    if (commit) {
        session.commit();
        this.encoding = encoding; // Make sure to remember which encoding we used.
    } else {
        session.cancel();
    }

    return commit;
}

From source file:net.sf.jabref.CompressedEntryEditorTab.java

License:Open Source License

void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) {

    InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = panel.getActionMap();

    im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", parent.prevEntryAction);
    im.put(Globals.prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", parent.nextEntryAction);

    im.put(Globals.prefs.getKey("Entry editor, store field"), "store");
    am.put("store", parent.storeFieldAction);
    im.put(Globals.prefs.getKey("Entry editor, next panel"), "right");
    im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("left", parent.switchLeftAction);
    im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left");
    im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("right", parent.switchRightAction);
    im.put(Globals.prefs.getKey("Help"), "help");
    am.put("help", parent.helpAction);
    im.put(Globals.prefs.getKey("Save database"), "save");
    am.put("save", parent.saveDatabaseAction);
    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", parent.frame.nextTab);
    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", parent.frame.prevTab);

    panel.setName(title);/*from w w w  .  j  a  v a  2 s  .  c o m*/
    //String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref";
    String colSpec = "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, "
            + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref";
    StringBuffer sb = new StringBuffer();
    int rows = (int) Math.ceil((double) fields.length / 2.0);
    for (int i = 0; i < rows; i++) {
        sb.append("fill:pref:grow, ");
    }
    if (addKeyField)
        sb.append("4dlu, fill:pref");
    else if (sb.length() >= 2)
        sb.delete(sb.length() - 2, sb.length());
    String rowSpec = sb.toString();

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

    for (int i = 0; i < fields.length; i++) {
        // Create the text area:
        int editorType = BibtexFields.getEditorType(fields[i]);

        final FieldEditor ta;
        if (editorType == GUIGlobals.FILE_LIST_EDITOR) {
            ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
            fileListEditor = (FileListEditor) ta;
        } else {
            ta = new FieldTextArea(fields[i], null);
            //inform the fieldtextarea of search events to highlight searchstrings
            frame.getSearchManager().addSearchListener((FieldTextArea) ta);
        }
        //ta.addUndoableEditListener(bPanel.undoListener);

        JComponent ex = parent.getExtra(fields[i], ta);

        // Add autocompleter listener, if required for this field:
        AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]);
        AutoCompleteListener acl = null;
        if (autoComp != null) {
            acl = new AutoCompleteListener(autoComp);
        }
        setupJTextComponent(ta.getTextComponent(), acl);
        ta.setAutoCompleteListener(acl);

        // Store the editor for later reference:
        editors.put(fields[i], ta);
        if (i == 0)
            activeField = ta;
        //System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i]));
        //ta.getPane().setPreferredSize(new Dimension(100,
        //        (int)(50.0*BibtexFields.getFieldWeight(fields[i]))));
        builder.append(ta.getLabel());
        if (ex == null)
            builder.append(ta.getPane(), 3);
        else {
            builder.append(ta.getPane());
            JPanel pan = new JPanel();
            pan.setLayout(new BorderLayout());
            pan.add(ex, BorderLayout.NORTH);
            builder.append(pan);
        }
        if (i % 2 == 1)
            builder.nextLine();
    }

    // Add the edit field for Bibtex-key.
    if (addKeyField) {
        final FieldTextField tf = new FieldTextField(BibtexFields.KEY_FIELD,
                parent.getEntry().getField(BibtexFields.KEY_FIELD), true);
        //tf.addUndoableEditListener(bPanel.undoListener);
        setupJTextComponent(tf, null);

        editors.put("bibtexkey", tf);
        /*
         * 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 = tf;
        builder.nextLine();
        builder.append(tf.getLabel());
        builder.append(tf, 3);
    }
}

From source file:net.sf.jabref.EntryEditorPrefsTab.java

License:Open Source License

public EntryEditorPrefsTab(JabRefFrame frame, JabRefPreferences prefs) {
    _prefs = prefs;/*from w  w w.jav a  2 s .  c o m*/
    _frame = frame;
    setLayout(new BorderLayout());

    autoOpenForm = new JCheckBox(Globals.lang("Open editor when a new entry is created"));
    defSource = new JCheckBox(Globals.lang("Show BibTeX source by default"));
    showSource = new JCheckBox(Globals.lang("Show BibTeX source panel"));
    emacsMode = new JCheckBox(Globals.lang("Use Emacs key bindings"));
    emacsRebindCtrlA = new JCheckBox(Globals.lang("Rebind C-a, too"));
    emacsRebindCtrlF = new JCheckBox(Globals.lang("Rebind C-f, too"));
    disableOnMultiple = new JCheckBox(Globals.lang("Disable entry editor when multiple entries are selected"));
    autoComplete = new JCheckBox(Globals.lang("Enable word/name autocompletion"));

    shortestToComplete = new JSpinner(
            new SpinnerNumberModel(prefs.getInt(JabRefPreferences.SHORTEST_TO_COMPLETE), 1, 5, 1));

    // allowed name formats
    autoCompFF = new JRadioButton(Globals.lang("Autocomplete names in 'Firstname Lastname' format only"));
    autoCompLF = new JRadioButton(Globals.lang("Autocomplete names in 'Lastname, Firstname' format only"));
    autoCompBoth = new JRadioButton(Globals.lang("Autocomplete names in both formats"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(autoCompLF);
    bg.add(autoCompFF);
    bg.add(autoCompBoth);

    // treatment of first name
    autoCompFirstNameMode_Full = new JRadioButton(Globals.lang("Use full firstname whenever possible"));
    autoCompFirstNameMode_Abbr = new JRadioButton(Globals.lang("Use abbreviated firstname whenever possible"));
    autoCompFirstNameMode_Both = new JRadioButton(Globals.lang("Use abbreviated and full firstname"));
    ButtonGroup bg_firstNameMode = new ButtonGroup();
    bg_firstNameMode.add(autoCompFirstNameMode_Full);
    bg_firstNameMode.add(autoCompFirstNameMode_Abbr);
    bg_firstNameMode.add(autoCompFirstNameMode_Both);

    Insets marg = new Insets(0, 20, 3, 0);
    defSource.setMargin(marg);
    // We need a listener on showSource to enable and disable the source panel-related choices:
    showSource.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            defSource.setEnabled(showSource.isSelected());
        }
    });

    emacsRebindCtrlA.setMargin(marg);
    // We need a listener on showSource to enable and disable the source panel-related choices:
    emacsMode.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            emacsRebindCtrlA.setEnabled(emacsMode.isSelected());
        }
    });

    emacsRebindCtrlF.setMargin(marg);
    // We need a listener on showSource to enable and disable the source panel-related choices:
    emacsMode.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            emacsRebindCtrlF.setEnabled(emacsMode.isSelected());
        }
    });

    autoCompFields = new JTextField(40);
    // We need a listener on autoComplete to enable and disable the
    // autoCompFields text field:
    autoComplete.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            setAutoCompleteElementsEnabled(autoComplete.isSelected());
        }
    });

    FormLayout layout = new FormLayout(// columns
            "8dlu, left:pref, 8dlu, fill:150dlu, 4dlu, fill:pref", // 4dlu, left:pref, 4dlu",
            // rows  1 to 10
            "pref, 6dlu, pref, 6dlu, pref, 6dlu, pref, 6dlu, pref, 6dlu, " +
            // rows 11 to 20
                    "pref, 6dlu, pref, 6dlu, pref, 6dlu, pref, 6dlu, pref, 6dlu, " +
                    // rows 21 to 31
                    "pref, 6dlu, pref, pref, pref, pref, 6dlu, pref, pref, pref, pref");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    CellConstraints cc = new CellConstraints();
    builder.addSeparator(Globals.lang("Editor options"), cc.xyw(1, 1, 5));
    builder.add(autoOpenForm, cc.xy(2, 3));
    builder.add(disableOnMultiple, cc.xy(2, 5));
    builder.add(showSource, cc.xy(2, 7));
    builder.add(defSource, cc.xy(2, 9));
    builder.add(emacsMode, cc.xy(2, 11));
    builder.add(emacsRebindCtrlA, cc.xy(2, 13));
    builder.add(emacsRebindCtrlF, cc.xy(2, 15));

    builder.addSeparator(Globals.lang("Autocompletion options"), cc.xyw(1, 17, 5));
    builder.add(autoComplete, cc.xy(2, 19));

    DefaultFormBuilder builder3 = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:150dlu", ""));
    JLabel label = new JLabel(Globals.lang("Use autocompletion for the following fields") + ":");

    builder3.append(label);
    builder3.append(autoCompFields);
    JLabel label2 = new JLabel(Globals.lang("Autocomplete after following number of characters") + ":");
    builder3.append(label2);
    builder3.append(shortestToComplete);
    builder.add(builder3.getPanel(), cc.xyw(2, 21, 3));

    builder.addSeparator(Globals.lang("Name format used for autocompletion"), cc.xyw(2, 23, 4));
    builder.add(autoCompFF, cc.xy(2, 24));
    builder.add(autoCompLF, cc.xy(2, 25));
    builder.add(autoCompBoth, cc.xy(2, 26));

    builder.addSeparator(Globals.lang("Treatment of first names"), cc.xyw(2, 28, 4));
    builder.add(autoCompFirstNameMode_Abbr, cc.xy(2, 29));
    builder.add(autoCompFirstNameMode_Full, cc.xy(2, 30));
    builder.add(autoCompFirstNameMode_Both, cc.xy(2, 31));

    JPanel pan = builder.getPanel();
    pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(pan, BorderLayout.CENTER);
}

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

License:Open Source License

private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, boolean compressed,
        String title) {//from  ww w . ja  v a2s  .c  om

    InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = panel.getActionMap();

    im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", parent.prevEntryAction);
    im.put(Globals.prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", parent.nextEntryAction);

    im.put(Globals.prefs.getKey("Entry editor, store field"), "store");
    am.put("store", parent.storeFieldAction);
    im.put(Globals.prefs.getKey("Entry editor, next panel"), "right");
    im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("left", parent.switchLeftAction);
    im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left");
    im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("right", parent.switchRightAction);
    im.put(Globals.prefs.getKey("Help"), "help");
    am.put("help", parent.helpAction);
    im.put(Globals.prefs.getKey("Save database"), "save");
    am.put("save", parent.saveDatabaseAction);
    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", parent.frame.nextTab);
    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", parent.frame.prevTab);

    panel.setName(title);

    int fieldsPerRow = compressed ? 2 : 1;
    //String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref";
    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 sb = new StringBuilder();
    int rows = (int) Math.ceil((double) fields.length / fieldsPerRow);
    for (int i = 0; i < rows; i++) {
        sb.append("fill:pref:grow, ");
    }
    if (addKeyField) {
        sb.append("4dlu, fill:pref");
    } else if (sb.length() >= 2) {
        sb.delete(sb.length() - 2, sb.length());
    }
    String rowSpec = sb.toString();

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

    for (int i = 0; i < fields.length; i++) {
        // Create the text area:
        int editorType = BibtexFields.getEditorType(fields[i]);

        final FieldEditor ta;
        int defaultHeight;
        int wHeight = (int) (50.0 * BibtexFields.getFieldWeight(fields[i]));
        if (editorType == GUIGlobals.FILE_LIST_EDITOR) {
            ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
            fileListEditor = (FileListEditor) ta;
            defaultHeight = 0;
        } else {
            ta = new FieldTextArea(fields[i], null);
            frame.getSearchManager().addSearchListener((FieldTextArea) ta);
            defaultHeight = ta.getPane().getPreferredSize().height;
        }
        //ta.addUndoableEditListener(bPanel.undoListener);

        JComponent ex = parent.getExtra(fields[i], ta);

        // Add autocompleter listener, if required for this field:
        AutoCompleter autoComp = bPanel.getAutoCompleters().get(fields[i]);
        AutoCompleteListener acl = null;
        if (autoComp != null) {
            acl = new AutoCompleteListener(autoComp);
        }
        setupJTextComponent(ta.getTextComponent(), acl);
        ta.setAutoCompleteListener(acl);

        // Store the editor for later reference:
        editors.put(fields[i], ta);
        if (i == 0) {
            activeField = ta;
        }
        //System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i]));
        if (!compressed) {
            ta.getPane().setPreferredSize(new Dimension(100, Math.max(defaultHeight, wHeight)));
        }
        builder.append(ta.getLabel());
        if (ex == null) {
            builder.append(ta.getPane(), 3);
        } else {
            builder.append(ta.getPane());
            JPanel pan = new JPanel();
            pan.setLayout(new BorderLayout());
            pan.add(ex, BorderLayout.NORTH);
            builder.append(pan);
        }
        if (((i + 1) % fieldsPerRow) == 0) {
            builder.nextLine();
        }
    }

    // Add the edit field for Bibtex-key.
    if (addKeyField) {
        final FieldTextField tf = new FieldTextField(BibtexFields.KEY_FIELD,
                parent.getEntry().getField(BibtexFields.KEY_FIELD), true);
        //tf.addUndoableEditListener(bPanel.undoListener);
        setupJTextComponent(tf, null);

        editors.put("bibtexkey", tf);
        /*
         * 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 = tf;
        }
        builder.nextLine();
        builder.append(tf.getLabel());
        builder.append(tf, 3);
    }
}

From source file:net.sf.jabref.export.SaveDatabaseAction.java

License:Open Source License

private boolean saveDatabase(File file, boolean selectedOnly, String encoding) throws SaveException {
    SaveSession session;/*  w w w. ja  va  2 s  .c  o m*/
    frame.block();
    try {
        if (!selectedOnly) {
            session = FileActions.saveDatabase(panel.database(), panel.metaData(), file, Globals.prefs, false,
                    false, encoding, false);
        } else {
            session = FileActions.savePartOfDatabase(panel.database(), panel.metaData(), file, Globals.prefs,
                    panel.getSelectedEntries(), encoding, FileActions.DatabaseSaveType.DEFAULT);
        }

    } catch (UnsupportedCharsetException ex2) {
        JOptionPane.showMessageDialog(frame,
                Globals.lang("Could not save file. " + "Character encoding '%0' is not supported.", encoding),
                Globals.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex == SaveException.FILE_LOCKED) {
            throw ex;
        }
        if (ex.specificEntry()) {
            // Error occured during processing of
            // be. Highlight it:
            int row = panel.mainTable.findEntry(ex.getEntry()), topShow = Math.max(0, row - 3);
            panel.mainTable.setRowSelectionInterval(row, row);
            panel.mainTable.scrollTo(topShow);
            panel.showEntry(ex.getEntry());
        } else {
            ex.printStackTrace();
        }

        JOptionPane.showMessageDialog(frame, Globals.lang("Could not save file") + ".\n" + ex.getMessage(),
                Globals.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");

    } finally {
        frame.unblock();
    }

    boolean commit = true;
    if (!session.getWriter().couldEncodeAll()) {
        DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref", ""));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.append(Globals.lang("The chosen encoding '%0' could not encode the following characters: ",
                session.getEncoding()));
        builder.append(ta);
        builder.append(Globals.lang("What do you want to do?"));
        String tryDiff = Globals.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Globals.lang("Save database"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
                new String[] { Globals.lang("Save"), tryDiff, Globals.lang("Cancel") }, tryDiff);

        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Globals.lang("Select encoding"),
                    Globals.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null, Globals.ENCODINGS,
                    encoding);
            if (choice != null) {
                String newEncoding = (String) choice;
                return saveDatabase(file, selectedOnly, newEncoding);
            } else {
                commit = false;
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            commit = false;
        }

    }

    try {
        if (commit) {
            session.commit();
            panel.setEncoding(encoding); // Make sure to remember which encoding we used.
        } else {
            session.cancel();
        }
    } catch (SaveException e) {
        int ans = JOptionPane.showConfirmDialog(null,
                Globals.lang("Save failed during backup creation") + ". "
                        + Globals.lang("Save without backup?"),
                Globals.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            session.setUseBackup(false);
            session.commit();
            panel.setEncoding(encoding);
        } else {
            commit = false;
        }
    }

    return commit;
}

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

License:Open Source License

private void init(ExternalFileType entry) {
    this.entry = entry;
    icon.setText(null);/*from  w w  w  .jav a2s. c om*/

    ButtonGroup bg = new ButtonGroup();
    bg.add(useDefault);
    bg.add(other);

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref", ""));
    builder.append(Globals.lang("Icon"));
    builder.append(icon);
    builder.nextLine();
    builder.append(Globals.lang("Name"));
    builder.append(name);
    builder.nextLine();
    builder.append(Globals.lang("Extension"));
    builder.append(extension);
    builder.nextLine();
    builder.append(Globals.lang("MIME type"));
    builder.append(mimeType);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.nextLine();
    builder.append(Globals.lang("Application"));
    JButton browseBut = new JButton(Globals.lang("Browse"));
    if (Globals.ON_WIN) {
        builder.append(useDefault);
        builder.nextLine();
        JPanel p1 = new JPanel();
        builder.append(p1);
        JPanel p2 = new JPanel();
        application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
        BorderLayout bl = new BorderLayout();
        bl.setHgap(4);
        p2.setLayout(bl);
        p2.add(other, BorderLayout.WEST);
        p2.add(application, BorderLayout.CENTER);
        builder.append(p2);
        builder.append(browseBut);
    } else {
        builder.append(application);
        builder.append(browseBut);
    }
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            okPressed = true;
            storeSettings(ExternalFileTypeEntryEditor.this.entry);
            diag.dispose();

        }
    });
    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            diag.dispose();
        }
    });

    icon.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String initSel = ExternalFileTypeEntryEditor.this.entry.getIconName();
            if (selectedIcon != null) {
                initSel = selectedIcon;
            }
            IconSelection ic = new IconSelection(diag, initSel);
            ic.setVisible(true);
            if (ic.isOkPressed()) {
                selectedIcon = ic.getSelectedIconKey();
                icon.setIcon(GUIGlobals.getImage(selectedIcon));
            }
            //JOptionPane.showMessageDialog(null, "Sorry, the icon can unfortunately not be changed in this version of JabRef");
        }
    });

    if (Globals.ON_WIN) {
        application.getDocument().addDocumentListener(new DocumentListener() {

            private void handle(DocumentEvent e) {
                if (application.getText().length() == 0) {
                    useDefault.setSelected(true);
                } else {
                    other.setSelected(true);
                }
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                handle(e);
            }

            @Override
            public void removeUpdate(DocumentEvent documentEvent) {
                handle(documentEvent);
            }

            @Override
            public void changedUpdate(DocumentEvent documentEvent) {
                handle(documentEvent);
            }
        });
    }

    if (dParent != null) {
        diag = new JDialog(dParent, Globals.lang("Edit file type"), true);
    } else {
        diag = new JDialog(fParent, Globals.lang("Edit file type"), true);
    }
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();

    BrowseListener browse = new BrowseListener(diag, application);
    browseBut.addActionListener(browse);

    if (dParent != null) {
        diag.setLocationRelativeTo(dParent);
    } else {
        diag.setLocationRelativeTo(fParent);
        //Util.placeDialog(diag, parent);
    }

    setValues(entry);
}