Package javax.swing

Examples of javax.swing.SwingWorker$DoSubmitAccumulativeRunnable


     * @param fileName
     * @param newThread specifica se avviare l'ispezione dei file in un nuovo thread
     */
    private void startInspect(final String fileName, boolean newThread) {
        if (newThread) {
            SwingWorker worker = new SwingWorker() {

                @Override
                protected String doInBackground() throws InterruptedException {
                    Layout.log("Inizio ispezione del file: " + fileName);
                    FileBugInspector inspector = new FileBugInspector(fileName);
                    inspector.inspect();
                    return null;
                }

                @Override
                protected void done() {
                    Layout.log("Fine ispezione del file" + fileName);
                }
            };
            worker.execute();
        } else {
            Layout.log("Inizio ispezione del file: " + fileName);
            FileBugInspector inspector = new FileBugInspector(fileName);
            inspector.inspect();
            Layout.log("Fine ispezione del file" + fileName);
View Full Code Here


                    layout.disableAll();
                    layout.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                }

                // Avvio thread
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected String doInBackground() throws InterruptedException {
                        BugUpdater bugUpdater = new BugUpdater();
                        bugUpdater.update(true);
                        return null;
                    }

                    @Override
                    protected void done() {
                        layout.enableAll();
                        layout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                    }
                };
                worker.execute();
                break;
            }
            case 2: {
                // Inizio l'analisi
                if (layout != null) {
                    layout.disableAll();
                    layout.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                }
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected String doInBackground() throws InterruptedException {
                        StartAnalyze analyzer = new StartAnalyze();
                        analyzer.start(false);
                        return null;
                    }

                    @Override
                    protected void done() {
                        layout.enableAll();
                        layout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                    }
                };
                worker.execute();
                break;
            }
            case 3: {
                // Creo la query sql per creare il database
                if (layout != null) {
                    layout.disableAll();
                    layout.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                }
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected String doInBackground() throws InterruptedException {
                        // Verifico l'esisteza di almeno un file da indicizzare
                        File f = new File(Indexer.path_for_data);
                        if ((!f.exists()) || (f.listFiles().length == 0)) {
                            Layout.log("Cartella da indicizzare " + f.getPath() + " vuota, aggiorno i file!!");
                            // Aggiorno i file di bug
                            BugUpdater bugUpdater = new BugUpdater();
                            bugUpdater.update(false);
                        }

                        // Se non avevo clacolato le priorità statiche lo faccio ora
                        if (StartAnalyze.finalPriority == null) {
                            StartAnalyze s = new StartAnalyze();
                            s.start(false);
                        }

                        Layout.clearLogger();
                        // Recupero le classificazioni degli script
                        ScriptClassification scriptClass = new ScriptClassification();
                        Hashtable classification = scriptClass.getClassification();
                        // Creo il database
                        SqliteDb db = new SqliteDb(false);

                        if (Layout.staticPriority.isSelected()) {
                            // Uso priorità statiche
                            db.createDbScript(StartAnalyze.finalPriority, classification);
                        } else {
                            // Inizializzo le priorità a 1
                            SqliteDb.setUseDefaultPriority(false);
                            db.createDbScript(StartAnalyze.finalPriority, classification);
                        }
                        return null;
                    }

                    @Override
                    protected void done() {
                        layout.enableAll();
                        layout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                    }
                };
                worker.execute();
                break;
            }
            case 4: {
                // Salvo il file Sql (forced)
                if (SqliteDb.query != null) {
View Full Code Here

                    layout.disableAll();
                    layout.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                }

                // Avvio thread
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected String doInBackground() throws InterruptedException {
                        BugUpdater bugUpdater = new BugUpdater();
                        bugUpdater.update(true);
                        return null;
                    }

                    @Override
                    protected void done() {
                        layout.enableAll();
                        layout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                    }
                };
                worker.execute();
                break;
            }
            case 2: {
                // Inizio l'analisi
                if (layout != null) {
                    layout.disableAll();
                    layout.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                }
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected String doInBackground() throws InterruptedException {
                        StartAnalyze analyzer = new StartAnalyze();
                        analyzer.start();
                        return null;
                    }

                    @Override
                    protected void done() {
                        layout.enableAll();
                        layout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                    }
                };
                worker.execute();
                break;
            }
            case 3: {
                // Creo la query sql per creare il database
                if (layout != null) {
                    layout.disableAll();
                    layout.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                }
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected String doInBackground() throws InterruptedException {
                        // Verifico l'esisteza di almeno un file da indicizzare
                        File f = new File(Indexer.path_for_data);
                        if ((!f.exists())||(f .listFiles().length == 0)) {
                            Layout.log("Cartella da indicizzare " + f.getPath() + " vuota, aggiorno i file!!");
                            // Aggiorno i file di bug
                            BugUpdater bugUpdater = new BugUpdater();
                            bugUpdater.update(false);
                        }
                       
                        // Se non avevo clacolato le priorità statiche lo faccio ora
                        if (StartAnalyze.finalPriority == null) {
                            StartAnalyze s = new StartAnalyze();
                            s.start();
                        }

                        Layout.clearLogger();
                        // Recupero le classificazioni degli script
                        ScriptClassification scriptClass = new ScriptClassification();
                        Hashtable classification = scriptClass.getClassification();
                        // Creo il database
                        SqliteDb db = new SqliteDb();
                        db.createDb(StartAnalyze.finalPriority, classification);
                        return null;
                    }

                    @Override
                    protected void done() {
                        layout.enableAll();
                        layout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                    }
                };
                worker.execute();
                break;
            }
            case 4: {
                // Salvo il file Sql (forced)
                if (SqliteDb.query != null) {
View Full Code Here

        menu.addScript(script);

        cliGuiCtx.getTabs().setSelectedIndex(1); // set to Output tab to view the output
        output.post("\n");

        SwingWorker scriptRunner = new ScriptRunner(script);
        scriptRunner.execute();
    }
View Full Code Here

          if(cross !=null){
            final JFileChooser fileChoose = new JFileChooser();
            fileChoose.setCurrentDirectory(new File(System.getProperty("user.dir")));
            fileChoose.setFileFilter(new CrosswordFileFilter());
            final int result = fileChoose.showSaveDialog(frame);
            @SuppressWarnings("rawtypes")
            SwingWorker save = new SwingWorker(){

              @Override
              protected Object doInBackground() throws Exception {
                switch (result){
                case JFileChooser.APPROVE_OPTION:

                  //creates the file chosen by the user
                  File output = fileChoose.getSelectedFile();
                  String filename = output.getPath();

                  //adds the extension if they forgot when naming it
                  if(!filename.endsWith(".crossword")){
                    filename = filename + ".crossword";
                  }
                  try {
                    CrosswordIO.writePuzzle(cross, filename);
                    JOptionPane.showMessageDialog(frame, "Crossword Saved");
                  } catch (IOException e) {
                    JOptionPane.showMessageDialog(frame, "Error saving, please try again");
                  }

                }               
                return null;
              }

            };
            save.execute();

          }else{
            JOptionPane.showMessageDialog(frame, "No Crossword open to save");
          }

        }

      });

      saveXML.addActionListener(new ActionListener(){

        /*
         * Saves the currently open crossword as a .xml file.
         */
        @Override
        public void actionPerformed(ActionEvent arg0) {

          //will only save if a crossword is open
          if(cross !=null){
            final JFileChooser fileChoose = new JFileChooser();
            fileChoose.setCurrentDirectory(new File(System.getProperty("user.dir")));
            fileChoose.setFileFilter(new XMLFileFilter());
            final int result = fileChoose.showSaveDialog(frame);
            @SuppressWarnings("rawtypes")
            SwingWorker save = new SwingWorker(){
              @Override
              protected Object doInBackground() throws Exception {

                switch (result){
                case JFileChooser.APPROVE_OPTION:

                  //creates the file chosen by the user
                  File output = fileChoose.getSelectedFile();
                  String filename = output.getPath();

                  //adds the extension if forgotten
                  if(!filename.endsWith(".xml")){
                    filename = filename + ".xml";
                  }
                  try {
                    CrosswordIO.writeXML(cross, filename);
                    JOptionPane.showMessageDialog(frame, "Crossword Saved");
                  } catch (IOException e) {
                    JOptionPane.showMessageDialog(frame, "Error saving, please try again", "Error Saving", JOptionPane.ERROR_MESSAGE);
                  } catch (ParserConfigurationException e) {
                    JOptionPane.showMessageDialog(frame, e.getMessage(), "Error Saving", JOptionPane.ERROR_MESSAGE);
                  } catch (SAXException e) {
                    JOptionPane.showMessageDialog(frame, e.getMessage(), "Error Saving", JOptionPane.ERROR_MESSAGE);
                  } catch (TransformerException e) {
                    JOptionPane.showMessageDialog(frame, e.getMessage(), "Error Saving", JOptionPane.ERROR_MESSAGE);
                  }

                }
                return null;
              }

            };
            save.execute();

          }else{
            JOptionPane.showMessageDialog(frame, "No Crossword open to save");
          }

View Full Code Here

        this.startTime = new Date().getTime();
    }
   
    @Override
    public void run() {
        SwingWorker worker = new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                // protection time for waiting events to work before script starts
                Thread.sleep(ptime);
               
                return new ScriptEngineManager().getEngineByName("AppleScript").eval(code);
            }
        };       
        worker.execute();

        try {
            // AppleScript から帰ってこなくなることがあるので,10秒戻ってこなかったら強制終了とする
            worker.get(10, TimeUnit.SECONDS);
            long past = new Date().getTime() - startTime;
            if (past > 500) {
                System.out.println("AppleScriptExecutor: Code below took more than 500msec!");
                System.out.println("AppleScriptExecutor: " +  code);
                System.out.println("AppleScriptExecutor: done in " + past + "msec");
View Full Code Here

            public void optionSelected(SheetEvent e) {
                if (e.getOption() == JFileChooser.APPROVE_OPTION) {
                    final File file = fileChooser.getSelectedFile();
                    if (!file.exists() || overwriteConfirmed(file)) {

                        SwingWorker worker = new SwingWorker<String, Void>() {

                            @Override
                            protected String doInBackground() throws Exception {
                                blockGlass.block();
                                ArrayList<StampTree> publishList = new ArrayList<StampTree>(IInfoModel.STAMP_ENTITIES.length);
                                List<StampTree> trees = stampBox.getAllTrees();
                                publishList.addAll(trees);
                                String ret = director.build(publishList);
                                return ret;
                            }

                            @Override
                            protected void done() {
                                String xml = null;
                                FileOutputStream fos = null;
                                OutputStreamWriter writer = null;

                                try {
                                    xml = get();
                                    fos = new FileOutputStream(file);
                                    writer = new OutputStreamWriter(fos, "UTF-8");
                                    // 書き出す内容
                                    writer.write(xml);
                                } catch (InterruptedException ex) {
                                    processException(ex);
                                } catch (ExecutionException ex) {
                                    processException(ex);
                                } catch (FileNotFoundException ex) {
                                    processException(ex);
                                } catch (UnsupportedEncodingException ex) {
                                    processException(ex);
                                } catch (IOException ex) {
                                    processException(ex);
                                } finally {
                                    try {
                                        writer.close();
                                        fos.close();
                                    } catch (IOException ex) {
                                        processException(ex);
                                    }
                                }
                                blockGlass.setText("");
                                blockGlass.unblock();
                            }

                            private void processException(Exception ex){
                                System.out.println("StampBoxPluginExtraMenu.java: " + ex);
                            }
                        };
                        worker.execute();
                    }
                }
            }
//masuda$
        });
View Full Code Here

        MyJSheet.showOpenSheet(fileChooser, context.getFrame(), new SheetListener() {
            public void optionSelected(SheetEvent e) {
                if (e.getOption() == JFileChooser.APPROVE_OPTION) {
                    final File file = fileChooser.getSelectedFile();

                    SwingWorker worker = new SwingWorker(){

                        @Override
                        protected Object doInBackground() throws Exception {
                            blockGlass.block();
                            try {
                                // xml ファイルから StampTree 作成
                                FileInputStream in = new FileInputStream(file);
                                BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        //masuda^   stampBytesを含めたデータを読み込む
                                ExtendedStampTreeBuilder builder = new ExtendedStampTreeBuilder();
                                ExtendedStampTreeDirector director = new ExtendedStampTreeDirector(builder);
        //masuda$
                                List<StampTree> userTrees = director.build(reader);
                                reader.close();

                                // StampTree に組み込む transfer handler を作っておく
                                StampTreeTransferHandler transferHandler = new StampTreeTransferHandler();
                               
                                for (final StampTree stampTree : userTrees) {
                                    // ORCA は無視
                                    if (stampTree.getEntity().equals(IInfoModel.ENTITY_ORCA)) {
                                        continue;
                                    }

                                    // 読み込んだ stampTree に transfer handler などを組み込む
                                    stampTree.setUserTree(true);
                                    stampTree.setTransferHandler(transferHandler);
                                    stampTree.setStampBox(context);
                                   
                                    // ポップアップメニュー組込
                                    final StampTreePopupMenu popup = new StampTreePopupMenu(stampTree);
                                    stampTree.addMouseListener(new MouseAdapter(){
                                        @Override
                                        public void mousePressed(MouseEvent e) { showPopup(e);}
                                        @Override
                                        public void mouseReleased(MouseEvent e) { showPopup(e);}

                                        private void showPopup(MouseEvent e) {
                                            if (e.isPopupTrigger()) {
                                                popup.show(stampTree, e.getX(), e.getY());
                                            }
                                        }
                                    });
                                   
                                    // StampTreePanel 作成
                                    StampTreePanel treePanel = new StampTreePanel(stampTree);

                                    // 作った StampTreePanel を該当する tab に replace
                                    String treeName = stampTree.getTreeName();
                                    int index = stampBox.indexOfTab(treeName);
                                    if (index == -1) {
                                        // 同じ名前のタブがなければ最後に加える
                                        stampBox.add(treeName, treePanel);
                                    } else {
                                        // 同じタブがあれば,replace
                                        stampBox.setComponentAt(index, treePanel);
                                    }
                                }                               

                            } catch (FileNotFoundException ex) {
                                processException(ex);
                            } catch (UnsupportedEncodingException ex) {
                                processException(ex);
                            } catch (IOException ex) {
                                processException(ex);
                            }
                            return null;
                        }

                        @Override
                        protected void done() {
                            blockGlass.setText("");
                            blockGlass.unblock();
                        }

                        private void processException(Exception ex) {
                            System.out.println("StampBoxPluginExtraMenu.java: " + ex);
                        }
                    };
                    worker.execute();
                }
            }
        });
    }
