public void importFile() { Editor editor=getJPE().getEditor(); String tempfilename = getFileName(FileDialog.LOAD); OpenFile tempfile = new OpenFile(tempfilename); String txt = tempfile.getText(); if (txt != null) { editor.insertText(txt); getJPE().say("Text Import"); } }
/** * create new file, under the name untitled or a followup * untitled2, untitled3 etc etc */ public void newFile(boolean template) { // get the openfile handler to add the new file OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); if (ofh==null) { // no opened handler started so lets start one and add it the // menu. ofh=(OpenFileHandler)getJPE().addHandler(new OpenFileHandler(getJPE())); ofh.createMenu(getJPE().getMenuBar()); } // find a empty untitled filename String prefix="untitled"; String filename=prefix; int i=2; // repeat until we found one while (ofh.isLoaded(filename)) { filename=prefix+(i++); } // open a file with the found name OpenFile file=new OpenFile(filename); if(template) { // open a dialog to let the user select the file we need to load String tempfilename = getFileName(FileDialog.LOAD); OpenFile tempfile = new OpenFile(tempfilename); String txt = tempfile.getText(); try { RE re = new RE("<getJPE():date>"); txt = re.substitute(txt,""+new Date()); file.setText(txt); } catch(REException ree) { ree.printStackTrace(); } } // add the file to the opened file list ofh.addFile(file); // load this file into the text area getJPE().getEditor().useFile(file); }