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

📄 globalsettings.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   		if (m_globalPath==null || m_globalPath.equals("")){
   			m_globalPath	=System.getProperty("user.dir");
   		}
   		return m_globalPath;
   	}
  
   	/**
    	*   Set the global path.
    	*   @param path A new global path.
    	*/
   	public void setGlobalPath(String path){
   		if (!m_globalPath.equals(path)){
   			m_globalPath	=path;
			writeConfigFile();
		}
   	}


        /**
         *  Get if user would like to export/print graph with grid.
         *  @return True if export with grid, false otherwise.
         */
        public boolean isExportWithGrid(){
        	return m_exportWithGrid;
	}


   	/** Set export with grid, or not.
   	 * @param withGrid if export with grid.
    	 */
   	public void setExportWithGrid(boolean withGrid){
   		m_exportWithGrid	=withGrid;
   		writeConfigFile();
   	}

        /**
         *  Get if user would like to export/print graph with ruler.
         *  @return True if export with ruler, false otherwise.
         */
        public boolean isExportWithRuler(){
        	return m_exportWithRuler;
	}

   	/** Set export with ruler, or not.
   	 * @param withRuler if export with ruler.
    	 */
   	public void setExportWithRuler(boolean withRuler){
   		m_exportWithRuler	=withRuler;
   		writeConfigFile();
   	}

        /** get arrow format*/
	public Arrow getArrow(){
		return m_arrow;
	}        
        /** set arrow format*/
	public void setArrow(Arrow arrow){
		m_arrow.setValue(arrow);
        	Arrow.setDefaultArrow(arrow);
   		writeConfigFile();
	}        

        /** get line format*/
	public LineFormat getLineFormat(){
		return m_lineFormat;
	}        
        /** set line format*/
	public void setLineFormat(LineFormat lineFormat){
		m_lineFormat.setValue(lineFormat);
        	LineFormat.setDefaultLineFormat(lineFormat);
   		writeConfigFile();
	}        

        /** get fill format*/
	public FillFormat getFillFormat(){
		return m_fillFormat;
	}        
        /** set fill format*/
	public void setFillFormat(FillFormat fillFormat){
		m_fillFormat.setValue(fillFormat);
        	FillFormat.setDefaultFillFormat(fillFormat);
   		writeConfigFile();
	}        

        /** get font format*/
	public FontFormat getFontFormat(){
		return m_fontFormat;
	}        
        /** set font format*/
	public void setFontFormat(FontFormat fontFormat){
		m_fontFormat.setValue(fontFormat);
        	FontFormat.setDefaultFontFormat(fontFormat);
   		writeConfigFile();
	}        

        /** get canvas format*/
	public CanvasFormat getCanvasFormat(){
		return m_canvasFormat;
	}        
        /** set canvas format*/
	public void setCanvasFormat(CanvasFormat canvasFormat){
		m_canvasFormat.setValue(canvasFormat);
        	CanvasFormat.setDefaultCanvasFormat(canvasFormat);
   		writeConfigFile();
	}        
       

        //private global settings for global usage.
        private static GlobalSettings settings	=new GlobalSettings();
	public static GlobalSettings getInstance(){
		return settings;
	}
	
	/** private constructor to prevent 'new' operations*/
    	private GlobalSettings() { 
    		loadConfigFile();
	}
        
        /**
         *   Load a key-value pair from a string value.
         *   A statement would be a key value pair, such as 'key=value'
         */
        private void loadKeyValue(String stmt){
        	if (stmt==null || stmt.equals(""))
        		return;
        	
        	int pos	=stmt.indexOf('=');
        	if (pos<0)
        		return;
        	
		String key	=stmt.substring(0,pos).trim();
		String value	=stmt.substring(pos+1).trim();  
		
		if (key.equals("") || value.equals(""))
			return;
		
		int intValue		=CommonUtil.s2i(value);
		double doubleValue      =CommonUtil.s2f(value);
		boolean boolValue	=(intValue==1?true:false);

		//general settings				
		if (key.equals(CONFIG_KEY_MEASURE)){
			m_measure	=intValue;

		}else if (key.equals(CONFIG_KEY_HIDEPORTS)){
			m_hidePorts	=boolValue;
			
		}else if (key.equals(CONFIG_KEY_DISABLEPORTSNAPPING)){
			m_disablePortSnapping	=(boolValue);

		}else if (key.equals(CONFIG_KEY_SCALEVALUE)){
			m_scaleValue		=doubleValue;
			
		}else if (key.equals(CONFIG_KEY_SCALEUNIT)){
			m_scaleUnit	=intValue;
			
		}else if (key.equals(CONFIG_KEY_SCREENUNIT)){
			m_screenUnit	=intValue;

		}else if (key.equals(CONFIG_KEY_GLOBALPATH)){
			m_globalPath	=value;

		}else if (key.equals(CONFIG_KEY_EXPORTWITHGRID)){
			m_exportWithGrid	=boolValue;

		}else if (key.equals(CONFIG_KEY_EXPORTWITHRULER)){
			m_exportWithRuler	=boolValue;
		
		//global arrow format 
		}else if (key.equals(CONFIG_KEY_ARROWFORMAT_STARTARROWTYPE)){
			m_arrow.setStartArrow(intValue);
		}else if (key.equals(CONFIG_KEY_ARROWFORMAT_ENDARROWTYPE)){
			m_arrow.setEndArrow(intValue);
		
		//global line format
		}else if (key.equals(CONFIG_KEY_LINEFORMAT_LINESTYLE)){
			m_lineFormat.setLineStyle(intValue);
		}else if (key.equals(CONFIG_KEY_LINEFORMAT_LINEWIDTH)){
			m_lineFormat.setLineWidth(intValue);
		}else if (key.equals(CONFIG_KEY_LINEFORMAT_LINECOLOR)){
			m_lineFormat.setLineColor(new Color(intValue));
		
		//global fill format
		}else if (key.equals(CONFIG_KEY_FILLFORMAT_FILLSTYLE)){
			m_fillFormat.setFillStyle(intValue);
		}else if (key.equals(CONFIG_KEY_FILLFORMAT_FILLCOLOR)){
			m_fillFormat.setFillColor(new Color(intValue));
		}else if (key.equals(CONFIG_KEY_FILLFORMAT_FILLCOLOR2)){
			m_fillFormat.setFillColor2(new Color(intValue));
		}else if (key.equals(CONFIG_KEY_FILLFORMAT_FILLLINESTYLE)){
			m_fillFormat.setFillLineStyle(intValue);
		}else if (key.equals(CONFIG_KEY_FILLFORMAT_FILLLINECOLOR)){
			m_fillFormat.setFillLineColor(new Color(intValue));
                
                //global font format
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FONTSTYLE)){
			m_fontFormat.setFontStyle(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FONTSIZE)){
			m_fontFormat.setFontSize(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FONTNAME)){
			m_fontFormat.setFontName(value);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FONTCOLOR)){
			m_fontFormat.setFontColor(new Color(intValue));

		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FONTTRANSPARENCY)){
			m_fontFormat.setTransparency(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_USESTROKEANDFILL)){
			m_fontFormat.setUseStrokeAndFill(boolValue);

		}else if (key.equals(CONFIG_KEY_FONTFORMAT_LINESTYLE)){
			m_fontFormat.getLineFormat().setLineStyle(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_LINEWIDTH)){
			m_fontFormat.getLineFormat().setLineWidth(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_LINECOLOR)){
			m_fontFormat.getLineFormat().setLineColor(new Color(intValue));

		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FILLSTYLE)){
			m_fontFormat.getFillFormat().setFillStyle(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FILLCOLOR)){
			m_fontFormat.getFillFormat().setFillColor(new Color(intValue));
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FILLCOLOR2)){
			m_fontFormat.getFillFormat().setFillColor2(new Color(intValue));
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FILLLINESTYLE)){
			m_fontFormat.getFillFormat().setFillLineStyle(intValue);
		}else if (key.equals(CONFIG_KEY_FONTFORMAT_FILLLINECOLOR)){
			m_fontFormat.getFillFormat().setFillLineColor(new Color(intValue));
		
		//global canvas format
		}else if (key.equals(CONFIG_KEY_CANVASFORMAT_CANVASWIDTH)){
			m_canvasFormat.setWidth(doubleValue);
		}else if (key.equals(CONFIG_KEY_CANVASFORMAT_CANVASWIDTHUNIT)){
			m_canvasFormat.setWidthUnit(intValue);
		}else if (key.equals(CONFIG_KEY_CANVASFORMAT_CANVASHEIGHT)){
			m_canvasFormat.setHeight(doubleValue);
		}else if (key.equals(CONFIG_KEY_CANVASFORMAT_CANVASHEIGHTUNIT)){
			m_canvasFormat.setHeightUnit(intValue);

		}else if (key.equals(CONFIG_KEY_ROTATE_TYPE)){
			m_rotateType	=intValue;
		}else if (key.equals(CONFIG_KEY_ROTATE_ANGLE)){
			m_rotateAngle	=doubleValue;
		}
	}

        
        /**
         *   Read content from a text config file.
         */
	public void loadConfigFile(){
		try{		                	
			String fileName	=CommonUtil.getSystemProperty("user.dir")+"/"+CONFIG_FILE;
			BufferedReader in = new BufferedReader(new FileReader(fileName) );
                	while (true){
                		String text	= in.readLine();
                		if (text==null)
                			break;
                		loadKeyValue(text);
                	}
                	in.close();  
                	
                	Arrow.getDefaultArrow().setValue(m_arrow);
                	LineFormat.getDefaultLineFormat().setValue(m_lineFormat);
                	FillFormat.getDefaultFillFormat().setValue(m_fillFormat);
                	FontFormat.getDefaultFontFormat().setValue(m_fontFormat);
                	CanvasFormat.getDefaultCanvasFormat().setValue(m_canvasFormat);  
                	
               	
                	
                }catch(Exception e){
                	//System.out.println("read config file error: "+e.getMessage());
                }
        }


        /**
         *   save text config file from current global settings definition.
         *   
         */
	public void writeConfigFile(){
		try{		 
			String fileName	=CommonUtil.getSystemProperty("user.dir")+"/"+CONFIG_FILE;
                	PrintWriter out = new PrintWriter( new FileWriter(fileName) );
        
        		//general settings        	
                	out.println(CONFIG_KEY_MEASURE 			+"="+ m_measure);
                	out.println(CONFIG_KEY_HIDEPORTS 		+"="+ (m_hidePorts?1:0));
                	out.println(CONFIG_KEY_DISABLEPORTSNAPPING 	+"="+ (m_disablePortSnapping?1:0));
                	out.println(CONFIG_KEY_SCALEVALUE		+"="+ m_scaleValue);
                	out.println(CONFIG_KEY_SCALEUNIT		+"="+ m_scaleUnit);
                	out.println(CONFIG_KEY_SCREENUNIT		+"="+ m_screenUnit);
                	out.println(CONFIG_KEY_GLOBALPATH		+"="+ m_globalPath);
                	out.println(CONFIG_KEY_EXPORTWITHGRID 		+"="+ (m_exportWithGrid?1:0));
                	out.println(CONFIG_KEY_EXPORTWITHRULER 		+"="+ (m_exportWithRuler?1:0));
			
			//global arrow settings
                	out.println(CONFIG_KEY_ARROWFORMAT_STARTARROWTYPE+"="+ 	m_arrow.getStartArrow());
                	out.println(CONFIG_KEY_ARROWFORMAT_ENDARROWTYPE +"="+  	m_arrow.getEndArrow());
			
			//global line format settings
                	out.println(CONFIG_KEY_LINEFORMAT_LINESTYLE	+"="+	m_lineFormat.getLineStyle());
                	out.println(CONFIG_KEY_LINEFORMAT_LINEWIDTH	+"="+	m_lineFormat.getLineWidth());
                	out.println(CONFIG_KEY_LINEFORMAT_LINECOLOR	+"="+	m_lineFormat.getLineColor().getRGB());
			
			//global fill format settings
			out.println(CONFIG_KEY_FILLFORMAT_FILLSTYLE	+"="+	m_fillFormat.getFillStyle());
			out.println(CONFIG_KEY_FILLFORMAT_FILLCOLOR	+"="+	m_fillFormat.getFillColor().getRGB());
			out.println(CONFIG_KEY_FILLFORMAT_FILLCOLOR2	+"="+	m_fillFormat.getFillColor2().getRGB());
			out.println(CONFIG_KEY_FILLFORMAT_FILLLINESTYLE +"="+	m_fillFormat.getFillLineStyle());
			out.println(CONFIG_KEY_FILLFORMAT_FILLLINECOLOR	+"="+	m_fillFormat.getFillLineColor().getRGB());
			
			//global font format settings			
			out.println(CONFIG_KEY_FONTFORMAT_FONTSTYLE	+"="+	m_fontFormat.getFontStyle());
			out.println(CONFIG_KEY_FONTFORMAT_FONTSIZE	+"="+	m_fontFormat.getFontSize());
			out.println(CONFIG_KEY_FONTFORMAT_FONTNAME	+"="+	m_fontFormat.getFontName());
			out.println(CONFIG_KEY_FONTFORMAT_FONTCOLOR	+"="+	m_fontFormat.getFontColor().getRGB());

			out.println(CONFIG_KEY_FONTFORMAT_FONTTRANSPARENCY +"="+m_fontFormat.getTransparency());
			out.println(CONFIG_KEY_FONTFORMAT_USESTROKEANDFILL +"="+ (m_fontFormat.isUseStrokeAndFill()?1:0));

                	out.println(CONFIG_KEY_FONTFORMAT_LINESTYLE	+"="+	m_fontFormat.getLineFormat().getLineStyle());
                	out.println(CONFIG_KEY_FONTFORMAT_LINEWIDTH	+"="+	m_fontFormat.getLineFormat().getLineWidth());
                	out.println(CONFIG_KEY_FONTFORMAT_LINECOLOR	+"="+	m_fontFormat.getLineFormat().getLineColor().getRGB());
			
			out.println(CONFIG_KEY_FONTFORMAT_FILLSTYLE	+"="+	m_fontFormat.getFillFormat().getFillStyle());
			out.println(CONFIG_KEY_FONTFORMAT_FILLCOLOR	+"="+	m_fontFormat.getFillFormat().getFillColor().getRGB());
			out.println(CONFIG_KEY_FONTFORMAT_FILLCOLOR2	+"="+	m_fontFormat.getFillFormat().getFillColor2().getRGB());
			out.println(CONFIG_KEY_FONTFORMAT_FILLLINESTYLE +"="+	m_fontFormat.getFillFormat().getFillLineStyle());
			out.println(CONFIG_KEY_FONTFORMAT_FILLLINECOLOR	+"="+	m_fontFormat.getFillFormat().getFillLineColor().getRGB());

			//global canvas format settings
			out.println(CONFIG_KEY_CANVASFORMAT_CANVASWIDTH		+"="+	m_canvasFormat.getWidth());
			out.println(CONFIG_KEY_CANVASFORMAT_CANVASWIDTHUNIT	+"="+	m_canvasFormat.getWidthUnit());
			out.println(CONFIG_KEY_CANVASFORMAT_CANVASHEIGHT	+"="+	m_canvasFormat.getHeight());
			out.println(CONFIG_KEY_CANVASFORMAT_CANVASHEIGHTUNIT	+"="+	m_canvasFormat.getHeightUnit());


			//rotate setup
			out.println(CONFIG_KEY_ROTATE_TYPE		+"="+	m_rotateType);
			out.println(CONFIG_KEY_ROTATE_ANGLE		+"="+	m_rotateAngle);
				                	
                	out.close();
                }catch(Exception e){
                	//System.out.println("write config file error: "+e.getMessage());
        	}
	}              




 }

⌨️ 快捷键说明

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