Example usage for com.jgoodies.forms.layout CellConstraints xyw

List of usage examples for com.jgoodies.forms.layout CellConstraints xyw

Introduction

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

Prototype

public CellConstraints xyw(int col, int row, int colSpan, String encodedAlignments) 

Source Link

Document

Sets the column, row, width, and height; decodes the horizontal and vertical alignments from the given string.

Usage

From source file:ca.sqlpower.architect.swingui.CompareDMFrame.java

License:Open Source License

public JComponent mainFrame() {

    FormLayout layout = new FormLayout(
            "4dlu,fill:min(150dlu;default):grow, 6dlu, fill:min(150dlu;default):grow, 4dlu", // columns //$NON-NLS-1$
            " min(300dlu;default), 6dlu, min(300dlu;default), 6dlu,  min(300dlu;default), 3dlu, fill:min(300dlu;default):grow, 3dlu, 20dlu,6dlu,20dlu"); // rows //$NON-NLS-1$

    CellConstraints cc = new CellConstraints();
    JLabel titleLabel = new JLabel(title);
    Font oldFont = titleLabel.getFont();
    Font titleFont = new Font(oldFont.getName(), oldFont.getStyle(), oldFont.getSize() * 2);

    titleLabel.setFont(titleFont);/*from w  w  w .j  a  va2s .co m*/
    JLabel subTitleLabel = new JLabel(whatTheHeckIsGoingOn);
    leftOutputArea = new JTextPane();
    leftOutputArea.setMargin(new Insets(6, 10, 4, 6));
    leftOutputArea.setDocument(sourceOutputText);
    leftOutputArea.setEditable(false);
    JPanel comparePanel = new JPanel(new GridLayout(1, 2));
    JScrollPane sp = new JScrollPane(comparePanel);

    int lineHeight = 16;
    try {
        FontMetrics fm = leftOutputArea.getFontMetrics(leftOutputArea.getFont());
        lineHeight = fm.getHeight() + 2;
    } catch (Exception e) {
        lineHeight = 16;
    }
    // If the increments are not set, klicking on the up or down arrow of the scrollbar
    // will scroll the display by one pixel, which is definitely not what the user wants
    // by setting unitIncrement to the font's height the display will scroll by approx. one line
    sp.getVerticalScrollBar().setUnitIncrement(lineHeight);

    // Clicking in the "empty" area of the scrollbar will scroll by 10 lines
    sp.getVerticalScrollBar().setBlockIncrement(lineHeight * 10);

    comparePanel.add(leftOutputArea);
    Action sourceCopy = new sourceCopyAction(sourceOutputText);

    Action sourceSave = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            SPSUtils.saveDocument(CompareDMFrame.this, sourceOutputText,
                    (FileExtensionFilter) SPSUtils.TEXT_FILE_FILTER);
        }
    };
    CloseAction close = new CloseAction();
    close.setDialog(this);
    SPSUtils.makeJDialogCancellable(this, close);

    ButtonBarBuilder sourcebbBuilder = new ButtonBarBuilder();
    JButton copySource = new JButton(sourceCopy);
    copySource.setText(Messages.getString("CompareDMFrame.copy")); //$NON-NLS-1$
    sourcebbBuilder.addGridded(copySource);
    sourcebbBuilder.addRelatedGap();
    sourcebbBuilder.addGlue();

    JButton sourceSaveButton = new JButton(sourceSave);
    sourceSaveButton.setText(Messages.getString("CompareDMFrame.save")); //$NON-NLS-1$
    sourcebbBuilder.addGridded(sourceSaveButton);
    sourcebbBuilder.addRelatedGap();
    sourcebbBuilder.addGlue();

    ButtonBarBuilder closeBar = new ButtonBarBuilder();
    JButton closeButton = new JButton(close);
    closeButton.setText(Messages.getString("CompareDMFrame.close")); //$NON-NLS-1$
    closeBar.addGridded(closeButton);
    PanelBuilder pb;

    layout.setColumnGroups(new int[][] { { 2, 4 } });
    JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);

    pb = new PanelBuilder(layout, p);
    pb.setDefaultDialogBorder();

    rightOutputArea = new JTextPane();
    rightOutputArea.setMargin(new Insets(6, 10, 4, 6));
    rightOutputArea.setDocument(targetOutputText);
    rightOutputArea.setEditable(false);
    comparePanel.add(rightOutputArea);
    Action targetCopy = new targetCopyAction(targetOutputText);
    //Sets the target Buttons
    ButtonBarBuilder targetbbBuilder = new ButtonBarBuilder();
    JButton copyTarget = new JButton(targetCopy);
    copyTarget.setText(Messages.getString("CompareDMFrame.copy")); //$NON-NLS-1$
    targetbbBuilder.addGridded(copyTarget);
    targetbbBuilder.addRelatedGap();
    targetbbBuilder.addGlue();

    Action targetSaveAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            SPSUtils.saveDocument(CompareDMFrame.this, targetOutputText,
                    (FileExtensionFilter) SPSUtils.TEXT_FILE_FILTER);
        }
    };

    JButton targetSave = new JButton(targetSaveAction);
    targetSave.setText(Messages.getString("CompareDMFrame.save")); //$NON-NLS-1$
    targetbbBuilder.addGridded(targetSave);
    targetbbBuilder.addRelatedGap();
    targetbbBuilder.addGlue();
    getRootPane().setDefaultButton(targetSave);

    pb.add(titleLabel, cc.xyw(2, 1, 3, "c,c")); //$NON-NLS-1$
    pb.add(subTitleLabel, cc.xyw(2, 3, 3, "c,c")); //$NON-NLS-1$
    pb.add(new JLabel(Messages.getString("CompareDMFrame.older")), cc.xy(2, 5)); //$NON-NLS-1$
    pb.add(new JLabel(Messages.getString("CompareDMFrame.newer")), cc.xy(4, 5)); //$NON-NLS-1$
    pb.add(sp, cc.xyw(2, 7, 3));
    pb.add(sourcebbBuilder.getPanel(), cc.xy(2, 9, "l,c")); //$NON-NLS-1$
    pb.add(targetbbBuilder.getPanel(), cc.xy(4, 9, "r,c")); //$NON-NLS-1$
    pb.add(closeBar.getPanel(), cc.xy(4, 11, "r,c")); //$NON-NLS-1$

    return pb.getPanel();
}

