package application.pen; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Insets; import java.awt.Toolkit; import java.awt.dnd.DropTarget; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; 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.Hashtable; import java.util.TooManyListenersException; import java.util.Vector; import javax.swing.BoxLayout; import javax.swing.JButton; //import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSlider; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.SwingConstants; import javax.swing.table.DefaultTableModel; import javax.swing.text.Document; import javax.swing.text.PlainDocument; import java.awt.event.*; import javax.swing.event.*; /* import application.webbrowser.WebFrame; import nodesystem.CommunicationNode; import nodesystem.DialogListener; import nodesystem.EditDialog; import nodesystem.FileFrame; import nodesystem.LoadFileFrame; */ import controlledparts.*; import connector.*; /** * GUIの基礎部分です。 * * @author rn_magi * */ public class MainGUI extends ControlledFrame implements FrameWithControlledTextAreas, FrameWithControlledButton, FrameWithControlledSlider, FrameWithControlledPane, FrameWithControlledTabbedPane, FrameWithControlledMenu, FrameWithControlledMenuItem, DialogListener, PukiwikiJavaApplication { String Version = "ver1.09_7"; String SystemName = "PEN"; String WindowName = SystemName + " " + Version; // JFrame main_window = new JFrame("NewFile - " + WindowName); ControlledFrame main_window = new ControlledFrame("NewFile - "+ WindowName); JPanel menu_panel = new JPanel(); JPanel run_time_panel = new JPanel(); JPanel edit_panel = new JPanel(); JPanel edit_area_panel = new JPanel(); // JPanel run_panel = new JPanel(); JPanel console_panel = new JPanel(); JPanel var_panel = new JPanel(); JSplitPane main_splitpane; JSplitPane run_splitpane; JScrollPane edit_JSP; JScrollPane console_JSP; JScrollPane console_log_JSP; JScrollPane var_JSP; DropTarget edit_area_drop = new DropTarget(); Font font = new Font("MS ゴシック", 0, 14); String ButtonListFile = ""; Document edit_doc = new PlainDocument(); EditAreaUndoableEditListener undo = new EditAreaUndoableEditListener(); String[] columnNames = {"型" , "変数名" , "値"}; int[] COLSIZE = {45,80,100}; static DefaultTableModel vt_model; static MyJMenuBar MenuBar; static MyRunJLabel run_print = new MyRunJLabel(); /* static JButton new_button = new MenuButton("新規", 60, 30); static JButton open_button = new MenuButton("開く", 60, 30); static JButton save_button = new MenuButton("保存", 60, 30); static JButton run_button = new MenuButton("実行", 80, 30); static JButton step_button = new MenuButton("一行実行", 80, 30); static JButton stop_button = new MenuButton("始めに戻る", 80, 30); static JTabbedPane console_tab = new JTabbedPane(); static JTextArea run_point = new JTextArea(1,1); static JTextArea breakpoint = new JTextArea(1,1); static JTextArea numbar_area = new JTextArea(1,2); static JTextArea edit_area = new JTextArea(0,0); static JTextArea console = new JTextArea(0,0); static JTextArea console_log = new JTextArea(13,0); static JTable var_table = new JTable(); static JSlider run_time = new JSlider(SwingConstants.HORIZONTAL,0,2000,0); */ // static JFileChooser fc = new JFileChooser("./"); static RunButtonListener RunButton = new RunButtonListener(); static IntVgOutputWindow gDrowWindow = new IntVgOutputWindow(); // static JButton new_button = new MenuButton("新規", 60, 30); static ControlledButton new_button = new MenuButton("新規", 60, 30); // static JButton open_button // static ControlledButton open_button = new MenuButton("開く", 60, 30); static ControlledButton open_button = new MenuButton("開く/保存", 75, 30); // static JButton save_button // static ControlledButton save_button = new MenuButton("保存", 60, 30); // static JButton run_button static ControlledButton run_button = new MenuButton("実行", 75, 30); // static JButton step_button static ControlledButton step_button = new MenuButton("一行実行", 75, 30); // static JButton stop_button static ControlledButton stop_button = new MenuButton("始めに戻る", 75, 30); // static JTabbedPane console_tab = new JTabbedPane(); static ControlledTabbedPane console_tab = new ControlledTabbedPane(); // static JTextArea run_point = new JTextArea(1,1); static ControlledTextArea run_point = new ControlledTextArea(1,1); // static JTextArea breakpoint = new JTextArea(1,1); static ControlledTextArea breakpoint = new ControlledTextArea(1,1); // static JTextArea numbar_area = new JTextArea(1,2); static ControlledTextArea numbar_area = new ControlledTextArea(1,2); // static JTextArea edit_area = new JTextArea(0,0); static ControlledTextArea edit_area = new ControlledTextArea(0,0); // static JTextArea console = new JTextArea(10,0); static ControlledTextArea console = new ControlledTextArea(10,0); // static JTextArea console_log = new JTextArea(10,0); static ControlledTextArea console_log = new ControlledTextArea(10,0); static JTable var_table = new JTable(); // static JSlider run_time = new JSlider(SwingConstants.HORIZONTAL,0,2000,0); static ControlledSlider run_time = new ControlledSlider(SwingConstants.HORIZONTAL,0,2000,0); ControlledButton helpButton= new ControlledButton(); static boolean Run_flag = false; static boolean Step_flag = false; static boolean Suspend_flag = false; static boolean Input_flag = false; static boolean Stop_flag = false; static boolean Bug_flag = false; static boolean Debug_flag = false; PenFileFilter filter[] = { new PenFileFilter("txt" , "テキストファイル (*.txt)") , new PenFileFilter("pen" , "PENファイル (*.pen)") }; // public MainGUI(){ // GUI(); // } // fields for dsr Vector texts=new Vector(); Vector buttons=new Vector(); Vector sliders=new Vector(); Vector panes=new Vector(); Vector tabbedPanes=new Vector(); Vector menus=new Vector(); Vector menuItems=new Vector(); Hashtable editButtons = new Hashtable(); // WebFrame browser; static Object isAlreadyConstructed=null; FileFrame fileFrame; // static ExecutionPart executionPart; int lastManipulatedTextArea; // // NewFileButtonListener newFileButtonListener=new NewFileButtonListener(main_window,edit_area,WindowName);// t.yamanoue // FileOpenButtonListener fileOpenButtonListener = new FileOpenButtonListener(fc, main_window, edit_area, WindowName); // t.yamanoue // FileSaveButtonListener fileSaveButtonListener = new FileSaveButtonListener(fc, main_window, edit_area, WindowName); // t.yamanoue NewFileButtonListener newFileButtonListener=new NewFileButtonListener(this,edit_area,WindowName);// t.yamanoue // FileOpenButtonListener fileOpenButtonListener = new FileOpenButtonListener(fc, this, edit_area, WindowName); // t.yamanoue // FileSaveButtonListener fileSaveButtonListener = new FileSaveButtonListener(fc, this, edit_area, WindowName); // t.yamanoue // ExitButtonListener exitButtonListener = new ExitButtonListener(fc, this, edit_area); // t.yamanoue ConsoleKeyListener consoleKeyListener=new ConsoleKeyListener(); EditAreaKeyListener editAreaKeyListener=new EditAreaKeyListener(edit_area); EditAreaMouseListener editAreaMouseListener=new EditAreaMouseListener(edit_area); // EditAreaDocumentListener editAreaDocumetnListener=new EditAreaDocumentListener(main_window, edit_area, numbar_area); EditAreaDocumentListener editAreaDocumetnListener=new EditAreaDocumentListener(this, edit_area, numbar_area); // UndoMenuItem.addActionListener(undo); // RedoMenuItem.addActionListener(undo); EditAreaUndoableEditListener editAreaUndoAbleListner =new EditAreaUndoableEditListener(); // ConsoleCopyMenuItem.addActionListener(new ConsoleCopyButtonListener(console)); ConsoleCopyButtonListener consoleButtonListener= new ConsoleCopyButtonListener(console); // VarCopyMenuItem.addActionListener(new VarCopyButtonListener(var_table)); VarCopyButtonListener varCopyButtonListener=new VarCopyButtonListener(var_table); // HelpPenMenuItem.addActionListener(new HelpPenButtonListener(SystemName, Version, window));// add window, 2006 3.23 public MainGUI(){ // 編集ボタン設定ファイルの場所: // dsr/commondata/pen/ButtonList.ini /* String currentDir=System.getProperty("user.dir"); File dsrRoot=new File(currentDir); File commonDataDir=new File(dsrRoot,"commondata"); if(!commonDataDir.exists()) commonDataDir.mkdir(); ButtonListFile=commonDataDir.getPath()+ System.getProperty("file.separator")+ "pen"+ System.getProperty("file.separator")+ "ButtonList.ini"; */ GUI(); } /** * 実行時の引数の解析を行い GUIメソッド を呼び出す。 */ public MainGUI(String argv[]){ File path = new File(System.getProperty("java.class.path")); if(path.isDirectory()){ ButtonListFile = path.getPath() + System.getProperty("file.separator") + "ButtonList.ini"; } else { ButtonListFile = path.getParent() + System.getProperty("file.separator") + "ButtonList.ini"; } for(int i = 0; i < argv.length; i++) { if(argv[i].equals("-teacher") || argv[i].equals("-t")){ COLSIZE[0] = 80; font = new Font("MS ゴシック", 0, 22); } else if(argv[i].equals("-debug") || argv[i].equals("-d")) { Debug_flag = true; } else if(argv[i].equals("-b")){ ButtonListFile = argv[++i]; } } this.GUI(); } /** * 各コンポーネントの初期化や配置を行う */ public void GUI(){ /* JFrame.setDefaultLookAndFeelDecorated(true); try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); SwingUtilities.updateComponentTreeUI(this); }catch(Exception ex){} */ /* for(int i = 0 ; i < filter.length ; i++) fc.addChoosableFileFilter(filter[i]); */ // 2006 3/22 t.yamanoue /* // main_window.addWindowListener(new MyWindowAdapter(main_window, edit_area)); main_window.setIconImage(Toolkit.getDefaultToolkit().createImage(getClass().getResource("pen.png"))); // main_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); main_window.setSize(800,600); main_window.setResizable(false); // uncomment by t. yamanoue, 2006 3/19 main_window.setLocation(100,100); MenuBar = new MyJMenuBar(fc, main_window, edit_area, console, var_table, SystemName, Version, undo); main_window.setJMenuBar(MenuBar.createMenuBar()); */ // 2006 3.22 t.yamanoue this.setIconImage(Toolkit.getDefaultToolkit().createImage(getClass().getResource("pen.png"))); // main_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(800,600); this.setResizable(false); // uncomment by t. yamanoue, 2006 3/19 this.setLocation(100,100); MenuBar = new MyJMenuBar(this, edit_area, console, var_table, SystemName, Version, undo); this.setJMenuBar(MenuBar.createMenuBar()); // added by 2006 3/9 t.yamanoue this.menus.addElement(MenuBar.FileMenu); this.menus.addElement(MenuBar.EditMenu); this.menus.addElement(MenuBar.HelpMenu); int maxMenu=menus.size(); for(int i=0;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 void saveText(String urlname) { /* ControlledTextArea mes=console; 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=edit_area.getText(); // byte[] buff=new byte[outx.length()]; byte[] buff=null; buff=outx.getBytes(); // 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); */ } String tempText; public void pasteAtTheText(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(); // startPosition=ta.getSelectionStart(); if(startPosition<0) startPosition=0; endPosition=ta.getSelectionEnd(); if(endPositiontheText.length()) endPosition=theText.length(); newText=theText.substring(0,startPosition); newText=newText+ tempText+ (ta.getText()).substring(endPosition); ta.setText(newText); 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(); /* communicationNode.tempText=theText.substring(startPosition,endPosition); */ this.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.communicationNode.tempText=theText.substring(startPosition,endPosition); this.tempText=theText.substring(startPosition,endPosition); return; } public void receiveEvent(String s) { /* if(this.communicationNode==null) return; // if(!this.communicationNode.isReceivingEvents) return; if(!this.isReceiving()) return; BufferedReader dinstream=null; try{ dinstream=new BufferedReader( new StringReader(s) ); } catch(Exception e){ System.out.println("exception:"+e); } if(dinstream==null) return; InputQueue iq=new InputQueue(dinstream); ParsePenEvent evParser=new ParsePenEvent(this,iq); evParser.parsingString=s; evParser.run(); */ } public void exitThis() { this.mouseClickedAtButton(stop_button.getID()); this.recordMessage("0,\"exit pen\""); this.setVisible(false); } /* (非 Javadoc) * @see controlledparts.FrameWithControlledTextAreas#keyIsReleasedAtTextArea(int, int) */ public void keyIsReleasedAtTextArea(int id, int p, int code) { // TODO 自動生成されたメソッド・スタブ ControlledTextArea t=(ControlledTextArea)(texts.elementAt(id)); t.setCaretPosition(p); KeyEvent e=new KeyEvent(t, 0, 0, 0, code); e.setKeyCode(code); if(id==console.getID()){ consoleKeyListener.keyReleased(e); // this.typeKey(i,p,key); } if(id==edit_area.getID()){ this.editAreaKeyListener.keyReleased(e); } } /* (非 Javadoc) * @see controlledparts.FrameWithControlledTextAreas#releaseKey(int, int) */ public void releaseKey(int i, int p, int code) { // TODO 自動生成されたメソッド・スタブ ControlledTextArea t=(ControlledTextArea)(texts.elementAt(i)); t.setCaretPosition(p); KeyEvent e=new KeyEvent(t, 0, 0, 0, code); e.setKeyCode(code); if(i==console.getID()){ consoleKeyListener.keyReleased(e); } else if(i==edit_area.getID()){ editAreaKeyListener.keyReleased(e); } } public void pressKey(int i, int p, int code){ ControlledTextArea t=(ControlledTextArea)(texts.elementAt(i)); // t.setCaretPosition(p); t.requestFocus(); KeyEvent e=new KeyEvent(t, 0, 0, 0, code); e.setKeyCode(code); if(i==console.getID()){ consoleKeyListener.keyPressed(e); // t.pressKey(p,code); } else if(i==edit_area.getID()){ editAreaKeyListener.keyPressed(e); // t.pressKey(p,code); } } public void showHelpPage(){ /* browser=(WebFrame) (this.communicationNode.applicationManager.spawnApplication2("WebFrame", "local")); if(browser==null) return; // this.pageArea.setEditable(false); String cdd=this.communicationNode.commonDataDir.toString(); String sep=""+System.getProperty("file.separator"); String initPage=""; String urlHead="file:"; if(sep.equals("\\")){ urlHead=urlHead+"///"; } else { urlHead=urlHead+"//"; } initPage=urlHead+cdd+sep+"html"+sep+"pen.html"; browser.startLoading(initPage); */ } public void clickMenu(int i) { // TODO 自動生成されたメソッド・スタブ ControlledMenu m=(ControlledMenu)(menus.elementAt(i)); m.click(); /* ActionEvent e=new ActionEvent(m,0,""); ActionListener[] ls=m.getActionListeners(); int asize=ls.length; for(int j=0;j