From: Miguel <mig...@us...> - 2004-10-22 16:18:37
|
Update of /cvsroot/jmol/Jmol/src/org/jmol/viewer/managers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18819/viewer/managers Added Files: ColorManager.java FileManager.java ModelManager.java MouseManager.java MouseManager10.java MouseManager11.java MouseManager14.java MouseWrapper11.java MouseWrapper14.java RepaintManager.java SelectionManager.java StyleManager.java TempManager.java TransformManager.java Log Message: moved viewer out of org/opensource --- NEW FILE: ColorManager.java --- /* $RCSfile: ColorManager.java,v $ * $Author: migueljmol $ * $Date: 2004/10/22 16:18:25 $ * $Revision: 1.1 $ * * Copyright (C) 2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.jmol.viewer.managers; import org.jmol.g3d.*; import org.jmol.viewer.*; import org.jmol.viewer.datamodel.Atom; import org.jmol.viewer.datamodel.Frame; import org.jmol.viewer.script.Token; import java.awt.Color; import java.util.Hashtable; import javax.vecmath.Vector3f; import javax.vecmath.Point3f; public class ColorManager { JmolViewer viewer; Graphics3D g3d; int[] argbsCpk; public byte paletteDefault = JmolConstants.PALETTE_NONE_CPK; public ColorManager(JmolViewer viewer, Graphics3D g3d) { this.viewer = viewer; this.g3d = g3d; argbsCpk = JmolConstants.argbsCpk; } public void setColorScheme(String colorScheme) { System.out.println("setting color scheme to:" + colorScheme); if (colorScheme.equals("jmol")) { argbsCpk = JmolConstants.argbsCpk; viewer.setColorBackground(Color.black); viewer.setColorMeasurement(Color.white); viewer.setColorLabel(Color.white); viewer.setShapeColorProperty(JmolConstants.SHAPE_DOTS, null); } else if (colorScheme.equals("rasmol")) { int argb = JmolConstants.argbsCpkRasmol[0] | 0xFF000000; argbsCpk = new int[JmolConstants.argbsCpk.length]; for (int i = JmolConstants.argbsCpk.length; --i >= 0; ) argbsCpk[i] = argb; for (int i = JmolConstants.argbsCpkRasmol.length; --i >= 0; ) { argb = JmolConstants.argbsCpkRasmol[i]; int atomNo = argb >> 24; argb |= 0xFF000000; argbsCpk[atomNo] = argb; g3d.changeColixArgb((short)atomNo, argb); } viewer.setColorBackground(Color.black); viewer.setColorMeasurement(Color.white); viewer.setColorLabel(null); viewer.setShapeColorProperty(JmolConstants.SHAPE_DOTS, null); } else { System.out.println("unrecognized color scheme"); return; } for (int i = JmolConstants.argbsCpk.length; --i >= 0; ) g3d.changeColixArgb((short)i, argbsCpk[i]); } public void setPaletteDefault(byte palette) { paletteDefault = palette; } public byte getPaletteDefault() { return paletteDefault; } public Color colorSelection = Color.orange; public short colixSelection = Graphics3D.ORANGE; public void setColorSelection(Color c) { colorSelection = c; colixSelection = g3d.getColix(c); } public Color getColorSelection() { return colorSelection; } public short getColixSelection() { return colixSelection; } public Color colorRubberband = Color.pink; public short colixRubberband = Graphics3D.PINK; public Color getColorRubberband() { return colorRubberband; } public short getColixRubberband() { return colixRubberband; } public void setColorRubberband(Color color) { if (color == null) color = Color.pink; colorRubberband = color; colixRubberband = g3d.getColix(color); } public boolean isBondAtomColor = true; public void setIsBondAtomColor(boolean isBondAtomColor) { this.isBondAtomColor = isBondAtomColor; } public Color colorBond = null; public short colixBond = 0; public void setColorBond(Color c) { colorBond = c; colixBond = g3d.getColix(c); } public Color colorHbond = null; public short colixHbond = 0; public void setColorHbond(Color c) { colorHbond = c; colixHbond = g3d.getColix(c); } public Color colorSsbond = null; public short colixSsbond = 0; public void setColorSsbond(Color c) { colorSsbond = c; colixSsbond = g3d.getColix(c); } public Color colorLabel = Color.black; public short colixLabel = Graphics3D.BLACK; public void setColorLabel(Color color) { colorLabel = color; colixLabel = g3d.getColix(color); } public short colixDotsConvex = 0; public short colixDotsConcave = 0; public short colixDotsSaddle = 0; public void setColorDotsConvex(Color color) { colixDotsConvex = g3d.getColix(color); } public void setColorDotsConcave(Color color) { colixDotsConcave = g3d.getColix(color); } public void setColorDotsSaddle(Color color) { colixDotsSaddle = g3d.getColix(color); } public Color colorDistance = Color.white; public short colixDistance = Graphics3D.WHITE; public void setColorDistance(Color c) { colorDistance = c; colixDistance = g3d.getColix(c); } public Color colorAngle = Color.white; public short colixAngle = Graphics3D.WHITE; public void setColorAngle(Color c) { colorAngle = c; colixAngle = g3d.getColix(c); } public Color colorTorsion = Color.white; public short colixTorsion = Graphics3D.WHITE; public void setColorTorsion(Color c) { colorTorsion = c; colixTorsion = g3d.getColix(c); } public void setColorMeasurement(Color c) { colorDistance = colorAngle = colorTorsion = c; colixDistance = colixAngle = colixTorsion = g3d.getColix(c); } public Color colorBackground = Color.white; public short colixBackground = Graphics3D.WHITE; public void setColorBackground(Color bg) { if (bg == null) colorBackground = Color.getColor("colorBackground"); else colorBackground = bg; colixBackground = g3d.getColix(colorBackground); g3d.setBackground(colixBackground); } public Color colorAxes = new Color(128, 128, 0); public short colixAxes = Graphics3D.OLIVE; public void setColorAxes(Color color) { colorAxes = color; colixAxes = g3d.getColix(color); } public Color colorAxesText = colorAxes; public short colixAxesText = Graphics3D.OLIVE; public void setColorAxesText(Color color) { colorAxesText = color; colixAxesText = g3d.getColix(color); } // FIXME NEEDSWORK -- arrow vector stuff public Color colorVector = Color.black; public short colixVector = Graphics3D.BLACK; public void setColorVector(Color c) { colorVector = c; colixVector = g3d.getColix(c); } public Color getColorVector() { return colorVector; } public void setColorBackground(String colorName) { if (colorName != null && colorName.length() > 0) setColorBackground(viewer.getColorFromString(colorName)); } public short getColixAtom(Atom atom) { return getColixAtomPalette(atom, paletteDefault); } public short getColixAtomPalette(Atom atom, byte palette) { int argb = 0; int index; switch (palette) { case JmolConstants.PALETTE_NONE_CPK: // Note that CPK colors can be changed based upon user preference // therefore, a changable colix is allocated in this case short id = atom.elementNumber; return g3d.getChangableColix(id, argbsCpk[id]); case JmolConstants.PALETTE_PARTIALCHARGE: /* This code assumes that the range of partial charges is [-1, 1]. It also explicitly constructs colors red (negative) and blue (positive) Using colors other than these would make the shading calculations more difficult */ index = quantize(-1, 1, atom.getPartialCharge(), JmolConstants.argbsRwbScale.length); argb = JmolConstants.argbsRwbScale[index]; break; case JmolConstants.PALETTE_TEMPERATURE: case JmolConstants.PALETTE_FIXEDTEMP: float lo,hi; if (palette == JmolConstants.PALETTE_TEMPERATURE) { Frame frame = viewer.getFrame(); lo = frame.getBfactor100Lo(); hi = frame.getBfactor100Hi(); } else { lo = 0; hi = 100 * 100; // scaled by 100 } index = quantize(lo, hi, atom.getBfactor100(), JmolConstants.argbsRwbScale.length); index = JmolConstants.argbsRwbScale.length - 1 - index; argb = JmolConstants.argbsRwbScale[index]; break; case JmolConstants.PALETTE_FORMALCHARGE: index = atom.getFormalCharge() - JmolConstants.FORMAL_CHARGE_MIN; argb = JmolConstants.argbsCharge[index]; break; case JmolConstants.PALETTE_STRUCTURE: argb = JmolConstants.argbsStructure[atom.getProteinStructureType()]; break; case JmolConstants.PALETTE_AMINO: index = atom.getGroupID(); if (index >= JmolConstants.GROUPID_AMINO_MAX) index = 0; argb = JmolConstants.argbsAmino[index]; break; case JmolConstants.PALETTE_SHAPELY: index = atom.getGroupID(); if (index >= JmolConstants.GROUPID_SHAPELY_MAX) index = 0; argb = JmolConstants.argbsShapely[index]; break; case JmolConstants.PALETTE_CHAIN: int chain = atom.getChainID() & 0x1F; if (chain >= JmolConstants.argbsChainAtom.length) chain = chain % JmolConstants.argbsChainAtom.length; argb = (atom.isHetero() ? JmolConstants.argbsChainHetero : JmolConstants.argbsChainAtom)[chain]; break; } if (argb == 0) return Graphics3D.HOTPINK; return g3d.getColix(argb); } int quantize(float lo, float hi, float val, int segmentCount) { float range = hi - lo; if (range <= 0 || Float.isNaN(val)) return segmentCount / 2; float t = val - lo; if (t <= 0) return 0; float quanta = range / segmentCount; int q = (int)(t / quanta + 0.5f); if (q >= segmentCount) q = segmentCount - 1; return q; } public short getColixHbondType(short order) { int argbIndex = ((order & JmolConstants.BOND_HYDROGEN_MASK) >> JmolConstants.BOND_HBOND_SHIFT); return g3d.getColix(JmolConstants.argbsHbondType[argbIndex]); } public void flushCachedColors() { } final Vector3f vAB = new Vector3f(); final Vector3f vAC = new Vector3f(); final Vector3f vNormal = new Vector3f(); final Vector3f vRotated = new Vector3f(); public int calcSurfaceIntensity(Point3f pA, Point3f pB, Point3f pC) { vAB.sub(pB, pA); vAC.sub(pC, pA); vNormal.cross(vAB, vAC); viewer.transformVector(vNormal, vRotated); int intensity = vRotated.z >= 0 ? calcIntensity(-vRotated.x, -vRotated.y, vRotated.z) : calcIntensity(vRotated.x, vRotated.y, -vRotated.z); if (intensity > Graphics3D.intensitySpecularSurfaceLimit) intensity = Graphics3D.intensitySpecularSurfaceLimit; return intensity; } private void flushCaches() { g3d.flushShadesAndImageCaches(); viewer.refresh(); } public void setSpecular(boolean specular) { g3d.setSpecular(specular); flushCaches(); } public boolean getSpecular() { return g3d.getSpecular(); } public void setSpecularPower(int specularPower) { g3d.setSpecularPower(specularPower); flushCaches(); } public void setAmbientPercent(int ambientPercent) { g3d.setAmbientPercent(ambientPercent); flushCaches(); } public void setDiffusePercent(int diffusePercent) { g3d.setDiffusePercent(diffusePercent); flushCaches(); } public void setSpecularPercent(int specularPercent) { g3d.setSpecularPercent(specularPercent); flushCaches(); } public void setLightsourceZ(float dist) { g3d.setLightsourceZ(dist); flushCaches(); } public int calcIntensity(float x, float y, float z) { return g3d.calcIntensity(x, y, z); } } --- NEW FILE: FileManager.java --- /* $RCSfile: FileManager.java,v $ * $Author: migueljmol $ * $Date: 2004/10/22 16:18:25 $ * $Revision: 1.1 $ * * Copyright (C) 2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.jmol.viewer.managers; import org.jmol.viewer.*; import org.jmol.api.JmolAdapter; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import java.net.MalformedURLException; import java.io.InputStream; import java.io.BufferedInputStream; import java.io.FilterInputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.FileNotFoundException; import java.io.StringReader; import java.io.Reader; import java.io.BufferedReader; import java.util.zip.GZIPInputStream; /**************************************************************** * will not work with applet import java.net.URI; import java.net.URISyntaxException; import java.util.Enumeration; import org.openscience.jmol.io.ChemFileReader; import org.openscience.jmol.io.ReaderFactory; import org.openscience.dadml.DATABASE; import org.openscience.dadml.DBDEF; import org.openscience.dadml.DBLIST; import org.openscience.dadml.FIELD; import org.openscience.dadml.INDEX; import org.openscience.dadml.filereaders.DBDEFFileReader; import org.openscience.dadml.filereaders.DBLISTFileReader; import org.openscience.dadml.tools.DBDEFInfo; */ public class FileManager { JmolViewer viewer; JmolAdapter modelAdapter; private String openErrorMessage; // for applet proxy URL appletDocumentBase = null; URL appletCodeBase = null; String appletProxy = null; // for expanding names into full path names private boolean isURL; private String nameAsGiven; private String fullPathName; private String fileName; private File file; private FileOpenThread fileOpenThread; public FileManager(JmolViewer viewer, JmolAdapter modelAdapter) { this.viewer = viewer; this.modelAdapter = modelAdapter; } public void openFile(String name) { System.out.println("FileManager.openFile(" + name + ")"); nameAsGiven = name; openErrorMessage = fullPathName = fileName = null; classifyName(name); if (openErrorMessage != null) { System.out.println("openErrorMessage=" + openErrorMessage); return; } fileOpenThread = new FileOpenThread(fullPathName, name); fileOpenThread.run(); } public void openStringInline(String strModel) { openErrorMessage = null; fullPathName = fileName = "string"; fileOpenThread = new FileOpenThread(fullPathName, new StringReader(strModel)); fileOpenThread.run(); } public void openReader(String fullPathName, String name, Reader reader) { openErrorMessage = null; fullPathName = fullPathName; fileName = name; fileOpenThread = new FileOpenThread(fullPathName, reader); fileOpenThread.run(); } public Object waitForClientFileOrErrorMessage() { Object clientFile = null; if (fileOpenThread != null) { clientFile = fileOpenThread.clientFile; if (fileOpenThread.errorMessage != null) openErrorMessage = fileOpenThread.errorMessage; else if (clientFile == null) openErrorMessage = "Client file is null loading:" + nameAsGiven; fileOpenThread = null; } if (openErrorMessage != null) return openErrorMessage; return clientFile; } public String getFullPathName() { return fullPathName != null ? fullPathName : nameAsGiven; } public String getFileName() { return fileName != null ? fileName : nameAsGiven; } public void setAppletContext(URL documentBase, URL codeBase, String jmolAppletProxy) { appletDocumentBase = documentBase; System.out.println("appletDocumentBase=" + documentBase); // dumpDocumentBase("" + documentBase); appletCodeBase = codeBase; appletProxy = jmolAppletProxy; } void dumpDocumentBase(String documentBase) { System.out.println("dumpDocumentBase:" + documentBase); Object inputStreamOrError = getInputStreamOrErrorMessageFromName(documentBase); if (inputStreamOrError == null) { System.out.println("?Que? ?null?"); } else if (inputStreamOrError instanceof String) { System.out.println("Error:" + inputStreamOrError); } else { BufferedReader br = new BufferedReader(new InputStreamReader((InputStream)inputStreamOrError)); String line; try { while ((line = br.readLine()) != null) System.out.println(line); br.close(); } catch (Exception ex) { System.out.println("exception caught:" + ex); } } } // mth jan 2003 -- there must be a better way for me to do this!? final String[] urlPrefixes = {"http:", "https:", "ftp:", "file:"}; private void classifyName(String name) { isURL = false; if (name == null) return; if (appletDocumentBase != null) { // This code is only for the applet isURL = true; try { URL url = new URL(appletDocumentBase, name); fullPathName = url.toString(); // we add one to lastIndexOf(), so don't worry about -1 return value fileName = fullPathName.substring(fullPathName.lastIndexOf('/') + 1, fullPathName.length()); } catch (MalformedURLException e) { openErrorMessage = e.getMessage(); } return; } // This code is for the app for (int i = 0; i < urlPrefixes.length; ++i) { if (name.startsWith(urlPrefixes[i])) { isURL = true; try { URL url = new URL(name); fullPathName = url.toString(); fileName = fullPathName.substring(fullPathName.lastIndexOf('/') + 1, fullPathName.length()); } catch (MalformedURLException e) { openErrorMessage = e.getMessage(); } return; } } /**************************************************************** * we need to comment this out because it will not work with applet if (name.startsWith("dadml:")) { isURL = true; try { URI uri = new URI(name); URL resolvedURL = resolveLink(uri); if (resolvedURL != null) { fullPathName = resolvedURL.toString(); fileName = fullPathName.substring(fullPathName.lastIndexOf('/') + 1, fullPathName.length()); } } catch (URISyntaxException e) { openErrorMessage = e.getMessage(); } System.out.println("dadml fullPathName=" + fullPathName); return; } ****************************************************************/ isURL = false; file = new File(name); fullPathName = file.getAbsolutePath(); fileName = file.getName(); } /* *************************************************************** public URL resolveLink(URI dadmlRI) { System.out.println("Resolving URI: " + dadmlRI); boolean found = false; // this is true when a structure is downloaded boolean done = false; // this is true when all URLS have been tested String indexType = dadmlRI.getPath().substring(1); String index = dadmlRI.getQuery(); DBLIST dblist = new DBLIST(); String superdb = "http://jmol.sf.net/super.xml"; try { System.out.println("Downloading DADML super database: " + superdb); // Proxy authorization has to be ported from Chemistry Development Kit (CDK) // for now, do without authorization DBLISTFileReader reader = new DBLISTFileReader(); dblist = reader.read(superdb); } catch (Exception supererror) { openErrorMessage = "Exception while reading super db: " + supererror.getMessage(); return null; } Enumeration dbases = dblist.databases(); while (!found && !done && dbases.hasMoreElements()) { DATABASE database = (DATABASE)dbases.nextElement(); String dburl = database.getURL() + database.getDefinition(); DBDEF dbdef = new DBDEF(); // Proxy authorization has to be ported from Chemistry Development Kit (CKD) // for now, do without authorization try { System.out.println("Downloading: " + dburl); // do without authorization DBDEFFileReader reader = new DBDEFFileReader(); dbdef = reader.read(dburl); } catch (Exception deferror) { openErrorMessage = deferror.getMessage(); return null; } if (DBDEFInfo.hasINDEX(dbdef, indexType)) { // oke, find a nice URL to use for download System.out.println("Trying: " + dbdef.getTITLE()); Enumeration fields = dbdef.fields(); while (fields.hasMoreElements()) { FIELD field = (FIELD)fields.nextElement(); String mime = field.getMIMETYPE(); String ftype = field.getTYPE(); if ((mime.equals("chemical/x-mdl-mol") || mime.equals("chemical/x-pdb") || mime.equals("chemical/x-cml")) && (ftype.equals("3DSTRUCTURE") || ftype.equals("2DSTRUCTURE"))) { System.out.println("Accepted: " + field.getMIMETYPE() + "," + field.getTYPE()); Enumeration indices = field.getINDEX(); while (indices.hasMoreElements()) { INDEX ind = (INDEX)indices.nextElement(); if (ind.getTYPE().equals(indexType)) { // here is the URL composed String url = dbdef.getURL() + ind.getACCESS_PREFIX() + index + ind.getACCESS_SUFFIX(); System.out.println("Will retrieve information from: " + url); try { return new URL(url); } catch (MalformedURLException exception) { System.out.println("Malformed URL: " + exception.getMessage()); } } } } else { // reject other mime types && type structures System.out.println("Rejected: " + field.getMIMETYPE() + "," + field.getTYPE()); } } } else { System.out.println("Database does not have indexType: " + indexType); } } openErrorMessage = "Database does not contain the requested compound"; return null; } ****************************************************************/ public Object getInputStreamOrErrorMessageFromName(String name) { String errorMessage = null; int iurlPrefix; for (iurlPrefix = urlPrefixes.length; --iurlPrefix >= 0; ) if (name.startsWith(urlPrefixes[iurlPrefix])) break; try { InputStream in; int length; if (appletDocumentBase == null) { if (iurlPrefix >= 0) { URL url = new URL(name); URLConnection conn = url.openConnection(); length = conn.getContentLength(); in = conn.getInputStream(); } else { File file = new File(name); length = (int)file.length(); in = new FileInputStream(file); } } else { if (iurlPrefix >= 0 && appletProxy != null) name = appletProxy + "?url=" + URLEncoder.encode(name, "utf-8"); URL url = new URL(appletDocumentBase, name); URLConnection conn = url.openConnection(); length = conn.getContentLength(); in = conn.getInputStream(); } return new MonitorInputStream(in, length); } catch (Exception e) { errorMessage = "" + e; } return errorMessage; } class FileOpenThread implements Runnable { boolean terminated; String errorMessage; String fullPathName; String nameAsGiven; Object clientFile; Reader reader; FileOpenThread(String fullPathName, String nameAsGiven) { this.fullPathName = fullPathName; this.nameAsGiven = nameAsGiven; } FileOpenThread(String name, Reader reader) { nameAsGiven = fullPathName = name; this.reader = reader; } public void run() { if (reader != null) { openReader(reader); } else { Object t = getInputStreamOrErrorMessageFromName(nameAsGiven); if (! (t instanceof InputStream)) { errorMessage = (t == null ? "error opening:" + nameAsGiven : (String)t); } else { openInputStream(fullPathName, fileName, (InputStream) t); } } if (errorMessage != null) System.out.println("error opening " + fullPathName + "\n" + errorMessage); terminated = true; } byte[] abMagic = new byte[4]; private void openInputStream(String fullPathName, String fileName, InputStream istream) { BufferedInputStream bistream = new BufferedInputStream(istream, 8192); InputStream istreamToRead = bistream; bistream.mark(5); int countRead = 0; try { countRead = bistream.read(abMagic, 0, 4); bistream.reset(); if (countRead == 4) { if (abMagic[0] == (byte)0x1F && abMagic[1] == (byte)0x8B) { istreamToRead = new GZIPInputStream(bistream); } } openReader(new InputStreamReader(istreamToRead)); } catch (IOException ioe) { errorMessage = ioe.getMessage(); } } private void openReader(Reader reader) { Object clientFile = modelAdapter.openBufferedReader(fullPathName, new BufferedReader(reader)); if (clientFile instanceof String) errorMessage = (String)clientFile; else this.clientFile = clientFile; } } } class MonitorInputStream extends FilterInputStream { int length; int position; int markPosition; int readEventCount; long timeBegin; MonitorInputStream(InputStream in, int length) { super(in); this.length = length; this.position = 0; timeBegin = System.currentTimeMillis(); } public int read() throws IOException{ ++readEventCount; int nextByte = super.read(); if (nextByte >= 0) ++position; return nextByte; } public int read(byte[] b) throws IOException { ++readEventCount; int cb = super.read(b); if (cb > 0) position += cb; return cb; } public int read(byte[] b, int off, int len) throws IOException { ++readEventCount; int cb = super.read(b, off, len); if (cb > 0) position += cb; /* System.out.println("" + getPercentageRead() + "% " + getPosition() + " of " + getLength() + " in " + getReadingTimeMillis()); */ return cb; } public long skip(long n) throws IOException { long cb = super.skip(n); // this will only work in relatively small files ... 2Gb position = (int)(position + cb); return cb; } public void mark(int readlimit) { super.mark(readlimit); markPosition = position; } public void reset() throws IOException { position = markPosition; super.reset(); } int getPosition() { return position; } int getLength() { return length; } int getPercentageRead() { return position * 100 / length; } int getReadingTimeMillis() { return (int)(System.currentTimeMillis() - timeBegin); } } --- NEW FILE: ModelManager.java --- /* $RCSfile: ModelManager.java,v $ * $Author: migueljmol $ * $Date: 2004/10/22 16:18:25 $ * $Revision: 1.1 $ * * Copyright (C) 2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.jmol.viewer.managers; import org.jmol.viewer.*; import org.jmol.api.JmolAdapter; import org.jmol.viewer.datamodel.Frame; import org.jmol.viewer.datamodel.FrameBuilder; import org.jmol.viewer.datamodel.Atom; import java.util.BitSet; import java.util.Hashtable; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; import java.awt.Rectangle; import java.awt.Color; public class ModelManager { final JmolViewer viewer; final JmolAdapter modelAdapter; final Frame nullFrame; final FrameBuilder frameBuilder; public ModelManager(JmolViewer viewer, JmolAdapter modelAdapter) { this.viewer = viewer; this.modelAdapter = modelAdapter; nullFrame = new Frame(viewer, "null"); frameBuilder = new FrameBuilder(viewer, modelAdapter); } public String fullPathName; public String fileName; public String modelSetName; public String modelFileHeader; // public int frameCount = 0; public boolean haveFile = false; // public int currentFrameNumber; public Frame frame; // public Frame[] frames; public void setClientFile(String fullPathName, String fileName, Object clientFile) { if (clientFile == null) { fullPathName = fileName = modelSetName = modelFileHeader = null; frame = null; haveFile = false; } else { this.fullPathName = fullPathName; this.fileName = fileName; modelSetName = modelAdapter.getAtomSetCollectionName(clientFile); if (modelSetName != null) { modelSetName = modelSetName.trim(); if (modelSetName.length() == 0) modelSetName = null; } modelFileHeader = modelAdapter.getFileHeader(clientFile); frame = frameBuilder.buildFrame(clientFile); haveFile = true; } } public String getClientAtomStringProperty(Object clientAtom, String propertyName) { return modelAdapter.getClientAtomStringProperty(clientAtom, propertyName); } public Frame getFrame() { return (frame == null) ? nullFrame : frame; } public JmolAdapter getExportJmolAdapter() { return (frame == null) ? null : frame.getExportJmolAdapter(); } public String getModelSetName() { return modelSetName; } public String getModelFileHeader() { return modelFileHeader; } public boolean hasVibrationVectors() { return frame.hasVibrationVectors(); } public float getRotationRadius() { return (frame == null) ? 1 : frame.getRotationRadius(); } public void increaseRotationRadius(float increaseInAngstroms) { if (frame != null) frame.increaseRotationRadius(increaseInAngstroms); } public Point3f getBoundingBoxCenter() { return (frame == null) ? null : frame.getBoundingBoxCenter(); } public Vector3f getBoundingBoxCornerVector() { return (frame == null) ? null : frame.getBoundingBoxCornerVector(); } public int getModelCount() { return (frame == null) ? 0 : frame.getModelCount(); } public int getModelIndex(String modelTag) { return (frame == null) ? -1 : frame.getModelIndex(modelTag); } public int getChainCount() { return (frame == null) ? 0 : frame.getChainCount(); } public int getGroupCount() { return (frame == null) ? 0 : frame.getGroupCount(); } public int getAtomCount() { return (frame == null) ? 0 : frame.getAtomCount(); } public int getBondCount() { return (frame == null) ? 0 : frame.getBondCount(); } private final Point3f pointT = new Point3f(); public void setCenterBitSet(BitSet bsCenter) { if (frame == null) return; Point3f center = null; if (bsCenter != null) { int countSelected = 0; center = pointT; center.set(0,0,0); for (int i = getAtomCount(); --i >= 0; ) { if (! bsCenter.get(i)) continue; ++countSelected; center.add(frame.getAtomPoint3f(i)); } if (countSelected > 0) center.scale(1.0f / countSelected); // just divide by the quantity else center = null; } frame.setRotationCenter(center); } public void setRotationCenter(Point3f center) { if (frame != null) frame.setRotationCenter(center); } public Point3f getRotationCenter() { return (frame == null ? null : frame.getRotationCenter()); } public boolean autoBond = true; public void rebond() { if (frame != null) frame.rebond(); } public void setAutoBond(boolean ab) { autoBond = ab; } // angstroms of slop ... from OpenBabel ... mth 2003 05 26 public float bondTolerance = 0.45f; public void setBondTolerance(float bondTolerance) { this.bondTolerance = bondTolerance; } // minimum acceptable bonding distance ... from OpenBabel ... mth 2003 05 26 public float minBondDistance = 0.4f; public void setMinBondDistance(float minBondDistance) { this.minBondDistance = minBondDistance; } /* public void deleteAtom(int atomIndex) { frame.deleteAtom(atomIndex); } */ public boolean frankClicked(int x, int y) { return (getShapeSize(JmolConstants.SHAPE_FRANK) != 0 && frame.frankClicked(x, y)); } public int findNearestAtomIndex(int x, int y) { return (frame == null) ? -1 : frame.findNearestAtomIndex(x, y); } public BitSet findAtomsInRectangle(Rectangle rectRubber) { return frame.findAtomsInRectangle(rectRubber); } // FIXME mth 2004 02 23 -- this does *not* belong here public float solventProbeRadius = 1.2f; public void setSolventProbeRadius(float radius) { this.solventProbeRadius = radius; } public boolean solventOn = false; public void setSolventOn(boolean solventOn) { this.solventOn = solventOn; } /**************************************************************** * shape support ****************************************************************/ int[] shapeSizes = new int[JmolConstants.SHAPE_MAX]; Hashtable[] shapeProperties = new Hashtable[JmolConstants.SHAPE_MAX]; public void setShapeSize(int shapeType, int size, BitSet bsSelected) { shapeSizes[shapeType] = size; if (frame != null) frame.setShapeSize(shapeType, size, bsSelected); } public int getShapeSize(int shapeType) { return shapeSizes[shapeType]; } private static final Object NULL_SURROGATE = new Object(); public void setShapeProperty(int shapeType, String propertyName, Object value, BitSet bsSelected) { Hashtable props = shapeProperties[shapeType]; if (props == null) props = shapeProperties[shapeType] = new Hashtable(); // be sure to intern all propertyNames! propertyName = propertyName.intern(); /* System.out.println("propertyName=" + propertyName + "\n" + "value=" + value); */ // Hashtables cannot store null values :-( props.put(propertyName, value != null ? value : NULL_SURROGATE); if (frame != null) frame.setShapeProperty(shapeType, propertyName, value, bsSelected); } public Object getShapeProperty(int shapeType, String propertyName, int index) { Object value = null; if (frame != null) value = frame.getShapeProperty(shapeType, propertyName, index); if (value == null) { Hashtable props = shapeProperties[shapeType]; if (props != null) { value = props.get(propertyName); if (value == NULL_SURROGATE) return value = null; } } return value; } public int getAtomIndexFromAtomNumber(int atomNumber) { return (frame == null) ? -1 : frame.getAtomIndexFromAtomNumber(atomNumber); } public BitSet getElementsPresentBitSet() { return (frame == null) ? null : frame.getElementsPresentBitSet(); } public BitSet getGroupsPresentBitSet() { return (frame == null) ? null : frame.getGroupsPresentBitSet(); } //////////////////////////////////////////////////////////////// // Access to atom properties for clients //////////////////////////////////////////////////////////////// public String getAtomInfo(int i) { return frame.getAtomAt(i).getInfo(); } /* public String getAtomInfoChime(int i) { Atom atom = frame.atoms[i]; PdbAtom pdbAtom = atom.pdbAtom; if (pdbAtom == null) return "Atom: " + atom.getAtomicSymbol() + " " + atom.getAtomno(); return "Atom: " + pdbAtom.getAtomName() + " " + pdbAtom.getAtomSerial() + " " + pdbAtom.getGroup3() + " " + pdbAtom.getSeqcodeString() + " Chain:" + pdbAtom.getChainID(); } */ public String getElementSymbol(int i) { return frame.getAtomAt(i).getElementSymbol(); } public int getElementNumber(int i) { return frame.getAtomAt(i).getElementNumber(); } public String getAtomName(int i) { return frame.getAtomAt(i).getAtomName(); } public int getAtomNumber(int i) { return frame.getAtomAt(i).getAtomNumber(); } public float getAtomX(int i) { return frame.getAtomAt(i).getAtomX(); } public float getAtomY(int i) { return frame.getAtomAt(i).getAtomY(); } public float getAtomZ(int i) { return frame.getAtomAt(i).getAtomZ(); } public Point3f getAtomPoint3f(int i) { return frame.getAtomAt(i).getPoint3f(); } public float getAtomRadius(int i) { return frame.getAtomAt(i).getRadius(); } public short getAtomColix(int i) { return frame.getAtomAt(i).getColix(); } public Point3f getBondPoint3f1(int i) { return frame.getBondAt(i).atom1.getPoint3f(); } public Point3f getBondPoint3f2(int i) { return frame.getBondAt(i).atom2.getPoint3f(); } public float getBondRadius(int i) { return frame.getBondAt(i).getRadius(); } public short getBondOrder(int i) { return frame.getBondAt(i).getOrder(); } public short getBondColix1(int i) { return frame.getBondAt(i).getColix1(); } public short getBondColix2(int i) { return frame.getBondAt(i).getColix2(); } } --- NEW FILE: MouseManager.java --- /* $RCSfile: MouseManager.java,v $ * $Author: migueljmol $ * $Date: 2004/10/22 16:18:25 $ * $Revision: 1.1 $ * * Copyright (C) 2002-2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.jmol.viewer.managers; import org.jmol.viewer.*; import java.awt.Component; import java.awt.Cursor; import java.awt.Rectangle; import java.awt.Event; import java.util.BitSet; public abstract class MouseManager { final static int HOVER_TIME = 1000; Component component; JmolViewer viewer; Thread hoverWatcherThread; int previousDragX, previousDragY; public int xCurrent, yCurrent; long timeCurrent; int modifiersWhenPressed; boolean wasDragged; boolean measurementMode = false; boolean hoverActive = false; boolean rubberbandSelectionMode = false; int xAnchor, yAnchor; final static Rectangle rectRubber = new Rectangle(); private static final boolean logMouseEvents = false; public MouseManager(Component component, JmolViewer viewer) { this.component = component; this.viewer = viewer; hoverWatcherThread = new Thread(new HoverWatcher()); hoverWatcherThread.start(); } public static final String[] modeNames = { "ROTATE", "ZOOM", "XLATE", "PICK", "DELETE", "MEASURE", "DEFORM", "ROTATE_Z", "SLAB_PLANE"}; public int modeMouse = JmolConstants.MOUSE_ROTATE; public void setMode(int mode) { if (logMouseEvents) System.out.println("MouseManager.setMode(" + modeNames[mode] + ")"); modeMouse = mode; } public int getMode() { return modeMouse; } public Rectangle getRubberBand() { if (!rubberbandSelectionMode) return null; return rectRubber; } void calcRectRubberBand() { if (xCurrent < xAnchor) { rectRubber.x = xCurrent; rectRubber.width = xAnchor - xCurrent; } else { rectRubber.x = xAnchor; rectRubber.width = xCurrent - xAnchor; } if (yCurrent < yAnchor) { rectRubber.y = yCurrent; rectRubber.height = yAnchor - yCurrent; } else { rectRubber.y = yAnchor; rectRubber.height = yCurrent - yAnchor; } } final static long MAX_DOUBLE_CLICK_MILLIS = 700; final static int LEFT = 16; final static int MIDDLE = Event.ALT_MASK; // 8 note that MIDDLE final static int ALT = Event.ALT_MASK; // 8 and ALT are the same final static int RIGHT = Event.META_MASK; // 4 final static int CTRL = Event.CTRL_MASK; // 2 final static int SHIFT = Event.SHIFT_MASK; // 1 final static int MIDDLE_RIGHT = MIDDLE | RIGHT; final static int LEFT_MIDDLE_RIGHT = LEFT | MIDDLE | RIGHT; final static int CTRL_SHIFT = CTRL | SHIFT; final static int CTRL_LEFT = CTRL | LEFT; final static int CTRL_RIGHT = CTRL | RIGHT; final static int CTRL_MIDDLE = CTRL | MIDDLE; final static int CTRL_ALT_LEFT = CTRL | ALT | LEFT; final static int ALT_LEFT = ALT | LEFT; final static int ALT_SHIFT_LEFT = ALT | SHIFT | LEFT; final static int SHIFT_LEFT = SHIFT | LEFT; final static int CTRL_SHIFT_LEFT = CTRL | SHIFT | LEFT; final static int CTRL_ALT_SHIFT_LEFT = CTRL | ALT | SHIFT | LEFT; final static int SHIFT_MIDDLE = SHIFT | MIDDLE; final static int CTRL_SHIFT_MIDDLE = CTRL | SHIFT | MIDDLE; final static int SHIFT_RIGHT = SHIFT | RIGHT; final static int CTRL_SHIFT_RIGHT = CTRL | SHIFT | RIGHT; final static int CTRL_ALT_SHIFT_RIGHT = CTRL | ALT | SHIFT | RIGHT; final static int BUTTON_MODIFIER_MASK = CTRL | ALT | SHIFT | LEFT | MIDDLE | RIGHT; int previousPressedX, previousPressedY; int previousPressedModifiers, previousPressedCount; long previousPressedTime; int pressedCount; void mousePressed(long time, int x, int y, int modifiers, boolean isPopupTrigger) { if (previousPressedX == x && previousPressedY == y && previousPressedModifiers == modifiers && (time - previousPressedTime) < MAX_DOUBLE_CLICK_MILLIS) { ++pressedCount; } else { pressedCount = 1; } hoverOff(); previousPressedX = previousDragX = xCurrent = x; previousPressedY = previousDragY = yCurrent = y; previousPressedModifiers = modifiers; previousPressedTime = timeCurrent = time; if (logMouseEvents) System.out.println("mousePressed("+x+","+y+","+modifiers+ " isPopupTrigger=" + isPopupTrigger+")"); modifiersWhenPressed = modifiers; wasDragged = false; switch (modifiers & BUTTON_MODIFIER_MASK) { /**************************************************************** * mth 2004 03 17 * this isPopupTrigger stuff just doesn't work reliably for me * and I don't have a Mac to test out CTRL-CLICK behavior * Therefore ... we are going to implement both gestures * to bring up the popup menu * The fact that we are using CTRL_LEFT may * interfere with other platforms if/when we * need to support multiple selections, but we will * cross that bridge when we come to it ****************************************************************/ case CTRL_LEFT: // on MacOSX this brings up popup case RIGHT: // with multi-button mice, this will too viewer.popupMenu(x, y); return; } } void mouseEntered(long time, int x, int y) { if (logMouseEvents) System.out.println("mouseEntered("+x+","+y+")"); hoverOff(); timeCurrent = time; xCurrent = x; yCurrent = y; } void mouseExited(long time, int x, int y) { if (logMouseEvents) System.out.println("mouseExited("+x+","+y+")"); hoverOff(); timeCurrent = time; xCurrent = x; yCurrent = y; exitMeasurementMode(); } void mouseReleased(long time, int x, int y, int modifiers) { hoverOff(); timeCurrent = time; xCurrent = x; yCurrent = y; if (logMouseEvents) System.out.println("mouseReleased("+x+","+y+","+modifiers+")"); viewer.setInMotion(false); } int previousClickX, previousClickY; int previousClickModifiers, previousClickCount; long previousClickTime; void mouseClicked(long time, int x, int y, int modifiers, int clickCount) { // clickCount is not reliable on some platforms // so we will just deal with it ourselves if (previousClickX == x && previousClickY == y && previousClickModifiers == modifiers && clickCount == 1 && (time - previousClickTime) < MAX_DOUBLE_CLICK_MILLIS) { clickCount = previousClickCount + 1; } hoverOff(); xCurrent = previousClickX = x; yCurrent = previousClickY = y; previousClickModifiers = modifiers; previousClickCount = clickCount; timeCurrent = previousClickTime = time; if (logMouseEvents) System.out.println("mouseClicked("+x+","+y+","+modifiers+ ",clickCount="+clickCount+ ",time=" + (time - previousClickTime) + ")"); if (! viewer.haveFrame()) return; int nearestAtomIndex = viewer.findNearestAtomIndex(x, y); if (clickCount == 1) mouseSingleClick(x, y, modifiers, nearestAtomIndex); else if (clickCount == 2) mouseDoubleClick(x, y, modifiers, nearestAtomIndex); } void mouseSingleClick(int x, int y, int modifiers, int nearestAtomIndex) { switch (modifiers & BUTTON_MODIFIER_MASK) { case LEFT: if (viewer.frankClicked(x, y)) { viewer.popupMenu(x, y); return; } if (measurementMode) { addToMeasurement(nearestAtomIndex, false); } else { viewer.notifyPicked(nearestAtomIndex); } break; } } void mouseDoubleClick(int x, int y, int modifiers, int nearestAtomIndex) { switch (modifiers & BUTTON_MODIFIER_MASK) { case LEFT: if (measurementMode) { addToMeasurement(nearestAtomIndex, true); toggleMeasurement(); } else { enterMeasurementMode(); addToMeasurement(nearestAtomIndex, true); } break; case ALT_LEFT: case MIDDLE: case SHIFT_LEFT: viewer.homePosition(); break; } } void mouseDragged(long time, int x, int y, int modifiers) { if (logMouseEvents) System.out.println("mouseDragged("+x+","+y+","+modifiers + ")"); int deltaX = x - previousDragX; int deltaY = y - previousDragY; hoverOff(); timeCurrent = time; xCurrent = previousDragX = x; yCurrent = previousDragY = y; wasDragged = true; viewer.setInMotion(true); if (pressedCount == 1) mouseSinglePressDrag(deltaX, deltaY, modifiers); else if (pressedCount == 2) mouseDoublePressDrag(deltaX, deltaY, modifiers); } void mouseSinglePressDrag(int deltaX, int deltaY, int modifiers) { switch (modifiers & BUTTON_MODIFIER_MASK) { case LEFT: viewer.rotateXYBy(deltaX, deltaY); break; case SHIFT_LEFT: case ALT_LEFT: case MIDDLE: viewer.zoomBy(deltaY); // fall into case SHIFT_RIGHT: // the one-button Mac folks won't get this gesture viewer.rotateZBy(-deltaX); break; } } void mouseDoublePressDrag(int deltaX, int deltaY, int modifiers) { switch (modifiers & BUTTON_MODIFIER_MASK) { case SHIFT_LEFT: case ALT_LEFT: case MIDDLE: viewer.translateXYBy(deltaX, deltaY); break; } } /* int getMode(int modifiers) { if (modeMouse != JmolConstants.MOUSE_ROTATE) return modeMouse; /* RASMOL // mth - I think that right click should be reserved for a popup menu if ((modifiers & CTRL_LEFT) == CTRL_LEFT) return SLAB_PLANE; if ((modifiers & SHIFT_LEFT) == SHIFT_LEFT) return ZOOM; if ((modifiers & SHIFT_RIGHT) == SHIFT_RIGHT) return ROTATE_Z; if ((modifiers & RIGHT) == RIGHT) return XLATE; if ((modifiers & LEFT) == LEFT) mol is a collaboratively developed visualization an return ROTATE; / if ((modifiers & SHIFT_RIGHT) == SHIFT_RIGHT) return JmolConstants.MOUSE_ROTATE_Z; if ((modifiers & CTRL_RIGHT) == CTRL_RIGHT) return JmolConstants.MOUSE_XLATE; if ((modifiers & RIGHT) == RIGHT) return JmolConstants.MOUSE_POPUP_MENU; if ((modifiers & SHIFT_LEFT) == SHIFT_LEFT) return JmolConstants.MOUSE_ZOOM; if ((modifiers & CTRL_LEFT) == CTRL_LEFT) return JmolConstants.MOUSE_SLAB_PLANE; if ((modifiers & LEFT) == LEFT) return JmolConstants.MOUSE_ROTATE; return modeMouse; } public void mouseDragged(int x, int y, int modifiers) { xCurrent = x; yCurrent = y; wasDragged = true; viewer.setInMotion(true); switch (getMode(modifiers)) { case JmolConstants.MOUSE_MEASURE: case JmolConstants.MOUSE_ROTATE: //if (logMouseEvents) //System.out.println("mouseDragged Rotate("+x+","+y+","+modifiers+")"); viewer.rotateXYBy(xCurrent - xPrevious, yCurrent - yPrevious); break; case JmolConstants.MOUSE_ROTATE_Z: //if (logMouseEvents) //System.out.println("mouseDragged RotateZ("+x+","+y+","+modifiers+")"); viewer.rotateZBy(xPrevious - xCurrent); break; case JmolConstants.MOUSE_XLATE: //if (logMouseEvents) //System.out.println("mouseDragged Translate("+x+","+y+","+modifiers+")"); viewer.translateXYBy(xCurrent - xPrevious, yCurrent - yPrevious); break; case JmolConstants.MOUSE_ZOOM: //if (logMouseEvents) //System.out.println("mouseDragged Zoom("+x+","+y+","+modifiers+")"); viewer.zoomBy(yCurrent - yPrevious); break; case JmolConstants.MOUSE_SLAB_PLANE: viewer.slabBy(yCurrent - yPrevious); break; case JmolConstants.MOUSE_PICK: if (viewer.haveFrame()) { calcRectRubberBand(); BitSet selectedAtoms = viewer.findAtomsInRectangle(rectRubber); if ((modifiers & SHIFT) != 0) { viewer.addSelection(selectedAtoms); } else { viewer.setSelectionSet(selectedAtoms); } } break; case JmolConstants.MOUSE_POPUP_MENU: break; } xPrevious = xCurrent; yPrevious = yCurrent; } */ int mouseMovedX, mouseMovedY; long mouseMovedTime; void mouseMoved(long time, int x, int y, int modifiers) { /* if (logMouseEvents) System.out.println("mouseMoved("+x+","+y+","+modifiers"+)"); */ hoverOff(); timeCurrent = mouseMovedTime = time; mouseMovedX = xCurrent = x; mouseMovedY = yCurrent = y; if (measurementMode | hoverActive) { int atomIndex = viewer.findNearestAtomIndex(x, y); if (measurementMode) setAttractiveMeasurementTarget(atomIndex); } } final static float wheelClickFractionUp = 1.25f; final static float wheelClickFractionDown = 1/wheelClickFractionUp; void mouseWheel(long time, int rotation, int modifiers) { hoverOff(); timeCurrent = time; if (rotation == 0) return; if ((modifiers & BUTTON_MODIFIER_MASK) == 0) { float zoomLevel = viewer.getZoomPercentSetting() / 100f; if (rotation > 0) { while (--rotation >= 0) zoomLevel *= wheelClickFractionUp; } else { while (++rotation <= 0) zoomLevel *= wheelClickFractionDown; } viewer.zoomToPercent((int)(zoomLevel * 100 + 0.5f)); } } public abstract boolean handleOldJvm10Event(Event e); // note that these two may *not* be consistent // this term refers to the count of what has actually been selected int measurementCount = 0; // measurementCountPlusIndices[0] may be one higher if there is // an attractive measurement target // ie. the cursor is hovering near an atom int[] measurementCountPlusIndices = new int[5]; // the attractive target may be -1 void setAttractiveMeasurementTarget(int atomIndex) { if (measurementCountPlusIndices[0] == measurementCount + 1 && measurementCountPlusIndices[measurementCount + 1] == atomIndex) { viewer.refresh(); return; } for (int i = measurementCount; i > 0; --i) if (measurementCountPlusIndices[i] == atomIndex) { viewer.refresh(); return; } int attractiveCount = measurementCount + 1; measurementCountPlusIndices[0] = attractiveCount; measurementCountPlusIndices[attractiveCount] = atomIndex; viewer.setPendingMeasurement(measurementCountPlusIndices); } void addToMeasurement(int atomIndex, boolean dblClick) { if (atomIndex == -1) { exitMeasurementMode(); return; } for (int i = measurementCount; --i >= 0; ) if (measurementCountPlusIndices[i + 1] == atomIndex) { // exitMeasurementMode(); return; } if (measurementCount == 3 && !dblClick) return; measurementCountPlusIndices[++measurementCount] = atomIndex; measurementCountPlusIndices[0] = measurementCount; if (measurementCount == 4) toggleMeasurement(); else viewer.setPendingMeasurement(measurementCountPlusIndices); } void exitMeasurementMode() { if (measurementMode) { viewer.setPendingMeasurement(null); measurementMode = false; measurementCount = 0; viewer.getAwtComponent().setCursor(Cursor.getDefaultCursor()); } } void enterMeasurementMode() { viewer.getAwtComponent() .setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); measurementCount = 0; measurementMode = true; } void toggleMeasurement() { if (measurementCount >= 2 && measurementCount <= 4) { measurementCountPlusIndices[0] = measurementCount; viewer.toggleMeasurement(measurementCountPlusIndices); } exitMeasurementMode(); } void hoverOn(int atomIndex) { viewer.hoverOn(atomIndex); } void hoverOff() { viewer.hoverOff(); } class HoverWatcher implements Runnable { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while (true) { try { Thread.sleep(1000); if (xCurrent == mouseMovedX && yCurrent == mouseMovedY && timeCurrent == mouseMovedTime) { // the last event was mouse move long currentTime = System.currentTimeMillis(); int howLong = (int)(currentTime - mouseMovedTime); if (howLong > HOVER_TIME) { int atomIndex = viewer.findNearestAtomIndex(xCurrent, yCurrent); if (atomIndex != -1) hoverOn(atomIndex); } } } catch (InterruptedException ie) { System.out.println("InterruptedException!"); return; } } } } } --- NEW FILE: MouseManager10.java --- /* $RCSfile: MouseManager10.java,v $ * $Author: migueljmol $ * $Date: 2004/10/22 16:18:25 $ * $Revision: 1.1 $ * * Copyright (C) 2002-2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.jmol.viewer.managers; import org.jmol.viewer.*; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Dimension; import java.awt.Component; import java.awt.Event; import java.util.BitSet; public class MouseManager10 extends MouseManager { public MouseManager10(Component component, JmolViewer viewer) { super(component, viewer); } private int applyLeftMouse(int modifiers) { // if neither BUTTON2 or BUTTON3 then it must be BUTTON1 return ((modifiers & MIDDLE_RIGHT) == 0) ? (modifiers | LEFT) : modifiers; } int xWhenPressed, yWhenPressed, modifiersWhenPressed; public boolean handleOldJvm10Event(Event e) { int x = e.x, y = e.y, modifiers = e.modifiers, clickCount = e.clickCount; long time = e.when; modifiers = applyLeftMouse(modifiers); switch (e.id) { case Event.MOUSE_DOWN: xWhenPressed = x; yWhenPressed = y; modifiersWhenPressed = modifiers; mousePressed(time, x, y, modifiers, false); break; case Event.MOUSE_DRAG: mouseDragged(time, x, y, modifiers); break; case Event.MOUSE_ENTER: mouseEntered(time, x, y); break; case Event.MOUSE_EXIT: mouseExited(time, x, y); break; case Event.MOUSE_MOVE: mouseMoved(time, x, y, modifiers); break; case Event.MOUSE_UP: mouseReleased(time, x, y, modifiers); // simulate a mouseClicked event for us if (x == xWhenPressed && y == yWhenPressed && modifiers == modifiersWhenPressed) { // the underlying code will turn this into dbl clicks for us mouseClicked(time, x, y, modifiers, 1); } break; default: return false; } return true; } } --- NEW FILE: MouseManager11.java --- /* $RCSfile: MouseManager11.java,v $ * $Author: migueljmol $ * $Date: 2004/10/22 16:18:25 $ * $Revision: 1.1 $ * * Copyright (C) 2002-2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Fo... [truncated message content] |