Example usage for javax.swing ButtonGroup add

List of usage examples for javax.swing ButtonGroup add

Introduction

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

Prototype

public void add(AbstractButton b) 

Source Link

Document

Adds the button to the group.

Usage

From source file:misc.ModalityDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method is invoked from the//  ww  w  .  ja  v a 2s. co  m
 * event-dispatching thread.
 */
private void createAndShowGUI() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gc);
    int sw = gc.getBounds().width - ins.left - ins.right;
    int sh = gc.getBounds().height - ins.top - ins.bottom;

    // first document

    // frame f1

    f1 = new JFrame("Book 1 (parent frame)");
    f1.setBounds(32, 32, 300, 200);
    f1.addWindowListener(closeWindow);
    // create radio buttons
    rb11 = new JRadioButton("Biography", true);
    rb12 = new JRadioButton("Funny tale", false);
    rb13 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(rb11);
    bg1.add(rb12);
    bg1.add(rb13);
    JButton b1 = new JButton("OK");
    b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb11.isSelected()) {
                title = rb11.getText();
            } else if (rb12.isSelected()) {
                title = rb12.getText();
            } else {
                title = rb13.getText();
            }
            // prepend radio button label to dialogs' titles
            d2.setTitle(title + " (modeless dialog)");
            d3.setTitle(title + " (document-modal dialog)");
            d2.setVisible(true);
        }
    });
    Container cp1 = f1.getContentPane();
    // create three containers to improve layouting
    cp1.setLayout(new GridLayout(1, 3));
    // an empty container
    Container cp11 = new Container();
    // a container to layout components
    Container cp12 = new Container();
    // an empty container
    Container cp13 = new Container();
    // add a button into a separate panel
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout());
    p1.add(b1);
    // add radio buttons and the OK button one after another into a single column
    cp12.setLayout(new GridLayout(4, 1));
    cp12.add(rb11);
    cp12.add(rb12);
    cp12.add(rb13);
    cp12.add(p1);
    // add three containers
    cp1.add(cp11);
    cp1.add(cp12);
    cp1.add(cp13);

    // dialog d2

    d2 = new JDialog(f1);
    d2.setBounds(132, 132, 300, 200);
    d2.addWindowListener(closeWindow);
    JLabel l2 = new JLabel("Enter your name: ");
    l2.setHorizontalAlignment(SwingConstants.CENTER);
    tf2 = new JTextField(12);
    JButton b2 = new JButton("OK");
    b2.setHorizontalAlignment(SwingConstants.CENTER);
    b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l3.setText("by " + tf2.getText());
            d3.setVisible(true);
        }
    });
    Container cp2 = d2.getContentPane();
    // add label, text field and button one after another into a single column
    cp2.setLayout(new BorderLayout());
    cp2.add(l2, BorderLayout.NORTH);
    cp2.add(tf2, BorderLayout.CENTER);
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(b2);
    cp2.add(p2, BorderLayout.SOUTH);

    // dialog d3

    d3 = new JDialog(d2, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d3.setBounds(232, 232, 300, 200);
    d3.addWindowListener(closeWindow);
    JTextArea ta3 = new JTextArea();
    l3 = new JLabel();
    l3.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp3 = d3.getContentPane();
    cp3.setLayout(new BorderLayout());
    cp3.add(new JScrollPane(ta3), BorderLayout.CENTER);
    JPanel p3 = new JPanel();
    p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p3.add(l3);
    cp3.add(p3, BorderLayout.SOUTH);

    // second document

    // frame f4

    f4 = new JFrame("Book 2 (parent frame)");
    f4.setBounds(sw - 300 - 32, 32, 300, 200);
    f4.addWindowListener(closeWindow);
    // create radio buttons
    rb41 = new JRadioButton("Biography", true);
    rb42 = new JRadioButton("Funny tale", false);
    rb43 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg4 = new ButtonGroup();
    bg4.add(rb41);
    bg4.add(rb42);
    bg4.add(rb43);
    JButton b4 = new JButton("OK");
    b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb41.isSelected()) {
                title = rb41.getText();
            } else if (rb42.isSelected()) {
                title = rb42.getText();
            } else {
                title = rb43.getText();
            }
            // prepend radiobutton label to dialogs' titles
            d5.setTitle(title + " (modeless dialog)");
            d6.setTitle(title + " (document-modal dialog)");
            d5.setVisible(true);
        }
    });
    Container cp4 = f4.getContentPane();
    // create three containers to improve layouting
    cp4.setLayout(new GridLayout(1, 3));
    Container cp41 = new Container();
    Container cp42 = new Container();
    Container cp43 = new Container();
    // add the button into a separate panel
    JPanel p4 = new JPanel();
    p4.setLayout(new FlowLayout());
    p4.add(b4);
    // add radiobuttons and the OK button one after another into a single column
    cp42.setLayout(new GridLayout(4, 1));
    cp42.add(rb41);
    cp42.add(rb42);
    cp42.add(rb43);
    cp42.add(p4);
    //add three containers
    cp4.add(cp41);
    cp4.add(cp42);
    cp4.add(cp43);

    // dialog d5

    d5 = new JDialog(f4);
    d5.setBounds(sw - 400 - 32, 132, 300, 200);
    d5.addWindowListener(closeWindow);
    JLabel l5 = new JLabel("Enter your name: ");
    l5.setHorizontalAlignment(SwingConstants.CENTER);
    tf5 = new JTextField(12);
    tf5.setHorizontalAlignment(SwingConstants.CENTER);
    JButton b5 = new JButton("OK");
    b5.setHorizontalAlignment(SwingConstants.CENTER);
    b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l6.setText("by " + tf5.getText());
            d6.setVisible(true);
        }
    });
    Container cp5 = d5.getContentPane();
    // add label, text field and button one after another into a single column
    cp5.setLayout(new BorderLayout());
    cp5.add(l5, BorderLayout.NORTH);
    cp5.add(tf5, BorderLayout.CENTER);
    JPanel p5 = new JPanel();
    p5.setLayout(new FlowLayout());
    p5.add(b5);
    cp5.add(p5, BorderLayout.SOUTH);

    // dialog d6

    d6 = new JDialog(d5, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d6.setBounds(sw - 500 - 32, 232, 300, 200);
    d6.addWindowListener(closeWindow);
    JTextArea ta6 = new JTextArea();
    l6 = new JLabel();
    l6.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp6 = d6.getContentPane();
    cp6.setLayout(new BorderLayout());
    cp6.add(new JScrollPane(ta6), BorderLayout.CENTER);
    JPanel p6 = new JPanel();
    p6.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p6.add(l6);
    cp6.add(p6, BorderLayout.SOUTH);

    // third document

    // frame f7

    f7 = new JFrame("Classics (excluded frame)");
    f7.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    f7.setBounds(32, sh - 200 - 32, 300, 200);
    f7.addWindowListener(closeWindow);
    JLabel l7 = new JLabel("Famous writers: ");
    l7.setHorizontalAlignment(SwingConstants.CENTER);
    // create radio buttons
    rb71 = new JRadioButton("Burns", true);
    rb72 = new JRadioButton("Dickens", false);
    rb73 = new JRadioButton("Twain", false);
    // place radio buttons into a single group
    ButtonGroup bg7 = new ButtonGroup();
    bg7.add(rb71);
    bg7.add(rb72);
    bg7.add(rb73);
    Container cp7 = f7.getContentPane();
    // create three containers to improve layouting
    cp7.setLayout(new GridLayout(1, 3));
    Container cp71 = new Container();
    Container cp72 = new Container();
    Container cp73 = new Container();
    // add the label into a separate panel
    JPanel p7 = new JPanel();
    p7.setLayout(new FlowLayout());
    p7.add(l7);
    // add a label and radio buttons one after another into a single column
    cp72.setLayout(new GridLayout(4, 1));
    cp72.add(p7);
    cp72.add(rb71);
    cp72.add(rb72);
    cp72.add(rb73);
    // add three containers
    cp7.add(cp71);
    cp7.add(cp72);
    cp7.add(cp73);

    // fourth document

    // frame f8

    f8 = new JFrame("Feedback (parent frame)");
    f8.setBounds(sw - 300 - 32, sh - 200 - 32, 300, 200);
    f8.addWindowListener(closeWindow);
    JButton b8 = new JButton("Rate yourself");
    b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showConfirmDialog(null, "I really like my book", "Question (application-modal dialog)",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        }
    });
    Container cp8 = f8.getContentPane();
    cp8.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8));
    cp8.add(b8);
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

