Example usage for java.awt GridBagConstraints WEST

List of usage examples for java.awt GridBagConstraints WEST

Introduction

In this page you can find the example usage for java.awt GridBagConstraints WEST.

Prototype

int WEST

To view the source code for java.awt GridBagConstraints WEST.

Click Source Link

Document

Put the component on the left side of its display area, centered vertically.

Usage

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.pdf.PdfExportDialog.java

private JPanel createMetaDataPanel() {
    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    final JLabel lblAuthor = new JLabel(getResources().getString("pdfsavedialog.author")); //$NON-NLS-1$
    final JLabel lblTitel = new JLabel(getResources().getString("pdfsavedialog.title")); //$NON-NLS-1$
    final JLabel lblKeywords = new JLabel(getResources().getString("pdfsavedialog.keywords")); //$NON-NLS-1$
    final JLabel lblDescription = new JLabel(getResources().getString("pdfsavedialog.description")); //$NON-NLS-1$

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;//from ww w . j av a2  s.com
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(3, 1, 1, 1);
    contentPane.add(lblTitel, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(lblAuthor, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(lblKeywords, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(lblDescription, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(3, 1, 1, 1);
    contentPane.add(txTitle, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(txAuthor, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(txKeywords, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(txDescription, gbc);

    final JPanel advancedOptionsPane = new JPanel();
    advancedOptionsPane.setLayout(new BorderLayout());
    advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
    return advancedOptionsPane;
}

From source file:com.stefanbrenner.droplet.utils.UiUtilsTest.java

@Test
public void testCreateGridBagConstraints() {

    GridBagConstraints gbc = UiUtils.createGridBagConstraints(3, 4);
    assertEquals(3, gbc.gridx);//from w w  w .jav  a 2s.c  o m
    assertEquals(4, gbc.gridy);
    assertEquals(1, gbc.gridwidth);
    assertEquals(1, gbc.gridheight);
    assertEquals(0.0, gbc.weightx);
    assertEquals(0.0, gbc.weighty);
    assertEquals(GridBagConstraints.CENTER, gbc.anchor);
    assertEquals(GridBagConstraints.NONE, gbc.fill);

    gbc = UiUtils.createGridBagConstraints(5, 6, 7, 8);
    assertEquals(5, gbc.gridx);
    assertEquals(6, gbc.gridy);
    assertEquals(1, gbc.gridwidth);
    assertEquals(1, gbc.gridheight);
    assertEquals(7.0, gbc.weightx);
    assertEquals(8.0, gbc.weighty);
    assertEquals(GridBagConstraints.CENTER, gbc.anchor);
    assertEquals(GridBagConstraints.NONE, gbc.fill);

    gbc = UiUtils.createGridBagConstraints(9, 10, 11, 12, GridBagConstraints.WEST);
    assertEquals(9, gbc.gridx);
    assertEquals(10, gbc.gridy);
    assertEquals(1, gbc.gridwidth);
    assertEquals(1, gbc.gridheight);
    assertEquals(11.0, gbc.weightx);
    assertEquals(12.0, gbc.weighty);
    assertEquals(GridBagConstraints.WEST, gbc.anchor);
    assertEquals(GridBagConstraints.NONE, gbc.fill);

}

From source file:ca.uhn.hl7v2.testpanel.ui.AddMessageDialog.java

/**
 * Create the dialog./*www . j ava  2s.  c o  m*/
 */
public AddMessageDialog(Controller theController) {
    myController = theController;

    setMinimumSize(new Dimension(450, 400));
    setPreferredSize(new Dimension(450, 400));
    setSize(new Dimension(450, 400));
    setResizable(false);
    setMaximumSize(new Dimension(450, 400));
    setTitle("Add Message");
    setBounds(100, 100, 450, 401);
    getContentPane().setLayout(new BorderLayout());
    mycontentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(mycontentPanel, BorderLayout.CENTER);
    GridBagLayout gbl_contentPanel = new GridBagLayout();
    gbl_contentPanel.columnWidths = new int[] { 0, 0 };
    gbl_contentPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_contentPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_contentPanel.rowWeights = new double[] { 1.0, 0.0, Double.MIN_VALUE };
    mycontentPanel.setLayout(gbl_contentPanel);
    {
        JPanel panel = new JPanel();
        panel.setBorder(
                new TitledBorder(null, "Message Type", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GridBagConstraints gbc_panel = new GridBagConstraints();
        gbc_panel.weighty = 1.0;
        gbc_panel.insets = new Insets(0, 0, 5, 0);
        gbc_panel.fill = GridBagConstraints.BOTH;
        gbc_panel.gridx = 0;
        gbc_panel.gridy = 0;
        mycontentPanel.add(panel, gbc_panel);
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[] { 0, 0, 0 };
        gbl_panel.rowHeights = new int[] { 0, 0, 0 };
        gbl_panel.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
        gbl_panel.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
        panel.setLayout(gbl_panel);
        {
            JLabel lblVersion = new JLabel("Version");
            GridBagConstraints gbc_lblVersion = new GridBagConstraints();
            gbc_lblVersion.insets = new Insets(0, 0, 5, 5);
            gbc_lblVersion.gridx = 0;
            gbc_lblVersion.gridy = 0;
            panel.add(lblVersion, gbc_lblVersion);
        }
        {
            JLabel lblType = new JLabel("Type");
            GridBagConstraints gbc_lblType = new GridBagConstraints();
            gbc_lblType.insets = new Insets(0, 0, 5, 0);
            gbc_lblType.gridx = 1;
            gbc_lblType.gridy = 0;
            panel.add(lblType, gbc_lblType);
        }
        {
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportBorder(null);
            GridBagConstraints gbc_scrollPane = new GridBagConstraints();
            gbc_scrollPane.weighty = 1.0;
            gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
            gbc_scrollPane.fill = GridBagConstraints.BOTH;
            gbc_scrollPane.gridx = 0;
            gbc_scrollPane.gridy = 1;
            panel.add(scrollPane, gbc_scrollPane);
            {
                myVersionList = new JList();
                myVersionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                scrollPane.setViewportView(myVersionList);
            }
        }
        {
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportBorder(null);
            GridBagConstraints gbc_scrollPane = new GridBagConstraints();
            gbc_scrollPane.weighty = 1.0;
            gbc_scrollPane.weightx = 1.0;
            gbc_scrollPane.fill = GridBagConstraints.BOTH;
            gbc_scrollPane.gridx = 1;
            gbc_scrollPane.gridy = 1;
            panel.add(scrollPane, gbc_scrollPane);
            {
                myMessageTypeList = new JList();
                myMessageTypeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                scrollPane.setViewportView(myMessageTypeList);
            }
        }
    }
    {
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(null, "Options", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GridBagConstraints gbc_panel = new GridBagConstraints();
        gbc_panel.fill = GridBagConstraints.BOTH;
        gbc_panel.gridx = 0;
        gbc_panel.gridy = 1;
        mycontentPanel.add(panel, gbc_panel);
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[] { 0, 0, 0 };
        gbl_panel.rowHeights = new int[] { 0, 0 };
        gbl_panel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
        gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
        panel.setLayout(gbl_panel);
        {
            JLabel lblEncoding = new JLabel("Encoding");
            GridBagConstraints gbc_lblEncoding = new GridBagConstraints();
            gbc_lblEncoding.insets = new Insets(0, 0, 0, 5);
            gbc_lblEncoding.gridx = 0;
            gbc_lblEncoding.gridy = 0;
            panel.add(lblEncoding, gbc_lblEncoding);
        }
        {
            JPanel panel_1 = new JPanel();
            panel_1.setBorder(null);
            GridBagConstraints gbc_panel_1 = new GridBagConstraints();
            gbc_panel_1.anchor = GridBagConstraints.WEST;
            gbc_panel_1.fill = GridBagConstraints.VERTICAL;
            gbc_panel_1.gridx = 1;
            gbc_panel_1.gridy = 0;
            panel.add(panel_1, gbc_panel_1);
            {
                myEr7Radio = new JRadioButton("ER7");
                myEr7Radio.setSelected(true);
                encodingButtonGroup.add(myEr7Radio);
                panel_1.add(myEr7Radio);
            }
            {
                JRadioButton myXmlRadio = new JRadioButton("XML");
                encodingButtonGroup.add(myXmlRadio);
                panel_1.add(myXmlRadio);
            }
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("OK");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        String version = (String) myVersionList.getSelectedValue();
                        String fullType = (String) myMessageTypeList.getSelectedValue();
                        String structure = myTypesToStructures.get(fullType);
                        String[] fullTypeBits = fullType.split("\\^");
                        String type = fullTypeBits[0];
                        String trigger = fullTypeBits[1];

                        Hl7V2EncodingTypeEnum encoding = myEr7Radio.isSelected() ? Hl7V2EncodingTypeEnum.ER_7
                                : Hl7V2EncodingTypeEnum.XML;
                        myController.addMessage(version, type, trigger, structure, encoding);
                    } finally {
                        setVisible(false);
                    }
                }
            });
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    AddMessageDialog.this.setVisible(false);
                }
            });
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }

    initLocal();
}

From source file:com.frostwire.gui.bittorrent.PartialFilesDialog.java

private void setupToggleAllSelectionCheckbox() {
    GridBagConstraints c;//w  w  w . j  ava  2s. c o m
    _checkBoxToggleAll = new JCheckBox(I18n.tr("Select/Unselect all files"), true);
    _checkBoxToggleAll.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            onCheckBoxToggleAll(e);
        }
    });

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.insets = new Insets(5, 5, 5, 5);
    panel.add(_checkBoxToggleAll, c);
}

From source file:org.openmicroscopy.shoola.agents.metadata.rnd.GraphicsPane.java

/** 
 * Builds hosting the various sliders//from w  ww  .j  a v  a 2s .c o m
 * 
 * @return See above.
 */
private JPanel buildGeneralPane() {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridy = 0;
    c.gridx = 0;
    if (model.isGeneralIndex()) {
        content.add(previewToolBar, c);
        c.gridy++;
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.HORIZONTAL;
        content.add(new JSeparator(), c);
        c.gridy++;
    }
    content.add(controlsBar, c);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE;//reset to default
    c.weightx = 0.0;

    Iterator<ChannelSlider> i = sliders.iterator();
    while (i.hasNext()) {
        c.gridy++;
        content.add(i.next(), c);
    }
    c.gridy++;
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    content.add(viewedBy, c);
    JPanel p = UIUtilities.buildComponentPanel(content);
    p.setBackground(content.getBackground());
    return p;
}

From source file:us.paulevans.basicxslt.TransformOutputPropertiesFrame.java

/**
 * Builds the main panel//from   w w  w  . j a  v  a2s.  co  m
 * @return
 */
private JPanel buildMainPanel() {

    int row;
    GridBagLayout layout;
    GridBagConstraints constraints;
    JPanel main;

    layout = new GridBagLayout();
    constraints = new GridBagConstraints();
    main = new JPanel(layout);
    row = 0;
    GUIUtils.add(main,
            new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_CDATA_SECTION_ELEMENTS)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JScrollPane(CDATASectionElements = new JTextArea(3, 30)), layout, constraints, row++,
            1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_DOCTYPE_PUBLIC)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, doctypePublic = new JTextField(30), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_DOCTYPE_SYSTEM)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, doctypeSystem = new JTextField(30), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_ENCODING)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, encoding = new JTextField(30), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_MEDIA_TYPE)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, mediaType = new JTextField(30), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_METHOD)), layout,
            constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, buildMethodPanel(), layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_VERSION)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, version = new JTextField(30), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_INDENT)), layout,
            constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, indent = new JCheckBox(), layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main,
            new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_OMIT_XML_DECLARATION)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, omitXmlDeclaration = new JCheckBox(), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, new JLabel(stringFactory.getString(LabelStringFactory.OUTPUTPROPS_FRAME_IS_STANDALONE)),
            layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE,
            GUIUtils.SMALL_INSETS);
    GUIUtils.add(main, standalone = new JCheckBox(), layout, constraints, row++, 1, 1, 1,
            GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS);
    return main;
}

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();//from  www.  jav a 2 s.c  o  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:com.stefanbrenner.droplet.utils.UiUtilsTest.java

