Search in sources :

Example 1 with ComboMenuBar

use of com.glitchcog.fontificator.gui.component.combomenu.ComboMenuBar 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)

Aggregations

CharacterPicker (com.glitchcog.fontificator.gui.component.CharacterPicker)1 LabeledInput (com.glitchcog.fontificator.gui.component.LabeledInput)1 LabeledSlider (com.glitchcog.fontificator.gui.component.LabeledSlider)1 ComboMenuBar (com.glitchcog.fontificator.gui.component.combomenu.ComboMenuBar)1 DropdownBorder (com.glitchcog.fontificator.gui.controls.panel.model.DropdownBorder)1 DropdownLabel (com.glitchcog.fontificator.gui.controls.panel.model.DropdownLabel)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 JSlider (javax.swing.JSlider)1 TitledBorder (javax.swing.border.TitledBorder)1 ChangeEvent (javax.swing.event.ChangeEvent)1