📄 svgselectionmanager.java
字号:
* sets the cursor to be displayed on the canvas * @param point a point on the canvas */ protected void setCursor(Point2D.Double point){ SVGSelectionSquare sq=getSelectionSquare(point); SVGCanvas canvas=frame.getScrollPane().getSVGCanvas(); if(sq!=null){ //if the selection square is not null, sets the canvas cursor with the cursor associated with the square currentCursor=sq.getCursor(); canvas.setSVGCursor(currentCursor); }else{ //if the selection square is null, //if the node (on which the mouse event has been done) is selected, //sets the new cursor, otherwise sets the default cursor Node node=frame.getNodeAt(parentElement, point); if(node!=null && isSelected(node) && ! isLocked(node)){ currentCursor=getSVGSelection().getSVGEditor().getCursors().getCursor("translate"); }else{ currentCursor=getSVGSelection().getSVGEditor().getCursors().getCursor("default"); } canvas.setSVGCursor(currentCursor); } } /** * adds the selection squares contained in the map to the selection squares * @param table the map associating a node to selection squares */ public void addSelectionSquares(Hashtable table){ if(table!=null){ selectionSquares.putAll(table); } } /** * adds an undo/redo action to the action list * @param action the action to be added */ public void addUndoRedoAction(SVGUndoRedoAction action){ if(action!=null && getSVGSelection().getSVGEditor().getUndoRedo()!=null){ if(undoRedoList==null){ undoRedoList=new SVGUndoRedoActionList(action.getName()); } undoRedoList.addLast(action); undoRedoList.setName(action.getName()); } } /** * selects the given element that is not already selected, does not handle undo/redos * @param element a non selected element */ protected void select(Element element){ } /** adds or removes a node from the selected nodes * @param element the element that will be treated * @param isMultiSelectionEnabled true if the multi selection is enabled * @param enableUndoRedoAction the boolean telling if an undo/redo action should be added for this method * @param alwaysSelect whether to always select the given node */ public void handleNodeSelection(Element element, boolean isMultiSelectionEnabled, boolean enableUndoRedoAction, boolean alwaysSelect){ if( element!=null && ! element.getNodeName().equals("svg") && ! element.equals(element.getOwnerDocument().getDocumentElement())){ final Element felement=element; //gets the list of the selected nodes managed by one module LinkedList list=(LinkedList)selectedItemsByModule.get(getAssociatedModuleName(element)); if(list==null){ list=new LinkedList(); } //if the list does not contain a node, the node is added, otherwise, it is removed if(alwaysSelect || ! isMultiSelectionEnabled || (isMultiSelectionEnabled && ! list.contains(element))){ //sets the selection level String type="default"; if(! list.contains(element)){ list.add(element); }else{ type=(String)currentSelectionType.get(element); } selectedItemsByModule.put(getAssociatedModuleName(element), list); //gets the default first selection level for the node SVGShape shape=getShapeModule(getAssociatedModuleName(element)); if(shape!=null && ! isLocked(element)){ type=shape.getNextLevel(type); }else if(isLocked(element)){ type="lock"; } currentSelectionType.put(element, type); //create the undo/redo action and insert it into the undo/redo stack if(enableUndoRedoAction && getSVGSelection().getSVGEditor().getUndoRedo()!=null){ final String ftype=type; SVGUndoRedoAction action=new SVGUndoRedoAction(getSVGSelection().undoredoselect){ public void undo(){ //gets the list of the selected nodes managed by one module LinkedList list=(LinkedList)selectedItemsByModule.get(getAssociatedModuleName(felement)); if(list==null){ list=new LinkedList(); } //removes the node from the list list.remove(felement); //removes the list from the map if it is empty if(list.size()==0){ selectedItemsByModule.remove(getAssociatedModuleName(felement)); } //removes the node from the map of the types currentSelectionType.remove(felement); } public void redo(){ //gets the list of the selected nodes managed by one module LinkedList list=(LinkedList)selectedItemsByModule.get(getAssociatedModuleName(felement)); if(list==null){ list=new LinkedList(); } //removes the node from the list list.add(felement); //removes the list from the map if it is empty if(list.size()==1){ selectedItemsByModule.put(getAssociatedModuleName(felement), list); } //removes the node from the map of the types currentSelectionType.put(felement, ftype); } }; //creates a undoredo list into which the action will be inserted if(undoRedoList==null){ undoRedoList=new SVGUndoRedoActionList(getSVGSelection().undoredoselect); } undoRedoList.add(action); undoRedoList.setName(getSVGSelection().undoredoselect); } }else if(isMultiSelectionEnabled && list.contains(element)){ list.remove(element); //removes this list from the map if it is empty if(list.size()==0){ selectedItemsByModule.remove(getAssociatedModuleName(element)); } //getting the type associated with this node final String type=(String)currentSelectionType.get(element); currentSelectionType.remove(element); //create the undo/redo action and insert it into the undo/redo stack if(enableUndoRedoAction && getSVGSelection().getSVGEditor().getUndoRedo()!=null){ SVGUndoRedoAction action=new SVGUndoRedoAction(getSVGSelection().undoredodeselect){ public void undo() { //gets the list of the selected nodes managed by one module LinkedList list=(LinkedList)selectedItemsByModule.get(getAssociatedModuleName(felement)); if(list==null){ list=new LinkedList(); } //removes the node from the list list.add(felement); //removes the list from the map if it is empty if(list.size()==1){ selectedItemsByModule.put(getAssociatedModuleName(felement), list); } //removes the node from the map of the types currentSelectionType.put(felement, type); } public void redo(){ //gets the list of the selected nodes managed by one module LinkedList list=(LinkedList)selectedItemsByModule.get(getAssociatedModuleName(felement)); if(list==null){ list=new LinkedList(); } //removes the node from the list list.remove(felement); //removes the list from the map if it is empty if(list.size()==0){ selectedItemsByModule.remove(getAssociatedModuleName(felement)); } //removes the node from the map of the types currentSelectionType.remove(felement); } }; //creates a undoredo list into which the action will be inserted if(undoRedoList==null){ undoRedoList=new SVGUndoRedoActionList(getSVGSelection().undoredodeselect); } undoRedoList.addLast(action); undoRedoList.setName(getSVGSelection().undoredodeselect); } } } } /** * refreshes the hashtable of the selected items, and draws the selections */ public void refreshSelection(){ //adds the current undo/redo list into the undo/redo stack if(getSVGSelection().getSVGEditor().getUndoRedo()!=null && undoRedoList!=null && undoRedoList.size()>0){ SVGUndoRedoAction actionFirst=new SVGUndoRedoAction(""){ public void undo() { redrawSelection(); getSVGSelection().selectionChanged(false); } public void redo(){ } }; SVGUndoRedoAction actionLast=new SVGUndoRedoAction(""){ public void undo() { } public void redo(){ redrawSelection(); getSVGSelection().selectionChanged(false); } }; undoRedoList.addFirst(actionFirst); undoRedoList.addLast(actionLast); getSVGSelection().getSVGEditor().getUndoRedo().addActionList(frame, undoRedoList); undoRedoList=null; } //notifies that the selection has changed getSVGSelection().selectionChanged(false); //redraws the selections of the selected nodes redrawSelection(); } /** * notifies the refresh manager that a refresh should be done */ protected synchronized void redrawSelection(){ shouldRefresh=true; } /** * redraws the selections over the nodes that have been selected */ protected void redrawSelectionMethod(){ //stopping refreshing the canvas frame.getScrollPane().getSVGCanvas().setRepaintEnabled(false); //deselects all the shape modules SVGShape sh=null; for(Iterator it=getSVGSelection().getSVGEditor().getShapeModules().iterator(); it.hasNext();){ try{sh=(SVGShape)it.next();}catch (Exception ex){sh=null;} if(sh!=null){ sh.deselectAll(frame, false); } } clearSelectionSquares(); Hashtable dSelectedItemsByModule=new Hashtable(selectedItemsByModule), selectedItems=null, map; LinkedHashMap dCurrentSelectionType=new LinkedHashMap(currentSelectionType); Iterator it2; LinkedList list=null; String current=null; Object obj=null; //invokes on each module the "select" method passing the linked list containing the nodes to be selected for each module as an argument for(Iterator it=dSelectedItemsByModule.keySet().iterator(); it.hasNext();){ try{ current=(String)it.next(); list=(LinkedList)dSelectedItemsByModule.get(current); }catch (Exception ex){list=null;} if(list!=null && list.size()>0){ selectedItems=new Hashtable(); for(it2=list.iterator(); it2.hasNext();){ obj=it2.next(); if(obj!=null){ String type=(String)dCurrentSelectionType.get(obj); if(type!=null){ selectedItems.put(obj, type); } } } //getting the shape module sh=getShapeModule(current); if(sh!=null){ //selecting the items sh.select(frame, selectedItems); //getting the selection squares map=sh.getSelectionSquares(frame); if(map!=null){ selectionSquares.putAll(map); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -