@Override public CustomWidget visit(StringType stringType) { final CustomJTextField customJTextField = new CustomJTextField(LENGTH); customJTextField.setEditable(this.editable); customJTextField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { update(); } public void removeUpdate(DocumentEvent e) { update(); } public void insertUpdate(DocumentEvent e) { update(); } public void update() { variableState.put( TypeWidgetVisitor.this.identifierNode, new StringValue(customJTextField.getText())); } }); this.panel.add(customJTextField); return customJTextField; }
@Override public CustomWidget visit(IntegerType integerType) { final CustomJTextField customJTextField = new CustomJTextField(LENGTH); customJTextField.setEditable(this.editable); customJTextField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { update(); } public void removeUpdate(DocumentEvent e) { update(); } public void insertUpdate(DocumentEvent e) { update(); } public void update() { final String text = customJTextField.getText(); Integer value = 0; try { if (!text.isEmpty()) { value = Integer.valueOf(text); } } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(panel, MESSAGE, TITLE, JOptionPane.ERROR_MESSAGE); } variableState.put(TypeWidgetVisitor.this.identifierNode, new IntegerValue(value)); } }); this.panel.add(customJTextField); return customJTextField; }