| |
public void frame_windowclose_windowclosing(windowlistener e){ this.close(); } ///////////////////////////////////////////////////////// public void text_mouseclicked(mouseevent e){ if(e.getmodifiers()==inputevent.button3_mask){ pop.show((component)e.getsource(),e.getx(),e.gety()); } } public void text_ancestoradded(ancestorevent e){ this.dirty=false; this.newtext(); } public void text_caretupdate(caretevent e) { this.dirty=true; //this.statubar.settext(this.text.gettext()); } ///////////// file ///////////////////////////////////// public void file_open_actionperformed(actionevent e){ //打开的事件 this.opentext(); }
public void file_new_actionperformed(actionevent e){ ///新建的事件 this.newtext(); }
public void file_save_actionperformed(actionevent e){ //保存的事件 this.save(); }
public void file_saveas_actionperformed(actionevent e){ //另存为 this.saveas(); } public void file_quite_actionperformed(actionevent e){ this.close(); } ////////////////// edit ///////////////////////////////////// public void edit_undo_actionperformed(actionevent e){ //撤销 this.undo(); } public void edit_cut_actionperformed(actionevent e){ //剪切 this.cut(); } public void edit_copy_actionperformed(actionevent e){ //复制 this.copy(); } public void edit_paste_actionperformed(actionevent e){ //粘贴 this.paste(); } public void edit_delete_actionperformed(actionevent e){ //删除 this.delete(); } public void edit_find_actionperformed(actionevent e){ //查找 int cu=this.text.getcaretposition(); int end=this.text.gettext().length(); finddlg fd=new finddlg(frame,"查找",true); fd.show(); string str=fd.getfindstr().trim();
if(fd.getflag()){ this.nextfindstr(str,cu,end); }else{ this.upfindstr(str,cu); }
} public void edit_replace_actionperformed(actionevent e){ //替换 int cu=this.text.getcaretposition(); int end=this.text.gettext().length(); replacedlg rd=new replacedlg(frame,"替换",true); rd.show(); this.replacestr(rd.findstr().trim(),rd.replacestr().trim(),cu,end); } public void edit_selectall_actionperformed(actionevent e){ //全选 this.text.setselectionstart(0); this.text.setselectionend(this.text.gettext().length()); } public void edit_timedate_actionperformed(actionevent e){ //时间日期 simpledateformat sdf = new simpledateformat("yyyy-mm-dd hh:mm:ss"); this.text.append("/r/n当前时间:"+sdf.format(new date())); } ///////////// format////////////////////////////////////// public void format_word_actionperformed(actionevent e){ //自动换行 if(!this.text.getlinewrap()){ this.text.setlinewrap(true); } else{ this.text.setlinewrap(false); } } public void format_font_actionperformed(actionevent e){ //字体"常规","斜体","粗体","粗斜体" font cur=this.text.getfont(); int type=font.bold; fontset fs=new fontset(frame,"字体设置",true); fs.show(); if(fs.flag){ switch(fs.font2()){ case 0:type=font.plain;break; case 1:type=font.99valic;break; case 2:type=font.bold; break; case 3:type=font.roman_baseline;break; default:type=font.plain;break; } font f=new font(fs.font1(),type,16); this.text.setfont(f); }else{ this.text.setfont(cur); } } public void format_color_actionperformed(actionevent e){ // 颜色 color current=this.text.getforeground(); this.jcolor.setcolor(current); this.text.setforeground( this.jcolor.showdialog(text,"选择颜色",current));
} //////////////////// help ///////////////////////////////////// public void help_about_actionperformed(actionevent e){ //关于作者 new aboutdlg(); } //////////////////////////////////////////////////////// public void pop_undo_actionperformed(actionevent e){ //pop undo this.undo(); } public void pop_cut_actionperformed(actionevent e){ //pop cut this.cut(); } public void pop_copy_acionperformed(actionevent e){ //pop copy this.copy(); } public void pop_paste_actionperformed(actionevent e){ //pop paste this.paste(); } public void pop_delete_actionperformed(actionevent e){ //pop delete this.delete(); }
/************************************************************ ///////////////////////////////////////////////////////////// ////////////// coustm function /////////////////////////////// ///////////////////////////////////////////////////////////// ************************************************************/
void close(){
if(this.dirty){ dlgtext dt=new dlgtext(frame,"提示",true); dt.show(); if(dt.getcheck()){ this.save(); } else { frame.dispose(); system.exit(0); } }else{ frame.dispose(); system.exit(0);
} } void newtext(){//新建 if((!this.dirty)||(!this.saveas())){ this.text.settext(""); this.text.setfocusable(true); this.frame.settitle("未命名-----author:jeason"); this.statubar.settext("新建文本"); } else this.saveas(); }
void opentext(){//打开 // string strfileopen=""; if(!this.dirty){ try{ if(this.jfilechooser1.approve_option== this.jfilechooser1.showopendialog(frame)){ strfileopen=this.jfilechooser1.getselectedfile().getpath();
file file=new file(strfileopen); int flength=(int)file.length(); int num=0; filereader freader=new filereader(file); char[] data=new char[flength]; while(freader.ready()){ num+=freader.read(data,num,flength-num); } freader.close(); this.text.settext(new string(data,0,num)); this.filename=strfileopen; this.frame.settitle(this.filename); this.statubar.settext("open file:"+this.filename); this.dirty=false; }else { return ; } }catch(exception e){ this.statubar.settext("error open:"+e.getmessage()); } }else{ this.save(); } } boolean save(){//保存 if(this.dirty){ if(this.filename.length()!=0){ try{ file savefile=new file(this.filename);
filewriter fw=new filewriter(savefile); fw.write(this.text.gettext()); fw.close(); this.dirty=false; this.statubar.settext("保存文件:"+this.filename); return true; }catch(exception e) { this.statubar.settext("保存出错: "+e.getmessage()); return false; } }else{ return this.saveas(); } }else{ return true; } }
boolean saveas(){//另存为 if(this.jfilechooser1.approve_option==this.jfilechooser1.showsavedialog(frame)){ this.filename=this.jfilechooser1.getselectedfile().g
|
|