Search in sources :

Example 26 with JSlider

use of javax.swing.JSlider 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)

Example 27 with JSlider

use of javax.swing.JSlider in project jdk8u_jdk by JetBrains.

the class TranslucentShapedFrameTest method transparencySldStateChanged.

//GEN-LAST:event_shapedCbActionPerformed
private void transparencySldStateChanged(javax.swing.event.ChangeEvent evt) {
    //GEN-FIRST:event_transparencySldStateChanged
    JSlider source = (JSlider) evt.getSource();
    int transl = transparencySld.getValue();
    if (testFrame != null) {
        testFrame.setOpacity((float) transl / 100f);
    }
}
Also used : JSlider(javax.swing.JSlider)

Example 28 with JSlider

use of javax.swing.JSlider in project jdk8u_jdk by JetBrains.

the class InsetsEncapsulation method run.

@Override
public void run() {
    runTest(new JLabel("hi"));
    runTest(new JMenu());
    runTest(new JTree());
    runTest(new JTable());
    runTest(new JMenuItem());
    runTest(new JCheckBoxMenuItem());
    runTest(new JToggleButton());
    runTest(new JSpinner());
    runTest(new JSlider());
    runTest(Box.createVerticalBox());
    runTest(Box.createHorizontalBox());
    runTest(new JTextField());
    runTest(new JTextArea());
    runTest(new JTextPane());
    runTest(new JPasswordField());
    runTest(new JFormattedTextField());
    runTest(new JEditorPane());
    runTest(new JButton());
    runTest(new JColorChooser());
    runTest(new JFileChooser());
    runTest(new JCheckBox());
    runTest(new JInternalFrame());
    runTest(new JDesktopPane());
    runTest(new JTableHeader());
    runTest(new JLayeredPane());
    runTest(new JRootPane());
    runTest(new JMenuBar());
    runTest(new JOptionPane());
    runTest(new JRadioButton());
    runTest(new JRadioButtonMenuItem());
    runTest(new JPopupMenu());
    runTest(new JScrollBar());
    runTest(new JScrollPane());
    runTest(new JViewport());
    runTest(new JSplitPane());
    runTest(new JTabbedPane());
    runTest(new JToolBar());
    runTest(new JSeparator());
    runTest(new JProgressBar());
    if (!failures.isEmpty()) {
        System.out.println("These classes failed");
        for (final Component failure : failures) {
            System.out.println(failure.getClass());
        }
        throw new RuntimeException("Test failed");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) JLayeredPane(javax.swing.JLayeredPane) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JScrollBar(javax.swing.JScrollBar) JTextPane(javax.swing.JTextPane) JToggleButton(javax.swing.JToggleButton) JSlider(javax.swing.JSlider) JMenuItem(javax.swing.JMenuItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JViewport(javax.swing.JViewport) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JToolBar(javax.swing.JToolBar) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JFileChooser(javax.swing.JFileChooser) JPasswordField(javax.swing.JPasswordField) JTable(javax.swing.JTable) JEditorPane(javax.swing.JEditorPane) JSpinner(javax.swing.JSpinner) JRootPane(javax.swing.JRootPane) JSplitPane(javax.swing.JSplitPane) JColorChooser(javax.swing.JColorChooser) JInternalFrame(javax.swing.JInternalFrame) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 29 with JSlider

use of javax.swing.JSlider in project jdk8u_jdk by JetBrains.

the class Test6657026 method main.

public static void main(String[] args) throws Exception {
    JSlider slider = new JSlider();
    test(slider);
    ThreadGroup group = new ThreadGroup("$$$");
    Thread thread = new Thread(group, new Test6657026());
    thread.start();
    thread.join();
    test(slider);
}
Also used : JSlider(javax.swing.JSlider)

Example 30 with JSlider

use of javax.swing.JSlider in project jdk8u_jdk by JetBrains.

the class Test6657026 method run.

public void run() {
    SunToolkit.createNewAppContext();
    JSlider slider = new JSlider();
    test(slider);
    tickLength = -10000;
}
Also used : JSlider(javax.swing.JSlider)

Aggregations

JSlider (javax.swing.JSlider)43 ChangeEvent (javax.swing.event.ChangeEvent)23 ChangeListener (javax.swing.event.ChangeListener)23 JLabel (javax.swing.JLabel)14 JPanel (javax.swing.JPanel)14 JButton (javax.swing.JButton)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 GridBagLayout (java.awt.GridBagLayout)8 Dimension (java.awt.Dimension)7 GridBagConstraints (java.awt.GridBagConstraints)7 BorderLayout (java.awt.BorderLayout)6 JCheckBox (javax.swing.JCheckBox)6 JComponent (javax.swing.JComponent)6 JToggleButton (javax.swing.JToggleButton)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 JRadioButton (javax.swing.JRadioButton)5 JTextField (javax.swing.JTextField)5 Color (java.awt.Color)4 Point (java.awt.Point)4