package uk.ac.leeds.ccg.widgets; import uk.ac.leeds.ccg.geotools.*; import java.awt.*; import java.util.*; import java.awt.event.*; /** A simple toolbar to save me (ian) adding all this code to control a viewer everytime * I write a quick applet, then I decided it might be useful to others. * Simply construct with the viewer to control and a boolean to decide if you want select enabled in the bar * now makes use of tools rather than the deprecated int method in viewer. 23/11/00 * New version makes use of tool's new found ability to know thier own name to construct the toolbar. 28/11/00 * added support for linking viewers together with a single tool bar 25/6/01 */ public class ToolBar extends Panel implements ActionListener,ItemListener,ScaleChangedListener{ static final boolean DEBUG = false; static final String DBC ="TB >"; Vector viewers = new Vector(); Viewer v; int views=1; boolean selection=false; boolean checkbox = true; CheckboxGroup cbg = new CheckboxGroup(); static final int MAX_VIEWS = 5; Vector tools[] = new Vector[MAX_VIEWS]; Button reset; Vector controls = new Vector(); public ToolBar(){ } /** generate a basic tool bar with reset, zoom and pan buttons to opperate on viewer ve */ public ToolBar(Viewer ve){ this(ve,false); } /** basic tool bar with reset, zoom and pan, and optionally selection (based on value of boolean s) to * operate on viewer ve. */ public ToolBar(Viewer ve, boolean s){ this(ve,s,true); } /** create toolbar to work on viewer ve with an optional selection button * and if checks == true a set of check boxes instead of buttons */ public ToolBar(Viewer ve, boolean sel, boolean checks){ viewers.addElement(ve); ve.getScale().addScaleChangedListener(this); views=0; tools[0]= new Vector(); checkbox = checks; reset = new Button("Reset"); add(reset); controls.addElement(reset); reset.addActionListener(this); //addTool(new resetTool()); addTool(new ZoomTool()); addTool(new PanTool()); if(sel)addTool(new SelectTool()); } /** custom tool bar, contains reset button and then adds tools from vector t. * I don't think you would ever want a toolbar with out a reset button, but I've been wrong before. */ public ToolBar(Viewer ve, Vector t){ viewers.addElement(ve); ve.getScale().addScaleChangedListener(this); tools[0]=new Vector(); views=0; reset = new Button("Reset"); controls.addElement(reset); add(reset); reset.addActionListener(this); for(int i=0;iOTHER viewers to * Quitely change mapextent */ Scaler source = (Scaler)sce.getSource(); if(DEBUG)System.out.println(DBC+"Scale change source "+source); for(int j=0;j