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

📄 scale.java

📁 JaNet: Java Neural Network Toolkit resume: A well documented toolkit for designing and training, a
💻 JAVA
字号:
////////////////////////////////////////////////////////////////////////////////////  //  //  Copyright (C) 1996 L.  Patocchi & W.Gander////  This program is free  software;  you can  redistribute  it and/or  modify it//  under the terms of the GNU General  Public  License as published by the Free//  Software  Foundation;  either  version 2 of the License, or (at your option)//  any later version.////  This program is  distributed in the hope that it will be useful, but WITHOUT//  ANY  WARRANTY;  without  even the implied  warranty  of  MERCHANTABILITY  or//  FITNESS FOR A PARTICULAR  PURPOSE.  See the GNU General  Public  License for//  more details.////  You should have received a copy of the GNU General Public License along with//  this program; if not, write to the Free Software  Foundation, Inc., 675 Mass//  Ave, Cambridge, MA 02139, USA.////  Contacts://  //    Project Supervisor//      W.Hett       hew@info.isbiel.ch//  //    Authors//      W.Gander     gandw@info.isbiel.ch//      L.Patocchi   patol@info.isbiel.ch////  Documentation can be found at:////      http://www.isbiel.ch/Projects/janet/index.html////////////////////////////////////////////////////////////////////////////////////////// File : Scale.java//package jaNet.backprop.gui;import java.awt.*;public class Scale extends Canvas{	public static final int CONTINUE	= 0;	public static final int BINARY		= 1;	private double	minVal;	private double	maxVal;	private Color	minCol = Color.red;	private Color	maxCol = Color.blue;		private int		verticalBorder 		= 10;	private int		horizontalBorder 	= 4;	private int		block 				= 5;	private double 	valueToShow 		= 0.0;	private boolean showValueToShow 	= false;		private int		scaleMode			= CONTINUE;	private boolean	barIsPressed		= false;	private boolean scaleIsOn			= false;    private BPNgui	dearParent;	public Scale(Frame parent, double min, double max){		super();		minVal = min;		maxVal = max;		dearParent = (BPNgui) parent;	}	public Scale(Frame parent, double min, double max, Color cMin, Color cMax){		this(parent, min, max);		minCol = cMin;		maxCol = cMax;	}	public void paint(Graphics g){        Dimension d = this.size();        int w = d.width;        int h = d.height - 2*verticalBorder;        Color c1,c2;				// create an image to avoid flicks		Image image = createImage(d.width, d.height);		Graphics g2 = image.getGraphics();				g2.setColor(Color.lightGray);		g2.fillRect(0,0,d.width, d.height);		g2.fill3DRect(w*3/4-1, verticalBorder-1, w/4-horizontalBorder+2, h+2, !barIsPressed);				if(scaleIsOn){			for(int y=0; y<h-block; y+=block){				g2.setColor(getColor((double)y/(double)h * (maxVal - minVal) + minVal));				g2.fillRect(w*3/4, y+verticalBorder, w/4-horizontalBorder, block);			}		}				if(showValueToShow){			showValue(g2, valueToShow, Font.BOLD);		}else{			showValue(g2, 0.0, Font.PLAIN);			showValue(g2, minVal, Font.PLAIN);			showValue(g2, maxVal, Font.PLAIN);		}				g.drawImage(image,  0,0, this);	}		public void showValue(Graphics g, double val, int font){        Dimension d = this.size();        int w = d.width;        int h = d.height - 2*verticalBorder;		int hVal = verticalBorder+(int)((val-minVal)*(double)h /(maxVal-minVal));		g.setColor(Color.black);		g.fillRect(w*3/4, hVal, w/4-horizontalBorder, 1);		g.setFont(new Font("Helvetica",font , 10));		String str = ""+val;		if(str.length()>4){			g.drawString(str.substring(0,5), horizontalBorder, hVal);		}else{			g.drawString(str, 2, hVal);		}	}		public void showValue(double val){		valueToShow = val;		showValueToShow = true;		paint(getGraphics());	}	public void hideValue(){		showValueToShow = false;		paint(getGraphics());	}		public Color getColor(double x){		if(!scaleIsOn) return Color.lightGray;		if(scaleMode == CONTINUE){			int rMin = minCol.getRed();			int gMin = minCol.getGreen();			int bMin = minCol.getBlue();			int rMax = maxCol.getRed();			int gMax = maxCol.getGreen();			int bMax = maxCol.getBlue();			int r,g,b;			r = (int)( (x-minVal) * (double)(rMax-rMin)/(maxVal-minVal) ) + rMin;			g = (int)( (x-minVal) * (double)(gMax-gMin)/(maxVal-minVal) ) + gMin;			b = (int)( (x-minVal) * (double)(bMax-bMin)/(maxVal-minVal) ) + bMin;			//System.out.println("x="+x+"  rgb=("+r+","+g+","+b+")");			return new Color(r, g, b);		}// else ...		if((x-minVal) > (maxVal-minVal)/2){			return maxCol;		}// else ...		return minCol;	}		public void setDomainValue(double min, double max){		minVal = min;		maxVal = max;		paint(getGraphics());	}		public void setScaleIsOn(boolean bool){		scaleIsOn = bool;		paint(getGraphics());	}	    public boolean handleEvent(Event event) {		if (event.id == Event.MOUSE_DOWN){			barIsPressed = true;			if(scaleMode == CONTINUE){				scaleMode = BINARY;			}else{				scaleMode = CONTINUE;			}			requestFocus();			paint(getGraphics());			return true;		}else if (event.id == Event.MOUSE_UP){			barIsPressed = false;			paint(getGraphics());			dearParent.refreshBPNgui();			return true;		}		    	return super.handleEvent(event);    }	}

⌨️ 快捷键说明

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