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

The following are Jave code examples for showing how to use getMinX() of the java.awt.Rectangle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jmt   File: JmtEdge.java   View Source Code Vote up 6 votes
public int getOffset() {
	JmtCell sourceOfEdge = (JmtCell) ((DefaultPort) this.getSource()).getParent();
	Rectangle boundsSource = GraphConstants.getBounds(sourceOfEdge.getAttributes()).getBounds();
	JmtCell targetOfEdge = (JmtCell) ((DefaultPort) this.getTarget()).getParent();
	Rectangle boundsTarget = GraphConstants.getBounds(targetOfEdge.getAttributes()).getBounds();
	GraphModel graphmodel = mediator.getGraph().getModel();
	Object[] fathers = (DefaultGraphModel.getIncomingEdges(graphmodel, targetOfEdge));
	int max = (int) boundsSource.getMaxX();
	for (Object father : fathers) {
		if (father instanceof JmtEdge) {
			JmtCell sourceOfEdge2 = (JmtCell) ((DefaultPort) ((JmtEdge) father).getSource()).getParent();
			Rectangle boundsSource2 = GraphConstants.getBounds(sourceOfEdge2.getAttributes()).getBounds();
			if (sourceOfEdge != sourceOfEdge2 && boundsSource.getMaxX() < boundsTarget.getMinX() - 5
					&& boundsSource2.getMaxX() < boundsTarget.getMinX() - 5) {
				if (max < boundsSource2.getMaxX() && (int) boundsSource.getMaxX() > (int) boundsSource2.getMinX()) {
					max = (int) boundsSource2.getMaxX();
				}
			}
		}
	}
	return (int) (max - boundsSource.getMaxX());
}
 
Example 2
Project: sumo   File: MaskGeometries.java   View Source Code Vote up 6 votes
/**
 * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
 */
public BufferedImage rasterize(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {

	// create the buffered image of the size of the Rectangle
    BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
    GeometryFactory gf = new GeometryFactory();

    // define the clipping region in full scale
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};

    Polygon geom = gf.createPolygon(gf.createLinearRing(coords));

    Graphics g2d = image.getGraphics();

    g2d.setColor(Color.white);
    for (Geometry p : maskGeometries) {
    	/*if(p instanceof MultiPolygon){
    		p=p.getBoundary();
    	}*/
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];//build array for x coordinates
            int[] yPoints = new int[p.getNumPoints()];//build array for y coordinates
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) ((c.x + offsetX ) * scalingFactor);
                yPoints[i] = (int) ((c.y + offsetY ) * scalingFactor);
                i++;
            }
            g2d.fillPolygon(xPoints, yPoints, i);
        }
    }
    g2d.dispose();
    return image;

}
 
Example 3
Project: sumo   File: InterpolatedVectorLayer.java   View Source Code Vote up 6 votes
public Area getShape() {
    Area maskArea = new Area();
    Rectangle rect = new Rectangle(0, 0, reader.getWidth(), reader.getHeight());
    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
    };
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) (c.x);
                yPoints[i++] = (int) (c.y);
            }
            maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
        }
    }
    return maskArea;
}
 
Example 4
Project: QN-ACTR-Release   File: JmtEdge.java   View Source Code Vote up 6 votes
public int getOffset() {
	JmtCell sourceOfEdge = (JmtCell) ((DefaultPort) this.getSource()).getParent();
	Rectangle boundsSource = GraphConstants.getBounds(sourceOfEdge.getAttributes()).getBounds();
	JmtCell targetOfEdge = (JmtCell) ((DefaultPort) this.getTarget()).getParent();
	Rectangle boundsTarget = GraphConstants.getBounds(targetOfEdge.getAttributes()).getBounds();
	Object[] listEdges = null;
	GraphModel graphmodel = mediator.getGraph().getModel();
	//		System.out.println("Padre: "+targetOfEdge);
	Object[] fathers = (DefaultGraphModel.getIncomingEdges(graphmodel, targetOfEdge));
	int max = (int) boundsSource.getMaxX();
	for (Object father : fathers) {
		//			System.out.println("Dentro il for");
		if (father instanceof JmtEdge) {
			JmtCell sourceOfEdge2 = (JmtCell) ((DefaultPort) ((JmtEdge) father).getSource()).getParent();
			Rectangle boundsSource2 = GraphConstants.getBounds(sourceOfEdge2.getAttributes()).getBounds();
			if (sourceOfEdge != sourceOfEdge2 && boundsSource.getMaxX() < boundsTarget.getMinX() - 5
					&& boundsSource2.getMaxX() < boundsTarget.getMinX() - 5) {
				if (max < boundsSource2.getMaxX() && (int) boundsSource.getMaxX() > (int) boundsSource2.getMinX()) {
					max = (int) boundsSource2.getMaxX();
				}
			}
		}
	}
	return (int) (max - boundsSource.getMaxX());
}
 