private JMenu getjTrommelSortMenu() {
    JMenu trommelSortMenu = new JMenu("Trommel Sortierung");

    JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren");
    inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder());
    inOrder.addActionListener(new ActionListener() {
        @Override// w  ww .  j a va 2s .  co m
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setTrommelInOrder(inOrder.isSelected());
                //                    if (kabelTypAuswahlAAS != null) {
                //                        kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected());
                //                    }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    trommelSortMenu.add(inOrder);

    trommelSortMenu.addSeparator();

    ButtonGroup group = new ButtonGroup();
    for (AbstractTrommelSort aTS : ConfigReader.getInstance().getAllTrommelSort()) {

        JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName());
        sw.setSelected(aTS.equals(ConfigReader.getInstance().getTrommelSort()));
        group.add(sw);
        trommelSortMenu.add(sw);

        sw.addActionListener(aTS);
    }
    return trommelSortMenu;
}

From source file:lab4.YouQuiz.java

private void initComponents() {

    menuBar = new JMenuBar();
    menuBarFile = new JMenu();
    menuBarExit = new JMenuItem();
    menuBarMode = new JMenu();
    menuBarEdit = new JRadioButtonMenuItem();
    menuBarQuiz = new JRadioButtonMenuItem();
    menuBarHelp = new JMenu();
    menuBarAbout = new JMenuItem();

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("YouQuiz | Your Quiz Factory");
    setIconImage((new ImageIcon(getClass().getClassLoader().getResource("resources/icon.png"))).getImage());
    setMinimumSize(new Dimension(800, 500));
    setResizable(false);/*w w  w .  ja v  a  2s . c  om*/

    menuBarFile.setText("File");

    menuBarExit.setAccelerator(
            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
    menuBarExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menuBarExit.setText("Exit");
    menuBarFile.add(menuBarExit);

    menuBar.add(menuBarFile);

    menuBarMode.setText("Mode");

    menuBarEdit.setAccelerator(
            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
    menuBarEdit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //Execute when button is pressed
            System.out.println("You clicked the button");
        }
    });
    menuBarEdit.setText("Edit Mode");

    menuBarQuiz.setAccelerator(
            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
    menuBarQuiz.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //Execute when button is pressed
            System.out.println("You clicked the button");
        }
    });
    menuBarQuiz.setSelected(true);
    menuBarQuiz.setText("Quiz Mode");

    ButtonGroup menuBarGroup = new ButtonGroup();
    menuBarGroup.add(menuBarEdit);
    menuBarGroup.add(menuBarQuiz);

    menuBarMode.add(menuBarEdit);
    menuBarMode.add(menuBarQuiz);

    menuBar.add(menuBarMode);

    menuBarHelp.setText("Help");

    menuBarAbout.setAccelerator(
            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
    menuBarAbout.setText("About");
    menuBarAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            JOptionPane.showMessageDialog(null, "By Anwar Mohamed ~ 2491", "YouQuiz",
                    JOptionPane.INFORMATION_MESSAGE,
                    new ImageIcon(getClass().getClassLoader().getResource("resources/icon-48.png")));
        }
    });
    menuBarHelp.add(menuBarAbout);

    menuBar.add(menuBarHelp);
    setJMenuBar(menuBar);

    pack();
    setLocationRelativeTo(null);
}

