List of usage examples for java.awt Rectangle intersects
public boolean intersects(Rectangle r)
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; super.paintComponent(g2d); g2d.setPaint(gridColor);// ww w. j a v a2 s .c o m Rectangle clipBounds = g.getClipBounds(); int[] indices = stripRangeForRect(clipBounds); int startIndex = indices[0]; int endIndex = indices[1]; Point p1, p2; p1 = new Point(); p2 = new Point(getWidth(), getHeight()); for (int i = startIndex; i <= endIndex; i++) { int gridLine = getGridLine(i); orientation.updateCoord(p1, gridLine); orientation.updateCoord(p2, gridLine); g2d.drawLine(p1.x, p1.y, p2.x, p2.y); } p1.setLocation(0, 0); p2.setLocation(getWidth(), getHeight()); int groupGridLine = 0; for (CategoryView v : groupings) { groupGridLine += v.size; orientation.opposite().updateCoord(p1, groupGridLine); orientation.opposite().updateCoord(p2, groupGridLine); g2d.drawLine(p1.x, p1.y, p2.x, p2.y); groupGridLine += GRID_SIZE; } for (int level = 0, levelCount = groupings.length; level < levelCount; level++) { for (HeaderCell cell : groupings[level].cells) { if (cell.endIndex < startIndex || cell.startIndex >= endIndex) continue; Rectangle rect = getRect(level, cell.startIndex, cell.endIndex); if (clipBounds != null && !clipBounds.intersects(rect)) continue; paintHeaderCell(g2d, rect, cell.levelValue); } } if (cellResizingRange != null) { Rectangle rect = new Rectangle(getWidth(), getHeight()); orientation.updateRange(rect, cellResizingRange); rect.grow(orientation.select(GRID_SIZE, 0), orientation.select(0, GRID_SIZE)); g2d.setColor(new Color(0x9999ff, false)); g2d.draw(rect); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); g2d.fill(rect); } }
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
private void paintHeaderCell(Graphics2D g2d, Rectangle rect, Object value) { Rectangle clipBounds = g2d.getClipBounds(); if (clipBounds != null && !clipBounds.intersects(rect)) return;/*w ww.j a va2 s. co m*/ boolean selected = (selectedValue != null && selectedValue.equals(value)); JComponent renderer = setupCellRenderer(value, selected); cellRendererPane.paintComponent(g2d, renderer, this, rect); cellRendererPane.remove(renderer); }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
@Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; Rectangle clipRect = g.getClipBounds(); Dimension compSize = getSize(); // columnCount = (int)(compSize.getWidth()/columnWidth); int photoCount = 0; if (photos != null) { photoCount = photos.size();//w ww . j av a2s. co m } // Determine the grid size based on couln & row count columnsToPaint = columnCount; // if columnCount is not specified determine it based on row count if (columnCount < 0) { if (rowCount > 0) { columnsToPaint = photoCount / rowCount; if (columnsToPaint * rowCount < photoCount) { columnsToPaint++; } } else { columnsToPaint = (int) (compSize.getWidth() / columnWidth); } } int col = 0; int row = 0; Rectangle thumbRect = new Rectangle(); for (PhotoInfo photo : photos) { thumbRect.setBounds(col * columnWidth, row * rowHeight, columnWidth, rowHeight); if (thumbRect.intersects(clipRect)) { if (photo != null) { paintThumbnail(g2, photo, col * columnWidth, row * rowHeight, selection.contains(photo)); } } col++; if (col >= columnsToPaint) { row++; col = 0; } } // Paint the selection rectangle if needed if (dragSelectionRect != null) { Stroke prevStroke = g2.getStroke(); Color prevColor = g2.getColor(); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.BLACK); g2.draw(dragSelectionRect); g2.setColor(prevColor); g2.setStroke(prevStroke); lastDragSelectionRect = dragSelectionRect; } }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
/** This method is called by background task scheduler when it is ready to execute a task for this window.//from ww w .j ava 2 s .c o m @return Task to create a thumbnail if one is needed. <code>null</code> otherwise. */ public BackgroundTask requestTask() { PhotoInfo nextPhoto = null; Container parent = getParent(); Rectangle viewRect = null; if (parent instanceof JViewport) { viewRect = ((JViewport) parent).getViewRect(); } // Walk through all photos until we find a photo that is visible // and does not have a thumbnail. If all visible photos have a thumbnail // but some non-visible ones do not, create a thumbnail for one of those. log.debug("Finding photo without thumbnail"); for (int n = 0; n < photos.size(); n++) { PhotoInfo photoCandidate = photos.get(n); log.debug("Photo " + photoCandidate.getUuid()); if (!photoCandidate.hasThumbnail()) { log.debug("No thumbnail"); Rectangle photoRect = getPhotoBounds(n); if (photoRect.intersects(viewRect)) { // This photo is visible so it is a perfect candidate // for thumbnail creation. Do not look further nextPhoto = photoCandidate; break; } else if (nextPhoto == null) { // Not visible but no photo without thumbnail has been // found previously. Store as a candidate and keep looking. nextPhoto = photoCandidate; } } } if (nextPhoto != null) { // We found a photo without thumbnail VolumeDAO volDAO = ctrl.getDAOFactory().getVolumeDAO(); Volume vol = volDAO.getDefaultVolume(); return new CreatePreviewImagesTask(nextPhoto); } // All photos have thumbnail :-) return null; }
From source file:pcgen.gui2.PCGenFrame.java
/** * This checks to make sure that the given rectangle will be visible * on the current graphics environment/*w w w. j a va2s .com*/ */ private boolean checkBounds(Rectangle rect) { if (rect.isEmpty()) { return false; } GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice device : env.getScreenDevices()) { Rectangle bounds = device.getDefaultConfiguration().getBounds(); if (bounds.contains(rect) || bounds.intersects(rect)) { return true; } } return false; }