Search in sources :

Example 6 with LoadConfigReport

use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport 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 7 with LoadConfigReport

use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.

the class ControlPanelFont method validateInput.

@Override
protected LoadConfigReport validateInput() {
    LoadConfigReport report = new LoadConfigReport();
    config.validateFontFile(report, fontFilenameInput.getText());
    config.validateBorderFile(report, borderFilenameInput.getText());
    final String widthStr = gridWidthInput.getText();
    final String heightStr = gridHeightInput.getText();
    final String charKey = characterKeyInput.getText();
    final String unknownStr = Character.toString(charPicker.getSelectedChar());
    config.validateStrings(report, widthStr, heightStr, charKey, unknownStr);
    return report;
}
Also used : LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport)

Example 8 with LoadConfigReport

use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.

the class ControlPanelFont method updateFontOrBorder.

private boolean updateFontOrBorder(boolean isFont) {
    LoadConfigReport report = new LoadConfigReport();
    if (isFont) {
        config.validateFontFile(report, fontFilenameInput.getText());
        config.validateStrings(report, gridWidthInput.getText(), gridHeightInput.getText(), characterKeyInput.getText(), Character.toString(charPicker.getSelectedChar()));
    } else {
        config.validateBorderFile(report, borderFilenameInput.getText());
    }
    if (report.isErrorFree()) {
        try {
            fillConfigFromInput();
            if (isFont) {
                chat.reloadFontFromConfig();
            } else {
                chat.reloadBorderFromConfig();
            }
            chat.repaint();
            return true;
        } catch (Exception ex) {
            logger.error(ex.toString(), ex);
            ChatWindow.popup.handleProblem("Unable to load " + (isFont ? "font" : "border") + " image", ex);
        }
    } else {
        ChatWindow.popup.handleProblem(report);
    }
    return false;
}
Also used : LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport)

Example 9 with LoadConfigReport

use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.

the class ControlPanelChat method validateInput.

@Override
protected LoadConfigReport validateInput() {
    LoadConfigReport report = new LoadConfigReport();
    config.validateDimStrings(report, widthInput.getText(), heightInput.getText());
    config.validateChromaDimStrings(report, chromaBorderInput[0].getText(), chromaBorderInput[1].getText(), chromaBorderInput[2].getText(), chromaBorderInput[3].getText());
    return report;
}
Also used : LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport)

Example 10 with LoadConfigReport

use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport 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)

Aggregations

LoadConfigReport (com.glitchcog.fontificator.config.loadreport.LoadConfigReport)16 IOException (java.io.IOException)4 LabeledInput (com.glitchcog.fontificator.gui.component.LabeledInput)3 GridBagLayout (java.awt.GridBagLayout)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JButton (javax.swing.JButton)3 JCheckBox (javax.swing.JCheckBox)3 JPanel (javax.swing.JPanel)3 TitledBorder (javax.swing.border.TitledBorder)3 LabeledSlider (com.glitchcog.fontificator.gui.component.LabeledSlider)2 GridBagConstraints (java.awt.GridBagConstraints)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 DocumentEvent (javax.swing.event.DocumentEvent)2 DocumentListener (javax.swing.event.DocumentListener)2 MessageCasing (com.glitchcog.fontificator.config.MessageCasing)1