[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ToolFactory.java,1.34,1.35
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-03-13 22:04:18
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18030/src/net/sourceforge/bprocessor/gl/tool Modified Files: ToolFactory.java Log Message: Refactored ToolFactory Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** ToolFactory.java 13 Mar 2006 12:06:51 -0000 1.34 --- ToolFactory.java 13 Mar 2006 22:04:11 -0000 1.35 *************** *** 11,14 **** --- 11,16 ---- import java.net.URL; + import java.util.HashMap; + import java.util.Map; import java.awt.Cursor; import java.awt.Image; *************** *** 37,40 **** --- 39,55 ---- private static Logger log = Logger.getLogger(ToolFactory.class); + /** glv */ + private GLView glv; + + /** tools */ + private Map tools; + + /** buttons */ + private Map buttons; + + /** button group */ + private ButtonGroup group; + + /** The factory */ private static ToolFactory factory; *************** *** 117,120 **** --- 132,140 ---- */ private ToolFactory(GLView glv) { + tools = new HashMap(); + buttons = new HashMap(); + group = new ButtonGroup(); + this.glv = glv; + ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("Bcursorpen1.gif"); *************** *** 136,182 **** Toolkit.getDefaultToolkit().createCustomCursor(walkImage, new Point(7, 8), "Walk"); - ButtonGroup bg = new ButtonGroup(); - Toolbar tb = Toolbar.getInstance(); - tb.addSeparator(); - selBut = tb.registerAction(new SelectAction(glv)); - bg.add(selBut); - selBut.setToolTipText("Select"); - pencilBut = tb.registerAction(new PencilAction(glv)); - bg.add(pencilBut); - pencilBut.setToolTipText("Pencil"); - - eraserBut = tb.registerAction(new EraserAction(glv)); - bg.add(eraserBut); - eraserBut.setToolTipText("Eraser"); - - - moveBut = tb.registerAction(new MoveAction(glv)); - bg.add(moveBut); - moveBut.setToolTipText("Move"); - moveBut.addMouseListener(new MoveButtonMouseListener(moveBut)); - rotBut = tb.registerAction(new RotationAction(glv)); - bg.add(rotBut); - rotBut.setToolTipText("Rotate"); - extrudBut = tb.registerAction(new ExtrudeAction(glv)); - bg.add(extrudBut); - extrudBut.setToolTipText("Extrude"); - clipBut = tb.registerAction(new ClipAction(glv)); - bg.add(clipBut); - clipBut.setToolTipText("Clipping"); - tmBut = tb.registerAction(new TapeMeasureAction(glv)); - bg.add(tmBut); - tmBut.setToolTipText("Tape Measure"); - tb.addSeparator(); - cRotBut = tb.registerAction(new CameraAction(glv)); - bg.add(cRotBut); - cRotBut.setToolTipText("Camera rotation"); - flyBut = tb.registerAction(new CameraFlyAction(glv)); - bg.add(flyBut); - flyBut.setToolTipText("Fly mode"); - walkBut = tb.registerAction(new CameraWalkAction(glv)); - bg.add(walkBut); - walkBut.setToolTipText("Walk mode"); - - select = new SpaceTool(glv, null); pencil = new PencilTool(glv, pencilcursor); --- 156,159 ---- *************** *** 190,193 **** --- 167,192 ---- fly = new CameraFlyTool(glv, flyCursor); walk = new CameraWalkTool(glv, walkCursor); + + Toolbar tb = Toolbar.getInstance(); + tb.addSeparator(); + + selBut = this.registerTool(Tool.SELECT_TOOL, select, "Biconselecttool.gif", "Select"); + pencilBut = this.registerTool(Tool.PENCIL_TOOL, pencil, "Biconpentool.gif", "Pencil"); + eraserBut = this.registerTool(Tool.ERASER_TOOL, eraser, "Biconeraser.gif", "Eraser"); + moveBut = this.registerTool(Tool.MOVE_TOOL, move, "Biconmovetool.gif", "Move"); + moveBut.addMouseListener(new MoveButtonMouseListener(moveBut)); + rotBut = this.registerTool(Tool.ROTATION_TOOL, rotation, "Biconrotobj.gif", "Rotation"); + extrudBut = this.registerTool(Tool.EXTRUSION_TOOL, extrusion, + "Biconextrudetool.gif", "Extrude"); + clipBut = this.registerTool(Tool.CLIP_TOOL, clipplane, + "Biconclipplane.gif", "Clipping"); + tmBut = this.registerTool(Tool.TAPE_MEASURE_TOOL, tapeMeasure, + "Bicontapemes.gif", "Tape Measure"); + + tb.addSeparator(); + + cRotBut = this.registerTool(Tool.CAMERA_TOOL, camera, "Biconrotcam.gif", "Orbit"); + flyBut = this.registerTool(Tool.FLY_TOOL, fly, "Biconfly.gif", "Fly"); + walkBut = this.registerTool(Tool.WALK_TOOL, walk, "Biconwalk.gif", "Walk"); } *************** *** 222,225 **** --- 221,243 ---- return temp; } + + /** + * Register Tool + * @param key Key + * @param tool Tool + * @param iconname Icon name + * @param tooltip Tool tip + * @return Button + */ + public JToggleButton registerTool(int key, Tool tool, String iconname, String tooltip) { + tools.put(new Integer(key), tool); + ToolAction action = new ToolAction(glv, key, iconname); + JToggleButton button = Toolbar.getInstance().registerAction(action); + button.setToolTipText(tooltip); + group.add(button); + buttons.put(tool, button); + return button; + } + /** *************** *** 230,594 **** public Tool get(int i) { Tool temp = currentTool; ! if (i == Tool.SELECT_TOOL) { ! selBut.setSelected(true); ! currentTool = select; ! } else if (i == Tool.MOVE_TOOL) { ! moveBut.setSelected(true); ! currentTool = move; ! } else if (i == Tool.ROTATION_TOOL) { ! rotBut.setSelected(true); ! currentTool = rotation; ! } else if (i == Tool.EXTRUSION_TOOL) { ! extrudBut.setSelected(true); ! currentTool = extrusion; ! } else if (i == Tool.PENCIL_TOOL) { ! pencilBut.setSelected(true); ! currentTool = pencil; ! } else if (i == Tool.CLIP_TOOL) { ! clipBut.setSelected(true); ! currentTool = clipplane; ! } else if (i == Tool.CAMERA_TOOL) { ! cRotBut.setSelected(true); ! currentTool = camera; ! } else if (i == Tool.FLY_TOOL) { ! flyBut.setSelected(true); ! currentTool = fly; ! } else if (i == Tool.WALK_TOOL) { ! walkBut.setSelected(true); ! currentTool = walk; ! } else if (i == Tool.TAPE_MEASURE_TOOL) { ! tmBut.setSelected(true); ! currentTool = tapeMeasure; ! } else if (i == Tool.ERASER_TOOL) { ! eraserBut.setSelected(true); ! currentTool = eraser; } else { log.error("[get] No such tool " + i); return null; } - if (currentTool != temp) { - previousTool = temp; - } - return currentTool; - } - - /** - * The select action inner class - */ - class SelectAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - SelectAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconselecttool.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.SELECT_TOOL); - } - } - - - - /** - * The rotation action inner class - */ - class CameraAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - CameraAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconrotcam.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.CAMERA_TOOL); - } - } - - /** - * The fly action inner class - */ - class CameraFlyAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - CameraFlyAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconfly.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.FLY_TOOL); - } - } - - /** - * The walk action inner class - */ - class CameraWalkAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - CameraWalkAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconwalk.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.WALK_TOOL); - } - } - - /** - * The move action inner class - */ - class MoveAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - MoveAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconmovetool.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.MOVE_TOOL); - } - } - - /** - * The rotaion action inner class - */ - class RotationAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - RotationAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconrotobj.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.ROTATION_TOOL); - } } /** ! * The extrude action inner class ! */ ! class ExtrudeAction extends AbstractAction { ! /** The GLView */ ! private GLView glv = null; ! ! /** ! * Constructor ! * @param glv TheGLView ! */ ! ExtrudeAction(GLView glv) { ! this.glv = glv; ! ClassLoader cl = Thread.currentThread().getContextClassLoader(); ! URL url = cl.getResource("Biconextrudetool.gif"); ! ImageIcon im = new ImageIcon(url); ! putValue(Action.SMALL_ICON, im); ! } ! ! /** ! * Called when the button is pressed ! * @param e The ActionEvent ! */ ! public void actionPerformed(ActionEvent e) { ! glv.changeTool(Tool.EXTRUSION_TOOL); ! } ! } ! ! /** ! * The pencil action inner class */ ! class PencilAction extends AbstractAction { ! /** The GLView */ ! private GLView glv = null; ! ! /** The mouse cursor */ ! private Cursor cursor; ! /** ! * Constructor ! * @param glv TheGLView ! */ ! PencilAction(GLView glv) { ! this.glv = glv; ! ClassLoader cl = Thread.currentThread().getContextClassLoader(); ! URL url = cl.getResource("Biconpentool.gif"); ! ImageIcon im = new ImageIcon(url); ! putValue(Action.SMALL_ICON, im); ! Image image = Toolkit.getDefaultToolkit().getImage(url); ! cursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "Pencil"); ! } ! ! /** ! * Called when the button is pressed ! * @param e The ActionEvent ! */ ! public void actionPerformed(ActionEvent e) { ! glv.changeTool(Tool.PENCIL_TOOL); ! } ! } ! ! /** ! * EraserAction ! */ ! class EraserAction extends AbstractAction { ! /** The GLView */ ! private GLView glv = null; ! ! /** The mouse cursor */ ! private Cursor cursor; - /** - * Constructor - * @param glv TheGLView - */ - EraserAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconeraser.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - /** ! * Called when the button is pressed ! * @param e The ActionEvent ! */ ! public void actionPerformed(ActionEvent e) { ! glv.changeTool(Tool.ERASER_TOOL); ! } ! } ! ! ! /** ! * The clipping action inner class ! */ ! class ClipAction extends AbstractAction { ! /** The GLView */ ! private GLView glv = null; ! ! /** ! * Constructor ! * @param glv TheGLView */ ! ClipAction(GLView glv) { this.glv = glv; ClassLoader cl = Thread.currentThread().getContextClassLoader(); ! URL url = cl.getResource("Biconclipplane.gif"); ImageIcon im = new ImageIcon(url); putValue(Action.SMALL_ICON, im); } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.changeTool(Tool.CLIP_TOOL); - } - } - - - /** - * The tape measure action inner class - */ - class TapeMeasureAction extends AbstractAction { - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - TapeMeasureAction(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Bicontapemes.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - /** ! * Called when the button is pressed ! * @param e The ActionEvent */ ! public void actionPerformed(ActionEvent e) { ! glv.changeTool(Tool.TAPE_MEASURE_TOOL); } } --- 248,296 ---- public Tool get(int i) { Tool temp = currentTool; ! Tool next = (Tool) tools.get(new Integer(i)); ! if (next != null) { ! JToggleButton button = (JToggleButton) buttons.get(next); ! button.setSelected(true); ! currentTool = next; ! if (currentTool != temp) { ! previousTool = temp; ! } ! return currentTool; } else { log.error("[get] No such tool " + i); return null; } } /** ! * ToolAction */ ! class ToolAction extends AbstractAction { ! /** glv */ ! private GLView glv; ! /** key */ ! private int key; /** ! * Constructor ! * @param glv GLView ! * @param key Key ! * @param iconname Iconname */ ! public ToolAction(GLView glv, int key, String iconname) { this.glv = glv; + this.key = key; ClassLoader cl = Thread.currentThread().getContextClassLoader(); ! URL url = cl.getResource(iconname); ImageIcon im = new ImageIcon(url); putValue(Action.SMALL_ICON, im); } /** ! * @param event ActionEvent */ ! public void actionPerformed(ActionEvent event) { ! glv.changeTool(key); } } |