Custom Input Dialogs

From AIBenchWiki

Jump to: navigation, search

If you don't like the default generated input dialog for some operation, you can make your own dialog:

1. You have to implement the es.uvigo.ei.aibench.workbench.InputGui interface into your viewer class and return an array of parameter specifications: es.uvigo.ei.aibench.core.ParamSpec[].

2. Alternatively, you can extend es.uvigo.ei.aibench.workbench.inputgui.ParamsWindow, which is the class that AIBench uses as default dialog. ParamsWindow defines the getParamProvider(...) method intended to be overrided in order to change the component that will be used for a given port. This visual component and the parameter value are specified via the returning instance of the ParamProvider interface. The getComponent() method is used to specify the component and the getParamSpec() method is used for the parameter's value. Lets see the example:

  public class SearchInputDialog extends ParamsWindow {
       private JTextField txt = new JTextField("Example");
  
       protected ParamProvider getParamProvider (final Port arg0, final Class<?> arg1,final Object arg2){

         // change the default behaviour for the port named "PortName"
         if (arg0.name().equals("PortName")){
            
             return new AbstractParamProvider() {
               public JComponent getComponent() {
                 return txt;
               }
               public ParamSpec getParamSpec() throws IllegalArgumentException {
                 return new ParamSpec(arg0.name(), arg1, txt.getText(), ParamSource.STRING_CONSTRUCTOR);
               }
               public Port getPort() {
                 return arg0;
               }
             };
          }

          // use the default behaviour for the other ports
          return super.getParamProvider(arg0, arg1, arg2);
        }
   }

3. Finally you have to add to plugins.xml a reference to new dialog:

  <extension uid="aibench.workbench" name="aibench.workbench.view" >
      <gui-operation  operation="OperationUID" class="samplePlugin.ClassName"/>
  </extension>
Personal tools
Documentation