Java Code Examples for java.awt.Rectangle

The following examples show how to use java.awt.Rectangle. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: magarena   Source File: CardFlowPanel.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void drawActiveImage(final Graphics2D g2d, final int activeSlotIndex) {

        final Rectangle startRect = flowDirection == FlowDirection.RIGHT
                ? slots.get(activeSlotIndex - 1)
                : slots.get(activeSlotIndex + 1);

        final Rectangle endRect = slots.get(activeSlotIndex);

        final int adjX = (int)((startRect.x - endRect.x) * timelinePulse);
        final int adjX2 = (int)(getBellShapedFunctionB(timelinePulse));

        final Rectangle imageRect = new Rectangle(
                (startRect.x - adjX) + (flowDirection == FlowDirection.LEFT ? adjX2 : -adjX2),
                0,
                startRect.width + (int) ((endRect.width - startRect.width) * timelinePulse),
                startRect.height + (int) ((endRect.height - startRect.height) * timelinePulse)
        );

        BufferedImage image = ImageHelper.scale(
            getImage(activeImageIndex), imageRect.width, imageRect.height
        );
        g2d.drawImage(image, imageRect.x, imageRect.y, null);

    }
 
Example 2
Source Project: iBioSim   Source File: CloseTabPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
public void scrollForward(int tabPlacement) {
	Dimension viewSize = viewport.getViewSize();
	Rectangle viewRect = viewport.getViewRect();

	if (tabPlacement == TOP || tabPlacement == BOTTOM) {
		if (viewRect.width >= viewSize.width - viewRect.x) {
			return; // no room left to scroll
		}
	}
	else { // tabPlacement == LEFT || tabPlacement == RIGHT
		if (viewRect.height >= viewSize.height - viewRect.y) {
			return;
		}
	}
	setLeadingTabIndex(leadingTabIndex + 1);
}
 
Example 3
Source Project: jdk8u_jdk   Source File: XComponentPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void coalescePaintEvent(PaintEvent e) {
    Rectangle r = e.getUpdateRect();
    if (!(e instanceof IgnorePaintEvent)) {
        paintArea.add(r, e.getID());
    }
    if (true) {
        switch(e.getID()) {
          case PaintEvent.UPDATE:
              if (log.isLoggable(PlatformLogger.Level.FINER)) {
                  log.finer("XCP coalescePaintEvent : UPDATE : add : x = " +
                        r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
              }
              return;
          case PaintEvent.PAINT:
              if (log.isLoggable(PlatformLogger.Level.FINER)) {
                  log.finer("XCP coalescePaintEvent : PAINT : add : x = " +
                        r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
              }
              return;
        }
    }
}
 
Example 4
Source Project: magarena   Source File: OracleText.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static SortedMap<Float, TextLayout> fitTextLayout(
    AttributedString attrString,
    Font font,
    FontRenderContext frc,
    Rectangle box,
    int leftPadding,
    int topPadding
) {
    // decrease font by 0.5 points each time until lines can fit
    SortedMap<Float, TextLayout> lines = new TreeMap<>();
    Font f = font;
    while (lines.isEmpty()) {
        attrString.addAttribute(TextAttribute.FONT, f);
        lines = tryTextLayout(attrString, frc, box, leftPadding, topPadding);
        f = f.deriveFont(f.getSize2D() - 0.5f);
    }
    return lines;
}
 
Example 5
Source Project: jdk8u-jdk   Source File: SynthTableUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Rectangle extendRect(Rectangle rect, boolean horizontal) {
    if (rect == null) {
        return rect;
    }

    if (horizontal) {
        rect.x = 0;
        rect.width = table.getWidth();
    } else {
        rect.y = 0;

        if (table.getRowCount() != 0) {
            Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true);
            rect.height = lastRect.y + lastRect.height;
        } else {
            rect.height = table.getHeight();
        }
    }

    return rect;
}
 
Example 6
Source Project: TencentKona-8   Source File: BlockWidget.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void paintWidget() {
    super.paintWidget();
    Graphics2D g = this.getGraphics();
    Stroke old = g.getStroke();
    g.setColor(Color.BLUE);
    Rectangle r = new Rectangle(this.getPreferredBounds());
    r.width--;
    r.height--;
    if (this.getBounds().width > 0 && this.getBounds().height > 0) {
        g.setStroke(new BasicStroke(2));
        g.drawRect(r.x, r.y, r.width, r.height);
    }

    Color titleColor = Color.BLACK;
    g.setColor(titleColor);
    g.setFont(titleFont);

    String s = "B" + blockNode.toString();
    Rectangle2D r1 = g.getFontMetrics().getStringBounds(s, g);
    g.drawString(s, r.x + 5, r.y + (int) r1.getHeight());
    g.setStroke(old);
}
 
Example 7
Source Project: dragonwell8_jdk   Source File: MotifBorders.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Draws the FrameBorder's left border.
  */
protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
                       int width, int height) {
    Rectangle borderRect =
        new Rectangle(0, 0, getBorderInsets(c).left, height);
    if (!g.getClipBounds().intersects(borderRect)) {
        return false;
    }

    int startY = BORDER_SIZE;

    g.setColor(frameHighlight);
    g.drawLine(x, startY, x, height - 1);
    g.drawLine(x + 1, startY, x + 1, height - 2);

    g.setColor(frameColor);
    g.fillRect(x + 2, startY, x + 2, height - 3);

    g.setColor(frameShadow);
    g.drawLine(x + 4, startY, x + 4, height - 5);

    return true;
}
 
Example 8
Source Project: netbeans   Source File: NbToolTip.java    License: Apache License 2.0 6 votes vote down vote up
private static int getOffsetForPoint(Point p, JTextComponent c, BaseDocument doc) throws BadLocationException {
    if (p.x >= 0 && p.y >= 0) {
        int offset = c.viewToModel(p);
        Rectangle r = c.modelToView(offset);
        EditorUI eui = Utilities.getEditorUI(c);

        // Check that p is on a line with text and not completely below text,
        // ie. behind EOF.
        int relY = p.y - r.y;
        if (eui != null && relY < eui.getLineHeight()) {
            // Check that p is on a line with text before its EOL.
            if (offset < Utilities.getRowEnd(doc, offset)) {
                return offset;
            }
        }
    }
    
    return -1;
}
 
Example 9
Source Project: Pixie   Source File: ResultPanel.java    License: MIT License 6 votes vote down vote up
/**
 * Merges the given object map in the image object map, at the specified
 * coordinates.
 *
 * @param newObjMap - the object map that has to be merged in the result map
 * @param pos       - the position where the image has to be copied: info x - the top-left X coordinate where the image has to be copied info; y - the top-left Y coordinate where the image has to be copied info; width - the width of the image to be copied info; height - the height of the image to be copied
 * @param objId     - the object id as byte value (it is obtained by computing the image object id % 255)
 * @param mergeBkg  - true if both the background and object have to overwrite the existent content of the object map; false if only the object should be merged
 */
public void mergeCrop(byte[][] newObjMap, Rectangle pos, long objId, boolean mergeBkg) {
    byte mapId = getByteObjId(objId);

    // update objectMap
    for (int y = 0; y < pos.getHeight(); y++) {
        for (int x = 0; x < pos.getWidth(); x++) {

            if (mergeBkg) {
                // merge bakground in object map (overwrites the initial byte, no matter what was storred, with bkg)
                objMap[x + pos.x][y + pos.y] = (newObjMap[x][y] > 0) ? mapId : (byte) 0;

            } else {
                // merge just the pure object - when the pixel in the  object map is != 0
                objMap[x + pos.x][y + pos.y] = ((objMap[x + pos.x][y + pos.y] == mapId) && (newObjMap[x][y] == 0)) ? 0 : objMap[x + pos.x][y + pos.y];
                objMap[x + pos.x][y + pos.y] = (newObjMap[x][y] > 0) ? mapId : objMap[x + pos.x][y + pos.y];
            }
        }
    }
}
 
Example 10
Source Project: jdk8u_jdk   Source File: SunGraphics2D.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Intersects <code>destRect</code> with <code>clip</code> and
 * overwrites <code>destRect</code> with the result.
 * Returns false if the intersection was empty, true otherwise.
 */
private boolean clipTo(Rectangle destRect, Rectangle clip) {
    int x1 = Math.max(destRect.x, clip.x);
    int x2 = Math.min(destRect.x + destRect.width, clip.x + clip.width);
    int y1 = Math.max(destRect.y, clip.y);
    int y2 = Math.min(destRect.y + destRect.height, clip.y + clip.height);
    if (((x2 - x1) < 0) || ((y2 - y1) < 0)) {
        destRect.width = -1; // Set both just to be safe
        destRect.height = -1;
        return false;
    } else {
        destRect.x = x1;
        destRect.y = y1;
        destRect.width = x2 - x1;
        destRect.height = y2 - y1;
        return true;
    }
}
 
