package ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;/*** Autho : showncx* time : Oct 14, 2008 8:31:00 AM* insert here....*/public class NoteBook extends JFrame implements ActionListener{private static final long serialVersionUID = 1L;private JFileChooser fileDialog;private JTextArea content;private JDialog dialog;private JPopupMenu jpm;private JTextField rep_word1,rep_word2;private String rep_director,rep_newword;private JLabel rep_mes1,rep_mes2;// private boolean isUndo = false;private String fileInfo = null;private String[] menus = new String[]{"File","Edit","Format","View","Help"};private String[][] menuItems = new String[][]{{"new","open","save","anotherSave","","setter","print","exit"},{"undo","","cut","copy","paste","delete","","forward/replace","goto","","allselect","time/date"},{"auto_change","font"},{"status"},{"help"}};private String[] popItems = new String[]{"undo","","cut","copy","paste","delete","selectall","","a_it's so short want it longger..."};// private LinkedList oldContent = new LinkedList();private UndoManager undoManager;/*** the constructor*/public NoteBook(){super("NoteBook");initJPopMenu();undoManager = new UndoManager();fileDialog = new JFileChooser();(new File("E:\\")) ;content = new JTextArea();().addUndoableEditListener(undoManager);// ().addDocumentListener(new DocumentListener(){//// public void changedUpdate(DocumentEvent e) {// if(!isUndo){//// (());// isUndo = false;// }//// isUndo = false;// }//// public void insertUpdate(DocumentEvent e) {// if(!isUndo){//// (());// ("insert--update");// isUndo = false;// }// isUndo = false;// }//// public void removeUpdate(DocumentEvent e) {// if(!isUndo){//// (());// isUndo = false;// }//// isUndo = false;// }// });(new MouseAdapter(){@Overridepublic void mouseClicked(MouseEvent e) {if(() == 3){(content, (), ());}}});(new Font("font1",25,25));JScrollPane jsp = new JScrollPane(content);(jsp);(getMenuBar(menuItems,menus));();(500,400);(200,200);();(true);}//end constructor//------------------------------------------------------------------------------------------------------/*** for the pop_bar right click*/public void initJPopMenu(){jpm = new JPopupMenu();for(int i = 0 ; i < ; i ++){String popItemName = popItems[i];if("".equals(popItemName)){();}else{JMenuItem jmItem = new JMenuItem(popItemName);((0));(this);(jmItem);}}}//------------------------------------------------------------------------------------------------------//------------------------------------------------------------------------------------------------------/*** init the menuBar* */public JMenuBar getMenuBar(String[][] menuItens,String[] menus){JMenuBar jmb = new JMenuBar();for(int i = 0; i < ; i ++){String jmName = menus[i];JMenu jm = new JMenu(jmName);((0));for(int j = 0; j < menuItems[i].length ; j ++){if(!"".equals(menuItems[i][j])){String itemName = menuItems[i][j];JMenuItem jmItem = new JMenuItem(itemName) ;if("undo".equals(menuItems[i][j])){(());}else if("cut".equals(itemName)){(());}else if("copy".equals(itemName)){(());}else if("paste".equals(itemName)){(());}else if("forward/replace".equals(itemName)){(());}else if("selectall".equals(itemName)){(());}else if("new".equals(itemName)){(());}else if("open".equals(itemName)){(());}else if("save".equals(itemName)){(());}else if("font".equals(itemName)){(());}else if("exit".equals(itemName)){('e');}(this);(jmItem);}else{();}}(jm);}return jmb;}//-------------------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------------------/*** //create the forward/replace dialog*/public JDialog createDialog(){JDialog dialog = new JDialog(this,"forward/repalce");rep_mes1 = new JLabel("the word you want to replace..");rep_mes2 = new JLabel("the one replace to the oldone...");rep_word1 = new JTextField();rep_word2 = new JTextField();JButton rep_btn = new JButton("replace");(new ActionListener(){public void actionPerformed(ActionEvent e) {String contentAll = ();rep_director = ();rep_newword = ();(rep_newword, (rep_director), (rep_director)+());}});JButton rep_btn2 = new JButton("forward");(new ActionListener(){public void actionPerformed(ActionEvent e) {int selectEnd = ();if(selectEnd == 0 || selectEnd == -1 || selectEnd >= ().length()){selectEnd = 0;}rep_director = ();int nextStart = ().indexOf(rep_director,selectEnd);(nextStart);(nextStart+());}});(new GridLayout(4,1,2,2));(rep_mes1);(rep_word1);(rep_mes2);(rep_word2);(rep_btn);(rep_btn2);return dialog;}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String currentOper = ();if("new".equals(currentOper)){String currentContent = ();if("".equals(currentContent) || currentContent == null){("");}else{/*** 关于新建的操作.....*/}}else if("open".equals(currentOper)){("");(this);File selectedFile = ();if(selectedFile != null){fileInfo = ();try {(());InputStream filein = new FileInputStream(selectedFile);byte[] temp = new byte[20];while(true){int i = (temp);if( i == -1) break;(()+new String(temp,0,i));}();} catch (FileNotFoundException e1) {();}catch (IOException e1) {();}}}else if("save".equals(currentOper)){// ();if( null != fileInfo){try {File currentFile = new File(fileInfo);OutputStream fileout = new FileOutputStream(currentFile);byte[] temp = ().getBytes();(temp);();} catch (FileNotFoundException e1) {();}catch (IOException e2) {();}}else{(this);String dir = ().getPath();String fileName = ().getName();if(!"".equals(fileName) && fileName != null){try {File currentFile = new File(dir,fileName);OutputStream fileout = new FileOutputStream(currentFile);byte[] temp = ().getBytes();(temp);();} catch (FileNotFoundException e1) {();}catch (IOException e2) {();}}}}else if("anotherSave".equals(currentOper)){(this);String dir = ().getPath();String fileName = ().getName();if(!"".equals(fileName) && fileName != null){try {File currentFile = new File(dir,fileName);OutputStream fileout = new FileOutputStream(currentFile);byte[] temp = ().getBytes();(temp);();} catch (FileNotFoundException e1) {();}catch (IOException e2) {();}}}else if("exit".equals(currentOper)){(0);}else if("undo".equals(currentOper)){if(()){();}/*isUndo = true;// ("undo之前的记录集合:--"+());if(() > 0){((()-2));// ("当前想要删除的字符串:--"+(()-1));// ("没有删除之前的记录集合长度:--"+());(()-1);// ("删除之后的记录集合长度:--"+()+"&&&&&");}("undo之后的记录集合:--"+());*/}else if("cut".equals(currentOper)){// (());();}else if("copy".equals(currentOper)){();}else if("paste".equals(currentOper)){();}else if("delete".equals(currentOper)){("");}else if("forward/replace".equals(currentOper)){dialog = createDialog();(300,150);(250, 250);(true);}else if("selectall".equals(currentOper)){(0);(().length());}else if("auto_change".equals(currentOper)){}else if("font".equals(currentOper)){TableDialogFont fontDlg = new TableDialogFont();Font f = ();(f,content);("设置字体");(null);(true);(true);}else if("help".equals(currentOper)){}}public static void main(String[] args) {// TODO Auto-generated method stubnew NoteBook();}}