Example usage for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder

List of usage examples for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder

Introduction

In this page you can find the example usage for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder.

Prototype

public DefaultFormBuilder(FormLayout layout) 

Source Link

Document

Constructs a DefaultFormBuilder for the given layout.

Usage

From source file:ca.sqlpower.matchmaker.swingui.munge.NumberConstantMungeComponent.java

License:Open Source License

@Override
protected JPanel buildUI() {
    final NumberConstantMungeStep step = (NumberConstantMungeStep) getStep();
    valueField = new JTextField(step.getValue() == null ? "" : step.getValue().toString());

    valueField.getDocument().addDocumentListener(new DocumentListener() {
        void change() {
            step.setValue(new BigDecimal(valueField.getText()));
        }/*from w  w  w.  j a v a 2  s .  c  o  m*/

        public void changedUpdate(DocumentEvent e) {
            change();
        }

        public void insertUpdate(DocumentEvent e) {
            change();
        }

        public void removeUpdate(DocumentEvent e) {
            change();
        }
    });

    retNull = new JCheckBox("Return null");
    retNull.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            boolean b = retNull.isSelected();
            valueField.setEnabled(!b);
            if (b) {
                step.setValue(null);
            }
        }
    });

    retNull.setSelected(step.getValue() == null);
    valueField.setEnabled(!retNull.isSelected());

    FormLayout layout = new FormLayout("pref,4dlu,pref:grow");
    DefaultFormBuilder fb = new DefaultFormBuilder(layout);
    fb.append("Value:", valueField);
    fb.append("", retNull);

    return fb.getPanel();
}

From source file:ca.sqlpower.matchmaker.swingui.munge.StringConstantMungeComponent.java

License:Open Source License

@Override
protected JPanel buildUI() {
    StringConstantMungeStep step = ((StringConstantMungeStep) getStep());
    final JTextField valueField = new JTextField(step.getOutValue());
    valueField.getDocument().addDocumentListener(new DocumentListener() {

        void change() {
            ((StringConstantMungeStep) getStep()).setOutValue(valueField.getText());
        }/*from   w  w w .  j a  v  a  2  s.  c o m*/

        public void changedUpdate(DocumentEvent e) {
            change();
        }

        public void insertUpdate(DocumentEvent e) {
            change();
        }

        public void removeUpdate(DocumentEvent e) {
            change();
        }
    });

    final JCheckBox retNull = new JCheckBox("Return null");
    retNull.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            boolean b = retNull.isSelected();
            valueField.setEnabled(!b);
            ((StringConstantMungeStep) getStep()).setReturnNull(b);
        }
    });

    retNull.setSelected(Boolean.valueOf(((StringConstantMungeStep) getStep()).isReturnNull()));
    valueField.setEnabled(!retNull.isSelected());

    FormLayout layout = new FormLayout("pref,4dlu,pref:grow");
    DefaultFormBuilder fb = new DefaultFormBuilder(layout);
    fb.append("Value:", valueField);
    fb.append("", retNull);

    return fb.getPanel();
}

From source file:ca.sqlpower.matchmaker.swingui.SQLObjectChooser.java

License:Open Source License

/**
 * Presents a modal dialog with combo boxes for database connections,
 * catalogs, and schemas. Initially, there is no selection in the database
 * combo box, and the others are empty. As databases are chosen by the user,
 * the other combo boxes become enabled depending on the containment
 * hierarchy of the selected datbase (for instance, some databases have
 * catalogs but not schemas; others have schemas but not catalogs; others
 * have both; and still others just have tables directly inside the
 * top-level database connection).//from   w  w w. j av  a  2s . c  o  m
 * <p>
 * The type of the return value depends on the containment hierarchy of the selected database (the possibilities are described above).
 * The guarantee is that the returned object will itself be a "table container;" that is, its
 * children are of type SQLTable.
 * 
 * @param session The current MatchMaker session
 * @param owner The component that owns the dialog
 * @param dialogTitle The title to give the dialog
 * @param okButtonLabel The text that should appear on the OK button
 * @return The selected "table container" object, or <tt>null</tt> if the user cancels or
 * closes the dialog.
 * @throws SQLObjectException If there are problems connecting to or populating the chosen databases
 */
