import java.awt.*; import java.awt.event.MouseEvent; import java.util.*; import java.io.*; import java.lang.*; import java.text.*; public class graphWindow extends Frame{ OutputWindow Caller; Button OKButton; Label blank1; graph2D graph; graphWindow(){} graphWindow(String title, OutputWindow Caller){ super(title); this.Caller = Caller; DoLayout(); graph.requestFocus(); } /* public synchronized void reshape(int x, int y, int w, int h) { super.reshape(x, y, w, h); paint(super.getGraphics()); repaint(); } */ public final void DoLayout(){ addNotify(); resize(500,400); // Event e = new Event(this, Event.WINDOW_DEICONIFY, // new Object()); // postEvent(e); graph = new graph2D(this); OKButton = new Button("OK"); blank1 = new Label("",Label.LEFT); OKButton.setFont(new Font ("Arial", Font.PLAIN, 12)); OKButton.setBackground(Color.lightGray); OKButton.setForeground(Color.black); this.setBackground(Color.blue.brighter()); this.setForeground(Color.black); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); setLayout(gridbag); //Row 1 buildConstraints(constraints, 0, 0, 1, 1, 100, 90); constraints.fill = GridBagConstraints.BOTH; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(graph, constraints); add(graph); /* //Row 2 buildConstraints(constraints, 0, 1, 1, 1, 100, 10); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; constraints.ipadx = 40; gridbag.setConstraints(OKButton, constraints); add(OKButton); */ show(); validate(); } public synchronized void update(Graphics g) { graph.repaint(); paint(g); } public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy){ gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; } public Insets insets(){ return new Insets(30, 10, 32, 10); // return new Insets(38, 18, 40, 18); //Without button // return new Insets(38, 18, 25, 18); //With button } public boolean action(Event e, Object arg){ Object theSource; String label=null; theSource = e.target; if(theSource instanceof Button){ label = ((Button)theSource).getLabel(); if(label == "OK"){ hide(); //dispose(); validate(); return(true); } } return(false); } // Make sure that pressing on a button is handled in // the same way as clicking on it (action event). public boolean keyDown(Event e, int key){ Object theSource; theSource = e.target; if(key == Event.ENTER){ if(theSource instanceof Button ){ //Create an "ACTION_EVENT" associated with any //button (target=(Button)theSource) and post it here //for processing. e = new Event((Button)theSource, Event.ACTION_EVENT, ((Button)theSource).getLabel()); //this.postEvent(e); postEvent(e); return(true); } } return(false); } public boolean handleEvent(Event e){ Object theSource; int id; theSource = e.target; id = e.id; switch(id){ case(Event.WINDOW_DESTROY): hide(); return(true); default: return super.handleEvent(e); } } } class graph2D extends Panel{ private static final double zero=0.0e0; private static final double one=1.0e0; graphWindow Caller; private OutputWindow output; private int Degree; private double x[][]; private double y[]; private double Y[], z[]; private double rms, Rsquared, correlation; private int nx, Ncards, Nparms, Imethod; private boolean Constant; private double scale=0.1e0; private int Umin, Umax, Vmin, Vmax; private int UMIN, UMAX, VMIN, VMAX; private double XMIN, XMAX, YMIN, YMAX; private int w, h, Npoints=100, NaxisDiv=5; private double T[][], V[][], Mwv[][], Sx, Sy, Ou[], Ox[]; private double X[][], Px[], Py[], P[][]; private int Xtic[], Ytic[]; private int Iv[]; private Util util; private graphUtil gutil; private function2D function; private NumFormat nf; private String XexpoStr, YexpoStr, Xstr[], Ystr[]; graph2D(){} graph2D(graphWindow Caller){ this.Caller = Caller; this.output = Caller.Caller; init(); } public void init() { gutil = new graphUtil(); util = new Util(); nf = new NumFormat(); T = new double[3][3]; V = new double[3][3]; Ou = new double[2]; Ox = new double[2]; setBackground(Color.white); setForeground(Color.black); //Retrieve info associated with the "calling" output window. Imethod = output.getMethod(); Degree = output.getDegree(); Constant = output.isConstant(); rms = output.getRMS(); Rsquared = output.getRsquared(); correlation = output.getCorrelation(); Ncards = output.getN(); nx = output.getNx(); x = new double[Ncards][nx]; y = new double[Ncards]; // Y = new double[Ncards]; x = output.GetX(); y = output.GetY(); getWorldlimits(); Xstr = new String[NaxisDiv]; Ystr = new String[NaxisDiv]; getAxisValues(); // Y = output.getYY(); Nparms = output.getNparms(); z = new double[Nparms]; z = output.getParameters(); X = new double[Ncards][3]; P = new double[Npoints][3]; function = new function2D(Npoints, Imethod, Degree, Constant, z, XMIN, XMAX); Px = function.GetX(); Py = function.GetY(); Xtic = new int[NaxisDiv]; Ytic = new int[NaxisDiv]; // gutil.setClipFactor(0.95e0); gutil.setClipFactor(one); } public synchronized void paint(Graphics g) { w = this.size().width; h = this.size().height; gutil.ViewportWindowBounds(w, h, scale, scale, scale, scale); gutil.DrawFrame(g, false); Iv = new int[4]; Iv = gutil.get2DWindowLimits(); UMIN = Iv[0]; UMAX = Iv[1]; VMIN = Iv[2]; VMAX = Iv[3]; Mwv = getMwv(); putTicMarks(g); g.setFont(new Font ("Courier", Font.PLAIN, 11)); putAxisValues(g); putLegends(g); gutil.setClipRectangle(g); g.setColor(Color.blue); drawOutputFunction(g); g.setColor(Color.red); drawInputPoints(g); } public void drawInputPoints(Graphics g) { int W=3; for(int i=0; i max){ max=Math.abs(x[i]); } } power_10_max=util.Ilog10(max); /* we want the graduations to run to a maximum of 10E(max_power_10), in units of power_10_max */ if( Math.pow(10.0,(double)power_10_max) - max == zero ){ power_10_max=power_10_max - max_power_10; } fact=Math.pow(10.0,-power_10_max); for(i=0;i