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

📄 jfdrawapplet.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
字号:
/**
 *    $Id:JFDrawApplet.java $
 *
 *    Copyright 2004 ~ 2005  JingFei International Cooperation LTD. All rights reserved. *
 */

import javax.swing.JApplet;
import javax.swing.JMenuBar;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


import com.jfimagine.jfdraw.gui.DrawPane;
import com.jfimagine.jfdraw.gui.DrawCanvas;    
import com.jfimagine.jfdraw.gui.dialog.LibDialog;
import com.jfimagine.jfdraw.gui.dialog.LibHelper;
import com.jfimagine.jfdraw.gui.dialog.LibContainer;

import com.jfimagine.jfgraph.shape.union.JFPage;
import com.jfimagine.jfdraw.gui.ToolFactory;

import com.jfimagine.jfgraph.transfer.ExportBase;
import com.jfimagine.jfgraph.transfer.ExportJPG;

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


 /**
 * JFDrawApplet class is an applet class for runing JFDraw.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.6.0 $
 */  
 public class JFDrawApplet extends JApplet implements ActionListener {
        
        private DrawPane m_drawPane;
        
        //a specified save file name
	private String m_exportJFD	="";
	//a specified export JPG file name
	private String m_exportJPG	="";
	 
	       
	public void init(){ 
		
		//an inner class for a subclass of DrawPane.
		class AppletDrawPane extends DrawPane{
			ToolFactory toolFactory;
		
			public AppletDrawPane(ToolFactory toolFactory){
				this.toolFactory  =toolFactory;
			}

			/** set current layer name of current drawing page.
    			*  @param layerName  Current layername
    			*/
   			public void setLayerName(String layerName){
   				toolFactory.setLayerName(layerName);
			}
		}
		
				 
		ToolFactory toolFactory =new ToolFactory();

		Container c; 
		c=getContentPane(); 
		c.setLayout(new BorderLayout()); 
                
            	//Action: create a draw panel
            	//Desc:   A DrawPane object packaged a vertical ruler, a horizontal ruler and a drawing canvas
            	m_drawPane	=new AppletDrawPane(toolFactory);

                //add two toolba1r to applet.
                JPanel toolPanel	=new JPanel();
                toolPanel.setLayout(new BorderLayout());
                toolPanel.add("North",createToolBar1(this));
                toolPanel.add("Center",createToolBar2(this));
		c.add("North",toolPanel);

            	//action: add menu to Applet
            	setJMenuBar(createMenuBar(this));
               
                ///* demo 
                //make a library container
		LibHelper helper	=LibHelper.getInstance();
		helper.setLibraryType(LibHelper.LIBRARY_VISIBLETYPE_EXTERNAL);
		
		LibContainer container	=new LibContainer(m_drawPane);
		helper.setLibraryPanel(container.getLibraryPanel());
		helper.setTemplatePanel(container.getTemplatePanel());
		
		//add drawPane and library container into a SplitPane:
		JSplitPane splitPane	=new JSplitPane();
		splitPane.setLeftComponent(container);
		splitPane.setRightComponent(m_drawPane); 
		splitPane.setDividerLocation(140); 
		splitPane.setOneTouchExpandable(true);

		//add this split pane into applet's content pane.
		c.add("Center",splitPane);
		//*/
		//c.add("Center",m_drawPane);
            	

		//open a file when applet startup. 
		/*
    		String file1 = getParameter("file1");
    		if (file1!=null && !file1.equals("")){
    			try{
    				m_drawPane.openFile(file1);
    				//DrawCanvas drawCanvas	=m_drawPane.getDrawCanvas();
    				//drawCanvas.getDrawPage().loadFromBinary(file1,drawCanvas);
    			}catch(Exception e){
    			}
    		} 


    		String library1 = getParameter("library1");
    		if (library1!=null && !library1.equals("")){
    			container.getLibraryPanel().loadLibrary(library1);
    		} 

    		String template1 = getParameter("template1");
    		if (template1!=null && !template1.equals("")){
    			container.getTemplatePanel().loadLibrary(template1);
    		} 

		//specified file name to be saved to
		//m_exportJFD	= getParameter("exportJFD");
		//specified jpeg file name to be exported to
		//m_exportJPG	= getParameter("exportJPG");
		
    		//*/
	} 


	public void paint(Graphics g){ 
                super.paint(g);
                m_drawPane.repaint();
	} 


	public void actionPerformed(ActionEvent e){ 
		
		String cmd		=e.getActionCommand();
		boolean saveProcessed	=false;                
                if (ActionConst.CMD_FILE_SAVE.equals(cmd)){
                	
			                	
			//save to JPG
			if (m_exportJFD!=null && !m_exportJFD.equals("")){
				m_drawPane.saveFile(m_exportJFD);
				saveProcessed	=true;
			}

			//exporting to JPG
			if (m_exportJPG!=null && !m_exportJPG.equals("")){
				FileAction m_fileAction	=new FileAction(m_drawPane);		
				ExportBase export	=new ExportJPG();
				//export.setUsePageBounds(true);
				//export.getOutputPage().setUsePageBounds(true);
				m_fileAction.exportingFile(export,false,m_exportJPG);
				saveProcessed	=true;
			}

			
			if (saveProcessed)
				return;	
				
		}
		
		m_drawPane.actionPerformed(e);
	} 
        
        
   	/**
     	*   Create a main menu bar.
     	*/	
   	public static JMenuBar createMenuBar(ActionListener listener) {
        	JMenuBar mBar = new JMenuBar();
        
        	mBar.add(ToolFactory.createDocMenu(listener,true));
        	mBar.add(ToolFactory.createEditMenu(listener,false));
        	mBar.add(ToolFactory.createViewMenu(listener,true,true));
        	mBar.add(ToolFactory.createShapeMenu(listener));
        	mBar.add(ToolFactory.createDrawMenu(listener));
        	mBar.add(ToolFactory.createSetMenu(listener));
        	mBar.add(ToolFactory.createHelpMenu(listener));
        
        	return mBar;
   	}      
      

    	/**
     	*   Create a tool bar.
     	*/	
    	public JToolBar createToolBar1(ActionListener listener) {

        	//Create the toolbar.
        	JToolBar toolBar = new JToolBar();
        	toolBar.setFloatable(false);
                
                ToolFactory factory	=new ToolFactory();
                
		//add file buttons	
		factory.addFileButtons(toolBar,listener);
        	toolBar.addSeparator();

		//add alignment buttons	
		factory.addAlignmentButtons(toolBar,listener);
        	toolBar.addSeparator();

		//add layer buttons
		factory.addLayerButtons(toolBar,listener);
        	
        	        	
        	return toolBar;
	}


    	/**
     	*   Create a tool bar.
     	*/	
    	public JToolBar createToolBar2(ActionListener listener) {

        	//Create the toolbar.
        	JToolBar toolBar = new JToolBar();
        	toolBar.setFloatable(false);

                ToolFactory factory	=new ToolFactory();

		//add graph drawing buttons
		factory.addGraphDrawButtons(toolBar,listener);
        	toolBar.addSeparator();



		//add graph processing buttons
		factory.addGraphProcessButtons(toolBar,listener);

		return toolBar;
    	}
    
             	    	
    	
 }

⌨️ 快捷键说明

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