| 1 |
package com.jidesoft.swing; |
| 2 |
|
| 3 |
import java.awt.*; |
| 4 |
|
| 5 |
import javax.swing.JFrame; |
| 6 |
import javax.swing.JPanel; |
| 7 |
import javax.swing.JScrollPane; |
| 8 |
|
| 9 |
public class CornerScrollerVisualTest { |
| 10 |
|
| 11 |
/* |
| 12 |
* Issue: if the view component is very large, the zoom must be limited or the overview becomes to small. |
| 13 |
* Possible illegal buffered image argument when the BufferedImage width/height becomes zero. |
| 14 |
* |
| 15 |
* The problem is that you can only select to scroll to the top left corner with the overview. |
| 16 |
* Although for typical components this won't be a problem. |
| 17 |
*/ |
| 18 |
public static void main(String[] args) { |
| 19 |
// TEST AGAIN AND AGAIN |
| 20 |
EventQueue.invokeLater(new Runnable() { |
| 21 |
public void run() { |
| 22 |
LargeView largeView = new LargeView(200); |
| 23 |
largeView.setPreferredSize(new Dimension(100000, 100000)); |
| 24 |
JScrollPane largePane = new JScrollPane(largeView); |
| 25 |
largePane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, new CornerScroller(largePane)); |
| 26 |
|
| 27 |
LargeView smallView = new LargeView(10); |
| 28 |
smallView.setPreferredSize(new Dimension(1600, 1200)); |
| 29 |
JScrollPane smallPane = new JScrollPane(smallView); |
| 30 |
smallPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, new CornerScroller(smallPane)); |
| 31 |
|
| 32 |
JideSplitPane split = new JideSplitPane(); |
| 33 |
split.add(smallPane); |
| 34 |
split.add(largePane); |
| 35 |
split.setProportionalLayout(true); |
| 36 |
split.setProportions(new double[] { 0.5 }); |
| 37 |
|
| 38 |
JFrame frame = new JFrame("Test"); |
| 39 |
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
| 40 |
frame.getContentPane().add(split); |
| 41 |
frame.setPreferredSize(new Dimension(800, 600)); |
| 42 |
frame.pack(); |
| 43 |
frame.setLocationRelativeTo(null); |
| 44 |
frame.setVisible(true); |
| 45 |
} |
| 46 |
}); |
| 47 |
} |
| 48 |
|
| 49 |
private static class LargeView extends JPanel { |
| 50 |
private final int scale; |
| 51 |
|
| 52 |
public LargeView(int scale) { |
| 53 |
this.scale = scale; |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
protected void paintComponent(Graphics g) { |
| 58 |
super.paintComponent(g); |
| 59 |
|
| 60 |
g.setFont(g.getFont().deriveFont(24f)); |
| 61 |
Rectangle clipBounds = g.getClipBounds(); |
| 62 |
int width = getWidth() / scale; |
| 63 |
int height = getWidth() / scale; |
| 64 |
for(int x = ((clipBounds.x / width) * width) - width / 2; x < clipBounds.x + clipBounds.width + width; x += width) { |
| 65 |
for(int y = ((clipBounds.y / height) * height) - height / 2; y < clipBounds.y + clipBounds.height + height; y += height) { |
| 66 |
g.drawString("(" + x + ", " + y + ")", x, y); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
} |