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

📄 poly.java

📁 JavaMapper是一个免费的Java应用程序
💻 JAVA
字号:
import java.awt.*;public class Poly implements ShapeInterface {int x,y,w,h;public boolean nextShown=false;public String url="",name;private int px[]=new int[500],py[]=new int[500],points,index,nodeResize=-1,nextX,nextY;private boolean selected,highlighted,drawing=true;private Polygon polygon;public Poly(int x, int y) {	this.x = x;	this.y = y;	px[0] = x;	py[0] = y;	points = 1;	showNext(x,y);}public void draw(Graphics s) {	s.setColor(Color.blue);	if (points==0) return;	polygon = new Polygon(px,py,points);		if (drawing) {		s.fillRect(px[points-1]-2,py[points-1]-2,5,5);		if (nextShown) {			s.drawLine(px[points-1],py[points-1],nextX,nextY);			if (points>1) drawDottedLine(s,px[0],py[0],nextX,nextY);		}		for (int i=0;i<points-1;i++) {			s.drawLine(px[i],py[i],px[i+1],py[i+1]);		}/*		if (points>2) {			if (nextShown) s.setColor(Color.red);			drawDottedLine(s,px[0],py[0],px[points-1],py[points-1]);			s.setColor(Color.blue);		}*/	}	else {		if (isHighlighted() || isSelected()) {			s.setColor(Color.red);			// draw highlight lines		}		s.drawPolygon(polygon);			if (isSelected()) {			// draw resize blocks			for (int i=0;i<points;i++) {				s.fillRect(px[i]-2,py[i]-2,7,7);			}		}	}}public void drawDottedLine(Graphics s, int x1, int y1, int x2, int y2) {	int x[]=new int[200],y[]=new int[200],lw,lh;	double num,dx,dy;	lw = x1-x2;	lh = y1-y2;	num = Math.sqrt(Math.pow(lw,2)+Math.pow(lh,2))/5;	dx = lw/num;	dy = lh/num;	for (int i=0;i<=(int)num;i++) {		x[i] = (int)Math.round(x1-i*dx);		y[i] = (int)Math.round(y1-i*dy);	}	for (int i=0;i<(int)num;i+=2) {		s.drawLine(x[i],y[i],x[i+1],y[i+1]);	}}public void showNext(int x, int y) {	nextX = x;	nextY = y;}public int getPoints() {	return points;}public void setDrawing(boolean b) {	drawing = b;}public void newPoint(int x, int y) {	px[points] = x;	py[points] = y;	points += 1;}public boolean checkNewPoint(int x, int y) {	return checkWithin(x,y,px[points-1]-2,py[points-1]-2,px[points-1]+2,py[points-1]+2);}public void changePoint(int x, int y) {	px[points-1] = x;	py[points-1] = y;}public void deletePoint(int pointIndex) {	if (points<3) return;	for (int i=pointIndex;i<points-1;i++) {		px[i] = px[i+1];		py[i] = py[i+1];	}	points -= 1;}public void insertPoint(int node) {		for (int i=points;i>node;i--) {		px[i] = px[i-1];		py[i] = py[i-1];	}	points += 1;	if (node==points-2) {		px[node+1] += (px[0]-px[node+1])/2;		py[node+1] += (py[0]-py[node+1])/2;	}	else {		px[node+1] += (px[node+2]-px[node+1])/2;		py[node+1] += (py[node+2]-py[node+1])/2;	}}public void moveTo(int x, int y) {	int dx = x-px[0];	int dy = y-py[0];	for (int i=0;i<points;i++) {		px[i] += dx;		py[i] += dy;	}}public int getResize(int x, int y) {	int i;	for (i=0;i<points;i++) {		if (checkWithin(x,y, px[i]-2, py[i]-2, px[i]+3, py[i]+3)) {			nodeResize = i;			break;		}	}	if (i==points) nodeResize = -1;	return nodeResize;}public boolean resize (int x, int y) {	if (nodeResize>-1) {		px[nodeResize] = x;		py[nodeResize] = y;		return true;	}	else return false;}public void setSelected(boolean b) {	setHighlighted(false);	selected = b;}public boolean isSelected() {	return selected;}public void setHighlighted(boolean b) {	this.highlighted = b;}public boolean isHighlighted() {	return highlighted;}public boolean contains(int x, int y) {	polygon = new Polygon(px,py,points);	return polygon.contains(x,y);}public boolean checkWithin(int x, int y, int x1, int y1, int x2, int y2) {	if (x>=x1 && x<=x2+1 && y>=y1 && y<=y2+1) return true;	else return false;}public int getX() {return px[0];}public int getY() {return py[0];}public int getW() {return w;}public int getH() {return h;}public String getType() {return "poly";}public void setIndex(int i) {	index = i;}public int getIndex() {	return index;}public void setURL(String url) {	this.url = url;}public String getURL() {	return url;}public void setName(String name) {	if (name != getType()+String.valueOf(index)) this.name = name;}public String getName() {	if (name!=null) return name;	else return getType()+String.valueOf(index);}public String getCoords(String type) {	String coords="";	for (int i=0;i<points;i++) {		if (type=="client") coords += ","+String.valueOf(px[i])+","+String.valueOf(py[i]);		else if (type=="server") coords += " "+String.valueOf(px[i])+","+String.valueOf(py[i]);	}	return coords.substring(1);}}

⌨️ 快捷键说明

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