Example usage for javax.swing SwingConstants CENTER

List of usage examples for javax.swing SwingConstants CENTER

Introduction

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

Prototype

int CENTER

To view the source code for javax.swing SwingConstants CENTER.

Click Source Link

Document

The central position in an area.

Usage

From source file:drusy.ui.panels.SwitchStatePanel.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Kevin Renella
    headerPanel = new JPanel();
    label1 = new JLabel();
    mainPanel = new JPanel();

    //======== this ========

    setLayout(new BorderLayout());

    //======== headerPanel ========
    {//w  w w  . j  a  va 2s .c  o m
        headerPanel.setLayout(new BorderLayout());

        //---- label1 ----
        label1.setText("This panel shows you the users connected on the Switch");
        label1.setHorizontalAlignment(SwingConstants.CENTER);
        headerPanel.add(label1, BorderLayout.CENTER);
    }
    add(headerPanel, BorderLayout.NORTH);

    //======== mainPanel ========
    {
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    }
    add(mainPanel, BorderLayout.CENTER);
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:misc.ModalityDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method is invoked from the/*from   w w  w . j  ava  2 s  .  com*/
 * 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:com.sshtools.common.ui.SshToolsConnectionPanel.java

/**
 *
 *
 * @param parent//from   w w w  .j av  a  2 s . com
 * @param profile
 * @param optionalTabs
 *
 * @return
 */
public static SshToolsConnectionProfile showConnectionDialog(Component parent,
        SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) {
    //  If no properties are provided, then use the default
    if (profile == null) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile = new SshToolsConnectionProfile();
        profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, ""));
        profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port));
        profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, ""));

    }

    final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true);

    if (optionalTabs != null) {
        for (int i = 0; i < optionalTabs.length; i++) {
            conx.addTab(optionalTabs[i]);
        }
    }

    conx.setConnectionProfile(profile);

    JDialog d = null;
    Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);

    if (w instanceof JDialog) {
        d = new JDialog((JDialog) w, "Connection Profile", true);
    } else if (w instanceof JFrame) {
        d = new JDialog((JFrame) w, "Connection Profile", true);
    } else {
        d = new JDialog((JFrame) null, "Connection Profile", true);
    }

    final JDialog dialog = d;

    class UserAction {
        boolean connect;
    }

    final UserAction userAction = new UserAction();

    //  Create the bottom button panel
    final JButton cancel = new JButton("Cancel");
    cancel.setMnemonic('c');
    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            userAction.connect = false;
            dialog.setVisible(false);
        }
    });

    final JButton connect = new JButton("Connect");
    connect.setMnemonic('t');
    connect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (conx.validateTabs()) {
                userAction.connect = true;
                dialog.setVisible(false);
            }
        }
    });
    dialog.getRootPane().setDefaultButton(connect);

    JPanel buttonPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(6, 6, 0, 0);
    gbc.weighty = 1.0;
    UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE);
    UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER);

    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
    southPanel.add(buttonPanel);

    //
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPanel.add(conx, BorderLayout.CENTER);
    mainPanel.add(southPanel, BorderLayout.SOUTH);

    // Show the dialog
    dialog.getContentPane().setLayout(new GridLayout(1, 1));
    dialog.getContentPane().add(mainPanel);
    dialog.pack();
    dialog.setResizable(false);
    UIUtil.positionComponent(SwingConstants.CENTER, dialog);

    //show the simple box and act on the answer.
    SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance();
    StringBuffer sb = new StringBuffer();
    userAction.connect = !stscp.getHostname(sb, profile.getHost());

    boolean advanced = stscp.getAdvanced();

    if (advanced) {
        userAction.connect = false;
        profile.setHost(sb.toString());
        conx.hosttab.setConnectionProfile(profile);
        dialog.setVisible(true);
    }

    // Make sure we didn't cancel
    if (!userAction.connect) {
        return null;
    }

    conx.applyTabs();
    if (!advanced)
        profile.setHost(sb.toString());
    if (!advanced) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile.setPort(port);
    }
    if (!advanced)
        profile.setUsername("");

    PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost());
    // only save user inputed configuration
    if (advanced) {
        PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername());
        PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort());
    }
    // Return the connection properties
    return profile;
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java

private SampleGroupViewer(String title, KdxploreDatabase kdxdb, Trial trial, SampleGroup sampleGroup) {
    super(new BorderLayout());

    this.title = title;
    //        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.kdxdb = kdxdb;
    this.trial = trial;
    this.sampleGroup = sampleGroup;

    initialise();//w  w  w.  java2  s  .c  o m
    if (plotInfoByPlotId.isEmpty()) {
        add(new JLabel("No Plots available"), BorderLayout.CENTER);
    } else {
        tiChoiceTableModel = new TraitInstanceChoiceTableModel();
        JTable tiTable = new JTable(tiChoiceTableModel);
        tiTable.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    List<Integer> modelRows = GuiUtil.getSelectedModelRows(tiTable);
                    if (modelRows.isEmpty()) {
                        Point pt = e.getPoint();
                        int vrow = tiTable.rowAtPoint(pt);
                        if (vrow >= 0) {
                            int mrow = tiTable.convertRowIndexToModel(vrow);
                            if (mrow >= 0) {
                                showPopupMenu(tiTable, pt, Arrays.asList(Integer.valueOf(mrow)));
                            }
                        }
                    } else {
                        showPopupMenu(tiTable, e.getPoint(), modelRows);
                    }
                }
            }
        });

        tableModel = new DataTableModel(plotInfoByPlotId);
        JTable table = new JTable(tableModel);
        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(SwingConstants.CENTER);
        table.setDefaultRenderer(String.class, r);

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tiTable),
                new JScrollPane(table));
        splitPane.setResizeWeight(0.2);
        add(splitPane, BorderLayout.CENTER);
        table.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(table, true));
    }
}

From source file:edu.cuny.cat.ui.ClockPanel.java

private void initIterationLabel() {
    iteration = -1;//from   ww  w.  j a  v  a  2s.  c  o m
    iterationLabel = new JLabel();
    iterationLabel.setHorizontalAlignment(SwingConstants.CENTER);
    add(iterationLabel, BorderLayout.SOUTH);
}

From source file:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java

/**
 * @return/*from  ww w. j a  v  a  2s  . c  o  m*/
 */
private DefaultTableCellRenderer getTableCellRenderer() {
    return new DefaultTableCellRenderer() {
        @SuppressWarnings("unchecked")
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            //                DataObjTableModelRowInfo rowInfo = rowInfoList.get(row);

            boolean doCenter = false;
            Object val = value;
            if (value instanceof Pair<?, ?>) {
                Pair<Object, Object> pair = (Pair<Object, Object>) value;
                val = pair.first;
                doCenter = true;
            }

            JLabel lbl = (JLabel) super.getTableCellRendererComponent(table, val, isSelected, hasFocus, row,
                    column);
            //                if (rowInfo.isMainRecord())
            //                {
            //                    lbl.setForeground(Color.WHITE);
            //                    lbl.setBackground(Color.BLUE.brighter().brighter());
            //                    
            //                } else
            //                {
            //                    lbl.setForeground(model.isSame(column) ? sameColor : Color.BLACK);
            //                    lbl.setBackground(Color.WHITE);
            //                }
            lbl.setHorizontalTextPosition(doCenter ? SwingConstants.CENTER : SwingConstants.LEFT);

            return lbl;
        }
    };
}

From source file:edu.ku.brc.specify.tasks.subpane.LabelsPane.java

/**
 * Set the text to the label (create the label if it doesn't exist)
 * @param msg the message to be displayed
 *///from w w  w . ja  v  a 2s .c  o m
public void setLabelText(final String msg) {
    if (label == null) {
        removeAll();

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,2px,p,f:p:g", "f:p:g, p, f:p:g"), this);//$NON-NLS-1$ //$NON-NLS-2$

        JButton moreBtn = createIconBtn("InfoIcon", IconManager.IconSize.Std16, null, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showErrorMsgs();
            }
        });
        label = createLabel("", SwingConstants.CENTER);
        pb.add(label, cc.xy(2, 2));
        pb.add(moreBtn, cc.xy(4, 2));

        moreBtn.setEnabled(true);
    }

    if (progressBarPanel != null) {
        remove(progressBarPanel);
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            label.setText(msg);
            invalidate();
            doLayout();
            repaint();
        }
    });
}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Setup the GUI.//from  w w  w.j ava  2 s  .c o m
 */
