001: /*
002: * Javu WingS - Lightweight Java Component Set
003: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004: * e-mail: ksadlocha@programics.com
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.javujavu.javux.wings;
022:
023: import java.awt.Component;
024: import java.awt.Container;
025: import java.awt.Graphics;
026: import java.awt.GraphicsConfiguration;
027: import java.awt.GraphicsEnvironment;
028: import java.awt.Rectangle;
029: import java.awt.Window;
030: import java.awt.event.HierarchyEvent;
031: import java.awt.event.HierarchyListener;
032: import java.awt.event.MouseWheelEvent;
033: import java.awt.event.MouseWheelListener;
034: import java.awt.image.VolatileImage;
035:
036: /**
037: * This class overrides <code>WingTooltit</code> to provide
038: * Java version dependent methods for Java >= 1.4
039: * <br>
040: * <br>
041: * <b>This class is thread safe.</b>
042: **/
043: public class WingToolkit14 extends WingToolkit12 {
044: protected static final int VOLATILE_BUFFER_REUSE = 18;
045: protected static final int VOLATILE_RETRY = 2;
046:
047: private VolatileImage volBuffer;
048: private int volBufferUsed;
049:
050: protected VolatileImage getVolBuffer(Component c, int width,
051: int height, boolean reset) {
052: GraphicsConfiguration cg = c.getGraphicsConfiguration();
053: if (cg == null) {
054: cg = GraphicsEnvironment.getLocalGraphicsEnvironment()
055: .getDefaultScreenDevice().getDefaultConfiguration();
056: }
057:
058: width = (width + 7) & 0xfff8;
059: height = (height + 7) & 0xfff8;
060:
061: if (volBuffer != null
062: && (volBuffer.getWidth() < width
063: || volBuffer.getHeight() < height || reset || (volBufferUsed >= VOLATILE_BUFFER_REUSE
064: && volBuffer.getWidth() != width && volBuffer
065: .getHeight() != height))) {
066: volBuffer.flush();
067: volBuffer = null;
068: }
069: if (volBuffer == null) {
070: volBuffer = cg.createCompatibleVolatileImage(width, height);
071: volBufferUsed = 0;
072: }
073: volBufferUsed++;
074: return volBuffer;
075: }
076:
077: protected synchronized void paintBuffered(Component comp,
078: Graphics g, Rectangle clipBounds, Rectangle bufRect) {
079: if (WingComponent.doubleBuffering) {
080: VolatileImage vbuf = getVolBuffer(comp, bufRect.width,
081: bufRect.height, false);
082: GraphicsConfiguration gc = comp.getGraphicsConfiguration();
083: for (int i = 0; i < VOLATILE_RETRY; i++) {
084: if (vbuf.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
085: vbuf = getVolBuffer(comp, bufRect.width,
086: bufRect.height, true);
087: continue;
088: }
089: paintBuffered(comp, g, clipBounds, bufRect, vbuf);
090:
091: if (!vbuf.contentsLost()) {
092: return;
093: }
094: }
095: }
096: super .paintBuffered(comp, g, clipBounds, bufRect);
097: }
098:
099: protected void addWheelListener(final WingComponent src,
100: final WingComponent target) {
101: src.addMouseWheelListener(new MouseWheelListener() {
102: public void mouseWheelMoved(MouseWheelEvent e) {
103: target.mouseWheelMoved(e.getSource(), e
104: .getWheelRotation());
105: }
106: });
107: }
108:
109: public void addHierarchyListener(final WingComponent c) {
110: c.addHierarchyListener(new HierarchyListener() {
111: public void hierarchyChanged(HierarchyEvent e) {
112: if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
113: c.wingHierarchyChanged(c.isShowing());
114: }
115: }
116: });
117: }
118:
119: public void requestFocusInWindow(Container c) {
120: c.requestFocusInWindow();
121: }
122:
123: protected Window createPopup(WingComponent origin,
124: WingComponent content, boolean focusableWindow) {
125: Window w = super.createPopup(origin, content, focusableWindow);
126: w.setFocusableWindowState(focusableWindow);
127: return w;
128: }
129:
130: }
|