Java Code Examples for java.awt.Rectangle#getMinX()
The following examples show how to use
java.awt.Rectangle#getMinX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmsMapcalc.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private static CoordinateTransform getTransform( Rectangle2D worldBounds, Rectangle imageBounds ) { if (worldBounds == null || worldBounds.isEmpty()) { throw new IllegalArgumentException("worldBounds must not be null or empty"); } if (imageBounds == null || imageBounds.isEmpty()) { throw new IllegalArgumentException("imageBounds must not be null or empty"); } double xscale = (imageBounds.getMaxX() - imageBounds.getMinX()) / (worldBounds.getMaxX() - worldBounds.getMinX()); double xoff = imageBounds.getMinX() - xscale * worldBounds.getMinX(); double yscale = (imageBounds.getMaxY() - imageBounds.getMinY()) / (worldBounds.getMaxY() - worldBounds.getMinY()); double yoff = imageBounds.getMinY() - yscale * worldBounds.getMinY(); return new AffineCoordinateTransform(new AffineTransform(xscale, 0, 0, yscale, xoff, yoff)); }
Example 2
Source File: BoundsCheck.java From TFC2 with GNU General Public License v3.0 | 6 votes |
/** * * @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; }
Example 3
Source File: CoordinateFormatter.java From dsworkbench with Apache License 2.0 | 6 votes |
@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); } }
Example 4
Source File: DSWorkbenchSelectionFrame.java From dsworkbench with Apache License 2.0 | 6 votes |
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); }
Example 5
Source File: SelectableChartPanel.java From chipster with MIT License | 5 votes |
public Rectangle.Double translateToChart(Rectangle mouseCoords){ //Screen coordinates are integers Point corner1 = new Point((int)mouseCoords.getMinX(), (int)mouseCoords.getMinY()); Point corner2 = new Point((int)mouseCoords.getMaxX(), (int)mouseCoords.getMaxY()); Point.Double translated1 = translateToChart(corner1); Point.Double translated2 = translateToChart(corner2); return createOrderedRectangle(translated1, translated2); }
Example 6
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
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); }
Example 7
Source File: CaptureController.java From logbook-kai with MIT License | 5 votes |
private void setBounds(Robot robot, Rectangle fixed) { String text = "(" + (int) fixed.getMinX() + "," + (int) fixed.getMinY() + ")"; this.message.setText(text); this.capture.setDisable(false); this.config.setDisable(false); this.sc = new ScreenCapture(robot, fixed); this.sc.setItems(this.images); this.sc.setCurrent(this.preview); }
Example 8
Source File: FarmManager.java From dsworkbench with Apache License 2.0 | 5 votes |
public int findFarmsFromBarbarians(Point pCenter, int pRadius) { int addCount = 0; invalidate(); Ellipse2D.Double e = new Ellipse2D.Double(pCenter.x - pRadius, pCenter.y - pRadius, 2 * pRadius, 2 * pRadius); Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); for (int i = pCenter.x - pRadius; i < pCenter.x + pRadius; i++) { for (int j = pCenter.y - pRadius; j < pCenter.y + pRadius; j++) { if (i >= mapDim.getMinX() && i <= mapDim.getMaxX() && j >= mapDim.getMinY() && j <= mapDim.getMaxY()) { if (e.contains(new Point2D.Double(i, j))) { Village v = DataHolder.getSingleton().getVillages()[i][j]; if (v != null && v.getTribe().equals(Barbarians.getSingleton())) { FarmInformation info = addFarm(v); if (info.getLastReport() < 0) { FightReport r = ReportManager.getSingleton().findLastReportForSource(v); if (r != null) { info.updateFromReport(r); } else { info.setInitialResources(); } addCount++; } } } } } } revalidate(true); return addCount; }
Example 9
Source File: FarmManager.java From dsworkbench with Apache License 2.0 | 5 votes |
/** * Find barbarians in radius around all own villages */ public int findFarmsFromBarbarians(int pRadius) { int addCount = 0; invalidate(); for (Village v : GlobalOptions.getSelectedProfile().getTribe().getVillageList()) { Ellipse2D.Double e = new Ellipse2D.Double((int) v.getX() - pRadius, (int) v.getY() - pRadius, 2 * pRadius, 2 * pRadius); Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); for (int x = (int) v.getX() - pRadius; x < (int) v.getX() + pRadius; x++) { for (int y = (int) v.getY() - pRadius; y < (int) v.getY() + pRadius; y++) { if (x >= mapDim.getMinX() && x <= mapDim.getMaxX() && y >= mapDim.getMinY() && y <= mapDim.getMaxY()) { if (e.contains(new Point2D.Double(x, y))) { Village farm = DataHolder.getSingleton().getVillages()[x][y]; if (farm != null && farm.getTribe().equals(Barbarians.getSingleton())) { FarmInformation info = addFarm(farm); if (info.getLastReport() < 0) { FightReport r = ReportManager.getSingleton().findLastReportForSource(farm); if (r != null) { info.updateFromReport(r); } else { info.setInitialResources(); } addCount++; } } } } } } } revalidate(true); return addCount; }
Example 10
Source File: DSWorkbenchMainFrame.java From dsworkbench with Apache License 2.0 | 5 votes |
private void refreshMap() { //ensure that within map range Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); if(dCenterX < mapDim.getMinX() || dCenterX > mapDim.getMaxX() || dCenterY < mapDim.getMinY() || dCenterY > mapDim.getMaxX()) { //find out where we tried to leaf map and set these valuese to max / min if(dCenterX < mapDim.getMinX()) { dCenterX = (int) mapDim.getMinX(); jCenterX.setText(Integer.toString((int) dCenterX)); } else if(dCenterX > mapDim.getMaxX()) { dCenterX = (int) mapDim.getMaxX(); jCenterX.setText(Integer.toString((int) dCenterX)); } if(dCenterY < mapDim.getMinY()) { dCenterY = (int) mapDim.getMinY(); jCenterY.setText(Integer.toString((int) dCenterY)); } else if(dCenterY > mapDim.getMaxX()) { dCenterY = (int) mapDim.getMaxX(); jCenterY.setText(Integer.toString((int) dCenterY)); } } double w = (double) MapPanel.getSingleton().getWidth() / GlobalOptions.getSkin().getBasicFieldWidth() * dZoomFactor; double h = (double) MapPanel.getSingleton().getHeight() / GlobalOptions.getSkin().getBasicFieldHeight() * dZoomFactor; MinimapPanel.getSingleton().setSelection((int) Math.floor(dCenterX), (int) Math.floor(dCenterY), (int) Math.rint(w), (int) Math.rint(h)); MapPanel.getSingleton().updateMapPosition(dCenterX, dCenterY, true); }
Example 11
Source File: ViewDragScrollListener.java From openAGV with Apache License 2.0 | 5 votes |
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()); }
Example 12
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
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); }
Example 13
Source File: DefaultProcessDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
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); }
Example 14
Source File: DatumShiftGridGroup.java From sis with Apache License 2.0 | 5 votes |
/** 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; }
Example 15
Source File: ContinuousPhysics.java From GVGAI_GYM with Apache License 2.0 | 5 votes |
/** * Euclidean distance between two rectangles. * @param r1 rectangle 1 * @param r2 rectangle 2 * @return Euclidean distance between the top-left corner of the rectangles. */ public double distance(Rectangle r1, Rectangle r2) { double topDiff = r1.getMinY() - r2.getMinY(); double leftDiff = r1.getMinX() - r2.getMinX(); return Math.sqrt(topDiff*topDiff + leftDiff*leftDiff); }
Example 16
Source File: ImageModeCanvas.java From niftyeditor with Apache License 2.0 | 5 votes |
@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; } }
Example 17
Source File: ClientGUI.java From megamek with GNU General Public License v2.0 | 4 votes |
/** * Initializes a number of things about this frame. */ private void initializeFrame() { frame = new JFrame(Messages.getString("ClientGUI.title")); //$NON-NLS-1$ menuBar.setGame(client.getGame()); frame.setJMenuBar(menuBar); Rectangle virtualBounds = getVirtualBounds(); if (GUIPreferences.getInstance().getWindowSizeHeight() != 0) { int x = GUIPreferences.getInstance().getWindowPosX(); int y = GUIPreferences.getInstance().getWindowPosY(); int w = GUIPreferences.getInstance().getWindowSizeWidth(); int h = GUIPreferences.getInstance().getWindowSizeHeight(); if ((x < virtualBounds.getMinX()) || ((x + w) > virtualBounds.getMaxX())) { x = 0; } if ((y < virtualBounds.getMinY()) || ((y + h) > virtualBounds.getMaxY())) { y = 0; } if (w > virtualBounds.getWidth()) { w = (int) virtualBounds.getWidth(); } if (h > virtualBounds.getHeight()) { h = (int) virtualBounds.getHeight(); } frame.setLocation(x, y); frame.setSize(w, h); } else { frame.setSize(800, 600); } frame.setMinimumSize(new Dimension(640,480)); frame.setBackground(SystemColor.menu); frame.setForeground(SystemColor.menuText); List<Image> iconList = new ArrayList<>(); iconList.add(frame.getToolkit().getImage( new MegaMekFile(Configuration.miscImagesDir(), FILENAME_ICON_16X16).toString() )); iconList.add(frame.getToolkit().getImage( new MegaMekFile(Configuration.miscImagesDir(), FILENAME_ICON_32X32).toString() )); iconList.add(frame.getToolkit().getImage( new MegaMekFile(Configuration.miscImagesDir(), FILENAME_ICON_48X48).toString() )); iconList.add(frame.getToolkit().getImage( new MegaMekFile(Configuration.miscImagesDir(), FILENAME_ICON_256X256).toString() )); frame.setIconImages(iconList); }
Example 18
Source File: ImageModeCanvas.java From niftyeditor with Apache License 2.0 | 4 votes |
@Override public void mouseDragged(MouseEvent e) { Rectangle selected = this.model.getRectangle(); int to; switch (curDir) { case DIR_E: to = (int) (e.getX() - selected.getMaxX()); if ((selected.width + to) > 0) { selected.width += to; } break; case DIR_W: to = (int) (selected.getMinX() - e.getX()); if ((selected.width + to) > 0) { selected.x = e.getX(); selected.width += to; } break; case DIR_S: to = (int) (e.getY() - selected.getMaxY()); if ((selected.height + to) > 0) { selected.height += to; } break; case DIR_SE: to = (int) (e.getX() - selected.getMaxX()); int toy = (int) (e.getY() - selected.getMaxY()); if (((selected.width + to) > 0) && (selected.height + to) > 0) { if (e.isControlDown()) { selected.height += to; } else { selected.height += toy; } selected.width += to; } break; case DIR_N: to = (int) (selected.getMinY() - e.getY()); if ((selected.height + to) > 0) { selected.height += to; selected.y = e.getY(); } break; case MOV: selected.x = e.getX() - selected.width/2; selected.y = e.getY() - selected.height/2; break; default: } updateUI(); }
Example 19
Source File: FileControlArrow.java From whyline with MIT License | 4 votes |
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); } } }
Example 20
Source File: SxBeam.java From SikuliX1 with MIT License | 4 votes |
public void drawRayPolygon1(Graphics g, Point p, Rectangle rect) { if (p == null || rect == null) { return; } Graphics2D g2d = (Graphics2D) g; Rectangle r = rect; // corners of the target rectangle int cxs[] = {r.x, r.x, r.x + r.width, r.x + r.width}; int cys[] = {r.y, r.y + r.height, r.y + r.height, r.height}; ArrayList<Point> corners = new ArrayList<Point>(); corners.add(new Point(r.x, r.y)); corners.add(new Point(r.x + r.width, r.y + r.height)); corners.add(new Point(r.x + r.width, r.y)); corners.add(new Point(r.x, r.y + r.height)); Collections.sort(corners, new Comparator() { @Override public int compare(Object arg0, Object arg1) { return (int) (current.distance((Point) arg0) - current.distance((Point) arg1)); } }); int[] xs; int[] ys; int d = 5; if (p.x > rect.getMinX() - 5 && p.x < rect.getMaxX() + 5 || p.y > rect.getMinY() - 5 && p.y < rect.getMaxY() + 5) { xs = new int[3]; ys = new int[3]; xs[0] = (int) p.x; xs[1] = (int) corners.get(0).x; xs[2] = (int) corners.get(1).x; ys[0] = (int) p.y; ys[1] = (int) corners.get(0).y; ys[2] = (int) corners.get(1).y; } else { xs = new int[4]; ys = new int[4]; xs[0] = (int) p.x; xs[1] = (int) corners.get(2).x; xs[2] = (int) corners.get(0).x; xs[3] = (int) corners.get(1).x; ys[0] = (int) p.y; ys[1] = (int) corners.get(2).y; ys[2] = (int) corners.get(0).y; ys[3] = (int) corners.get(1).y; } Polygon shape = new Polygon(xs, ys, xs.length); Stroke pen = new BasicStroke(3.0F); g2d.setStroke(pen); g2d.setColor(Color.black); //g2d.drawPolygon(pointing_triangle); //g2d.drawRect(x,y,w,h); g2d.setColor(Color.red); g2d.fillPolygon(shape); g2d.drawRect(rect.x, rect.y, rect.width, rect.height); }