Example usage for javax.swing JButton setActionCommand

List of usage examples for javax.swing JButton setActionCommand

Introduction

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

Prototype

public void setActionCommand(String actionCommand) 

Source Link

Document

Sets the action command for this button.

Usage

From source file:playground.sergioo.facilitiesGenerator2012.gui.ClustersWindow.java

public ClustersWindow(String title, List<CentroidCluster<PointPerson>> clusters, int numTotalPoints) {
    setTitle(title);// w  ww. j  av  a2s  .  c om
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setLocation(0, 0);
    this.setLayout(new BorderLayout());
    layersPanels.put(PanelIds.ONE, new ClustersPanel(this, clusters, numTotalPoints));
    this.add(layersPanels.get(PanelIds.ONE), BorderLayout.CENTER);
    option = Options.ZOOM;
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(Options.values().length, 1));
    for (Options option : Options.values()) {
        JButton optionButton = new JButton(option.getCaption());
        optionButton.setActionCommand(option.getCaption());
        optionButton.addActionListener(this);
        buttonsPanel.add(optionButton);
    }
    this.add(buttonsPanel, BorderLayout.EAST);
    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new BorderLayout());
    readyButton = new JButton("Ready to exit");
    readyButton.addActionListener(this);
    readyButton.setActionCommand(READY_TO_EXIT);
    infoPanel.add(readyButton, BorderLayout.WEST);
    JPanel labelsPanel = new JPanel();
    labelsPanel.setLayout(new GridLayout(1, Labels.values().length));
    labelsPanel.setBorder(new TitledBorder("Information"));
    labels = new JTextField[Labels.values().length];
    for (int i = 0; i < Labels.values().length; i++) {
        labels[i] = new JTextField("");
        labels[i].setEditable(false);
        labels[i].setBackground(null);
        labels[i].setBorder(null);
        labelsPanel.add(labels[i]);
    }
    infoPanel.add(labelsPanel, BorderLayout.CENTER);
    JPanel coordsPanel = new JPanel();
    coordsPanel.setLayout(new GridLayout(1, 2));
    coordsPanel.setBorder(new TitledBorder("Coordinates"));
    coordsPanel.add(lblCoords[0]);
    coordsPanel.add(lblCoords[1]);
    infoPanel.add(coordsPanel, BorderLayout.EAST);
    this.add(infoPanel, BorderLayout.SOUTH);
    pack();
}

From source file:playground.sergioo.workplaceCapacities2012.gui.ClustersWindow.java

public ClustersWindow(String title, Map<Integer, Cluster<Double>> clusters, int numTotalPoints) {
    setTitle(title);/*ww w  .  ja v  a2  s .co  m*/
    setDefaultCloseOperation(HIDE_ON_CLOSE);
    this.setLocation(0, 0);
    this.setLayout(new BorderLayout());
    layersPanels.put(PanelIds.ONE, new ClustersPanel(this, clusters, numTotalPoints));
    this.add(layersPanels.get(PanelIds.ONE), BorderLayout.CENTER);
    option = Options.ZOOM;
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(Options.values().length, 1));
    for (Options option : Options.values()) {
        JButton optionButton = new JButton(option.getCaption());
        optionButton.setActionCommand(option.getCaption());
        optionButton.addActionListener(this);
        buttonsPanel.add(optionButton);
    }
    this.add(buttonsPanel, BorderLayout.EAST);
    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new BorderLayout());
    readyButton = new JButton("Ready to exit");
    readyButton.addActionListener(this);
    readyButton.setActionCommand(READY_TO_EXIT);
    infoPanel.add(readyButton, BorderLayout.WEST);
    JPanel labelsPanel = new JPanel();
    labelsPanel.setLayout(new GridLayout(1, Labels.values().length));
    labelsPanel.setBorder(new TitledBorder("Information"));
    labels = new JTextField[Labels.values().length];
    for (int i = 0; i < Labels.values().length; i++) {
        labels[i] = new JTextField("");
        labels[i].setEditable(false);
        labels[i].setBackground(null);
        labels[i].setBorder(null);
        labelsPanel.add(labels[i]);
    }
    infoPanel.add(labelsPanel, BorderLayout.CENTER);
    JPanel coordsPanel = new JPanel();
    coordsPanel.setLayout(new GridLayout(1, 2));
    coordsPanel.setBorder(new TitledBorder("Coordinates"));
    coordsPanel.add(lblCoords[0]);
    coordsPanel.add(lblCoords[1]);
    infoPanel.add(coordsPanel, BorderLayout.EAST);
    this.add(infoPanel, BorderLayout.SOUTH);
    pack();
}

From source file:playground.sergioo.workplaceCapacities2012.gui.ClustersWindow.java

public ClustersWindow(String title, List<CentroidCluster<PointPerson>> clusters) {
    setTitle(title);//from  w  w w . j ava 2s .c o m
    setDefaultCloseOperation(HIDE_ON_CLOSE);
    this.setLocation(0, 0);
    this.setLayout(new BorderLayout());
    layersPanels.put(PanelIds.ONE, new ClustersPanel(this, clusters));
    this.add(layersPanels.get(PanelIds.ONE), BorderLayout.CENTER);
    option = Options.ZOOM;
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(Options.values().length, 1));
    for (Options option : Options.values()) {
        JButton optionButton = new JButton(option.getCaption());
        optionButton.setActionCommand(option.getCaption());
        optionButton.addActionListener(this);
        buttonsPanel.add(optionButton);
    }
    this.add(buttonsPanel, BorderLayout.EAST);
    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new BorderLayout());
    readyButton = new JButton("Ready to exit");
    readyButton.addActionListener(this);
    readyButton.setActionCommand(READY_TO_EXIT);
    infoPanel.add(readyButton, BorderLayout.WEST);
    JPanel labelsPanel = new JPanel();
    labelsPanel.setLayout(new GridLayout(1, Labels.values().length));
    labelsPanel.setBorder(new TitledBorder("Information"));
    labels = new JTextField[Labels.values().length];
    for (int i = 0; i < Labels.values().length; i++) {
        labels[i] = new JTextField("");
        labels[i].setEditable(false);
        labels[i].setBackground(null);
        labels[i].setBorder(null);
        labelsPanel.add(labels[i]);
    }
    infoPanel.add(labelsPanel, BorderLayout.CENTER);
    JPanel coordsPanel = new JPanel();
    coordsPanel.setLayout(new GridLayout(1, 2));
    coordsPanel.setBorder(new TitledBorder("Coordinates"));
    coordsPanel.add(lblCoords[0]);
    coordsPanel.add(lblCoords[1]);
    infoPanel.add(coordsPanel, BorderLayout.EAST);
    this.add(infoPanel, BorderLayout.SOUTH);
    pack();
}

From source file:plugins.ImageRectificationPanel.java

private JButton createButton(String buttonLabel, String toolTip, String actionCommand) {
    JButton btn = new JButton(buttonLabel);
    btn.addActionListener(this);
    btn.setActionCommand(actionCommand);
    btn.setToolTipText(toolTip);/*from  w  w  w  .j  a  va  2 s  .  c  o  m*/
    return btn;
}

From source file:Provider.GoogleMapsStatic.TestUI.MySample.java

/**
 * @author Nazmul/*from   ww w. ja v  a  2 s  .co m*/
 */
private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY
    // //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    ttfSizeW = new JTextField("512");
    ttfLat = new JTextField("45.5");
    btnGetMap = new JButton("Get Map");
    btnQuit = new JButton("Quit");
    ttfSizeH = new JTextField("512");
    ttfLon = new JTextField("-73.55");
    ttfZoom = new JTextField("14");
    ttaStatus = new JTextArea();
    checkboxRecvStatus = new JCheckBox();
    checkboxSendStatus = new JCheckBox();
    ttfProgressMsg = new JTextField();
    progressBar = new JProgressBar();
    imgLbl = new JLabel();

    /***
     * @author Dhgiang, jpmolinamatute
     * Created a slider, zoom in/out buttons, conbo box (drop down listbox) for city selection,
     * a panel to group the zoom buttons and the slider bar
     */
    slider = new JSlider(0, 19, 14);
    controlPanel = new JPanel(new GridBagLayout()); // controlPanel was created by jpmolinamatute 
    cities = new JComboBox<Object>(new String[] { "Montreal", "Toronto", // the place setting where the combo box is now used to be a text field
            "Vancouver", "New York City", "Caracas", "Hong Kong" }); // for license key, but it was removed to accommodate space for combo box 
    // @author Dhgiang

    JPanel panel1 = new JPanel();
    JPanel contentPanel = new JPanel();
    JPanel btnPanel = new JPanel();
    JPanel dialogPane = new JPanel();

    JLabel label1 = new JLabel("Select City"); // this used to be the label for license key, it was changed to label as 'select city'
    JLabel label2 = new JLabel("Size Width");
    JLabel label3 = new JLabel("Size Height");
    JLabel label4 = new JLabel("Latitude");
    JLabel label5 = new JLabel("Longitude");
    JLabel label6 = new JLabel("Zoom");

    JButton btnZoomIn = new JButton("-");
    JButton btnZoomOut = new JButton("+");

    /***
     * @author jpmolinamatute
     * Created 8 cardinal points: N,NE,NW; S,SE,SW; E, W; 
     */
    JButton btnSE = new JButton("SE");
    JButton btnS = new JButton("S");
    JButton btnSW = new JButton("SW");
    JButton btnE = new JButton("E");
    JButton btnW = new JButton("W");
    JButton btnNE = new JButton("NE");
    JButton btnN = new JButton("N");
    JButton btnNW = new JButton("NW");

    /*** 
     * @author JPMolinaMatute
     * Creaetd a spaceControl GridBagConstraints object to manage 
     * the cardinal points, and add KeyListener so users can use the
     * 8 cardinal keys on the num pad; initialize dimensions
     * 
     */
    GridBagConstraints spaceControl = new GridBagConstraints();
    spaceControl.insets = new Insets(5, 5, 5, 5);
    controlPanel.addKeyListener(this);
    controlPanel.setSize(new Dimension(512, 512));
    // ---- My Combo Boxes for different city coordinates ----//

    // ======== this ========
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("Google Static Maps");
    setIconImage(null);
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    // ======== dialogPane ========
    {
        dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
        dialogPane.setOpaque(false);
        dialogPane.setLayout(new BorderLayout());

        // ======== contentPanel ========
        {
            contentPanel.setOpaque(false);
            contentPanel.setLayout(new TableLayout(
                    new double[][] { { TableLayoutConstants.FILL }, { TableLayoutConstants.PREFERRED,
                            TableLayoutConstants.FILL, TableLayoutConstants.PREFERRED } }));
            ((TableLayout) contentPanel.getLayout()).setHGap(5);
            ((TableLayout) contentPanel.getLayout()).setVGap(5);

            // ======== panel1 ========
            {
                panel1.setOpaque(false);
                panel1.setBorder(new CompoundBorder(
                        new TitledBorder("Configure the inputs to Google Static Maps"), Borders.DLU2_BORDER));
                panel1.setLayout(new TableLayout(
                        new double[][] { { 0.17, 0.17, 0.17, 0.17, 0.05, TableLayoutConstants.FILL },
                                { TableLayoutConstants.PREFERRED, TableLayoutConstants.PREFERRED,
                                        TableLayoutConstants.PREFERRED } }));
                ((TableLayout) panel1.getLayout()).setHGap(5);
                ((TableLayout) panel1.getLayout()).setVGap(5);

                label1.setHorizontalAlignment(SwingConstants.RIGHT);
                panel1.add(label1, new TableLayoutConstraints(0, 2, 0, 2, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));
                // ---- label2 ----
                label2.setHorizontalAlignment(SwingConstants.RIGHT);
                panel1.add(label2, new TableLayoutConstraints(0, 0, 0, 0, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- ttfSizeW ----

                panel1.add(ttfSizeW, new TableLayoutConstraints(1, 0, 1, 0, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- label4 ----

                label4.setHorizontalAlignment(SwingConstants.RIGHT);
                panel1.add(label4, new TableLayoutConstraints(2, 0, 2, 0, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- ttfLat ----

                panel1.add(ttfLat, new TableLayoutConstraints(3, 0, 3, 0, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- btnGetMap ----
                btnGetMap.setHorizontalAlignment(SwingConstants.LEFT);
                btnGetMap.setMnemonic('G');
                btnGetMap.setActionCommand("getMap");
                btnGetMap.addActionListener(this);
                panel1.add(btnGetMap, new TableLayoutConstraints(5, 0, 5, 0, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- label3 ----
                label3.setHorizontalAlignment(SwingConstants.RIGHT);
                panel1.add(label3, new TableLayoutConstraints(0, 1, 0, 1, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- ttfSizeH ----

                panel1.add(ttfSizeH, new TableLayoutConstraints(1, 1, 1, 1, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- label5 ----
                label5.setHorizontalAlignment(SwingConstants.RIGHT);
                panel1.add(label5, new TableLayoutConstraints(2, 1, 2, 1, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- ttfLon ----

                panel1.add(ttfLon, new TableLayoutConstraints(3, 1, 3, 1, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- btnQuit ----
                btnQuit.setMnemonic('Q');
                btnQuit.setHorizontalAlignment(SwingConstants.LEFT);
                btnQuit.setHorizontalTextPosition(SwingConstants.RIGHT);
                btnQuit.setActionCommand("quit");
                btnQuit.addActionListener(this);

                panel1.add(btnQuit, new TableLayoutConstraints(5, 1, 5, 1, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                /***
                 * @author Dhgiang
                 * Added an anonymous inner class for ItemLister and event handling for the combo box
                 * Used the switch case condition handling to set coordinates based on the city selected
                 * Juan helped modified this method by adding the startTaskAction() at the end so 
                 * users don't have to click on Get Map button.
                 */

                cities.setSelectedIndex(0); // initialize the city selection item to 0 (or the first item)      

                cities.addItemListener(new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        Integer z = cities.getSelectedIndex();
                        switch (z) {
                        case 0:
                            ttfLat.setText("45.5");
                            ttfLon.setText("-73.55");
                            break;
                        case 1:
                            ttfLat.setText("43.65");
                            ttfLon.setText("-79.38");
                            break;
                        case 2:
                            ttfLat.setText("49.2505");
                            ttfLon.setText("-123.1119");
                            break;
                        case 3:
                            ttfLat.setText("40.7142");
                            ttfLon.setText("-74.0064");
                            break;
                        case 4:
                            ttfLat.setText("10.4901");
                            ttfLon.setText("-66.9151");
                            break;
                        case 5:
                            ttfLat.setText("22.257");
                            ttfLon.setText("114.2");
                            break;
                        default:
                            break;
                        }
                        startTaskAction();
                    }
                });

                /***
                 * @author Dhgiang
                 * Added the combo box to the panel
                 */
                panel1.add(cities, new TableLayoutConstraints(1, 2, 1, 2, TableLayoutConstraints.FULL,
                        TableLayoutConstraints.FULL));

                // ---- label6 ----
                label6.setHorizontalAlignment(SwingConstants.RIGHT);
                panel1.add(label6, new TableLayoutConstraints(2, 2, 2, 2, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));

                // ---- ttfZoom ----

                panel1.add(ttfZoom, new TableLayoutConstraints(3, 2, 3, 2, TableLayoutConstants.FULL,
                        TableLayoutConstants.FULL));
            }
            {
                btnPanel.setOpaque(false);
                btnPanel.setLayout(new GridLayout(0, 3));

                /****
                 * @author Dhgiang
                 * Initializing the zoom IN / OUT buttons with proper parameters and
                 * adding them to the btnPanel of Panel1 (panel within a panel)
                 */
                // ---- btnZoomIn ----
                btnZoomIn.setHorizontalAlignment(SwingConstants.LEFT);
                btnZoomIn.setHorizontalTextPosition(SwingConstants.RIGHT);
                btnZoomIn.setActionCommand("Zoomin");
                btnZoomIn.addActionListener(this);
                btnPanel.add(btnZoomIn, new TableLayoutConstraints(5, 2, 5, 2, TableLayoutConstraints.FULL,
                        TableLayoutConstraints.FULL));

                // ---- btnZoomOut ----
                btnZoomOut.setHorizontalAlignment(SwingConstants.RIGHT);
                btnZoomOut.setHorizontalTextPosition(SwingConstants.RIGHT);
                btnZoomOut.setActionCommand("Zoomout");
                btnZoomOut.addActionListener(this);

                btnPanel.add(btnZoomOut, new TableLayoutConstraints(5, 2, 5, 2, TableLayoutConstraints.FULL,
                        TableLayoutConstraints.FULL));

                /***
                 * @author Dhgiang
                 * Having created a new JSlider slider object, maximum & minimum values 
                 * are initialized along with incremental values
                 * 
                 */
                // ---- slider -----
                slider.setMaximum(19);
                slider.setMinimum(0);
                slider.setPaintTicks(true);
                slider.setMajorTickSpacing(19);
                slider.setMinorTickSpacing(1);
                slider.setPaintTrack(false);
                slider.createStandardLabels(4, 0);

                /***
                 * @author Dhgiang
                 * Added a ChangeListener to the slider so that 
                 * 1) the slider moves left if (-) button is clicked, slider moves right if (+) is clicked
                 * 2) and zoom values will increase or decrease if slider bar is shifted left or right accordingly
                 * 3) after the user releases the click button, the map will display automatically with the values
                 *    set by the slider bar, without having the user to click on get map button
                 */
                slider.addChangeListener(new ChangeListener() {
                    @Override
                    public void stateChanged(ChangeEvent arg0) {
                        Integer a = slider.getValue();

                        if (a >= 0 && a <= 19) {
                            ttfZoom.setText(a.toString());
                            startTaskAction();
                        }

                    }

                });
                slider.setBorder(null);

                /***
                 * @author Dhgiang
                 * Added the slider bar to the button panel
                 */
                btnPanel.add(slider, new TableLayoutConstraints(5, 2, 5, 2, TableLayoutConstraints.FULL,
                        TableLayoutConstraints.FULL));
            }

            /***
             * @author Dhgiang
             * Adding the button panel to panel1
             */
            panel1.add(btnPanel, new TableLayoutConstraints(5, 2, 5, 2, TableLayoutConstraints.FULL,
                    TableLayoutConstraints.FULL));
            contentPanel.add(panel1, new TableLayoutConstraints(0, 0, 0, 0, TableLayoutConstants.FULL,
                    TableLayoutConstants.FULL));

            /***
             * @author jpmolinamatute
             * Initializing coordinates for the cardinal points
             * Adding the cardinal points button to the control panel
             */
            // ---- Cardinals points -----
            btnNW.setActionCommand("Northwest");
            btnNW.addActionListener(this);
            spaceControl.gridx = 0;
            spaceControl.gridy = 0;
            controlPanel.add(btnNW, spaceControl);

            btnN.setActionCommand("North");
            btnN.addActionListener(this);
            spaceControl.gridx = 3;
            spaceControl.gridy = 0;
            controlPanel.add(btnN, spaceControl);

            btnNE.setActionCommand("Northeast");
            btnNE.addActionListener(this);
            spaceControl.gridx = 6;
            spaceControl.gridy = 0;
            controlPanel.add(btnNE, spaceControl);

            btnW.setActionCommand("West");
            btnW.addActionListener(this);
            spaceControl.gridx = 0;
            spaceControl.gridy = 3;
            controlPanel.add(btnW, spaceControl);

            spaceControl.gridx = 3;
            spaceControl.gridy = 3;
            controlPanel.add(imgLbl, spaceControl);

            btnE.setActionCommand("East");
            btnE.addActionListener(this);
            spaceControl.gridx = 6;
            spaceControl.gridy = 3;
            controlPanel.add(btnE, spaceControl);

            btnSW.setActionCommand("Southwest");
            btnSW.addActionListener(this);
            spaceControl.gridx = 0;
            spaceControl.gridy = 6;
            controlPanel.add(btnSW, spaceControl);

            btnS.setActionCommand("South");
            btnS.addActionListener(this);
            spaceControl.gridx = 3;
            spaceControl.gridy = 6;
            controlPanel.add(btnS, spaceControl);

            btnSE.setActionCommand("Southeast");
            btnSE.addActionListener(this);
            spaceControl.gridx = 6;
            spaceControl.gridy = 6;
            controlPanel.add(btnSE, spaceControl);

            contentPanel.add(controlPanel, new TableLayoutConstraints(0, 1, 0, 1, TableLayoutConstants.FULL,
                    TableLayoutConstants.FULL));

        }
        dialogPane.add(contentPanel, BorderLayout.CENTER);
    }

    contentPane.add(dialogPane, BorderLayout.CENTER);
    setSize(700, 800);

    setLocationRelativeTo(null);
}

From source file:ro.nextreports.designer.datasource.ConnectionDialog.java

private void create() {
    this.getContentPane().setLayout(new GridBagLayout());
    this.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            resize();/*w w w.j  av  a2 s.co  m*/
        }
    });

    JPanel p = new JPanel(new GridBagLayout());
    backColor = p.getBackground();

    mName = new JTextField();
    mDriver = new JTextField();
    //mDriver.setBackground(backColor);
    mURL = new JTextField();
    //mURL.setBackground(backColor);
    mUser = new JTextField();
    //mUser.setBackground(backColor);
    mPassword = new JPasswordField();
    mPassword.setEchoChar('*');
    //mPassword.setBackground(backColor);
    txaStatus = new JTextArea();
    txaStatus.setEditable(false);
    txaStatus.setBackground(backColor);
    scr = new JScrollPane(txaStatus);
    scr.setSize(220, 50);
    scr.setBorder(new TitledBorder(STATUS));
    types = new JComboBox();
    types.addItemListener(this);

    urlFormatLabel = new JLabel();
    Font font = urlFormatLabel.getFont().deriveFont(Font.BOLD, 10);
    urlFormatLabel.setFont(font);

    urlButton = new JButton();
    urlButton.setPreferredSize(buttonDim);
    urlButton.setMinimumSize(buttonDim);
    urlButton.setMaximumSize(buttonDim);
    urlButton.setIcon(ImageUtil.getImageIcon("url_edit"));
    urlButton.setToolTipText(I18NSupport.getString("connection.dialog.tags.tooltip"));
    urlButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            editUrl();
        }
    });

    for (DriverTemplate template : templates) {
        types.addItem(template.getType());
    }
    types.setSelectedItem(DEFAULT_DRIVER_TYPE);

    auto = new JCheckBox(I18NSupport.getString("connection.dialog.auto"));

    if (viewOnly) {
        mName.setEditable(false);
        types.setEnabled(false);
        mDriver.setEditable(false);
        mURL.setEditable(false);
        mUser.setEditable(false);
        mPassword.setEditable(false);
        urlButton.setEnabled(false);
    }

    p.add(new JLabel(I18NSupport.getString("connection.dialog.name")), new GridBagConstraints(0, 0, 1, 1, 0.0,
            0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    p.add(mName, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    p.add(new JLabel(I18NSupport.getString("connection.dialog.type")), new GridBagConstraints(0, 1, 1, 1, 0.0,
            0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    p.add(types, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    p.add(new JLabel(I18NSupport.getString("connection.dialog.driver")), new GridBagConstraints(0, 2, 1, 1, 0.0,
            0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    p.add(mDriver, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    p.add(new JLabel(I18NSupport.getString("connection.dialog.url")), new GridBagConstraints(0, 3, 1, 1, 0.0,
            0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    p.add(mURL, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0));
    p.add(urlButton, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

    if (!viewOnly) {
        p.add(urlFormatLabel, new GridBagConstraints(1, 4, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0));
    }

    p.add(new JLabel(I18NSupport.getString("connection.dialog.user")), new GridBagConstraints(0, 5, 1, 1, 0.0,
            0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    p.add(mUser, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    p.add(new JLabel(I18NSupport.getString("connection.dialog.password")), new GridBagConstraints(0, 6, 1, 1,
            0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    p.add(mPassword, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

    if (!viewOnly) {
        p.add(auto, new GridBagConstraints(1, 7, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    }

    JButton okBtn, disBtn, drvBtn, addBtn, propBtn;
    okBtn = new JButton(I18NSupport.getString("connection.dialog.test"),
            ImageUtil.getImageIcon("database_connect"));
    okBtn.setMnemonic('T');
    okBtn.setActionCommand("ConnectOk");
    okBtn.setToolTipText(I18NSupport.getString("connection.dialog.test.tooltip"));
    okBtn.addActionListener(this);
    disBtn = new JButton(I18NSupport.getString("connection.dialog.disconnect"),
            ImageUtil.getImageIcon("database"));
    disBtn.setMnemonic('D');
    disBtn.setActionCommand("Disconnect");
    disBtn.setToolTipText(I18NSupport.getString("connection.dialog.disconnect"));
    disBtn.addActionListener(this);
    drvBtn = new JButton(I18NSupport.getString("connection.dialog.add.driver"),
            ImageUtil.getImageIcon("add_driver"));
    drvBtn.setMnemonic('A');
    drvBtn.setActionCommand("AddDriver");
    drvBtn.setToolTipText(I18NSupport.getString("connection.dialog.add.driver.tooltip"));
    drvBtn.addActionListener(this);
    propBtn = new JButton(I18NSupport.getString("connection.dialog.properties"),
            ImageUtil.getImageIcon("properties"));
    propBtn.setMnemonic('P');
    propBtn.setActionCommand("Properties");
    propBtn.setToolTipText(I18NSupport.getString("connection.dialog.properties.tooltip"));
    propBtn.addActionListener(this);
    addBtn = new JButton(ImageUtil.getImageIcon("database_export"));
    if (oldDataSource == null) {
        addBtn.setText(I18NSupport.getString("connection.dialog.save"));
        addBtn.setToolTipText(I18NSupport.getString("connection.dialog.save.tooltip"));
        addBtn.setMnemonic('S');
    } else {
        addBtn.setText(I18NSupport.getString("connection.dialog.modify"));
        addBtn.setToolTipText(I18NSupport.getString("connection.dialog.modify.tooltip"));
        addBtn.setMnemonic('M');
    }
    addBtn.setActionCommand("AddDataSource");
    addBtn.addActionListener(this);
    JPanel btnPanel = new JPanel();
    btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.X_AXIS));
    btnPanel.add(Box.createHorizontalGlue());
    btnPanel.add(propBtn);
    btnPanel.add(Box.createRigidArea(new Dimension(5, 5)));
    btnPanel.add(okBtn);
    btnPanel.add(Box.createRigidArea(new Dimension(5, 5)));
    //btnPanel.add(disBtn);
    //btnPanel.add(Box.createRigidArea(new Dimension(5, 5)));
    btnPanel.add(addBtn);
    //        btnPanel.add(Box.createRigidArea(new Dimension(5, 5)));
    //        btnPanel.add(drvBtn);
    SwingUtil.equalizeButtonSizes(btnPanel);

    if (!viewOnly) {
        p.add(btnPanel, new GridBagConstraints(0, 8, 3, 1, 1.0, 0.0, GridBagConstraints.EAST,
                GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
        p.add(scr, new GridBagConstraints(0, 9, 3, 1, 1.0, 1.0, GridBagConstraints.EAST,
                GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
    }

    this.getContentPane().add(p, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));

    if (oldDataSource != null) {
        mName.setText(oldDataSource.getName());
        types.setSelectedItem(oldDataSource.getType());
        mDriver.setText(oldDataSource.getDriver());
        mURL.setText(oldDataSource.getUrl());
        mUser.setText(oldDataSource.getUser());
        mPassword.setText(oldDataSource.getPassword());
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.simulator.viewcomponent.DataGenerationPanel.java

/**
 * Inits the components./*from w w  w. j a  v a 2s  . c  o  m*/
 */
public synchronized void initComponents() {

    while (activeFrame == null) {
        if (applicationService != null && applicationService.getFrameView() != null) {
            activeFrame = applicationService.getFrameView().getActiveFrame();
        }
    }

    JPanel runPanel = new JPanel();
    runPanel.setLayout(new BoxLayout(runPanel, BoxLayout.LINE_AXIS));
    runPanel.setBorder(BorderFactory.createEmptyBorder(paddingSize, paddingSize, paddingSize, paddingSize));
    JXLabel label = new JXLabel();
    label.setLineWrap(true);
    label.setText(
            "<html>This panel allows the creation of clinically plausible data based on a query specification. "
                    + "Please note that you <b>must</b> always specify a data generation source. "
                    + "The rest of the parameters can be left in their default state. When you've configured the parameters "
                    + "click the 'Generate data' button.</html>");
    runPanel.add(label);
    runPanel.add(new JSeparator(SwingConstants.VERTICAL));
    runPanel.add(Box.createHorizontalStrut(paddingSize));
    JideButton runButton = new JideButton(new GenerateDataAction(applicationService, queryService,
            dataGenerationEngine, propertyChangeTrackerService));
    runButton.setButtonStyle(ButtonStyle.HYPERLINK_STYLE);
    runPanel.add(runButton);
    runButton.setIcon(new ImageIcon(DataGenerationPanel.class.getResource("resources/linuxconf.png")));
    runPanel.add(Box.createHorizontalStrut(paddingSize));

    // create radio buttons for choosing source
    JRadioButton queryButton = new JRadioButton("Active Query");
    queryButton.setSelected(true);
    queryButton.addActionListener(this);
    queryButton.setActionCommand("activeQuery");
    JRadioButton fileButton = new JRadioButton("File");
    fileButton.addActionListener(this);
    fileButton.setActionCommand("file");

    JRadioButton folderButton = new JRadioButton("Folder");
    folderButton.addActionListener(this);
    folderButton.setActionCommand("folder");
    ButtonGroup bg = new ButtonGroup();
    bg.add(queryButton);
    bg.add(fileButton);
    bg.add(folderButton);
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    //      buttonsPanel.add(new JLabel("Select data generation source"));
    buttonsPanel.setBorder(BorderFactory.createTitledBorder("Select data generation source"));
    buttonsPanel.add(Box.createHorizontalStrut(paddingSize));
    buttonsPanel.add(queryButton);
    buttonsPanel.add(Box.createHorizontalStrut(paddingSize));
    buttonsPanel.add(fileButton);
    buttonsPanel.add(Box.createHorizontalStrut(paddingSize));
    buttonsPanel.add(folderButton);

    locationField = new JTextField(100);
    JButton loadQueryButton = new JButton("Browse");
    loadQueryButton.addActionListener(this);
    loadQueryButton.setActionCommand("load");
    locationPanel = new JPanel();
    locationPanel.setLayout(new BoxLayout(locationPanel, BoxLayout.LINE_AXIS));
    locationPanel.add(new JLabel("Load file from"));
    locationPanel.add(Box.createHorizontalStrut(paddingSize));
    locationPanel.add(locationField);
    locationPanel.add(Box.createHorizontalStrut(paddingSize));
    locationPanel.add(loadQueryButton);

    JPanel lhsPanel = new JPanel(new GridLayout(0, 2));
    JPanel rhsPanel = new JPanel(new GridLayout(0, 2));

    lhsPanel.add(new JLabel("Max number of patients to generate"));

    SpinnerNumberModel model = new SpinnerNumberModel(initialPatientsNumber, 1, 1000000, 1);
    ptNumberSpinner = new JSpinner(model);
    ptNumberSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent event) {
            // get value currently selected in spinner and set in engine
            dataGenerationEngine.setMaxPatientNumber(Long.parseLong(ptNumberSpinner.getValue().toString()));
            //                Object value = ptNumberSpinner.getValue();
            //                if(value instanceof Double)
            //                {
            //                    Double d = (Double) ptNumberSpinner.getValue();
            //                    dataGenerationEngine.setMaxPatientNumber(d.longValue());
            //                }
            //                else
            //                {
            //                    dataGenerationEngine.setMaxPatientNumber(Long.parseLong(ptNumberSpinner.getValue().toString()));
            //                }
            logger.debug("ptNumberSpinner.getValue().getClass() = " + ptNumberSpinner.getValue().getClass());
            logger.debug("Max pt number in engine set to : " + dataGenerationEngine.getMaxPatientNumber());
        }
    });
    lhsPanel.add(ptNumberSpinner);

    lhsPanel.add(new JLabel("Min age of patients to generate"));
    SpinnerNumberModel ageModel = new SpinnerNumberModel(initialMinimumAge, 1, 120, 1);
    minAgeSpinner = new JSpinner(ageModel);
    minAgeSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            // set min pt age to current value
            dataGenerationEngine.setMinPatientAgeInYears(Integer.parseInt(minAgeSpinner.getValue().toString()));
            logger.debug("Value of engine.getMinPatientAgeInYears() : "
                    + dataGenerationEngine.getMinPatientAgeInYears());
        }
    });
    lhsPanel.add(minAgeSpinner);

    lhsPanel.add(new JLabel("Data generation strategy"));
    generationStrategyBox = new JComboBox(DataGenerationEngine.DataGenerationStrategy.values());
    generationStrategyBox.setSelectedItem(DataGenerationEngine.DataGenerationStrategy.ADD_IF_NOT_EXISTS);
    generationStrategyBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dataGenerationEngine.setDataGenerationStrategy(
                    (DataGenerationEngine.DataGenerationStrategy) generationStrategyBox.getSelectedItem());
        }
    });
    lhsPanel.add(generationStrategyBox);

    includeExcludedTermsBox = new JCheckBox(new AbstractAction("Include Excluded terms in data") {

        public void actionPerformed(ActionEvent arg0) {
            dataGenerationEngine.setIncludeExcludedTerms(includeExcludedTermsBox.isSelected());
            logger.debug("dataGenerationEngine.isIncludeExcludedTerms() = "
                    + dataGenerationEngine.isIncludeExcludedTerms());
        }
    });
    rhsPanel.add(includeExcludedTermsBox);

    randomiseNumericalValuesBox = new JCheckBox(new AbstractAction("Randomise Numerical values in data") {

        public void actionPerformed(ActionEvent arg0) {
            dataGenerationEngine.setRandomiseNumericalValues(randomiseNumericalValuesBox.isSelected());
            logger.debug("dataGenerationEngine.isRandomiseNumericalValues() = "
                    + dataGenerationEngine.isRandomiseNumericalValues());
        }
    });
    rhsPanel.add(randomiseNumericalValuesBox);

    refineQualifiersCheckBox = new JCheckBox(new AbstractAction("Refine Qualifiers in expression") {
        public void actionPerformed(ActionEvent e) {
            dataGenerationEngine.setRefineQualifiers(refineQualifiersCheckBox.isSelected());
            logger.debug(
                    "dataGenerationEngine.isRefineQualifiers() = " + dataGenerationEngine.isRefineQualifiers());
        }
    });
    rhsPanel.add(refineQualifiersCheckBox);

    includePreCoordinatedDataCheckBox = new JCheckBox(
            new AbstractAction("Include pre-coordinated expressions") {
                public void actionPerformed(ActionEvent e) {
                    dataGenerationEngine
                            .setIncludePrecoordinatedData(includePreCoordinatedDataCheckBox.isSelected());
                    logger.debug("dataGenerationEngine.isIncludePrecoordinatedData() = "
                            + dataGenerationEngine.isIncludePrecoordinatedData());
                }
            });
    rhsPanel.add(includePreCoordinatedDataCheckBox);
    rhsPanel.add(new JLabel("  "));

    /*
    * create panel for parametrising engine
    */
    JPanel parametrisationPanel = new JPanel();
    parametrisationPanel.setLayout(new GridLayout(0, 2));
    parametrisationPanel.setBorder(BorderFactory.createTitledBorder("Engine Parameters"));

    // add panels to parametrisation panel
    parametrisationPanel.add(lhsPanel);
    parametrisationPanel.add(rhsPanel);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
    topPanel.add(runPanel);
    topPanel.add(new JSeparator(SwingConstants.VERTICAL));
    topPanel.add(buttonsPanel);
    // add all panels to this component
    setLayout(new BorderLayout());
    add(topPanel, BorderLayout.NORTH);
    add(parametrisationPanel, BorderLayout.CENTER);

    // initialise values
    populateFields(dataGenerationEngine);
}

From source file:verdandi.ui.ProjectViewerPanel.java

private JToolBar getToolbar() {
    // JPanel toolbar = new JPanel();
    // toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.LINE_AXIS));
    JToolBar toolbar = new JToolBar(SwingConstants.HORIZONTAL);

    toolbar.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;/*from   w w  w .j a va 2s .co m*/
    c.gridy = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 0.0;
    c.weighty = 0.0;

    URL imageURL = null;
    imageURL = Thread.currentThread().getContextClassLoader()
            .getResource(THEME_RC.getString("icon.project.add"));
    ImageIcon addProjectIcon = new ImageIcon(imageURL, "add");

    JButton addProject = new JButton(addProjectIcon);
    addProject.setActionCommand(CMD_ADD_PROJECT);
    addProject.setToolTipText(RB.getString("projectviewer.add.tooltip"));
    addProject.addActionListener(this);
    toolbar.add(addProject, c);
    c.gridx++;

    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.edit"));
    ImageIcon editProjectIcon = new ImageIcon(imageURL, "edit");

    JButton editProject = new JButton(editProjectIcon);
    editProject.setActionCommand(CMD_EDIT_PROJECT);
    editProject.setToolTipText(RB.getString("projectviewer.edit.tooltip"));
    editProject.addActionListener(this);
    toolbar.add(editProject, c);
    c.gridx++;

    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.projects.import"));
    ImageIcon importProjectIcon = new ImageIcon(imageURL, "import");
    JButton importProject = new JButton(importProjectIcon);
    importProject.setActionCommand(CMD_IMPORT_PROJECT);
    importProject.setToolTipText(RB.getString("projectviewer.import.tooltip"));
    importProject.addActionListener(this);
    toolbar.add(importProject, c);
    c.gridx++;

    // THEME_RC.getString("")
    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.projects.export"));
    ImageIcon exportProjectIcon = new ImageIcon(imageURL, "export");
    JButton exportProject = new JButton(exportProjectIcon);
    exportProject.setActionCommand(CMD_EXPORT_PROJECT);
    exportProject.setToolTipText(RB.getString("projectviewer.export.tooltip"));
    exportProject.addActionListener(this);
    toolbar.add(exportProject, c);
    c.gridx++;

    toolbar.add(new JToolBar.Separator(), c);
    c.gridx++;

    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.hide.active"));
    hideActiveIcon = new ImageIcon(imageURL, "hide active");
    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.show.active"));
    showActiveIcon = new ImageIcon(imageURL, "show active");
    toggleShowActive = new JToggleButton(hideActiveIcon);
    toggleShowActive.setActionCommand(CMD_TOGGLE_SHOW_ACTIVE);
    toggleShowActive.setToolTipText(RB.getString("projectviewer.toggleshowactive.tooltip"));
    toggleShowActive.addActionListener(this);
    toolbar.add(toggleShowActive, c);
    c.gridx++;

    c.weightx = 0.5;
    toolbar.add(Box.createHorizontalGlue(), c);
    c.weightx = 0.0;
    c.gridx++;

    c.insets = new Insets(0, 5, 0, 5);
    toolbar.add(new JLabel("Filter"), c);
    c.gridx++;
    c.insets = new Insets(0, 0, 0, 0);
    searchField = new JTextField(10);
    searchField.getDocument().addDocumentListener(this);
    searchField.setToolTipText(RB.getString("projectviewer.searchfield.tooltip"));
    toolbar.add(searchField, c);

    toolbar.setFloatable(false);
    return toolbar;
}