Java 类javax.swing.Scrollable 实例源码

项目:PasswordSafe    文件:CScrollBar.java   
public int getBlockIncrement(int direction)
{
    JViewport vp = scroll.getViewport();
    if(blockIncrementSet || vp == null)
    {
        return super.getBlockIncrement(direction);
    }
    else if(vp.getView() instanceof Scrollable)
    {
        Scrollable view = (Scrollable)(vp.getView());
        Rectangle vr = vp.getViewRect();
        return view.getScrollableBlockIncrement(vr, getOrientation(), direction);
    }
    else if(getOrientation() == VERTICAL)
    {
        return vp.getExtentSize().height;
    }
    else
    {
        return vp.getExtentSize().width;
    }
}
项目:spring-rich-client    文件:OverlayHelperTests.java   
/**
     * Ensures that OverlayHelper will NOT implement the Scrollable interface if the view component does not implement
     * the Scrollable interface.
     * 
     * @throws Exception
     */
    private void performNonScrollableTest() throws Exception {
        final JPanel view = new JPanel(new BorderLayout());
        final JComponent overlay = createTestOverlay();
        final JComponent someField = createTestComponent();

        OverlayHelper.attachOverlay(overlay, someField, 0, 0, 0);

        view.add(someField);

        final JScrollPane scrollPane = new JScrollPane(view);

        waitUntilEventQueueIsEmpty();

        final Component viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertFalse(viewportView instanceof Scrollable);
    }
项目:spring-richclient    文件:OverlayHelperTests.java   
/**
     * Ensures that OverlayHelper will NOT implement the Scrollable interface if the view component does not implement
     * the Scrollable interface.
     * 
     * @throws Exception
     */
    private void performNonScrollableTest() throws Exception {
        final JPanel view = new JPanel(new BorderLayout());
        final JComponent overlay = createTestOverlay();
        final JComponent someField = createTestComponent();

        OverlayHelper.attachOverlay(overlay, someField, 0, 0, 0);

        view.add(someField);

        final JScrollPane scrollPane = new JScrollPane(view);

        waitUntilEventQueueIsEmpty();

        final Component viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertFalse(viewportView instanceof Scrollable);
    }
