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:us.paulevans.basicxslt.TransformParametersFrame.java

/**
 * Rebuilds the parameters panel/* w  ww  .jav a 2 s. c o  m*/
 *
 */
private void rebuildParametersPanel() {

    int loop, row, size;
    JTextField paramNameTf, paramValueTf, paramNamespaceURITf;
    JCheckBox removeCb;
    String paramNames[];
    ParameterTextFieldGroup paramTfGroup;

    row = 0;
    parametersPanel.removeAll();
    GUIUtils.add(parametersPanel, new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_NAME_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row, 0, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    GUIUtils.add(parametersPanel,
            new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_VALUE_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row, 1, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    GUIUtils.add(parametersPanel,
            new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_NAMESPACE_URI_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row, 2, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    GUIUtils.add(parametersPanel,
            new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_REMOVE_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row++, 3, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    paramNames = parameters.getParameterNames();
    size = parameterTextFieldGroups.size();
    for (loop = 0; loop < size; loop++) {
        paramTfGroup = (ParameterTextFieldGroup) parameterTextFieldGroups.get(loop);
        GUIUtils.add(parametersPanel, paramNameTf = paramTfGroup.getParamNameTf(), parametersPanelLayout,
                parametersPanelConstraints, row, 0, 1, 1, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, GUIUtils.SMALL_INSETS);
        GUIUtils.add(parametersPanel, paramValueTf = paramTfGroup.getParamValueTf(), parametersPanelLayout,
                parametersPanelConstraints, row, 1, 1, 1, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, GUIUtils.SMALL_INSETS);
        GUIUtils.add(parametersPanel, paramNamespaceURITf = paramTfGroup.getParamNamespaceURITf(),
                parametersPanelLayout, parametersPanelConstraints, row, 2, 1, 1, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, GUIUtils.SMALL_INSETS);
        GUIUtils.add(parametersPanel, removeCb = paramTfGroup.getRemoveCb(), parametersPanelLayout,
                parametersPanelConstraints, row++, 3, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE,
                GUIUtils.SMALL_INSETS);
        removeCb.addActionListener(this);
        if (loop < paramNames.length) {
            paramNameTf.setText(TransformParameters.getParameterName(paramNames[loop]));
            paramValueTf.setText(parameters.getParameter(paramNames[loop]).toString());
            paramNamespaceURITf.setText(TransformParameters.getNamespaceURI(paramNames[loop]));
        }
    }
}

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

private void setupTable() {
    GridBagConstraints c;//  w ww  .  j a v a 2s  .c  o m
    _table = new JTable() {
        private static final long serialVersionUID = -4266029708016964901L;

        public void paint(java.awt.Graphics g) {
            super.paint(g);

            try {
                if (tablePainted) {
                    return;
                }
                tablePainted = true;

                GUIUtils.adjustColumnWidth(_model, 2, 620, 10, this);
                GUIUtils.adjustColumnWidth(_model, 3, 150, 10, this);
            } catch (Exception e) {
                tablePainted = false;
            }

        };
    };

    _table.setPreferredScrollableViewportSize(new Dimension(600, 300));
    _table.setRowSelectionAllowed(false);
    _table.setModel(_model);
    _table.getColumnModel().getColumn(0).setHeaderValue(""); //checkbox
    _table.getColumnModel().getColumn(1).setHeaderValue(""); //icon
    _table.getColumnModel().getColumn(2).setHeaderValue(I18n.tr("File"));
    _table.getColumnModel().getColumn(3).setHeaderValue(I18n.tr("Type"));
    _table.getColumnModel().getColumn(4).setHeaderValue(I18n.tr("Extension"));
    _table.getColumnModel().getColumn(5).setHeaderValue(I18n.tr("Size"));

    _table.getColumnModel().getColumn(0).setPreferredWidth(30);//checkbox
    _table.getColumnModel().getColumn(1).setPreferredWidth(30);//icon
    _table.getColumnModel().getColumn(2).setPreferredWidth(620);
    _table.getColumnModel().getColumn(3).setPreferredWidth(150);
    _table.getColumnModel().getColumn(4).setPreferredWidth(60);
    _table.getColumnModel().getColumn(5).setPreferredWidth(60);

    _scrollPane = new JScrollPane(_table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    _table.setFillsViewportHeight(true);
    _table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    c = new GridBagConstraints();
    c.insets = new Insets(5, 5, 5, 5);
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    panel.add(_scrollPane, c);
}

From source file:cool.pandora.modeller.ui.jpanel.base.NewBagInPlaceFrame.java

/**
 * layoutProfileSelectionContent./*from w  w w .  ja  va 2  s .  c  om*/
 *
 * @param contentPane JPanel
 * @param row         int
 */
private void layoutProfileSelectionContent(final JPanel contentPane, final int row) {
    // content
    // profile selection
    final JLabel bagProfileLabel = new JLabel(bagView.getPropertyMessage("Select Profile:"));
    bagProfileLabel.setToolTipText(bagView.getPropertyMessage("bag.projectlist.help"));

    profileList = new JComboBox<>(bagView.getProfileStore().getProfileNames());
    profileList.setName(bagView.getPropertyMessage("bag.label.projectlist"));
    profileList.setSelectedItem(bagView.getPropertyMessage("bag.project.noproject"));
    profileList.setToolTipText(bagView.getPropertyMessage("bag.projectlist.help"));

    GridBagConstraints glbc = new GridBagConstraints();

    final JLabel spacerLabel = new JLabel();
    glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 5, 50, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.WEST);
    contentPane.add(bagProfileLabel, glbc);
    glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 40, 50, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.CENTER);
    contentPane.add(profileList, glbc);
    glbc = LayoutUtil.buildGridBagConstraints(2, row, 1, 1, 40, 50, GridBagConstraints.NONE,
            GridBagConstraints.EAST);
    contentPane.add(spacerLabel, glbc);
}

From source file:net.sf.taverna.t2.activities.wsdlsir.views.WSDLActivityConfigurationView.java

private void initComponents() {

    this.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);

    int gridy = 0;

    // title panel
    JPanel titlePanel = new JPanel(new BorderLayout());
    titlePanel.setBackground(Color.WHITE);
    JLabel titleLabel = new JLabel("Security configuration");
    titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 13.5f));
    titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10));
    DialogTextArea titleMessage = new DialogTextArea("Select a security profile for the service");
    titleMessage.setMargin(new Insets(5, 20, 10, 10));
    titleMessage.setFont(titleMessage.getFont().deriveFont(11f));
    titleMessage.setEditable(false);/*from w  ww  .j  av a  2  s . c o m*/
    titleMessage.setFocusable(false);
    titlePanel.setBorder(new EmptyBorder(10, 10, 0, 10));
    titlePanel.add(titleLabel, BorderLayout.NORTH);
    titlePanel.add(titleMessage, BorderLayout.CENTER);
    addDivider(titlePanel, SwingConstants.BOTTOM, true);

    // Main panel
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new GridBagLayout());
    mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10));

    //Create the radio buttons
    noSecurityRadioButton = new JRadioButton("None");
    noSecurityRadioButton.addItemListener(this);

    wsSecurityAuthNRadioButton = new JRadioButton("WS-Security username and password authentication");
    wsSecurityAuthNRadioButton.addItemListener(this);

    httpSecurityAuthNRadioButton = new JRadioButton("HTTP username and password authentication");
    httpSecurityAuthNRadioButton.addItemListener(this);

    SAMLSecurityAuthNRadioButton = new JRadioButton("SAML WEB SSO profile authentication");
    SAMLSecurityAuthNRadioButton.addItemListener(this);

    //Group the radio buttons
    buttonGroup = new ButtonGroup();
    buttonGroup.add(noSecurityRadioButton);
    buttonGroup.add(wsSecurityAuthNRadioButton);
    buttonGroup.add(httpSecurityAuthNRadioButton);
    buttonGroup.add(SAMLSecurityAuthNRadioButton);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;

    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 10, 0, 0);
    mainPanel.add(noSecurityRadioButton, gbc);

    noSecurityLabel = new JLabel("Service requires no security");
    noSecurityLabel.setFont(noSecurityLabel.getFont().deriveFont(11f));
    //      addDivider(noSecurityLabel, SwingConstants.BOTTOM, false);
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(0, 40, 10, 10);
    mainPanel.add(noSecurityLabel, gbc);

    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 10, 0, 0);
    mainPanel.add(httpSecurityAuthNRadioButton, gbc);

    ActionListener usernamePasswordListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            // Get Credential Manager UI to get the username and password for the service
            CredentialManagerUI credManagerUI = CredentialManagerUI.getInstance();
            if (credManagerUI != null)
                credManagerUI.newPasswordForService(oldBean.getWsdl());
        }
    };

    httpSecurityAuthNLabel = new JLabel(
            "Service requires HTTP username and password in order to authenticate the user");
    httpSecurityAuthNLabel.setFont(httpSecurityAuthNLabel.getFont().deriveFont(11f));
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(0, 40, 10, 10);
    mainPanel.add(httpSecurityAuthNLabel, gbc);

    // Set username and password button;
    setHttpUsernamePasswordButton = new JButton("Set username and password");
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.insets = new Insets(0, 40, 10, 10);
    gbc.weightx = 1.0;
    gbc.weighty = 1.0; // add any vertical space to this component
    mainPanel.add(setHttpUsernamePasswordButton, gbc);
    setHttpUsernamePasswordButton.addActionListener(usernamePasswordListener);

    /////SAML

    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 10, 0, 0);
    mainPanel.add(SAMLSecurityAuthNRadioButton, gbc);

    ActionListener getCookieListener = new ActionListener() {

        /**
         * This listener will use the CallPreparator to obtain the cookies (included shibsession_XXX cookie) and 
         * save it in the Credential Manager (as the password for user "nomatter")
         */
        public void actionPerformed(ActionEvent e) {
            try {
                WSDLParser parser = new WSDLParser(newBean.getWsdl());
                List<String> endpoints = parser.getOperationEndpointLocations(newBean.getOperation());
                for (String endpoint : endpoints) //Actually i am only expecting one endpoint
                {
                    if (debug)
                        System.out
                                .println("Obtaining a SAML cookies to save in credential manager:" + endpoint);

                    Cookie[] cookies = CallPreparator.createCookieForCallToEndpoint(endpoint);

                    // Uncomment for just the shibsession cookie
                    //                  Cookie[] cookiessession = new Cookie[1];
                    //                  for (Cookie cook : cookies)
                    //                     if (cook.getName().contains("shibsession"))
                    //                        cookiessession[0]=cook;
                    //                  cookies=cookiessession;

                    CredentialManager credman = CredentialManager.getInstance();
                    credman.saveUsernameAndPasswordForService(
                            new UsernamePassword("nomatter", serializetoString(cookies)), new URI(endpoint));
                }
            } catch (WSDLException ex) {
                System.err.println(
                        "Problem getting or saving SAML cookie: " + newBean.getWsdl() + ". " + ex.getMessage());
                ex.printStackTrace();
            } catch (ParserConfigurationException ex) {
                System.err.println(
                        "Problem getting or saving SAML cookie: " + newBean.getWsdl() + ". " + ex.getMessage());
                ex.printStackTrace();
            } catch (Exception ex) {
                System.err.println(
                        "Problem getting or saving SAML cookie: " + newBean.getWsdl() + ". " + ex.getMessage());
                ex.printStackTrace();
            }
        }
    };

    SAMLSecurityAuthNLabel = new JLabel("<html>"
            + "Service requires SAML Web SSO profile to be perfomed in order to authenticate the user. "
            + "A cookie will be saved in your Credential Manger. "
            + "In the case that it stops working, please delete the entry in your Credential Manager or re-authenticate"
            + "</html>");
    SAMLSecurityAuthNLabel.setFont(SAMLSecurityAuthNLabel.getFont().deriveFont(11f));
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(3, 40, 10, 10);
    mainPanel.add(SAMLSecurityAuthNLabel, gbc);

    // Set username and password button;
    setSAMLGETCookieButton = new JButton("Authenticate and save Authentication data in Credential Manger");
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.insets = new Insets(0, 40, 10, 10);
    gbc.weightx = 1.0;
    gbc.weighty = 1.0; // add any vertical space to this component
    mainPanel.add(setSAMLGETCookieButton, gbc);
    setSAMLGETCookieButton.addActionListener(getCookieListener);

    //END SAML

    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 10, 0, 0);
    mainPanel.add(wsSecurityAuthNRadioButton, gbc);

    wsSecurityAuthNLabel = new JLabel(
            "Service requires WS-Security username and password in order to authenticate the user");
    wsSecurityAuthNLabel.setFont(wsSecurityAuthNLabel.getFont().deriveFont(11f));
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(0, 40, 0, 0);
    mainPanel.add(wsSecurityAuthNLabel, gbc);

    // Password type list
    passwordTypeComboBox = new JComboBox(passwordTypes);
    passwordTypeComboBox.setRenderer(new ComboBoxTooltipRenderer());
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(10, 40, 0, 0);
    mainPanel.add(passwordTypeComboBox, gbc);

    // 'Add timestamp' checkbox
    addTimestampCheckBox = new JCheckBox("Add a timestamp to SOAP message");
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 40, 10, 10);
    mainPanel.add(addTimestampCheckBox, gbc);

    // Set username and password button;
    setWsdlUsernamePasswordButton = new JButton("Set username and password");
    gbc.gridx = 0;
    gbc.gridy = gridy++;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.insets = new Insets(0, 40, 10, 10);
    gbc.weightx = 1.0;
    gbc.weighty = 1.0; // add any vertical space to this component
    mainPanel.add(setWsdlUsernamePasswordButton, gbc);
    setWsdlUsernamePasswordButton.addActionListener(usernamePasswordListener);

    addDivider(mainPanel, SwingConstants.BOTTOM, true);

    // OK/Cancel button panel
    JPanel okCancelPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    JButton okButton = new JButton("OK");
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            cancelPressed();
        }
    });
    okCancelPanel.add(cancelButton);
    okCancelPanel.add(okButton);

    // Enable/disable controls based on what is the current security profiles
    String securityProfile = oldBean.getSecurityProfile();
    if (securityProfile == null) {
        noSecurityRadioButton.setSelected(true);
    } else {
        if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)
                || securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)
                || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)
                || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
            wsSecurityAuthNRadioButton.setSelected(true);
        }
        if (securityProfile.equals(SecurityProfiles.HTTP_BASIC_AUTHN)
                || securityProfile.equals(SecurityProfiles.HTTP_DIGEST_AUTHN)) {
            httpSecurityAuthNRadioButton.setSelected(true);
        }
        if (securityProfile.equals(SecurityProfiles.SAMLWEBSSOAUTH)) {
            SAMLSecurityAuthNRadioButton.setSelected(true);
        }
        if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)
                || securityProfile
                        .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
            passwordTypeComboBox.setSelectedItem(PLAINTEXT_PASSWORD);
        } else if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)
                || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
            passwordTypeComboBox.setSelectedItem(DIGEST_PASSWORD);
        }
        if (securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)
                || securityProfile
                        .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
            addTimestampCheckBox.setSelected(true);
        } else {
            addTimestampCheckBox.setSelected(false);
        }
    }

    // Put everything together
    JPanel layoutPanel = new JPanel(new BorderLayout());
    layoutPanel.add(titlePanel, BorderLayout.NORTH);
    layoutPanel.add(mainPanel, BorderLayout.CENTER);
    layoutPanel.add(okCancelPanel, BorderLayout.SOUTH);
    layoutPanel.setPreferredSize(new Dimension(550, 490));

    this.getContentPane().add(layoutPanel);
    this.pack();
}

From source file:ViewDB.java

 /**
 * Constructs the data panel./*from  ww  w .  java  2s .  c o m*/
 * @param rs the result set whose contents this panel displays
 */
public DataPanel(RowSet rs) throws SQLException
{
   fields = new ArrayList<JTextField>();
   setLayout(new GridBagLayout());
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.gridwidth = 1;
   gbc.gridheight = 1;

   ResultSetMetaData rsmd = rs.getMetaData();
   for (int i = 1; i <= rsmd.getColumnCount(); i++)
   {
      gbc.gridy = i - 1;

      String columnName = rsmd.getColumnLabel(i);
      gbc.gridx = 0;
      gbc.anchor = GridBagConstraints.EAST;
      add(new JLabel(columnName), gbc);

      int columnWidth = rsmd.getColumnDisplaySize(i);
      JTextField tb = new JTextField(columnWidth);
      if (!rsmd.getColumnClassName(i).equals("java.lang.String"))
         tb.setEditable(false);
               
      fields.add(tb);

      gbc.gridx = 1;
      gbc.anchor = GridBagConstraints.WEST;
      add(tb, gbc);
   }
}

From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java

private void initFrame() {
    frame = new JFrame();
    frame.setTitle("libautocaptcha vodafone.it tool");
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    JPanel setupPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) setupPanel.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Setup", null, setupPanel, null);

    JPanel setupFormPanel = new JPanel();
    setupPanel.add(setupFormPanel);//www  .j ava 2s .  co m
    GridBagLayout gbl_setupFormPanel = new GridBagLayout();
    gbl_setupFormPanel.columnWidths = new int[] { 150, 250 };
    gbl_setupFormPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_setupFormPanel.columnWeights = new double[] { 0.0, 1.0 };
    gbl_setupFormPanel.rowWeights = new double[] { 0.0, 0.0, 0.0 };
    setupFormPanel.setLayout(gbl_setupFormPanel);

    JLabel usernameLabel = new JLabel("Username");
    GridBagConstraints gbc_usernameLabel = new GridBagConstraints();
    gbc_usernameLabel.anchor = GridBagConstraints.WEST;
    gbc_usernameLabel.fill = GridBagConstraints.VERTICAL;
    gbc_usernameLabel.insets = new Insets(0, 0, 5, 5);
    gbc_usernameLabel.gridx = 0;
    gbc_usernameLabel.gridy = 0;
    setupFormPanel.add(usernameLabel, gbc_usernameLabel);
    usernameField = new JTextField();
    GridBagConstraints gbc_usernameField = new GridBagConstraints();
    gbc_usernameField.fill = GridBagConstraints.BOTH;
    gbc_usernameField.insets = new Insets(0, 0, 5, 0);
    gbc_usernameField.gridx = 1;
    gbc_usernameField.gridy = 0;
    setupFormPanel.add(usernameField, gbc_usernameField);
    usernameField.setColumns(10);

    JLabel passwordLabel = new JLabel("Password");
    GridBagConstraints gbc_passwordLabel = new GridBagConstraints();
    gbc_passwordLabel.anchor = GridBagConstraints.WEST;
    gbc_passwordLabel.fill = GridBagConstraints.VERTICAL;
    gbc_passwordLabel.insets = new Insets(0, 0, 5, 5);
    gbc_passwordLabel.gridx = 0;
    gbc_passwordLabel.gridy = 1;
    setupFormPanel.add(passwordLabel, gbc_passwordLabel);
    passwordField = new JPasswordField();
    GridBagConstraints gbc_passwordField = new GridBagConstraints();
    gbc_passwordField.fill = GridBagConstraints.BOTH;
    gbc_passwordField.insets = new Insets(0, 0, 5, 0);
    gbc_passwordField.gridx = 1;
    gbc_passwordField.gridy = 1;
    setupFormPanel.add(passwordField, gbc_passwordField);
    passwordField.setColumns(10);

    JLabel receiverLabel = new JLabel("Mobile number");
    GridBagConstraints gbc_receiverLabel = new GridBagConstraints();
    gbc_receiverLabel.fill = GridBagConstraints.VERTICAL;
    gbc_receiverLabel.anchor = GridBagConstraints.WEST;
    gbc_receiverLabel.insets = new Insets(0, 0, 5, 5);
    gbc_receiverLabel.gridx = 0;
    gbc_receiverLabel.gridy = 2;
    setupFormPanel.add(receiverLabel, gbc_receiverLabel);

    receiverField = new JTextField();
    GridBagConstraints gbc_receiverField = new GridBagConstraints();
    gbc_receiverField.insets = new Insets(0, 0, 5, 0);
    gbc_receiverField.fill = GridBagConstraints.BOTH;
    gbc_receiverField.gridx = 1;
    gbc_receiverField.gridy = 2;
    setupFormPanel.add(receiverField, gbc_receiverField);
    receiverField.setColumns(10);

    JPanel backgroundPanel = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) backgroundPanel.getLayout();
    flowLayout_1.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Background", null, backgroundPanel, null);

    JPanel backgroundFormPanel = new JPanel();
    backgroundPanel.add(backgroundFormPanel);
    GridBagLayout gbl_backgroundFormPanel = new GridBagLayout();
    gbl_backgroundFormPanel.columnWidths = new int[] { 150, 50, 100, 0 };
    gbl_backgroundFormPanel.rowHeights = new int[] { 0, 25, 0 };
    gbl_backgroundFormPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_backgroundFormPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    backgroundFormPanel.setLayout(gbl_backgroundFormPanel);

    JLabel numberLabel = new JLabel("Number of CAPTCHAs");
    GridBagConstraints gbc_numberLabel = new GridBagConstraints();
    gbc_numberLabel.anchor = GridBagConstraints.WEST;
    gbc_numberLabel.insets = new Insets(0, 0, 5, 5);
    gbc_numberLabel.gridx = 0;
    gbc_numberLabel.gridy = 0;
    backgroundFormPanel.add(numberLabel, gbc_numberLabel);

    numberField = new JTextField();
    numberField.setText("5");
    GridBagConstraints gbc_numberField = new GridBagConstraints();
    gbc_numberField.anchor = GridBagConstraints.WEST;
    gbc_numberField.insets = new Insets(0, 0, 5, 5);
    gbc_numberField.gridx = 1;
    gbc_numberField.gridy = 0;
    backgroundFormPanel.add(numberField, gbc_numberField);
    numberField.setColumns(3);

    JButton numberButton = new JButton("Download");
    numberButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int counter = 0;

            do {
                BufferedImage captcha = downloadCAPTCHA();
                if (captcha != null) {
                    try {
                        int number = new File(tempFolder.getAbsolutePath()).listFiles().length;
                        File file = new File(tempFolder.getAbsolutePath() + "/background_" + number + ".png");
                        ImageIO.write(captcha, "png", file);
                        Thread.sleep(2500);
                    } catch (Exception x) {
                        x.printStackTrace();
                    }
                }
            } while (++counter < Integer.valueOf(numberField.getText()));

            Image background = loadBackground();
            if (background != null) {
                backgroundImage.setIcon(new ImageIcon(background));
            }
        }
    });
    GridBagConstraints gbc_numberButton = new GridBagConstraints();
    gbc_numberButton.anchor = GridBagConstraints.NORTHWEST;
    gbc_numberButton.insets = new Insets(0, 0, 5, 0);
    gbc_numberButton.gridx = 2;
    gbc_numberButton.gridy = 0;
    backgroundFormPanel.add(numberButton, gbc_numberButton);

    JLabel backgroundLabel = new JLabel("Current background");
    GridBagConstraints gbc_backgroundLabel = new GridBagConstraints();
    gbc_backgroundLabel.anchor = GridBagConstraints.WEST;
    gbc_backgroundLabel.insets = new Insets(0, 0, 0, 5);
    gbc_backgroundLabel.gridx = 0;
    gbc_backgroundLabel.gridy = 1;
    backgroundFormPanel.add(backgroundLabel, gbc_backgroundLabel);

    backgroundImage = new JLabel("");
    GridBagConstraints gbc_backgroundImage = new GridBagConstraints();
    gbc_backgroundImage.anchor = GridBagConstraints.WEST;
    gbc_backgroundImage.gridwidth = 2;
    gbc_backgroundImage.insets = new Insets(0, 0, 0, 5);
    gbc_backgroundImage.gridx = 1;
    gbc_backgroundImage.gridy = 1;
    backgroundFormPanel.add(backgroundImage, gbc_backgroundImage);

    JPanel trainingPanel = new JPanel();
    tabbedPane.addTab("Training", null, trainingPanel, null);
    GridBagLayout gbl_trainingPanel = new GridBagLayout();
    gbl_trainingPanel.columnWidths = new int[] { 437, 0 };
    gbl_trainingPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_trainingPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_trainingPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    trainingPanel.setLayout(gbl_trainingPanel);

    trainingLoadPanel = new JPanel();
    GridBagConstraints gbc_trainingLoadPanel = new GridBagConstraints();
    gbc_trainingLoadPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_trainingLoadPanel.insets = new Insets(0, 0, 5, 0);
    gbc_trainingLoadPanel.gridx = 0;
    gbc_trainingLoadPanel.gridy = 0;
    trainingPanel.add(trainingLoadPanel, gbc_trainingLoadPanel);
    trainingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JButton trainingLoadButton = new JButton("Download");
    trainingLoadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            trainingCaptcha = downloadCAPTCHA();
            if (trainingCaptcha != null) {
                trainingCaptchaImage.setIcon(new ImageIcon(trainingCaptcha));
                List<Image> glyphs = loadGlyphs(trainingCaptcha);
                for (int g = 0; g < 5; ++g) {
                    trainingGlyphImage[g].setIcon(null);
                    trainingGlyphField[g].setText("");
                }
                for (int g = 0; g < glyphs.size() && g < 5; ++g) {
                    trainingGlyph[g] = glyphs.get(g);
                    trainingGlyphImage[g].setIcon(new ImageIcon(trainingGlyph[g]));
                }
                trainingLoadPanel.invalidate();
                trainingSavePanel.invalidate();
            }
        }
    });
    trainingLoadPanel.add(trainingLoadButton);

    trainingCaptchaImage = new JLabel("");
    trainingLoadPanel.add(trainingCaptchaImage);

    trainingSavePanel = new JPanel();
    GridBagConstraints gbc_trainingSavePanel = new GridBagConstraints();
    gbc_trainingSavePanel.insets = new Insets(0, 5, 0, 0);
    gbc_trainingSavePanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_trainingSavePanel.gridx = 0;
    gbc_trainingSavePanel.gridy = 1;
    trainingPanel.add(trainingSavePanel, gbc_trainingSavePanel);
    GridBagLayout gbl_trainingSavePanel = new GridBagLayout();
    gbl_trainingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 };
    gbl_trainingSavePanel.rowHeights = new int[] { 25, 0, 0 };
    gbl_trainingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_trainingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    trainingSavePanel.setLayout(gbl_trainingSavePanel);

    trainingGlyph = new Image[5];
    trainingGlyphImage = new JLabel[5];
    trainingGlyphField = new JTextField[5];

    trainingGlyphImage[0] = new JLabel("");
    GridBagConstraints gbc_glyphImage0 = new GridBagConstraints();
    gbc_glyphImage0.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage0.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage0.gridx = 0;
    gbc_glyphImage0.gridy = 0;
    trainingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[0], gbc_glyphImage0);

    trainingGlyphImage[1] = new JLabel("");
    GridBagConstraints gbc_glyphImage1 = new GridBagConstraints();
    gbc_glyphImage1.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage1.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage1.gridx = 1;
    gbc_glyphImage1.gridy = 0;
    trainingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[1], gbc_glyphImage1);

    trainingGlyphImage[2] = new JLabel("");
    GridBagConstraints gbc_glyphImage2 = new GridBagConstraints();
    gbc_glyphImage2.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage2.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage2.gridx = 2;
    gbc_glyphImage2.gridy = 0;
    trainingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[2], gbc_glyphImage2);

    trainingGlyphImage[3] = new JLabel("");
    GridBagConstraints gbc_glyphImage3 = new GridBagConstraints();
    gbc_glyphImage3.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage3.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage3.gridx = 3;
    gbc_glyphImage3.gridy = 0;
    trainingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[3], gbc_glyphImage3);

    trainingGlyphImage[4] = new JLabel("");
    GridBagConstraints gbc_glyphImage4 = new GridBagConstraints();
    gbc_glyphImage4.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage4.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage4.gridx = 4;
    gbc_glyphImage4.gridy = 0;
    trainingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[4], gbc_glyphImage4);

    JButton trainingSaveButton = new JButton("Train");
    trainingSaveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int g = 0; g < 5; ++g) {
                String s = trainingGlyphField[g].getText();
                if (s.length() == 1) {
                    char c = Character.toUpperCase(s.charAt(0));
                    net.sourceforge.javaocr.Image glyph = convertImage(trainingGlyph[g]);
                    grayFilter.process(glyph);
                    ThresholdFilter thresholdFilter = new ThresholdFilter(0, FG, BG);
                    thresholdFilter.process(glyph);
                    train(glyph, c);
                }
                trainingGlyphField[g].setText("");
            }

            for (Map.Entry<Character, Cluster> m : clusters.entrySet()) {
                System.out.println("****************************************");
                System.out.print(" character:  ");
                //          int samples = ((EuclidianDistanceCluster) m.getValue()).getAmountSamples();
                int samples = ((SigmaWeightedEuclidianDistanceCluster) m.getValue()).getAmountSamples();
                for (int s = 0; s < samples; ++s)
                    System.out.print(m.getKey());
                System.out.println();
                double[] c = m.getValue().center();
                for (int i = 0; i < c.length; ++i)
                    System.out.println(" centroid[" + i + "]: " + c[i]);
            }

            System.out.println("****************************************");
            System.out.println("TOTAL CLUSTERS: " + clusters.size());
        }
    });
    GridBagConstraints gbc_trainingSaveButton = new GridBagConstraints();
    gbc_trainingSaveButton.gridheight = 2;
    gbc_trainingSaveButton.insets = new Insets(0, 0, 5, 0);
    gbc_trainingSaveButton.gridx = 5;
    gbc_trainingSaveButton.gridy = 0;
    trainingSavePanel.add(trainingSaveButton, gbc_trainingSaveButton);

    trainingGlyphField[0] = new JTextField();
    GridBagConstraints gbc_glyphField0 = new GridBagConstraints();
    gbc_glyphField0.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField0.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField0.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField0.gridx = 0;
    gbc_glyphField0.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[0], gbc_glyphField0);
    trainingGlyphField[0].setColumns(2);

    trainingGlyphField[1] = new JTextField();
    GridBagConstraints gbc_glyphField1 = new GridBagConstraints();
    gbc_glyphField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField1.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField1.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField1.gridx = 1;
    gbc_glyphField1.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[1], gbc_glyphField1);
    trainingGlyphField[1].setColumns(2);

    trainingGlyphField[2] = new JTextField();
    GridBagConstraints gbc_glyphField2 = new GridBagConstraints();
    gbc_glyphField2.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField2.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField2.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField2.gridx = 2;
    gbc_glyphField2.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[2], gbc_glyphField2);
    trainingGlyphField[2].setColumns(2);

    trainingGlyphField[3] = new JTextField();
    GridBagConstraints gbc_glyphField3 = new GridBagConstraints();
    gbc_glyphField3.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField3.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField3.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField3.gridx = 3;
    gbc_glyphField3.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[3], gbc_glyphField3);
    trainingGlyphField[3].setColumns(2);

    trainingGlyphField[4] = new JTextField();
    GridBagConstraints gbc_glyphField4 = new GridBagConstraints();
    gbc_glyphField4.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField4.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField4.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField4.gridx = 4;
    gbc_glyphField4.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[4], gbc_glyphField4);
    trainingGlyphField[4].setColumns(2);

    JPanel testingPanel = new JPanel();
    tabbedPane.addTab("Testing", null, testingPanel, null);
    GridBagLayout gbl_testingPanel = new GridBagLayout();
    gbl_testingPanel.columnWidths = new int[] { 437, 0 };
    gbl_testingPanel.rowHeights = new int[] { 0, 0, 0, 0 };
    gbl_testingPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_testingPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
    testingPanel.setLayout(gbl_testingPanel);

    testingLoadPanel = new JPanel();
    GridBagConstraints gbc_testingLoadPanel = new GridBagConstraints();
    gbc_testingLoadPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingLoadPanel.insets = new Insets(0, 0, 5, 0);
    gbc_testingLoadPanel.gridx = 0;
    gbc_testingLoadPanel.gridy = 0;
    testingPanel.add(testingLoadPanel, gbc_testingLoadPanel);
    testingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JButton testingLoadButton = new JButton("Download");
    testingLoadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            testingCaptcha = downloadCAPTCHA();
            if (testingCaptcha != null) {
                testingCaptchaImage.setIcon(new ImageIcon(testingCaptcha));
                List<Image> glyphs = loadGlyphs(testingCaptcha);
                for (int g = 0; g < 5; ++g) {
                    testingGlyphImage[g].setIcon(null);
                    testingGlyphField[g].setText("");
                }
                for (int g = 0; g < glyphs.size() && g < 5; ++g) {
                    testingGlyph[g] = glyphs.get(g);
                    testingGlyphImage[g].setIcon(new ImageIcon(testingGlyph[g]));
                }
                testingLoadPanel.invalidate();
                testingSavePanel.invalidate();
            }
        }
    });
    testingLoadPanel.add(testingLoadButton);

    testingCaptchaImage = new JLabel("");
    testingLoadPanel.add(testingCaptchaImage);

    testingSavePanel = new JPanel();
    GridBagConstraints gbc_testingSavePanel = new GridBagConstraints();
    gbc_testingSavePanel.insets = new Insets(0, 5, 5, 0);
    gbc_testingSavePanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingSavePanel.gridx = 0;
    gbc_testingSavePanel.gridy = 1;
    testingPanel.add(testingSavePanel, gbc_testingSavePanel);
    GridBagLayout gbl_testingSavePanel = new GridBagLayout();
    gbl_testingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 };
    gbl_testingSavePanel.rowHeights = new int[] { 25, 0, 0 };
    gbl_testingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_testingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    testingSavePanel.setLayout(gbl_testingSavePanel);

    testingGlyph = new Image[5];
    testingGlyphImage = new JLabel[5];
    testingGlyphField = new JTextField[5];

    testingGlyphImage[0] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage0 = new GridBagConstraints();
    gbc_testingGlyphImage0.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage0.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage0.gridx = 0;
    gbc_testingGlyphImage0.gridy = 0;
    testingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[0], gbc_testingGlyphImage0);

    testingGlyphImage[1] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage1 = new GridBagConstraints();
    gbc_testingGlyphImage1.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage1.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage1.gridx = 1;
    gbc_testingGlyphImage1.gridy = 0;
    testingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[1], gbc_testingGlyphImage1);

    testingGlyphImage[2] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage2 = new GridBagConstraints();
    gbc_testingGlyphImage2.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage2.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage2.gridx = 2;
    gbc_testingGlyphImage2.gridy = 0;
    testingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[2], gbc_testingGlyphImage2);

    testingGlyphImage[3] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage3 = new GridBagConstraints();
    gbc_testingGlyphImage3.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage3.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage3.gridx = 3;
    gbc_testingGlyphImage3.gridy = 0;
    testingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[3], gbc_testingGlyphImage3);

    testingGlyphImage[4] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage4 = new GridBagConstraints();
    gbc_testingGlyphImage4.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage4.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage4.gridx = 4;
    gbc_testingGlyphImage4.gridy = 0;
    testingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[4], gbc_testingGlyphImage4);

    JButton testingSaveButton = new JButton("Save and test");
    testingSaveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String text = "";
            for (int g = 0; g < 5; ++g) {
                String s = testingGlyphField[g].getText();
                if (s.length() == 1)
                    text += s.toUpperCase();
                trainingGlyphField[g].setText("");
            }

            if (text.length() != 5)
                return;

            try {
                File file = new File(tempFolder.getAbsolutePath() + "/captcha_" + text + ".png");
                ImageIO.write(testingCaptcha, "png", file);
            } catch (IOException x) {
                x.printStackTrace();
            }

            testingViewArea.setText(loadStatistics());
        }
    });
    GridBagConstraints gbc_testingSaveButton = new GridBagConstraints();
    gbc_testingSaveButton.gridheight = 2;
    gbc_testingSaveButton.insets = new Insets(0, 0, 5, 0);
    gbc_testingSaveButton.gridx = 5;
    gbc_testingSaveButton.gridy = 0;
    testingSavePanel.add(testingSaveButton, gbc_testingSaveButton);

    testingGlyphField[0] = new JTextField();
    GridBagConstraints gbc_testingGlyphField0 = new GridBagConstraints();
    gbc_testingGlyphField0.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField0.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField0.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField0.gridx = 0;
    gbc_testingGlyphField0.gridy = 1;
    testingSavePanel.add(testingGlyphField[0], gbc_testingGlyphField0);
    testingGlyphField[0].setColumns(2);

    testingGlyphField[1] = new JTextField();
    GridBagConstraints gbc_testingGlyphField1 = new GridBagConstraints();
    gbc_testingGlyphField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField1.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField1.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField1.gridx = 1;
    gbc_testingGlyphField1.gridy = 1;
    testingSavePanel.add(testingGlyphField[1], gbc_testingGlyphField1);
    testingGlyphField[1].setColumns(2);

    testingGlyphField[2] = new JTextField();
    GridBagConstraints gbc_testingGlyphField2 = new GridBagConstraints();
    gbc_testingGlyphField2.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField2.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField2.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField2.gridx = 2;
    gbc_testingGlyphField2.gridy = 1;
    testingSavePanel.add(testingGlyphField[2], gbc_testingGlyphField2);
    testingGlyphField[2].setColumns(2);

    testingGlyphField[3] = new JTextField();
    GridBagConstraints gbc_testingGlyphField3 = new GridBagConstraints();
    gbc_testingGlyphField3.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField3.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField3.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField3.gridx = 3;
    gbc_testingGlyphField3.gridy = 1;
    testingSavePanel.add(testingGlyphField[3], gbc_testingGlyphField3);
    testingGlyphField[3].setColumns(2);

    testingGlyphField[4] = new JTextField();
    GridBagConstraints gbc_testingGlyphField4 = new GridBagConstraints();
    gbc_testingGlyphField4.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField4.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField4.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField4.gridx = 4;
    gbc_testingGlyphField4.gridy = 1;
    testingSavePanel.add(testingGlyphField[4], gbc_testingGlyphField4);

    JPanel testingViewPanel = new JPanel();
    GridBagConstraints gbc_testingViewPanel = new GridBagConstraints();
    gbc_testingViewPanel.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingViewPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingViewPanel.gridx = 0;
    gbc_testingViewPanel.gridy = 2;
    testingPanel.add(testingViewPanel, gbc_testingViewPanel);
    GridBagLayout gbl_testingViewPanel = new GridBagLayout();
    gbl_testingViewPanel.columnWidths = new int[] { 330, 0 };
    gbl_testingViewPanel.rowHeights = new int[] { 75, 0 };
    gbl_testingViewPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_testingViewPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    testingViewPanel.setLayout(gbl_testingViewPanel);

    testingViewArea = new JTextArea();
    testingViewArea.setRows(5);
    testingViewArea.setColumns(30);
    GridBagConstraints gbc_testingViewArea = new GridBagConstraints();
    gbc_testingViewArea.fill = GridBagConstraints.BOTH;
    gbc_testingViewArea.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingViewArea.gridx = 0;
    gbc_testingViewArea.gridy = 0;
    testingViewPanel.add(testingViewArea, gbc_testingViewArea);
    testingGlyphField[4].setColumns(2);

    JPanel outputPanel = new JPanel();
    FlowLayout flowLayout2 = (FlowLayout) outputPanel.getLayout();
    flowLayout2.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Output", null, outputPanel, null);

    JPanel outputFormPanel = new JPanel();
    outputPanel.add(outputFormPanel);
    GridBagLayout gbl_outputFormPanel = new GridBagLayout();
    gbl_outputFormPanel.columnWidths = new int[] { 150, 250 };
    gbl_outputFormPanel.rowHeights = new int[] { 0 };
    gbl_outputFormPanel.columnWeights = new double[] { 0.0, 1.0 };
    gbl_outputFormPanel.rowWeights = new double[] { 0.0 };
    outputFormPanel.setLayout(gbl_outputFormPanel);

    JLabel javaLabel = new JLabel("Output .java file");
    GridBagConstraints gbc_javaLabel = new GridBagConstraints();
    gbc_javaLabel.anchor = GridBagConstraints.WEST;
    gbc_javaLabel.fill = GridBagConstraints.VERTICAL;
    gbc_javaLabel.insets = new Insets(0, 0, 5, 5);
    gbc_javaLabel.gridx = 0;
    gbc_javaLabel.gridy = 0;
    outputFormPanel.add(javaLabel, gbc_javaLabel);

    javaField = new JTextField();
    javaField.addFocusListener(new FocusListener() {
        public void focusLost(FocusEvent e) {
            javaField.removeFocusListener(this);
        }

        public void focusGained(FocusEvent e) {
            JFileChooser chooser = new JFileChooser(outFolderName);
            chooser.setSelectedFile(new File(outFileName));
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            if (chooser.showDialog(frame, "Save .java file") == JFileChooser.APPROVE_OPTION) {
                javaField.setText(chooser.getSelectedFile().getAbsolutePath());

                try {
                    PrintWriter output = new PrintWriter(
                            new FileWriter(chooser.getSelectedFile().getAbsolutePath()));
                    output.println("package com.googlecode.libautocaptcha.decoder.data;");
                    output.println("import net.sourceforge.javaocr.plugin.cluster.Cluster;");
                    output.println("import net.sourceforge.javaocr.plugin.cluster.MahalanobisDistanceCluster;");
                    output.println("public class VodafoneItalyData {");

                    output.println("  public static final int[] " + BACKGROUND_FIELD + " = ");
                    output.print("    new int[] { ");
                    for (int y = 0; y < HEIGHT; ++y)
                        for (int x = 0; x < WIDTH; ++x)
                            output.print(background.get(x, y) + ", ");
                    output.println("};");

                    output.println("  public static final char[] " + CHARACTERS_FIELD + " = ");
                    output.print("    new char[] { ");
                    for (Character c : clusters.keySet())
                        output.print("'" + c + "', ");
                    output.println("};");

                    output.println("  public static final Cluster[] " + CLUSTERS_FIELD + " = ");
                    output.print("    new MahalanobisDistanceCluster[] { ");
                    for (Cluster c : clusters.values()) {
                        output.print("new MahalanobisDistanceCluster(new double[] { ");
                        double[] mx = ((MahalanobisDistanceCluster) c).getMx();
                        for (double i : mx)
                            output.print(i + ", ");
                        output.print("}, new double[][] { ");
                        double[][] invcov = ((MahalanobisDistanceCluster) c).getInvcov();
                        for (double[] row : invcov) {
                            output.print("new double[] { ");
                            for (double i : row)
                                output.print(i + ", ");
                            output.print("}, ");
                        }
                        output.print("}), ");
                    }
                    output.println("};");

                    output.println("}");
                    output.close();
                } catch (IOException x) {
                    x.printStackTrace();
                }
            }
        }
    });
    GridBagConstraints gbc_javaField = new GridBagConstraints();
    gbc_javaField.fill = GridBagConstraints.BOTH;
    gbc_javaField.insets = new Insets(0, 0, 5, 0);
    gbc_javaField.gridx = 1;
    gbc_javaField.gridy = 0;
    outputFormPanel.add(javaField, gbc_javaField);
    javaField.setColumns(10);

    JPanel statusPanel = new JPanel();
    frame.getContentPane().add(statusPanel, BorderLayout.SOUTH);
    GridBagLayout gbl_statusPanel = new GridBagLayout();
    gbl_statusPanel.columnWidths = new int[] { 150, 0, 0 };
    gbl_statusPanel.rowHeights = new int[] { 14, 0 };
    gbl_statusPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_statusPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    statusPanel.setLayout(gbl_statusPanel);

    statusBar = new JProgressBar();
    GridBagConstraints gbc_statusBar = new GridBagConstraints();
    gbc_statusBar.insets = new Insets(0, 0, 0, 5);
    gbc_statusBar.gridx = 0;
    gbc_statusBar.gridy = 0;
    statusPanel.add(statusBar, gbc_statusBar);

    statusLabel = new JLabel("");
    GridBagConstraints gbc_statusLabel = new GridBagConstraints();
    gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL;
    gbc_statusLabel.gridx = 1;
    gbc_statusLabel.gridy = 0;
    statusPanel.add(statusLabel, gbc_statusLabel);
}

From source file:com.vgi.mafscaling.Rescale.java

private void createControlPanel(JPanel dataPanel) {
    JPanel cntlPanel = new JPanel();
    GridBagConstraints gbl_ctrlPanel = new GridBagConstraints();
    gbl_ctrlPanel.insets = insets3;//ww  w  . j av  a  2  s.c o m
    gbl_ctrlPanel.anchor = GridBagConstraints.PAGE_START;
    gbl_ctrlPanel.fill = GridBagConstraints.HORIZONTAL;
    gbl_ctrlPanel.weightx = 1.0;
    gbl_ctrlPanel.gridx = 0;
    gbl_ctrlPanel.gridy = 0;
    dataPanel.add(cntlPanel, gbl_ctrlPanel);

    GridBagLayout gbl_cntlPanel = new GridBagLayout();
    gbl_cntlPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_cntlPanel.rowHeights = new int[] { 0, 0 };
    gbl_cntlPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
    gbl_cntlPanel.rowWeights = new double[] { 0 };
    cntlPanel.setLayout(gbl_cntlPanel);

    NumberFormat doubleFmt = NumberFormat.getNumberInstance();
    doubleFmt.setGroupingUsed(false);
    doubleFmt.setMaximumIntegerDigits(1);
    doubleFmt.setMinimumIntegerDigits(1);
    doubleFmt.setMaximumFractionDigits(3);
    doubleFmt.setMinimumFractionDigits(1);
    doubleFmt.setRoundingMode(RoundingMode.HALF_UP);

    NumberFormat scaleDoubleFmt = NumberFormat.getNumberInstance();
    scaleDoubleFmt.setGroupingUsed(false);
    scaleDoubleFmt.setMaximumIntegerDigits(1);
    scaleDoubleFmt.setMinimumIntegerDigits(1);
    scaleDoubleFmt.setMaximumFractionDigits(8);
    scaleDoubleFmt.setMinimumFractionDigits(1);
    scaleDoubleFmt.setRoundingMode(RoundingMode.HALF_UP);

    GridBagConstraints gbc_cntlPanelLabel = new GridBagConstraints();
    gbc_cntlPanelLabel.anchor = GridBagConstraints.EAST;
    gbc_cntlPanelLabel.insets = new Insets(2, 3, 2, 1);
    gbc_cntlPanelLabel.gridx = 0;
    gbc_cntlPanelLabel.gridy = 0;

    GridBagConstraints gbc_cntlPanelInput = new GridBagConstraints();
    gbc_cntlPanelInput.anchor = GridBagConstraints.WEST;
    gbc_cntlPanelInput.insets = new Insets(2, 1, 2, 3);
    gbc_cntlPanelInput.gridx = 1;
    gbc_cntlPanelInput.gridy = 0;

    cntlPanel.add(new JLabel("New Max V"), gbc_cntlPanelLabel);

    newMaxVFmtTextBox = new JFormattedTextField(doubleFmt);
    newMaxVFmtTextBox.setColumns(7);
    newMaxVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            Object source = e.getSource();
            if (source == newMaxVFmtTextBox)
                updateNewMafScale();
        }
    });
    cntlPanel.add(newMaxVFmtTextBox, gbc_cntlPanelInput);

    gbc_cntlPanelLabel.gridx += 2;
    cntlPanel.add(new JLabel("Min V"), gbc_cntlPanelLabel);

    minVFmtTextBox = new JFormattedTextField(doubleFmt);
    minVFmtTextBox.setColumns(7);
    minVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            Object source = e.getSource();
            if (source == minVFmtTextBox)
                updateNewMafScale();
        }
    });
    gbc_cntlPanelInput.gridx += 2;
    cntlPanel.add(minVFmtTextBox, gbc_cntlPanelInput);

    gbc_cntlPanelLabel.gridx += 2;
    cntlPanel.add(new JLabel("Max Unchanged"), gbc_cntlPanelLabel);

    maxVUnchangedFmtTextBox = new JFormattedTextField(doubleFmt);
    maxVUnchangedFmtTextBox.setColumns(7);
    maxVUnchangedFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            Object source = e.getSource();
            if (source == maxVUnchangedFmtTextBox)
                updateNewMafScale();
        }
    });
    gbc_cntlPanelInput.gridx += 2;
    cntlPanel.add(maxVUnchangedFmtTextBox, gbc_cntlPanelInput);

    gbc_cntlPanelLabel.gridx += 2;
    cntlPanel.add(new JLabel("Mode deltaV"), gbc_cntlPanelLabel);

    modeDeltaVFmtTextBox = new JFormattedTextField(scaleDoubleFmt);
    modeDeltaVFmtTextBox.setColumns(7);
    modeDeltaVFmtTextBox.setEditable(false);
    modeDeltaVFmtTextBox.setBackground(new Color(210, 210, 210));
    gbc_cntlPanelInput.gridx += 2;
    cntlPanel.add(modeDeltaVFmtTextBox, gbc_cntlPanelInput);
}

From source file:org.opendatakit.briefcase.ui.settings.SettingsPanelForm.java

/**
 * Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 *
 * @noinspection ALL/*  w  w  w . j av a 2  s.c o  m*/
 */
private void $$$setupUI$$$() {
    createUIComponents();
    container = new JPanel();
    container.setLayout(new GridBagLayout());
    storageLocationContainer = new JPanel();
    storageLocationContainer.setLayout(new GridBagLayout());
    GridBagConstraints gbc;
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.gridwidth = 5;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(storageLocationContainer, gbc);
    storageLocationLabel = new JLabel();
    storageLocationLabel.setText("Storage Location");
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    storageLocationContainer.add(storageLocationLabel, gbc);
    storageLocationField = new JTextField();
    storageLocationField.setEditable(false);
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    storageLocationContainer.add(storageLocationField, gbc);
    storageLocationButtons = new JPanel();
    storageLocationButtons.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
    gbc = new GridBagConstraints();
    gbc.gridx = 3;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    storageLocationContainer.add(storageLocationButtons, gbc);
    storageLocationClearButton = new JButton();
    storageLocationClearButton.setText("Clear");
    storageLocationClearButton.setVisible(false);
    storageLocationButtons.add(storageLocationClearButton);
    storageLocationChooseButton = new JButton();
    storageLocationChooseButton.setText("Choose...");
    storageLocationButtons.add(storageLocationChooseButton);
    final JPanel spacer1 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    storageLocationContainer.add(spacer1, gbc);
    pullInParallelField = new JCheckBox();
    pullInParallelField.setText("Pull submissions in parallel (experimental)");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.gridwidth = 5;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(pullInParallelField, gbc);
    rememberPasswordsField = new JCheckBox();
    rememberPasswordsField.setText("Remember passwords (unencrypted)");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.gridwidth = 5;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(rememberPasswordsField, gbc);
    sendUsageDataField = new JCheckBox();
    sendUsageDataField.setText("Send usage data and crash logs to core developers");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 9;
    gbc.gridwidth = 5;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(sendUsageDataField, gbc);
    useHttpProxyField = new JCheckBox();
    useHttpProxyField.setText("Use HTTP Proxy");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 11;
    gbc.gridwidth = 5;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(useHttpProxyField, gbc);
    final JPanel spacer2 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 12;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(0, 0, 0, 20);
    container.add(spacer2, gbc);
    httpProxyJostLabel = new JLabel();
    httpProxyJostLabel.setText("Host");
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 12;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(httpProxyJostLabel, gbc);
    httpProxyHostField = new JTextField();
    httpProxyHostField.setPreferredSize(new Dimension(150, 30));
    httpProxyHostField.setText("127.0.0.1");
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.gridy = 12;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(httpProxyHostField, gbc);
    final JPanel spacer3 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 3;
    gbc.gridy = 12;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(spacer3, gbc);
    httpProxyPortLabel = new JLabel();
    httpProxyPortLabel.setText("Port");
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 13;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(httpProxyPortLabel, gbc);
    final JPanel spacer4 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 5;
    gbc.gridy = 12;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(spacer4, gbc);
    httpProxyPortField.setPreferredSize(new Dimension(150, 30));
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.gridy = 13;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(httpProxyPortField, gbc);
    final JPanel spacer5 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 10;
    gbc.gridwidth = 5;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer5, gbc);
    final JPanel spacer6 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 6;
    gbc.gridy = 1;
    gbc.gridheight = 13;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(spacer6, gbc);
    final JPanel spacer7 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridheight = 13;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    container.add(spacer7, gbc);
    final JPanel spacer8 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 5;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer8, gbc);
    final JPanel spacer9 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 14;
    gbc.gridwidth = 5;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer9, gbc);
    final JPanel spacer10 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.gridwidth = 5;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer10, gbc);
    final JPanel spacer11 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.gridwidth = 5;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer11, gbc);
    final JPanel panel1 = new JPanel();
    panel1.setLayout(new GridBagLayout());
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 15;
    gbc.gridwidth = 5;
    gbc.fill = GridBagConstraints.BOTH;
    container.add(panel1, gbc);
    panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Troubleshooting"));
    reloadCacheButton = new JButton();
    reloadCacheButton.setEnabled(false);
    reloadCacheButton.setText("Reload forms from storage location");
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel1.add(reloadCacheButton, gbc);
    final JPanel spacer12 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.VERTICAL;
    panel1.add(spacer12, gbc);
    final JPanel spacer13 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 9;
    gbc.fill = GridBagConstraints.VERTICAL;
    panel1.add(spacer13, gbc);
    final JPanel spacer14 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 3;
    gbc.gridy = 8;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel1.add(spacer14, gbc);
    final JPanel spacer15 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel1.add(spacer15, gbc);
    final JLabel label1 = new JLabel();
    label1.setText("The form list in Briefcase can get out of date if files are moved manually.");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.WEST;
    panel1.add(label1, gbc);
    final JLabel label2 = new JLabel();
    label2.setText("This reload is always safe.");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.WEST;
    panel1.add(label2, gbc);
    final JPanel spacer16 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel1.add(spacer16, gbc);
    final JPanel spacer17 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.VERTICAL;
    panel1.add(spacer17, gbc);
    final JPanel spacer18 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel1.add(spacer18, gbc);
    final JPanel spacer19 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.VERTICAL;
    panel1.add(spacer19, gbc);
    cleanAllPullResumePointsButton = new JButton();
    cleanAllPullResumePointsButton.setEnabled(false);
    cleanAllPullResumePointsButton.setText("Clear pull history");
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel1.add(cleanAllPullResumePointsButton, gbc);
    final JLabel label3 = new JLabel();
    label3.setText("Use if you wish to pull every submission, regardless of last submission pulled.");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.gridwidth = 3;
    gbc.anchor = GridBagConstraints.WEST;
    panel1.add(label3, gbc);
    final JPanel spacer20 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.VERTICAL;
    panel1.add(spacer20, gbc);
    final JPanel spacer21 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 16;
    gbc.gridwidth = 6;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer21, gbc);
    resumeLastPullField = new JCheckBox();
    resumeLastPullField.setText("Start pull from last submission pulled");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.gridwidth = 5;
    gbc.anchor = GridBagConstraints.WEST;
    container.add(resumeLastPullField, gbc);
    final JPanel spacer22 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.gridwidth = 5;
    gbc.fill = GridBagConstraints.VERTICAL;
    container.add(spacer22, gbc);
}

From source file:org.wandora.modules.servlet.ModulesWandoraWebAppHandler.java

@Override
public ConfigComponent getConfigComponent(WandoraWebApp app, WandoraWebAppServer server) {
    return new ConfigComponent() {
        SimpleField configField;/*  w  ww  . j  ava2  s  .c o m*/
        SimpleField staticPathField;
        public JPanel panel;
        {
            panel = new JPanel();
            GridBagConstraints gbc = GenericOptionsPanel.makeGBC();
            gbc.anchor = GridBagConstraints.WEST;
            gbc.insets = new java.awt.Insets(0, 5, 0, 5);
            panel.setLayout(new GridBagLayout());
            SimpleLabel myLabel = new SimpleLabel("Config file");
            myLabel.setPreferredSize(new Dimension(100, 20));
            myLabel.setHorizontalAlignment(SimpleLabel.RIGHT);
            panel.add(myLabel, gbc);
            gbc.gridx = 1;
            gbc.weightx = 1.0;

            configField = new SimpleField();
            configField.setText(getConfigFile() != null ? getConfigFile() : "");
            panel.add(configField, gbc);

            gbc.gridy = 1;
            gbc.gridx = 0;
            gbc.weightx = 0.0;
            myLabel = new SimpleLabel("Static path");
            myLabel.setPreferredSize(new Dimension(100, 20));
            myLabel.setHorizontalAlignment(SimpleLabel.RIGHT);
            panel.add(myLabel, gbc);
            gbc.gridx = 1;
            gbc.weightx = 1.0;
            staticPathField = new SimpleField();
            staticPathField.setText(getStaticPath() != null ? getStaticPath() : "");
            panel.add(staticPathField, gbc);

            gbc.gridx = 0;
            gbc.gridy = 2;
            gbc.weightx = 0.0;
            panel.add(new JPanel(), gbc);

        }

        public void accept() {
            setConfigFile(configField.getText().trim());
            setStaticPath(staticPathField.getText().trim());
        }

        public void cancel() {
        }

        public JComponent getComponent() {
            return panel;
        }
    };
}

From source file:be.agiv.security.demo.Main.java

private void secConvCancelToken() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    JPanel contentPanel = new JPanel(gridBagLayout);

    JLabel urlLabel = new JLabel("URL:");
    gridBagConstraints.gridx = 0;//w  w  w.  ja v  a  2s.  c  o  m
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

    JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_SC_LOCATION, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(urlTextField, gridBagConstraints);
    contentPanel.add(urlTextField);

    int result = JOptionPane.showConfirmDialog(this, contentPanel, "Secure Conversation Cancel Token",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.CANCEL_OPTION) {
        return;
    }

    String location = urlTextField.getText();

    SecureConversationClient secConvClient = new SecureConversationClient(location);
    try {
        secConvClient.cancelSecureConversationToken(this.secConvSecurityToken);
        this.secConvViewMenuItem.setEnabled(false);
        this.secConvCancelMenuItem.setEnabled(false);
        this.secConvSecurityToken = null;
        JOptionPane.showMessageDialog(this, "Secure conversation token cancelled.", "Secure Conversation",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
        showException(e);
    }
}