version 1.1, 2000/07/03 05:57:43 |
version 1.8, 2001/01/30 05:55:14 |
|
|
/** |
/** |
* $OpenXM$ |
* $OpenXM: OpenXM/src/OpenMath/OXplot.java,v 1.7 2000/11/09 06:50:16 tam Exp $ |
*/ |
*/ |
|
|
import JP.ac.kobe_u.math.tam.OpenXM.*; |
import ORG.openxm.tam.*; |
import java.util.Stack; |
import java.util.Stack; |
//import java.io.*; |
import java.util.Vector; |
|
import java.awt.*; |
|
|
public class OXplot extends OpenXMserver{ |
|
|
|
|
public class OXplot extends OpenXMControlServer{ |
private Stack stack = new Stack(); |
private Stack stack = new Stack(); |
private Vector plotframe = new Vector(); |
private Vector plotframe = new Vector(); |
protected boolean debug = true; |
protected boolean debug = true; |
final int version = 200007010; |
final int version = 200011090; |
|
|
public OXplot(String hostname,int ControlPort,int DataPort){ |
public OXplot(String hostname,int ControlPort,int DataPort){ |
super(hostname,ControlPort,DataPort); |
super(hostname,ControlPort,DataPort); |
} |
} |
|
|
public void computeProcess(OpenXMconnection stream){ |
public void computeProcess(OpenXMstream stream){ |
debug("OXplot started."); |
debug("OXplot started."); |
|
stack = new Stack(); |
|
plotframe = new Vector(); |
try{ |
try{ |
while(true){ |
while(true){ |
|
Thread.yield(); |
try{ |
try{ |
OXmessage message = stream.receive(); |
OXmessage message = stream.receive(); |
int ox_tag = message.getTag(); |
int ox_tag = message.getTag(); |
Line 50 public class OXplot extends OpenXMserver{ |
|
Line 56 public class OXplot extends OpenXMserver{ |
|
e.printStackTrace(); |
e.printStackTrace(); |
System.err.println("error occured, and recovering processes seems to be impossible."); |
System.err.println("error occured, and recovering processes seems to be impossible."); |
}finally{ |
}finally{ |
System.out.println("breaking..."); |
System.err.println("breaking..."); |
} |
} |
} |
} |
|
|
class plotframe extends java.awt.Frame{ |
|
int pixels[][]; |
|
|
|
plotframe(int width,int height){ |
private void SM_popCMO(OpenXMstream stream) throws java.io.IOException{ |
super("plotframe"); |
|
setSize(width,height); |
|
setResizable(false); |
|
|
|
pixels = new int[width][]; |
|
for(int i=0;i<pixels.length;i++){ |
|
pixels[i] = new int[height]; |
|
} |
|
} |
|
} |
|
|
|
private void SM_popCMO(OpenXMconnection stream) throws java.io.IOException{ |
|
try{ |
try{ |
if(stack.empty()){ |
if(stack.empty()){ |
stream.send(new CMO_NULL()); |
stream.send(new CMO_NULL()); |
Line 102 public class OXplot extends OpenXMserver{ |
|
Line 94 public class OXplot extends OpenXMserver{ |
|
argv[i] = (CMO)stack.pop(); |
argv[i] = (CMO)stack.pop(); |
} |
} |
|
|
if(function_name.equals("CREATE") && argc==2){ |
if(function_name.equals("create") && argc==2){ |
stack.push(CREATE(argv)); |
stack.push(CREATE(argv)); |
}else if(function_name.equals("CMO2OMXML") && argc==1){ |
}else if(function_name.equals("pset") && argc==4){ |
//stack.push(CMO2OMXML(argv[0])); |
PSET(argv); |
}else{ |
}else{ |
stack.push(new CMO_ERROR2(new CMO_NULL())); |
stack.push(new CMO_ERROR2(new CMO_NULL())); |
} |
} |
Line 113 public class OXplot extends OpenXMserver{ |
|
Line 105 public class OXplot extends OpenXMserver{ |
|
return; |
return; |
} |
} |
|
|
private void SM_mathcap(OpenXMconnection stream) throws java.io.IOException{ |
private void SM_mathcap(OpenXMstream stream) throws java.io.IOException{ |
CMO[] mathcap = new CMO[3]; |
CMO[] mathcap = new CMO[3]; |
|
|
{ |
{ |
Line 158 public class OXplot extends OpenXMserver{ |
|
Line 150 public class OXplot extends OpenXMserver{ |
|
debug("push: "+ stack.peek()); |
debug("push: "+ stack.peek()); |
} |
} |
|
|
private void SM_setMathCap(OpenXMconnection stream) |
private void SM_setMathCap(OpenXMstream stream) |
throws java.io.IOException{ |
throws java.io.IOException{ |
Object mathcap = stack.pop(); |
Object mathcap = stack.pop(); |
|
|
Line 168 public class OXplot extends OpenXMserver{ |
|
Line 160 public class OXplot extends OpenXMserver{ |
|
stream.setMathCap((CMO_MATHCAP)mathcap); |
stream.setMathCap((CMO_MATHCAP)mathcap); |
} |
} |
|
|
private void StackMachine(SM mesg,OpenXMconnection stream) |
private void StackMachine(SM mesg,OpenXMstream stream) |
throws java.io.IOException{ |
throws java.io.IOException{ |
debug("receive: "+mesg); |
debug("receive: "+mesg); |
|
|
Line 190 public class OXplot extends OpenXMserver{ |
|
Line 182 public class OXplot extends OpenXMserver{ |
|
break; |
break; |
|
|
default: |
default: |
System.out.println("received "+ mesg); |
System.err.println("received "+ mesg); |
} |
} |
} |
} |
|
|
private CREATE(CMO[] argv){ |
private CMO CREATE(CMO[] argv){ |
plotframe tmp = new plotframe(argv[0],argv[1]); |
plotframe tmp = new plotframe(((CMO_INT32)argv[0]).intValue() |
int i; |
,((CMO_INT32)argv[1]).intValue()); |
|
|
for(i=0;i<plotframe.size();i++){ |
for(int i=0;i<plotframe.size();i++){ |
if(plotframe.elementAt(i) == null){ |
if(plotframe.elementAt(i) == null){ |
plotframe.setElementAt(tmp,i); |
plotframe.setElementAt(tmp,i); |
return i; |
return new CMO_INT32(i); |
} |
} |
} |
} |
|
|
plotframe.addElement(tmp); |
plotframe.addElement(tmp); |
|
plotframe.trimToSize(); |
|
|
|
return new CMO_INT32(plotframe.size()-1); |
} |
} |
|
|
|
private CMO PSET(CMO[] argv){ |
|
plotframe tmp = (plotframe)plotframe.elementAt(((CMO_INT32)argv[0]).intValue()); |
|
|
|
tmp.pset(((CMO_INT32)argv[1]).intValue(), |
|
((CMO_INT32)argv[2]).intValue(), |
|
((CMO_INT32)argv[3]).intValue()); |
|
return new CMO_NULL(); |
|
} |
|
|
private void debug(String str){ |
private void debug(String str){ |
if(debug){ |
if(debug){ |
System.err.println(str); |
System.err.println(str); |
Line 232 public class OXplot extends OpenXMserver{ |
|
Line 236 public class OXplot extends OpenXMserver{ |
|
public static void main(String[] argv){ |
public static void main(String[] argv){ |
String hostname = "localhost"; |
String hostname = "localhost"; |
int ControlPort = 1200, DataPort = 1300; |
int ControlPort = 1200, DataPort = 1300; |
OpenXMserver ox; |
OpenXMControlServer ox; |
|
|
for(int i=0;i<argv.length;i++){ |
for(int i=0;i<argv.length;i++){ |
if(argv[i].equals("-h")){ |
if(argv[i].equals("-h")){ |
System.out.println(""); |
System.err.println(""); |
System.exit(0); |
System.exit(0); |
}else if(argv[i].equals("-host")){ |
}else if(argv[i].equals("-host")){ |
hostname = argv[++i]; |
hostname = argv[++i]; |
Line 251 public class OXplot extends OpenXMserver{ |
|
Line 255 public class OXplot extends OpenXMserver{ |
|
} |
} |
|
|
//ox = new OpenXMserver(hostname,ControlPort,DataPort); |
//ox = new OpenXMserver(hostname,ControlPort,DataPort); |
ox = new OMproxy(hostname,ControlPort,DataPort); |
ox = new OXplot(hostname,ControlPort,DataPort); |
/* |
/* |
try{ |
try{ |
}catch(java.net.UnknownHostException e){ |
}catch(java.net.UnknownHostException e){ |
Line 268 public class OXplot extends OpenXMserver{ |
|
Line 272 public class OXplot extends OpenXMserver{ |
|
|
|
ox.start(); |
ox.start(); |
|
|
System.out.println("breaking..."); |
System.err.println("breaking..."); |
|
} |
|
} |
|
|
|
class plotframe extends java.awt.Frame implements java.awt.event.MouseListener{ |
|
Canvas canvas; |
|
int pixels[][]; |
|
int offset_x,offset_y; |
|
|
|
plotframe(int width,int height){ |
|
super("plotframe"); |
|
add("Center", new Panel().add(canvas = new Canvas())); |
|
canvas.setSize(width,height); |
|
setResizable(false); |
|
canvas.addMouseListener(this); |
|
|
|
pixels = new int[height][width]; |
|
for(int i=0;i<pixels.length;i++){ |
|
pixels[i] = new int[width]; |
|
} |
|
offset_x = width/2; |
|
offset_y = height/2; |
|
|
|
pack(); |
|
show(); |
|
} |
|
|
|
public void paint(Graphics gr){ |
|
paint(); |
|
} |
|
|
|
public void paint(){ |
|
Graphics g = canvas.getGraphics(); |
|
|
|
for(int y=0;y<pixels.length;y++){ |
|
for(int x=0;x<pixels[y].length;x++){ |
|
g.setColor(new Color(pixels[y][x],pixels[y][x],pixels[y][x])); |
|
g.fillRect(x,y,1,1); |
|
} |
|
} |
|
} |
|
|
|
public void mouseClicked(java.awt.event.MouseEvent e){ |
|
paint(); |
|
} |
|
|
|
public void mousePressed(java.awt.event.MouseEvent e){ |
|
} |
|
|
|
public void mouseReleased(java.awt.event.MouseEvent e){ |
|
} |
|
|
|
public void mouseEntered(java.awt.event.MouseEvent e){ |
|
} |
|
|
|
public void mouseExited(java.awt.event.MouseEvent e){ |
|
} |
|
|
|
public void pset(int x,int y,int bright){ |
|
if(offset_x + x < 0 || offset_x + x >= pixels[0].length){ |
|
return; |
|
} |
|
if(offset_y + y < 0 || offset_y + y >= pixels.length){ |
|
return; |
|
} |
|
pixels[offset_y + y][offset_x + x] = bright; |
} |
} |
} |
} |