项目:incubator-netbeans    文件:OutlineView.java   
@Override
public Dimension preferredLayoutSize(Container parent) {
    Dimension dim = super.preferredLayoutSize(parent);
    OutlineView ov = (OutlineView) parent;
    int thsbPolicy = ov.treeHorizontalScrollBarPolicy;
    if ((thsb != null) && (thsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)) {
        if (thsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
            dim.height += thsb.getPreferredSize().height;
        }
        else {
            Dimension extentSize = null;
            Dimension viewSize = null;
            Component view = null;

            if (viewport !=  null) {
                extentSize = viewport.getPreferredSize();
                viewSize = viewport.getViewSize();
                view = viewport.getView();
            }

            if ((viewSize != null) && (extentSize != null)) {
                boolean canScroll = true;
                if (view instanceof Scrollable) {
                    canScroll = !((Scrollable)view).getScrollableTracksViewportWidth();
                }
                if (canScroll && (viewSize.width > extentSize.width)) {
                    dim.height += thsb.getPreferredSize().height;
                }
            }
        }
    }
    return dim;
}
项目:incubator-netbeans    文件:IndexedEditorPanel.java   
private boolean isEditorScrollable(PropertyPanel p) {
    Component[] comps = p.getComponents();

    for (int i = 0; i < comps.length; i++) {
        if (comps[i] instanceof Scrollable || isInstanceOfTopComponent(comps[i])) {
            return true;
        }
    }

    return false;
}
项目:incubator-netbeans    文件:ScrollAction.java   
private int getDefaultIncrement() {
    Component content = scrollPane.getViewport().getView();
    Point position = scrollPane.getViewport().getViewPosition();
    int increment = isHorizontal ? 30 : 8;
    Dimension viewSize = scrollPane.getViewport().getExtentSize();
    if( content instanceof Scrollable ) {
        increment = ((Scrollable)content).getScrollableUnitIncrement( new Rectangle( position, viewSize ),
                isHorizontal ? SwingConstants.HORIZONTAL : SwingConstants.VERTICAL,
                isScrollLeft ? -1 : 1 );
    }
    return increment;
}
项目:SweetHome3D    文件:HomePane.java   
public void propertyChange(PropertyChangeEvent ev)
{
    // If home pane was garbage collected, remove this listener from preferences
    HomePane homePane = this.homePane.get();
    if (homePane == null)
    {
        ((UserPreferences) ev.getSource())
                .removePropertyChangeListener(UserPreferences.Property.FURNITURE_CATALOG_VIEWED_IN_TREE, this);
    }
    else
    {
        // Replace previous furniture catalog view by the new one
        JComponent oldFurnitureCatalogView = this.furnitureCatalogView.get();
        if (oldFurnitureCatalogView != null)
        {
            boolean transferHandlerEnabled = homePane.transferHandlerEnabled;
            homePane.setTransferEnabled(false);
            JComponent newFurnitureCatalogView = (JComponent) homePane.controller
                    .getFurnitureCatalogController().getView();
            newFurnitureCatalogView.setComponentPopupMenu(oldFurnitureCatalogView.getComponentPopupMenu());
            homePane.setTransferEnabled(transferHandlerEnabled);
            JComponent splitPaneTopComponent = newFurnitureCatalogView;
            if (newFurnitureCatalogView instanceof Scrollable)
            {
                splitPaneTopComponent = SwingTools.createScrollPane(newFurnitureCatalogView);
            }
            else
            {
                splitPaneTopComponent = newFurnitureCatalogView;
            }
            ((JSplitPane) SwingUtilities.getAncestorOfClass(JSplitPane.class, oldFurnitureCatalogView))
                    .setTopComponent(splitPaneTopComponent);
            this.furnitureCatalogView = new WeakReference<JComponent>(newFurnitureCatalogView);
        }
    }
}
项目:PasswordSafe    文件:CScrollBar.java   
public int getUnitIncrement(int direction)
{
    JViewport vp = scroll.getViewport();
    if(!unitIncrementSet && (vp != null) && (vp.getView() instanceof Scrollable))
    {
        Scrollable view = (Scrollable)(vp.getView());
        Rectangle vr = vp.getViewRect();
        return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
    }
    else
    {
        return Theme.plainFont().getSize() * scrollLineCount;
    }
}
项目:swingx    文件:CodeViewer.java   
@Override
public Dimension getPreferredScrollableViewportSize() {
    if (master instanceof Scrollable) {
        return ((Scrollable) master).getPreferredScrollableViewportSize();
    }
    return getPreferredSize();
}
项目:swingx    文件:CodeViewer.java   
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect,
        int orientation, int direction) {
    if (master instanceof Scrollable) {
        return ((Scrollable) master).getScrollableBlockIncrement(visibleRect, orientation, direction);
    }
    return visibleRect.height;
}
项目:swingx    文件:CodeViewer.java   
@Override
public boolean getScrollableTracksViewportHeight() {
    if (master instanceof Scrollable) {
        return ((Scrollable) master).getScrollableTracksViewportHeight();
    }
    return false;
}
项目:swingx    文件:CodeViewer.java   
@Override
public boolean getScrollableTracksViewportWidth() {
    if (master instanceof Scrollable) {
        return ((Scrollable) master).getScrollableTracksViewportWidth();
    }
    return false;
}
项目:swingx    文件:CodeViewer.java   
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect,
        int orientation, int direction) {
    if (master instanceof Scrollable) {
        return ((Scrollable) master).getScrollableUnitIncrement(visibleRect, orientation, direction);
    }
    return visibleRect.height / 10;
}
项目:genomeartist    文件:JScrollableBottomSpacingContainer.java   
/**
 * Obtine unitatea cu care se face scroll
 * @param visibleRect
 * @param orientation
 * @param direction
 * @return 
 */
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
    if (component instanceof Scrollable) {
        return ((Scrollable) component)
                .getScrollableUnitIncrement(visibleRect, orientation, direction);
    } else {
        return 10;
    }
}
项目:genomeartist    文件:JScrollableBottomSpacingContainer.java   
/**
 * Obtine marimea blocului de scroll
 * @param visibleRect
 * @param orientation
 * @param direction
 * @return 
 */
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
    if (component instanceof Scrollable) {
        return ((Scrollable) component)
                .getScrollableBlockIncrement(visibleRect, orientation, direction);
    } else {
        return 10;
    }
}
项目:genomeartist    文件:JScrollableBottomSpacingContainer.java   
/**
 * Obtine boolean daca viewportul va incerca sa mareasca width-ul 
 *  containerul sau va folosi scroll
 * @return 
 */
public boolean getScrollableTracksViewportWidth() {
    if (component instanceof Scrollable) {
        return ((Scrollable) component)
                .getScrollableTracksViewportWidth();
    } else {
        return false;
    }
}
项目:genomeartist    文件:JScrollableBottomSpacingContainer.java   
/**
 * Obtine boolean daca viewportul va incerca sa mareasca heightul
 *  containerul sau va folosi scroll
 * @return 
 */
public boolean getScrollableTracksViewportHeight() {
    if (component instanceof Scrollable) {
        boolean parentIsViewport = getParent() instanceof JViewport;
        boolean parentHeightIsBigger = 
                getParent().getHeight() > component.getPreferredSize().height+spacerHeight;

        //Intorc rezultatul
        return  parentIsViewport && parentHeightIsBigger;
    } else {
        return false;
    }
}
项目:genomeartist    文件:JScrollableBottomSpacingContainer.java   
/**
 * Obtine dimensiunea preferata a ferestrei de scroll
 * @return 
 */
public Dimension getPreferredScrollableViewportSize() {
    if (component instanceof Scrollable) {
        return ((Scrollable) component)
                .getPreferredScrollableViewportSize();
    } else {
        return new Dimension(100, 100);
    }
}
项目:CodenameOne    文件:BasicOutlookBarUI.java   
public JScrollPane makeScrollPane(Component component) {
  // the component is not scrollable, wraps it in a ScrollableJPanel
  JScrollPane scroll = new JScrollPane();
  scroll.setBorder(BorderFactory.createEmptyBorder());
  if (component instanceof Scrollable) {
    scroll.getViewport().setView(component);
  } else {
    scroll.getViewport().setView(new ScrollableJPanel(component));
  }
  scroll.setOpaque(false);
  scroll.getViewport().setOpaque(false);
  return scroll;
}
项目:cn1    文件:BasicOutlookBarUI.java   
public JScrollPane makeScrollPane(Component component) {
  // the component is not scrollable, wraps it in a ScrollableJPanel
  JScrollPane scroll = new JScrollPane();
  scroll.setBorder(BorderFactory.createEmptyBorder());
  if (component instanceof Scrollable) {
    scroll.getViewport().setView(component);
  } else {
    scroll.getViewport().setView(new ScrollableJPanel(component));
  }
  scroll.setOpaque(false);
  scroll.getViewport().setOpaque(false);
  return scroll;
}
项目:studio    文件:IndexedEditorPanel.java   
private boolean isEditorScrollable(PropertyPanel p) {
    Component[] comps = p.getComponents();
    for (int i=0; i< comps.length; i++) {
        if ( comps[i] instanceof Scrollable || comps[i] instanceof TopComponent )
            return true;
    }

    return false;
}
项目:spring-rich-client    文件:OverlayHelperTests.java   
/**
     * Ensures that OverlayHelper supports the Scrollable interface and properly proxies Scrollable methods.
     * 
     * @throws Exception
     */
    private void performScrollableTest() throws Exception {
        final ScrollablePanel view = new ScrollablePanel(new BorderLayout());
        view.setScrollableUnitIncrement(5);
        view.setScrollableBlockIncrement(30);
        view.setScrollableTracksViewportWidth(true);

        final JComponent overlay = createTestOverlay();
        final JComponent someField = createTestComponent();

        OverlayHelper.attachOverlay(overlay, someField, 0, 0, 0);

        view.add(someField);

        final JScrollPane scrollPane = new JScrollPane(view);

        waitUntilEventQueueIsEmpty();

        final Component viewportView = scrollPane.getViewport().getView();

        // If OverlayHelper changes the way it handles scrollable overlays,
        // then the test will need to be revisited - this makes sure it
        // won't get ignored. :)
//        assertFalse(viewportView == view);

        assertTrue(viewportView instanceof Scrollable);
        assertTrue(((Scrollable) viewportView).getScrollableTracksViewportWidth());
        assertFalse(((Scrollable) viewportView).getScrollableTracksViewportHeight());
        assertEquals(5, ((Scrollable) viewportView).getScrollableUnitIncrement(null, 0, 0));
        assertEquals(30, ((Scrollable) viewportView).getScrollableBlockIncrement(null, 0, 0));
        assertEquals(view.getPreferredScrollableViewportSize(), ((Scrollable) viewportView)
                .getPreferredScrollableViewportSize());
    }
项目:spring-rich-client    文件:OverlayHelperTests.java   
public void testSwapScrollableForNonScrollable() throws Exception {
        JComponent view = new ScrollablePanel(new BorderLayout());

        final JComponent overlay = createTestOverlay();
        final JComponent someField = createTestComponent();

        OverlayHelper.attachOverlay(overlay, someField, 0, 0, 0);

        view.add(someField);

        final JScrollPane scrollPane = new JScrollPane(view);

        waitUntilEventQueueIsEmpty();

        Component viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertTrue(viewportView instanceof Scrollable);

        view.remove(someField);
        view = new JPanel(new BorderLayout());
        view.add(someField);
        scrollPane.setViewportView(view);

        waitUntilEventQueueIsEmpty();

        viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertFalse(viewportView instanceof Scrollable);

        view.remove(someField);
        view = new ScrollablePanel(new BorderLayout());
        view.add(someField);
        scrollPane.setViewportView(view);

        waitUntilEventQueueIsEmpty();

        viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertTrue(viewportView instanceof Scrollable);
    }
项目:spring-richclient    文件:OverlayHelperTests.java   
/**
     * Ensures that OverlayHelper supports the Scrollable interface and properly proxies Scrollable methods.
     * 
     * @throws Exception
     */
    private void performScrollableTest() throws Exception {
        final ScrollablePanel view = new ScrollablePanel(new BorderLayout());
        view.setScrollableUnitIncrement(5);
        view.setScrollableBlockIncrement(30);
        view.setScrollableTracksViewportWidth(true);

        final JComponent overlay = createTestOverlay();
        final JComponent someField = createTestComponent();

        OverlayHelper.attachOverlay(overlay, someField, 0, 0, 0);

        view.add(someField);

        final JScrollPane scrollPane = new JScrollPane(view);

        waitUntilEventQueueIsEmpty();

        final Component viewportView = scrollPane.getViewport().getView();

        // If OverlayHelper changes the way it handles scrollable overlays,
        // then the test will need to be revisited - this makes sure it
        // won't get ignored. :)
//        assertFalse(viewportView == view);

        assertTrue(viewportView instanceof Scrollable);
        assertTrue(((Scrollable) viewportView).getScrollableTracksViewportWidth());
        assertFalse(((Scrollable) viewportView).getScrollableTracksViewportHeight());
        assertEquals(5, ((Scrollable) viewportView).getScrollableUnitIncrement(null, 0, 0));
        assertEquals(30, ((Scrollable) viewportView).getScrollableBlockIncrement(null, 0, 0));
        assertEquals(view.getPreferredScrollableViewportSize(), ((Scrollable) viewportView)
                .getPreferredScrollableViewportSize());
    }
项目:spring-richclient    文件:OverlayHelperTests.java   
public void testSwapScrollableForNonScrollable() throws Exception {
        JComponent view = new ScrollablePanel(new BorderLayout());

        final JComponent overlay = createTestOverlay();
        final JComponent someField = createTestComponent();

        OverlayHelper.attachOverlay(overlay, someField, 0, 0, 0);

        view.add(someField);

        final JScrollPane scrollPane = new JScrollPane(view);

        waitUntilEventQueueIsEmpty();

        Component viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertTrue(viewportView instanceof Scrollable);

        view.remove(someField);
        view = new JPanel(new BorderLayout());
        view.add(someField);
        scrollPane.setViewportView(view);

        waitUntilEventQueueIsEmpty();

        viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertFalse(viewportView instanceof Scrollable);

        view.remove(someField);
        view = new ScrollablePanel(new BorderLayout());
        view.add(someField);
        scrollPane.setViewportView(view);

        waitUntilEventQueueIsEmpty();

        viewportView = scrollPane.getViewport().getView();
//        assertFalse(viewportView == view);
        assertTrue(viewportView instanceof Scrollable);
    }
项目:incubator-netbeans    文件:DetailsPanel.java   
private void initComponents() {        
    table = new DetailsTable();
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JViewport viewport = new Viewport(table);

    final JScrollPane tableScroll = new JScrollPane(
                                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScroll.setViewport(viewport);
    tableScroll.setBorder(BorderFactory.createEmptyBorder());
    tableScroll.setViewportBorder(BorderFactory.createEmptyBorder());
    tableScroll.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new HeaderPanel());

    scrollBar = new ScrollBar(JScrollBar.VERTICAL) {
        public int getUnitIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
        }
        public int getBlockIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableBlockIncrement(vr, getOrientation(), direction);
        }
        public void setValues(int newValue, int newExtent, int newMin, int newMax) {
            setEnabled(newExtent < newMax);
            if (isEnabled() && !isSelectionChanging() && isTrackingEnd())
                newValue = newMax - newExtent;
            super.setValues(newValue, newExtent, newMin, newMax);
        }
    };
    tableScroll.setVerticalScrollBar(scrollBar);
    dataContainer = tableScroll;

    JLabel noDataLabel = new JLabel("<No probe selected>", JLabel.CENTER);
    noDataLabel.setEnabled(false);
    noDataContainer = new JPanel(new BorderLayout());
    noDataContainer.setOpaque(false);
    noDataContainer.add(noDataLabel, BorderLayout.CENTER);

    setOpaque(false);
    setLayout(new BorderLayout());
    add(noDataContainer, BorderLayout.CENTER);
}
项目:PhET    文件:PScrollPane.java   
/**
 * Performs the scroll action if the action was performed on visible
 * scrollbars and if the viewport is valid.
 * 
 * @param event the event responsible for this action being performed
 */
public void actionPerformed(final ActionEvent event) {
    final JScrollPane scrollpane = (JScrollPane) event.getSource();
    if (!isScrollEventOnVisibleScrollbars(scrollpane)) {
        return;
    }

    final JViewport vp = scrollpane.getViewport();
    if (vp == null) {
        return;
    }

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

    final Rectangle visRect = vp.getViewRect();
    // LEG: Modification to query the viewport for the
    // view size rather than going directly to the view
    final Dimension vSize = vp.getViewSize();
    final int amount;

    if (view instanceof Scrollable) {
        if (block) {
            amount = ((Scrollable) view).getScrollableBlockIncrement(visRect, orientation, direction);
        }
        else {
            amount = ((Scrollable) view).getScrollableUnitIncrement(visRect, orientation, direction);
        }
    }
    else {
        if (block) {
            if (orientation == SwingConstants.VERTICAL) {
                amount = visRect.height;
            }
            else {
                amount = visRect.width;
            }
        }
        else {
            amount = MINIMUM_SCROLL_SIZE;
        }
    }

    if (orientation == SwingConstants.VERTICAL) {
        visRect.y += amount * direction;
        if (visRect.y + visRect.height > vSize.height) {
            visRect.y = Math.max(0, vSize.height - visRect.height);
        }
        else if (visRect.y < 0) {
            visRect.y = 0;
        }
    }
    else {
        visRect.x += amount * direction;
        if (visRect.x + visRect.width > vSize.width) {
            visRect.x = Math.max(0, vSize.width - visRect.width);
        }
        else if (visRect.x < 0) {
            visRect.x = 0;
        }
    }
    vp.setViewPosition(visRect.getLocation());
}
项目:piccolo2d.java    文件:PScrollPane.java   
/**
 * Performs the scroll action if the action was performed on visible
 * scrollbars and if the viewport is valid.
 * 
 * @param event the event responsible for this action being performed
 */
public void actionPerformed(final ActionEvent event) {
    final JScrollPane scrollpane = (JScrollPane) event.getSource();
    if (!isScrollEventOnVisibleScrollbars(scrollpane)) {
        return;
    }

    final JViewport vp = scrollpane.getViewport();
    if (vp == null) {
        return;
    }

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

    final Rectangle visRect = vp.getViewRect();
    // LEG: Modification to query the viewport for the
    // view size rather than going directly to the view
    final Dimension vSize = vp.getViewSize();
    final int amount;

    if (view instanceof Scrollable) {
        if (block) {
            amount = ((Scrollable) view).getScrollableBlockIncrement(visRect, orientation, direction);
        }
        else {
            amount = ((Scrollable) view).getScrollableUnitIncrement(visRect, orientation, direction);
        }
    }
    else {
        if (block) {
            if (orientation == SwingConstants.VERTICAL) {
                amount = visRect.height;
            }
            else {
                amount = visRect.width;
            }
        }
        else {
            amount = MINIMUM_SCROLL_SIZE;
        }
    }

    if (orientation == SwingConstants.VERTICAL) {
        visRect.y += amount * direction;
        if (visRect.y + visRect.height > vSize.height) {
            visRect.y = Math.max(0, vSize.height - visRect.height);
        }
        else if (visRect.y < 0) {
            visRect.y = 0;
        }
    }
    else {
        visRect.x += amount * direction;
        if (visRect.x + visRect.width > vSize.width) {
            visRect.x = Math.max(0, vSize.width - visRect.width);
        }
        else if (visRect.x < 0) {
            visRect.x = 0;
        }
    }
    vp.setViewPosition(visRect.getLocation());
}
项目:PhET    文件:ControlPanel.java   
/**
 * Sets a new scroll policy for the JComponent in this ControlPanel.
 *
 * @param scrollPolicy
 */
public void setScrollPolicy( Scrollable scrollPolicy ) {
    this.scrollPolicy = scrollPolicy;
}
项目:TreeTable    文件:TreeTable.java   
/**
 * JTree and JTable have different scrolling behavior,
 * so scroll as if a JTree for vertical scrolls and
 * as a JTable for horizontal scrolls.
 *
 * @param orientation VERTICAL or HORIZONTAL
 * @return tree for VERTICAL, table for HORIZONTAL
 */
private Scrollable getScrollable(int orientation) {
    return orientation == SwingConstants.VERTICAL ? tree : table;
}