Search in sources :

Example 16 with FormLayout

use of com.jgoodies.forms.layout.FormLayout in project intellij-community by JetBrains.

the class GroupRowsColumnsAction method update.

@Override
public void update(final AnActionEvent e) {
    super.update(e);
    CaptionSelection selection = CaptionSelection.DATA_KEY.getData(e.getDataContext());
    if (selection != null) {
        e.getPresentation().setEnabled(selection.getContainer() != null && selection.getContainer().getLayout() instanceof FormLayout && getCellsToGroup(selection).length > 1 && !isGrouped(selection));
    }
}
Also used : CaptionSelection(com.intellij.uiDesigner.CaptionSelection) FormLayout(com.jgoodies.forms.layout.FormLayout)

Example 17 with FormLayout

use of com.jgoodies.forms.layout.FormLayout in project intellij-community by JetBrains.

the class FormFirstComponentInsertLocation method processDrop.

@Override
public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) {
    RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager();
    if (myContainer.getGridRowCount() == 0) {
        gridLayout.insertGridCells(myContainer, 0, true, true, true);
    }
    if (myContainer.getGridColumnCount() == 0) {
        gridLayout.insertGridCells(myContainer, 0, false, true, true);
    }
    dropIntoGrid(myContainer, components, myRow, myColumn, dragObject);
    FormLayout formLayout = (FormLayout) myContainer.getDelegee().getLayout();
    if (myXPart == 0) {
        formLayout.setColumnSpec(1, new ColumnSpec("d"));
    } else if (myXPart == 2) {
        gridLayout.insertGridCells(myContainer, 0, false, true, true);
    }
    if (myYPart == 0) {
        formLayout.setRowSpec(1, new RowSpec("d"));
    } else if (myYPart == 2) {
        gridLayout.insertGridCells(myContainer, 0, true, true, true);
    }
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) ColumnSpec(com.jgoodies.forms.layout.ColumnSpec) RowSpec(com.jgoodies.forms.layout.RowSpec)

Example 18 with FormLayout

use of com.jgoodies.forms.layout.FormLayout in project jabref by JabRef.

the class ManageKeywordsAction method createDialog.

private void createDialog() {
    if (diag != null) {
        return;
    }
    // keyword to add
    JTextField keyword = new JTextField();
    keywordListModel = new DefaultListModel<>();
    JList<Keyword> keywordList = new JList<>(keywordListModel);
    keywordList.setVisibleRowCount(8);
    JScrollPane kPane = new JScrollPane(keywordList);
    diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    JButton add = new JButton(Localization.lang("Add"));
    JButton remove = new JButton(Localization.lang("Remove"));
    keywordList.setVisibleRowCount(10);
    intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
    mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
    ButtonGroup group = new ButtonGroup();
    group.add(intersectKeywords);
    group.add(mergeKeywords);
    ActionListener stateChanged = e -> fillKeyWordList();
    intersectKeywords.addActionListener(stateChanged);
    mergeKeywords.addActionListener(stateChanged);
    intersectKeywords.setSelected(true);
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
    builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
    builder.add(intersectKeywords).xyw(1, 3, 3);
    builder.add(mergeKeywords).xyw(1, 5, 3);
    builder.add(kPane).xywh(1, 7, 1, 3);
    builder.add(remove).xy(3, 9);
    builder.add(keyword).xy(1, 11);
    builder.add(add).xy(3, 11);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ok.addActionListener(e -> {
        canceled = false;
        diag.dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            canceled = true;
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
    add.addActionListener(addActionListener);
    final ActionListener removeActionListenter = arg0 -> {
        List<Keyword> values = keywordList.getSelectedValuesList();
        for (Keyword val : values) {
            keywordListModel.removeElement(val);
        }
    };
    remove.addActionListener(removeActionListenter);
    keywordList.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
                removeActionListenter.actionPerformed(null);
            }
        }
    });
    AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
    AutoCompleteListener acl = new AutoCompleteListener(autoComp);
    keyword.addKeyListener(acl);
    keyword.addFocusListener(acl);
    keyword.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                addActionListener.actionPerformed(null);
            }
        }
    });
    // Key bindings:
    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", cancelAction);
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
Also used : KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) NamedCompound(org.jabref.gui.undo.NamedCompound) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) Enumeration(java.util.Enumeration) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) Keyword(org.jabref.model.entry.Keyword) BorderLayout(java.awt.BorderLayout) SpecialFieldsUtils(org.jabref.logic.specialfields.SpecialFieldsUtils) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) JabRefGUI(org.jabref.JabRefGUI) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) JScrollPane(javax.swing.JScrollPane) FieldChange(org.jabref.model.FieldChange) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) Optional(java.util.Optional) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) InputMap(javax.swing.InputMap) KeyBinding(org.jabref.gui.keyboard.KeyBinding) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) JList(javax.swing.JList) List(java.util.List) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) Keyword(org.jabref.model.entry.Keyword) ActionMap(javax.swing.ActionMap) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) KeyListener(java.awt.event.KeyListener) InputMap(javax.swing.InputMap) JList(javax.swing.JList) JDialog(javax.swing.JDialog)

Example 19 with FormLayout

use of com.jgoodies.forms.layout.FormLayout 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 20 with FormLayout

use of com.jgoodies.forms.layout.FormLayout in project jabref by JabRef.

the class SaveDatabaseAction method saveDatabase.

private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
    SaveSession session;
    // block user input
    frame.block();
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding);
        BibtexDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs);
        } else {
            session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);
        }
        panel.registerUndoableChanges(session);
    } catch (UnsupportedCharsetException ex) {
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
        // FIXME: rethrow anti-pattern
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex == SaveException.FILE_LOCKED) {
            throw ex;
        }
        if (ex.specificEntry()) {
            BibEntry entry = ex.getEntry();
            // Error occured during processing of an entry. Highlight it!
            panel.highlightEntry(entry);
        } else {
            LOGGER.error("A problem occured when trying to save the file", ex);
        }
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
        // FIXME: rethrow anti-pattern
        throw new SaveException("rt");
    } finally {
        // re-enable user input
        frame.unblock();
    }
    // handle encoding problems
    boolean success = true;
    if (!session.getWriter().couldEncodeAll()) {
        FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1);
        builder.add(ta).xy(3, 1);
        builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
        String tryDiff = Localization.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save library"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);
        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save library"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding);
            if (choice == null) {
                success = false;
            } else {
                Charset newEncoding = Charset.forName((String) choice);
                return saveDatabase(file, selectedOnly, newEncoding);
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            success = false;
        }
    }
    // backup file?
    try {
        if (success) {
            session.commit(file.toPath());
            // Make sure to remember which encoding we used.
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
        } else {
            session.cancel();
        }
    } catch (SaveException e) {
        int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            session.setUseBackup(false);
            session.commit(file.toPath());
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
        } else {
            success = false;
        }
    }
    return success;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) BibEntry(org.jabref.model.entry.BibEntry) FormBuilder(com.jgoodies.forms.builder.FormBuilder) SaveException(org.jabref.logic.exporter.SaveException) JTextArea(javax.swing.JTextArea) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) Charset(java.nio.charset.Charset) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) SavePreferences(org.jabref.logic.exporter.SavePreferences) SaveSession(org.jabref.logic.exporter.SaveSession) FileSaveSession(org.jabref.logic.exporter.FileSaveSession)

Aggregations

FormLayout (com.jgoodies.forms.layout.FormLayout)224 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)112 JPanel (javax.swing.JPanel)82 CellConstraints (com.jgoodies.forms.layout.CellConstraints)81 JScrollPane (javax.swing.JScrollPane)57 JLabel (javax.swing.JLabel)40 JButton (javax.swing.JButton)28 FormBuilder (com.jgoodies.forms.builder.FormBuilder)19 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)18 JCheckBox (javax.swing.JCheckBox)13 DatePanel (jgnash.ui.components.DatePanel)11 ActionEvent (java.awt.event.ActionEvent)8 AbstractAction (javax.swing.AbstractAction)8 JDialog (javax.swing.JDialog)8 JRadioButton (javax.swing.JRadioButton)8 RowSpec (com.jgoodies.forms.layout.RowSpec)7 BorderLayout (java.awt.BorderLayout)7 LocalDate (java.time.LocalDate)7 List (java.util.List)7 Action (javax.swing.Action)7