📄 rectangle.java
字号:
/**
* Rectangle.java - rectangle component.
* Mark Bryan Yu
* jimagemapper.sourceforge.net
*
* This file was modified by
* Heiko Schroeder
* wikiimagemapper.sourceforge.net
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package cn.dxm.client;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Random;
public class Rectangle extends Shape {
private java.awt.Rectangle _retangle;
private static java.awt.Rectangle currentRecatangle;
public Rectangle(){
}
public Rectangle(int x, int y, int width, int height) {
this._retangle = new java.awt.Rectangle(x, y, width, height);
}
public Rectangle(int[] coords) {
this._retangle = new java.awt.Rectangle(coords[0], coords[1], coords[2]-coords[0], coords[3]-coords[1]);
}
public void draw(Graphics2D g2d) {
Random r=new Random();
Color color=new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255));
g2d.setColor(color);
g2d.drawRect((int) _retangle.x, (int) _retangle.y, (int) _retangle.width, (int) _retangle.height);
if(active)
drawHighlighted(g2d);
}
public void drawHighlighted(Graphics2D g2d) {
g2d.setColor(new Color(1.0f, 1.0f, 1.0f, 0.15f));
g2d.fillRect((int) _retangle.x+1, (int) _retangle.y+1, (int) _retangle.width-1, (int) _retangle.height-1);
}
public void updateCoordinates(Point layerLocation, Dimension layerSize,Point clickPoint, Point releasePoint)
{
double delta_x = releasePoint.getX()-clickPoint.getX();
double delta_y = releasePoint.getY()-clickPoint.getY();
//移动后的长方形必须限制在图片区域以内.
if((this._retangle.x+(int)delta_x)<layerLocation.x){
delta_x=layerLocation.x-this._retangle.x;
}else if((this._retangle.x+(int)delta_x+this._retangle.width)>layerLocation.x+layerSize.width){
delta_x=layerLocation.x+layerSize.width-this._retangle.x-this._retangle.width;
}
if((this._retangle.y+(int)delta_y)<layerLocation.y){
delta_y=layerLocation.y-this._retangle.y;
}else if((this._retangle.y+(int)delta_y+this._retangle.height)>layerLocation.y+layerSize.height){
delta_y=layerLocation.y+layerSize.height-this._retangle.y-this._retangle.height;
}
this._retangle.translate((int)delta_x,(int)delta_y);
}
public boolean contains(Point p) {
return _retangle.contains(p);
}
public int getX() {
return this._retangle.x;
}
public int getY() {
return this._retangle.y;
}
public int getHeight() {
return this._retangle.height;
}
public int getWidth() {
return this._retangle.width;
}
public java.awt.Rectangle get_retangle() {
return _retangle;
}
public void set_retangle(java.awt.Rectangle _retangle) {
this._retangle = _retangle;
}
public static java.awt.Rectangle getCurrentRecatangle() {
return currentRecatangle;
}
public static void setCurrentRecatangle(java.awt.Rectangle currentRecatangle) {
Rectangle.currentRecatangle = currentRecatangle;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -