1 /* 2 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import java.awt.Dimension; 29 import java.awt.Rectangle; 30 31 32 /** 33 * An interface that provides information to a scrolling container 34 * like JScrollPane. A complex component that's likely to be used 35 * as a viewing a JScrollPane viewport (or other scrolling container) 36 * should implement this interface. 37 * 38 * @see JViewport 39 * @see JScrollPane 40 * @see JScrollBar 41 * @author Hans Muller 42 * @since 1.2 43 */ 44 public interface Scrollable 45 { 46 /** 47 * Returns the preferred size of the viewport for a view component. 48 * For example, the preferred size of a <code>JList</code> component 49 * is the size required to accommodate all of the cells in its list. 50 * However, the value of <code>preferredScrollableViewportSize</code> 51 * is the size required for <code>JList.getVisibleRowCount</code> rows. 52 * A component without any properties that would affect the viewport 53 * size should just return <code>getPreferredSize</code> here. 54 * 55 * @return the preferredSize of a <code>JViewport</code> whose view 56 * is this <code>Scrollable</code> 57 * @see JViewport#getPreferredSize 58 */ 59 Dimension getPreferredScrollableViewportSize(); 60 61 62 /** 63 * Components that display logical rows or columns should compute 64 * the scroll increment that will completely expose one new row 65 * or column, depending on the value of orientation. Ideally, 66 * components should handle a partially exposed row or column by 67 * returning the distance required to completely expose the item. 68 * <p> 69 * Scrolling containers, like JScrollPane, will use this method 70 * each time the user requests a unit scroll. 71 * 72 * @param visibleRect The view area visible within the viewport 73 * @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. 74 * @param direction Less than zero to scroll up/left, greater than zero for down/right. 75 * @return The "unit" increment for scrolling in the specified direction. 76 * This value should always be positive. 77 * @see JScrollBar#setUnitIncrement 78 */ 79 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction); 80 81 82 /** 83 * Components that display logical rows or columns should compute 84 * the scroll increment that will completely expose one block 85 * of rows or columns, depending on the value of orientation. 86 * <p> 87 * Scrolling containers, like JScrollPane, will use this method 88 * each time the user requests a block scroll. 89 * 90 * @param visibleRect The view area visible within the viewport 91 * @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. 92 * @param direction Less than zero to scroll up/left, greater than zero for down/right. 93 * @return The "block" increment for scrolling in the specified direction. 94 * This value should always be positive. 95 * @see JScrollBar#setBlockIncrement 96 */ 97 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction); 98 99 100 /** 101 * Return true if a viewport should always force the width of this 102 * <code>Scrollable</code> to match the width of the viewport. 103 * For example a normal 104 * text view that supported line wrapping would return true here, since it 105 * would be undesirable for wrapped lines to disappear beyond the right 106 * edge of the viewport. Note that returning true for a Scrollable 107 * whose ancestor is a JScrollPane effectively disables horizontal 108 * scrolling. 109 * <p> 110 * Scrolling containers, like JViewport, will use this method each 111 * time they are validated. 112 * 113 * @return True if a viewport should force the Scrollables width to match its own. 114 */ 115 boolean getScrollableTracksViewportWidth(); 116 117 /** 118 * Return true if a viewport should always force the height of this 119 * Scrollable to match the height of the viewport. For example a 120 * columnar text view that flowed text in left to right columns 121 * could effectively disable vertical scrolling by returning 122 * true here. 123 * <p> 124 * Scrolling containers, like JViewport, will use this method each 125 * time they are validated. 126 * 127 * @return True if a viewport should force the Scrollables height to match its own. 128 */ 129 boolean getScrollableTracksViewportHeight(); 130 }