source: trunk/src/org/expeditee/gio/swing/ExpediteeRepaintManager.java@ 1097

Last change on this file since 1097 was 1097, checked in by davidb, 6 years ago

Newly structured files from Corey's work on logic/graphics separation

File size: 3.4 KB
Line 
1/**
2 * ExpediteeRepaintManager.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.gio.swing;
20
21import java.awt.Component;
22import java.awt.Point;
23import java.awt.Rectangle;
24
25import javax.swing.JComponent;
26import javax.swing.RepaintManager;
27
28import org.expeditee.gui.Browser;
29import org.expeditee.gui.DisplayController;
30
31public class ExpediteeRepaintManager extends RepaintManager {
32
33 private static ExpediteeRepaintManager _instance = null;
34
35 public static ExpediteeRepaintManager getInstance()
36 {
37 if (_instance == null) _instance = new ExpediteeRepaintManager();
38
39 return _instance;
40 }
41
42 private ExpediteeRepaintManager()
43 {
44 super();
45 setDoubleBufferingEnabled(false); // use as few resources as possible
46 }
47
48
49 public synchronized void addDirtyRegion(JComponent c, int x, int y, int w, int h)
50 {
51 if (c != null) {
52
53 if (Browser._theBrowser == null || c == SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()) return;
54
55 Rectangle dirty = new Rectangle();
56 convertRectangleOrigin(c, new Rectangle(x, y, w, h), dirty);
57 DisplayController.invalidateArea(SwingConversions.fromSwingRectangle(dirty));
58 DisplayController.requestRefresh(true); // ALWAYS REQUEST: Avoids AWT locks
59
60 /* if (convertRectangleOrigin(c, new Rectangle(x, y, w, h), dirty)) {
61 FrameGraphics.invalidateArea(dirty);
62 FrameGraphics.refresh(true);
63 } else {
64 FrameGraphics.invalidateArea(dirty);
65 FrameGraphics.requestRefresh(true);
66 }*/
67
68 // DEBUGGING
69 //Browser._theBrowser.g.setColor(Color.ORANGE);
70 //Browser._theBrowser.g.fillRect(dirty.x, dirty.y, dirty.width, dirty.height);
71
72 }
73 }
74
75 /*@Override
76 public void addDirtyRegion(Applet applet, int x, int y, int w, int h) {
77 // Ignore
78 }
79
80 @Override
81 public void addDirtyRegion(Window window, int x, int y, int w, int h) {
82 // Ignore
83 }*/
84
85 /**
86 * Converts a rectangle from swing/awt space to expeditee space
87 * @param c
88 * @param dirty
89 * @return
90 */
91 private boolean convertRectangleOrigin(JComponent c, Rectangle dirty, Rectangle dest)
92 {
93 Point p = new Point(0,0);
94 boolean isInContentPane = getPointInContentPane(c, p);
95 dest.setBounds(dirty);
96 dest.translate(p.x, p.y);
97 return isInContentPane;
98 }
99
100 private boolean getPointInContentPane(Component c, Point p)
101 {
102 if (c == SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()) {
103 return true;
104 } else if (c == null || c == SwingMiscManager.getIfUsingSwingGraphicsManager().getLayeredPane()) {
105 return false;
106 }
107
108 p.translate(c.getX(), c.getY());
109
110 return getPointInContentPane(c.getParent(), p);
111 }
112
113
114
115
116}
Note: See TracBrowser for help on using the repository browser.