/** * Updates the map's viewport's viewing rectangle * * @param playerCoords Player's coordinates */ public void updateCurrentView(Coord playerCoords) { int x = (playerCoords.getX() * ImageBank.FEATUREWIDTH) - (viewPort.getWidth() >>> 1); int y = ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT) - ((playerCoords.getY() * ImageBank.FEATUREHEIGHT) + (viewPort.getHeight() >>> 1)); if (x < 0) x = 0; if (x > (currentScreen.getWidth() - viewPort.getWidth())) x = (currentScreen.getWidth() - viewPort.getWidth()); if (y < 0) y = 0; if (y > (currentScreen.getHeight() - viewPort.getHeight())) y = (currentScreen.getHeight() - viewPort.getHeight()); viewPort.setViewPosition(new Point(x, y)); }
/** {@inheritDoc} */ @Override public void mouseDragged(final MouseEvent aEvent) { final MouseEvent event = convertEvent(aEvent); final Point point = event.getPoint(); // Update the selected channel while dragging... this.controller.setSelectedChannel(point); if (getModel().isCursorMode() && (this.movingCursor >= 0)) { this.controller.moveCursor(this.movingCursor, getCursorDropPoint(point)); aEvent.consume(); } else { if ((this.lastClickPosition == null) && ((aEvent.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)) { this.lastClickPosition = new Point(point); } final JScrollPane scrollPane = getAncestorOfClass(JScrollPane.class, (Component) aEvent.getSource()); if ((scrollPane != null) && (this.lastClickPosition != null)) { final JViewport viewPort = scrollPane.getViewport(); final Component signalView = this.controller.getSignalDiagram().getSignalView(); boolean horizontalOnly = (aEvent.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0; boolean verticalOnly = horizontalOnly && ((aEvent.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0); int dx = aEvent.getX() - this.lastClickPosition.x; int dy = aEvent.getY() - this.lastClickPosition.y; Point scrollPosition = viewPort.getViewPosition(); int newX = scrollPosition.x; if (!verticalOnly) { newX -= dx; } int newY = scrollPosition.y; if (verticalOnly || !horizontalOnly) { newY -= dy; } int diagramWidth = signalView.getWidth(); int viewportWidth = viewPort.getWidth(); int maxX = diagramWidth - viewportWidth - 1; scrollPosition.x = Math.max(0, Math.min(maxX, newX)); int diagramHeight = signalView.getHeight(); int viewportHeight = viewPort.getHeight(); int maxY = diagramHeight - viewportHeight; scrollPosition.y = Math.max(0, Math.min(maxY, newY)); viewPort.setViewPosition(scrollPosition); } // Use UNCONVERTED/ORIGINAL mouse event! handleZoomRegion(aEvent, this.lastClickPosition); } }
/** Scrolls the viewport according to the fake cursor position in the preview popup menu. */ private void scrollViewPort() { Point cursorLocation = _cursorLabel.getLocation(); int dx = (int) Math.max(cursorLocation.getX(), 0); int dy = (int) Math.max(cursorLocation.getY(), 0); dx = (int) (dx * _ratio); dy = (int) (dy * _ratio); ((JComponent) _viewPort.getComponent(0)) .scrollRectToVisible(new Rectangle(dx, dy, _viewPort.getWidth(), _viewPort.getHeight())); }
public Component getTableCellEditorComponent( final JTable table, final Object value, final boolean isSelected, final int row, final int column) { final String boundaryString; if (value instanceof PropertyMap) { final PropertyMap map = (PropertyMap) value; boundaryString = map.getPropertyString(KEY_BOUNDARY_PATH, null); } else { boundaryString = null; } final GeneralPath[] geoBoundaryPathes = createGeoBoundaryPathes(boundaryString); if (geoBoundaryPathes.length > 0) { wmPainter.setWorldMapImage(scaledImage); final BufferedImage worldMapImage = wmPainter.createWorldMapImage(geoBoundaryPathes); scrollPane.setViewportView(new JLabel(new ImageIcon(worldMapImage))); final Color backgroundColor = table.getSelectionBackground(); scrollPane.setBorder(BorderFactory.createLineBorder(backgroundColor, 3)); scrollPane.setBackground(backgroundColor); // todo: first time scrolling is not good, cause the viewRect has no width and height at // this time // hack: this is not good, there might be a better solution final JViewport viewport = scrollPane.getViewport(); if (viewport.getWidth() == 0 && viewport.getHeight() == 0) { viewport.setSize( table.getColumnModel().getColumn(column).getWidth(), table.getRowHeight(row)); } scrollToCenterPath(geoBoundaryPathes[0], viewport); return scrollPane; } else { return null; } }
/** * @see * com.seaglasslookandfeel.painter.ViewportPainter#paintViewport(com.seaglasslookandfeel.SeaGlassContext, * java.awt.Graphics, javax.swing.JViewport) */ public void paintViewport(SeaGlassContext context, Graphics g, JViewport c) { paintStripesAndGrid(context, g, c, c.getWidth(), c.getHeight(), table.getLocation().y); }
/** * By default, the right corner of a popup menu is positionned at the right of a mouse click. What * we want is to have the preview popup menu positionned <i>inside</i> the scroll pane, near the * corner component. The purpose of this method is to display the scaled image of the component of * the scroll pane, and to calculate the correct position of the preview popup menu. */ public void showUpInCorner(Component c, String corner) { if (_viewPort.getComponentCount() == 0) return; float scaleFactor = 1.1f; // _viewPort.getComponent( 0 ).getHeight() / // _scrollPane.getHeight() * 2; // if (_viewPort.getWidth() < (_viewPort.getHeight() * scaleFactor)) // _ratio =( int ) ( _viewPort.getComponent(0).getWidth() / // (_viewPort.getWidth() / scaleFactor) ); // // else // _ratio = ( int ) (( _viewPort.getComponent(0).getHeight() / // (_viewPort.getHeight()) / scaleFactor )); _ratio = (((float) _viewPort.getComponent(0).getHeight() / ((float) _viewPort.getHeight()) / scaleFactor)); if (_ratio < 2) _ratio = 2; // System.out.println( "ratio = " + _ratio ); int zoomWindowImageWidth = (int) (_viewPort.getComponent(0).getWidth() / _ratio); if (zoomWindowImageWidth < 10) { UISupport.showInfoMessage("Viewport too large for readable image, use scrollbar instead"); return; } int zoomWindowImageHeight = (int) (_viewPort.getComponent(0).getHeight() / _ratio); // System.out.println( "ratio = " + _ratio + ", zoomWindowImageWidth = " + // zoomWindowImageWidth + // ", zoomWindowImageHeight = " + zoomWindowImageHeight); /* * Image componentImage = * captureComponentViewAsBufferedImage(_viewPort.getComponent(0)) * .getScaledInstance( zoomWindowImageWidth, zoomWindowImageHeight, * Image.SCALE_SMOOTH); */ /* * Based on Shannon Hickey's comments. This is much faster way to scale * instance Thanks! Shannon */ Image capture = captureComponentViewAsBufferedImage(_viewPort.getComponent(0)); Image componentImage = new BufferedImage(zoomWindowImageWidth, zoomWindowImageHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) componentImage.getGraphics(); /* if you want smoother scaling */ if (zoomWindowImageWidth > 15) g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.drawImage(capture, 0, 0, zoomWindowImageWidth, zoomWindowImageHeight, null); g2d.dispose(); // Converts the Image to an ImageIcon to be used with a JLabel. ImageIcon componentIcon = new ImageIcon(componentImage); _iconWidth = componentIcon.getIconWidth(); _iconHeight = componentIcon.getIconHeight(); _zoomWindow.setIcon(componentIcon); _zoomWindow.setBounds(0, 0, _iconWidth, _iconHeight); int cursorWidth = (int) (_viewPort.getWidth() / _ratio); int cursorHeight = (int) (_viewPort.getHeight() / _ratio); _cursorLabel.setBounds(0, 0, cursorWidth, cursorHeight); _layeredPane.setPreferredSize(new Dimension(_iconWidth, _iconHeight)); int dx = componentIcon.getIconWidth() + DELTA; int dy = componentIcon.getIconHeight() + DELTA; if (corner.equals(JScrollPane.UPPER_LEFT_CORNER)) ; else if (corner.equals(JScrollPane.UPPER_RIGHT_CORNER)) dx = -dx; else if (corner.equals(JScrollPane.LOWER_RIGHT_CORNER)) { dx = -dx; dy = -dy; } else if (corner.equals(JScrollPane.LOWER_LEFT_CORNER)) dy = -dy; if (dy < 0 && Math.abs(dy) > _viewPort.getHeight()) { dy = -_viewPort.getHeight() - 10; } // System.out.println( "Showing at " + dx + ", " + dy ); // Shows the popup menu at the right place. this.show(c, dx, dy); }