Search in sources :

Example 1 with UsernameCaseResolutionType

use of com.glitchcog.fontificator.config.UsernameCaseResolutionType 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

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