01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: StructurePanelRepositioner.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.gui.old;
09:
10: import java.awt.*;
11: import javax.swing.*;
12:
13: class StructurePanelRepositioner extends Thread {
14: private StructurePanel mStructurePanel = null;
15: private Point mCenterPoint = null;
16: private Cursor mCursor = null;
17:
18: public StructurePanelRepositioner(StructurePanel structurePanel,
19: Point centerPoint) {
20: this (structurePanel, centerPoint, null);
21: }
22:
23: public StructurePanelRepositioner(StructurePanel structurePanel,
24: Point centerPoint, Cursor cursor) {
25: mStructurePanel = structurePanel;
26: mCenterPoint = centerPoint;
27: mCursor = cursor;
28: }
29:
30: public void run() {
31: JScrollPane scroll_pane = mStructurePanel.getScrollPane();
32: scroll_pane.getViewport().setView(mStructurePanel);
33: if (mCenterPoint != null) {
34: int view_width = scroll_pane.getWidth()
35: - scroll_pane.getVerticalScrollBar().getWidth();
36: int view_height = scroll_pane.getHeight()
37: - scroll_pane.getHorizontalScrollBar().getHeight();
38: int panel_width = mStructurePanel.getCalculatedWidth();
39: int panel_height = mStructurePanel.getCalculatedHeight();
40:
41: int topleft_x = 0;
42:
43: if (view_width < panel_width) {
44: topleft_x = mCenterPoint.x - view_width / 2;
45: if (topleft_x + view_width > panel_width) {
46: topleft_x = panel_width - view_width;
47: }
48: if (topleft_x < 0) {
49: topleft_x = 0;
50: }
51: }
52:
53: int topleft_y = 0;
54:
55: if (view_height < panel_height) {
56: topleft_y = mCenterPoint.y - view_height / 2;
57: if (topleft_y + view_height > panel_height) {
58: topleft_y = panel_height - view_height;
59: }
60: if (topleft_y < 0) {
61: topleft_y = 0;
62: }
63: }
64:
65: scroll_pane.getViewport().setViewPosition(
66: new Point(topleft_x, topleft_y));
67: }
68: if (mCursor != null) {
69: mStructurePanel.setCursor(mCursor);
70: mStructurePanel.getToolkit().sync();
71: }
72: }
73: }
|