Generated on Fri Oct 6 16:26:43 2006 for Gecode/J by doxygen 1.4.7

CenteringClipView.java

Go to the documentation of this file.
00001 package org.gecode.explorer.cocoa;
00002 
00003 import com.apple.cocoa.foundation.*;
00004 import com.apple.cocoa.application.*;
00005 
00006 
00007 public class CenteringClipView extends NSClipView {
00008     
00009     public CenteringClipView() {
00010         super();
00011     }
00012     
00013     public CenteringClipView(NSRect aRect) {
00014         super(aRect);
00015     }
00016     
00017     public void centerDocumentView() {
00018         NSRect docRect = documentView().frame();
00019         NSRect clipRect = bounds();
00020         NSSize clipRectSize = clipRect.size();
00021         float originX = clipRect.origin().x();
00022         float originY = clipRect.origin().y();
00023         if (docRect.size().width() < clipRect.size().width()) {
00024             originX =
00025             (docRect.size().width() - clipRect.size().width()) / (float) 2.0;
00026         }
00027 //        if (docRect.size().height() < clipRect.size().height()) {
00028 //            originY =
00029 //            (docRect.size().height() - clipRect.size().height()) / (float) 2.0;
00030 //        }
00031         if (documentView().isFlipped()) {
00032             originY = docRect.origin().y();
00033         } else {
00034             originY = docRect.size().height() - clipRect.size().height();
00035         }
00036         NSPoint newClipRectOrigin = new NSPoint(originX, originY);
00037         NSRect newClipRect = new NSRect(newClipRectOrigin, clipRectSize);
00038         setBounds(newClipRect);
00039         scrollToPoint(newClipRectOrigin);
00040     }
00041     
00042     public NSPoint constrainScrollPoint(NSPoint proposedNewOrigin) {
00043         NSRect docRect = documentView().frame();
00044         NSRect clipRect = bounds();
00045         float maxX = docRect.size().width() - clipRect.size().width();
00046         float maxY = docRect.size().height() - clipRect.size().height();
00047         float newScrollPointX = proposedNewOrigin.x();
00048         float newScrollPointY = proposedNewOrigin.y();
00049         if (docRect.size().width() < clipRect.size().width()) {
00050             newScrollPointX = maxX / (float) 2.0;
00051         } else {
00052             float tmp = Math.min(newScrollPointX, maxX);
00053             newScrollPointX = Math.max((float) 0, tmp);
00054         }
00055         if (docRect.size().height() < clipRect.size().height()) {
00056             //            newScrollPointY = maxY / (float) 2.0;
00057             if (documentView().isFlipped()) {
00058                 newScrollPointY = docRect.origin().y();
00059             } else {
00060                 newScrollPointY = docRect.size().height() - clipRect.size().height();
00061             }
00062         } else {
00063             float tmp = Math.min(newScrollPointY, maxY);
00064             newScrollPointY = Math.max((float) 0, tmp);
00065         }
00066         return new NSPoint(newScrollPointX, newScrollPointY);
00067     }
00068     
00069     public void viewBoundsChanged(NSNotification notification) {
00070         super.viewBoundsChanged(notification);
00071         centerDocumentView();
00072     }
00073     
00074     public void viewFrameChanged(NSNotification notification) {
00075         super.viewFrameChanged(notification);
00076         centerDocumentView();
00077     }
00078     
00079     public void setFrame(NSRect newFrameRect) {
00080         super.setFrame(newFrameRect);
00081         centerDocumentView();
00082     }
00083     
00084     public void setFrameOrigin(NSPoint newFrameOrigin) {
00085         super.setFrameOrigin(newFrameOrigin);
00086         centerDocumentView();
00087     }
00088     
00089     public void setFrameSize(NSSize newFrameSize) {
00090         super.setFrameSize(newFrameSize);
00091         centerDocumentView();
00092     }
00093     
00094     public void setFrameRotation(float newAngle) {
00095         super.setFrameRotation(newAngle);
00096         centerDocumentView();
00097     }
00098 
00099 }