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

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

Introduction

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

Prototype

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

Source Link

Document

Constructs a FormLayout using the given column and row specifications.

Usage

From source file:ca.phon.script.params.ui.ParamPanelFactory.java

License:Open Source License

private JPanel createComponentPanel(JLabel label, JComponent comp) {
    String cols = "20px, fill:pref:grow";
    String rows = "pref, pref";
    FormLayout layout = new FormLayout(cols, rows);
    JPanel compPanel = new JPanel(layout);
    CellConstraints cc = new CellConstraints();
    compPanel.add(label, cc.xyw(1, 1, 2));
    compPanel.add(comp, cc.xy(2, 2));/*from w  ww  . j  a  v  a2s .co  m*/

    return compPanel;
}

From source file:ca.phon.syllabifier.editor.SyllabifierSettingsPanel.java

License:Open Source License

private void init() {
    final FormLayout layout = new FormLayout("right:pref, fill:pref:grow", "pref, 3dlu, pref");
    setLayout(layout);//from   w  ww .j a  va 2 s .  c  o m

    final CellConstraints cc = new CellConstraints();

    add(new JLabel("Syllabifier name:"), cc.xy(1, 1));
    nameField = new JTextField();
    add(nameField, cc.xy(2, 1));

    add(new JLabel("Syllabifier language:"), cc.xy(1, 3));
    languageField = new JTextField();
    add(languageField, cc.xy(2, 3));
}

From source file:ca.phon.ui.JRangeSlider.java

License:Open Source License

public static void main(String[] args) {
    JRangeSlider slider = new JRangeSlider(1000, 10000, 1000, 3000);
    slider.setLabelFormat(new MsFormat());
    slider.setPaintSlidingLabel(true);/*from   w w w.j a  va  2  s.  c o m*/
    //      slider.setPreferredSize(new Dimension(100, 30));
    //      slider.setFont(new Font("Charis SIL", Font.PLAIN, 10));

    JFrame f = new JFrame("Test Slider");

    FormLayout layout = new FormLayout("3dlu, fill:pref:grow, 3dlu", "3dlu, pref, 3dlu");
    //      f.getContentPane().setLayout(layout);

    CellConstraints cc = new CellConstraints();
    //      f.getContentPane().add(slider, cc.xy(2,2));
    f.add(slider);
    f.pack();
    f.setVisible(true);
}

From source file:ca.phon.ui.layout.ButtonBarBuilder.java

License:Open Source License

public JComponent build() {
    final CellConstraints cc = new CellConstraints();
    final FormLayout layout = new FormLayout(createColumnSchema(), "pref");

    final JPanel retVal = new JPanel(layout);

    int colIdx = 1;

    for (int i = 0; i < leftAlignedComponents.size(); i++) {
        final WeakReference<JComponent> buttonRef = leftAlignedComponents.get(i);
        final JComponent button = buttonRef.get();

        retVal.add(button, cc.xy(colIdx, 1));
        ++colIdx;//from  www  . j av a2 s.com
    }
    if (colIdx == 1)
        ++colIdx;
    if (leftFillComponent != null) {
        retVal.add(leftFillComponent.get(), cc.xy(colIdx, 1));
    }
    ++colIdx;

    int oldIdx = colIdx;
    for (int i = 0; i < centerAlignedComponents.size(); i++) {
        final WeakReference<JComponent> buttonRef = centerAlignedComponents.get(i);
        final JComponent button = buttonRef.get();

        retVal.add(button, cc.xy(colIdx, 1));
        ++colIdx;
    }
    if (colIdx == oldIdx)
        ++colIdx;
    if (rightFillComponent != null) {
        retVal.add(rightFillComponent.get(), cc.xy(colIdx, 1));
    }
    ++colIdx;

    for (int i = 0; i < rightAlignedComponents.size(); i++) {
        final WeakReference<JComponent> buttonRef = rightAlignedComponents.get(i);
        final JComponent button = buttonRef.get();

        retVal.add(button, cc.xy(colIdx, 1));
        ++colIdx;
    }

    return retVal;
}

From source file:ca.phon.ui.participant.ParticipantPanel.java

License:Open Source License

private void init() {
    // setup form
    roleBox = new JComboBox(ParticipantRole.values());

    assignIdBox = new JCheckBox("Assign ID from role");
    assignIdBox.setSelected(true);/*  w ww.  ja  v a2 s .  c o m*/

    idField = new JTextField();
    idField.setEnabled(false);

    sexBox = new JComboBox(Sex.values());
    sexBox.setSelectedItem((participant.getSex() != null ? participant.getSex() : Sex.UNSPECIFIED));
    sexBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            final JLabel retVal = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected,
                    cellHasFocus);
            final Sex sex = (Sex) value;

            retVal.setText(sex.getText());

            return retVal;
        }

    });

    final PhonUIAction anonymizeAct = new PhonUIAction(this, "onAnonymize");
    anonymizeAct.putValue(PhonUIAction.NAME, "Anonymize");
    anonymizeAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Remove all optional information");
    anonymizeBtn = new JButton(anonymizeAct);

    int defCols = 20;
    nameField = new JTextField();
    nameField.setColumns(defCols);
    groupField = new JTextField();
    groupField.setColumns(defCols);
    sesField = new JTextField();
    sesField.setColumns(defCols);
    educationField = new JTextField();
    educationField.setColumns(defCols);
    languageField = new LanguageField();
    languageField.setColumns(defCols);

    bdayField = new DatePicker();
    ageField = FormatterTextField.createTextField(Period.class);
    ageField.setPrompt("YY;MM.DD");
    ageField.setToolTipText("Enter age in format YY;MM.YY");
    ageField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent arg0) {
            if (ageField.getText().length() > 0 && !ageField.validateText()) {
                ToastFactory.makeToast("Age format: " + AgeFormatter.AGE_FORMAT).start(ageField);
                Toolkit.getDefaultToolkit().beep();
                bdayField.requestFocus();
            }
        }

        @Override
        public void focusGained(FocusEvent arg0) {
        }

    });

    // setup info

    if (participant.getRole() != null)
        roleBox.setSelectedItem(participant.getRole());
    if (participant.getId() != null) {
        idField.setText(participant.getId());
    }
    idField.setText(participant.getId());
    if (participant.getName() != null)
        nameField.setText(participant.getName());
    if (participant.getGroup() != null)
        groupField.setText(participant.getGroup());
    if (participant.getSES() != null)
        sesField.setText(participant.getSES());
    if (participant.getLanguage() != null)
        languageField.setText(participant.getLanguage());
    if (participant.getEducation() != null)
        educationField.setText(participant.getEducation());

    if (participant.getBirthDate() != null) {
        bdayField.setDateTime(participant.getBirthDate());
    }

    if (participant.getAge(null) != null) {
        ageField.setValue(participant.getAge(null));
    }

    // setup listeners
    final Functor<Void, Participant> roleUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            final ParticipantRole role = (ParticipantRole) roleBox.getSelectedItem();
            participant.setRole(role);
            if (assignIdBox.isSelected()) {
                idField.setText(getRoleId());
            }

            return null;
        }

    };
    roleBox.addItemListener(new ItemUpdater(roleUpdater));

    final Functor<Void, Participant> idUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setId(idField.getText());
            return null;
        }

    };
    idField.getDocument().addDocumentListener(new TextFieldUpdater(idUpdater));

    final Functor<Void, Participant> nameUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setName(nameField.getText());
            return null;
        }

    };
    nameField.getDocument().addDocumentListener(new TextFieldUpdater(nameUpdater));

    final Functor<Void, Participant> langUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setLanguage(languageField.getText());
            return null;
        }

    };
    languageField.getDocument().addDocumentListener(new TextFieldUpdater(langUpdater));

    final Functor<Void, Participant> groupUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setGroup(groupField.getText());
            return null;
        }

    };
    groupField.getDocument().addDocumentListener(new TextFieldUpdater(groupUpdater));

    final Functor<Void, Participant> eduUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setEducation(educationField.getText());
            return null;
        }

    };
    educationField.getDocument().addDocumentListener(new TextFieldUpdater(eduUpdater));

    final Functor<Void, Participant> sesUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setSES(sesField.getText());
            return null;
        }

    };
    sesField.getDocument().addDocumentListener(new TextFieldUpdater(sesUpdater));

    final Functor<Void, Participant> sexUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            participant.setSex((Sex) sexBox.getSelectedItem());
            return null;
        }

    };
    sexBox.addItemListener(new ItemUpdater(sexUpdater));

    final Functor<Void, Participant> assignIdFunctor = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            if (assignIdBox.isSelected()) {
                if (assignIdBox.isSelected()) {
                    idField.setText(getRoleId());
                }
            }
            idField.setEnabled(!assignIdBox.isSelected());
            return null;
        }

    };
    assignIdBox.addItemListener(new ItemUpdater(assignIdFunctor));

    final Functor<Void, Participant> bdayUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            final LocalDate bday = bdayField.getDateTime();
            participant.setBirthDate(bday);
            if (participant.getAge(null) == null) {
                if (sessionDate != null && sessionDate.isAfter(participant.getBirthDate())) {
                    final Period age = participant.getAge(sessionDate);
                    ageField.setPrompt(AgeFormatter.ageToString(age));
                    ageField.setKeepPrompt(true);
                } else {
                    ageField.setPrompt("YY:MM.DD");
                    ageField.setKeepPrompt(false);
                }
            }
            return null;
        }

    };
    bdayField.getTextField().getDocument().addDocumentListener(new TextFieldUpdater(bdayUpdater));
    bdayField.getTextField().addActionListener(new ActionUpdater(bdayUpdater));

    final Functor<Void, Participant> ageUpdater = new Functor<Void, Participant>() {

        @Override
        public Void op(Participant obj) {
            if (ageField.getText().trim().length() == 0) {
                participant.setAge(null);
            } else {
                final Period p = ageField.getValue();
                participant.setAge(p);
            }
            return null;
        }

    };
    ageField.getDocument().addDocumentListener(new TextFieldUpdater(ageUpdater));

    // ensure a role is selected!
    if (participant.getRole() == null) {
        roleBox.setSelectedItem(ParticipantRole.TARGET_CHILD);
    }

    final CellConstraints cc = new CellConstraints();
    final FormLayout reqLayout = new FormLayout("right:pref, 3dlu, fill:pref:grow", "pref, pref, pref");
    final JPanel required = new JPanel(reqLayout);
    required.setBorder(BorderFactory.createTitledBorder("Required Information"));
    required.add(new JLabel("Role"), cc.xy(1, 1));
    required.add(roleBox, cc.xy(3, 1));
    required.add(assignIdBox, cc.xy(3, 2));
    required.add(new JLabel("Id"), cc.xy(1, 3));
    required.add(idField, cc.xy(3, 3));

    final FormLayout optLayout = new FormLayout(
            "right:pref, 3dlu, fill:pref:grow, 5dlu, right:pref, 3dlu, fill:pref:grow",
            "pref, pref, pref, pref");
    final JPanel optional = new JPanel(optLayout);
    optional.setBorder(BorderFactory.createTitledBorder("Optional Information"));
    optional.add(new JLabel("Name"), cc.xy(1, 1));
    optional.add(nameField, cc.xy(3, 1));
    optional.add(new JLabel("Sex"), cc.xy(1, 2));
    optional.add(sexBox, cc.xy(3, 2));
    optional.add(new JLabel("Birthday (" + DateFormatter.DATETIME_FORMAT + ")"), cc.xy(1, 3));
    optional.add(bdayField, cc.xy(3, 3));
    optional.add(new JLabel("Age (" + AgeFormatter.AGE_FORMAT + ")"), cc.xy(1, 4));
    optional.add(ageField, cc.xy(3, 4));

    optional.add(new JLabel("Language"), cc.xy(5, 1));
    optional.add(languageField, cc.xy(7, 1));
    optional.add(new JLabel("Group"), cc.xy(5, 2));
    optional.add(groupField, cc.xy(7, 2));
    optional.add(new JLabel("Education"), cc.xy(5, 3));
    optional.add(educationField, cc.xy(7, 3));
    optional.add(new JLabel("SES"), cc.xy(5, 4));
    optional.add(sesField, cc.xy(7, 4));

    setLayout(new VerticalLayout(5));
    add(required);
    add(optional);
    add(ButtonBarBuilder.buildOkBar(anonymizeBtn));
    add(new JSeparator(SwingConstants.HORIZONTAL));
}

From source file:ca.phon.ui.text.FileSelectionField.java

License:Open Source License

private void init() {
    final FormLayout layout = new FormLayout("fill:pref:grow, pref", "pref");
    final CellConstraints cc = new CellConstraints();
    setLayout(layout);//from   www.  j  a  v a2s .  c o  m

    textField = new PromptedTextField();
    add(textField, cc.xy(1, 1));

    final ImageIcon browseIcon = IconManager.getInstance().getIcon("actions/document-open", IconSize.SMALL);
    final PhonUIAction browseAct = new PhonUIAction(this, "onBrowse");
    browseAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Browse...");
    browseAct.putValue(PhonUIAction.SMALL_ICON, browseIcon);
    browseButton = new JButton(browseAct);
    browseButton.putClientProperty("JButton.buttonType", "square");
    browseButton.setCursor(Cursor.getDefaultCursor());
    add(browseButton, cc.xy(2, 1));

    setBorder(textField.getBorder());
    textField.setBorder(null);

    textField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            final File f = getSelectedFile();
            setFile(f);
        }
    });
}

From source file:ca.phon.ui.text.SearchField.java

License:Open Source License

private void init() {
    final FormLayout layout = new FormLayout("pref, 3dlu, fill:pref:grow, 3dlu, pref", "pref");
    setLayout(layout);/*  w ww .  j a  v a  2  s .  c  o  m*/
    final CellConstraints cc = new CellConstraints();

    // load search icon
    final ImageIcon searchIcon = new ImageIcon(createSearchIcon());
    final PhonUIAction ctxAction = new PhonUIAction(this, "onShowContextMenu");
    ctxAction.putValue(PhonUIAction.SMALL_ICON, searchIcon);
    ctxAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Click for options");
    ctxButton = new SearchFieldButton(ctxAction);
    ctxButton.setCursor(Cursor.getDefaultCursor());
    ctxButton.setFocusable(false);
    add(ctxButton, cc.xy(1, 1));

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

    final ImageIcon clearIcon = new ImageIcon(createClearIcon());
    final PhonUIAction clearTextAct = new PhonUIAction(this, "onClearText");
    clearTextAct.putValue(PhonUIAction.SMALL_ICON, clearIcon);
    clearTextAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Clear field");
    endButton = new SearchFieldButton(clearTextAct);
    endButton.setCursor(Cursor.getDefaultCursor());
    endButton.setDrawIcon(false);
    add(endButton, cc.xy(5, 1));

    setBorder(queryField.getBorder());
    final Insets insets = queryField.getBorder().getBorderInsets(queryField);
    queryField.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
}

From source file:ca.phon.ui.wizard.WizardFrame.java

License:Open Source License

private void init() {
    // step panel
    stepLayout = new CardLayout();
    stepPanel = new JPanel(stepLayout);
    add(stepPanel, BorderLayout.CENTER);

    // button bar
    ImageIcon icnBack = IconManager.getInstance().getIcon("actions/agt_back", IconSize.SMALL);
    ImageIcon icnNext = IconManager.getInstance().getIcon("actions/agt_forward", IconSize.SMALL);
    ImageIcon icnFinish = IconManager.getInstance().getIcon("actions/button_ok", IconSize.SMALL);
    ImageIcon icnCancel = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);

    btnBack = new JButton("Back");
    btnBack.setIcon(icnBack);/*www  .  j  av  a 2  s . co m*/
    btnBack.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            prev();
        }

    });

    btnNext = new JButton("Next");
    btnNext.setIcon(icnNext);
    btnNext.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            next();
        }
    });

    btnNext.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    btnFinish = new JButton("Finish");
    btnFinish.setIcon(icnFinish);
    btnFinish.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            finish();
        }

    });
    super.getRootPane().setDefaultButton(btnFinish);

    btnCancel = new JButton("Close");
    btnCancel.setIcon(icnCancel);
    btnCancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel();
        }

    });

    FormLayout barLayout = new FormLayout("fill:pref:grow, pref, pref, 5dlu, pref, pref", "pref");
    CellConstraints cc = new CellConstraints();
    JPanel buttonPanel = new JPanel(barLayout);

    buttonPanel.add(btnBack, cc.xy(2, 1));
    buttonPanel.add(btnNext, cc.xy(3, 1));
    buttonPanel.add(btnFinish, cc.xy(5, 1));
    buttonPanel.add(btnCancel, cc.xy(6, 1));
    buttonPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.DARK_GRAY));

    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:ca.sqlpower.architect.swingui.action.KettleJobAction.java

License:Open Source License

public void actionPerformed(ActionEvent arg0) {
    logger.debug("Starting to create a Kettle job."); //$NON-NLS-1$

    JDialog d;/*from   w w  w .  jav  a2s.c  om*/
    final JPanel cp = new JPanel(new BorderLayout(12, 12));
    cp.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
    final KettleJobPanel kettleETLPanel = new KettleJobPanel(getSession());

    Callable<Boolean> okCall, cancelCall;
    okCall = new Callable<Boolean>() {

        public Boolean call() {
            if (!kettleETLPanel.applyChanges()) {
                return Boolean.FALSE;
            }
            KettleRepositoryDirectoryChooser chooser = new UserRepositoryDirectoryChooser(frame);
            final KettleJob kettleJob = getSession().getKettleJob();
            kettleJob.setRepositoryDirectoryChooser(chooser);

            final JDialog createKettleJobMonitor = new JDialog(frame);
            createKettleJobMonitor.setTitle(Messages.getString("KettleJobAction.progressDialogTitle")); //$NON-NLS-1$
            FormLayout layout = new FormLayout("pref", ""); //$NON-NLS-1$ //$NON-NLS-2$
            DefaultFormBuilder builder = new DefaultFormBuilder(layout);
            builder.setDefaultDialogBorder();
            builder.append(Messages.getString("KettleJobAction.progressDialogTitle")); //$NON-NLS-1$
            builder.nextLine();
            JProgressBar progressBar = new JProgressBar();
            builder.append(progressBar);
            builder.nextLine();
            JButton cancel = new JButton(Messages.getString("KettleJobAction.cancelOption")); //$NON-NLS-1$
            cancel.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    kettleJob.setCancelled(true);
                }
            });
            builder.append(cancel);
            createKettleJobMonitor.add(builder.getPanel());

            SPSwingWorker compareWorker = new SPSwingWorker(getSession()) {

                @Override
                public void doStuff() throws Exception {
                    createKettleJobMonitor.pack();
                    createKettleJobMonitor.setLocationRelativeTo(frame);
                    createKettleJobMonitor.setVisible(true);
                    List<SQLTable> tableList = getSession().getPlayPen().getTables();
                    kettleJob.doExport(tableList, getSession().getTargetDatabase());
                }

                @Override
                public void cleanup() throws Exception {
                    createKettleJobMonitor.dispose();
                    if (getDoStuffException() != null) {
                        Throwable ex = getDoStuffException();
                        if (ex instanceof SQLObjectException) {
                            ASUtils.showExceptionDialog(getSession(),
                                    Messages.getString("KettleJobAction.errorReadingTables"), ex); //$NON-NLS-1$
                        } else if (ex instanceof RuntimeException || ex instanceof IOException
                                || ex instanceof SQLException) {
                            StringBuffer buffer = new StringBuffer();
                            buffer.append(Messages.getString("KettleJobAction.runtimeError")).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
                            for (String task : kettleJob.getTasksToDo()) {
                                buffer.append(task).append("\n"); //$NON-NLS-1$
                            }
                            ASUtils.showExceptionDialog(getSession(), buffer.toString(), ex);
                        } else if (ex instanceof KettleException) {
                            ASUtils.showExceptionDialog(getSession(),
                                    Messages.getString("KettleJobAction.kettleExceptionDuringExport") + //$NON-NLS-1$
                            "\n" + ex.getMessage().trim(), ex); //$NON-NLS-1$
                        } else {
                            ASUtils.showExceptionDialog(getSession(),
                                    Messages.getString("KettleJobAction.unexpectedExceptionDuringExport"), ex); //$NON-NLS-1$
                        }
                        return;
                    }
                    final JDialog toDoListDialog = new JDialog(frame);
                    toDoListDialog.setTitle(Messages.getString("KettleJobAction.kettleTasksDialogTitle")); //$NON-NLS-1$
                    FormLayout layout = new FormLayout("10dlu, 2dlu, fill:pref:grow, 12dlu", //$NON-NLS-1$
                            "pref, fill:pref:grow, pref"); //$NON-NLS-1$
                    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
                    builder.setDefaultDialogBorder();
                    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder();
                    JTextArea toDoList = new JTextArea(10, 60);
                    toDoList.setEditable(false);
                    List<String> tasksToDo = kettleJob.getTasksToDo();
                    for (String task : tasksToDo) {
                        toDoList.append(task + "\n"); //$NON-NLS-1$
                    }
                    JButton close = new JButton(Messages.getString("KettleJobAction.closeOption")); //$NON-NLS-1$
                    close.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
                            toDoListDialog.dispose();
                        }
                    });
                    builder.nextColumn(2);
                    builder.append(Messages.getString("KettleJobAction.kettleTasksInstructions")); //$NON-NLS-1$
                    builder.nextLine();
                    builder.append(""); //$NON-NLS-1$
                    builder.append(new JScrollPane(toDoList));
                    builder.nextLine();
                    builder.append(""); //$NON-NLS-1$
                    buttonBarBuilder.addGlue();
                    buttonBarBuilder.addGridded(close);
                    buttonBarBuilder.addGlue();
                    builder.append(buttonBarBuilder.getPanel());
                    toDoListDialog.add(builder.getPanel());
                    toDoListDialog.pack();
                    toDoListDialog.setLocationRelativeTo(frame);
                    toDoListDialog.setVisible(true);
                }
            };

            new Thread(compareWorker).start();
            ProgressWatcher.watchProgress(progressBar, kettleJob);
            return Boolean.TRUE;
        }
    };

    cancelCall = new Callable<Boolean>() {
        public Boolean call() {
            return Boolean.TRUE;
        }
    };

    d = DataEntryPanelBuilder.createDataEntryPanelDialog(kettleETLPanel, getSession().getArchitectFrame(),
            Messages.getString("KettleJobAction.dialogTitle"), Messages.getString("KettleJobAction.okOption"), //$NON-NLS-1$ //$NON-NLS-2$
            okCall, cancelCall);
    d.pack();
    d.setLocationRelativeTo(getSession().getArchitectFrame());
    d.setVisible(true);
}

From source file:ca.sqlpower.architect.swingui.action.ProgressAction.java

License:Open Source License

/**
 * Setup the dialog, monitors and worker.  Classes that extend this class
 * should use doStuff() and cleanUp()/*from   w  w w  .  j av a  2s .  co m*/
 */
public void actionPerformed(ActionEvent e) {
    final JDialog progressDialog;
    final Map<String, Object> properties = new HashMap<String, Object>();
    progressDialog = new JDialog(frame, Messages.getString("ProgressAction.name"), false); //$NON-NLS-1$
    progressDialog.setLocationRelativeTo(frame);
    progressDialog.setTitle(getDialogMessage());

    PanelBuilder pb = new PanelBuilder(
            new FormLayout("4dlu,fill:min(100dlu;default):grow, pref, fill:min(100dlu;default):grow,4dlu", //$NON-NLS-1$
                    "4dlu,pref,4dlu, pref, 6dlu, pref,4dlu")); //$NON-NLS-1$
    JLabel label = new JLabel(getDialogMessage());
    JProgressBar progressBar = new JProgressBar();
    final MonitorableImpl monitor = new MonitorableImpl();
    if (!setup(monitor, properties)) {
        // if setup indicates not to continue (returns false), then exit method
        return;
    }
    CellConstraints c = new CellConstraints();
    pb.add(label, c.xyw(2, 2, 3));
    pb.add(progressBar, c.xyw(2, 4, 3));
    pb.add(new JButton(new AbstractAction(getButtonText()) {
        public void actionPerformed(ActionEvent e) {
            progressDialog.dispose();
            monitor.setCancelled(true);
        }
    }), c.xy(3, 6));
    progressDialog.add(pb.getPanel());

    SPSwingWorker worker = new SPSwingWorker(getSession()) {
        @Override
        public void cleanup() throws Exception {
            if (getDoStuffException() != null) {
                ASUtils.showExceptionDialog(getSession(),
                        Messages.getString("ProgressAction.unexpectedException"), getDoStuffException()); //$NON-NLS-1$
            }
            ProgressAction.this.cleanUp(monitor);
            monitor.setFinished(true);
            progressDialog.dispose();
        }

        @Override
        public void doStuff() throws Exception {
            ProgressAction.this.doStuff(monitor, properties);
        }
    };
    ProgressWatcher.watchProgress(progressBar, monitor);
    progressDialog.pack();
    progressDialog.setVisible(true);

    new Thread(worker).start();
}