Search in sources :

Example 56 with ChangeListener

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

the class ToolEditorDialog method addListeners.

private void addListeners() {
    myOutputFiltersButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            OutputFiltersDialog dialog = new OutputFiltersDialog(myOutputFiltersButton, getData().getOutputFilters());
            if (dialog.showAndGet()) {
                myOutputFilters = dialog.getData();
            }
        }
    });
    myInsertCommandMacroButton.addActionListener(new InsertMacroActionListener(myTfCommand));
    myInsertParametersMacroButton.addActionListener(new InsertMacroActionListener(myParametersField));
    myInsertWorkingDirectoryMacroButton.addActionListener(new InsertMacroActionListener(myTfCommandWorkingDirectory));
    myNameField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            handleOKButton();
        }
    });
    myUseConsoleCheckbox.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            myShowConsoleOnStdOutCheckbox.setVisible(myUseConsoleCheckbox.isSelected());
            myShowConsoleOnStdErrCheckbox.setVisible(myUseConsoleCheckbox.isSelected());
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) ChangeListener(javax.swing.event.ChangeListener) DocumentEvent(javax.swing.event.DocumentEvent)

Example 57 with ChangeListener

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

the class AllFileTemplatesConfigurable method createComponent.

@Override
public JComponent createComponent() {
    myUIDisposable = Disposer.newDisposable();
    myTemplatesList = new FileTemplateTabAsList(TEMPLATES_TITLE) {

        @Override
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myIncludesList = new FileTemplateTabAsList(INCLUDES_TITLE) {

        @Override
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myCodeTemplatesList = new FileTemplateTabAsList(CODE_TITLE) {

        @Override
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myCurrentTab = myTemplatesList;
    final List<FileTemplateTab> allTabs = new ArrayList<>(Arrays.asList(myTemplatesList, myIncludesList, myCodeTemplatesList));
    final FileTemplateGroupDescriptorFactory[] factories = Extensions.getExtensions(FileTemplateGroupDescriptorFactory.EXTENSION_POINT_NAME);
    if (factories.length != 0) {
        myOtherTemplatesList = new FileTemplateTabAsTree(OTHER_TITLE) {

            @Override
            public void onTemplateSelected() {
                onListSelectionChanged();
            }

            @Override
            protected FileTemplateNode initModel() {
                SortedSet<FileTemplateGroupDescriptor> categories = new TreeSet<>((o1, o2) -> o1.getTitle().compareTo(o2.getTitle()));
                for (FileTemplateGroupDescriptorFactory templateGroupFactory : factories) {
                    ContainerUtil.addIfNotNull(categories, templateGroupFactory.getFileTemplatesDescriptor());
                }
                //noinspection HardCodedStringLiteral
                return new FileTemplateNode("ROOT", null, ContainerUtil.map2List(categories, s -> new FileTemplateNode(s)));
            }
        };
        allTabs.add(myOtherTemplatesList);
    }
    myEditor = new FileTemplateConfigurable(myProject);
    myEditor.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            onEditorChanged();
        }
    });
    myEditorComponent = myEditor.createComponent();
    myEditorComponent.setBorder(JBUI.Borders.empty(10, 0, 10, 10));
    myTabs = allTabs.toArray(new FileTemplateTab[allTabs.size()]);
    myTabbedPane = new TabbedPaneWrapper(myUIDisposable);
    myTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    myLeftPanel = new JPanel(new CardLayout());
    myLeftPanel.setBorder(JBUI.Borders.empty(10, 10, 10, 0));
    for (FileTemplateTab tab : myTabs) {
        myLeftPanel.add(ScrollPaneFactory.createScrollPane(tab.getComponent()), tab.getTitle());
        JPanel fakePanel = new JPanel();
        fakePanel.setPreferredSize(new Dimension(0, 0));
        myTabbedPane.addTab(tab.getTitle(), fakePanel);
    }
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            onTabChanged();
        }
    });
    DefaultActionGroup group = new DefaultActionGroup();
    AnAction removeAction = new AnAction(IdeBundle.message("action.remove.template"), null, AllIcons.General.Remove) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            onRemove();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
            e.getPresentation().setEnabled(selectedItem != null && !isInternalTemplate(selectedItem.getName(), myCurrentTab.getTitle()));
        }
    };
    AnAction addAction = new AnAction(IdeBundle.message("action.create.template"), null, AllIcons.General.Add) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            onAdd();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            e.getPresentation().setEnabled(!(myCurrentTab == myCodeTemplatesList || myCurrentTab == myOtherTemplatesList));
        }
    };
    AnAction cloneAction = new AnAction(IdeBundle.message("action.copy.template"), null, PlatformIcons.COPY_ICON) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            onClone();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            e.getPresentation().setEnabled(myCurrentTab != myCodeTemplatesList && myCurrentTab != myOtherTemplatesList && myCurrentTab.getSelectedTemplate() != null);
        }
    };
    AnAction resetAction = new AnAction(IdeBundle.message("action.reset.to.default"), null, AllIcons.Actions.Reset) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            onReset();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            final FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
            e.getPresentation().setEnabled(selectedItem instanceof BundledFileTemplate && !selectedItem.isDefault());
        }
    };
    group.add(addAction);
    group.add(removeAction);
    group.add(cloneAction);
    group.add(resetAction);
    addAction.registerCustomShortcutSet(CommonShortcuts.INSERT, myCurrentTab.getComponent());
    removeAction.registerCustomShortcutSet(CommonShortcuts.getDelete(), myCurrentTab.getComponent());
    myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent();
    myToolBar.setBorder(IdeBorderFactory.createEmptyBorder());
    JPanel toolbarPanel = new JPanel(new BorderLayout());
    toolbarPanel.add(myToolBar, BorderLayout.WEST);
    JComponent schemaComponent = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, new DefaultCompactActionGroup(new ChangeSchemaCombo(this)), true).getComponent();
    JPanel schemaPanel = new JPanel(new BorderLayout());
    schemaPanel.add(schemaComponent, BorderLayout.EAST);
    schemaPanel.add(new JLabel("Schema:"), BorderLayout.WEST);
    toolbarPanel.add(schemaPanel, BorderLayout.EAST);
    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(myTabbedPane.getComponent(), BorderLayout.NORTH);
    Splitter splitter = new Splitter(false, 0.3f);
    splitter.setDividerWidth(JBUI.scale(10));
    splitter.setFirstComponent(myLeftPanel);
    splitter.setSecondComponent(myEditorComponent);
    centerPanel.add(splitter, BorderLayout.CENTER);
    myMainPanel = new JPanel(new BorderLayout());
    myMainPanel.add(toolbarPanel, BorderLayout.NORTH);
    myMainPanel.add(centerPanel, BorderLayout.CENTER);
    final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
    final String tabName = propertiesComponent.getValue(CURRENT_TAB);
    if (selectTab(tabName)) {
    //final String selectedTemplateName = propertiesComponent.getValue(SELECTED_TEMPLATE);
    //for (FileTemplate template : myCurrentTab.getTemplates()) {
    //  if (Comparing.strEqual(template.getName(), selectedTemplateName)) {
    //    myCurrentTab.selectTemplate(template);
    //    break;
    //  }
    //}
    }
    return myMainPanel;
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) ArrayUtil(com.intellij.util.ArrayUtil) URL(java.net.URL) com.intellij.ide.fileTemplates(com.intellij.ide.fileTemplates) ContainerUtil(com.intellij.util.containers.ContainerUtil) MessageFormat(java.text.MessageFormat) Comparing(com.intellij.openapi.util.Comparing) JBUI(com.intellij.util.ui.JBUI) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) ChangeListener(javax.swing.event.ChangeListener) Logger(com.intellij.openapi.diagnostic.Logger) Splitter(com.intellij.openapi.ui.Splitter) PlatformIcons(com.intellij.util.PlatformIcons) ChangeEvent(javax.swing.event.ChangeEvent) Extensions(com.intellij.openapi.extensions.Extensions) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) Configurable(com.intellij.openapi.options.Configurable) Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) IdeBundle(com.intellij.ide.IdeBundle) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) javax.swing(javax.swing) ChangeListener(javax.swing.event.ChangeListener) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) Splitter(com.intellij.openapi.ui.Splitter) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) ChangeEvent(javax.swing.event.ChangeEvent)

Example 58 with ChangeListener

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

the class DocumentationComponent method createSettingsPanel.

private JComponent createSettingsPanel() {
    JPanel result = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 0));
    result.add(new JLabel(ApplicationBundle.message("label.font.size")));
    myFontSizeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, FontSize.values().length - 1, 3);
    myFontSizeSlider.setMinorTickSpacing(1);
    myFontSizeSlider.setPaintTicks(true);
    myFontSizeSlider.setPaintTrack(true);
    myFontSizeSlider.setSnapToTicks(true);
    UIUtil.setSliderIsFilled(myFontSizeSlider, true);
    result.add(myFontSizeSlider);
    result.setBorder(BorderFactory.createLineBorder(JBColor.border(), 1));
    myFontSizeSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (myIgnoreFontSizeSliderChange) {
                return;
            }
            setQuickDocFontSize(FontSize.values()[myFontSizeSlider.getValue()]);
            applyFontSize();
        }
    });
    String tooltipText = ApplicationBundle.message("quickdoc.tooltip.font.size.by.wheel");
    result.setToolTipText(tooltipText);
    myFontSizeSlider.setToolTipText(tooltipText);
    result.setVisible(false);
    result.setOpaque(true);
    myFontSizeSlider.setOpaque(true);
    return result;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 59 with ChangeListener

use of javax.swing.event.ChangeListener 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 60 with ChangeListener

use of javax.swing.event.ChangeListener in project jgnash by ccavanaugh.

the class JideSwingUtilities method synchronizeView.

/**
     * Synchronizes the two viewports. The view position changes in the master view, the slave view's view position will
     * change too. Generally speaking, if you want the two viewports to synchronize vertically, they should have the
     * same height. If horizontally, the same width.
     * <p>
     * It's OK if you call this method with the same master viewport and slave viewport duplicate times. It won't cause
     * multiple events fired.
     *
     * @param masterViewport the master viewport
     * @param slaveViewport  the slave viewport
     * @param orientation    the orientation. It could be either SwingConstants.HORIZONTAL or SwingConstants.VERTICAL.
     */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void synchronizeView(final JViewport masterViewport, final JViewport slaveViewport, final int orientation) {
    if (masterViewport == null || slaveViewport == null) {
        return;
    }
    ChangeListener[] changeListeners = masterViewport.getChangeListeners();
    int i = 0;
    for (; i < changeListeners.length; i++) {
        if (changeListeners[i] == getViewportSynchronizationChangeListener()) {
            break;
        }
    }
    if (i >= changeListeners.length) {
        masterViewport.addChangeListener(getViewportSynchronizationChangeListener());
    }
    Object property = masterViewport.getClientProperty(JideScrollPane.CLIENT_PROPERTY_SLAVE_VIEWPORT);
    if (!(property instanceof Map)) {
        property = new HashMap<JViewport, Integer>();
    }
    Map<JViewport, Integer> slaveViewportMap = (Map) property;
    slaveViewportMap.put(slaveViewport, orientation);
    masterViewport.putClientProperty(JideScrollPane.CLIENT_PROPERTY_SLAVE_VIEWPORT, slaveViewportMap);
    property = slaveViewport.getClientProperty(JideScrollPane.CLIENT_PROPERTY_MASTER_VIEWPORT);
    if (!(property instanceof Map)) {
        property = new HashMap<JViewport, Integer>();
    }
    Map<JViewport, Integer> masterViewportMap = (Map) property;
    masterViewportMap.put(masterViewport, orientation);
    slaveViewport.putClientProperty(JideScrollPane.CLIENT_PROPERTY_MASTER_VIEWPORT, masterViewportMap);
}
Also used : JViewport(javax.swing.JViewport) ChangeListener(javax.swing.event.ChangeListener) Map(java.util.Map) HashMap(java.util.HashMap) Point(java.awt.Point)

Aggregations

ChangeListener (javax.swing.event.ChangeListener)218 ChangeEvent (javax.swing.event.ChangeEvent)205 JPanel (javax.swing.JPanel)54 ActionEvent (java.awt.event.ActionEvent)47 ActionListener (java.awt.event.ActionListener)46 JLabel (javax.swing.JLabel)34 Dimension (java.awt.Dimension)29 GridBagConstraints (java.awt.GridBagConstraints)27 GridBagLayout (java.awt.GridBagLayout)24 JCheckBox (javax.swing.JCheckBox)24 Insets (java.awt.Insets)21 JSlider (javax.swing.JSlider)20 PropertyChangeListener (java.beans.PropertyChangeListener)19 JButton (javax.swing.JButton)19 BorderLayout (java.awt.BorderLayout)17 PropertyChangeEvent (java.beans.PropertyChangeEvent)17 IOException (java.io.IOException)14 BoxLayout (javax.swing.BoxLayout)14 ButtonGroup (javax.swing.ButtonGroup)14 JSpinner (javax.swing.JSpinner)13