Search in sources :

Example 66 with ChangeEvent

use of javax.swing.event.ChangeEvent in project intellij-community by JetBrains.

the class ImportLayoutPanel method createTableForPackageEntries.

public static JBTable createTableForPackageEntries(final PackageEntryTable packageTable, final ImportLayoutPanel panel) {
    final String[] names = { ApplicationBundle.message("listbox.import.package"), ApplicationBundle.message("listbox.import.with.subpackages") };
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return names.length + (panel.areStaticImportsEnabled() ? 1 : 0);
        }

        public int getRowCount() {
            return packageTable.getEntryCount();
        }

        @Nullable
        public Object getValueAt(int row, int col) {
            PackageEntry entry = packageTable.getEntryAt(row);
            if (entry == null || !isCellEditable(row, col))
                return null;
            col += panel.areStaticImportsEnabled() ? 0 : 1;
            if (col == 0) {
                return entry.isStatic();
            }
            if (col == 1) {
                return entry.getPackageName();
            }
            if (col == 2) {
                return entry.isWithSubpackages();
            }
            throw new IllegalArgumentException(String.valueOf(col));
        }

        public String getColumnName(int column) {
            if (panel.areStaticImportsEnabled() && column == 0)
                return "Static";
            column -= panel.areStaticImportsEnabled() ? 1 : 0;
            return names[column];
        }

        public Class getColumnClass(int col) {
            col += panel.areStaticImportsEnabled() ? 0 : 1;
            if (col == 0) {
                return Boolean.class;
            }
            if (col == 1) {
                return String.class;
            }
            if (col == 2) {
                return Boolean.class;
            }
            throw new IllegalArgumentException(String.valueOf(col));
        }

        public boolean isCellEditable(int row, int col) {
            PackageEntry packageEntry = packageTable.getEntryAt(row);
            return !packageEntry.isSpecial();
        }

        public void setValueAt(Object aValue, int row, int col) {
            PackageEntry packageEntry = packageTable.getEntryAt(row);
            col += panel.areStaticImportsEnabled() ? 0 : 1;
            if (col == 0) {
                PackageEntry newPackageEntry = new PackageEntry((Boolean) aValue, packageEntry.getPackageName(), packageEntry.isWithSubpackages());
                packageTable.setEntryAt(newPackageEntry, row);
            } else if (col == 1) {
                PackageEntry newPackageEntry = new PackageEntry(packageEntry.isStatic(), ((String) aValue).trim(), packageEntry.isWithSubpackages());
                packageTable.setEntryAt(newPackageEntry, row);
            } else if (col == 2) {
                PackageEntry newPackageEntry = new PackageEntry(packageEntry.isStatic(), packageEntry.getPackageName(), ((Boolean) aValue).booleanValue());
                packageTable.setEntryAt(newPackageEntry, row);
            } else {
                throw new IllegalArgumentException(String.valueOf(col));
            }
        }
    };
    // Create the table
    final JBTable result = new JBTable(dataModel);
    result.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    resizeColumns(packageTable, result, panel.areStaticImportsEnabled());
    TableCellEditor editor = result.getDefaultEditor(String.class);
    if (editor instanceof DefaultCellEditor) {
        ((DefaultCellEditor) editor).setClickCountToStart(1);
    }
    TableCellEditor beditor = result.getDefaultEditor(Boolean.class);
    beditor.addCellEditorListener(new CellEditorListener() {

        public void editingStopped(ChangeEvent e) {
            if (panel.areStaticImportsEnabled()) {
                // add/remove static keyword
                result.repaint();
            }
        }

        public void editingCanceled(ChangeEvent e) {
        }
    });
    return result;
}
Also used : CellEditorListener(javax.swing.event.CellEditorListener) JBTable(com.intellij.ui.table.JBTable) ChangeEvent(javax.swing.event.ChangeEvent) PackageEntry(com.intellij.psi.codeStyle.PackageEntry) AbstractTableModel(javax.swing.table.AbstractTableModel) TableCellEditor(javax.swing.table.TableCellEditor) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 67 with ChangeEvent

use of javax.swing.event.ChangeEvent in project jadx by skylot.

the class JadxSettingsWindow method makeDecompilationGroup.

private SettingsGroup makeDecompilationGroup() {
    JCheckBox fallback = new JCheckBox();
    fallback.setSelected(settings.isFallbackMode());
    fallback.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            settings.setFallbackMode(e.getStateChange() == ItemEvent.SELECTED);
            needReload();
        }
    });
    JCheckBox showInconsistentCode = new JCheckBox();
    showInconsistentCode.setSelected(settings.isShowInconsistentCode());
    showInconsistentCode.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            settings.setShowInconsistentCode(e.getStateChange() == ItemEvent.SELECTED);
            needReload();
        }
    });
    JCheckBox resourceDecode = new JCheckBox();
    resourceDecode.setSelected(settings.isSkipResources());
    resourceDecode.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            settings.setSkipResources(e.getStateChange() == ItemEvent.SELECTED);
            needReload();
        }
    });
    final JSpinner threadsCount = new JSpinner();
    threadsCount.setValue(settings.getThreadsCount());
    threadsCount.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            settings.setThreadsCount((Integer) threadsCount.getValue());
        }
    });
    JCheckBox autoStartJobs = new JCheckBox();
    autoStartJobs.setSelected(settings.isAutoStartJobs());
    autoStartJobs.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            settings.setAutoStartJobs(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    JCheckBox escapeUnicode = new JCheckBox();
    escapeUnicode.setSelected(settings.escapeUnicode());
    escapeUnicode.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            settings.setEscapeUnicode(e.getStateChange() == ItemEvent.SELECTED);
            needReload();
        }
    });
    JCheckBox replaceConsts = new JCheckBox();
    replaceConsts.setSelected(settings.isReplaceConsts());
    replaceConsts.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            settings.setReplaceConsts(e.getStateChange() == ItemEvent.SELECTED);
            needReload();
        }
    });
    SettingsGroup other = new SettingsGroup(NLS.str("preferences.decompile"));
    other.addRow(NLS.str("preferences.threads"), threadsCount);
    other.addRow(NLS.str("preferences.start_jobs"), autoStartJobs);
    other.addRow(NLS.str("preferences.showInconsistentCode"), showInconsistentCode);
    other.addRow(NLS.str("preferences.escapeUnicode"), escapeUnicode);
    other.addRow(NLS.str("preferences.replaceConsts"), replaceConsts);
    other.addRow(NLS.str("preferences.fallback"), fallback);
    other.addRow(NLS.str("preferences.skipResourcesDecode"), resourceDecode);
    return other;
}
Also used : JCheckBox(javax.swing.JCheckBox) ItemEvent(java.awt.event.ItemEvent) ChangeEvent(javax.swing.event.ChangeEvent) JSpinner(javax.swing.JSpinner) ItemListener(java.awt.event.ItemListener) ChangeListener(javax.swing.event.ChangeListener)

Example 68 with ChangeEvent

use of javax.swing.event.ChangeEvent in project jabref by JabRef.

the class JTextFieldChangeListenerUtil method addChangeListener.

/**
     * Installs a listener to receive notification when the text of any
     * {@code JTextComponent} is changed. Internally, it installs a
     * {@link DocumentListener} on the text component's {@link Document},
     * and a {@link PropertyChangeListener} on the text component to detect
     * if the {@code Document} itself is replaced.
     *
     * Taken from
     *
     * @param text any text component, such as a {@link JTextField}
     *        or {@link JTextArea}
     * @param changeListener a listener to receive {@link ChangeEvent}s
     *        when the text is changed; the source object for the events
     *        will be the text component
     * @throws NullPointerException if either parameter is null
     */
