Search in sources :

Example 51 with ChangeListener

use of javax.swing.event.ChangeListener in project ChatGameFontificator by GlitchCog.

the class ControlPanelChat method build.

@Override
protected void build() {
    resizableBox = new JCheckBox("Resize Chat by Dragging");
    scrollableBox = new JCheckBox("Mouse Wheel Scrolls Chat");
    reverseScrollBox = new JCheckBox("Reverse Chat Order");
    chatFromBottomBox = new JCheckBox("Chat Starts from Bottom");
    widthInput = new LabeledInput("Width", 3);
    heightInput = new LabeledInput("Height", 3);
    DocumentListener chatSizeDocListener = new DocumentListener() {

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

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

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

        /**
             * Something changed, so try to get the new width and height and set the updateSizeButton to enabled or
             * disabled accordingly
             * 
             * @param e
             */
        private void somethingChanged(DocumentEvent e) {
            try {
                int w = Integer.parseInt(widthInput.getText());
                int h = Integer.parseInt(heightInput.getText());
                updateSizeButton.setEnabled(w != config.getWidth() || h != config.getHeight());
            } catch (Exception ex) {
                updateSizeButton.setEnabled(false);
            }
        }
    };
    DocumentListener chromaDocListener = new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            toggleChromaButtonEnabled();
        }
    };
    widthInput.addDocumentListener(chatSizeDocListener);
    heightInput.addDocumentListener(chatSizeDocListener);
    updateSizeButton = new JButton("Update Chat Size");
    chromaEnabledBox = new JCheckBox("Enable Chroma Key Border");
    chromaInvertBox = new JCheckBox("Invert Chroma Key Border");
    chromaCornerSlider = new LabeledSlider("Corner Radius", "pixels", ConfigChat.MIN_CHROMA_CORNER_RADIUS, ConfigChat.MAX_CHROMA_CORNER_RADIUS);
    final String[] chromaLabels = new String[] { "Left", "Top", "Right", "Bottom" };
    chromaBorderInput = new LabeledInput[chromaLabels.length];
    for (int i = 0; i < chromaBorderInput.length; i++) {
        chromaBorderInput[i] = new LabeledInput(chromaLabels[i], 4);
        chromaBorderInput[i].addDocumentListener(chromaDocListener);
    }
    updateChromaSizeButton = new JButton("Update Chroma Border");
    ActionListener boxListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox source = (JCheckBox) e.getSource();
            if (resizableBox.equals(source)) {
                chatWindow.setResizable(resizableBox.isSelected());
                config.setResizable(resizableBox.isSelected());
            } else if (scrollableBox.equals(source)) {
                config.setScrollable(scrollableBox.isSelected());
                if (!scrollableBox.isSelected()) {
                    // No scrolling, so reset any existing scroll offset
                    chat.resetScrollOffset();
                }
            } else if (reverseScrollBox.equals(source)) {
                config.setReverseScrolling(reverseScrollBox.isSelected());
            } else if (chatFromBottomBox.equals(source)) {
                // Reset scrolling to avoid having to translate it between chat-start top/bottom styles
                chat.resetScrollOffset();
                config.setChatFromBottom(chatFromBottomBox.isSelected());
            } else if (chromaEnabledBox.equals(source)) {
                config.setChromaEnabled(chromaEnabledBox.isSelected());
                toggleChromaInputFields();
            } else if (chromaInvertBox.equals(source)) {
                config.setChromaInvert(chromaInvertBox.isSelected());
            }
            chat.repaint();
        }
    };
    resizableBox.addActionListener(boxListener);
    scrollableBox.addActionListener(boxListener);
    reverseScrollBox.addActionListener(boxListener);
    chatFromBottomBox.addActionListener(boxListener);
    chromaEnabledBox.addActionListener(boxListener);
    chromaInvertBox.addActionListener(boxListener);
    ActionListener dimListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                LoadConfigReport report = new LoadConfigReport();
                config.validateDimStrings(report, widthInput.getText(), heightInput.getText());
                if (report.isErrorFree()) {
                    final int width = Integer.parseInt(widthInput.getText());
                    final int height = Integer.parseInt(heightInput.getText());
                    config.setWidth(width);
                    config.setHeight(height);
                    chatWindow.setSize(config.getWidth(), config.getHeight());
                } else {
                    ChatWindow.popup.handleProblem(report);
                }
            } catch (Exception ex) {
                ChatWindow.popup.handleProblem("Chat Width and Chat Height values could not be parsed", ex);
            }
        }
    };
    updateSizeButton.addActionListener(dimListener);
    ActionListener chromaDimListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                LoadConfigReport report = new LoadConfigReport();
                config.validateChromaDimStrings(report, chromaBorderInput[0].getText(), chromaBorderInput[1].getText(), chromaBorderInput[2].getText(), chromaBorderInput[3].getText());
                if (report.isErrorFree()) {
                    inputToConfigChromaBorders();
                    chat.repaint();
                } else {
                    ChatWindow.popup.handleProblem(report);
                }
            } catch (Exception ex) {
                ChatWindow.popup.handleProblem("Chat Chroma border values could not be parsed", ex);
            }
        }
    };
    updateChromaSizeButton.addActionListener(chromaDimListener);
    chromaCornerSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            config.setChromaCornerRadius(chromaCornerSlider.getValue());
            chat.repaint();
        }
    });
    JPanel chatDimPanel = new JPanel(new GridBagLayout());
    JPanel chatOptionsPanel = new JPanel(new GridBagLayout());
    JPanel chromaDimPanel = new JPanel(new GridBagLayout());
    chatDimPanel.setBorder(new TitledBorder(baseBorder, "Chat Window Size", TitledBorder.CENTER, TitledBorder.TOP));
    chatOptionsPanel.setBorder(new TitledBorder(baseBorder, "Chat Window Options", TitledBorder.CENTER, TitledBorder.TOP));
    chromaDimPanel.setBorder(baseBorder);
    GridBagConstraints dGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, DEFAULT_INSETS, 0, 0);
    dGbc.gridx = 0;
    dGbc.gridy = 0;
    dGbc.gridwidth = 1;
    chatDimPanel.add(widthInput, dGbc);
    dGbc.gridx++;
    chatDimPanel.add(heightInput, dGbc);
    dGbc.gridx = 0;
    dGbc.gridy++;
    dGbc.gridwidth = 2;
    chatDimPanel.add(updateSizeButton, dGbc);
    dGbc.gridy++;
    chatDimPanel.add(resizableBox, dGbc);
    dGbc.gridy++;
    GridBagConstraints coGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, DEFAULT_INSETS, 0, 0);
    coGbc.anchor = GridBagConstraints.WEST;
    chatOptionsPanel.add(scrollableBox, coGbc);
    coGbc.gridy++;
    chatOptionsPanel.add(reverseScrollBox, coGbc);
    coGbc.gridy++;
    chatOptionsPanel.add(chatFromBottomBox, coGbc);
    coGbc.gridy++;
    GridBagConstraints chromaGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, NO_INSETS, 0, 0);
    chromaGbc.gridwidth = 3;
    chromaDimPanel.add(chromaEnabledBox, chromaGbc);
    chromaGbc.gridy++;
    chromaDimPanel.add(chromaBorderInput[1], chromaGbc);
    chromaGbc.gridy++;
    chromaGbc.gridwidth = 1;
    chromaGbc.anchor = GridBagConstraints.EAST;
    chromaDimPanel.add(chromaBorderInput[0], chromaGbc);
    chromaGbc.gridx++;
    chromaGbc.anchor = GridBagConstraints.CENTER;
    chromaDimPanel.add(updateChromaSizeButton, chromaGbc);
    chromaGbc.gridx++;
    chromaGbc.anchor = GridBagConstraints.WEST;
    chromaDimPanel.add(chromaBorderInput[2], chromaGbc);
    chromaGbc.gridx = 0;
    chromaGbc.anchor = GridBagConstraints.CENTER;
    chromaGbc.gridy++;
    chromaGbc.gridwidth = 3;
    chromaDimPanel.add(chromaBorderInput[3], chromaGbc);
    chromaGbc.gridy++;
    chromaDimPanel.add(chromaInvertBox, chromaGbc);
    chromaGbc.gridy++;
    chromaDimPanel.add(chromaCornerSlider, chromaGbc);
    JPanel everything = new JPanel(new GridBagLayout());
    GridBagConstraints eGbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, NO_INSETS, 0, 0);
    eGbc.weighty = 0.5;
    eGbc.weightx = 0.5;
    eGbc.fill = GridBagConstraints.HORIZONTAL;
    eGbc.insets = new Insets(0, 3, 0, 3);
    everything.add(chatDimPanel, eGbc);
    eGbc.weightx = 0.5;
    eGbc.gridx++;
    everything.add(chatOptionsPanel, eGbc);
    eGbc.weightx = 1.0;
    eGbc.weighty = 0.0;
    eGbc.gridx = 0;
    eGbc.gridy++;
    eGbc.gridwidth = 2;
    eGbc.fill = GridBagConstraints.BOTH;
    eGbc.anchor = GridBagConstraints.CENTER;
    everything.add(chromaDimPanel, eGbc);
    eGbc.gridy++;
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    add(everything, gbc);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DocumentEvent(javax.swing.event.DocumentEvent) TitledBorder(javax.swing.border.TitledBorder) LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport) JCheckBox(javax.swing.JCheckBox) LabeledSlider(com.glitchcog.fontificator.gui.component.LabeledSlider) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 52 with ChangeListener

use of javax.swing.event.ChangeListener in project ChatGameFontificator by GlitchCog.

the class ControlPanelFont method build.

@Override
protected void build() {
    sliderListener = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (fontScaleSlider.getSlider().equals(source)) {
                config.setFontScale(fontScaleSlider.getScaledValue());
                fontScaleSlider.setValueTextColor(((int) config.getFontScale() == config.getFontScale()) ? SCALE_EVEN : SCALE_UNEVEN);
            } else if (borderScaleSlider.getSlider().equals(source)) {
                config.setBorderScale(borderScaleSlider.getScaledValue());
                borderScaleSlider.setValueTextColor(((int) config.getBorderScale() == config.getBorderScale()) ? SCALE_EVEN : SCALE_UNEVEN);
            } else if (borderInsetXSlider.getSlider().equals(source)) {
                config.setBorderInsetX(borderInsetXSlider.getValue());
            } else if (borderInsetYSlider.getSlider().equals(source)) {
                config.setBorderInsetY(borderInsetYSlider.getValue());
            } else if (spaceWidthSlider.getSlider().equals(source)) {
                config.setSpaceWidth(spaceWidthSlider.getValue());
            } else if (baselineOffsetSlider.getSlider().equals(source)) {
                config.setBaselineOffset(baselineOffsetSlider.getValue());
            } else if (lineSpacingSlider.getSlider().equals(source)) {
                config.setLineSpacing(lineSpacingSlider.getValue());
            } else if (charSpacingSlider.getSlider().equals(source)) {
                config.setCharSpacing(charSpacingSlider.getValue());
            }
            chat.repaint();
        }
    };
    ActionListener fontAl = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JMenuItem source = (JMenuItem) e.getSource();
            DropdownLabel key = new DropdownLabel(source.getText());
            if (CUSTOM_KEY.equals(key)) {
                int selectionResult = fontPngPicker.showDialog(ControlWindow.me, "Select Font PNG");
                if (selectionResult == JFileChooser.APPROVE_OPTION) {
                    fontFilenameInput.setText(fontPngPicker.getSelectedFile().getAbsolutePath());
                    fontPresetDropdown.setSelectedText(fontPngPicker.getSelectedFile().getName());
                }
            } else {
                fontFilenameInput.setText(PRESET_FONT_FILE_MAP.get(key).getFontFilename());
                fontTypeCheckbox.setSelected(FontType.VARIABLE_WIDTH.equals(PRESET_FONT_FILE_MAP.get(key).getDefaultType()));
                spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
            }
            updateFontOrBorder(true);
        }
    };
    ActionListener borderAl = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JMenuItem source = (JMenuItem) e.getSource();
            DropdownLabel key = new DropdownLabel(source.getText());
            if (CUSTOM_KEY.equals(key)) {
                int selectionResult = borderPngPicker.showDialog(ControlWindow.me, "Select Border PNG");
                if (selectionResult == JFileChooser.APPROVE_OPTION) {
                    borderFilenameInput.setText(borderPngPicker.getSelectedFile().getAbsolutePath());
                    borderPresetDropdown.setSelectedText(borderPngPicker.getSelectedFile().getName());
                }
            } else {
                DropdownBorder border = PRESET_BORDER_FILE_MAP.get(key);
                borderFilenameInput.setText(border.getBorderFilename());
                colorPanel.setBorderColor(border.getDefaultTint());
            }
            updateFontOrBorder(false);
        }
    };
    fontTypeListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            config.setFontType(fontTypeCheckbox.isSelected() ? FontType.VARIABLE_WIDTH : FontType.FIXED_WIDTH);
            spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
            updateFontOrBorder(true);
        }
    };
    extendedCharBox = new JCheckBox("Display Extended Characters");
    extendedCharBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final boolean ecbSelected = extendedCharBox.isSelected();
            config.setExtendedCharEnabled(ecbSelected);
            unknownCharPopupButton.setEnabled(!ecbSelected);
            unknownCharLabel.setEnabled(!ecbSelected);
            chat.repaint();
        }
    });
    unknownCharLabel = new JLabel("");
    charPicker = new CharacterPicker(ControlWindow.me, fProps.getFontConfig(), unknownCharLabel, chat);
    Map<String, List<String>> fontMenuMap = getMenuMapFromPresets(PRESET_FONT_FILE_MAP.keySet());
    fontMenuMap.put(CUSTOM_KEY.getLabel(), null);
    Map<String, List<String>> borderMenuMap = getMenuMapFromPresets(PRESET_BORDER_FILE_MAP.keySet());
    borderMenuMap.put(CUSTOM_KEY.getLabel(), null);
    fontTypeCheckbox = new JCheckBox("Variable Width Characters");
    fontFilenameInput = new LabeledInput("Font Filename", 32);
    fontPresetDropdown = new ComboMenuBar(fontMenuMap, fontAl);
    borderFilenameInput = new LabeledInput("Border Filename", 32);
    borderPresetDropdown = new ComboMenuBar(borderMenuMap, borderAl);
    gridWidthInput = new LabeledInput("Grid Width", 4);
    gridHeightInput = new LabeledInput("Grid Height", 4);
    fontScaleSlider = new LabeledSlider("Font Scale", "x", ConfigFont.MIN_FONT_SCALE, ConfigFont.MAX_FONT_SCALE, ConfigFont.FONT_BORDER_SCALE_GRANULARITY);
    borderScaleSlider = new LabeledSlider("Border Scale", "x", ConfigFont.MIN_BORDER_SCALE, ConfigFont.MAX_BORDER_SCALE, ConfigFont.FONT_BORDER_SCALE_GRANULARITY);
    borderInsetXSlider = new LabeledSlider("X", "pixels", ConfigFont.MIN_BORDER_INSET, ConfigFont.MAX_BORDER_INSET);
    borderInsetYSlider = new LabeledSlider("Y", "pixels", ConfigFont.MIN_BORDER_INSET, ConfigFont.MAX_BORDER_INSET);
    characterKeyInput = new LabeledInput("Character Key", 32);
    spaceWidthSlider = new LabeledSlider("Space Width", "%", ConfigFont.MIN_SPACE_WIDTH, ConfigFont.MAX_SPACE_WIDTH);
    baselineOffsetSlider = new LabeledSlider("Baseline Height Offset", "pixels", ConfigFont.MIN_BASELINE_OFFSET, ConfigFont.MAX_BASELINE_OFFSET);
    lineSpacingSlider = new LabeledSlider("Line Spacing", "pixels", ConfigFont.MIN_LINE_SPACING, ConfigFont.MAX_LINE_SPACING);
    charSpacingSlider = new LabeledSlider("Char Spacing", "pixels", ConfigFont.MIN_CHAR_SPACING, ConfigFont.MAX_LINE_SPACING);
    unknownCharPopupButton = new JButton("Select Missing Character");
    unknownCharPopupButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            charPicker.setVisible(true);
        }
    });
    fontFilenameInput.setEnabled(false);
    borderFilenameInput.setEnabled(false);
    fontScaleSlider.addChangeListener(sliderListener);
    borderScaleSlider.addChangeListener(sliderListener);
    borderInsetXSlider.addChangeListener(sliderListener);
    borderInsetYSlider.addChangeListener(sliderListener);
    spaceWidthSlider.addChangeListener(sliderListener);
    baselineOffsetSlider.addChangeListener(sliderListener);
    lineSpacingSlider.addChangeListener(sliderListener);
    charSpacingSlider.addChangeListener(sliderListener);
    JPanel fontPanel = new JPanel(new GridBagLayout());
    JPanel borderPanel = new JPanel(new GridBagLayout());
    JPanel unknownPanel = new JPanel(new GridBagLayout());
    fontPanel.setBorder(new TitledBorder(baseBorder, "Font"));
    borderPanel.setBorder(new TitledBorder(baseBorder, "Border"));
    unknownPanel.setBorder(new TitledBorder(baseBorder, "Extended and Unicode Characters"));
    GridBagConstraints fontGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
    GridBagConstraints borderGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
    GridBagConstraints unknownGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
    // Fields are still used and stored in properties files when saved, but the values are either fixed or meant to
    // be filled by other components
    // add(fontFilenameInput);
    // add(borderFilenameInput);
    // add(gridWidthInput);
    // add(gridHeightInput);
    // add(characterKeyInput);
    fontPanel.add(fontPresetDropdown, fontGbc);
    fontGbc.gridx++;
    // This slider being on the same row as the preset dropdown keeps the combo menu bar from collapsing to no
    // height in the layout
    fontPanel.add(fontScaleSlider, fontGbc);
    fontGbc.gridwidth = 2;
    fontGbc.gridx = 0;
    fontGbc.gridy++;
    fontPanel.add(lineSpacingSlider, fontGbc);
    fontGbc.gridy++;
    fontPanel.add(charSpacingSlider, fontGbc);
    fontGbc.gridy++;
    JPanel variableWidthPanel = new JPanel(new GridBagLayout());
    GridBagConstraints vwpGbc = getGbc();
    vwpGbc.anchor = GridBagConstraints.EAST;
    vwpGbc.weightx = 0.0;
    vwpGbc.fill = GridBagConstraints.NONE;
    variableWidthPanel.add(fontTypeCheckbox, vwpGbc);
    vwpGbc.anchor = GridBagConstraints.WEST;
    vwpGbc.weightx = 1.0;
    vwpGbc.fill = GridBagConstraints.HORIZONTAL;
    vwpGbc.gridx++;
    variableWidthPanel.add(spaceWidthSlider, vwpGbc);
    fontPanel.add(variableWidthPanel, fontGbc);
    fontGbc.gridy++;
    fontPanel.add(baselineOffsetSlider, fontGbc);
    fontGbc.gridy++;
    borderPanel.add(borderPresetDropdown, borderGbc);
    borderGbc.gridx++;
    // This slider being on the same row as the preset dropdown keeps the combo menu bar from collapsing to no
    // height in the layout
    borderPanel.add(borderScaleSlider, borderGbc);
    borderGbc.gridwidth = 2;
    borderGbc.gridx = 0;
    borderGbc.gridy++;
    borderGbc.anchor = GridBagConstraints.CENTER;
    borderPanel.add(new JLabel("Font Insets Off Border"), borderGbc);
    borderGbc.gridy++;
    borderPanel.add(borderInsetXSlider, borderGbc);
    borderGbc.gridy++;
    borderPanel.add(borderInsetYSlider, borderGbc);
    borderGbc.gridy++;
    unknownPanel.add(extendedCharBox, unknownGbc);
    unknownGbc.gridx++;
    unknownPanel.add(unknownCharPopupButton, unknownGbc);
    unknownGbc.gridx++;
    unknownPanel.add(unknownCharLabel, unknownGbc);
    unknownGbc.gridx++;
    JPanel everything = new JPanel(new GridBagLayout());
    GridBagConstraints eGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 10, 10);
    everything.add(fontPanel, eGbc);
    eGbc.gridy++;
    everything.add(borderPanel, eGbc);
    eGbc.gridy++;
    everything.add(unknownPanel, eGbc);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    add(everything, gbc);
    // Filler panel
    gbc.gridy++;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.SOUTH;
    add(new JPanel(), gbc);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) DropdownBorder(com.glitchcog.fontificator.gui.controls.panel.model.DropdownBorder) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DropdownLabel(com.glitchcog.fontificator.gui.controls.panel.model.DropdownLabel) TitledBorder(javax.swing.border.TitledBorder) JCheckBox(javax.swing.JCheckBox) LabeledSlider(com.glitchcog.fontificator.gui.component.LabeledSlider) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) CharacterPicker(com.glitchcog.fontificator.gui.component.CharacterPicker) JSlider(javax.swing.JSlider) ComboMenuBar(com.glitchcog.fontificator.gui.component.combomenu.ComboMenuBar) ChangeListener(javax.swing.event.ChangeListener) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem)

Example 53 with ChangeListener

use of javax.swing.event.ChangeListener in project jmeter by apache.

the class RespTimeGraphVisualizer method init.

/**
     * Initialize the GUI.
     */
private void init() {
    // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
    this.setLayout(new BorderLayout());
    // MAIN PANEL
    JPanel mainPanel = new JPanel();
    Border margin = new EmptyBorder(10, 10, 5, 10);
    Border margin2 = new EmptyBorder(10, 10, 5, 10);
    mainPanel.setBorder(margin);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.add(makeTitlePanel());
    JPanel settingsPane = new VerticalPanel();
    settingsPane.setBorder(margin2);
    graphPanel = new RespTimeGraphChart();
    graphPanel.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGTH));
    settingsPane.add(createGraphActionsPane());
    settingsPane.add(createGraphSettingsPane());
    settingsPane.add(createGraphTitlePane());
    settingsPane.add(createLinePane());
    settingsPane.add(createGraphDimensionPane());
    JPanel axisPane = new JPanel(new BorderLayout());
    axisPane.add(createGraphXAxisPane(), BorderLayout.WEST);
    axisPane.add(createGraphYAxisPane(), BorderLayout.CENTER);
    settingsPane.add(axisPane);
    settingsPane.add(createLegendPane());
    //$NON-NLS-1$
    tabbedGraph.addTab(JMeterUtils.getResString("aggregate_graph_tab_settings"), settingsPane);
    //$NON-NLS-1$
    tabbedGraph.addTab(JMeterUtils.getResString("aggregate_graph_tab_graph"), graphPanel);
    // If clic on the Graph tab, make the graph (without apply interval or filter)
    ChangeListener changeListener = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane srcTab = (JTabbedPane) changeEvent.getSource();
            int index = srcTab.getSelectedIndex();
            if (srcTab.getTitleAt(index).equals(JMeterUtils.getResString("aggregate_graph_tab_graph"))) {
                //$NON-NLS-1$
                actionMakeGraph();
            }
        }
    };
    tabbedGraph.addChangeListener(changeListener);
    this.add(mainPanel, BorderLayout.NORTH);
    this.add(tabbedGraph, BorderLayout.CENTER);
}
Also used : JPanel(javax.swing.JPanel) VerticalPanel(org.apache.jmeter.gui.util.VerticalPanel) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) BoxLayout(javax.swing.BoxLayout) JTabbedPane(javax.swing.JTabbedPane) ChangeListener(javax.swing.event.ChangeListener) Dimension(java.awt.Dimension) EmptyBorder(javax.swing.border.EmptyBorder) Border(javax.swing.border.Border) EmptyBorder(javax.swing.border.EmptyBorder)

Example 54 with ChangeListener

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

the class AbstractTreeClassChooserDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
    myTree = new Tree(model);
    ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {

        @Override
        public boolean isFlattenPackages() {
            return false;
        }

        @Override
        public boolean isShowMembers() {
            return myIsShowMembers;
        }

        @Override
        public boolean isHideEmptyMiddlePackages() {
            return true;
        }

        @Override
        public boolean isAbbreviatePackageNames() {
            return false;
        }

        @Override
        public boolean isShowLibraryContents() {
            return myIsShowLibraryContents;
        }

        @Override
        public boolean isShowModules() {
            return false;
        }
    };
    myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandRow(0);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setCellRenderer(new NodeRenderer());
    UIUtil.setLineStyleAngled(myTree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                doOKAction();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
            if (path != null && myTree.isPathSelected(path)) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            handleSelectionChanged();
        }
    });
    new TreeSpeedSearch(myTree);
    myTabbedPane = new TabbedPaneWrapper(getDisposable());
    final JPanel dummyPanel = new JPanel(new BorderLayout());
    String name = null;
    /*
    if (myInitialClass != null) {
      name = myInitialClass.getName();
    }
*/
    myGotoByNamePanel = new ChooseByNamePanel(myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) {

        @Override
        protected void showTextFieldPanel() {
        }

        @Override
        protected void close(boolean isOk) {
            super.close(isOk);
            if (isOk) {
                doOKAction();
            } else {
                doCancelAction();
            }
        }

        @NotNull
        @Override
        protected Set<Object> filter(@NotNull Set<Object> elements) {
            return doFilter(elements);
        }

        @Override
        protected void initUI(ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()), true);
            });
        }

        @Override
        protected void showList() {
            super.showList();
            if (myInitialClass != null && myList.getModel().getSize() > 0) {
                myList.setSelectedValue(myInitialClass, true);
                myInitialClass = null;
            }
        }

        @Override
        protected void chosenElementMightChange() {
            handleSelectionChanged();
        }
    };
    Disposer.register(myDisposable, myGotoByNamePanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
    myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false);
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            handleSelectionChanged();
        }
    });
    return myTabbedPane.getComponent();
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) NotNull(org.jetbrains.annotations.NotNull) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) KeyEvent(java.awt.event.KeyEvent) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) Tree(com.intellij.ui.treeStructure.Tree) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) ModalityState(com.intellij.openapi.application.ModalityState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 55 with ChangeListener

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

the class FileStructureDialog method addNarrowDownCheckbox.

private void addNarrowDownCheckbox(final JPanel panel) {
    final JCheckBox checkBox = new JCheckBox(IdeBundle.message("checkbox.narrow.down.the.list.on.typing"));
    checkBox.setSelected(PropertiesComponent.getInstance().isTrueValue(ourPropertyKey));
    checkBox.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            myShouldNarrowDown = checkBox.isSelected();
            PropertiesComponent.getInstance().setValue(ourPropertyKey, myShouldNarrowDown);
            ProjectListBuilder builder = (ProjectListBuilder) myCommanderPanel.getBuilder();
            if (builder == null) {
                return;
            }
            builder.addUpdateRequest();
        }
    });
    checkBox.setFocusable(false);
    panel.add(checkBox);
//,new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
}
Also used : ProjectListBuilder(com.intellij.ide.commander.ProjectListBuilder) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener)

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