/**编辑器test Edition
*EditFace实现了界面制作;
*EditFace$FileOpen完成了打开文件功能;
*EditFace$FileSave完成了保存文件功能;
*Edit$FindAndReplace查找与替换窗口;
*Edit$AutoSave自动备分文件线程;
*Edit$SaveFileDialog保存文件对话框;
*SetKey添加关键字;
*SetColor设置颜色;
*About程序基本介绍;
*Edit组合各个窗口,并实现功能。
*by KOF 10-27-2004
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;
class Edit extends EditFace implements ActionListener,ClipboardOwner,MouseListener,TextListener
{
public int flag=0;
//判断文件是否被修改
SetKey setkey=new SetKey();
//添加关键字类
static SetColor setcolor=new SetColor();
//设置颜色类
Clipboard myclipboard=f.getToolkit().getSystemClipboard();
FindAndReplace fr=new FindAndReplace();
//查找与替换内部类
String information="您希望保存当前文件吗?";
SaveFileDialog sfd=new SaveFileDialog(f,"Save File--Test Edition",true,information);
//弹出保存文件对话框
public Edit()
{
super();
ta.addTextListener(this);
//添加自动保存文件线程---每两分钟保存一次
AutoSave as=new AutoSave();
as.start();
}
public static void main(String[] args)
{
new Edit();
setcolor.set(setcolor);
}
public void lostOwnership(Clipboard db,Transferable contents)
{
}
public void textValueChanged(TextEvent e)
{
flag=1;//文件内容以改变~
}
//如果内容已变,弹出保存文件对话框,保持文件
public void saveFile()
{
if(flag==1)
{
sfd.setVisible(true);//弹出保存文件对话框
if(sfd.isSave==1&&!tfpath.getText().equals(""))
{
FileSave fs=new FileSave();
fs.myFileSave(tfpath.getText());
}
else if((sfd.isSave==1&&tfpath.getText().equals(""))||sfd.isSave==2)
{
FileSave fs=new FileSave();
fs.myFileSave();
}
}
}
public void windowClosing(WindowEvent e)
{
saveFile();//询问是否保存当前文件
System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
//Open File
if(e.getActionCommand()=="Open")
{
saveFile();//询问是否保存当前文件
FileOpen fo=new FileOpen();
fo.myFileOpen();//打开文件
ta.select(0,0);
flag=0;
}
//Save File
if(e.getActionCommand()=="Save")
{
if(tfpath.getText().equals(""))
{
FileSave fs=new FileSave();//保存文件
fs.myFileSave();
}
else
{
FileSave fs=new FileSave();//保存文件
fs.myFileSave(tfpath.getText());
}
flag=0;
}
//Save As a File
if(e.getActionCommand()=="Save As")
{
FileSave fs=new FileSave();
fs.myFileSave(); //保存文件
flag=0;
}
if(e.getActionCommand()=="Exit")
{
saveFile();//询问是否保存当前文件
System.exit(0);
}
//set color
if(e.getActionCommand()=="SetColor")
{
setcolor.setVisible(true);//设置文本区颜色
ta.setForeground(setcolor.newcolor);
}
//clear all content
if(e.getSource()==bclearall)
{
saveFile();//询问是否保存当前文件
tfpath.setText("");//清除
ta.setText("");
}
//set key
if(e.getSource()==bsetkey)
{
setkey.setVisible(true);//设置关键字
}
//set color
if(e.getSource()==bcolor)
{
setcolor.setVisible(true);//设置文本区颜色
ta.setForeground(setcolor.newcolor);
}
if(e.getActionCommand()=="Copy")//复制到剪贴板
{
if(!ta.getSelectedText().equals(""))
{
try
{
StringSelection contents=new StringSelection(ta.getSelectedText());
myclipboard.setContents(contents,this);
ta.select(ta.getSelectionEnd(),ta.getSelectionEnd());
}
catch(Exception ee)
{
System.out.println(ee);
}
}
}
if(e.getActionCommand()=="Cut")//复制到剪贴板并清楚内容
{
if(!ta.getSelectedText().equals(""))
try
{
int startpos=ta.getSelectionStart();//start position
int endpos=ta.getSelectionEnd();
StringSelection contents=new StringSelection(ta.getSelectedText());
myclipboard.setContents(contents,this);
ta.setText(ta.getText().substring(0,startpos)+ta.getText().substring(endpos,ta.getText().length()));
ta.select(startpos,startpos);
}
catch(Exception ee)
{
System.out.println(ee);
}
}
if(e.getActionCommand()=="Paste")//粘贴
{
try
{
Transferable contents=myclipboard.getContents(this);
String dstdata=(String)contents.getTransferData(DataFlavor.stringFlavor);
int startpos=ta.getSelectionStart();
int endpos=ta.getSelectionEnd();
ta.setText(ta.getText().substring(0,startpos)+dstdata+ta.getText().substring(endpos,ta.getText().length()));
ta.select(startpos+dstdata.length(),startpos+dstdata.length());
}
catch(Exception ee)
{
System.err.println(ee);
}
}
if(e.getActionCommand()=="Select All")//全选功能的实现
{
ta.select(0,ta.getText().length());
}
if(e.getActionCommand()=="Find")//查找功能的实现
{
fr.setVisible(true);
fr.setEnabled(false);
}
if(e.getActionCommand()=="Replace")//替换功能的实现
{
fr.setVisible(true);
fr.setEnabled(true);
}
if(e.getActionCommand()=="About Edit"||e.getActionCommand()=="About Me")
{
About about=new About();
about.setVisible(true);
}
}
//change the color
public void mouseClicked(MouseEvent mec) //单击文本区才会改变颜色
{ ta.setForeground(setcolor.newcolor); }
public void mousePressed(MouseEvent mep)
{
if(mep.getModifiers()==mep.BUTTON3_MASK)//弹出右键菜单
pm.show(ta,mep.getX(),mep.getY());
}
public void mouseReleased(MouseEvent mer) { }
public void mouseEntered(MouseEvent mee) { }
public void mouseExited(MouseEvent mex) { }
public void mouseDragged(MouseEvent med) { }
//查找与替换窗口
class FindAndReplace extends WindowAdapter implements ActionListener
{
private Frame frame;
private TextField tffind,tfreplace;
private Label labfind,labreplace;
private Button bfind,bfindnext,breplace,breplaceall;
private Panel p1,p2,p3,p4;
private Label labinfo;
private String info="";
private int pos;
public FindAndReplace()
{
frame=new Frame("Find And Replace--Test Edition");
frame.setLayout(new GridLayout(3,1));
frame.setSize(300,200);
frame.setLocation(80,20);
frame.setBackground(Color.lightGray);
p1=new Panel();
p1.setLayout(new GridLayout(2,1));
labfind=new Label("Please input what you want to search:");
tffind=new TextField(25);
p1.add(labfind);
p1.add(tffind);
p2=new Panel();
p2.setLayout(new GridLayout(2,1));
labreplace=new Label("Please input what you want to replace:");
tfreplace=new TextField(25);
p2.add(labreplace);
p2.add(tfreplace);
p3=new Panel();
p3.setLayout(new FlowLayout(FlowLayout.LEFT));
bfind=new Button(" Find ");
bfindnext=new Button("Find Next");
breplace=new Button(" Replace ");
breplaceall=new Button("Replace All");
bfind.addActionListener(this);
bfindnext.addActionListener(this);
breplace.addActionListener(this);
breplaceall.addActionListener(this);
p3.add(bfind);
p3.add(bfindnext);
p3.add(breplace);
p3.add(breplaceall);
p4=new Panel();
p4.setLayout(new GridLayout(2,1));
labinfo=new Label();
p4.add(p3);
p4.add(labinfo);
frame.addWindowListener(this);
frame.add(p1);
frame.add(p2);
frame.add(p4);
}
public void setVisible(boolean b)
{
frame.setVisible(b);
pos=0;
ta.select(pos,pos);
}
public void setEnabled(boolean b)
{
tfreplace.setEnabled(b);
breplace.setEn
没有合适的资源?快使用搜索试试~ 我知道了~
java实现一款编辑器的源码
共13个文件
class:10个
bat:1个
java:1个
5星 · 超过95%的资源 需积分: 9 29 下载量 191 浏览量
2011-02-25
11:32:43
上传
评论 1
收藏 27KB RAR 举报
温馨提示
java实现一款编辑器的源码 java实现一款编辑器的源码 java实现一款编辑器的源码java实现一款编辑器的源码
资源推荐
资源详情
资源评论
收起资源包目录
java实现一款编辑器的源码.rar (13个子文件)
编辑器程序
edit.bat 56B
About.class 5KB
Edit.class 6KB
key.dat 33B
edit.java 27KB
EditFace$FileOpen.class 2KB
Edit$SaveFileDialog.class 2KB
EditFace$FileSave.class 2KB
EditFace.class 6KB
Edit$AutoSave.class 1KB
Edit$FindAndReplace.class 5KB
SetKey.class 4KB
SetColor.class 3KB
共 13 条
- 1
资源评论
- renmin200628622013-07-04不错 功能都实现了
- nianhua3212013-08-22不错 功能都实现了
- alachun_luxu2013-12-03不太好用,唉,看了好久了
有庙无僧风扫地
- 粉丝: 4
- 资源: 59
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功