Package edu.harvard.wcfia.yoshikoder.util

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker


  protected void writeCsvUTF8(List<YKDocument> documents, File file) throws Exception {
    final List<YKDocument> docs = documents;
    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),
        Charset.forName("UTF8")));
   
    tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
              pushOutCountsCSVUtf8(docs, writer);
            }
            protected void onError() {
              try {
View Full Code Here


  protected void writeExcel(List<YKDocument> documents, File file) throws Exception {
    final List<YKDocument> docs = documents;
    final File outputFile = file;
    final FileOutputStream stream = new FileOutputStream(outputFile);

    tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
              pushOutCountsExcel(docs, stream);
            }
            protected void onError() {
              try {
View Full Code Here

            log.warning("couldn't decode bytes as system encoding");
        }
        encodings.setSelectedItem(new CharsetWrapper(cs));
        encodings.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                TaskWorker tworker = new TaskWorker(PreviewPanel.this.getTopLevelAncestor()){
                    String ns;
                    protected void doWork() throws Exception {
                        Charset newEnc = ((CharsetWrapper)encodings.getSelectedItem()).charset;
                        ns = new String(bytes, newEnc);
                    }
                    protected void onError() {}
                    protected void onSuccess() {
                        text.setText(ns); // actually *this* is the slow bit...
                        text.setCaretPosition(0);                        
                    }
                };
                tworker.start();
            }});
        setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        JPanel enc = new JPanel(new BorderLayout());
        enc.add(encodings, BorderLayout.CENTER);
        enc.add(new JLabel("Encoding: "), BorderLayout.WEST);
View Full Code Here

        String fname = concordanceSaver.getFile();
        if (fname == null) return;
       
        final File file =
            new File(concordanceSaver.getDirectory(), FileUtil.suffix(fname, "ykc"));
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
             
              YKDocument d = concordance.keySet().iterator().next();
                Concordance conc = concordance.get(d);
                int ws = conc.getWindowSize();
View Full Code Here

        String filename = projectExporter.getFile();
        if (filename==null) return;
        File f = new File(projectExporter.getDirectory(), filename);       
       
        final File file = FileUtil.suffix(f, "html", "htm");
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                ExportUtil.exportAsHTML(yoshikoder.getProject(), file);
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not export the project as HTML", e);
View Full Code Here

        String fname = documentExporter.getFile();
        if (fname == null) return;
       
        File filed = new File(documentExporter.getDirectory(), fname);
        final File file = FileUtil.suffix( filed, "txt");
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                FileUtil.save(file, doc.getText(), "UTF-8");
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not export the document", e); // TODO loc
View Full Code Here

        String filename = dictionaryExporter.getFile();
        if (filename == null) return;
       
        final File file = new File(dictionaryExporter.getDirectory(),
                FileUtil.suffix(filename, "html", "htm"));
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                ExportUtil.exportAsHTML(dict, file);
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not export dictionary as HTML", e);
View Full Code Here

                JOptionPane.PLAIN_MESSAGE);   
        if (i != JOptionPane.OK_OPTION)
            return;
               
        // parse the contents and insert the resulting dictionary
        tworker = new TaskWorker(yoshikoder){
            VBProFileParser parser = new VBProFileParser();
            protected void doWork() throws Exception {
                importedDictionary = parser.parse(f, preview.getSelectedEncoding().name());
                importedDictionary.setName(f.getName());
                if (parser.getErrors().size()>0)
View Full Code Here

        chooser.show();
        String fname = chooser.getFile();
        if (fname == null) return;

        final File f = new File(chooser.getDirectory(), fname);
        TaskWorker tworker = new TaskWorker(yoshikoder){
            TM tmd;
            protected void doWork() throws Exception {
                tmd =
                    TokenizationService.getTokenizationService().addTokenizerPlugin(f);
                log.info(tmd.name + "/" + tmd.description + "/" + tmd.classname + "/" + tmd.location);
            }
            protected void onError(){
                if (e instanceof DuplicatePluginException){
                    int resp = DialogUtil.askYesNo(yoshikoder,
                            "Replace existing plugin with this name?",
                            "Replace Tokenizer Plugin");
                    if (resp == JOptionPane.YES_OPTION){
                        // replace on the dispatch thread - not ideal
                        try {
                            TM tm =
                                TokenizationService.getTokenizationService().replaceTokenizerPlugin(tmd,f);
                            listModel.removeElement(tmd);
                            listModel.addElement(tm);
                            list.setSelectedValue(tm, true);
                            return;
                   
                        } catch (PluginException ple){
                            log.log(Level.WARNING, "Failed to replace tokenizer", ple);
                        }
                    } else {
                        // just leave things as they are
                        return;
                    }
                }
                String mess =
                    Messages.getString("TokenizerPluginsPanel.metadataExtractionFailure");
                DialogUtil.yelp(yoshikoder, mess, new PluginException(mess));
            }
            protected void onSuccess() {
                listModel.addElement(tmd);
                list.setSelectedValue(tmd, true);
            }
        };
        tworker.start();
    }
View Full Code Here

   
    protected void remove(){
        final int index = list.getSelectedIndex();
        if (index == -1) return; // nothing selected
       
        TaskWorker tworker = new TaskWorker(yoshikoder){
            TM tmd = null;
            protected void doWork() throws Exception {
                tmd = (TM)listModel.get(index);
                TokenizationService.getTokenizationService().removeTokenizerPlugin(tmd);
            }
            protected void onError() {
                String mess = Messages.getString("TokenizerPluginsPanel.removeFailure");
                DialogUtil.yelp(yoshikoder, mess, new PluginException(mess));
            }
            protected void onSuccess() {
                listModel.remove(index);
            }
        };
        tworker.start();
    }
View Full Code Here

TOP

Related Classes of edu.harvard.wcfia.yoshikoder.util.TaskWorker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.