Update Chart Viewer

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@101628 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-11-17 15:47:06 +00:00
parent 0125cf539b
commit 128c420b0b
12 changed files with 305 additions and 100 deletions

View File

@ -42,6 +42,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/tabular-data-resources-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>

View File

@ -342,4 +342,5 @@
</dependency>
</dependencies>
</dependencyManagement>
<packaging>war</packaging>
</project>

View File

@ -35,6 +35,7 @@ public class ResourcesWidgetEntry implements EntryPoint {
//dialog.show();
resourceTDDescriptor=new ResourceTDDescriptor();
resourceTDDescriptor.setName("Test Chart");
ChartViewerDialog chartDialog=new ChartViewerDialog(resourceTDDescriptor, trId, eventBus, true);
chartDialog.show();

View File

@ -16,6 +16,8 @@ import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseWheelEvent;
import com.google.gwt.event.dom.client.MouseWheelHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
@ -25,11 +27,13 @@ import com.google.gwt.safehtml.shared.SafeUri;
import com.google.gwt.safehtml.shared.UriUtils;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasValue;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
import com.sencha.gxt.chart.client.draw.DrawComponent;
import com.sencha.gxt.chart.client.draw.Scaling;
import com.sencha.gxt.chart.client.draw.Translation;
import com.sencha.gxt.chart.client.draw.sprite.ImageSprite;
import com.sencha.gxt.chart.client.draw.sprite.Sprite;
import com.sencha.gxt.chart.client.draw.sprite.SpriteOutEvent;
@ -43,13 +47,13 @@ import com.sencha.gxt.core.client.util.ToggleGroup;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.button.ToggleButton;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.sencha.gxt.widget.core.client.info.Info;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
/**
@ -77,7 +81,7 @@ public class ChartViewerPanel extends FramedPanel {
ZOOMIN, ZOOMOUT, MOVE
};
private Operation activeOperation = Operation.ZOOMIN;
private Operation activeOperation;
private Sprite activeSprite;
private Vector2D startPosition;
@ -94,11 +98,12 @@ public class ChartViewerPanel extends FramedPanel {
private ImageSprite chartSprite;
private int MAX_SCALE_FACTOR = 20;
private int MAX_SCALE_FACTOR = 32;
private int MIN_SCALE_FACTOR = 0;
private double scaleFactor = 0;
private Vector2D baseDimension;
private Vector2D fitScale;
private Vector2D chartScale;
private Vector2D chartDimension;
private DrawComponent paint;
@ -112,6 +117,7 @@ public class ChartViewerPanel extends FramedPanel {
private Timer mouseTimer;
private Vector2D chartTranslation;
private ComboBox<ZoomLevelElement> comboZoomLevel;
private TextButton btnOpenInWindow;
public ChartViewerPanel(ChartViewerDialog parent,
ResourceTDDescriptor resourceTDDescriptor, TRId trId,
@ -123,6 +129,8 @@ public class ChartViewerPanel extends FramedPanel {
ResourceTDDescriptor resourceTDDescriptor, TRId trId,
EventBus eventBus, boolean test) {
super();
ResourceBundle.INSTANCE.resourceCSS().ensureInjected();
this.parent = parent;
this.resourceTDDescriptor = resourceTDDescriptor;
this.test = test;
@ -243,20 +251,19 @@ public class ChartViewerPanel extends FramedPanel {
VerticalLayoutContainer layout = new VerticalLayoutContainer();
add(layout);
// ToolBar
ToolBar toolBar = new ToolBar();
btnZoomIn = new ToggleButton();
btnZoomIn.setValue(true);
btnZoomIn.setValue(false);
btnZoomIn.setIcon(ResourceBundle.INSTANCE.magnifierZoomIn());
btnZoomIn.setToolTip("Zoom In");
btnZoomIn.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
.getCursorZoomIn());
chartSprite.setCursor("zoom-in");
forceLayout();
}
});
@ -270,8 +277,8 @@ public class ChartViewerPanel extends FramedPanel {
@Override
public void onSelect(SelectEvent event) {
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
.getCursorZoomOut());
chartSprite.setCursor("zoom-out");
forceLayout();
}
});
@ -285,8 +292,7 @@ public class ChartViewerPanel extends FramedPanel {
@Override
public void onSelect(SelectEvent event) {
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
.getCursorZoomOut());
chartSprite.setCursor("move");
}
});
@ -321,9 +327,8 @@ public class ChartViewerPanel extends FramedPanel {
}
});
ZoomLevelPropertiesCombo props = GWT.create(ZoomLevelPropertiesCombo.class);
ZoomLevelPropertiesCombo props = GWT
.create(ZoomLevelPropertiesCombo.class);
ListStore<ZoomLevelElement> storeZoomLevelTypes = new ListStore<ZoomLevelElement>(
props.id());
@ -334,20 +339,29 @@ public class ChartViewerPanel extends FramedPanel {
comboZoomLevel = new ComboBox<ZoomLevelElement>(storeZoomLevelTypes,
props.label());
Log.trace("Combo created");
addHandlersForComboZoomLevel(props.label());
comboZoomLevel.setEmptyText("Zoom Level");
comboZoomLevel.setItemId("ComboZoomLevel");
comboZoomLevel.setWidth(COMBO_ZOOM_LEVEL_WIDTH);
comboZoomLevel.setEditable(false);
comboZoomLevel.setTriggerAction(TriggerAction.ALL);
toolBar.add(comboZoomLevel);;
toolBar.add(comboZoomLevel);
//
btnOpenInWindow = new TextButton();
btnOpenInWindow.setIcon(ResourceBundle.INSTANCE.application());
btnOpenInWindow.setToolTip("Open in new window");
btnOpenInWindow.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
openInNewWindow();
}
});
toolBar.add(btnOpenInWindow);
// Paint
paint = new DrawComponent();
@ -390,15 +404,36 @@ public class ChartViewerPanel extends FramedPanel {
}
}, MouseUpEvent.getType());
layout.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
layout.add(paint, new VerticalLayoutData(1, -1, new Margins(0)));
paint.addDomHandler(new MouseWheelHandler() {
@Override
public void onMouseWheel(MouseWheelEvent event) {
spriteMouseWheel(event);
}
}, MouseWheelEvent.getType());
layout.add(toolBar, new VerticalLayoutData(1, 26, new Margins(0)));
layout.add(paint, new VerticalLayoutData(1, 1, new Margins(0)));
}
protected void openInNewWindow() {
String link;
if (test) {
link = testImageResource.getSafeUri().asString();
} else {
link = chartImageResource.getSafeUri().asString();
}
Log.debug("Retrieved link: " + link);
Window.open(link, resourceTDDescriptor.getName(), "");
}
protected void drawInit() {
@ -414,32 +449,36 @@ public class ChartViewerPanel extends FramedPanel {
paint.addSprite(chartSprite);
if (test) {
Log.debug("testImageResource width:" + testImageResource.getWidth()
+ " height:" + testImageResource.getHeight());
baseDimension = new Vector2D(new Double(DRAW_WIDTH_INT)
fitScale = new Vector2D(new Double(DRAW_WIDTH_INT)
/ testImageResource.getWidth(), new Double(DRAW_HEIGHT_INT)
/ testImageResource.getHeight());
chartDimension = new Vector2D(testImageResource.getWidth(),
testImageResource.getHeight());
} else {
Log.debug("chartImageResource width:"
+ chartImageResource.getWidth() + " height:"
+ chartImageResource.getHeight());
baseDimension = new Vector2D(new Double(DRAW_WIDTH_INT)
fitScale = new Vector2D(new Double(DRAW_WIDTH_INT)
/ chartImageResource.getWidth(),
new Double(DRAW_HEIGHT_INT)
/ chartImageResource.getHeight());
chartDimension = new Vector2D(chartImageResource.getWidth(),
chartImageResource.getHeight());
}
Log.debug("Offset width:" + DRAW_WIDTH_INT + " height:"
+ DRAW_HEIGHT_INT);
Log.debug("Base Width: " + baseDimension.getX() + ", Base Height:"
+ baseDimension.getY());
Log.debug("Fit Scale: " + fitScale);
Log.debug("Chart Dimension: "+chartDimension);
chartSprite.setScaling(new Scaling(fitScale.getX(), fitScale.getY()));
chartSprite.setScaling(new Scaling(baseDimension.getX(), baseDimension
.getY()));
chartDimension = baseDimension.copy();
chartTranslation=new Vector2D();
chartScale = fitScale.copy();
chartTranslation = new Vector2D();
paint.redrawSurfaceForced();
// Image image = new Image(chartImageResource.getSafeUri());
@ -451,9 +490,9 @@ public class ChartViewerPanel extends FramedPanel {
mouseTimer = new Timer() {
@Override
public void run() {
if (activeSprite != null){
if (activeSprite != null) {
if (activeSprite == chartSprite) {
actionOnChartSpriteWhenMouseLeftDown();
actionOnChartSpriteWhenMouseLeftDown();
}
}
}
@ -474,8 +513,8 @@ public class ChartViewerPanel extends FramedPanel {
browseEvent.getClientY());
if (activeSprite != null) {
if (activeSprite == chartSprite) {
if (activeOperation.compareTo(Operation.ZOOMIN)==0
|| activeOperation.compareTo(Operation.ZOOMOUT)==0) {
if (activeOperation.compareTo(Operation.ZOOMIN) == 0
|| activeOperation.compareTo(Operation.ZOOMOUT) == 0) {
actionOnChartSpriteWhenMouseLeftDown();
comboZoomLevel.reset();
comboZoomLevel.redraw();
@ -493,17 +532,19 @@ public class ChartViewerPanel extends FramedPanel {
endPosition = new Vector2D(event.getClientX(), event.getClientY());
displacement = startPosition.sub(endPosition);
activeSprite = null;
if(mouseTimer!=null){
if (mouseTimer != null) {
mouseTimer.cancel();
}
}
protected void spriteLeave(SpriteOutEvent event) {
Event browseEvent = event.getBrowserEvent();
Log.debug("Leave Position: " + browseEvent.getClientX() + ", "
+ browseEvent.getClientY());
activeSprite = null;
if(mouseTimer!=null){
if (mouseTimer != null) {
mouseTimer.cancel();
}
}
@ -529,6 +570,19 @@ public class ChartViewerPanel extends FramedPanel {
}
protected void spriteMouseWheel(MouseWheelEvent event) {
int deltaY=event.getDeltaY();
Log.debug("Wheel: "+deltaY);
if(deltaY<0){
zoomIn();
} else {
zoomOut();
}
draw();
}
protected void actionOnChartSpriteWhenMove() {
Log.debug("Operation:" + activeOperation);
switch (activeOperation) {
@ -548,7 +602,7 @@ public class ChartViewerPanel extends FramedPanel {
protected void actionOnChartSpriteWhenMouseLeftDown() {
Log.debug("Operation:" + activeOperation);
switch(activeOperation){
switch (activeOperation) {
case MOVE:
break;
case ZOOMIN:
@ -564,15 +618,15 @@ public class ChartViewerPanel extends FramedPanel {
draw();
}
protected void zoomIn() {
if (scaleFactor < MAX_SCALE_FACTOR) {
scaleFactor++;
}
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
chartSprite.setScaling(new Scaling(chartDimension.getX(),
chartDimension.getY()));
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
}
protected void zoomOut() {
@ -580,16 +634,19 @@ public class ChartViewerPanel extends FramedPanel {
scaleFactor--;
}
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
chartSprite.setScaling(new Scaling(chartDimension.getX(),
chartDimension.getY()));
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
}
private void moveChart() {
displacement=displacement.divide(1+scaleFactor/10);
displacement = displacement.divide(1 + scaleFactor);
displacement = displacement.negate();
chartTranslation=chartTranslation.add(displacement);
chartSprite.setTranslation(chartTranslation.getX(), chartTranslation.getY());
chartTranslation = chartTranslation.add(displacement);
chartSprite.setTranslation(chartTranslation.getX(),
chartTranslation.getY());
}
protected void draw() {
@ -598,26 +655,37 @@ public class ChartViewerPanel extends FramedPanel {
}
private void addHandlersForComboZoomLevel(
final LabelProvider<ZoomLevelElement> label) {
comboZoomLevel
.addSelectionHandler(new SelectionHandler<ZoomLevelElement>() {
public void onSelection(
SelectionEvent<ZoomLevelElement> event) {
Log.debug("ComboZoomLevel selected: "
+ event.getSelectedItem());
ZoomLevelElement zoomLevelElement = event
.getSelectedItem();
updateZoomLevel(zoomLevelElement.getType());
}
.addSelectionHandler(new SelectionHandler<ZoomLevelElement>() {
public void onSelection(
SelectionEvent<ZoomLevelElement> event) {
Log.debug("ComboZoomLevel selected: "
+ event.getSelectedItem());
ZoomLevelElement zoomLevelElement = event
.getSelectedItem();
updateZoomLevel(zoomLevelElement.getType());
}
});
});
}
protected void updateZoomLevel(ZoomLevelType type) {
switch(type){
switch (type) {
case P50:
zoomLevel50();
break;
case P75:
zoomLevel75();
break;
case P100:
zoomLevel100();
break;
case P200:
zoomLevel200();
break;
case Fit:
zoomLevelFit();
break;
@ -632,29 +700,96 @@ public class ChartViewerPanel extends FramedPanel {
}
protected void zoomLevelFit(){
chartTranslation=new Vector2D();
scaleFactor=MIN_SCALE_FACTOR;
protected void zoomLevel50() {
/*
* Log.debug("Paint :" + paint.getAbsoluteLeft() + ", " +
* paint.getAbsoluteTop()); Log.debug("Paint offset:" +
* paint.getOffsetWidth(true) + ", " + paint.getOffsetHeight(true));
*
* Vector2D center = new Vector2D((paint.getOffsetWidth(true) / 2),
* (paint.getOffsetHeight(true) / 2)); Log.debug("Center: " + center);
* RectangleSprite rectangleSprite = new RectangleSprite(20, 20,
* center.getX(), center.getY()); paint.addSprite(rectangleSprite);
*/
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
chartSprite.setScaling(new Scaling(chartDimension.getX(),
chartDimension.getY()));
chartSprite.setTranslation(chartTranslation.getX(), chartTranslation.getY());
chartTranslation = new Vector2D();
scaleFactor = 2;
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
chartSprite.setTranslation(new Translation(chartTranslation.getX(),
chartTranslation.getY()));
}
protected void zoomLevelMax(){
chartTranslation=new Vector2D();
scaleFactor=MAX_SCALE_FACTOR;
protected void zoomLevel75() {
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
chartSprite.setScaling(new Scaling(chartDimension.getX(),
chartDimension.getY()));
chartSprite.setTranslation(chartTranslation.getX(), chartTranslation.getY());
chartTranslation = new Vector2D();
scaleFactor = 9;
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
chartSprite.setTranslation(new Translation(chartTranslation.getX(),
chartTranslation.getY()));
}
protected void zoomLevel100() {
chartTranslation = new Vector2D();
scaleFactor = 15;
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
chartSprite.setTranslation(new Translation(chartTranslation.getX(),
chartTranslation.getY()));
}
protected void zoomLevel200() {
chartTranslation = new Vector2D();
scaleFactor = 30;
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
chartSprite.setTranslation(new Translation(chartTranslation.getX(),
chartTranslation.getY()));
}
protected void zoomLevelFit() {
chartTranslation = new Vector2D();
scaleFactor = MIN_SCALE_FACTOR;
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
chartSprite.setTranslation(chartTranslation.getX(),
chartTranslation.getY());
}
protected void zoomLevelMax() {
chartTranslation = new Vector2D();
scaleFactor = MAX_SCALE_FACTOR;
chartScale = fitScale.multiply(1 + scaleFactor / 10);
chartSprite
.setScaling(new Scaling(chartScale.getX(), chartScale.getY()));
chartSprite.setTranslation(chartTranslation.getX(),
chartTranslation.getY());
}
protected void close() {
if (parent != null) {

View File

@ -126,6 +126,12 @@ public interface ResourceBundle extends ClientBundle {
@Source("arrow-move.png")
ImageResource move();
@Source("application_32.png")
ImageResource application32();
@Source("application.png")
ImageResource application();
@Source("Resources.css")
ResourceCSS resourceCSS();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

View File

@ -19,12 +19,20 @@ public class ZoomLevelStore implements Serializable {
protected static ZoomLevelElement fitElement=new ZoomLevelElement(1,ZoomLevelType.Fit);
protected static ZoomLevelElement maxZoomElement=new ZoomLevelElement(2,ZoomLevelType.MaxZoom);
protected static ZoomLevelElement p50Element=new ZoomLevelElement(3,ZoomLevelType.P50);
protected static ZoomLevelElement p75Element=new ZoomLevelElement(4,ZoomLevelType.P75);
protected static ZoomLevelElement p100Element=new ZoomLevelElement(5,ZoomLevelType.P100);
protected static ZoomLevelElement p200Element=new ZoomLevelElement(6,ZoomLevelType.P200);
public static ArrayList<ZoomLevelElement> getZoomLevelTypes(){
store=new ArrayList<ZoomLevelElement>();
store.add(fitElement);
store.add(maxZoomElement);
store.add(p50Element);
store.add(p75Element);
store.add(p100Element);
store.add(p200Element);
return store;
}
@ -36,7 +44,23 @@ public class ZoomLevelStore implements Serializable {
if(selected.compareTo(ZoomLevelType.MaxZoom.toString())==0){
position=2;
} else {
if(selected.compareTo(ZoomLevelType.P50.toString())==0){
position=3;
} else {
if(selected.compareTo(ZoomLevelType.P75.toString())==0){
position=4;
} else {
if(selected.compareTo(ZoomLevelType.P100.toString())==0){
position=5;
} else {
if(selected.compareTo(ZoomLevelType.P200.toString())==0){
position=6;
} else {
}
}
}
}
}
}
return position;
@ -50,7 +74,23 @@ public class ZoomLevelStore implements Serializable {
if(selected.compareTo(ZoomLevelType.MaxZoom.toString())==0){
return ZoomLevelType.MaxZoom;
} else {
return null;
if(selected.compareTo(ZoomLevelType.P50.toString())==0){
return ZoomLevelType.P50;
} else {
if(selected.compareTo(ZoomLevelType.P75.toString())==0){
return ZoomLevelType.P75;
} else {
if(selected.compareTo(ZoomLevelType.P100.toString())==0){
return ZoomLevelType.P100;
} else {
if(selected.compareTo(ZoomLevelType.P200.toString())==0){
return ZoomLevelType.P200;
} else {
return null;
}
}
}
}
}
}
}
@ -62,7 +102,23 @@ public class ZoomLevelStore implements Serializable {
if(selected.compareTo(ZoomLevelType.MaxZoom.toString())==0){
return maxZoomElement;
} else {
return null;
if(selected.compareTo(ZoomLevelType.P50.toString())==0){
return p50Element;
} else {
if(selected.compareTo(ZoomLevelType.P75.toString())==0){
return p75Element;
} else {
if(selected.compareTo(ZoomLevelType.P100.toString())==0){
return p100Element;
} else {
if(selected.compareTo(ZoomLevelType.P200.toString())==0){
return p200Element;
} else {
return null;
}
}
}
}
}
}
}

View File

@ -7,7 +7,12 @@ package org.gcube.portlets.user.td.resourceswidget.client.store;
*
*/
public enum ZoomLevelType {
Fit("Fit"), MaxZoom("Max");
Fit("Fit"),
P50("50%"),
P75("75%"),
P100("100%"),
P200("200%"),
MaxZoom("Max");
/**
* @param text

View File

@ -27,8 +27,8 @@
<inherits name='org.gcube.portlets.user.td.wizardwidget.Wizard' />
<!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.user.td.resourceswidget.client.ResourcesWidgetEntry'
/> -->
<entry-point class='org.gcube.portlets.user.td.resourceswidget.client.ResourcesWidgetEntry'
/>
<!-- Specify the paths for translatable code -->
<source path='client' />

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B