Search in sources :

Example 1 with LabeledInput

use of com.glitchcog.fontificator.gui.component.LabeledInput 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 2 with LabeledInput

use of com.glitchcog.fontificator.gui.component.LabeledInput 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 3 with LabeledInput

use of com.glitchcog.fontificator.gui.component.LabeledInput in project ChatGameFontificator by GlitchCog.

the class ControlPanelIrc method build.

@Override
protected void build() {
    userInput = new LabeledInput("Username", 11);
    authInput = new LabeledInput("OAuth Token", true, 25);
    authHelpButton = new JButton("Get OAuth Token");
    chanInput = new LabeledInput("Channel", 11);
    hostInput = new LabeledInput("Host", 7);
    portInput = new LabeledInput("Port", 3);
    FocusListener fl = new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        public void focusLost(FocusEvent e) {
            // the configuration
            try {
                fillConfigFromInput();
            } catch (Exception ex) {
                logger.trace(ex.toString(), ex);
            }
        }
    };
    userInput.addFocusListener(fl);
    authInput.addFocusListener(fl);
    chanInput.addFocusListener(fl);
    hostInput.addFocusListener(fl);
    portInput.addFocusListener(fl);
    authHelpButton.addActionListener(new ActionListener() {

        final String url = "http://www.twitchapps.com/tmi/";

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(URI.create(url));
            } catch (java.io.IOException ex) {
                ChatWindow.popup.handleProblem("Unable to open website at URL: " + url);
            }
        }
    });
    connectButton = new JButton(BUTTON_TEXT_CONNECT);
    connectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JButton source = (JButton) e.getSource();
            // Reset it just in case
            source.setText(bot.isConnected() ? BUTTON_TEXT_DISCONNECT : BUTTON_TEXT_CONNECT);
            if (bot.isConnected()) {
                bot.setDisconnectExpected(true);
                bot.disconnect();
            } else {
                try {
                    LoadConfigReport report = validateInputForConnect();
                    if (report.isErrorFree()) {
                        // Connect to the IRC channel
                        connect();
                        emojiControl.loadAndRunEmojiWork();
                    } else {
                        ChatWindow.popup.handleProblem(report);
                    }
                } catch (NumberFormatException ex) {
                    ChatWindow.popup.handleProblem("Invalid login port value", ex);
                } catch (NickAlreadyInUseException ex) {
                    ChatWindow.popup.handleProblem("Nickname already in use", ex);
                } catch (IOException ex) {
                    ChatWindow.popup.handleProblem("Error connecting to the IRC server. Verify the Internet connection and then the host and port values.", ex);
                } catch (IrcException ex) {
                    ChatWindow.popup.handleProblem("The host IRC server rejected the connection", ex);
                } catch (Exception ex) {
                    ChatWindow.popup.handleProblem("Unanticipated error connecting", ex);
                }
            }
        }
    });
    clearChatButton = new JButton("Clear Chat");
    clearChatButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            chat.clearChat();
            chat.repaint();
        }
    });
    autoReconnectBox = new JCheckBox("Automatically attempt to reconnect if connection is lost");
    autoReconnectBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            config.setAutoReconnect(autoReconnectBox.isSelected());
        }
    });
    JPanel everything = new JPanel(new GridBagLayout());
    everything.setBorder(new TitledBorder(baseBorder, "IRC Connection Properties / Clear Chat", TitledBorder.CENTER, TitledBorder.TOP));
    JPanel topRow = new JPanel(new GridBagLayout());
    JPanel midRow = new JPanel(new GridBagLayout());
    JPanel botRow = new JPanel(new GridBagLayout());
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    topRow.add(userInput, gbc);
    gbc.gridx++;
    topRow.add(chanInput, gbc);
    gbc.gridx++;
    gbc.gridx = 0;
    midRow.add(authInput, gbc);
    gbc.gridx++;
    gbc.weightx = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    midRow.add(authHelpButton, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.gridx = 0;
    botRow.add(hostInput, gbc);
    gbc.gridx++;
    botRow.add(portInput, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    botRow.add(connectButton, gbc);
    gbc.gridx++;
    botRow.add(clearChatButton, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 0;
    everything.add(topRow, gbc);
    gbc.gridy++;
    everything.add(midRow, gbc);
    gbc.gridy++;
    everything.add(botRow, gbc);
    gbc.gridy++;
    everything.add(autoReconnectBox, gbc);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.NORTH;
    add(everything, gbc);
    gbc.gridy++;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.fill = GridBagConstraints.BOTH;
    add(logBox, gbc);
}
Also used : JPanel(javax.swing.JPanel) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) NickAlreadyInUseException(org.jibble.pircbot.NickAlreadyInUseException) JButton(javax.swing.JButton) IOException(java.io.IOException) TitledBorder(javax.swing.border.TitledBorder) FocusEvent(java.awt.event.FocusEvent) LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport) IOException(java.io.IOException) NickAlreadyInUseException(org.jibble.pircbot.NickAlreadyInUseException) IrcException(org.jibble.pircbot.IrcException) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) FocusListener(java.awt.event.FocusListener) IrcException(org.jibble.pircbot.IrcException)

Example 4 with LabeledInput

use of com.glitchcog.fontificator.gui.component.LabeledInput in project ChatGameFontificator by GlitchCog.

the class MessagePostPanel method build.

private void build() {
    setBorder(new TitledBorder(ControlPanelBase.getBaseBorder(), "Manually Post Message to Chat", TitledBorder.CENTER, TitledBorder.TOP));
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 2, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
    manualInfo = new JLabel("This message will be posted to the visualization only; it will not be sent to the IRC channel.");
    usernameInput = new LabeledInput("Username", 8);
    textInput = new LabeledInput("Message", 32);
    textInput.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            submit();
        }
    });
    retainMessageBox = new JCheckBox("Retain message input after post");
    submitButton = new JButton("Post");
    clearButton = new JButton("Clear");
    ActionListener al = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JButton source = (JButton) e.getSource();
            if (submitButton.equals(source)) {
                submit();
            } else if (clearButton.equals(source)) {
                reset();
            }
        }
    };
    submitButton.addActionListener(al);
    clearButton.addActionListener(al);
    add(manualInfo, gbc);
    gbc.gridy++;
    gbc.gridwidth = 1;
    add(usernameInput, gbc);
    gbc.gridx++;
    add(textInput, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 2;
    JPanel buttonPanel = new JPanel();
    add(buttonPanel, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridy = 0;
    gbc.gridwidth = 0;
    gbc.anchor = GridBagConstraints.WEST;
    buttonPanel.add(retainMessageBox, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.EAST;
    buttonPanel.add(submitButton, gbc);
    gbc.gridx++;
    buttonPanel.add(clearButton, gbc);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder)

Example 5 with LabeledInput

use of com.glitchcog.fontificator.gui.component.LabeledInput in project ChatGameFontificator by GlitchCog.

the class ControlPanelMessage method build.

@Override
protected void build() {
    usernamesBox = new JCheckBox("Show Usernames");
    joinMessagesBox = new JCheckBox("Show Joins");
    timestampsBox = new JCheckBox("Show Timestamps");
    timeFormatInput = new LabeledInput(null, 9);
    timeFormatUpdateButton = new JButton("Update Time Format");
    queueSizeSlider = new LabeledSlider("Message Queue Size", "messages", ConfigMessage.MIN_QUEUE_SIZE, ConfigMessage.MAX_QUEUE_SIZE);
    final String maxSpeedLabel = "MAX";
    messageSpeedSlider = new LabeledSlider("Message Speed", "char/sec", ConfigMessage.MIN_MESSAGE_SPEED, ConfigMessage.MAX_MESSAGE_SPEED, maxSpeedLabel.length()) {

        private static final long serialVersionUID = 1L;

        @Override
        public String getValueString() {
            if (getValue() == slider.getMaximum()) {
                return maxSpeedLabel;
            } else {
                return super.getValueString();
            }
        }
    };
    final String minExpirationLabel = "NEVER";
    expirationTimeSlider = new LabeledSlider("Hide Messages After ", "sec", ConfigMessage.MIN_MESSAGE_EXPIRATION, ConfigMessage.MAX_MESSAGE_EXPIRATION, minExpirationLabel.length()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected String getUnitLabelStr() {
            if (getValue() == slider.getMinimum()) {
                return padValue("", super.getUnitLabelStr().length());
            } else {
                return super.getUnitLabelStr();
            }
        }

        @Override
        public String getValueString() {
            if (getValue() == slider.getMinimum()) {
                return minExpirationLabel;
            } else {
                return super.getValueString();
            }
        }
    };
    JLabel hideLabel = new JLabel("When No Messages Are Displayed: ");
    hideEmptyBorder = new JCheckBox("Hide Border");
    hideEmptyBackground = new JCheckBox("Hide Background");
    caseTypeDropdown = new JComboBox<UsernameCaseResolutionType>(UsernameCaseResolutionType.values());
    specifyCaseBox = new JCheckBox("Permit users to specify their own username case in posts");
    messageCasingDropdown = new JComboBox<MessageCasing>(MessageCasing.values());
    DocumentListener docListener = new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            toggleEnableds();
        }
    };
    timeFormatInput.addDocumentListener(docListener);
    caseTypeDropdown.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            UsernameCaseResolutionType type = (UsernameCaseResolutionType) caseTypeDropdown.getSelectedItem();
            boolean changed = config.getCaseResolutionType() != type;
            config.setCaseResolutionType(type);
            if (changed) {
                chatWindow.clearUsernameCases();
            }
        }
    });
    messageCasingDropdown.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            config.setMessageCasing((MessageCasing) messageCasingDropdown.getSelectedItem());
            chat.repaint();
        }
    });
    ActionListener boxListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox source = (JCheckBox) e.getSource();
            if (usernamesBox.equals(source)) {
                config.setShowUsernames(source.isSelected());
            } else if (joinMessagesBox.equals(source)) {
                config.setJoinMessages(source.isSelected());
            } else if (timestampsBox.equals(source)) {
                config.setShowTimestamps(source.isSelected());
                toggleEnableds();
            } else if (specifyCaseBox.equals(source)) {
                config.setSpecifyCaseAllowed(specifyCaseBox.isSelected());
                chatWindow.clearUsernameCases();
            } else if (hideEmptyBorder.equals(source)) {
                config.setHideEmptyBorder(hideEmptyBorder.isSelected());
            } else if (hideEmptyBackground.equals(source)) {
                config.setHideEmptyBackground(hideEmptyBackground.isSelected());
            }
            chat.repaint();
        }
    };
    usernamesBox.addActionListener(boxListener);
    joinMessagesBox.addActionListener(boxListener);
    timestampsBox.addActionListener(boxListener);
    specifyCaseBox.addActionListener(boxListener);
    hideEmptyBorder.addActionListener(boxListener);
    hideEmptyBackground.addActionListener(boxListener);
    timeFormatUpdateButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            LoadConfigReport report = new LoadConfigReport();
            config.validateTimeFormat(report, timeFormatInput.getText());
            if (report.isErrorFree()) {
                config.setTimeFormat(timeFormatInput.getText());
                toggleEnableds();
                chat.repaint();
            } else {
                ChatWindow.popup.handleProblem(report);
            }
        }
    });
    ChangeListener cl = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                if (queueSizeSlider.getSlider().equals(source)) {
                    config.setQueueSize(queueSizeSlider.getValue());
                } else if (messageSpeedSlider.getSlider().equals(source)) {
                    config.setMessageSpeed(messageSpeedSlider.getValue(), chat.getMessageProgressor());
                } else if (expirationTimeSlider.getSlider().equals(source)) {
                    config.setExpirationTime(expirationTimeSlider.getValue(), chat.getMessageExpirer());
                    chat.repaint();
                }
            }
        }
    };
    messageSpeedSlider.addChangeListener(cl);
    expirationTimeSlider.addChangeListener(cl);
    queueSizeSlider.addChangeListener(cl);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.fill = GridBagConstraints.NONE;
    JPanel topOptions = new JPanel(new GridBagLayout());
    topOptions.setBorder(new TitledBorder(baseBorder, "Message Format Options", TitledBorder.CENTER, TitledBorder.TOP));
    JPanel optionsA = new JPanel(new GridBagLayout());
    JPanel optionsB = new JPanel(new GridBagLayout());
    GridBagConstraints tfGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, DEFAULT_INSETS, 0, 0);
    JPanel timeFormatPanel = new JPanel(new GridBagLayout());
    timeFormatPanel.add(timeFormatInput, tfGbc);
    tfGbc.gridx++;
    timeFormatPanel.add(timeFormatUpdateButton, tfGbc);
    GridBagConstraints aGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, DEFAULT_INSETS, 0, 0);
    optionsA.add(usernamesBox, aGbc);
    aGbc.gridx++;
    aGbc.anchor = GridBagConstraints.NORTH;
    optionsA.add(timestampsBox, aGbc);
    aGbc.gridy++;
    aGbc.gridx = 0;
    aGbc.anchor = GridBagConstraints.WEST;
    optionsA.add(joinMessagesBox, aGbc);
    aGbc.gridx++;
    aGbc.anchor = GridBagConstraints.EAST;
    optionsA.add(timeFormatPanel, aGbc);
    GridBagConstraints bGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, DEFAULT_INSETS, 0, 0);
    bGbc.gridwidth = 3;
    optionsB.add(queueSizeSlider, bGbc);
    bGbc.gridy++;
    optionsB.add(messageSpeedSlider, bGbc);
    bGbc.gridy++;
    bGbc.fill = GridBagConstraints.HORIZONTAL;
    optionsB.add(expirationTimeSlider, bGbc);
    bGbc.gridy++;
    bGbc.fill = GridBagConstraints.NONE;
    bGbc.weightx = 0.333;
    bGbc.gridwidth = 1;
    bGbc.anchor = GridBagConstraints.EAST;
    optionsB.add(hideLabel, bGbc);
    bGbc.gridx++;
    bGbc.anchor = GridBagConstraints.CENTER;
    optionsB.add(hideEmptyBorder, bGbc);
    bGbc.gridx++;
    bGbc.anchor = GridBagConstraints.WEST;
    optionsB.add(hideEmptyBackground, bGbc);
    bGbc.gridx = 0;
    bGbc.gridwidth = 3;
    bGbc.gridy++;
    bGbc.anchor = GridBagConstraints.CENTER;
    bGbc.weightx = 1.0;
    GridBagConstraints topOpGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
    topOpGbc.anchor = GridBagConstraints.SOUTH;
    topOptions.add(optionsA, topOpGbc);
    topOpGbc.gridy++;
    topOpGbc.anchor = GridBagConstraints.NORTH;
    topOptions.add(optionsB, topOpGbc);
    topOpGbc.gridy++;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    add(topOptions, gbc);
    gbc.gridy++;
    JPanel usernameOptions = new JPanel(new GridLayout(3, 1));
    usernameOptions.setBorder(new TitledBorder(baseBorder, "Username Options", TitledBorder.CENTER, TitledBorder.TOP));
    usernameOptions.add(new JLabel("Default Method for Handling Username Casing"));
    usernameOptions.add(caseTypeDropdown);
    usernameOptions.add(specifyCaseBox);
    JPanel casingOptions = new JPanel();
    casingOptions.setBorder(new TitledBorder(baseBorder, "Message Casing Options", TitledBorder.CENTER, TitledBorder.TOP));
    casingOptions.add(new JLabel("Force uppercase or lowercase: "));
    casingOptions.add(messageCasingDropdown);
    add(usernameOptions, gbc);
    gbc.gridy++;
    add(casingOptions, gbc);
    gbc.gridy++;
    // Filler panel
    gbc.gridy++;
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    add(new JPanel(), gbc);
    gbc.gridy++;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) MessageCasing(com.glitchcog.fontificator.config.MessageCasing) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) TitledBorder(javax.swing.border.TitledBorder) LabeledSlider(com.glitchcog.fontificator.gui.component.LabeledSlider) GridLayout(java.awt.GridLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) UsernameCaseResolutionType(com.glitchcog.fontificator.config.UsernameCaseResolutionType) JLabel(javax.swing.JLabel) DocumentEvent(javax.swing.event.DocumentEvent) LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent)

Aggregations

LabeledInput (com.glitchcog.fontificator.gui.component.LabeledInput)5 GridBagLayout (java.awt.GridBagLayout)5 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 JButton (javax.swing.JButton)5 JCheckBox (javax.swing.JCheckBox)5 JPanel (javax.swing.JPanel)5 TitledBorder (javax.swing.border.TitledBorder)5 GridBagConstraints (java.awt.GridBagConstraints)4 LoadConfigReport (com.glitchcog.fontificator.config.loadreport.LoadConfigReport)3 LabeledSlider (com.glitchcog.fontificator.gui.component.LabeledSlider)3 JLabel (javax.swing.JLabel)3 ChangeEvent (javax.swing.event.ChangeEvent)3 ChangeListener (javax.swing.event.ChangeListener)3 Insets (java.awt.Insets)2 JSlider (javax.swing.JSlider)2 DocumentEvent (javax.swing.event.DocumentEvent)2 DocumentListener (javax.swing.event.DocumentListener)2 MessageCasing (com.glitchcog.fontificator.config.MessageCasing)1 UsernameCaseResolutionType (com.glitchcog.fontificator.config.UsernameCaseResolutionType)1