Methods Summary |
---|
public java.lang.String | getMoleculeName()
return moleculeName;
|
public java.awt.Dimension | getPreferredSize()
return new java.awt.Dimension(150,150);
|
public synchronized void | initialize()
InputStream is = null;
try {
width = getSize().width;
height = getSize().height;
is = this.getClass().getResourceAsStream(moleculeName + ".xyz");
XYZChemModel m = new XYZChemModel(is);
Atom.setComponent(this);
md = m;
m.findBB();
float xw = m.xmax - m.xmin;
float yw = m.ymax - m.ymin;
float zw = m.zmax - m.zmin;
if (yw > xw) {
xw = yw;
}
if (zw > xw) {
xw = zw;
}
float f1 = width / xw;
float f2 = height / xw;
xfac = 0.7f * (f1 < f2 ? f1 : f2) * scalefudge;
backBuffer = createImage(width, height);
backGC = backBuffer.getGraphics();
} catch(Exception e) {
e.printStackTrace();
md = null;
message = e.toString();
}
try {
if (is != null) {
is.close();
}
} catch(Exception e) {
}
|
public void | mouseClicked(java.awt.event.MouseEvent evt)
|
public void | mouseDragged(java.awt.event.MouseEvent evt)
rotate(evt.getX(), evt.getY());
|
public void | mouseEntered(java.awt.event.MouseEvent evt)
|
public void | mouseExited(java.awt.event.MouseEvent evt)
|
public void | mouseMoved(java.awt.event.MouseEvent evt)
|
public synchronized void | mousePressed(java.awt.event.MouseEvent evt)
prevx = evt.getX();
prevy = evt.getY();
|
public void | mouseReleased(java.awt.event.MouseEvent evt)
|
public synchronized void | paint(java.awt.Graphics g)
if (backBuffer == null || getSize().width != width
|| getSize().height != height) {
initialize();
}
if (md != null) {
md.mat.unit();
md.mat.translate(-(md.xmin + md.xmax) / 2,
-(md.ymin + md.ymax) / 2,
-(md.zmin + md.zmax) / 2);
md.mat.mult(amat);
// md.mat.scale(xfac, -xfac, 8 * xfac / getSize().width);
md.mat.scale(xfac, -xfac, 16 * xfac / getSize().width);
md.mat.translate(getSize().width / 2, getSize().height / 2, 8);
md.transformed = false;
backGC.setColor(getBackground());
backGC.fillRect(0,0,getSize().width, getSize().height);
md.paint(backGC);
g.drawImage(backBuffer, 0, 0, this);
} else if (message != null) {
g.drawString("Error in model:", 3, 20);
g.drawString(message, 10, 40);
}
|
private void | readObject(java.io.ObjectInputStream s)
// Compensate for missing constructor.
reset();
if (s.readInt() != ourVersion) {
throw new IOException("Molecule.readObject: version mismatch");
}
moleculeName = (String) s.readObject();
|
private synchronized void | reset()
md = null;
xfac = (float)0.0;
prevx = 0;
prevy = 0;
xtheta = (float)0.0;
ytheta = (float)0.0;
scalefudge = 1;
amat = new Matrix3D();
tmat = new Matrix3D();
message = null;
backBuffer = null;
backGC = null;
|
private synchronized void | rotate(int x, int y)
tmat.unit();
float xtheta = (prevy - y) * (360.0f / width);
float ytheta = (x - prevx) * (360.0f / height);
tmat.xrot(xtheta);
tmat.yrot(ytheta);
amat.mult(tmat);
repaint();
prevx = x;
prevy = y;
|
public synchronized void | rotateOnX()
int x = (prevx + 10)%width;
int y = prevy;
rotate(x, y);
|
public synchronized void | rotateOnY()
int x = prevx;
int y = (prevy + 10)%height;
rotate(x, y);
|
public synchronized void | rotateX(java.awt.event.ActionEvent b)
rotateOnX();
|
public synchronized void | rotateY(java.awt.event.ActionEvent b)
rotateOnY();
|
public void | setMoleculeName(java.lang.String name)
moleculeName = name;
reset();
repaint();
|
public synchronized void | update(java.awt.Graphics g)
if (backBuffer == null) {
g.clearRect(0, 0, getSize().width, getSize().height);
}
paint(g);
|
private void | writeObject(java.io.ObjectOutputStream s)
s.writeInt(ourVersion);
s.writeObject(moleculeName);
|