import java.awt.*; import java.applet.*; import java.io.*; import java.net.*; import java.util.*; public class PetaSIM extends Applet implements Runnable { Thread runner; Button button1, button2; public int howmanyClicked = 0; TextArea resultTxtArea; NodeSetControls nodeSetPanel; LinkSetControls linkSetPanel; DataSetControls dataSetPanel; DistribControls distribPanel; ExScriptControls exscriptPanel; public void add(Component c, GridBagLayout gbl, GridBagConstraints gbc, int x, int y, int w, int h) { gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; gbl.setConstraints(c,gbc); add(c); } public void init() { setFont(new Font("Helvetica", Font.PLAIN, 14)); Panel PetaSIMPanel = new Panel(); Panel ArchitecturePanel = new Panel(); Panel ApllicationPanel = new Panel(); Panel ControlPanel = new Panel(); setLayout(new BorderLayout()); this.resize(940,620); //nodeSetPanel = new NodeSetControls(this); nodeSetPanel = new NodeSetControls(); linkSetPanel = new LinkSetControls(); dataSetPanel = new DataSetControls(); // no Distribution // distribPanel = new DistribControls(); exscriptPanel = new ExScriptControls(); PetaSIMPanel.setLayout(new GridLayout(2 ,1, 10, 10)); ArchitecturePanel.setLayout(new GridLayout(1,2,5,5)); ApllicationPanel.setLayout(new GridLayout(1,3,5,5)); ControlPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); ArchitecturePanel.add(nodeSetPanel); ArchitecturePanel.add(linkSetPanel); ApllicationPanel.add(dataSetPanel); // no Distribution // ApllicationPanel.add(distribPanel); ApllicationPanel.add(exscriptPanel); PetaSIMPanel.add(ArchitecturePanel); PetaSIMPanel.add(ApllicationPanel); ControlPanel.add(new Button(" Clear All ")); ControlPanel.add(new Label(" ")); ControlPanel.add(new Button(" Examples ")); ControlPanel.add(new Label(" ")); ControlPanel.add(new Button(" Run ")); ControlPanel.add(new Label(" ")); ControlPanel.add(new Label("Result :")); resultTxtArea = new TextArea(2,38); ControlPanel.add(resultTxtArea); // ControlPanel.add(new Button(" Quit ")); add("Center",PetaSIMPanel); add("South", ControlPanel); } public void getResultFromServer() throws IOException { try { URL url = new URL(getDocumentBase(), "results.out"); DataInputStream din = new DataInputStream(url.openStream()); String sLine; //sLine = din.readLine(); //resultTxtArea.setText(""); while((sLine = din.readLine()) != null) { resultTxtArea.setText(sLine); } din.close(); } catch(IOException ioe) { System.err.println("Error in PetaSIM showResult0...."+ioe); return; } } public void sendComanndToServer() { Socket thisSocket = null; DataOutputStream os = null; DataInputStream is = null; String st; try { thisSocket = new Socket("www.new-npac.org", 8778); os = new DataOutputStream(thisSocket.getOutputStream()); is = new DataInputStream(thisSocket.getInputStream()); } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis"); resultTxtArea.setText("Don't know about host: taranis"); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: taranis"); resultTxtArea.setText("Couldn't get I/O for the connection to: taranis"); } if (thisSocket != null && os != null && is != null) { try { nodeSetPanel.sendInputToServer(os); linkSetPanel.sendInputToServer(os); dataSetPanel.sendInputToServer(os); // no Distribution // distribPanel.sendInputToServer(os); exscriptPanel.sendInputToServer(os); os.writeBytes("run"); // send run command to server os.writeByte('\n'); resultTxtArea.setText(is.readLine()); // write result on text area. os.close(); is.close(); thisSocket.close(); } catch (IOException e) { System.err.println ("I/O failed on the connection to: taranis"); resultTxtArea.setText ("I/O failed on the connection to: taranis"); } } } public void setExampleInput(String ex, String st) { String s, tmp =""; StringTokenizer t = new StringTokenizer(st, "|"); s = t.nextToken(); nodeSetPanel.setExample(s); s = t.nextToken(); linkSetPanel.setExample(s); s = t.nextToken(); dataSetPanel.setExample(s); // no Distribution // s = t.nextToken(); // distribPanel.setExample(s); s = t.nextToken(); exscriptPanel.setExample(s); } public boolean action(Event evt, Object obj) { String command = (String)obj; try { if (command.equals(" Run ")) { resultTxtArea.setText(" Please Wait.... "); sendComanndToServer(); } else if (command.equals(" Examples ")) { ExampleFrame exF = new ExampleFrame(this); //exF.pack(); exF.setTitle("Examples"); exF.show(); } else if (command.equals(" Clear All ")) { nodeSetPanel.clearAll(); linkSetPanel.clearAll(); dataSetPanel.clearAll(); // no Distribution // distribPanel.clearAll(); exscriptPanel.clearAll(); resultTxtArea.setText(""); validate(); } //else if (command.equals(" Quit ")) { //this.dispose(); //} else return false; } catch(Exception e) { System.err.println("Error in PetsSIM...." + e); //return; } return true; } public Image getPic(int picnum) { URL url = getDocumentBase(); Image pic; if((picnum==1) ||(picnum==2)) pic = getImage(getDocumentBase(),"example1-2.gif"); else if((picnum==3) ||(picnum==4)) pic = getImage(getDocumentBase(),"example3-4.gif"); else pic = null; return pic; } public void start() { runner = new Thread(this); runner.start(); } public void stop() { if (runner != null) runner.stop(); } public void run() { } /* public static void main(String[] args) { PetaSIM tester = new PetaSIM(); tester.resize(800, 650); // tester.setSize(200, 100); tester.init(); tester.show(); } */ };