View Full Code Here

    // NOTE TO SELF: ErrorMarkers are calculated for the present tab only
    // Error Marker index in the arraylist is LOCALIZED for current tab.

     final int fheight = this.getHeight();
      SwingWorker worker = new SwingWorker() {

        protected Object doInBackground() throws Exception {
          return null;
        }

        protected void done() {
          int bigCount = 0;
          int totalLines = 0;
          int currentTab = 0;
          for (SketchCode sc : editor.getSketch().getCode()) {
            if (sc.isExtension("pde")) {
              sc.setPreprocOffset(bigCount);

              try {
                if (editor.getSketch().getCurrentCode().equals(sc)) {
                  // Adding + 1 to len because \n gets appended for each
                  // sketchcode extracted during processPDECode()
                  totalLines = Base.countLines(sc.getDocument().getText(
                      0, sc.getDocument().getLength())) + 1;
                  break;
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
            currentTab++;
          }
          // System.out.println("Total lines: " + totalLines);

          errorPointsOld.clear();
          for (ErrorMarker marker : errorPoints) {
            errorPointsOld.add(marker);
          }
          errorPoints.clear();

          // Each problem.getSourceLine() will have an extra line added because of
          // class declaration in the beginning
          for (Problem problem : problems) {
            if (problem.tabIndex == currentTab) {
              // Ratio of error line to total lines
              float y = problem.lineNumber / ((float) totalLines);
              // Ratio multiplied by height of the error bar
              y *= fheight - 15; // -15 is just a vertical offset
              errorPoints.add(new ErrorMarker(problem, (int) y, problem
                  .isError() ? ErrorMarker.Error : ErrorMarker.Warning));
              // System.out.println("Y: " + y);
            }
          }

          repaint();
        }
      };

      try {
        worker.execute(); // I eat concurrency bugs for breakfast.
      } catch (Exception exp) {
        System.out.println("Errorbar update markers is slacking."
            + exp.getMessage());
        // e.printStackTrace();
      }
View Full Code Here

    // If problems list is not visible, no need to update
    if (!this.isVisible())
      return false;

    SwingWorker worker = new SwingWorker() {

      protected Object doInBackground() throws Exception {
        return null;
      }

      protected void done() {

        try {
          setModel(tableModel);
         
          // Set column widths to user defined widths
          for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
            getColumnModel().getColumn(i).setPreferredWidth(
                columnWidths[i]);
          }
          getTableHeader().setReorderingAllowed(false);
          validate();
          repaint();
        } catch (Exception e) {
          System.out.println("Exception at XQErrorTable.updateTable " + e);
          // e.printStackTrace();
        }
      }
    };

    try {
      if (!columnResizing)
        worker.execute();
    } catch (Exception e) {
      System.out.println("ErrorTable updateTable Worker's slacking."
          + e.getMessage());
      // e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of javax.swing.SwingWorker$DoSubmitAccumulativeRunnable

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.