Example 11
Source Project: brModelo   Source File: baseDrawerItem.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void DrawImagem(Graphics2D g) {
    BufferedImage img = getImagem();
    if (img == null) {
        return;
    }
    int[] pts = ArrayDePontos(getPosiImagem());
    if (pts.length != 4) {
        posiImagem = "L,T,200,200";
        imgres = null;
        pts = ArrayDePontos(getPosiImagem());
    }
    Rectangle rec = new Rectangle(pts[0], pts[1], pts[2], pts[3]);
    rec.grow(-2, -2);
    if (imgres == null) {
        imgres = img.getScaledInstance(rec.width, rec.height, Image.SCALE_SMOOTH);
    }
    g.drawImage(imgres, rec.x, rec.y, null);
}
 
Example 12
Source Project: universal-tween-engine   Source File: TimelineApplet.java    License: Apache License 2.0 6 votes vote down vote up
public MyCanvas() {
	Tween.enablePooling(false);
	Tween.registerAccessor(Sprite.class, new SpriteAccessor());
	
	imgUniversalSprite = new Sprite("img-universal.png").setCentered(false);
	imgTweenSprite = new Sprite("img-tween.png").setCentered(false);
	imgEngineSprite = new Sprite("img-engine.png").setCentered(false);
	imgLogoSprite = new Sprite("img-logo.png");
	blankStripSprite = new Sprite("blankStrip.png");

	try {
		BufferedImage bgImage = ImageIO.read(TimelineApplet.class.getResource("/aurelienribon/tweenengine/applets/gfx/transparent-dark.png"));
		bgPaint = new TexturePaint(bgImage, new Rectangle(0, 0, bgImage.getWidth(), bgImage.getHeight()));
	} catch (IOException ex) {
	}
}
 
Example 13
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example 14
private void init(Component parent, String  title, String message,
                  String buttonText) {
    Panel p = new Panel();
    add("Center", new Label(message));
    Button btn = new Button(buttonText);
    btn.addActionListener(this);
    p.add(btn);
    add("South", p);
    pack();

    Dimension dDim = getSize();
    if (parent != null) {
        Rectangle fRect = parent.getBounds();
        setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
                    fRect.y + ((fRect.height - dDim.height) / 2));
    }
}
 
Example 15
Source Project: openjdk-jdk9   Source File: XWM.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void setShellNotResizable(XDecoratedPeer window, WindowDimensions newDimensions, Rectangle shellBounds,
                                 boolean justChangeSize)
{
    if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
        insLog.fine("Setting non-resizable shell " + window + ", dimensions " + newDimensions +
                    ", shellBounds " + shellBounds +", just change size: " + justChangeSize);
    }
    XToolkit.awtLock();
    try {
        /* Fix min/max size hints at the specified values */
        if (!shellBounds.isEmpty()) {
            window.updateSizeHints(newDimensions);
            requestWMExtents(window.getWindow());
            XToolkit.XSync();
            XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(),
                                          window.getShell(),
                                          window.scaleUp(shellBounds.x),
                                          window.scaleUp(shellBounds.y),
                                          window.scaleUp(shellBounds.width),
                                          window.scaleUp(shellBounds.height));
        }
        if (!justChangeSize) {  /* update decorations */
            setShellDecor(window);
        }
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 16
Source Project: ocular   Source File: PdfImageReader.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static BufferedImage readPage(PDFFile pdf, int pageNumber) {
	double scale = 2.5; // because otherwise the image comes out really tiny
	PDFPage page = pdf.getPage(pageNumber);
	Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());
	BufferedImage bufferedImage = new BufferedImage((int)(rect.width * scale), (int)(rect.height * scale), BufferedImage.TYPE_INT_RGB);
	Image image = page.getImage((int)(rect.width * scale), (int)(rect.height * scale), rect, null, true, true);
	Graphics2D bufImageGraphics = bufferedImage.createGraphics();
	bufImageGraphics.drawImage(image, 0, 0, null);
	return bufferedImage;
}
 
Example 17
Source Project: jdk8u-dev-jdk   Source File: WGLSurfaceData.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Rectangle getBounds() {
    if (type == FLIP_BACKBUFFER) {
        Rectangle r = peer.getBounds();
        r.x = r.y = 0;
        return r;
    } else {
        return new Rectangle(width, height);
    }
}
 
Example 18
Source Project: jdk8u-jdk   Source File: OGLUtilities.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Rectangle describing the OpenGL scissor box on the
 * Java 2D surface associated with the given Graphics object.  When a
 * third-party library is performing OpenGL rendering directly
 * into the visible region of the associated surface, this scissor box
 * must be set to avoid drawing over existing rendering results.
 *
 * Note that the x/y values in the returned Rectangle object represent
 * the lower-left corner of the scissor region, relative to the
 * lower-left corner of the given surface.
 *
 * @param g the Graphics object for the corresponding destination surface;
 * cannot be null
 * @return a Rectangle describing the OpenGL scissor box for the given
 * Graphics object and corresponding destination surface, or null if the
 * given Graphics object is invalid or the clip region is non-rectangular
 */
