예제 #1
0
  private int getCurrentLineCenter(FilePanel fp) {
    JScrollPane scrollPane;
    BufferDocumentIF bd;
    JTextComponent editor;
    JViewport viewport;
    int line;
    Rectangle rect;
    int offset;
    Point p;

    editor = fp.getEditor();
    scrollPane = fp.getScrollPane();
    viewport = scrollPane.getViewport();
    p = viewport.getViewPosition();
    offset = editor.viewToModel(p);

    // Scroll around the center of the editpane
    p.y += getHeightOffset(fp);

    offset = editor.viewToModel(p);
    bd = fp.getBufferDocument();
    if (bd == null) {
      return -1;
    }
    line = bd.getLineForOffset(offset);

    return line;
  }
예제 #2
0
  /**
   * Scales to the given zoom level, 1.0 being 100%, centered on the given point.
   *
   * @param level The level to zoom to.
   * @param center The center point for the scaling operation.
   * @return The new zoom level.
   */
  public float scaleTo(float level, Point2D center) {
    if (this.scrollPane == null) return 1.0f;
    float oldZoom = this.currentZoom;
    this.currentZoom = Math.max(minimumZoom, level);
    //		this.absoluteViewScaler.scale( this, level, center );
    Dimension viewSize;
    if (level < 1.0f) {
      viewSize = this.scrollPane.getSize();
    } else {
      viewSize = this.scrollPane.getViewport().getExtentSize();
    }
    Dimension newSize =
        new Dimension((int) (viewSize.width * currentZoom), (int) (viewSize.height * currentZoom));
    this.setPreferredSize(newSize);
    this.setSize(newSize);
    //		new LayoutScaler( this.getGraphLayout( )).setSize( newSize );
    if (Float.compare(level, 1.0f) <= 0) this.center();

    // translate the new view position so the mouse is in the same place
    // on the scaled view.
    JViewport vp = this.scrollPane.getViewport();
    double centerX = center.getX();
    double centerY = center.getY();
    double viewPortMouseX = centerX - vp.getViewPosition().getX();
    double viewPortMouseY = centerY - vp.getViewPosition().getY();
    centerX *= currentZoom / oldZoom;
    centerY *= currentZoom / oldZoom;
    viewPortMouseX = centerX - viewPortMouseX;
    viewPortMouseY = centerY - viewPortMouseY;
    vp.setViewPosition(new Point((int) viewPortMouseX, (int) viewPortMouseY));

    return this.currentZoom;
  }
예제 #3
0
  /*
   *  This method is called every time:
   *  - to make sure the viewport is returned to its default position
   *  - to remove the horizontal scrollbar when it is not wanted
   */
  private void checkHorizontalScrollBar(BasicComboPopup popup) {
    //  Reset the viewport to the left

    JViewport viewport = scrollPane.getViewport();
    Point p = viewport.getViewPosition();
    p.x = 0;
    viewport.setViewPosition(p);

    //  Remove the scrollbar so it is never painted

    if (!scrollBarRequired) {
      scrollPane.setHorizontalScrollBar(null);
      return;
    }

    //	Make sure a horizontal scrollbar exists in the scrollpane

    JScrollBar horizontal = scrollPane.getHorizontalScrollBar();

    if (horizontal == null) {
      horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
      scrollPane.setHorizontalScrollBar(horizontal);
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }

    //	Potentially increase height of scroll pane to display the scrollbar

    if (horizontalScrollBarWillBeVisible(popup, scrollPane)) {
      Dimension scrollPaneSize = scrollPane.getPreferredSize();
      scrollPaneSize.height += horizontal.getPreferredSize().height;
      scrollPane.setPreferredSize(scrollPaneSize);
      scrollPane.setMaximumSize(scrollPaneSize);
      scrollPane.revalidate();
    }
  }
예제 #4
0
  //
  //  Implement the ChangeListener
  //
  public void stateChanged(ChangeEvent e) {
    //  Keep the scrolling of the row table in sync with main table

    JViewport viewport = (JViewport) e.getSource();
    JScrollPane scrollPane = (JScrollPane) viewport.getParent();
    scrollPane.getVerticalScrollBar().setValue(viewport.getViewPosition().y);
  }
예제 #5
0
  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);
  }
예제 #6
0
    @Override
    public void layoutContainer(Container parent) {
      if (linkedViewPort == null) {
        super.layoutContainer(parent);
      } else {
        JViewport vp = (JViewport) parent;
        Component view = vp.getView();

        if (view != null) {
          Point p = linkedViewPort.getViewPosition();
          Dimension size = linkedViewPort.getViewSize();

          if (horizontalLink) {
            p.y = 0;
            size.height = vp.getExtentSize().height;
          } else {
            p.x = 0;
            size.width = vp.getExtentSize().width;
          }

          vp.setViewPosition(p);
          vp.setViewSize(size);
        }
      }
    }
예제 #7
0
  private int getCorrectionOffset(FilePanel fp) {
    JTextComponent editor;
    int offset;
    Rectangle rect;
    Point p;
    JViewport viewport;

    editor = fp.getEditor();
    viewport = fp.getScrollPane().getViewport();
    p = viewport.getViewPosition();
    offset = editor.viewToModel(p);

    try {
      // This happens when you scroll to the bottom. The upper line won't
      //   start at the right position (You can see half of the line)
      // Correct this offset with the pane next to it to keep in sync.
      rect = editor.modelToView(offset);
      if (rect != null) {
        return p.y - rect.getLocation().y;
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return 0;
  }
  /**
   * scrolls to selected line number
   *
   * @param lineNumber the line number to scroll to
   * @param toTop display on the top row
   * @return true if .. , false if
   */
  public boolean scrollToLine(final int lineNumber, final boolean toTop) {
    final int lineNumbers = m_sourceModel.getLineNumbers();

    if ((lineNumber >= 0) && (lineNumber < lineNumbers)) {
      int viewColumnIndex = 0;

      Rectangle rect = m_sourceCode.getCellRect(lineNumber, viewColumnIndex, true);

      JViewport viewport = (JViewport) m_sourceCode.getParent();

      if (toTop) {
        Rectangle lastRect = m_sourceCode.getCellRect(lineNumbers - 1, viewColumnIndex, true);
        viewport.scrollRectToVisible(lastRect);
      }

      Point pt = viewport.getViewPosition();
      rect.setLocation(rect.x - pt.x, rect.y - pt.y);

      // Scroll the area into view

      viewport.scrollRectToVisible(rect);

      m_sourceCode.repaint();

      return true;
    }
    return false;
  }
예제 #9
0
  /** {@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);
    }
  }
예제 #10
0
 @Override
 public void stateChanged(ChangeEvent e) {
   if (e.getSource() instanceof JViewport) {
     JViewport port = (JViewport) e.getSource();
     Point tablePos = port.getViewPosition();
     Point filtersPos = filtersViewport.getViewPosition();
     if (filtersPos.x != tablePos.x) {
       filtersPos.x = tablePos.x;
       filtersViewport.setViewPosition(filtersPos);
     }
   } else if (e.getSource() instanceof JTabbedPane) {
     JTabbedPane tabs = (JTabbedPane) e.getSource();
     if (baseDirty && tabs.getSelectedIndex() != 0) {
       UITableModel mdl = (UITableModel) otherTable.getModel();
       mdl.clearCache();
     }
   }
 }
예제 #11
0
  /**
   * Shows a tool tip over the upper left corner of the viewport with the contents of the pannable
   * view's pannable tip text (typically a string identifiying the corner point). Tip is removed
   * after a short delay.
   */
  public void showPanTip() {
    String tipText = null;
    Point upperLeft = new Point(0, 0);
    JViewport vp = getEnclosingViewport();
    if (!isPannableUnbounded() && vp != null) upperLeft = vp.getViewPosition();
    Location loc = locationForPoint(upperLeft);
    if (loc != null) tipText = getToolTipText(loc);

    showTip(tipText, getLocation());
  }
예제 #12
0
 //////////////////////// END OF CONSTRUCTOR/////////////////////////////
 public static boolean isCellVisible(JTable table, int rowIndex, int vColIndex) {
   if (!(table.getParent() instanceof JViewport)) {
     return false;
   }
   JViewport viewport = (JViewport) table.getParent();
   Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
   Point pt = viewport.getViewPosition();
   rect.setLocation(rect.x - pt.x, rect.y - pt.y);
   return new Rectangle(viewport.getExtentSize()).contains(rect);
 }
예제 #13
0
 public void captureDecorated() {
   JViewport view = gui.graphComponent.getViewport();
   Point currentPos = view.getViewPosition();
   view.setViewPosition(new Point(0, 0)); // We have to do that otherwise, top left is not painted
   Dimension size = view.getViewSize();
   BufferedImage image = (BufferedImage) view.createImage(size.width, size.height);
   Graphics2D captureG = image.createGraphics();
   view.paintComponents(captureG);
   view.setViewPosition(currentPos);
   ImagePlus imp = new ImagePlus("TrackScheme capture", image);
   imp.show();
 }
예제 #14
0
  public void scrollToCellLocation(int rowIndex, int colIndex) {

    if (!(getParent() instanceof JViewport)) {
      return;
    }

    JViewport scrollPane = (JViewport) getParent();
    Rectangle rect = getCellRect(rowIndex, colIndex, true);
    Point p = scrollPane.getViewPosition();
    rect.setLocation(rect.x - p.x, rect.y - p.y);
    scrollPane.scrollRectToVisible(rect);
  }
예제 #15
0
  /**
   * Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it
   * is visible within the viewport.
   */
  public static void scrollToVisible(JTable table, int row, int col) {
    if (!(table.getParent() instanceof JViewport)) return;

    JViewport viewport = (JViewport) table.getParent();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(row, col, 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);
  }
예제 #16
0
  /**
   * 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));
  }
  public void scrollToColumnLocation(int colIndex) {
    JTable scrollTable = transposedSpreadsheetSubform.getScrollTable();
    scrollTable.setColumnSelectionInterval(colIndex, colIndex);

    JViewport scrollPane = transposedSpreadsheetSubform.getFrozenTable().getViewport();
    Rectangle rect = scrollTable.getCellRect(1, colIndex, true);
    Point p = scrollPane.getViewPosition();
    rect.setLocation(rect.x - p.x, rect.y - p.y);

    scrollPane.scrollRectToVisible(rect);

    Map<Integer, Color> columnToColor = new HashMap<Integer, Color>();
    columnToColor.put(colIndex, new Color(28, 117, 188, 70));

    transposedSpreadsheetSubform.changeTableRenderer(
        transposedSpreadsheetSubform.getScrollTable(),
        new SubFormCellRenderer(
            UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, null, columnToColor));

    transposedSpreadsheetSubform.validate();
    transposedSpreadsheetSubform.repaint();
  }
예제 #18
0
 public Point getViewPosition() {
   return vp.getViewPosition();
 }