Example 5
Project: rapidminer   File: PanningManager.java   View Source Code Vote up 5 votes
/**
 * 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)));
		}
	}
}
 
Example 6
Project: sumo   File: MaskGeometries.java   View Source Code Vote up 5 votes
/**
 * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
 */
public BufferedImage rasterizeJTS(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {

	// create the buffered image of the size of the Rectangle
    BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
    GeometryFactory gf = new GeometryFactory();

    // define the clipping region in full scale
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};

    Polygon geom = gf.createPolygon(gf.createLinearRing(coords));

    for (Geometry p : maskGeometries) {
        if (p.intersects(geom)) {
        	Geometry pg=p.intersection(geom).buffer(0);
        	//Coordinate[] coordsInter=gg.getCoordinates();
        	//Polygon pg=gf.createPolygon(coordsInter);

        	for(int x=0;x<rect.width;x++){
        		for(int y=0;y<rect.height;y++){
        			Point point=gf.createPoint(new Coordinate(rect.x+x,rect.y+y));
        			if(pg.contains(point)){
          		try{
          			image.setRGB(x,y, Color.WHITE.getRGB());
          		}catch(Exception e){
          			logger.error(e.getMessage()+"  x:"+x+"  y:"+y);
          		}
        			}
         	}
         }
     }
    }
    return image;

}
 
Example 7
Project: sumo   File: MaskVectorLayer.java   View Source Code Vote up 5 votes
public Area getShape(int width, int height) {
    Area maskArea = new Area();

    Rectangle rect = new Rectangle(0, 0, width,height);//reader.getWidth(), reader.getHeight());

    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),};
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) (c.x);
                yPoints[i++] = (int) (c.y);
            }
            maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
        }
    }
    return maskArea;
}
 
Example 8
Project: sumo   File: InterpolatedVectorLayer.java   View Source Code Vote up 5 votes
public BufferedImage rasterize(BufferedImage image, int offsetX, int offsetY, double scalingFactor) {
    Rectangle rect = image.getRaster().getBounds();
    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
    };
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    Graphics g2d = image.getGraphics();
    g2d.setColor(Color.WHITE);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) ((c.x - offsetX) * scalingFactor);
                yPoints[i++] = (int) ((c.y - offsetY) * scalingFactor);
            }
            g2d.fillPolygon(xPoints, yPoints, p.getNumPoints());
        }
    }
    g2d.dispose();
    return image;
}
 
Example 9
Project: sumo   File: MaskGeometries.java   View Source Code Vote up 4 votes
/**
 * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
 */
public int[] rasterMaskJTS(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {

	// create the buffered image of the size of the Rectangle
    int[] mask = new int[rect.width* rect.height];
    GeometryFactory gf = new GeometryFactory();

    // define the clipping region in full scale
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};

    Polygon geom = gf.createPolygon(gf.createLinearRing(coords));
    PreparedPolygon ppol=new PreparedPolygon(geom);

    int numPix=rect.width*rect.height;
    for (Geometry p : maskGeometries) {
        if (ppol.intersects(p)) {
        	Geometry pg=p.intersection(geom).buffer(0);
        	IndexedPointInAreaLocator locator=new IndexedPointInAreaLocator(pg);


        	int x=0;
        	int y=0;

        	for(int ii=0;ii<numPix;ii++){
        		if(ii%rect.width==0){
        			x=0;
        			y++;
        		}
    			//Point point=gf.createPoint(new Coordinate(rect.x+x,rect.y+y));
    			//PreparedPoint ppoint=new PreparedPoint(point);
    			//if(ppoint.within(pg)){
        		int loc=locator.locate(new Coordinate(rect.x+x,rect.y+y));
        		if(loc==Location.INTERIOR||loc==Location.BOUNDARY)
         		try{
         			mask[x]=1;
         		}catch(Exception e){
         			logger.warn(e.getMessage()+"  x:"+x+"  y:"+y);
         		}
    			}
         }
     //}
    }
    return mask;

}