Example usage for com.jgoodies.forms.layout FormLayout FormLayout

List of usage examples for com.jgoodies.forms.layout FormLayout FormLayout

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout FormLayout FormLayout.

Prototype

public FormLayout(ColumnSpec[] colSpecs, RowSpec[] rowSpecs) 

Source Link

Document

Constructs a FormLayout using the given column and row specifications.

Usage

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

License:Open Source License

private void buildUI() {

    //This created the layout for the internal panel at the top wit
    //the lables and the text fields

    String txt = "fill:min(pref;" + (new JTextField().getMinimumSize().width) + "px):grow";
    FormLayout layout = new FormLayout(
            "4dlu,pref,4dlu," + txt + ",4dlu,pref,4dlu," + txt + ",4dlu,pref,4dlu,pref,4dlu", // columns
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu"); // rows
    //    1     2    3    4    5    6    7 

    PanelBuilder internalPB;/*w  ww  . j  av a 2 s.  c om*/
    JPanel internalP = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);

    internalPB = new PanelBuilder(layout, internalP);
    CellConstraints cc = new CellConstraints();

    int row = 2;
    internalPB.add(status, cc.xy(4, row));

    row += 2;
    internalPB.add(new JLabel("Group Name:"), cc.xy(2, row, "r,t"));
    setGroupName();
    internalPB.add(groupName, cc.xy(4, row, "f,f"));

    row += 2;
    internalPB.add(new JLabel("From:"), cc.xy(2, row, "r,t"));
    internalPB.add(from, cc.xy(4, row, "f,f"));

    internalPB.add(new JLabel("To:"), cc.xy(6, row, "r,t"));
    internalPB.add(to, cc.xy(8, row, "f,f"));
    internalPB.add(new JButton(createWordsAction), cc.xy(10, row, "l,t"));

    //The layout for the external frame that houses the table and the button bars
    FormLayout bbLayout = new FormLayout(
            "4dlu,pref,50dlu,fill:min(pref;" + (new JComboBox().getMinimumSize().width)
                    + "px):grow, 4dlu,pref,4dlu", // columns
            "4dlu,pref,4dlu,fill:40dlu:grow,4dlu,pref,4dlu,pref,4dlu"); // rows
    //    1     2    3    4    5    6    7     8   9   

    PanelBuilder externalPB;
    JPanel externalP = logger.isDebugEnabled() ? new FormDebugPanel(bbLayout) : new JPanel(bbLayout);

    externalPB = new PanelBuilder(bbLayout, externalP);
    CellConstraints bbcc = new CellConstraints();

    row = 4;
    translateWordsScrollPane = new JScrollPane(translateWordsTable);
    externalPB.add(translateWordsScrollPane, bbcc.xy(4, row, "f,f"));

    ButtonStackBuilder bsb = new ButtonStackBuilder();
    bsb.addGridded(new JButton(moveTopAction));
    bsb.addRelatedGap();
    bsb.addGridded(new JButton(moveUpAction));
    bsb.addRelatedGap();
    bsb.addGridded(new JButton(moveDownAction));
    bsb.addRelatedGap();
    bsb.addGridded(new JButton(moveBottomAction));
    externalPB.add(bsb.getPanel(), bbcc.xy(6, row, "c,c"));

    row += 2;
    ButtonBarBuilder bbb = new ButtonBarBuilder();
    //new actions for delete and save should be extracted and be put into its own file.
    bbb.addGridded(new JButton(deleteWordsAction));
    bbb.addRelatedGap();
    bbb.addGridded(new JButton(saveGroupAction));

    externalPB.add(bbb.getPanel(), bbcc.xy(4, row, "c,c"));

    externalPB.add(internalPB.getPanel(), cc.xyw(2, 2, 4, "f,f"));

    MMODuplicateValidator mmoValidator = new MMODuplicateValidator(
            swingSession.getRootNode().getTranslateGroupParent(), null, "translate group name", 35, mmo);
    handler.addValidateObject(groupName, mmoValidator);
    TranslateWordValidator wordValidator = new TranslateWordValidator(translateWordsTable);
    handler.addValidateObject(translateWordsTable, wordValidator);

    panel = externalPB.getPanel();
}

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.//from  w w w. j  a va 2 s  .  c om
 */
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.DatabaseConnectionManager.java

License:Open Source License

private JPanel createPanel(List<Action> additionalActions, List<JComponent> additionalComponents,
        boolean showCloseButton, String message) {

    FormLayout layout = new FormLayout("6dlu, fill:min(160dlu;default):grow, 6dlu, pref, 6dlu", // columns //$NON-NLS-1$
            " 6dlu,10dlu,6dlu,fill:min(180dlu;default):grow,10dlu"); // rows //$NON-NLS-1$

    layout.setColumnGroups(new int[][] { { 1, 3, 5 } });
    CellConstraints cc = new CellConstraints();

    PanelBuilder pb;//  ww w.  j  av a 2s  .  c  om
    JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);
    pb = new PanelBuilder(layout, p);
    pb.setDefaultDialogBorder();

    pb.add(new JLabel(message), cc.xyw(2, 2, 3)); //$NON-NLS-1$

    TableModel tm = new ConnectionTableModel(dsCollection);
    dsTable = new EditableJTable(tm);
    dsTable.setTableHeader(null);
    dsTable.setShowGrid(false);
    dsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dsTable.addMouseListener(new DSTableMouseListener());
    dsTable.setDefaultRenderer(SPDataSource.class, new ConnectionTableCellRenderer());

    JScrollPane sp = new JScrollPane(dsTable);
    sp.getViewport().setBackground(dsTable.getBackground());

    pb.add(sp, cc.xy(2, 4));

    ButtonStackBuilder bsb = new ButtonStackBuilder();

    JButton newButton = new JButton();
    AbstractAction newDatabaseConnectionAction = new NewConnectionAction(
            Messages.getString("DatabaseConnectionManager.newDbConnectionActionName"), newButton); //$NON-NLS-1$
    newButton.setAction(newDatabaseConnectionAction);
    bsb.addGridded(newButton);
    bsb.addRelatedGap();
    bsb.addGridded(new JButton(editDatabaseConnectionAction));
    bsb.addRelatedGap();
    bsb.addGridded(new JButton(removeDatabaseConnectionAction));

    removeDatabaseConnectionAction.setEnabled(false);
    editDatabaseConnectionAction.setEnabled(false);

    bsb.addUnrelatedGap();
    JButton jdbcDriversButton = new JButton(jdbcDriversAction);
    bsb.addGridded(jdbcDriversButton);

    for (Action a : additionalActions) {
        bsb.addUnrelatedGap();
        JButton b = new JButton(a);
        Object disableValue = a.getValue(DISABLE_IF_NO_CONNECTION_SELECTED);
        if (disableValue instanceof Boolean && disableValue.equals(Boolean.TRUE)) {
            b.setEnabled(false);
        }

        Object heightValue = a.getValue(ADDITIONAL_BUTTON_HEIGHT);
        if (heightValue instanceof Integer) {
            b.setPreferredSize(new Dimension((int) b.getPreferredSize().getWidth(), (Integer) heightValue));
        }

        Object verticalTextPos = a.getValue(VERTICAL_TEXT_POSITION);
        if (verticalTextPos instanceof Integer) {
            Integer verticalTextInt = (Integer) verticalTextPos;
            if (verticalTextInt == SwingConstants.TOP || verticalTextInt == SwingConstants.BOTTOM
                    || verticalTextInt == SwingConstants.CENTER) {
                b.setVerticalTextPosition(verticalTextInt);
            }
        }

        Object horizontalTextPos = a.getValue(HORIZONTAL_TEXT_POSITION);
        if (horizontalTextPos instanceof Integer) {
            Integer horizontalTextInt = (Integer) horizontalTextPos;
            if (horizontalTextInt == SwingConstants.LEFT || horizontalTextInt == SwingConstants.RIGHT
                    || horizontalTextInt == SwingConstants.CENTER || horizontalTextInt == SwingConstants.LEADING
                    || horizontalTextInt == SwingConstants.TRAILING) {
                b.setHorizontalTextPosition(horizontalTextInt);
            }
        }

        additionalActionButtons.add(b);
        bsb.addFixed(b);
    }

    for (JComponent comp : additionalComponents) {
        bsb.addUnrelatedGap();
        bsb.addFixed(comp);
    }

    if (showCloseButton) {
        bsb.addUnrelatedGap();
        bsb.addGridded(new JButton(closeAction));
    }

    pb.add(bsb.getPanel(), cc.xy(4, 4));
    return pb.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.//  w w w.jav a  2 s .  com
 */
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.DataSourceTypeEditorPanel.java

License:Open Source License

private void buildPanel() {

    connectionStringTemplate.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
            updateTemplate();/*from  w  ww  .  j a v a  2s.c o m*/
        }

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

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

        /**
         * Updates the template if dsType is not currently null.
         */
        private void updateTemplate() {
            if (dsType != null) {
                dsType.setJdbcUrl(connectionStringTemplate.getText());
                template.setTemplate(dsType);
            }
        }

    });

    tabbedPane = new JTabbedPane();

    PanelBuilder pb = new PanelBuilder(new FormLayout("4dlu,pref,4dlu,pref:grow,4dlu", //$NON-NLS-1$
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu, pref:grow, 4dlu")); //$NON-NLS-1$

    CellConstraints cc = new CellConstraints();
    CellConstraints cl = new CellConstraints();
    int row = 2;
    pb.addLabel(Messages.getString("DataSourceTypeEditorPanel.nameLabel"), cl.xy(2, row), name, cc.xy(4, row)); //$NON-NLS-1$
    row += 2;
    pb.addLabel(Messages.getString("DataSourceTypeEditorPanel.driverClassLabel"), cl.xy(2, row), driverClass, //$NON-NLS-1$
            cc.xy(4, row));
    row += 2;
    pb.addLabel(Messages.getString("DataSourceTypeEditorPanel.connectionStringTemplateLabel"), cl.xy(2, row), //$NON-NLS-1$
            connectionStringTemplate, cc.xy(4, row));
    row += 2;
    connectionStringTemplate.setToolTipText(Messages.getString("DataSourceTypeEditorPanel.templateToolTip")); //$NON-NLS-1$
    pb.addTitle(Messages.getString("DataSourceTypeEditorPanel.optionsEditorPreview"), cl.xyw(2, row, 3)); //$NON-NLS-1$
    row += 2;
    pb.addLabel(Messages.getString("DataSourceTypeEditorPanel.sampleOptions"), cl.xy(2, row), //$NON-NLS-1$
            template.getPanel(), cc.xy(4, row));
    row += 2;
    pb.add(jdbcPanel, cc.xyw(2, row, 3));

    tabbedPane.addTab(Messages.getString("DataSourceTypeEditorPanel.generalTab"), pb.getPanel()); //$NON-NLS-1$

    panel = new JPanel(new BorderLayout());
    panel.add(tabbedPane, BorderLayout.CENTER);

    ButtonBarBuilder copyBar = new ButtonBarBuilder();
    copyBar.addGlue();
    copyBar.addGridded(copyPropertiesButton);
    panel.add(copyBar.getPanel(), BorderLayout.SOUTH);
}

From source file:ca.sqlpower.swingui.DialogUserPrompter.java

License:Open Source License

/**
 * Creates a new user prompter that uses a dialog to prompt the user.
 * Normally this constructor should be called via a {@link UserPrompterFactory}
 * such as the current ArchitectSession.
 *///from w  ww  .jav a2s.  c  o m
public DialogUserPrompter(UserPromptOptions optionType, UserPromptResponse defaultResponseType, JFrame owner,
        String questionMessage, boolean modal, String... buttonNames) {
    if (optionType.getButtonCount() != buttonNames.length) {
        throw new IllegalStateException(
                "Expecting " + optionType.getButtonCount() + " arguments for the optionType " + optionType
                        + "Recieved only " + buttonNames.length + "arguments\n" + Arrays.toString(buttonNames));
    }
    this.defaultResponseType = defaultResponseType;
    this.owner = owner;
    applyToAll = new JCheckBox(Messages.getString("ModalDialogUserPrompter.applyToAllOption")); //$NON-NLS-1$

    confirmDialog = new JDialog(owner);

    // FIXME the title needs to be configurable and/or set itself based on prompt type
    confirmDialog.setTitle(""); //$NON-NLS-1$

    // this is just filled with the message pattern template to help with sizing
    //Using JEditorPane for html messages as JTextAreas do not respect html tags.
    //Using JTextArea for the rest of the messages as JEditorPane does not support
    //new line characters and to keep font consistent.
    if (questionMessage.startsWith("<html>")) {
        questionField = new JEditorPane();
        questionField.setText(questionMessage);
        ((JEditorPane) questionField).setContentType("text/html");
        questionField.setFont(new JTextArea().getFont());
    } else {
        questionField = new JTextArea(questionMessage);
    }
    questionField.setEditable(false);
    questionField.setBackground(null);

    questionFormat = new MessageFormat(questionMessage);

    JPanel confirmPanel = new JPanel();
    FormLayout formLayout = new FormLayout("10dlu, 2dlu, pref:grow, 2dlu, 10dlu" //$NON-NLS-1$
            , ""); //$NON-NLS-1$
    DefaultFormBuilder builder = new DefaultFormBuilder(formLayout, confirmPanel);
    builder.setDefaultDialogBorder();

    builder.nextColumn(2);
    builder.append(questionField);
    builder.nextLine();

    builder.appendParagraphGapRow();
    builder.nextLine();

    ButtonBarBuilder buttonBar = new ButtonBarBuilder();
    buttonBar.addGlue();
    JButton okButton = new JButton();
    if (optionType == UserPromptOptions.OK_NEW_NOTOK_CANCEL || optionType == UserPromptOptions.OK_NOTOK_CANCEL
            || optionType == UserPromptOptions.OK_NEW_CANCEL || optionType == UserPromptOptions.OK_CANCEL
            || optionType == UserPromptOptions.OK) {
        okButton.setText(buttonNames[0]);
        buttonBar.addGridded(okButton);
    }
    JButton notOkButton = new JButton();
    if (optionType == UserPromptOptions.OK_NEW_NOTOK_CANCEL
            || optionType == UserPromptOptions.OK_NOTOK_CANCEL) {
        buttonBar.addRelatedGap();
        notOkButton
                .setText((optionType == UserPromptOptions.OK_NOTOK_CANCEL) ? buttonNames[1] : buttonNames[2]);
        buttonBar.addGridded(notOkButton);
    }
    JButton cancelButton = new JButton();
    if (optionType == UserPromptOptions.OK_NEW_NOTOK_CANCEL || optionType == UserPromptOptions.OK_NOTOK_CANCEL
            || optionType == UserPromptOptions.OK_NEW_CANCEL || optionType == UserPromptOptions.OK_CANCEL) {
        buttonBar.addRelatedGap();
        cancelButton.setText(buttonNames[buttonNames.length - 1]);
        buttonBar.addGridded(cancelButton);
    }
    buttonBar.addGlue();

    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            response = UserPromptResponse.OK;
            confirmDialog.dispose();
        }
    });
    notOkButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            response = UserPromptResponse.NOT_OK;
            confirmDialog.dispose();
        }
    });
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            response = UserPromptResponse.CANCEL;
            confirmDialog.dispose();
        }
    });
    builder.append(""); //$NON-NLS-1$
    builder.append(buttonBar.getPanel());
    builder.nextLine();

    builder.append(""); //$NON-NLS-1$
    builder.append(applyToAll);

    switch (defaultResponseType) {
    case OK:
        okButton.requestFocusInWindow();
        break;
    case NOT_OK:
        notOkButton.requestFocusInWindow();
        break;
    case CANCEL:
        cancelButton.requestFocusInWindow();
        break;
    default:
        throw new UnsupportedOperationException(
                "Default response type : " + defaultResponseType + " is not known");
    }

    confirmDialog.setModal(modal);
    confirmDialog.add(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.
 * //from ww  w .j  a  v  a2 s . 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./*  w  ww .jav  a  2 s .  co 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.
 * /*  w  w  w .  j  av  a2 s  .c om*/
 * @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();
}

From source file:ca.sqlpower.swingui.FontSelector.java

License:Open Source License

public FontSelector(Font font, String[] fontList, SPFontLoader fontLoader) {

    this.fontLoader = fontLoader;
    if (font == null) {
        if (fontList == null || fontList.length == 0) {
            throw new IllegalArgumentException("The fontList parameter requires at least one valid font.");
        }//w  ww  .  j  av a  2  s  . com
        font = Font.decode(fontList[0]);
        if (font == null) {
            throw new IllegalArgumentException("The fontList[0] element cannot be loaded.");
        }
    }

    logger.debug("Creating new font selector with given font: " + font);

    this.originalFont = font;

    SelectionHandler selectionHandler = new SelectionHandler();
    fontNameList = new JList(fontList);
    fontNameList.addListSelectionListener(selectionHandler);

    fontSizeSpinner = new JSpinner(new SpinnerNumberModel(font.getSize(), 1, 200, 1));
    fontSizeSpinner.addChangeListener(selectionHandler);

    fontSizeList = new JList(FONT_SIZES);
    fontSizeList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (fontSizeList.getSelectedValue() != null) {
                fontSizeSpinner.setValue((Integer) fontSizeList.getSelectedValue());
            }
        }
    });

    styleChoice = new JList(FontStyle.values());
    styleChoice.setSelectedValue(FontStyle.forCode(font.getStyle()), true);
    styleChoice.addListSelectionListener(selectionHandler);

    FormLayout layout = new FormLayout("pref:grow, 4dlu, pref, 4dlu, pref",
            "pref, 4dlu, pref, 4dlu, fill:pref:grow");
    layout.setHonorsVisibility(true);
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    CellConstraints cc = new CellConstraints();

    builder.add(new JScrollPane(fontNameList), cc.xywh(1, 1, 1, 3));
    builder.add(fontSizeSpinner, cc.xywh(3, 1, 1, 1));
    builder.add(new JScrollPane(fontSizeList), cc.xywh(3, 3, 1, 1));
    builder.add(new JScrollPane(styleChoice), cc.xywh(5, 1, 1, 3));

    previewArea.setBackground(Color.WHITE);
    previewArea.setPreferredSize(new Dimension(300, 100));
    builder.add(previewArea, cc.xywh(1, 5, 5, 1));

    // Set defaults after creating layout so the "scroll to visible" works
    fontSizeList.setSelectedValue(Integer.valueOf(font.getSize()), true);
    fontNameList.setSelectedValue(font.getFamily(), true);
    logger.debug(
            "Set family list to \"" + font.getFamily() + "\" and size to " + Integer.valueOf(font.getSize()));

    panel = builder.getPanel();

    previewFont(); // ensure view is up to date!
}