public static Rectangle getOGLScissorBox(Graphics g) {
    if (!(g instanceof SunGraphics2D)) {
        return null;
    }

    SunGraphics2D sg2d = (SunGraphics2D)g;
    SurfaceData sData = (SurfaceData)sg2d.surfaceData;
    Region r = sg2d.getCompClip();
    if (!r.isRectangular()) {
        // caller probably doesn't know how to handle shape clip
        // appropriately, so just return null (Swing currently never
        // sets a shape clip, but that could change in the future)
        return null;
    }

    // this is the upper-left origin of the scissor box relative to the
    // upper-left origin of the surface (in Java 2D coordinates)
    int x0 = r.getLoX();
    int y0 = r.getLoY();

    // this is the width and height of the scissor region
    int w = r.getWidth();
    int h = r.getHeight();

    // this is the lower-left origin of the scissor box relative to the
    // lower-left origin of the surface (in OpenGL coordinates)
    Rectangle surfaceBounds = sData.getBounds();
    int x1 = x0;
    int y1 = surfaceBounds.height - (y0 + h);

    return new Rectangle(x1, y1, w, h);
}
 
Example 19
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel.
 * The Raster's upper left corner is origin and it is the same
 * size as the SampleModel.  A DataBuffer large enough to describe the
 * Raster is automatically created.  SampleModel must be of type
 * SinglePixelPackedSampleModel or InterleavedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param origin          The Point that specified the origin.
 */
