1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import java.awt.Dimension;
|
---|
5 | import java.awt.LayoutManager;
|
---|
6 | import java.awt.Rectangle;
|
---|
7 |
|
---|
8 | import javax.swing.JPanel;
|
---|
9 | import javax.swing.JScrollPane;
|
---|
10 | import javax.swing.Scrollable;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * A panel that can be scrolled vertically. It enhances the normal {@link JPanel} to allow for better scrolling.
|
---|
16 | * Scroll pane contents may extend this.
|
---|
17 | * Use {@link #getVerticalScrollPane()} once to embed it into a scroll pane.
|
---|
18 | */
|
---|
19 | public class VerticallyScrollablePanel extends JPanel implements Scrollable {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Constructs a new {@code VerticallyScrollablePanel}.
|
---|
23 | */
|
---|
24 | public VerticallyScrollablePanel() {
|
---|
25 | super();
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Constructs a new {@code VerticallyScrollablePanel}.
|
---|
30 | * @param isDoubleBuffered a boolean, true for double-buffering, which
|
---|
31 | * uses additional memory space to achieve fast, flicker-free updates
|
---|
32 | */
|
---|
33 | public VerticallyScrollablePanel(boolean isDoubleBuffered) {
|
---|
34 | super(isDoubleBuffered);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Constructs a new {@code VerticallyScrollablePanel}.
|
---|
39 | * @param layout the LayoutManager to use
|
---|
40 | * @param isDoubleBuffered a boolean, true for double-buffering, which
|
---|
41 | * uses additional memory space to achieve fast, flicker-free updates
|
---|
42 | */
|
---|
43 | public VerticallyScrollablePanel(LayoutManager layout, boolean isDoubleBuffered) {
|
---|
44 | super(layout, isDoubleBuffered);
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Constructs a new {@code VerticallyScrollablePanel}.
|
---|
49 | * @param layout the LayoutManager to use
|
---|
50 | */
|
---|
51 | public VerticallyScrollablePanel(LayoutManager layout) {
|
---|
52 | super(layout);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Returns a vertical scrollable {@code JScrollPane} containing this panel.
|
---|
57 | * @return the vertical scrollable {@code JScrollPane}
|
---|
58 | * @since 6666
|
---|
59 | */
|
---|
60 | public final JScrollPane getVerticalScrollPane() {
|
---|
61 | return GuiHelper.embedInVerticalScrollPane(this);
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public Dimension getPreferredScrollableViewportSize() {
|
---|
66 | return getPreferredSize();
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
|
---|
71 | return 20;
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public boolean getScrollableTracksViewportHeight() {
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public boolean getScrollableTracksViewportWidth() {
|
---|
81 | return true;
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Override
|
---|
85 | public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
|
---|
86 | return 10;
|
---|
87 | }
|
---|
88 | }
|
---|