1 /* $RCSfile$
2  * $Author: hansonr $
3  * $Date: 2014-12-13 22:43:17 -0600 (Sat, 13 Dec 2014) $
4  * $Revision: 20162 $
5  *
6  * Copyright (C) 2002-2005  The Jmol Development Team
7  *
8  * Contact: jmol-developers@lists.sf.net
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Lesser General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2.1 of the License, or (at your option) any later version.
14  *
15  *  This library is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 package org.jmol.render;
25 
26 import javajs.util.P3;
27 
28 import org.jmol.modelset.Atom;
29 import org.jmol.modelset.Text;
30 import org.jmol.shape.Hover;
31 import org.jmol.util.Txt;
32 
33 public class HoverRenderer extends ShapeRenderer {
34 
35   private float[] tempXY = new float[3];
36   private P3 ptTemp;
37 
38   @Override
render()39   protected boolean render() {
40     // hover rendering always involves translucent pass
41     if (tm.isNavigating())
42       return false;
43     if (ptTemp == null)
44       ptTemp = new P3();
45     Hover hover = (Hover) shape;
46     boolean antialias = g3d.isAntialiased();
47     Text text = hover.hoverText;
48     String label;
49     if (hover.atomIndex >= 0) {
50       Atom atom = ms.at[hover.atomIndex];
51       label = (hover.specialLabel != null ? hover.specialLabel
52           : hover.atomFormats != null
53           && hover.atomFormats[hover.atomIndex] != null ?
54               vwr.ms.getLabeler().formatLabel(vwr, atom, hover.atomFormats[hover.atomIndex], ptTemp)
55           : hover.labelFormat != null ? vwr.ms.getLabeler().formatLabel(vwr, atom, fixLabel(atom, hover.labelFormat), ptTemp)
56               : null);
57       if (label == null)
58         return false;
59       text.setXYZs(atom.sX, atom.sY, 1, Integer.MIN_VALUE);
60     } else if (hover.text != null) {
61       label = hover.text;
62       text.setXYZs(hover.xy.x, hover.xy.y, 1, Integer.MIN_VALUE);
63     } else {
64       return true;
65     }
66     if (vwr != null &&(label.indexOf("%{") >= 0 || label
67         .indexOf("@{") >= 0))
68       label = Txt.formatText(vwr, label);
69     text.setText(label);
70     //System.out.println("hoverRenderer " + text.getText());
71     TextRenderer.render(text, g3d, 0, antialias ? 2 : 1, false, null, tempXY );
72     return true;
73   }
74 
fixLabel(Atom atom, String label)75   String fixLabel(Atom atom, String label) {
76     if (label == null)
77       return null;
78     return (vwr.ms.isJmolDataFrameForModel(atom.mi)
79         && label.equals("%U") ?"%W" : label);
80   }
81 }
82