Ticket #1968: centered_pwa.patch
File centered_pwa.patch, 44.5 KB (added by tanya, 15 years ago) |
---|
-
modules/org.sophie2.main.app.halos/src/main/java/org/sophie2/main/app/halos/frame/rotate/FrameRotateHaloButton.java
### Eclipse Workspace Patch 1.0 #P sophie
20 20 import org.sophie2.base.scene.interfaces.Scene; 21 21 import org.sophie2.base.skins.SkinElementId; 22 22 import org.sophie2.base.visual.skins.VisualElementDef; 23 import org.sophie2.main.app.commons.PageAreaMouseCapture; 23 24 import org.sophie2.main.app.commons.frame.FrameView; 24 25 import org.sophie2.main.app.commons.page.PageWorkArea; 25 26 import org.sophie2.main.app.halos.common.AppHaloUtil; … … 48 49 final FrameH frame = frameView.model().get(); 49 50 final double oldAngle = frame.getRotationAngle(); 50 51 51 PageWorkArea pwa = AppHaloUtil.getWorkArea(this);52 final PageWorkArea pwa = AppHaloUtil.getWorkArea(this); 52 53 final Scene scene = pwa.scene().get(); 53 54 final ImmMatrix sceneToParent = SceneHelper.getElementToSceneTransform(scene, 54 55 frameView.parent().get().sceneElement().get()).inverse(); … … 68 69 final ImmPoint oldControl = sceneToParent.transform(controlInScene); 69 70 70 71 final SceneVisual sceneVisual = pwa.sceneVisual().get(); 71 sceneVisual.wantedViewRect().set(sceneVisual. actualViewRect().get());72 sceneVisual.wantedViewRect().set(sceneVisual.lastViewRect().get()); 72 73 73 return new MouseCapture(0, 0, e) {74 return new PageAreaMouseCapture(0, 0, e) { 74 75 75 76 @Override 76 77 public void shouldMove(int newX, int newY) { … … 85 86 } 86 87 87 88 @Override 88 public void released() {89 public void onReleased() { 89 90 final Double angle = frame.getRotationAngle(); 90 91 setAngle(angle, true); 91 92 sceneVisual.wantedViewRect().set(null); … … 144 145 145 146 } 146 147 148 @Override 149 public PageWorkArea getWorkArea() { 150 return pwa; 151 } 152 147 153 }; 148 154 } 149 155 -
modules/org.sophie2.base.commons/src/main/java/org/sophie2/base/commons/util/position/ImmRect.java
336 336 public boolean contains(ImmRect other) { 337 337 return this.toRectangle().contains(other.toRectangle()); 338 338 } 339 340 /** 341 * Creates rectangle by given point and size. The given point is the center 342 * point for the rectangle. The size is the size of the rectangle. 343 * 344 * @param centerPoint 345 * The center of the rectangle. 346 * @param size 347 * The size of the rectangle. 348 * @return New rectangle. 349 */ 350 public static ImmRect create(ImmPoint centerPoint, ImmSize size) { 351 ImmPoint topLeft = new ImmPoint(centerPoint.getX() - size.getWidth()/2, 352 centerPoint.getY() - size.getHeight()/2); 353 ImmRect res = new ImmRect(topLeft, size); 354 355 return res; 356 } 339 357 } -
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/PageAreaMouseCapture.java
1 package org.sophie2.main.app.commons; 2 3 import java.awt.event.MouseEvent; 4 5 import org.sophie2.base.commons.gui.MouseCapture; 6 import org.sophie2.main.app.commons.page.PageWorkArea; 7 8 /** 9 * Modified {@link MouseCapture} for {@link PageWorkArea}. 10 * 11 * @author tanya 12 */ 13 public abstract class PageAreaMouseCapture extends MouseCapture { 14 15 /** 16 * Initiates capture. 17 * @param initCompX The current X coordinate of the component. 18 * @param initCompY The current Y coordinate of the component. 19 * @param e The mouse event initiating the capture. 20 */ 21 public PageAreaMouseCapture(int initCompX, int initCompY, MouseEvent e) { 22 super(initCompX, initCompY, e); 23 getWorkArea().scrollsLocked().set(Boolean.TRUE); 24 } 25 26 @Override 27 final public void released() { 28 onReleased(); 29 getWorkArea().scrollsLocked().set(Boolean.FALSE); 30 } 31 32 /** 33 * Called when the user has released the mouse button. Should be overrided and called in the {@link #released()}. 34 */ 35 public abstract void onReleased(); 36 37 /** 38 * Returns the {@link PageWorkArea} over which the {@link MouseCapture} is performed. 39 * 40 * @return {@link PageWorkArea} 41 */ 42 public abstract PageWorkArea getWorkArea(); 43 } 44 No newline at end of file -
modules/org.sophie2.base.halos/src/test/java/org/sophie2/base/halos/HalosDemo.java
232 232 } 233 233 234 234 /** 235 ??????* A demo implementation of the {@link ClickHaloButton}.235 * A demo implementation of the {@link ClickHaloButton}. 236 236 * 237 237 * @author peko 238 238 * -
modules/org.sophie2.base.layout/src/test/java/org/sophie2/base/layout/model/LayoutDemo.java
1 package org.sophie2.base.layout.model; 2 3 import java.awt.BorderLayout; 4 5 import javax.swing.JDesktopPane; 6 import javax.swing.JFrame; 7 import javax.swing.JInternalFrame; 8 import javax.swing.JLayeredPane; 9 10 /** 11 * Demo for demonstrating the usage of {@link CustomLayout}. 12 * @author tanya 13 */ 14 public class LayoutDemo { 15 16 /** 17 * Constructor that creates {@link JFrame}, adds a {@link JDesktopPane} with 18 * {@link CustomLayout} and set different layers to be with different 19 * layouts. 20 */ 21 public LayoutDemo() { 22 23 JFrame frame = new JFrame(); 24 frame.setSize(300, 300); 25 frame.setVisible(true); 26 27 JDesktopPane pane = new JDesktopPane(); 28 29 frame.setContentPane(pane); 30 pane.setLayout(new CustomLayout(new BorderLayout())); 31 32 JInternalFrame frame1 = new JInternalFrame(); 33 frame1.setLocation(10, 10); 34 frame1.setSize(90, 90); 35 frame1.setVisible(true); 36 37 pane.setLayer(frame1, JLayeredPane.DEFAULT_LAYER); 38 39 pane.add(frame1, BorderLayout.CENTER); 40 41 JInternalFrame frame2 = new JInternalFrame(); 42 frame2.setLocation(110, 110); 43 frame2.setSize(90, 90); 44 frame2.setVisible(true); 45 46 pane.setLayer(frame2, JLayeredPane.PALETTE_LAYER); 47 48 pane.add(frame2, CustomLayout.CUSTOM); 49 } 50 51 /** 52 * The main method. 53 * @param args 54 */ 55 public static void main(String args[]) { 56 new LayoutDemo(); 57 } 58 } 59 -
modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/view/halos/StickyMoveHaloButton.java
16 16 import org.sophie2.base.skins.SkinElementId; 17 17 import org.sophie2.base.visual.skins.VisualElementDef; 18 18 import org.sophie2.extra.func.annotations.view.StickyView; 19 import org.sophie2.main.app.commons.PageAreaMouseCapture; 19 20 import org.sophie2.main.app.commons.page.PageWorkArea; 20 21 import org.sophie2.main.app.halos.page.element.PageElementMoveHaloButton; 21 22 … … 34 35 // lock the view rect, so that we don't have auto-scrolls while moving. 35 36 final PageWorkArea workArea = workArea().get(); 36 37 final SceneVisual sv = workArea.sceneVisual().get(); 37 sv.wantedViewRect().set(sv. actualViewRect().get());38 sv.wantedViewRect().set(sv.lastViewRect().get()); 38 39 39 40 StickyView stickyView = findParentElement(StickyHaloMenu.class).stickyView().get(); 40 41 final TimePos time = stickyView.getTime(); … … 47 48 workArea.getSel().getEditScope().sceneElement().get()).inverse(); 48 49 final ImmPoint zero = sceneToParent.transform(ImmPoint.ZERO); 49 50 50 MouseCapture result = new MouseCapture(0, 0, e) {51 MouseCapture result = new PageAreaMouseCapture(0, 0, e) { 51 52 52 53 private void releaseAction(final LocationChannel locationChannel) { 53 54 final ImmPoint newlocation = … … 80 81 } 81 82 82 83 @Override 83 public void released() {84 public void onReleased() { 84 85 sv.wantedViewRect().set(null); 85 86 releaseAction(channel); 86 87 87 } 88 88 89 89 @Override 90 90 public void shouldMove(final int newX, final int newY) { 91 91 moveAction(channel, newX, newY); 92 92 } 93 94 @Override 95 public PageWorkArea getWorkArea() { 96 return workArea; 97 } 93 98 }; 94 99 95 100 return result; -
modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/interfaces/Scene.java
1 1 package org.sophie2.base.scene.interfaces; 2 2 3 3 import org.sophie2.base.commons.util.ImmColor; 4 import org.sophie2.base.commons.util.position.ImmRect; 4 5 import org.sophie2.base.scene.helpers.SceneHelper; 5 6 import org.sophie2.core.prolib.impl.BaseProObject; 6 7 import org.sophie2.core.prolib.interfaces.Prop; … … 35 36 * @return property 36 37 */ 37 38 public abstract Prop<? extends SceneElement> rootElement(); 38 39 40 /** 41 * The rectangle over which the actual view rectangle will be centered. 42 * 43 * @return property 44 */ 45 public abstract RwProp<ImmRect> centeringRect(); 46 39 47 /** 40 48 * The background color of the scene. This is the infinite area that is 41 49 * outside of any object. Note that, you should usually use elements that -
modules/org.sophie2.base.scene/src/test/java/org/sophie2/base/scene/SceneDemo.java
443 443 return component; 444 444 } 445 445 446 public Prop<ImmRect> actualViewRect() {446 public RwProp<ImmRect> lastViewRect() { 447 447 return getBean().makeValueProp("actualViewRect", ImmRect.class, 448 448 ImmRect.ZERO_RECT); 449 449 } … … 471 471 472 472 public RwProp<ImmRect> minimalViewRect() { 473 473 return getBean().makeValueProp("minimalViewRect", ImmRect.class, null); 474 } 474 } 475 475 476 public RwProp<ImmRect> actualViewRectCache() { 477 return getBean().makeValueProp("actualViewRectCache", ImmRect.class, null); 478 } 476 public RwProp<ImmRect> actualViewRect() { 477 // return getBean().makeValueProp("halosBoundSize", ImmRect.class, ImmRect.ZERO_RECT); 478 return null; 479 } 480 481 // public RwProp<ImmRect> lastViewRect() { 482 // // TODO Auto-generated method stub 483 // return null; 484 // } 479 485 } 480 486 481 487 /** -
modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/BaseSceneVisual.java
4 4 import java.util.List; 5 5 6 6 import javax.swing.JComponent; 7 import javax.swing.JScrollPane; 7 8 8 9 import org.sophie2.base.commons.util.OSUtil; 10 import org.sophie2.base.commons.util.position.ImmPoint; 9 11 import org.sophie2.base.commons.util.position.ImmRect; 12 import org.sophie2.base.commons.util.position.ImmSize; 10 13 import org.sophie2.base.dnd.SophieDragDropHandler; 11 14 import org.sophie2.base.scene.helpers.ElementHelper; 12 15 import org.sophie2.base.scene.helpers.SceneHelper; … … 70 73 } 71 74 72 75 private static final int DEFAULT_PADDING_L = 18; 73 private static final int DEFAULT_PADDING_R = 18;76 private static final int DEFAULT_PADDING_R = 30; 74 77 private static final int DEFAULT_PADDING_T = 48; 75 78 private static final int DEFAULT_PADDING_B = 18; 76 79 77 80 public RwProp<ImmRect> wantedViewRect() { 78 81 return getBean().makeValueProp("wantedViewRect", ImmRect.class, null); 79 82 } 80 83 81 public RwProp<ImmRect> minimalViewRect() {82 return getBean().makeValueProp("minimalViewRect", ImmRect.class, null);83 }84 85 public RwProp<ImmRect> actualViewRectCache() {86 return getBean().makeValueProp("actualViewRectCache", ImmRect.class, null);87 }88 89 84 @Own 90 85 public RwProp<Scene> scene() { 91 86 return getBean().makeValueProp("scene", Scene.class); 92 87 } 88 89 /** 90 * The size of the component where the scene is painted. This is the size which will be used for centering into it. 91 * 92 * @return The property. 93 */ 94 public RwProp<ImmSize> viewportSize() { 95 return getBean().makeValueProp("viewportSize", ImmSize.class, ImmSize.ZERO); 96 } 93 97 94 98 public Prop<JComponent> swingComponent() { 95 99 class swingComponent extends ResourceProperty<JComponent> { … … 112 116 113 117 @Override 114 118 protected void setup(JComponent res) { 119 115 120 Dimension size = actualViewRect().get().getSize().toDimension(); 121 122 123 int vScrollWidth = 0; 124 int hScrollHeight = 0; 125 126 if (res.getParent() != null && 127 res.getParent().getParent() != null && 128 res.getParent().getParent().getParent() != null && 129 res.getParent().getParent().getParent() instanceof JScrollPane) { 130 131 if (res.getParent().getParent().getParent() instanceof JScrollPane) { 132 JScrollPane pane = (JScrollPane)(swingComponent().get().getParent().getParent().getParent()); 133 vScrollWidth = pane.getVerticalScrollBar().getWidth(); 134 hScrollHeight = pane.getHorizontalScrollBar().getHeight(); 135 } 136 } 137 138 int newWidth = size.width; 139 int newHeight = size.height; 140 141 if (size.getWidth() <= viewportSize().get().getWidth() 142 && size.getHeight() > viewportSize().get().getHeight()) { 143 newWidth -= hScrollHeight; 144 } 145 146 if (size.getWidth() > viewportSize().get().getWidth() 147 && size.getHeight() <= viewportSize().get().getHeight()) { 148 newHeight -= vScrollWidth; 149 } 150 151 size = new Dimension(newWidth, newHeight); 152 153 minimalViewRect().get(); 154 116 155 res.setSize(size); 117 156 res.setPreferredSize(size); 118 157 res.setLayout(null); 119 158 res.revalidate(); 159 res.repaint(); 120 160 } 121 161 122 162 @SuppressWarnings("unused") … … 157 197 return getBean().makeProp(swingComponent.class); 158 198 } 159 199 200 201 160 202 /** 161 203 * A view rectangle, if it can not be determined automatically (such as, 162 204 * when no scene is set). 163 205 */ 164 206 protected static final ImmRect DEFAULT_VIEW_RECT = 165 207 new ImmRect(0, 0, 256, 256); 166 167 public Prop<ImmRect> actualViewRect() { 168 class actualViewRect extends AutoProperty<ImmRect> { 208 209 public RwProp<ImmRect> actualViewRect(){ 210 return getBean().makeValueProp("actualViewRect", ImmRect.class, ImmRect.ZERO_RECT); 211 } 212 213 public RwProp<ImmRect> lastViewRect(){ 214 return getBean().makeValueProp("lastViewRect", ImmRect.class, ImmRect.ZERO_RECT); 215 } 216 217 public Prop<ImmRect> minimalViewRect() { 218 class minimalViewRect extends AutoProperty<ImmRect> { 169 219 170 220 @Override 171 221 protected ImmRect compute() { … … 177 227 && scene().get().rootElement().get() != null) { 178 228 ImmRect bound = SceneHelper.getBoundingRect(scene().get(), 179 229 scene().get().rootElement().get()); 230 res = bound; 231 232 180 233 res = new ImmRect( 181 bound.getX() - DEFAULT_PADDING_L, 182 bound.getY() - DEFAULT_PADDING_T, 183 bound.getWidth() + DEFAULT_PADDING_R + DEFAULT_PADDING_L, 184 bound.getHeight() + DEFAULT_PADDING_B + DEFAULT_PADDING_T); 234 res.getX() - DEFAULT_PADDING_L, 235 res.getY() - DEFAULT_PADDING_T, 236 res.getWidth() + DEFAULT_PADDING_R + DEFAULT_PADDING_L, 237 res.getHeight() + DEFAULT_PADDING_B + DEFAULT_PADDING_T); 238 239 ImmRect centeringRect = scene().get().centeringRect().get(); 240 241 if (!centeringRect.equals(ImmRect.ZERO_RECT)) { 242 ImmPoint centerPoint = new ImmPoint(centeringRect.getWidth()/2, 243 centeringRect.getHeight()/2); 244 ImmRect toUnite = ImmRect.create(centerPoint, viewportSize().get()); 245 res = res.union(toUnite); 246 } else { 247 ImmRect toUnite = new ImmRect(ImmPoint.ZERO, viewportSize().get()); 248 res = res.union(toUnite); 249 } 185 250 } else { 186 251 // can not determine... 187 252 // just make something... 188 253 res = DEFAULT_VIEW_RECT; 189 254 } 190 191 // Center the actualRect on the minimalViewRect192 // wantedViewRect is set by halo mouse tracking to limit the rect,193 // so do nothing if wantedViewRect is not null194 if (wantedViewRect().get() == null) {195 ImmRect myMinimalViewRect = minimalViewRect().get();196 if (myMinimalViewRect != null) {197 float xOffset =198 Math.max((myMinimalViewRect.getWidth() - res.getWidth()) / 2, 0);199 float yOffset =200 Math.max((myMinimalViewRect.getHeight() - res.getHeight()) / 2, 0);201 res = new ImmRect(res.getX() - xOffset,202 res.getY() - yOffset,203 Math.max(res.getWidth(), myMinimalViewRect.getWidth()),204 Math.max(res.getHeight(), myMinimalViewRect.getHeight()));205 }206 207 if (!res.equals(actualViewRectCache().get())) {208 actualViewRectCache().set(res);209 }210 }211 212 255 assert res != null; 213 256 return res; 214 257 } 215 258 } 216 217 return getBean().makeProp(actualViewRect.class); 259 return getBean().makeProp(minimalViewRect.class); 218 260 } 219 261 220 262 /** 221 263 * Override this to provide logic for the creation of the Swing Component 222 264 * of this {@link SceneVisual}. -
modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/helpers/SceneHelper.java
248 248 SophieLog.trace("sceneToSwing: sceneRect=" + sceneRect); 249 249 assert sceneRect != null; 250 250 // only translation... 251 ImmRect viewRect = visual. actualViewRect().get();251 ImmRect viewRect = visual.lastViewRect().get(); 252 252 assert viewRect != null; 253 253 SophieLog.trace("sceneToSwing: viewRect=" + viewRect); 254 254 ImmRect res = Position.translate(sceneRect, -viewRect.getX(), -viewRect … … 271 271 SophieLog.trace("sceneToSwing: sceneRect=" + scenePoint); 272 272 assert scenePoint != null; 273 273 // only translation... 274 ImmRect viewRect = visual. actualViewRect().get();274 ImmRect viewRect = visual.lastViewRect().get(); 275 275 assert viewRect != null; 276 276 SophieLog.trace("sceneToSwing: viewRect=" + viewRect); 277 277 ImmPoint res = scenePoint.translate(-viewRect.getX(), -viewRect.getY()); … … 291 291 */ 292 292 public static ImmRect swingToScene(SceneVisual visual, ImmRect swingRect) { 293 293 // only translation... 294 ImmRect viewRect = visual. actualViewRect().get();294 ImmRect viewRect = visual.lastViewRect().get(); 295 295 return Position.translate(swingRect, viewRect.getX(), viewRect.getY()); 296 296 } 297 297 … … 306 306 */ 307 307 public static ImmPoint swingToScene(SceneVisual visual, ImmPoint swingPoint) { 308 308 // only translation... 309 ImmRect viewRect = visual. actualViewRect().get();309 ImmRect viewRect = visual.lastViewRect().get(); 310 310 assert viewRect != null; 311 311 return swingPoint.translate(viewRect.getX(), viewRect.getY()); 312 312 } -
modules/org.sophie2.base.layout/src/main/java/org/sophie2/base/layout/model/CustomLayout.java
1 package org.sophie2.base.layout.model; 2 3 import java.awt.BorderLayout; 4 import java.awt.Component; 5 import java.awt.Container; 6 import java.awt.Dimension; 7 import java.awt.LayoutManager2; 8 9 import javax.swing.JDesktopPane; 10 import javax.swing.JLayeredPane; 11 12 /** 13 * LayoutManager that support adding of components with different layouts - null 14 * and some specific layout. An object is created with a specific 15 * {@link LayoutManager2}. When different components are added, they can be with 16 * constraint - CustomLayout.CUSTOM. This means that for layouting of these 17 * components will be used null layout. For all other components added, it will 18 * be used the given layout manager. This layout manager can be used for example 19 * for {@link JDesktopPane}. For example, components at 20 * {@link JLayeredPane#DEFAULT_LAYER} can be with {@link BorderLayout} and the 21 * components at {@link JLayeredPane#PALETTE_LAYER} to be with null layout. 22 * 23 * @author tanya 24 */ 25 public class CustomLayout implements LayoutManager2,java.io.Serializable { 26 27 /** 28 * Used for serialization. 29 */ 30 private static final long serialVersionUID = 810513263396699528L; 31 32 private LayoutManager2 layoutManager; 33 34 /** 35 * The constraint for the objects which we want to be with null layout. 36 */ 37 public static final String CUSTOM = "Custom"; 38 39 /** 40 * Constructs an object with another layout manager. The components added 41 * will be with null layout or will be added according 42 * 43 * @param manager 44 * The manager which will be responsible for how the components 45 * will be added and how will be layouted. 46 */ 47 public CustomLayout(LayoutManager2 manager) { 48 this.layoutManager = manager; 49 } 50 51 public void addLayoutComponent(Component comp, Object constraints) { 52 if (constraints != CUSTOM && this.layoutManager != null) { 53 this.layoutManager.addLayoutComponent(comp, constraints); 54 } 55 } 56 57 public float getLayoutAlignmentX(Container target) { 58 if (this.layoutManager != null) { 59 return this.layoutManager.getLayoutAlignmentX(target); 60 } 61 62 return 0f; 63 } 64 65 public float getLayoutAlignmentY(Container target) { 66 if (this.layoutManager != null) { 67 return this.layoutManager.getLayoutAlignmentY(target); 68 } 69 70 return 0f; 71 } 72 73 public void invalidateLayout(Container target) { 74 if (this.layoutManager != null) { 75 this.layoutManager.invalidateLayout(target); 76 } 77 } 78 79 public Dimension maximumLayoutSize(Container target) { 80 if (this.layoutManager != null) { 81 return this.layoutManager.maximumLayoutSize(target); 82 } 83 84 return null; 85 } 86 87 public void addLayoutComponent(String name, Component comp) { 88 if (this.layoutManager != null) { 89 this.layoutManager.addLayoutComponent(name, comp); 90 } 91 } 92 93 public void layoutContainer(Container parent) { 94 if (this.layoutManager != null) { 95 this.layoutManager.layoutContainer(parent); 96 } 97 } 98 99 public Dimension minimumLayoutSize(Container parent) { 100 if (this.layoutManager != null) { 101 return this.layoutManager.minimumLayoutSize(parent); 102 } 103 104 return null; 105 } 106 107 public Dimension preferredLayoutSize(Container parent) { 108 if (this.layoutManager != null) { 109 return this.layoutManager.preferredLayoutSize(parent); 110 } 111 112 return null; 113 } 114 115 public void removeLayoutComponent(Component comp) { 116 if (this.layoutManager != null) { 117 this.layoutManager.removeLayoutComponent(comp); 118 } 119 } 120 } 121 No newline at end of file -
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/page/PageWorkArea.java
1 1 package org.sophie2.main.app.commons.page; 2 2 3 import java.awt.BorderLayout; 3 4 import java.util.ArrayList; 4 5 import java.util.List; 5 6 … … 10 11 import org.sophie2.base.commons.util.ImmColor; 11 12 import org.sophie2.base.commons.util.position.ImmArea; 12 13 import org.sophie2.base.commons.util.position.ImmMatrix; 14 import org.sophie2.base.commons.util.position.ImmPoint; 13 15 import org.sophie2.base.commons.util.position.ImmRect; 16 import org.sophie2.base.commons.util.position.ImmSize; 17 import org.sophie2.base.layout.model.CustomLayout; 14 18 import org.sophie2.base.model.book.PageH; 15 19 import org.sophie2.base.scene.SceneVisual; 16 20 import org.sophie2.base.scene.effects.ColorEffect; … … 157 161 @Override 158 162 protected void setupScene() { 159 163 rootElement().set(rootSceneElement().get()); 164 165 ImmPoint pageLocation = ImmPoint.ZERO; 166 float zoom = bookView().get().getViewOptions().getZoom(); 167 ImmSize pageSize = bookView().get().model().get().getPageSize(); 168 pageSize = new ImmSize(pageSize.getWidth()*zoom, pageSize.getHeight()*zoom); 169 170 ImmRect centeringRect = new ImmRect(pageLocation, pageSize); 171 172 boolean isDesktopBook = !(bookView().get().getViewOptions().isShowControls()); 173 174 if (!isDesktopBook) { 175 centeringRect().set(centeringRect); 176 } 177 160 178 topEventSource().set(PageWorkArea.this); 161 179 } 162 180 }; … … 208 226 @Override 209 227 protected void setup(JDesktopPane res) { 210 228 229 res.setLayout(new CustomLayout(new BorderLayout())); 230 211 231 JComponent sceneComp = sceneVisual().get().swingComponent().get(); 212 232 213 233 sceneComp.setLocation(0, 0); 214 234 SophieLog.debug("PageWorkArea.layeredPage: sceneComp:" + sceneComp); 215 235 216 236 res.removeAll(); 217 res.add(sceneComp, JLayeredPane.DEFAULT_LAYER); 237 res.setLayer(sceneComp, JLayeredPane.DEFAULT_LAYER); 238 239 res.add(sceneComp, BorderLayout.CENTER); 218 240 219 241 res.revalidate(); 220 242 res.repaint(); … … 224 246 @SuppressWarnings("unused") 225 247 @Setup 226 248 protected void setupActualSize(JLayeredPane res) { 227 228 // grab the value to set up the property sync229 ImmRect actualCache = sceneVisual().get().actualViewRect().get();230 231 249 JDesktopPane desktopPane = swingComponent().get(); 232 250 desktopPane.revalidate(); 233 251 desktopPane.repaint(); … … 427 445 } 428 446 return getBean().makeProp(selectionRisenElement.class); 429 447 } 448 449 /** 450 * Property which have True or False value depending on whether mouse capture event is started or not. 451 * <b>true</b> if mouse capture is on, <b>false</b> otherwise. 452 * 453 * @return property 454 */ 455 public RwProp<Boolean> scrollsLocked() { 456 return getBean().makeValueProp("scrollsLocked", Boolean.class, Boolean.FALSE); 457 } 430 458 } 459 No newline at end of file -
modules/org.sophie2.main.app.halos/src/main/java/org/sophie2/main/app/halos/page/resize/PageResizeHaloButton.java
22 22 import org.sophie2.base.visual.skins.SkinPartDef; 23 23 import org.sophie2.base.visual.skins.VisualElementDef; 24 24 import org.sophie2.core.prolib.interfaces.Prop; 25 import org.sophie2.main.app.commons.PageAreaMouseCapture; 25 26 import org.sophie2.main.app.commons.page.PageWorkArea; 26 27 import org.sophie2.main.app.halos.common.AppHaloUtil; 27 28 … … 49 50 50 51 @Override 51 52 protected MouseCapture captureClick(MouseEvent e) { 52 PageWorkArea pwa = AppHaloUtil.getWorkArea(PageResizeHaloButton.this);53 final PageWorkArea pwa = AppHaloUtil.getWorkArea(PageResizeHaloButton.this); 53 54 54 55 if(pwa !=null ){ 55 56 56 57 final SceneVisual sv = pwa.sceneVisual().get(); 57 sv.wantedViewRect().set(sv. actualViewRect().get());58 sv.wantedViewRect().set(sv.lastViewRect().get()); 58 59 59 60 final BookH book = pwa.bookView().get().model().get(); 60 61 … … 63 64 final ImmMatrix transf = SceneHelper.getElementToSceneTransform(pwa.scene().get(), pwa.rootSceneElement().get()); 64 65 65 66 ImmVector resizedSize = transf.transform(v); 66 return new MouseCapture((int) resizedSize.getPointX(), (int) resizedSize.getPointY(),67 return new PageAreaMouseCapture((int) resizedSize.getPointX(), (int) resizedSize.getPointY(), 67 68 e) { 68 69 69 70 @Override 70 public void released() {71 public void onReleased() { 71 72 sv.wantedViewRect().set(null); 72 73 73 74 74 new AutoAction("Set page size", true) { 75 75 76 76 @Override … … 112 112 }.register(book.getAccess()); 113 113 } 114 114 115 @Override 116 public PageWorkArea getWorkArea() { 117 return pwa; 118 } 119 115 120 }; 116 121 } 117 122 return null; -
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/page/ScenePageLogic.java
4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 6 7 import org.sophie2.base.commons.gui.MouseCapture;8 7 import org.sophie2.base.commons.util.position.ImmArea; 9 8 import org.sophie2.base.commons.util.position.ImmMatrix; 10 9 import org.sophie2.base.commons.util.position.ImmPoint; … … 31 30 import org.sophie2.core.mvc.OperationDef; 32 31 import org.sophie2.core.mvc.SortKey; 33 32 import org.sophie2.core.mvc.events.EventR3; 33 import org.sophie2.main.app.commons.PageAreaMouseCapture; 34 34 import org.sophie2.main.app.commons.app.AppMainWindow; 35 35 import org.sophie2.main.app.commons.book.BookDocView; 36 36 import org.sophie2.main.app.commons.book.BookViewOptions; … … 130 130 131 131 MouseEvent cause = event.getCausingEvent(EventR3.class).getCausingEvent( 132 132 MouseEvent.class); 133 new MouseCapture(0, 0, cause) {133 new PageAreaMouseCapture(0, 0, cause) { 134 134 135 135 @Override 136 public void released() {136 public void onReleased() { 137 137 pwa.selectionArea().set(ImmArea.EMPTY); 138 138 } 139 139 … … 169 169 pwa.getSel().select(toSelect, false); 170 170 } 171 171 } 172 173 @Override 174 public PageWorkArea getWorkArea() { 175 return pwa; 176 } 172 177 }; 173 178 return true; 174 179 } -
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/app/AppMainWindow.java
14 14 import org.sophie2.base.commons.util.position.ImmRect; 15 15 import org.sophie2.base.halos.HaloMenu; 16 16 import org.sophie2.base.layout.impl.DefaultMainWindow; 17 import org.sophie2.base.layout.model.CustomLayout; 17 18 import org.sophie2.base.layout.model.DocView; 18 19 import org.sophie2.base.media.MediaComposite; 19 20 import org.sophie2.base.media.MediaUtil; … … 211 212 if (hm.visible().get()) { 212 213 for (JComponent c : hm.swingComponents().get()) { 213 214 214 res.add(c, JLayeredPane.PALETTE_LAYER); 215 res.setLayer(c, JLayeredPane.PALETTE_LAYER); 216 res.add(c, CustomLayout.CUSTOM); 217 215 218 } 216 219 } 217 220 } … … 235 238 } 236 239 PageWorkArea workArea = bookDocView.workArea().get(); 237 240 238 JDesktopPane res = workArea.swingComponent().get(); 239 240 // The scene bounds 241 ImmRect bounds = workArea.sceneVisual().get().actualViewRect().get(); 242 // The bounds of visible huds 243 for (HaloMenu hm : haloMenus().get()) { 241 if (!workArea.scrollsLocked().get()) { 244 242 245 bounds = bounds.union(SceneHelper.swingToScene( 246 workArea.sceneVisual().get(), hm.activeBounds().get())); 247 } 243 JDesktopPane res = workArea.swingComponent().get(); 248 244 249 bounds = SceneHelper.sceneToSwing(workArea.sceneVisual().get(), bounds); 250 Dimension d = bounds.getSize().toDimension(); 245 // The scene bounds 246 ImmRect bounds = workArea.sceneVisual().get().minimalViewRect().get(); 247 // The bounds of visible huds 248 for (HaloMenu hm : haloMenus().get()) { 249 bounds = bounds.union(SceneHelper.swingToScene( 250 workArea.sceneVisual().get(), hm.activeBounds().get())); 251 } 252 bounds = SceneHelper.sceneToSwing(workArea.sceneVisual() 253 .get(), bounds); 251 254 252 res.setPreferredSize(d); 253 res.setSize(d); 254 res.revalidate(); 255 Dimension dim = bounds.getSize().toDimension(); 256 workArea.sceneVisual().get().actualViewRect().set( 257 new ImmRect(workArea.sceneVisual().get().minimalViewRect().get().getX(), 258 workArea.sceneVisual().get().minimalViewRect().get().getY(), dim.width, dim.height)); 259 } 255 260 } 256 257 261 } 258 262 return getBean().makeProp(haloSync.class); 259 263 } -
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/frame/FrameLogic.java
2 2 3 3 import java.awt.event.MouseEvent; 4 4 5 import org.sophie2.base.commons.gui.MouseCapture;6 5 import org.sophie2.base.commons.util.position.ImmMatrix; 7 6 import org.sophie2.base.commons.util.position.ImmPoint; 8 7 import org.sophie2.base.commons.util.position.ImmSize; … … 24 23 import org.sophie2.core.mvc.EventFilterBuilder; 25 24 import org.sophie2.core.mvc.OperationDef; 26 25 import org.sophie2.core.mvc.events.EventR3; 26 import org.sophie2.main.app.commons.PageAreaMouseCapture; 27 27 import org.sophie2.main.app.commons.element.ElementView; 28 28 import org.sophie2.main.app.commons.element.ResizeAreaSceneElement.ResizeSubAreaElement; 29 29 import org.sophie2.main.app.commons.page.PageWorkArea; … … 55 55 final ElementView elementView = event.getSource(ElementView.class); 56 56 final ResourceAccess access = elementView.getAccess(); 57 57 58 PageWorkArea pwa = elementView.getPwa();58 final PageWorkArea pwa = elementView.getPwa(); 59 59 Mode sizeTemplateMode = ResizableElement.KEY_SIZE.getMode(access); 60 60 Mode locTemplateMode = MemberElement.KEY_LOCATION.getMode(access); 61 61 … … 75 75 76 76 // lock the view rect, so that we don't have auto-scrolls while moving. 77 77 final SceneVisual sv = pwa.sceneVisual().get(); 78 sv.wantedViewRect().set(sv. actualViewRect().get());78 sv.wantedViewRect().set(sv.lastViewRect().get()); 79 79 80 80 MouseEvent cause = event.getCausingEvent(EventR3.class).getCausingEvent( 81 81 MouseEvent.class); 82 82 83 new MouseCapture(0, 0, cause) {83 new PageAreaMouseCapture(0, 0, cause) { 84 84 85 85 private void doResize(final LocationChannel oldChannel) { 86 86 final ImmSize newSize = ResizableElement.KEY_SIZE.get(access); … … 100 100 } 101 101 102 102 @Override 103 public void released() {103 public void onReleased() { 104 104 doResize(channel); 105 105 sv.wantedViewRect().set(null); 106 106 } … … 173 173 174 174 } 175 175 } 176 177 @Override 178 public PageWorkArea getWorkArea() { 179 return pwa; 180 } 176 181 }; 177 182 178 183 return true; -
modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/impl/BaseScene.java
1 1 package org.sophie2.base.scene.impl; 2 2 3 3 import org.sophie2.base.commons.util.ImmColor; 4 import org.sophie2.base.commons.util.position.ImmRect; 4 5 import org.sophie2.base.scene.interfaces.Scene; 5 6 import org.sophie2.base.scene.interfaces.SceneElement; 6 7 import org.sophie2.core.prolib.impl.ResourceProperty; … … 20 21 } 21 22 22 23 @Override 24 public RwProp<ImmRect> centeringRect() { 25 return getBean().makeValueProp("centeringRect", ImmRect.class, ImmRect.ZERO_RECT); 26 } 27 28 @Override 23 29 public RwProp<ImmColor> backgroundColor() { 24 30 return getBean().makeValueProp("backgroundColor", ImmColor.class, 25 31 ImmColor.GRAY); -
modules/org.sophie2.main.scene.simple/src/main/java/org/sophie2/main/scene/simple/SimpleSceneVisual.java
1 1 package org.sophie2.main.scene.simple; 2 2 3 import java.awt.Container; 3 4 import java.awt.Graphics; 4 5 import java.awt.Graphics2D; 5 6 6 7 import javax.swing.JComponent; 7 8 import javax.swing.JPanel; 9 import javax.swing.JScrollPane; 8 10 9 11 import org.sophie2.base.commons.util.position.ImmRect; 12 import org.sophie2.base.commons.util.position.ImmSize; 10 13 import org.sophie2.base.scene.BaseSceneVisual; 11 14 import org.sophie2.base.scene.SceneVisual; 12 15 import org.sophie2.base.scene.helpers.SceneHelper; … … 16 19 /** 17 20 * Simple scene implementation. 18 21 * 19 * @author milo, peko, nenko, mira, gogov 22 * @author milo, peko, nenko, mira, gogov, tanya 20 23 */ 21 24 @SkinElementId("main.scene.simple.simple-scene-visual") 22 25 public class SimpleSceneVisual extends BaseSceneVisual { … … 37 40 private static final long serialVersionUID = 4801814966438437503L; 38 41 39 42 private long lastPaintTime = System.currentTimeMillis(); 40 43 44 private static final int OFFSET = 2; 45 41 46 @Override 42 47 protected void paintComponent(Graphics graphics) { 43 48 … … 53 58 SophieLog.trace("paintComponent: parent=" + getParent()); 54 59 55 60 Graphics2D g2d = (Graphics2D) graphics.create(); 61 //Centering the actual view rectangle. 62 63 int w = this.getParent().getParent().getParent().getWidth(); 64 int h = this.getParent().getParent().getParent().getHeight(); 65 66 67 viewportSize().set(new ImmSize(w, h)); 56 68 ImmRect visRect = actualViewRect().get(); 57 69 58 70 SceneHelper.paint(g2d, visRect, scene().get()); 59 71 72 Container container = this.getParent().getParent().getParent(); 73 if (container instanceof JScrollPane) { 74 JScrollPane pane = (JScrollPane) container; 75 76 if (!lastViewRect().get().equals(visRect)) { 77 if (lastViewRect().get().getY() > visRect.getY()) { 78 pane.getVerticalScrollBar().setValue(0); 79 } else if (lastViewRect().get().getHeight() + OFFSET + lastViewRect().get().getY() < visRect.getHeight() + visRect.getY() 80 && lastViewRect().get().getY() <= visRect.getY()) { 81 pane.getVerticalScrollBar().setValue(pane.getVerticalScrollBar().getMaximum()); 82 } 83 84 if (lastViewRect().get().getX() > visRect.getX()) { 85 pane.getHorizontalScrollBar().setValue(0); 86 } else if (lastViewRect().get().getWidth() + OFFSET + lastViewRect().get().getX() < visRect.getWidth() + visRect.getX() 87 && lastViewRect().get().getX() <= visRect.getX()) { 88 pane.getHorizontalScrollBar().setValue(pane.getHorizontalScrollBar().getMaximum()); 89 } 90 } 91 } 92 93 lastViewRect().set(visRect); 94 60 95 SophieLog.debug("paintComponent: total paint time=" 61 96 + (System.currentTimeMillis() - startTime)); 97 62 98 } 63 99 } 64 100 } -
modules/org.sophie2.main.scene.sprites/src/main/java/org/sophie2/main/scene/sprites/SpritesSceneVisual.java
52 52 SophieLog.trace("paintComponent: parent=" + getParent()); 53 53 54 54 Graphics2D g2d = (Graphics2D) graphics.create(); 55 ImmRect visRect = actualViewRect().get();55 ImmRect visRect = lastViewRect().get(); 56 56 57 57 SceneHelper.paintSprite(g2d, visRect, scene().get()); 58 58 -
modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/SceneVisual.java
32 32 * @return property 33 33 */ 34 34 RwProp<ImmRect> wantedViewRect(); 35 36 /** 37 * The smallest rectangle this scene should have. 38 * 39 * Use this to tell the scene it should be larger than its components, for example, 40 * to fill out a window. 41 * 42 * @return property 43 */ 44 RwProp<ImmRect> minimalViewRect(); 45 46 /** 47 * Last known value of the actual view rect, so PageWorkArea can listen for changes 48 * 49 * Only set this value when it has actually changed 50 * 51 * @return property 52 */ 53 RwProp<ImmRect> actualViewRectCache(); 35 54 36 /** 55 37 * The swing component displaying the scene. 56 38 * … … 72 54 * 73 55 * @return property 74 56 */ 75 Prop<ImmRect> actualViewRect(); 57 RwProp<ImmRect> lastViewRect(); 58 59 /** 60 * Minimal part of the scene that will be displayed. 61 * 62 * @return property 63 */ 64 Prop<ImmRect> minimalViewRect(); 65 66 /** 67 * Contains what the dimension of the visible part of the scene should be if 68 * we want the visible part of the scene to surround the halos. 69 * 70 * @return property 71 */ 72 RwProp<ImmRect> actualViewRect(); 76 73 } -
modules/org.sophie2.main.scene.jogl/src/main/java/org/sophie2/main/scene/jogl/JoglSceneVisual.java
64 64 public void display(GLAutoDrawable drawable) { 65 65 final GL2 gl = drawable.getGL().getGL2(); 66 66 67 SceneHelper.paint(gl, actualViewRect().get(), scene().get());67 SceneHelper.paint(gl, lastViewRect().get(), scene().get()); 68 68 } 69 69 70 70 public void reshape(GLAutoDrawable drawable, -
modules/org.sophie2.main.app.halos/src/main/java/org/sophie2/main/app/halos/frame/MainTitleBarHalo.java
45 45 import org.sophie2.core.prolib.interfaces.RwProp; 46 46 import org.sophie2.core.prolib.list.ComposingProList; 47 47 import org.sophie2.core.prolib.list.ProList; 48 import org.sophie2.main.app.commons.PageAreaMouseCapture; 48 49 import org.sophie2.main.app.commons.element.ElementView; 49 50 import org.sophie2.main.app.commons.element.GroupView; 50 51 import org.sophie2.main.app.commons.frame.FrameView; … … 253 254 */ 254 255 protected MouseCapture captureClick(MouseEvent e) { 255 256 257 final PageWorkArea pwa = workArea().get(); 258 256 259 // lock the view rect, so that we don't have auto-scrolls while moving. 257 final SceneVisual sv = workArea().get().sceneVisual().get();258 sv.wantedViewRect().set(sv. actualViewRect().get());260 final SceneVisual sv = pwa.sceneVisual().get(); 261 sv.wantedViewRect().set(sv.lastViewRect().get()); 259 262 260 263 // get the selected frame locations before start moving 261 264 ResourceRefList frameRefs = ResourceRefList.EMPTY; … … 289 292 290 293 291 294 //TODO: rewrite --milo 292 MouseCapture result = new MouseCapture(0, 0, e) {295 MouseCapture result = new PageAreaMouseCapture(0, 0, e) { 293 296 294 297 private void releasedAction( 295 298 final ImmList<ImmPoint> oldPositions, … … 341 344 } 342 345 343 346 @Override 344 public void released() {347 public void onReleased() { 345 348 sv.wantedViewRect().set(null); 346 349 releasedAction(finalOldLocations, finalFrameRefs, finalTimes); 347 350 } … … 349 352 @Override 350 353 public void shouldMove(final int newX, final int newY) { 351 354 moveAction(finalOldLocations, finalFrameRefs, finalTimes, newX, newY); 355 } 352 356 357 @Override 358 public PageWorkArea getWorkArea() { 359 return pwa; 353 360 } 354 361 }; 355 362 return result;