GComponentList

De GENIUS
Aller à la navigation Aller à la recherche

GComponentList allows to display list of widgets :

  • These widgets must have a constructor without arguments
  • There is the possibility to duplicate an element only if the Cloneable interface (and a clone() method) is implemented.

Two modes are also available:

  • a « single » mode, displaying only one widget each time (case of complex widgets)
  • a « multiple » mode displaying all the widgets placed behind each other

The GComponentList may be instantiated by giving the kind of class to display or an object that will serve to initialized new ones.

  GComponentList test;
  test = new GComponentList(name, className.class, mode[true/false]); // First way to instantiate
  test = new GComponentList(name, defaultObj, mode[true/false]); // Second way to instantiate

The list may also be initialized by a predefined list:

  ArrayList<GComponent> list = new ArrayList<GComponent>();
  list.add(new XXX(...));
  list.add(new XXX(...));

  GComponentList test = null;
  test.setList (list);

Example

First, let us create a class, corresponding to a widget including several basic other widgets (here a GEntryString, a GEntryInt and a GEntryReal):

public class TestForGComponentListWidget extends GPanel implements GReadWrite {
	
  GEntryString widget1;
  GEntryInt widget2;
  GEntryReal widget3;
	
  public TestForGComponentListWidget () {
		
    widget1 = new GEntryString("Text", "try");
    widget2 = new GEntryInt("Integer", 0);
    widget3 = new GEntryReal("Double", 0.);

  }
	
  public void generic() throws GException {
    beginOfElement("widForGC", "test");
      put(widget1);
      put(widget2);
      put(widget3);
    endOfElement();
  }

  public void read() throws GException { generic(); }
  public void write() throws GException { generic(); }
  public void display() throws GException { generic(); }
  
}

Note that it is recommended to encapsulate data with beginOfElement() and endOfElement() (see Data file management section) not to have conflicts when reading or writing between to data with the same name.

At last, we will have just to create a GComponentList for this kind of TestForGComponentListWidget

  GComponentList test = new GComponentList("TestGC", TestForGComponentListWidget.class, [true/false]);


330 px "single" mode 330 px "multiple" mode


It is also possible to custom some labels ("Amount of Items", "Item number" and "Item n") by using the setLabels() method.

At last, it is also possible to use the setEditable() method if we just want to disply the list without modifying it.


Return to the introduction ↑ Go to the next page →