private void setupGUI() {
    JPanel mainPanel = new JPanel();
    this.setContentPane(mainPanel);

    // start layout
    mainPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 2, 5);
    JPanel radioPanel = new JPanel();
    radioPanel.setLayout(new BorderLayout());
    zoomRadiobutton = new JRadioButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.label"));
    zoomRadiobutton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.tip"));
    zoomRadiobutton.setSelected(true);
    radioPanel.add(zoomRadiobutton, BorderLayout.LINE_START);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 1;
    selectionRadiobutton = new JRadioButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.label"));
    selectionRadiobutton
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.tip"));
    selectionRadiobutton.setHorizontalAlignment(SwingConstants.CENTER);
    radioPanel.add(selectionRadiobutton, BorderLayout.LINE_END);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 3;
    this.add(radioPanel, gbc);

    ButtonGroup group = new ButtonGroup();
    group.add(zoomRadiobutton);
    group.add(selectionRadiobutton);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.CENTER;
    rangeAxisSelectionCombobox = new JComboBox();
    rangeAxisSelectionCombobox.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.range_axis_combobox.tip"));
    rangeAxisSelectionCombobox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateValueRange();
        }
    });
    this.add(rangeAxisSelectionCombobox, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 2, 5);
    JLabel domainRangeLowerBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.label"));
    this.add(domainRangeLowerBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.insets = new Insets(2, 5, 2, 5);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    domainRangeLowerBoundField = new JTextField();
    domainRangeLowerBoundField.setText(String.valueOf(domainRangeLowerBound));
    domainRangeLowerBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyDomainRangeLowerBoundInput(input);
        }
    });
    domainRangeLowerBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.tip"));
    this.add(domainRangeLowerBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.NONE;
    JLabel domainRangeUpperBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.label"));
    this.add(domainRangeUpperBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    domainRangeUpperBoundField = new JTextField();
    domainRangeUpperBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.tip"));
    domainRangeUpperBoundField.setText(String.valueOf(domainRangeUpperBound));
    domainRangeUpperBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyDomainRangeUpperBoundInput(input);
        }
    });
    this.add(domainRangeUpperBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.NONE;
    JLabel valueRangeLowerBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.label"));
    this.add(valueRangeLowerBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    valueRangeLowerBoundField = new JTextField();
    valueRangeLowerBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.tip"));
    valueRangeLowerBoundField.setText(String.valueOf(valueRangeLowerBound));
    valueRangeLowerBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyValueRangeLowerBoundInput(input);
        }
    });
    this.add(valueRangeLowerBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.NONE;
    JLabel valueRangeUpperBoundLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.label"));
    this.add(valueRangeUpperBoundLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    valueRangeUpperBoundField = new JTextField();
    valueRangeUpperBoundField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.tip"));
    valueRangeUpperBoundField.setText(String.valueOf(valueRangeUpperBound));
    valueRangeUpperBoundField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyValueRangeUpperBoundInput(input);
        }
    });
    this.add(valueRangeUpperBoundField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    this.add(new JSeparator(), gbc);

    gbc.gridx = 0;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    JLabel colorMinValueLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.label"));
    this.add(colorMinValueLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    colorMinValueField = new JTextField();
    colorMinValueField
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.tip"));
    colorMinValueField.setText(String.valueOf(colorMinValue));
    colorMinValueField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyColorInput(input);
        }
    });
    colorMinValueField.setEnabled(false);
    this.add(colorMinValueField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.NONE;
    JLabel colorMaxValueLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.label"));
    this.add(colorMaxValueLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    colorMaxValueField = new JTextField();
    colorMaxValueField
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.tip"));
    colorMaxValueField.setText(String.valueOf(colorMaxValue));
    colorMaxValueField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyColorInput(input);
        }
    });
    colorMaxValueField.setEnabled(false);
    this.add(colorMaxValueField, gbc);

    gbc.gridx = 1;
    gbc.gridy = 9;
    gbc.fill = GridBagConstraints.NONE;
    restoreColorButton = new JButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.label"));
    restoreColorButton
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.tip"));
    restoreColorButton.setIcon(SwingTools.createIcon(
            "16/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.icon")));
    restoreColorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            LinkAndBrushSelection linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.RESTORE_COLOR,
                    new LinkedList<Pair<Integer, Range>>(), new LinkedList<Pair<Integer, Range>>(), null, null,
                    engine.getPlotInstance());
            engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection);
            updateColorValues();
        }
    });
    restoreColorButton.setEnabled(false);
    this.add(restoreColorButton, gbc);

    gbc.gridx = 0;
    gbc.gridy = 10;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(2, 5, 5, 5);
    this.add(new JSeparator(), gbc);

    gbc.gridx = 0;
    gbc.gridy = 11;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 5, 5);
    okButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.label"));
    okButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.tip"));
    okButton.setIcon(SwingTools
            .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.icon")));
    okButton.setMnemonic(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.mne").toCharArray()[0]);
    okButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // make sure fields have correct values
            boolean fieldsPassedChecks = checkFields();
            if (!fieldsPassedChecks) {
                return;
            }

            Object selectedItem = rangeAxisSelectionCombobox.getSelectedItem();
            if (selectedItem != null && selectedItem instanceof RangeAxisConfig) {
                RangeAxisConfig config = (RangeAxisConfig) selectedItem;
                boolean zoomOnLinkAndBrushSelection = engine.getChartPanel().getZoomOnLinkAndBrushSelection();
                Range domainRange = new Range(Double.parseDouble(domainRangeLowerBoundField.getText()),
                        Double.parseDouble(domainRangeUpperBoundField.getText()));
                Range valueRange = new Range(Double.parseDouble(valueRangeLowerBoundField.getText()),
                        Double.parseDouble(valueRangeUpperBoundField.getText()));
                LinkedList<Pair<Integer, Range>> domainRangeList = new LinkedList<Pair<Integer, Range>>();
                // only add domain zoom if != 0
                if (domainRange.getUpperBound() != 0) {
                    domainRangeList.add(new Pair<Integer, Range>(0, domainRange));
                }
                LinkedList<Pair<Integer, Range>> valueRangeList = new LinkedList<Pair<Integer, Range>>();
                // only add range zoom if at least one RangeAxisConfig exists
                if (engine.getPlotInstance().getMasterPlotConfiguration().getRangeAxisConfigs().size() > 0) {
                    if (valueRange.getUpperBound() != 0) {
                        // only add value zoom if != 0
                        valueRangeList.add(
                                new Pair<Integer, Range>(engine.getPlotInstance().getMasterPlotConfiguration()
                                        .getIndexOfRangeAxisConfigById(config.getId()), valueRange));
                    }
                }

                // zoom or select or color
                LinkAndBrushSelection linkAndBrushSelection = null;
                if (zoomRadiobutton.isSelected()) {
                    linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.ZOOM_IN, domainRangeList,
                            valueRangeList);
                    if (isColorChanged(Double.parseDouble(colorMinValueField.getText()),
                            Double.parseDouble(colorMaxValueField.getText()))) {
                        linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_ZOOM,
                                domainRangeList, valueRangeList,
                                Double.parseDouble(colorMinValueField.getText()),
                                Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance());
                    }
                } else if (selectionRadiobutton.isSelected()) {
                    linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.SELECTION, domainRangeList,
                            valueRangeList);
                    if (isColorChanged(Double.parseDouble(colorMinValueField.getText()),
                            Double.parseDouble(colorMaxValueField.getText()))) {
                        linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_SELECTION,
                                domainRangeList, valueRangeList,
                                Double.parseDouble(colorMinValueField.getText()),
                                Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance());
                    }
                }
                engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection);
                engine.getChartPanel().setZoomOnLinkAndBrushSelection(zoomOnLinkAndBrushSelection);
            } else {
                return;
            }

            ManageZoomDialog.this.dispose();
        }
    });
    okButton.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                okButton.doClick();
            }
        }
    });
    this.add(okButton, gbc);

    gbc.gridx = 2;
    gbc.gridy = 11;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    cancelButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.label"));
    cancelButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.tip"));
    cancelButton.setIcon(SwingTools
            .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.icon")));
    cancelButton.setMnemonic(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.mne").toCharArray()[0]);
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // cancel requested, close dialog
            ManageZoomDialog.this.dispose();
        }
    });
    this.add(cancelButton, gbc);

    // misc settings
    this.setMinimumSize(new Dimension(375, 360));
    // center dialog
    this.setLocationRelativeTo(null);
    this.setTitle(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.title.label"));
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setModal(true);

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowActivated(WindowEvent e) {
            okButton.requestFocusInWindow();
        }
    });
}

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

/**
 * @param title/*from  w  w  w  .  j a v  a2  s.  c  om*/
 * @param fields
 * @param required
 */
protected void init(final String title, final String[] fields, final boolean[] required, final String[] types,
        final Integer[] lens) {

    Pair<String, String> rowCol = getRowColDefs();

    builder = new PanelBuilder(new FormLayout(rowCol.first, rowCol.second), this);
    row = 1;

    builder.add(createI18NLabel(title, SwingConstants.CENTER), cc.xywh(1, row, 4, 1));
    row += 2;

    if (required != null) {
        reqHash = new Hashtable<String, Boolean>();
    }

    int i = 0;
    for (String fName : fields) {
        if (fName.equals("-")) {
            JComponent c = builder.addSeparator(UIRegistry.getResourceString(labels[i]), cc.xyw(1, row, 4));
            compList.add(c);

        } else if (fName.equals(" ")) {
            JLabel lbl = UIHelper.createLabel("");
            builder.add(lbl, cc.xyw(1, row, 4));
            compList.add(lbl);

        } else {
            JComponent comp;
            if (reqHash != null) {
                reqHash.put(fName, required[i]);
            }

            if (types != null && types[i].equals("checkbox")) {
                comp = createCheckBox(builder, labels[i], row);

            } else {
                comp = createField(builder, labels[i], required != null ? required[i] : true, row,
                        lens != null ? lens[i] : null);
            }
            compList.add(comp);
            comps.put(fName, comp);
        }
        row += 2;
        i++;
    }
    updateBtnUI();
}

