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

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

Introduction

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

Prototype

public void setRowSpec(int rowIndex, RowSpec rowSpec) 

Source Link

Document

Sets the RowSpec at the specified row index.

Usage

From source file:com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SimpleContainsAssertion.java

License:EUPL

private void buildDialog() {
    XFormDialogBuilder builder = XFormFactory.createDialogBuilder("Contains Assertion");
    XForm mainForm = builder.createForm("Basic",
            new FormLayout("5px,left:pref,5px,fill:default:grow(1.0),5px"));
    JPanel mainFormPanel = ((SwingXFormImpl) mainForm).getPanel();
    FormLayout mainFormLayout = (FormLayout) mainFormPanel.getLayout();

    mainForm.addTextField(CONTENT, "Content to check for", XForm.FieldType.TEXTAREA).setWidth(40);

    mainFormLayout.setRowSpec(mainFormLayout.getRowCount(), new RowSpec("top:default:grow(1.0)"));
    mainFormPanel.add(mainFormPanel.getComponent(mainFormPanel.getComponents().length - 1),
            cc.xy(4, mainFormLayout.getRowCount(), "fill,fill"));

    mainForm.addCheckBox(IGNORE_CASE, "Ignore case in comparison");
    mainForm.addCheckBox(USE_REGEX, "Use token as Regular Expression");

    dialog = builder.buildDialog(builder.buildOkCancelHelpActions(HelpUrls.SIMPLE_CONTAINS_HELP_URL),
            "Specify options", UISupport.OPTIONS_ICON);
}

From source file:com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SimpleNotContainsAssertion.java

License:EUPL

private void buildDialog() {
    XFormDialogBuilder builder = XFormFactory.createDialogBuilder("NotContains Assertion");
    XForm mainForm = builder.createForm("Basic",
            new FormLayout("5px,left:pref,5px,fill:default:grow(1.0),5px"));
    JPanel mainFormPanel = ((SwingXFormImpl) mainForm).getPanel();
    FormLayout mainFormLayout = (FormLayout) mainFormPanel.getLayout();

    mainForm.addTextField(CONTENT, "Content to check for", XForm.FieldType.TEXTAREA).setWidth(40);

    mainFormLayout.setRowSpec(mainFormLayout.getRowCount(), new RowSpec("top:default:grow(1.0)"));
    mainFormPanel.add(mainFormPanel.getComponent(mainFormPanel.getComponents().length - 1),
            cc.xy(4, mainFormLayout.getRowCount(), "fill,fill"));

    mainForm.addCheckBox(IGNORE_CASE, "Ignore case in comparison");
    mainForm.addCheckBox(USE_REGEX, "Use token as Regular Expression");

    dialog = builder.buildDialog(builder.buildOkCancelHelpActions(HelpUrls.SIMPLE_NOT_CONTAINS_HELP_URL),
            "Specify options", UISupport.OPTIONS_ICON);
}

From source file:com.intellij.uiDesigner.designSurface.FormFirstComponentInsertLocation.java

License:Apache License

@Override
public void processDrop(final GuiEditor editor, final RadComponent[] components,
        final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) {
    RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager();
    if (myContainer.getGridRowCount() == 0) {
        gridLayout.insertGridCells(myContainer, 0, true, true, true);
    }/*from  w  ww.java  2 s. c o  m*/
    if (myContainer.getGridColumnCount() == 0) {
        gridLayout.insertGridCells(myContainer, 0, false, true, true);
    }
    dropIntoGrid(myContainer, components, myRow, myColumn, dragObject);

    FormLayout formLayout = (FormLayout) myContainer.getDelegee().getLayout();
    if (myXPart == 0) {
        formLayout.setColumnSpec(1, ColumnSpec.decode("d"));
    } else if (myXPart == 2) {
        gridLayout.insertGridCells(myContainer, 0, false, true, true);
    }
    if (myYPart == 0) {
        formLayout.setRowSpec(1, RowSpec.decode("d"));
    } else if (myYPart == 2) {
        gridLayout.insertGridCells(myContainer, 0, true, true, true);
    }
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

private static void setSpec(final FormLayout formLayout, final FormSpec newSpec, final int cell,
        boolean isRow) {
    if (isRow) {/*from  w w  w  . j a v a2  s.c  om*/
        formLayout.setRowSpec(cell, (RowSpec) newSpec);
    } else {
        formLayout.setColumnSpec(cell, (ColumnSpec) newSpec);
    }
}

From source file:de.dfki.dmas.owls2wsdl.gui.ExportWSDLFrame.java

License:Open Source License

private JPanel buildExportSubPanel(boolean debugmode) {
    FormLayout layout = new FormLayout("left:10dlu, fill:pref:grow, 10px, fill:pref");

    DefaultFormBuilder builder = null;/*from ww  w  .  j ava  2 s .co m*/
    if (debugmode)
        builder = new DefaultFormBuilder(layout, new FormDebugPanel());
    else
        builder = new DefaultFormBuilder(layout);

    builder.setDefaultDialogBorder();
    builder.setLeadingColumnOffset(1);

    builder.appendSeparator("Translatable Services");
    JScrollPane scrollPane_1 = new JScrollPane(translatableServiceList);
    scrollPane_1.setPreferredSize(translatableServiceList.getPreferredScrollableViewportSize());
    builder.append(scrollPane_1, 3);

    builder.appendSeparator("Non-Translatable Services");
    JScrollPane scrollPane_2 = new JScrollPane(nonTranslatableServiceList);
    scrollPane_2.setPreferredSize(nonTranslatableServiceList.getPreferredScrollableViewportSize());
    builder.append(scrollPane_2, 3);

    builder.appendSeparator("Export Settings");
    JPanel checkPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    // checkPanel.setBackground(Color.blue);
    checkPanel.add(generateWSDLCheckBox);
    checkPanel.add(generateOWLSCheckBox);
    // checkPanel.add(buildRelativePathCheckBox);
    builder.append(checkPanel, 3);
    builder.nextLine();

    JButton browseButton = new JButton("Path...");
    browseButton.setActionCommand(SET_EXPORT_PATH);
    browseButton.addActionListener(this);

    builder.append(urlField, 1);
    builder.append(browseButton, 1);

    // builder.appendGlueColumn();

    builder.appendSeparator("Export Log");

    JScrollPane scrollPane_3 = new JScrollPane(exportLog);
    // scrollPane_3.setPreferredSize(exportLog.getPreferredScrollableViewportSize());
    builder.append(scrollPane_3, 3);

    layout.setRowSpec(17, new com.jgoodies.forms.layout.RowSpec("fill:pref:grow"));

    // builder.append("Export Status #: ", new JLabel("n"), true);

    if (debugmode)
        FormDebugUtils.dumpAll(builder.getPanel());

    return builder.getPanel();
}

From source file:net.sf.jabref.gui.mergeentries.MergeEntries.java

License:Open Source License

/**
 * Main function for building the merge entry JPanel
 *//* w  ww.  j  ava  2s  .  c  om*/
private void initialize() {

    joint = new TreeSet<>(one.getFieldNames());
    joint.addAll(two.getFieldNames());

    // Remove field starting with __
    TreeSet<String> toberemoved = new TreeSet<>();
    for (String field : joint) {
        if (field.startsWith("__")) {
            toberemoved.add(field);
        }
    }

    for (String field : toberemoved) {
        joint.remove(field);
    }

    // Create storage arrays
    rb = new JRadioButton[3][joint.size() + 1];
    ButtonGroup[] rbg = new ButtonGroup[joint.size() + 1];
    identical = new Boolean[joint.size() + 1];
    jointStrings = new String[joint.size()];

    // Create main layout
    String colSpecMain = "left:pref, 5px, center:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, center:3cm:grow";
    String colSpecMerge = "left:pref, 5px, fill:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, fill:3cm:grow";
    String rowSpec = "pref, pref, 10px, fill:5cm:grow, 10px, pref, 10px, fill:3cm:grow";
    StringBuilder rowBuilder = new StringBuilder("");
    for (int i = 0; i < joint.size(); i++) {
        rowBuilder.append("pref, ");
    }
    rowBuilder.append("pref");

    FormLayout mainLayout = new FormLayout(colSpecMain, rowSpec);
    FormLayout mergeLayout = new FormLayout(colSpecMerge, rowBuilder.toString());
    mainPanel.setLayout(mainLayout);
    mergePanel.setLayout(mergeLayout);

    JLabel label = new JLabel(Localization.lang("Use"));
    Font font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));

    mainPanel.add(label, cc.xyw(4, 1, 7, "center, bottom"));

    // Set headings
    JLabel[] headingLabels = new JLabel[6];
    for (int i = 0; i < 6; i++) {
        headingLabels[i] = new JLabel(columnHeadings[i]);
        font = headingLabels[i].getFont();
        headingLabels[i].setFont(font.deriveFont(font.getStyle() | Font.BOLD));
        mainPanel.add(headingLabels[i], cc.xy(1 + (i * 2), 2));

    }

    mainPanel.add(new JSeparator(), cc.xyw(1, 3, 11));

    // Start with entry type
    String type1 = one.getType();
    String type2 = two.getType();

    mergedEntry.setType(type1);
    label = new JLabel(Localization.lang("Entry type"));
    font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
    mergePanel.add(label, cc.xy(1, 1));

    JTextArea type1ta = new JTextArea(type1);
    type1ta.setEditable(false);
    mergePanel.add(type1ta, cc.xy(3, 1));
    if (type1.compareTo(type2) == 0) {
        identical[0] = true;
    } else {
        identical[0] = false;
        rbg[0] = new ButtonGroup();
        for (int k = 0; k < 3; k += 2) {
            rb[k][0] = new JRadioButton();
            rbg[0].add(rb[k][0]);
            mergePanel.add(rb[k][0], cc.xy(5 + (k * 2), 1));
            rb[k][0].addChangeListener(e -> updateAll());
        }
        rb[0][0].setSelected(true);
    }
    JTextArea type2ta = new JTextArea(type2);
    type2ta.setEditable(false);
    mergePanel.add(type2ta, cc.xy(11, 1));

    // For all fields in joint add a row and possibly radio buttons
    int row = 2;
    int maxLabelWidth = -1;
    int tmpLabelWidth = 0;
    for (String field : joint) {
        jointStrings[row - 2] = field;
        label = new JLabel(CaseChangers.UPPER_FIRST.format(field));
        font = label.getFont();
        label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
        mergePanel.add(label, cc.xy(1, row));
        String string1 = one.getField(field);
        String string2 = two.getField(field);
        identical[row - 1] = false;
        if ((string1 != null) && (string2 != null) && (string1.equals(string2))) {
            identical[row - 1] = true;
        }

        tmpLabelWidth = label.getPreferredSize().width;
        if (tmpLabelWidth > maxLabelWidth) {
            maxLabelWidth = tmpLabelWidth;
        }

        if ("abstract".equals(field) || "review".equals(field)) {
            // Treat the abstract and review fields special
            JTextArea tf = new JTextArea();
            tf.setLineWrap(true);
            tf.setEditable(false);
            JScrollPane jsptf = new JScrollPane(tf);

            mergeLayout.setRowSpec(row, RowSpec.decode("center:2cm:grow"));
            mergePanel.add(jsptf, cc.xy(3, row, "f, f"));
            tf.setText(string1);
            tf.setCaretPosition(0);

        } else {
            JTextArea tf = new JTextArea(string1);
            mergePanel.add(tf, cc.xy(3, row));
            tf.setCaretPosition(0);
            tf.setEditable(false);
        }

        // Add radio buttons if the two entries do not have identical fields
        if (identical[row - 1]) {
            mergedEntry.setField(field, string1);
        } else {
            rbg[row - 1] = new ButtonGroup();
            for (int k = 0; k < 3; k++) {
                rb[k][row - 1] = new JRadioButton();
                rbg[row - 1].add(rb[k][row - 1]);
                mergePanel.add(rb[k][row - 1], cc.xy(5 + (k * 2), row));
                rb[k][row - 1].addChangeListener(e -> updateAll());
            }
            if (string1 == null) {
                rb[0][row - 1].setEnabled(false);
                mergedEntry.setField(field, string2);
                rb[2][row - 1].setSelected(true);
            } else {
                mergedEntry.setField(field, string1);
                rb[0][row - 1].setSelected(true);
                if (string2 == null) {
                    rb[2][row - 1].setEnabled(false);
                }
            }
        }

        if ("abstract".equals(field) || "review".equals(field)) {
            // Again, treat abstract and review special
            JTextArea tf = new JTextArea();
            tf.setLineWrap(true);
            tf.setEditable(false);
            JScrollPane jsptf = new JScrollPane(tf);

            mergePanel.add(jsptf, cc.xy(11, row, "f, f"));
            tf.setText(string2);
            tf.setCaretPosition(0);

        } else {
            JTextArea tf = new JTextArea(string2);
            mergePanel.add(tf, cc.xy(11, row));
            tf.setCaretPosition(0);
            tf.setEditable(false);
        }

        row++;
    }

    JScrollPane scrollPane = new JScrollPane(mergePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    mainPanel.add(scrollPane, cc.xyw(1, 4, 11));
    mainPanel.add(new JSeparator(), cc.xyw(1, 5, 11));

    // Synchronize column widths
    String[] rbAlign = { "right", "center", "left" };
    mainLayout.setColumnSpec(1, ColumnSpec.decode(Integer.toString(maxLabelWidth) + "px"));
    Integer maxRBWidth = -1;
    Integer tmpRBWidth;
    for (int k = 0; k < 3; k++) {
        tmpRBWidth = headingLabels[k + 2].getPreferredSize().width;
        if (tmpRBWidth > maxRBWidth) {
            maxRBWidth = tmpRBWidth;
        }
    }
    for (int k = 0; k < 3; k++) {
        mergeLayout.setColumnSpec(5 + (k * 2), ColumnSpec.decode(rbAlign[k] + ":" + maxRBWidth + "px"));
    }

    // Setup a PreviewPanel and a Bibtex source box for the merged entry
    label = new JLabel(Localization.lang("Merged entry"));
    font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
    mainPanel.add(label, cc.xyw(1, 6, 6));

    String layoutString = Globals.prefs.get(JabRefPreferences.PREVIEW_0);
    pp = new PreviewPanel(null, mergedEntry, null, new MetaData(), layoutString);
    // JScrollPane jsppp = new JScrollPane(pp, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    mainPanel.add(pp, cc.xyw(1, 8, 6));

    label = new JLabel(Localization.lang("Merged BibTeX source code"));
    font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
    mainPanel.add(label, cc.xyw(8, 6, 4));

    jta = new JTextArea();
    jta.setLineWrap(true);
    JScrollPane jspta = new JScrollPane(jta);
    mainPanel.add(jspta, cc.xyw(8, 8, 4));
    jta.setEditable(false);
    StringWriter sw = new StringWriter();
    try {
        new BibEntryWriter(new LatexFieldFormatter(), false).write(mergedEntry, sw, type);
    } catch (IOException ex) {
        LOGGER.error("Error in entry" + ": " + ex.getMessage(), ex);
    }
    jta.setText(sw.getBuffer().toString());
    jta.setCaretPosition(0);

    // Add some margin around the layout
    mainLayout.appendRow(RowSpec.decode(MARGIN));
    mainLayout.appendColumn(ColumnSpec.decode(MARGIN));
    mainLayout.insertRow(1, RowSpec.decode(MARGIN));
    mainLayout.insertColumn(1, ColumnSpec.decode(MARGIN));

    if (mainPanel.getHeight() > DIM.height) {
        mainPanel.setSize(new Dimension(mergePanel.getWidth(), DIM.height));
    }
    if (mainPanel.getWidth() > DIM.width) {
        mainPanel.setSize(new Dimension(DIM.width, mergePanel.getHeight()));
    }

    // Everything done, allow any action to actually update the merged entry
    doneBuilding = true;

    // Show what we've got
    mainPanel.setVisible(true);
    javax.swing.SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0));
}

From source file:net.sf.jabref.gui.MergeEntriesDialog.java

License:Open Source License

private void init(BibtexEntry[] selected) {

    // Check if there are two entries selected
    if (selected.length != 2) { // None selected. Inform the user to select entries first.
        JOptionPane.showMessageDialog(frame, Globals.lang("You have to choose exactly two entries to merge."),
                Globals.lang("Merge entries"), JOptionPane.INFORMATION_MESSAGE);
        this.dispose();
        return;//  w  ww . j av  a2 s .c  om
    }

    // Store the two entries
    one = selected[0];
    two = selected[1];

    // Create undo-compound
    ce = new NamedCompound(Globals.lang("Merge entries"));

    joint = new TreeSet<String>(one.getAllFields());
    joint.addAll(two.getAllFields());

    // Remove field starting with __
    Set<String> toberemoved = new TreeSet<String>();
    for (String field : joint) {
        if (field.startsWith("__")) {
            toberemoved.add(field);
        }
    }

    for (String field : toberemoved) {
        joint.remove(field);
    }

    // Create storage arrays
    rb = new JRadioButton[3][joint.size() + 1];
    ButtonGroup[] rbg = new ButtonGroup[joint.size() + 1];
    identical = new Boolean[joint.size() + 1];
    jointStrings = new String[joint.size()];

    // Create layout
    String colSpec = "left:pref, 5px, fill:4cm:grow, 5px, right:pref, 3px, center:pref, 3px, left:pref, 5px, fill:4cm:grow";
    StringBuilder rowBuilder = new StringBuilder("pref, 10px, pref, ");
    for (int i = 0; i < joint.size(); i++) {
        rowBuilder.append("pref, ");
    }
    rowBuilder.append("10px, top:4cm:grow, 10px, pref");

    FormLayout layout = new FormLayout(colSpec, rowBuilder.toString());
    // layout.setColumnGroups(new int[][] {{3, 11}});
    this.setLayout(layout);

    // Set headings
    for (int i = 0; i < 6; i++) {
        JLabel label = new JLabel(columnHeadings[i]);
        Font font = label.getFont();
        label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
        this.add(label, cc.xy(1 + (i * 2), 1));

    }

    this.add(new JSeparator(), cc.xyw(1, 2, 11));

    // Start with entry type
    BibtexEntryType type1 = one.getType();
    BibtexEntryType type2 = two.getType();

    mergedEntry.setType(type1);
    JLabel label = new JLabel(Globals.lang("Entry type"));
    Font font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
    this.add(label, cc.xy(1, 3));

    JTextArea type1ta = new JTextArea(type1.getName());
    type1ta.setEditable(false);
    this.add(type1ta, cc.xy(3, 3));
    if (type1.compareTo(type2) != 0) {
        identical[0] = false;
        rbg[0] = new ButtonGroup();
        for (int k = 0; k < 3; k += 2) {
            rb[k][0] = new JRadioButton();
            rbg[0].add(rb[k][0]);
            this.add(rb[k][0], cc.xy(5 + (k * 2), 3));
            rb[k][0].addChangeListener(new ChangeListener() {

                @Override
                public void stateChanged(ChangeEvent e) {
                    updateAll();
                }
            });
        }
        rb[0][0].setSelected(true);
    } else {
        identical[0] = true;
    }
    JTextArea type2ta = new JTextArea(type2.getName());
    type2ta.setEditable(false);
    this.add(type2ta, cc.xy(11, 3));

    // For all fields in joint add a row and possibly radio buttons
    int row = 4;
    for (String field : joint) {
        jointStrings[row - 4] = field;
        label = new JLabel(StringUtil.toUpperFirstLetter(field));
        font = label.getFont();
        label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
        this.add(label, cc.xy(1, row));
        String string1 = one.getField(field);
        String string2 = two.getField(field);
        identical[row - 3] = false;
        if ((string1 != null) && (string2 != null)) {
            if (string1.equals(string2)) {
                identical[row - 3] = true;
            }
        }

        if (field.equals("abstract")) {
            // Treat the abstract field special, maybe more fields? Review? Note?
            JTextArea tf = new JTextArea();
            tf.setLineWrap(true);
            tf.setEditable(false);
            JScrollPane jsptf = new JScrollPane(tf);

            layout.setRowSpec(row, RowSpec.decode("center:2cm:grow"));
            this.add(jsptf, cc.xy(3, row, "f, f"));
            tf.setText(string1);
            tf.setCaretPosition(0);

        } else {
            JTextArea tf = new JTextArea(string1);
            this.add(tf, cc.xy(3, row));
            tf.setCaretPosition(0);
            tf.setEditable(false);
        }

        // Add radio buttons if the two entries do not have identical fields
        if (!identical[row - 3]) {
            rbg[row - 3] = new ButtonGroup();
            for (int k = 0; k < 3; k++) {
                rb[k][row - 3] = new JRadioButton();
                rbg[row - 3].add(rb[k][row - 3]);
                this.add(rb[k][row - 3], cc.xy(5 + (k * 2), row));
                rb[k][row - 3].addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        updateAll();
                    }
                });
            }
            if (string1 != null) {
                mergedEntry.setField(field, string1);
                rb[0][row - 3].setSelected(true);
            } else {
                mergedEntry.setField(field, string2);
                rb[2][row - 3].setSelected(true);
            }
        } else {
            mergedEntry.setField(field, string1);
        }
        if (field.equals("abstract")) {
            // Again, treat abstract special
            JTextArea tf = new JTextArea();
            tf.setLineWrap(true);
            tf.setEditable(false);
            JScrollPane jsptf = new JScrollPane(tf);

            this.add(jsptf, cc.xy(11, row, "f, f"));
            tf.setText(string2);
            tf.setCaretPosition(0);

        } else {
            JTextArea tf = new JTextArea(string2);
            this.add(tf, cc.xy(11, row));
            tf.setCaretPosition(0);
            tf.setEditable(false);
        }

        row++;
    }

    this.add(new JSeparator(), cc.xyw(1, row, 11));
    row++;

    // Setup a PreviewPanel and a Bibtex source box for the merged entry
    label = new JLabel(Globals.lang("Merged entry"));
    font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
    this.add(label, cc.xy(1, row));

    String layoutString = Globals.prefs.get(JabRefPreferences.PREVIEW_0);
    pp = new PreviewPanel(null, mergedEntry, null, new MetaData(), layoutString);
    // JScrollPane jsppp = new JScrollPane(pp);
    this.add(pp, cc.xyw(3, row, 3));

    jta = new JTextArea();
    jta.setLineWrap(true);
    JScrollPane jspta = new JScrollPane(jta);
    this.add(jspta, cc.xyw(9, row, 3));
    jta.setEditable(false);
    StringWriter sw = new StringWriter();
    try {
        mergedEntry.write(sw, new LatexFieldFormatter(), false);
    } catch (IOException ex) {
        System.err.println(Globals.lang("Error in entry" + ": " + ex.getMessage()));
    }
    jta.setText(sw.getBuffer().toString());
    jta.setCaretPosition(0);
    row++;
    this.add(new JSeparator(), cc.xyw(1, row, 11));
    row++;

    // Create buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton cancel = new JButton(Globals.lang("Cancel"));
    cancel.setActionCommand("cancel");
    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            buttonPressed(e.getActionCommand());
        }
    });

    JButton newentry = new JButton(Globals.lang("Add new entry and keep both old entries"));
    newentry.setActionCommand("newentry");
    newentry.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            buttonPressed(e.getActionCommand());
        }
    });

    JButton replaceentries = new JButton(Globals.lang("Replace old entries with new entry"));
    replaceentries.setActionCommand("replace");
    replaceentries.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            buttonPressed(e.getActionCommand());
        }
    });

    bb.addButton(new JButton[] { replaceentries, newentry, cancel });
    this.add(bb.getPanel(), cc.xyw(1, row, 11));

    // Add some margin around the layout
    layout.appendRow(RowSpec.decode("10px"));
    layout.appendColumn(ColumnSpec.decode("10px"));
    layout.insertRow(1, RowSpec.decode("10px"));
    layout.insertColumn(1, ColumnSpec.decode("10px"));

    pack();

    if (getHeight() > DIM.height) {
        setSize(new Dimension(getWidth(), DIM.height));
    }
    if (getWidth() > DIM.width) {
        setSize(new Dimension(DIM.width, getHeight()));
    }

    // Everything done, allow any action to actually update the merged entry
    doneBuilding = true;

    // Show what we've got
    setVisible(true);

}

From source file:org.apache.cayenne.modeler.dialog.objentity.ObjAttributeInfoDialogView.java

License:Apache License

public ObjAttributeInfoDialogView(final ProjectController mediator) {

    this.mediator = mediator;

    // create widgets
    this.cancelButton = new JButton("Cancel");
    this.saveButton = new JButton("Done");
    this.selectPathButton = new JButton("Select path");

    this.attributeName = new JTextField(25);
    this.currentPathLabel = new JLabel();
    this.sourceEntityLabel = new JLabel();

    this.typeComboBox = Application.getWidgetFactory().createComboBox(ModelerUtil.getRegisteredTypeNames(),
            false);/*from   ww w . j  av  a  2 s. com*/
    AutoCompletion.enable(typeComboBox, false, true);
    typeComboBox.getRenderer();

    overrideAttributeTable = new CayenneTable();
    tablePreferences = new TableColumnPreferences(getClass(), "overrideAttributeTable");

    getRootPane().setDefaultButton(saveButton);
    saveButton.setEnabled(false);
    cancelButton.setEnabled(true);
    selectPathButton.setEnabled(false);

    setTitle("ObjAttribute Inspector");
    setLayout(new BorderLayout());

    CellConstraints cc = new CellConstraints();
    final PanelBuilder builder = new PanelBuilder(
            new FormLayout("right:max(50dlu;pref), 3dlu, 200dlu, 15dlu, right:max(30dlu;pref), 3dlu, 200dlu",
                    "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 6dlu, p, 6dlu, p, 3dlu, fill:p:grow"));
    builder.setDefaultDialogBorder();
    builder.addSeparator("ObjAttribute Information", cc.xywh(1, 1, 7, 1));

    builder.addLabel("Entity:", cc.xy(1, 3));
    builder.add(sourceEntityLabel, cc.xywh(3, 3, 1, 1));

    builder.addLabel("Attribute Name:", cc.xy(1, 5));
    builder.add(attributeName, cc.xywh(3, 5, 1, 1));

    builder.addLabel("Current Db Path:", cc.xy(1, 7));
    builder.add(currentPathLabel, cc.xywh(3, 7, 5, 1));

    builder.addLabel("Type:", cc.xy(1, 9));
    builder.add(typeComboBox, cc.xywh(3, 9, 1, 1));

    builder.addSeparator("Mapping to DbAttributes", cc.xywh(1, 11, 7, 1));

    typeManagerPane = new JPanel();
    typeManagerPane.setLayout(new CardLayout());

    final FormLayout fL = new FormLayout("493dlu ", "p, 3dlu, fill:min(128dlu;pref):grow");

    // panel for Flattened attribute
    final PanelBuilder builderPathPane = new PanelBuilder(fL);

    JPanel buttonsPane = new JPanel(new FlowLayout(FlowLayout.LEADING));
    buttonsPane.add(selectPathButton);

    builderPathPane.add(buttonsPane, cc.xywh(1, 1, 1, 1));
    pathBrowser = new ObjAttributePathBrowser(selectPathButton, saveButton);
    pathBrowser.setPreferredColumnSize(BROWSER_CELL_DIM);
    pathBrowser.setDefaultRenderer();
    builderPathPane.add(new JScrollPane(pathBrowser, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), cc.xywh(1, 3, 1, 1));

    // panel for embeddable attribute
    final FormLayout fLEmb = new FormLayout("493dlu ", "fill:min(140dlu;pref):grow");

    final PanelBuilder embeddablePane = new PanelBuilder(fLEmb);

    embeddablePane.add(new JScrollPane(overrideAttributeTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), cc.xywh(1, 1, 1, 1));

    typeManagerPane.add(builderPathPane.getPanel(), FLATTENED_PANEL);
    typeManagerPane.add(embeddablePane.getPanel(), EMBEDDABLE_PANEL);

    builder.add(typeManagerPane, cc.xywh(1, 13, 7, 1));

    add(builder.getPanel(), BorderLayout.CENTER);

    this.addComponentListener(new ComponentListener() {

        int height;

        public void componentHidden(ComponentEvent e) {
        }

        public void componentMoved(ComponentEvent e) {
        }

        public void componentResized(ComponentEvent e) {
            int delta = e.getComponent().getHeight() - height;
            if (delta < 0) {
                fL.setRowSpec(3, RowSpec.decode("fill:min(10dlu;pref):grow"));
                fLEmb.setRowSpec(1, RowSpec.decode("fill:min(10dlu;pref):grow"));
            }
        }

        public void componentShown(ComponentEvent e) {
            height = e.getComponent().getHeight();
        }
    });

    JButton[] buttons = { cancelButton, saveButton };
    add(PanelFactory.createButtonPanel(buttons), BorderLayout.SOUTH);

    typeComboBox.addActionListener(e -> {
        boolean isType = false;
        String[] typeNames = ModelerUtil.getRegisteredTypeNames();
        for (String typeName : typeNames) {
            if (typeComboBox.getSelectedItem() == null
                    || typeName.equals(typeComboBox.getSelectedItem().toString())) {
                isType = true;
            }
        }

        if (isType || !mediator.getEmbeddableNamesInCurrentDataDomain()
                .contains((String) typeComboBox.getSelectedItem())) {
            ((CardLayout) typeManagerPane.getLayout()).show(typeManagerPane, FLATTENED_PANEL);
        } else {
            ((CardLayout) typeManagerPane.getLayout()).show(typeManagerPane, EMBEDDABLE_PANEL);
            getCurrentPathLabel().setText("");
        }
    });
}