package nl.fontys.sofa.limo.view.custom.panel; import javax.swing.BoxLayout; import javax.swing.GroupLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.LayoutStyle; import javax.swing.SwingConstants; import nl.fontys.sofa.limo.view.util.LIMOResourceBundle; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.builtin.stringvalidation.StringValidators; import org.netbeans.validation.api.ui.ValidationUI; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; import org.openide.awt.Mnemonics; import org.openide.util.NbBundle; /** * Reusable {@link JPanel} for inputting name and description. * * @author Sebastiaan Heijmann */ public class AddNewProcedurePanel extends JPanel implements ValidationUI { private JPanel contentPane; private JLabel descriptionLB; private JTextArea descriptionTF; private JScrollPane scrollPane; private JLabel nameLB; private JTextField nameTF; private final SwingValidationGroup group; /** * Creates a new DialogInputPane with validation in place. */ public AddNewProcedurePanel() { initComponents(); nameTF.setName(LIMOResourceBundle.getString("NAME")); descriptionTF.setName(LIMOResourceBundle.getString("DESCRIPTION")); group = SwingValidationGroup.create(this); group.add(nameTF, StringValidators.REQUIRE_NON_EMPTY_STRING); group.add(descriptionTF, StringValidators.REQUIRE_NON_EMPTY_STRING); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") private void initComponents() { contentPane = new JPanel(); nameLB = new JLabel(); descriptionLB = new JLabel(); nameTF = new JTextField(); scrollPane = new JScrollPane(); descriptionTF = new JTextArea(); setMaximumSize(new java.awt.Dimension(450, 125)); setMinimumSize(new java.awt.Dimension(450, 125)); setPreferredSize(new java.awt.Dimension(450, 125)); setRequestFocusEnabled(false); setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); contentPane.setMaximumSize(new java.awt.Dimension(450, 100)); contentPane.setMinimumSize(new java.awt.Dimension(450, 100)); contentPane.setPreferredSize(new java.awt.Dimension(450, 100)); nameLB.setHorizontalAlignment(SwingConstants.RIGHT); Mnemonics.setLocalizedText(nameLB, NbBundle.getMessage(AddNewProcedurePanel.class, "NameDescriptionDialogInputPanel.nameLB.text")); // NOI18N descriptionLB.setHorizontalAlignment(SwingConstants.RIGHT); Mnemonics.setLocalizedText(descriptionLB, NbBundle.getMessage(AddNewProcedurePanel.class, "NameDescriptionDialogInputPanel.descriptionLB.text")); // NOI18N descriptionTF.setColumns(20); descriptionTF.setRows(5); descriptionTF.setName(LIMOResourceBundle.getString("DESCRIPTION")); // NOI18N scrollPane.setViewportView(descriptionTF); GroupLayout contentPaneLayout = new GroupLayout(contentPane); contentPane.setLayout(contentPaneLayout); contentPaneLayout.setHorizontalGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(contentPaneLayout.createSequentialGroup() .addGap(43, 43, 43) .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(nameLB, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(descriptionLB, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(nameTF, GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE) .addComponent(scrollPane)) .addGap(40, 40, 40)) ); contentPaneLayout.setVerticalGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(contentPaneLayout.createSequentialGroup() .addGap(0, 0, 0) .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(nameTF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(nameLB)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(contentPaneLayout.createSequentialGroup() .addComponent(descriptionLB) .addContainerGap(54, Short.MAX_VALUE)) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))) ); add(contentPane); } public String getNameFieldValue() { return nameTF.getText(); } public String getDescriptionFieldValue() { return descriptionTF.getText(); } public SwingValidationGroup getValidationGroup() { return group; } @Override public void showProblem(Problem prblm) { System.out.println(prblm.getMessage()); } @Override public void clearProblem() { } public void setBeanName(String name) { nameTF.setText(name); } public void setBeanDescription(String description) { descriptionTF.setText(description); } }