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

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

Introduction

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

Prototype

public CellConstraints xy(int col, int row) 

Source Link

Document

Sets column and row origins; sets width and height to 1; uses the default alignments.

Examples:

 cc.xy(1, 1); cc.xy(1, 3); 

Usage

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

License:Open Source License

private void buildUI() {

    FormLayout layout = new FormLayout(
            "4dlu,14dlu,4dlu,fill:min(pref;" + 3 * (new JComboBox().getMinimumSize().width)
                    + "px):grow, 4dlu,pref,4dlu", // columns
            "10dlu,pref,12dlu,pref,4dlu,fill:40dlu:grow,4dlu,pref,4dlu"); // rows
    //    1     2    3     4    5    6    7     8         9    10        

    PanelBuilder pb;/*from  www.  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();

    int row = 2;
    pb.add(new JLabel("List of table merge rules:"), cc.xy(4, row));
    row += 2;

    pb.add(new JLabel("Merge Rules:"), cc.xy(4, row, "l,t"));
    row += 2;
    mergeRulesScrollPane = new JScrollPane(mergeRulesTable);
    pb.add(mergeRulesScrollPane, cc.xy(4, row, "f,f"));

    ButtonStackBuilder bsb = new ButtonStackBuilder();
    bsb.addGridded(new JButton(moveUp));
    bsb.addRelatedGap();
    bsb.addGridded(new JButton(moveDown));
    pb.add(bsb.getPanel(), cc.xy(6, row, "c,c"));

    ButtonBarBuilder bbb = new ButtonBarBuilder();
    //new actions for delete and save should be extracted and be put into its own file.
    bbb.addGridded(new JButton(new NewMergeRuleAction(swingSession, mmo)));
    bbb.addRelatedGap();
    bbb.addGridded(new JButton(new DeriveRelatedRulesAction(swingSession, mmo)));
    bbb.addRelatedGap();
    bbb.addGridded(new JButton(deleteRule));
    bbb.addRelatedGap();
    bbb.addGridded(new JButton(saveAction));
    row += 2;
    pb.add(bbb.getPanel(), cc.xy(4, row, "c,c"));
    panel = pb.getPanel();

    moveDown.setEnabled(false);
    moveUp.setEnabled(false);
    deleteRule.setEnabled(false);
}

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

License:Open Source License

private void buildUI() {
    statusLabel = new StatusComponent();
    form = new FormValidationHandler(statusLabel);
    field = new JTextField();
    d = new JDialog();
    items = new JComboBox();
    area = new JTextArea();
    area.setEditable(false);//from  w w w.  j  av  a 2s  .  co m
    create = new JButton(new AbstractAction("Create") {

        public void actionPerformed(ActionEvent e) {
            StubMatchMakerObject child = new StubMatchMakerObject(field.getText());
            child.setAllowChildren(false);
            obj.addChild(child);
            field.setText("");
            refreshTextArea();
        }

    });

    exit = new JButton(new AbstractAction("Exit") {

        public void actionPerformed(ActionEvent e) {
            d.setVisible(false);
            d.dispose();
        }

    });

    FormLayout layout = new FormLayout("4dlu,pref,4dlu,fill:50dlu:grow,4dlu,pref,4dlu",
            "4dlu,pref,4dlu,pref,4dlu,fill:80dlu:grow, 4dlu, pref,4dlu");
    PanelBuilder pb = new PanelBuilder(layout);
    CellConstraints cc = new CellConstraints();
    pb.add(statusLabel, cc.xyw(2, 2, 6));
    pb.add(new JLabel("Project Name"), cc.xy(2, 4));
    pb.add(field, cc.xy(4, 4));
    pb.add(create, cc.xy(6, 4));
    pb.add(new JScrollPane(area), cc.xyw(2, 6, 5));
    pb.add(exit, cc.xy(6, 8));

    Validator v1 = new MMODuplicateValidator(obj, null, "Cannot have Duplicate Name",
            new MatchMakerTranslateGroup());
    form.addValidateObject(field, v1);
    d.getContentPane().add(pb.getPanel());

}

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

License:Open Source License

@Override
protected JPanel buildUI() {
    final BooleanToStringMungeStep step = (BooleanToStringMungeStep) getStep();
    trueValue = new JTextField(step.getTrueString());
    trueValue.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();//from w  w  w  .ja  v a  2s  . c om
        }

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

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

        private void doStuff() {
            step.setTrueString(trueValue.getText());
        }
    });

    falseValue = new JTextField(step.getFalseString());
    falseValue.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.setFalseString(falseValue.getText());
        }
    });

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

    JPanel content = new JPanel(layout);

    content.add(new JLabel("True:"), cc.xy(2, 2));
    content.add(trueValue, cc.xy(4, 2));
    content.add(new JLabel("False:"), cc.xy(2, 4));
    content.add(falseValue, cc.xy(4, 4));
    return content;
}

From source file:ca.sqlpower.matchmaker.swingui.munge.DateToStringMungeComponent.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"));
    final DateToStringMungeStep temp = (DateToStringMungeStep) getStep();
    final String[] dateFormats = DateToStringMungeStep.DATE_FORMATS.toArray(new String[] {});
    final String[] timeFormats = DateToStringMungeStep.TIME_FORMATS.toArray(new String[] {});

    dateFormat = new JComboBox(dateFormats);
    dateFormat.setSelectedItem(temp.getDateFormat());
    dateFormat.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            temp.setDateFormat((String) e.getItem());
            format.setText(temp.getFormat());
        }//w w w . jav a2  s  . c  o  m
    });

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

    format = new JTextField(temp.getFormat());
    format.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.setFormat(format.getText());
            if (getHandler().getWorstValidationStatus().getStatus() == Status.OK) {
                SimpleDateFormat sdf = new SimpleDateFormat(temp.getFormat());
                sample.setText(sdf.format(DateToStringMungeComponent.SAMPLE_DATE));
            }
        }
    });
    SimpleDateFormat sdf = new SimpleDateFormat(temp.getFormat());
    sample = new JTextField(sdf.format(DateToStringMungeComponent.SAMPLE_DATE));
    sample.setEditable(false);
    getHandler().addValidateObject(format, new DateFormatPatternValidator());

    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("Format: "), cc.xy(2, row));
    content.add(format, cc.xy(4, row));

    return content;
}

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

License:Open Source License

@Override
protected JPanel buildUI() {
    GoogleAddressLookup temp = (GoogleAddressLookup) getStep();

    url = new JTextField(temp.getGoogleGeocoderURL());
    url.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            doStuff();/*from w  w  w  .j  av a 2 s .co  m*/
        }

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

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

        private void doStuff() {
            GoogleAddressLookup step = (GoogleAddressLookup) getStep();
            step.setGoogleGeocoderURL(url.getText());
        }
    });

    key = new JTextField(temp.getGoogleMapsApiKey());
    key.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() {
            GoogleAddressLookup step = (GoogleAddressLookup) getStep();
            step.setGoogleMapsApiKey(key.getText());
        }
    });

    rateLimit = new JSpinner(new SpinnerNumberModel(0.0, 0.0, 10.0, 0.1));
    rateLimit.setValue(temp.getRateLimit());

    JPanel mainContent = new JPanel();
    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("fill:pref:grow", "fill:pref, pref"),
            mainContent);

    FormLayout layout = new FormLayout("4dlu,pref,4dlu,fill:pref:grow,4dlu", // columns
            "4dlu,pref,4dlu,pref,4dlu,pref,4dlu,pref,4dlu"); // rows
    CellConstraints cc = new CellConstraints();
    JPanel content = new JPanel(layout);
    content.add(new JLabel("URL:"), cc.xy(2, 2));
    content.add(url, cc.xy(4, 2));
    content.add(new JLabel("Google Maps API Key:"), cc.xy(2, 4));
    content.add(key, cc.xy(4, 4));
    content.add(new JLabel("Rate Limit (s):"), cc.xy(2, 6));
    content.add(rateLimit, cc.xy(4, 6));

    JPanel subPanel = new JPanel(new FlowLayout());
    showAllButton = new JButton(new HideShowAllLabelsAction("Show All", false, true, true));
    hideAllButton = new JButton(new HideShowAllLabelsAction("Hide All", false, true, false));
    subPanel.add(showAllButton);
    subPanel.add(hideAllButton);

    builder.append(content);
    builder.nextLine();
    builder.append(subPanel);

    return mainContent;
}

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

License:Open Source License

public MungePreviewPanel(MungeProcess process, MungePen pen) {
    this.mungePen = pen;
    previewer = new MungePreviewer(process);
    previewer.addPreviewListener(listener);
    FormLayout layout = new FormLayout("pref, 4dlu, pref", "pref");
    panel = new JPanel(layout) {
        @Override//from w w  w.j a v a 2s.c  o m
        public void paint(Graphics g) {
            AbstractMungeComponent lastModifiedMungeComp = mungePen
                    .getMungeComponent(getLastModifiedOrSelectedStep());
            if (lastModifiedMungeComp != null) {
                Rectangle stepBounds = lastModifiedMungeComp.getBounds();
                setBounds(stepBounds.x + stepBounds.width, stepBounds.y, getPreferredSize().width,
                        getPreferredSize().height);
            }
            g.setColor(getBackground());
            g.fillRoundRect(0, 0, getWidth(), getHeight(), BORDER_WIDTH * 3, BORDER_WIDTH * 3);
            super.paint(g);
        }
    };
    CellConstraints cc = new CellConstraints();
    inputTable = new JTable(new MSOTableModel("Input", 0, 0));
    outputTable = new JTable(new MSOTableModel("Output", 0, 0));
    JPanel inputPanel = new JPanel(new BorderLayout());
    inputPanel.add(inputTable, BorderLayout.CENTER);
    inputPanel.add(inputTable.getTableHeader(), BorderLayout.NORTH);
    panel.add(inputPanel, cc.xy(1, 1));

    JPanel outputPanel = new JPanel(new BorderLayout());
    outputPanel.add(outputTable, BorderLayout.CENTER);
    outputPanel.add(outputTable.getTableHeader(), BorderLayout.NORTH);
    panel.add(outputPanel, cc.xy(3, 1));

    panel.setOpaque(false);
    panel.setBackground(new Color(0x99333333, true));
    panel.setForeground(Color.WHITE);
    panel.setBorder(BorderFactory.createEmptyBorder(BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH));
    inputPanel.setOpaque(false);
    inputPanel.setBackground(null);
    inputPanel.setForeground(null);
    inputTable.setOpaque(false);
    inputTable.setBackground(null);
    inputTable.setForeground(null);
    inputTable.getTableHeader().setOpaque(false);
    inputTable.getTableHeader().setBackground(null);
    inputTable.getTableHeader().setForeground(null);

    outputPanel.setOpaque(false);
    outputPanel.setBackground(null);
    outputPanel.setForeground(null);
    outputTable.setOpaque(false);
    outputTable.setBackground(null);
    outputTable.setForeground(null);
    outputTable.getTableHeader().setOpaque(false);
    outputTable.getTableHeader().setBackground(null);
    outputTable.getTableHeader().setForeground(null);

    inputTable.getTableHeader().setBorder(new LineBorder(null));
    inputTable.setBorder(new LineBorder(null));

    inputTable.getTableHeader().setDefaultRenderer(new TableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            return table.getCellRenderer(0, column).getTableCellRendererComponent(table, value, isSelected,
                    hasFocus, row, column);
        }
    });

    outputTable.getTableHeader().setBorder(new LineBorder(null));
    outputTable.setBorder(new LineBorder(null));

    outputTable.getTableHeader().setDefaultRenderer(new TableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            return table.getCellRenderer(0, column).getTableCellRendererComponent(table, value, isSelected,
                    hasFocus, row, column);
        }
    });

    enablePreviewCheckBox = new JCheckBox(new AbstractAction("Show Preview") {
        public void actionPerformed(ActionEvent e) {
            enablePreview(enablePreviewCheckBox.isSelected());
        }
    });
    enablePreview(false);

    engineListener = new EngineListener() {
        public void engineStopped(EngineEvent e) {
            enablePreviewCheckBox.setEnabled(true);
        }

        public void engineStarted(EngineEvent e) {
            enablePreviewCheckBox.setEnabled(false);
        }
    };

    project = process.getParent();
    switch (project.getType()) {
    case FIND_DUPES:
        MatchEngineImpl matchingEngine = project.getMatchingEngine();
        matchingEngine.addEngineListener(engineListener);
        if (matchingEngine.isStarted() && !matchingEngine.isFinished())
            enablePreviewCheckBox.setEnabled(false);
        MergeEngineImpl mergingEngine = project.getMergingEngine();
        mergingEngine.addEngineListener(engineListener);
        if (mergingEngine.isStarted() && !mergingEngine.isFinished())
            enablePreviewCheckBox.setEnabled(false);
        break;
    case CLEANSE:
        CleanseEngineImpl cleansingEngine = project.getCleansingEngine();
        cleansingEngine.addEngineListener(engineListener);
        cleansingEngine.addEngineListener(engineListener);
        if (cleansingEngine.isStarted() && !cleansingEngine.isFinished())
            enablePreviewCheckBox.setEnabled(false);
        break;
    case ADDRESS_CORRECTION:
        AddressCorrectionEngine addressCorrectionEngine = project.getAddressCorrectionEngine();
        addressCorrectionEngine.addEngineListener(engineListener);
        if (addressCorrectionEngine.isStarted() && !addressCorrectionEngine.isFinished())
            enablePreviewCheckBox.setEnabled(false);
        AddressCorrectionEngine addressCommittingEngine = project.getAddressCommittingEngine();
        addressCommittingEngine.addEngineListener(engineListener);
        if (addressCommittingEngine.isStarted() && !addressCommittingEngine.isFinished())
            enablePreviewCheckBox.setEnabled(false);
        break;
    }
}

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());
        }/* w w  w  . j  a v  a 2  s .  co  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  .  j a  v  a2  s .com
    });
    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 .  jav  a 2  s  .  co 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 w w  .  j a  v  a  2  s . co  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;
}