예제 #1
0
 public ImportFixer() {
             try {
                         castRe = new RE("[^a-zA-Z0-9_]\\("+classRegexp+"\\)");
                     declRe = new RE(classRegexp+leastOneSpaceRegexp+wordRegexp+maybeSpaceRegexp+";");
                         assiRe = new RE(classRegexp+leastOneSpaceRegexp+wordRegexp+maybeSpaceRegexp+"=");
                         instRe = new RE("instanceof"+leastOneSpaceRegexp+classRegexp);
                       newRe = new RE("new"+leastOneSpaceRegexp+classRegexp);
                     classRe = new RE("class"+leastOneSpaceRegexp+classRegexp);
                     stringLitRe = new RE("\"[^\"]*\"");
                     cPlusCommentRe = new RE("/\\*[^/*]*\\*/");
                     cPlusStartCommentRe = new RE("/\\*[^/*]*");
                     cPlusEndCommentRe = new RE("[^/*]*\\*/");
                     cCommentRe = new RE("//.*$");
             } catch(REException ree) {
                     System.err.println("bad ree: "+ree.getMessage());
             }                
 }
예제 #2
0
        /**
        * 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);
        }