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

📄 actiondispatcher.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/**
 *    $Id:ActionDispatcher.java $
 *
 *    Copyright 2004 ~ 2005  JingFei International Cooperation LTD. All rights reserved. *
 */
package com.jfimagine.jfdraw.action;

import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

import java.awt.Dimension;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
			
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JPopupMenu;
import javax.swing.JToolBar;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;


import com.jfimagine.jfdraw.draw.DrawConst;
import com.jfimagine.jfdraw.draw.DrawState;
import com.jfimagine.jfdraw.draw.Selection;
import com.jfimagine.jfdraw.draw.AlignShapes;

import com.jfimagine.jfdraw.gui.GlobalSettings;
import com.jfimagine.jfdraw.gui.DrawFrame;
import com.jfimagine.jfdraw.gui.DrawAdapter;
import com.jfimagine.jfdraw.gui.CADPane;
import com.jfimagine.jfdraw.gui.DrawPane;
import com.jfimagine.jfdraw.gui.DrawCanvas;
import com.jfimagine.jfdraw.gui.DrawPane;
import com.jfimagine.jfdraw.gui.ToolFactory;

import com.jfimagine.jfdraw.gui.dialog.ArrowDialog;
import com.jfimagine.jfdraw.gui.dialog.LineFormatDialog;
import com.jfimagine.jfdraw.gui.dialog.FillFormatDialog;
import com.jfimagine.jfdraw.gui.dialog.FontFormatDialog;
import com.jfimagine.jfdraw.gui.dialog.GridFormatDialog; 
import com.jfimagine.jfdraw.gui.dialog.LayerSetupDialog;
import com.jfimagine.jfdraw.gui.dialog.ZoomDialog;
import com.jfimagine.jfdraw.gui.dialog.UndoSetupDialog;
import com.jfimagine.jfdraw.gui.dialog.PropertyDialog;
import com.jfimagine.jfdraw.gui.dialog.AboutDialog;
import com.jfimagine.jfdraw.gui.dialog.FileDialog;
import com.jfimagine.jfdraw.gui.dialog.LibHelper;   
import com.jfimagine.jfdraw.gui.dialog.LibPanel;
import com.jfimagine.jfdraw.gui.dialog.ShapeSettingDialog;   
import com.jfimagine.jfdraw.gui.dialog.PageSettingDialog;   
import com.jfimagine.jfdraw.gui.dialog.GlobalSettingDialog;   
import com.jfimagine.jfdraw.gui.dialog.PreviewDialog;
import com.jfimagine.jfdraw.gui.dialog.AlignmentDialog;
import com.jfimagine.jfdraw.gui.dialog.RotateSetupDialog;

//import com.jfimagine.jfdraw.gui.dialog.TableDialog;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.jfdraw.draw.GraphEventDispatcher;

import com.jfimagine.jfdraw.gui.GUIUtils;
import com.jfimagine.jfdraw.action.ActionConst;
import com.jfimagine.jfdraw.action.FileAction;

import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.AbstractShape;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.Port;
import com.jfimagine.jfgraph.shape.union.JFPage;
import com.jfimagine.jfgraph.shape.union.JFLayer;
import com.jfimagine.jfgraph.shape.union.JFGroup;
import com.jfimagine.jfgraph.shape.union.CheckItem;
import com.jfimagine.jfgraph.shape.union.AbstractLibrary;
import com.jfimagine.jfgraph.shape.union.JFLibElem;

import com.jfimagine.jfgraph.shape.rectangle.JFImage;
import com.jfimagine.jfgraph.shape.rectangle.JFText;

import com.jfimagine.jfgraph.transfer.ExportBase;
import com.jfimagine.jfgraph.transfer.ExportPrinter;
import com.jfimagine.jfgraph.transfer.JFClipboard;

import com.jfimagine.jfgraph.shape.decorate.Arrow;
import com.jfimagine.jfgraph.shape.decorate.LineFormat;
import com.jfimagine.jfgraph.shape.decorate.FillFormat;
import com.jfimagine.jfgraph.shape.decorate.FontFormat;
import com.jfimagine.jfgraph.shape.decorate.GridFormat;
import com.jfimagine.jfgraph.shape.decorate.JFPageFormat;
import com.jfimagine.jfgraph.shape.decorate.CanvasFormat;

import com.jfimagine.jfgraph.shape.line.JFQuadrant;

//import com.jfimagine.jfgraph.shape.table.JFTable;
//import com.jfimagine.jfgraph.shape.table.JFCell;

import com.jfimagine.jfgraph.geom.Rect;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.utils.commonutil.BrowserLauncher;

import com.jfimagine.utils.log.*; 
 /**
 * Action dispatcher class. It's a main class to receive and dispatch draw actions to proper routines.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.1.0 $
 */  
 public class ActionDispatcher {

   	/**an internal log utility*/
   	private JFLogger m_logger=JFLogManager.getLogger(this.getClass());
   
 	/** file action, for any file processing*/
    	private FileAction m_fileAction; 	

 	/** A panel(CADPane or DrawPane) to dispatch events */
    	private DrawAdapter  m_pane; 	

        /** Graph event dispatcher**/
        private GraphEventDispatcher m_graphEventDispatcher;
    	
    	/** Constructor */
    	public ActionDispatcher(DrawAdapter pane){
    		this.m_pane	=pane;
    		m_fileAction	=new FileAction(pane);
		//graph event dispatcher.
		m_graphEventDispatcher  =new GraphEventDispatcher(pane);
    	}

    	/** get current drawing canvas */
    	private DrawCanvas getCurrentDrawCanvas(){
    		return m_pane.getDrawCanvas();
    	}

    	
    	/** fire an action
    	 *  @param e An action currently fired by user.
    	 */
    	public void fireAction(ActionEvent e){
    		fireAction(e.getActionCommand(),e.getSource());
    	}


    	/** fire an action
    	 *  @param cmd A string command
    	 *  @param sender The sender of this command
    	 */
    	public void fireAction(String cmd,Object sender){
          	
            	//clear last drawing state firstly.
            	sendDrawCommand(DrawConst.DRAWSTATE_NONE,ShapeConst.SHAPETYPE_NONE);

        	if (ActionConst.CMD_FILE_NEW.equals(cmd))  //new file
            		m_fileAction.newFile();
		
		else if (ActionConst.CMD_FILE_SAVE.equals(cmd))  //save file
            		m_fileAction.saveFile();

		else if (ActionConst.CMD_FILE_SAVEAS.equals(cmd))  //save as a new file
            		m_fileAction.saveasFile();

		else if (ActionConst.CMD_FILE_SAVEASXML.equals(cmd))  //save as a new xml file
            		m_fileAction.saveasXMLFile();
                                                     
		else if (ActionConst.CMD_EXPORTING_JPG.equals(cmd))  //exporting to jpg files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_JPG_SELECTION.equals(cmd))  //exporting selection to jpg files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_GIF.equals(cmd))  //exporting to gif files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_GIF_SELECTION.equals(cmd))  //exporting selection to gif files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_PNG.equals(cmd))  //exporting to png files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_PNG_SELECTION.equals(cmd))  //exporting selection to png files
            		m_fileAction.exportingFile(cmd);


		else if (ActionConst.CMD_EXPORTING_EPS.equals(cmd))  //exporting to eps files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_EPS_SELECTION.equals(cmd))  //exporting selection to eps files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_SVG.equals(cmd))  //exporting to svg files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_SVG_SELECTION.equals(cmd))  //exporting selection to svg files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_SWF.equals(cmd))  //exporting to swf files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_SWF_SELECTION.equals(cmd))  //exporting selection to swf files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_EMF.equals(cmd))  //exporting to emf files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_EMF_SELECTION.equals(cmd))  //exporting selection to emf files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_CGM.equals(cmd))  //exporting to cgm files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_CGM_SELECTION.equals(cmd))  //exporting selection to cgm files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_PDF.equals(cmd))  //exporting to pdf files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_PDF_SELECTION.equals(cmd))  //exporting selection to pdf files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_PPM.equals(cmd))  //exporting to ppm files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_PPM_SELECTION.equals(cmd))  //exporting selection to ppm files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_EXPORTING_TIFF.equals(cmd))  //exporting to tiff files
            		m_fileAction.exportingFile(cmd);
		else if (ActionConst.CMD_EXPORTING_TIFF_SELECTION.equals(cmd))  //exporting selection to tiff files
            		m_fileAction.exportingFile(cmd);

		else if (ActionConst.CMD_FILE_OPEN.equals(cmd))  //open file
            		m_fileAction.openFile();

		else if (ActionConst.CMD_FILE_OPENURL.equals(cmd))  //open url file
            		m_fileAction.openURLFile();

		else if (ActionConst.CMD_EDIT_SELECTALL.equals(cmd))  //select all operation
            		processEditIssues(cmd);
		else if (ActionConst.CMD_EDIT_COPY.equals(cmd))  //copy operation
            		processEditIssues(cmd);
		else if (ActionConst.CMD_EDIT_CUT.equals(cmd))  //cut operation
            		processEditIssues(cmd);
		else if (ActionConst.CMD_EDIT_PASTE.equals(cmd))  //paste operation
            		processEditIssues(cmd);
		else if (ActionConst.CMD_EDIT_DELETE.equals(cmd))  //delete operation
            		processEditIssues(cmd);

		else if (ActionConst.CMD_FILE_PAGESETUP.equals(cmd))  //page setup
            		processPageSetupIssues(cmd);

		else if (ActionConst.CMD_FILE_PRINT.equals(cmd))  //print
            		processPrintIssues(cmd);

		else if (ActionConst.CMD_FILE_PRINTPREVIEW.equals(cmd))  //print preview
            		processPrintIssues(cmd);

		else if (ActionConst.CMD_GRAPH_DRAWTEXT.equals(cmd))  //draw text
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_TEXT);

		else if (ActionConst.CMD_GRAPH_DRAWLINETRIGGER.equals(cmd))  //draw line/curve's command menu
            		popupDrawMenu(cmd,sender);

        	else if (ActionConst.CMD_GRAPH_PICK.equals(cmd))  //pick object with none shape type.
            		sendDrawCommand(DrawConst.DRAWSTATE_NONE,ShapeConst.SHAPETYPE_NONE);

        	else if (ActionConst.CMD_GRAPH_DRAWLINE.equals(cmd))  //draw line
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_LINE);

        	else if (ActionConst.CMD_GRAPH_DRAWREGULARLINE.equals(cmd))  //draw regular line
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_REGULARLINE);

        	else if (ActionConst.CMD_GRAPH_DRAWLABELLINE.equals(cmd))  //draw label line
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_LABELLINE);

        	else if (ActionConst.CMD_GRAPH_DRAWHLABELLINE.equals(cmd))  //draw horizontal label line
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_HLABELLINE);

        	else if (ActionConst.CMD_GRAPH_DRAWVLABELLINE.equals(cmd))  //draw vertical label line
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_VLABELLINE);

        	else if (ActionConst.CMD_GRAPH_DRAWCURVE.equals(cmd))  //draw curve(bezier curve)
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_CURVE);

        	else if (ActionConst.CMD_GRAPH_DRAWQUADRANT.equals(cmd))  //draw quadrant
            		drawQuadrant();

        	else if (ActionConst.CMD_GRAPH_DRAWRECTTRIGGER.equals(cmd))  //draw rectangle's command menu
            		popupDrawMenu(cmd,sender);

        	else if (ActionConst.CMD_GRAPH_DRAWRECT.equals(cmd))  //draw rectangle
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_RECT);
            		
        	else if (ActionConst.CMD_GRAPH_DRAWRECT_ROUNDED.equals(cmd))  //draw rounded rectangle
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_RECT_ROUNDED);

        	else if (ActionConst.CMD_GRAPH_DRAWRECT_DIAMOND.equals(cmd))  //draw diamond
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_RECT_DIAMOND);

        	else if (ActionConst.CMD_GRAPH_DRAWRECT_PARALLELOGRAM.equals(cmd))  //draw parallelogram
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_RECT_PARALLELOGRAM);

        	else if (ActionConst.CMD_GRAPH_DRAWRECT_TRAPEZOID.equals(cmd))  //draw trapezoid
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_RECT_TRAPEZOID);

        	else if (ActionConst.CMD_GRAPH_DRAWRECT_ISOSCELESTRAPEZOID.equals(cmd))  //draw trapezoid
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_RECT_ISOSCELESTRAPEZOID);

        	else if (ActionConst.CMD_GRAPH_DRAWELLIPSETRIGGER.equals(cmd))  //draw ellipse's command menu
            		popupDrawMenu(cmd,sender);

        	else if (ActionConst.CMD_GRAPH_DRAWELLIPSE.equals(cmd))  //draw ellipse
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_ELLIPSE);

        	else if (ActionConst.CMD_GRAPH_DRAWARC.equals(cmd))  //draw arc
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_ARC);

        	else if (ActionConst.CMD_GRAPH_DRAWCHORD.equals(cmd))  //draw chord
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_CHORD);

        	else if (ActionConst.CMD_GRAPH_DRAWPIE.equals(cmd))  //draw pie
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_PIE);

        	else if (ActionConst.CMD_GRAPH_DRAWPOLYGONTRIGGER.equals(cmd))  //draw polygon's command menu
            		popupDrawMenu(cmd,sender);

⌨️ 快捷键说明

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