Author: DartPeng
Date: 2008-08-15 06:53:26 -0400 (Fri, 15 Aug 2008)
New Revision: 9740
Added:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/figures/CurveLineConnection.java
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/RootModelEditPart.java
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/StructuredDataConnectionEditPart.java
Log:
draw curve line
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-08-15
09:33:33 UTC (rev 9739)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-08-15
10:53:26 UTC (rev 9740)
@@ -11,9 +11,12 @@
package org.jboss.tools.smooks.ui.editors;
import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.dnd.TemplateTransfer;
+import org.eclipse.gef.editparts.LayerManager;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
import org.eclipse.gef.ui.parts.SelectionSynchronizer;
import org.eclipse.jface.dialogs.Dialog;
@@ -130,19 +133,18 @@
.getInstance() }, new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
event.data = sourceViewer.getSelection();
- System.out.println(event.data);
TemplateTransfer.getInstance().setTemplate(
sourceViewer.getSelection());
event.doit = true;
}
});
- sourceViewer.getTree().addPaintListener(new PaintListener(){
+ sourceViewer.getTree().addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
rootModel.firePropertyChange(RootModel.P_REFRESH_PANEL,
null, new Object());
}
});
-
+
if (initSourceTreeViewerProviders()) {
initSourceTreeViewer();
}
@@ -182,13 +184,7 @@
new Transfer[] { TemplateTransfer.getInstance() },
new TargetTreeDropTargetListener(targetViewer,
getGraphicalViewer()));
-// targetViewer.getTree().addPaintListener(new PaintListener() {
-// public void paintControl(PaintEvent e) {
-// rootModel.firePropertyChange(RootModel.P_REFRESH_PANEL,
-// null, new Object());
-// }
-// });
- targetViewer.getTree().addPaintListener(new PaintListener(){
+ targetViewer.getTree().addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
rootModel.firePropertyChange(RootModel.P_REFRESH_PANEL,
null, new Object());
@@ -274,12 +270,6 @@
}
protected void initSourceTreeViewer() {
- // TODO Test
- // JavaBeanModel model = JavaBeanModelFactory
- // .getJavaBeanModel(Order.class);
- // List modelList = new ArrayList();
- // modelList.add(model);
- // sourceViewer.setInput(modelList);
sourceViewer.expandAll();
}
@@ -388,6 +378,13 @@
this.getGraphicalViewer().setEditPartFactory(
new SmooksEditPartFactory());
this.getGraphicalViewer().setContents(rootModel);
+
+ LayerManager manager = (LayerManager) getGraphicalViewer()
+ .getEditPartRegistry().get(LayerManager.ID);
+ ConnectionLayer layer = (ConnectionLayer) manager
+ .getLayer(LayerConstants.CONNECTION_LAYER);
+ if (layer != null)
+ layer.setAntialias(SWT.SMOOTH);
}
public SelectionSynchronizer getSelectionSynchronizer() {
@@ -459,19 +456,20 @@
viewer.setInput(cw.getTreeViewerInputContents());
// the viewer must be expanded , then the graphics model can
// calculate the location correctly
-// viewer.refresh();
- try{
- viewer.expandAll();
- }catch(Exception e){
+ try {
+ viewer.expandAll();
+ if (viewer == this.sourceViewer) {
+ this.createSourceGraphModels();
+ }
+ if (viewer == this.targetViewer) {
+ this.createTargetGraphModels();
+ }
+ } catch (Exception e) {
e.printStackTrace();
+ MessageDialog.openError(getSite().getShell(), "Error",
+ "a error occurs during filling Data into the viewer:\n"
+ + e.toString());
}
-
- if (viewer == this.sourceViewer) {
- this.createSourceGraphModels();
- }
- if (viewer == this.targetViewer) {
- this.createTargetGraphModels();
- }
} else {
MessageDialog.openError(getSite().getShell(), "Error",
"a error occurs during filling Data into the viewer");
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/RootModelEditPart.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/RootModelEditPart.java 2008-08-15
09:33:33 UTC (rev 9739)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/RootModelEditPart.java 2008-08-15
10:53:26 UTC (rev 9740)
@@ -7,7 +7,6 @@
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ScalableFreeformLayeredPane;
import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.GraphicalEditPart;
import org.jboss.tools.smooks.ui.gef.figures.GraphRootFigureLayout;
import org.jboss.tools.smooks.ui.gef.model.AbstractStructuredDataModel;
import org.jboss.tools.smooks.ui.gef.policy.RootGraphicsXYLayoutEditPolicy;
@@ -15,14 +14,14 @@
public class RootModelEditPart extends AbstractStructuredDataEditPart {
protected IFigure createFigure() {
- IFigure figure = new ScalableFreeformLayeredPane(){
+ IFigure figure = new ScalableFreeformLayeredPane() {
@Override
public void paintClientArea(Graphics graphics) {
-// graphics.pushState();
-// graphics.setBackgroundColor(ColorConstants.lightGreen);
-// graphics.setForegroundColor(ColorConstants.white);
-// graphics.fillGradient(getBounds(), true);
-// graphics.popState();
+ // graphics.pushState();
+ // graphics.setBackgroundColor(ColorConstants.lightGreen);
+ // graphics.setForegroundColor(ColorConstants.white);
+ // graphics.fillGradient(getBounds(), true);
+ // graphics.popState();
super.paintClientArea(graphics);
}
};
@@ -31,29 +30,34 @@
}
public void propertyChange(PropertyChangeEvent evt) {
- if ( evt.getPropertyName().equals(AbstractStructuredDataModel.P_CHILDREN) ) {
+ if (evt.getPropertyName()
+ .equals(AbstractStructuredDataModel.P_CHILDREN)) {
refreshChildren();
}
- if ( evt.getPropertyName().equals(AbstractStructuredDataModel.P_REFRESH_PANEL) ) {
+ if (evt.getPropertyName().equals(
+ AbstractStructuredDataModel.P_REFRESH_PANEL)) {
this.getFigure().invalidate();
this.getFigure().validate();
-// this.getFigure().validate();
+ // this.getFigure().validate();
}
}
-
+
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
*/
protected void createEditPolicies() {
- this.installEditPolicy(EditPolicy.LAYOUT_ROLE, new RootGraphicsXYLayoutEditPolicy());
+ this.installEditPolicy(EditPolicy.LAYOUT_ROLE,
+ new RootGraphicsXYLayoutEditPolicy());
}
-
+
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
*/
protected List getModelChildren() {
- return ((AbstractStructuredDataModel)getModel()).getChildren();
+ return ((AbstractStructuredDataModel) getModel()).getChildren();
}
}
\ No newline at end of file
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/StructuredDataConnectionEditPart.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/StructuredDataConnectionEditPart.java 2008-08-15
09:33:33 UTC (rev 9739)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/editparts/StructuredDataConnectionEditPart.java 2008-08-15
10:53:26 UTC (rev 9740)
@@ -12,7 +12,7 @@
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
-import org.eclipse.swt.SWT;
+import org.jboss.tools.smooks.ui.gef.figures.CurveLineConnection;
import org.jboss.tools.smooks.ui.gef.policy.DeleteConnectionEditPolicy;
import org.jboss.tools.smooks.ui.gef.util.GraphicsConstants;
@@ -31,11 +31,12 @@
}
protected IFigure createFigure() {
- PolylineConnection conn = new PolylineConnection(){
+ CurveLineConnection conn = new CurveLineConnection(){
public void paintFigure(Graphics graphics){
super.paintFigure(graphics);
}
};
+// conn.setSmoothness(SmoothPolyLineConnection.SMOOTH_MORE);
Figure targetFlagFigure = new Figure() {
/*
Added:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/figures/CurveLineConnection.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/figures/CurveLineConnection.java
(rev 0)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/figures/CurveLineConnection.java 2008-08-15
10:53:26 UTC (rev 9740)
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.ui.gef.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * @author Dart Peng
+ * @Date Aug 16, 2008
+ */
+public class CurveLineConnection extends PolylineConnection {
+ private double[] fBasicCenterCurve;
+
+ private int[] getCenterCurvePoints(int startx, int starty, int endx,
+ int endy) {
+ buildBaseCenterCurve(endx - startx);
+ double height = endy - starty;
+ height = height / 2;
+ int width = Math.abs(startx - endx);
+ int[] points = new int[width];
+ for (int i = 0; i < width; i++) {
+ points[i] = (int) (-height * fBasicCenterCurve[i] + height + starty);
+ }
+ return points;
+ }
+
+ private PointList getcenterCurvePointList() {
+ if (this.getCenterWidth() < 0)
+ return null;
+ PointList list1 = this.getPoints();
+ Point start = this.getStart();
+ Point end = this.getEnd();
+ if (start == null || end == null) {
+ return null;
+ }
+ int[] points = getCenterCurvePoints(start.x + 8, start.y, end.x - 8, end.y);
+ PointList list = new PointList();
+ for (int i = 1; i < points.length; i++) {
+ list.addPoint(start.x + 8 + i - 1, points[i - 1]);
+ }
+ list.addPoint(this.getPoints().getLastPoint());
+ list.insertPoint(this.getStart(), 0);
+ return list;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.draw2d.Polyline#outlineShape(org.eclipse.draw2d.Graphics)
+ */
+ @Override
+ protected void outlineShape(Graphics g) {
+ try {
+ PointList displayPoints = getcenterCurvePointList();
+ if (displayPoints != null)
+ g.drawPolyline(displayPoints);
+ } catch (Exception e) {
+ e.printStackTrace();
+ super.outlineShape(g);
+ }
+ }
+
+ public Rectangle getBounds() {
+ if (bounds == null) {
+ if (this.getCenterWidth() <= 0)
+ return super.getBounds();
+ bounds = getcenterCurvePointList().getBounds();
+ bounds.expand(lineWidth / 2, lineWidth / 2);
+
+ for (int i = 0; i < getChildren().size(); i++) {
+ IFigure child = (IFigure) getChildren().get(i);
+ bounds.union(child.getBounds());
+ }
+ }
+ return bounds;
+ }
+
+ private void buildBaseCenterCurve(int w) {
+ double width = w;
+ int count = getCenterWidth();
+ if (count < 0)
+ return;
+ fBasicCenterCurve = new double[count];
+ for (int i = 0; i < getCenterWidth(); i++) {
+ double r = i / width;
+ fBasicCenterCurve[i] = Math.cos(Math.PI * r);
+ }
+ }
+
+ private int getCenterWidth() {
+ if (this.getPoints().size() == 0)
+ return -1;
+ Point start = this.getStart();
+ Point end = this.getEnd();
+ int w = Math.abs(start.x - end.x);
+ if (w <= 0)
+ return -1;
+ return Math.abs(w);
+ }
+}
Property changes on:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/figures/CurveLineConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain