Search in sources :

Example 36 with ItemEvent

use of java.awt.event.ItemEvent in project gephi by gephi.

the class LayoutPanel method initEvents.

private void initEvents() {
    layoutCombobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (layoutCombobox.getSelectedItem().equals(NO_SELECTION) && model.getSelectedLayout() != null) {
                setSelectedLayout(null);
            } else if (layoutCombobox.getSelectedItem() instanceof LayoutBuilderWrapper) {
                LayoutBuilder builder = ((LayoutBuilderWrapper) layoutCombobox.getSelectedItem()).getLayoutBuilder();
                if (model.getSelectedLayout() == null || model.getSelectedBuilder() != builder) {
                    setSelectedLayout(builder);
                }
            }
        }
    });
    infoLabel.addMouseListener(new MouseAdapter() {

        RichTooltip richTooltip;

        @Override
        public void mouseEntered(MouseEvent e) {
            if (infoLabel.isEnabled() && model != null && model.getSelectedLayout() != null) {
                richTooltip = buildTooltip(model.getSelectedBuilder());
                richTooltip.showTooltip(infoLabel, e.getLocationOnScreen());
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (richTooltip != null) {
                richTooltip.hideTooltip();
                richTooltip = null;
            }
        }
    });
    presetsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu menu = new JPopupMenu();
            List<Preset> presets = layoutPresetPersistence.getPresets(model.getSelectedLayout());
            if (presets != null && !presets.isEmpty()) {
                for (final Preset p : presets) {
                    JMenuItem item = new JMenuItem(p.toString());
                    item.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            layoutPresetPersistence.loadPreset(p, model.getSelectedLayout());
                            refreshProperties();
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.loadPreset", model.getSelectedBuilder().getName(), p.toString()));
                        }
                    });
                    menu.add(item);
                }
            } else {
                menu.add("<html><i>" + NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.nopreset") + "</i></html>");
            }
            JMenuItem saveItem = new JMenuItem(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset"));
            saveItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String lastPresetName = NbPreferences.forModule(LayoutPanel.class).get("LayoutPanel.lastPresetName", "");
                    NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input"), NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input.name"));
                    question.setInputText(lastPresetName);
                    if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
                        String input = question.getInputText();
                        if (input != null && !input.isEmpty()) {
                            layoutPresetPersistence.savePreset(input, model.getSelectedLayout());
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.savePreset", model.getSelectedBuilder().getName(), input));
                            NbPreferences.forModule(LayoutPanel.class).put("LayoutPanel.lastPresetName", input);
                        }
                    }
                }
            });
            menu.add(new JSeparator());
            menu.add(saveItem);
            menu.show(layoutToolbar, 0, -menu.getPreferredSize().height);
        }
    });
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder) ItemEvent(java.awt.event.ItemEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) Preset(org.gephi.desktop.layout.LayoutPresetPersistence.Preset) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) NotifyDescriptor(org.openide.NotifyDescriptor) RichTooltip(org.gephi.ui.components.richtooltip.RichTooltip) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem)

Example 37 with ItemEvent

use of java.awt.event.ItemEvent in project gephi by gephi.

the class EdgeSettingsPanel method setup.

public void setup() {
    VizModel vizModel = VizController.getInstance().getVizModel();
    vizModel.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("init")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeHasUniColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("showEdges")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeUniColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeInSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeOutSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeBothSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeScale")) {
                refreshSharedConfig();
            }
        }
    });
    refreshSharedConfig();
    showEdgesCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setShowEdges(showEdgesCheckbox.isSelected());
            setEnable(true);
        }
    });
    ((JColorButton) edgeColorButton).addPropertyChangeListener(JColorButton.EVENT_COLOR, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeUniColor(((JColorButton) edgeColorButton).getColorArray());
        }
    });
    sourceNodeColorCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeHasUniColor(!sourceNodeColorCheckbox.isSelected());
        }
    });
    selectionColorCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeSelectionColor(selectionColorCheckbox.isSelected());
        }
    });
    edgeInSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeInSelectionColor(edgeInSelectionColorChooser.getColor().getComponents(null));
        }
    });
    edgeBothSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeBothSelectionColor(edgeBothSelectionColorChooser.getColor().getComponents(null));
        }
    });
    edgeOutSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeOutSelectionColor(edgeOutSelectionColorChooser.getColor().getComponents(null));
        }
    });
    scaleSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            if (vizModel.getEdgeScale() != (scaleSlider.getValue() / 10f + 0.1f)) {
                vizModel.setEdgeScale(scaleSlider.getValue() / 10f + 0.1f);
            }
        }
    });
}
Also used : JColorButton(org.gephi.ui.components.JColorButton) VizModel(org.gephi.visualization.VizModel) PropertyChangeEvent(java.beans.PropertyChangeEvent) ItemEvent(java.awt.event.ItemEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) ActionEvent(java.awt.event.ActionEvent) ItemListener(java.awt.event.ItemListener) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 38 with ItemEvent

use of java.awt.event.ItemEvent in project omegat by omegat-org.

the class AlignFilePickerController method show.

/**
 * Display the align tool file picker. The picker is not modal, so this call will return immediately.
 *
 * @param parent
 *            Parent window of file picker and align window
 */
@SuppressWarnings("serial")
public void show(final Component parent) {
    final JFrame frame = new JFrame(OStrings.getString("ALIGNER_FILEPICKER"));
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    StaticUIUtils.setEscapeClosable(frame);
    final AlignFilePicker picker = new AlignFilePicker();
    picker.sourceLanguagePicker.setModel(new DefaultComboBoxModel<>(new Vector<>(Language.getLanguages())));
    picker.sourceLanguagePicker.setRenderer(new LanguageComboBoxRenderer());
    picker.sourceLanguagePicker.setSelectedItem(sourceLanguage);
    picker.sourceLanguagePicker.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            if (e.getItem() instanceof String) {
                String newVal = (String) e.getItem();
                if (Language.verifySingleLangCode(newVal)) {
                    sourceLanguage = new Language(newVal);
                } else {
                    sourceLanguage = null;
                    JOptionPane.showMessageDialog(frame, OStrings.getString("NP_INVALID_SOURCE_LOCALE") + OStrings.getString("NP_LOCALE_SUGGESTION"), OStrings.getString("TF_ERROR"), JOptionPane.ERROR_MESSAGE);
                    picker.sourceLanguagePicker.requestFocusInWindow();
                }
            } else if (e.getItem() instanceof Language) {
                sourceLanguage = (Language) e.getItem();
            } else {
                throw new IllegalArgumentException();
            }
            updatePicker(picker);
        }
    });
    picker.targetLanguagePicker.setModel(new DefaultComboBoxModel<>(new Vector<>(Language.getLanguages())));
    picker.targetLanguagePicker.setRenderer(new LanguageComboBoxRenderer());
    picker.targetLanguagePicker.setSelectedItem(targetLanguage);
    picker.targetLanguagePicker.addItemListener(e -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        if (e.getItem() instanceof String) {
            String newVal = (String) e.getItem();
            if (Language.verifySingleLangCode(newVal)) {
                targetLanguage = new Language(newVal);
            } else {
                targetLanguage = null;
                JOptionPane.showMessageDialog(frame, OStrings.getString("NP_INVALID_TARGET_LOCALE") + OStrings.getString("NP_LOCALE_SUGGESTION"), OStrings.getString("TF_ERROR"), JOptionPane.ERROR_MESSAGE);
                picker.targetLanguagePicker.requestFocusInWindow();
            }
        } else if (e.getItem() instanceof Language) {
            targetLanguage = (Language) e.getItem();
        } else {
            throw new IllegalArgumentException();
        }
        updatePicker(picker);
    });
    picker.sourceChooseFileButton.addActionListener(e -> {
        File file = chooseFile(frame, OStrings.getString("ALIGNER_FILEPICKER_CHOOSE_SOURCE"), StringUtil.isEmpty(sourceFile) ? sourceDefaultDir : sourceFile);
        if (file != null) {
            sourceDefaultDir = file.getParent();
            targetDefaultDir = targetDefaultDir == null ? sourceDefaultDir : targetDefaultDir;
            defaultSaveDir = defaultSaveDir == null ? sourceDefaultDir : defaultSaveDir;
            picker.sourceLanguageFileField.setText(file.getAbsolutePath());
        }
    });
    picker.targetChooseFileButton.addActionListener(e -> {
        File file = chooseFile(frame, OStrings.getString("ALIGNER_FILEPICKER_CHOOSE_TARGET"), StringUtil.isEmpty(targetFile) ? targetDefaultDir : targetFile);
        if (file != null) {
            targetDefaultDir = file.getParent();
            sourceDefaultDir = sourceDefaultDir == null ? targetDefaultDir : sourceDefaultDir;
            defaultSaveDir = defaultSaveDir == null ? targetDefaultDir : defaultSaveDir;
            picker.targetLanguageFileField.setText(file.getAbsolutePath());
        }
    });
    picker.sourceLanguageFileField.setText(sourceFile);
    picker.sourceLanguageFileField.getDocument().addDocumentListener(new DocumentListener() {

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

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

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

        private void update() {
            sourceFile = picker.sourceLanguageFileField.getText();
            updatePicker(picker);
        }
    });
    picker.targetLanguageFileField.setText(targetFile);
    picker.targetLanguageFileField.getDocument().addDocumentListener(new DocumentListener() {

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

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

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

        private void update() {
            targetFile = picker.targetLanguageFileField.getText();
            updatePicker(picker);
        }
    });
    TransferHandler transferHandler = new TransferHandler() {

        @Override
        public boolean canImport(TransferSupport support) {
            return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
        }

        @Override
        public boolean importData(TransferSupport support) {
            if (!canImport(support)) {
                return false;
            }
            try {
                List<?> list = (List<?>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                List<File> files = getSupportedFiles(list);
                if (files.isEmpty()) {
                    return false;
                }
                JTextComponent field = (JTextComponent) support.getComponent();
                field.setText(files.get(0).getAbsolutePath());
                return true;
            } catch (Exception e) {
                Log.log(e);
                return false;
            }
        }
    };
    picker.sourceLanguageFileField.setTransferHandler(transferHandler);
    picker.targetLanguageFileField.setTransferHandler(transferHandler);
    picker.setTransferHandler(new TransferHandler() {

        @Override
        public boolean canImport(TransferSupport support) {
            return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
        }

        @Override
        public boolean importData(TransferSupport support) {
            if (!canImport(support)) {
                return false;
            }
            try {
                List<?> list = (List<?>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                List<File> files = getSupportedFiles(list);
                if (files.isEmpty()) {
                    return false;
                } else if (files.size() == 1) {
                    JTextComponent insertTarget = picker.sourceLanguageFileField;
                    if (picker.sourceLanguageFileField.getDocument().getLength() != 0 && picker.targetLanguageFileField.getDocument().getLength() == 0) {
                        insertTarget = picker.targetLanguageFileField;
                    }
                    insertTarget.setText(files.get(0).getAbsolutePath());
                } else {
                    picker.sourceLanguageFileField.setText(files.get(0).getAbsolutePath());
                    picker.targetLanguageFileField.setText(files.get(1).getAbsolutePath());
                }
                return true;
            } catch (Exception e) {
                Log.log(e);
                return false;
            }
        }
    });
    picker.okButton.addActionListener(e -> {
        picker.bottomPanel.remove(picker.messageTextArea);
        picker.bottomPanel.add(picker.progressBar, BorderLayout.CENTER);
        picker.bottomPanel.revalidate();
        new SwingWorker<Aligner, Void>() {

            @Override
            protected Aligner doInBackground() throws Exception {
                Aligner aligner = new Aligner(sourceFile, sourceLanguage, targetFile, targetLanguage);
                aligner.loadFiles();
                return aligner;
            }

            @Override
            protected void done() {
                try {
                    Aligner aligner = get();
                    new AlignPanelController(aligner, defaultSaveDir).show(parent);
                } catch (CancellationException e) {
                // Ignore
                } catch (Exception e) {
                    Log.log(e);
                    JOptionPane.showMessageDialog(frame, OStrings.getString("ALIGNER_ERROR_LOADING"), OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE);
                }
                frame.dispose();
            }
        }.execute();
    });
    picker.cancelButton.addActionListener(e -> frame.dispose());
    frame.getRootPane().setDefaultButton(picker.okButton);
    updatePicker(picker);
    frame.add(picker);
    frame.pack();
    frame.setLocationRelativeTo(parent);
    frame.setVisible(true);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) ItemEvent(java.awt.event.ItemEvent) JTextComponent(javax.swing.text.JTextComponent) Language(org.omegat.util.Language) JFrame(javax.swing.JFrame) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) DocumentEvent(javax.swing.event.DocumentEvent) CancellationException(java.util.concurrent.CancellationException) LanguageComboBoxRenderer(org.omegat.util.gui.LanguageComboBoxRenderer) CancellationException(java.util.concurrent.CancellationException) TransferHandler(javax.swing.TransferHandler) ItemListener(java.awt.event.ItemListener) File(java.io.File)