public static void addChangeListener(JTextComponent text, ChangeListener changeListener) {
    Objects.requireNonNull(text);
    Objects.requireNonNull(changeListener);
    DocumentListener dl = new DocumentListener() {

        private int lastChange;

        private int lastNotifiedChange;

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

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            lastChange++;
            SwingUtilities.invokeLater(() -> {
                if (lastNotifiedChange != lastChange) {
                    lastNotifiedChange = lastChange;
                    changeListener.stateChanged(new ChangeEvent(text));
                }
            });
        }
    };
    text.addPropertyChangeListener("document", (PropertyChangeEvent e) -> {
        Document d1 = (Document) e.getOldValue();
        Document d2 = (Document) e.getNewValue();
        if (d1 != null) {
            d1.removeDocumentListener(dl);
        }
        if (d2 != null) {
            d2.addDocumentListener(dl);
        }
        dl.changedUpdate(null);
    });
    Document d = text.getDocument();
    if (d != null) {
        d.addDocumentListener(dl);
    }
}
Also used : DocumentListener(javax.swing.event.DocumentListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document)

Example 69 with ChangeEvent

use of javax.swing.event.ChangeEvent in project jabref by JabRef.

the class DroppedFileHandler method showLinkMoveCopyRenameDialog.

//
// @return true if user pushed "OK", false otherwise
//
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {
    String dialogTitle = Localization.lang("Link to file %0", linkFileName);
    Optional<Path> dir = panel.getBibDatabaseContext().getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences());
    if (!dir.isPresent()) {
        destDirLabel.setText(Localization.lang("File directory is not set or does not exist!"));
        copyRadioButton.setEnabled(false);
        moveRadioButton.setEnabled(false);
        renameToTextBox.setEnabled(false);
        renameCheckBox.setEnabled(false);
        linkInPlace.setSelected(true);
    } else {
        destDirLabel.setText(Localization.lang("File directory is '%0':", dir.get().toString()));
        copyRadioButton.setEnabled(true);
        moveRadioButton.setEnabled(true);
        renameToTextBox.setEnabled(true);
        renameCheckBox.setEnabled(true);
    }
    ChangeListener cl = arg0 -> {
        renameCheckBox.setEnabled(!linkInPlace.isSelected());
        renameToTextBox.setEnabled(!linkInPlace.isSelected());
    };
    linkInPlace.setText(Localization.lang("Leave file in its current directory"));
    copyRadioButton.setText(Localization.lang("Copy file to file directory"));
    moveRadioButton.setText(Localization.lang("Move file to file directory"));
    renameCheckBox.setText(Localization.lang("Rename file to").concat(": "));
    LayoutFormatterPreferences layoutPrefs = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
    // Determine which name to suggest:
    String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN), layoutPrefs);
    String fileDirPattern = Globals.prefs.get(JabRefPreferences.IMPORT_FILEDIRPATTERN);
    String targetDirName = "";
    if (!fileDirPattern.isEmpty()) {
        targetDirName = FileUtil.createFileNameFromPattern(database, entry, fileDirPattern, layoutPrefs);
    }
    if (targetDirName.isEmpty()) {
        renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));
    } else {
        renameToTextBox.setText(targetDirName.concat("/").concat(targetName.concat(".").concat(fileType.getExtension())));
    }
    linkInPlace.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE));
    copyRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY));
    moveRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE));
    renameCheckBox.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME));
    linkInPlace.addChangeListener(cl);
    cl.stateChanged(new ChangeEvent(linkInPlace));
    try {
        Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel };
        int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (reply == JOptionPane.OK_OPTION) {
            // store user's choice
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE, linkInPlace.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY, copyRadioButton.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE, moveRadioButton.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME, renameCheckBox.isSelected());
            return true;
        } else {
            return false;
        }
    } finally {
        linkInPlace.removeChangeListener(cl);
    }
}
Also used : Path(java.nio.file.Path) NamedCompound(org.jabref.gui.undo.NamedCompound) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) BibDatabase(org.jabref.model.database.BibDatabase) JabRefPreferences(org.jabref.preferences.JabRefPreferences) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) Path(java.nio.file.Path) BoxLayout(javax.swing.BoxLayout) ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) ChangeEvent(javax.swing.event.ChangeEvent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileUtil(org.jabref.logic.util.io.FileUtil) Files(java.nio.file.Files) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) IOException(java.io.IOException) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) JOptionPane(javax.swing.JOptionPane) MainTable(org.jabref.gui.maintable.MainTable) IdGenerator(org.jabref.model.entry.IdGenerator) File(java.io.File) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) FileListEntry(org.jabref.gui.filelist.FileListEntry) FileHelper(org.jabref.model.util.FileHelper) List(java.util.List) Paths(java.nio.file.Paths) FormLayout(com.jgoodies.forms.layout.FormLayout) JLabel(javax.swing.JLabel) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) XMPUtil(org.jabref.logic.xmp.XMPUtil) Log(org.apache.commons.logging.Log) JTextArea(javax.swing.JTextArea) ExternalFileTypes(org.jabref.gui.externalfiletype.ExternalFileTypes) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 70 with ChangeEvent

use of javax.swing.event.ChangeEvent in project jabref by JabRef.

the class EntryFromFileCreatorManager method addEntriesFromFiles.

/**
     * Tries to add a entry for each file in the List.
     *
     * @param files
     * @param database
     * @param panel
     * @param entryType
     * @param generateKeywordsFromPathToFile
     * @param changeListener
     * @param importGUIMessages list of unexpected import event - Messages including
     *         failures
     * @return Returns The number of entries added
     */
public int addEntriesFromFiles(List<File> files, BibDatabase database, BasePanel panel, EntryType entryType, boolean generateKeywordsFromPathToFile, ChangeListener changeListener, List<String> importGUIMessages) {
    int count = 0;
    CompoundEdit ce = new CompoundEdit();
    for (File f : files) {
        EntryFromFileCreator creator = getEntryCreator(f);
        if (creator == null) {
            importGUIMessages.add("Problem importing " + f.getPath() + ": Unknown filetype.");
        } else {
            Optional<BibEntry> entry = creator.createEntry(f, generateKeywordsFromPathToFile);
            if (!entry.isPresent()) {
                importGUIMessages.add("Problem importing " + f.getPath() + ": Entry could not be created.");
                continue;
            }
            if (entryType != null) {
                entry.get().setType(entryType);
            }
            if (entry.get().getId() == null) {
                entry.get().setId(IdGenerator.next());
            }
            /*
                 * TODO: database.insertEntry(BibEntry) is not sensible. Why
                 * does 'true' mean "There were duplicates", while 'false' means
                 * "Everything alright"?
                 */
            if (!database.containsEntryWithId(entry.get().getId())) {
                // Therefore, we only insert the entry if it is not already present
                if (database.insertEntry(entry.get())) {
                    importGUIMessages.add("Problem importing " + f.getPath() + ": Insert into BibDatabase failed.");
                } else {
                    count++;
                    if (panel != null) {
                        ce.addEdit(new UndoableInsertEntry(database, entry.get(), panel));
                    }
                }
            }
        }
        if (changeListener != null) {
            changeListener.stateChanged(new ChangeEvent(this));
        }
    }
    if ((count > 0) && (panel != null)) {
        ce.end();
        panel.getUndoManager().addEdit(ce);
    }
    return count;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ChangeEvent(javax.swing.event.ChangeEvent) CompoundEdit(javax.swing.undo.CompoundEdit) File(java.io.File) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Aggregations

ChangeEvent (javax.swing.event.ChangeEvent)245 ChangeListener (javax.swing.event.ChangeListener)206 JPanel (javax.swing.JPanel)60 ActionEvent (java.awt.event.ActionEvent)52 ActionListener (java.awt.event.ActionListener)47 JLabel (javax.swing.JLabel)40 Dimension (java.awt.Dimension)30 GridBagConstraints (java.awt.GridBagConstraints)27 GridBagLayout (java.awt.GridBagLayout)24 JCheckBox (javax.swing.JCheckBox)24 Insets (java.awt.Insets)22 JButton (javax.swing.JButton)21 JSlider (javax.swing.JSlider)21 PropertyChangeEvent (java.beans.PropertyChangeEvent)20 JSpinner (javax.swing.JSpinner)19 SpinnerNumberModel (javax.swing.SpinnerNumberModel)19 BorderLayout (java.awt.BorderLayout)18 PropertyChangeListener (java.beans.PropertyChangeListener)17 IOException (java.io.IOException)16 BoxLayout (javax.swing.BoxLayout)16