X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2FG2DRepaintManager.java;h=f0328f4893740dfa7434a84abd46adc66c898539;hb=e353ca45b2ad3ce36ea48336feca56e86ad0b089;hp=22b947a94580b3d8a7774de87b13c12eb6193deb;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRepaintManager.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRepaintManager.java index 22b947a94..f0328f489 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRepaintManager.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRepaintManager.java @@ -1,199 +1,199 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.scenegraph.g2d; - -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Image; -import java.awt.Rectangle; - -import javax.swing.JComponent; -import javax.swing.RepaintManager; - - -public class G2DRepaintManager extends RepaintManager { - private RepaintManager delegate; - private Class rootClass; - private final static Rectangle NULL_RECTANGLE = new Rectangle(); - private final static Dimension NULL_DIMENSION = new Dimension(); - public G2DRepaintManager(Class rootClass, RepaintManager repaintManager) { - //System.out.println("G2DRepaintManager(" + System.identityHashCode(this) + ", " + rootClass + ", " + repaintManager.getClass() + ")"); - delegate = repaintManager; - this.rootClass = rootClass; - } - - void setDelegate(RepaintManager manager) { - //System.out.println("G2DRepaintManager(" + System.identityHashCode(this) + ").setDelegate(" + manager + ")"); - this.delegate = manager; - } - - public RepaintManager getDelegate() { - return this.delegate; - } - - @Override - public void addDirtyRegion(JComponent c, int x, int y, int w, int h) { - final JComponent root = (JComponent) getAncestorOfClass(rootClass, c); - if (root != null) { - delegate.markCompletelyDirty(root); - } else if (delegate != null) { - delegate.addDirtyRegion(c, x, y, w, h); - } - } - - @Override - public void addInvalidComponent(JComponent invalidComponent) { - if (delegate != null) { - delegate.addInvalidComponent(invalidComponent); - } - } - - @Override - public Rectangle getDirtyRegion(JComponent component) { - if (delegate != null) { - return delegate.getDirtyRegion(component); - } else { - return NULL_RECTANGLE; - } - } - - @Override - public Dimension getDoubleBufferMaximumSize() { - if (delegate != null) { - return delegate.getDoubleBufferMaximumSize(); - } else { - assert false; - return NULL_DIMENSION; - } - } - - @Override - public Image getOffscreenBuffer(Component c, int proposedWidth, - int proposedHeight) { - if (delegate != null) { - return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight); - } else { - assert false; - return null; - } - } - - @Override - public Image getVolatileOffscreenBuffer(Component c, int proposedWidth, - int proposedHeight) { - if (delegate != null) { - return delegate.getVolatileOffscreenBuffer(c, proposedWidth, - proposedHeight); - } else { - assert false; - return null; - } - } - - @Override - public boolean isCompletelyDirty(JComponent component) { - if (delegate != null) { - return delegate.isCompletelyDirty(component); - } else { - assert false; - return false; - } - } - - @Override - public boolean isDoubleBufferingEnabled() { - if (delegate != null) { - return delegate.isDoubleBufferingEnabled(); - } else { - assert false; - return false; - } - } - - @Override - public void markCompletelyClean(JComponent component) { - if (delegate != null) { - delegate.markCompletelyClean(component); - } - } - - public static Container getAncestorOfClass(Class c, Component comp) - { - if(comp == null || c == null) - return null; - - if (c.isInstance(comp) && comp instanceof Container) - return (Container) comp; - - Container parent = comp.getParent(); - while(parent != null && !(c.isInstance(parent))) - parent = parent.getParent(); - return parent; - } - - @Override - public void markCompletelyDirty(JComponent component) { - final JComponent root = (JComponent) getAncestorOfClass(rootClass, component); - if (root != null) { - delegate.markCompletelyDirty(root); - } else if (delegate != null) { - delegate.markCompletelyDirty(component); - } - } - - @Override - public void paintDirtyRegions() { -// new Exception("paintDirtyRegions " + delegate).printStackTrace(); - if (delegate != null) { - delegate.paintDirtyRegions(); - } else { - assert false; - } - } - - @Override - public void removeInvalidComponent(JComponent component) { - if (delegate != null) { - delegate.removeInvalidComponent(component); - } else { - assert false; - } - } - - @Override - public void setDoubleBufferingEnabled(boolean flag) { - if (delegate != null) { - delegate.setDoubleBufferingEnabled(flag); - } else { - assert false; - } - } - - @Override - public void setDoubleBufferMaximumSize(Dimension d) { - if (delegate != null) { - delegate.setDoubleBufferMaximumSize(d); - } else { - assert false; - } - } - - @Override - public void validateInvalidComponents() { - if (delegate != null) { - delegate.validateInvalidComponents(); - } else { - assert false; - } - } - } +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.scenegraph.g2d; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Image; +import java.awt.Rectangle; + +import javax.swing.JComponent; +import javax.swing.RepaintManager; + + +public class G2DRepaintManager extends RepaintManager { + private RepaintManager delegate; + private Class rootClass; + private final static Rectangle NULL_RECTANGLE = new Rectangle(); + private final static Dimension NULL_DIMENSION = new Dimension(); + public G2DRepaintManager(Class rootClass, RepaintManager repaintManager) { + //System.out.println("G2DRepaintManager(" + System.identityHashCode(this) + ", " + rootClass + ", " + repaintManager.getClass() + ")"); + delegate = repaintManager; + this.rootClass = rootClass; + } + + void setDelegate(RepaintManager manager) { + //System.out.println("G2DRepaintManager(" + System.identityHashCode(this) + ").setDelegate(" + manager + ")"); + this.delegate = manager; + } + + public RepaintManager getDelegate() { + return this.delegate; + } + + @Override + public void addDirtyRegion(JComponent c, int x, int y, int w, int h) { + final JComponent root = (JComponent) getAncestorOfClass(rootClass, c); + if (root != null) { + delegate.markCompletelyDirty(root); + } else if (delegate != null) { + delegate.addDirtyRegion(c, x, y, w, h); + } + } + + @Override + public void addInvalidComponent(JComponent invalidComponent) { + if (delegate != null) { + delegate.addInvalidComponent(invalidComponent); + } + } + + @Override + public Rectangle getDirtyRegion(JComponent component) { + if (delegate != null) { + return delegate.getDirtyRegion(component); + } else { + return NULL_RECTANGLE; + } + } + + @Override + public Dimension getDoubleBufferMaximumSize() { + if (delegate != null) { + return delegate.getDoubleBufferMaximumSize(); + } else { + assert false; + return NULL_DIMENSION; + } + } + + @Override + public Image getOffscreenBuffer(Component c, int proposedWidth, + int proposedHeight) { + if (delegate != null) { + return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight); + } else { + assert false; + return null; + } + } + + @Override + public Image getVolatileOffscreenBuffer(Component c, int proposedWidth, + int proposedHeight) { + if (delegate != null) { + return delegate.getVolatileOffscreenBuffer(c, proposedWidth, + proposedHeight); + } else { + assert false; + return null; + } + } + + @Override + public boolean isCompletelyDirty(JComponent component) { + if (delegate != null) { + return delegate.isCompletelyDirty(component); + } else { + assert false; + return false; + } + } + + @Override + public boolean isDoubleBufferingEnabled() { + if (delegate != null) { + return delegate.isDoubleBufferingEnabled(); + } else { + assert false; + return false; + } + } + + @Override + public void markCompletelyClean(JComponent component) { + if (delegate != null) { + delegate.markCompletelyClean(component); + } + } + + public static Container getAncestorOfClass(Class c, Component comp) + { + if(comp == null || c == null) + return null; + + if (c.isInstance(comp) && comp instanceof Container) + return (Container) comp; + + Container parent = comp.getParent(); + while(parent != null && !(c.isInstance(parent))) + parent = parent.getParent(); + return parent; + } + + @Override + public void markCompletelyDirty(JComponent component) { + final JComponent root = (JComponent) getAncestorOfClass(rootClass, component); + if (root != null) { + delegate.markCompletelyDirty(root); + } else if (delegate != null) { + delegate.markCompletelyDirty(component); + } + } + + @Override + public void paintDirtyRegions() { +// new Exception("paintDirtyRegions " + delegate).printStackTrace(); + if (delegate != null) { + delegate.paintDirtyRegions(); + } else { + assert false; + } + } + + @Override + public void removeInvalidComponent(JComponent component) { + if (delegate != null) { + delegate.removeInvalidComponent(component); + } else { + assert false; + } + } + + @Override + public void setDoubleBufferingEnabled(boolean flag) { + if (delegate != null) { + delegate.setDoubleBufferingEnabled(flag); + } else { + assert false; + } + } + + @Override + public void setDoubleBufferMaximumSize(Dimension d) { + if (delegate != null) { + delegate.setDoubleBufferMaximumSize(d); + } else { + assert false; + } + } + + @Override + public void validateInvalidComponents() { + if (delegate != null) { + delegate.validateInvalidComponents(); + } else { + assert false; + } + } + }