From source file:au.org.ala.delta.intkey.ui.DefineButtonDialog.java

public DefineButtonDialog(Frame owner, boolean modal) {
    super(owner, modal);
    setPreferredSize(new Dimension(500, 430));

    ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(DefineButtonDialog.class);
    resourceMap.injectFields(this);
    ActionMap actionMap = Application.getInstance().getContext().getActionMap(DefineButtonDialog.class, this);

    setTitle(title);/*from   w  w w  .  ja  va 2  s.  com*/

    _okButtonPressed = false;

    _pnlButtons = new JPanel();
    getContentPane().add(_pnlButtons, BorderLayout.SOUTH);

    _btnOk = new JButton();
    _btnOk.setAction(actionMap.get("DefineButtonDialog_OK"));
    _pnlButtons.add(_btnOk);

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("DefineButtonDialog_Cancel"));
    _pnlButtons.add(_btnCancel);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("DefineButtonDialog_Help"));
    _btnHelp.setEnabled(false);
    _pnlButtons.add(_btnHelp);

    _pnlMain = new JPanel();
    getContentPane().add(_pnlMain, BorderLayout.CENTER);
    _pnlMain.setLayout(new BorderLayout(5, 0));

    _pnlButtonProperties = new JPanel();
    _pnlButtonProperties.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(
            new EtchedBorder(EtchedBorder.LOWERED, null, null), new EmptyBorder(5, 5, 5, 5))));
    _pnlMain.add(_pnlButtonProperties, BorderLayout.NORTH);
    GridBagLayout gbl__pnlButtonProperties = new GridBagLayout();
    gbl__pnlButtonProperties.columnWidths = new int[] { 475, 0 };
    gbl__pnlButtonProperties.rowHeights = new int[] { 14, 23, 14, 20, 14, 20, 14, 0, 23, 23, 23, 23, 0 };
    gbl__pnlButtonProperties.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl__pnlButtonProperties.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, Double.MIN_VALUE };
    _pnlButtonProperties.setLayout(gbl__pnlButtonProperties);

    _lblEnterNameOf = new JLabel(enterFileNameCaption);
    _lblEnterNameOf.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc__lblEnterNameOf = new GridBagConstraints();
    gbc__lblEnterNameOf.anchor = GridBagConstraints.WEST;
    gbc__lblEnterNameOf.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterNameOf.gridx = 0;
    gbc__lblEnterNameOf.gridy = 0;
    _pnlButtonProperties.add(_lblEnterNameOf, gbc__lblEnterNameOf);

    _pnlFile = new JPanel();
    GridBagConstraints gbc__pnlFile = new GridBagConstraints();
    gbc__pnlFile.fill = GridBagConstraints.HORIZONTAL;
    gbc__pnlFile.insets = new Insets(0, 0, 5, 0);
    gbc__pnlFile.gridx = 0;
    gbc__pnlFile.gridy = 1;
    _pnlButtonProperties.add(_pnlFile, gbc__pnlFile);
    _pnlFile.setLayout(new BorderLayout(0, 0));

    _txtFldFileName = new JTextField();
    _pnlFile.add(_txtFldFileName, BorderLayout.CENTER);
    _txtFldFileName.setColumns(10);

    _btnBrowse = new JButton();
    _btnBrowse.setAction(actionMap.get("DefineButtonDialog_Browse"));
    _pnlFile.add(_btnBrowse, BorderLayout.EAST);

    _lblEnterTheCommands = new JLabel(enterCommandsCaption);
    _lblEnterTheCommands.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc__lblEnterTheCommands = new GridBagConstraints();
    gbc__lblEnterTheCommands.anchor = GridBagConstraints.WEST;
    gbc__lblEnterTheCommands.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterTheCommands.gridx = 0;
    gbc__lblEnterTheCommands.gridy = 2;
    _pnlButtonProperties.add(_lblEnterTheCommands, gbc__lblEnterTheCommands);

    _txtFldCommands = new JTextField();
    GridBagConstraints gbc__txtFldCommands = new GridBagConstraints();
    gbc__txtFldCommands.fill = GridBagConstraints.HORIZONTAL;
    gbc__txtFldCommands.insets = new Insets(0, 0, 5, 0);
    gbc__txtFldCommands.gridx = 0;
    gbc__txtFldCommands.gridy = 3;
    _pnlButtonProperties.add(_txtFldCommands, gbc__txtFldCommands);
    _txtFldCommands.setColumns(10);

    _lblEnterBriefHelp = new JLabel(enterBriefHelpCaption);
    _lblEnterBriefHelp.setAlignmentY(Component.TOP_ALIGNMENT);
    GridBagConstraints gbc__lblEnterBriefHelp = new GridBagConstraints();
    gbc__lblEnterBriefHelp.anchor = GridBagConstraints.NORTHWEST;
    gbc__lblEnterBriefHelp.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterBriefHelp.gridx = 0;
    gbc__lblEnterBriefHelp.gridy = 4;
    _pnlButtonProperties.add(_lblEnterBriefHelp, gbc__lblEnterBriefHelp);

    _txtFldBriefHelp = new JTextField();
    GridBagConstraints gbc__txtFldBriefHelp = new GridBagConstraints();
    gbc__txtFldBriefHelp.fill = GridBagConstraints.HORIZONTAL;
    gbc__txtFldBriefHelp.insets = new Insets(0, 0, 5, 0);
    gbc__txtFldBriefHelp.gridx = 0;
    gbc__txtFldBriefHelp.gridy = 5;
    _pnlButtonProperties.add(_txtFldBriefHelp, gbc__txtFldBriefHelp);
    _txtFldBriefHelp.setColumns(10);

    _lblEnterMoreDetailed = new JLabel(enterDetailedHelpCaption);
    GridBagConstraints gbc__lblEnterMoreDetailed = new GridBagConstraints();
    gbc__lblEnterMoreDetailed.anchor = GridBagConstraints.WEST;
    gbc__lblEnterMoreDetailed.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterMoreDetailed.gridx = 0;
    gbc__lblEnterMoreDetailed.gridy = 6;
    _pnlButtonProperties.add(_lblEnterMoreDetailed, gbc__lblEnterMoreDetailed);

    _txtFldDetailedHelp = new JTextField();
    GridBagConstraints gbc__txtFldDetailedHelp = new GridBagConstraints();
    gbc__txtFldDetailedHelp.insets = new Insets(0, 0, 5, 0);
    gbc__txtFldDetailedHelp.fill = GridBagConstraints.HORIZONTAL;
    gbc__txtFldDetailedHelp.gridx = 0;
    gbc__txtFldDetailedHelp.gridy = 7;
    _pnlButtonProperties.add(_txtFldDetailedHelp, gbc__txtFldDetailedHelp);
    _txtFldDetailedHelp.setColumns(10);

    _chckbxEnableOnlyIfUsedCharacters = new JCheckBox(enableOnlyIfUsedCaption);
    GridBagConstraints gbc__chckbxEnableOnlyIf = new GridBagConstraints();
    gbc__chckbxEnableOnlyIf.anchor = GridBagConstraints.WEST;
    gbc__chckbxEnableOnlyIf.insets = new Insets(0, 0, 5, 0);
    gbc__chckbxEnableOnlyIf.gridx = 0;
    gbc__chckbxEnableOnlyIf.gridy = 8;
    _pnlButtonProperties.add(_chckbxEnableOnlyIfUsedCharacters, gbc__chckbxEnableOnlyIf);

    _rdbtnEnableInAll = new JRadioButton(enableInAllModesCaption);
    GridBagConstraints gbc__rdbtnEnableInAll = new GridBagConstraints();
    gbc__rdbtnEnableInAll.anchor = GridBagConstraints.WEST;
    gbc__rdbtnEnableInAll.insets = new Insets(0, 0, 5, 0);
    gbc__rdbtnEnableInAll.gridx = 0;
    gbc__rdbtnEnableInAll.gridy = 9;
    _pnlButtonProperties.add(_rdbtnEnableInAll, gbc__rdbtnEnableInAll);

    _rdbtnEnableInNormal = new JRadioButton(enableInNormalModeCaption);
    GridBagConstraints gbc__rdbtnEnableInNormal = new GridBagConstraints();
    gbc__rdbtnEnableInNormal.anchor = GridBagConstraints.WEST;
    gbc__rdbtnEnableInNormal.insets = new Insets(0, 0, 5, 0);
    gbc__rdbtnEnableInNormal.gridx = 0;
    gbc__rdbtnEnableInNormal.gridy = 10;
    _pnlButtonProperties.add(_rdbtnEnableInNormal, gbc__rdbtnEnableInNormal);

    _rdbtnEnableInAdvanced = new JRadioButton(enableInAdvancedModeCaption);
    GridBagConstraints gbc__rdbtnEnableInAdvanced = new GridBagConstraints();
    gbc__rdbtnEnableInAdvanced.anchor = GridBagConstraints.WEST;
    gbc__rdbtnEnableInAdvanced.gridx = 0;
    gbc__rdbtnEnableInAdvanced.gridy = 11;
    _pnlButtonProperties.add(_rdbtnEnableInAdvanced, gbc__rdbtnEnableInAdvanced);

    _pnlSpaceRemoveAll = new JPanel();
    _pnlSpaceRemoveAll.setBorder(new EmptyBorder(0, 10, 0, 0));
    _pnlMain.add(_pnlSpaceRemoveAll, BorderLayout.SOUTH);
    _pnlSpaceRemoveAll.setLayout(new BoxLayout(_pnlSpaceRemoveAll, BoxLayout.Y_AXIS));

    _chckbxInsertASpace = new JCheckBox(insertSpaceCaption);
    _chckbxInsertASpace.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            _insertSpace = !_insertSpace;

            if (_insertSpace) {
                _removeAllButtons = false;
                _chckbxRemoveAllButtons.setSelected(false);
            }

            updateButtonPropertyControls();
        }
    });
    _pnlSpaceRemoveAll.add(_chckbxInsertASpace);

    _chckbxRemoveAllButtons = new JCheckBox(removeAllCaption);
    _chckbxRemoveAllButtons.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            _removeAllButtons = !_removeAllButtons;

            if (_removeAllButtons) {
                _insertSpace = false;
                _chckbxInsertASpace.setSelected(false);
            }

            updateButtonPropertyControls();
        }
    });
    _pnlSpaceRemoveAll.add(_chckbxRemoveAllButtons);

    _pnlButtonProperties.setEnabled(false);

    ButtonGroup btnGroup = new ButtonGroup();
    btnGroup.add(_rdbtnEnableInAll);
    btnGroup.add(_rdbtnEnableInNormal);
    btnGroup.add(_rdbtnEnableInAdvanced);

    _rdbtnEnableInAll.setSelected(true);
}

