Ticket #1968: pwa-centering-deni.patch
File pwa-centering-deni.patch, 23.4 KB (added by deni, 15 years ago) |
---|
-
TabularUnified modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/book/BaseBookDocView.java
### Eclipse Workspace Patch 1.0 #P sophie
9 9 import org.sophie2.base.commons.gui.CustomScrollPane; 10 10 import org.sophie2.base.commons.util.ImageUtil; 11 11 import org.sophie2.base.commons.util.ImmImage; 12 import org.sophie2.base.commons.util.position.ImmSize; 12 13 import org.sophie2.base.layout.model.DocView; 13 14 import org.sophie2.base.media.AudioChunk; 14 15 import org.sophie2.base.media.MediaComposite; … … 231 232 modelSwing.removeAll(); 232 233 233 234 modelSwing.setLayout(new BorderLayout()); 234 235 236 ImmSize scrollPaneSize = null; 237 235 238 if (bookView().get().getViewOptions().isShowViewControls()) { 236 239 modelSwing.add(viewOptionsScrollPane().get().swingComponent(), BorderLayout.NORTH); 237 240 modelSwing.add(workAreaPane().get(), BorderLayout.CENTER); 241 242 // scrollPaneSize = new ImmSize(workAreaPane().get().getSize()); 243 // System.out.println(scrollPaneSize); 244 workArea().get().sceneVisual().get().scrollPane().set(workAreaPane().get()); 238 245 } else { 239 246 modelSwing.add(workArea().get().swingComponent().get()); 240 247 } -
TabularUnified 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 -
TabularUnified 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; … … 210 211 for (HaloMenu hm : haloMenus().get()) { 211 212 if (hm.visible().get()) { 212 213 for (JComponent c : hm.swingComponents().get()) { 213 214 res.add(c, JLayeredPane.PALETTE_LAYER);214 res.setLayer(c, JLayeredPane.PALETTE_LAYER); 215 res.add(c, CustomLayout.CUSTOM); 215 216 } 216 217 } 217 218 } -
TabularUnified modules/org.sophie2.base.scene/src/test/java/org/sophie2/base/scene/SceneDemo.java
7 7 import javax.swing.JComponent; 8 8 import javax.swing.JFrame; 9 9 import javax.swing.JPanel; 10 import javax.swing.JScrollPane; 10 11 import javax.swing.JTextPane; 11 12 import javax.swing.SwingUtilities; 12 13 … … 469 470 ImmRect.ZERO_RECT); 470 471 } 471 472 472 public RwProp< ImmRect> minimalViewRect() {473 return getBean().makeValueProp("minimalViewRect", ImmRect.class, null);473 public RwProp<JScrollPane> scrollPane() { 474 return getBean().makeValueProp("scrollPane", JScrollPane.class, null); 474 475 } 475 476 public RwProp<ImmRect> actualViewRectCache() {477 return getBean().makeValueProp("actualViewRectCache", ImmRect.class, null);478 }479 476 } 480 477 481 478 /** -
TabularUnified 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; … … 81 82 return getBean().makeValueProp("mouseOverElement", SceneElement.class, 82 83 null); 83 84 } 85 86 /** 87 * The rectangle over which the actual view rectangle will be centered. 88 * 89 * @return The property 90 */ 91 public abstract RwProp<ImmRect> centeringRect(); 84 92 } 93 No newline at end of file -
TabularUnified 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; … … 65 66 //Do nothing 66 67 } 67 68 69 @Override 70 public RwProp<ImmRect> centeringRect() { 71 return getBean().makeValueProp("centeringRect", ImmRect.class, ImmRect.ZERO_RECT); 72 } 73 68 74 } -
TabularUnified modules/org.sophie2.main.scene.simple/src/main/java/org/sophie2/main/scene/simple/SimpleSceneVisual.java
7 7 import javax.swing.JPanel; 8 8 9 9 import org.sophie2.base.commons.util.position.ImmRect; 10 import org.sophie2.base.commons.util.position.ImmSize; 10 11 import org.sophie2.base.scene.BaseSceneVisual; 11 12 import org.sophie2.base.scene.SceneVisual; 12 13 import org.sophie2.base.scene.helpers.SceneHelper; … … 51 52 SophieLog.trace("paintComponent: bounds=" + getBounds()); 52 53 SophieLog.trace("paintComponent: swing=" + toString()); 53 54 SophieLog.trace("paintComponent: parent=" + getParent()); 55 56 Graphics2D g2d = (Graphics2D) graphics.create(); 57 58 if (scrollPane().get() != null) { 59 viewportSize().set(new ImmSize(scrollPane().get().getSize())); 60 } 54 61 55 Graphics2D g2d = (Graphics2D) graphics.create();56 62 ImmRect visRect = actualViewRect().get(); 57 63 58 64 SceneHelper.paint(g2d, visRect, scene().get()); -
TabularUnified 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; 9 10 import org.sophie2.base.commons.util.position.ImmRect; 11 import org.sophie2.base.commons.util.position.ImmSize; 12 import org.sophie2.base.commons.util.position.Position; 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; … … 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); … … 96 91 @Override 97 92 protected JComponent create() { 98 93 JComponent res = createSwingComponent(); 94 95 // (deni) might be necessary to 96 // res.setLayout(null); 97 99 98 SwingEventAdapter.registerComponent(res, 100 99 BaseSceneVisual.this, null, res); 101 100 … … 111 110 } 112 111 113 112 @Override 114 protected void setup(JComponent res) { 113 protected void setup(JComponent res) { 115 114 Dimension size = actualViewRect().get().getSize().toDimension(); 116 115 res.setSize(size); 117 116 res.setPreferredSize(size); … … 123 122 @Setup 124 123 protected void setupTooltip(JComponent res) { 125 124 Scene scene = scene().get(); 126 if ( 125 if (scene != null) { 127 126 SceneElement overElement = scene.mouseOverElement().get(); 128 127 if (overElement != null) { 129 128 res.setToolTipText(overElement.tooltip().get()); … … 163 162 */ 164 163 protected static final ImmRect DEFAULT_VIEW_RECT = 165 164 new ImmRect(0, 0, 256, 256); 165 166 166 167 167 168 public Prop<ImmRect> actualViewRect() { 168 169 class actualViewRect extends AutoProperty<ImmRect> { … … 182 183 bound.getY() - DEFAULT_PADDING_T, 183 184 bound.getWidth() + DEFAULT_PADDING_R + DEFAULT_PADDING_L, 184 185 bound.getHeight() + DEFAULT_PADDING_B + DEFAULT_PADDING_T); 186 187 ImmRect centeringRect = scene().get().centeringRect().get(); 188 189 if (!centeringRect.equals(ImmRect.ZERO_RECT)) { 190 ImmRect toUnite = new ImmRect(Position.CENTER, centeringRect.getPoint(Position.CENTER), 191 viewportSize().get()); 192 res = res.union(toUnite); 193 } else { 194 ImmRect toUnite = new ImmRect(res.getLocation(), viewportSize().get()); 195 res = res.union(toUnite); 196 } 197 185 198 } else { 186 199 // can not determine... 187 // just makesomething...200 // just do something... 188 201 res = DEFAULT_VIEW_RECT; 189 202 } 190 191 // Center the actualRect on the minimalViewRect 192 // wantedViewRect is set by halo mouse tracking to limit the rect, 193 // so do nothing if wantedViewRect is not null 194 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 } 203 204 if (scrollPane().get() != null) { 205 // if there will be some scrollbars, 206 // remove their width/height from the actualViewRect 207 208 int hScrollHeight = scrollPane().get().getHorizontalScrollBar().getHeight(); 209 int vScrollWidth = scrollPane().get().getVerticalScrollBar().getWidth(); 210 211 float width = res.getWidth(); 212 float height = res.getHeight(); 213 214 if (height > viewportSize().get().getHeight() 215 && width <= viewportSize().get().getWidth()) { 216 width -= hScrollHeight; 217 } 218 219 if (width > viewportSize().get().getWidth() 220 && height <= viewportSize().get().getHeight()) { 221 height -= vScrollWidth; 222 } 223 224 res = new ImmRect(res.getLocation(), new ImmSize(width, height)); 210 225 } 211 226 212 227 assert res != null; 213 228 return res; 214 229 } … … 229 244 protected boolean computeVisible() { 230 245 return true; 231 246 } 247 248 public RwProp<JScrollPane> scrollPane() { 249 return getBean().makeValueProp("scrollPane", JScrollPane.class, null); 250 } 251 252 /** 253 * The size of the component where the scene is painted. This is the size which will be used for centering into it. 254 * 255 * @return The property. 256 */ 257 public RwProp<ImmSize> viewportSize() { 258 return getBean().makeValueProp("viewportSize", ImmSize.class, ImmSize.ZERO); 259 } 232 260 } -
TabularUnified 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 import java.io.Serializable; 9 10 import javax.swing.JDesktopPane; 11 import javax.swing.JLayeredPane; 12 13 /** 14 * LayoutManager that supports adding of components with different layouts - null 15 * and some specific layout. An object is created with a specific 16 * {@link LayoutManager2}. When different components are added, they can be with 17 * constraint - CustomLayout.CUSTOM. This means that for laying out of these 18 * components will be used null layout. For all other components added, it will 19 * be used the given layout manager. This layout manager can be used for example 20 * for {@link JDesktopPane}. For example, components at 21 * {@link JLayeredPane#DEFAULT_LAYER} can be with {@link BorderLayout} and the 22 * components at {@link JLayeredPane#PALETTE_LAYER} to be with null layout. 23 * 24 * @author tanya 25 */ 26 public class CustomLayout implements LayoutManager2, Serializable { 27 28 /** 29 * Used for serialization. 30 */ 31 private static final long serialVersionUID = 810513263396699528L; 32 33 private LayoutManager2 layoutManager; 34 35 /** 36 * The constraint for the objects which we want to be with null layout. 37 */ 38 public static final String CUSTOM = "Custom"; 39 40 /** 41 * Constructs an object with another layout manager. The components added 42 * will be with null layout or will be added according 43 * 44 * @param manager 45 * The manager which will be responsible for how the components 46 * will be added and how will be laid out. 47 */ 48 public CustomLayout(LayoutManager2 manager) { 49 this.layoutManager = manager; 50 } 51 52 public void addLayoutComponent(Component comp, Object constraints) { 53 if (constraints != CUSTOM && this.layoutManager != null) { 54 this.layoutManager.addLayoutComponent(comp, constraints); 55 } 56 } 57 58 public float getLayoutAlignmentX(Container target) { 59 if (this.layoutManager != null) { 60 return this.layoutManager.getLayoutAlignmentX(target); 61 } 62 63 return 0f; 64 } 65 66 public float getLayoutAlignmentY(Container target) { 67 if (this.layoutManager != null) { 68 return this.layoutManager.getLayoutAlignmentY(target); 69 } 70 71 return 0f; 72 } 73 74 public void invalidateLayout(Container target) { 75 if (this.layoutManager != null) { 76 this.layoutManager.invalidateLayout(target); 77 } 78 } 79 80 public Dimension maximumLayoutSize(Container target) { 81 if (this.layoutManager != null) { 82 return this.layoutManager.maximumLayoutSize(target); 83 } 84 85 return null; 86 } 87 88 public void addLayoutComponent(String name, Component comp) { 89 if (this.layoutManager != null) { 90 this.layoutManager.addLayoutComponent(name, comp); 91 } 92 } 93 94 public void layoutContainer(Container parent) { 95 if (this.layoutManager != null) { 96 this.layoutManager.layoutContainer(parent); 97 } 98 } 99 100 public Dimension minimumLayoutSize(Container parent) { 101 if (this.layoutManager != null) { 102 return this.layoutManager.minimumLayoutSize(parent); 103 } 104 105 return null; 106 } 107 108 public Dimension preferredLayoutSize(Container parent) { 109 if (this.layoutManager != null) { 110 return this.layoutManager.preferredLayoutSize(parent); 111 } 112 113 return null; 114 } 115 116 public void removeLayoutComponent(Component comp) { 117 if (this.layoutManager != null) { 118 this.layoutManager.removeLayoutComponent(comp); 119 } 120 } 121 } 122 No newline at end of file -
TabularUnified 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; … … 189 193 protected void setupScene() { 190 194 rootElement().set(rootSceneElement().get()); 191 195 topEventSource().set(PageWorkArea.this); 196 197 // TODO: maybe should check whether it is the desktop book 198 // AppMainWindow mainWindow = AppViewUtil.findMainWindow(PageWorkArea.this); 199 // DocView desktopDocument = mainWindow.desktopDocument().get() 200 // bookView().get().parent().get() 201 // ((BaseBookDocView)mainWindow.desktopDocument().get()).bookView() 202 // boolean isDesktopBook = !(bookView().get()); 203 // if (!isDesktopBook) { 204 // TODO: move in a separate setup 205 206 ImmPoint pageLocation = ImmPoint.ZERO; 207 float zoom = bookView().get().getViewOptions().getZoom(); 208 ImmSize pageSize = bookView().get().model().get().getPageSize(); 209 pageSize = new ImmSize(pageSize.getWidth() * zoom, pageSize.getHeight() * zoom); 210 ImmRect centeringRect = new ImmRect(pageLocation, pageSize); 211 212 centeringRect().set(centeringRect); 213 // } 192 214 } 193 215 }; 194 216 } … … 238 260 239 261 @Override 240 262 protected void setup(JDesktopPane res) { 263 264 res.setLayout(new CustomLayout(new BorderLayout())); 241 265 242 266 JComponent sceneComp = sceneVisual().get().swingComponent().get(); 243 267 … … 245 269 SophieLog.debug("PageWorkArea.layeredPage: sceneComp:" + sceneComp); 246 270 247 271 res.removeAll(); 248 res.add(sceneComp, JLayeredPane.DEFAULT_LAYER); 272 res.setLayer(sceneComp, JLayeredPane.DEFAULT_LAYER); 273 274 res.add(sceneComp, BorderLayout.CENTER); 249 275 250 276 res.revalidate(); 251 277 res.repaint(); 252 278 } 253 279 254 // TODO (r4) reimplement the page-work-area centering255 280 @SuppressWarnings("unused") 256 281 @Setup 257 282 protected void setupActualSize(JLayeredPane res) { -
TabularUnified modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/SceneVisual.java
1 1 package org.sophie2.base.scene; 2 2 3 3 import javax.swing.JComponent; 4 import javax.swing.JScrollPane; 4 5 5 6 import org.sophie2.base.commons.util.position.ImmRect; 6 7 import org.sophie2.base.scene.interfaces.Scene; … … 33 34 */ 34 35 RwProp<ImmRect> wantedViewRect(); 35 36 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 property43 */44 RwProp<ImmRect> minimalViewRect();45 46 /**47 * Last known value of the actual view rect, so PageWorkArea can listen for changes48 *49 * Only set this value when it has actually changed50 *51 * @return property52 */53 RwProp<ImmRect> actualViewRectCache();54 37 /** 55 38 * The swing component displaying the scene. 56 39 * … … 73 56 * @return property 74 57 */ 75 58 Prop<ImmRect> actualViewRect(); 59 60 /** 61 * The size of the component where the scene is painted. This is the size which will be used for centering into it. 62 * 63 * @return property. 64 */ 65 RwProp<JScrollPane> scrollPane(); 76 66 } -
TabularUnified modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/app/DocumentsLogic.java
7 7 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 8 8 import org.sophie2.base.model.resources.r4.changes.AutoAction; 9 9 import org.sophie2.base.skins.Message; 10 import org.sophie2.core.logging.SophieLog;11 10 import org.sophie2.core.modularity.SortKey; 12 11 import org.sophie2.core.mvc.EventFilterBuilder; 13 12 import org.sophie2.core.mvc.EventParams; … … 158 157 return true; 159 158 } 160 159 161 },162 163 164 /**165 * Handles resizing of the window by the user. Should center the page in the166 * window.167 */168 @SortKey("fff-document-resize")169 ON_RESIZE {170 171 public void defineFilter(EventFilterBuilder filter) {172 filter.setEventId(DefaultDocView.EventIds.RESIZE);173 filter.setSourceClass(DefaultDocView.class);174 }175 176 public boolean handle(EventR3 event) {177 // FIXME (R4) Reimplement page centering. This might need to go down to the layout.178 SophieLog.warn("(R4) Reimplement page centering!");179 return false;180 }181 182 160 }; 183 161 184 162 /**