public static SQLObject showSchemaChooserDialog(MatchMakerSwingSession session, Component owner,
        String dialogTitle, String okButtonLabel) throws SQLObjectException {
    // single boolean in final array so the buttons can modify its value
    final boolean[] dialogAccepted = new boolean[1];
    final JDialog d = SPSUtils.makeOwnedDialog(owner, dialogTitle);
    SQLObjectChooser soc = new SQLObjectChooser(session, d);

    FormLayout layout = new FormLayout("pref,4dlu,pref");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();

    builder.append("Connection", soc.getDataSourceComboBox());
    builder.append(soc.getCatalogTerm(), soc.getCatalogComboBox());
    builder.append(soc.getSchemaTerm(), soc.getSchemaComboBox());

    JButton okButton = new JButton(okButtonLabel);
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialogAccepted[0] = true;
            d.dispose();
        }
    });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            d.dispose();
        }
    });

    builder.append(ButtonBarFactory.buildOKCancelBar(okButton, cancelButton), 3);

    d.setContentPane(builder.getPanel());
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    d.setModal(true);
    d.pack();
    d.setLocationRelativeTo(owner);

    for (;;) {
        dialogAccepted[0] = false;
        d.setVisible(true);

        if (!dialogAccepted[0]) {
            return null;
        }

        logger.debug("User submitted a selection. Chooser state: " + soc);

        // post-mortem: figure out if we're returning a database, catalog, or schema
        if (soc.schema != null) {
            return soc.schema;
        } else if (soc.catalog != null && !soc.schemaComboBox.isEnabled()) {
            return soc.catalog;
        } else if (soc.db != null && (!(soc.schemaComboBox.isEnabled() || soc.catalogComboBox.isEnabled()))) {
            return soc.db;
        } else {
            return null;
        }
    }
}

From source file:ca.sqlpower.matchmaker.swingui.UserPreferencesEditor.java

License:Open Source License

/**
 * Subroutine of the constructor that puts together the panel, creating
 * all the GUI components and initializing them to the current values
 * in the session context.//w  w  w  .ja  v a  2 s  . com
 */
