Issue #588 Made Canvas sizes stay in sync to fix text size issues

Change-Id: I1a9bff16168eda355850d47983fe479853e2e907

Former-commit-id: c7ea0894bb [formerly 8b6bb90e6ba0f1b21e78594ff3b3604924662138]
Former-commit-id: fdbd626715
This commit is contained in:
Max Schenkelberg 2012-05-14 12:38:19 -05:00
parent 01f852004b
commit d44ba58859
9 changed files with 309 additions and 78 deletions

View file

@ -19,7 +19,19 @@
**/
package com.raytheon.uf.viz.collaboration.display.editor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import com.raytheon.uf.viz.collaboration.display.editor.input.CollaborationInputHandler;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.core.rsc.IInputHandler.InputPriority;
import com.raytheon.viz.ui.editor.AbstractEditor;
@ -50,11 +62,48 @@ public class CollaborationEditor extends AbstractEditor {
private String sessionId;
private Composite canvasComp;
private ScrolledComposite scrollable;
private CollaborationInputHandler inputHandler = new CollaborationInputHandler();
@Override
protected PaneManager getNewPaneManager() {
return new PaneManager();
return new PaneManager() {
@Override
public IDisplayPane addPane(IRenderableDisplay renderableDisplay) {
// // scrollable composite
scrollable = new ScrolledComposite(composite, SWT.H_SCROLL
| SWT.V_SCROLL);
scrollable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
// Sets background color of scrollable composite to white
scrollable.setBackground(scrollable.getDisplay()
.getSystemColor(SWT.COLOR_WHITE));
// Composite for canvas (fixed size)
canvasComp = new Composite(scrollable, SWT.NONE);
GridLayout gl = new GridLayout(1, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
canvasComp.setLayout(gl);
canvasComp.setSize(1000, 1000);
// Set canvasComp as content on scrollable
scrollable.setContent(canvasComp);
scrollable.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
setCanvasSize(canvasComp.getBounds());
}
});
IDisplayPane pane = addPane(renderableDisplay, canvasComp);
canvasComp.layout();
return pane;
}
};
}
@Override
@ -80,4 +129,24 @@ public class CollaborationEditor extends AbstractEditor {
this.sessionId = sessionId;
}
public void setCanvasSize(Rectangle bounds) {
canvasComp.setSize(bounds.width, bounds.height);
// This code centers the GLCanvas in the scrollable composite
ScrollBar vertical = scrollable.getVerticalBar();
ScrollBar horizon = scrollable.getHorizontalBar();
Rectangle scrollableBounds = scrollable.getBounds();
if (vertical.isVisible()) {
scrollableBounds.width -= vertical.getSize().x;
}
if (horizon.isVisible()) {
scrollableBounds.height -= horizon.getSize().y;
}
canvasComp.setLocation(
Math.max(0, (scrollableBounds.width - bounds.width) / 2),
Math.max(0, (scrollableBounds.height - bounds.height) / 2));
canvasComp.layout();
}
}

View file

@ -37,6 +37,7 @@ import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.IRenderFrame
import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.MouseLocationEvent;
import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.RenderFrame;
import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.RenderFrameNeededEvent;
import com.raytheon.uf.viz.collaboration.ui.rsc.ParticipantInitializedEvent;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
@ -151,10 +152,17 @@ public class CollaborationDispatcher extends Dispatcher {
// Remove and dispose to reset frame
previousFrames.remove(needed);
needed.dispose();
display.refresh();
}
}
}
@Subscribe
public void handleParticipantInitialized(ParticipantInitializedEvent event) {
// Force repaint when participant initializes
display.refresh();
}
/*
* (non-Javadoc)
*

View file

@ -27,7 +27,6 @@ import java.util.Set;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import com.google.common.eventbus.EventBus;
@ -35,6 +34,8 @@ import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession;
import com.raytheon.uf.viz.collaboration.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.display.editor.CollaborationEditor;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.FrameDisposed;
import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.IPersistedEvent;
@ -45,9 +46,8 @@ import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.RenderFrameN
import com.raytheon.uf.viz.collaboration.ui.role.dataprovider.event.UpdateRenderFrameEvent;
import com.raytheon.uf.viz.collaboration.ui.rsc.rendering.CollaborationRenderingDataManager;
import com.raytheon.uf.viz.collaboration.ui.rsc.rendering.CollaborationRenderingHandler;
import com.raytheon.uf.viz.core.IExtent;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.PixelExtent;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
import com.raytheon.uf.viz.core.drawables.PaintProperties;
@ -103,8 +103,6 @@ public class CollaborationResource extends
private MouseLocationEvent latestMouseLocation;
private IExtent providerWindow;
private Set<Integer> waitingOnObjects = new HashSet<Integer>();
private Set<Integer> waitingOnFrames = new HashSet<Integer>();
@ -128,15 +126,6 @@ public class CollaborationResource extends
@Override
protected void paintInternal(IGraphicsTarget target,
PaintProperties paintProps) throws VizException {
if (previousBounds == null
|| previousBounds.equals(paintProps.getCanvasBounds()) == false) {
if (previousBounds != null && providerWindow != null) {
adjustView(providerWindow);
}
previousBounds = paintProps.getCanvasBounds();
issueRefresh();
return;
}
List<AbstractDispatchingObjectEvent> currentDataChangeEvents = new LinkedList<AbstractDispatchingObjectEvent>();
synchronized (dataChangeEvents) {
if (waitingOnObjects.size() == 0) {
@ -152,16 +141,6 @@ public class CollaborationResource extends
}
}
if (providerWindow != null) {
IExtent clippingPane = paintProps.getClippingPane();
clippingPane = new PixelExtent(Math.max(providerWindow.getMinX(),
clippingPane.getMinX()), Math.min(providerWindow.getMaxX(),
clippingPane.getMaxX()), Math.max(providerWindow.getMinY(),
clippingPane.getMinY()), Math.min(providerWindow.getMaxY(),
clippingPane.getMaxY()));
paintProps.setClippingPane(clippingPane);
}
dataManager.beginRender(target, paintProps);
List<IRenderEvent> toRender = new LinkedList<IRenderEvent>();
@ -181,29 +160,6 @@ public class CollaborationResource extends
renderingRouter.post(latestMouseLocation);
}
}
if (providerWindow != null) {
// Render yellow box to show data provider visible area
target.clearClippingPlane();
IExtent currExtent = paintProps.getView().getExtent();
float size = 1.0f;
double xOffset = size
* (currExtent.getWidth() / paintProps.getCanvasBounds().width);
double yOffset = size
* (currExtent.getHeight() / paintProps.getCanvasBounds().height);
double minX = Math.max(currExtent.getMinX(),
providerWindow.getMinX());
double maxX = Math.min(currExtent.getMaxX(),
providerWindow.getMaxX());
double minY = Math.max(currExtent.getMinY(),
providerWindow.getMinY());
double maxY = Math.min(currExtent.getMaxY(),
providerWindow.getMaxY());
target.drawRect(new PixelExtent(minX - xOffset, maxX + xOffset,
minY - yOffset, maxY + yOffset), new RGB(255, 255, 0),
size + 1, 1.0f);
target.setupClippingPlane(paintProps.getClippingPane());
}
}
public void lockObject(int objectId) {
@ -227,10 +183,24 @@ public class CollaborationResource extends
.createRenderingHandlers(dataManager)) {
renderingRouter.register(handler);
}
ISharedDisplaySession session = resourceData.getSession();
ParticipantInitializedEvent event = new ParticipantInitializedEvent();
event.setUserId(session.getUserID().getFQName());
try {
session.sendObjectToPeer(session.getCurrentDataProvider(), event);
} catch (CollaborationException e) {
Activator.statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
@Subscribe
public void updateRenderFrameEvent(UpdateRenderFrameEvent event) {
if (dataManager == null) {
// Haven't initialized yet, don't process
return;
}
int objectId = event.getObjectId();
RenderFrameEvent frame = dataManager.getRenderableObject(objectId,
RenderFrameEvent.class, false);
@ -349,11 +319,29 @@ public class CollaborationResource extends
if (renderable instanceof BeginFrameEvent) {
// Handle begin frame event immediately before next
// paint occurs
IRenderableDisplay display = descriptor
final IRenderableDisplay display = descriptor
.getRenderableDisplay();
BeginFrameEvent bfe = (BeginFrameEvent) renderable;
adjustView(bfe.getExtent());
final BeginFrameEvent bfe = (BeginFrameEvent) renderable;
display.setBackgroundColor(bfe.getColor());
final CollaborationEditor editor = SharedDisplaySessionMgr
.getSessionContainer(
resourceData.getSession()
.getSessionId())
.getCollaborationEditor();
if (previousBounds == null
|| previousBounds.equals(bfe.getBounds()) == false) {
previousBounds = bfe.getBounds();
VizApp.runAsync(new Runnable() {
@Override
public void run() {
editor.setCanvasSize(bfe.getBounds());
display.getView().setExtent(
bfe.getExtent());
}
});
} else {
display.getView().setExtent(bfe.getExtent());
}
} else {
// Add to list for processing in paintInternal
currentRenderables.add(renderable);
@ -381,31 +369,6 @@ public class CollaborationResource extends
}
}
/**
* @param frameExtent
*/
private void adjustView(IExtent frameExtent) {
IRenderableDisplay display = descriptor.getRenderableDisplay();
providerWindow = frameExtent;
Rectangle bounds = display.getBounds();
double width = frameExtent.getWidth();
double height = frameExtent.getHeight();
if (width / height > bounds.width / (double) bounds.height) {
double neededHeight = (width / bounds.width) * bounds.height;
double padding = (neededHeight - height) / 2;
frameExtent = new PixelExtent(frameExtent.getMinX(),
frameExtent.getMaxX(), frameExtent.getMinY() - padding,
frameExtent.getMaxY() + padding);
} else {
double neededWidth = (height / bounds.height) * bounds.width;
double padding = (neededWidth - width) / 2;
frameExtent = new PixelExtent(frameExtent.getMinX() - padding,
frameExtent.getMaxX() + padding, frameExtent.getMinY(),
frameExtent.getMaxY());
}
display.getView().setExtent(frameExtent);
}
/*
* (non-Javadoc)
*

View file

@ -0,0 +1,62 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui.rsc;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* Event stating the participant has initialized and is ready for rendering
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 14, 2012 mschenke Initial creation
*
* </pre>
*
* @author mschenke
* @version 1.0
*/
@DynamicSerialize
public class ParticipantInitializedEvent {
@DynamicSerializeElement
private String userId;
/**
* @return the userId
*/
public String getUserId() {
return userId;
}
/**
* @param userId
* the userId to set
*/
public void setUserId(String userId) {
this.userId = userId;
}
}

View file

@ -3,6 +3,7 @@ package com.raytheon.uf.viz.remote.graphics;
import java.awt.image.BufferedImage;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@ -12,6 +13,7 @@ import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.core.PixelExtent;
import com.raytheon.uf.viz.remote.graphics.adapters.PixelExtentSerializationAdapter;
import com.raytheon.uf.viz.remote.graphics.adapters.RGBSerializationAdapter;
import com.raytheon.uf.viz.remote.graphics.adapters.RectangleAdapter;
import com.raytheon.uf.viz.remote.graphics.adapters.RenderedImageAdapter;
/**
@ -50,6 +52,8 @@ public class Activator extends AbstractUIPlugin {
new RGBSerializationAdapter());
DynamicSerializationManager.registerAdapter(BufferedImage.class,
new RenderedImageAdapter());
DynamicSerializationManager.registerAdapter(Rectangle.class,
new RectangleAdapter());
}
/*

View file

@ -29,7 +29,12 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.geotools.coverage.grid.GeneralGridGeometry;
import com.raytheon.uf.common.colormap.IColorMap;
@ -116,9 +121,19 @@ public class DispatchGraphicsTarget extends DispatchingObject<IGraphicsTarget>
private GraphicsExtensionManager extensionManager;
public DispatchGraphicsTarget(IGraphicsTarget target, Dispatcher dispatcher) {
private Rectangle bounds;
public DispatchGraphicsTarget(IGraphicsTarget target, Canvas canvas,
Dispatcher dispatcher) {
super(target, dispatcher);
extensionManager = new GraphicsExtensionManager(this);
bounds = canvas.getBounds();
canvas.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
bounds = ((Canvas) event.widget).getBounds();
}
});
}
/*
@ -806,6 +821,7 @@ public class DispatchGraphicsTarget extends DispatchingObject<IGraphicsTarget>
BeginFrameEvent.class, this);
beginFrame.setExtent(view.getExtent().clone());
beginFrame.setColor(backgroundColor);
beginFrame.setBounds(bounds);
dispatch(beginFrame);
}

View file

@ -90,7 +90,7 @@ public class DispatchingGraphicsFactory extends AbstractGraphicsFactoryAdapter {
public IGraphicsTarget constructTarget(Canvas canvas, float width,
float height) throws VizException {
return new DispatchGraphicsTarget(delegate.constructTarget(canvas,
width, height), dispatcher);
width, height), canvas, dispatcher);
}
/*

View file

@ -0,0 +1,79 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.remote.graphics.adapters;
import org.eclipse.swt.graphics.Rectangle;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
/**
* Adapter for swt Rectangle object
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 14, 2012 mschenke Initial creation
*
* </pre>
*
* @author mschenke
* @version 1.0
*/
public class RectangleAdapter implements ISerializationTypeAdapter<Rectangle> {
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.common.serialization.ISerializationTypeAdapter#serialize
* (com.raytheon.uf.common.serialization.ISerializationContext,
* java.lang.Object)
*/
@Override
public void serialize(ISerializationContext serializer, Rectangle object)
throws SerializationException {
serializer.writeI32(object.x);
serializer.writeI32(object.y);
serializer.writeI32(object.width);
serializer.writeI32(object.height);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.common.serialization.ISerializationTypeAdapter#deserialize
* (com.raytheon.uf.common.serialization.IDeserializationContext)
*/
@Override
public Rectangle deserialize(IDeserializationContext deserializer)
throws SerializationException {
return new Rectangle(deserializer.readI32(), deserializer.readI32(),
deserializer.readI32(), deserializer.readI32());
}
}

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.viz.remote.graphics.events.rendering;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
@ -51,6 +52,9 @@ public class BeginFrameEvent extends AbstractRemoteGraphicsRenderEvent {
@DynamicSerializeElement
private RGB color;
@DynamicSerializeElement
private Rectangle bounds;
/*
* (non-Javadoc)
*
@ -69,6 +73,9 @@ public class BeginFrameEvent extends AbstractRemoteGraphicsRenderEvent {
if (color.equals(diffEvent.color) == false) {
diffObject.color = diffEvent.color;
}
if (bounds.equals(diffEvent.bounds) == false) {
diffObject.bounds = diffEvent.bounds;
}
return diffObject;
}
@ -88,6 +95,9 @@ public class BeginFrameEvent extends AbstractRemoteGraphicsRenderEvent {
if (event.color != null) {
color = event.color;
}
if (event.bounds != null) {
bounds = event.bounds;
}
}
/**
@ -120,6 +130,21 @@ public class BeginFrameEvent extends AbstractRemoteGraphicsRenderEvent {
this.color = color;
}
/**
* @return the bounds
*/
public Rectangle getBounds() {
return bounds;
}
/**
* @param bounds
* the bounds to set
*/
public void setBounds(Rectangle bounds) {
this.bounds = bounds;
}
/*
* (non-Javadoc)
*
@ -134,6 +159,11 @@ public class BeginFrameEvent extends AbstractRemoteGraphicsRenderEvent {
if (getClass() != obj.getClass())
return false;
BeginFrameEvent other = (BeginFrameEvent) obj;
if (bounds == null) {
if (other.bounds != null)
return false;
} else if (!bounds.equals(other.bounds))
return false;
if (color == null) {
if (other.color != null)
return false;