Working with Editors
Note: for dialogs showing only text, consider using the dialogs API.
The simplest way to add forms to INTViewer is to create a JPanel using the Matisse editor integrated with NetBeans. Use the IntViewerDialogDisplayer to open your panel:
JPanel contents = ...;
IntViewerDialogDisplayer.getDefault().notify(contents, "My Dialog Title",
IntViewerDialogDisplayer.OK_CANCEL_OPTION, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// handle your buttons
if (e.getActionCommand().equals("Ok")) {
...
}
}
IntViewerDialogDisplayer automatically adds the buttons (OK, Cancel, Save, etc.) at the bottom of your dialog.
Property Editors
An API is provided to implement complex editor dialogs, including dialogs with multiple panels displayed as tabs. Instead of manipulating JPanels, you manipulate com.interactive.intviewerapi.IObjectEditorNode objects that have a getPanel() and an apply() methods.
Here is sample code to open an editor class implementing IObjectEditorNode in a dialog showing multiple tabs. This sample code makes use of the IObjectEditorNode, TabPropertiesPanel, AbstractPropertyEditor and PanelManager classes.
MyEditor oen = new MyEditor(...);
AbstractPropertyEditor bigEditor = new AbstractPropertyEditor() {
@Override
public String getDisplayName() {
return "My Big Editor"; // name of the dialog window
}
};
bigEditor.addEditor(oen); // only one tab for this dialog
String actionValue = "Cancel";
TabPropertiesPanel pp = new TabPropertiesPanel();
PanelManager pm = new PanelManager(bigEditor);
pp.setPanelManager(pm);
IntViewerDialogDisplayer.getDefault().notify(pp, bigEditor.getDisplayName(), IntViewerDialogDisplayer.OK_APPLY_CANCEL_OPTION, HelpCtx.DEFAULT_HELP, pm);
actionValue = pm.getActionValue();
Upon clicking OK or APPLY, the apply() method of each IObjectEditorNode is called.
Panel Validations
The INTViewer platform includes a copy of the Netbeans "Simple Validation API" library introduced in this article: http://netbeans.dzone.com/news/how-quickly-add-validation.
This API allows the real time validation of inputs, and disallows the Ok/Apply buttons when the current entries are incorrect.To benefit from this library in editors implementing com.interactive.intviewerapi.IObjectEditorNode, follow these 2 steps:
- add relevant validations to a validation group, using ValidationGroup.add(JTextComponent, Validator<String>..)
- return a org.netbeans.validation.api.ui.ValidationPanel instead of JPanel in IObjectEditorNode.getPanel()
A sample implementation is provided for triangle mesh 2D layers.
Many of the validators provided with the "Simple Validation API" library can be used without problems. When parsing and verifying numbers, it's best to implement your own validators as the input format may vary depending on your user base. Examples of validators are provided.
When you need to perform a validation for a component that cannot be added directly to a validation group (such as a javax.swing.JList component, a javax.swing.JRadioButton or javax.swing.JCheckBox), use a ValidationListener instead. Example:
import org.netbeans.validation.api.ui.ValidationListener;
private ValidationListener validationListener = null;
private JList = ...;
public void setUpValidationGroup(ValidationGroup group) {
this.validationListener = new ValidationListener() {
if (this.list.getModel().getSize() == 0) {
problems.add("List may not be empty");
return false;
} else {
return true;
}
};
group.add(this.validationListener);
}
public void actionPerformed(ActionEvent e) { // called when component's value is changed
....
this.validationListener.verify(null);
}