/* A basic implementation of the JFrame class. */ package application.basic; import java.awt.Dimension; import java.awt.Font; import java.awt.Insets; import java.awt.MediaTracker; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.util.StringTokenizer; import java.util.Vector; import language.CQueue; import language.LispObject; import language.ReadLine; import application.draw.DrawFrame; import connector.PukiwikiJavaApplication; import connector.SaveButtonDebugFrame; import controlledparts.*; import javax.swing.*; /** * This code was generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * ************************************* * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED * for this machine, so Jigloo or this code cannot be used legally * for any corporate or commercial purpose. * ************************************* */ public class BasicFrame extends controlledparts.ControlledFrame implements controlledparts.FrameWithControlledButton, controlledparts.FrameWithControlledCheckBox, controlledparts.FrameWithControlledPane, controlledparts.FrameWithControlledTextAreas, controlledparts.DialogListener, FrameWithLanguageProcessor, PukiwikiJavaApplication { private Vector checkBoxes; String tempText; public void focusCheckBox(int i) { // This method is derived from interface controlledparts.FrameWithControlledCheckBox // to do: code goes here ControlledCheckBox b=(ControlledCheckBox)(checkBoxes.elementAt(i)); b.focus(); } public void mouseEnteredAtCheckBox(int i) { // This method is derived from interface controlledparts.FrameWithControlledCheckBox // to do: code goes here } public void mouseExitedAtCheckBox(int i) { // This method is derived from interface controlledparts.FrameWithControlledCheckBox // to do: code goes here } public void changeStateCheckBox(int i, int x) { // This method is derived from interface controlledparts.FrameWithControlledCheckBox // to do: code goes here ControlledCheckBox b=(ControlledCheckBox)(checkBoxes.elementAt(i)); b.changeState(x); this.stateChangedAtCheckBox(i,x); } public void stateChangedAtCheckBox(int i, int x) { // This method is derived from interface controlledparts.FrameWithControlledCheckBox // to do: code goes here } public void unfocusCheckBox(int i) { // This method is derived from interface controlledparts.FrameWithControlledCheckBox // to do: code goes here ControlledCheckBox b=(ControlledCheckBox)(checkBoxes.elementAt(i)); b.unFocus(); } public void setTextOnTheText(int id, int pos,String s) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.setTextAt(pos,s); } public boolean stopFlag; public void resetStopFlag() { this.stopFlag=false; } public boolean stopFlagIsOn() { // This method is derived from interface language.GuiWithControlFlag // to do: code goes here return this.stopFlag; } public boolean traceFlagIsOn() { // This method is derived from interface language.GuiWithControlFlag // to do: code goes here return this.traceFlag.isSelected(); } public boolean stopFlagIsSelected() { // This method is derived from interface language.GuiWithStopFlag // to do: code goes here return false; } public boolean isControlledByLocalUser() { // This method is derived from interface FrameWithControlledPane // to do: code goes here return super.isControlledByLocalUser(); } /* public boolean isShowingRmouse() { return this.communicationNode.rmouseIsActivated; } */ public void enterMouseOnTheText(int id, int x, int y) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.enterMouse(x,y); } public void exitMouseOnTheText(int id, int x, int y) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.exitMouse(); } public void moveMouseOnTheText(int id, int x, int y) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); // t.rmouse.move(x,y); t.moveMouse(x,y); } public void mouseMoveAtTextArea(int id, int x, int y) { } public void mouseEnteredAtTheText(int id, int x, int y) { } public void mouseExitAtTheText(int id, int x, int y) { } public void clearAll() { exampleButton.setText(((ControlledButton)(this.basicExampleListFrame.buttons.elementAt(0))).getText()); this.currentExample=(String)(basicExampleListFrame.programs.elementAt(0)); this.edittingArea.setText(""); this.inputArea.setText(""); this.outputArea.setText(""); // this.fileFrame.setCommunicationNode(this.communicationNode); this.fileFrame.setWords(); /* if(!this.isApplet()) this.fileFrame.setFileChooser(new JFileChooser()); */ this.enterButton.setToolTipText(getLclTxt("enter")); } public String parseCommand(String x) { /* command: add-program clear-program set-command clear-command clear-output // add // click run enter exit */ if(x.startsWith("ex ")){ String st=x.substring("ex ".length()); this.inputArea.setText(st); this.basic.setWaitingFunction(st); this.clickButton(this.enterButton.getID()); return basic.waitForResult(st); } if(x.indexOf("add-program ")==0){ String st=x.substring("add-program ".length()); this.edittingArea.append(st+"\n"); return ""; } if(x.indexOf("clear-program ")==0){ String st=x.substring("clear-program ".length()); this.edittingArea.setText(""); return ""; } if(x.indexOf("set-command ")==0){ String st=x.substring("add-command ".length()); this.inputArea.setText(st); return ""; } if(x.indexOf("clear-command ")==0){ String st=x.substring("clear-command ".length()); this.inputArea.setText(""); return ""; } if(x.indexOf("run")==0){ this.clickButton(6); return ""; } if(x.indexOf("enter")==0){ this.clickButton(8); return ""; } if(x.indexOf("exit")==0){ this.clickButton(1); return ""; } if(x.indexOf("call ")==0){ String f=x.substring("call ".length()); String q="? "+f; this.inputArea.setText(q); this.enter(); } return null; } public boolean traceFlagIsSelected() { return this.traceFlag.isSelected(); } public void mouseIsMovedAtTheFrame(int x, int y) { sendEvent("frm.mm("+x+","+y+")\n"); } public void mouseIsExitedAtTheFrame(int x, int y) { } public void mouseIsEnteredAtTheFrame(int x, int y) { sendEvent("frm.ment("+x+","+y+")\n"); } public boolean graphicsIsShown; public void saveText(String urlname) {/* ControlledTextArea mes=this.outputArea; if(urlname==null) return; // int startTime=this.communicationNode.eventRecorder.timer.getMilliTime(); mes.append("saving "+urlname+"\n"); FileOutputStream fouts=null; try{ fouts= new FileOutputStream(new File(urlname));} catch(FileNotFoundException e){ mes.append("wrong directory:"+urlname+" ?\n"); } */ /* catch(IOException e){ mes.append("cannot access"+urlname+".\n");} */ /* String outx=this.edittingArea.getText(); // byte[] buff=new byte[outx.length()]; byte[] buff=null; try{ // buff=outx.getBytes(this.communicationNode.encodingCode); } catch(java.io.UnsupportedEncodingException e){ mes.append("exception:"+e); } // outx.getBytes(0,outx.length(),buff,0); try{ fouts.write(buff); fouts.flush(); } catch(IOException e) { mes.append("save:IOExceptin while flushing.\n");} try{ fouts.close(); } catch(IOException e) { mes.append("save:IOException while closing.\n");} mes.append("Saving done.\n"); // int endTime=this.communicationNode.eventRecorder.timer.getMilliTime(); // int savingtime=endTime-startTime; double length=(double)(outx.length()); String savingSpeed=""; */ /* if(savingtime>0){ savingSpeed=""+(length*1000)/savingtime; } else savingSpeed="(na)"; this.recordMessage(""+startTime+ ",\"savefig("+urlname+") \","+savingtime+ ","+length+","+savingSpeed); */ } public Vector getDialogs() { // This method is derived from interface DialogListener // to do: code goes here return null; } public void sendFileDialogMessage(String m) { // This method is derived from interface DialogListener // to do: code goes here // if(this.sendEventFlag) sendEvent("file."+m); sendEvent("file."+m); } public void whenActionButtonPressed(EditDialog d) { // This method is derived from interface DialogListener // to do: code goes here String dname=d.getDialogName(); if(dname.equals("input common file name:")){ String url=""; String fileName=d.getText(); // File commonDataPath=communicationNode.commonDataDir; // File thePath=new File(commonDataPath.getPath(),fileName); String separator=""+System.getProperty("file.separator"); if(separator.equals("\\")) // url="file:///"+thePath.getPath(); url="file:///"+fileName; else // url="file://"+thePath.getPath(); url="file://"+fileName; // urlField.setText(fileName); this.loadProgram(url); return; } if(dname.equals("input user file name:")){ String url=""; String fileName=d.getText(); /* File userDataPath=draw.communicationNode.userDataDir; if(!userDataPath.exists()) userDataPath.mkdir(); // File thePath=new File(userDataPath.getPath(),fileName); String separator=""+System.getProperty("file.separator"); if(separator.equals("\\")) // url="file:///"+thePath.getPath(); url="file:///"+fileName; else // url="file://"+thePath.getPath(); url="file://"+fileName; // urlField.setText(fileName); this.loadProgram(url); */ return; } if(dname.equals("output user file name:")){ String url=""; String fileName=d.getText(); /* File userDataPath=draw.communicationNode.userDataDir; if(!userDataPath.exists()) userDataPath.mkdir(); // File thePath=new File(userDataPath.getPath(),fileName); // urlField.setText(fileName); // this.saveText(thePath.getPath()); this.saveText(fileName); */ return; } if(dname.equals("url:")){ String url=d.getText(); // urlField.setText(url); this.loadProgram(url); return; } else if(dname.equals("output common file name:")){ /* if(!this.communicationNode.getControlMode().equals("teach")) return; String url=""; String fileName=d.getText(); // File commonDataPath=this.communicationNode.commonDataFigDir; // File thePath=new File(commonDataPath.getPath(),fileName); // System.out.println(thePath.getPath()); // editdispatch.save(thePath); this.saveText(fileName); */ return; } } public void whenCancelButtonPressed(EditDialog d) { // This method is derived from interface DialogListener // to do: code goes here } public int lastManipulatedTextArea; public FileFrame fileFrame; public void pasteAtTheText(int i) { String theText=""; String newText=""; int startPosition=0; int endPosition=0; ControlledTextArea ta=(ControlledTextArea)(this.texts.elementAt(i)); // ControlledScrollPane p=(ControlledScrollPane)(this.panes.elementAt(i)); // ControlledScrollBar vs=(ControlledScrollBar)(p.scrollBars.elementAt(0)); // int vsv=vs.getValue(); // ControlledScrollBar hs=(ControlledScrollBar)(p.scrollBars.elementAt(1)); // int hsv=hs.getValue(); startPosition=ta.getSelectionStart(); theText=ta.getText(); // startPosition=ta.getSelectionStart(); if(startPosition<0) startPosition=0; endPosition=ta.getSelectionEnd(); if(endPositiontheText.length()) endPosition=theText.length(); newText=theText.substring(0,startPosition); newText=newText+ this.tempText+ (ta.getText()).substring(endPosition); ta.setText(newText); // vs.setValue(vsv); // hs.setValue(hsv); return; } public void cutAnAreaOfTheText(int i) { String theText=""; String newText=""; int startPosition=0; int endPosition=0; ControlledTextArea ta=(ControlledTextArea)(this.texts.elementAt(i)); startPosition=ta.getSelectionStart(); theText=ta.getText(); if(startPosition<0) startPosition=0; endPosition=ta.getSelectionEnd(); if(endPositiontheText.length()) endPosition=theText.length(); tempText=theText.substring(startPosition,endPosition); newText=theText.substring(0,startPosition); newText=newText+ theText.substring(endPosition); ta.setText(newText); return; } public void copyFromTheText(int i) { String theText=""; String newText=""; int startPosition=0; int endPosition=0; ControlledTextArea ta=(ControlledTextArea)(this.texts.elementAt(i)); theText=ta.getText(); startPosition=ta.getSelectionStart(); if(startPosition<0) startPosition=0; endPosition=ta.getSelectionEnd(); if(endPositiontheText.length()) endPosition=theText.length(); this.tempText=theText.substring(startPosition,endPosition); return; } public Vector panes; public void pressMouseOnTheText(int id, int p, int x, int y) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.pressMouse(p,x,y); this.lastManipulatedTextArea=id; } public void mousePressedAtTextArea(int id, int p, int x, int y) { this.lastManipulatedTextArea=id; // sendEvent("txt.mps("+id+","+p+")\n"); } public void showScrollBar(int paneID, int barID) { ControlledScrollPane p=(ControlledScrollPane)(panes.elementAt(paneID)); p.showScrollBar(barID); } public void hideScrollBar(int paneID, int barID) { ControlledScrollPane p=(ControlledScrollPane)(panes.elementAt(paneID)); p.hideScrollBar(barID); } public void changeScrollbarValue(int paneID, int barID, int value) { ControlledScrollPane p=(ControlledScrollPane)(panes.elementAt(paneID)); p.setScrollBarValue(barID,value); } public void scrollBarHidden(int paneID, int barID) { // This method is derived from interface FrameWithControlledPane // to do: code goes here // sendEvent("sb.hidden("+paneID+","+barID+")\n"); } public void scrollBarShown(int paneID, int barID) { // This method is derived from interface FrameWithControlledPane // to do: code goes here // sendEvent("sb.shown("+paneID+","+barID+")\n"); } public void scrollBarValueChanged(int paneID, int barID, int v) { // This method is derived from interface FrameWithControlledPane // to do: code goes here // sendEvent("sb.value("+paneID+","+barID+","+v+")\n"); } public void showhideDraw() { } private String encodingCode; public void releaseMouseOnTheText(int id, int position, int x, int y) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.releaseMouse(position,x,y); } public void dragMouseOnTheText(int id, int position, int x, int y) { ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.dragMouse(position,x,y); } public void mouseReleasedAtTextArea(int id, int position, int x, int y) { // sendEvent("txt.mrl("+id+","+position+")\n"); } public void mouseDraggedAtTextArea(int id, int position, int x, int y) { // sendEvent("txt.mdg("+id+","+position+")\n"); } void enter() { //{{CONNECTION // TextArea にフォーカスを要求する // textInput.requestFocus(); //}} String input=inputArea.getText(); outputArea.append(input+"\n"); // outputArea.setCaretPosition(outputArea.getText().length()); inqueue.putString(input); inputArea.setText(""); inputArea.repaint(); /* // lisp.evals(inqueue); */ LispObject o=((ReadLine)(basic.read)).readProgram(inqueue); LispObject p=basic.basicparser.parseBasic(o); basic.evalList(p); // outputArea.setCaretPosition(outputArea.getText().length()); // outputArea.repaint(); } void loadExample() { /* String urlname=""; File thePath=new File(getDefaultPath(),currentExample); String separator=""+System.getProperty("file.separator"); if(separator.equals("\\")) urlname="file:///"+thePath.getPath(); else urlname="file://"+thePath.getPath(); System.out.println("url="+urlname); loadProgram( urlname ); */ String x=this.basicExampleListFrame.getExample(currentExample); this.edittingArea.setText(x); } void programRun() { try { // edittingArea.show(); } catch (Exception e) { } this.stopFlag=false; String input=edittingArea.getText(); // textOutput.appendText("> "+input+"\n"); inqueue.putString(input); basic.clearEnvironment(); // graphicsArea.clear(); LispObject o=((ReadLine)(basic.read)).readProgram(inqueue); LispObject p=basic.basicparser.parseBasic(o); basic.evalList(p); // outputArea.repaint(); // outputArea.setCaretPosition(outputArea.getText().length()); } String commandName="basic"; public String getCommandName(){ return commandName; } public void sendEvent(String s) { /* if(this.communicationNode==null) return; this.communicationNode.sendEvent(commandName,s); */ } public Vector texts; public void clickMouseOnTheText(int i, int p, int x, int y) { // This method is derived from interface FrameWithControlledTextAreas // to do: code goes here this.lastManipulatedTextArea=i; ControlledTextArea t=(ControlledTextArea)(texts.elementAt(i)); t.clickMouse(p,x,y); } public void keyIsTypedAtATextArea(int i, int p, int key) { // This method is derived from interface FrameWithControlledTextAreas // to do: code goes here } public void keyIsPressedAtATextArea(int i, int p, int key){ } public void mouseClickedAtTextArea(int i, int p, int x, int y) { // This method is derived from interface FrameWithControlledTextAreas // to do: code goes here this.lastManipulatedTextArea=i; } public void typeKey(int i, int p, int key) { // This method is derived from interface FrameWithControlledTextAreas // to do: code goes here ControlledTextArea t=(ControlledTextArea)(texts.elementAt(i)); t.typeKey(p,key); } public void clickButton(int i) { ControlledButton t=(ControlledButton)(buttons.elementAt(i)); t.click(); this.mouseClickedAtButton(i); } public void unfocusButton(int i) { SelectedButton button=(SelectedButton)(buttons.elementAt(i)); // button.controlledButton_mouseExited(null); button.unFocus(); } public void focusButton(int i) { SelectedButton button=(SelectedButton)(buttons.elementAt(i)); // button.controlledButton_mouseEntered(null); button.focus(); } String currentExample; BasicExampleListFrame basicExampleListFrame; public File getDefaultPath() { File rtn=//this.communicationNode.dsrRoot; new File(""); return rtn; } public void mouseExitedAtButton(int i) { // This method is derived from interface SelectButtonsFrame // to do: code goes here } public void mouseEnteredAtButton(int i) { // This method is derived from interface SelectButtonsFrame // to do: code goes here } public void mouseClickedAtButton(int i) { // This method is derived from interface SelectButtonsFrame // to do: code goes herevoid mouseClickedAtButton(int ) /* buttons.addElement( fileButton); buttons.addElement( exitButton ); buttons.addElement( editorClearButton ); buttons.addElement( this.copyButton ); buttons.addElement( this.cutButton ); buttons.addElement( this.pasteButton ); buttons.addElement( runButton ); buttons.addElement( loadExampleButton ); buttons.addElement( enterButton ); buttons.addElement( exampleButton ); buttons.addElement( outputClearButton ); buttons.addElement( inputClearButton ); buttons.addElement( graphicsButton); buttons.addElement( hideButton); buttons.addElement( stopButton); */ if(i==0){ fileFrame.setListener(this); fileFrame.setSeparator(System.getProperty("file.separator")); /* fileFrame.setCommonPath( this.communicationNode.commonDataDir.toString()); fileFrame.setUserPath( this.communicationNode.userDataDir.toString()); fileFrame.setVisible(true); */ return;} // fileButton if(i==1){exitThis(); return;} // exitButton if(i==2){edittingArea.setText(""); return;} // editorClearButton if(i==3){ this.copyFromTheText(this.lastManipulatedTextArea); return; } // copyButton if(i==4){ this.cutAnAreaOfTheText(this.lastManipulatedTextArea); return; } // cutButton if(i==5){ this.pasteAtTheText(this.lastManipulatedTextArea); return; } // pasteButton if(i==6){programRun(); return; } // runButton if(i==7){loadExample(); return;} // loadExampleButton if(i==8){enter(); return;} // enterButton if(i==9){basicExampleListFrame.setVisible(true); return;} // exampleButton if(i==10){outputArea.setText(""); return;} // outputClearButton if(i==11){inputArea.setText(""); return;} // inputClearButton if(i==12){ if(draw==null){ draw=this.getDrawFrame(); draw.clearAll(); draw.setIcons(iconPlace); } draw.setVisible(true); return; } // (show) graphicsButton if(i==13){ if(this.draw!=null) this.draw.setVisible(false); return; } // hideButton if(i==this.stopButton.getID()){ this.stopFlag=true; } } public void dispose() { // This method is derived from interface Spawnable // to do: code goes here } public DrawFrame draw; private Basic basic; String str2saveable(String str) { StringBuffer s=new StringBuffer(str); String sx=""; int i=0; int len=s.length(); while(i0){ readingSpeed=""+(((double)(tlength))*1000)/readingtime; } else readingSpeed="(na)"; // npMain.recordMessage("-"+startTime+":readfig("+urlname+") done."); this.recordMessage(""+startTime+ ",\"readfig("+urlname+") \""+","+readingtime+ ","+tlength+","+readingSpeed); this.sendAll(); */ } public BasicFrame() { panes=new Vector(); panes.addElement(this.editPane); panes.addElement(this.inputPane); panes.addElement(this.outputPane); int numberOfPanes=panes.size(); for(int i=0;i