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

The following examples show how to use java.awt.Rectangle#getLocation() . 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: CategoryList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public int getScrollableUnitIncrement (Rectangle visibleRect, int orientation, int direction) {
    int row;
    if (orientation == SwingConstants.VERTICAL &&
            direction < 0 && (row = getFirstVisibleIndex ()) != -1) {
        Rectangle r = getCellBounds (row, row);
        if ((r.y == visibleRect.y) && (row != 0)) {
            Point loc = r.getLocation ();
            loc.y--;
            int prevIndex = locationToIndex (loc);
            Rectangle prevR = getCellBounds (prevIndex, prevIndex);

            if (prevR == null || prevR.y >= r.y) {
                return 0;
            }
            return prevR.height;
        }
    }
    return super.getScrollableUnitIncrement (visibleRect, orientation, direction);
}
 
Example 2
Source File: RunTableView.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Interest in Location &rArr; Run
 *
 * @param locationEvent the location event
 */
@Override
protected void handleLocationEvent (LocationEvent locationEvent)
{
    super.handleLocationEvent(locationEvent);

    // Lookup for Run pointed by this pixel location
    Rectangle rect = locationEvent.getData();

    if (rect == null) {
        return;
    }

    SelectionHint hint = locationEvent.hint;
    MouseMovement movement = locationEvent.movement;

    if (!hint.isLocation()) {
        return;
    }

    Point pt = rect.getLocation();
    Run run = table.getRunAt(pt.x, pt.y);

    // Publish Run information
    table.getRunService().publish(new RunEvent(this, hint, movement, run));
}
 
Example 3
Source File: SeaGlassComboPopup.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the upper left location of the Popup.
 *
 * @return the Point representing the upper-left coordinate of the Popup.
 */
private Point getPopupLocation() {
    Dimension popupSize = comboBox.getSize();
    Insets    insets    = getInsets();

    // reduce the width of the scrollpane by the insets so that the popup
    // is the same width as the combo box.
    popupSize.setSize(popupSize.width - (insets.right + insets.left), getPopupHeightForRowCount(getMaximumRowCount()));
    Rectangle popupBounds   = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
    Dimension scrollSize    = popupBounds.getSize();
    Point     popupLocation = popupBounds.getLocation();

    scroller.setMaximumSize(scrollSize);
    scroller.setPreferredSize(scrollSize);
    scroller.setMinimumSize(scrollSize);

    list.revalidate();

    return popupLocation;
}
 
Example 4
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * For popups invoked by keyboard determines best location for it.
 *
 * @param table source of popup event
 * @return Point best location for menu popup
 */
public static Point getPositionForPopup(JTable table) {
    int idx = table.getSelectedRow();
    if (idx == -1) idx = 0;
    Rectangle rect = table.getCellRect(idx, 1, true);
    return rect.getLocation();
}
 
Example 5
Source File: CoordinateTransform.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
public Rectangle transform(Rectangle rectangle) {
    Point corner1 = rectangle.getLocation();
    Point corner2 = new Point(rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 1);
    transformInPlace(corner1);
    transformInPlace(corner2);
    return new Rectangle(Math.min(corner1.x, corner2.x), Math.min(corner1.y, corner2.y), Math.abs(corner2.x - corner1.x) + 1, Math.abs(corner2.y - corner1.y) + 1);
}
 
Example 6
Source File: AbstractVisualGraphTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Moves the given vertex as necessary so that it is not touching any other vertex
 * 
 * @param v the vertex
 */
protected void isolateVertex(AbstractTestVertex v) {
	GraphViewer<AbstractTestVertex, TestEdge> viewer = graphComponent.getPrimaryViewer();
	Layout<AbstractTestVertex, TestEdge> layout = viewer.getGraphLayout();
	Rectangle vBounds = GraphViewerUtils.getVertexBoundsInLayoutSpace(viewer, v);

	boolean hit = false;
	Collection<AbstractTestVertex> others = new HashSet<>(graph.getVertices());
	others.remove(v);
	for (AbstractTestVertex other : others) {
		Rectangle otherBounds = GraphViewerUtils.getVertexBoundsInLayoutSpace(viewer, other);
		if (vBounds.intersects(otherBounds)) {
			hit = true;
			Point p = vBounds.getLocation();
			int w = (int) vBounds.getWidth();
			int h = (int) vBounds.getHeight();
			Point newPoint = new Point(p.x + w, p.y + h);
			swing(() -> layout.setLocation(v, newPoint));
			viewer.repaint();
			sleep(50); // let us see the effect
			waitForSwing();
		}
	}

	if (hit) {
		// keep moving until we are clear of other vertices
		isolateVertex(v);
	}
}
 
Example 7
Source File: Picture.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Call-back triggered when sheet location has been modified.
 * Based on sheet location, we forward the pixel gray level to whoever is
 * interested in it.
 *
 * @param event the (sheet) location event
 */
@Override
public void onEvent (LocationEvent event)
{
    try {
        // Ignore RELEASING
        if (event.movement == MouseMovement.RELEASING) {
            return;
        }

        Integer level = null;

        // Compute and forward pixel gray level
        Rectangle rect = event.getData();

        if (rect != null) {
            Point pt = rect.getLocation();

            // Check that we are not pointing outside the image
            if ((pt.x >= 0)
                && (pt.x < getWidth())
                && (pt.y >= 0)
                && (pt.y < getHeight())) {
                level = Integer.valueOf(getPixel(pt.x, pt.y));
            }
        }

        levelService.publish(
                new PixelLevelEvent(this, event.hint, event.movement, level));
    } catch (Exception ex) {
        logger.warn(getClass().getName() + " onEvent error", ex);
    }
}
 
Example 8
Source File: RunTableFactory.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Report the RunTable created with the runs retrieved from the provided source.
 *
 * @param source the source to read runs from.
 * @param roi    region of interest (its coordinates are relative to the source)
 * @return a populated RunTable
 */
public RunTable createTable (ByteProcessor source,
                             Rectangle roi)
{
    RunTable table = new RunTable(orientation, roi.width, roi.height);
    RunsRetriever retriever = new RunsRetriever(
            orientation,
            orientation.isVertical() ? new VerticalAdapter(source, table, roi.getLocation())
            : new HorizontalAdapter(source, table, roi.getLocation()));
    retriever.retrieveRuns(roi);

    return table;
}
 
Example 9
Source File: HeadInter.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Report the reference point for a stem connection.
 *
 * @param anchor    desired side for stem (typically TOP_RIGHT_STEM or BOTTOM_LEFT_STEM)
 * @param interline relevant interline value
 * @return the reference point
 */
public Point2D getStemReferencePoint (Anchor anchor,
                                      int interline)
{
    ShapeDescriptor desc = getDescriptor();
    Rectangle templateBox = desc.getBounds(this.getBounds());
    Point ref = templateBox.getLocation();
    Point offset = desc.getOffset(anchor);
    ref.translate(offset.x, offset.y);

    return ref;
}
 
Example 10
Source File: SynthTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    Rectangle clip = g.getClipBounds();

    Rectangle bounds = table.getBounds();
    // account for the fact that the graphics has already been translated
    // into the table's bounds
    bounds.x = bounds.y = 0;

    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
            // this check prevents us from painting the entire table
            // when the clip doesn't intersect our bounds at all
            !bounds.intersects(clip)) {

        paintDropLines(context, g);
        return;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();

    Point upperLeft = clip.getLocation();

    Point lowerRight = new Point(clip.x + clip.width - 1,
                                 clip.y + clip.height - 1);

    int rMin = table.rowAtPoint(upperLeft);
    int rMax = table.rowAtPoint(lowerRight);
    // This should never happen (as long as our bounds intersect the clip,
    // which is why we bail above if that is the case).
    if (rMin == -1) {
        rMin = 0;
    }
    // If the table does not have enough rows to fill the view we'll get -1.
    // (We could also get -1 if our bounds don't intersect the clip,
    // which is why we bail above if that is the case).
    // Replace this with the index of the last row.
    if (rMax == -1) {
        rMax = table.getRowCount()-1;
    }

    int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
    int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
    // This should never happen.
    if (cMin == -1) {
        cMin = 0;
    }
    // If the table does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (cMax == -1) {
        cMax = table.getColumnCount()-1;
    }

    // Paint the cells.
    paintCells(context, g, rMin, rMax, cMin, cMax);

    // Paint the grid.
    // it is important to paint the grid after the cells, otherwise the grid will be overpainted
    // because in Synth cell renderers are likely to be opaque
    paintGrid(context, g, rMin, rMax, cMin, cMax);

    paintDropLines(context, g);
}
 
Example 11
Source File: AbstractListUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean redispatchComponent(MouseEvent e) {
    Point p = e.getPoint();
    int index = list.locationToIndex(p);
    if (index < 0 || index >= list.getModel().getSize()) {
        return false;
    }

    ListCellRenderer renderer = list.getCellRenderer();
    if (null == renderer) {
        return false;
    }
    Component renComponent = renderer.getListCellRendererComponent(list, list.getModel().getElementAt(index), index, false, false);
    if (null == renComponent) {
        return false;
    }
    Rectangle rect = list.getCellBounds(index, index);
    if (null == rect) {
        return false;
    }
    renComponent.setBounds(0, 0, rect.width, rect.height);
    renComponent.doLayout();
    Point p3 = rect.getLocation();

    Point p2 = new Point(p.x - p3.x, p.y - p3.y);
    Component dispatchComponent =
            SwingUtilities.getDeepestComponentAt(renComponent,
            p2.x, p2.y);
    if ( e.isPopupTrigger() &&
         dispatchComponent instanceof LinkButton && 
         !((LinkButton)dispatchComponent).isHandlingPopupEvents() ) 
    {
        return false;
    } 
    if (dispatchComponent instanceof AbstractButton) {
        if (!((AbstractButton) dispatchComponent).isEnabled()) {
            return false;
        }
        Point p4 = SwingUtilities.convertPoint(renComponent, p2, dispatchComponent);
        MouseEvent newEvent = new MouseEvent(dispatchComponent,
                e.getID(),
                e.getWhen(),
                e.getModifiers(),
                p4.x, p4.y,
                e.getClickCount(),
                e.isPopupTrigger(),
                MouseEvent.NOBUTTON);
        dispatchComponent.dispatchEvent(newEvent);
        list.repaint(rect);
        e.consume();
        return true;
    }
    return false;
}
 
Example 12
Source File: MultiScreenLocationTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
Example 13
Source File: MultiScreenLocationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
Example 14
Source File: SynthTableUI.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    Rectangle clip = g.getClipBounds();

    Rectangle bounds = table.getBounds();
    // account for the fact that the graphics has already been translated
    // into the table's bounds
    bounds.x = bounds.y = 0;

    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
            // this check prevents us from painting the entire table
            // when the clip doesn't intersect our bounds at all
            !bounds.intersects(clip)) {

        paintDropLines(context, g);
        return;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();

    Point upperLeft = clip.getLocation();

    Point lowerRight = new Point(clip.x + clip.width - 1,
                                 clip.y + clip.height - 1);

    int rMin = table.rowAtPoint(upperLeft);
    int rMax = table.rowAtPoint(lowerRight);
    // This should never happen (as long as our bounds intersect the clip,
    // which is why we bail above if that is the case).
    if (rMin == -1) {
        rMin = 0;
    }
    // If the table does not have enough rows to fill the view we'll get -1.
    // (We could also get -1 if our bounds don't intersect the clip,
    // which is why we bail above if that is the case).
    // Replace this with the index of the last row.
    if (rMax == -1) {
        rMax = table.getRowCount()-1;
    }

    int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
    int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
    // This should never happen.
    if (cMin == -1) {
        cMin = 0;
    }
    // If the table does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (cMax == -1) {
        cMax = table.getColumnCount()-1;
    }

    // Paint the cells.
    paintCells(context, g, rMin, rMax, cMin, cMax);

    // Paint the grid.
    // it is important to paint the grid after the cells, otherwise the grid will be overpainted
    // because in Synth cell renderers are likely to be opaque
    paintGrid(context, g, rMin, rMax, cMin, cMax);

    paintDropLines(context, g);
}
 
