⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgselectionmanager.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        //enabling refreshing the canvas        frame.getScrollPane().getSVGCanvas().setRepaintEnabled(true);    }    /**     * selects all the nodes included in the given rectangle     * @param rect a rectangle     * @param parent the parent element into which the selection will be computed     * @param isMultiSelectionEnabled true if the mutli selection is enabled     */    protected void select(Rectangle2D.Double rect, Element parent, boolean isMultiSelectionEnabled){        if(! isMultiSelectionEnabled){            deselectAll(false, false);        }        if(rect!=null && parent!=null){                        Rectangle2D r2=null;            for(Node current=parent.getFirstChild(); current!=null; current=current.getNextSibling()){                                if(current instanceof Element && SVGToolkit.isElementAShape((Element)current)){                                        r2=frame.getNodeGeometryBounds((Element)current);                    if(r2!=null){                        Rectangle2D.Double r3=new Rectangle2D.Double(r2.getX(), r2.getY(), r2.getWidth()+1, r2.getHeight()+1);                        //if the node is contained in the rectangle, it is selected                        if(r3!=null && rect.contains(r3)){                            handleNodeSelection((Element)current, isMultiSelectionEnabled, true, true);                        }                    }                }            }            refreshSelection();        }    }    /**     * tells whether a node is selected or not     * @param node     * @return true if the given node is selected     */    protected boolean isSelected(Node node){        return currentSelectionType.containsKey(node);    }    /**     * tells if one or more nodes are selected     * @return true if one or more nodes are selected     */    protected boolean isSmthSelected(){        if(currentSelectionType.size()>0){            return true;        }                return false;    }    /**     * deselects all the items on the canvas     * @param validateAction true to validate the action     * @param executeWhenNoNodesSelected whether to execute this method even if no node is selected     */    public void deselectAll(boolean validateAction, boolean executeWhenNoNodesSelected){        //creates the undo/redo action        if(getSVGSelection().getSVGEditor().getUndoRedo()!=null && (isSmthSelected() || executeWhenNoNodesSelected)){                        //stopping all the actions on the canvas//            SVGCanvas canvas=frame.getScrollPane().getSVGCanvas();            //creates a copy of the list of the selected items            final LinkedList oldSelection=new LinkedList(currentSelectionType.keySet());            SVGUndoRedoAction action=new SVGUndoRedoAction(getSVGSelection().undoredodeselectall){                public void undo(){                    selectedItemsByModule.clear();                    currentSelectionType.clear();                    selectionSquares.clear();                                        //reselects all the nodes that have been deselected                    Node current=null;                    for(Iterator it=oldSelection.iterator(); it.hasNext();){                                                try{current=(Node)it.next();}catch (Exception e){current=null;}                        if(current!=null && current instanceof Element){                                                        handleNodeSelection((Element)current, false, false, false);                        }                    }                                        redrawSelection();                    getSVGSelection().selectionChanged(false);                }                public void redo(){                                        selectedItemsByModule.clear();                    currentSelectionType.clear();                    selectionSquares.clear();                    //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);                		}                	}                	                	frame.getScrollPane().getSVGCanvas().delayedRepaint();                }            };                        //creates or gets the current undo/redo list and adds the new action into it            if(undoRedoList==null){                                undoRedoList=new SVGUndoRedoActionList(getSVGSelection().undoredodeselectall);            }                        undoRedoList.addLast(action);            undoRedoList.setName(getSVGSelection().undoredodeselectall);        }                //removing all the nodes from the selection         selectedItemsByModule.clear();        currentSelectionType.clear();        selectionSquares.clear();        //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, true);    		}    	}        //refreshes the selection        if(validateAction){                        refreshSelection();        }    }    /**     * selects all the nodes of the dom     * @param validateAction true to validate the action     */    protected void selectAll(boolean validateAction){        final LinkedList nodesThatWereSelected=new LinkedList(currentSelectionType.keySet());        //deselects all the selected nodes        deselectAll(false, false);        final LinkedList nodesToBeSelected=new LinkedList();        if(getParentElement()!=null){            for(Node current=getParentElement().getFirstChild(); current!=null; current=current.getNextSibling()){                if(current instanceof Element && ! current.getNodeName().equals("defs")){                                        handleNodeSelection((Element)current, false, true, false);                    nodesToBeSelected.add(current);                }            }        }                if(undoRedoList==null){                        undoRedoList=new SVGUndoRedoActionList(getSVGSelection().undoredodeselectall);        }                //adding the undo/redo action        undoRedoList.addLast(new SVGUndoRedoAction(getSVGSelection().undoredoselectall){            public void undo() {                                redrawSelection();            }            public void redo() {                                redrawSelection();            }        });                undoRedoList.setName(getSVGSelection().undoredoselectall);        //refreshes the selection        if(validateAction){                        refreshSelection();        }    }    /**     * gets the list of the selected nodes     * @return the list of the selected nodes     */    protected LinkedList<Element> getCurrentSelection(){        LinkedList<Element> list=new LinkedList();        Element current=null;                for(Iterator it=currentSelectionType.keySet().iterator(); it.hasNext();){                        try{current=(Element)it.next();}catch (Exception ex){current=null;}                        if(current!=null){                                String type=(String)currentSelectionType.get(current);                                if(type!=null && ! type.equals("lock")){                                        list.add(current);                }            }        }                return list;    }    /**     * @return the map of the current selection     */    protected Map getCurrentSelectionTypeMap(){        return new Hashtable(currentSelectionType);    }    /**     * adds the squares associated to a node in the selectionsquares hashtable     * @param node a node     * @param squares a list of selection squares     */    protected void addSelectionSquares(Node node, LinkedList squares){        if(selectionSquares.containsKey(node)){                        selectionSquares.remove(node);        }                selectionSquares.put(node, squares);    }    /**     * removes the squares associated to a node in the selectionsquares hashtable     * @param node a node     * @param squares a list of selection squares     */    protected void removeSelectionSquares(Node node, LinkedList squares){        if(selectionSquares.containsKey(node)){                        selectionSquares.remove(node);        }    }    /**     * clears the selection squares map     */    protected void clearSelectionSquares(){        LinkedList currentList=null;                for(Iterator it=selectionSquares.keySet().iterator(); it.hasNext();){                        currentList=(LinkedList)selectionSquares.get(it.next());                        if(currentList!=null){                                currentList.clear();            }        }                selectionSquares.clear();    }    /**     * gets the SelectionSquare object on which a mouse event has been done     * @param point the point on the canvas with a 1.0 scale     * @return the SelectionSquare object on which a mouse event has been done     * 			 null if the mouse event has not been done on the representation of a SelectionSquare object     */    public SVGSelectionSquare getSelectionSquare(Point2D.Double point){        Point2D.Double pt=frame.getScaledPoint(point, false);        Iterator it2=null;        LinkedList currentList=null;        SVGSelectionSquare square=null;        Rectangle2D.Double rect=null;                for(Iterator it=selectionSquares.values().iterator(); it.hasNext();){                        currentList=(LinkedList)it.next();                        if(currentList!=null){                for(it2=currentList.iterator(); it2.hasNext();){                                        square=(SVGSelectionSquare)it2.next();                    rect=square.getRectangle();                                        if(rect!=null && rect.contains(pt)){                                                return square;                    }                }            }        }                return null;    }        /**     * returns true if the node is locked     * @param node a node     * @return true if the node is locked     */    protected boolean isLocked(Node node){                if(node!=null && lockedNodes.contains(node)){                        return true;        }                return false;    }    /**     * locks the nodes of the current selection     */    protected void lock(){        //the hashtable of the current selection and the hashtable after the lock action        final LinkedHashMap oldSelection=new LinkedHashMap(), newSelection=new LinkedHashMap();                //the list of the nodes to be locked        final LinkedList nodesToBeLocked=new LinkedList();        //copies the hashtable of the current selection        LinkedList list=new LinkedList(currentSelectionType.keySet());        Object obj=null;                for(Iterator it0=currentSelectionType.keySet().iterator(); it0.hasNext();){                        obj=it0.next();            oldSelection.put(obj, currentSelectionType.get(obj));        }        //modifies the map of the current selection        Node current=null;        currentSelectionType.clear();                for(Iterator it=list.iterator(); it.hasNext();){                        try{current=(Node)it.next();}catch (Exception ex){current=null;}                        if(current!=null){                                currentSelectionType.put(current,"lock");                newSelection.put(current,"lock");                                if(! lockedNodes.contains(current)){                                        lockedNodes.add(current);                    nodesToBeLocked.add(current);                }            }        }        SVGUndoRedoAction action=new SVGUndoRedoAction(getSVGSelection().undoredounlock){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -