Update Chart Viewer
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@101625 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8a57c6288d
commit
0125cf539b
|
@ -18,7 +18,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.StringResourceT
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.charts.ChartDialog;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.charts.ChartViewerDialog;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.properties.ResourceTDDescriptorProperties;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.save.SaveResourceWizard;
|
||||
|
@ -663,7 +663,7 @@ public class ResourcesPanel extends FramedPanel {
|
|||
}
|
||||
|
||||
private void repquestOpenChart(ResourceTDDescriptor resourceTDDescriptor) {
|
||||
ChartDialog chartDialog=new ChartDialog(resourceTDDescriptor, trId, eventBus);
|
||||
ChartViewerDialog chartDialog=new ChartViewerDialog(resourceTDDescriptor, trId, eventBus);
|
||||
chartDialog.show();
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.gcube.portlets.user.td.resourceswidget.client;
|
|||
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.charts.ChartDialog;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.charts.ChartViewerDialog;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
|
@ -35,7 +35,7 @@ public class ResourcesWidgetEntry implements EntryPoint {
|
|||
//dialog.show();
|
||||
|
||||
resourceTDDescriptor=new ResourceTDDescriptor();
|
||||
ChartDialog chartDialog=new ChartDialog(resourceTDDescriptor, trId, eventBus, true);
|
||||
ChartViewerDialog chartDialog=new ChartViewerDialog(resourceTDDescriptor, trId, eventBus, true);
|
||||
chartDialog.show();
|
||||
|
||||
Log.info("Hello!");
|
||||
|
|
|
@ -1,478 +0,0 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.charts;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
import com.google.gwt.safehtml.shared.SafeUri;
|
||||
import com.google.gwt.safehtml.shared.UriUtils;
|
||||
import com.google.gwt.user.client.ui.HasValue;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.chart.client.draw.DrawComponent;
|
||||
import com.sencha.gxt.chart.client.draw.Scaling;
|
||||
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.SpriteSelectionEvent;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteSelectionEvent.SpriteSelectionHandler;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.core.client.util.ToggleGroup;
|
||||
import com.sencha.gxt.widget.core.client.FramedPanel;
|
||||
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.toolbar.ToolBar;
|
||||
|
||||
/**
|
||||
*
|
||||
* ResourcesPanel shows the resources
|
||||
*
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ChartPanel extends FramedPanel {
|
||||
private static final int IMAGE_WIDTH = 2000;
|
||||
private static final int IMAGE_HEIGHT = 1000;
|
||||
private static final String RETRIEVE_CHART_FILE_SERVLET = "RetrieveChartFileServlet";
|
||||
private static final String ATTRIBUTE_STORAGE_URI = "storageURI";
|
||||
|
||||
private static final String WIDTH = "800px";
|
||||
private static final String HEIGHT = "440px";
|
||||
private static final int DRAW_WIDTH_INT = 780;
|
||||
private static final int DRAW_HEIGHT_INT = 380;
|
||||
|
||||
private enum Operation {
|
||||
ZOOMIN, ZOOMOUT
|
||||
};
|
||||
|
||||
private Operation activeOperation = Operation.ZOOMIN;
|
||||
|
||||
private ChartDialog parent;
|
||||
private ResourceTDDescriptor resourceTDDescriptor;
|
||||
|
||||
private ImageResource chartImageResource;
|
||||
private ImageResource testImageResource;
|
||||
|
||||
private ImageSprite chartSprite;
|
||||
|
||||
private int MAX_SCALE_FACTOR = 20;
|
||||
private int MIN_SCALE_FACTOR = 0;
|
||||
private double scaleFactor = 0;
|
||||
|
||||
private double baseWidthDim;
|
||||
private double baseHeightDim;
|
||||
|
||||
private DrawComponent paint;
|
||||
|
||||
private ToggleButton btnZoomIn;
|
||||
private ToggleButton btnZoomOut;
|
||||
private ToggleGroup buttonGroup;
|
||||
private double chartWidthDim;
|
||||
private double chartHeightDim;
|
||||
|
||||
public ChartPanel(ChartDialog parent,
|
||||
ResourceTDDescriptor resourceTDDescriptor, TRId trId,
|
||||
EventBus eventBus) {
|
||||
this(parent, resourceTDDescriptor, trId, eventBus, false);
|
||||
}
|
||||
|
||||
public ChartPanel(ChartDialog parent,
|
||||
ResourceTDDescriptor resourceTDDescriptor, TRId trId,
|
||||
EventBus eventBus, boolean test) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.resourceTDDescriptor = resourceTDDescriptor;
|
||||
forceLayoutOnResize = true;
|
||||
|
||||
|
||||
if (test) {
|
||||
testImageResource = ResourceBundle.INSTANCE.testImage();
|
||||
createForTest();
|
||||
} else {
|
||||
retrieveChart();
|
||||
create();
|
||||
}
|
||||
}
|
||||
|
||||
public static String encodeUrlDelimiters(String s) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
s = s.replaceAll(";", "%2F");
|
||||
s = s.replaceAll("/", "%2F");
|
||||
s = s.replaceAll(":", "%3A");
|
||||
s = s.replaceAll("\\?", "%3F");
|
||||
s = s.replaceAll("&", "%26");
|
||||
s = s.replaceAll("\\=", "%3D");
|
||||
s = s.replaceAll("\\+", "%2B");
|
||||
s = s.replaceAll("\\$", "%24");
|
||||
s = s.replaceAll(",", "%2C");
|
||||
s = s.replaceAll("#", "%23");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
protected void retrieveChart() {
|
||||
InternalURITD internalURITD;
|
||||
ResourceTD resource = resourceTDDescriptor.getResourceTD();
|
||||
if (resource instanceof InternalURITD) {
|
||||
internalURITD = (InternalURITD) resource;
|
||||
} else {
|
||||
UtilsGXT3.alert("Attention",
|
||||
"This resource does not have valid internal URI!");
|
||||
Log.debug("Attention, this resource does not have valid Internal URI!");
|
||||
close();
|
||||
return;
|
||||
}
|
||||
Log.debug("InteranlURI: " + internalURITD);
|
||||
final String storageURI = encodeUrlDelimiters(internalURITD.getUri());
|
||||
|
||||
final String path = GWT.getModuleBaseURL()
|
||||
+ RETRIEVE_CHART_FILE_SERVLET;
|
||||
|
||||
chartImageResource = new ImageResource() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "image";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return IMAGE_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLeft() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SafeUri getSafeUri() {
|
||||
|
||||
SafeUri uri = UriUtils.fromString(path + "?"
|
||||
+ ATTRIBUTE_STORAGE_URI + "=" + storageURI);
|
||||
|
||||
Log.debug("Image uri:" + uri.asString());
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTop() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getURL() {
|
||||
return this.getSafeUri().asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return IMAGE_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnimated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
init();
|
||||
drawInit();
|
||||
}
|
||||
|
||||
protected void createForTest() {
|
||||
init();
|
||||
drawInitForTest();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setHeaderVisible(false);
|
||||
setBodyBorder(false);
|
||||
setResize(true);
|
||||
|
||||
}
|
||||
|
||||
protected void drawInit() {
|
||||
VerticalLayoutContainer layout = new VerticalLayoutContainer();
|
||||
add(layout);
|
||||
|
||||
ToolBar toolBar = new ToolBar();
|
||||
|
||||
btnZoomIn = new ToggleButton();
|
||||
btnZoomIn.setValue(true);
|
||||
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());
|
||||
|
||||
}
|
||||
});
|
||||
toolBar.add(btnZoomIn);
|
||||
|
||||
btnZoomOut = new ToggleButton();
|
||||
;
|
||||
btnZoomOut.setValue(false);
|
||||
btnZoomOut.setIcon(ResourceBundle.INSTANCE.magnifierZoomOut());
|
||||
btnZoomOut.setToolTip("Zoom Out");
|
||||
btnZoomOut.addSelectHandler(new SelectHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
|
||||
.getCursorZoomOut());
|
||||
|
||||
}
|
||||
});
|
||||
toolBar.add(btnZoomOut);
|
||||
|
||||
buttonGroup = new ToggleGroup();
|
||||
buttonGroup.add(btnZoomIn);
|
||||
buttonGroup.add(btnZoomOut);
|
||||
|
||||
buttonGroup
|
||||
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
|
||||
|
||||
public void onValueChange(
|
||||
ValueChangeEvent<HasValue<Boolean>> event) {
|
||||
|
||||
if (btnZoomIn.getValue()) {
|
||||
activeOperation = Operation.ZOOMIN;
|
||||
return;
|
||||
}
|
||||
|
||||
if (btnZoomOut.getValue()) {
|
||||
activeOperation = Operation.ZOOMOUT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
paint = new DrawComponent();
|
||||
|
||||
chartSprite = new ImageSprite(chartImageResource);
|
||||
chartSprite.setX(0);
|
||||
chartSprite.setY(0);
|
||||
|
||||
paint.addSprite(chartSprite);
|
||||
|
||||
paint.setLayoutData(new VerticalLayoutData(1, 1));
|
||||
|
||||
paint.addSpriteSelectionHandler(new SpriteSelectionHandler() {
|
||||
|
||||
@Override
|
||||
public void onSpriteSelect(SpriteSelectionEvent event) {
|
||||
actionOnSprite(event);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
layout.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
layout.add(paint, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
Log.debug("chartImageResource width:" + chartImageResource.getWidth()
|
||||
+ " height:" + chartImageResource.getHeight());
|
||||
baseWidthDim = new Double(DRAW_WIDTH_INT)
|
||||
/ chartImageResource.getWidth();
|
||||
baseHeightDim = new Double(DRAW_HEIGHT_INT)
|
||||
/ chartImageResource.getHeight();
|
||||
Log.debug("Offset width:" + DRAW_WIDTH_INT + " height:"
|
||||
+ DRAW_HEIGHT_INT);
|
||||
Log.debug("Base Width: " + baseWidthDim + ", Base Height:"
|
||||
+ baseHeightDim);
|
||||
chartSprite.setScaling(new Scaling(baseWidthDim, baseHeightDim));
|
||||
|
||||
chartWidthDim = baseWidthDim;
|
||||
chartHeightDim = baseHeightDim;
|
||||
|
||||
paint.redrawSurfaceForced();
|
||||
|
||||
// Image image = new Image(chartImageResource.getSafeUri());
|
||||
// layout.add(image);
|
||||
|
||||
}
|
||||
|
||||
protected void drawInitForTest() {
|
||||
VerticalLayoutContainer layout = new VerticalLayoutContainer();
|
||||
add(layout);
|
||||
|
||||
ToolBar toolBar = new ToolBar();
|
||||
|
||||
btnZoomIn = new ToggleButton();
|
||||
btnZoomIn.setValue(true);
|
||||
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());
|
||||
}
|
||||
});
|
||||
toolBar.add(btnZoomIn);
|
||||
|
||||
btnZoomOut = new ToggleButton();
|
||||
;
|
||||
btnZoomOut.setValue(false);
|
||||
btnZoomOut.setIcon(ResourceBundle.INSTANCE.magnifierZoomOut());
|
||||
btnZoomOut.setToolTip("Zoom Out");
|
||||
btnZoomOut.addSelectHandler(new SelectHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
|
||||
.getCursorZoomOut());
|
||||
|
||||
}
|
||||
});
|
||||
toolBar.add(btnZoomOut);
|
||||
|
||||
buttonGroup = new ToggleGroup();
|
||||
buttonGroup.add(btnZoomIn);
|
||||
buttonGroup.add(btnZoomOut);
|
||||
|
||||
buttonGroup
|
||||
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
|
||||
|
||||
public void onValueChange(
|
||||
ValueChangeEvent<HasValue<Boolean>> event) {
|
||||
|
||||
if (btnZoomIn.getValue()) {
|
||||
activeOperation = Operation.ZOOMIN;
|
||||
return;
|
||||
}
|
||||
|
||||
if (btnZoomOut.getValue()) {
|
||||
activeOperation = Operation.ZOOMOUT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
paint = new DrawComponent();
|
||||
|
||||
chartSprite = new ImageSprite(testImageResource);
|
||||
chartSprite.setX(0);
|
||||
chartSprite.setY(0);
|
||||
|
||||
paint.addSprite(chartSprite);
|
||||
|
||||
paint.setLayoutData(new VerticalLayoutData(1, 1));
|
||||
|
||||
paint.addSpriteSelectionHandler(new SpriteSelectionHandler() {
|
||||
|
||||
@Override
|
||||
public void onSpriteSelect(SpriteSelectionEvent event) {
|
||||
actionOnSprite(event);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
layout.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
layout.add(paint, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
Log.debug("testImageResource width:" + testImageResource.getWidth()
|
||||
+ " height:" + testImageResource.getHeight());
|
||||
baseWidthDim = new Double(DRAW_WIDTH_INT)
|
||||
/ testImageResource.getWidth();
|
||||
baseHeightDim = new Double(DRAW_HEIGHT_INT)
|
||||
/ testImageResource.getHeight();
|
||||
Log.debug("Offset width:" + DRAW_WIDTH_INT + " height:"
|
||||
+ DRAW_HEIGHT_INT);
|
||||
Log.debug("Base Width: " + baseWidthDim + ", Base Height:"
|
||||
+ baseHeightDim);
|
||||
chartSprite.setScaling(new Scaling(baseWidthDim, baseHeightDim));
|
||||
|
||||
chartWidthDim = baseWidthDim;
|
||||
chartHeightDim = baseHeightDim;
|
||||
|
||||
paint.redrawSurfaceForced();
|
||||
|
||||
}
|
||||
|
||||
protected void draw() {
|
||||
chartSprite.setScaling(new Scaling(chartWidthDim, chartHeightDim));
|
||||
paint.redrawSurfaceForced();
|
||||
}
|
||||
|
||||
protected void actionOnSprite(SpriteSelectionEvent event) {
|
||||
Sprite sprite = event.getSprite();
|
||||
if (sprite == chartSprite) {
|
||||
Log.debug("Chart Sprite Selected");
|
||||
actionOnChartSprite(event);
|
||||
} else {
|
||||
Log.debug("No sprite selected");
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionOnChartSprite(SpriteSelectionEvent event) {
|
||||
Log.debug("Position: " + event.getBrowserEvent().getClientX() + ", "
|
||||
+ event.getBrowserEvent().getClientY());
|
||||
Log.debug("Active Operation:" + activeOperation);
|
||||
switch (activeOperation) {
|
||||
case ZOOMIN:
|
||||
zoomIn();
|
||||
break;
|
||||
case ZOOMOUT:
|
||||
zoomOut();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
protected void zoomIn() {
|
||||
if (scaleFactor < MAX_SCALE_FACTOR) {
|
||||
scaleFactor++;
|
||||
}
|
||||
|
||||
chartWidthDim = baseWidthDim * (1 + scaleFactor / 10);
|
||||
chartHeightDim = baseHeightDim * (1 + scaleFactor / 10);
|
||||
}
|
||||
|
||||
protected void zoomOut() {
|
||||
if (scaleFactor > MIN_SCALE_FACTOR) {
|
||||
scaleFactor--;
|
||||
}
|
||||
|
||||
chartWidthDim = baseWidthDim * (1 + scaleFactor / 10);
|
||||
chartHeightDim = baseHeightDim * (1 + scaleFactor / 10);
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
if (parent != null) {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
|||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ChartDialog extends Window {
|
||||
public class ChartViewerDialog extends Window {
|
||||
private static final String WIDTH = "822px";
|
||||
private static final String HEIGHT = "460px";
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class ChartDialog extends Window {
|
|||
* @param trId
|
||||
* @param eventBus
|
||||
*/
|
||||
public ChartDialog(ResourceTDDescriptor resourceTDDescriptor, TRId trId, EventBus eventBus) {
|
||||
public ChartViewerDialog(ResourceTDDescriptor resourceTDDescriptor, TRId trId, EventBus eventBus) {
|
||||
this(resourceTDDescriptor, trId,eventBus, false);
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,10 @@ public class ChartDialog extends Window {
|
|||
* @param eventBus
|
||||
* @param test
|
||||
*/
|
||||
public ChartDialog(ResourceTDDescriptor resourceTDDescriptor, TRId trId, EventBus eventBus, boolean test) {
|
||||
public ChartViewerDialog(ResourceTDDescriptor resourceTDDescriptor, TRId trId, EventBus eventBus, boolean test) {
|
||||
initWindow();
|
||||
|
||||
ChartPanel chartPanel= new ChartPanel(this, resourceTDDescriptor, trId, eventBus,test);
|
||||
ChartViewerPanel chartPanel= new ChartViewerPanel(this, resourceTDDescriptor, trId, eventBus,test);
|
||||
add(chartPanel);
|
||||
}
|
||||
|
|
@ -0,0 +1,666 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.charts;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.graphics.Vector2D;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.properties.ZoomLevelPropertiesCombo;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelElement;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelStore;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelType;
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
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.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
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.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.sprite.ImageSprite;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.Sprite;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteOutEvent;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteOutEvent.SpriteOutHandler;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteOverEvent;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteOverEvent.SpriteOverHandler;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteSelectionEvent;
|
||||
import com.sencha.gxt.chart.client.draw.sprite.SpriteSelectionEvent.SpriteSelectionHandler;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
* ResourcesPanel shows the resources
|
||||
*
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ChartViewerPanel extends FramedPanel {
|
||||
private static final String COMBO_ZOOM_LEVEL_WIDTH = "100px";
|
||||
private static final int IMAGE_WIDTH = 2000;
|
||||
private static final int IMAGE_HEIGHT = 1000;
|
||||
private static final String RETRIEVE_CHART_FILE_SERVLET = "RetrieveChartFileServlet";
|
||||
private static final String ATTRIBUTE_STORAGE_URI = "storageURI";
|
||||
|
||||
private static final String WIDTH = "800px";
|
||||
private static final String HEIGHT = "440px";
|
||||
private static final int DRAW_WIDTH_INT = 780;
|
||||
private static final int DRAW_HEIGHT_INT = 380;
|
||||
|
||||
private enum Operation {
|
||||
ZOOMIN, ZOOMOUT, MOVE
|
||||
};
|
||||
|
||||
private Operation activeOperation = Operation.ZOOMIN;
|
||||
private Sprite activeSprite;
|
||||
|
||||
private Vector2D startPosition;
|
||||
private Vector2D currentPosition;
|
||||
private Vector2D endPosition;
|
||||
private Vector2D displacement;
|
||||
|
||||
private ChartViewerDialog parent;
|
||||
private ResourceTDDescriptor resourceTDDescriptor;
|
||||
private boolean test;
|
||||
|
||||
private ImageResource chartImageResource;
|
||||
private ImageResource testImageResource;
|
||||
|
||||
private ImageSprite chartSprite;
|
||||
|
||||
private int MAX_SCALE_FACTOR = 20;
|
||||
private int MIN_SCALE_FACTOR = 0;
|
||||
private double scaleFactor = 0;
|
||||
|
||||
private Vector2D baseDimension;
|
||||
private Vector2D chartDimension;
|
||||
|
||||
private DrawComponent paint;
|
||||
|
||||
private ToggleButton btnZoomIn;
|
||||
private ToggleButton btnZoomOut;
|
||||
private ToggleGroup buttonGroup;
|
||||
|
||||
private Sprite currentSprite;
|
||||
private ToggleButton btnMove;
|
||||
private Timer mouseTimer;
|
||||
private Vector2D chartTranslation;
|
||||
private ComboBox<ZoomLevelElement> comboZoomLevel;
|
||||
|
||||
public ChartViewerPanel(ChartViewerDialog parent,
|
||||
ResourceTDDescriptor resourceTDDescriptor, TRId trId,
|
||||
EventBus eventBus) {
|
||||
this(parent, resourceTDDescriptor, trId, eventBus, false);
|
||||
}
|
||||
|
||||
public ChartViewerPanel(ChartViewerDialog parent,
|
||||
ResourceTDDescriptor resourceTDDescriptor, TRId trId,
|
||||
EventBus eventBus, boolean test) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.resourceTDDescriptor = resourceTDDescriptor;
|
||||
this.test = test;
|
||||
forceLayoutOnResize = true;
|
||||
|
||||
if (test) {
|
||||
testImageResource = ResourceBundle.INSTANCE.testImage();
|
||||
create();
|
||||
} else {
|
||||
retrieveChart();
|
||||
create();
|
||||
}
|
||||
}
|
||||
|
||||
public static String encodeUrlDelimiters(String s) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
s = s.replaceAll(";", "%2F");
|
||||
s = s.replaceAll("/", "%2F");
|
||||
s = s.replaceAll(":", "%3A");
|
||||
s = s.replaceAll("\\?", "%3F");
|
||||
s = s.replaceAll("&", "%26");
|
||||
s = s.replaceAll("\\=", "%3D");
|
||||
s = s.replaceAll("\\+", "%2B");
|
||||
s = s.replaceAll("\\$", "%24");
|
||||
s = s.replaceAll(",", "%2C");
|
||||
s = s.replaceAll("#", "%23");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
protected void retrieveChart() {
|
||||
InternalURITD internalURITD;
|
||||
ResourceTD resource = resourceTDDescriptor.getResourceTD();
|
||||
if (resource instanceof InternalURITD) {
|
||||
internalURITD = (InternalURITD) resource;
|
||||
} else {
|
||||
UtilsGXT3.alert("Attention",
|
||||
"This resource does not have valid internal URI!");
|
||||
Log.debug("Attention, this resource does not have valid Internal URI!");
|
||||
close();
|
||||
return;
|
||||
}
|
||||
Log.debug("InteranlURI: " + internalURITD);
|
||||
final String storageURI = encodeUrlDelimiters(internalURITD.getUri());
|
||||
|
||||
final String path = GWT.getModuleBaseURL()
|
||||
+ RETRIEVE_CHART_FILE_SERVLET;
|
||||
|
||||
chartImageResource = new ImageResource() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "image";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return IMAGE_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLeft() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SafeUri getSafeUri() {
|
||||
|
||||
SafeUri uri = UriUtils.fromString(path + "?"
|
||||
+ ATTRIBUTE_STORAGE_URI + "=" + storageURI);
|
||||
|
||||
Log.debug("Image uri:" + uri.asString());
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTop() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getURL() {
|
||||
return this.getSafeUri().asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return IMAGE_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnimated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
init();
|
||||
createPanel();
|
||||
drawInit();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setHeaderVisible(false);
|
||||
setBodyBorder(false);
|
||||
setResize(true);
|
||||
|
||||
}
|
||||
|
||||
protected void createPanel() {
|
||||
VerticalLayoutContainer layout = new VerticalLayoutContainer();
|
||||
add(layout);
|
||||
|
||||
|
||||
// ToolBar
|
||||
ToolBar toolBar = new ToolBar();
|
||||
|
||||
btnZoomIn = new ToggleButton();
|
||||
btnZoomIn.setValue(true);
|
||||
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());
|
||||
|
||||
}
|
||||
});
|
||||
toolBar.add(btnZoomIn);
|
||||
|
||||
btnZoomOut = new ToggleButton();
|
||||
btnZoomOut.setValue(false);
|
||||
btnZoomOut.setIcon(ResourceBundle.INSTANCE.magnifierZoomOut());
|
||||
btnZoomOut.setToolTip("Zoom Out");
|
||||
btnZoomOut.addSelectHandler(new SelectHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
|
||||
.getCursorZoomOut());
|
||||
|
||||
}
|
||||
});
|
||||
toolBar.add(btnZoomOut);
|
||||
|
||||
btnMove = new ToggleButton();
|
||||
btnMove.setValue(false);
|
||||
btnMove.setIcon(ResourceBundle.INSTANCE.move());
|
||||
btnMove.setToolTip("Move");
|
||||
btnMove.addSelectHandler(new SelectHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
paint.setStyleName(ResourceBundle.INSTANCE.resourceCSS()
|
||||
.getCursorZoomOut());
|
||||
|
||||
}
|
||||
});
|
||||
toolBar.add(btnMove);
|
||||
|
||||
buttonGroup = new ToggleGroup();
|
||||
buttonGroup.add(btnZoomIn);
|
||||
buttonGroup.add(btnZoomOut);
|
||||
buttonGroup.add(btnMove);
|
||||
|
||||
buttonGroup
|
||||
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
|
||||
|
||||
public void onValueChange(
|
||||
ValueChangeEvent<HasValue<Boolean>> event) {
|
||||
|
||||
if (btnZoomIn.getValue()) {
|
||||
activeOperation = Operation.ZOOMIN;
|
||||
return;
|
||||
}
|
||||
|
||||
if (btnZoomOut.getValue()) {
|
||||
activeOperation = Operation.ZOOMOUT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (btnMove.getValue()) {
|
||||
activeOperation = Operation.MOVE;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
ZoomLevelPropertiesCombo props = GWT.create(ZoomLevelPropertiesCombo.class);
|
||||
ListStore<ZoomLevelElement> storeZoomLevelTypes = new ListStore<ZoomLevelElement>(
|
||||
props.id());
|
||||
|
||||
storeZoomLevelTypes.addAll(ZoomLevelStore.getZoomLevelTypes());
|
||||
|
||||
Log.trace("Store created");
|
||||
|
||||
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);;
|
||||
|
||||
|
||||
// Paint
|
||||
paint = new DrawComponent();
|
||||
|
||||
paint.setLayoutData(new VerticalLayoutData(1, 1));
|
||||
|
||||
paint.addSpriteSelectionHandler(new SpriteSelectionHandler() {
|
||||
|
||||
@Override
|
||||
public void onSpriteSelect(SpriteSelectionEvent event) {
|
||||
activeSprite(event);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
paint.addSpriteOverHandler(new SpriteOverHandler() {
|
||||
|
||||
@Override
|
||||
public void onSpriteOver(SpriteOverEvent event) {
|
||||
spriteOver(event);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
paint.addSpriteOutHandler(new SpriteOutHandler() {
|
||||
|
||||
@Override
|
||||
public void onSpriteLeave(SpriteOutEvent event) {
|
||||
spriteLeave(event);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
paint.addDomHandler(new MouseUpHandler() {
|
||||
|
||||
@Override
|
||||
public void onMouseUp(MouseUpEvent event) {
|
||||
spriteMouseUp(event);
|
||||
|
||||
}
|
||||
}, MouseUpEvent.getType());
|
||||
|
||||
layout.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
layout.add(paint, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected void drawInit() {
|
||||
|
||||
if (test) {
|
||||
chartSprite = new ImageSprite(testImageResource);
|
||||
} else {
|
||||
chartSprite = new ImageSprite(chartImageResource);
|
||||
}
|
||||
|
||||
chartSprite.setX(0);
|
||||
chartSprite.setY(0);
|
||||
|
||||
paint.addSprite(chartSprite);
|
||||
|
||||
if (test) {
|
||||
Log.debug("testImageResource width:" + testImageResource.getWidth()
|
||||
+ " height:" + testImageResource.getHeight());
|
||||
baseDimension = new Vector2D(new Double(DRAW_WIDTH_INT)
|
||||
/ testImageResource.getWidth(), new Double(DRAW_HEIGHT_INT)
|
||||
/ testImageResource.getHeight());
|
||||
|
||||
} else {
|
||||
Log.debug("chartImageResource width:"
|
||||
+ chartImageResource.getWidth() + " height:"
|
||||
+ chartImageResource.getHeight());
|
||||
baseDimension = new Vector2D(new Double(DRAW_WIDTH_INT)
|
||||
/ chartImageResource.getWidth(),
|
||||
new Double(DRAW_HEIGHT_INT)
|
||||
/ chartImageResource.getHeight());
|
||||
}
|
||||
|
||||
Log.debug("Offset width:" + DRAW_WIDTH_INT + " height:"
|
||||
+ DRAW_HEIGHT_INT);
|
||||
Log.debug("Base Width: " + baseDimension.getX() + ", Base Height:"
|
||||
+ baseDimension.getY());
|
||||
|
||||
chartSprite.setScaling(new Scaling(baseDimension.getX(), baseDimension
|
||||
.getY()));
|
||||
|
||||
chartDimension = baseDimension.copy();
|
||||
chartTranslation=new Vector2D();
|
||||
paint.redrawSurfaceForced();
|
||||
|
||||
// Image image = new Image(chartImageResource.getSafeUri());
|
||||
// layout.add(image);
|
||||
|
||||
}
|
||||
|
||||
protected void createMouseTimer() {
|
||||
mouseTimer = new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (activeSprite != null){
|
||||
if (activeSprite == chartSprite) {
|
||||
actionOnChartSpriteWhenMouseLeftDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Schedule the timer to run once in 300 milliseconds.
|
||||
mouseTimer.scheduleRepeating(200);
|
||||
Log.debug("MouseTimer Start");
|
||||
}
|
||||
|
||||
protected void activeSprite(SpriteSelectionEvent event) {
|
||||
Event browseEvent = event.getBrowserEvent();
|
||||
browseEvent.preventDefault();
|
||||
Log.debug("Active Position: " + browseEvent.getClientX() + ", "
|
||||
+ browseEvent.getClientY());
|
||||
activeSprite = event.getSprite();
|
||||
startPosition = new Vector2D(browseEvent.getClientX(),
|
||||
browseEvent.getClientY());
|
||||
if (activeSprite != null) {
|
||||
if (activeSprite == chartSprite) {
|
||||
if (activeOperation.compareTo(Operation.ZOOMIN)==0
|
||||
|| activeOperation.compareTo(Operation.ZOOMOUT)==0) {
|
||||
actionOnChartSpriteWhenMouseLeftDown();
|
||||
comboZoomLevel.reset();
|
||||
comboZoomLevel.redraw();
|
||||
createMouseTimer();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void spriteMouseUp(MouseUpEvent event) {
|
||||
Log.debug("Deactive Position: " + event.getClientX() + ", "
|
||||
+ event.getClientY());
|
||||
endPosition = new Vector2D(event.getClientX(), event.getClientY());
|
||||
displacement = startPosition.sub(endPosition);
|
||||
activeSprite = 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){
|
||||
mouseTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected void spriteOver(SpriteOverEvent event) {
|
||||
Event browseEvent = event.getBrowserEvent();
|
||||
Log.debug("Over Position: " + browseEvent.getClientX() + ", "
|
||||
+ browseEvent.getClientY());
|
||||
currentPosition = new Vector2D(browseEvent.getClientX(),
|
||||
browseEvent.getClientY());
|
||||
if (activeSprite != null) {
|
||||
currentSprite = event.getSprite();
|
||||
if (currentSprite == chartSprite) {
|
||||
displacement = startPosition.sub(currentPosition);
|
||||
Log.debug("Chart Sprite Selected");
|
||||
actionOnChartSpriteWhenMove();
|
||||
} else {
|
||||
Log.debug("No sprite selected");
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void actionOnChartSpriteWhenMove() {
|
||||
Log.debug("Operation:" + activeOperation);
|
||||
switch (activeOperation) {
|
||||
case ZOOMIN:
|
||||
break;
|
||||
case ZOOMOUT:
|
||||
break;
|
||||
case MOVE:
|
||||
moveChart();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
protected void actionOnChartSpriteWhenMouseLeftDown() {
|
||||
Log.debug("Operation:" + activeOperation);
|
||||
switch(activeOperation){
|
||||
case MOVE:
|
||||
break;
|
||||
case ZOOMIN:
|
||||
zoomIn();
|
||||
break;
|
||||
case ZOOMOUT:
|
||||
zoomOut();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
||||
|
||||
protected void zoomIn() {
|
||||
if (scaleFactor < MAX_SCALE_FACTOR) {
|
||||
scaleFactor++;
|
||||
}
|
||||
|
||||
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
|
||||
chartSprite.setScaling(new Scaling(chartDimension.getX(),
|
||||
chartDimension.getY()));
|
||||
}
|
||||
|
||||
protected void zoomOut() {
|
||||
if (scaleFactor > MIN_SCALE_FACTOR) {
|
||||
scaleFactor--;
|
||||
}
|
||||
|
||||
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
|
||||
chartSprite.setScaling(new Scaling(chartDimension.getX(),
|
||||
chartDimension.getY()));
|
||||
}
|
||||
|
||||
private void moveChart() {
|
||||
displacement=displacement.divide(1+scaleFactor/10);
|
||||
displacement = displacement.negate();
|
||||
chartTranslation=chartTranslation.add(displacement);
|
||||
chartSprite.setTranslation(chartTranslation.getX(), chartTranslation.getY());
|
||||
}
|
||||
|
||||
protected void draw() {
|
||||
|
||||
paint.redrawSurfaceForced();
|
||||
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void updateZoomLevel(ZoomLevelType type) {
|
||||
switch(type){
|
||||
case Fit:
|
||||
zoomLevelFit();
|
||||
break;
|
||||
case MaxZoom:
|
||||
zoomLevelMax();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
draw();
|
||||
|
||||
}
|
||||
|
||||
protected void zoomLevelFit(){
|
||||
chartTranslation=new Vector2D();
|
||||
scaleFactor=MIN_SCALE_FACTOR;
|
||||
|
||||
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
|
||||
chartSprite.setScaling(new Scaling(chartDimension.getX(),
|
||||
chartDimension.getY()));
|
||||
chartSprite.setTranslation(chartTranslation.getX(), chartTranslation.getY());
|
||||
|
||||
}
|
||||
|
||||
protected void zoomLevelMax(){
|
||||
chartTranslation=new Vector2D();
|
||||
scaleFactor=MAX_SCALE_FACTOR;
|
||||
|
||||
chartDimension = baseDimension.multiply(1 + scaleFactor / 10);
|
||||
chartSprite.setScaling(new Scaling(chartDimension.getX(),
|
||||
chartDimension.getY()));
|
||||
chartSprite.setTranslation(chartTranslation.getX(), chartTranslation.getY());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void close() {
|
||||
if (parent != null) {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.graphics;
|
||||
|
||||
/**
|
||||
*
|
||||
* Basic Vector 2D
|
||||
*
|
||||
* @author giancarlo email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class Vector2D {
|
||||
|
||||
public static Vector2D Vector2DNull = new Vector2D(0, 0);
|
||||
|
||||
protected double x;
|
||||
protected double y;
|
||||
|
||||
public Vector2D() {
|
||||
x = y = 0.0;
|
||||
}
|
||||
|
||||
public Vector2D(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
// Compute magnitude of vector ....
|
||||
public double length() {
|
||||
return Math.sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
// Sum of two vectors ....
|
||||
public Vector2D add(Vector2D v) {
|
||||
Vector2D v1 = new Vector2D(this.x + v.x, this.y + v.y);
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Add scalar
|
||||
public Vector2D add(double s) {
|
||||
Vector2D v1 = new Vector2D(this.x + s, this.y + s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Subtract vector v1 from v .....
|
||||
public Vector2D sub(Vector2D v) {
|
||||
Vector2D v1 = new Vector2D(this.x - v.x, this.y - v.y);
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Subtract scalar
|
||||
public Vector2D sub(double s) {
|
||||
Vector2D v2 = new Vector2D(this.x - s, this.y - s);
|
||||
return v2;
|
||||
}
|
||||
|
||||
// Scale vector by a constant ...
|
||||
public Vector2D scale(double scaleFactor) {
|
||||
Vector2D v2 = new Vector2D(this.x * scaleFactor, this.y * scaleFactor);
|
||||
return v2;
|
||||
}
|
||||
|
||||
// Normalize a vectors length....
|
||||
public Vector2D normalize() {
|
||||
Vector2D v2 = new Vector2D();
|
||||
|
||||
double length = Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
if (length != 0) {
|
||||
v2.x = this.x / length;
|
||||
v2.y = this.y / length;
|
||||
}
|
||||
|
||||
return v2;
|
||||
}
|
||||
|
||||
// Dot product of two vectors .....
|
||||
public double dot(Vector2D v) {
|
||||
return this.x * v.x + this.y * v.y;
|
||||
}
|
||||
|
||||
// Multiply
|
||||
public Vector2D multiply(Vector2D v) {
|
||||
Vector2D v1 = new Vector2D(this.x * v.getX(), this.y * v.getY());
|
||||
return v1;
|
||||
}
|
||||
|
||||
public Vector2D multiply(double s) {
|
||||
Vector2D v1 = new Vector2D(this.x * s, this.y * s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Divide
|
||||
public Vector2D divide(Vector2D v) {
|
||||
Vector2D v1 = new Vector2D(this.x / v.getX(), this.y / v.getY());
|
||||
return v1;
|
||||
}
|
||||
|
||||
public Vector2D divide(double s) {
|
||||
if (s != 0) {
|
||||
Vector2D v1 = new Vector2D(this.x / s, this.y / s);
|
||||
return v1;
|
||||
} else {
|
||||
return Vector2DNull;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Distance To Squared
|
||||
public double distanceToSquared(Vector2D v) {
|
||||
double dx = this.x - v.x, dy = this.y - v.y;
|
||||
return dx * dx + dy * dy;
|
||||
|
||||
}
|
||||
|
||||
// Distance
|
||||
public double distance(Vector2D v) {
|
||||
return Math.sqrt(this.distanceToSquared(v));
|
||||
}
|
||||
|
||||
// Negate
|
||||
public Vector2D negate() {
|
||||
Vector2D v1 = new Vector2D(-x, -y);
|
||||
return v1;
|
||||
}
|
||||
|
||||
public boolean equals(Vector2D v) {
|
||||
return v.getX() == x && v.getY() == y;
|
||||
}
|
||||
|
||||
public Vector2D copy() {
|
||||
return new Vector2D(x, y);
|
||||
}
|
||||
|
||||
// Floor
|
||||
public Vector2D floor() {
|
||||
Vector2D v1 = new Vector2D(Math.floor(this.x), Math.floor(this.y));
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Ceil
|
||||
public Vector2D ceil() {
|
||||
Vector2D v1 = new Vector2D(Math.ceil(this.x), Math.ceil(this.y));
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Round
|
||||
public Vector2D round() {
|
||||
Vector2D v1 = new Vector2D(Math.round(this.x), Math.round(this.y));
|
||||
return v1;
|
||||
}
|
||||
|
||||
// Round To Zero
|
||||
public Vector2D roundToZero() {
|
||||
double dx=x<0?Math.ceil( this.x ):Math.floor( this.x );
|
||||
double dy=y<0?Math.ceil( this.y ):Math.floor( this.y );
|
||||
Vector2D v1 = new Vector2D(dx,dy);
|
||||
return v1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector2D [x=" + x + ", y=" + y + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.properties;
|
||||
|
||||
|
||||
import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelElement;
|
||||
|
||||
import com.google.gwt.editor.client.Editor.Path;
|
||||
import com.sencha.gxt.data.shared.LabelProvider;
|
||||
import com.sencha.gxt.data.shared.ModelKeyProvider;
|
||||
import com.sencha.gxt.data.shared.PropertyAccess;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public interface ZoomLevelPropertiesCombo extends PropertyAccess<ZoomLevelElement> {
|
||||
|
||||
@Path("id")
|
||||
ModelKeyProvider<ZoomLevelElement> id();
|
||||
|
||||
LabelProvider<ZoomLevelElement> label();
|
||||
|
||||
}
|
|
@ -120,6 +120,12 @@ public interface ResourceBundle extends ClientBundle {
|
|||
@Source("magnifier-zoom-out.png")
|
||||
ImageResource magnifierZoomOut();
|
||||
|
||||
@Source("arrow-move_32.png")
|
||||
ImageResource move32();
|
||||
|
||||
@Source("arrow-move.png")
|
||||
ImageResource move();
|
||||
|
||||
@Source("Resources.css")
|
||||
ResourceCSS resourceCSS();
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 837 B |
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
|
@ -0,0 +1,50 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.store;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ZoomLevelElement {
|
||||
|
||||
protected int id; // For insert in table only
|
||||
protected ZoomLevelType type;
|
||||
|
||||
|
||||
public ZoomLevelElement(int id, ZoomLevelType type){
|
||||
this.id=id;
|
||||
this.type=type;
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public ZoomLevelType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void setType(ZoomLevelType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChartTypeElement [id=" + id + ", type=" + type + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.store;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ZoomLevelStore implements Serializable {
|
||||
private static final long serialVersionUID = -7118270169570196724L;
|
||||
|
||||
protected static ArrayList<ZoomLevelElement> store;
|
||||
|
||||
protected static ZoomLevelElement fitElement=new ZoomLevelElement(1,ZoomLevelType.Fit);
|
||||
protected static ZoomLevelElement maxZoomElement=new ZoomLevelElement(2,ZoomLevelType.MaxZoom);
|
||||
|
||||
|
||||
public static ArrayList<ZoomLevelElement> getZoomLevelTypes(){
|
||||
store=new ArrayList<ZoomLevelElement>();
|
||||
store.add(fitElement);
|
||||
store.add(maxZoomElement);
|
||||
return store;
|
||||
}
|
||||
|
||||
public static int selectedZoomLevelPosition(String selected){
|
||||
int position=0;
|
||||
if(selected.compareTo(ZoomLevelType.Fit.toString())==0){
|
||||
position=1;
|
||||
} else {
|
||||
if(selected.compareTo(ZoomLevelType.MaxZoom.toString())==0){
|
||||
position=2;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
public static ZoomLevelType selectedZoomLevel(String selected){
|
||||
if(selected.compareTo(ZoomLevelType.Fit.toString())==0){
|
||||
return ZoomLevelType.Fit;
|
||||
} else {
|
||||
if(selected.compareTo(ZoomLevelType.MaxZoom.toString())==0){
|
||||
return ZoomLevelType.MaxZoom;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ZoomLevelElement selectedZoomLevelElement(String selected){
|
||||
if(selected.compareTo(ZoomLevelType.Fit.toString())==0){
|
||||
return fitElement;
|
||||
} else {
|
||||
if(selected.compareTo(ZoomLevelType.MaxZoom.toString())==0){
|
||||
return maxZoomElement;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.portlets.user.td.resourceswidget.client.store;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public enum ZoomLevelType {
|
||||
Fit("Fit"), MaxZoom("Max");
|
||||
|
||||
/**
|
||||
* @param text
|
||||
*/
|
||||
private ZoomLevelType(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private final String id;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 837 B |
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in New Issue