Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Fwd: svn commit: r1059 - branches/gsoc2007/trunk/src/org: jfree jfree/experimental jfree/experimental/swt tigris/gef/graph/presentation tigris/gef/swt

gef
Discussion topic

Back to topic list

Fwd: svn commit: r1059 - branches/gsoc2007/trunk/src/org: jfree jfree/experimental jfree/experimental/swt tigris/gef/graph/presentation tigris/gef/swt

Reply

Author bobtarling
Full name Bob Tarling
Date 2007-08-08 09:07:47 PDT
Message Nice going.

I gather that hologate doesn't work as well as expected.

How is the JFree class?

Create a new issue in GEF to track the JFree jar. I think it would be
better to have that than copy their source. But for now we need to
progress so use what we have.

Cheers

Bob.



---------- Forwarded message ----------
From: johnnycoding at tigris dot org <johnnycoding at tigris dot org>
Date: 8 Aug 2007 16:00:57 -0000
Subject: svn commit: r1059 - branches/gsoc2007/tr​unk/src/org: jfree
jfree/experimental jfree/experimental/swt
tigris/gef/graph/presentation tigris/gef/swt
To: commits at gef dot tigris dot org


Author: johnnycoding
Date: 2007-08-08 09:00:56-0700
New Revision: 1059

Added:
   branches/gsoc2007/tr​unk/src/org/jfree/
   branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/
   branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/
   branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTGr​aphics2D.java
   branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTUt​ils.java
Modified:
   branches/gsoc2007/tr​unk/src/org/tigris/g​ef/graph/presentatio​n/PresentationFactor​y.java
   branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/JGraph.java
   branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/SwtUtil.java

Log:
Now swt version BasicApplication (switched in Presentation) works
using JFree Graphics2D convertor. I could not find the .jar for JFree.
So for now I just grab the source code of SWTGraphics2D and SWTUtils
classes but keep their package name: org.jfree.experimental.swt. Bob,
please let me know if it's inappropriate, I'll replace them with the
.jar later.

Added: branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTGr​aphics2D.java
Url: http://gef.tigris.or​g/source/browse/gef/​branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTGr​aphics2D.java?view=a​uto&rev=1059
====================​====================​====================​==================
--- (empty file)
+++ branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTGr​aphics2D.java
  2007-08-08 09:00:56-0700
@@ -0,0 +1,988 @@
+package org.jfree.experimental.swt;

+

+import java.awt.BasicStroke;

+

+import java.awt.Color;

+

+import java.awt.Composite;

+

+import java.awt.Font;

+

+import java.awt.FontMetrics;

+

+import java.awt.Graphics;

+

+import java.awt.Graphics2D;

+

+import java.awt.GraphicsConfiguration;

+

+import java.awt.Image;

+

+import java.awt.Paint;

+

+import java.awt.Rectangle;

+

+import java.awt.RenderingHints;

+

+import java.awt.Shape;

+

+import java.awt.Stroke;

+

+import java.awt.RenderingHints.Key;

+

+import java.awt.font.FontRe​nderContext;

+

+import java.awt.font.GlyphVector;

+

+import java.awt.geom.AffineTransform;

+

+import java.awt.geom.PathIterator;

+

+import java.awt.image.BufferedImage;

+

+import java.awt.image.BufferedImageOp;

+

+import java.awt.image.Direc​tColorModel;

+

+import java.awt.image.ImageObserver;

+

+import java.awt.image.IndexColorModel;

+

+import java.awt.image.RenderedImage;

+

+import java.awt.image.WritableRaster;

+

+import java.awt.image.rende​rable.RenderableImag​e;

+

+import java.text.Attributed​CharacterIterator;

+

+import java.util.Map;

+

+import javax.swing.JPanel;

+

+import org.eclipse.swt.SWT;

+

+import org.eclipse.swt.grap​hics.FontData;

+

+import org.eclipse.swt.graphics.GC;

+

+import org.eclipse.swt.grap​hics.ImageData;

+

+import org.eclipse.swt.grap​hics.PaletteData;

+

+import org.eclipse.swt.graphics.Path;

+

+import org.eclipse.swt.graphics.RGB;

+

+import org.eclipse.swt.grap​hics.Transform;

+

