Search in sources :

Example 1 with FileDialogConfiguration

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

the class FromAuxDialog method initPanels.

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;
        }
    }
    if (toSelect >= 0) {
        dbChooser.setSelectedIndex(toSelect);
    }
    auxFileField = new JTextField("", 25);
    JButton browseAuxFileButton = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.AUX).withDefaultExtension(FileExtensions.AUX).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browseAuxFileButton.addActionListener(e -> {
        Optional<Path> file = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
        file.ifPresent(f -> auxFileField.setText(f.toAbsolutePath().toString()));
    });
    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 library") + ":");
    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));
}
Also used : Path(java.nio.file.Path) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) JTextArea(javax.swing.JTextArea) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JTextField(javax.swing.JTextField) FXDialogService(org.jabref.gui.FXDialogService) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Example 2 with FileDialogConfiguration

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

the class OpenOfficePanel method showManualConnectionDialog.

private void showManualConnectionDialog() {
    dialogOkPressed = false;
    final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
    final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
    final DialogService dirDialog = new FXDialogService();
    DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    DialogService fileDialog = new FXDialogService();
    // Path fields
    final JTextField ooPath = new JTextField(30);
    JButton browseOOPath = new JButton(Localization.lang("Browse"));
    ooPath.setText(preferences.getInstallationPath());
    browseOOPath.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooPath.setText(f.toAbsolutePath().toString())));
    final JTextField ooExec = new JTextField(30);
    JButton browseOOExec = new JButton(Localization.lang("Browse"));
    ooExec.setText(preferences.getExecutablePath());
    browseOOExec.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> fileDialog.showFileOpenDialog(fileDialogConfiguration)).ifPresent(f -> ooExec.setText(f.toAbsolutePath().toString())));
    final JTextField ooJars = new JTextField(30);
    ooJars.setText(preferences.getJarsPath());
    JButton browseOOJars = new JButton(Localization.lang("Browse"));
    browseOOJars.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooJars.setText(f.toAbsolutePath().toString())));
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "pref"));
    if (OS.WINDOWS || OS.OS_X) {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice directory")).xy(1, 1);
        builder.add(ooPath).xy(3, 1);
        builder.add(browseOOPath).xy(5, 1);
    } else {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice executable")).xy(1, 1);
        builder.add(ooExec).xy(3, 1);
        builder.add(browseOOExec).xy(5, 1);
        builder.appendRows("4dlu, pref");
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice library dir")).xy(1, 3);
        builder.add(ooJars).xy(3, 3);
        builder.add(browseOOJars).xy(5, 3);
    }
    builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    // Buttons
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(e -> {
        if (OS.WINDOWS || OS.OS_X) {
            preferences.updateConnectionParams(ooPath.getText(), ooPath.getText(), ooPath.getText());
        } else {
            preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        }
        dialogOkPressed = true;
        cDiag.dispose();
    });
    cancel.addActionListener(e -> cDiag.dispose());
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addRelatedGap();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    // Finish and show dirDialog
    cDiag.pack();
    cDiag.setLocationRelativeTo(frame);
    cDiag.setVisible(true);
}
Also used : JDialog(javax.swing.JDialog) OpenOfficePreferences(org.jabref.logic.openoffice.OpenOfficePreferences) URL(java.net.URL) BibDatabase(org.jabref.model.database.BibDatabase) AbstractWorker(org.jabref.gui.worker.AbstractWorker) IconTheme(org.jabref.gui.IconTheme) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) BasePanel(org.jabref.gui.BasePanel) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) URLClassLoader(java.net.URLClassLoader) JabRefFrame(org.jabref.gui.JabRefFrame) SidePaneManager(org.jabref.gui.SidePaneManager) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) Method(java.lang.reflect.Method) Path(java.nio.file.Path) HelpFile(org.jabref.logic.help.HelpFile) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibEntry(org.jabref.model.entry.BibEntry) IllegalTypeException(com.sun.star.beans.IllegalTypeException) Icon(javax.swing.Icon) FXDialogService(org.jabref.gui.FXDialogService) StyleLoader(org.jabref.logic.openoffice.StyleLoader) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) Dimension(java.awt.Dimension) List(java.util.List) WrappedTargetException(com.sun.star.lang.WrappedTargetException) AbstractAction(javax.swing.AbstractAction) BibtexKeyPatternUtil(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil) FormLayout(com.jgoodies.forms.layout.FormLayout) OS(org.jabref.logic.util.OS) Optional(java.util.Optional) BootstrapException(com.sun.star.comp.helper.BootstrapException) LogFactory(org.apache.commons.logging.LogFactory) UndoableKeyChange(org.jabref.gui.undo.UndoableKeyChange) JPanel(javax.swing.JPanel) KeyBinding(org.jabref.gui.keyboard.KeyBinding) HelpAction(org.jabref.gui.help.HelpAction) NamedCompound(org.jabref.gui.undo.NamedCompound) JTextField(javax.swing.JTextField) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop) DialogService(org.jabref.gui.DialogService) Action(javax.swing.Action) SidePaneComponent(org.jabref.gui.SidePaneComponent) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) OOBibStyle(org.jabref.logic.openoffice.OOBibStyle) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) Localization(org.jabref.logic.l10n.Localization) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileUtil(org.jabref.logic.util.io.FileUtil) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) NoSuchElementException(com.sun.star.container.NoSuchElementException) ButtonGroup(javax.swing.ButtonGroup) JPopupMenu(javax.swing.JPopupMenu) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) NotRemoveableException(com.sun.star.beans.NotRemoveableException) ActionEvent(java.awt.event.ActionEvent) Globals(org.jabref.Globals) Paths(java.nio.file.Paths) PropertyExistException(com.sun.star.beans.PropertyExistException) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) Log(org.apache.commons.logging.Log) Defaults(org.jabref.model.Defaults) BibtexKeyPatternPreferences(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FXDialogService(org.jabref.gui.FXDialogService) DialogService(org.jabref.gui.DialogService) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) FXDialogService(org.jabref.gui.FXDialogService) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) JDialog(javax.swing.JDialog)

Example 3 with FileDialogConfiguration

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

the class ImportFormats method getImportAction.

/**
     * Create an AbstractAction for performing an Import operation.
     * @param frame The JabRefFrame of this JabRef instance.
     * @param openInNew Indicate whether the action should open into a new database or
     *  into the currently open one.
     * @return The action.
     */
public static AbstractAction getImportAction(JabRefFrame frame, boolean openInNew) {
    class ImportAction extends MnemonicAwareAction {

        private final boolean newDatabase;

        public ImportAction(boolean newDatabase) {
            this.newDatabase = newDatabase;
            if (newDatabase) {
                putValue(Action.NAME, Localization.menuTitle("Import into new library"));
                putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE));
            } else {
                putValue(Action.NAME, Localization.menuTitle("Import into current library"));
                putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE));
            }
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            SortedSet<Importer> importers = Globals.IMPORT_FORMAT_READER.getImportFormats();
            List<FileExtensions> extensions = importers.stream().map(Importer::getExtensions).collect(Collectors.toList());
            FileChooser.ExtensionFilter allImports = ImportFileFilter.convert(Localization.lang("Available import formats"), importers);
            FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilters(extensions).withInitialDirectory(Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)).build();
            DialogService ds = new FXDialogService();
            FileChooser fs = ds.getConfiguredFileChooser(fileDialogConfiguration);
            fs.setSelectedExtensionFilter(allImports);
            File f = DefaultTaskExecutor.runInJavaFXThread(() -> fs.showOpenDialog(null));
            Optional<Path> selectedFile = Optional.ofNullable(f).map(File::toPath);
            FileChooser.ExtensionFilter selectedExtension = fs.getSelectedExtensionFilter();
            // Add file filter for all supported types
            selectedFile.ifPresent(file -> {
                try {
                    if (!Files.exists(file)) {
                        JOptionPane.showMessageDialog(frame, Localization.lang("File not found") + ": '" + file.getFileName() + "'.", Localization.lang("Import"), JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    Optional<Importer> format = ImportFileFilter.convert(selectedExtension, importers);
                    ImportMenuItem importMenu = new ImportMenuItem(frame, newDatabase, format.orElse(null));
                    importMenu.automatedImport(Collections.singletonList(file.toString()));
                    Globals.prefs.put(JabRefPreferences.IMPORT_WORKING_DIRECTORY, file.getParent().toString());
                } catch (Exception ex) {
                    LOGGER.warn("Cannot import file", ex);
                }
            });
        }
    }
    return new ImportAction(openInNew);
}
Also used : Path(java.nio.file.Path) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) ActionEvent(java.awt.event.ActionEvent) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) FXDialogService(org.jabref.gui.FXDialogService) MnemonicAwareAction(org.jabref.gui.actions.MnemonicAwareAction) FileExtensions(org.jabref.logic.util.FileExtensions) FileChooser(javafx.stage.FileChooser) File(java.io.File) Importer(org.jabref.logic.importer.Importer)

Example 4 with FileDialogConfiguration

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

the class NewProtectedTermsFileDialog method setupDialog.

private void setupDialog() {
    JButton browse = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.TERMS).withDefaultExtension(FileExtensions.TERMS).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browse.addActionListener(e -> {
        Optional<Path> file = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
        file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString()));
    });
    // Build content panel
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:100dlu:grow, 4dlu, pref", "p, 4dlu, p, 4dlu, p"));
    builder.add(Localization.lang("Description")).xy(1, 1);
    builder.add(newDescription).xyw(3, 1, 3);
    builder.add(Localization.lang("File")).xy(1, 3);
    builder.add(newFile).xy(3, 3);
    builder.add(browse).xy(5, 3);
    builder.add(enabled).xyw(1, 5, 5);
    enabled.setSelected(true);
    builder.padding("10dlu, 10dlu, 10dlu, 10dlu");
    getContentPane().add(builder.build(), BorderLayout.CENTER);
    // Buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton addOKButton = new JButton(Localization.lang("OK"));
    JButton addCancelButton = new JButton(Localization.lang("Cancel"));
    bb.addGlue();
    bb.addButton(addOKButton);
    bb.addButton(addCancelButton);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    addOKButton.addActionListener(e -> {
        addOKPressed = true;
        loader.addNewProtectedTermsList(newDescription.getText(), newFile.getText(), enabled.isSelected());
        dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addOKPressed = false;
            dispose();
        }
    };
    addCancelButton.addActionListener(cancelAction);
    // Key bindings:
    bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    bb.getPanel().getActionMap().put("close", cancelAction);
    pack();
}
Also used : Path(java.nio.file.Path) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) FXDialogService(org.jabref.gui.FXDialogService) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) AbstractAction(javax.swing.AbstractAction)

Example 5 with FileDialogConfiguration

use of org.jabref.gui.util.FileDialogConfiguration 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)

Aggregations

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