XYZApp.java revision 2362
/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
/*
* A set of classes to parse, represent and display Chemical compounds in
* .xyz format (see http://chem.leeds.ac.uk/Project/MIME.html)
*/
/** The representation of a Chemical .xyz model */
class XYZChemModel {
float vert[];
int tvert[];
int ZsortMap[];
static Atom defaultAtom;
static {
}
boolean transformed;
XYZChemModel () {
}
/** Create a Cehmical model by parsing an input stream */
{
this();
st.eolIsSignificant(true);
int slot = 0;
try
{
scan:
while (true)
{
{
case StreamTokenizer.TT_EOF:
break scan;
default:
break;
case StreamTokenizer.TT_WORD:
double x = 0, y = 0, z = 0;
{
{
}
}
} // end Switch
} // end while
} // end Try
catch( IOException e) {}
} // end XYZChemModel()
/** Add a vertex to this model */
int i = nvert;
if (i >= maxvert)
maxvert = 100;
} else {
maxvert *= 2;
}
if (a == null) a = defaultAtom;
atoms[i] = a;
i *= 3;
vert[i] = x;
vert[i + 1] = y;
vert[i + 2] = z;
return nvert++;
}
/** Transform all the points in this model */
void transform() {
return;
transformed = true;
}
/** Paint this model to a graphics context. It uses the matrix associated
with this model to map from model space to screen space.
The next version of the browser should have double buffering,
which will make this *much* nicer */
return;
transform();
int v[] = tvert;
for (int i = nvert; --i >= 0;)
zs[i] = i * 3;
}
/*
* I use a bubble sort since from one iteration to the next, the sort
* order is pretty stable, so I just use what I had last time as a
* "guess" of the sorted order. With luck, this reduces O(N log N)
* to O(N)
*/
boolean flipped = false;
for (int j = 0; j <= i; j++) {
int a = zs[j];
int b = zs[j + 1];
if (v[a + 2] > v[b + 2]) {
zs[j + 1] = a;
zs[j] = b;
flipped = true;
}
}
if (!flipped)
break;
}
int lg = 0;
return;
for (int i = 0; i < lim; i++) {
int j = zs[i];
int grey = v[j + 2];
if (grey < 0)
grey = 0;
if (grey > 15)
grey = 15;
// g.drawString(names[i], v[j], v[j+1]);
// g.drawImage(iBall, v[j] - (iBall.width >> 1), v[j + 1] -
// (iBall.height >> 1));
}
}
/** Find the bounding box of this model */
void findBB() {
if (nvert <= 0)
return;
float v[] = vert;
float x = v[i];
if (x < xmin)
xmin = x;
if (x > xmax)
xmax = x;
float y = v[i + 1];
if (y < ymin)
ymin = y;
if (y > ymax)
ymax = y;
float z = v[i + 2];
if (z < zmin)
zmin = z;
if (z > zmax)
zmax = z;
}
}
}
/** An applet to put a Chemical model into a page */
public class XYZApp
extends Applet
boolean painted = true;
float xfac;
float scalefudge = 1;
private synchronized void newBackBuffer() {
}
}
public void init() {
try {
} catch(Exception e) {
};
mdname = "model.obj";
addMouseListener(this);
addMouseMotionListener(this);
}
public void destroy() {
removeMouseListener(this);
removeMouseMotionListener(this);
}
public void run() {
try {
md = m;
m.findBB();
} catch(Exception e) {
e.printStackTrace();
}
try {
} catch(Exception e) {
}
repaint();
}
public void start() {
}
public void stop() {
}
/* event handling */
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
e.consume();
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (painted) {
painted = false;
repaint();
}
prevx = x;
prevy = y;
e.consume();
}
public void mouseMoved(MouseEvent e) {
}
if (backBuffer == null)
paint(g);
}
// md.mat.scale(xfac, -xfac, 8 * xfac / getSize().width);
md.transformed = false;
if (backBuffer != null) {
}
else
setPainted();
}
}
private synchronized void setPainted() {
painted = true;
notifyAll();
}
private synchronized void waitPainted()
{
while (!painted)
{
try
{
wait();
}
catch (InterruptedException e) {}
}
painted = false;
}
public String getAppletInfo() {
return "Title: XYZApp \nAuthor: James Gosling \nAn applet to put a Chemical model into a page.";
}
public String[][] getParameterInfo() {
{"model", "path string", "The path to the model to be displayed in .xyz format (see http://chem.leeds.ac.uk/Project/MIME.html). Default is model.obj."},
{"scale", "float", "Scale factor. Default is 1 (i.e. no scale)."}
};
return info;
}
} // end class XYZApp
class Atom {
private static byte[] data;
private final static int R = 40;
private final static int hx = 15;
private final static int hy = 15;
private final static int bgGrey = 192;
private final static int nBalls = 16;
private static int maxr;
private int Rl;
private int Gl;
private int Bl;
static {
int mr = 0;
for (int Y = 2 * R; --Y >= 0;) {
int p = Y * (R * 2) + R - x0;
int x = X + hx;
int y = Y - R + hy;
if (r > mr)
mr = r;
}
}
}
}
}
}
private void Setup() {
byte red[] = new byte[256];
byte green[] = new byte[256];
byte blue[] = new byte[256];
for (int r = 0; r < nBalls; r++) {
float b = (float) (r+1) / nBalls;
for (int i = maxr; i >= 1; --i) {
float d = (float) i / maxr;
}
}
}
Setup();
}
int size = 10 + r;
}
}