Example usage for javax.swing ButtonGroup ButtonGroup

List of usage examples for javax.swing ButtonGroup ButtonGroup

Introduction

In this page you can find the example usage for javax.swing ButtonGroup ButtonGroup.

Prototype

public ButtonGroup() 

Source Link

Document

Creates a new ButtonGroup.

Usage

From source file:org.wsm.database.tools.editor.ui.GraphPane.java

public GraphPane() {
    GridBagLayout gbl = new GridBagLayout();
    this.setLayout(gbl);

    this.qesi = new QueryExecStatsInfo();
    this.qesi.addPropertyChangeListener(this);
    dcd = new DefaultCategoryDataset();
    JFreeChart chart = getChart(CHART_TYPE_BAR_3D);

    chart.setBackgroundPaint(Color.white);

    cp = new ChartPanel(chart);
    cp.setBorder(BorderFactory.createTitledBorder(null, "Graph", TitledBorder.LEADING, TitledBorder.TOP,
            UIConstants.LABEL_FONT));/*from   w ww .ja v  a 2  s .  c  o m*/

    cp.setMouseZoomable(true, true);
    //cp.setPreferredSize(new Dimension(700, 500));
    gbl.setConstraints(cp, SwingUtils.getGridBagConstraints(0, 0, 2, 1));

    this.add(cp);
    JPanel graphTypeSelectionPanel = new JPanel();
    viewBarGraph = new JRadioButton("View Bar Graph", true);
    viewLineGraph = new JRadioButton("View Line Graph", false);
    viewLineGraph.setEnabled(false);
    ButtonGroup bg = new ButtonGroup();
    bg.add(viewBarGraph);
    bg.add(viewLineGraph);

    GridBagLayout graphTypeGBL = new GridBagLayout();
    graphTypeSelectionPanel.setLayout(graphTypeGBL);

    graphTypeGBL.setConstraints(viewBarGraph, SwingUtils.getGridBagConstraints(0, 0));
    graphTypeGBL.setConstraints(viewLineGraph, SwingUtils.getGridBagConstraints(1, 0));
    graphTypeSelectionPanel.add(viewBarGraph);
    graphTypeSelectionPanel.add(viewLineGraph);
    viewBarGraph.addActionListener(this);
    viewLineGraph.addActionListener(this);

    graphTypeSelectionPanel.setBorder(BorderFactory.createTitledBorder(null, "Graph Type", TitledBorder.LEADING,
            TitledBorder.TOP, UIConstants.LABEL_FONT));

    gbl.setConstraints(graphTypeSelectionPanel, SwingUtils.getGridBagConstraints(0, 1, 2, 1));

    this.add(graphTypeSelectionPanel);
    //this.setBounds(50, 100, 100, 200);
    this.setBackground(Color.WHITE);
}

From source file:ListTest.java

public ListFrame() {
    setTitle("ListTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    String[] words = { "quick", "brown", "hungry", "wild", "silent", "huge", "private", "abstract", "static",
            "final" };

    wordList = new JList(words);
    wordList.setVisibleRowCount(4);/*from  w  w  w .  jav a2  s .  c o m*/
    JScrollPane scrollPane = new JScrollPane(wordList);

    listPanel = new JPanel();
    listPanel.add(scrollPane);
    wordList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            Object[] values = wordList.getSelectedValues();

            StringBuilder text = new StringBuilder(prefix);
            for (int i = 0; i < values.length; i++) {
                String word = (String) values[i];
                text.append(word);
                text.append(" ");
            }
            text.append(suffix);

            label.setText(text.toString());
        }
    });

    buttonPanel = new JPanel();
    group = new ButtonGroup();
    makeButton("Vertical", JList.VERTICAL);
    makeButton("Vertical Wrap", JList.VERTICAL_WRAP);
    makeButton("Horizontal Wrap", JList.HORIZONTAL_WRAP);

    add(listPanel, BorderLayout.NORTH);
    label = new JLabel(prefix + suffix);
    add(label, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:TapTapTap.java

private JPanel createPanel() {
    JPanel p = new JPanel();

    ButtonGroup entreeGroup = new ButtonGroup();
    JRadioButton radioButton;/*from  w ww . ja v  a 2s  .  com*/
    p.add(radioButton = new JRadioButton("Beef", true));
    entreeGroup.add(radioButton);
    p.add(radioButton = new JRadioButton("Chicken"));
    entreeGroup.add(radioButton);
    p.add(radioButton = new JRadioButton("Vegetable"));
    entreeGroup.add(radioButton);

    p.add(new JCheckBox("Ketchup"));
    p.add(new JCheckBox("Mustard"));
    p.add(new JCheckBox("Pickles"));

    p.add(new JLabel("Special requests:"));
    p.add(new JTextField(20));

    mOrderButton = new JButton("Place Order");
    p.add(mOrderButton);

    return p;
}

From source file:com.itemanalysis.jmetrik.swing.GraphOptionPanel.java

private void initComponents() {

    orientationButtonGroup = new ButtonGroup();
    colorPanel = new JPanel();
    color1Label = new JLabel();
    colorLabel2 = new JLabel();
    colorButton1 = new JButton();
    colorButton2 = new JButton();
    colorLabel3 = new JLabel();
    colorButton3 = new JButton();
    colorLabel4 = new JLabel();
    colorButton4 = new JButton();
    colorLabel5 = new JLabel();
    colorButton5 = new JButton();
    colorLabel6 = new JLabel();
    colorButton6 = new JButton();
    colorLabel7 = new JLabel();
    colorButton7 = new JButton();
    colorLabel8 = new JLabel();
    colorButton8 = new JButton();
    colorLabel9 = new JLabel();
    colorButton9 = new JButton();
    lineStylePanel = new JPanel();
    lineLabel1 = new JLabel();
    lineStyleComboBox1 = new JComboBox();
    lineLabel2 = new JLabel();
    lineStyleComboBox2 = new JComboBox();
    lineLabel3 = new JLabel();
    lineStyleComboBox3 = new JComboBox();
    lineLabel4 = new JLabel();
    lineStyleComboBox4 = new JComboBox();
    lineLabel5 = new JLabel();
    lineStyleComboBox5 = new JComboBox();
    lineLabel6 = new JLabel();
    lineStyleComboBox6 = new JComboBox();
    lineLabel7 = new JLabel();
    lineStyleComboBox7 = new JComboBox();
    lineLabel8 = new JLabel();
    lineStyleComboBox8 = new JComboBox();
    lineLabel9 = new JLabel();
    lineStyleComboBox9 = new JComboBox();
    lineWidthLabel = new JLabel();
    lineWidthTextField = new JTextField();
    displayPanel = new JPanel();
    legendPositionComboBox = new JComboBox();
    legendCheckbox = new JCheckBox();
    markersCheckbox = new JCheckBox();
    horizontalRadioButton = new JRadioButton();
    verticalRadioButton = new JRadioButton();
    sizePanel = new JPanel();
    widthLabel = new JLabel();
    widthTextField = new JTextField();
    heightLabel = new JLabel();
    heightTextField = new JTextField();
    resetButton = new JButton();

    //        setBorder(BorderFactory.createTitledBorder(""));

    colorPanel.setBorder(BorderFactory.createTitledBorder("Color Sequence"));

    color1Label.setText("Color 1");

    colorLabel2.setText("Color 2");

    colorButton1.setText("Choose Color");
    colorButton1.setMaximumSize(new Dimension(116, 25));
    colorButton1.setMinimumSize(new Dimension(116, 25));
    colorButton1.setPreferredSize(new Dimension(116, 25));
    colorButton1.setBackground(color[0]);
    colorButton1.addActionListener(new ActionListener() {
        @Override/* www  .  j ava 2s . co m*/
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 1", color[0]);
            if (newColor != null) {
                colorButton1.setBackground(newColor);
                color[0] = newColor;
            }
        }
    });

    colorButton2.setText("Choose Color");
    colorButton2.setMaximumSize(new Dimension(116, 25));
    colorButton2.setMinimumSize(new Dimension(116, 25));
    colorButton2.setPreferredSize(new Dimension(116, 25));
    colorButton2.setBackground(color[1]);
    colorButton2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 2", color[1]);
            if (newColor != null) {
                colorButton2.setBackground(newColor);
                color[1] = newColor;
            }
        }
    });

    colorLabel3.setText("Color 3");

    colorButton3.setText("Choose Color");
    colorButton3.setMaximumSize(new Dimension(116, 25));
    colorButton3.setMinimumSize(new Dimension(116, 25));
    colorButton3.setPreferredSize(new Dimension(116, 25));
    colorButton3.setBackground(color[2]);
    colorButton3.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 3", color[2]);
            if (newColor != null) {
                colorButton3.setBackground(newColor);
                color[2] = newColor;
            }
        }
    });

    colorLabel4.setText("Color 4");

    colorButton4.setText("Choose Color");
    colorButton4.setMaximumSize(new Dimension(116, 25));
    colorButton4.setMinimumSize(new Dimension(116, 25));
    colorButton4.setPreferredSize(new Dimension(116, 25));
    colorButton4.setBackground(color[3]);
    colorButton4.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 4", color[3]);
            if (newColor != null) {
                colorButton4.setBackground(newColor);
                color[3] = newColor;
            }
        }
    });

    colorLabel5.setText("Color 5");

    colorButton5.setText("Choose Color");
    colorButton5.setMaximumSize(new Dimension(116, 25));
    colorButton5.setMinimumSize(new Dimension(116, 25));
    colorButton5.setPreferredSize(new Dimension(116, 25));
    colorButton5.setBackground(color[4]);
    colorButton5.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 5", color[4]);
            if (newColor != null) {
                colorButton5.setBackground(newColor);
                color[4] = newColor;
            }
        }
    });

    colorLabel6.setText("Color 6");

    colorButton6.setText("Choose Color");
    colorButton6.setMaximumSize(new Dimension(116, 25));
    colorButton6.setMinimumSize(new Dimension(116, 25));
    colorButton6.setPreferredSize(new Dimension(116, 25));
    colorButton6.setBackground(color[5]);
    colorButton6.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 6", color[5]);
            if (newColor != null) {
                colorButton6.setBackground(newColor);
                color[5] = newColor;
            }
        }
    });

    colorLabel7.setText("Color 7");

    colorButton7.setText("Choose Color");
    colorButton7.setMaximumSize(new Dimension(116, 25));
    colorButton7.setMinimumSize(new Dimension(116, 25));
    colorButton7.setPreferredSize(new Dimension(116, 25));
    colorButton7.setBackground(color[6]);
    colorButton7.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 7", color[6]);
            if (newColor != null) {
                colorButton7.setBackground(newColor);
                color[6] = newColor;
            }
        }
    });

    colorLabel8.setText("Color 8");

    colorButton8.setText("Choose Color");
    colorButton8.setMaximumSize(new Dimension(116, 25));
    colorButton8.setMinimumSize(new Dimension(116, 25));
    colorButton8.setPreferredSize(new Dimension(116, 25));
    colorButton8.setBackground(color[7]);
    colorButton8.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 8", color[7]);
            if (newColor != null) {
                colorButton8.setBackground(newColor);
                color[7] = newColor;
            }
        }
    });

    colorLabel9.setText("Color 9");

    colorButton9.setText("Choose Color");
    colorButton9.setMaximumSize(new Dimension(116, 25));
    colorButton9.setMinimumSize(new Dimension(116, 25));
    colorButton9.setPreferredSize(new Dimension(116, 25));
    colorButton9.setBackground(color[8]);
    colorButton9.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 9", color[8]);
            if (newColor != null) {
                colorButton9.setBackground(newColor);
                color[8] = newColor;
            }
        }
    });

    GroupLayout colorPanelLayout = new GroupLayout(colorPanel);
    colorPanel.setLayout(colorPanelLayout);
    colorPanelLayout.setHorizontalGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(colorPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(color1Label)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton1, GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel2)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton2, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel3)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton3, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel4)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton4, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel5)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton5, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel6)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton6, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel7)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton7, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel8)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton8, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel9)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton9, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addContainerGap()));
    colorPanelLayout.setVerticalGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(colorPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(color1Label).addComponent(colorButton1, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel2).addComponent(colorButton2, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel3).addComponent(colorButton3, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel4).addComponent(colorButton4, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel5).addComponent(colorButton5, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel6).addComponent(colorButton6, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel7).addComponent(colorButton7, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel8).addComponent(colorButton8, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel9).addComponent(colorButton9, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    lineStylePanel.setBorder(BorderFactory.createTitledBorder("Line Styles"));

    lineLabel1.setText("Line 1");

    lineStyleComboBox1.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox1.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox1.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[0]));
    lineStyleComboBox1.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox1.setPreferredSize(new Dimension(150, 25));

    lineLabel2.setText("Line 2");

    lineStyleComboBox2.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox2.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox2.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[1]));
    lineStyleComboBox2.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox2.setPreferredSize(new Dimension(150, 25));

    lineLabel3.setText("Line 3");

    lineStyleComboBox3.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox3.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox3.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[2]));
    lineStyleComboBox3.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox3.setPreferredSize(new Dimension(150, 25));

    lineLabel4.setText("Line 4");

    lineStyleComboBox4.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox4.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox4.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[3]));
    lineStyleComboBox4.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox4.setPreferredSize(new Dimension(150, 25));

    lineLabel5.setText("Line 5");

    lineStyleComboBox5.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox5.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox5.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[4]));
    lineStyleComboBox5.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox5.setPreferredSize(new Dimension(150, 25));

    lineLabel6.setText("Line 6");

    lineStyleComboBox6.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox6.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox6.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[5]));
    lineStyleComboBox6.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox6.setPreferredSize(new Dimension(150, 25));

    lineLabel7.setText("Line 7");

    lineStyleComboBox7.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox7.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox7.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[6]));
    lineStyleComboBox7.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox7.setPreferredSize(new Dimension(150, 25));

    lineLabel8.setText("Line 8");

    lineStyleComboBox8.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox8.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox8.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[7]));
    lineStyleComboBox8.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox8.setPreferredSize(new Dimension(150, 25));

    lineLabel9.setText("Line 9");

    lineStyleComboBox9.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox9.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox9.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[8]));
    lineStyleComboBox9.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox9.setPreferredSize(new Dimension(150, 25));

    GroupLayout lineStylePanelLayout = new GroupLayout(lineStylePanel);
    lineStylePanel.setLayout(lineStylePanelLayout);
    lineStylePanelLayout.setHorizontalGroup(lineStylePanelLayout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(lineStylePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel1)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox1, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel2)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox2, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel3)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox3, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel4)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox4, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel5)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox5, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel6)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox6, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel7)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox7, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel8)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox8, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel9)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox9, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    lineStylePanelLayout
            .setVerticalGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(lineStylePanelLayout.createSequentialGroup().addContainerGap()
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel1).addComponent(lineStyleComboBox1,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel2).addComponent(lineStyleComboBox2,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel3).addComponent(lineStyleComboBox3,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel4).addComponent(lineStyleComboBox4,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel5).addComponent(lineStyleComboBox5,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel6).addComponent(lineStyleComboBox6,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel7).addComponent(lineStyleComboBox7,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel8).addComponent(lineStyleComboBox8,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel9).addComponent(lineStyleComboBox9,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    displayPanel.setBorder(BorderFactory.createTitledBorder("Display Options"));

    legendPositionComboBox
            .setModel(new DefaultComboBoxModel(new String[] { "Bottom", "Left", "Top", "Right" }));
    legendPositionComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String s = legendPositionComboBox.getSelectedItem().toString();
            if ("Bottom".equals(s)) {
                prefs.setLegendPosition(RectangleEdge.BOTTOM);
            } else if ("Left".equals(s)) {
                prefs.setLegendPosition(RectangleEdge.LEFT);
            } else if ("Top".equals(s)) {
                prefs.setLegendPosition(RectangleEdge.TOP);
            } else {
                prefs.setLegendPosition(RectangleEdge.RIGHT);
            }

        }
    });

    legendCheckbox.setSelected(true);
    legendCheckbox.setText("Legend");
    legendCheckbox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (legendCheckbox.isSelected()) {
                prefs.setShowLegend(true);
            } else {
                prefs.setShowLegend(false);
            }
        }
    });

    markersCheckbox.setText("Point markers");
    markersCheckbox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (markersCheckbox.isSelected()) {
                prefs.setShowMarkers(true);
            } else {
                prefs.setShowMarkers(false);
            }
        }
    });

    orientationButtonGroup.add(horizontalRadioButton);
    horizontalRadioButton.setText("Horizontal orientation");
    horizontalRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (horizontalRadioButton.isSelected()) {
                prefs.setChartOrientation(PlotOrientation.HORIZONTAL);
            }
        }
    });

    orientationButtonGroup.add(verticalRadioButton);
    verticalRadioButton.setSelected(true);
    verticalRadioButton.setText("Vertical orientation");
    verticalRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (verticalRadioButton.isSelected()) {
                prefs.setChartOrientation(PlotOrientation.VERTICAL);
            }
        }
    });

    GroupLayout displayPanelLayout = new GroupLayout(displayPanel);
    displayPanel.setLayout(displayPanelLayout);
    displayPanelLayout.setHorizontalGroup(displayPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(displayPanelLayout.createSequentialGroup().addContainerGap().addGroup(displayPanelLayout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(displayPanelLayout.createSequentialGroup().addGroup(displayPanelLayout
                            .createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(markersCheckbox)
                            .addGroup(displayPanelLayout.createSequentialGroup().addComponent(legendCheckbox)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(legendPositionComboBox, 0, 89, Short.MAX_VALUE)))
                            .addGap(26, 26, 26))
                    .addGroup(displayPanelLayout.createSequentialGroup().addComponent(horizontalRadioButton)
                            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(displayPanelLayout.createSequentialGroup().addComponent(verticalRadioButton)
                            .addGap(0, 0, Short.MAX_VALUE)))));
    displayPanelLayout.setVerticalGroup(displayPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(displayPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(displayPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(legendCheckbox).addComponent(legendPositionComboBox,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(markersCheckbox)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(horizontalRadioButton)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(verticalRadioButton)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    sizePanel.setBorder(BorderFactory.createTitledBorder("Chart Size"));

    widthLabel.setText("Width");

    widthTextField.setText("450");
    widthTextField.setMaximumSize(new Dimension(100, 25));
    widthTextField.setMinimumSize(new Dimension(100, 25));
    widthTextField.setPreferredSize(new Dimension(100, 25));
    widthTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            //do nothing
        }

        @Override
        public void focusLost(FocusEvent e) {
            String s = widthTextField.getText();
            try {
                int w = Integer.parseInt(s);
                prefs.setChartWidth(w);
            } catch (NumberFormatException ex) {
                widthTextField.setText("450");
            }
        }
    });

    heightLabel.setText("Height");

    heightTextField.setText("400");
    heightTextField.setMaximumSize(new Dimension(100, 25));
    heightTextField.setMinimumSize(new Dimension(100, 25));
    heightTextField.setPreferredSize(new Dimension(100, 25));
    heightTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            //do nothing
        }

        @Override
        public void focusLost(FocusEvent e) {
            try {
                String s = heightTextField.getText();
                int h = Integer.parseInt(s);
                prefs.setChartHeight(h);
            } catch (NumberFormatException ex) {
                heightTextField.setText("400");
            }
        }
    });

    lineWidthLabel.setText("Line width");

    lineWidthTextField.setText("1.0");
    lineWidthTextField.setMaximumSize(new Dimension(100, 25));
    lineWidthTextField.setMinimumSize(new Dimension(100, 25));
    lineWidthTextField.setPreferredSize(new Dimension(100, 25));
    lineWidthTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            //do nothing
        }

        @Override
        public void focusLost(FocusEvent e) {
            try {

                String s = lineWidthTextField.getText();
                float lw = Float.parseFloat(s);
                prefs.setChartLineWidth(lw);
            } catch (NumberFormatException ex) {
                lineWidthTextField.setText("1.0");
            }
        }
    });

    GroupLayout sizePanelLayout = new GroupLayout(sizePanel);
    sizePanel.setLayout(sizePanelLayout);
    sizePanelLayout.setHorizontalGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(sizePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(widthLabel).addComponent(heightLabel).addComponent(lineWidthLabel))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
                            .addComponent(widthTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(heightTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(lineWidthTextField, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    sizePanelLayout.setVerticalGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(sizePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(widthLabel).addComponent(widthTextField, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(heightLabel).addComponent(heightTextField, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(lineWidthLabel).addComponent(lineWidthTextField,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    resetButton.setText("Reset to Default Chart Options");
    resetButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetPanel();
        }
    });

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
                    .createSequentialGroup()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                            .addComponent(displayPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(colorPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(lineStylePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(sizePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)))
                    .addComponent(resetButton))
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(colorPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(lineStylePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(sizePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(displayPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(resetButton)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
}

From source file:LNFSwitcher.java

/** Construct a program... */
public LNFSwitcher() {
    super();/* w w w.j av  a 2  s . c  o m*/
    theFrame = new JFrame("LNF Switcher");
    theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    cp = theFrame.getContentPane();
    cp.setLayout(new FlowLayout());

    ButtonGroup bg = new ButtonGroup();

    JRadioButton bJava = new JRadioButton("Java");
    bJava.addActionListener(new LNFSetter("javax.swing.plaf.metal.MetalLookAndFeel", bJava));
    bg.add(bJava);
    cp.add(bJava);

    JRadioButton bMSW = new JRadioButton("MS-Windows");
    bMSW.addActionListener(new LNFSetter("com.sun.java.swing.plaf.windows.WindowsLookAndFeel", bMSW));
    bg.add(bMSW);
    cp.add(bMSW);

    JRadioButton bMotif = new JRadioButton("Motif");
    bMotif.addActionListener(new LNFSetter("com.sun.java.swing.plaf.motif.MotifLookAndFeel", bMotif));
    bg.add(bMotif);
    cp.add(bMotif);

    JRadioButton bMac = new JRadioButton("Sun-MacOS");
    bMac.addActionListener(new LNFSetter("com.sun.java.swing.plaf.mac.MacLookAndFeel", bMac));
    bg.add(bMac);
    cp.add(bMac);

    String defaultLookAndFeel = UIManager.getSystemLookAndFeelClassName();
    // System.out.println(defaultLookAndFeel);
    JRadioButton bDefault = new JRadioButton("Default");
    bDefault.addActionListener(new LNFSetter(defaultLookAndFeel, bDefault));
    bg.add(bDefault);
    cp.add(bDefault);

    (previousButton = bDefault).setSelected(true);

    theFrame.pack();
    theFrame.setVisible(true);
}

From source file:GenealogyExample.java

public GenealogyExample() {
    super(new BorderLayout());

    // Construct the panel with the toggle buttons.
    JRadioButton showDescendant = new JRadioButton("Show descendants", true);
    final JRadioButton showAncestor = new JRadioButton("Show ancestors");
    ButtonGroup bGroup = new ButtonGroup();
    bGroup.add(showDescendant);/*from  w  w  w.ja v  a  2s .com*/
    bGroup.add(showAncestor);
    showDescendant.addActionListener(this);
    showAncestor.addActionListener(this);
    showAncestor.setActionCommand(SHOW_ANCESTOR_CMD);
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(showDescendant);
    buttonPanel.add(showAncestor);

    // Construct the tree.
    tree = new GenealogyTree(getGenealogyGraph());
    JScrollPane scrollPane = new JScrollPane(tree);
    scrollPane.setPreferredSize(new Dimension(200, 200));

    // Add everything to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:EditorPaneExample7.java

public EditorPaneExample7() {
    super("JEditorPane Example 7");

    pane = new JEditorPane();
    pane.setEditable(false); // Start read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;// w w  w  .  ja  va2 s . c om
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("File name: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);

    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 1;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;

    textField = new JTextField(32);
    panel.add(textField, c);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    c.gridwidth = 2;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);

    getContentPane().add(panel, "South");

    panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    saveButton = new JButton("Save");
    plain = new JCheckBox("Plain Text");
    html = new JCheckBox("HTML");
    rtf = new JCheckBox("RTF");
    panel.add(plain);
    panel.add(html);
    panel.add(rtf);

    ButtonGroup group = new ButtonGroup();
    group.add(plain);
    group.add(html);
    group.add(rtf);
    plain.setSelected(true);

    panel.add(Box.createVerticalStrut(10));
    panel.add(saveButton);
    panel.add(Box.createVerticalGlue());
    panel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));

    getContentPane().add(panel, "East");

    // Change page based on text field
    textField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String fileName = textField.getText().trim();
            file = new File(fileName);
            absolutePath = file.getAbsolutePath();
            String url = "file:///" + absolutePath;

            try {
                // Check if the new page and the old
                // page are the same.
                URL newURL = new URL(url);
                URL loadedURL = pane.getPage();
                if (loadedURL != null && loadedURL.sameFile(newURL)) {
                    return;
                }

                // Try to display the page
                textField.setEnabled(false); // Disable input
                textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height);

                saveButton.setEnabled(false);
                saveButton.paintImmediately(0, 0, saveButton.getSize().width, saveButton.getSize().height);
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                // Busy cursor
                loadingState.setText("Loading...");
                loadingState.paintImmediately(0, 0, loadingState.getSize().width,
                        loadingState.getSize().height);
                loadedType.setText("");
                loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height);
                pane.setEditable(false);
                pane.setPage(url);

                loadedType.setText(pane.getContentType());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url },
                        "File Open Error", JOptionPane.ERROR_MESSAGE);
                loadingState.setText("Failed");
                textField.setEnabled(true);
                setCursor(Cursor.getDefaultCursor());
            }
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadingState.setText("Page loaded.");

                textField.setEnabled(true); // Allow entry of new file name
                textField.requestFocus();
                setCursor(Cursor.getDefaultCursor());

                // Allow editing and saving if appropriate
                pane.setEditable(file.canWrite());
                saveButton.setEnabled(file.canWrite());
            }
        }
    });

    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Writer w = null;
            OutputStream os = System.out;
            String contentType;
            if (plain.isSelected()) {
                contentType = "text/plain";
                w = new OutputStreamWriter(os);
            } else if (html.isSelected()) {
                contentType = "text/html";
                w = new OutputStreamWriter(os);
            } else {
                contentType = "text/rtf";
            }

            EditorKit kit = pane.getEditorKitForContentType(contentType);
            try {
                if (w != null) {
                    kit.write(w, pane.getDocument(), 0, pane.getDocument().getLength());
                    w.flush();
                } else {
                    kit.write(os, pane.getDocument(), 0, pane.getDocument().getLength());
                    os.flush();
                }
            } catch (Exception e) {
                System.out.println("Write failed");
            }
        }
    });
}

From source file:MenuTest.java

public MenuFrame() {
    setTitle("MenuTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    JMenu fileMenu = new JMenu("File");
    fileMenu.add(new TestAction("New"));

    // demonstrate accelerators

    JMenuItem openItem = fileMenu.add(new TestAction("Open"));
    openItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O"));

    fileMenu.addSeparator();//  w  w w. j  a v  a  2s.  c o m

    saveAction = new TestAction("Save");
    JMenuItem saveItem = fileMenu.add(saveAction);
    saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S"));

    saveAsAction = new TestAction("Save As");
    fileMenu.add(saveAsAction);
    fileMenu.addSeparator();

    fileMenu.add(new AbstractAction("Exit") {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    // demonstrate check box and radio button menus

    readonlyItem = new JCheckBoxMenuItem("Read-only");
    readonlyItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            boolean saveOk = !readonlyItem.isSelected();
            saveAction.setEnabled(saveOk);
            saveAsAction.setEnabled(saveOk);
        }
    });

    ButtonGroup group = new ButtonGroup();

    JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert");
    insertItem.setSelected(true);
    JRadioButtonMenuItem overtypeItem = new JRadioButtonMenuItem("Overtype");

    group.add(insertItem);
    group.add(overtypeItem);

    // demonstrate icons

    Action cutAction = new TestAction("Cut");
    cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif"));
    Action copyAction = new TestAction("Copy");
    copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif"));
    Action pasteAction = new TestAction("Paste");
    pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif"));

    JMenu editMenu = new JMenu("Edit");
    editMenu.add(cutAction);
    editMenu.add(copyAction);
    editMenu.add(pasteAction);

    // demonstrate nested menus

    JMenu optionMenu = new JMenu("Options");

    optionMenu.add(readonlyItem);
    optionMenu.addSeparator();
    optionMenu.add(insertItem);
    optionMenu.add(overtypeItem);

    editMenu.addSeparator();
    editMenu.add(optionMenu);

    // demonstrate mnemonics

    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic('H');

    JMenuItem indexItem = new JMenuItem("Index");
    indexItem.setMnemonic('I');
    helpMenu.add(indexItem);

    // you can also add the mnemonic key to an action
    Action aboutAction = new TestAction("About");
    aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A'));
    helpMenu.add(aboutAction);

    // add all top-level menus to menu bar

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(helpMenu);

    // demonstrate pop-ups

    popup = new JPopupMenu();
    popup.add(cutAction);
    popup.add(copyAction);
    popup.add(pasteAction);

    JPanel panel = new JPanel();
    panel.setComponentPopupMenu(popup);
    add(panel);

    // the following line is a workaround for bug 4966109
    panel.addMouseListener(new MouseAdapter() {
    });
}

From source file:net.sourceforge.doddle_owl.ui.GeneralOntologySelectionPanel.java

public GeneralOntologySelectionPanel(NameSpaceTable nsTable) {
    nameSpaceTable = nsTable;/*from  w w w .  j a v a2  s.c  o  m*/
    edrCheckBox = new JCheckBox(Translator.getTerm("GenericEDRCheckBox"), false);
    edrCheckBox.addActionListener(this);
    edrtCheckBox = new JCheckBox(Translator.getTerm("TechnicalEDRCheckBox"), false);
    edrtCheckBox.addActionListener(this);
    wnCheckBox = new JCheckBox(Translator.getTerm("WordNetCheckBox"), false);
    wnCheckBox.addActionListener(this);
    wnVersionSelectionPanel = new JPanel();
    wn30RadioButton = new JRadioButton("3.0");
    wn30RadioButton.addChangeListener(this);
    wn31RadioButton = new JRadioButton("3.1");
    wn31RadioButton.setSelected(true);
    wn31RadioButton.addChangeListener(this);
    ButtonGroup group = new ButtonGroup();
    group.add(wn30RadioButton);
    group.add(wn31RadioButton);
    wnVersionSelectionPanel.add(wnCheckBox);
    wnVersionSelectionPanel.add(wn30RadioButton);
    wnVersionSelectionPanel.add(wn31RadioButton);
    JPanel borderPanel = new JPanel();
    borderPanel.setLayout(new BorderLayout());
    borderPanel.add(wnVersionSelectionPanel, BorderLayout.WEST);

    jpnWnCheckBox = new JCheckBox(Translator.getTerm("JpnWordNetCheckBox"), false);
    jpnWnCheckBox.addActionListener(this);
    jwoCheckBox = new JCheckBox(Translator.getTerm("JWOCheckBox"), false);
    jwoCheckBox.addActionListener(this);
    JPanel checkPanel = new JPanel();
    checkPanel.add(borderPanel);
    checkPanel.add(jpnWnCheckBox);
    checkPanel.add(jwoCheckBox);
    checkPanel.add(edrCheckBox);
    checkPanel.add(edrtCheckBox);
    setLayout(new BorderLayout());
    add(checkPanel, BorderLayout.WEST);

    generalOntologyDirLabel = new JLabel(Utils.TEMP_DIR);
    removeGeneralOntologyDirButton = new JButton(Translator.getTerm("RemoveGeneralOntologyDirectoryButton"));
    removeGeneralOntologyDirButton.addActionListener(this);
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());
    buttonPanel.add(generalOntologyDirLabel, BorderLayout.CENTER);
    buttonPanel.add(removeGeneralOntologyDirButton, BorderLayout.WEST);
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:edu.ku.brc.specify.config.init.DBLocationPanel.java

/**
 * Creates a dialog for entering database name and selecting the appropriate driver.
 *///from  w ww .  j ava 2s.  co  m
public DBLocationPanel(final JButton nextBtn) {
    super("Storage", null, nextBtn, null);

    localDirOK = true;
    File currentPath = new File(UIRegistry.getAppDataDir() + File.separator + "specify_tmp.tmp");
    try {
        FileUtils.touch(currentPath);
        currentPath.delete();

    } catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBLocationPanel.class, ex);
        localDirOK = false;
    }

    //localDirOK = false ; // XXX TESTING

    ButtonGroup grp = new ButtonGroup();
    useHomeRB = new JRadioButton(
            "<html>Use your home directory: <b>" + UIRegistry.getUserHomeAppDir() + "</b></html>");
    grp.add(useHomeRB);
    useHomeRB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (browse != null) {
                browse.setEnabled(false);
            }
            updateBtnUI();
        }
    });

    int numRows = 3;
    StringBuilder header = new StringBuilder(
            "<html>This step requires you to select a storage for the database.");
    //localDirOK = false; // DEBUG
    if (localDirOK) {
        header.append("There are three options:</html>");

        useCurrentRB = new JRadioButton(
                "<html>Use your current directory: <b>" + UIRegistry.getDefaultWorkingPath() + "</b></html>");
        grp.add(useCurrentRB);
        useCurrentRB.setSelected(true);
        numRows++;

    } else {
        header.append(
                "<br>The database cannot be stored on the media you are currently running Workbench from, ");
        header.append(
                "so you can allow it to default to your '<i>home</i>' directory. Or choose a different storage.</html>");
        useHomeRB.setSelected(true);
    }

    useUserDefinedRB = new JRadioButton("Use other storage:");
    grp.add(useUserDefinedRB);
    useUserDefinedRB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            browse.setEnabled(true);
            updateBtnUI();
        }
    });

    filePath = new JTextField(30);
    filePath.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            updateBtnUI();
        }

        public void removeUpdate(DocumentEvent e) {
            updateBtnUI();
        }

        public void changedUpdate(DocumentEvent e) {
            updateBtnUI();
        }
    });
    browse = new BrowseBtnPanel(filePath, true, true);
    browse.setEnabled(false);

    CellConstraints cc = new CellConstraints();

    JLabel lbl = new JLabel(header.toString());
    PanelBuilder cmtBldr = new PanelBuilder(new FormLayout("f:min(300px;p):g", "f:p:g"));
    cmtBldr.add(lbl, cc.xy(1, 1));

    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p:g",
            "p:g,2px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", numRows) + ",f:p:g"), this);
    int row = 1;

    builder.add(cmtBldr.getPanel(), cc.xywh(1, row, 3, 1));
    row += 2;
    builder.add(useHomeRB, cc.xy(1, row));
    row += 2;
    if (useCurrentRB != null) {
        builder.add(useCurrentRB, cc.xy(1, row));
        row += 2;
    }
    builder.add(useUserDefinedRB, cc.xy(1, row));
    row += 2;
    builder.add(browse, cc.xy(1, row));
    row += 2;

}