⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 JTREE的例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        for(int j=0;j<v.size();j++){          msgarr[j]=(Messager)(v.elementAt(j));        }        bpan.addBtns(msgarr);        breader.close();        reader.close();      }catch(FileNotFoundException fnfe){       // fnfe.printStackTrace();/*shouldent do it        showStateReport("File not found , check for error then try again .");      }      catch(IOException ioe){        //ioe.printStackTrace();/*shouldent do it        showStateReport("Can't read from this file or try again . ");      }    }    public void load(){new Thread(this).start();}  }*/  protected class LoadForEditor// implements Runnable  {    File file;    LoadForEditor(){}    public LoadForEditor reSet(File file)      {this.file=file; return this;}    public void load(){      try{        FileInputStream fis=new FileInputStream(file);        InputStreamReader isr=null;        BufferedReader br=new BufferedReader(isr=new InputStreamReader(fis,encoding));        currenEditor.getXeditor().read(br,file);        //currenEditor.getXeditor().setCaretDot(0); //set to top viewing        fis.close();        this.file=null;      }catch(FileNotFoundException fne){        //fne.printStackTrace();        showStateReport("File not found , try again .");      }      catch(IOException ioe){//ioe.printStackTrace();        showStateReport("Can not read from this file , try again .");      }    }    //void load(){new Thread(this).start();}  }  class FindStrAction extends AbstractAction implements FindStrListener  {    FindStrAction(){super("find string");}    public void actionPerformed(ActionEvent e){      if(currenEditor==null) return;      find();    }    public void find(){      strSelDia.addFindStrListener(this);      strSelDia.showIt();    }//because of the getText() and getText(int,int) return defferent things, the former//return all string with "\n", so use getText(int,int), see try block in forward(...)    public void forward(String goal){      Xeditor editor=currenEditor.getXeditor();      int position=editor.getCaretPosition();      int lin=0;      String allStr="";      try{allStr=editor.getText(position,          editor.getDocument().getEndPosition().getOffset()-position);}      catch(Exception e){e.printStackTrace();}      int index=0;      if((index=allStr.indexOf(goal))==-1){        strSelDia.setVisible(false);        MainFrame.this.showStateReport("No more '"+goal+"' found.");        return;      }      editor.select((position+index),(position+index+(goal.length())));      MainFrame.this.requestFocus();      editor.requestFocus();    }    public void backward(String goal){      Xeditor xeditor=currenEditor.getXeditor();      int currPosit=xeditor.getCaretPosition();      String s=null;      try{s=xeditor.getText(0,currPosit);}      catch(Exception e){}//System.out.println(s);      int index=0;      if((index=s.lastIndexOf(goal))==-1){        strSelDia.setVisible(false);        MainFrame.this.showStateReport("No more '"+goal+"' found.");        return;      }      if((index+goal.length())==currPosit){        s=s.substring(0,(currPosit-goal.length()));        if((index=s.lastIndexOf(goal))==-1){          strSelDia.setVisible(false);          MainFrame.this.showStateReport("No more '"+goal+"' found.");          return;        }      }      xeditor.select(index,(index+(goal.length())));      MainFrame.this.requestFocus();      xeditor.requestFocus();    }  }  class NewAction extends AbstractAction  {    NewAction(){super("New");}    public void actionPerformed(ActionEvent e){      fileChooser.setFileFilter(null);      fileChooser.setFileFilter(MainFrame.this.relaFilter);      fileChooser.setApproveButtonText("Create");      int value = fileChooser.showOpenDialog(MainFrame.this);      if(value==JFileChooser.APPROVE_OPTION){        File f=fileChooser.getSelectedFile();        ContainEdi ce=new ContainEdi(f);        ce.addUndoRedoListener(undoRedoHandle);        ce.addERCListener(MainFrame.this);        rightTabPan.addTab(f.getName(),null,ce,f.getAbsolutePath());        rightTabPan.setSelectedIndex(rightTabPan.getTabCount()-1);      }    }  }  class OpenAction extends AbstractAction  {    OpenAction(){super("Open");}    public void actionPerformed(ActionEvent e){      fileChooser.setFileFilter(null);      fileChooser.setFileFilter(relaFilter);      fileChooser.setApproveButtonText("Open");      int value=fileChooser.showOpenDialog(MainFrame.this);      if(value==JFileChooser.APPROVE_OPTION){        File f=fileChooser.getSelectedFile();        ContainEdi ce=new ContainEdi(f);        ce.addUndoRedoListener(undoRedoHandle);        ce.addERCListener(MainFrame.this);        rightTabPan.addTab(f.getName(),null,ce,f.getAbsolutePath());        rightTabPan.setSelectedIndex(rightTabPan.getTabCount()-1);        loadForEdi.reSet(f).load();        ce.getUndoManager().discardAllEdits();      }    }  }//after save and save as action performed, undo and redo should not remain, and//shoule be made null.  protected class SaveAction extends AbstractAction  { SaveAction(){super("save");}    public void actionPerformed(ActionEvent e){      if(MainFrame.this.rightTabPan.getTabCount()==0) return;      saveAsAction.saveIt(currenEditor.getFile(),currenEditor);    }  }  protected class SaveAsAction extends AbstractAction  {    SaveAsAction(){super("save as");}    public void actionPerformed(ActionEvent e){      if(MainFrame.this.rightTabPan.getTabCount()==0) return;      fileChooser.setFileFilter(null);      fileChooser.setFileFilter(relaFilter);      int value=fileChooser.showSaveDialog(MainFrame.this);      if(value==JFileChooser.APPROVE_OPTION){        File f=fileChooser.getSelectedFile();        saveIt(f,currenEditor);      }    }    public void saveIt(File file,ContainEdi edi){      try{        FileOutputStream fos=new FileOutputStream(file);        OutputStreamWriter osw=new OutputStreamWriter(fos,encoding);        osw.write(edi.getAllText().toCharArray());        osw.flush();        osw.close();        fos.close();      }catch(IOException e){//e.printStackTrace();        showStateReport("Save failure , please try again .");      }      edi.saved();    }  }  protected class CloseAction extends AbstractAction implements YorNListener  { CloseAction(){super("close");}    public void gotYes(int val){      if(val==YorNListener.yes){//System.out.print("got yes. ");        saveAsAction.saveIt(currenEditor.getFile(),currenEditor);      }      else if(val==YorNListener.no) this.closeIt();    }    public void actionPerformed(ActionEvent e){      if(currenEditor.isModified()){ //System.out.print("action. ");        ynDia.setLab(currenEditor.getFile().getName()+" unsaved, save ?");        ynDia.addYorNListener(this);      }      else this.closeIt();    }    void closeIt(){      currenEditor.eraseUR();      MainFrame.this.rightTabPan.remove(currenEditor);      currenEditor=(ContainEdi)(rightTabPan.getSelectedComponent());      //to update the undo redo      undoRedoHandle.update();    }  }  protected class SetupBrowserAction extends AbstractAction implements YorNListener  {    public SetupBrowserAction(){super("setup browser");}    public void actionPerformed(ActionEvent e){      ynDia.setLab("You are going to setup browser, right?");      ynDia.addYorNListener(this);    }    public void gotYes(int val){      if(val==YorNListener.yes){setup();}    }    private void setup(){      fileChooser.setFileFilter(new ExampleFileFilter("exe","Executable file"));      fileChooser.setApproveButtonText("OK");      int value=fileChooser.showOpenDialog(MainFrame.this);      if(value==JFileChooser.APPROVE_OPTION){        try{          File f=fileChooser.getSelectedFile();          File file=new File(iniFile.getParent()+"/Browser");          FileWriter fw=new FileWriter(file.getAbsolutePath(),false);          fw.write(f.getAbsolutePath());          fw.flush();          fw.close();          browseAction.setBrowsePath(f.getAbsolutePath());        }catch(Exception excep){          reporter.setStateLab("Can't set up with Browser!");          reporter.show();          excep.printStackTrace();        }      }    }  }  protected class BrowseAction extends AbstractAction  {    private String browsePath=null;    protected void setBrowsePath(String path){      browsePath=path;      MainFrame.this.viewPMI.setEnabled(true);    }    public BrowseAction(){super("browse action");}    public void actionPerformed(ActionEvent e){      if(browsePath==null) return;      if(currenEditor.isModified())        saveAsAction.saveIt(currenEditor.getFile(),currenEditor);      try{        String ars[]=new String[2];        ars[0]=browsePath;        ars[1]=currenEditor.getFile().getAbsolutePath();        Runtime.getRuntime().exec(ars);      }      catch(Exception ex)      {        reporter.setStateLab("Something wrong,could not view.");        reporter.show();      }    }  }  protected class ExitAction extends AbstractAction implements YorNListener  { boolean gotSome=false;    public ExitAction(){super("exit");}    private void exit(){      if(MainFrame.windowCount==1){System.exit(1);}      else {        //MainFrame.this.setVisible(false);        MainFrame.this.dispose();        MainFrame.windowCount--;      }    }    public void gotYes(int val){      if(val==YorNListener.yes){        ContainEdi[] edi=MainFrame.this.ssd.returnResult();        for(int i=0;i<edi.length;i++){          MainFrame.this.saveAsAction.saveIt(edi[i].getFile(),edi[i]);        }        exit();      }      else ssd.resetAll();    }    public void actionPerformed(ActionEvent e){      this.gotSome=false;      Component[] edi=null;      if((edi=rightTabPan.getComponents()).length!=0)      {        for(int i=edi.length-1;i>=0;i--){          ContainEdi edit=(ContainEdi)edi[i];          if(edit.isModified()){//System.out.print("modify. ");            ssd.addQues(edit);            this.gotSome=true;          }        }        if(this.gotSome){ssd.addYorNListener(this);}        else exit();      }      else exit();    }  }  protected class EncodeChangeAction extends AbstractAction{    Hashtable ht=new Hashtable(3);    Vector mis=new Vector(2);    public EncodeChangeAction(){      super("encode change action");    }    public void registerNotifyer(String actionCommandString,String encName,JRadioButtonMenuItem jmi){      ht.put(actionCommandString,encName);      mis.add(jmi);    }    public void actionPerformed(ActionEvent e){      encoding=(String)ht.get(e.getActionCommand());      JRadioButtonMenuItem mi1=((JRadioButtonMenuItem)e.getSource());      mi1.setSelected(true);      for(int i=0;i<mis.size();i++){        JRadioButtonMenuItem mi2=(JRadioButtonMenuItem)mis.elementAt(i);        if(mi1!=mi2){mi2.setSelected(false);}      }    }  }  protected class UndoRedoHandle implements UndoRedoListener  { JButton undoBut,redoBut;    public void undo(){      try{currenEditor.getUndoManager().undo();}      catch(Exception e){e.printStackTrace();}      this.update();    }    public void redo(){      try{currenEditor.getUndoManager().redo();}      catch(Exception e){e.printStackTrace();}      this.update();    }    public UndoRedoHandle(JButton undoBut,JButton redoBut){      this.undoBut=undoBut;      this.redoBut=redoBut;    }    public void update(){      try{        if(currenEditor.getUndoManager().canRedo())          {this.redoBut.setEnabled(true);}        else this.redoBut.setEnabled(false);        if(currenEditor.getUndoManager().canUndo())          {this.undoBut.setEnabled(true);}        else this.undoBut.setEnabled(false);      }catch(Exception e){}    }    public void discardAllEdits(){      currenEditor.getUndoManager().discardAllEdits();    }  }  public static void main(String arg[]){    //Locale.setDefault(Locale.ENGLISH);    /*try{      UIManager.setLookAndFeel(	    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");    }catch(Exception e){}*/    MainFrame mf=new MainFrame();    mf.setBounds(60,20,690,540);    mf.show();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -