annotate visualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSatelliteComponent.java @ 9971:390df0b3eefe

Refactor CompressedOopTest
author Christos Kotselidis <christos.kotselidis@oracle.com>
date Mon, 10 Jun 2013 11:06:58 +0200
parents 015fb895586b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4512
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 *
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 */
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24 package com.sun.hotspot.igv.util;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import java.awt.*;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import java.awt.event.*;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 import javax.swing.JComponent;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import org.netbeans.api.visual.widget.Scene;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 /**
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 * @author David Kaspar
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 * @author Thomas Wuerthinger
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 */
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 public class ExtendedSatelliteComponent extends JComponent implements MouseListener, MouseMotionListener, Scene.SceneListener, ComponentListener {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 private Scene scene;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 private Image image;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 private int imageWidth;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 private int imageHeight;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 public ExtendedSatelliteComponent(Scene scene) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 this.scene = scene;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 setDoubleBuffered(true);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 setPreferredSize(new Dimension(128, 128));
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 addMouseListener(this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 addMouseMotionListener(this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 public void addNotify() {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 super.addNotify();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 scene.addSceneListener(this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 JComponent viewComponent = scene.getView();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 if (viewComponent == null) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 viewComponent = scene.createView();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 viewComponent.addComponentListener(this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 repaint();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 public void removeNotify() {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 scene.getView().removeComponentListener(this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 scene.removeSceneListener(this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 super.removeNotify();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 public void update() {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 this.image = null;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 repaint();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 public void paint(Graphics g) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 Graphics2D gr = (Graphics2D) g;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 super.paint(g);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 Rectangle bounds = scene.getBounds();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 Dimension size = getSize();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 double scale = Math.min(sx, sy);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 int vw = (int) (scale * bounds.width);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 int vh = (int) (scale * bounds.height);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 int vx = (size.width - vw) / 2;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 int vy = (size.height - vh) / 2;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 if (image == null || vw != imageWidth || vh != imageHeight) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 imageWidth = vw;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 imageHeight = vh;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 image = this.createImage(imageWidth, imageHeight);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 Graphics2D ig = (Graphics2D) image.getGraphics();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 ig.scale(scale, scale);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 scene.paint(ig);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 gr.drawImage(image, vx, vy, this);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 JComponent component = scene.getView();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 double zoomFactor = scene.getZoomFactor();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 if (viewRectangle != null) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 Rectangle window = new Rectangle(
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 (int) ((double) viewRectangle.x * scale / zoomFactor),
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 (int) ((double) viewRectangle.y * scale / zoomFactor),
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 (int) ((double) viewRectangle.width * scale / zoomFactor),
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 (int) ((double) viewRectangle.height * scale / zoomFactor));
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 window.translate(vx, vy);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 gr.setColor(new Color(200, 200, 200, 128));
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 gr.fill(window);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 gr.setColor(Color.BLACK);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 public void mouseClicked(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125 public void mousePressed(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 moveVisibleRect(e.getPoint());
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 public void mouseReleased(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 moveVisibleRect(e.getPoint());
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 public void mouseEntered(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 public void mouseExited(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 public void mouseDragged(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 moveVisibleRect(e.getPoint());
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 public void mouseMoved(MouseEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 private void moveVisibleRect(Point center) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 JComponent component = scene.getView();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 if (component == null) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 return;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 double zoomFactor = scene.getZoomFactor();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 Rectangle bounds = scene.getBounds();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158 Dimension size = getSize();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 double scale = Math.min(sx, sy);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 int vw = (int) (scale * bounds.width);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 int vh = (int) (scale * bounds.height);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 int vx = (size.width - vw) / 2;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 int vy = (size.height - vh) / 2;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 int cx = (int) ((double) (center.x - vx) / scale * zoomFactor);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 int cy = (int) ((double) (center.y - vy) / scale * zoomFactor);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 Rectangle visibleRect = component.getVisibleRect();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 visibleRect.x = cx - visibleRect.width / 2;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 visibleRect.y = cy - visibleRect.height / 2;
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 component.scrollRectToVisible(visibleRect);
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 public void sceneRepaint() {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 public void sceneValidating() {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
186
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188 public void sceneValidated() {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
190
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 public void componentResized(ComponentEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 repaint();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 public void componentMoved(ComponentEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 repaint();
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 public void componentShown(ComponentEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
204
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 @Override
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 public void componentHidden(ComponentEvent e) {
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 }
015fb895586b Moved visualizer to new directory.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 }