From source file:com.funambol.admin.module.panels.DefaultSyncSourceConfigPanel.java

/**
 * Creates the panel/*from  w w  w . ja v  a 2s .  co  m*/
 */
private void init() {

    this.setLayout(null);

    titledBorder = new TitledBorder("");

    panelName.setFont(GuiFactory.titlePanelFont);
    panelName.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_EDIT) + " " + sourceTypeDescription);
    panelName.setBounds(new Rectangle(14, 5, 316, 28));
    panelName.setAlignmentX(SwingConstants.CENTER);
    panelName.setBorder(titledBorder);

    final int LABEL_X = 14;
    final int VALUE_X = 170;
    int y = 60;
    final int GAP_Y = 30;

    sourceUriLabel.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_URI) + ": ");
    sourceUriLabel.setFont(defaultFont);
    sourceUriLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    sourceUriValue.setFont(defaultFont);
    sourceUriValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    nameLabel.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_NAME) + ": ");
    nameLabel.setFont(defaultFont);
    nameLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    nameValue.setFont(defaultFont);
    nameValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    infoTypesLabel.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_SUPPORTED_TYPES) + ": ");
    infoTypesLabel.setFont(defaultFont);
    infoTypesLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    infoTypesValue.setFont(defaultFont);
    infoTypesValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    infoVersionsLabel.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_SUPPORTED_VERSIONS) + ": ");
    infoVersionsLabel.setFont(defaultFont);
    infoVersionsLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    infoVersionsValue.setFont(defaultFont);
    infoVersionsValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    int x = LABEL_X;

    encryption.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_ENCRYPTION));
    encryption.setFont(defaultFont);
    encryption.setSelected(false);
    encryption.setBounds(x, y, 150, 25);

    // What happens if the encryption is enabled?
    encryption.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == e.SELECTED) {
                encoding.setSelected(true); // Encryption implies encoding
                encoding.setEnabled(false);
            }
            if (e.getStateChange() == e.DESELECTED) {
                encoding.setSelected(false);
                encoding.setEnabled(true);
            }
        }
    });
    y += GAP_Y; // New line

    encoding.setText(Bundle.getMessage(Bundle.LABEL_SYNC_SOURCE_ENCODING));
    encoding.setFont(defaultFont);
    encoding.setSelected(false);
    encoding.setBounds(x, y, 150, 25);
    y += GAP_Y; // New line
    y += GAP_Y; // New line

    confirmButton.setFont(defaultFont);
    confirmButton.setText(Bundle.getMessage(Bundle.LABEL_BUTTON_ADD));
    confirmButton.setBounds(VALUE_X, y, 70, 25);

    // What happens when the confirmButton is pressed?
    confirmButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                if (getState() == STATE_INSERT) {
                    DefaultSyncSourceConfigPanel.this.actionPerformed(new ActionEvent(
                            DefaultSyncSourceConfigPanel.this, ACTION_EVENT_INSERT, event.getActionCommand()));
                } else {
                    DefaultSyncSourceConfigPanel.this.actionPerformed(new ActionEvent(
                            DefaultSyncSourceConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand()));
                }
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage()));
            }
        }
    });

    // Adds all components to the panel
    this.add(panelName, null);
    this.add(nameLabel, null);
    this.add(sourceUriLabel, null);
    this.add(sourceUriValue, null);
    this.add(nameValue, null);
    this.add(infoTypesLabel, null);
    this.add(infoTypesValue, null);
    this.add(infoVersionsLabel, null);
    this.add(infoVersionsValue, null);
    this.add(encryption, null);
    this.add(encoding, null);
    this.add(confirmButton, null);
}