/************************************************************ This is the skeleton for a Customizer implementing the User Inteface for the TableViewTool class. by Fernando Das Neves, august 1999.r implementing ************************************************************/ /* Change the next linet to the package this tool belongs to. It can be any package, but for Sluice this is tipically the same package in which the tools for which this class is a customizer is located: - sieve.sluice.view (for data filters), - sieve.sluice.nuggets (for data visualizers), or - sieve.sluice.codebook (for data readers) */ package sieve.sluice.myGroupOfTools; import java.beans.*; import java.awt.*; import sieve.sluice.*; import javax.swing.*; /* * @author Your_Name_here * @version Version_number_here * * Write here a short description of the customizer. */ public class TableViewToolCustomizer extends JPanel implements Customizer, TableViewListener, PropertyChangeListener { /* zeroSize variable is used for comparison in getPreferredSize(), to see if the component already has a size */ private static Dimension zeroSize = new Dimension(0,0); /* initial size of the component when it is instantiated. All sieve tools must return an initial size. Change these numbers to whatever size you like */ private static Dimension initialSize = new Dimension(200,100); /* * table is the instance variable table will hold the model. * When a new tool is instantiated the customizer will be informed * of its model with a call to setObject(). */ TableView table = null; public ToolCustomizer() { super(); /* * Here you do the UI setup, creating UI objects, * setting layouts, colors, etc */ } public void setObject(Object model) { /* In this method the customizer receives its model. * In Sluice all other objects received by a tool customizer * will be TableViews, so it is safe to cast to TableView * at least. In an specific customizer you will be able * to cast to a more specific class, since you know * what class the model for your customizer belongs to. */ table = (TableView) model; /* set the customizer as a listener of the tool, so any change in the source of the tool can be properly reflected in the UI */ table.addTableViewListener(this); /* * Here goes the rest of the code to initialize the UI * once the model is known. */ } public Dimension getPreferredSize() { /* This implementation of getPreferredSize() gives * an initial size, and also allows dynamic resizing * of the tool */ Dimension current = getSize(); return (current.equals(zero) ? initialSize : current); } //--------implementation of-PropertyChangeListener protocol--------- public void addPropertyChangeListener(PropertyChangeListener l) { support.addPropertyChangeListener(l); } public void removePropertyChangeListener(PropertyChangeListener l) { support.removePropertyChangeListener(l); } private PropertyChangeSupport support = new PropertyChangeSupport(this); //---------------------------------------------------------------------- public void propertyChange(PropertyChangeEvent evt) { /* In this method you write the code to react to changes in properties of the model, * carried out by the user. This method will consist of * a long list of if...else if...else if... and so on, to find out * the property that changed. For example, let us say that your customizer * has a property called urlLocation, that is shown in a TextField called * location. An example of the code to react to changes in this property * would be : * if (evt.getPropertyName().equals("location")) { * location.tf.setText((String)evt.getNewValue()); * else if(evt.getPropertyName() equals is another property name...) */ } } //--------implementation of TableViewListener protocol--------- public void tableViewChanged(sieve.sluice.TableViewEvent event) { /* here add code to react to the changes in the source of the tool. * Changes are signaled with any of these events: * sieve.sluice.events.TableViewChangedEvent, * sieve.sluice.events.SourceAddedEvent, * sieve.sluice.events.SourceRemovedEvent */ } //---End of implementation of TableViewListener protocol--------- }