Example 15
Source File: FormaTriangular.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
protected Point[] getPontosDoTriangulo() {
    //poupa recursos. Zerado no método reescrito resized.
    if (PontosDoTriangulo != null) {
        return PontosDoTriangulo;
    }
    calculePontos();
    Point pt1, pt2, pt3, pMeio;
    Rectangle r = new Rectangle(getLeft(), getTop(), getWidth(), getHeight()); //getBounds();
    //r.grow(-espaco, -espaco);
    Point p0 = r.getLocation();
    Point p1 = new Point(r.x + r.width, r.y);
    Point p2 = new Point(r.x + r.width, r.y + r.height);
    Point p3 = new Point(r.x, r.y + r.height);

    switch (direcao) {
        case Up:
            pt1 = pontoPosi4;
            pt2 = p2;
            pt3 = p3;
            pMeio = pontoPosi6;
            break;
        case Right:
            pt1 = pontoPosi5;
            pt2 = p3;
            pt3 = p0;
            pMeio = pontoPosi7;
            break;
        case Down:
            pt1 = pontoPosi6;
            pt2 = p0;
            pt3 = p1;
            pMeio = pontoPosi4;
            break;
        default: //case  Left:
            pt1 = pontoPosi7;
            pt2 = p1;
            pt3 = p2;
            pMeio = pontoPosi5;
            break;
    }
    PontosDoTriangulo = new Point[]{pt1, pt2, pt3, pMeio};
    return PontosDoTriangulo;
}
 
Example 16
Source File: BasicAlignment.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void computeLine ()
{
    line = new BasicLine();

    for (Section section : glyph.getMembers()) {
        line.includeLine(section.getAbsoluteLine());
    }

    Rectangle box = glyph.getBounds();

    // We have a problem if glyph is just 1 pixel: no computable slope!
    if (glyph.getWeight() <= 1) {
        startPoint = stopPoint = box.getLocation();
        slope = 0d; // Why not? we just need a value.

        return;
    }

    slope = line.getSlope();

    double top = box.y;
    double bot = (box.y + box.height) - 1;
    double left = box.x;
    double right = (box.x + box.width) - 1;

    if (isRatherVertical()) {
        // Use line intersections with top & bottom box sides
        startPoint = new Point2D.Double(line.xAtY(top), top);
        stopPoint = new Point2D.Double(line.xAtY(bot), bot);

        if (!line.isVertical()) {
            Point2D pLeft = new Point2D.Double(left, line.yAtX(left));
            Point2D pRight = new Point2D.Double(right, line.yAtX(right));

            if (line.getInvertedSlope() > 0) {
                if (pLeft.getY() > startPoint.getY()) {
                    startPoint = pLeft;
                }

                if (pRight.getY() < stopPoint.getY()) {
                    stopPoint = pRight;
                }
            } else {
                if (pRight.getY() > startPoint.getY()) {
                    startPoint = pRight;
                }

                if (pLeft.getY() < stopPoint.getY()) {
                    stopPoint = pLeft;
                }
            }
        }
    } else {
        // Use line intersections with left & right box sides
        startPoint = new Point2D.Double(left, line.yAtX(left));
        stopPoint = new Point2D.Double(right, line.yAtX(right));

        if (!line.isHorizontal()) {
            Point2D pTop = new Point2D.Double(line.xAtY(top), top);
            Point2D pBot = new Point2D.Double(line.xAtY(bot), bot);

            if (slope > 0) {
                if (pTop.getX() > startPoint.getX()) {
                    startPoint = pTop;
                }

                if (pBot.getX() < stopPoint.getX()) {
                    stopPoint = pBot;
                }
            } else {
                if (pBot.getX() > startPoint.getX()) {
                    startPoint = pBot;
                }

                if (pTop.getX() < stopPoint.getX()) {
                    stopPoint = pTop;
                }
            }
        }
    }
}
 
Example 17
Source File: TemplateBoard.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Display rectangle attributes
 *
 * @param locEvent the location event
 */
protected void handleLocationEvent (LocationEvent locEvent)
{
    AnchoredTemplate anchoredTemplate = (AnchoredTemplate) templateService.getSelection(
            AnchoredTemplateEvent.class);

    if (anchoredTemplate == null) {
        return;
    }

    Rectangle rect = locEvent.getData();

    if ((rect == null) || (rect.width != 0) || (rect.height != 0)) {
        return;
    }

    Point pt = rect.getLocation();

    if (locEvent.hint == SelectionHint.CONTEXT_INIT) {
        // Template reference point has been changed, re-eval template at this location
        refPoint = pt;
        tryEvaluate(refPoint, anchoredTemplate);
    } else if (locEvent.hint == SelectionHint.LOCATION_INIT) {
        // User inspects location, display template key point value if any
        if (refPoint != null) {
            Template template = anchoredTemplate.template;
            Anchored.Anchor anchor = anchoredTemplate.anchor;
            Rectangle tplRect = template.getBoundsAt(refPoint.x, refPoint.y, anchor);
            pt.translate(-tplRect.x, -tplRect.y);

            for (PixelDistance pix : template.getKeyPoints()) {
                if ((pix.x == pt.x) && (pix.y == pt.y)) {
                    keyPointField.setValue(pix.d / table.getNormalizer());

                    return;
                }
            }

            keyPointField.setText("");
        }
    }
}
 
Example 18
Source File: SynthTableUI.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    Rectangle clip = g.getClipBounds();

    Rectangle bounds = table.getBounds();
    // account for the fact that the graphics has already been translated
    // into the table's bounds
    bounds.x = bounds.y = 0;

    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
            // this check prevents us from painting the entire table
            // when the clip doesn't intersect our bounds at all
            !bounds.intersects(clip)) {

        paintDropLines(context, g);
        return;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();

    Point upperLeft = clip.getLocation();

    Point lowerRight = new Point(clip.x + clip.width - 1,
                                 clip.y + clip.height - 1);

    int rMin = table.rowAtPoint(upperLeft);
    int rMax = table.rowAtPoint(lowerRight);
    // This should never happen (as long as our bounds intersect the clip,
    // which is why we bail above if that is the case).
    if (rMin == -1) {
        rMin = 0;
    }
    // If the table does not have enough rows to fill the view we'll get -1.
    // (We could also get -1 if our bounds don't intersect the clip,
    // which is why we bail above if that is the case).
    // Replace this with the index of the last row.
    if (rMax == -1) {
        rMax = table.getRowCount()-1;
    }

    int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
    int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
    // This should never happen.
    if (cMin == -1) {
        cMin = 0;
    }
    // If the table does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (cMax == -1) {
        cMax = table.getColumnCount()-1;
    }

    // Paint the cells.
    paintCells(context, g, rMin, rMax, cMin, cMax);

    // Paint the grid.
    // it is important to paint the grid after the cells, otherwise the grid will be overpainted
    // because in Synth cell renderers are likely to be opaque
    paintGrid(context, g, rMin, rMax, cMin, cMax);

    paintDropLines(context, g);
}
 
Example 19
Source File: MultiScreenLocationTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
Example 20
Source File: SynthTableUI.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    Rectangle clip = g.getClipBounds();

    Rectangle bounds = table.getBounds();
    // account for the fact that the graphics has already been translated
    // into the table's bounds
    bounds.x = bounds.y = 0;

    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
            // this check prevents us from painting the entire table
            // when the clip doesn't intersect our bounds at all
            !bounds.intersects(clip)) {

        paintDropLines(context, g);
        return;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();

    Point upperLeft = clip.getLocation();

    Point lowerRight = new Point(clip.x + clip.width - 1,
                                 clip.y + clip.height - 1);

    int rMin = table.rowAtPoint(upperLeft);
    int rMax = table.rowAtPoint(lowerRight);
    // This should never happen (as long as our bounds intersect the clip,
    // which is why we bail above if that is the case).
    if (rMin == -1) {
        rMin = 0;
    }
    // If the table does not have enough rows to fill the view we'll get -1.
    // (We could also get -1 if our bounds don't intersect the clip,
    // which is why we bail above if that is the case).
    // Replace this with the index of the last row.
    if (rMax == -1) {
        rMax = table.getRowCount()-1;
    }

    int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
    int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
    // This should never happen.
    if (cMin == -1) {
        cMin = 0;
    }
    // If the table does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (cMax == -1) {
        cMax = table.getColumnCount()-1;
    }

    // Paint the cells.
    paintCells(context, g, rMin, rMax, cMin, cMax);

    // Paint the grid.
    // it is important to paint the grid after the cells, otherwise the grid will be overpainted
    // because in Synth cell renderers are likely to be opaque
    paintGrid(context, g, rMin, rMax, cMin, cMax);

    paintDropLines(context, g);
}