Java 类javax.swing.JViewport 实例源码

项目:incubator-netbeans    文件:UIUtils.java   
@Override
public void focusGained(FocusEvent e) {
    if (e.isTemporary()) {
        return;
    }
    Component cmp = e.getComponent();
    if(cmp instanceof JComponent) {
        JViewport vp = getViewport(container);
        if(vp == null) {
            return;
        }
        Rectangle vr = vp.getViewRect();
        Point p = SwingUtilities.convertPoint(cmp.getParent(), cmp.getLocation(), container);
        final Rectangle r = new Rectangle(p, cmp.getSize());
        if(vr.intersects(r)) {
            return; 
        }
        container.scrollRectToVisible(r);
    }
}
项目:incubator-netbeans    文件:EditorUI.java   
/** Get position of the component extent. The (x, y) are set to (0, 0) if there's
* no viewport or (-x, -y) if there's one.
*/
public Rectangle getExtentBounds(Rectangle r) {
    if (r == null) {
        r = new Rectangle();
    }
    if (component != null) {
        JViewport port = getParentViewport();
        if (port != null) {
            Point p = port.getViewPosition();
            r.width = port.getWidth();
            r.height = port.getHeight();
            r.x = p.x;
            r.y = p.y;
        } else { // no viewport
            r.setBounds(component.getVisibleRect());
        }
    }
    return r;
}
项目:incubator-netbeans    文件:Utilities.java   
private void changed() {
    JViewport viewport = sp.getViewport();
    Point viewPosition = viewport.getViewPosition();
    if (viewPosition.x > 0) {
        try {
            Rectangle textRect = editorPane.getUI().modelToView(editorPane, editorPane.getDocument().getLength());
            int textLength = textRect.x + textRect.width;
            int viewLength = viewport.getExtentSize().width;
            //System.out.println("Utilities.createSingleLineEditor(): spLength = "+sp.getSize().width+", viewLength = "+viewLength+", textLength = "+textLength+", viewPosition = "+viewPosition);
            if (textLength < (viewPosition.x + viewLength)) {
                viewPosition.x = Math.max(textLength - viewLength, 0);
                viewport.setViewPosition(viewPosition);
                //System.out.println("Utilities.createSingleLineEditor(): setting new view position = "+viewPosition);
            }
        } catch (BadLocationException blex) {
            Exceptions.printStackTrace(blex);
        }
    }
}
项目:incubator-netbeans    文件:ComponentPeer.java   
private int[] computeVisibleSpan() {
    Component parent = pane.getParent();

    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }

    if (parent instanceof JViewport) {
        JViewport vp = (JViewport) parent;

        Point start = vp.getViewPosition();
        Dimension size = vp.getExtentSize();
        Point end = new Point((int) (start.getX() + size.getWidth()), (int) (start.getY() + size.getHeight()));

        int startPosition = pane.viewToModel(start);
        int endPosition = pane.viewToModel(end);

        if (parentWithListener != vp) {
            vp.addChangeListener(WeakListeners.change(this, vp));
            parentWithListener = vp;
        }
        return new int[] {startPosition, endPosition};
    }

    return new int[] {0, pane.getDocument().getLength()};
}
项目:incubator-netbeans    文件:BaseTable.java   
protected int getVisibleRowCount() {
    int rowCount = getRowCount();
    int rowHeight = getRowHeight();

    if ((rowCount == 0) || (rowHeight == 0)) {
        return 0;
    }

    if (getParent() instanceof JViewport) {
        JViewport jvp = (JViewport) getParent();

        // +1 to return also half-displayed rows (issue 53660)
        int result = Math.min(rowCount, (jvp.getExtentSize().height / rowHeight) + 1);

        return result;
    } else {
        return Math.min(rowCount, getHeight() / rowHeight);
    }
}
项目:incubator-netbeans    文件:BaseTable.java   
private void hideSearchField() {
    if (searchField == null) {
        return;
    }

    searchpanel.setVisible(false);

    if (getParent() instanceof JViewport && null != viewportListener ) {
        JViewport jvp = (JViewport) getParent();
        jvp.removeChangeListener( viewportListener );
        viewportListener = null;
    }

    getParent().removeComponentListener(searchField);
    if (searchpanel.getParent() != null) {
        searchpanel.getParent().remove(searchpanel);
    }

    paintSelectionRow();
}
项目:incubator-netbeans    文件:PalettePanel.java   
/**
 * Adds the search field to the tree.
 */
private void displaySearchField(char initialChar) {
    if( null != searchpanel )
        return;
    JViewport vp = scrollPane.getViewport();
    originalScrollMode = vp.getScrollMode();
    vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
    searchTextField.setFont(getFont());
    searchTextField.setText(String.valueOf(initialChar));
    prepareSearchPanel();
    scrollPane.add(searchpanel);
    invalidate();
    revalidate();
    repaint();
    searchTextField.requestFocus();
}
项目:incubator-netbeans    文件:ETable.java   
/**
 * This method update mouse listener on the scrollPane if it is needed.
 * It also recomputes the model of searchCombo. Both actions are needed after
 * the set of visible columns is changed.
 */
void updateColumnSelectionMouseListener() {
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane)gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.removeMouseListener(columnSelectionMouseListener);
            if (getColumnModel().getColumnCount() == 0) {
                scrollPane.addMouseListener(columnSelectionMouseListener);
            }
        }
    }
    if (searchCombo != null) {
        searchCombo.setModel(getSearchComboModel());
    }
}
项目:AWGW    文件:GridPanel.java   
/**
 * Calculate the cell size to use given the current viewable region and the
 * the number of rows and columns in the grid. We use the largest
 * cellSize that will fit in the viewable region, bounded to be at least the
 * parameter minSize.
 */
private void recalculateCellSize(int minSize) {
    if (numRows == 0 || numCols == 0) {
        cellSize = 0;
    } else {
        JViewport vp = getEnclosingViewport();
        Dimension viewableSize = (vp != null) ? vp.getSize() : getSize();
        int desiredCellSize = Math.min(
                (viewableSize.height - extraHeight()) / numRows,
                (viewableSize.width - extraWidth()) / numCols) - 1;
        // now we want to approximate this with
        // DEFAULT_CELL_SIZE * Math.pow(2, k)
        cellSize = DEFAULT_CELL_SIZE;
        if (cellSize <= desiredCellSize)
            while (2 * cellSize <= desiredCellSize)
                cellSize *= 2;
        else
            while (cellSize / 2 >= Math.max(desiredCellSize, MIN_CELL_SIZE))
                cellSize /= 2;
    }
    revalidate();
}
项目:jdk8u-jdk    文件:Test6526631.java   
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
项目:incubator-netbeans    文件:IndexedCustomizer.java   
/** notify the Component to autoscroll */
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();
    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;

    if ((cursorLoc.y - viewPos.y) <= realInsets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - realInsets.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) <= realInsets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + realInsets.bottom, this.getHeight() - viewHeight))
        );
    }
}
项目:Logisim    文件:LayoutPopupManager.java   
private void showPopup(Set<AppearancePort> portObjects) {
    dragStart = null;
    CircuitState circuitState = canvas.getCircuitState();
    if (circuitState == null)
        return;
    ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
    for (AppearancePort portObject : portObjects) {
        ports.add(portObject.getPin());
    }

    hideCurrentPopup();
    LayoutThumbnail layout = new LayoutThumbnail();
    layout.setCircuit(circuitState, ports);
    JViewport owner = canvasPane.getViewport();
    Point ownerLoc = owner.getLocationOnScreen();
    Dimension ownerDim = owner.getSize();
    Dimension layoutDim = layout.getPreferredSize();
    int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
    int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
    PopupFactory factory = PopupFactory.getSharedInstance();
    Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
    popup.show();
    curPopup = popup;
    curPopupTime = System.currentTimeMillis();
}
项目:openjdk-jdk10    文件:JViewPortBackingStoreImageTest.java   
private static JComponent createComponent() {
    createStyles();
    for (int i = 0; i < data.length; i++) {
        Paragraph p = data[i];
        addParagraph(p);
    }

    JTextPane textPane = new JTextPane(doc);

    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
    port.add(textPane);

    return scroller;
}
项目:Tarski    文件:SchemaGraphComponent.java   
/**
 * 
 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
  Component[] c = components.get(terminal.getCell());
  int y = 0;

  if (c != null) {
    for (int i = 0; i < c.length; i++) {
      if (c[i] instanceof JTableRenderer) {
        JTableRenderer vertex = (JTableRenderer) c[i];

        JTable table = vertex.table;
        JViewport viewport = (JViewport) table.getParent();
        double dy = -viewport.getViewPosition().getY();
        y = (int) Math.max(terminal.getY() + 22,
            terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
      }
    }
  }

  return y;
}
项目:jmt    文件:ExactTable.java   
@Override
protected void unconfigureEnclosingScrollPane() {
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setColumnHeaderView(null);
            scrollPane.setRowHeaderView(null);

            viewport.removeChangeListener(scrollListener);
            rowHeader.uninstall();
        }
    }
}
项目:AWGW    文件:GridPanel.java   
/**
 * Sets the grid being displayed. Reset the cellSize to be the
 * largest that fits the entire grid in the current visible area (use
 * default if grid is too large).
 *
 * @param gr the grid to display
 */
public void setGrid(Grid<?> gr) {
    currentLocation = new Location(0, 0);
    JViewport vp = getEnclosingViewport(); // before changing, reset
    // scroll/pan position
    if (vp != null)
        vp.setViewPosition(new Point(0, 0));

    grid = gr;
    originRow = originCol = 0;

    if (grid.getNumRows() == -1 && grid.getNumCols() == -1) {
        numRows = numCols = 2000;
        // This determines the "virtual" size of the pan world
    } else {
        numRows = grid.getNumRows();
        numCols = grid.getNumCols();
    }
    recalculateCellSize(MIN_CELL_SIZE);
}
项目:QN-ACTR-Release    文件:ExactTable.java   
@Override
protected void unconfigureEnclosingScrollPane() {
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setColumnHeaderView(null);
            scrollPane.setRowHeaderView(null);

            viewport.removeChangeListener(scrollListener);
            rowHeader.uninstall();
        }
    }

}
项目:org.alloytools.alloy    文件:GraphViewer.java   
/** Repaint this component. */
public void alloyRepaint() {
    Container c = getParent();
    while (c != null) {
        if (c instanceof JViewport)
            break;
        else
            c = c.getParent();
    }
    setSize((int) (graph.getTotalWidth() * scale), (int) (graph.getTotalHeight() * scale));
    if (c != null) {
        c.invalidate();
        c.repaint();
        c.validate();
    } else {
        invalidate();
        repaint();
        validate();
    }
}
项目:JavaGraph    文件:ZoomMenu.java   
@Override
public void actionPerformed(ActionEvent evt) {
    Component component = ZoomMenu.this.jgraph.getParent();
    while (component != null && !(component instanceof JViewport)) {
        component = component.getParent();
    }
    if (component != null) {
        final JViewport viewport = (JViewport) component;
        Rectangle2D graphBounds = ZoomMenu.this.jgraph.getGraphBounds();
        Dimension viewportBounds = viewport.getExtentSize();
        double scale =
            Math.min(viewportBounds.width / graphBounds.getWidth(), viewportBounds.height
                / graphBounds.getHeight());
        ZoomMenu.this.jgraph.setScale(Math.min(scale, 1.0));
        ZoomMenu.this.jgraph.scrollRectToVisible(graphBounds.getBounds());
        setActionsEnabled();
    }
}
项目:Equella    文件:TablePasteAdapter.java   
public static JTable createRawTable(TableModel model)
{
    JTable table = new JTable(model)
    {
        @Override
        public boolean getScrollableTracksViewportHeight()
        {
            // fetch the table's parent
            Container viewport = getParent();

            // if the parent is not a viewport, calling this isn't useful
            if( !(viewport instanceof JViewport) )
            {
                return false;
            }

            // return true if the table's preferred height is smaller
            // than the viewport height, else false
            return getPreferredSize().height < viewport.getHeight();
        }
    };
    return table;
}
项目:openjdk-jdk10    文件:Test6526631.java   
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
项目:powertext    文件:RTextAreaEditorKit.java   
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
    Container parent = textArea.getParent();
    if (parent instanceof JViewport) {
        JViewport viewport = (JViewport)parent;
        Point p = viewport.getViewPosition();
        p.y += delta*textArea.getLineHeight();
        if (p.y<0) {
            p.y = 0;
        }
        else {
            Rectangle viewRect = viewport.getViewRect();
            int visibleEnd = p.y + viewRect.height;
            if (visibleEnd>=textArea.getHeight()) {
                p.y = textArea.getHeight() - viewRect.height;
            }
        }
        viewport.setViewPosition(p);
    }
}
项目:incubator-netbeans    文件:UIUtils.java   
private static JViewport getViewport(Container c) {
    if(c == null) {
        return null;
    }
    if(c instanceof JScrollPane) {
        return ((JScrollPane) c).getViewport();
    }
    return getViewport(c.getParent());
}
项目:incubator-netbeans    文件:AnnotationHolder.java   
private void addViewportListener(JEditorPane pane) {
    Container parent = pane.getParent();

    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }

    if (parent instanceof JViewport) {
        JViewport viewport = (JViewport) parent;

        viewport.addChangeListener(WeakListeners.change(AnnotationHolder.this, viewport));
    }
}
项目:incubator-netbeans    文件:HintsUI.java   
private int getUsableWidth(JTextComponent component) {
    Container parent = component.getParent();
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }
    return (parent instanceof JViewport)
        ? ((JViewport)parent).getExtentSize().width
        : component.getSize().width;
}
项目:incubator-netbeans    文件:ListCompletionView.java   
public @Override void paintComponent(Graphics g) {
            // Although the JScrollPane without horizontal scrollbar
            // is explicitly set with a preferred size
            // it does not force its items with the only width into which
            // they can render (and still leaves them with the preferred width
            // of the widest item).
            // Therefore the item's render width is taken from the viewport's width.
            int itemRenderWidth = ((JViewport)ListCompletionView.this.getParent()).getWidth();
            Color bgColor = getBackground();
            Color fgColor = getForeground();
            int height = getHeight();

            // Clear the background
            g.setColor(bgColor);
            g.fillRect(0, 0, itemRenderWidth, height);
            g.setColor(fgColor);

            // Render the item
            renderHtml(fix, g, ListCompletionView.this.getFont(), getForeground(),
                    itemRenderWidth, getHeight(), selected);

//            if (separator) {
//                g.setColor(Color.gray);
//                g.drawLine(0, 0, itemRenderWidth, 0);
//                g.setColor(fgColor);
//            }
        }
