Java Code Examples for java.awt.Rectangle#getMinX()

The following examples show how to use java.awt.Rectangle#getMinX() . These examples are extracted from open source projects. 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
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&ouml;nnte mehr als 10.000 D&ouml;rfer umfassen.<br/>"
                    + "Die Auswahl k&ouml;nnte so sehr lange dauern. Bitte verkleinere den gew&auml;hlten Bereich.");
        } else {
            List<Village> selection = DataHolder.getSingleton().getVillagesInRegion(start, end);
            addVillages(selection);
        }
    }

    jRegionSelectDialog.setVisible(false);
}
 
Example 2
Source Project: dsworkbench   File: CoordinateFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: TFC2   File: BoundsCheck.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @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 4
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 5
Source Project: openAGV   File: ViewDragScrollListener.java    License: Apache License 2.0 5 votes vote down vote up
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 6
Source Project: niftyeditor   File: ImageModeCanvas.java    License: Apache License 2.0 5 votes vote down vote up
@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 7
Source Project: GVGAI_GYM   File: ContinuousPhysics.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 8
Source Project: sis   File: DatumShiftGridGroup.java    License: Apache License 2.0 5 votes vote down vote up
/** 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 9
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 10
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 11
Source Project: chipster   File: SelectableChartPanel.java    License: MIT License 5 votes vote down vote up
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 12
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 13
Source Project: dsworkbench   File: FarmManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 14
Source Project: dsworkbench   File: FarmManager.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: logbook-kai   File: CaptureController.java    License: MIT License 5 votes vote down vote up
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 16
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 17
Source Project: SikuliX1   File: SxBeam.java    License: MIT License 4 votes vote down vote up
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);


}
 
Example 18
Source Project: whyline   File: FileControlArrow.java    License: MIT License 4 votes vote down vote up
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 19
Source Project: niftyeditor   File: ImageModeCanvas.java    License: Apache License 2.0 4 votes vote down vote up
@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 20
Source Project: megamek   File: ClientGUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}