Example 39 with ItemEvent

use of java.awt.event.ItemEvent in project frostwire by frostwire.

the class MessageService method alwaysUseThisAnswerLabel.

private final JComponent alwaysUseThisAnswerLabel(final String message, final IntSetting setting) {
    JPanel thePanel = new JPanel(new BorderLayout(0, 15));
    JCheckBox option = new JCheckBox(I18n.tr("Always use this answer"));
    JComponent lbl = getLabel(message);
    thePanel.add(lbl, BorderLayout.NORTH);
    thePanel.add(option, BorderLayout.WEST);
    option.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                setting.setValue(REMEMBER_ANSWER);
            else
                setting.setValue(FORGET_ANSWER);
        }
    });
    return thePanel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener)

Example 40 with ItemEvent

use of java.awt.event.ItemEvent in project frostwire by frostwire.

the class MessageService method doNotDisplayAgainLabel.

private final JComponent doNotDisplayAgainLabel(final String message, final Switch setting) {
    JPanel thePanel = new JPanel(new BorderLayout(0, 15));
    JCheckBox option = new JCheckBox(I18n.tr("Do not display this message again"));
    JComponent lbl = getLabel(message);
    thePanel.add(lbl, BorderLayout.NORTH);
    thePanel.add(option, BorderLayout.WEST);
    option.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            setting.setValue(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    return thePanel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener)

Aggregations

ItemEvent (java.awt.event.ItemEvent)346 ItemListener (java.awt.event.ItemListener)320 ActionEvent (java.awt.event.ActionEvent)124 ActionListener (java.awt.event.ActionListener)114 JPanel (javax.swing.JPanel)106 JLabel (javax.swing.JLabel)84 JCheckBox (javax.swing.JCheckBox)74 JComboBox (javax.swing.JComboBox)65 Dimension (java.awt.Dimension)59 JButton (javax.swing.JButton)53 BorderLayout (java.awt.BorderLayout)48 JTextField (javax.swing.JTextField)46 ButtonGroup (javax.swing.ButtonGroup)35 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)33 ChangeEvent (javax.swing.event.ChangeEvent)32 ChangeListener (javax.swing.event.ChangeListener)31 GridLayout (java.awt.GridLayout)30 GridBagConstraints (java.awt.GridBagConstraints)29 JMenu (javax.swing.JMenu)29 GridBagLayout (java.awt.GridBagLayout)28