Search in sources :

Example 6 with FXDialogService

use of org.jabref.gui.FXDialogService in project jabref by JabRef.

the class AbstractPushToApplication method initSettingsPanel.

/**
     * Create a FormBuilder, fill it with a textbox for the path and store the JPanel in settings
     */
protected void initSettingsPanel() {
    builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p"));
    StringBuilder label = new StringBuilder(Localization.lang("Path to %0", getApplicationName()));
    // In case the application name and the actual command is not the same, add the command in brackets
    if (getCommandName() == null) {
        label.append(':');
    } else {
        label.append(" (").append(getCommandName()).append("):");
    }
    builder.add(label.toString()).xy(1, 1);
    builder.add(path).xy(3, 1);
    JButton browse = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browse.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration)).ifPresent(f -> path.setText(f.toAbsolutePath().toString())));
    builder.add(browse).xy(5, 1);
    settings = builder.build();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JTextField(javax.swing.JTextField) BibDatabase(org.jabref.model.database.BibDatabase) BibEntry(org.jabref.model.entry.BibEntry) DialogService(org.jabref.gui.DialogService) IOException(java.io.IOException) FXDialogService(org.jabref.gui.FXDialogService) JabRefPreferences(org.jabref.preferences.JabRefPreferences) BasePanel(org.jabref.gui.BasePanel) Globals(org.jabref.Globals) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) List(java.util.List) FormLayout(com.jgoodies.forms.layout.FormLayout) OS(org.jabref.logic.util.OS) MetaData(org.jabref.model.metadata.MetaData) Localization(org.jabref.logic.l10n.Localization) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration)

Example 7 with FXDialogService

use of org.jabref.gui.FXDialogService in project jabref by JabRef.

the class FileLinksUpgradeWarning method performAction.

/**
     * This method presents a dialog box explaining and offering to make the
     * changes. If the user confirms, the changes are performed.
     * @param panel
     * @param parserResult
     */
@Override
public void performAction(BasePanel panel, ParserResult parserResult) {
    if (!isThereSomethingToBeDone()) {
        // Nothing to do, just return.
        return;
    }
    JCheckBox changeSettings = new JCheckBox(Localization.lang("Change table column and General fields settings to use the new feature"), offerChangeSettings);
    JCheckBox changeDatabase = new JCheckBox(Localization.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase);
    JCheckBox setFileDir = new JCheckBox(Localization.lang("Set main external file directory") + ":", offerSetFileDir);
    JTextField fileDir = new JTextField(30);
    JCheckBox doNotShowDialog = new JCheckBox(Localization.lang("Do not show these options in the future"), false);
    JPanel message = new JPanel();
    FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p"));
    // 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
    int row = 1;
    formBuilder.add(new JLabel("<html>" + Localization.lang("This library uses outdated file links.") + "<br><br>" + Localization.lang("JabRef no longer supports 'ps' or 'pdf' fields.<br>File links are now stored in the 'file' field and files are stored in an external file directory.<br>To make use of this feature, JabRef needs to upgrade file links.<br><br>") + "<p>" + Localization.lang("Do you want JabRef to do the following operations?") + "</html>")).xy(1, row);
    if (offerChangeSettings) {
        formBuilder.appendRows("2dlu, p");
        row += 2;
        formBuilder.add(changeSettings).xy(1, row);
    }
    if (offerChangeDatabase) {
        formBuilder.appendRows("2dlu, p");
        row += 2;
        formBuilder.add(changeDatabase).xy(1, row);
    }
    if (offerSetFileDir) {
        if (Globals.prefs.hasKey(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX)) {
            fileDir.setText(Globals.prefs.get(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX));
        } else {
            fileDir.setText(Globals.prefs.get(FieldName.PS + FileDirectoryPreferences.DIR_SUFFIX));
        }
        JPanel builderPanel = new JPanel();
        builderPanel.add(setFileDir);
        builderPanel.add(fileDir);
        JButton browse = new JButton(Localization.lang("Browse"));
        FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
        DialogService ds = new FXDialogService();
        browse.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString()))));
        builderPanel.add(browse);
        formBuilder.appendRows("2dlu, p");
        row += 2;
        formBuilder.add(builderPanel).xy(1, row);
    }
    formBuilder.appendRows("6dlu, p");
    formBuilder.add(doNotShowDialog).xy(1, row + 2);
    message.add(formBuilder.build());
    int answer = JOptionPane.showConfirmDialog(panel.frame(), message, Localization.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, parserResult, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null);
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) FormLayout(com.jgoodies.forms.layout.FormLayout) FXDialogService(org.jabref.gui.FXDialogService) JPanel(javax.swing.JPanel) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

Example 8 with FXDialogService

use of org.jabref.gui.FXDialogService in project jabref by JabRef.

the class EntryEditorTab method setupPanel.

private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, boolean compressed, String title) {
    setupKeyBindings(panel.getInputMap(JComponent.WHEN_FOCUSED), panel.getActionMap());
    panel.setName(title);
    editors.clear();
    List<Label> labels = new ArrayList<>();
    for (String fieldName : fields) {
        // TODO: Reenable/migrate this
        // Store the editor for later reference:
        /*
            FieldEditor fieldEditor;
            int defaultHeight;
            int wHeight = (int) (50.0 * InternalBibtexFields.getFieldWeight(field));
            if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) {
                fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
                        true);
                defaultHeight = 0;
            } else if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
                fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
                        false);
                defaultHeight = 0;
            } else {
                fieldEditor = new TextArea(field, null, getPrompt(field));
                //parent.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);
            */
        FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext(), entry.getType());
        fieldEditor.bindToEntry(entry);
        editors.put(fieldName, fieldEditor);
        /*
            // TODO: Reenable this
            if (i == 0) {
                activeField = fieldEditor;
            }
            */
        /*
            // TODO: Reenable this
            if (!compressed) {
                fieldEditor.getPane().setPreferredSize(new Dimension(100, Math.max(defaultHeight, wHeight)));
            }
            */
        /*
            // TODO: Reenable content selector
            if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(editor.getFieldName()).isEmpty()) {
                FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false,
                        ", ");
                contentSelectors.add(ws);
                controls.add(ws, BorderLayout.NORTH);
            }
            //} else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) {
            //return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction);
             */
        labels.add(new FieldNameLabel(fieldName));
    }
    GridPane gridPane = new GridPane();
    gridPane.setPrefSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
    gridPane.setMaxSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
    gridPane.getStyleClass().add("editorPane");
    ColumnConstraints columnExpand = new ColumnConstraints();
    columnExpand.setHgrow(Priority.ALWAYS);
    ColumnConstraints columnDoNotContract = new ColumnConstraints();
    columnDoNotContract.setMinWidth(Region.USE_PREF_SIZE);
    int rows;
    if (compressed) {
        rows = (int) Math.ceil((double) fields.size() / 2);
        addColumn(gridPane, 0, labels.subList(0, rows));
        addColumn(gridPane, 3, labels.subList(rows, labels.size()));
        addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode).limit(rows));
        addColumn(gridPane, 4, editors.values().stream().map(FieldEditorFX::getNode).skip(rows));
        gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand, new ColumnConstraints(10), columnDoNotContract, columnExpand);
    } else {
        rows = fields.size();
        addColumn(gridPane, 0, labels);
        addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode));
        gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand);
    }
    RowConstraints rowExpand = new RowConstraints();
    rowExpand.setVgrow(Priority.ALWAYS);
    if (rows == 0) {
        rowExpand.setPercentHeight(100);
    } else {
        rowExpand.setPercentHeight(100 / rows);
    }
    for (int i = 0; i < rows; i++) {
        gridPane.getRowConstraints().add(rowExpand);
    }
    return gridPane;
}
Also used : FXDialogService(org.jabref.gui.FXDialogService) FieldNameLabel(org.jabref.gui.fieldeditors.FieldNameLabel) GridPane(javafx.scene.layout.GridPane) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ArrayList(java.util.ArrayList) FieldNameLabel(org.jabref.gui.fieldeditors.FieldNameLabel) Label(javafx.scene.control.Label) FieldEditorFX(org.jabref.gui.fieldeditors.FieldEditorFX) RowConstraints(javafx.scene.layout.RowConstraints)

Example 9 with FXDialogService

use of org.jabref.gui.FXDialogService in project jabref by JabRef.

the class DatabasePropertiesDialog method init.

