Exemplo n.º 1
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);
        }
      }
    }
Exemplo n.º 2
0
  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();
    }
  }
Exemplo n.º 3
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);
 }