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

📄 actiondispatcher.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        	else if (ActionConst.CMD_GRAPH_DRAWISOSCELESTRIANGLE.equals(cmd))  //draw isosceles triangle
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_ISOSCELESTRIANGLE);

        	else if (ActionConst.CMD_GRAPH_DRAWHEXAGON.equals(cmd))  //draw hexagon
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_HEXAGON);

        	else if (ActionConst.CMD_GRAPH_DRAWPOLYGON.equals(cmd))  //draw polygon
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_POLYGON);

        	else if (ActionConst.CMD_GRAPH_DRAWIMAGE.equals(cmd))  //draw image
            		sendDrawCommand(DrawConst.DRAWSTATE_DRAW,ShapeConst.SHAPETYPE_IMAGE);
		
		/*
        	else if (ActionConst.CMD_GRAPH_DRAWTABLE.equals(cmd))  //draw table
            		drawTable();
            	*/
        	
        	// rotate, mirror or flip objects.
        	else if (ActionConst.CMD_GRAPH_ROTATE.equals(cmd))  //rotate objects.
            		sendDrawCommand(DrawConst.DRAWSTATE_ROTATE,ShapeConst.SHAPETYPE_NONE);
        	else if (ActionConst.CMD_GRAPH_ROTATE_SETUP.equals(cmd))  //rotate objects setup.
            		rotateObjectSetup();

        	else if (ActionConst.CMD_GRAPH_MIRROR.equals(cmd)){  //mirror objects.
            		flipObject(DrawConst.DRAWSTATE_MIRROR);

                }else if (ActionConst.CMD_GRAPH_FLIP.equals(cmd)){  //flip objects.
            		flipObject(DrawConst.DRAWSTATE_FLIP);
            		
        	}else if (ActionConst.CMD_GRAPH_ADDPORT.equals(cmd))  //add ports to objects
            		processPortIssues(cmd);
        	else if (ActionConst.CMD_GRAPH_REMOVEPORT.equals(cmd))  //remove ports from objects
            		processPortIssues(cmd);
        	else if (ActionConst.CMD_GRAPH_BINDPORTS.equals(cmd))  //bind ports at current cursor position
            		processPortIssues(cmd);
        	else if (ActionConst.CMD_GRAPH_UNBINDPORTS.equals(cmd))  //unbind ports at current cursor position
            		processPortIssues(cmd);  
                
        	else if (ActionConst.CMD_GRAPH_ARROWHEAD.equals(cmd))  //change arrow head
            		processDecorateIssues(cmd);  
        	else if (ActionConst.CMD_GRAPH_LINEFORMAT.equals(cmd))  //change line format
            		processDecorateIssues(cmd);  
        	else if (ActionConst.CMD_GRAPH_FILLFORMAT.equals(cmd))  //change fill format
            		processDecorateIssues(cmd);  
        	else if (ActionConst.CMD_GRAPH_FONTFORMAT.equals(cmd))  //change font format
            		processDecorateIssues(cmd);  
        	else if (ActionConst.CMD_GRAPH_GRIDFORMAT.equals(cmd))  //change grid format
            		processGrid(cmd);  


        	else if (ActionConst.CMD_GRAPH_SENDTOBACK.equals(cmd))  //send graphs to back
            		processSendTo(cmd);  
        	else if (ActionConst.CMD_GRAPH_BRINGTOFRONT.equals(cmd))  //bring graphs to front
            		processSendTo(cmd);  

        	else if (ActionConst.CMD_GRAPH_GROUP.equals(cmd))  //group objects
            		processGroup(cmd);  

        	else if (ActionConst.CMD_GRAPH_UNGROUP.equals(cmd))  //ungroup objects
            		processGroup(cmd);  

           	
        	else if (ActionConst.CMD_EDIT_ADDTOLIB.equals(cmd))  //add current objects to library
            		processLibIssues(cmd);  
        	else if (ActionConst.CMD_EDIT_ADDTOTEMPLATE.equals(cmd))  //add current objects to template
            		processLibIssues(cmd);  


		else if (ActionConst.CMD_GRAPH_ALIGNMENT.equals(cmd)) //alignment
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_LEFT.equals(cmd)) //align left
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_RIGHT.equals(cmd)) //align right
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_TOP.equals(cmd)) //align top
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_BOTTOM.equals(cmd)) //align bottom
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_CENTER.equals(cmd)) //align center
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_JUSTIFY_HORIZONTAL.equals(cmd)) //align justify horizontal
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_JUSTIFY_VERTICAL.equals(cmd)) //align justify vertical
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_PROPORTIONAL_SPACING_HORIZONTAL.equals(cmd)) //align horizontal proportional spacing
			processAlignment(cmd);
		else if (ActionConst.CMD_GRAPH_ALIGNMENT_PROPORTIONAL_SPACING_VERTICAL.equals(cmd)) //align vertical proportional spacing
			processAlignment(cmd);


		else if (ActionConst.CMD_GRAPH_ZOOM_ACTUALSIZE.equals(cmd)) //zoom in actual size
			processZoom(cmd);
        	else if (ActionConst.CMD_GRAPH_ZOOMIN.equals(cmd))  //zoom in canvas
            		processZoom(cmd);  
        	else if (ActionConst.CMD_GRAPH_ZOOMOUT.equals(cmd))  //zoom out canvas
            		processZoom(cmd);  

        	else if (ActionConst.CMD_GRAPH_ZOOMSETUP.equals(cmd))  //zoom setup/ customized zoom
            		processZoom(cmd);  


        	else if (ActionConst.CMD_GRAPH_RULER_ENGLISH.equals(cmd))  //change ruler as an english ruler
            		processRulerIssues(cmd);  

        	else if (ActionConst.CMD_GRAPH_RULER_METRIC.equals(cmd))  //change ruler as an metric ruler
            		processRulerIssues(cmd);  

        	else if (ActionConst.CMD_GRAPH_LIBRARY.equals(cmd))  //libraries and templates
            		processLibIssues(cmd);  

        	else if (ActionConst.CMD_WINDOW_CASCADE.equals(cmd))  //cascade internal frames
            		processWindowIssues(cmd,null);  
        	else if (ActionConst.CMD_WINDOW_TILE.equals(cmd))  //tile internal frames
            		processWindowIssues(cmd,null);  
        	else if (ActionConst.CMD_WINDOW_MAXIMIZE.equals(cmd))  //maximize internal frames
            		processWindowIssues(cmd,null);  
        	else if (ActionConst.CMD_WINDOW_MINIMIZE.equals(cmd))  //minimize internal frames
            		processWindowIssues(cmd,null);  
        	else if (ActionConst.CMD_WINDOW_TOGGLE.equals(cmd))  //toggle internal frames
            		processWindowIssues(cmd,sender);  

        	else if (ActionConst.CMD_GRAPH_LAYERS.equals(cmd))  //layer setup
            		processLayerIssues(cmd);  

        	else if (ActionConst.CMD_HELP_ABOUT.equals(cmd))  //a help about menu
            		processHelpIssues(cmd);  

        	else if (ActionConst.CMD_HELP_WEBSITE.equals(cmd))  //a help web site menu
            		processHelpIssues(cmd);  

        	else if (ActionConst.CMD_HELP_MAILTO.equals(cmd))  //a send email menu
            		processHelpIssues(cmd);  

        	else if (ActionConst.CMD_EDIT_UNDO.equals(cmd))  //an undo operation
            		processUndoIssues(cmd);  

        	else if (ActionConst.CMD_EDIT_REDO.equals(cmd))  //an redo operation
            		processUndoIssues(cmd);  

        	else if (ActionConst.CMD_EDIT_UNDOSETUP.equals(cmd))  //an undo setup operation
            		processUndoIssues(cmd);  

        	else if (ActionConst.CMD_SETTING_SHAPEPROPERTIES.equals(cmd))  //change object properties
            		processSettings(cmd);  

        	else if (ActionConst.CMD_SETTING_SHAPETEXT.equals(cmd))  //change shape text
            		processSettings(cmd);  

        	else if (ActionConst.CMD_SETTING_CHANGEIMAGE.equals(cmd))  //change image, for jfimage only.
            		processSettings(cmd);  

        	else if (ActionConst.CMD_SETTING_SHAPESETTING.equals(cmd))  //shape setting
            		processSettings(cmd);  

        	else if (ActionConst.CMD_SETTING_PAGESETTING.equals(cmd))  //page setting
            		processSettings(cmd);  

        	else if (ActionConst.CMD_SETTING_GLOBALSETTING.equals(cmd))  //global setting
            		processSettings(cmd);  



        	else if (ActionConst.CMD_TEXTALIGNMENT_LEFT.equals(cmd))  //text alignment left
            		processTextAlignment(cmd);  
        	else if (ActionConst.CMD_TEXTALIGNMENT_RIGHT.equals(cmd))  //text alignment right
            		processTextAlignment(cmd);  
        	else if (ActionConst.CMD_TEXTALIGNMENT_MIDDLE.equals(cmd))  //text alignment middle
            		processTextAlignment(cmd);  


        	else  if (ActionConst.CMD_QUIT.equals(cmd)){  //quit
        		m_pane.closeAllWindows();
			System.exit(0);
		}

    	}


	/** process text alignment issues */
	private void processTextAlignment(String cmd){


	    	//current drawing canvas
    		DrawCanvas canvas   =getCurrentDrawCanvas();
    		if (canvas==null) return;
    			
                        
		//only works for a not null selection
		Selection selection     =canvas.getSelection();
		if (selection==null || selection.size()==0)
			return;


		//works for the object list in selection
		List objList    =selection.getList().getList();
                                        
                int alignmentType	=JFText.TEXTALIGNMENT_LEFT;
		if (ActionConst.CMD_TEXTALIGNMENT_LEFT.equals(cmd)){ //align left  
			alignmentType	=JFText.TEXTALIGNMENT_LEFT;
		}else if (ActionConst.CMD_TEXTALIGNMENT_MIDDLE.equals(cmd)){ //align middle/center
			alignmentType	=JFText.TEXTALIGNMENT_MIDDLE;
		}else if (ActionConst.CMD_TEXTALIGNMENT_RIGHT.equals(cmd)){ //align right
			alignmentType	=JFText.TEXTALIGNMENT_RIGHT;
		}

		
		Iterator it     =objList.iterator();
		boolean ifPropertyChanged	=false;
		while (it!=null && it.hasNext()){
			AbstractShape shape     =(AbstractShape)it.next();
			if (shape instanceof JFText){
				((JFText)shape).setTextAlignment(alignmentType);
				ifPropertyChanged	=true;
			}
			
		}


		//repaint drawcanvas
		if (ifPropertyChanged){
                        /** Graph event dispatcher**/
                        if (m_graphEventDispatcher==null)
                                m_graphEventDispatcher  =new GraphEventDispatcher(m_pane);

			m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
			canvas.repaint();
		}
			
	}




	/** process alignment issues */
	private void processAlignment(String cmd){

		if (ActionConst.CMD_GRAPH_ALIGNMENT.equals(cmd)){ //alignment
			AlignmentDialog.showAlignmentDialog(m_pane);
		}else{
	    		//current drawing canvas
    			DrawCanvas drawCanvas   =getCurrentDrawCanvas();
    			if (drawCanvas==null) return;
    			
			Selection selection	=drawCanvas.getSelection();


			if (ActionConst.CMD_GRAPH_ALIGNMENT_LEFT.equals(cmd)){ //align left  
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_LEFT); 
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_LEFT);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_RIGHT.equals(cmd)){ //align right
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_RIGHT);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_RIGHT);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_TOP.equals(cmd)){ //align top
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_TOP);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_TOP);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_BOTTOM.equals(cmd)){ //align bottom
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_BOTTOM);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_BOTTOM);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_CENTER.equals(cmd)){ //align center
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_CENTER);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_CENTER);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_JUSTIFY_HORIZONTAL.equals(cmd)){ //align justify horizontal
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_JUSTIFY_HORIZONTAL);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_JUSTIFY_HORIZONTAL);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_JUSTIFY_VERTICAL.equals(cmd)){ //align justify vertical
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_JUSTIFY_VERTICAL);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_JUSTIFY_VERTICAL);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_PROPORTIONAL_SPACING_HORIZONTAL.equals(cmd)){ //align horizontal proportional spacing
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_PROPORTIONAL_SPACING_HORIZONTAL);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_PROPORTIONAL_SPACING_HORIZONTAL);
			
			}else if (ActionConst.CMD_GRAPH_ALIGNMENT_PROPORTIONAL_SPACING_VERTICAL.equals(cmd)){ //align vertical proportional spacing
				selection.alignObjects(AlignShapes.ALIGNMENTTYPE_PROPORTIONAL_SPACING_VERTICAL);
				m_graphEventDispatcher.fireShapeAlignment(selection.getList(),AlignShapes.ALIGNMENTTYPE_PROPORTIONAL_SPACING_VERTICAL);
			}


			drawCanvas.repaint();
		}
			
	}


	
    	/** draw a quadrant on current drawcanvas.*/
	private void drawQuadrant(){
            
	    	//current drawing canvas
    		DrawCanvas drawCanvas   =getCurrentDrawCanvas();
    		if (drawCanvas==null)
    			return;

		//view center of drawing canvas
		JFPoint center	=drawCanvas.getViewCenter();		
		//drawing page
    		JFPage page	=drawCanvas.getDrawPage();

		CanvasFormat canvasFormat	=page.getCanvasFormat();
		
		double width	=Math.max(canvasFormat.getScreenWidth(),JFQuadrant.DEFAULT_SIZE);
		double height	=Math.max(canvasFormat.getScreenHeight(),JFQuadrant.DEFAULT_SIZE);

   				
		//create a new quadrant
		page.getCurrentLayer().getShapeList().add(new JFQuadrant(center.getX(),center.getY(),width,height));
		
		drawCanvas.repaint();
	}


    	/** Process edit issues
    	 *  @param actionName Action name for edit issues.
    	 */
    	private  void processEditIssues(String actionName){

	    	//current drawing canvas
    		DrawCanvas drawCanvas   =getCurrentDrawCanvas();
		Selection selection	=drawCanvas.getSelection();

⌨️ 快捷键说明

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