From: <ha...@us...> - 2006-09-11 02:46:35
|
Revision: 5481 http://svn.sourceforge.net/jmol/?rev=5481&view=rev Author: hansonr Date: 2006-09-10 19:46:22 -0700 (Sun, 10 Sep 2006) Log Message: ----------- 10.9.56 broad, unlimited echo capability Modified Paths: -------------- branches/v10_9/Jmol/src/org/jmol/viewer/Echo.java branches/v10_9/Jmol/src/org/jmol/viewer/EchoRenderer.java branches/v10_9/Jmol/src/org/jmol/viewer/Eval.java branches/v10_9/Jmol/src/org/jmol/viewer/JmolConstants.java Modified: branches/v10_9/Jmol/src/org/jmol/viewer/Echo.java =================================================================== --- branches/v10_9/Jmol/src/org/jmol/viewer/Echo.java 2006-09-10 19:49:12 UTC (rev 5480) +++ branches/v10_9/Jmol/src/org/jmol/viewer/Echo.java 2006-09-11 02:46:22 UTC (rev 5481) @@ -30,9 +30,21 @@ import java.awt.FontMetrics; import java.util.BitSet; +import java.util.Hashtable; class Echo extends Shape { + + /* + * set echo TOP [LEFT|CENTER|RIGHT] + * set echo MIDDLE [LEFT|CENTER|RIGHT] + * set echo BOTTOM [LEFT|CENTER|RIGHT] + * set echo name [LEFT|CENTER|RIGHT] + * set echo name x-position y-position + * + */ + + private final static int XY = 0; private final static int LEFT = 1; private final static int CENTER = 2; private final static int RIGHT = 3; @@ -45,20 +57,17 @@ private final static int FONTSIZE = 20; private final static short COLOR = Graphics3D.RED; - Text topText; - Text middleText; - Text bottomText; + Hashtable texts = new Hashtable(); Text currentText; - Text movableText; void initShape() { + setProperty("target", "top", null); } - void setProperty(String propertyName, Object value, - BitSet bsSelected) { - + void setProperty(String propertyName, Object value, BitSet bsSelected) { + Logger.debug("Echo.setProperty(" + propertyName + "," + value + ")"); - + if ("color" == propertyName) { if (currentText != null) currentText.colix = Graphics3D.getColix(value); @@ -71,103 +80,103 @@ if ("bgcolor" == propertyName) { if (currentText != null) - currentText.bgcolix = value == null ? (short)0 : Graphics3D.getColix(value); + currentText.bgcolix = value == null ? (short) 0 : Graphics3D + .getColix(value); return; } if ("font" == propertyName) { if (currentText != null) { - currentText.font3d = (Font3D)value; + currentText.font3d = (Font3D) value; currentText.recalc(); } return; } - + if ("echo" == propertyName) { if (currentText != null) { - currentText.text = (String)value; + currentText.text = (String) value; currentText.recalc(); } } + if ("allOff" == propertyName) { + currentText = null; + texts = new Hashtable(); + return; + } + if ("off" == propertyName) { + if (currentText == null) + return; + texts.remove(currentText.target); currentText = null; - if (topText != null) topText.text = null; - if (middleText != null) middleText.text = null; - if (bottomText != null) bottomText.text = null; + return; } - - if ("target" == propertyName) { - if (value instanceof Integer) { - if (movableText == null) - movableText = new Text(0, 0, - g3d.getFont3D(FONTFACE, FONTSIZE), COLOR); - currentText = movableText; - currentText.movableX = ((Integer)value).intValue(); + + if ("xpos" == propertyName) { + if (currentText == null) return; - } - String target = ((String)value).intern(); - if ("movable" == target) { - if (movableText == null) - movableText = new Text(TOP, CENTER, - g3d.getFont3D(FONTFACE, FONTSIZE), COLOR); - currentText = movableText; - return; - } - if ("top" == target) { - if (topText == null) - topText = new Text(TOP, CENTER, - g3d.getFont3D(FONTFACE, FONTSIZE), COLOR); - currentText = topText; + currentText.valign = XY; + currentText.movableX = ((Integer) value).intValue(); + return; + } + + if ("ypos" == propertyName) { + if (currentText == null) return; - } - - if ("middle" == target) { - if (middleText == null) - middleText = new Text(MIDDLE, CENTER, - g3d.getFont3D(FONTFACE, FONTSIZE), COLOR); - currentText = middleText; - return; - } - - if ("bottom" == target) { - if (bottomText == null) - bottomText = new Text(BOTTOM, LEFT, - g3d.getFont3D(FONTFACE, FONTSIZE), COLOR); - currentText = bottomText; - return; - } + currentText.valign = XY; + currentText.movableY = ((Integer) value).intValue(); + return; + } + if ("target" == propertyName) { + String target = ((String) value).intern().toLowerCase(); + Text t = (Text) texts.get(target); if ("none" == target) { - currentText = null; + currentText = null; return; } - Logger.error("unrecognized target:" + target); + if (t == null) { + int valign = XY; + int halign = LEFT; + int textalign = LEFT; + if ("top" == target) { + valign = TOP; + halign = textalign = CENTER; + } else if ("middle" == target) { + valign = MIDDLE; + halign = textalign = CENTER; + } else if ("bottom" == target) { + valign = BOTTOM; + } + t = new Text(valign, halign, textalign, + g3d.getFont3D(FONTFACE, FONTSIZE), COLOR); + t.target = target; + texts.put(target, t); + } + currentText = t; return; } if ("align" == propertyName) { if (currentText == null) return; - if (value instanceof Integer) { - currentText.valign = (((Integer)value).intValue()) << 2; - return; - } - String align = ((String)value).intern(); + String align = ((String) value).intern(); if ("left" == align) { - currentText.align = LEFT; + currentText.align = LEFT; return; } - + if ("center" == align) { - currentText.align = CENTER; - currentText.recalc(); + currentText.align = CENTER; + currentText.recalc(); return; } - + if ("right" == align) { - currentText.align = RIGHT; - currentText.recalc(); + currentText.align = RIGHT; + currentText.recalc(); return; } Logger.error("unrecognized align:" + align); @@ -176,11 +185,13 @@ } class Text { + String target; String text; String[] lines; int align; int valign; - int movableX = Integer.MAX_VALUE; + int movableX; + int movableY; Font3D font3d; short colix; short bgcolix; @@ -190,7 +201,7 @@ int ascent; int descent; - Text(int valign, int align, Font3D font3d, short colix) { + Text(int valign, int align, int textAlign, Font3D font3d, short colix) { this.align = align; this.valign = valign; this.font3d = font3d; @@ -198,7 +209,7 @@ } void recalc() { - if (text == null || text.length() == 0) { + if (text == null) { text = null; lines = null; widths = null; @@ -225,13 +236,18 @@ if (text == null) return; - int width = g3d.getRenderWidth(); - int xLeft = (movableX < Integer.MAX_VALUE ? movableX : 5); - int xCenter = (movableX < Integer.MAX_VALUE ? movableX + 1 : width / 2); - int xRight = (movableX < Integer.MAX_VALUE ? movableX : width - 5); + int xLeft, xCenter, xRight; + if (valign == XY) { + xLeft = xRight = xCenter = movableX; + } else { + int width = g3d.getRenderWidth(); + xLeft = 5; + xCenter = width / 2; + xRight = width - 5; + } int y = ascent; - switch (valign % 4) { + switch (valign) { case TOP: break; case MIDDLE: @@ -241,7 +257,7 @@ y = g3d.getRenderHeight() - descent - 1; break; default: - y += (valign >> 2); + y += movableY; } int offset = ascent + descent; Modified: branches/v10_9/Jmol/src/org/jmol/viewer/EchoRenderer.java =================================================================== --- branches/v10_9/Jmol/src/org/jmol/viewer/EchoRenderer.java 2006-09-10 19:49:12 UTC (rev 5480) +++ branches/v10_9/Jmol/src/org/jmol/viewer/EchoRenderer.java 2006-09-11 02:46:22 UTC (rev 5481) @@ -23,18 +23,15 @@ */ package org.jmol.viewer; +import java.util.Enumeration; + class EchoRenderer extends ShapeRenderer { void render() { Echo echo = (Echo)shape; - if (echo.topText != null) - echo.topText.render(g3d); - if (echo.middleText != null) - echo.middleText.render(g3d); - if (echo.bottomText != null) - echo.bottomText.render(g3d); - if (echo.movableText != null) - echo.movableText.render(g3d); + Enumeration e = echo.texts.elements(); + while (e.hasMoreElements()) + ((Echo.Text)e.nextElement()).render(g3d); } } Modified: branches/v10_9/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- branches/v10_9/Jmol/src/org/jmol/viewer/Eval.java 2006-09-10 19:49:12 UTC (rev 5480) +++ branches/v10_9/Jmol/src/org/jmol/viewer/Eval.java 2006-09-11 02:46:22 UTC (rev 5481) @@ -1190,11 +1190,11 @@ } int floatParameterSet(int i, float[] fparams) throws ScriptException { - if (i < statement.length && statement[i].tok == Token.leftbrace) + if (i < statementLength && statement[i].tok == Token.leftbrace) i++; for (int j = 0; j < fparams.length; j++) fparams[j] = floatParameter(i++); - if (i < statement.length && statement[i].tok != Token.rightbrace) + if (i < statementLength && statement[i].tok != Token.rightbrace) i++; return i; } @@ -1405,7 +1405,7 @@ if (statement[i++].tok != Token.leftbrace) coordinateExpected(); Point3f pt = new Point3f(); - for (int j = i; j + 1 < statement.length; j++) { + for (int j = i; j + 1 < statementLength; j++) { switch (statement[j].tok) { case Token.slash: coordinatesAreFractional = true; @@ -1430,7 +1430,7 @@ if (statement[i++].tok != Token.leftbrace) coordinateExpected(); Point4f pt = new Point4f(); - for (int j = i; j + 1 < statement.length; j++) { + for (int j = i; j + 1 < statementLength; j++) { switch (statement[j].tok) { case Token.slash: coordinatesAreFractional = true; @@ -1465,7 +1465,7 @@ } Token getToken(int i) throws ScriptException { - if (i >= statement.length) + if (i >= statementLength) endOfStatementUnexpected(); return statement[i]; } @@ -1967,7 +1967,9 @@ boolean echoShapeActive = false; - void echo() { + void echo() throws ScriptException { + if(viewer.getFrame() == null) + evalError("ECHO must follow, not precede, model loading"); String text = ""; if (statementLength == 2 && statement[1].tok == Token.string) text = (String) statement[1].value; @@ -2031,7 +2033,7 @@ filename = viewer.getFullPathName(); if (statement[i].tok == Token.integer) params[0] = statement[i++].intValue; - if (i < statement.length && statement[i].tok == Token.leftbrace) { + if (i < statementLength && statement[i].tok == Token.leftbrace) { unitCells = getCoordinate(i, false); params[1] = (int) unitCells.x; params[2] = (int) unitCells.y; @@ -2039,7 +2041,7 @@ i = pcLastExpressionInstruction + 1; int iGroup = -1; int[] p; - if (i < statement.length && statement[i].tok == Token.spacegroup) { + if (i < statementLength && statement[i].tok == Token.spacegroup) { ++i; String spacegroup = viewer.simpleReplace(stringParameter(i++), "''", "\""); @@ -2056,7 +2058,7 @@ p[4] = iGroup; params = p; } - if (i < statement.length && statement[i].tok == Token.unitcell) { + if (i < statementLength && statement[i].tok == Token.unitcell) { ++i; p = new int[11]; for (int j = 0; j < params.length; j++) @@ -2317,7 +2319,7 @@ * */ - if (statement.length == 2) + if (statementLength == 2) switch (statement[1].tok) { case Token.on: viewer.setSpinOn(true); @@ -3357,7 +3359,7 @@ break; } if (str.equalsIgnoreCase("defaultLattice")) { - if (statement.length < 3) + if (statementLength < 3) badArgumentCount(); Point3f pt; if (statement[2].tok == Token.integer) { @@ -3417,12 +3419,12 @@ } void setAxes(int cmdPt) throws ScriptException { - if (statement.length == 1) { + if (statementLength == 1) { viewer.setShapeSize(JmolConstants.SHAPE_AXES, 1); return; } // set axes scale x.xxx - if (statement.length == cmdPt + 2 + if (statementLength == cmdPt + 2 && statement[cmdPt].tok == Token.identifier && ((String) statement[cmdPt].value).equalsIgnoreCase("scale")) { viewer.setShapeProperty(JmolConstants.SHAPE_AXES, "scale", new Float( @@ -3437,7 +3439,7 @@ } void setUnitcell(int cmdPt) throws ScriptException { - if (statement.length == cmdPt + 1) { + if (statementLength == cmdPt + 1) { if (statement[cmdPt].tok == Token.integer && statement[cmdPt].intValue >= 111) viewer.setShapeProperty(JmolConstants.SHAPE_UCCAGE, "offset", @@ -3501,45 +3503,62 @@ } void setEcho() throws ScriptException { + if(viewer.getFrame() == null) + evalError("SET ECHO must follow, not precede, model loading"); String propertyName = "target"; Object propertyValue = null; - checkLength34(); echoShapeActive = true; + if (statementLength < 3) + badArgumentCount(); + //set echo xxx switch (statement[2].tok) { case Token.off: + checkLength3(); echoShapeActive = false; - propertyName = "off"; + propertyName = "allOff"; break; case Token.none: + checkLength3(); echoShapeActive = false; case Token.identifier: propertyValue = statement[2].value; break; - case Token.integer: - propertyValue = new Integer(statement[2].intValue); - break; default: keywordExpected(); } viewer.loadShape(JmolConstants.SHAPE_ECHO); viewer.setShapeProperty(JmolConstants.SHAPE_ECHO, propertyName, propertyValue); + propertyName = "align"; + if (statementLength == 3) + return; + // set echo name xxx if (statementLength == 4) { switch (statement[3].tok) { + case Token.off: + propertyName = "off"; + break; case Token.identifier: case Token.center: propertyValue = statement[3].value; break; - case Token.integer: - propertyValue = new Integer(statement[3].intValue); - break; default: keywordExpected(); } - viewer.setShapeProperty(JmolConstants.SHAPE_ECHO, "align", + viewer.setShapeProperty(JmolConstants.SHAPE_ECHO, propertyName, propertyValue); + return; } - } + //set echo name x-pos y-pos + if (statementLength != 5) + badArgumentCount(); + propertyValue = new Integer(intParameter(3)); + viewer.setShapeProperty(JmolConstants.SHAPE_ECHO, "xpos", + propertyValue); + propertyValue = new Integer(intParameter(4)); + viewer.setShapeProperty(JmolConstants.SHAPE_ECHO, "ypos", + propertyValue); + } void setFontsize() throws ScriptException { int rasmolSize = 8; @@ -3923,7 +3942,7 @@ evalError("no MO basis/coefficient data available for this frame"); viewer.setShapeProperty(JmolConstants.SHAPE_MO, "moData", moData); showString((String) viewer.getShapeProperty(JmolConstants.SHAPE_MO, - "showMO", statement.length > 2 ? intParameter(2) : Integer.MAX_VALUE)); + "showMO", statementLength > 2 ? intParameter(2) : Integer.MAX_VALUE)); return; case Token.model: showString(viewer.getModelInfoAsString()); @@ -4159,7 +4178,7 @@ havePoints = true; break; case Token.color: - if (++i < statement.length && statement[i].tok == Token.colorRGB) { + if (++i < statementLength && statement[i].tok == Token.colorRGB) { viewer.setShapeProperty(JmolConstants.SHAPE_DRAW, "colorRGB", new Integer(getArgbParam(i))); continue; @@ -4311,11 +4330,11 @@ propertyValue = new Float(floatParameter(++i)); break; case Token.color: - if (++i < statement.length && statement[i].tok == Token.colorRGB) { + if (++i < statementLength && statement[i].tok == Token.colorRGB) { viewer.setShapeProperty(JmolConstants.SHAPE_LCAOCARTOON, "colorRGB", new Integer(getArgbParam(i))); viewer.setShapeProperty(JmolConstants.SHAPE_LCAOCARTOON, "colorRGB", - new Integer(getArgbParam(i + 1 < statement.length + new Integer(getArgbParam(i + 1 < statementLength && statement[i + 1].tok == Token.colorRGB ? ++i : i))); continue; } @@ -4387,10 +4406,10 @@ break; case Token.color: //mo color color1 color2 - if (2 < statement.length && statement[2].tok == Token.colorRGB) { + if (2 < statementLength && statement[2].tok == Token.colorRGB) { viewer.setShapeProperty(JmolConstants.SHAPE_MO, "colorRGB", new Integer(getArgbParam(2))); - if (3 < statement.length && statement[3].tok == Token.colorRGB) + if (3 < statementLength && statement[3].tok == Token.colorRGB) viewer.setShapeProperty(JmolConstants.SHAPE_MO, "colorRGB", new Integer(getArgbParam(3))); break; @@ -4399,7 +4418,7 @@ case Token.identifier: str = (String) token.value; if (str.equalsIgnoreCase("CUTOFF")) { - if (2 < statement.length && statement[2].tok == Token.plus) { + if (2 < statementLength && statement[2].tok == Token.plus) { propertyName = "cutoffPositive"; propertyValue = new Float(floatParameter(3)); } else { @@ -4419,7 +4438,7 @@ break; } if (str.equalsIgnoreCase("TITLEFORMAT")) { - if (2 < statement.length && statement[2].tok == Token.string) { + if (2 < statementLength && statement[2].tok == Token.string) { propertyName = "titleFormat"; propertyValue = stringParameter(2); } @@ -4451,7 +4470,7 @@ viewer.setShapeProperty(JmolConstants.SHAPE_MO, propertyName, propertyValue); if (moNumber != Integer.MAX_VALUE) { - if (2 < statement.length && statement[2].tok == Token.string) + if (2 < statementLength && statement[2].tok == Token.string) title = stringParameter(2); setMoData(JmolConstants.SHAPE_MO, moNumber, title); } @@ -4531,7 +4550,7 @@ * because the term COLOR is too general. * */ - if (i + 1 == statement.length) + if (i + 1 == statementLength) invalidArgument(i, " COLOR keyword not in context"); colorRangeStage = 0; switch (statement[i + 1].tok) { @@ -4573,7 +4592,7 @@ break; } if (str.equalsIgnoreCase("CUTOFF")) { - if (++i < statement.length && statement[i].tok == Token.plus) { + if (++i < statementLength && statement[i].tok == Token.plus) { propertyName = "cutoffPositive"; propertyValue = new Float(floatParameter(++i)); } else { @@ -4656,13 +4675,13 @@ } if (str.equalsIgnoreCase("CONTOUR")) { propertyName = "contour"; - propertyValue = new Integer(i + 1 < statement.length + propertyValue = new Integer(i + 1 < statementLength && statement[i + 1].tok == Token.integer ? intParameter(++i) : 0); break; } if (str.equalsIgnoreCase("PHASE")) { propertyName = "phase"; - propertyValue = (i + 1 < statement.length + propertyValue = (i + 1 < statementLength && statement[i + 1].tok == Token.string ? stringParameter(++i) : "_orb"); break; @@ -4718,7 +4737,7 @@ if (str.equalsIgnoreCase("functionXY")) { surfaceObjectSeen = true; Vector v = new Vector(); - if (++i == statement.length) + if (++i == statementLength) badArgumentCount(); if (statement[i].tok != Token.string) invalidArgument(i, "function name in quotation marks expected"); @@ -4760,7 +4779,7 @@ break; case Token.mo: //mo 1-based-index - if (++i == statement.length) + if (++i == statementLength) badArgumentCount(); int moNumber = intParameter(i); setMoData(JmolConstants.SHAPE_ISOSURFACE, moNumber, null); @@ -4779,7 +4798,7 @@ String filename = (String) token.value; if (filename.length() == 0) filename = viewer.getFullPathName(); - if (i + 1 < statement.length && statement[i + 1].tok == Token.integer) + if (i + 1 < statementLength && statement[i + 1].tok == Token.integer) viewer.setShapeProperty(JmolConstants.SHAPE_ISOSURFACE, "fileIndex", new Integer(intParameter(++i))); Object t = viewer Modified: branches/v10_9/Jmol/src/org/jmol/viewer/JmolConstants.java =================================================================== --- branches/v10_9/Jmol/src/org/jmol/viewer/JmolConstants.java 2006-09-10 19:49:12 UTC (rev 5480) +++ branches/v10_9/Jmol/src/org/jmol/viewer/JmolConstants.java 2006-09-11 02:46:22 UTC (rev 5481) @@ -41,7 +41,7 @@ // for now, just update this by hand // perhaps use ant filter later ... but mth doesn't like it :-( public final static String copyright = "(C) 2006 Jmol Development"; - public final static String version = "10.9.55 (branch 10_9)"; + public final static String version = "10.9.56 (branch 10_9)"; public final static String cvsDate = "$Date$"; public final static String date = cvsDate.substring(7, 23); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |