📄 omdrawingtool.java
字号:
if (DEBUG) { EditableOMGraphic ce = getCurrentEditable(); Debug.output("OMDrawingTool: current editable is: " + (ce == null ? "null" : ce.getClass().getName())); } // Activate the list to make sure the listeners are // set up // so the map gets repainted with the new EOMG in // selected mode activate(false); // Don't need to repaint if we call activate() repaintCanvas = false; } else { // We already have an EditableOMGraphicList, just add // the new stuff to it. if (DEBUG) { Debug.output("OMDrawingTool.select: already working on EditableOMGraphicList"); } } // OK, even if we've just created the new EOMGL and added // a previous OMG to it, we still need to deal with the // OMG that has just been added into the method. ((EditableOMGraphicList) currentEditable).add(omg, this); if (requestor instanceof DrawingToolRequestorList) { ((DrawingToolRequestorList) requestor).add(omg, req); } else { Debug.error("OHHHH, THE HORRORS!"); Thread.dumpStack(); } // OK, make the EditableOMGraphic list react to the new // mouse event, which will also set the state machine, // which will flow to the new EditableOMGraphic. ((EditableOMGraphicList) currentEditable).handleInitialMouseEvent(e); // Make sure the list is returned. ret = currentEditable.getGraphic(); // Only need to call canvas.repaint() if activate isn't // called, and this is where that will happen. This makes // the grab points show up on the new OMGraphic. if (repaintCanvas && canvas != null) { canvas.repaint(); } } else { if (DEBUG) { Debug.output("OMDrawingTool.select: activating for: " + omg.getClass().getName()); } // Since this is the first OMG in the tool at this point, // it's standard editing behavior.... ret = edit(omg, req, e); } return ret != null; } /** * Given a classname, check the EditToolLoaders and create the * OMGraphic it represents wrapped in an EditableOMGraphic. * * @param classname the classname of an OMGraphic to create. * @param ga GraphicAttributes needed to initialize the OMGraphic. * @return EdtiableOMGraphic, or null if none of the loaders can * figure out what to make. */ public EditableOMGraphic getEditableGraphic(String classname, GraphicAttributes ga) { EditableOMGraphic eomg = null; EditToolLoader loader = (EditToolLoader) loaders.get(classname); if (loader == null) { if (DEBUG) { Debug.output("OMDrawingTool.getEditableGraphic(" + classname + ") - rechecking loaders"); } // The loaders may be able to instantiate objects they // don't want in the GUI - check to see if they can.. for (Iterator things = loaders.values().iterator(); things.hasNext();) { EditToolLoader ldr = (EditToolLoader) things.next(); eomg = ldr.getEditableGraphic(classname, ga); if (eomg != null) { break; } } } else { eomg = loader.getEditableGraphic(classname, ga); } if (eomg instanceof EditableOMGraphicList) { ((EditableOMGraphicList) eomg).init(this); } return eomg; } /** * Given an OMGraphic, check the EditToolLoaders and wrap it in an * EditableOMGraphic. * * @param g the OMGraphic being wrapped. * @return EdtiableOMGraphic, or null if none of the loaders can * figure out what to make. */ public EditableOMGraphic getEditableGraphic(OMGraphic g) { // This is what we need to do to handle an OMGraphicList // handled for editing, but we still need to come up with a // way to handle DrawingToolRequestors. // if (g instanceof OMGraphicList) { // EditableOMGraphicList eomgl = // new EditableOMGraphicList((OMGraphicList)g); // eomgl.init(this); // return eomgl; // } Set keys = loaders.keySet(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); if (DEBUG) Debug.output("OMDrawingTool.getEditableGraphic(" + g.getClass().getName() + "): looking at (" + key + ") loader."); try { Class kc = Class.forName(key); Class gc = g.getClass(); if (kc == gc || kc.isAssignableFrom(gc)) { EditToolLoader loader = (EditToolLoader) loaders.get(key); if (loader == null) { return null; } // There is a reason why the generation of the // graphic is done here. I think it has to do // with something with the creation of the // EditableOMGraphic and its display with the // GrabPoints. generateOMGraphic(g); EditableOMGraphic eomg = loader.getEditableGraphic(g); if (DEBUG) Debug.output("OMDrawingTool.getEditableGraphic(" + g.getClass().getName() + "): found one."); return eomg; } } catch (ClassNotFoundException cnfe) { if (DEBUG) { Debug.output("OMDrawingTool.getEditableGraphic(" + g.getClass().getName() + ") comparision couldn't find class for " + key); } } } return null; } /** * Return true if the OMDrawingTool can edit the OMGraphic. Meant * to be a low-cost check, with a minimal allocation of memory. */ public boolean canEdit(Class omgc) { Iterator iterator; if (possibleEditableClasses == null) { Set keys = loaders.keySet(); possibleEditableClasses = new Vector(keys.size()); iterator = keys.iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); try { possibleEditableClasses.add(Class.forName(key)); } catch (ClassNotFoundException cnfe) { // Don't worry about this now... } } } iterator = possibleEditableClasses.iterator(); while (iterator.hasNext()) { Class kc = (Class) iterator.next(); if (kc == omgc || kc.isAssignableFrom(omgc)) { return true; } } return false; } /** * Set the EditableOMGraphic being used, if it hasn't already been * set. You can set it to null all the time. This method triggers * the selection listeners. */ public synchronized boolean setCurrentEditable(EditableOMGraphic eomg) { if (currentEditable == null || eomg == null) { // Moved here so that currentEditable is set when the // events are fired, in case someone want's to know when // an OMGraphic has been selected. currentEditable = eomg; if (selectionSupport != null) { if (eomg == null && currentEditable != null) { // No longer being edited. selectionSupport.fireSelection(currentEditable.getGraphic(), requestor, false); } else if (eomg != null) { // Starting to be edited. selectionSupport.fireSelection(eomg.getGraphic(), requestor, true); } // else all is null, ignore... } if (currentEditable != null) { return true; } } return false; } /** * Get the current EditableOMGraphic being used by the drawing * tool. Could be null if nothing valid is happening, i.e. if the * OMDrawingTool isn't actively editing something. */ public EditableOMGraphic getCurrentEditable() { return currentEditable; } /** * If you need your OMDrawingToolMouseMode to do something a * little different, you can substitude your subclass here. Don't * set this to null. */ public void setMouseMode(OMDrawingToolMouseMode adtmm) { dtmm = adtmm; } /** * If you want to run the drawing tool in passive mode, you'll * need a handle on the mouseMode to feed events to. */ public OMDrawingToolMouseMode getMouseMode() { return dtmm; } /** * Add an EditToolLoader to the Hashtable of loaders that the * OMDrawingTool can use to create/modify OMGraphics. */ public void addLoader(EditToolLoader loader) { String[] classnames = loader.getEditableClasses(); rawLoaders.add(loader); // Add the loader to the hashtable, with the classnames as // keys. Then, when we get a request for a classname, we do // a lookup and get the proper loader for the key. if (classnames != null) { for (int i = 0; i < classnames.length; i++) { loaders.put(classnames[i].intern(), loader); } possibleEditableClasses = null; } firePropertyChange(LoadersProperty, null, rawLoaders); } /** * Make sure that new property change listeners receive a current * list of edit tool loaders. */ public void addPropertyChangeListener(PropertyChangeListener listener) { if (listener != null) { super.addPropertyChangeListener(listener); listener.propertyChange(new PropertyChangeEvent(this, LoadersProperty, null, rawLoaders)); } } /** * Remove an EditToolLoader from the Hashtable of loaders that the * OMDrawingTool can use to create/modify OMGraphics. */ public void removeLoader(EditToolLoader loader) { String[] classnames = loader.getEditableClasses(); // Remove the loader to the hashtable, with the classnames as // keys. if (classnames != null) { for (int i = 0; i < classnames.length; i++) { EditToolLoader etl = (EditToolLoader) loaders.get(classnames[i].intern()); if (etl == loader) { loaders.remove(classnames[i]); } else { if (DEBUG) { Debug.output("DrawingTool.removeLoader: loader to be removed isn't the current loader for " + classnames[i] + ", ignored."); } } } rawLoaders.remove(loader); firePropertyChange(LoadersProperty, null, rawLoaders); possibleEditableClasses = null; } } /** * Get all the loaders the OMDrawingTool has access to. */ public EditToolLoader[] getLoaders() { Set keys = loaders.keySet(); EditToolLoader[] etls = new EditToolLoader[keys.size()]; Iterator iterator = keys.iterator(); int count = 0; while (iterator.hasNext()) { etls[count++] = (EditToolLoader) loaders.get(iterator.next()); } return etls; } /** * Set the loaders that the OMDrawingTool has access to. */ public void setLoaders(EditToolLoader[] etls) { loaders.clear(); rawLoaders.clear(); for (int i = 0; i < etls.length; i++) { addLoader(etls[i]); } } public void resetGUIWhenDeactivated(boolean value) { resetGUIWhenDeactivated = value; } /** * Get the GUI that dictates what the OMDrawingTool has control * over. This should include a section on controlling the * GraphicAttributes, a section for controls provided by the * current EditableOMGraphic for parameters unique to the EOMG, * and any other controls that the tool may need. This method now * returns this OMDrawingTool, but also serves as a reset method * for the GUI to configure itself for the current * EditableOMGraphic.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -