Exemple #1
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;
  }
  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;
  }
 private JScrollPane getScrollPane() {
   if (desktop.getParent() instanceof JViewport) {
     JViewport viewPort = (JViewport) desktop.getParent();
     if (viewPort.getParent() instanceof JScrollPane) return (JScrollPane) viewPort.getParent();
   }
   return null;
 }
  /**
   * Constructor de la clase, crea la tabla y de da todas las propiedades para mostrarla en la
   * aplicacion.
   */
  public PanelHojaCalculo() {
    modelo = new ModeloTabla();
    columnasTabla = new ModeloColumnasTabla();
    tabla = new JTable(modelo, columnasTabla);
    tablaAux = new JTable(modelo, filasTabla);

    tabla.createDefaultColumnsFromModel();
    tablaAux.createDefaultColumnsFromModel();

    tabla.setColumnSelectionAllowed(true);
    tabla.setRowSelectionAllowed(true);

    tablaAux.setSelectionModel(tabla.getSelectionModel());
    tablaAux.setMaximumSize(new Dimension(40, 10000));
    tablaAux.setBackground(new Color(238, 238, 238));
    // Se puede pasar a true si se quiere seleccionar las filas
    tablaAux.setEnabled(false);
    tablaAux.setColumnSelectionAllowed(false);
    tablaAux.setCellSelectionEnabled(false);

    viewPort = new JViewport();
    viewPort.setView(tablaAux);
    viewPort.setPreferredSize(tablaAux.getMaximumSize());

    tabla.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    tablaAux.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    scrollPane = new JScrollPane(tabla);
    scrollPane.setRowHeader(viewPort);
    scrollPane.setPreferredSize(new Dimension(790, 500));
    add(scrollPane);
  }
  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);
  }
Exemple #6
0
  public VText(SessionShare sshare, ButtonIF vif, String typ) {
    this.vnmrIf = vif;
    setOpaque(false);
    setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    twin = new VTextWin(this, sshare, vif, typ);
    setViewportView(twin);
    JViewport vp = getViewport();
    vp.setBackground(Util.getBgColor());

    orgBg = getBackground();

    ml =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent evt) {
            int clicks = evt.getClickCount();
            int modifier = evt.getModifiers();
            if ((modifier & (1 << 4)) != 0) {
              if (clicks >= 2) {
                ParamEditUtil.setEditObj((VObjIF) evt.getSource());
              }
            }
          }
        };
    new DropTarget(this, this);
    DisplayOptions.addChangeListener(this);
  }
  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;
  }
Exemple #8
0
  private static void check() {
    try {
      JViewport vp = null;
      for (Component c : tabbedPane.getComponents()) {
        if (c instanceof JViewport) {
          vp = (JViewport) c;
          break;
        }
      }

      JComponent v = (JComponent) vp.getView();
      Rectangle vr = vp.getViewRect();
      Dimension vs = v.getSize();

      // The tab view must be scrolled to the end so that the last tab is visible
      if (vs.width != (vr.x + vr.width)) {
        throw new RuntimeException(
            "tabScroller.tabPanel view is positioned incorrectly: "
                + vs.width
                + " vs "
                + (vr.x + vr.width));
      }
    } catch (Exception e) {
      exception = e;
    }
  }
 /** Move a block it's prior location to the drop location */
 @Override
 public boolean importData(TransferSupport supp) {
   if (canImport(supp)) {
     IconList list = (IconList) supp.getComponent().getParent().getParent().getParent();
     JViewport panel = (JViewport) supp.getComponent().getParent();
     try {
       Transferable t = supp.getTransferable();
       int from = (int) t.getTransferData(DataFlavor.imageFlavor);
       list.move(
           from,
           (int)
               (Math.ceil(
                   supp.getDropLocation().getDropPoint().getX()
                           * list.length()
                           / panel.getViewSize().getWidth()
                       - 1)),
           false);
     } catch (Exception e) {
       e.printStackTrace();
       return false;
     }
     return true;
   }
   return false;
 }
  public DataModel getDataModel(TypeEl typeEl) {
    String type = new String();
    switch (typeEl) {
      case CD:
        type = "CD";
        break;
      case DVD:
        type = "DVD";
        break;
      case LIVRE:
        type = "Livre";
        break;
      case JEUX:
        type = "Jeux";
        break;
      case BD:
        type = "BD";
        break;
    }
    tabbedpane.setSelectedIndex(tabbedpane.indexOfTab(type));

    JScrollPane t = (JScrollPane) tabbedpane.getComponent(tabbedpane.indexOfTab(type));
    JViewport view = t.getViewport();
    JTable f = (JTable) view.getView();
    DataModel model = (DataModel) f.getModel();

    return model;
  }
  /**
   * 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;
  }
  /*
   *  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();
    }
  }
  //
  //  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);
  }
  public void scrollToLine(FilePanel fp, int line) {
    JScrollPane scrollPane;
    FilePanel fp2;
    BufferDocumentIF bd;
    JTextComponent editor;
    JViewport viewport;
    Rectangle rect;
    int offset;
    Point p;
    Rectangle viewRect;
    Dimension viewSize;
    Dimension extentSize;
    int x;

    fp2 = fp == filePanelLeft ? filePanelRight : filePanelLeft;

    bd = fp.getBufferDocument();
    if (bd == null) {
      return;
    }

    offset = bd.getOffsetForLine(line);
    if (offset < 0) {
      return;
    }

    viewport = fp.getScrollPane().getViewport();
    editor = fp.getEditor();

    try {
      rect = editor.modelToView(offset);
      if (rect == null) {
        return;
      }

      p = rect.getLocation();
      p.y -= getHeightOffset(fp);
      p.y += getCorrectionOffset(fp2);

      // Do not allow scrolling before the begin.
      if (p.y < 0) {
        p.y = 0;
      }

      // Do not allow scrolling after the end.
      viewSize = viewport.getViewSize();
      viewRect = viewport.getViewRect();
      extentSize = viewport.getExtentSize();
      if (p.y > viewSize.height - extentSize.height) {
        p.y = viewSize.height - extentSize.height;
      }

      p.x = viewRect.x;

      viewport.setViewPosition(p);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Exemple #15
0
 /**
  * Update the visibility of the buttons Only show them if the Viewport is too small for the
  * content.
  */
 public void showOrHideButtons() {
   boolean needButtons =
       vp.getViewSize().height > vp.getViewRect().height
           || vp.getViewSize().width > vp.getViewRect().width;
   for (JButton b : buttons) {
     b.setVisible(needButtons);
   }
 }
  public void selectField(String fieldName) {
    int idx = listModel.indexOf(fieldName);
    if (idx >= 0) list.setSelectedIndex(idx);

    // Make sure it is visible:
    JViewport viewport = sp.getViewport();
    viewport.scrollRectToVisible(list.getCellBounds(idx, idx));
  }
  /** {@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);
    }
  }
Exemple #18
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);
 }
Exemple #19
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());
  }
Exemple #20
0
 private void scrollToCenterPath(final GeneralPath geoBoundaryPath, final JViewport viewport) {
   final GeneralPath pixelPath =
       ProductUtils.convertToPixelPath(geoBoundaryPath, wmPainter.getGeoCoding());
   final Rectangle viewRect = viewport.getViewRect();
   final Rectangle pathBounds = pixelPath.getBounds();
   setCenter(viewRect, new Point((int) pathBounds.getCenterX(), (int) pathBounds.getCenterY()));
   final Dimension bounds =
       new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null));
   ensureRectIsInBounds(viewRect, bounds);
   viewport.scrollRectToVisible(viewRect);
 }
Exemple #21
0
 /**
  * Pans the display back to the origin, so that 0, 0 is at the the upper left of the visible
  * viewport.
  */
 public void recenter(Location loc) {
   originRow = loc.getRow();
   originCol = loc.getCol();
   repaint();
   JViewport vp = getEnclosingViewport();
   if (vp != null) {
     if (!isPannableUnbounded() || !(vp instanceof PseudoInfiniteViewport))
       vp.setViewPosition(pointForLocation(loc));
     else showPanTip();
   }
 }
Exemple #22
0
  /** 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()));
  }
    private void updateColor(Component c) {
      if (!(c instanceof JScrollPane)) return;

      JViewport vp = ((JScrollPane) c).getViewport();
      if (vp == null) return;

      Component view = vp.getView();
      if (view == null) return;

      lineColor = view.getBackground();
    }
 @Override
 public Component getToolComponent() {
   JViewport viewPort = rootPane.getViewport();
   if (viewPort == null) {
     viewPort = new JViewport();
     rootPane.setViewport(viewPort);
   }
   if (viewPort.getView() != this) {
     viewPort.setView(this);
   }
   return rootPane;
 }
 /**
  * in Android server, AddHarHTMLMlet is NOT need to adapter size.
  *
  * @param scrollPane
  * @return
  */
 public static boolean isForAddHtml(final JScrollPane scrollPane) {
   if (scrollPane != null) {
     final JViewport jviewport = scrollPane.getViewport();
     if (jviewport != null) {
       final Component view = jviewport.getView();
       if (view != null && view instanceof SystemHTMLMlet) {
         return true;
       }
     }
   }
   return false;
 }
Exemple #26
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);
  }
Exemple #27
0
  @Override
  public void update(Observable o, Object arg) {
    SortedSet<Feature> fs = model.selectionModel().getFeatureSelection();

    if (fs.size() == 1) {

      if (fs.first().type() == listModel.getType()) {
        int row = listModel.getRow(fs.first());
        // getSelectionModel().setSelectionInterval(row, row);
        if (!(getParent() instanceof JViewport)) {
          return;
        }
        JViewport viewport = (JViewport) getParent();

        // This rectangle is relative to the table where the
        // northwest corner of cell (0,0) is always (0,0).
        Rectangle rect = getCellRect(row, 0, true);

        // The location of the view relative to the table
        Rectangle viewRect = viewport.getViewRect();

        int topVisible = viewport.getViewRect().y;
        int bottomVisible = viewport.getViewRect().height + topVisible;

        /* When the cell is visible, don't do anything */
        if (rect.y > topVisible && rect.y + rect.height < bottomVisible) {
          return;
        }
        // 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 - viewRect.x, rect.y - viewRect.y);

        // Calculate location of rect if it were at the center of view
        int centerX = (viewRect.width - rect.width) / 2;
        int centerY = (viewRect.height - rect.height) / 2;

        // Fake the location of the cell so that scrollRectToVisible
        // will move the cell to the center
        if (rect.x < centerX) {
          centerX = -centerX;
        }
        if (rect.y < centerY) {
          centerY = -centerY;
        }
        rect.translate(centerX, centerY);

        // Scroll the area into view.
        viewport.scrollRectToVisible(rect);
      }
    }
  }
  @Override
  public void addNotify() {
    super.addNotify();

    Component c = getParent();

    //  Keep scrolling of the row table in sync with the main table.

    if (c instanceof JViewport) {
      JViewport viewport = (JViewport) c;
      viewport.addChangeListener(this);
    }
  }
 /** {@inheritDoc} */
 @Override
 protected void uninstallListeners(JComponent c) {
   super.uninstallListeners(c);
   c.removePropertyChangeListener(this);
   if (viewportViewFocusHandler != null) {
     JViewport viewport = ((JScrollPane) c).getViewport();
     viewport.removeContainerListener(viewportViewFocusHandler);
     if (viewport.getView() != null) {
       viewport.getView().removeFocusListener(viewportViewFocusHandler);
     }
     viewportViewFocusHandler = null;
   }
 }
Exemple #30
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);
        }
      }
    }