+public class SWTGraphics2D extends Graphics2D {

+ private GC gc;

+

+ private static final JPanel DUMMY_PANEL = new JPanel();

+

+

+

+ public SWTGraphics2D(GC gc) {

+

+ super();

+

+ this.gc = gc;

+

+ }

+

+

+

+ private void switchColors() {

+

+ org.eclipse.swt.graphics.Color bg = gc.getBackground();

+

+ org.eclipse.swt.graphics.Color fg = gc.getForeground();

+

+ gc.setBackground(fg);

+

+ gc.setForeground(bg);

+

+ }

+

+

+

+ private Path toSwtPath(Shape shape) {

+

+ int type;

+

+ float[] coords = new float[6];

+

+ Path path = new Path(this.gc.getDevice());

+

+ PathIterator pit = shape.getPathIterator(null);

+

+ while (!pit.isDone()) {

+

+ type = pit.currentSegment(coords);

+

+ switch (type) {

+ case (PathIterator.SEG_MOVETO):

+ path.moveTo(coords[0], coords[1]);

+

+ break;

+

+

+

+ case (PathIterator.SEG_LINETO):

+ path.lineTo(coords[0], coords[1]);

+

+ break;

+

+

+

+ case (PathIterator.SEG_QUADTO):

+ path.quadTo(coords[0], coords[1], coords[2], coords[3]);

+

+ break;

+

+

+

+ case (PathIterator.SEG_CUBICTO):

+ path.cubicTo(coords[0], coords[1], coords[2],
coords[3], coords[4], coords[5]);

+

+ break;

+

+

+

+ case (PathIterator.SEG_CLOSE):

+ path.close();

+

+ break;

+

+

+

+ default:

+ break;

+

+

+

+ }

+

+ pit.next();

+

+ }

+

+ return path;

+

+ }

+

+

+

+ private Transform toSwtTransform(AffineTransform awtTransform) {

+

+ Transform t = new Transform(gc.getDevice());

+

+ double[] matrix = new double[6];

+

+ awtTransform.getMatrix(matrix);

+

+ t.setElements((float)matrix[0], (float)matrix[1],
(float)matrix[2], (float)matrix[3], (float)matrix[4],
(float)matrix[5]);

+

+ return t;

+

+ }

+

+

+

+ private AffineTransform toAwtTransform(Transform swtTransform) {

+

+ float[] elements = new float[6];

+

+ swtTransform.getElem​ents(elements);

+

+ AffineTransform awtTransform = new AffineTransform(elements);

+

+ return awtTransform;

+

+ }

+

+

+

+ public void draw(Shape shape) {

+

+ Path path = toSwtPath(shape);

+

+ gc.drawPath(path);

+

+ path.dispose();

+

+ }

+

+

+

+ public boolean drawImage(Image image, AffineTransform xform,
ImageObserver obs) {

+

+ return false;

+

+ }

+

+

+

+ public void drawImage(BufferedImage image, BufferedImageOp op,
int x, int y) {

+

+ org.eclipse.swt.graphics.Image im = new
org.eclipse.swt.grap​hics.Image(gc.getDev​ice(), convertToSWT(image));

+

+ gc.drawImage(im, x, y);

+

+ im.dispose();

+

+ }

+

+

+

+ public void drawImage(org.eclips​e.swt.graphics.Image​ image, int x, int y) {

+

+ gc.drawImage(image, x, y);

+

+ }

+

+

+

+ public void drawRenderedImage(RenderedImage image, AffineTransform xform) {

+

+ }

+

+

+

+ public void drawRenderableImage(​RenderableImage image,
AffineTransform xform) {

+

+ }

+

+

+

+ public void drawString(String text, int x, int y) {

+

+ float fm = gc.getFontMetrics().​getAscent();

+

+ gc.drawString(text, x, (int)(y - fm), true);

+

+ }

+

+

+

+ public void drawString(String text, float x, float y) {

+

+ float fm = gc.getFontMetrics().​getAscent();

+

+ gc.drawString(text, (int)x, (int)(y - fm), true);

+

+ }

+

+

+

+ public void drawString(Attribute​dCharacterIterator iterator, int
x, int y) {

+

+ }

+

+

+

+ public void drawString(Attribute​dCharacterIterator iterator,
float x, float y) {

+

+ }

+

+

+

+ public void fill(Shape shape) {

+

+ Path path = toSwtPath(shape);

+

+ switchColors();

+

+ this.gc.fillPath(path);

+

+ switchColors();

+

+ path.dispose();

+

+ }

+

+

+

+ public boolean hit(Rectangle rect, Shape text, boolean onStroke) {

+

+ return false;

+

+ }

+

+

+

+ public GraphicsConfiguration getDeviceConfiguration() {

+

+ return null;

+

+ }

+

+

+

+ public void setComposite(Composite comp) {

+

+ }

+

+

+

+ public void setPaint(Paint paint) {

+

+ if (paint instanceof Color) {

+

+ setColor((Color)paint);

+

+ } else {

+

+ throw new RuntimeException("Can only handle \\\'Color\\\'
at present.");

+

+ }

+

+ }

+

+

+

+ public void setStroke(Stroke stroke) {

+

+ if (stroke instanceof BasicStroke) {

+

+ BasicStroke bs = (BasicStroke)stroke;

+

+ gc.setLineWidth((int​)bs.getLineWidth());​

+

+ switch (bs.getLineJoin()) {

+ case BasicStroke.JOIN_BEVEL:

+ gc.setLineJoin(SWT.JOIN_BEVEL);

+

+ break;

+

+

+

+ case BasicStroke.JOIN_MITER:

+ gc.setLineJoin(SWT.JOIN_MITER);

+

+ break;

+

+

+

+ case BasicStroke.JOIN_ROUND:

+ gc.setLineJoin(SWT.JOIN_ROUND);

+

+ break;

+

+

+

+ }

+

+ switch (bs.getEndCap()) {

+ case BasicStroke.CAP_BUTT:

+ gc.setLineCap(SWT.CAP_FLAT);

+

+ break;

+

+

+

+ case BasicStroke.CAP_ROUND:

+ gc.setLineCap(SWT.CAP_ROUND);

+

+ break;

+

+

+

+ case BasicStroke.CAP_SQUARE:

+ gc.setLineCap(SWT.CAP_SQUARE);

+

+ break;

+

+

+

+ }

+

+ gc.setLineStyle(SWT.​LINE_SOLID);

+

+ float[] dashes = bs.getDashArray();

+

+ if (dashes != null) {

+

+ int[] swtDashes = new int[dashes.length];

+

+ for (int i = 0; i < swtDashes.length; i++) {

+

+ swtDashes[i] = (int)dashes[i];

+

+ }

+

+ gc.setLineDash(swtDashes);

+

+ }

+

+ } else {

+

+ throw new RuntimeException("Can only handle \\\'Basic
Stroke\\\' at present.");

+

+ }

+

+ }

+

+

+

+ public void setRenderingHint(Key hintKey, Object hintValue) {

+

+ }

+

+

+

+ public Object getRenderingHint(Key hintKey) {

+

+ return null;

+

+ }

+

+

+

+ public void setRenderingHints(Map hints) {

+

+ }

+

+

+

+ public void addRenderingHints(Map hints) {

+

+ }

+

+

+

+ public RenderingHints getRenderingHints() {

+

+ return null;

+

+ }

+

+

+

+ public void translate(int x, int y) {

+

+ Transform swtTransform = new Transform(gc.getDevice());

+

+ gc.getTransform(swtTransform);

+

+ swtTransform.translate(x, y);

+

+ gc.setTransform(swtTransform);

+

+ swtTransform.dispose();

+

+ }

+

+

+

+ public void translate(double tx, double ty) {

+

+ translate((int)tx, (int)ty);

+

+ }

+

+

+

+ public void rotate(double theta) {

+

+ Transform swtTransform = new Transform(gc.getDevice());

+

+ gc.getTransform(swtTransform);

+

+ swtTransform.rotate(​(float)(theta * 180 / Math.PI));

+

+ gc.setTransform(swtTransform);

+

+ swtTransform.dispose();

+

+ }

+

+

+

+ public void rotate(double theta, double x, double y) {

+

+ }

+

+

+

+ public void scale(double scaleX, double scaleY) {

+

+ Transform swtTransform = new Transform(gc.getDevice());

+

+ gc.getTransform(swtTransform);

+

+ swtTransform.scale((​float)scaleX, (float)scaleY);

+

+ gc.setTransform(swtTransform);

+

+ swtTransform.dispose();

+

+ }

+

+

+

+ public void shear(double shearX, double shearY) {

+

+ Transform swtTransform = new Transform(gc.getDevice());

+

+ gc.getTransform(swtTransform);

+

+ Transform shear = new Transform(gc.getDevice(), 1.0F,
(float)shearX, (float)shearY, 1.0F, 0, 0);

+

+ swtTransform.multiply(shear);

+

+ gc.setTransform(swtTransform);

+

+ swtTransform.dispose();

+

+ }

+

+

+

+ public void transform(AffineTransform Tx) {

+

+ Transform swtTransform = new Transform(gc.getDevice());

+

+ gc.getTransform(swtTransform);

+

+ swtTransform.multipl​y(toSwtTransform(Tx)​);

+

+ gc.setTransform(swtTransform);

+

+ swtTransform.dispose();

+

+ }

+

+

+

+ public void setTransform(AffineTransform Tx) {

+

+ gc.setTransform(toSw​tTransform(Tx));

+

+ }

+

+

+

+ public AffineTransform getTransform() {

+

+ Transform swtTransform = new Transform(gc.getDevice());

+

+ gc.getTransform(swtTransform);

+

+ return toAwtTransform(swtTransform);

+

+ }

+

+

+

+ public Paint getPaint() {

+

+ return SWTUtils.toAwtColor(​gc.getForeground());​

+

+ }

+

+

+

+ public Composite getComposite() {

+

+ return null;

+

+ }

+

+

+

+ public void setBackground(Color color) {

+

+ gc.setBackground(SWT​Utils.toSwtColor(gc.​getDevice(), color));

+

+ }

+

+

+

+ public Color getBackground() {

+

+ return SWTUtils.toAwtColor(​gc.getBackground());​

+

+ }

+

+

+

+ public Stroke getStroke() {

+

+ return new BasicStroke(gc.getLineWidth(), gc.getLineCap(),
gc.getLineJoin());

+

+ }

+

+

+

+ public void clip(Shape s) {

+

+ Path path = toSwtPath(s);

+

+ gc.setClipping(path);

+

+ path.dispose();

+

+ }

+

+

+

+ public FontRenderContext getFontRenderContext() {

+

+ FontRenderContext fontRenderContext = new
FontRenderContext(new AffineTransform(), true, true);

+

+ return fontRenderContext;

+

+ }

+

+

+

+ public void drawGlyphVector(GlyphVector g, float x, float y) {

+

+ }

+

+

+

+ public Graphics create() {

+

+ return null;

+

+ }

+

+

+

+ public Color getColor() {

+

+ return SWTUtils.toAwtColor(​gc.getForeground());​

+

+ }

+

+

+

+ public void setColor(Color color) {

+

+ gc.setForeground(SWT​Utils.toSwtColor(gc.​getDevice(), color));

+

+ }

+

+

+

+ public void setPaintMode() {

+

+ }

+

+

+

+ public void setXORMode(Color color) {

+

+ }

+

+

+

+ public Font getFont() {

+

+ FontData[] fontData = gc.getFont().getFontData();

+

+ return SWTUtils.toAwtFont(g​c.getDevice(), fontData[0], true);

+

+ }

+

+

+

+ public void setFont(Font font) {

+

+ org.eclipse.swt.graphics.Font swtFont = new
org.eclipse.swt.grap​hics.Font(gc.getDevi​ce(),
SWTUtils.toSwtFontDa​ta(gc.getDevice(), font, true));

+

+ gc.setFont(swtFont);

+

+ }

+

+

+

+ public FontMetrics getFontMetrics(Font font) {

+

+ return DUMMY_PANEL.getFontM​etrics(font);

+

+ }

+

+

+

+ public Rectangle getClipBounds() {

+

+ org.eclipse.swt.grap​hics.Rectangle clip = gc.getClipping();

+

+ return new Rectangle(clip.x, clip.y, clip.width, clip.height);

+

+ }

+

+

+

+ public void clipRect(int x, int y, int width, int height) {

+

+ org.eclipse.swt.grap​hics.Rectangle clip = gc.getClipping();

+

+ clip.intersects(x, y, width, height);

+

+ gc.setClipping(clip);

+

+ }

+

+

+

+ public void setClip(int x, int y, int width, int height) {

+

+ gc.setClipping(x, y, width, height);

+

+ }

+

+

+

+ public Shape getClip() {

+

+ return null;

+

+ }

+

+

+

+ public void setClip(Shape clip) {

+

+ if (clip == null) return;

+

+ Path clipPath = toSwtPath(clip);

+

+ gc.setClipping(clipPath);

+

+ clipPath.dispose();

+

+ }

+

+

+

+ public void copyArea(int x, int y, int width, int height, int dx, int dy) {

+

+ }

+

+

+

+ public void drawLine(int x1, int y1, int x2, int y2) {

+

+ gc.drawLine(x1, y1, x2, y2);

+

+ }

+

+

+

+ public void fillRect(int x, int y, int width, int height) {

+

+ gc.fillRectangle(x, y, width, height);

+

+ }

+

+

+

+ public void clearRect(int x, int y, int width, int height) {

+

+ }

+

+

+

+ public void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight) {

+

+ }

+

+

+

+ public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight) {

+

+ }

+

+

+

+ public void drawOval(int x, int y, int width, int height) {

+

+ }

+

+

+

+ public void fillOval(int x, int y, int width, int height) {

+

+ }

+

+

+

+ public void drawArc(int x, int y, int width, int height, int
arcStart, int arcAngle) {

+

+ }

+

+

+

+ public void fillArc(int x, int y, int width, int height, int
arcStart, int arcAngle) {

+

+ }

+

+

+

+ public void drawPolyline(int[] xPoints, int[] yPoints, int npoints) {

+

+ }

+

+

+

+ public void drawPolygon(int[] xPoints, int[] yPoints, int npoints) {

+

+ }

+

+

+

+ public void fillPolygon(int[] xPoints, int[] yPoints, int npoints) {

+

+ }

+

+

+

+ public boolean drawImage(Image image, int x, int y, ImageObserver
observer) {

+

+ return false;

+

+ }

+

+

+

+ public boolean drawImage(Image image, int x, int y, int width,
int height, ImageObserver observer) {

+

+ return false;

+

+ }

+

+

+

+ public boolean drawImage(Image image, int x, int y, Color
bgcolor, ImageObserver observer) {

+

+ return false;

+

+ }

+

+

+

+ public boolean drawImage(Image image, int x, int y, int width,
int height, Color bgcolor, ImageObserver observer) {

+

+ return false;

+

+ }

+

+

+

+ public boolean drawImage(Image image, int dx1, int dy1, int dx2,
int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {

+

+ return false;

+

+ }

+

+

+

+ public boolean drawImage(Image image, int dx1, int dy1, int dx2,
int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
ImageObserver observer) {

+

+ return false;

+

+ }

+

+

+

+ public void dispose() {

+

+ gc.dispose();

+

+ }

+

+

+

+ static ImageData convertToSWT(BufferedImage bufferedImage) {

+

+ if (bufferedImage.getColorModel() instanceof DirectColorModel) {

+

+ DirectColorModel colorModel =
(DirectColorModel)bu​fferedImage.getColor​Model();

+

+ PaletteData palette = new
PaletteData(colorMod​el.getRedMask(), colorModel.getGreenMask(),
colorModel.getBlueMask());

+

+ ImageData data = new ImageData(bufferedIm​age.getWidth(),
bufferedImage.getHeight(), colorModel.getPixelSize(), palette);

+

+ WritableRaster raster = bufferedImage.getRaster();

+

+ int[] pixelArray = new int[3];

+

+ for (int y = 0; y < data.height; y++) {

+

+ for (int x = 0; x < data.width; x++) {

+

+ raster.getPixel(x, y, pixelArray);

+

+ int pixel = palette.getPixel(new
RGB(pixelArray[0], pixelArray[1], pixelArray[2]));

+

+ data.setPixel(x, y, pixel);

+

+ }

+

+ }

+

+ return data;

+

+ } else if (bufferedImage.getColorModel() instanceof IndexColorModel) {

+

+ IndexColorModel colorModel =
(IndexColorModel)buf​feredImage.getColorM​odel();

+

+ int size = colorModel.getMapSize();

+

+ byte[] reds = new byte[size];

+

+ byte[] greens = new byte[size];

+

+ byte[] blues = new byte[size];

+

+ colorModel.getReds(reds);

+

+ colorModel.getGreens(greens);

+

+ colorModel.getBlues(blues);

+

+ RGB[] rgbs = new RGB[size];

+

+ for (int i = 0; i < rgbs.length; i++) {

+

+ rgbs[i] = new RGB(reds[i] & 255, greens[i] & 255,
blues[i] & 255);

+

+ }

+

+ PaletteData palette = new PaletteData(rgbs);

+

+ ImageData data = new ImageData(bufferedIm​age.getWidth(),
bufferedImage.getHeight(), colorModel.getPixelSize(), palette);

+

+ data.transparentPixel = colorModel.getTransp​arentPixel();

+

+ WritableRaster raster = bufferedImage.getRaster();

+

+ int[] pixelArray = new int[1];

+

+ for (int y = 0; y < data.height; y++) {

+

+ for (int x = 0; x < data.width; x++) {

+

+ raster.getPixel(x, y, pixelArray);

+

+ data.setPixel(x, y, pixelArray[0]);

+

+ }

+

+ }

+

+ return data;

+

+ }

+

+ return null;

+

+ }

+

+}

+


Added: branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTUt​ils.java
Url: http://gef.tigris.or​g/source/browse/gef/​branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTUt​ils.java?view=auto​&rev=1059
====================​====================​====================​==================
--- (empty file)
+++ branches/gsoc2007/tr​unk/src/org/jfree/ex​perimental/swt/SWTUt​ils.java
       2007-08-08 09:00:56-0700
@@ -0,0 +1,252 @@
+package org.jfree.experimental.swt;

+

+import javax.swing.JPanel;

+

+import org.eclipse.swt.SWT;

+

+import org.eclipse.swt.graphics.Color;

+

+import org.eclipse.swt.grap​hics.Device;

+

+import org.eclipse.swt.graphics.Font;

+

+import org.eclipse.swt.grap​hics.FontData;

+

+import org.eclipse.swt.graphics.GC;

+

+public class SWTUtils {

+

+ private static final String Az = "ABCpqr";

+

+ public static FontData toSwtFontData(Device device, java.awt.Font font,

+ boolean ensureSameSize) {

+

+ FontData fontData = new FontData();

+

+ fontData.setName(fon​t.getFamily());

+

+ int style = SWT.NORMAL;

+

+ switch (font.getStyle()) {

+ case java.awt.Font.PLAIN:

+ style |= SWT.NORMAL;

+

+ break;

+

+ case java.awt.Font.BOLD:

+ style |= SWT.BOLD;

+

+ break;

+

+ case java.awt.Font.ITALIC:

+ style |= SWT.ITALIC;

+

+ break;

+

+ case (java.awt.Font.ITALIC + java.awt.Font.BOLD):

+ style |= SWT.ITALIC | SWT.BOLD;

+

+ break;

+

+ }

+

+ fontData.setStyle(style);

+

+ int height = (int) Math

+ .round(font.getSize() * 72.0 / device.getDPI().y);

+

+ fontData.setHeight(height);

+

+ if (ensureSameSize) {

+

+ GC tmpGC = new GC(device);

+

+ JPanel DUMMY_PANEL = new JPanel();

+

+ Font tmpFont = new Font(device, fontData);

+

+ tmpGC.setFont(tmpFont);

+

+ if (tmpGC.textExtent(Az).x > DUMMY_PANEL.getFontM​etrics(font)

+ .stringWidth(Az)) {

+

+ while (tmpGC.textExtent(Az).x > DUMMY_PANEL

+ .getFontMetrics(font​).stringWidth(Az)) {

+

+ tmpFont.dispose();

+

+ height--;

+

+ fontData.setHeight(height);

+

+ tmpFont = new Font(device, fontData);

+

+ tmpGC.setFont(tmpFont);

+

+ }

+

+ } else if (tmpGC.textExtent(Az).x < DUMMY_PANEL

+ .getFontMetrics(font​).stringWidth(Az)) {

+

+ while (tmpGC.textExtent(Az).x < DUMMY_PANEL

+ .getFontMetrics(font​).stringWidth(Az)) {

+

+ tmpFont.dispose();

+

+ height++;

+

+ fontData.setHeight(height);

+

+ tmpFont = new Font(device, fontData);

+

+ tmpGC.setFont(tmpFont);

+

+ }

+

+ }

+

+ tmpFont.dispose();

+

+ tmpGC.dispose();

+

+ }

+

+ return fontData;

+

+ }

+

+ public static java.awt.Font toAwtFont(Device device, FontData fontData,

+ boolean ensureSameSize) {

+

+ int style;

+

+ switch (fontData.getStyle()) {

+ case SWT.NORMAL:

+ style = java.awt.Font.PLAIN;

+

+ break;

+

+ case SWT.ITALIC:

+ style = java.awt.Font.ITALIC;

+

+ break;

+

+ case SWT.BOLD:

+ style = java.awt.Font.BOLD;

+

+ break;

+

+ default:

+ style = java.awt.Font.PLAIN;

+

+ break;

+

+ }

+

+ int height = (int) Math.round(fontData.height * device.getDPI().y

+ / 72.0);

+

+ if (ensureSameSize) {

+

+ GC tmpGC = new GC(device);

+

+ Font tmpFont = new Font(device, fontData);

+

+ tmpGC.setFont(tmpFont);

+

+ JPanel DUMMY_PANEL = new JPanel();

+

+ java.awt.Font tmpAwtFont = new java.awt.Font(fontDa​ta.getName(),

+ style, height);

+

+ if (DUMMY_PANEL.getFont​Metrics(tmpAwtFont).​stringWidth(Az) > tmpGC

+ .textExtent(Az).x) {

+

+ while
(DUMMY_PANEL.getFont​Metrics(tmpAwtFont).​stringWidth(Az) > tmpGC

+ .textExtent(Az).x) {

+

+ height--;

+

+ tmpAwtFont = new java.awt.Font(fontDa​ta.getName(), style,

+ height);

+

+ }

+

+ } else if
(DUMMY_PANEL.getFont​Metrics(tmpAwtFont).​stringWidth(Az) < tmpGC

+ .textExtent(Az).x) {

+

+ while
(DUMMY_PANEL.getFont​Metrics(tmpAwtFont).​stringWidth(Az) < tmpGC

+ .textExtent(Az).x) {

+

+ height++;

+

+ tmpAwtFont = new java.awt.Font(fontDa​ta.getName(), style,

+ height);

+

+ }

+

+ }

+

+ tmpFont.dispose();

+

+ tmpGC.dispose();

+

+ }

+

+ return new java.awt.Font(fontDa​ta.getName(), style, height);

+

+ }

+

+ public static java.awt.Font toAwtFont(Device device, Font font) {

+

+ FontData fontData = font.getFontData()[0];

+

+ return toAwtFont(device, fontData, true);

+

+ }

+

+ public static java.awt.Color toAwtColor(Color color) {

+

+ return new java.awt.Color(color.getRed(), color.getGreen(), color

+ .getBlue());

+

+ }

+

+ public static Color toSwtColor(Device device, java.awt.Paint paint) {

+

+ java.awt.Color color;

+

+ if (paint instanceof java.awt.Color) {

+

+ color = (java.awt.Color) paint;

+

+ } else {

+

+ try {

+

+ throw new Exception(

+ "only color is supported at present... setting
paint to uniform black color");

+

+ } catch (Exception e) {

+

+ e.printStackTrace();

+

+ color = new java.awt.Color(0, 0, 0);

+

+ }

+

+ }

+

+ return new org.eclipse.swt.grap​hics.Color(device, color.getRed(), color

+ .getGreen(), color.getBlue());

+

+ }

+

+ public static Color toSwtColor(Device device, java.awt.Color color) {

+

+ return new org.eclipse.swt.grap​hics.Color(device, color.getRed(), color

+ .getGreen(), color.getBlue());

+

+ }

+

+}


Modified: branches/gsoc2007/tr​unk/src/org/tigris/g​ef/graph/presentatio​n/PresentationFactor​y.java
Url: http://gef.tigris.or​g/source/browse/gef/​branches/gsoc2007/tr​unk/src/org/tigris/g​ef/graph/presentatio​n/PresentationFactor​y.java?view=diff​&rev=1059&p1=bra​nches/gsoc2007/trunk​/src/org/tigris/gef/​graph/presentation/P​resentationFactory.j​ava&p2=branches/​gsoc2007/trunk/src/o​rg/tigris/gef/graph/​presentation/Present​ationFactory.java​&r1=1058&r2=105​9
====================​====================​====================​==================
--- branches/gsoc2007/tr​unk/src/org/tigris/g​ef/graph/presentatio​n/PresentationFactor​y.java
     (original)
+++ branches/gsoc2007/tr​unk/src/org/tigris/g​ef/graph/presentatio​n/PresentationFactor​y.java
     2007-08-08 09:00:56-0700
@@ -1,10 +1,12 @@
 package org.tigris.gef.graph​.presentation;

 import org.tigris.gef.swing​.SwingPresentation;
+import org.tigris.gef.swt.S​wtPresentation;
+//graphics2dFactory =
org.holongate.j2d.J2​DRegistry.createGrap​hics2DFactory(super.​getSWTPeer());

 public class PresentationFactory {

- private static Presentation presentation = new SwingPresentation();
+ private static Presentation presentation = new
SwtPresentation();// new SwingPresentation();

     static public Presentation getPresentation() {
        return presentation;

Modified: branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/JGraph.java
Url: http://gef.tigris.or​g/source/browse/gef/​branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/JGraph.java?v​iew=diff&rev=105​9&p1=branches/gs​oc2007/trunk/src/org​/tigris/gef/swt/JGra​ph.java&p2=branc​hes/gsoc2007/trunk/s​rc/org/tigris/gef/sw​t/JGraph.java&r1​=1058&r2=1059
====================​====================​====================​==================
--- branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/JGraph.java (original)
+++ branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/JGraph.java
2007-08-08 09:00:56-0700
@@ -602,6 +602,8 @@


     protected org.tigris.gef.base.FileDialog fileDialog;



+ //protected org.holongate.j2d.Gr​aphics2DFactory graphics2dFactory;

+

     public JGraphInternalPane(Editor e) {

        _editor = e;

        setLayout(null);

@@ -612,6 +614,7 @@
        addMouseMotionListener(this);

        addKeyListener(this);



+ //graphics2dFactory =
org.holongate.j2d.J2​DRegistry.createGrap​hics2DFactory(super.​getSWTPeer());

        //initiate the eventListeners ArrayList

        eventListeners = new ArrayList<EventLi​stener>();

     }


Modified: branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/SwtUtil.java
Url: http://gef.tigris.or​g/source/browse/gef/​branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/SwtUtil.java?​view=diff&rev=10​59&p1=branches/g​soc2007/trunk/src/or​g/tigris/gef/swt/Swt​Util.java&p2=bra​nches/gsoc2007/trunk​/src/org/tigris/gef/​swt/SwtUtil.java​&r1=1058&r2=1059​
====================​====================​====================​==================
--- branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/SwtUtil.java (original)
+++ branches/gsoc2007/tr​unk/src/org/tigris/g​ef/swt/SwtUtil.java
2007-08-08 09:00:56-0700
@@ -28,6 +28,7 @@
 package org.tigris.gef.swt;



 import swingwt.awt.*;

+import org.jfree.experimental.swt.*;



 public class SwtUtil{



@@ -35,7 +36,7 @@
     private static final int HOLONGATE_GRAPHICS = 1;

     private static final int JFREE_GRAPHICS = 2;



- private static final int GRAPHICS_IMPLEMENTATION = SWINGWT_GRAPHICS;

+ private static final int GRAPHICS_IMPLEMENTATION = JFREE_GRAPHICS;



     public static Rectangle translateRectangle(j​ava.awt.Rectangle awt) {

        return new Rectangle(awt.x, awt.y, awt.width, awt.height);

@@ -60,10 +61,13 @@
                return new GraphicsTranslator(swt);

            }

        } else if (GRAPHICS_IMPLEMENTATION == HOLONGATE_GRAPHICS) {

- // TODO experiment here with Holongate Graphics

            return null;

        } else if (GRAPHICS_IMPLEMENTATION == JFREE_GRAPHICS) {

- // TODO experiment here with JFree Graphics

+ if (swt instanceof SWTGraphics2DRenderer) {

+ SWTGraphics2DRenderer render = (SWTGraphics2DRenderer)swt;

+ SWTGraphics2D swtGraphics2D = new
SWTGraphics2D(render​.getSWTGC());

+ return swtGraphics2D;

+ }

            return null;

        } else {

            return null;


--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: commits-unsubscribe@​gef.tigris.org
For additional commands, e-mail: commits-help at gef dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

Fwd: svn commit: r1059 - branches/gsoc2007/trunk/src/org: jfree jfree/experimental jfree/experimental/swt tigris/gef/graph/presentation tigris/gef/swt bobtarling Bob Tarling 2007-08-08 09:07:47 PDT
Messages per page: