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

📄 svgselectionmanager.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            public void undo() {                                //restores the old selection                lockedNodes.removeAll(nodesToBeLocked);                currentSelectionType.clear();                currentSelectionType.putAll(oldSelection);                redrawSelection();                                //notifies that the selection has changed                getSVGSelection().selectionChanged(false);            }            public void redo(){                                //restores the selection that had been modified                lockedNodes.addAll(nodesToBeLocked);                currentSelectionType.clear();                currentSelectionType.putAll(newSelection);                redrawSelection();                                //notifies that the selection has changed                getSVGSelection().selectionChanged(false);            }        };                //creates or gets the current undo/redo list and adds the new action into it        if(undoRedoList==null){                        undoRedoList=new SVGUndoRedoActionList(getSVGSelection().undoredolock);        }                undoRedoList.addLast(action);        undoRedoList.setName(getSVGSelection().undoredolock);        refreshSelection();    }    /**     * unlocks the nodes of the current selection     */    protected void unlock(){        //the hashtable of the current selection and the hashtable after the lock action        final LinkedHashMap oldSelection=new LinkedHashMap(), newSelection=new LinkedHashMap();        LinkedList list=new LinkedList(currentSelectionType.keySet());        //copies the hashtable of the current selection        Object obj=null;                for(Iterator it0=currentSelectionType.keySet().iterator(); it0.hasNext();){                        obj=it0.next();            oldSelection.put(obj, currentSelectionType.get(obj));        }        //modifies the hastable 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,"level1");                newSelection.put(current,"level1");                lockedNodes.remove(current);            }        }        //the list of the nodes to be unlocked        final LinkedList fnodes=new LinkedList(list);        SVGUndoRedoAction action=new SVGUndoRedoAction(getSVGSelection().undoredounlock){            public void undo() {                                //restores the old selection                lockedNodes.addAll(fnodes);                currentSelectionType.clear();                currentSelectionType.putAll(oldSelection);                redrawSelection();                                //notifies that the selection has changed                getSVGSelection().selectionChanged(false);            }            public void redo(){                                //restores the selection that had been modified                lockedNodes.removeAll(fnodes);                currentSelectionType.clear();                currentSelectionType.putAll(newSelection);                redrawSelection();                                //notifies that the selection has changed                getSVGSelection().selectionChanged(false);            }        };                //creates or gets the current undo/redo list and adds the new action into it        if(undoRedoList==null){                        undoRedoList=new SVGUndoRedoActionList(getSVGSelection().undoredounlock);        }                undoRedoList.addLast(action);        undoRedoList.setName(getSVGSelection().undoredounlock);        refreshSelection();    }        /**     * returns the shape module having the given name     * @param name a name     * @return a module associated having the given name     */    public SVGShape getShapeModule(String name){        SVGShape shape=null;                if(name!=null){        	        	shape=getSVGSelection().getSVGEditor().getShapeModule(name);        }                if(shape==null){                        shape=getSVGSelection().getSVGEditor().getShapeModule("any");        }                return shape;    }        /**     * returns the name of the shape module linked with the given element     * @param element an element     * @return the name of the shape module linked with the given element     */    public String getAssociatedModuleName(Element element){                String moduleName="";                if(element!=null){        	        	if(SVGEditor.isRtdaAnimationsVersion) {        		        		NodeList children=element.getChildNodes();        		        		if(children!=null && children.getLength()>0) {        			            		for(int i=0; i<children.getLength(); i++){            			            			if(children.item(i).getNodeName().equals(SVGToolkit.jwidgetTagName)){            				            				moduleName="JWidgetManager";            				break;            			}            		}        		}        	}        	        	if(moduleName==null || (moduleName!=null && moduleName.equals(""))) {        		        		moduleName=element.getNodeName();        	}        	        }else {        	        	moduleName="any";        }                return moduleName;    }        /**     * returns the shape module linked with the given element     * @param element an element     * @return a module associated with the given element     */    /*public SVGShape getShapeModule(Element element){                SVGShape shape=null;                if(element!=null){        	        	if(SVGEditor.isRtdaAnimationsVersion) {        		        		NodeList children=element.getElementsByTagName("rtda:jwidget");        		        		if(children!=null && children.getLength()>0) {        			        			//the element is a jwidget element        			shape=SVGEditor.getSVGEditor().getShapeModule("JWidgetManager");        		}        	}        	        	if(shape==null) {        		        		shape=getSVGSelection().getSVGEditor().getShapeModule(element.getNodeName());        	}        }                if(shape==null){                        shape=getSVGSelection().getSVGEditor().getShapeModule("any");        }                return shape;    }*/        /**     * shows an outline of the translation of the given nodes with the given translation values     * @param translationValues     */    protected void translateSelectedNodes(Point2D.Double translationValues){                if(translationValues!=null){                        Iterator it2;            LinkedList list=null, notLockedNodes=null;            SVGShape shape=null;            String name="";            Node node=null;            for(Iterator it=selectedItemsByModule.keySet().iterator(); it.hasNext();){                try{name=(String)it.next();}catch (Exception ex){name=null;}                if(name!=null && ! name.equals("")){                    shape=getShapeModule(name);                                        if(shape!=null){                        try{                            list=(LinkedList)selectedItemsByModule.get(name);                        }catch (Exception ex){list=null;}                        if(list!=null && list.size()>0){                            notLockedNodes=new LinkedList();                            //creates the list that does not contain the locked nodes                            for(it2=list.iterator(); it2.hasNext();){                                try{node=(Node)it2.next();}catch (Exception ex){node=null;}                                if(node!=null && ! isLocked(node)){                                                                        notLockedNodes.add(node);                                }                            }                            if(notLockedNodes!=null && notLockedNodes.size()>0){                                Object[] args={notLockedNodes, translationValues};                                                                //invokes the "doActions" method on the nodes to translate them                                shape.doActions(frame, "level1", SVGShape.DO_TRANSLATE_ACTION, args);                            }                        }                    }                }            }        }    }        /**     * translates the given nodes with the translation values range     * @param translationValues     */    protected void validateTranslateSelectedNodes(Point2D.Double translationValues){                final Point2D.Double ftranslationValues=translationValues;                if(ftranslationValues!=null){            Runnable runnable=new Runnable(){                public void run(){                    Iterator it2;                    LinkedList list=null, notLockedNodes=null;                    SVGShape shape=null;                    String name="";                    Node node=null;                    //for each type of modules                    for(Iterator it=selectedItemsByModule.keySet().iterator(); it.hasNext();){                        try{name=(String)it.next();}catch (Exception ex){name=null;}                        if(name!=null && ! name.equals("")){                                                        //gets the module                            shape=getShapeModule(name);                            if(shape!=null){                                try{                                    list=(LinkedList)selectedItemsByModule.get(name);                                }catch (Exception ex){list=null;}                                if(list!=null && list.size()>0){                                    notLockedNodes=new LinkedList();                                    //creates the list that does not contain the locked nodes                                    for(it2=list.iterator(); it2.hasNext();){                                        try{node=(Node)it2.next();}catch (Exception ex){node=null;}                                        if(node!=null && ! isLocked(node)){                                            notLockedNodes.add(node);                                        }                                    }                                    if(notLockedNodes.size()>0){                                        Object[] args={notLockedNodes, ftranslationValues};                                                                                //invokes the "doActions" method on the nodes to translate them                                        shape.doActions(frame, "level1", SVGShape.VALIDATE_TRANSLATE_ACTION,args);                                    }                                }                            }                        }                    }                    //notifies that the selection has changed                    refreshSelection();                    getSVGSelection().selectionChanged(true);                }            };            frame.enqueue(runnable);        }    }        /**     * the method for doing an action given the current selection square and the points     * @param square     * @param originPoint     * @param point     * @param scaledOriginPoint     * @param scaledPoint     */    protected void doActions(SVGSelectionSquare square, Point2D.Double originPoint, Point2D.Double point, Point2D.Double scaledOriginPoint, Point2D.Double scaledPoint){        if(square!=null && originPoint!=null && point!=null && scaledOriginPoint!=null && scaledPoint!=null){                        final String type=(String)currentSelectionType.get(square.getNode());            final SVGShape shape=getShapeModule(getAssociatedModuleName((Element)square.getNode()));            if(type!=null && shape!=null && ! type.equals("lock") ){                final Object[] args={square, originPoint, point, scaledOriginPoint, scaledPoint};                shape.doActions(frame, type, SVGShape.DO_ACTION, args);            }        }    }    /**     * the method for validating an action given the current selection square and the points     * @param square     * @param originPoint     * @param point     * @param scaledOriginPoint     * @param scaledPoint     */    protected void validateDoActions(SVGSelectionSquare square, Point2D.Double originPoint, Point2D.Double point, Point2D.Double scaledOriginPoint, Point2D.Double scaledPoint){        if(square!=null && originPoint!=null && point!=null && scaledOriginPoint!=null && scaledPoint!=null){                        final String type=(String)currentSelectionType.get(square.getNode());            final SVGShape shape=getShapeModule(getAssociatedModuleName((Element)square.getNode()));            if(type!=null && shape!=null && ! type.equals("lock") ){                final Object[] args={square, originPoint, point, scaledOriginPoint, scaledPoint};                Runnable runnable=new Runnable(){                    public void run() {                        shape.doActions(frame, type, SVGShape.VALIDATE_ACTION, args);                        getSVGSelection().selectionChanged(true);                    }                 };                frame.enqueue(runnable);            }        }    }}

⌨️ 快捷键说明

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