Search in sources :

Example 21 with JButton

use of javax.swing.JButton in project libgdx by libgdx.

the class Hiero method initializeComponents.

private void initializeComponents() {
    getContentPane().setLayout(new GridBagLayout());
    JPanel leftSidePanel = new JPanel();
    leftSidePanel.setLayout(new GridBagLayout());
    getContentPane().add(leftSidePanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    {
        JPanel fontPanel = new JPanel();
        leftSidePanel.add(fontPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
        fontPanel.setLayout(new GridBagLayout());
        fontPanel.setBorder(BorderFactory.createTitledBorder("Font"));
        {
            fontSizeSpinner = new JSpinner(new SpinnerNumberModel(32, 0, 256, 1));
            fontPanel.add(fontSizeSpinner, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0));
            ((JSpinner.DefaultEditor) fontSizeSpinner.getEditor()).getTextField().setColumns(2);
        }
        {
            JScrollPane fontScroll = new JScrollPane();
            fontPanel.add(fontScroll, new GridBagConstraints(1, 1, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
            {
                fontListModel = new DefaultComboBoxModel(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
                fontList = new JList();
                fontScroll.setViewportView(fontList);
                fontList.setModel(fontListModel);
                fontList.setVisibleRowCount(6);
                fontList.setSelectedIndex(0);
                fontScroll.setMinimumSize(new Dimension(220, fontList.getPreferredScrollableViewportSize().height));
            }
        }
        {
            systemFontRadio = new JRadioButton("System:", true);
            fontPanel.add(systemFontRadio, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
            systemFontRadio.setMargin(new Insets(0, 0, 0, 0));
        }
        {
            fontFileRadio = new JRadioButton("File:");
            fontPanel.add(fontFileRadio, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            fontFileRadio.setMargin(new Insets(0, 0, 0, 0));
        }
        {
            fontFileText = new JTextField();
            fontPanel.add(fontFileText, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
        }
        {
            fontPanel.add(new JLabel("Size:"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        }
        {
            unicodePanel = new JPanel(new GridBagLayout());
            fontPanel.add(unicodePanel, new GridBagConstraints(2, 3, 2, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 5), 0, 0));
            {
                boldCheckBox = new JCheckBox("Bold");
                unicodePanel.add(boldCheckBox, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                italicCheckBox = new JCheckBox("Italic");
                unicodePanel.add(italicCheckBox, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
        }
        {
            bitmapPanel = new JPanel(new GridBagLayout());
            fontPanel.add(bitmapPanel, new GridBagConstraints(2, 3, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
            {
                bitmapPanel.add(new JLabel("Gamma:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                gammaSpinner = new JSpinner(new SpinnerNumberModel(1.8f, 0, 30, 0.01));
                ((JSpinner.DefaultEditor) gammaSpinner.getEditor()).getTextField().setColumns(2);
                bitmapPanel.add(gammaSpinner, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0));
            }
            {
                monoCheckBox = new JCheckBox("Mono");
                bitmapPanel.add(monoCheckBox, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
        }
        {
            browseButton = new JButton("...");
            fontPanel.add(browseButton, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            browseButton.setMargin(new Insets(0, 0, 0, 0));
        }
        {
            fontPanel.add(new JLabel("Rendering:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        }
        {
            JPanel renderingPanel = new JPanel(new GridBagLayout());
            fontPanel.add(renderingPanel, new GridBagConstraints(1, 4, 3, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            {
                freeTypeRadio = new JRadioButton("FreeType");
                renderingPanel.add(freeTypeRadio, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                javaRadio = new JRadioButton("Java");
                renderingPanel.add(javaRadio, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                nativeRadio = new JRadioButton("Native");
                renderingPanel.add(nativeRadio, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
        }
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(systemFontRadio);
        buttonGroup.add(fontFileRadio);
        buttonGroup = new ButtonGroup();
        buttonGroup.add(freeTypeRadio);
        buttonGroup.add(javaRadio);
        buttonGroup.add(nativeRadio);
        freeTypeRadio.setSelected(true);
    }
    {
        JPanel samplePanel = new JPanel();
        leftSidePanel.add(samplePanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 5, 5), 0, 0));
        samplePanel.setLayout(new GridBagLayout());
        samplePanel.setBorder(BorderFactory.createTitledBorder("Sample Text"));
        {
            JScrollPane textScroll = new JScrollPane();
            samplePanel.add(textScroll, new GridBagConstraints(0, 0, 4, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
            {
                sampleTextPane = new JTextPane();
                textScroll.setViewportView(sampleTextPane);
            }
        }
        {
            sampleNeheButton = new JButton();
            sampleNeheButton.setText("NEHE");
            samplePanel.add(sampleNeheButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        }
        {
            sampleAsciiButton = new JButton();
            sampleAsciiButton.setText("ASCII");
            samplePanel.add(sampleAsciiButton, new GridBagConstraints(3, 1, 1, 1, 0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        }
        {
            sampleExtendedButton = new JButton();
            sampleExtendedButton.setText("Extended");
            samplePanel.add(sampleExtendedButton, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        }
    }
    {
        JPanel renderingPanel = new JPanel();
        leftSidePanel.add(renderingPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
        renderingPanel.setBorder(BorderFactory.createTitledBorder("Rendering"));
        renderingPanel.setLayout(new GridBagLayout());
        {
            JPanel wrapperPanel = new JPanel();
            renderingPanel.add(wrapperPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
            wrapperPanel.setLayout(new BorderLayout());
            wrapperPanel.setBackground(java.awt.Color.white);
            {
                gamePanel = new JPanel();
                wrapperPanel.add(gamePanel);
                gamePanel.setLayout(new BorderLayout());
                gamePanel.setBackground(java.awt.Color.white);
            }
        }
        {
            glyphCachePanel = new JPanel() {

                private int maxWidth;

                public Dimension getPreferredSize() {
                    // Keep glyphCachePanel width from ever going down so the CanvasGameContainer doesn't change sizes and flicker.
                    Dimension size = super.getPreferredSize();
                    maxWidth = Math.max(maxWidth, size.width);
                    size.width = maxWidth;
                    return size;
                }
            };
            glyphCachePanel.setVisible(false);
            renderingPanel.add(glyphCachePanel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            glyphCachePanel.setLayout(new GridBagLayout());
            {
                glyphCachePanel.add(new JLabel("Glyphs:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
            {
                glyphCachePanel.add(new JLabel("Pages:"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
            {
                glyphCachePanel.add(new JLabel("Page width:"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
            {
                glyphCachePanel.add(new JLabel("Page height:"), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
            {
                glyphPageWidthCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] { new Integer(32), new Integer(64), new Integer(128), new Integer(256), new Integer(512), new Integer(1024), new Integer(2048) }));
                glyphCachePanel.add(glyphPageWidthCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
                glyphPageWidthCombo.setSelectedIndex(4);
            }
            {
                glyphPageHeightCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] { new Integer(32), new Integer(64), new Integer(128), new Integer(256), new Integer(512), new Integer(1024), new Integer(2048) }));
                glyphCachePanel.add(glyphPageHeightCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
                glyphPageHeightCombo.setSelectedIndex(4);
            }
            {
                resetCacheButton = new JButton("Reset Cache");
                glyphCachePanel.add(resetCacheButton, new GridBagConstraints(0, 6, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
            {
                glyphPagesTotalLabel = new JLabel("1");
                glyphCachePanel.add(glyphPagesTotalLabel, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                glyphsTotalLabel = new JLabel("0");
                glyphCachePanel.add(glyphsTotalLabel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                glyphPageComboModel = new DefaultComboBoxModel();
                glyphPageCombo = new JComboBox();
                glyphCachePanel.add(glyphPageCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
                glyphPageCombo.setModel(glyphPageComboModel);
            }
            {
                glyphCachePanel.add(new JLabel("View:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
        }
        {
            JPanel radioButtonsPanel = new JPanel();
            renderingPanel.add(radioButtonsPanel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            radioButtonsPanel.setLayout(new GridBagLayout());
            {
                sampleTextRadio = new JRadioButton("Sample text");
                radioButtonsPanel.add(sampleTextRadio, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
                sampleTextRadio.setSelected(true);
            }
            {
                glyphCacheRadio = new JRadioButton("Glyph cache");
                radioButtonsPanel.add(glyphCacheRadio, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            {
                radioButtonsPanel.add(new JLabel("Background:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
            }
            {
                backgroundColorLabel = new JLabel();
                radioButtonsPanel.add(backgroundColorLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
            }
            ButtonGroup buttonGroup = new ButtonGroup();
            buttonGroup.add(glyphCacheRadio);
            buttonGroup.add(sampleTextRadio);
        }
    }
    JPanel rightSidePanel = new JPanel();
    rightSidePanel.setLayout(new GridBagLayout());
    getContentPane().add(rightSidePanel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    {
        JPanel paddingPanel = new JPanel();
        paddingPanel.setLayout(new GridBagLayout());
        rightSidePanel.add(paddingPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
        paddingPanel.setBorder(BorderFactory.createTitledBorder("Padding"));
        {
            padTopSpinner = new JSpinner(new SpinnerNumberModel(1, 0, 999, 1));
            paddingPanel.add(padTopSpinner, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            ((JSpinner.DefaultEditor) padTopSpinner.getEditor()).getTextField().setColumns(2);
        }
        {
            padRightSpinner = new JSpinner(new SpinnerNumberModel(1, 0, 999, 1));
            paddingPanel.add(padRightSpinner, new GridBagConstraints(2, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
            ((JSpinner.DefaultEditor) padRightSpinner.getEditor()).getTextField().setColumns(2);
        }
        {
            padLeftSpinner = new JSpinner(new SpinnerNumberModel(1, 0, 999, 1));
            paddingPanel.add(padLeftSpinner, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
            ((JSpinner.DefaultEditor) padLeftSpinner.getEditor()).getTextField().setColumns(2);
        }
        {
            padBottomSpinner = new JSpinner(new SpinnerNumberModel(1, 0, 999, 1));
            paddingPanel.add(padBottomSpinner, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            ((JSpinner.DefaultEditor) padBottomSpinner.getEditor()).getTextField().setColumns(2);
        }
        {
            JPanel advancePanel = new JPanel();
            FlowLayout advancePanelLayout = new FlowLayout();
            advancePanel.setLayout(advancePanelLayout);
            paddingPanel.add(advancePanel, new GridBagConstraints(0, 4, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            {
                advancePanel.add(new JLabel("X:"));
            }
            {
                padAdvanceXSpinner = new JSpinner(new SpinnerNumberModel(-2, -999, 999, 1));
                advancePanel.add(padAdvanceXSpinner);
                ((JSpinner.DefaultEditor) padAdvanceXSpinner.getEditor()).getTextField().setColumns(2);
            }
            {
                advancePanel.add(new JLabel("Y:"));
            }
            {
                padAdvanceYSpinner = new JSpinner(new SpinnerNumberModel(-2, -999, 999, 1));
                advancePanel.add(padAdvanceYSpinner);
                ((JSpinner.DefaultEditor) padAdvanceYSpinner.getEditor()).getTextField().setColumns(2);
            }
        }
    }
    {
        effectsPanel = new JPanel();
        effectsPanel.setLayout(new GridBagLayout());
        rightSidePanel.add(effectsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 5, 5), 0, 0));
        effectsPanel.setBorder(BorderFactory.createTitledBorder("Effects"));
        effectsPanel.setMinimumSize(new Dimension(210, 1));
        {
            effectsScroll = new JScrollPane();
            effectsPanel.add(effectsScroll, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0));
            {
                effectsListModel = new DefaultComboBoxModel();
                effectsList = new JList();
                effectsScroll.setViewportView(effectsList);
                effectsList.setModel(effectsListModel);
                effectsList.setVisibleRowCount(7);
                effectsScroll.setMinimumSize(effectsList.getPreferredScrollableViewportSize());
            }
        }
        {
            addEffectButton = new JButton("Add");
            effectsPanel.add(addEffectButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 6, 5), 0, 0));
            addEffectButton.setEnabled(false);
        }
        {
            appliedEffectsScroll = new JScrollPane();
            effectsPanel.add(appliedEffectsScroll, new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
            appliedEffectsScroll.setBorder(new EmptyBorder(0, 0, 0, 0));
            appliedEffectsScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            {
                JPanel panel = new JPanel();
                panel.setLayout(new GridBagLayout());
                appliedEffectsScroll.setViewportView(panel);
                {
                    appliedEffectsPanel = new JPanel();
                    appliedEffectsPanel.setLayout(new GridBagLayout());
                    panel.add(appliedEffectsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                    appliedEffectsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, java.awt.Color.black));
                }
            }
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JCheckBox(javax.swing.JCheckBox) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) ButtonGroup(javax.swing.ButtonGroup) JSpinner(javax.swing.JSpinner) EmptyBorder(javax.swing.border.EmptyBorder) JList(javax.swing.JList)

Example 22 with JButton

use of javax.swing.JButton in project libgdx by libgdx.

the class RegionInfluencerPanel method initializeComponents.

@Override
protected void initializeComponents() {
    super.initializeComponents();
    JButton pickButton;
    regionSelectDialog = new JDialog(editor, "Pick regions", true);
    regionPickerPanel = new RegionPickerPanel(this);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(regionPickerPanel);
    regionSelectDialog.setContentPane(scrollPane);
    regionSelectDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
    pickButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (editor.isUsingDefaultTexture()) {
                JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first.");
                return;
            }
            TextureAtlas atlas = editor.getAtlas();
            if (atlas != null)
                regionPickerPanel.setAtlas(atlas);
            else
                regionPickerPanel.setTexture(editor.getTexture());
            regionPickerPanel.revalidate();
            regionPickerPanel.repaint();
            regionSelectDialog.validate();
            regionSelectDialog.repaint();
            regionSelectDialog.pack();
            regionSelectDialog.setVisible(true);
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) JButton(javax.swing.JButton) JDialog(javax.swing.JDialog)

Example 23 with JButton

use of javax.swing.JButton in project libgdx by libgdx.

the class RegionPickerPanel method initializeComponents.

private void initializeComponents() {
    setLayout(new GridBagLayout());
    content = new JPanel();
    atlasPanel = new TextureAtlasPanel();
    texturePanel = new TexturePanel();
    CustomCardLayout cardLayout = new CustomCardLayout();
    content.setLayout(cardLayout);
    content.add(atlasPanel, "atlas");
    content.add(texturePanel, "texture");
    add(content, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    JPanel controls = new JPanel(new GridBagLayout());
    controls.add(selectButton = new JButton("Select"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    controls.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
    //Pick
    JPanel pickPanel = new JPanel(new GridBagLayout());
    pickPanel.add(selectAllButton = new JButton("Pick All"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    pickPanel.add(clearButton = new JButton("Clear Selection"), new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    pickPanel.add(reverseButton = new JButton("Reverse Selection"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    controls.add(pickPanel, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    //Generation
    generationPanel = new JPanel(new GridBagLayout());
    generationPanel.add(new JLabel("Rows"), new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    generationPanel.add(rowSlider = new Slider(1, 1, 9999, 1), new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    generationPanel.add(new JLabel("Columns"), new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    generationPanel.add(columnSlider = new Slider(1, 1, 9999, 1), new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    generationPanel.add(generateBox = new JComboBox(new DefaultComboBoxModel(GenerationMode.values())), new GridBagConstraints(0, 2, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    generationPanel.add(generateButton = new JButton("Generate"), new GridBagConstraints(1, 2, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    controls.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
    controls.add(generationPanel, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    add(controls, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    selectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JPanel panel = ((CustomCardLayout) content.getLayout()).getCurrentCard(content);
            TexturePanel currentTexturePanel = panel == atlasPanel ? atlasPanel.getCurrentRegionPanel() : texturePanel;
            listener.onRegionsSelected(currentTexturePanel.selectedRegions);
        }
    });
    selectAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JPanel panel = ((CustomCardLayout) content.getLayout()).getCurrentCard(content);
            TexturePanel currentTexturePanel = panel == atlasPanel ? atlasPanel.getCurrentRegionPanel() : texturePanel;
            currentTexturePanel.selectAll();
        }
    });
    reverseButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JPanel panel = ((CustomCardLayout) content.getLayout()).getCurrentCard(content);
            TexturePanel currentTexturePanel = panel == atlasPanel ? atlasPanel.getCurrentRegionPanel() : texturePanel;
            currentTexturePanel.selectedRegions.reverse();
            currentTexturePanel.revalidate();
            currentTexturePanel.repaint();
        }
    });
    clearButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JPanel panel = ((CustomCardLayout) content.getLayout()).getCurrentCard(content);
            TexturePanel currentPanel = panel == atlasPanel ? atlasPanel.getCurrentRegionPanel() : texturePanel;
            currentPanel.clearSelection();
        }
    });
    generateButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            generateRegions((GenerationMode) generateBox.getSelectedItem());
            texturePanel.revalidate();
            texturePanel.repaint();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JSeparator(javax.swing.JSeparator) ActionListener(java.awt.event.ActionListener)

Example 24 with JButton

use of javax.swing.JButton in project libgdx by libgdx.

the class ScaledNumericPanel method initializeComponents.

private void initializeComponents(String chartTitle) {
    JPanel contentPanel = getContentPanel();
    {
        formPanel = new JPanel(new GridBagLayout());
        contentPanel.add(formPanel, new GridBagConstraints(5, 5, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0));
        {
            JLabel label = new JLabel("High:");
            formPanel.add(label, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0));
        }
        {
            highMinSlider = new Slider(0, -99999, 99999, 1f, -400, 400);
            formPanel.add(highMinSlider, new GridBagConstraints(3, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        }
        {
            highMaxSlider = new Slider(0, -99999, 99999, 1f, -400, 400);
            formPanel.add(highMaxSlider, new GridBagConstraints(4, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
        }
        {
            highRangeButton = new JButton("<");
            highRangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
            formPanel.add(highRangeButton, new GridBagConstraints(5, 1, 1, 1, 0.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0));
        }
        {
            JLabel label = new JLabel("Low:");
            formPanel.add(label, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0));
        }
        {
            lowMinSlider = new Slider(0, -99999, 99999, 1f, -400, 400);
            formPanel.add(lowMinSlider, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        }
        {
            lowMaxSlider = new Slider(0, -99999, 99999, 1f, -400, 400);
            formPanel.add(lowMaxSlider, new GridBagConstraints(4, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
        }
        {
            lowRangeButton = new JButton("<");
            lowRangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
            formPanel.add(lowRangeButton, new GridBagConstraints(5, 2, 1, 1, 0.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0));
        }
    }
    {
        chart = new Chart(chartTitle) {

            public void pointsChanged() {
                value.setTimeline(chart.getValuesX());
                value.setScaling(chart.getValuesY());
            }
        };
        contentPanel.add(chart, new GridBagConstraints(6, 5, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        chart.setPreferredSize(new Dimension(150, 30));
    }
    {
        expandButton = new JButton("+");
        contentPanel.add(expandButton, new GridBagConstraints(7, 5, 1, 1, 1, 0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
        expandButton.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
    }
    {
        relativeCheckBox = new JCheckBox("Relative");
        contentPanel.add(relativeCheckBox, new GridBagConstraints(7, 5, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension)

Example 25 with JButton

use of javax.swing.JButton in project smile by haifengl.

the class PlotCanvas method createPropertyDialog.

/**
     * Creates the property dialog.
     * @return the property dialog.
     */
private JDialog createPropertyDialog() {
    Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
    JDialog dialog = new JDialog(frame, "Plot Properties", true);
    Action okAction = new PropertyDialogOKAction(dialog);
    Action cancelAction = new PropertyDialogCancelAction(dialog);
    JButton okButton = new JButton(okAction);
    JButton cancelButton = new JButton(cancelAction);
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));
    ActionMap actionMap = buttonsPanel.getActionMap();
    actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
    actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
    InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));
    String[] columnNames = { "Property", "Value" };
    if (base.dimension == 2) {
        Object[][] data = { { "Title", title }, { "Title Font", titleFont }, { "Title Color", titleColor }, { "X Axis Title", getAxis(0).getAxisLabel() }, { "X Axis Range", new double[] { base.getLowerBounds()[0], base.getUpperBounds()[0] } }, { "Y Axis Title", getAxis(1).getAxisLabel() }, { "Y Axis Range", new double[] { base.getLowerBounds()[1], base.getUpperBounds()[1] } } };
        propertyTable = new Table(data, columnNames);
    } else {
        Object[][] data = { { "Title", title }, { "Title Font", titleFont }, { "Title Color", titleColor }, { "X Axis Title", getAxis(0).getAxisLabel() }, { "X Axis Range", new double[] { base.getLowerBounds()[0], base.getUpperBounds()[0] } }, { "Y Axis Title", getAxis(1).getAxisLabel() }, { "Y Axis Range", new double[] { base.getLowerBounds()[1], base.getUpperBounds()[1] } }, { "Z Axis Title", getAxis(2).getAxisLabel() }, { "Z Axis Range", new double[] { base.getLowerBounds()[2], base.getUpperBounds()[2] } } };
        propertyTable = new Table(data, columnNames);
    }
    // There is a known issue with JTables whereby the changes made in a
    // cell editor are not committed when focus is lost.
    // This can result in the table staying in 'edit mode' with the stale
    // value in the cell being edited still showing, although the change
    // has not actually been committed to the model.
    //
    // In fact what should happen is for the method stopCellEditing()
    // on CellEditor to be called when focus is lost.
    // So the editor can choose whether to accept the new value and stop
    // editing, or have the editing cancelled without committing.
    // There is a magic property which you have to set on the JTable
    // instance to turn this feature on.
    propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    propertyTable.setFillsViewportHeight(true);
    JScrollPane tablePanel = new JScrollPane(propertyTable);
    dialog.getContentPane().add(tablePanel, BorderLayout.CENTER);
    dialog.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setLocationRelativeTo(frame);
    return dialog;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Frame(java.awt.Frame) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) FlowLayout(java.awt.FlowLayout) JTable(javax.swing.JTable) Table(smile.swing.Table) ActionMap(javax.swing.ActionMap) JButton(javax.swing.JButton) InputMap(javax.swing.InputMap) JDialog(javax.swing.JDialog)

Aggregations

JButton (javax.swing.JButton)923 JPanel (javax.swing.JPanel)408 ActionEvent (java.awt.event.ActionEvent)389 ActionListener (java.awt.event.ActionListener)317 JLabel (javax.swing.JLabel)278 JScrollPane (javax.swing.JScrollPane)166 BoxLayout (javax.swing.BoxLayout)158 FlowLayout (java.awt.FlowLayout)142 BorderLayout (java.awt.BorderLayout)138 Dimension (java.awt.Dimension)138 Insets (java.awt.Insets)114 JTextField (javax.swing.JTextField)114 GridBagLayout (java.awt.GridBagLayout)110 JCheckBox (javax.swing.JCheckBox)103 GridBagConstraints (java.awt.GridBagConstraints)95 ImageIcon (javax.swing.ImageIcon)95 JTable (javax.swing.JTable)67 JDialog (javax.swing.JDialog)65 JComboBox (javax.swing.JComboBox)56 JTextArea (javax.swing.JTextArea)56