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

📄 actiondispatcher.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            			image.setCanvas(drawCanvas);
				if (!image.loadImage(imageFile)){
					JOptionPane.showMessageDialog(null, CADResource.getString("image.loadFailure")+"\n"+image.getLastError(), CADResource.getString("sys.error"), JOptionPane.ERROR_MESSAGE); 
					return;
				}
				//first graph event: shape property changed
				m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
				
				drawCanvas.repaint();
            			
        	}else if (ActionConst.CMD_SETTING_SHAPESETTING.equals(actionName)){  //shape setting
				if (selection.size()==0){
 					JOptionPane.showMessageDialog(null, CADResource.getString("invalid.shapeObject"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    					return;      
				}

				if (ShapeSettingDialog.newShapeSetting(f,selection.getList().getList())){
					page.setModified(true);
					drawCanvas.repaint();
				}

        			
       		}else if (ActionConst.CMD_SETTING_PAGESETTING.equals(actionName)){  //page setting
				if (PageSettingDialog.newPageSetting(f,page)){
					//set page modified state.					
					page.setModified(true);
					//copy page setting to global setting
        				GlobalSettings settings	=GlobalSettings.getInstance();
        				settings.setHidePorts(page.isHidePorts());
        				settings.setDisablePortSnapping(page.isDisablePortSnapping());
        				settings.setScaleValue(page.getScaleValue());
        				settings.setScaleUnit(page.getScaleUnit());
        				settings.setScreenUnit(page.getScreenUnit());
        				settings.setCanvasFormat(page.getCanvasFormat());
			                
					//trigger ruler repaint event.        				
					DrawPane drawPane	=drawCanvas.getParentDrawPane();
			                drawPane.setCanvasFormat(page.getCanvasFormat());
        				drawPane.setIsMetric(drawPane.getIsMetric());
					//repaint canvas
					drawCanvas.repaint();
				}        			
		}
    	}

        
        /**reset all frame's metric or english measurement */
  	private void resetMeasurement(JDesktopPane desktop,boolean isMetric){
     		JInternalFrame[] frames = desktop.getAllFrames();

      		for (int i = 0; i < frames.length; i++){
         		  try{
         		  	DrawFrame  frame	=(DrawFrame)frames[i];
         		  	DrawPane  pane	=frame.getDrawPane();
         		  	DrawCanvas canvas=pane.getDrawCanvas();
         		  	JFPage page	=canvas.getDrawPage();
				
				//reset isMetric of rulers.         		  	
         		  	pane.setIsMetric(isMetric);
         		  	//reset grid format of canvas.
         		  	canvas.getGridFormat().setIsMetric(isMetric); 
				//reset scale measurement of page.
				page.setIsMetric(isMetric);
				
         		  	canvas.repaint();
            		  }catch(Exception e){}
      		}
   	}



    	/** Process group/ungroup issues. 
    	 *  @param actionName Action name for group issues
    	 */
    	private  void processGroup(String actionName){
	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;

    		/** A CAD selection for current shape objects.*/
    		Selection selection	=drawCanvas.getSelection();
    		if (selection.size()<=0){
 			JOptionPane.showMessageDialog(null, CADResource.getString("group.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    			return;      
		}   
		JFPage page     =drawCanvas.getDrawPage();
	        if (ActionConst.CMD_GRAPH_GROUP.equals(actionName)){

			//if a quadrant is in the list, raise an 'cannot group quadrant(s)' error        			
			if (selection.hasQuadrant()){
        			JOptionPane.showMessageDialog(null, CADResource.getString("group.cannotgroupquadrant"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
        			return;
        		}

	        	AbstractObject obj=page.groupShapes(selection.getList().getList());
	        	if (obj!=null){
	        		obj.setZoomScale(page.getZoomScale());
				drawCanvas.getDrawPage().setModified(true);
	        		selection.clear();
	        		selection.add(obj); 
        			drawCanvas.getOperationManager().addGroup((JFGroup)obj);
	        		
	        	}
	        }else{
	        	if (selection.size()>0)
				drawCanvas.getDrawPage().setModified(true);
        		drawCanvas.getOperationManager().addUngroup(selection.getList().getList());
	        	List l	=page.ungroupShapes(selection.getList().getList());
	        	selection.clear();
	        	selection.add(l); 
	        }
	        drawCanvas.repaint();
        }


    	/** Process send to issues. 
    	 *  @param actionName Action name for send to issues
    	 */
    	private  void processSendTo(String actionName){
	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;

    		/** A CAD selection for current shape objects.*/
    		Selection selection	=drawCanvas.getSelection();
    		if (selection.size()<=0){
 			JOptionPane.showMessageDialog(null, CADResource.getString("sendto.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    			return;      
		}   
		JFPage page     =drawCanvas.getDrawPage();
	        if (ActionConst.CMD_GRAPH_SENDTOBACK.equals(actionName)){
			drawCanvas.getDrawPage().setModified(true);
	        	drawCanvas.getOperationManager().addSendToBack(selection.getList().getList());
	                page.sendToBack(selection.getList().getList());
	        }else{
			drawCanvas.getDrawPage().setModified(true);
	        	drawCanvas.getOperationManager().addBringToFront(selection.getList().getList());
	                page.bringToFront(selection.getList().getList());
	        }
	        drawCanvas.repaint();
        }


    	/** Process decorate issues. e.g. arrowhead,line format, fill format,etc.
    	 *  @param actionName Action name for decorate issues.
    	 */
    	private  void processDecorateIssues(String actionName){
	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;

    		// A CAD selection for current shape objects.
    		Selection selection	=drawCanvas.getSelection();
    		if (selection.size()<=0){
 			JOptionPane.showMessageDialog(null, CADResource.getString("decorate.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    			return;      
		}    			 
                
                //one object in select was disabled modifying properties
    		if (ShapeSettingDialog.getDisableModifyingProperties(selection.getList().getList(),true)){
 			JOptionPane.showMessageDialog(null, CADResource.getString("dialog.shapesetting.modificationdisabled"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    			return;      
    		}

    		
                JFrame	f	=GUIUtils.getJFrame(m_pane);
    		if (ActionConst.CMD_GRAPH_ARROWHEAD.equals(actionName)){
    			Arrow arrow	=selection.getArrow();
    			if (arrow==null){
 				JOptionPane.showMessageDialog(null, CADResource.getString("decorate.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    				return;      
    			}else{

            			arrow	=ArrowDialog.getNewArrow(f,arrow);
            			if (arrow!=null){
					drawCanvas.getDrawPage().setModified(true);
	        			drawCanvas.getOperationManager().addModifyArrow(selection.getList().getList(),arrow);
				  	//first graph event: shape property changed
				  	m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
            				selection.setArrow(arrow);
					m_pane.notifyObjectSelected(selection.getList());
            				drawCanvas.repaint();
            			}
            		}
                
                }else if (ActionConst.CMD_GRAPH_LINEFORMAT.equals(actionName)){

    			LineFormat lineFormat	=selection.getLineFormat();
    			if (lineFormat==null){
 				JOptionPane.showMessageDialog(null, CADResource.getString("decorate.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    				return;      
    			}else{


            			lineFormat	=LineFormatDialog.getNewLineFormat(f,lineFormat);
            			if (lineFormat!=null){

					drawCanvas.getDrawPage().setModified(true);
	        			drawCanvas.getOperationManager().addModifyLineFormat(selection.getList().getList(),lineFormat);
				  	//first graph event: shape property changed
				  	m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
	        			
            				selection.setLineFormat(lineFormat);
					m_pane.notifyObjectSelected(selection.getList());
            				drawCanvas.repaint();
            			}
            		}


                }else if (ActionConst.CMD_GRAPH_FILLFORMAT.equals(actionName)){
    			FillFormat fillFormat	=selection.getFillFormat();
    			if (fillFormat==null){
 				JOptionPane.showMessageDialog(null, CADResource.getString("decorate.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    				return;      
    			}else{

            			fillFormat	=FillFormatDialog.getNewFillFormat(f,fillFormat);
            			if (fillFormat!=null){
					drawCanvas.getDrawPage().setModified(true);
	        			drawCanvas.getOperationManager().addModifyFillFormat(selection.getList().getList(),fillFormat);
				  	//first graph event: shape property changed
				  	m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
            				selection.setFillFormat(fillFormat);
					m_pane.notifyObjectSelected(selection.getList());
            				drawCanvas.repaint();
            			}
            		}

                }else if (ActionConst.CMD_GRAPH_FONTFORMAT.equals(actionName)){
    			FontFormat fontFormat	=selection.getFontFormat();
    			if (fontFormat==null){
 				JOptionPane.showMessageDialog(null, CADResource.getString("decorate.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    				return;      
    			}else{

            			fontFormat	=FontFormatDialog.getNewFontFormat(f,fontFormat);
            			if (fontFormat!=null){
					drawCanvas.getDrawPage().setModified(true);
	        			drawCanvas.getOperationManager().addModifyFontFormat(selection.getList().getList(),fontFormat);
				  	//first graph event: shape property changed
				  	m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
            				selection.setFontFormat(fontFormat);
					m_pane.notifyObjectSelected(selection.getList());
            				drawCanvas.repaint();
            			}
            		}
                }                        
    		
        }    		


    	/** Process port issues(add/remove).
    	 *  @param actionName Action name for port issues.
    	 */
    	private  void processPortIssues(String actionName){
	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;

    		/** A CAD selection for current shape objects.*/
    		Selection selection	=drawCanvas.getSelection();
    		if (selection.size()<=0){
 			JOptionPane.showMessageDialog(null, CADResource.getString("port.invalidShape"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    			return;
		}    			 
		
		//last mouse pos on draw canvas
		JFPoint lastPos		=drawCanvas.getLastMousePos();

        	if (ActionConst.CMD_GRAPH_ADDPORT.equals(actionName)){  //add ports to objects
        		
        		Port port	=selection.addPort(lastPos.getX(),lastPos.getY());
        		if (port!=null){
				drawCanvas.getDrawPage().setModified(true);
        			drawCanvas.getOperationManager().addNewPort(port);
        			drawCanvas.repaint();
        		}else
				JOptionPane.showMessageDialog(null, CADResource.getString("port.invalidShape"),CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 

        	}else if (ActionConst.CMD_GRAPH_REMOVEPORT.equals(actionName)){  //remove ports from objects
            		Port port	=selection.pickPort(lastPos.getX(),lastPos.getY());
            		if (port==null)
            			return;

			if (port.getPortType()==Port.PORTTYPE_DEFAULT){
				JOptionPane.showMessageDialog(null, CADResource.getString("port.unremovable"),CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
				return;
			}
            		
                    	int n = JOptionPane.showConfirmDialog(
                                   null,
                                   CADResource.getString("port.removeAlert"),
                                   CADResource.getString("port.remove"),
                                    JOptionPane.YES_NO_OPTION);
                                   

                    	if (n == JOptionPane.YES_OPTION) {
				drawCanvas.getDrawPage().setModified(true);
        			drawCanvas.getOperationManager().addRemovePort(port);
                    		selection.removePort(port);
                    		drawCanvas.repaint();
                    	}
                }else if (ActionConst.CMD_GRAPH_BINDPORTS.equals(actionName)){
                        bindPorts(true);
                }else if (ActionConst.CMD_GRAPH_UNBINDPORTS.equals(actionName)){
                        bindPorts(false);
                }        
    	}

    	/** Send a bind or unbind ports command to all the ports close to current cursor.
    	 *  @param  True if bind, false if unbind.
    	 */
    	private  void bindPorts(boolean bind){
    	        
	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();

    		if (drawCanvas!=null){ 
    		        JFPage    page  =drawCanvas.getDrawPage();
    		        JFPoint pnt	=drawCanvas.getLastMousePos();
    		        int    ret	=0;
    		        
    		        if (bind){
				dr

⌨️ 快捷键说明

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