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

📄 svgeditor.java~1~

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
/* * Created on 23 mars 2004  *  ============================================= GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 ============================================= GLIPS Graffiti Editor, a SVG Editor Copyright (C) 2003 Jordi SUC, Philippe Gil, SARL ITRIS  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  Contact : jordi.suc@itris.fr; philippe.gil@itris.fr  ============================================= */package fr.itris.glips.svgeditor;import fr.itris.glips.svgeditor.resources.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.menutool.*;import fr.itris.glips.svgeditor.undoredo.*;import fr.itris.glips.svgeditor.selection.*;import fr.itris.glips.svgeditor.shape.*;import fr.itris.glips.svgeditor.colorchooser.*;import javax.swing.*;import com.jgoodies.looks.plastic.*;import org.w3c.dom.*;import java.awt.*;import java.text.*;import java.util.*;import java.io.*;import java.lang.reflect.*;import java.awt.dnd.*;import java.awt.image.BufferedImage;import java.net.*;/** * The main class of the editor *  * @author Jordi SUC */public class SVGEditor {		/**	 * whether the editor handles the rtda animations	 */	public static boolean isRtdaAnimationsVersion=false;		/**	 * the parent container	 */	private static Container parentContainer=null;		/**	 * the component in which SVGFrames are inserted	 */	private JComponent desktop;		/**	 * the module loader	 */	private static SVGModuleManager moduleManager;		/**	 * the class that gives the resources	 */	private SVGResource resource;		/**	 * the toolkit object	 */	private SVGToolkit toolkit;		/**	 * tells whether the mutli windowing method has to be used or not	 */	private boolean isMultiWindow=false;		/**	 * the undo/Rdo module	 */	private SVGUndoRedo undoRedo;		/**	 * the map associating a name to a rectangle representing bounds	 */	private final Map<String, Rectangle> widgetBounds=new Hashtable<String, Rectangle>();		/**	 * the selection module	 */	private SVGSelection selection;		/**	 * the drag source	 */	private DragSource dragSource=DragSource.getDefaultDragSource();    	/**	 * the color chooser of the editor	 */	private static SVGColorChooser colorChooser=null;        /**     * whether the quit action is disabled     */    private boolean isQuitActionDisabled=false;        /**     * whether the JVM will be exited when the user requires to exit from the editor     */    private boolean canExitFromJVM=false;        /**     * the font     */    public static final Font theFont=new Font("theFont", Font.ROMAN_BASELINE, 12);        /**     * the small font     */    public static final Font smallFont=new Font("smallFont", Font.ROMAN_BASELINE, 10);        /**     * the set of the runnables that should be run when the editor is exiting     */    private HashSet<Runnable> disposeRunnables=new HashSet<Runnable>();        /**     * the map of the name spaces that should be checked     */    public static HashMap<String, String> requiredNameSpaces=new HashMap<String, String>();        /**     * the resource bundle for this editor     */    private static ResourceBundle bundle=null;        /**     * the decimal format and the format used when displaying numbers     */	private static DecimalFormat format, displayFormat;		/**	 * the svg editor	 */	private static SVGEditor editor=null;        /**     * creating the bundle     */    static {                try{            bundle=ResourceBundle.getBundle("fr.itris.glips.svgeditor.resources.properties.SVGEditorStrings");        }catch (Exception ex){bundle=null;}        		//sets the format object that will be used to convert a double value into a string		DecimalFormatSymbols symbols=new DecimalFormatSymbols();		symbols.setDecimalSeparator('.');		format=new DecimalFormat("############.################", symbols);		displayFormat=new DecimalFormat("##########.#", symbols);    }		/**	 * The constructor of the class	 */	public SVGEditor(){		try {			PlasticXPLookAndFeel laf=new PlasticXPLookAndFeel();			UIManager.setLookAndFeel(laf);			PlasticLookAndFeel.set3DEnabled(true);		 } catch (Exception e) {}		 		 editor=this;	}		/**	 * initializing the editor	 * @param parent the parent container for the application	 * @param fileToBeLoaded the file to be directly loaded     * @param showSplash whether the splash screen should be shown or not     * @param displayFrame whether or not to show the frame      * @param quitDisabled whether the quit action is disabled     * @param exitFromJVM whether the JVM will be exited when the user requires to exit from the editor     * @param disposeRunnable the runnable that should be run when exiting the editor	 */	public void init(Container parent, String fileToBeLoaded, boolean showSplash, final boolean displayFrame, 									boolean quitDisabled, boolean exitFromJVM, Runnable disposeRunnable) {   		//loading classes of the library		/*try {			Class.forName("fr.itris.glips.svgeditor.canvas.SVGCanvas", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.bridge.UserAgentAdapter", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.bridge.GVTBuilder", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.bridge.BridgeContext", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.bridge.UpdateManager", true, ClassLoader.getSystemClassLoader());									Class.forName("org.apache.batik.gvt.GraphicsNode", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.gvt.AbstractGraphicsNode", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.gvt.CompositeGraphicsNode", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.gvt.CanvasGraphicsNode", true, ClassLoader.getSystemClassLoader());			Class.forName("org.apache.batik.gvt.ShapeNode", true, ClassLoader.getSystemClassLoader());						Class.forName("org.apache.batik.dom.svg.SVGDOMImplementation", true, ClassLoader.getSystemClassLoader());			Class.forName("org.w3c.dom.svg.SVGDocument", true, ClassLoader.getSystemClassLoader());		}catch (Exception ex) {ex.printStackTrace();}*/				parentContainer=parent;        this.isQuitActionDisabled=quitDisabled;        this.canExitFromJVM=exitFromJVM;                if(disposeRunnable!=null){        	    		this.disposeRunnables.add(disposeRunnable);        }		//setting the values for the tooltip manager		ToolTipManager.sharedInstance().setInitialDelay(100);		ToolTipManager.sharedInstance().setDismissDelay(10000);		ToolTipManager.sharedInstance().setReshowDelay(100);		//the window containing the splash screen		JWindow window=null;                if(showSplash) {                		//the icon that will be displayed in the splash screen    		final ImageIcon icon=SVGResource.getIcon("Splash", false);            window=new JWindow();            final int mww=icon.getIconWidth(), mwh=icon.getIconHeight();            window.setBounds((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2-mww/2),             								(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2-mwh/2), mww, mwh);            final BufferedImage splashImage=new BufferedImage(	icon.getIconWidth(), icon.getIconHeight(),             																						BufferedImage.TYPE_INT_ARGB);            splashImage.getGraphics().drawImage(icon.getImage(), 0, 0, window);                        //the panel displaying the image            JPanel panel=new JPanel(){                            	@Override                protected void paintComponent(Graphics g) {                                        super.paintComponent(g);                                        if(icon.getImage()!=null){                                                ((Graphics2D)g).drawRenderedImage(splashImage, null);                    }                }             };                        window.getContentPane().setLayout(new BoxLayout(window.getContentPane(), BoxLayout.Y_AXIS));            window.getContentPane().add(panel);            window.setVisible(true);        }		//creating the toolkit object		toolkit=new SVGToolkit(this);				//creating the resource manager		resource=new SVGResource(this);				//getting the configuration values				//the bounds of the widgets contained in the main frame		Map<String, Rectangle> map=getWidgetBoundsMap();				if(map!=null){						widgetBounds.putAll(map);		}				//gets the type of the desktop		String display=getWindowDisplayType();				if(display!=null){						if(display.equals("multi-window")){								isMultiWindow=true;								//the component into which all the SVGFrames containing the scroll panes will be placed				desktop=new JDesktopPane();                ((JDesktopPane)desktop).setDragMode(JDesktopPane.LIVE_DRAG_MODE);			}		}				if(desktop==null){						//the desktop is not multi-windowed			desktop=new JPanel();			desktop.setLayout(new BoxLayout(desktop, BoxLayout.X_AXIS));		}				//the module loader is created and initialized		moduleManager=new SVGModuleManager(this);		moduleManager.init();				//sets the default color chooser		if(getColorChooser()==null){						setColorChooser(new SVGColorChooser(this));		}				//sets particular modules		try{			undoRedo=(SVGUndoRedo)moduleManager.getModule("UndoRedo");		}catch (Exception ex){undoRedo=null;}				try{			selection=(SVGSelection)moduleManager.getModule("Selection");		}catch (Exception ex){selection=null;}				if(parentContainer instanceof JFrame){						//setting the icon			ImageIcon icon2=SVGResource.getIcon("Editor", false);						if(icon2!=null && icon2.getImage()!=null){								((JFrame)parentContainer).setIconImage(icon2.getImage());			}						//handling the frame content			((JFrame)parentContainer).getContentPane().setLayout(new BorderLayout());			((JFrame)parentContainer).getContentPane().add(moduleManager.getEditorToolBars(), BorderLayout.NORTH);			((JFrame)parentContainer).getContentPane().add(desktop, BorderLayout.CENTER);			((JFrame)parentContainer).setJMenuBar(moduleManager.getMenuBar());						//computing the bounds of the main frame			Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();			Insets screenInsets=Toolkit.getDefaultToolkit().getScreenInsets(													((JFrame)parentContainer).getGraphicsConfiguration());			final Rectangle frameBounds=new Rectangle(	screenInsets.left, 																						screenInsets.top, 																						screenSize.width-screenInsets.left-screenInsets.right, 																						screenSize.height-screenInsets.top-screenInsets.bottom);			widgetBounds.put("mainframe", frameBounds);						//sets the bounds of the main frame			((JFrame)parentContainer).setBounds(frameBounds);			desktop.setBounds(frameBounds);					}else if(parentContainer instanceof JApplet){						//handling the applet content			((JApplet)parentContainer).getContentPane().setLayout(new BoxLayout(((JFrame)parentContainer).getContentPane(), BoxLayout.Y_AXIS));			((JApplet)parentContainer).getContentPane().add(moduleManager.getEditorToolBars(), BorderLayout.NORTH);			((JApplet)parentContainer).getContentPane().add(desktop, BorderLayout.CENTER);			((JApplet)parentContainer).setJMenuBar(moduleManager.getMenuBar());		}		//layout some elements inside the frame		moduleManager.layoutElements();				//displays the main frame		if(displayFrame && parentContainer instanceof JFrame) {			((JFrame)parentContainer).setVisible(true);        }		        //opening the file specified in the constructor arguments        openFile(fileToBeLoaded);				if(window!=null) {                  window.setVisible(false);        }	}		 	/**     * @return the resource bundle     */    public static ResourceBundle getBundle() {                return bundle;    }		/**	 * @return the class that manages the different frames in the desktop pane	 */	public SVGFrameManager getFrameManager(){		return  moduleManager.getFrameManager();	}		/**	 * @return the main frame	 */	public static Container getParent(){		return parentContainer;	}        /**     * shows or hides the editor frame     * @param visible whether the editor frame should be visible or not     */    public void setVisible(final boolean visible) {                //invoking the given runnable in the AWT thread        SwingUtilities.invokeLater(new Runnable(){                        public void run() {                            	if(parentContainer instanceof JFrame){            		                    ((JFrame)parentContainer).setVisible(visible);                    ((JFrame)parentContainer).toFront();                                        if(! visible) {                                                closeAll();                    }            	}            }        });    }	/**     * @return Returns the isQuitActionDisabled.     */    public boolean isQuitActionDisabled() {        return isQuitActionDisabled;    }    /**	 * @return the boolean telling whether the mutli windowing method has to be used or not	 */	public boolean isMultiWindow(){		return isMultiWindow;	}		/**	 * @return Returns the dragSource.	 */	public DragSource getDragSource() {		return dragSource;	}		/**	 * @return Returns the colorChooser.	 */	public static SVGColorChooser getColorChooser() {		return colorChooser;	}		/**	 * sets the new color chooser	 * @param newColorChooser The colorChooser to set.	 */	public static void setColorChooser(SVGColorChooser newColorChooser) {				colorChooser=newColorChooser;	}		/**

⌨️ 快捷键说明

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