private int createArmSelect( PanelBuilder builder, int row, final Study curStudy, TreatmentDefinition def, CellConstraints cc) { builder.addLabel(def.getLabel(), cc.xy(2, row)); ListModel arms = d_pm.getArmsPerStudyPerDefinition(curStudy, def); final JComboBox drugBox = AuxComponentFactory.createBoundComboBox( arms, d_pm.getSelectedArmModel(curStudy, def), true); if (arms.getSize() == 1) drugBox.setEnabled(false); final JPanel drugAndDosePanel = new JPanel(new BorderLayout()); builder.add(drugBox, cc.xy(4, row)); drugBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateDrugAndDoseLabel(curStudy, drugBox, drugAndDosePanel); } }); row = LayoutUtil.addRow(builder.getLayout(), row); updateDrugAndDoseLabel(curStudy, drugBox, drugAndDosePanel); builder.add(drugAndDosePanel, cc.xy(4, row)); return LayoutUtil.addRow(builder.getLayout(), row); }
private JPanel buildPanel() { CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("fill:0:grow, 3dlu, pref", "p"); PanelBuilder builder = new PanelBuilder(layout); int row = 1; for (Note note : d_notes) { builder.add(AuxComponentFactory.createNoteView(note, d_editable), cc.xyw(1, row, 3)); LayoutUtil.addRow(layout); row += 2; } if (d_editable) { final ValueModel model = new ValueHolder(DEFAULT_NOTE_TEXT); JScrollPane editNote = AuxComponentFactory.createTextArea(model, true); final JButton addNoteButton = new JButton(Main.IMAGELOADER.getIcon(FileNames.ICON_NOTE_NEW)); addNoteButton.setEnabled(false); final JTextArea area = (JTextArea) editNote.getViewport().getView(); area.setBackground(AuxComponentFactory.COLOR_NOTE_EDIT); area.getDocument() .addDocumentListener( new DocumentListener() { private void validateComponents() { if (area.getText().equals("") || area.getText().equals(DEFAULT_NOTE_TEXT)) addNoteButton.setEnabled(false); else addNoteButton.setEnabled(true); } public void changedUpdate(DocumentEvent e) { validateComponents(); } public void removeUpdate(DocumentEvent e) { validateComponents(); } public void insertUpdate(DocumentEvent e) { validateComponents(); } }); area.addFocusListener( new FocusListener() { public void focusLost(FocusEvent e) { if (area.getText().equals("")) { area.setText(DEFAULT_NOTE_TEXT); } } public void focusGained(FocusEvent e) { if (area.getText().equals(DEFAULT_NOTE_TEXT)) { area.setText(""); } } }); builder.add(editNote, cc.xy(1, row)); builder.add(addNoteButton, cc.xy(3, row)); addNoteButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { d_notes.add(new Note(Source.MANUAL, (String) model.getValue())); } }); } return builder.getPanel(); }