下面列出了java.awt.Rectangle#getMaxY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public String valueToString(Object value) throws ParseException {
if (value instanceof Point) {
Point point = (Point) value;
Village v = null;
Rectangle dim = ServerSettings.getSingleton().getMapDimension();
if (point.x >= dim.getMinX() && point.x <= dim.getMaxX()
&& point.y >= dim.getMinY() && point.y <= dim.getMaxY()) {
v = DataHolder.getSingleton().getVillages()[point.x][point.y];
}
if (v == null) {
return "Kein Dorf (" + point.x + "|" + point.y + ")";
} else {
return v.getFullName();
}
} else {
return super.valueToString(value);
}
}
public boolean contains(Rectangle rectangle, int row, int column) {
if (rectangle == null)
return true;
double px = column * (pageWidth + W_SPACE / zoom) * getZoom();
double py = row * (pageHeight + W_SPACE / zoom) * getZoom();
double r = (width + W_SPACE / zoom) * getZoom() + px;
double b = (height + W_SPACE / zoom) * getZoom() + py;
double rx = rectangle.getX();
double ry = rectangle.getY();
double rr = rectangle.getMaxX();
double rb = rectangle.getMaxY();
if (((px <= rr) && (px >= rx)) || ((r <= rr) && (r >= rx))
|| ((rr <= r) && (rr >= px)) || ((rx <= r) && (rx >= px))) {
return (((py <= rb) && (py >= ry)) || ((b <= rb) && (b >= ry))
|| ((rb <= b) && (rb >= py)) || ((ry <= b) && (ry >= py)));
}
return false;
}
/**
*
* @param point
* @param bounds
* @return an int with the appropriate bits set if the Point lies on the corresponding bounds lines
*
*/
public static int check(Point point, Rectangle bounds)
{
int value = 0;
if (point.x == bounds.getMinX())
{
value |= LEFT;
}
if (point.x == bounds.getMaxX())
{
value |= RIGHT;
}
if (point.y == bounds.getMinY())
{
value |= TOP;
}
if (point.y == bounds.getMaxY())
{
value |= BOTTOM;
}
return value;
}
private void firePerformRegionSelectionEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_firePerformRegionSelectionEvent
if (evt.getSource() == jPerformSelection) {
Point start = new Point((Integer) jStartX.getValue(), (Integer) jStartY.getValue());
Point end = new Point((Integer) jEndX.getValue(), (Integer) jEndY.getValue());
Rectangle mapDim = ServerSettings.getSingleton().getMapDimension();
if (start.x < mapDim.getMinX() || start.x > mapDim.getMaxX() || start.y < mapDim.getMinY() || start.y > mapDim.getMaxY()
|| end.x < mapDim.getMinX() || end.x > mapDim.getMaxX() || end.y < mapDim.getMinY() || end.y > mapDim.getMaxY()) {
showError("Ungültiger Start- oder Endpunkt");
} else if ((Math.abs(end.x - start.x) * (end.y - start.y)) > 30000) {
showError("<html>Die angegebene Auswahl könnte mehr als 10.000 Dörfer umfassen.<br/>"
+ "Die Auswahl könnte so sehr lange dauern. Bitte verkleinere den gewählten Bereich.");
} else {
List<Village> selection = DataHolder.getSingleton().getVillagesInRegion(start, end);
addVillages(selection);
}
}
jRegionSelectDialog.setVisible(false);
}
private boolean isFigureCompletelyInView(Figure figure,
JViewport viewport,
OpenTCSDrawingView drawingView) {
Rectangle viewPortBounds = viewport.getViewRect();
Rectangle figureBounds = drawingView.drawingToView(figure.getDrawingArea());
return (figureBounds.getMinX() > viewPortBounds.getMinX())
&& (figureBounds.getMinY() > viewPortBounds.getMinY())
&& (figureBounds.getMaxX() < viewPortBounds.getMaxX())
&& (figureBounds.getMaxY() < viewPortBounds.getMaxY());
}
@Override
public void mouseMoved(MouseEvent e) {
Rectangle selected = this.model.getRectangle();
if(e.getX()>selected.getMaxX()-5 && e.getX()<selected.getMaxX()+5
&& e.getY()>selected.getMaxY()-5
&& e.getY()<selected.getMaxY()+5
){
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
curDir=DIR_SE;
}else if(e.getX()==selected.getMinX() && (e.getY()<selected.getMaxY() && e.getY()>selected.getMinY() )){
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
curDir=DIR_W;
}else if(e.getX()==selected.getMaxX() && (e.getY()<selected.getMaxY() && e.getY()>selected.getMinY() )){
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
curDir=DIR_E;
}
else if(e.getY()<selected.getMaxY()+5 && e.getY()>selected.getMaxY()-5
&& (e.getX()<selected.getMaxX() && e.getX()>selected.getMinX() )){
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
curDir=DIR_S;
}
else if(e.getY()==selected.getMinY() && (e.getX()<selected.getMaxX() && e.getX()>selected.getMinX() )){
curDir=DIR_N;
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
}else if(e.getY()<selected.getCenterY()+10 &&
e.getY()>selected.getCenterY()-10 && (e.getX()<(selected.getCenterX()+10) && e.getX()>selected.getCenterX()-10 )){
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
curDir = MOV;
}
else{
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
curDir=NOP;
}
}
/** Creates a new instance from the given {@link TileOrganizer} result. */
Region(final Tile tile) throws IOException {
final Rectangle r = tile.getAbsoluteRegion(); // In units of the grid having finest resolution.
final Dimension s = tile.getSubsampling();
xmin = r.getMinX();
xmax = r.getMaxX();
ymin = r.getMinY();
ymax = r.getMaxY();
sx = s.width;
sy = s.height;
}
/**
* The bounding box is only valid for a given meshCellSize, i.e. setting it
* independently of the meshCellSize is potentially harmful.
*
* @param box coordinates that define the bounding box for this tile.
*/
public void setBoundingBox(final Rectangle box, final double meshCellSize) {
this.minX = box.getX();
this.minY = box.getY();
this.maxX = box.getMaxX();
this.maxY = box.getMaxY();
this.meshCellSize = meshCellSize;
}
public void drawCollapsedMarker(int x, int y, int width, int height) {
// rectangle
int rectangleWidth = MARKER_WIDTH;
int rectangleHeight = MARKER_WIDTH;
Rectangle rect = new Rectangle(x + (width - rectangleWidth) / 2, y + height - rectangleHeight - 3, rectangleWidth, rectangleHeight);
g.draw(rect);
// plus inside rectangle
Line2D.Double line = new Line2D.Double(rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2);
g.draw(line);
line = new Line2D.Double(rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY());
g.draw(line);
}
/**
* zSetPopupLocation, This calculates and sets the appropriate location for the popup windows,
* for both the DatePicker and the TimePicker.
*/
static void zSetPopupLocation(CustomPopup popup, int defaultX, int defaultY, JComponent picker,
JComponent verticalFlipReference, int verticalFlipDistance, int bottomOverlapAllowed) {
// Gather some variables that we will need.
Window topWindowOrNull = SwingUtilities.getWindowAncestor(picker);
Rectangle workingArea = InternalUtilities.getScreenWorkingArea(topWindowOrNull);
int popupWidth = popup.getBounds().width;
int popupHeight = popup.getBounds().height;
// Calculate the default rectangle for the popup.
Rectangle popupRectangle = new Rectangle(defaultX, defaultY, popupWidth, popupHeight);
// If the popup rectangle is below the bottom of the working area, then move it upwards by
// the minimum amount which will ensure that it will never cover the picker component.
if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
popupRectangle.y = verticalFlipReference.getLocationOnScreen().y - popupHeight
- verticalFlipDistance;
}
// Confine the popup to be within the working area.
if (popupRectangle.getMaxX() > (workingArea.getMaxX())) {
popupRectangle.x -= (popupRectangle.getMaxX() - workingArea.getMaxX());
}
if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
popupRectangle.y -= (popupRectangle.getMaxY() - workingArea.getMaxY());
}
if (popupRectangle.x < workingArea.x) {
popupRectangle.x += (workingArea.x - popupRectangle.x);
}
if (popupRectangle.y < workingArea.y) {
popupRectangle.y += (workingArea.y - popupRectangle.y);
}
// Set the location of the popup.
popup.setLocation(popupRectangle.x, popupRectangle.y);
}
/**
* Start scrolling.
*/
private void scrollNow() {
if (mouseOnScreenPoint != null && target.isShowing()) {
Point origin = target.getLocationOnScreen();
Point relative = new Point(mouseOnScreenPoint.x - origin.x, mouseOnScreenPoint.y - origin.y);
Rectangle visibleRect = target.getVisibleRect();
if (!visibleRect.contains(relative)) {
int destX = relative.x;
if (relative.getX() < visibleRect.getMinX()) {
destX = (int) visibleRect.getMinX() - PAN_STEP_SIZE;
}
if (relative.getX() > visibleRect.getMaxX()) {
destX = (int) visibleRect.getMaxX() + PAN_STEP_SIZE;
}
int destY = relative.y;
if (relative.getY() < visibleRect.getMinY()) {
destY = (int) visibleRect.getMinY() - PAN_STEP_SIZE;
}
if (relative.getY() > visibleRect.getMaxY()) {
destY = (int) visibleRect.getMaxY() + PAN_STEP_SIZE;
}
target.scrollRectToVisible(new Rectangle(new Point(destX, destY)));
}
}
}
public static Village parseFromPlainData(String pLine) {
StringTokenizer tokenizer = new StringTokenizer(pLine, ",");
Village entry = new Village();
if (tokenizer.countTokens() < 7) {
return null;
}
try {
entry.setId(Integer.parseInt(tokenizer.nextToken()));
String n = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
//replace HTML characters
if (n.contains("&")) {
n = n.replaceAll(">", ">").replaceAll("<", "<").replaceAll(""",
"\"").replaceAll("&", "&").replaceAll("˜", "~");
}
entry.setName(n);
entry.setX(Short.parseShort(tokenizer.nextToken()));
entry.setY(Short.parseShort(tokenizer.nextToken()));
entry.setTribeID(Integer.parseInt(tokenizer.nextToken()));
entry.setPoints(Integer.parseInt(tokenizer.nextToken()));
entry.setType(Byte.parseByte(tokenizer.nextToken()));
if (entry.getPoints() < 21) {
//invalid village (event stuff?)
return null;
}
//check if village within coordinate range
Rectangle dim = ServerSettings.getSingleton().getMapDimension();
if (entry.getX() >= dim.getMinX() && entry.getX() <= dim.getMaxX()
&& entry.getY() >= dim.getMinY() && entry.getY() <= dim.getMaxY()) {
return entry;
} else {
logger.warn("Imported village out of Range " + entry.getId() + "/" + entry.getCoordAsString());
return null;
}
} catch (Exception e) { //village invalid
}
return null;
}
private boolean printView(final Graphics2D graphics2D,
final Shape allocation, final View view) {
boolean pageExists = false;
final Rectangle clipRectangle = new Rectangle(0, 0, (int) (pageFormat
.getImageableWidth() / SCALE), (int) clientHeight);
Shape childAllocation;
View childView;
if (view.getViewCount() > 0) {
for (int i = 0; i < view.getViewCount(); i++) {
childAllocation = view.getChildAllocation(i, allocation);
if (childAllocation != null) {
childView = view.getView(i);
if (printView(graphics2D, childAllocation, childView)) {
pageExists = true;
}
}
}
} else {
if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
if (allocation.getBounds().getHeight() > clipRectangle
.getHeight()
&& allocation.intersects(clipRectangle)) {
paintView(graphics2D, view, allocation);
pageExists = true;
} else {
if (allocation.getBounds().getY() >= clipRectangle.getY()) {
if (allocation.getBounds().getMaxY() <= clipRectangle
.getMaxY()) {
paintView(graphics2D, view, allocation);
pageExists = true;
} else {
if (allocation.getBounds().getY() < pageEndY) {
pageEndY = allocation.getBounds().getY();
}
}
}
}
}
}
return pageExists;
}
protected void paintSelectedArrow(Graphics2D g, int labelLeft, int labelRight, int labelTop, int labelBottom) {
if(toRange != null && toRange.first != null) {
Area area = files.getAreaForTokenRange(toRange);
if(area != null) {
Rectangle tokens = area.getBounds();
g.setColor(relationship.getColor(true));
// Outline the tokens
files.outline(g, toRange);
// Get the boundaries of the selection.
int tokenLeft = (int)tokens.getMinX();
int tokenRight = (int) tokens.getMaxX();
int tokenTop = (int) tokens.getMinY();
int tokenBottom = (int) tokens.getMaxY();
int labelX = tokenRight < (labelLeft + labelRight) / 2 ? labelLeft : labelRight;
int labelY = labelBottom - descent;
Line2D line = Util.getLineBetweenRectangleEdges(
labelX, labelX + 1,
labelY, labelY + 1,
tokenLeft, tokenRight,
tokenTop, tokenBottom
);
int xOff = 0;
int yOff = 0;
Util.drawQuadraticCurveArrow(g, (int)line.getX1(), (int)line.getY1(), (int)line.getX2(), (int)line.getY2(), xOff, yOff, true, relationship.getStroke(true));
g.drawLine(labelLeft, labelY, labelRight, labelY);
}
}
}
/**
* Lookup the provided list of interpretations for those whose bounds
* intersect the given area.
*
* @param inters the list of interpretations to search for
* @param order if the list is already sorted by some order, this may speedup the search
* @param area the intersecting area
* @return the intersected interpretations found, perhaps empty but not null
*/
public static List<Inter> intersectedInters (List<Inter> inters,
GeoOrder order,
Area area)
{
List<Inter> found = new ArrayList<>();
Rectangle bounds = area.getBounds();
double xMax = bounds.getMaxX();
double yMax = bounds.getMaxY();
for (Inter inter : inters) {
if (inter.isRemoved()) {
continue;
}
Rectangle iBox = inter.getBounds();
if (area.intersects(iBox)) {
found.add(inter);
} else {
switch (order) {
case BY_ABSCISSA:
if (iBox.x > xMax) {
return found;
}
break;
case BY_ORDINATE:
if (iBox.y > yMax) {
return found;
}
break;
case NONE:
}
}
}
return found;
}
void writeZoneForShape(SebisStringBuilder sb, ITrpShapeType s, String facsId, boolean close) {
String id = facsId+"_"+s.getId();
String zoneStr;
if (pars.boundingBoxCoords) {
Rectangle bb = s.getBoundingBox();
zoneStr = "<zone ulx='"+(int)bb.getX()+"' uly='"+(int)bb.getY()+"' lrx='"+(int)bb.getMaxX()+"' lry='"+(int)bb.getMaxY()+"'";
}
else {
if(StringUtils.isEmpty(s.getCoordinates())) {
logger.error("Coordinates are empty on shape with ID = " + s.getId());
zoneStr = "<zone points=''";
} else {
zoneStr = "<zone points='"+getValidZonePointsString(s.getCoordinates())+"'";
}
}
// write type of shape:
String type = RegionTypeUtil.getRegionType(s);
// if (s instanceof TrpTextRegionType) {
// type = "textregion";
// }
// else if (s instanceof TrpTextLineType) {
// type = "line";
// }
// else if (s instanceof TrpWordType) {
// type = "word";
// }
if (!type.isEmpty()) {
zoneStr += " rendition='"+type+"'";
}
// write struct type:
String struct = s.getStructure();
if (struct!=null && !struct.isEmpty()) {
zoneStr += " subtype='"+struct+"'";
}
zoneStr += " xml:id='"+id+"'";
zoneStr += close ? "/>" : ">";
sb.incIndent();
sb.addLine(zoneStr);
if (close)
sb.decIndent();
}
private Rectangle getBoundingRectWithTranslate(
final List<Polygon> polys, final Dimension mapDimensions) {
Rectangle boundingRect = null;
final int mapWidth = mapDimensions.width;
final int mapHeight = mapDimensions.height;
final int closeToMapWidth = (int) (mapWidth * 0.9);
final int closeToMapHeight = (int) (mapHeight * 0.9);
final boolean scrollWrapX = this.scrollWrapX();
final boolean scrollWrapY = this.scrollWrapY();
for (final Polygon item : polys) {
// if our rectangle is on the right side (mapscrollx) then we push it to be on the negative
// left side, so that the
// bounds.x will be negative
// this solves the issue of maps that have a territory where polygons were on both sides of
// the map divide
// (so our bounds.x was 0, and our bounds.y would be the entire map width)
// (when in fact it should actually be bounds.x = -10 or something, and bounds.width = 20 or
// something)
// we use map dimensions.width * 0.9 because the polygon may not actually touch the side of
// the map (like if the
// territory borders are thick)
final Rectangle itemRect = item.getBounds();
if (scrollWrapX && itemRect.getMaxX() >= closeToMapWidth) {
itemRect.translate(-mapWidth, 0);
}
if (scrollWrapY && itemRect.getMaxY() >= closeToMapHeight) {
itemRect.translate(0, -mapHeight);
}
if (boundingRect == null) {
boundingRect = itemRect;
} else {
boundingRect.add(itemRect);
}
}
// if the polygon is completely negative, we can make translate it back to normal
if (boundingRect.x < 0 && boundingRect.getMaxX() <= 0) {
boundingRect.translate(mapWidth, 0);
}
if (boundingRect.y < 0 && boundingRect.getMaxY() <= 0) {
boundingRect.translate(0, mapHeight);
}
return boundingRect;
}
private boolean printView(Graphics2D graphics2D, Shape allocation,
View view) {
boolean pageExists = false;
Rectangle clipRectangle = graphics2D.getClipBounds();
Shape childAllocation;
View childView;
if (view.getViewCount() > 0) {
for (int i = 0; i < view.getViewCount(); i++) {
childAllocation = view.getChildAllocation(i, allocation);
if (childAllocation != null) {
childView = view.getView(i);
if (printView(graphics2D, childAllocation, childView)) {
pageExists = true;
}
}
}
}
else {
// I
if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
pageExists = true;
// II
if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) &&
(allocation.intersects(clipRectangle))) {
view.paint(graphics2D, allocation);
}
else {
// III
if (allocation.getBounds().getY() >= clipRectangle.getY()) {
if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
view.paint(graphics2D, allocation);
}
else {
// IV
if (allocation.getBounds().getY() < pageEndY) {
pageEndY = allocation.getBounds().getY();
}
}
}
}
}
}
return pageExists;
}
protected void paintComponent(Graphics g) {
long startTime = System.nanoTime();
// prevVX is set to -10000 when first enabled
if (useCopyArea && prevVX > -9999) {
// Most of this code determines the proper areas to copy and clip
int scrollX = viewX - prevVX;
int scrollY = viewY - prevVY;
int copyFromY, copyFromX;
int clipFromY, clipFromX;
if (scrollX == 0) {
// vertical scroll
if (scrollY < 0) {
copyFromY = 0;
clipFromY = 0;
} else {
copyFromY = scrollY;
clipFromY = getHeight() - scrollY;
}
// copy the old content, set the clip to the new area
g.copyArea(0, copyFromY, getWidth(), getHeight() - Math.abs(scrollY),
0, -scrollY);
g.setClip(0, clipFromY, getWidth(), Math.abs(scrollY));
} else {
// horizontal scroll
if (scrollX < 0) {
copyFromX = 0;
clipFromX = 0;
} else {
copyFromX = scrollX;
clipFromX = getWidth() - scrollX;
}
// copy the old content, set the clip to the new area
g.copyArea(copyFromX, 0, getWidth() - Math.abs(scrollX),
getHeight(), -scrollX, 0);
g.setClip(clipFromX, 0, Math.abs(scrollX), getHeight());
}
}
// Track previous view position for next scrolling operation
prevVX = viewX;
prevVY = viewY;
// Get the clip in case we need it later
Rectangle clipRect = g.getClip().getBounds();
int clipL = (int)(clipRect.getX());
int clipT = (int)(clipRect.getY());
int clipR = (int)(clipRect.getMaxX());
int clipB = (int)(clipRect.getMaxY());
g.setColor(Color.WHITE);
g.fillRect(clipL, clipT, (int)clipRect.getWidth(), (int)clipRect.getHeight());
for (int column = 0; column < 256; ++column) {
int x = column * (SMILEY_SIZE + PADDING) - viewX;
if (useClip) {
if (x > clipR || (x + (SMILEY_SIZE + PADDING)) < clipL) {
// trivial reject; outside to the left or right
continue;
}
}
for (int row = 0; row < 256; ++row) {
int y = row * (SMILEY_SIZE + PADDING) - viewY;
if (useClip) {
if (y > clipB || (y + (SMILEY_SIZE + PADDING)) < clipT) {
// trivial reject; outside to the top or bottom
continue;
}
}
Color faceColor = new Color(column, row, 0);
drawSmiley(g, faceColor, x, y);
}
}
long stopTime = System.nanoTime();
System.out.println("Painted in " +
((stopTime - startTime) / 1000000) + " ms");
}
public Dimension getPreferredSize() {
final Rectangle bounds = shape.getBounds();
return new Dimension( (int) bounds.getMaxX(), (int) bounds.getMaxY() );
}