public ByteInterleavedRaster(SampleModel sampleModel, Point origin) {
    this(sampleModel,
         sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
Example 20
Source Project: aparapi   Source File: InstructionViewer.java    License: Apache License 2.0 5 votes vote down vote up
double foldPlace(Graphics2D _g, InstructionView _instructionView, double _x, double _y, boolean _dim) {
   _instructionView.dim = _dim;
   final FontMetrics fm = _g.getFontMetrics();

   _instructionView.label = InstructionHelper.getLabel(_instructionView.instruction, config.showPc, config.showExpressions,
         config.verboseBytecodeLabels);

   final int w = fm.stringWidth(_instructionView.label) + HMARGIN;
   final int h = fm.getHeight() + VMARGIN;

   double y = _y;
   final double x = _x + w + (_instructionView.instruction.getRootExpr() == _instructionView.instruction ? HGAP : HGAP);

   if (!config.collapseAll && !config.showExpressions) {

      for (Instruction e = _instructionView.instruction.getFirstChild(); e != null; e = e.getNextExpr()) {

         y = foldPlace(_g, getInstructionView(e), x, y, _dim);
         if (e != _instructionView.instruction.getLastChild()) {
            y += VGAP;
         }
      }

   }
   final double top = ((y + _y) / 2) - (h / 2);
   _instructionView.shape = new Rectangle((int) _x, (int) top, w, h);
   return (Math.max(_y, y));

}
 
Example 21
Source Project: SIMVA-SoS   Source File: LegendGraphicTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    Rectangle r = new Rectangle(1, 2, 3, 4);
    LegendGraphic g1 = new LegendGraphic(r, Color.black);
    LegendGraphic g2 = (LegendGraphic) g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    r.setBounds(4, 3, 2, 1);
    assertFalse(g1.equals(g2));
}
 
Example 22
Source Project: netbeans   Source File: CheckTreeView.java    License: Apache License 2.0 5 votes vote down vote up
private void showPathWithoutExpansion(TreePath path) {
    Rectangle rect = tree.getPathBounds(path);

    if (rect != null && getWidth() > 0 && getHeight() > 0 ) {
        tree.scrollRectToVisible(rect);
    }
}
 
Example 23
Source Project: jdk8u_jdk   Source File: ShortBandedRaster.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel.
 * The Raster's upper left corner is origin and it is the same
 * size as the SampleModel.  A DataBuffer large enough to describe the
 * Raster is automatically created.  SampleModel must be of type
 * BandedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param origin          The Point that specified the origin.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            Point origin) {
    this(sampleModel,
         sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
Example 24
Source Project: pumpernickel   Source File: ListLocationBrowserUI.java    License: MIT License 5 votes vote down vote up
public void run() {
	synchronizeDirectoryContents();
	if (adjustingModels > 0)
		return;
	adjustingModels++;
	try {
		IOLocation[] obj = browser.getSelectionModel().getSelection();
		List<Integer> ints = new ArrayList<Integer>();
		ListModel listModel = browser.getListModel();
		synchronized (listModel) {
			for (int a = 0; a < obj.length; a++) {
				int k = getIndexOf(listModel, obj[a]);
				if (k != -1) {
					ints.add(new Integer(k));
				}
			}
			int[] indices = new int[ints.size()];
			for (int a = 0; a < ints.size(); a++) {
				indices[a] = (ints.get(a)).intValue();
			}
			// seriously? there isn't a way to set the selection all at
			// once?
			table.getSelectionModel().clearSelection();
			for (int a = 0; a < indices.length; a++) {
				table.getSelectionModel().addSelectionInterval(
						indices[a], indices[a]);
			}

			if (indices.length > 0) {
				Rectangle r = table.getCellRect(indices[0], 0, false);
				table.scrollRectToVisible(r);
			}
		}
	} finally {
		adjustingModels--;
	}
}
 
Example 25
Source Project: openjdk-jdk9   Source File: CustomComponent.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 26
/**
 * Creates a Writable subRaster given a region of the Raster. The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffer as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ByteInterleavedRaster(sm,
                                   dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
 
Example 27
/**
 * Background pixels inside a given shape must be recognized as such.
 * <p>
 * Such pixels are marked with a specific color (pink foreground) so that the template can
 * measure their distance to (black) foreground.
 *
 * @param img the source image
 * @param box bounds of symbol relative to image
 */
private void addHoles (BufferedImage img,
                       Rectangle box)
{
    if (shapesWithHoles.contains(shape)) {
        // Identify holes
        final List<Point> holeSeeds = new ArrayList<>();

        // We have no ledger, just a big hole in the symbol center
        holeSeeds.add(new Point(box.x + (box.width / 2), box.y + (box.height / 2)));

        // Fill the holes if any with HOLE color
        FloodFiller floodFiller = new FloodFiller(img);

        for (Point seed : holeSeeds) {
            // Background (BACK) -> interior background (HOLE)
            // Hole seeds are very coarse with low interline value, so try points nearby
            Neiborhood:
            for (int iy = 0; iy <= 1; iy++) {
                for (int ix = 0; ix <= 1; ix++) {
                    if (isBackground(img, seed.x + ix, seed.y + iy)) {
                        floodFiller.fill(seed.x + ix, seed.y + iy, BACK, HOLE);

                        break Neiborhood;
                    }
                }
            }
        }
    }
}
 
Example 28
Source Project: TrakEM2   Source File: DisplayCanvas.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Repaint the given offscreen Rectangle after transforming its data on the fly to the
 * srcRect and magnification of this DisplayCanvas. The Rectangle is not
 * modified.
 */
public void repaint(final Rectangle r, final int extra) {
	invalidateVolatile();
	if (null == r) {
		//Utils.log2("DisplayCanvas.repaint(Rectangle, int) warning: null r");
		RT.paint(null, update_graphics);
		return;
	}
	// repaint((int) ((r.x - srcRect.x) * magnification) - extra, (int) ((r.y - srcRect.y) * magnification) - extra, (int) Math .ceil(r.width * magnification) + extra + extra, (int) Math.ceil(r.height * magnification) + extra + extra);
	RT.paint(new Rectangle((int) ((r.x - srcRect.x) * magnification) - extra, (int) ((r.y - srcRect.y) * magnification) - extra, (int) Math.ceil(r.width * magnification) + extra + extra, (int) Math.ceil(r.height * magnification) + extra + extra), update_graphics);
}
 
Example 29
Source Project: netbeans   Source File: CaretItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Repaint caret bounds if the caret is showing or do nothing
 * @param c
 * @return 
 */
synchronized Rectangle repaintIfShowing(JTextComponent c, String logMessage, int logIndex) {
    Rectangle bounds = this.caretBounds;
    if (bounds != null) {
        boolean repaint = (this.statusBits & CARET_PAINTED) != 0;
        if (repaint) {
            this.statusBits &= ~CARET_PAINTED;
            if (EditorCaret.LOG.isLoggable(Level.FINE)) {
                logRepaint(logMessage + "-repaintIfShowing", logIndex, bounds);
            }
            c.repaint(bounds);
        }
    }
    return bounds;
}
 
Example 30
Source Project: netbeans   Source File: DesktopImpl.java    License: Apache License 2.0 5 votes vote down vote up
public void performSlideIntoEdge(SlideOperation operation, Rectangle editorBounds) {
    operation.setFinishBounds(computeLastButtonBounds(operation));
    Rectangle screenStart = operation.getStartBounds();
    operation.setStartBounds(convertRectFromScreen(layeredPane, screenStart));
    
    performSlide(operation);
}