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

The following are Jave code examples for showing how to use setLocation() 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: RevertDeletedAction.java   View Source Code Vote up 8 votes
@Override
public void mouseClicked(MouseEvent e) {
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int row = tree.getRowForLocation(e.getX(), e.getY());
    TreePath path = tree.getPathForRow(row);
    
    // if path exists and mouse is clicked exactly once
    if (path != null) {
        FileNode node = (FileNode) path.getLastPathComponent();
        Rectangle chRect = DeletedListRenderer.getCheckBoxRectangle();
        Rectangle rowRect = tree.getPathBounds(path);
        chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
        if (e.getClickCount() == 1 && chRect.contains(p)) {
            boolean isSelected = !(node.isSelected());
            node.setSelected(isSelected);
            ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
            if (row == 0) {
                tree.revalidate();
            }
            tree.repaint();
        }
    }
}
 
Example 2
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 3
Project: incubator-netbeans   File: QuickSearchPopup.java   View Source Code Vote up 6 votes
private void computePopupBounds (Rectangle result, JLayeredPane lPane, int modelSize) {
    Dimension cSize = comboBar.getSize();
    int width = getPopupWidth();
    Point location = new Point(cSize.width - width - 1, comboBar.getBottomLineY() - 1);
    if (SwingUtilities.getWindowAncestor(comboBar) != null) {
        location = SwingUtilities.convertPoint(comboBar, location, lPane);
    }
    result.setLocation(location);

    // hack to make jList.getpreferredSize work correctly
    // JList is listening on ResultsModel same as us and order of listeners
    // is undefined, so we have to force update of JList's layout data
    jList1.setFixedCellHeight(15);
    jList1.setFixedCellHeight(-1);
    // end of hack

    jList1.setVisibleRowCount(modelSize);
    Dimension preferredSize = jList1.getPreferredSize();

    preferredSize.width = width;
    preferredSize.height += statusPanel.getPreferredSize().height + 3;

    result.setSize(preferredSize);
}
 
Example 4
Project: QN-ACTR-Release   File: EdgeAnimation.java   View Source Code Vote up 6 votes
/**Refreshes appearence of the image to be rendered. In facts, recalculates all of the jobs'
 * new positions.*/
public void refresh() {
	for (int i = 0; i < jobAnimations.size(); i++) {
		JobAnimation ja = jobAnimations.get(i);
		//update position as time*speed
		ja.setPosition((System.currentTimeMillis() - ja.getTimeOfEntrance()) * ja.getSpeed());
		Point p = convertPositionToCoord(ja.getPosition());
		//tests if this job should be painted outside bounding box of this edge
		if (p != null) {
			boolean exceedsWidth = (p.getX() >= bounds.x + bounds.width), exceedsHeight = (p.getY() >= bounds.y + bounds.height);
			if (exceedsWidth || exceedsHeight) {
				routeJob(ja);
			}
			//set bounds of the job in order to be centered to the coords.
			Rectangle r = ja.getBounds();
			p.setLocation(p.getX() - r.getWidth() / 2, p.getY() - r.getHeight() / 2);
			r.setLocation(p);
		} else {
			routeJob(ja);
		}
	}
}
 
Example 5
Project: incubator-netbeans   File: CheckListener.java   View Source Code Vote up 5 votes
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
 
Example 6
Project: incubator-netbeans   File: ToolbarConfiguration.java   View Source Code Vote up 5 votes
/**
 * @param screenLocation
 * @return Toolbar row at given screen location or null.
 */
ToolbarRow getToolbarRowAt( Point screenLocation ) {
    Rectangle bounds = new Rectangle();
    for( ToolbarRow row : rows ) {
        bounds = row.getBounds(bounds);
        if( row.isShowing() ) {
            bounds.setLocation(row.getLocationOnScreen());
            if( bounds.contains(screenLocation) )
                return row;
        }
    }
    return null;
}
 
Example 7
Project: openjdk-jdk10   File: XContentWindow.java   View Source Code Vote up 5 votes
void setContentBounds(WindowDimensions dims) {
    XToolkit.awtLock();
    try {
        // Bounds of content window are of the same size as bounds of Java window and with
        // location as -(insets)
        Rectangle newBounds = dims.getBounds();
        Insets in = dims.getInsets();
        if (in != null) {
            newBounds.setLocation(-in.left, -in.top);
        }
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
            insLog.fine("Setting content bounds {0}, old bounds {1}",
                        newBounds, getBounds());
        }
        // Fix for 5023533:
        // Change in the size of the content window means, well, change of the size
        // Change in the location of the content window means change in insets
        boolean needHandleResize = !(newBounds.equals(getBounds()));
        boolean needPaint = width <= 0 || height <= 0;
        reshape(newBounds);
        if (needHandleResize) {
            insLog.fine("Sending RESIZED");
            handleResize(newBounds);
        }
        if (needPaint) {
            postPaintEvent(target, 0, 0, newBounds.width, newBounds.height);
        }
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 8
Project: Pogamut3   File: DnDMoveProvider.java   View Source Code Vote up 5 votes
/**
 * Find widget that contains point <tt>center</tt>.
 *
 * @param center
 * @return widget that contains the center or null if no such widget exists.
 */
private PoshWidget<? extends PoshElement> findContainingWidget(Point center) {

    for (Widget widget : scene.getPoshWidgets()) {
        Rectangle rect = (Rectangle) widget.getClientArea().clone();
        rect.setLocation(widget.getLocation());

        if (rect.contains(center) && widget instanceof PoshWidget) {
            return (PoshWidget<? extends PoshElement>) widget;
        }
    }
    return null;
}
 
Example 9
Project: jmt   File: Mediator.java   View Source Code Vote up 5 votes
private void repositionSons(JmtCell padre, List<Object> sons, int numero, int cont) {
	inRepositionSons = true;
	Object[] listEdges = null;
	GraphModel graphmodel = graph.getModel();

	flag1 = true;

	int j = 0;
	Rectangle boundspadre = GraphConstants.getBounds(padre.getAttributes()).getBounds();
	int w = boundspadre.y + ((heightMax + 35) * (numero + 1)) - 38;

	for (int i = cont; i < sons.size(); i++) {
		if (((JmtCell) sons.get(i)).seen == false) {
			Rectangle bounds = GraphConstants.getBounds(((JmtCell) sons.get(i)).getAttributes()).getBounds();
			bounds.setLocation((int) (boundspadre.getCenterX()) + widthMax + 50 - (int) (bounds.getWidth() / 2),
					w - (int) (bounds.getHeight() / 2) + 80);
			GraphConstants.setBounds(((JmtCell) sons.get(i)).getAttributes(), bounds);

			((JmtCell) sons.get(i)).seen = true;
			listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, sons.get(i));

			if (listEdges.length > 0) {
				flag = true;
				j = searchNext((JmtCell) sons.get(i));
				inRepositionSons = true;
			}

			if (j > 0) {
				j = j - 1;
			}

			listEdges = null;
		}

		w = w + (heightMax + ((heightMax + 15) * j) + 30);
		j = 0;
	}

	inRepositionSons = false;
}
 
Example 10
Project: OpenJSharp   File: XContentWindow.java   View Source Code Vote up 5 votes
void setContentBounds(WindowDimensions dims) {
    XToolkit.awtLock();
    try {
        // Bounds of content window are of the same size as bounds of Java window and with
        // location as -(insets)
        Rectangle newBounds = dims.getBounds();
        Insets in = dims.getInsets();
        if (in != null) {
            newBounds.setLocation(-in.left, -in.top);
        }
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
            insLog.fine("Setting content bounds {0}, old bounds {1}",
                        newBounds, getBounds());
        }
        // Fix for 5023533:
        // Change in the size of the content window means, well, change of the size
        // Change in the location of the content window means change in insets
        boolean needHandleResize = !(newBounds.equals(getBounds()));
        reshape(newBounds);
        if (needHandleResize) {
            insLog.fine("Sending RESIZED");
            handleResize(newBounds);
        }
    } finally {
        XToolkit.awtUnlock();
    }
    validateSurface();
}
 
Example 11
Project: ObsidianSuite   File: EntitySetupController.java   View Source Code Vote up 5 votes
public boolean hoverCheckRequired() {
	Point mousePos = MouseInfo.getPointerInfo().getLocation();
	Rectangle bounds = frame.getBounds();
	try {
		bounds.setLocation(frame.getLocationOnScreen());
	}
	catch(Exception e) {
		return false;
	}
	return !bounds.contains(mousePos);
}
 
Example 12
Project: sumo   File: MultiThumbSlider.java   View Source Code Vote up 5 votes
public void setThumbLocationAt(int x, int y, int index) {
    Rectangle rect = thumbRects[index];
    unionRect.setBounds(rect);

    rect.setLocation(x, y);
    SwingUtilities.computeUnion(rect.x, rect.y, rect.width, rect.height,
            unionRect);
    mSlider.repaint(unionRect.x, unionRect.y, unionRect.width,
            unionRect.height);
}
 
Example 13
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 14
Project: incubator-netbeans   File: TabbedSlideAdapter.java   View Source Code Vote up 4 votes
@Override
public Rectangle getTabsArea() {
    Rectangle res = slideBar.getBounds();
    res.setLocation( 0, 0 );
    return res;
}
 
Example 15
Project: jmt   File: Mediator.java   View Source Code Vote up 4 votes
private int searchNext(JmtCell prev) {
	Rectangle boundspadre = GraphConstants.getBounds((prev).getAttributes()).getBounds();
	Object[] listEdges = null;
	GraphModel graphmodel = graph.getModel();
	List<Object> next = new ArrayList<Object>();

	if (flag1 == false && prev.seen == false) {
		if (!flag2) {
			boundspadre.setLocation(x, y + ((e + 1) * (42 + heightMax)) - (int) (boundspadre.getHeight() / 2) + 30);
		} else {
			boundspadre.setLocation(x - (int) (boundspadre.getWidth() / 2), y + ((e + 1) * (42 + heightMax))
					- (int) (boundspadre.getHeight() / 2) + 30);
		}

		GraphConstants.setBounds(prev.getAttributes(), boundspadre);
		x = (int) boundspadre.getCenterX() + widthMax + 50;
		prev.seen = true;
		flag2 = true;
	}

	listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, prev);
	Vector<Object> listEdgestmp = new Vector<Object>();
	for (Object listEdge : listEdges) {
		JmtCell qq = (JmtCell) (graphmodel.getParent(graphmodel.getTarget(listEdge)));
		if (!(qq).seen) {
			listEdgestmp.add(listEdge);
		}
	}
	listEdges = listEdgestmp.toArray();

	int numTarget = listEdges.length;
	if (numTarget == 0) {
		return 1;
	}

	for (int k = 0; k < numTarget; k++) {
		next.add((graphmodel.getParent(graphmodel.getTarget(listEdges[k]))));
	}

	int j = 1;
	if (inRepositionSons == false && ((JmtCell) next.get(0)).seen == false) {
		j = searchNext((JmtCell) next.get(0));
	} else if (inRepositionSons == true && ((JmtCell) next.get(0)).seen == false) {
		Rectangle bounds = GraphConstants.getBounds(((JmtCell) next.get(0)).getAttributes()).getBounds();
		bounds.setLocation((int) (boundspadre.getCenterX()) + widthMax + 50 - (int) (bounds.getWidth() / 2),
				(int) boundspadre.getCenterY() - (int) (bounds.getHeight() / 2));
		GraphConstants.setBounds(((JmtCell) next.get(0)).getAttributes(), bounds);

		((JmtCell) next.get(0)).seen = true;
		j = searchNext((JmtCell) next.get(0));
	}

	if (numTarget > 0) {
		if (!flag) {
			repositionSons(prev, next, j - 1, 1);
		} else {
			repositionSons(prev, next, -1, 0);
		}
		flag = false;
	}

	(prev).sons = 0;
	for (int w = 0; w < numTarget; w++) {
		prev.sons += ((JmtCell) next.get(w)).sons;
	}

	return prev.sons;
}
 
Example 16
Project: VASSAL-src   File: HandMetrics.java   View Source Code Vote up 4 votes
protected void nextPosition(Point currentPos, Rectangle currentBounds, Point nextPos, Rectangle nextBounds, int dx, int dy) {
  int x = currentPos.x + currentBounds.width + dx;
  int y = currentPos.y;
  nextBounds.setLocation(x, y);
  nextPos.setLocation(x, y);
}
 
Example 17
Project: VASSAL-src   File: Map.java   View Source Code Vote up 4 votes
/**
 * Repaint the given area, specified in map coordinates
 */
public void repaint(Rectangle r) {
  r.setLocation(componentCoordinates(new Point(r.x, r.y)));
  r.setSize((int) (r.width * getZoom()), (int) (r.height * getZoom()));
  theMap.repaint(r.x, r.y, r.width, r.height);
}
 
Example 18
Project: QN-ACTR-Release   File: Mediator.java   View Source Code Vote up 4 votes
private int searchNext(JmtCell prev) {
	Rectangle boundspadre = GraphConstants.getBounds((prev).getAttributes()).getBounds();
	Object[] listEdges = null;
	GraphModel graphmodel = graph.getModel();
	List<Object> next = new ArrayList<Object>();

	if (flag1 == false && prev.seen == false) {

		// Rectangle bounds =
		// GraphConstants.getBounds(((JmtCell)prev).getAttributes()).getBounds();
		if (!flag2) {
			boundspadre.setLocation(x, y + ((e + 1) * (42 + heightMax)) - (int) (boundspadre.getHeight() / 2) + 30);
		} else {
			boundspadre.setLocation(x - (int) (boundspadre.getWidth() / 2), y + ((e + 1) * (42 + heightMax))
					- (int) (boundspadre.getHeight() / 2) + 30);
		}

		GraphConstants.setBounds(prev.getAttributes(), boundspadre);
		x = (int) boundspadre.getCenterX() + widthMax + 50;
		prev.seen = true;
		flag2 = true;
	}

	// inserisco tutti gli archi uscenti e entranti di min.get(j) in
	// listEdges
	listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, prev);
	Vector<Object> listEdgestmp = new Vector<Object>();
	for (Object listEdge : listEdges) {
		JmtCell qq = (JmtCell) (graphmodel.getParent(graphmodel.getTarget(listEdge)));
		if (!(qq).seen) {
			listEdgestmp.add(listEdge);
		}
	}
	listEdges = listEdgestmp.toArray();

	int numTarget = listEdges.length;
	if (numTarget == 0) {
		return 1;
	}

	for (int k = 0; k < numTarget; k++) {
		next.add((graphmodel.getParent(graphmodel.getTarget(listEdges[k]))));
	}

	int j = 1;
	if (inRepositionSons == false && ((JmtCell) next.get(0)).seen == false) {
		j = searchNext((JmtCell) next.get(0));
	} else if (inRepositionSons == true && ((JmtCell) next.get(0)).seen == false) {

		Rectangle bounds = GraphConstants.getBounds(((JmtCell) next.get(0)).getAttributes()).getBounds();
		bounds.setLocation((int) (boundspadre.getCenterX()) + widthMax + 50 - (int) (bounds.getWidth() / 2), (int) boundspadre.getCenterY()
				- (int) (bounds.getHeight() / 2));
		GraphConstants.setBounds(((JmtCell) next.get(0)).getAttributes(), bounds);

		((JmtCell) next.get(0)).seen = true;
		j = searchNext((JmtCell) next.get(0));
	}

	if (numTarget > 0) {
		if (!flag) {
			repositionSons(prev, next, j - 1, 1);
		} else {
			repositionSons(prev, next, -1, 0);
		}
		flag = false;
	}

	(prev).sons = 0;
	for (int w = 0; w < numTarget; w++) {
		prev.sons += ((JmtCell) next.get(w)).sons;
	}

	return prev.sons;
}
 
Example 19
Project: QN-ACTR-Release   File: Mediator.java   View Source Code Vote up 4 votes
private void repositionSons(JmtCell padre, List<Object> sons, int numero, int cont) {
	inRepositionSons = true;
	Object[] listEdges = null;
	GraphModel graphmodel = graph.getModel();

	flag1 = true;

	int j = 0;
	Rectangle boundspadre = GraphConstants.getBounds(padre.getAttributes()).getBounds();
	int w = boundspadre.y + ((heightMax + 35) * (numero + 1)) - 38;

	for (int i = cont; i < sons.size(); i++) {

		if (((JmtCell) sons.get(i)).seen == false) {

			Rectangle bounds = GraphConstants.getBounds(((JmtCell) sons.get(i)).getAttributes()).getBounds();
			bounds.setLocation((int) (boundspadre.getCenterX()) + widthMax + 50 - (int) (bounds.getWidth() / 2), w
					- (int) (bounds.getHeight() / 2) + 80);

			GraphConstants.setBounds(((JmtCell) sons.get(i)).getAttributes(), bounds);
			((JmtCell) sons.get(i)).seen = true;

			listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, sons.get(i));

			if (listEdges.length > 0) {
				flag = true;

				j = searchNext((JmtCell) sons.get(i));
				inRepositionSons = true;
			}

			if (j > 0) {
				j = j - 1;
			}

			listEdges = null;
		}

		w = w + (heightMax + ((heightMax + 15) * j) + 30);
		j = 0;
	}

	inRepositionSons = false;
}
 
Example 20
Project: Pixie   File: ObjectBBox.java   View Source Code Vote up 2 votes
/**
 * Moves one box with the specified offset.
 *
 * @param xOffset    - how much should the object move on the X axis
 * @param yOffset    - how much the object should move on the Y axis
 * @param boxPosOrig - the initial position of the selected box in image coordinates
 */
public void moveBox(int xOffset, int yOffset, Rectangle boxPosOrig) {

    boxPosOrig.setLocation(boxPosOrig.x + xOffset, boxPosOrig.y + yOffset);
}