public void scrollToAttribute(Attribute a) { if (!a.getDescriptor().getConfig().equals(getConfig())) { logger.fine("Cannot scroll to attribute that isn't attached to this type of descriptor"); return; } int rowIndex = getCurrentModel().getRowForDescriptor(a.getDescriptor()); int colIndex = getCurrentModel().getColumnForAttribute(a); JScrollPane scrollPane = (JScrollPane) this.getComponent(0); JViewport viewport = (JViewport) scrollPane.getViewport(); EnhancedTable table = (EnhancedTable) viewport.getView(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(rowIndex, colIndex, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); // Scroll the area into view viewport.scrollRectToVisible(rect); }
@Override protected RelativePoint getPointToShowResults() { Rectangle rect = myEntryTable.getCellRect(myEntryTable.getSelectedRow(), 1, false); Point location = rect.getLocation(); location.y += rect.height; return new RelativePoint(myEntryTable, location); }
/** Enlarge the canvas if the user enlarges the window. */ void resizeCanvas(int width, int height) { ImageWindow win = imp.getWindow(); // IJ.log("resizeCanvas: "+srcRect+" "+imageWidth+" "+imageHeight+" "+width+" "+height+" // "+dstWidth+" "+dstHeight+" "+win.maxBounds); if (!maxBoundsReset && (width > dstWidth || height > dstHeight) && win != null && win.maxBounds != null && width != win.maxBounds.width - 10) { if (resetMaxBoundsCount != 0) resetMaxBounds(); // Works around problem that prevented window from being larger than // maximized size resetMaxBoundsCount++; } if (IJ.altKeyDown()) { fitToWindow(); return; } if (srcRect.width < imageWidth || srcRect.height < imageHeight) { if (width > imageWidth * magnification) width = (int) (imageWidth * magnification); if (height > imageHeight * magnification) height = (int) (imageHeight * magnification); setDrawingSize(width, height); srcRect.width = (int) (dstWidth / magnification); srcRect.height = (int) (dstHeight / magnification); if ((srcRect.x + srcRect.width) > imageWidth) srcRect.x = imageWidth - srcRect.width; if ((srcRect.y + srcRect.height) > imageHeight) srcRect.y = imageHeight - srcRect.height; repaint(); } // IJ.log("resizeCanvas2: "+srcRect+" "+dstWidth+" "+dstHeight+" "+width+" "+height); }
protected RelativePoint getPointToShowResults() { final int selectedRow = myTree.getSelectionRows()[0]; final Rectangle rowBounds = myTree.getRowBounds(selectedRow); final Point location = rowBounds.getLocation(); location.x += rowBounds.width; return new RelativePoint(myTree, location); }
private void recalculateMaxValues() { myIdxLeft = widestEditor(myLeftEditors); final Editor leftEditor = myLeftEditors.get(myIdxLeft); final int wholeWidth = leftEditor.getContentComponent().getWidth(); final Rectangle va = leftEditor.getScrollingModel().getVisibleArea(); final int visibleLeft = leftEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsLeft = (int) (visibleLeft * ((double) wholeWidth / va.getWidth())); myIdxRight = widestEditor(myRightEditors); final Editor rightEditor = myRightEditors.get(myIdxRight); final int wholeWidthRight = rightEditor.getContentComponent().getWidth(); final Rectangle vaRight = rightEditor.getScrollingModel().getVisibleArea(); final int visibleRight = rightEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsRight = (int) (visibleRight * ((double) wholeWidthRight / vaRight.getWidth())); myByLeft = !(myMaxColumnsLeft <= visibleLeft); if (!myByLeft) { // check right editor if (myLeftScroll.getVisibleAmount() != visibleRight) { myLeftScroll.setVisibleAmount(visibleRight); } myLeftScroll.setMaximum(myMaxColumnsRight); } else { if (myLeftScroll.getVisibleAmount() != visibleLeft) { myLeftScroll.setVisibleAmount(visibleLeft); } myLeftScroll.setMaximum(myMaxColumnsLeft); } }
private BeforeAfter<Integer> getEditorLines() { final Editor editor = ((DiffPanelImpl) getCurrentPanel()).getEditor1(); Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int offset = editor.getScrollingModel().getVerticalScrollOffset(); int leftPixels = offset % editor.getLineHeight(); final Point start = visibleArea.getLocation(); final LogicalPosition startLp = editor.xyToLogicalPosition(start); final Point location = new Point(start.x + visibleArea.width, start.y + visibleArea.height); final LogicalPosition lp = editor.xyToLogicalPosition(location); int curStartLine = startLp.line == (editor.getDocument().getLineCount() - 1) ? startLp.line : (startLp.line + 1); int cutEndLine = lp.line == 0 ? 0 : lp.line - 1; boolean commonPartOk = leftPixels == 0 || startLp.line == lp.line; return new BeforeAfter<Integer>( commonPartOk && startLp.softWrapLinesOnCurrentLogicalLine == 0 ? startLp.line : curStartLine, commonPartOk && lp.softWrapLinesOnCurrentLogicalLine == 0 ? lp.line : cutEndLine); /*if (leftPixels == 0 || startLp.line == lp.line) { return new BeforeAfter<Integer>(startLp.line, lp.line); } else { return new BeforeAfter<Integer>(curStartLine, cutEndLine); }*/ }
public TabSpawnable spawn() { JFrame f = new JFrame(); f.getContentPane().setLayout(new BorderLayout()); f.setTitle(_title); TabSpawnable newPanel = (TabSpawnable) clone(); if (newPanel == null) return null; // failed to clone newPanel.setTitle(_title); if (newPanel instanceof TabToDoTarget) { TabToDoTarget me = (TabToDoTarget) this; TabToDoTarget it = (TabToDoTarget) newPanel; it.setTarget(me.getTarget()); } else if (newPanel instanceof TabModelTarget) { TabModelTarget me = (TabModelTarget) this; TabModelTarget it = (TabModelTarget) newPanel; it.setTarget(me.getTarget()); } f.getContentPane().add(newPanel, BorderLayout.CENTER); Rectangle bounds = getBounds(); bounds.height += OVERLAPP * 2; f.setBounds(bounds); Point loc = new Point(0, 0); SwingUtilities.convertPointToScreen(loc, this); loc.y -= OVERLAPP; f.setLocation(loc); f.setVisible(true); if (_tear && (getParent() instanceof JTabbedPane)) ((JTabbedPane) getParent()).remove(this); return newPanel; }
// ------------------------------ public void scrollToCaret() { // not called - fixed with putting visible scrollbars on JScrollPane // Rectangle rect1 = scroller1.getViewport().getViewRect(); double x1 = rect1.getX(); double y1 = rect1.getY(); double r1height = rect1.getHeight(); double r1width = rect1.getWidth(); Caret caret1 = editor1.getCaret(); Point pt2 = caret1.getMagicCaretPosition(); // the end of the string double x2 = pt2.getX(); double y2 = pt2.getY(); if (((x2 > x1) && (x2 < (x1 + r1width))) && ((y2 > y1) && (y2 < (y1 + r1height)))) { // inview } else { double newheight = r1height / 2; double newwidth = r1width / 2; double x3 = pt2.getX() - newwidth; double y3 = pt2.getY() - newheight; if (x3 < 0) x3 = 0; if (y3 < 0) y3 = 0; Rectangle rect3 = new Rectangle((int) x3, (int) y3, (int) newwidth, (int) newheight); editor1.scrollRectToVisible(rect3); } } // end scrollToCaret
private static Point fixPopupLocation(final Component contents, final int x, final int y) { if (!(contents instanceof JToolTip)) return new Point(x, y); final PointerInfo info; try { info = MouseInfo.getPointerInfo(); } catch (InternalError e) { // http://www.jetbrains.net/jira/browse/IDEADEV-21390 // may happen under Mac OSX 10.5 return new Point(x, y); } int deltaY = 0; if (info != null) { final Point mouse = info.getLocation(); deltaY = mouse.y - y; } final Dimension size = contents.getPreferredSize(); final Rectangle rec = new Rectangle(new Point(x, y), size); ScreenUtil.moveRectangleToFitTheScreen(rec); if (rec.y < y) { rec.y += deltaY; } return rec.getLocation(); }
/** * Paint to an offscreen graphic, e.g. a graphic for an image or svg file. * * @param g * @param rect */ public void paintOffscreen(Graphics2D g, Rectangle rect) { // Get the components of the sort by X position. Component[] components = getComponents(); Arrays.sort( components, new Comparator<Component>() { public int compare(Component component, Component component1) { return component.getX() - component1.getX(); } }); for (Component c : this.getComponents()) { if (c instanceof DataPanel) { Graphics2D g2d = (Graphics2D) g.create(); Rectangle clipRect = new Rectangle(c.getBounds()); clipRect.height = rect.height; g2d.setClip(clipRect); g2d.translate(c.getX(), 0); ((DataPanel) c).paintOffscreen(g2d, rect); } } // super.paintBorder(g); }
/** Este metodo ubica los componentes del SlotMachine en sus ubicaciones por defecto */ private void presentacion() { marco.changeColor("black"); marco.changeSize(50, 50 * casillas); marco.moveHorizontal(5); marco.moveVertical(5); /*ganador.moveVertical(10); ganador.moveHorizontal(10); ganador.moveHorizontal(50*(casillas/2)); ganador.moveVertical(50);*/ for (int i = 0; i < casillas; i++) { cubiculo[i] = new Rectangle(); opcion[i] = new Circle(); } for (int i = 0; i < casillas; i++) { cubiculo[i].changeSize(40, 40); cubiculo[i].changeColor("white"); cubiculo[i].moveHorizontal(10); cubiculo[i].moveVertical(10); cubiculo[i].moveHorizontal(50 * i); opcion[i].changeSize(40); opcion[i].moveHorizontal(10); opcion[i].moveVertical(10); opcion[i].moveHorizontal(50 * i); opcion[i].changeColor(colores[dados[i]]); } }
public Point getEmptyPosition(Dimension spriteSize) { Rectangle trialSpaceOccupied = new Rectangle(0, 0, spriteSize.width, spriteSize.height); Random rand = new Random(System.currentTimeMillis()); boolean empty = false; int numTries = 0; // Search for an empty position while (!empty && numTries++ < 100) { // Get a trial position trialSpaceOccupied.x = Math.abs(rand.nextInt() % backgroundImage.getSize().width); trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage.getSize().height); // Iterate through existing // sprites, checking if position // is empty boolean collision = false; for (int cnt = 0; cnt < size(); cnt++) { Rectangle testSpaceOccupied = ((Sprite) elementAt(cnt)).getSpaceOccupied(); if (trialSpaceOccupied.intersects(testSpaceOccupied)) { collision = true; } // end if } // end for loop empty = !collision; } // end while loop return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y); } // end getEmptyPosition()
protected void updateHoverHandles(@Nullable DrawingView view, @Nullable Figure f) { if (f != hoverFigure) { Rectangle r = null; if (hoverFigure != null && hoverFigure.isSelectable()) { for (Handle h : hoverHandles) { if (r == null) { r = h.getDrawingArea(); } else { r.add(h.getDrawingArea()); } h.setView(null); h.dispose(); } hoverHandles.clear(); } hoverFigure = f; if (hoverFigure != null) { hoverHandles.addAll(hoverFigure.createHandles(-1)); for (Handle h : hoverHandles) { h.setView(view); if (r == null) { r = h.getDrawingArea(); } else { r.add(h.getDrawingArea()); } } } if (r != null) { r.grow(1, 1); fireAreaInvalidated(r); } } }
public void zoomIn() { Dimension asz = this.getSize(); int maxzf = 3; int coef = 1; int r; cmdline = "/bin/sh get.sh " + j2kfilename + " " + iw + " " + ih + " " + rect.x + " " + rect.y + " " + rect.width + " " + rect.height; Exec.execPrint(cmdline); rect.x = rect.y = rect.width = rect.height = 0; img = pgm.open("out.pgm"); iw = img.getWidth(this); ih = img.getHeight(this); bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); big = bi.createGraphics(); selected = 0; fullRefresh = true; repaint(); }
/** * Overrides Step getBounds method. * * @param trackerPanel the tracker panel drawing the step * @return the bounding rectangle */ public Rectangle getBounds(TrackerPanel trackerPanel) { Rectangle bounds = getMark(trackerPanel).getBounds(false); Rectangle layoutRect = layoutBounds.get(trackerPanel); if (layoutRect != null) { bounds.add(layoutRect); } return bounds; }
/* * Convert to global coordinates. */ Rectangle toGlobal(Rectangle rec) { Point p = toGlobal(rec.getLocation()); Rectangle newRec = new Rectangle(rec); if (p != null) { newRec.setLocation(p); } return newRec; }
/** Returns the coordinates of the top left corner of the value at the given index. */ public Point getCoordinates(int index) { JScrollBar bar = scrollPane.getVerticalScrollBar(); Rectangle r = pinsTable.getCellRect(index, 2, true); pinsTable.scrollRectToVisible(r); return new Point( (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY() - bar.getValue())); }
/** * Zooms out by making the source rectangle (srcRect) larger and centering it on (x,y). If we * can't make it larger, then make the window smaller. */ public void zoomOut(int x, int y) { if (magnification <= 0.03125) return; double oldMag = magnification; double newMag = getLowerZoomLevel(magnification); double srcRatio = (double) srcRect.width / srcRect.height; double imageRatio = (double) imageWidth / imageHeight; double initialMag = imp.getWindow().getInitialMagnification(); if (Math.abs(srcRatio - imageRatio) > 0.05) { double scale = oldMag / newMag; int newSrcWidth = (int) Math.round(srcRect.width * scale); int newSrcHeight = (int) Math.round(srcRect.height * scale); if (newSrcWidth > imageWidth) newSrcWidth = imageWidth; if (newSrcHeight > imageHeight) newSrcHeight = imageHeight; int newSrcX = srcRect.x - (newSrcWidth - srcRect.width) / 2; int newSrcY = srcRect.y - (newSrcHeight - srcRect.height) / 2; if (newSrcX < 0) newSrcX = 0; if (newSrcY < 0) newSrcY = 0; srcRect = new Rectangle(newSrcX, newSrcY, newSrcWidth, newSrcHeight); // IJ.log(newMag+" "+srcRect+" "+dstWidth+" "+dstHeight); int newDstWidth = (int) (srcRect.width * newMag); int newDstHeight = (int) (srcRect.height * newMag); setMagnification(newMag); setMaxBounds(); // IJ.log(newDstWidth+" "+dstWidth+" "+newDstHeight+" "+dstHeight); if (newDstWidth < dstWidth || newDstHeight < dstHeight) { // IJ.log("pack"); setDrawingSize(newDstWidth, newDstHeight); imp.getWindow().pack(); } else repaint(); return; } if (imageWidth * newMag > dstWidth) { int w = (int) Math.round(dstWidth / newMag); if (w * newMag < dstWidth) w++; int h = (int) Math.round(dstHeight / newMag); if (h * newMag < dstHeight) h++; x = offScreenX(x); y = offScreenY(y); Rectangle r = new Rectangle(x - w / 2, y - h / 2, w, h); if (r.x < 0) r.x = 0; if (r.y < 0) r.y = 0; if (r.x + w > imageWidth) r.x = imageWidth - w; if (r.y + h > imageHeight) r.y = imageHeight - h; srcRect = r; } else { srcRect = new Rectangle(0, 0, imageWidth, imageHeight); setDrawingSize((int) (imageWidth * newMag), (int) (imageHeight * newMag)); // setDrawingSize(dstWidth/2, dstHeight/2); imp.getWindow().pack(); } // IJ.write(newMag + " " + srcRect.x+" "+srcRect.y+" "+srcRect.width+" "+srcRect.height+" // "+dstWidth + " " + dstHeight); setMagnification(newMag); // IJ.write(srcRect.x + " " + srcRect.width + " " + dstWidth); setMaxBounds(); repaint(); }
private void drawMark(Graphics g, Polygon r) { g.setColor(Color.black); Rectangle rr = r.getBoundingBox(); rr.x += 3; rr.y += 3; rr.height -= 5; rr.width -= 6; drawRect(g, rr.x, rr.y, rr.width, rr.height); }
private static Rectangle fitToScreen( @NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) { Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim); ScreenUtil.fitToScreen(rectangle); if (rectangle.getHeight() != newDim.getHeight()) { int newHeight = (int) rectangle.getHeight(); int roundedHeight = newHeight - newHeight % table.getRowHeight(); rectangle.setSize((int) rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight())); } return rectangle; }
public void drawingInvalidated(DrawingChangeEvent e) { Rectangle r = e.getInvalidatedRectangle(); if (getDamage() == null) { setDamage(r); } else { // don't manipulate rectangle returned by getDamage() directly // because it could be a cloned rectangle. Rectangle damagedR = getDamage(); damagedR.add(r); setDamage(damagedR); } }
/** * Compute the bounds of the <code>Lite</code> objets. * * @return The bounding rectangle. */ public Rectangle getBounds() { if (lites.isEmpty()) return new Rectangle(); Enumeration e = elements(); Lite l = (Lite) e.nextElement(); Rectangle r = l.getBounds(); while (e.hasMoreElements()) { l = (Lite) e.nextElement(); r.add(l.getBounds()); } return r; }
/** * Adds the tile to the set, setting the id of the tile only if the current value of id is -1. * * @param t the tile to add * @return int The <b>local</b> id of the tile */ public int addTile(Tile t) { if (t.getId() < 0) t.setId(tiles.size()); if (tileDimensions.width < t.getWidth()) tileDimensions.width = t.getWidth(); if (tileDimensions.height < t.getHeight()) tileDimensions.height = t.getHeight(); tiles.add(t); t.setTileSet(this); return t.getId(); }
private void setSizeAndDimensions( @NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); // table.setPreferredSize(dimension); // table.setMaximumSize(dimension); // table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4 /* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
/** [Internal] */ public void paintComponent(Graphics g) { boolean opq = true; if (theOpaque != null) opq = theOpaque; super.setOpaque(opq); // if(theBackground!=null)super.setBackground(theBackground); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Rectangle rt = getBounds(); rt.x = 0; rt.y = 0; doBuffer(g2, opq, rt); chkFPS(); }
@Override public void mouseReleased(MouseEvent evt) { dragLocation = new Point(evt.getX(), evt.getY()); multicaster.trackEnd(anchor, dragLocation, evt.getModifiersEx(), getView()); // Note: we must not fire "Tool Done" in this method, because then we can not // listen to keyboard events for the handle. Rectangle r = new Rectangle(anchor.x, anchor.y, 0, 0); r.add(evt.getX(), evt.getY()); maybeFireBoundsInvalidated(r); dragLocation = null; }
/** * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>, * <code>nohref</code> Attribute for the specified figure and ellipse. * * @return Returns true, if the circle is inside of the image bounds. */ private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) { AffineTransform t = TRANSFORM.getClone(f); if (t == null) { t = drawingTransform; } else { t.preConcatenate(drawingTransform); } if ((t.getType() & (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) == t.getType() && ellipse.width == ellipse.height ) { Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y); Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height); t.transform(start, start); t.transform(end, end); ellipse.x = Math.min(start.x, end.x); ellipse.y = Math.min(start.y, end.y); ellipse.width = Math.abs(start.x - end.x); ellipse.height = Math.abs(start.y - end.y); elem.setAttribute("shape", "circle"); elem.setAttribute("coords", (int) (ellipse.x + ellipse.width / 2d)+","+ (int) (ellipse.y + ellipse.height / 2d)+","+ (int) (ellipse.width / 2d) ); writeHrefAttribute(elem, f); return bounds.intersects(ellipse.getBounds()); } else { return writePolyAttributes(elem, f, (Shape) ellipse); } }
public Rectangle getScreenViewableBounds(GraphicsDevice gd) { Rectangle bounds = new Rectangle(0, 0, 0, 0); if (gd != null) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); bounds = gc.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); } return bounds; }
public boolean mouseDrag(Event e, int x, int y) { if ((rubberBand == true) && (drawArea.inside(x, y))) { endX = x; endY = y; } // tracks mouse's movement else if (drawArea.inside(x, y)) { oldX = newX; oldY = newY; newX = x; newY = y; } repaint(); return true; }
public boolean isCollidingWith(SolidObject what) { // Test whether the collision between two solid objex is happening compileHull(); what.compileHull(); if (collisionHull.intersects(what.collisionHull)) return true; return false; }