Issue #1395 Modified LineStyle to contain a definition of the style so that GL and SWT can render them the same way

Change-Id: I9e9875c3d56870309d4c5420a541674fb8733a09

Former-commit-id: 330e913cb2 [formerly 5143e82d4a] [formerly 330e913cb2 [formerly 5143e82d4a] [formerly 9398573f2f [formerly 6c2704dffcbadab19611464df580f781bb5ebefd]]]
Former-commit-id: 9398573f2f
Former-commit-id: d42afa44dc [formerly 10479a1909]
Former-commit-id: ddd26d1fbd
This commit is contained in:
Ron Anderson 2012-12-06 15:38:04 -06:00
parent 1a27d852e1
commit bb50fa220a
3 changed files with 122 additions and 74 deletions

View file

@ -23,7 +23,9 @@ package com.raytheon.uf.viz.core;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.geotools.coverage.grid.GeneralGridGeometry; import org.geotools.coverage.grid.GeneralGridGeometry;
@ -84,18 +86,94 @@ public interface IGraphicsTarget extends IImagingExtension {
* the target may want to switch default to a different style before drawing * the target may want to switch default to a different style before drawing
*/ */
public static enum LineStyle { public static enum LineStyle {
DEFAULT, SOLID, DASHED, DASHED_LARGE, DOTTED, DASH_DOTTED, DEFAULT, //
SOLID, //
DASHED(4, (short) 0xAAAA), //
DASHED_LARGE(4, (short) 0xEEEE), //
DOTTED(1, (short) 0xAAAA), //
DASH_DOTTED(1, (short) 0xE4E4),
// Task 69 : Added for NMAP // Task 69 : Added for NMAP
SHORT_DASHED, // GEMPAK line type 2 SHORT_DASHED(8, (short) 0xAAAA), // GEMPAK line type 2
MEDIUM_DASHED, // GEMPAK line type 3 MEDIUM_DASHED(3, (short) 0xF8F8), // GEMPAK line type 3
LONG_DASH_SHORT_DASH, // GEMPAK line type 4 LONG_DASH_SHORT_DASH(3, (short) 0xFC38), // GEMPAK line type 4
LONG_DASHED, // GEMPAK line type 5 LONG_DASHED(3, (short) 0xFCFC), // GEMPAK line type 5
LONG_DASH_THREE_SHORT_DASHES, // GEMPAK line type 6 LONG_DASH_THREE_SHORT_DASHES(3, (short) 0xFDB6), // GEMPAK line type 6
LONG_DASH_DOT, // GEMPAK line type 7 LONG_DASH_DOT(2, (short) 0xFFE4), // GEMPAK line type 7
LONG_DASH_THREE_DOTS, // GEMPAK line type 8 LONG_DASH_THREE_DOTS(2, (short) 0xFC92), // GEMPAK line type 8
MEDIUM_DASH_DOT, // GEMPAK line type 9 MEDIUM_DASH_DOT(2, (short) 0xFF88), // GEMPAK line type 9
DOTS DOTS(1, (short) 0x8888); // GEMPAK line type 10
// GEMPAK line type 10
private final int factor;
private final short pattern;
LineStyle() {
this.factor = 0;
this.pattern = 0;
}
LineStyle(int factor, short pattern) {
if (factor < 1) {
this.factor = 1;
} else if (factor > 255) {
this.factor = 255;
} else {
this.factor = factor;
}
this.pattern = pattern;
}
public int getFactor() {
return factor;
}
public short getPattern() {
return pattern;
}
public int[] getSWTLineStyle() {
if (this.factor == 0 || this.pattern == 0) {
return null;
} else {
List<Integer> dashPattern = new ArrayList<Integer>();
int p = this.pattern & 0xFFFF;
// strip trailing 0s
int prevLsb = p & 1;
while (prevLsb == 0) {
p >>= 1;
prevLsb = p & 1;
}
int count = 0;
int sum = 0;
while (p != 0) {
int lsb = p & 1;
if (lsb != prevLsb) {
dashPattern.add(count * factor);
sum += count;
count = 0;
prevLsb = lsb;
}
count++;
p >>= 1;
}
if (prevLsb == 1 & count > 0) {
dashPattern.add(count * factor);
sum += count;
}
if (sum < 16) {
dashPattern.add((16 - sum) * factor);
}
int[] array = new int[dashPattern.size()];
for (int i = 0; i < dashPattern.size(); i++) {
array[i] = dashPattern.get(i);
}
return array;
}
}
} }
public static enum PointStyle { public static enum PointStyle {
@ -732,9 +810,7 @@ public interface IGraphicsTarget extends IImagingExtension {
public IView getView(); public IView getView();
/** /**
* /** Use drawStrings(DrawableString parameters)
/**
* Use drawStrings(DrawableString parameters)
*/ */
@Deprecated @Deprecated
public abstract void drawString(IFont font, String text, double x, public abstract void drawString(IFont font, String text, double x,

View file

@ -1130,44 +1130,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
if (lineStyle != null && lineStyle != LineStyle.SOLID if (lineStyle != null && lineStyle != LineStyle.SOLID
&& lineStyle != LineStyle.DEFAULT) { && lineStyle != LineStyle.DEFAULT) {
gl.glEnable(GL.GL_LINE_STIPPLE); gl.glEnable(GL.GL_LINE_STIPPLE);
if (lineStyle == LineStyle.DASHED) { gl.glLineStipple(lineStyle.getFactor(), lineStyle.getPattern());
gl.glLineStipple(4, (short) 0xAAAA);
} else if (lineStyle == LineStyle.DASHED_LARGE) {
gl.glLineStipple(4, (short) 0xEEEE);
} else if (lineStyle == LineStyle.DOTTED) {
gl.glLineStipple(1, (short) 0xAAAA);
} else if (lineStyle == LineStyle.DASH_DOTTED) {
gl.glLineStipple(1, (short) 0xE4E4);
}
// NMAP Task 69 to add line styles from GEMPAK
else if (lineStyle == LineStyle.DOTS) {
gl.glLineStipple(1, (short) 0x8888);
} else if (lineStyle == LineStyle.SHORT_DASHED) {
gl.glLineStipple(8, (short) 0xAAAA);
} else if (lineStyle == LineStyle.MEDIUM_DASHED) {
gl.glLineStipple(3, (short) 0xF8F8);
} else if (lineStyle == LineStyle.LONG_DASHED) {
gl.glLineStipple(3, (short) 0xFCFC);
} else if (lineStyle == LineStyle.LONG_DASH_DOT) {
gl.glLineStipple(2, (short) 0xFFE4);
} else if (lineStyle == LineStyle.LONG_DASH_SHORT_DASH) {
gl.glLineStipple(3, (short) 0xFC38);
} else if (lineStyle == LineStyle.LONG_DASH_THREE_DOTS) {
// gl.glLineStipple(2, (short) 0xFFAA);
// gl.glLineStipple(3, (short) 0xFFAA);
gl.glLineStipple(2, (short) 0xFC92);
} else if (lineStyle == LineStyle.LONG_DASH_THREE_SHORT_DASHES) {
// gl.glLineStipple(5, (short) 0xFFAA);
gl.glLineStipple(3, (short) 0xFDB6);
} else if (lineStyle == LineStyle.MEDIUM_DASH_DOT) {
// GEMPAK appears to have a bug where line type 9 draws as 'long
// dash 2 dots'
// This line type will draw a MEDIUM DASH DOT
// gl.glLineStipple(2, (short) 0xFF24 ); // long dash 2 dots as
// drawn by GEMPAK
// gl.glLineStipple(2, (short) 0xFF18);
gl.glLineStipple(2, (short) 0xFF88);
}
} else { } else {
gl.glDisable(GL.GL_LINE_STIPPLE); gl.glDisable(GL.GL_LINE_STIPPLE);
} }
@ -1188,6 +1151,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* *
* @see com.raytheon.viz.IGraphicsTarget#init() * @see com.raytheon.viz.IGraphicsTarget#init()
*/ */
@Override
public void init() { public void init() {
makeContextCurrent(); makeContextCurrent();
GLU glu = new GLU(); GLU glu = new GLU();
@ -1322,6 +1286,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* *
* @see com.raytheon.viz.core.gl.IGLTarget#makeContextCurrent() * @see com.raytheon.viz.core.gl.IGLTarget#makeContextCurrent()
*/ */
@Override
public boolean makeContextCurrent() { public boolean makeContextCurrent() {
return theContext.makeContextCurrent(); return theContext.makeContextCurrent();
} }
@ -1332,6 +1297,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* Do not call outside of gl package * Do not call outside of gl package
* *
*/ */
@Override
public void releaseContext() { public void releaseContext() {
theContext.releaseContext(); theContext.releaseContext();
} }
@ -1475,6 +1441,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* *
* @see com.raytheon.uf.viz.core.IGraphicsTarget#getModelView() * @see com.raytheon.uf.viz.core.IGraphicsTarget#getModelView()
*/ */
@Override
public double[] getModelView() { public double[] getModelView() {
double[] modelMatrix = new double[16]; double[] modelMatrix = new double[16];
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelMatrix, 0); gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelMatrix, 0);
@ -1486,6 +1453,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* *
* @see com.raytheon.uf.viz.core.IGraphicsTarget#getModelView() * @see com.raytheon.uf.viz.core.IGraphicsTarget#getModelView()
*/ */
@Override
public double[] getProjection() { public double[] getProjection() {
double[] projection = new double[16]; double[] projection = new double[16];
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection, 0); gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection, 0);
@ -1497,6 +1465,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* *
* @see com.raytheon.uf.viz.core.IGraphicsTarget#getViewPort() * @see com.raytheon.uf.viz.core.IGraphicsTarget#getViewPort()
*/ */
@Override
public int[] getViewPort() { public int[] getViewPort() {
int[] vp = new int[4]; int[] vp = new int[4];
gl.glGetIntegerv(GL.GL_VIEWPORT, vp, 0); gl.glGetIntegerv(GL.GL_VIEWPORT, vp, 0);
@ -1509,6 +1478,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* @param p * @param p
* @return * @return
*/ */
@Override
public double[] project(double[] p) { public double[] project(double[] p) {
double[] window = new double[3]; double[] window = new double[3];
if (!this.glu.gluProject(p[0], p[1], p[2], getModelView(), 0, if (!this.glu.gluProject(p[0], p[1], p[2], getModelView(), 0,
@ -1529,6 +1499,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* screen coordinate * screen coordinate
* @return pixel value * @return pixel value
*/ */
@Override
public double[] unproject(double[] pos) { public double[] unproject(double[] pos) {
return this.unproject(pos[0], pos[1], pos[2]); return this.unproject(pos[0], pos[1], pos[2]);
} }
@ -1569,6 +1540,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
* *
* @see com.raytheon.viz.core.gl.IDisplayPane#getBounds() * @see com.raytheon.viz.core.gl.IDisplayPane#getBounds()
*/ */
@Override
public Rectangle getBounds() { public Rectangle getBounds() {
if (theCanvas != null && theCanvas.isDisposed()) { if (theCanvas != null && theCanvas.isDisposed()) {
return null; return null;
@ -1617,7 +1589,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
*/ */
@Override @Override
public void setView(IView view) { public void setView(IView view) {
this.targetView = (IView) view.clone(); this.targetView = view.clone();
this.targetView.setupView(this); this.targetView.setupView(this);
} }

View file

@ -162,27 +162,27 @@ public class ChangeLineStyleAction extends AbstractRightClickAction implements
super(style.toString()); super(style.toString());
this.style = style; this.style = style;
int[] dashes = null; int[] dashes = style.getSWTLineStyle();
switch (style) { // switch (style) {
case DASHED: // case DASHED:
dashes = new int[] { 4, 4 }; // dashes = new int[] { 4, 4 };
break; // break;
case DASHED_LARGE: // case DASHED_LARGE:
dashes = new int[] { 12, 4 }; // dashes = new int[] { 12, 4 };
break; // break;
case DOTTED: // case DOTTED:
dashes = new int[] { 1, 1 }; // dashes = new int[] { 1, 1 };
break; // break;
case DASH_DOTTED: // case DASH_DOTTED:
dashes = new int[] { 3, 2, 1, 2 }; // dashes = new int[] { 3, 2, 1, 2 };
; // ;
break; // break;
case DEFAULT: // case DEFAULT:
case SOLID: // case SOLID:
default: // default:
dashes = null; // dashes = null;
break; // break;
} // }
boolean selected = style == getTopMostSelectedResource() boolean selected = style == getTopMostSelectedResource()
.getCapability(OutlineCapability.class).getLineStyle(); .getCapability(OutlineCapability.class).getLineStyle();