项目:incubator-netbeans    文件:EditorUI.java   
/** Is the parent of some editor component a viewport */
private JViewport getParentViewport() {
    Component pc = component.getParent();
    if (pc instanceof JLayeredPane) {
        pc = pc.getParent();
    }
    return (pc instanceof JViewport) ? (JViewport)pc : null;
}
项目:incubator-netbeans    文件:EditorUI.java   
void setExtentPosition(int x, int y) {
    JViewport port = getParentViewport();
    if (port != null) {
        Point p = new Point(Math.max(x, 0), Math.max(y, 0));
        port.setViewPosition(p);
    }
}
项目:incubator-netbeans    文件:PopupManager.java   
/** Variation of the method for computing the bounds
 * for the concrete view component. As the component can possibly
 * be placed in a scroll pane it's first necessary
 * to translate the cursor bounds and also translate
 * back the resulting popup bounds.
 * @param popup  popup panel to be displayed
 * @param view component over which the popup is displayed.
 * @param cursorBounds the bounds of the caret or mouse cursor
 *    relative to the upper-left corner of the visible view.
 * @param placement where to place the popup panel according to
 *    the cursor position.
 * @return bounds of popup panel relative to the upper-left corner
 *    of the underlying view component.
 *    <CODE>null</CODE> if there is no place to display popup.
 */
protected static Rectangle computeBounds(JComponent popup,
JComponent view, Rectangle cursorBounds, Placement placement, HorizontalBounds horizontalBounds) {

    if (horizontalBounds == null) horizontalBounds = ViewPortBounds;

    Rectangle ret;
    Component viewParent = view.getParent();

    if (viewParent instanceof JLayeredPane) {
        viewParent = viewParent.getParent();
    }

    if (viewParent instanceof JViewport) {
        Rectangle viewBounds = ((JViewport)viewParent).getViewRect();

        Rectangle translatedCursorBounds = (Rectangle)cursorBounds.clone();
        if (placement != FixedPoint) {
            translatedCursorBounds.translate(-viewBounds.x, -viewBounds.y);
        }

        ret = computeBounds(popup, viewBounds.width, viewBounds.height,
            translatedCursorBounds, placement, horizontalBounds);

        if (ret != null) { // valid bounds
            ret.translate(viewBounds.x, viewBounds.y);
        }

    } else { // not in scroll pane
        ret = computeBounds(popup, view.getWidth(), view.getHeight(),
            cursorBounds, placement);
    }

    return ret;
}
项目:Tarski    文件:GraphViewer.java   
/** Repaint this component. */
public void alloyRepaint() {
    Container c=getParent();
    while(c!=null) { if (c instanceof JViewport) break; else c=c.getParent(); }
    setSize((int)(graph.getTotalWidth()*scale), (int)(graph.getTotalHeight()*scale));
    if (c!=null) { c.invalidate(); c.repaint(); c.validate(); } else { invalidate(); repaint(); validate(); }
}
项目:incubator-netbeans    文件:ValidityAwarePanel.java   
@Override
public Dimension getPreferredSize() {
    if (getParent() instanceof JViewport) {
        return getMinimumSize();
    } else {
        return super.getPreferredSize();
    }
}
项目:AWGW    文件:GridPanel.java   
/**
 * 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();
    }
}
项目:incubator-netbeans    文件:AntSanityTest.java   
/**
 * Takes GUI snapshot of debugged application.
 */
public void takeGUISnapshot() throws InterruptedException {
    new Action("Debug|Debug Project (debugTestProjectAnt)", null).perform();
    Thread.sleep(3000); // Wait 3 seconds. Sometimes starting debugging session was slow.
    OutputTabOperator op = new OutputTabOperator(DEBUGGER_CONSOLE);
    assertEquals("User program running", op.getLine(op.getLineCount() - 2));
    new TakeGUISnapshotAction().perform();
    TopComponentOperator guiSnapshot = new TopComponentOperator("Snapshot of \"Memory View\"");
    assertEquals(guiSnapshot.getComponent(1).getName(), "Snapshot Zoom Toolbar");
    JViewport viewPort = (JViewport) guiSnapshot.getComponent(0).getComponentAt(10, 10);
    assertTrue(viewPort.getComponent(0).toString().startsWith("org.netbeans.modules.debugger.jpda.visual.ui.ScreenshotComponent$ScreenshotCanvas"));
    new FinishDebuggerAction().perform();
}
项目:incubator-netbeans    文件:ScrollableJPanel.java   
@Override
public boolean getScrollableTracksViewportHeight() {
    if (getParent() instanceof JViewport) {
        return (((JViewport) getParent()).getHeight() > getPreferredSize().height);
    }

    return false;
}
项目:incubator-netbeans    文件:AutoscrollSupport.java   
/** Performs autoscroll operation.
*/
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();

    if (viewport == null) {
        return;
    }

    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;
    int viewWidth = viewport.getExtentSize().width;

    // perform scrolling
    if ((cursorLoc.y - viewPos.y) < insets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) < insets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight))
        );
    } else if ((cursorLoc.x - viewPos.x) < insets.left) {
        // scroll left
        viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
    } else if (((viewPos.x + viewWidth) - cursorLoc.x) < insets.right) {
        // scroll right
        viewport.setViewPosition(
            new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y)
        );
    }
}
项目:incubator-netbeans    文件:PSheet.java   
private JScrollPane createScrollPane(Component inner) {
    JScrollPane result = new JScrollPane(inner);
    JViewport vp = result.getViewport();
    vp.addMouseListener(this);

    MarginViewportUI ui = (MarginViewportUI) MarginViewportUI.createUI(vp);
    vp.setUI(ui);
    ui.setMarginPainted(marginPainted);
    ui.setMarginColor(marginColor);
    ui.setEmptyString(emptyString);
    result.setBorder(BorderFactory.createEmptyBorder());
    result.setViewportBorder(result.getBorder());

    return result;
}
项目:incubator-netbeans    文件:MarginViewportUI.java   
public void uninstallUI(JComponent vp) {
    JViewport jv = (JViewport) vp;
    Component[] c = jv.getComponents();

    for (int i = 0; i < c.length; i++) {
        c[i].removeComponentListener(this);
    }

    jv.removeContainerListener(this);
}
项目:incubator-netbeans    文件:MarginViewportUI.java   
/** Overridden to draw "no properties" if necessary */
public void paint(Graphics g, JComponent c) {
    Component view = ((JViewport) c).getView();

    if (view != null) {
        lastKnownSize = view.getSize();
    }

    if (stringWidth == -1) {
        calcStringSizes(c.getFont(), g);
    }

    //Update will have set paintNoProps to the correct value
    if (shouldPaintEmptyMessage()) {
        //We need to paint centered "<No Properties>" text
        g.setFont(c.getFont());
        g.setColor(c.getForeground());

        Rectangle r = getEmptyMessageBounds();

        //See if we really need to do any painting
        if (g.hitClip(r.x, r.y, r.width, r.height)) {
            //Paint the string
            g.drawString(emptyString, r.x, r.y + ascent);
        }
    }
}
项目:incubator-netbeans    文件:BaseTable.java   
protected int getFirstVisibleRow() {
    if (getParent() instanceof JViewport) {
        JViewport jvp = (JViewport) getParent();

        return rowAtPoint(jvp.getViewPosition());
    } else {
        Insets ins = getInsets();

        return rowAtPoint(new Point(ins.left, ins.top));
    }
}
项目:AWGW    文件:GridPanel.java   
/**
 * 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());
}