@Test
public void testEditGridBagConstraints() {
    GridBagConstraints gbc = new GridBagConstraints(1, 2, 3, 4, 5.0, 6.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(1, 2, 3, 4), 9, 0);

    UiUtils.editGridBagConstraints(gbc, 11, 12);
    assertEquals(11, gbc.gridx);/*w w  w  . j av a 2 s.  com*/
    assertEquals(12, gbc.gridy);
    assertEquals(3, gbc.gridwidth);
    assertEquals(4, gbc.gridheight);
    assertEquals(0.0, gbc.weightx);
    assertEquals(0.0, gbc.weighty);
    assertEquals(GridBagConstraints.CENTER, gbc.anchor);
    assertEquals(GridBagConstraints.BOTH, gbc.fill);

    UiUtils.editGridBagConstraints(gbc, 13, 14, 15.0, 16.0);
    assertEquals(13, gbc.gridx);
    assertEquals(14, gbc.gridy);
    assertEquals(3, gbc.gridwidth);
    assertEquals(4, gbc.gridheight);
    assertEquals(15.0, gbc.weightx);
    assertEquals(16.0, gbc.weighty);
    assertEquals(GridBagConstraints.CENTER, gbc.anchor);
    assertEquals(GridBagConstraints.BOTH, gbc.fill);

    UiUtils.editGridBagConstraints(gbc, 17, 18, 19.0, 20.0, GridBagConstraints.WEST);
    assertEquals(17, gbc.gridx);
    assertEquals(18, gbc.gridy);
    assertEquals(3, gbc.gridwidth);
    assertEquals(4, gbc.gridheight);
    assertEquals(19.0, gbc.weightx);
    assertEquals(20.0, gbc.weighty);
    assertEquals(GridBagConstraints.WEST, gbc.anchor);
    assertEquals(GridBagConstraints.BOTH, gbc.fill);

}

From source file:net.java.sip.communicator.gui.AuthenticationSplash.java

/**
 *
 * We use dynamic layout managers, so that layout is dynamic and will
 * adapt properly to user-customized fonts and localized text. The
 * GridBagLayout makes it easy to line up components of varying
 * sizes along invisible vertical and horizontal grid lines. It
 * is important to sketch the layout of the interface and decide
 * on the grid before writing the layout code.
 *
 * Here we actually use/*from w w  w. j av  a2s .c o m*/
 * our own subclass of GridBagLayout called StringGridBagLayout,
 * which allows us to use strings to specify constraints, rather
 * than having to create GridBagConstraints objects manually.
 *
 *
 * We use the JLabel.setLabelFor() method to connect
 * labels to what they are labeling. This allows mnemonics to work
 * and assistive to technologies used by persons with disabilities
 * to provide much more useful information to the user.
 */

private void initComponents(final Frame parent) {
    Container contents = getContentPane();
    contents.setLayout(new BorderLayout());

    String title = Utils.getProperty("net.java.sip.communicator.gui.AUTH_WIN_TITLE");

    if (title == null)
        title = "Login Manager";

    setTitle(title);
    setResizable(false);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            dialogDone(CMD_CANCEL, parent);
        }
    });

    // Accessibility -- all frames, dialogs, and applets should
    // have a description
    getAccessibleContext().setAccessibleDescription("Authentication Splash");

    String authPromptLabelValue = Utils.getProperty("net.java.sip.communicator.gui.AUTHENTICATION_PROMPT");

    if (authPromptLabelValue == null)
        authPromptLabelValue = "Please register to the service or enter your credentials to log in:";

    JLabel splashLabel = new JLabel(authPromptLabelValue);
    splashLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    splashLabel.setHorizontalAlignment(SwingConstants.CENTER);
    splashLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    contents.add(splashLabel, BorderLayout.NORTH);

    JPanel centerPane = new JPanel();
    centerPane.setLayout(new GridBagLayout());

    userNameTextField = new JTextField(); // needed below

    // user name label
    JLabel userNameLabel = new JLabel();
    userNameLabel.setDisplayedMnemonic('U');
    // setLabelFor() allows the mnemonic to work
    userNameLabel.setLabelFor(userNameTextField);

    String userNameLabelValue = Utils.getProperty("net.java.sip.communicator.gui.USER_NAME_LABEL");

    if (userNameLabelValue == null)
        userNameLabelValue = "Username";

    int gridy = 0;

    userNameLabel.setText(userNameLabelValue);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = gridy;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(12, 12, 0, 0);
    centerPane.add(userNameLabel, c);

    // user name text
    c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = gridy++;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.insets = new Insets(12, 7, 0, 11);
    centerPane.add(userNameTextField, c);

    passwordTextField = new JPasswordField(); //needed below

    // password label
    JLabel passwordLabel = new JLabel();
    passwordLabel.setDisplayedMnemonic('P');
    passwordLabel.setLabelFor(passwordTextField);
    String pLabelStr = PropertiesDepot.getProperty("net.java.sip.communicator.gui.PASSWORD_LABEL");

    if (pLabelStr == null)
        pLabelStr = "Password";

    passwordLabel.setText(pLabelStr);
    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = gridy;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(11, 12, 0, 0);

    centerPane.add(passwordLabel, c);

    // password text
    passwordTextField.setEchoChar('\u2022');
    c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = gridy++;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.insets = new Insets(11, 7, 0, 11);
    centerPane.add(passwordTextField, c);

    //Set a relevant realm value
    //Bug report by Steven Lass (sltemp at comcast.net)
    //JLabel realmValueLabel = new JLabel("SipPhone.com"); // needed below

    // realm label

    JLabel realmLabel = new JLabel();
    realmLabel.setDisplayedMnemonic('R');
    realmLabel.setLabelFor(realmValueLabel);
    realmLabel.setText("Realm");
    realmValueLabel = new JLabel();

    // Buttons along bottom of window
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, 0));
    loginButton = new JButton();
    loginButton.setText("Login");
    loginButton.setActionCommand(CMD_LOGIN);
    loginButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dialogDone(event, parent);
        }
    });
    buttonPanel.add(loginButton);

    // space
    buttonPanel.add(Box.createRigidArea(new Dimension(5, 0)));

    registerButton = new JButton();
    registerButton.setMnemonic('G');
    registerButton.setText("Register");
    registerButton.setActionCommand(CMD_REGISTER);
    registerButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dialogDone(event, parent);
        }
    });
    buttonPanel.add(registerButton);

    buttonPanel.add(Box.createRigidArea(new Dimension(5, 0)));

    cancelButton = new JButton();
    cancelButton.setText("Cancel");
    cancelButton.setActionCommand(CMD_CANCEL);
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dialogDone(event, parent);
        }
    });
    buttonPanel.add(cancelButton);

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    c.insets = new Insets(11, 12, 11, 11);

    centerPane.add(buttonPanel, c);

    contents.add(centerPane, BorderLayout.CENTER);
    getRootPane().setDefaultButton(loginButton);
    equalizeButtonSizes();

    setFocusTraversalPolicy(new FocusTraversalPol());

}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryPublishDialog.java

protected JPanel createHeaderPanel() {
    final JPanel publishHeaderPanel = new JPanel(new GridBagLayout());

    final GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;//w w  w .j ava  2  s.c om
    c.gridy = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(5, 5, 5, 5);
    publishHeaderPanel.add(new JLabel(Messages.getInstance().getString("RepositoryPublishDialog.ReportName")),
            c);

    c.gridy = 1;
    c.insets = new Insets(2, 5, 0, 5);
    publishHeaderPanel.add(getFileNameTextField(), c);

    c.gridy = 2;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(5, 5, 5, 5);
    publishHeaderPanel.add(new JLabel(Messages.getInstance().getString("RepositoryPublishDialog.ReportTitle")),
            c);

    c.gridy = 3;
    c.insets = new Insets(2, 5, 0, 5);
    publishHeaderPanel.add(titleTextField, c);

    c.gridy = 4;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(5, 5, 5, 5);
    publishHeaderPanel
            .add(new JLabel(Messages.getInstance().getString("RepositoryPublishDialog.ReportDescription")), c);

    c.gridy = 5;
    c.insets = new Insets(2, 5, 0, 5);
    publishHeaderPanel.add(desciptionTextField, c);

    c.gridy = 6;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(2, 5, 0, 5);
    publishHeaderPanel.add(new JLabel(Messages.getInstance().getString("RepositoryPublishDialog.Location")), c);

    c.insets = new Insets(0, 0, 0, 0);
    c.gridx = 0;
    c.gridy = 7;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    publishHeaderPanel.add(createLocationFieldPanel(), c);
    return publishHeaderPanel;
}