From source file:io.github.jeremgamer.editor.panels.MusicFrame.java

public MusicFrame(JFrame frame, final GeneralSave gs) {

    ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>();
    try {//from   w  w  w .  j  a  v  a2s  .  c  o m
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    this.setIconImages((List<? extends Image>) icons);

    this.setTitle("Musique");
    this.setSize(new Dimension(300, 225));

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowActivated(WindowEvent event) {
        }

        @Override
        public void windowClosed(WindowEvent event) {
        }

        @Override
        public void windowClosing(WindowEvent event) {
            try {
                gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (clip != null) {
                clip.stop();
                clip.close();
                try {
                    audioStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void windowDeactivated(WindowEvent event) {
        }

        @Override
        public void windowDeiconified(WindowEvent event) {
        }

        @Override
        public void windowIconified(WindowEvent event) {
        }

        @Override
        public void windowOpened(WindowEvent event) {
        }
    });

    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));

    this.setModal(true);
    this.setLocationRelativeTo(frame);

    JPanel properties = new JPanel();
    properties.setBorder(BorderFactory.createTitledBorder("Lecture"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(one);
    bg.add(loop);
    one.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JRadioButton rb = (JRadioButton) event.getSource();
            if (rb.isSelected()) {
                gs.set("music.reading", 0);
                try {
                    gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (clip != null) {
                    if (clip.isRunning())
                        clip.loop(0);
                }
            }
        }
    });
    loop.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JRadioButton rb = (JRadioButton) event.getSource();
            if (rb.isSelected()) {
                gs.set("music.reading", 1);
                try {
                    gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (clip != null) {
                    if (clip.isRunning())
                        clip.loop(Clip.LOOP_CONTINUOUSLY);
                }
            }
        }
    });
    properties.add(one);
    properties.add(loop);
    if (gs.getInt("music.reading") == 0) {
        one.setSelected(true);
    } else {
        loop.setSelected(true);
    }

    volume.setMaximum(100);
    volume.setMinimum(0);
    volume.setValue(30);
    volume.setPaintTicks(true);
    volume.setPaintLabels(true);
    volume.setMinorTickSpacing(10);
    volume.setMajorTickSpacing(20);
    volume.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            JSlider slider = (JSlider) event.getSource();
            double value = slider.getValue();
            gain = value / 100;
            dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0);
            if (clip != null)
                gainControl.setValue(dB);
            gs.set("music.volume", (int) value);
        }
    });
    volume.setValue(gs.getInt("music.volume"));
    properties.add(volume);
    properties.setPreferredSize(new Dimension(300, 125));

    content.add(properties);

    JPanel browsePanel = new JPanel();
    browsePanel.setBorder(BorderFactory.createTitledBorder(""));
    JButton browse = new JButton("Parcourir...");
    if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
        preview.setEnabled(false);
        browse.setText("");
        try {
            browse.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    browse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
                if (clip != null) {
                    clip.stop();
                    clip.close();
                    try {
                        audioStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                name.setText("");
                preview.setEnabled(false);
                button.setText("Parcourir...");
                button.setIcon(null);
                new File("projects/" + Editor.getProjectName() + "/music.wav").delete();
                gs.set("music.name", "");
            } else {
                String path = null;
                JFileChooser chooser = new JFileChooser(Editor.lastPath);
                FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio (WAV)", "wav");
                chooser.setFileFilter(filter);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int option = chooser.showOpenDialog(null);
                if (option == JFileChooser.APPROVE_OPTION) {
                    path = chooser.getSelectedFile().getAbsolutePath();
                    Editor.lastPath = chooser.getSelectedFile().getParent();
                    copyMusic(new File(path));
                    button.setText("");
                    try {
                        button.setIcon(
                                new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    gs.set("music.name", new File(path).getName());
                    try {
                        gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    name.setText(new File(path).getName());
                    preview.setEnabled(true);
                }
            }
        }

    });
    if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
        preview.setEnabled(true);
    } else {
        preview.setEnabled(false);
    }
    preview.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JToggleButton tb = (JToggleButton) event.getSource();
            if (tb.isSelected()) {
                try {
                    audioStream = AudioSystem.getAudioInputStream(
                            new File("projects/" + Editor.getProjectName() + "/music.wav"));
                    format = audioStream.getFormat();
                    info = new DataLine.Info(Clip.class, format);
                    clip = (Clip) AudioSystem.getLine(info);
                    clip.open(audioStream);
                    clip.start();
                    gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                    gainControl.setValue(dB);
                    if (loop.isSelected()) {
                        clip.loop(Clip.LOOP_CONTINUOUSLY);
                    } else {
                        clip.loop(0);
                    }
                    clip.addLineListener(new LineListener() {
                        @Override
                        public void update(LineEvent event) {
                            Clip clip = (Clip) event.getSource();
                            if (!clip.isRunning()) {
                                preview.setSelected(false);
                                clip.stop();
                                clip.close();
                                try {
                                    audioStream.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                    });
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            } else {
                clip.stop();
                clip.close();
                try {
                    audioStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    });
    JPanel buttons = new JPanel();
    buttons.setLayout(new BorderLayout());
    buttons.add(browse, BorderLayout.WEST);
    buttons.add(preview, BorderLayout.EAST);
    browsePanel.setLayout(new BorderLayout());
    browsePanel.add(buttons, BorderLayout.NORTH);
    browsePanel.add(name, BorderLayout.SOUTH);

    name.setPreferredSize(new Dimension(280, 25));
    name.setText(gs.getString("music.name"));
    content.add(browsePanel);

    this.setContentPane(content);
    this.setVisible(true);
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java

/**
 * Initializes this window.  This method is invoked in the constructor, and
 * should not be invoked again./*from w ww  .j a v a2s .  c  o m*/
 */
protected void initialize() {
    //initialize the NFE slider
    int minimumNFE = Integer.MAX_VALUE;
    int maximumNFE = Integer.MIN_VALUE;

    for (Accumulator accumulator : accumulators) {
        minimumNFE = Math.min(minimumNFE, (Integer) accumulator.get("NFE", 0));
        maximumNFE = Math.max(maximumNFE, (Integer) accumulator.get("NFE", accumulator.size("NFE") - 1));
    }

    slider = new JSlider(minimumNFE, maximumNFE, minimumNFE);
    slider.setPaintTicks(true);
    slider.setMinorTickSpacing(100);
    slider.setMajorTickSpacing(1000);
    slider.addChangeListener(this);

    //initializes the options available for axis plotting
    Solution solution = (Solution) ((List<?>) accumulators.get(0).get("Approximation Set", 0)).get(0);
    Vector<String> objectives = new Vector<String>();

    for (int i = 0; i < solution.getNumberOfObjectives(); i++) {
        objectives.add(localization.getString("text.objective", i + 1));
    }

    for (int i = 0; i < solution.getNumberOfConstraints(); i++) {
        objectives.add(localization.getString("text.constraint", i + 1));
    }

    for (int i = 0; i < solution.getNumberOfVariables(); i++) {
        objectives.add(localization.getString("text.variable", i + 1));
    }

    xAxisSelection = new JComboBox(objectives);
    yAxisSelection = new JComboBox(objectives);

    xAxisSelection.setSelectedIndex(0);
    yAxisSelection.setSelectedIndex(1);

    xAxisSelection.addActionListener(this);
    yAxisSelection.addActionListener(this);

    //initialize the reference set bounds
    initializeReferenceSetBounds();

    //initialize plotting controls
    useInitialBounds = new JRadioButton(localization.getString("action.useInitialBounds.name"));
    useReferenceSetBounds = new JRadioButton(localization.getString("action.useReferenceSetBounds.name"));
    useDynamicBounds = new JRadioButton(localization.getString("action.useDynamicBounds.name"));
    useZoomBounds = new JRadioButton(localization.getString("action.useZoom.name"));

    useInitialBounds.setToolTipText(localization.getString("action.useInitialBounds.description"));
    useReferenceSetBounds.setToolTipText(localization.getString("action.useReferenceSetBounds.description"));
    useDynamicBounds.setToolTipText(localization.getString("action.useDynamicBounds.description"));
    useZoomBounds.setToolTipText(localization.getString("action.useZoom.description"));

    ButtonGroup rangeButtonGroup = new ButtonGroup();
    rangeButtonGroup.add(useInitialBounds);
    rangeButtonGroup.add(useReferenceSetBounds);
    rangeButtonGroup.add(useDynamicBounds);
    rangeButtonGroup.add(useZoomBounds);

    if (referenceSet == null) {
        useReferenceSetBounds.setEnabled(false);
    }

    useInitialBounds.setSelected(true);
    useInitialBounds.addActionListener(this);
    useReferenceSetBounds.addActionListener(this);
    useDynamicBounds.addActionListener(this);
    useZoomBounds.addActionListener(this);

    //initialize the seed list
    String[] seeds = new String[accumulators.size()];

    for (int i = 0; i < accumulators.size(); i++) {
        seeds[i] = localization.getString("text.seed", i + 1);
    }

    seedList = new JList(seeds);
    seedList.addListSelectionListener(this);

    selectAll = new JButton(new AbstractAction() {

        private static final long serialVersionUID = -3709557130361259485L;

        {
            putValue(Action.NAME, localization.getString("action.selectAll.name"));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            seedList.getSelectionModel().setSelectionInterval(0, seedList.getModel().getSize() - 1);
        }

    });

    //initialize miscellaneous components
    paintHelper = new PaintHelper();
    paintHelper.set(localization.getString("text.referenceSet"), Color.BLACK);

    chartContainer = new JPanel(new BorderLayout());
}

From source file:com.projity.pm.graphic.chart.ChartLegend.java

void initControls() {
    chartInfo.setAxisPanel(new AxisPanel(chartInfo));
    filterComboBox = new TransformComboBox(null, MenuActionConstants.ACTION_CHOOSE_FILTER,
            TransformComboBoxModel.FILTER);
    filterComboBox.setView(ViewConfiguration.getView(MenuActionConstants.ACTION_CHARTS));
    filterComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (chartInfo.isRestoring())
                return;
            TransformComboBox combo = (TransformComboBox) e.getSource();
            CommonTransformFactory factory = (CommonTransformFactory) combo.getSelectedItem();
            ((TransformComboBoxModel) combo.getModel()).changeTransform(factory);
        }/*from  w  ww .java2 s . c o  m*/
    });

    initTree();
    Object[] fields = getFields(false);

    workTraces = getListInstance(false);
    tracesList = workTraces; // start off work
    tracesScrollPane = new JScrollPane(workTraces);
    workTraces.setVisibleRowCount(Environment.getStandAlone() ? HasTimeDistributedData.tracesCount
            : HasTimeDistributedData.serverTracesCount);

    //      final ViewTransformer transformer=ViewConfiguration.getView(MenuActionConstants.ACTION_CHARTS).getTransform();
    //      final ResourceInTeamFilter hiddenFilter=(ResourceInTeamFilter)transformer.getHiddenFilter();      
    //      teamResources= new JCheckBox(Messages.getString("Text.ShowTeamResourcesOnly"));
    //      teamResources.addItemListener(new ItemListener() {
    //         public void itemStateChanged(ItemEvent e) {
    //            hiddenFilter.setFilterTeam(e.getStateChange() == ItemEvent.SELECTED);
    //            transformer.update();
    //         }
    //      });
    //      teamResources.setSelected(hiddenFilter.isFilterTeam());

    if (simple) {
        chartInfo.setTraces(fields);
        tree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); // allow only 1 for histogram

        selectedOnTop = new JCheckBox(Messages.getString("Text.ShowSelectedOnTop")); //$NON-NLS-1$
        selectedOnTop.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {

                chartInfo.setSelectedOnTop(e.getStateChange() == ItemEvent.SELECTED);
                Object[] traces = getFields(false);
                chartInfo.setTraces(traces);
                workTraces = getListInstance(false);
                tracesScrollPane.getViewport().add(workTraces);
                workTraces.setVisibleRowCount(Environment.getStandAlone() ? HasTimeDistributedData.tracesCount
                        : HasTimeDistributedData.serverTracesCount);
            }
        });
        selectedOnTop.setSelected(chartInfo.isSelectedOnTop()); // start off as histogram

        return;
    }

    costTraces = getListInstance(true);
    cumulative = new JCheckBox(Messages.getString("Text.Cumulative")); //$NON-NLS-1$
    cumulative.setSelected(chartInfo.isCumulative()); // start off as histogram
    cumulative.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            chartInfo.setCumulative(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    histogram = new JCheckBox(Messages.getString("Text.Histogram")); //$NON-NLS-1$
    histogram.setSelected(chartInfo.isHistogram()); // start off as histogram
    histogram.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            boolean histogramSelected = e.getStateChange() == ItemEvent.SELECTED;
            chartInfo.setHistogram(histogramSelected);
            if (histogramSelected) {
                workTraces.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); // allow only 1 for histogram
                costTraces.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); // allow only 1 for histogram
            } else {
                workTraces.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // allow many
                costTraces.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // allow only 1 for histogram               
            }
        }
    });

    work = new JRadioButton(Messages.getString("Text.work")); //$NON-NLS-1$
    work.setSelected(chartInfo.isWork());
    cost = new JRadioButton(Messages.getString("Text.cost")); //$NON-NLS-1$

    ItemListener costWork = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            boolean isCost = e.getSource() == cost;
            chartInfo.setWork(!isCost);
            tracesList = isCost ? costTraces : workTraces;
            tracesScrollPane.getViewport().add(tracesList);
            if (!chartInfo.isRestoring())
                chartInfo.setTraces(tracesList.getSelectedValues());
        }
    };
    cost.addItemListener(costWork);
    work.addItemListener(costWork);
    ButtonGroup group = new ButtonGroup();
    group.add(cost);
    group.add(work);

    // by default, always select first item
    chartInfo.setTraces(new Object[] { fields[0] });
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatDlg.java