private JPanel buildUI() {
    FormLayout layout = new FormLayout("pref,4dlu,max(300;min),4dlu,min",
            "pref,4dlu,pref,4dlu,pref,12dlu,min,4dlu,pref,2dlu,max(40;min)");
    CellConstraints cc = new CellConstraints();
    DefaultFormBuilder fb = new DefaultFormBuilder(layout);
    fb.setDefaultDialogBorder();

    validatePathExInfo.setOpaque(false);
    validatePathExInfo.setEditable(false);
    validatePathExInfo.setLineWrap(true);
    validatePathExInfo.setWrapStyleWord(true);
    validatePathExInfo.setFont(validatePathResult.getFont());

    addressDataPath.setDocument(addressDataPathDoc);
    addressDataPathDoc.addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {

        }

        public void insertUpdate(DocumentEvent e) {
            validatePathResult.setText("");
            validatePathExInfo.setText("");
        }

        public void removeUpdate(DocumentEvent e) {
            validatePathResult.setText("");
            validatePathExInfo.setText("");
        }

    });
    try {
        addressDataPathDoc.remove(0, addressDataPathDoc.getLength());
        addressDataPathDoc.insertString(0, context.getAddressCorrectionDataPath(), null);
    } catch (BadLocationException e2) {
        SPSUtils.showExceptionDialogNoReport(getPanel(), "", e2);
    }

    JButton selectPath = new JButton(new AbstractAction("...") {

        public void actionPerformed(ActionEvent e) {
            addressDataPathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int selected = addressDataPathChooser.showOpenDialog(getPanel());
            if (selected == JFileChooser.APPROVE_OPTION) {
                try {
                    addressDataPathDoc.remove(0, addressDataPathDoc.getLength());
                    addressDataPathDoc.insertString(0,
                            addressDataPathChooser.getSelectedFile().getAbsolutePath(), null);
                } catch (BadLocationException e1) {
                    SPSUtils.showExceptionDialogNoReport(getPanel(), "", e1);
                }
            }
        }
    });

    JButton validateAddressDataPath = new JButton(new AbstractAction("Test Path") {

        public void actionPerformed(ActionEvent e) {
            try {
                testPath = new AddressDatabase(new File(addressDataPath.getText()));
                validatePathResult.setText("Address Data Path is valid");
            } catch (DatabaseException e1) {
                validatePathResult.setText("Invalid Address Data Path");
                validatePathExInfo.setText(e1.toString());
                logger.error("Invalid Address Data Path", e1);
            } catch (Exception e2) {
                validatePathResult.setText("Invalid Address Data Path");
                validatePathExInfo.setText(e2.toString());
                logger.error("Invalid Address Data Path", e2);
            } finally {
                if (testPath != null) {
                    testPath.close();
                }
            }
        }

    });

    fb.addLabel("Address Correction Data Path:", cc.xy(1, 7));
    fb.add(addressDataPath, cc.xy(3, 7));
    fb.add(selectPath, cc.xy(5, 7));
    fb.add(validateAddressDataPath, cc.xy(1, 9));
    fb.add(validatePathResult, cc.xy(3, 9));
    fb.add(validatePathExInfo, cc.xy(3, 11));

    return fb.getPanel();
}

From source file:ca.sqlpower.swingui.db.DataSourceTypeCopyPropertiesPanel.java

License:Open Source License

private JPanel buildUI() {
    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref"));
    builder.setDefaultDialogBorder();//  www  . ja  v a2s .c  o  m
    builder.append(new JLabel("Copy all properties from which data source type?"));
    builder.append(dsTypesComboBox);
    builder.append(new JLabel("Note: This will overwrite all current settings on " + dsType.getName() + "."));
    return builder.getPanel();
}

From source file:ca.sqlpower.swingui.db.DataSourceTypeEditor.java

License:Open Source License

/**
 * Creates the panel layout. Requires that the GUI components have already
 * been created. Does not fill in any values into the components. See
 * {@link #switchToDsType()} for that./*from  w w  w. java  2 s .  c  o m*/
 */
private JPanel createPanel() {
    FormLayout layout = new FormLayout("fill:max(60dlu;pref), 6dlu, pref:grow", //$NON-NLS-1$
            "pref, 6dlu, pref:grow, 3dlu, pref"); //$NON-NLS-1$
    DefaultFormBuilder fb = new DefaultFormBuilder(layout);
    fb.setDefaultDialogBorder();

    JComponent addRemoveBar = new JPanel(new FlowLayout(FlowLayout.LEFT));
    addRemoveBar.add(addDsTypeButton);
    addRemoveBar.add(removeDsTypeButton);

    JScrollPane dsTypePane = new JScrollPane(dsTypeList);
    //Setting the preferred size to 0 so the add/remove bar and the default size
    //set the width of the column and not the max type name width.
    dsTypePane.setPreferredSize(new Dimension(0, 0));
    fb.add(dsTypePane, "1, 1, 1, 3"); //$NON-NLS-1$
    fb.add(addRemoveBar, "1, 5"); //$NON-NLS-1$
    fb.add(dsTypePanel.getPanel(), "3, 1"); //$NON-NLS-1$

    return fb.getPanel();
}

From source file:ca.sqlpower.swingui.db.NewDataSourceTypePanel.java

License:Open Source License

private JPanel buildUI() {
    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref"));
    builder.setDefaultDialogBorder();/*from   www . j a v a  2s. co m*/

    builder.append("New Data Source Type");
    builder.append(blankOption);
    builder.append(copyOption);
    builder.append(existingDSTypes);

    return builder.getPanel();
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

License:Open Source License

/**
 * This constructor creates a dialog for modifying and loading a project
 * from a single server designated by the given serverInfo parameter.
 * /* w  ww.  j av  a  2s.  co  m*/
 * @param serverInfo
 *            Projects will be retrieved from this server based on the
 *            information and displayed. The dialog will allow editing the
 *            security as well as creating and deleting projects on this
 *            server.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfo serverInfo, Component dialogOwner, UserPrompterFactory upf,
        Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.serverInfo = serverInfo;
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = null;

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel(serverInfo.getName() + "'s projects:"), cc.xyw(1, 1, 2));
    builder.nextLine();
    builder.add(projectsPane, cc.xywh(1, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(3, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

License:Open Source License

/**
 * Creates a dialog that lets the user choose a server connection and then a
 * project.// www. ja v  a 2s  . c  o  m
 * 
 * @param serverManager
 *            This object contains all of the server information objects
 *            known and the servers based on their information will be
 *            displayed in a list so a user can navigate to different
 *            projects in different servers.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfoManager serverManager, Component dialogOwner,
        UserPrompterFactory upf, Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = new JList(new DefaultListModel());
    servers.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
                refreshInfoList();
            }
        }
    });

    DefaultListModel serversModel = (DefaultListModel) servers.getModel();
    serversModel.removeAllElements();
    if (serverManager.getServers(false).size() > 0) {
        for (SPServerInfo serverInfo : serverManager.getServers(false)) {
            serversModel.addElement(serverInfo);
        }
    } else {
        serversModel.addElement("No Servers");
        servers.setEnabled(false);
    }

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    JScrollPane serverPane = new JScrollPane(servers);
    serverPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel("Servers:"), cc.xyw(1, 1, 2));
    builder.add(new JLabel("Projects:"), cc.xyw(3, 1, 2));
    builder.nextLine();
    builder.add(serverPane, cc.xywh(1, 2, 1, 2));
    builder.add(projectsPane, cc.xywh(3, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(uploadAction));
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(5, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:ca.sqlpower.swingui.enterprise.client.SPServerInfoManagerPanel.java

License:Open Source License

/**
 * Creates a panel that displays the currently configured server
 * connections. New connections can be added from this panel and existing
 * connections can be modified or removed.
 * //from   w  w  w.java2  s  .co  m
 * @param manager
 *            An {@link SPServerInfoManager} instance that contains server connection information.
 * @param dialogOwner
 *            A component that will be used as the dialog owner for other
 *            panels.
 * @param closeAction
 *            An action that will properly close the object displaying the
 *            panel.
 * @param boxLabel
 *           Label of the server information box
 * @param addOrEditDialogLable
 *             Label of the Add/Edit panel
 */
public SPServerInfoManagerPanel(SPServerInfoManager manager, Component dialogOwner, Action closeAction,
        String boxLabel, String addOrEditDialogLable) {
    this.manager = manager;
    this.dialogOwner = dialogOwner;
    this.boxLable = boxLabel;
    this.addOrEditDialogLabel = addOrEditDialogLable;
    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref", "pref, pref, pref"));

    serverInfos = new JList(new DefaultListModel());
    serverInfos.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)
                    && connectButton.getAction() != null) {
                connectButton.getAction().actionPerformed(null);
            }
        }

    });
    JScrollPane scrollPane = new JScrollPane(serverInfos);
    scrollPane.setPreferredSize(new Dimension(400, 300));

    this.connectButton = new JButton();

    // Build the GUI
    refreshInfoList();
    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel(boxLable), cc.xyw(1, 1, 3));
    builder.nextLine();
    builder.add(scrollPane, cc.xywh(1, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(addAction));
    buttonBarBuilder.append(new JButton(editAction));
    buttonBarBuilder.append(new JButton(removeAction));
    buttonBarBuilder.append(connectButton);
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(3, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}