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

The following are Jave code examples for showing how to use getLocation() 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: incubator-netbeans   File: ListCompletionView.java   View Source Code Vote up 6 votes
public boolean right() {
        Fix f = (Fix) getSelectedValue();
        Iterable<? extends Fix> subfixes = HintsControllerImpl.getSubfixes(f);

        if (subfixes.iterator().hasNext()) {
            Rectangle r = getCellBounds(getSelectedIndex(), getSelectedIndex());
            Point p = new Point(r.getLocation());
            SwingUtilities.convertPointToScreen(p, this);
            p.x += r.width;
//            p.y += r.height;
            HintsUI.getDefault().openSubList(subfixes, p);
            return true;
        }

        return false;
    }
 
Example 2
Project: incubator-netbeans   File: CategoryList.java   View Source Code Vote up 6 votes
@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 3
Project: incubator-netbeans   File: TabTable.java   View Source Code Vote up 6 votes
@Override
public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction ) {
    int res = 0;
    if( orientation == SwingConstants.VERTICAL ) {
        res = getRowHeight() / 2;
    } else {
        Point columnPoint = visibleRect.getLocation();
        columnPoint.x += 1;
        int col = columnAtPoint( columnPoint );
        if( col >= 0 ) {
            Rectangle rect = getCellRect( 0, col, true );
            res = rect.width / 2;
        } else {
            res = super.getScrollableUnitIncrement( visibleRect, orientation, direction );
        }
    }
    if( direction < 0 )
        res *= -1;
    return res;
}
 
Example 4
Project: incubator-netbeans   File: InnerPanelSupport.java   View Source Code Vote up 6 votes
@Override
public void mouseExited(MouseEvent e) {
    if (e.getSource() == listClasses && currentPopup != null) {
        // check if hovering above the popup -> do not dismiss.
        // the mouse exits the table, when it crosses the boudary to the
        // tooltip.
        Point screen = e.getLocationOnScreen();
        Rectangle visibleRec = listClasses.getVisibleRect();
        Point pt = visibleRec.getLocation();
        SwingUtilities.convertPointToScreen(pt, listClasses);
        visibleRec.setLocation(pt);
        if (visibleRec.contains(screen)) {
            return;
        }
        
        hidePopup();
    } else if (e.getSource() == this.popupContents) {
        // exit from the popup
        hidePopup();
    }
}
 
Example 5
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 6 votes
private Point getPopupLocation() {
	Dimension popupSize = new Dimension((int) this.comboBox.getSize().getWidth(), (int) this.comboBox.getSize()
			.getHeight());
	Insets insets = getInsets();
	popupSize.setSize(popupSize.width - (insets.right + insets.left),
			getPopupHeightForRowCount(this.comboBox.getMaximumRowCount()));
	Rectangle popupBounds = computePopupBounds(0, this.comboBox.getBounds().height, popupSize.width,
			popupSize.height);
	Dimension scrollSize = popupBounds.getSize();
	Point popupLocation = popupBounds.getLocation();

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

	this.list.revalidate();
	return popupLocation;
}
 
Example 6
Project: gate-core   File: TextualDocumentView.java   View Source Code Vote up 6 votes
public void scrollAnnotationToVisible(Annotation ann) {
  // if at least part of the blinking section is visible then we
  // need to do no scrolling
  // this is required for long annotations that span more than a
  // screen
  Rectangle visibleView = scroller.getViewport().getViewRect();
  int viewStart = textView.viewToModel(visibleView.getLocation());
  Point endPoint = new Point(visibleView.getLocation());
  endPoint.translate(visibleView.width, visibleView.height);
  int viewEnd = textView.viewToModel(endPoint);
  int annStart = ann.getStartNode().getOffset().intValue();
  int annEnd = ann.getEndNode().getOffset().intValue();
  if(annEnd < viewStart || viewEnd < annStart) {
    try {
      textView.scrollRectToVisible(textView.modelToView(annStart));
    } catch(BadLocationException ble) {
      // this should never happen
      throw new GateRuntimeException(ble);
    }
  }
}
 
Example 7
Project: incubator-netbeans   File: DnDSupport.java   View Source Code Vote up 5 votes
private void setupDropLine( DropTargetDragEvent dtde, CategoryList list, int dropIndex ) {
    boolean verticalDropBar = list.getColumnCount() > 1;
    Rectangle rect = list.getCellBounds( dropIndex, dropIndex );
    if( verticalDropBar )
        dropBefore = dtde.getLocation().x < (rect.x + rect.width/2);
    else
        dropBefore = dtde.getLocation().y < (rect.y + rect.height/2);
    Point p1 = rect.getLocation();
    Point p2 = rect.getLocation();
    if( verticalDropBar ) {
        p2.y += rect.height;
        if( !dropBefore ) {
            p1.x += rect.width;
            p2.x += rect.width;
        }
    } else {
        p2.x += rect.width;
        if( !dropBefore ) {
            p1.y += rect.height;
            p2.y += rect.height;
        }
    }
    p1 = SwingUtilities.convertPoint( list, p1, palette.getRootPane() );
    p2 = SwingUtilities.convertPoint( list, p2, palette.getRootPane() );
    Line2D line = new Line2D.Double( p1.x, p1.y, p2.x, p2.y );
    dropPane.setDropLine( line );
    targetItem = (Item)list.getModel().getElementAt( dropIndex );
}
 
Example 8
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 5 votes
/**
 * 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 9
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 5 votes
/**
 * For popups invoked by keyboard determines best location for it.
 *
 * @param tree source of popup event
 * @return Point best location for menu popup
 */
public static Point getPositionForPopup(JTree tree) {
    TreePath path = tree.getSelectionPath();
    if (path == null) path = tree.getPathForRow(0);
    Rectangle rect = tree.getPathBounds(path);
    rect.x += 10; rect.y += rect.height;
    return rect.getLocation();
}
 
Example 10
Project: incubator-netbeans   File: DesktopImpl.java   View Source Code Vote up 5 votes
/** Returns bounds of last button in sliding view to which given
 * operation belongs. Bounds are relative to desktop layered pane.
 */
private Rectangle computeLastButtonBounds(SlideOperation operation) {
    String side = operation.getSide();
    SlidingView view = findView(side);
    Rectangle screenRect = view.getTabBounds(view.getTopComponents().size() - 1);
    Point leftTop = screenRect.getLocation();
    
    if (Constants.BOTTOM.equals(side)) {
        leftTop.y += desktop.getHeight() - view.getComponent().getPreferredSize().height;
    } else if (Constants.RIGHT.equals(side)) {
        leftTop.x += desktop.getWidth() - view.getComponent().getPreferredSize().width;
    }
    
    return new Rectangle(leftTop, screenRect.getSize());
}
 
Example 11
Project: incubator-netbeans   File: CompletionScrollPane.java   View Source Code Vote up 5 votes
public Point getSelectedLocation() {
    Rectangle r = view.getCellBounds(getSelectedIndex(), getSelectedIndex());
    Point p = new Point(r.getLocation());
    SwingUtilities.convertPointToScreen(p, view);
    p.x += r.width;
    return p;
}
 
Example 12
Project: jdk8u-jdk   File: MultiScreenLocationTest.java   View Source Code Vote up 5 votes
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
Project: incubator-netbeans   File: ProfilerTable.java   View Source Code Vote up 5 votes
public void updateColumnPreferredWidth(int column) {
    Rectangle visible = getVisibleRect();
    if (visible.isEmpty()) return;
    
    Point visibleP = visible.getLocation();
    int first = rowAtPoint(visible.getLocation());
    visibleP.translate(0, visible.height - 1);
    int last = rowAtPoint(visibleP);
    
    int _column = convertColumnIndexToView(column);
    
    int width = computeColumnPreferredWidth(column, _column, first, last);
    _getColumnModel().setColumnPreferredWidth(column, width);
}
 
Example 14
Project: Motunautr   File: Utils.java   View Source Code Vote up 5 votes
public static Point insert(final Rectangle in, final Rectangle bounds) {
	in.x -= Math.max(0, in.getMaxX() - bounds.getMaxX());
	in.y -= Math.max(0, in.getMaxY() - bounds.getMaxY());
	in.x += Math.max(0, bounds.getMinX() - in.getMinX());
	in.y += Math.max(0, bounds.getMinY() - in.getMinY());
	return in.getLocation();
}
 
Example 15
Project: powertext   File: FocusableTip.java   View Source Code Vote up 5 votes
/**
 * Compute the bounds in which the user can move the mouse without the
 * tip window disappearing.
 */
private void computeTipVisibleBounds() {
	// Compute area that the mouse can move in without hiding the
	// tip window. Note that Java 1.4 can only detect mouse events
	// in Java windows, not globally.
	Rectangle r = tipWindow.getBounds();
	Point p = r.getLocation();
	SwingUtilities.convertPointFromScreen(p, textArea);
	r.setLocation(p);
	tipVisibleBounds.setBounds(r.x,r.y-15, r.width,r.height+15*2);
}
 
Example 16
Project: incubator-netbeans   File: AbstractListUI.java   View Source Code Vote up 4 votes
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 17
Project: brModelo   File: FormaTriangular.java   View Source Code Vote up 4 votes
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 18
Project: incubator-netbeans   File: TaskListTableUI.java   View Source Code Vote up 4 votes
/** Paint a representation of the <code>table</code> instance
    * that was set in installUI().
    * 
    * (copy & paste from BasicTableUI)
    */
   public void paint(Graphics g, JComponent c) {
       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)) {

    return;
}

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;
       }

       boolean ltr = table.getComponentOrientation().isLeftToRight();
       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 grid.
       paintGrid(g, rMin, rMax, cMin, cMax);

       // Paint the cells.
paintCells(g, rMin, rMax, cMin, cMax);
   }
 
Example 19
Project: OpenJSharp   File: SynthTableUI.java   View Source Code Vote up 4 votes
/**
 * 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 20
Project: jdk8u-jdk   File: SynthTableUI.java   View Source Code Vote up 4 votes
/**
 * 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);
}