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

📄 spellchecker.java

📁 文本编辑分析大师
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        //setLocation(140,85);//1024*768
        setLocation(0,0);//800*600
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

        try{Thread.sleep(99);}catch(InterruptedException ex){}
        startwin.resume();
        srcfile=new File(defaultTxt);
        if(!srcfile.exists()||!srcfile.canRead())
            System.out.println("源文件读取失败!");
        else{
            this.srcFileLoader(srcfile);//载入需要分析的源文件
        }
        try{Thread.sleep(99);}catch(InterruptedException ex){}
        startwin.resume();
        
        String text=null;
        try{
            String textTemp=styledpad.getEditor().getDocument().getText(0, styledpad.getEditor().getDocument().getLength());//获取刚修改的文本中的字符
            text=textTemp.concat(" ");
        }
        catch(BadLocationException ex){
            System.out.println("获取整个文本产成异常!\n"+ex.getClass()+"\n"+ex.getMessage());
        }
        CheckPorcessor precheckproc_pre = new CheckPorcessor(text,styledpad.getEditor().getDocument(),table,dirProc);
        precheckproc_pre.start();  //启动文本分析线程
        try{
            precheckproc_pre.join();//等待文本分析线程结束
        }catch(InterruptedException ex){}
        try{Thread.sleep(99);}catch(InterruptedException ex){}
        startwin.resume();
        try{Thread.sleep(1001);}catch(InterruptedException ex){}
        startwin.resume();
    }
    public static void main(String[] args) {
        SpellChecker mainFram=new SpellChecker();
    }
    
    private void confirmExit(){
        int choose = JOptionPane.showConfirmDialog(SpellChecker.this,"文件还没保存! 是否保存对文件的修改?","确认退出",JOptionPane.YES_NO_CANCEL_OPTION );
        String logfilepath=srcfile.getPath().substring(0,srcfile.getPath().length()-3)+"analyzer.log";
        if(choose == JOptionPane.YES_OPTION) {
            FileSaver(srcfile);//保存文件
            timer.stop();
            logFileSaver(new File(logfilepath));
            System.exit(0);
        }
        if(choose == JOptionPane.NO_OPTION) {
            timer.stop();
            logFileSaver(new File(logfilepath));
            System.exit(0);
        }
    }
    private void creatMenu(){
        JMenuBar menuBar;
        JMenu menu;
        JMenuItem menuItem;
        //创建菜单栏组件
        menuBar = new JMenuBar();
        this.setJMenuBar(menuBar);
        menu = new JMenu("文件(F)");
        menu.setMnemonic(KeyEvent.VK_F);
        menuItem = new JMenuItem("新建");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                styledpad.getEditor().setText("");
                isDocumentModified=false;
            }
        });
        menuItem = new JMenuItem("打开");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                srcFileLoader();
            }
        });
        menu.addSeparator();
        menuItem = new JMenuItem("保存");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                FileSaver(srcfile);
            }
        });
        menuItem = new JMenuItem("另存为...");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                FileSaver();
            }
        });
        menu.addSeparator();
        menuItem = new JMenuItem("自定义词典...");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                JFileChooser chooser = new JFileChooser();
                int retval = chooser.showOpenDialog(SpellChecker.this);
                if (retval != JFileChooser.APPROVE_OPTION) {
                    return;
                }
                directoryfile = chooser.getSelectedFile();
                dirProc=new DictionaryProcessor(directoryfile);//将词典文件中的单词存入TreeSet中
            }
        });
        
        menuItem = new JMenuItem("导出词典...");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                JFileChooser chooser = new JFileChooser();
                int retval = chooser.showSaveDialog(SpellChecker.this);
                if (retval != JFileChooser.APPROVE_OPTION) {
                    return;
                }
                File f = chooser.getSelectedFile();
                dirProc.ExtraDictionary(f);
            }
        });
        
        menuItem = new JMenuItem("导出分析记录...");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                JFileChooser chooser = new JFileChooser();
                int retval = chooser.showSaveDialog(SpellChecker.this);
                if (retval != JFileChooser.APPROVE_OPTION) {
                    return;
                }
                File file = chooser.getSelectedFile();
                logFileSaver(file);
            }
        });
        menu.addSeparator();
        menuItem = new JMenuItem("退出(E)");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK));
        menuItem.setMnemonic(KeyEvent.VK_E);
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                if(isDocumentModified)//如果文档被修改了
                    confirmExit();
                else{
                    timer.stop();
                    System.exit(0);
                }
            }
        });
        
        menuBar.add(menu);
        menu = new JMenu("编辑(E)");
        menu.setMnemonic(KeyEvent.VK_E);
        menuItem = new JMenuItem("剪切");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent actionevent){
                styledpad.getEditor().cut();
            }
        }
        );
        menuItem = new JMenuItem("复制");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                styledpad.getEditor().copy();
            }
        });
        menuItem = new JMenuItem("粘贴");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                styledpad.getEditor().paste();
            }
        });
        menu.addSeparator();
        undomenuItem= new JMenuItem("Undo");
        menu.add(undomenuItem);
        undomenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,InputEvent.CTRL_MASK));
        undomenuItem.addActionListener(styledpad.undoAction);
        
        redomenuItem= new JMenuItem("Redo");
        menu.add(redomenuItem);
        redomenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,InputEvent.CTRL_MASK));
        redomenuItem.addActionListener(styledpad.redoAction);
        menuBar.add(menu);
        
        menu = new JMenu("分析工具(A)");
        menu.setMnemonic(KeyEvent.VK_A);
        menuItem.addActionListener(spellmenuListener);
        menuItem = new JMenuItem("标记错误单词");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(spellmenuListener);
        menuItem = new JMenuItem("错误智能更正");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,InputEvent.CTRL_MASK));
        menu.add(menuItem);
        menuItem.addActionListener(spellmenuListener);
        menu.addSeparator();
        menuBar.add(menu);
        
        cbMenuItem_show = new JCheckBoxMenuItem("显示统计结果",false);        
        cbMenuItem_show.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent actionevent){
                if(cbMenuItem_show.isSelected()){
                    contentPane.removeAll();  
                    contentPane.validate();			
				    text_tablePanel.setLayout(new FlowLayout(FlowLayout.LEFT,5,0));
                    scroller_text.setPreferredSize(new Dimension(550,475));
                    scroller_table.setPreferredSize(new Dimension(230,475));
                    text_tablePanel.add(scroller_text);
                    text_tablePanel.add(scroller_table);                    
                    contentPane.add("North", toolbar);
                    contentPane.add("Center", text_tablePanel);
                    contentPane.add("South",statusbar);
                    contentPane.validate();          
                }
                else{
                	SpellChecker.this.setResizable(true);
                    contentPane.removeAll();
                    contentPane.validate();
                    contentPane.add("North", toolbar);
                    contentPane.add("Center",scroller_text);
                    contentPane.add("South",statusbar);
                    contentPane.validate();
                }
            }
        });
        menu.add(cbMenuItem_show);
        cbMenuItem_auto = new JCheckBoxMenuItem("自动语法检查",false);
        cbMenuItem_auto.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent actionevent){
                if(cbMenuItem_auto.isSelected())
                    isNeedAutoCheck=true;
                else
                    isNeedAutoCheck=false;
            }
        });
        menu.add(cbMenuItem_auto);
        
        ActionListener actionlistener;
        
        menu=new JMenu("字体设置(R)");
        menu.setMnemonic(KeyEvent.VK_R);
        for(int i=0;i<7;i++){
            menuItem = new JMenuItem((i*5+7)+"号");
            actionlistener = new StyledEditorKit.FontSizeAction("set-font",i*5+7);
            menuItem.addActionListener(actionlistener);
            menu.add(menuItem);
        }
        menuBar.add(menu);
        menu=new JMenu("颜色设置(C)");
        menu.setMnemonic(KeyEvent.VK_C);
        menuItem = new JMenuItem("Red(deprecate)");
        actionlistener = new StyledEditorKit.ForegroundAction("set-foreground-red", Color.red);
        menuItem.addActionListener(actionlistener);
        menu.add(menuItem);
        
        menuItem = new JMenuItem("Green");
        actionlistener = new StyledEditorKit.ForegroundAction("set-foreground-red", Color.green);
        menuItem.addActionListener(actionlistener);
        menu.add(menuItem);
        
        menuItem = new JMenuItem("Blue");
        actionlistener = new StyledEditorKit.ForegroundAction("set-foreground-red", Color.blue);
        menuItem.addActionListener(actionlistener);
        menu.add(menuItem);
        
        menuItem = new JMenuItem("Gray");
        actionlistener = new StyledEditorKit.ForegroundAction("set-foreground-red", Color.GRAY);
        menuItem.addActionListener(actionlistener);
        menu.add(menuItem);
        
        menuItem = new JMenuItem("Magenta");
        actionlistener = new StyledEditorKit.ForegroundAction("set-foreground-red", Color.magenta);
        menuItem.addActionListener(actionlistener);
        menu.add(menuItem);
        
        
        menuItem = new JMenuItem("Black");
        actionlistener = new StyledEditorKit.ForegroundAction("set-foreground-red", Color.black);
        menuItem.addActionListener(actionlistener);
        menu.add(menuItem);
        menuBar.add(menu);
        
        menu = new JMenu("风格(S)");
        menu.setMnemonic(KeyEvent.VK_S);//创建快捷方式
        StyleListener stylelistener=new  StyleListener(); //生成监听器实例对象
        menuItem = new JMenuItem("Windows");
        menuItem.setMnemonic(KeyEvent.VK_W);
        menu.add(menuItem);
        menuItem.addActionListener(stylelistener);  // 注册监听器
        menuItem = new JMenuItem("Metal");
        menuItem.setMnemonic(KeyEvent.VK_M);
        menu.add(menuItem);
        menuItem.addActionListener(stylelistener);  // 注册监听器
        menuItem = new JMenuItem("Motif");
        menuItem.setMnemonic(KeyEvent.VK_O);
        menu.add(menuItem);
        menuItem.addActionListener(stylelistener);  // 注册监听器
        menuBar.add(menu);
        
        menuBar.add(menu);
        menu = new JMenu("帮助(H)");
        menu.setMnemonic(KeyEvent.VK_H);
        menuBar.add(menu);
        menuItem = new JMenuItem("帮助");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                JOptionPane.showMessageDialog(SpellChecker.this,"help","帮助",JOptionPane.INFORMATION_MESSAGE,new ImageIcon("images/help.png"));
            }
        });
        menuItem = new JMenuItem("关于");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,InputEvent.CTRL_MASK));
        menuItem.addActionListener(new ActionListener(){

⌨️ 快捷键说明

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