Howto add/modify a plotter

You must create an XPlotter and an controller for it. Here is an example XPlotter:
import java.awt.*;
import java.io.Serializable;

/** An example XPlotter 
 * 
 * The purpose of this class is to contain the bare minimum amount of information
 * necessary to do a plot (of this type). 
 * 
 * When a tile is saved to a file, the data saved will be 
 * 1) A word
 * 2) A color
 * 3) an XPlotter (say this XPlotter)
 * 
 * From this data McBilliards can reconstruct the tile in another session
 * using "plotter.plot(word, color, I, M);"
 *
 * The moral is that an XPlotter should not hold unnecessary data
 * (e.g. a Manager) because that will make these saved files much bigger.
 * (Furthermore a Manager can not be recovered from a file)
 */
public class XNewPlotter implements XPlotter, Serializable {
    
    // This int represents some plot setting
    public int some_int;
    
    /** default constructor */
    public XNewPlotter() {
        some_int=0;        
    }
    
    /** copy constructor */
    public XNewPlotter(XNewPlotter p) {
        some_int=p.some_int;
    }
    
    
    /** plots the tile */
    public Tile plot(String word, Color C, Interrupter I, Manager M){
        // here you want to actually plot the tile
        // for example look at XFillPlotter.plot
        // you would probably want to use the plot settings (e.g. some_int) here
        return null;
    }
    
    /** build a controlling canvas */
    public Component getController(Manager M) {
        return new XNewPlotterController(M, this);
    }
    
    /** Return the name of the plot technique */
    public String getName() {
        return "new";
    }
    
    /** Returns true if the plot can be run. This is useful for example
     * if the plot relies on C code which may or may not be available
     */
    public boolean canRun() {
        return true;
    }
    
    /** return the documentation for this plotter */
    public HelpDocument document(){
        return null;
    }
    
    /** button color */
    public Color getColor() {
        return Color.blue;
    }
    
}


You must create a controller:
import java.awt.*;
import java.awt.event.*;

/** This class controlls an XNewPlotter
 *
 * It allows editing an object of type XNewPlotter. Currently it controls a
 * single integer (some_int).
 */

public class XNewPlotterController extends DBCanvas implements MouseListener {
    Manager M;
    
    IntegerSelector some_int; // level of detail
    
    /** this class now does the real work */
    XNewPlotter plotter;
    
    public XNewPlotterController(Manager M, XNewPlotter plotter) {
        this.M=M;
        this.plotter=plotter;
        
        // initialize the selector to plotter.some_int
        some_int=new IntegerSelector(7,23,32,16,plotter.some_int,1,25,1);
        
        this.addMouseListener(this);
    }
    
    /** draw the buttons etc. */
    public void paint(Graphics gfx){
        Graphics2D g=(Graphics2D) gfx;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
        
        Color C1=new Color(250,0,255);
        g.setColor(Color.black);
        some_int.render(g,C1,Color.black,Color.white);
    }
    
    /** Return smallest area that the drawing will take up.
     * You can change this to get more space. */
    public Dimension getPreferredSize() {
        return new Dimension(80,32);
    }
    
    /** These are taken from MouseListener */
    public void mouseClicked(MouseEvent e){
        e.consume();
        Point X=new Point();
        X.x=e.getX();
        X.y=e.getY();
        
        // when the Integer selector is changed, immediately propigate
        // the change to the plotter
        some_int.modify(X);
        plotter.some_int=some_int.val;
        
        repaint();
    }
    
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}
    public void mousePressed(MouseEvent e){}
    public void mouseReleased(MouseEvent e){}
}


Then you need to let the PlotCanvas know about it. This should only require editing one line:
    XPlotter[] types={
        new XFillPlotter(),
        new XPackPlotter(),
        new XCoverPlotter(),
        new XZonePlotter(),
        new XBilliardLikePlotter(),
        new XNewPlotter()
    };
Just add your new plotter there.

PAT'S HOME >>>>> McBILLIARDS >>>>> DEVELOPMENT