@Override
public void createUI() {
    super.createUI();

    JLabel titleLbl = createLabel(getResourceString("DOF_TITLE") + ":");
    titleText = createTextField(32);//  www  . jav  a  2  s  .c  o  m

    JLabel nameLbl = createLabel(getResourceString("DOF_NAME") + ":");
    nameText = createTextField(32);

    // radio buttons (single/multiple/external object display formats
    JLabel typeLbl = createLabel(getResourceString("DOF_TYPE") + ":");
    singleDisplayBtn = createRadioButton(getResourceString("DOF_SINGLE"));
    multipleDisplayBtn = createRadioButton(getResourceString("DOF_MULTIPLE") + ":");
    singleDisplayBtn.setSelected(true);

    CellConstraints cc = new CellConstraints();

    if (dataObjFormatter.getFormatters().size() == 1) {
        DataObjDataFieldFormatIFace dof = dataObjFormatter.getFormatters().iterator().next();
        if (dof.isCustom()) {
            if (dof.hasEditor()) {
                customEditor = dof.getCustomEditor(new ChangeListener() {
                    @Override
                    public void stateChanged(ChangeEvent e) {
                        setHasChanged(true);
                    }
                });
            } else {
                isEditable = false;
                UIRegistry.showLocalizedMsg("DOF_NO_CST_EDT");
                return;
            }
        }
    }

    if (customEditor == null) {
        ButtonGroup displayTypeGrp = new ButtonGroup();
        displayTypeGrp.add(singleDisplayBtn);
        displayTypeGrp.add(multipleDisplayBtn);
        addDisplayTypeRadioButtonListeners();

        // combo box that lists fields that can be selected when multiple
        // display radio button is selected
        DefaultComboBoxModel cboModel = new DefaultComboBoxModel();
        valueFieldCbo = createComboBox(cboModel);
        addValueFieldsToCombo(null);
        addValueFieldCboAL();

        // little panel to hold multiple display radio button and its combo box
        PanelBuilder multipleDisplayPB = new PanelBuilder(new FormLayout("l:p,f:p:g", "p"));
        multipleDisplayPB.add(multipleDisplayBtn, cc.xy(1, 1));
        multipleDisplayPB.add(valueFieldCbo, cc.xy(2, 1));

        // format editing panels (dependent on the type for format: single/multiple)
        DataObjSwitchFormatterContainerIface formatterContainer = new DataObjSwitchFormatterSingleContainer(
                dataObjFormatter);
        fmtSingleEditingPanel = new DataObjFieldFormatSinglePanel(tableInfo, formatterContainer,
                dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache, this, getOkBtn());
        fmtMultipleEditingPanel = new DataObjFieldFormatMultiplePanel(tableInfo, formatterContainer,
                dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache, this, getOkBtn());

        // Panel for radio buttons and display formatting editing panel
        PanelBuilder pb = new PanelBuilder(new FormLayout("r:p,4px,f:p:g", "p,2px,p,10px,p,p,10px,f:p:g"));

        int y = 1;
        pb.add(nameLbl, cc.xy(1, y));
        pb.add(nameText, cc.xy(3, y));
        y += 2;

        pb.add(titleLbl, cc.xy(1, y));
        pb.add(titleText, cc.xy(3, y));
        y += 2;

        pb.add(typeLbl, cc.xy(1, y));
        pb.add(singleDisplayBtn, cc.xy(3, y));
        y += 1;
        pb.add(multipleDisplayPB.getPanel(), cc.xy(3, y));
        y += 2;

        // both panels occupy the same space
        pb.add(fmtSingleEditingPanel, cc.xyw(1, y, 3));
        pb.add(fmtMultipleEditingPanel, cc.xyw(1, y, 3));

        pb.setDefaultDialogBorder();

        contentPanel = pb.getPanel();

    } else {
        PanelBuilder pb = new PanelBuilder(new FormLayout("r:p,4px,f:p:g", "p,6px,p,2px,p,4px,p,10px"));

        int y = 1;
        pb.addSeparator(getResourceString("DOF_CST_ED"), cc.xyw(1, y, 3));
        y += 2;

        pb.add(nameLbl, cc.xy(1, y));
        pb.add(nameText, cc.xy(3, y));
        y += 2;

        pb.add(titleLbl, cc.xy(1, y));
        pb.add(titleText, cc.xy(3, y));
        y += 2;

        String labelStr = dataObjFormatter.getFormatters().iterator().next().getLabel();
        if (StringUtils.isNotEmpty(labelStr)) {
            pb.add(UIHelper.createFormLabel(labelStr), cc.xy(1, y));
            pb.add(customEditor, cc.xy(3, y));
            y += 2;

        } else {
            pb.add(customEditor, cc.xyw(1, y, 3));
            y += 2;
        }

        pb.setDefaultDialogBorder();

        contentPanel = pb.getPanel();
    }

    mainPanel.add(contentPanel, BorderLayout.CENTER);

    // after all is created, set initial selection on format list
    fillWithObjFormatter(dataObjFormatter, true);

    // title text field
    DocumentAdaptor nameChangedDL = new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent ev) {
            String name = nameText.getText();
            String title = titleText.getText();

            isInError = (StringUtils.isEmpty(name)
                    || dataObjFieldFormatMgrCache.getDataFormatter(name) != null);

            dataObjFormatter.setName(name);
            dataObjFormatter.setTitle(title);

            setHasChanged(true);
        }
    };

    titleText.getDocument().addDocumentListener(nameChangedDL);
    nameText.getDocument().addDocumentListener(nameChangedDL);

    updateUIEnabled();

    packWithLargestPanel();
}

From source file:MenuDemo.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    JMenu menuFile = new JMenu("File");
    menuFile.setMnemonic('f');

    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setIcon(new ImageIcon("file_new.gif"));
    menuItem.setMnemonic('n');
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("New");
        }/* w  w w . java  2 s.  co m*/
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Open...");
    menuItem.setIcon(new ImageIcon("file_open.gif"));
    menuItem.setMnemonic('o');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MenuDemo.this.repaint();
            if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION)
                return;
            System.out.println(fileChooser.getSelectedFile());
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Save...");
    menuItem.setIcon(new ImageIcon("file_save.gif"));
    menuItem.setMnemonic('s');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Save...");
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuFile.addSeparator();

    menuItem = new JMenuItem("Exit");
    menuItem.setMnemonic('x');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);
    menuBar.add(menuFile);

    ActionListener fontListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateMonitor();
        }
    };

    JMenu mFont = new JMenu("Font");
    mFont.setMnemonic('o');

    ButtonGroup group = new ButtonGroup();
    menus = new JMenuItem[FontNames.length];
    for (int i = 0; i < FontNames.length; i++) {
        int m = i + 1;
        menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]);
        boolean selected = (i == 0);
        menus[i].setSelected(selected);
        menus[i].setMnemonic('1' + i);
        menus[i].setFont(fontArray[i]);
        menus[i].addActionListener(fontListener);
        group.add(menus[i]);
        mFont.add(menus[i]);
    }

    mFont.addSeparator();

    boldMenuItem = new JCheckBoxMenuItem("Bold");
    boldMenuItem.setMnemonic('b');
    Font fn = fontArray[1].deriveFont(Font.BOLD);
    boldMenuItem.setFont(fn);
    boldMenuItem.setSelected(false);
    boldMenuItem.addActionListener(fontListener);
    mFont.add(boldMenuItem);

    italicMenuItem = new JCheckBoxMenuItem("Italic");
    italicMenuItem.setMnemonic('i');
    fn = fontArray[1].deriveFont(Font.ITALIC);
    italicMenuItem.setFont(fn);
    italicMenuItem.setSelected(false);
    italicMenuItem.addActionListener(fontListener);
    mFont.add(italicMenuItem);

    menuBar.add(mFont);

    return menuBar;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRInputController.java

/**
 * Initialize view//from www  .jav a 2 s. co  m
 */
@Override
protected void initDRInputPanel() {
    dRInputPanel = new DRInputPanel();
    // control opaque property of bottom table
    dRInputPanel.getSlopesTableScrollPane().getViewport().setBackground(Color.white);
    slopesTable = dRInputPanel.getSlopesTable();
    slopesTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));
    slopesTable.getTableHeader().setReorderingAllowed(false);
    slopesTable.setFillsViewportHeight(true);
    slopesTable.setModel(new NonEditableTableModel());

    //create a ButtonGroup for the radioButtons used for analysis
    ButtonGroup experimentTypeRadioButtonGroup = new ButtonGroup();
    //adding buttons to a ButtonGroup automatically deselect one when another one gets selected
    experimentTypeRadioButtonGroup.add(dRInputPanel.getStimulationRadioButton());
    experimentTypeRadioButtonGroup.add(dRInputPanel.getInhibitionRadioButton());
    //select as default first button (Stimulation)
    dRInputPanel.getStimulationRadioButton().setSelected(true);

    //initialize treatment choice dialog
    chooseTreatmentDialog = new ChooseTreatmentDialog(doseResponseController.getCellMissyFrame(), true);

    /*
     * Action listeners for buttons
     */
    dRInputPanel.getAddConditionButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //add selected condition to analysis
            addToDRAnalysis();
        }
    });

    dRInputPanel.getRemoveConditionButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // remove condition from analysis
            removeFromDRAnalysis();
        }
    });

    /**
     * Choosing stimulation or inhibition type experiment defines standard
     * hillslope parameter
     */
    dRInputPanel.getStimulationRadioButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doseResponseController.setStandardHillslope(1);
        }
    });

    dRInputPanel.getInhibitionRadioButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doseResponseController.setStandardHillslope(-1);
        }
    });

    /**
     * When button is pressed, selection of combo box gets taken into
     * account as treatment to analyse and dialog closes.
     */
    chooseTreatmentDialog.getSelectTreatmentButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setTreatment(chooseTreatmentDialog.getTreatmentComboBox().getSelectedItem().toString());
            chooseTreatmentDialog.setVisible(false);
            doseResponseController.setFirstFitting(true);
        }
    });
}