private void init() {
    DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    JButton browseFile = new JButton(Localization.lang("Browse"));
    JButton browseFileIndv = new JButton(Localization.lang("Browse"));
    browseFile.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showDirectorySelectionDialog(directoryDialogConfiguration)).ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString())));
    browseFileIndv.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showDirectorySelectionDialog(directoryDialogConfiguration)).ifPresent(f -> fileDirIndv.setText(f.toAbsolutePath().toString())));
    setupSortOrderConfiguration();
    FormLayout form = new FormLayout("left:pref, 4dlu, pref:grow, 4dlu, pref:grow, 4dlu, pref", "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, fill:pref:grow, 180dlu, fill:pref:grow,");
    FormBuilder builder = FormBuilder.create().layout(form);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.add(Localization.lang("Library encoding")).xy(1, 1);
    builder.add(encoding).xy(3, 1);
    builder.addSeparator(Localization.lang("Override default file directories")).xyw(1, 3, 5);
    builder.add(Localization.lang("General file directory")).xy(1, 5);
    builder.add(fileDir).xy(3, 5);
    builder.add(browseFile).xy(5, 5);
    builder.add(Localization.lang("User-specific file directory")).xy(1, 7);
    builder.add(fileDirIndv).xy(3, 7);
    builder.add(browseFileIndv).xy(5, 7);
    builder.addSeparator(Localization.lang("Save sort order")).xyw(1, 13, 5);
    builder.add(saveInOriginalOrder).xyw(1, 15, 5);
    builder.add(saveInSpecifiedOrder).xyw(1, 17, 5);
    saveOrderPanel = new SaveOrderConfigDisplay();
    builder.add(saveOrderPanel.getPanel()).xyw(1, 21, 5);
    builder.addSeparator(Localization.lang("Library protection")).xyw(1, 23, 5);
    builder.add(protect).xyw(1, 25, 5);
    fieldFormatterCleanupsPanel = new FieldFormatterCleanupsPanel(Localization.lang("Enable save actions"), Cleanups.DEFAULT_SAVE_ACTIONS);
    builder.addSeparator(Localization.lang("Save actions")).xyw(1, 27, 5);
    builder.add(fieldFormatterCleanupsPanel).xyw(1, 29, 5);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addRelatedGap();
    bb.addButton(new HelpAction(HelpFile.DATABASE_PROPERTIES).getHelpButton());
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    pack();
    AbstractAction closeAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    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", closeAction);
    ok.addActionListener(e -> {
        storeSettings();
        dispose();
    });
    cancel.addActionListener(e -> dispose());
}
Also used : ActionListener(java.awt.event.ActionListener) JTextField(javax.swing.JTextField) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DialogService(org.jabref.gui.DialogService) JabRefPreferences(org.jabref.preferences.JabRefPreferences) BasePanel(org.jabref.gui.BasePanel) Charset(java.nio.charset.Charset) Encodings(org.jabref.logic.l10n.Encodings) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) MetaData(org.jabref.model.metadata.MetaData) Localization(org.jabref.logic.l10n.Localization) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) SaveOrderConfigDisplay(org.jabref.gui.SaveOrderConfigDisplay) HelpFile(org.jabref.logic.help.HelpFile) JButton(javax.swing.JButton) ButtonGroup(javax.swing.ButtonGroup) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig) Cleanups(org.jabref.logic.cleanup.Cleanups) BorderFactory(javax.swing.BorderFactory) FXDialogService(org.jabref.gui.FXDialogService) FieldFormatterCleanupsPanel(org.jabref.gui.cleanup.FieldFormatterCleanupsPanel) ActionEvent(java.awt.event.ActionEvent) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) JabRefDialog(org.jabref.gui.JabRefDialog) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) DatabaseLocation(org.jabref.model.database.DatabaseLocation) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) InputMap(javax.swing.InputMap) KeyBinding(org.jabref.gui.keyboard.KeyBinding) HelpAction(org.jabref.gui.help.HelpAction) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) HelpAction(org.jabref.gui.help.HelpAction) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FXDialogService(org.jabref.gui.FXDialogService) SaveOrderConfigDisplay(org.jabref.gui.SaveOrderConfigDisplay) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) InputMap(javax.swing.InputMap) FieldFormatterCleanupsPanel(org.jabref.gui.cleanup.FieldFormatterCleanupsPanel) AbstractAction(javax.swing.AbstractAction)

Example 10 with FXDialogService

use of org.jabref.gui.FXDialogService in project jabref by JabRef.

the class SaveDatabaseAction method saveAs.

public void saveAs() throws Exception {
    // configure file dialog
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.BIBTEX_DB).withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    Optional<Path> path = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration));
    if (path.isPresent()) {
        saveAs(path.get().toFile());
    } else {
        canceled = true;
        return;
    }
}
Also used : FXDialogService(org.jabref.gui.FXDialogService) Path(java.nio.file.Path) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration)

Aggregations

FXDialogService (org.jabref.gui.FXDialogService)13 DialogService (org.jabref.gui.DialogService)12 FileDialogConfiguration (org.jabref.gui.util.FileDialogConfiguration)10 Path (java.nio.file.Path)9 FormBuilder (com.jgoodies.forms.builder.FormBuilder)7 FormLayout (com.jgoodies.forms.layout.FormLayout)6 JButton (javax.swing.JButton)6 JTextField (javax.swing.JTextField)5 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)4 ActionEvent (java.awt.event.ActionEvent)4 AbstractAction (javax.swing.AbstractAction)3 JPanel (javax.swing.JPanel)3 Globals (org.jabref.Globals)3 BasePanel (org.jabref.gui.BasePanel)3 BorderLayout (java.awt.BorderLayout)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Action (javax.swing.Action)2 Log (org.apache.commons.logging.Log)2