From source file:ca.sqlpower.matchmaker.swingui.engine.EngineSettingsPanel.java

License:Open Source License

/**
 * Builds the UI for this editor pane. This is broken into two parts,
 * the configuration and output. Configuration is done in this method
 * while the output section is handled by the EngineOutputPanel and
 * this method simply lays out the components that class provides.
 *//*from  w  w w .j  av  a2  s . c  o  m*/
private JPanel buildUI() {

    logger.debug("We are building the UI of an engine settings panel.");
    if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        expiryDatePane = new JEditorPane();
        expiryDatePane.setEditable(false);
        final AddressDatabase addressDatabase;
        try {
            addressDatabase = new AddressDatabase(
                    new File(swingSession.getContext().getAddressCorrectionDataPath()));
            expiryDate = addressDatabase.getExpiryDate();
            expiryDatePane.setText(DateFormat.getDateInstance().format(expiryDate));
        } catch (DatabaseException e1) {
            MMSUtils.showExceptionDialog(parentFrame,
                    "An error occured while loading the Address Correction Data", e1);
            expiryDatePane.setText("Database missing, expiry date invalid");
        }

        logger.debug("We are adding the listener");
        swingSession.getContext().addPreferenceChangeListener(new PreferenceChangeListener() {
            public void preferenceChange(PreferenceChangeEvent evt) {
                if (MatchMakerSessionContext.ADDRESS_CORRECTION_DATA_PATH.equals(evt.getKey())) {
                    logger.debug("The new database path is: " + evt.getNewValue());
                    final AddressDatabase addressDatabase;
                    try {
                        addressDatabase = new AddressDatabase(new File(evt.getNewValue()));
                        expiryDate = addressDatabase.getExpiryDate();
                        expiryDatePane.setText(DateFormat.getDateInstance().format(expiryDate));
                    } catch (DatabaseException ex) {
                        MMSUtils.showExceptionDialog(parentFrame,
                                "An error occured while loading the Address Correction Data", ex);
                        expiryDate = null;
                        expiryDatePane.setText("Database missing, expiry date invalid");
                    }
                }
            }
        });
        // handler listens to expiryDatePane so whenever the expiryDatePane's text has been changed, the below method will be called.
        handler.addValidateObject(expiryDatePane, new Validator() {
            public ValidateResult validate(Object contents) {
                if (expiryDate == null) {
                    return ValidateResult.createValidateResult(Status.FAIL,
                            "Address Correction Database is missing. Please reset your Address Correction Data Path in Preferences.");
                }
                if (Calendar.getInstance().getTime().after(expiryDate)) {
                    return ValidateResult.createValidateResult(Status.WARN,
                            "Address Correction Database is expired. The results of this engine run cannot be SERP valid.");
                }
                return ValidateResult.createValidateResult(Status.OK, "");
            }
        });
    }

    File logFile = engineSettings.getLog();

    logFilePath = new JTextField(logFile.getAbsolutePath());
    handler.addValidateObject(logFilePath, new FileNameValidator("Log"));

    browseLogFileAction = new BrowseFileAction(parentFrame, logFilePath);

    appendToLog = new JCheckBox("Append to old Log File?", engineSettings.getAppendToLog());

    recordsToProcess = new JSpinner(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 100));
    if (engineSettings.getProcessCount() != null) {
        recordsToProcess.setValue(engineSettings.getProcessCount());
    }

    spinnerUpdateManager = new SpinnerUpdateManager(recordsToProcess, engineSettings, "processCount", handler,
            this, refreshButton);

    debugMode = new JCheckBox("Debug Mode (Changes will be rolled back)", engineSettings.getDebug());
    updaters.add(new CheckBoxModelUpdater(debugMode, "debug"));
    engineSettings.addSPListener(updaters.get(updaters.size() - 1));
    itemListener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (((JCheckBox) e.getSource()).isSelected()) {
                if (type == EngineType.MATCH_ENGINE || type == EngineType.ADDRESS_CORRECTION_ENGINE) {
                    clearMatchPool.setSelected(false);
                    // I've currently disabled the clear match pool option because the match
                    // in debug mode, changes should be rolled back, but if the clearing of the match
                    // pool is rolled back but the engine thinks that it is cleared, it can cause
                    // unique key violations when it tries to insert 'new' matches. But if the engine
                    // is made aware of the rollback, then it would be as if clear match pool wasn't
                    // selected in the first place, so I don't see the point in enabling it in debug mode
                    clearMatchPool.setEnabled(false);
                }
                recordsToProcess.setValue(new Integer(1));
                engine.setMessageLevel(Level.ALL);
                messageLevel.setSelectedItem(engine.getMessageLevel());
            } else {
                if (type == EngineType.MATCH_ENGINE || type == EngineType.ADDRESS_CORRECTION_ENGINE) {
                    clearMatchPool.setEnabled(true);
                }
                recordsToProcess.setValue(new Integer(0));
            }
            engineSettings.setDebug(debugMode.isSelected());
        }
    };
    debugMode.addItemListener(itemListener);

    if (type == EngineType.MATCH_ENGINE || type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        if (type == EngineType.MATCH_ENGINE) {
            clearMatchPool = new JCheckBox("Clear match pool",
                    ((MungeSettings) engineSettings).isClearMatchPool());
        } else {
            clearMatchPool = new JCheckBox("Clear address pool",
                    ((MungeSettings) engineSettings).isClearMatchPool());
        }
        itemListener = new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                ((MungeSettings) engineSettings).setClearMatchPool(clearMatchPool.isSelected());
            }
        };
        clearMatchPool.addItemListener(itemListener);
        updaters.add(new CheckBoxModelUpdater(clearMatchPool, "clearMatchPool"));
        engineSettings.addSPListener(updaters.get(updaters.size() - 1));
        if (debugMode.isSelected()) {
            clearMatchPool.setSelected(false);
            // See comment just above about why this is disabled
            clearMatchPool.setEnabled(false);
        }
    }

    if (engineSettings instanceof MungeSettings) {
        useBatchExecute = new JCheckBox("Batch execute SQL statments",
                ((MungeSettings) engineSettings).isUseBatchExecution());
        itemListener = new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                ((MungeSettings) engineSettings).setUseBatchExecution(useBatchExecute.isSelected());
            }
        };
        useBatchExecute.addItemListener(itemListener);
        updaters.add(new CheckBoxModelUpdater(useBatchExecute, "useBatchExecution"));
        engineSettings.addSPListener(updaters.get(updaters.size() - 1));
    }

    if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        autoWriteAutoValidatedAddresses = new JCheckBox("Immediately commit auto-corrected addresses",
                ((MungeSettings) engineSettings).isAutoWriteAutoValidatedAddresses());
        itemListener = new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                ((MungeSettings) engineSettings)
                        .setAutoWriteAutoValidatedAddresses(autoWriteAutoValidatedAddresses.isSelected());
            }
        };
        autoWriteAutoValidatedAddresses.addItemListener(itemListener);
        updaters.add(
                new CheckBoxModelUpdater(autoWriteAutoValidatedAddresses, "autoWriteAutoValidatedAddresses"));
        engineSettings.addSPListener(updaters.get(updaters.size() - 1));
    }

    messageLevel = new JComboBox(new Level[] { Level.OFF, Level.FATAL, Level.ERROR, Level.WARN, Level.INFO,
            Level.DEBUG, Level.ALL });
    messageLevel.setSelectedItem(engine.getMessageLevel());
    messageLevel.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setText(value == null ? null : value.toString());
            return this;
        }
    });

    messageLevelActionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Level sel = (Level) messageLevel.getSelectedItem();
            engine.setMessageLevel(sel);
        }
    };
    messageLevel.addActionListener(messageLevelActionListener);

    String rowSpecs;
    if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        rowSpecs = ADDRESS_CORRECTION_ENGINE_PANEL_ROW_SPECS;
    } else if (type == EngineType.VALIDATED_ADDRESS_COMMITING_ENGINE) {
        rowSpecs = ADDRESS_COMMITTING_ENGINE_PANEL_ROW_SPECS;
    } else if (type == EngineType.MERGE_ENGINE) {
        rowSpecs = MERGE_ENGINE_PANEL_ROW_SPECS;
    } else if (type == EngineType.CLEANSE_ENGINE) {
        rowSpecs = CLEANSE_ENGINE_PANEL_ROW_SPECS;
    } else {
        rowSpecs = MATCH_ENGINE_PANEL_ROW_SPECS;
    }

    String columnSpecs = "4dlu,fill:pref,4dlu,pref,pref,40dlu,fill:pref:grow,pref,4dlu";

    FormLayout layout = new FormLayout(columnSpecs, rowSpecs);

    PanelBuilder pb;
    JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);
    pb = new PanelBuilder(layout, p);

    CellConstraints cc = new CellConstraints();

    pb.add(status, cc.xyw(4, 2, 6, "l,c"));
    pb.add(refreshButton, cc.xy(6, 2, "l, c"));
    refreshButton.setVisible(false);

    int y = 4;
    pb.add(new JLabel("Log File:"), cc.xy(2, y, "r,f"));
    pb.add(logFilePath, cc.xyw(4, y, 4, "f,f"));
    pb.add(new JButton(browseLogFileAction), cc.xy(8, y, "l,f"));
    y += 2;
    pb.add(appendToLog, cc.xy(4, y, "l,t"));
    pb.add(new JButton(new ShowLogFileAction(logFilePath)), cc.xy(5, y, "r,t"));

    if (type == EngineType.MATCH_ENGINE || type == EngineType.CLEANSE_ENGINE) {
        y += 2;

        pb.add(new JLabel("Tranformations to run: "), cc.xy(2, y, "r,t"));
        final MungeProcessSelectionList selectionButton = new MungeProcessSelectionList(project) {
            @Override
            public boolean getValue(MungeProcess mp) {
                return mp.getActive();
            }

            @Override
            public void setValue(MungeProcess mp, boolean value) {
                mp.setActive(value);
            }
        };

        activeListener = new AbstractPoolingSPListener() {
            boolean isSelectionListUpdate = false;

            @Override
            protected void finalCommitImpl(TransactionEvent e) {
                if (isSelectionListUpdate) {
                    selectionButton.checkModel();
                }
            }

            @Override
            public void propertyChangeImpl(PropertyChangeEvent evt) {
                logger.debug("checking property with name " + evt.getPropertyName());
                if (evt.getPropertyName().equals("active")) {
                    isSelectionListUpdate = true;
                } else {
                    isSelectionListUpdate = false;
                }
            }
        };

        swingSession.getRootNode().addSPListener(activeListener);
        for (MungeProcess mp : project.getMungeProcesses()) {
            mp.addSPListener(activeListener);
        }

        newMungeProcessListener = new AbstractSPListener() {
            @Override
            public void childAdded(SPChildEvent e) {
                selectionButton.refreshList();
            }

            @Override
            public void childRemoved(SPChildEvent e) {
                selectionButton.refreshList();
            }
        };
        project.addSPListener(newMungeProcessListener);

        pb.add(selectionButton, cc.xyw(4, y, 2, "l,c"));
    }

    y += 2;
    pb.add(new JLabel("# of records to process:"), cc.xy(2, y, "r,c"));
    pb.add(recordsToProcess, cc.xy(4, y, "l,c"));
    pb.add(new JLabel(" (Set to 0 to process all)"), cc.xy(5, y, "l, c"));

    if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        pb.add(new JLabel("Address Filter Setting:"), cc.xy(7, y));
    }

    if (engineSettings instanceof MungeSettings) {
        MungeSettings mungeSettings = (MungeSettings) engineSettings;
        y += 2;
        pb.add(useBatchExecute, cc.xyw(4, y, 2, "l,c"));

        if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
            final JLabel poolSettingLabel = new JLabel(
                    mungeSettings.getPoolFilterSetting().getLongDescription());
            SPListener poolFilterSettingChangeListener = new SPListener() {
                public void childAdded(SPChildEvent evt) {
                    // no-op
                }

                public void childRemoved(SPChildEvent evt) {
                    // no-op
                }

                public void propertyChanged(PropertyChangeEvent evt) {
                    if (evt.getPropertyName() == "poolFilterSetting") {
                        PoolFilterSetting newValue = (PoolFilterSetting) evt.getNewValue();
                        poolSettingLabel.setText(newValue.getLongDescription());
                    }
                }

                public void transactionStarted(TransactionEvent evt) {
                    // no-op
                }

                public void transactionRollback(TransactionEvent evt) {
                    // no-op
                }

                public void transactionEnded(TransactionEvent evt) {

                }

            };
            mungeSettings.addSPListener(poolFilterSettingChangeListener);
            Font f = poolSettingLabel.getFont();
            Font newFont = f.deriveFont(Font.ITALIC);
            poolSettingLabel.setFont(newFont);
            pb.add(poolSettingLabel, cc.xy(7, y));
        }
    }

    if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        y += 2;
        pb.add(autoWriteAutoValidatedAddresses, cc.xyw(4, y, 2, "l,c"));
        if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
            pb.add(new JLabel("Auto-correction Setting:"), cc.xy(7, y));
        }
    }

    if (type == EngineType.MATCH_ENGINE || type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        y += 2;
        pb.add(clearMatchPool, cc.xyw(4, y, 2, "l,c"));
        if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
            MungeSettings mungeSettings = (MungeSettings) engineSettings;
            final JLabel autoValidateSettingLabel = new JLabel(
                    ((MungeSettings) engineSettings).getAutoValidateSetting().getLongDescription());
            SPListener poolFilterSettingChangeListener = new SPListener() {
                public void childAdded(SPChildEvent evt) {
                    // no-op
                }

                public void childRemoved(SPChildEvent evt) {
                    // no-op
                }

                public void propertyChanged(PropertyChangeEvent evt) {
                    if (evt.getPropertyName() == "autoValidateSetting") {
                        AutoValidateSetting newValue = (AutoValidateSetting) evt.getNewValue();
                        autoValidateSettingLabel.setText(newValue.getLongDescription());
                    }
                }

                public void transactionStarted(TransactionEvent evt) {
                    // no-op
                }

                public void transactionRollback(TransactionEvent evt) {
                    // no-op
                }

                public void transactionEnded(TransactionEvent evt) {
                    // no-op
                }
            };
            mungeSettings.addSPListener(poolFilterSettingChangeListener);
            Font f = autoValidateSettingLabel.getFont();
            Font newFont = f.deriveFont(Font.ITALIC);
            autoValidateSettingLabel.setFont(newFont);
            pb.add(autoValidateSettingLabel, cc.xy(7, y));
        }
    }

    y += 2;
    pb.add(debugMode, cc.xyw(4, y, 2, "l,c"));
    if (type == EngineType.ADDRESS_CORRECTION_ENGINE) {
        final AddressValidationSettingsPanel avsp = new AddressValidationSettingsPanel(
                (MungeSettings) engineSettings);
        final JDialog validationSettingsDialog = DataEntryPanelBuilder.createDataEntryPanelDialog(avsp,
                swingSession.getFrame(), "Address Validation Settings", "OK", new Callable<Boolean>() {
                    public Boolean call() throws Exception {
                        boolean returnValue = avsp.applyChanges();
                        return returnValue;
                    }
                }, new Callable<Boolean>() {
                    public Boolean call() throws Exception {
                        return true;
                    }
                });
        validationSettingsDialog.setLocationRelativeTo(pb.getPanel());

        JButton addressValidationSettings = new JButton(new AbstractAction("Validation Settings...") {
            public void actionPerformed(ActionEvent e) {
                validationSettingsDialog.setVisible(true);
            }
        });
        pb.add(addressValidationSettings, cc.xy(7, y, "l,c"));
    }

    y += 2;
    pb.add(new JLabel("Message Level:"), cc.xy(2, y, "r,t"));
    pb.add(messageLevel, cc.xy(4, y, "l,t"));

    abortButton = new JButton(new AbstractAction("Abort!") {
        public void actionPerformed(ActionEvent e) {
            engine.setCancelled(true);
        }
    });

    abortButton.setEnabled(false);

    ButtonBarBuilder bbb = new ButtonBarBuilder();
    bbb.addFixed(new JButton(new SaveAction()));
    bbb.addRelatedGap();
    bbb.addFixed(new JButton(new ShowCommandAction(parentFrame, this, engine)));
    bbb.addRelatedGap();
    bbb.addFixed(new JButton(runEngineAction));
    bbb.addRelatedGap();
    bbb.addFixed(abortButton);

    y += 2;
    pb.add(bbb.getPanel(), cc.xyw(2, y, 7, "r,c"));

    y += 2;
    pb.add(engineOutputPanel.getProgressBar(), cc.xyw(2, y, 7));

    y += 2;
    pb.add(engineOutputPanel.getOutputComponent(), cc.xyw(2, y, 7));

    y += 2;
    pb.add(engineOutputPanel.getButtonBar(), cc.xyw(2, y, 7));

    refreshRunActionStatus();

    return pb.getPanel();
}

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

License:Open Source License

private void buildUI() {
    folderName.setName("Folder Name");
    folderDesc.setName("Folder Description");

    JButton saveButton = new JButton(saveAction);

    FormLayout layout = new FormLayout("4dlu,pref,4dlu,pref,4dlu,pref,4dlu", // columns
            "10dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,10dlu"); // rows
    //       1     2    3    4    5    6    7    8    9

    PanelBuilder pb;//  w w  w  .  ja v a 2 s .c om

    JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);
    pb = new PanelBuilder(layout, p);
    CellConstraints cc = new CellConstraints();

    pb.add(status, cc.xy(4, 2, "l,c"));
    pb.add(refreshButton, cc.xy(6, 2, "l, c"));
    refreshButton.setVisible(false);

    pb.add(new JLabel("Folder Name:"), cc.xy(2, 4, "r,c"));
    pb.add(new JLabel("Description:"), cc.xy(2, 6, "r,c"));

    pb.add(folderName, cc.xy(4, 4, "l,c"));
    pb.add(new JScrollPane(folderDesc), cc.xy(4, 6, "l,c"));

    pb.add(saveButton, cc.xyw(2, 8, 3, "c,c"));
    panel = pb.getPanel();

}

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

License:Open Source License

private void buildUI() {

    String comboMinSize = "fill:min(pref;" + (new JComboBox().getMinimumSize().width) + "px):grow";
    FormLayout layout = new FormLayout(
            "4dlu,pref,4dlu," + comboMinSize + ",4dlu,pref,4dlu," + comboMinSize + ",4dlu,pref,4dlu", // columns
            "10dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,fill:40dlu:grow,4dlu,pref,4dlu"); // rows
    //    1     2    3    4               5    6    7     8         9    10   11      
    //    status    cat       schema    table     index     del dup   table      button bar

    PanelBuilder pb;//w w w.  ja  v  a2  s .c o m
    JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);
    pb = new PanelBuilder(layout, p);
    CellConstraints cc = new CellConstraints();

    int row = 2;
    pb.add(status, cc.xy(4, row));
    row += 2;
    pb.add(new JLabel("Catalog:"), cc.xy(2, row, "r,c"));
    JTextField temp = new JTextField(mmo.getSourceTable().getCatalogName());
    temp.setEditable(false);
    pb.add(temp, cc.xyw(4, row, 5, "f,c"));
    row += 2;

    pb.add(new JLabel("Schema:"), cc.xy(2, row, "r,c"));
    temp = new JTextField(mmo.getSourceTable().getSchemaName());
    temp.setEditable(false);
    pb.add(temp, cc.xyw(4, row, 5, "f,c"));

    row += 2;
    pb.add(new JLabel("Table Name:"), cc.xy(2, row, "r,c"));
    temp = new JTextField(mmo.getTableName());
    temp.setEditable(false);
    pb.add(temp, cc.xyw(4, row, 5, "f,c"));

    row += 2;
    pb.add(new JLabel("Index Name:"), cc.xy(2, row, "r,c"));
    String indexName = "";

    if (mmo.getTableIndex() == null) {
        indexName = "";
    } else {
        indexName = mmo.getTableIndex().getName();
    }

    temp = new JTextField(indexName);
    temp.setEditable(false);
    pb.add(temp, cc.xyw(4, row, 5, "f,c"));

    row += 2;
    if (!mmo.isSourceMergeRule()) {
        pb.add(new JLabel("Parent Table:"), cc.xy(2, row, "l,c"));
        pb.add(parentMergeRule, cc.xy(4, row, "f,c"));
        if (mmo.getParentMergeRule() != null) {
            parentMergeRule.setSelectedItem(mmo.getParentMergeRule().getSourceTable());
        } else {
            parentMergeRule.setSelectedItem(null);
        }
        pb.add(new JLabel("Merge Action:"), cc.xy(6, row, "r,c"));
        pb.add(childMergeAction, cc.xy(8, row, "f,c"));
        childMergeAction.setSelectedItem(mmo.getChildMergeAction());
    }

    row += 2;
    pb.add(new JScrollPane(ruleTable), cc.xyw(4, row, 5, "f,f"));

    row += 2;
    pb.add(new JButton(saveAction), cc.xyw(4, row, 5, "c,c"));
    panel = pb.getPanel();
}

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

License:Open Source License

@Override
protected JPanel buildUI() {
    final SortWordsMungeStep step = getStep();

    useRegex = new JCheckBox("Use Regular Expressions");
    useRegex.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            step.setRegex(useRegex.isSelected());
        }//from  w  ww.  j ava 2 s .c o  m
    });
    useRegex.setSelected(step.isRegex());

    caseSensitive = new JCheckBox("Case Sensitive");
    caseSensitive.setSelected(step.isCaseSensitive());
    caseSensitive.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            step.setCaseSensitive(caseSensitive.isSelected());
        }

    });

    delimiter = new JTextField(step.getDelimiter());
    delimiter.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            step.setDelimiter(delimiter.getText());
        }
    });
    RegexValidator validator = new RegexValidator();
    getHandler().addValidateObject(delimiter, useRegex, validator, true, "");

    resultDelimiter = new JTextField(step.getResultDelim());
    resultDelimiter.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            step.setResultDelim(resultDelimiter.getText());
        }
    });

    FormLayout layout = new FormLayout("4dlu,pref,4dlu,fill:pref:grow,4dlu", // columns
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu"); // rows
    CellConstraints cc = new CellConstraints();

    JPanel content = new JPanel(layout);

    content.add(new JLabel("Delimiter:"), cc.xy(2, 2));
    content.add(delimiter, cc.xy(4, 2));
    content.add(new JLabel("Result Delim:"), cc.xy(2, 4));
    content.add(resultDelimiter, cc.xy(4, 4));

    JPanel bottom = new JPanel(new GridLayout(2, 1));
    bottom.add(useRegex);
    bottom.add(caseSensitive);
    content.add(bottom, cc.xyw(2, 6, 3, "c,f"));

    return content;
}

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

License:Open Source License

@Override
protected JPanel buildUI() {
    StringSubstitutionMungeStep step = (StringSubstitutionMungeStep) getStep();

    useRegex = new JCheckBox("Use Regular Expressions");
    useRegex.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            StringSubstitutionMungeStep step = (StringSubstitutionMungeStep) getStep();
            step.setRegex(useRegex.isSelected());
        }//from  w  w  w.  ja  v a 2 s  . c  o m
    });
    useRegex.setSelected(step.isRegex());

    caseSensitive = new JCheckBox("Case Sensitive");
    caseSensitive.setSelected(step.isCaseSensitive());
    caseSensitive.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            StringSubstitutionMungeStep temp = (StringSubstitutionMungeStep) getStep();
            temp.setCaseSensitive(caseSensitive.isSelected());
        }

    });

    from = new JTextField(step.getFrom());
    from.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            StringSubstitutionMungeStep step = (StringSubstitutionMungeStep) getStep();
            step.setFrom(from.getText());
        }
    });

    to = new JTextField(step.getTo());
    to.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            StringSubstitutionMungeStep step = (StringSubstitutionMungeStep) getStep();
            step.setTo(to.getText());
        }
    });
    RegexValidator validator = new RegexValidator();
    getHandler().addValidateObject(from, useRegex, validator, true, "");

    FormLayout layout = new FormLayout("4dlu,pref,4dlu,fill:pref:grow,4dlu", // columns
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu"); // rows
    CellConstraints cc = new CellConstraints();

    JPanel content = new JPanel(layout);

    content.add(new JLabel("From:"), cc.xy(2, 2));
    content.add(from, cc.xy(4, 2));
    content.add(new JLabel("To:"), cc.xy(2, 4));
    content.add(to, cc.xy(4, 4));

    JPanel bottom = new JPanel(new GridLayout(2, 1));
    bottom.add(useRegex);
    bottom.add(caseSensitive);
    content.add(bottom, cc.xyw(2, 6, 3, "c,f"));

    return content;
}

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

License:Open Source License

@Override
protected JPanel buildUI() {
    JPanel content = new JPanel(new FormLayout("4dlu,pref,4dlu,pref,4dlu",
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu"));
    final StringToDateMungeStep temp = (StringToDateMungeStep) getStep();

    /**/*from  w  ww.j  av a 2s.c  o m*/
     * Gets the lists of formats from the step and converts them into arrays 
     * so that it's easier to make the combo boxes.
     */
    final String[] dateFormats = StringToDateMungeStep.DATE_FORMATS.toArray(new String[] {});
    final String[] timeFormats = StringToDateMungeStep.TIME_FORMATS.toArray(new String[] {});
    final String[] outputFormats = StringToDateMungeStep.OUTPUT_FORMATS.toArray(new String[] {});

    SimpleDateFormat sdf = new SimpleDateFormat(temp.getInputFormat());
    sample = new JTextField(sdf.format(StringToDateMungeComponent.SAMPLE_DATE));
    sample.setEditable(false);

    ignoreError = new JCheckBox("Continue on Error");
    ignoreError.setSelected(((StringToDateMungeStep) getStep()).isIgnoreError());

    ignoreError.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            StringToDateMungeStep temp = (StringToDateMungeStep) getStep();
            temp.setIgnoreError(ignoreError.isSelected());
        }

    });

    dateFormat = new JComboBox(dateFormats);
    dateFormat.setSelectedItem(temp.getDateFormat());
    dateFormat.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            temp.setDateFormat((String) e.getItem());
            inputFormat.setText(temp.getInputFormat());
        }
    });

    timeFormat = new JComboBox(timeFormats);
    timeFormat.setSelectedItem(temp.getTimeFormat());
    timeFormat.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            temp.setTimeFormat((String) e.getItem());
            inputFormat.setText(temp.getInputFormat());
        }
    });

    inputFormat = new JTextField(temp.getInputFormat());
    inputFormat.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            temp.setInputFormat(inputFormat.getText());
            if (getHandler().getWorstValidationStatus().getStatus() == Status.OK) {
                SimpleDateFormat sdf = new SimpleDateFormat(temp.getInputFormat());
                sample.setText(sdf.format(StringToDateMungeComponent.SAMPLE_DATE));
            }
        }
    });
    getHandler().addValidateObject(inputFormat, new DateFormatPatternValidator());

    outputFormat = new JComboBox(outputFormats);
    outputFormat.setSelectedItem(temp.getOutputFormat());
    outputFormat.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            temp.setOutputFormat((String) e.getItem());
        }
    });

    CellConstraints cc = new CellConstraints();
    int row = 2;
    content.add(new JLabel("Example: "), cc.xy(2, row));
    content.add(sample, cc.xy(4, row));
    row += 2;
    content.add(new JLabel("Date Format: "), cc.xy(2, row));
    content.add(dateFormat, cc.xy(4, row));
    row += 2;
    content.add(new JLabel("Time Format: "), cc.xy(2, row));
    content.add(timeFormat, cc.xy(4, row));
    row += 2;
    content.add(new JLabel("Input Format: "), cc.xy(2, row));
    content.add(inputFormat, cc.xy(4, row));
    row += 2;
    content.add(new JLabel("Output Format: "), cc.xy(2, row));
    content.add(outputFormat, cc.xy(4, row));
    row += 2;
    content.add(ignoreError, cc.xyw(2, row, 3, "c,c"));

    return content;
}

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

License:Open Source License

@Override
protected JPanel buildUI() {
    SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();

    useRegex = new JCheckBox("Use Regular Expressions");
    useRegex.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();
            step.setRegex(useRegex.isSelected());
        }//from   w  ww. j  av a  2  s  .  c o m
    });
    useRegex.setSelected(step.isRegex());

    caseSensitive = new JCheckBox("Case Sensitive");
    caseSensitive.setSelected(step.isCaseSensitive());
    caseSensitive.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();
            step.setCaseSensitive(caseSensitive.isSelected());
        }

    });

    delimiter = new JTextField(step.getDelimiter());
    delimiter.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();
            step.setDelimiter(delimiter.getText());
        }
    });
    RegexValidator validator = new RegexValidator();
    getHandler().addValidateObject(delimiter, useRegex, validator, true, "");

    resultDelimiter = new JTextField(step.getResultDelim());
    resultDelimiter.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();
        }

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

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

        private void doStuff() {
            SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();
            step.setResultDelim(resultDelimiter.getText());
        }
    });

    int beginIndex = step.getBegIndex();
    SpinnerNumberModel beginNumberModel = new SpinnerNumberModel(beginIndex, 0, Integer.MAX_VALUE, 1);
    begin = new JSpinner(beginNumberModel);
    begin.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();
            step.setBegIndex((Integer) begin.getValue());
        }

    });

    int endIndex = step.getEndIndex();
    SpinnerNumberModel endNumberModel = new SpinnerNumberModel(endIndex, 0, Integer.MAX_VALUE, 1);
    end = new JSpinner(endNumberModel);
    end.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            SubstringByWordMungeStep step = (SubstringByWordMungeStep) getStep();
            step.setEndIndex((Integer) end.getValue());
        }

    });

    FormLayout layout = new FormLayout("4dlu,pref,4dlu,fill:pref:grow,4dlu", // columns
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu"); // rows
    CellConstraints cc = new CellConstraints();

    JPanel content = new JPanel(layout);

    content.add(new JLabel("Begin Index:"), cc.xy(2, 2));
    content.add(begin, cc.xy(4, 2));
    content.add(new JLabel("End Index:"), cc.xy(2, 4));
    content.add(end, cc.xy(4, 4));
    content.add(new JLabel("Delimiter:"), cc.xy(2, 6));
    content.add(delimiter, cc.xy(4, 6));
    content.add(new JLabel("Result Delim:"), cc.xy(2, 8));
    content.add(resultDelimiter, cc.xy(4, 8));

    JPanel bottom = new JPanel(new GridLayout(2, 1));
    bottom.add(useRegex);
    bottom.add(caseSensitive);
    content.add(bottom, cc.xyw(2, 10, 3, "c,f"));

    return content;
}

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

License:Open Source License

private JPanel buildUI() {
    FormLayout layout = new FormLayout(
            "10dlu,pref,4dlu,fill:max(pref;" + 5 * new JComboBox().getMinimumSize().getWidth()
                    + "px):grow,10dlu",
            "10dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,10dlu");
    //1    2    3    4    5     6    7   8    9 
    CellConstraints cc = new CellConstraints();

    JPanel p = logger.isDebugEnabled() ? new FormDebugPanel(layout) : new JPanel(layout);
    PanelBuilder pb = new PanelBuilder(layout, p);

    int row = 2;//ww  w .j a  va  2s .c  o  m
    pb.add(status, cc.xyw(2, row, 3, "f,f"));

    row += 2;
    pb.add(new JLabel("Catalog:"), cc.xy(2, row));
    pb.add(chooser.getCatalogComboBox(), cc.xy(4, row));

    row += 2;
    pb.add(new JLabel("Schema:"), cc.xy(2, row));
    pb.add(chooser.getSchemaComboBox(), cc.xy(4, row));

    row += 2;
    pb.add(new JLabel("Table:"), cc.xy(2, row));
    pb.add(chooser.getTableComboBox(), cc.xy(4, row));

    row += 2;
    pb.add(new JLabel("Index:"), cc.xy(2, row));
    pb.add(chooser.getUniqueKeyComboBox(), cc.xy(4, row));

    row += 2;
    pb.add(new JLabel("Parent Table:"), cc.xy(2, row));
    pb.add(parentMergeRule, cc.xy(4, row));

    return pb.getPanel();
}

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;//from www  .  j  ava  2s  .  c  o  m
    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();
}