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

The following are Jave code examples for showing how to use contains() 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: rapidminer   File: ExtendedJTableColumnFitMouseListener.java   View Source Code Vote up 6 votes
private TableColumn getResizingColumn(JTableHeader header, Point p, int column) {
	if (column == -1) {
		return null;
	}

	Rectangle r = header.getHeaderRect(column);
	r.grow(-3, 0);

	if (r.contains(p)) {
		return null;
	}

	int midPoint = r.x + r.width / 2;
	int columnIndex = 0;
	if (header.getComponentOrientation().isLeftToRight()) {
		columnIndex = (p.x < midPoint) ? column - 1 : column;
	} else {
		columnIndex = (p.x < midPoint) ? column : column - 1;
	}

	if (columnIndex == -1) {
		return null;
	}

	return header.getColumnModel().getColumn(columnIndex);
}
 
Example 2
Project: brModelo   File: Mostrador.java   View Source Code Vote up 6 votes
private void ChecaCursor(Point p) {
    if (areas.isEmpty()) {
        return;
    }
    int i = 0;
    for (Rectangle r : areas) {
        if (r.contains(p)) {
            setOverNow(r);
            if (i > 1) {
                Rectangle r2 = new Rectangle(r.x + r.width - 18, r.y + fh / 2, 16, 16);
                if (r2.contains(p)) {
                    this.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
                } else {
                    this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                }
            }
            return;
        }
        i++;
    }
    setOverNow(null);
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
 
Example 3
Project: incubator-netbeans   File: ToolTipSupport.java   View Source Code Vote up 6 votes
public @Override void mouseMoved(MouseEvent evt) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "mouseMoved: x=" + evt.getX() + "; y=" + evt.getY() + "enabled=" + enabled + ", status=" + status + ", flags=" + flags); //NOI18N
    }

    if (toolTip != null) {
        Rectangle ignoredArea = (Rectangle) toolTip.getClientProperty(MOUSE_MOVE_IGNORED_AREA);
        Point mousePosition = SwingUtilities.convertPoint(evt.getComponent(), evt.getPoint(), toolTip.getParent());
        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "Mouse-Move-Ignored-Area=" + ignoredArea + "; mouse=" + mousePosition //NOI18N
                + "; is-inside=" + (ignoredArea != null ? ignoredArea.contains(mousePosition) : null)); //NOI18N
        }
        if (ignoredArea != null && ignoredArea.contains(mousePosition)) {
            return;
        }
    }

    if (!isToolTipShowing() || (flags & FLAG_HIDE_ON_MOUSE_MOVE) != 0) {
        setToolTipVisible(false);
    }
    
    if (enabled) {
        enterTimer.restart();
    }
    lastMouseEvent = evt;
}
 
Example 4
Project: incubator-netbeans   File: TreeViewDragSupport.java   View Source Code Vote up 6 votes
/** Utility method. Returns either selected nodes in tree
* (if cursor hotspot is above some selected node) or the node
* the cursor points to.
* @return Node array or null if position of the cursor points
* to no node.
*/
Node[] obtainNodes(DragGestureEvent dge) {
    TreePath[] tps = tree.getSelectionPaths();

    if (tps == null) {
        return null;
    }

    Node[] result = new Node[tps.length];

    int cnt = 0;

    for (int i = 0; i < tps.length; i++) {
        Rectangle r = tree.getPathBounds(tps[i]);
        if (r != null && r.contains(dge.getDragOrigin())) {
            cnt++;
        }

        result[i] = DragDropUtilities.secureFindNode(tps[i].getLastPathComponent());
    }

    // #41954:
    // if the drag source is not at all in path location, do not return
    // any nodes
    return (cnt == 0) ? null : result;
}
 
Example 5
Project: Cognizant-Intelligent-Test-Scripter   File: TestDataComponent.java   View Source Code Vote up 6 votes
private MouseAdapter onAddNewTDTab() {
    return new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            JTabbedPane tabbedPane = (JTabbedPane) me.getSource();
            if (tabbedPane.getSelectedIndex() != -1 && getSelectedData() == null) {
                Rectangle rect = tabbedPane.getUI().
                        getTabBounds(tabbedPane, tabbedPane.getSelectedIndex());
                if (rect.contains(me.getPoint())) {
                    tabbedPane.setSelectedIndex(tabbedPane.getSelectedIndex() - 1);
                    addNewTestData(tabbedPane);
                }
            }
        }
    };
}
 
Example 6
Project: incubator-netbeans   File: QuickSearchPopup.java   View Source Code Vote up 6 votes
private void jList1MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseMoved
    // toggle resize/default cursor
    if (evt.getX() < RESIZE_AREA_WIDTH) {
        QuickSearchPopup.this.setCursor(Cursor.getPredefinedCursor(
                Cursor.W_RESIZE_CURSOR));
    } else {
        QuickSearchPopup.this.setCursor(Cursor.getDefaultCursor());
    }
    // selection follows mouse move
    Point loc = evt.getPoint();
    int index = jList1.locationToIndex(loc);
    if (index == -1) {
        return;
    }
    Rectangle rect = jList1.getCellBounds(index, index);
    if (rect != null && rect.contains(loc)) {
        jList1.setSelectedIndex(index);
    }

}
 
Example 7
Project: Pogamut3   File: ShedScene.java   View Source Code Vote up 6 votes
private ShedWidget findShedWidget(Widget searchedEnvelope, Point scenePoint) {
    for (Widget searchedEnvelopeChild : searchedEnvelope.getChildren()) {
        ShedWidget foundWidget = findShedWidget(searchedEnvelopeChild, scenePoint);
        if (foundWidget != null) {
            return foundWidget;
        }
    }

    Rectangle localSearchedBounds = searchedEnvelope.getBounds();
    Rectangle sceneSearchedBounds = searchedEnvelope.convertLocalToScene(localSearchedBounds);

    if (sceneSearchedBounds.contains(scenePoint) && (searchedEnvelope instanceof ShedWidget)) {
        return (ShedWidget) searchedEnvelope;
    }
    return null;
}
 
Example 8
Project: brModelo   File: Mostrador.java   View Source Code Vote up 6 votes
@Override
public void mouseClicked(MouseEvent e) {
    super.mouseClicked(e);
    if (areas.isEmpty()) {
        return;
    }
    int i = 0;
    for (Rectangle r : areas) {
        if (r.contains(e.getPoint())) {
            Rectangle r2 = new Rectangle(r.x + r.width - 18, r.y + fh / 2, 16, 16);
            ProcessClick(i);
            if (i > 1 && r2.contains(e.getPoint())) {
                master.FechaDiagrama(i - 2);
                Construa();
                ChecaCursor(e.getPoint());
                repaint();
            }
            break;
        }
        i++;
    }
    e.consume();
}
 
Example 9
Project: incubator-netbeans   File: CompletionPopup.java   View Source Code Vote up 6 votes
@Override
public void mouseDragged(MouseEvent e) {
    if (e.getSource() == list) {
        return;
    }

    if (isVisible()) {
        MouseEvent newEvent = convertMouseEvent(e);
        Rectangle r = new Rectangle();
        list.computeVisibleRect(r);
        Point location = newEvent.getPoint();
        int index = list.locationToIndex(location);
        if (r.contains(location)) {
            list.setSelectedIndex(index);
        }
    }
}
 
Example 10
Project: incubator-netbeans   File: RectangularAnchor.java   View Source Code Vote up 5 votes
@Override
public List<Point> compute(List<Point> points) {
    ArrayList<Point> bestPoints = new ArrayList<Point> (points) ;
    Point relatedLocation = getRelatedSceneLocation();

    int direction = 1 ;
    int index = 0 ;
    
    //the related location is the center of this anchor. It is possible that
    //the list of points started at the opposite anchor (other end of connection).
    Point endPoint = bestPoints.get(index);
    if (!endPoint.equals(relatedLocation)) {
        index = bestPoints.size() - 1 ;
        endPoint = bestPoints.get(index);
        direction = -1 ;
    }
    
    Widget widget = getRelatedWidget();
    Rectangle bounds = widget.getBounds();
    bounds = widget.convertLocalToScene(bounds);
    
    Point neighbor = bestPoints.get (index+direction) ;
    
    //moving the end point to the end of the anchor from the interior
    while (bounds.contains(neighbor)) {
        bestPoints.remove(index) ;
        endPoint = bestPoints.get (index);
        neighbor = bestPoints.get (index+direction);
    }
    
    Result intersection = this.computeBoundaryIntersectionPoint(endPoint, neighbor);
            
    bestPoints.remove(index) ;
    bestPoints.add(index, intersection.getAnchorSceneLocation());
    
    return bestPoints ;
}
 
Example 11
Project: Logisim   File: JTreeUtil.java   View Source Code Vote up 5 votes
private static void autoscroll(JTree tree, Point cursorLocation) {
	Insets insets = DEFAULT_INSETS;
	Rectangle outer = tree.getVisibleRect();
	Rectangle inner = new Rectangle(outer.x + insets.left, outer.y + insets.top,
			outer.width - (insets.left + insets.right), outer.height - (insets.top + insets.bottom));
	if (!inner.contains(cursorLocation)) {
		Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left, cursorLocation.y - insets.top,
				insets.left + insets.right, insets.top + insets.bottom);
		tree.scrollRectToVisible(scrollRect);
	}
}
 
Example 12
Project: incubator-netbeans   File: SummaryCellRenderer.java   View Source Code Vote up 5 votes
@Override
public boolean mouseMoved (Point p, JComponent component) {
    if (bounds != null && component.getToolTipText() == null) {
        for (Rectangle b : bounds) {
            if (b.contains(p)) {
                component.setToolTipText(text);
                return true;
            }
        }
    }
    return false;
}
 
Example 13
Project: TrabalhoFinalEDA2   File: mxInteractiveCanvas.java   View Source Code Vote up 5 votes
/**
 * Returns true if the given point is inside the content area of the given
 * swimlane. (The content area of swimlanes is transparent to events.) This
 * implementation does not check if the given state is a swimlane, it is
 * assumed that the caller has checked this before using this method.
 */
public boolean hitSwimlaneContent(mxGraphComponent graphComponent,
		mxCellState swimlane, int x, int y)
{
	if (swimlane != null)
	{
		int start = (int) Math.max(2, Math.round(mxUtils.getInt(
				swimlane.getStyle(), mxConstants.STYLE_STARTSIZE,
				mxConstants.DEFAULT_STARTSIZE)
				* graphComponent.getGraph().getView().getScale()));
		Rectangle rect = swimlane.getRectangle();

		if (mxUtils.isTrue(swimlane.getStyle(),
				mxConstants.STYLE_HORIZONTAL, true))
		{
			rect.y += start;
			rect.height -= start;
		}
		else
		{
			rect.x += start;
			rect.width -= start;
		}

		return rect.contains(x, y);
	}

	return false;
}
 
Example 14
Project: brModelo   File: Ancorador.java   View Source Code Vote up 5 votes
private void ChecarOver(Point p) {
    if (areas.isEmpty()) {
        return;
    }
    for (Rectangle r : areas) {
        if (r.contains(p)) {
            setOverNow(r);
            return;
        }
    }
    setOverNow(null);
}
 
Example 15
Project: powertext   File: Util.java   View Source Code Vote up 5 votes
/**
 * Returns the screen coordinates for the monitor that contains the
 * specified point.  This is useful for setups with multiple monitors,
 * to ensure that popup windows are positioned properly.
 *
 * @param x The x-coordinate, in screen coordinates.
 * @param y The y-coordinate, in screen coordinates.
 * @return The bounds of the monitor that contains the specified point.
 */
public static Rectangle getScreenBoundsForPoint(int x, int y) {
	GraphicsEnvironment env = GraphicsEnvironment.
									getLocalGraphicsEnvironment();
	GraphicsDevice[] devices = env.getScreenDevices();
	for (int i=0; i<devices.length; i++) {
		GraphicsConfiguration config = devices[i].getDefaultConfiguration();
		Rectangle gcBounds = config.getBounds();
		if (gcBounds.contains(x, y)) {
			return gcBounds;
		}
	}
	// If point is outside all monitors, default to default monitor (?)
	return env.getMaximumWindowBounds();
}
 
Example 16
Project: incubator-netbeans   File: NewPluginPanel.java   View Source Code Vote up 5 votes
@Override
public void mouseClicked(MouseEvent e) {
    int idx = parentList.locationToIndex(e.getPoint());
    if (idx == -1) {
        return;
    }
    Rectangle rect = parentList.getCellBounds(idx, idx);
    if (rect.contains(e.getPoint())) {
        doCheck();
    }
}
 
Example 17
Project: geomapapp   File: LocationInset.java   View Source Code Vote up 4 votes
public void mousePressed( MouseEvent evt ) {
	dragWindow = false;
	dragMap = false;
	if( evt.isControlDown() ) {
		return;
	} 

	Rectangle r = map.getVisibleRect();
	if (rect == null) return;

	r.x += x;
	r.y += y;
	r.width = this.w;
	r.height = this.h;
	if( r.contains( evt.getPoint() ) ) {
		evt.consume();
		AbstractButton b = map.getMapTools().profileB;
		profileEnabled = b.isSelected();
		if (profileEnabled) b.doClick();

		dragWindow = true;
		lastPoint = evt.getPoint();
		r.x+=rect.x;
		r.y+=rect.y;
		r.width=(int)rect.width;
		r.height=(int)rect.height;
		if (r.contains(evt.getPoint())){
			dragMap=true;
			dragWindow = false;
			drawRect();
		} else if (rect.x+rect.width>this.w){
			r.x-=this.w;
			if (r.contains(evt.getPoint())) {
				rect.x-=this.w;
				dragMap=true;
				dragWindow = false;
				drawRect();
			}
		}
		else 
			drawBox();
	}
}
 
Example 18
Project: incubator-netbeans   File: JExtendedTree.java   View Source Code Vote up 4 votes
protected void processCellTipMouseMove(MouseEvent e) {
    // Identify treetable row and column at cursor
    TreePath currentTreePath = getPathForLocation(e.getX(), e.getY());

    // Return if treetable cell is the same as in previous event
    if (currentTreePath == lastTreePath) {
        return;
    }

    lastTreePath = currentTreePath;

    // Return if cursor isn't at any cell
    if (lastTreePath == null) {
        CellTipManager.sharedInstance().setEnabled(false);

        return;
    }

    Component cellRenderer;
    Component cellRendererPersistent;
    int row = getRowForPath(lastTreePath);

    TreeCellRenderer treeCellRenderer = getCellRenderer();

    if (!(treeCellRenderer instanceof TreeCellRendererPersistent)) {
        return;
    }

    cellRenderer = treeCellRenderer.getTreeCellRendererComponent(JExtendedTree.this, lastTreePath.getLastPathComponent(),
                                                                 false, isExpanded(row),
                                                                 getModel().isLeaf(lastTreePath.getLastPathComponent()), row,
                                                                 false);
    cellRendererPersistent = ((TreeCellRendererPersistent) treeCellRenderer).getTreeCellRendererComponentPersistent(JExtendedTree.this,
                                                                                                                    lastTreePath
                                                                                                                    .getLastPathComponent(),
                                                                                                                    false,
                                                                                                                    isExpanded(row),
                                                                                                                    getModel()
                                                                                                                        .isLeaf(lastTreePath
                                                                                                                                .getLastPathComponent()),
                                                                                                                    row, false);

    // Return if celltip is not supported for the cell
    if (cellRenderer == null) {
        CellTipManager.sharedInstance().setEnabled(false);

        return;
    }

    Point cellStart = getPathBounds(lastTreePath).getLocation();
    rendererRect = new Rectangle(cellStart.x, cellStart.y, cellRenderer.getPreferredSize().width,
                                 cellRenderer.getPreferredSize().height + 2);

    if (!rendererRect.contains(e.getPoint())) {
        CellTipManager.sharedInstance().setEnabled(false);

        return;
    }

    // Return if cell contents is fully visible
    Rectangle visibleRect = getVisibleRect();

    if ((rendererRect.x >= visibleRect.x) && ((rendererRect.x + rendererRect.width) <= (visibleRect.x + visibleRect.width))) {
        CellTipManager.sharedInstance().setEnabled(false);

        return;
    }

    while (cellTip.getComponentCount() > 0) {
        cellTip.remove(0);
    }

    cellTip.add(cellRendererPersistent, BorderLayout.CENTER);
    cellTip.setPreferredSize(new Dimension(cellRendererPersistent.getPreferredSize().width + 2, getRowHeight() + 2));

    CellTipManager.sharedInstance().setEnabled(true);
}
 
Example 19
Project: incubator-netbeans   File: FindTypesSupport.java   View Source Code Vote up 4 votes
@Override
    public void mouseMoved(MouseEvent e) {
        JTextPane pane = (JTextPane)e.getSource();
        StyledDocument doc = pane.getStyledDocument();

        int offset = pane.viewToModel(e.getPoint());
        Element elem = doc.getCharacterElement(offset);

        Highlight h = getHighlight(pane, offset);
        Highlight prevHighlight = (Highlight) pane.getClientProperty(PREV_HIGHLIGHT_PROPERTY);
        AttributeSet prevAs = (AttributeSet) pane.getClientProperty(PREV_HIGHLIGHT_ATTRIBUTES);
//        if(h != null && h.equals(prevHighlight)) {
//            return; // nothing to do
//        } else 
        if(prevHighlight != null && prevAs != null) {
            doc.setCharacterAttributes(prevHighlight.startOffset, prevHighlight.endOffset - prevHighlight.startOffset, prevAs, true);
            pane.putClientProperty(PREV_HIGHLIGHT_PROPERTY, null);
            pane.putClientProperty(PREV_HIGHLIGHT_ATTRIBUTES, null);
        }

        int modifiers = e.getModifiers() | e.getModifiersEx();
        if ( (modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK ||
             (modifiers & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) 
        {            
            AttributeSet as = elem.getAttributes();
            if (StyleConstants.isUnderline(as)) {
                // do not underline whats already underlined
                return;
            }

            Font font = doc.getFont(as);
            FontMetrics fontMetrics = pane.getFontMetrics(font);
            try {
                Rectangle rectangle = new Rectangle(
                        pane.modelToView(elem.getStartOffset()).x,
                        pane.modelToView(elem.getStartOffset()).y,
                        fontMetrics.stringWidth(doc.getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset())),
                        fontMetrics.getHeight());

                if (h != null && offset < elem.getEndOffset() - 1 && rectangle.contains(e.getPoint())) {
                    Style hlStyle = doc.getStyle("regularBlue-findtype");               // NOI18N

                    pane.putClientProperty(PREV_HIGHLIGHT_ATTRIBUTES, as.copyAttributes());
                    doc.setCharacterAttributes(h.startOffset, h.endOffset - h.startOffset, hlStyle, true);
    //                doc.setCharacterAttributes(h.startOffset, h.endOffset - h.startOffset, as.copyAttributes(), true);
                    pane.putClientProperty(PREV_HIGHLIGHT_PROPERTY, h);
                } 
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
 
Example 20
Project: AWGW   File: GridPanel.java   View Source Code Vote up 4 votes
/**
 * Moves the current location by a given amount.
 *
 * @param dr the number of rows by which to move the location
 * @param dc the number of columns by which to move the location
 */
public void moveLocation(int dr, int dc) {
    Location newLocation = new Location(currentLocation.getRow() + dr,
            currentLocation.getCol() + dc);
    if (!grid.isValid(newLocation))
        return;

    currentLocation = newLocation;

    JViewport viewPort = getEnclosingViewport();
    if (isPannableUnbounded()) {
        if (originRow > currentLocation.getRow())
            originRow = currentLocation.getRow();
        if (originCol > currentLocation.getCol())
            originCol = currentLocation.getCol();
        Dimension dim = viewPort.getSize();
        int rows = dim.height / (cellSize + 1);
        int cols = dim.width / (cellSize + 1);
        if (originRow + rows - 1 < currentLocation.getRow())
            originRow = currentLocation.getRow() - rows + 1;
        if (originCol + rows - 1 < currentLocation.getCol())
            originCol = currentLocation.getCol() - cols + 1;
    } else if (viewPort != null) {
        int dx = 0;
        int dy = 0;
        Point p = pointForLocation(currentLocation);
        Rectangle locRect = new Rectangle(p.x - cellSize / 2, p.y
                - cellSize / 2, cellSize + 1, cellSize + 1);

        Rectangle viewRect = viewPort.getViewRect();
        if (!viewRect.contains(locRect)) {
            while (locRect.x < viewRect.x + dx)
                dx -= cellSize + 1;
            while (locRect.y < viewRect.y + dy)
                dy -= cellSize + 1;
            while (locRect.getMaxX() > viewRect.getMaxX() + dx)
                dx += cellSize + 1;
            while (locRect.getMaxY() > viewRect.getMaxY() + dy)
                dy += cellSize + 1;

            Point pt = viewPort.getViewPosition();
            pt.x += dx;
            pt.y += dy;
            viewPort.setViewPosition(pt);
        }
    }
    repaint();
    showTip(getToolTipText(currentLocation),
            pointForLocation(currentLocation));
}