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

📄 actiondispatcher.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
							libraryPanel.newLibrary();
							lib	=libraryPanel.getCurrentLibrary();
    						}catch(Exception e){
    						}
    					}
    			}

			if (lib!=null){ 
				JFLibElem elem	=new JFLibElem();
				elem.setElement(selection.getList());
				lib.add(elem);
				libraryPanel.repaint();
			}
        	}else if (ActionConst.CMD_EDIT_ADDTOTEMPLATE.equals(actionName)){  //add current objects to template

			AbstractLibrary lib	=templatePanel.getCurrentLibrary();

			if (lib==null){
		  		int n = JOptionPane.showConfirmDialog(
                                   	null,
                                   	CADResource.getString("dialog.template.createnew"),
                                   	CADResource.getString("sys.warn"),
                                   	JOptionPane.YES_NO_OPTION);
                                   
					if (n==JOptionPane.YES_OPTION){
						try{
							templatePanel.newLibrary();
							lib	=templatePanel.getCurrentLibrary();
    						}catch(Exception e){
    						}
    					}
    			}


			if (lib!=null){ 
				JFLibElem elem	=new JFLibElem();
				elem.setElement(drawCanvas.getDrawPage());
				lib.add(elem);
				templatePanel.repaint();
			}
		}
	}


    	/** Process window issues. cascade,tile,maximize,minimize.
    	 *  @param actionName Action name for window
    	 */
    	private  void processWindowIssues(String actionName,Object sender){
    			
    		JDesktopPane	desktop	=m_pane.getDesktop();
    		if (desktop==null)
    			return;
    			

    		if (ActionConst.CMD_WINDOW_CASCADE.equals(actionName)){
    			cascadeWindows(desktop);

    		}else if (ActionConst.CMD_WINDOW_TILE.equals(actionName)){
			tileWindows(desktop);    			

    		}else if (ActionConst.CMD_WINDOW_MAXIMIZE.equals(actionName)){
			maximizeWindows(desktop,true);

    		}else if (ActionConst.CMD_WINDOW_MINIMIZE.equals(actionName)){
			maximizeWindows(desktop,false);
		
		}else if (ActionConst.CMD_WINDOW_TOGGLE.equals(actionName)){

			if (sender!=null && sender instanceof JMenuItem){
				JMenuItem mi	=(JMenuItem)sender;
				m_pane.focusWindowByTitle(mi.getText());
			}
		}
	}

  	private void maximizeWindows(JDesktopPane desktop,boolean max){
     		JInternalFrame[] frames = desktop.getAllFrames();

      		for (int i = 0; i < frames.length; i++){
         		  try{  /* try to make maximized frames resizable
                  		    this might be vetoed
               			*/
               			if (max)
               				frames[i].setMaximum(true);
               			else
               				frames[i].setIcon(true);
            		  }catch(Exception e){}
      		}
   	}


  	private void cascadeWindows(JDesktopPane desktop){
     		JInternalFrame[] frames = desktop.getAllFrames();
      		int x = 0;
      		int y = 0;
      		int width = desktop.getWidth() / 2;
      		int height = desktop.getHeight() / 2;
      		int frameDistance =30;

      		for (int i = 0; i < frames.length; i++){
      		  	if (!frames[i].isIcon()){
         		  try{  /* try to make maximized frames resizable
                  		    this might be vetoed
               			*/
               			frames[i].setMaximum(false);
               			frames[i].reshape(x, y, width, height);

               			x += frameDistance;
               			y += frameDistance;
               			// wrap around at the desktop edge
               			if (x + width > desktop.getWidth()) x = 0;
               			if (y + height > desktop.getHeight()) y = 0;
            		  }catch(Exception e){}
         		}
      		}
   	}

   	public void tileWindows(JDesktopPane desktop){
   	  	JInternalFrame[] frames = desktop.getAllFrames();

      		// count frames that aren't iconized
      		int frameCount = 0;
      		for (int i = 0; i < frames.length; i++){
        		if (!frames[i].isIcon())
            		frameCount++;
      		}

      		int rows = (int)Math.sqrt(frameCount);
      		int cols = frameCount / rows;
      		int extra = frameCount % rows;
         	// number of columns with an extra row

      		int width = desktop.getWidth() / cols;
      		int height = desktop.getHeight() / rows;
      		int r = 0;
      		int c = 0;
      		for (int i = 0; i < frames.length; i++){
        		if (!frames[i].isIcon()){
         		  try{
              			frames[i].setMaximum(false);
               			frames[i].reshape(c * width,
                  		r * height, width, height);
               			r++;
               			if (r == rows){
               			  	r = 0;
                  			c++;
                  			if (c == cols - extra){
                  			  	// start adding an extra row
                     				rows++;
                     				height = desktop.getHeight() / rows;
                  			}
               			}
            		  }catch(Exception e){}
         		}
      		}
   	}


    	/** Process ruler issues. i.e. change it into english or metric ruler.
    	 *  @param actionName Action name for ruler
    	 */
    	private  void processRulerIssues(String actionName){

	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;
    		
    		DrawPane   drawPane	=drawCanvas.getParentDrawPane();
    		if (drawPane==null) return;
    		
		if (ActionConst.CMD_GRAPH_RULER_ENGLISH.equals(actionName)){
    			drawPane.setIsMetric(false);

    		}else if (ActionConst.CMD_GRAPH_RULER_METRIC.equals(actionName)){
    			drawPane.setIsMetric(true);
    		}

         }



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

	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;


                JFrame	f	=GUIUtils.getJFrame(m_pane);
                double zoomScale	=drawCanvas.getZoomScale();
                double oldZoomScale	=zoomScale;
                
		if (ActionConst.CMD_GRAPH_ZOOM_ACTUALSIZE.equals(actionName)){
			drawCanvas.setZoomScale(1.0);
			
	        }else if (ActionConst.CMD_GRAPH_ZOOMIN.equals(actionName)){
	        	zoomScale	=ZoomDialog.nextBigZoomScale(zoomScale);
            		drawCanvas.setZoomScale(zoomScale);

	        }else if (ActionConst.CMD_GRAPH_ZOOMOUT.equals(actionName)){
	        	zoomScale	=ZoomDialog.nextSmallZoomScale(zoomScale);
            		drawCanvas.setZoomScale(zoomScale);
	        
	        }else if (ActionConst.CMD_GRAPH_ZOOMSETUP.equals(actionName)){
	        	zoomScale	=ZoomDialog.getNewZoomScale(f,zoomScale);
            		drawCanvas.setZoomScale(zoomScale);
	        }
	        
	        drawCanvas.getOperationManager().addZoom(oldZoomScale,zoomScale);
	        drawCanvas.repaint();
        }


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

	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
    		if (drawCanvas==null) return;


		GridFormat gridFormat	=drawCanvas.getGridFormat();
                JFrame	f	=GUIUtils.getJFrame(m_pane);
	        if (ActionConst.CMD_GRAPH_GRIDFORMAT.equals(actionName)){
            		GridFormat	newGridFormat	=GridFormatDialog.getNewGridFormat(f,gridFormat);
            		gridFormat.setValue(newGridFormat);
	        }
	        drawCanvas.repaint();
        }


    	/** Process settings
    	 *  @param actionName Action name for settings.
    	 */
    	private  void processSettings(String actionName){

                JFrame	f	=GUIUtils.getJFrame(m_pane);
                
        	if (ActionConst.CMD_SETTING_GLOBALSETTING.equals(actionName)){  //page setting
        		GlobalSettings settings	=GlobalSettings.getInstance();
			if (GlobalSettingDialog.newGlobalSetting(f,settings)){

				boolean isMetric	=settings.isMetric();
				 
				JDesktopPane	desktop	=m_pane.getDesktop();
				if (desktop!=null){
					if (desktop.getAllFrames().length<=0)
						return;
					resetMeasurement(desktop,isMetric);
				}
				m_pane.setIsMetric(isMetric);
			};
			
			return;
            	}

                
	    	//current drawing canvas
    		DrawCanvas drawCanvas =getCurrentDrawCanvas();
                if (drawCanvas==null)
                       	return;
                        	
    		JFPage    page  =drawCanvas.getDrawPage();
		Selection selection	=drawCanvas.getSelection();

    		if (ActionConst.CMD_SETTING_SHAPEPROPERTIES.equals(actionName)){//change object properties
    				if (selection.size()<=0){
 					JOptionPane.showMessageDialog(null, CADResource.getString("invalid.shapeObject"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    					return;      
				}   


				AbstractShape	aShape  =selection.getFirstObj();
				try{
					ObjectList  oldProperties =(ObjectList)aShape.getPropertyList().clone();
					if (PropertyDialog.getNewProperties(f,aShape)){
						drawCanvas.getDrawPage().setModified(true);
						ObjectList newProperties	=aShape.getPropertyList();
						drawCanvas.getOperationManager().addModifyProperties(aShape,oldProperties,newProperties);
				  		//first graph event: shape property changed
				  		m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
					}
				}catch(Exception e){
				
				}

            	}else if (ActionConst.CMD_SETTING_SHAPETEXT.equals(actionName)){  //change shape text
    				if (selection.size()<=0){
 					JOptionPane.showMessageDialog(null, CADResource.getString("invalid.shapeObject"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    					return;      
				}   
				
				if (selection.modifyLabel(drawCanvas,drawCanvas.getOperationManager())){
				  	//first graph event: shape property changed
				  	m_graphEventDispatcher.fireShapePropertyChanged(selection.getList());
					
					drawCanvas.repaint();
				}

            	}else if (ActionConst.CMD_SETTING_CHANGEIMAGE.equals(actionName)){  //change image, for jfimage only.
				AbstractShape shape	=selection.getFirstObj();
				if (shape==null || !(shape instanceof JFImage)){
 					JOptionPane.showMessageDialog(null, CADResource.getString("invalid.imageObject"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    					return;      
				}

                		//one object in select was disabled modifying properties
                		List l	=new ArrayList();
                		l.add(shape);
    				if (ShapeSettingDialog.getDisableModifyingProperties(l,true)){
 					JOptionPane.showMessageDialog(null, CADResource.getString("dialog.shapesetting.modificationdisabled"), CADResource.getString("sys.warn"), JOptionPane.ERROR_MESSAGE); 
    					return;      
    				}
				
				File imageFile	=FileDialog.getInputFile(drawCanvas,FileDialog.getImageFileFilter());
				if (imageFile==null)
					return;
					
            			JFImage image	=(JFImage)shape;

⌨️ 快捷键说明

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