List of usage examples for com.jgoodies.forms.layout CellConstraints CellConstraints
public CellConstraints()
From source file:ca.phon.plugins.praat.FormantSettingsPanel.java
License:Open Source License
private void init() { setLayout(new BorderLayout()); final FormLayout formLayout = new FormLayout("right:pref, 3dlu, fill:pref:grow, pref", ""); final CellConstraints cc = new CellConstraints(); final PanelBuilder builder = new PanelBuilder(formLayout); final NumberFormat numberFormat = NumberFormat.getNumberInstance(); int rowIdx = 1; numFormantsField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Num formants"), cc.xy(1, rowIdx)); builder.add(numFormantsField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2;/*from w w w.j a va 2 s . co m*/ windowLengthField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Window length"), cc.xy(1, rowIdx)); builder.add(windowLengthField, cc.xy(3, rowIdx)); builder.add(new JLabel("(s)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; maxFreqField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Max frequency"), cc.xy(1, rowIdx)); builder.add(maxFreqField, cc.xy(3, rowIdx)); builder.add(new JLabel("(Hz)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; timeStepField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Time step"), cc.xy(1, rowIdx)); builder.add(timeStepField, cc.xy(3, rowIdx)); builder.add(new JLabel("(s)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; preEmphasisField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Preemphasis"), cc.xy(1, rowIdx)); builder.add(preEmphasisField, cc.xy(3, rowIdx)); builder.add(new JLabel("(Hz)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; dynamicRangeField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Dynamic range"), cc.xy(1, rowIdx)); builder.add(dynamicRangeField, cc.xy(3, rowIdx)); builder.add(new JLabel("(dB)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; dotSizeField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Dot size"), cc.xy(1, rowIdx)); builder.add(dotSizeField, cc.xy(3, rowIdx)); builder.add(new JLabel("(mm)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; includeNumFormantsBox = new JCheckBox("Include num formants"); builder.appendRow("pref"); builder.add(includeNumFormantsBox, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; includeIntensityBox = new JCheckBox("Include intensity"); builder.appendRow("pref"); builder.add(includeIntensityBox, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; includeBandwidthsBox = new JCheckBox("Include bandwidths"); builder.appendRow("pref"); builder.add(includeBandwidthsBox, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; add(builder.getPanel(), BorderLayout.CENTER); final JPanel btnPanel = new JPanel(new VerticalLayout()); final PhonUIAction loadDefaultsAct = new PhonUIAction(this, "loadDefaults"); loadDefaultsAct.putValue(PhonUIAction.NAME, "Load defaults"); loadDefaultsButton = new JButton(loadDefaultsAct); btnPanel.add(loadDefaultsButton); final PhonUIAction loadStandardsAct = new PhonUIAction(this, "loadStandards"); loadStandardsAct.putValue(PhonUIAction.NAME, "Load standards"); loadStandardsButton = new JButton(loadStandardsAct); btnPanel.add(loadStandardsButton); final PhonUIAction saveDefaultsAct = new PhonUIAction(this, "saveSettingsAsDefaults"); saveDefaultsAct.putValue(PhonUIAction.NAME, "Save as defaults"); saveDefaultsButton = new JButton(saveDefaultsAct); btnPanel.add(saveDefaultsButton); add(btnPanel, BorderLayout.EAST); }
From source file:ca.phon.plugins.praat.IntensitySettingsPanel.java
License:Open Source License
private void init() { setLayout(new BorderLayout()); final FormLayout formLayout = new FormLayout("right:pref, 3dlu, fill:pref:grow, pref", ""); final CellConstraints cc = new CellConstraints(); final PanelBuilder builder = new PanelBuilder(formLayout); final NumberFormat numberFormat = NumberFormat.getNumberInstance(); int rowIdx = 1; minRangeField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("View range start"), cc.xy(1, rowIdx)); builder.add(minRangeField, cc.xy(3, rowIdx)); builder.add(new JLabel("(dB)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2;// w w w . j a v a 2 s .c om maxRangeField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("View range end"), cc.xy(1, rowIdx)); builder.add(maxRangeField, cc.xy(3, rowIdx)); builder.add(new JLabel("(dB)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; final ButtonGroup btnGrp = new ButtonGroup(); medianBox = new JRadioButton("median"); btnGrp.add(medianBox); meanEnergyBox = new JRadioButton("mean energy"); btnGrp.add(meanEnergyBox); meanSonesBox = new JRadioButton("mean sones"); btnGrp.add(meanSonesBox); meanDbBox = new JRadioButton("mean dB"); btnGrp.add(meanDbBox); builder.appendRow("pref"); builder.add(new JLabel("Averaging method"), cc.xy(1, rowIdx)); builder.add(medianBox, cc.xy(3, rowIdx++)); builder.appendRow("pref"); builder.add(meanEnergyBox, cc.xy(3, rowIdx++)); builder.appendRow("pref"); builder.add(meanSonesBox, cc.xy(3, rowIdx++)); builder.appendRow("pref"); builder.add(meanDbBox, cc.xy(3, rowIdx++)); builder.appendRow("3dlu"); rowIdx++; subtractMeanBox = new JCheckBox("Subtract mean pressure"); builder.appendRow("pref"); builder.add(subtractMeanBox, cc.xy(3, rowIdx++)); add(builder.getPanel(), BorderLayout.CENTER); final JPanel btnPanel = new JPanel(new VerticalLayout()); final PhonUIAction loadDefaultsAct = new PhonUIAction(this, "loadDefaults"); loadDefaultsAct.putValue(PhonUIAction.NAME, "Load defaults"); loadDefaultsButton = new JButton(loadDefaultsAct); btnPanel.add(loadDefaultsButton); final PhonUIAction loadStandardsAct = new PhonUIAction(this, "loadStandards"); loadStandardsAct.putValue(PhonUIAction.NAME, "Load standards"); loadStandardsButton = new JButton(loadStandardsAct); btnPanel.add(loadStandardsButton); final PhonUIAction saveDefaultsAct = new PhonUIAction(this, "saveSettingsAsDefaults"); saveDefaultsAct.putValue(PhonUIAction.NAME, "Save as defaults"); saveDefaultsButton = new JButton(saveDefaultsAct); btnPanel.add(saveDefaultsButton); add(btnPanel, BorderLayout.EAST); }
From source file:ca.phon.plugins.praat.PitchSettingsPanel.java
License:Open Source License
private void init() { setLayout(new BorderLayout()); final FormLayout formLayout = new FormLayout("right:pref, 3dlu, fill:pref:grow, pref", ""); final CellConstraints cc = new CellConstraints(); final PanelBuilder builder = new PanelBuilder(formLayout); final NumberFormat numberFormat = NumberFormat.getNumberInstance(); int rowIdx = 1; timeStepField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Time step"), cc.xy(1, rowIdx)); builder.add(timeStepField, cc.xy(3, rowIdx)); builder.add(new JLabel("(s)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2;/*from ww w.j av a2 s . c om*/ rangeStartField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Range start"), cc.xy(1, rowIdx)); builder.add(rangeStartField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; rangeEndField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Range end"), cc.xy(1, rowIdx)); builder.add(rangeEndField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; unitsBox = new JComboBox(kPitch_unit.values()); builder.appendRow("pref"); builder.add(new JLabel("Units"), cc.xy(1, rowIdx)); builder.add(unitsBox, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; final ButtonGroup btnGrp = new ButtonGroup(); autoCorrelateButton = new JRadioButton("Auto-correlate"); autoCorrelateButton.setSelected(true); crossCorrelateButton = new JRadioButton("Cross-correlate"); btnGrp.add(autoCorrelateButton); btnGrp.add(crossCorrelateButton); builder.appendRow("pref"); builder.add(new JLabel("Correlation"), cc.xy(1, rowIdx)); builder.add(autoCorrelateButton, cc.xy(3, rowIdx)); builder.appendRow("pref"); ++rowIdx; builder.add(crossCorrelateButton, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; veryAccurateBox = new JCheckBox("Very accurate"); builder.appendRow("pref"); builder.add(veryAccurateBox, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; maxCandidatesField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Max. candidates"), cc.xy(1, rowIdx)); builder.add(maxCandidatesField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; silenceThresholdField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Silence threshold"), cc.xy(1, rowIdx)); builder.add(silenceThresholdField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; voicingThresholdField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Voicing threshold"), cc.xy(1, rowIdx)); builder.add(voicingThresholdField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; octaveCostField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Octave cost"), cc.xy(1, rowIdx)); builder.add(octaveCostField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; octaveJumpCostField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Octave-jump cost"), cc.xy(1, rowIdx)); builder.add(octaveJumpCostField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; voicedUnvoicedCostField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Voiced/unvoiced cost"), cc.xy(1, rowIdx)); builder.add(voicedUnvoicedCostField, cc.xy(3, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; dotSizeField = new JFormattedTextField(numberFormat); builder.appendRow("pref"); builder.add(new JLabel("Dot size"), cc.xy(1, rowIdx)); builder.add(dotSizeField, cc.xy(3, rowIdx)); builder.add(new JLabel("(mm)"), cc.xy(4, rowIdx)); builder.appendRow("3dlu"); rowIdx += 2; add(builder.getPanel(), BorderLayout.CENTER); final JPanel btnPanel = new JPanel(new VerticalLayout()); final PhonUIAction loadDefaultsAct = new PhonUIAction(this, "loadDefaults"); loadDefaultsAct.putValue(PhonUIAction.NAME, "Load defaults"); loadDefaultsButton = new JButton(loadDefaultsAct); btnPanel.add(loadDefaultsButton); final PhonUIAction loadStandardsAct = new PhonUIAction(this, "loadStandards"); loadStandardsAct.putValue(PhonUIAction.NAME, "Load standards"); loadStandardsButton = new JButton(loadStandardsAct); btnPanel.add(loadStandardsButton); final PhonUIAction saveDefaultsAct = new PhonUIAction(this, "saveSettingsAsDefaults"); saveDefaultsAct.putValue(PhonUIAction.NAME, "Save as defaults"); saveDefaultsButton = new JButton(saveDefaultsAct); btnPanel.add(saveDefaultsButton); add(btnPanel, BorderLayout.EAST); }
From source file:ca.phon.plugins.praat.SpectrogramSettingsPanel.java
License:Open Source License
private void init() { final FormLayout layout = new FormLayout("right:pref, 3dlu, fill:pref:grow, pref", "pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu"); final JPanel formPanel = new JPanel(layout); final CellConstraints cc = new CellConstraints(); final NumberFormat numberFormat = NumberFormat.getNumberInstance(); windowLengthField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Window length:"), cc.xy(1, 1)); formPanel.add(windowLengthField, cc.xy(3, 1)); formPanel.add(new JLabel("(s)"), cc.xy(4, 1)); maxFreqField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Max frequency:"), cc.xy(1, 3)); formPanel.add(maxFreqField, cc.xy(3, 3)); formPanel.add(new JLabel("(Hz)"), cc.xy(4, 3)); timeStepField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Time step:"), cc.xy(1, 5)); formPanel.add(timeStepField, cc.xy(3, 5)); formPanel.add(new JLabel("(s)"), cc.xy(4, 5)); freqStepField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Frequency step:"), cc.xy(1, 7)); formPanel.add(freqStepField, cc.xy(3, 7)); formPanel.add(new JLabel("(Hz)"), cc.xy(4, 7)); windowShapeBox = new JComboBox<>(kSound_to_Spectrogram_windowShape.values()); formPanel.add(new JLabel("Window shape:"), cc.xy(1, 9)); formPanel.add(windowShapeBox, cc.xy(3, 9)); preEmphasisField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Pre-emphasis:"), cc.xy(1, 11)); formPanel.add(preEmphasisField, cc.xy(3, 11)); formPanel.add(new JLabel("(dB/oct)"), cc.xy(4, 11)); dynamicRangeField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Dynamic range:"), cc.xy(1, 13)); formPanel.add(dynamicRangeField, cc.xy(3, 13)); formPanel.add(new JLabel("(Hz)"), cc.xy(4, 13)); dynamicCompressionField = new JFormattedTextField(numberFormat); formPanel.add(new JLabel("Dynamic compression:"), cc.xy(1, 15)); formPanel.add(dynamicCompressionField, cc.xy(3, 15)); formPanel.add(new JLabel("(dB)"), cc.xy(4, 15)); final JPanel btnPanel = new JPanel(new VerticalLayout()); final PhonUIAction loadDefaultsAct = new PhonUIAction(this, "loadDefaults"); loadDefaultsAct.putValue(PhonUIAction.NAME, "Load defaults"); loadDefaultsButton = new JButton(loadDefaultsAct); btnPanel.add(loadDefaultsButton);// ww w .ja v a2s . c om final PhonUIAction loadStandardsAct = new PhonUIAction(this, "loadStandards"); loadStandardsAct.putValue(PhonUIAction.NAME, "Load standards"); loadStandardsButton = new JButton(loadStandardsAct); btnPanel.add(loadStandardsButton); final PhonUIAction saveDefaultsAct = new PhonUIAction(this, "saveSettingsAsDefaults"); saveDefaultsAct.putValue(PhonUIAction.NAME, "Save as defaults"); saveDefaultsButton = new JButton(saveDefaultsAct); btnPanel.add(saveDefaultsButton); setLayout(new BorderLayout()); add(formPanel, BorderLayout.CENTER); add(btnPanel, BorderLayout.EAST); loadSettings(new SpectrogramSettings()); }
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 w w. j av a 2 s . 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);// w ww .j av a 2s . c om 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);// w ww .j a v a2 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 w w w . j av a2 s . c o m*/ } 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);/*from w w w . ja va2s . c om*/ 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 av a 2s . com*/ 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); } }); }