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

📄 svgselection.java~1~

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA~1~
📖 第 1 页 / 共 3 页
字号:
/* * Created on 7 avr. 2004 * =============================================                   GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 =============================================Copyright (C) 2003 Jordi SUC, Philippe Gil, SARL ITRISThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USAContact : jordi.suc@itris.fr; philippe.gil@itris.fr ============================================= */package fr.itris.glips.svgeditor.selection;import fr.itris.glips.svgeditor.*;import fr.itris.glips.svgeditor.menutool.*;import fr.itris.glips.svgeditor.undoredo.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.resources.*;import javax.swing.*;import org.w3c.dom.*;import java.awt.event.*;import java.awt.*;import java.awt.geom.*;import java.util.*;/** * @author Jordi SUC * the class managing the selections over the canvas */public class SVGSelection extends SVGModuleAdapter{    /**     * the ids of the module     */    final private String idselection="Selection", idselectall="SelectAll", iddeselectall="DeselectAll", idlock="Lock", 									idunlock="UnLock", idregularmode="RegularMode", idgroupmenu="GroupMenu", idgroupenter="EnterGroup", 									idgroupexit="ExitGroup";    /**     * the labels     */    protected String labelselection="", labelselect="", labelselectall="", labeldeselectall="", labellock="", 								labelunlock="", labelregularmode="", labelgroup="", labelgroupenter="", labelgroupexit="";    /**     * the undo/redo labels     */    protected String undoredoselect="", undoredodeselect="", undoredodeselectall="", undoredoselectall="", 								undoredolock="", undoredounlock="", undoredogroupenter="", undoredogroupexit="";    /**     * the menu items that will be inserted into the menubar     */    private JMenuItem selectAll, deselectAll, lock, unlock, groupEnter, groupExit;        /**     * the listeners to the menu items     */    private ActionListener selectAllListener, deselectAllListener, lockListener, unlockListener, groupEnterListener, groupExitListener;        /**     * the group menu     */    private JMenu groupMenu;    /**     * the tool button corresponding to a regular selection     */    private JToggleButton regularModeTool=null;        /**     * the listener to the regular mode tool button     */    private ActionListener regularModeToolListener=null;    /**     * a reference to the current object of this class     */    private final SVGSelection selection=this;        /**     * whether the selection is enabled or not     */    private boolean isSelectionEnabled=true;        /**     * the map associating a frame to its selection manager     */    private Map selectionManagers=Collections.synchronizedMap(new Hashtable());        /**     * the listeners that are registered by other modules to be notified when a selection modification occurs     */    private LinkedList selectionListeners=new LinkedList();    /**     * the color for drawing the selected area     */    protected final Color LINE_SELECTION_COLOR=new Color(75, 100, 200),    									LINE_SELECTION_COLOR_HIGHLIGHT=new Color(255,255,255);    	/**	 * the stroke for the selection outlines	 */	protected static final BasicStroke lineStroke=new BasicStroke(	1, BasicStroke.CAP_BUTT, 	        																										BasicStroke.JOIN_BEVEL, 	        																										0, new float[]{5, 5}, 0);        /**     * the lastly selected nodes     */    private final java.util.List lastSelectedNodes=Collections.synchronizedList(new LinkedList());    /**     * the editor     */    private SVGEditor editor;    /**     * the constructor of the class     * @param editor the editor     */    public SVGSelection(SVGEditor editor){        this.editor=editor;        //gets the labels from the resources        ResourceBundle bundle=SVGEditor.getBundle();        if(bundle!=null){                        try{                labelselection=bundle.getString("labelselection");                labelselectall=bundle.getString("labelselectall");                labeldeselectall=bundle.getString("labeldeselectall");                labellock=bundle.getString("labellock");                labelunlock=bundle.getString("labelunlock");                labelgroup=bundle.getString("labelgroup");                labelgroupenter=bundle.getString("labelgroupenter");                labelgroupexit=bundle.getString("labelgroupexit");                labelregularmode=bundle.getString("labelregularmode");                undoredoselect=bundle.getString("undoredoselect");                undoredodeselect=bundle.getString("undoredodeselect");                undoredodeselectall=bundle.getString("undoredodeselectall");                undoredoselectall=bundle.getString("undoredoselectall");                undoredolock=bundle.getString("undoredolock");                undoredounlock=bundle.getString("undoredounlock");                undoredogroupenter=bundle.getString("undoredogroupenter");                undoredogroupexit=bundle.getString("undoredogroupexit");            }catch (Exception ex){}        }        //the icons        final ImageIcon 	regularModeIcon=SVGResource.getIcon(idregularmode, false),        							regularModeDisabledIcon=SVGResource.getIcon(idregularmode, true);		//getting the icons		ImageIcon selectAllIcon=SVGResource.getIcon("SelectAll", false),						dselectAllIcon=SVGResource.getIcon("SelectAll", true),						deselectAllIcon=SVGResource.getIcon("DeselectAll", false),						ddeselectAllIcon=SVGResource.getIcon("DeselectAll", true),						lockIcon=SVGResource.getIcon("Lock", false),						dlockIcon=SVGResource.getIcon("Lock", true),						unlockIcon=SVGResource.getIcon("Unlock", false),						dunlockIcon=SVGResource.getIcon("Unlock", true),						groupEnterIcon=SVGResource.getIcon("GroupEnter", false),						dgroupEnterIcon=SVGResource.getIcon("GroupEnter", true),						groupExitIcon=SVGResource.getIcon("GroupExit", false),						dgroupExitIcon=SVGResource.getIcon("GroupExit", true);						                //creates the menu items        selectAll=new JMenuItem(labelselectall, selectAllIcon);        selectAll.setDisabledIcon(dselectAllIcon);        selectAll.setAccelerator(KeyStroke.getKeyStroke("ctrl A"));        selectAll.setEnabled(false);                deselectAll=new JMenuItem(labeldeselectall, deselectAllIcon);        deselectAll.setDisabledIcon(ddeselectAllIcon);        deselectAll.setAccelerator(KeyStroke.getKeyStroke("ctrl D"));        deselectAll.setEnabled(false);        lock=new JMenuItem(labellock, lockIcon);        lock.setDisabledIcon(dlockIcon);        lock.setEnabled(false);                unlock=new JMenuItem(labelunlock, unlockIcon);        unlock.setDisabledIcon(dunlockIcon);        unlock.setEnabled(false);                groupEnter=new JMenuItem(labelgroupenter, groupEnterIcon);        groupEnter.setDisabledIcon(dgroupEnterIcon);        groupEnter.setAccelerator(KeyStroke.getKeyStroke("shift ctrl E"));        groupEnter.setEnabled(false);                groupExit=new JMenuItem(labelgroupexit, groupExitIcon);        groupExit.setDisabledIcon(dgroupExitIcon);        groupExit.setAccelerator(KeyStroke.getKeyStroke("shift ctrl X"));        groupExit.setEnabled(false);                //the group menu        groupMenu=new JMenu(labelgroup);        groupMenu.add(groupEnter);        groupMenu.add(groupExit);        //creates the tool items        regularModeTool=new JToggleButton(regularModeDisabledIcon);        regularModeTool.setEnabled(false);        regularModeTool.setSelected(true);        regularModeTool.setToolTipText(labelregularmode);                //a listener that listens to the changes of the SVGFrames        final ActionListener svgframeListener=new ActionListener(){            /**             * a listener on the selection changes             */            private ActionListener selectionListener=null;            public void actionPerformed(ActionEvent e) {            	//clears the last selection            	lastSelectedNodes.clear();            	                //deals with the state of the menu items                if(getSVGEditor().getFrameManager().getFrameNumber()>0){                    selectAll.setEnabled(true);                    deselectAll.setEnabled(true);                    regularModeTool.setEnabled(true);                    regularModeTool.setIcon(regularModeIcon);                }else{                    selectAll.setEnabled(false);                    deselectAll.setEnabled(false);                    regularModeTool.setEnabled(false);                    regularModeTool.setIcon(regularModeDisabledIcon);                }                //disables the menuitems                lock.setEnabled(false);                unlock.setEnabled(false);                groupEnter.setEnabled(false);                groupExit.setEnabled(false);                SVGSelectionManager selectionManager=null;                Collection frames=getSVGEditor().getFrameManager().getFrames();                                for(Iterator it=new LinkedList(selectionManagers.values()).iterator(); it.hasNext();){                                        try{selectionManager=(SVGSelectionManager)it.next();}catch (Exception ex){selectionManager=null;}                    if(selectionManager!=null && ! frames.contains(selectionManager.getSVGFrame())){                        selectionManagers.remove(selectionManager.getSVGFrame());                        selectionManager.dispose();                    }                }                SVGFrame frame=null;                                //adds the new mouse motion and key listeners                for(Iterator it=frames.iterator(); it.hasNext();){                    try{frame=(SVGFrame)it.next();}catch (Exception ex){frame=null;}                    if(frame!=null && ! selectionManagers.containsKey(frame)){                                                selectionManagers.put(frame, new SVGSelectionManager(selection, frame));                    }                }                frame=getSVGEditor().getFrameManager().getCurrentFrame();                if(frame!=null){                    manageSelection();                    //the listener to the selection changes                    selectionListener=new ActionListener(){                        public void actionPerformed(ActionEvent e) {                            manageSelection();                        }                    };                                        //adds the selection listener                    if(selectionListener!=null){                                                selection.addSelectionListener(selectionListener);                    }                }            }            /**             * updates the selected items and the state of the menu items             */            protected void manageSelection(){                SVGFrame currentFrame=getSVGEditor().getFrameManager().getCurrentFrame();                                //disables the menuitems                deselectAll.setEnabled(false);                lock.setEnabled(false);                unlock.setEnabled(false);                groupEnter.setEnabled(false);                //getting the current parent node for the current frame                Element parent=getCurrentParentElement(currentFrame);                                //handling the enablement of the groupExit menuItem                if(parent!=null && parent.getNodeName().equals("g")){                                        groupExit.setEnabled(true);                                    }else{                                        groupExit.setEnabled(false);                }                Node current=null;                String type="";                //gets the currently selected nodes list                Map selectedNodes=getSelectionMap(currentFrame);                if(selectedNodes.size()>0){                    lock.setEnabled(true);                    deselectAll.setEnabled(true);                                        //if the node is already locked                    if(selectedNodes.size()==1){                                                try{                            current=(Node)selectedNodes.keySet().iterator().next();                            type=(String)selectedNodes.get(current);                                                        if(type.equals("lock")){                                                                lock.setEnabled(false);                                                            }else if(current.getNodeName().equals("g")){                                                                groupEnter.setEnabled(true);                            }                        }catch (Exception ex){}                    }                    for(Iterator it=selectedNodes.keySet().iterator(); it.hasNext();){                        try{current=(Node)it.next();}catch (Exception ex){current=null;}                        if(current!=null){                            type=(String)selectedNodes.get(current);                            if(type!=null && type.equals("lock")){                                unlock.setEnabled(true);                                break;                            }                        }                    }                }            }        };        //adds the SVGFrame change listener        editor.getFrameManager().addSVGFrameChangedListener(svgframeListener);        //adds the listener on the menu items and tool items        regularModeToolListener=new ActionListener(){            public void actionPerformed(ActionEvent e) {

⌨️ 快捷键说明

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