Package javax.swing

Examples of javax.swing.SwingWorker


    this.directed = false;
  }

  public void start(boolean return_when_done)
  {
    SwingWorker worker = new SwingWorker()
    {
      protected Object doInBackground() throws Exception
      {
        return new NodeDistance.NodeDistancesTask();
      }
    };
    worker.execute();

    if (return_when_done)
      try
      {
        worker.get();
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (ExecutionException e) {
        e.printStackTrace();
      }
View Full Code Here


      final Cluster cluster = (Cluster)ResultPanel.this.clusters.get(this.selectedRow);
      final CyNetwork clusterNetwork = cluster.getNetwork();
      final String title = this.trigger.getResultId() + ": " + cluster.getName() + " (Score: " +
        nf.format(cluster.getScore()) + ")";

      SwingWorker worker = new SwingWorker()
      {
        protected CyNetworkView doInBackground() throws Exception
        {
          CySubNetwork newNetwork = ResultPanel.this.mcodeUtil.createSubNetwork(clusterNetwork, clusterNetwork.getNodeList(),
            SavePolicy.SESSION_FILE);
          newNetwork.getRow(newNetwork).set("name", title);

          VisualStyle vs = ResultPanel.this.mcodeUtil.getNetworkViewStyle(ResultPanel.this.networkView);
          CyNetworkView newNetworkView = ResultPanel.this.mcodeUtil.createNetworkView(newNetwork, vs);

          newNetworkView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION, Double.valueOf(0.0D));
          newNetworkView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION, Double.valueOf(0.0D));

          ResultPanel.this.mcodeUtil.displayNetworkView(newNetworkView);

          boolean layoutNecessary = false;
          CyNetworkView clusterView = cluster.getView();

          for (View nv : newNetworkView.getNodeViews()) {
            CyNode node = (CyNode)nv.getModel();
            View cnv = clusterView != null ? clusterView.getNodeView(node) : null;

            if (cnv != null)
            {
              double x = ((Double)cnv.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION)).doubleValue();
              double y = ((Double)cnv.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION)).doubleValue();
              nv.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, Double.valueOf(x));
              nv.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, Double.valueOf(y));
            }
            else
            {
              double w = ((Double)newNetworkView.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH)).doubleValue();
              double h = ((Double)newNetworkView.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT)).doubleValue();

              nv.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, Double.valueOf(w * Math.random()));

              nv.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, Double.valueOf((h + 100.0D) * Math.random()));

              layoutNecessary = true;
            }
          }

          if (layoutNecessary) {
            SpringEmbeddedLayouter lay = new SpringEmbeddedLayouter(newNetworkView);
            lay.doLayout(0.0D, 0.0D, 0.0D, null);
          }

          newNetworkView.fitContent();
          newNetworkView.updateView();

          return newNetworkView;
        }
      };
      worker.execute();
    }
View Full Code Here

  }

 
  public void start(boolean return_when_done) {
    // TODO Auto-generated method stub
    SwingWorker worker = new SwingWorker() {

      final NodeDistances this$0;

      protected Object doInBackground()
        throws Exception
      {
        return new NodeDistancesTask();
      }

     
      {
        this$0 = NodeDistances.this;
        //super();
      }
    };
    worker.execute();
    if (return_when_done)
      try
      {
        worker.get();
      }
      catch (InterruptedException e)
      {
        e.printStackTrace();
      }
View Full Code Here

      }
      // Don't need to clear compiler error messages
      if(type == STATUS_COMPILER_ERR) return;
     
      // Clear the message after a delay
      SwingWorker s = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
          try {
            Thread.sleep(2 * 1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          statusEmpty();
          return null;
        }
      };
      s.execute();
    }
View Full Code Here

      }
      if(evt.isAltDown() || evt.isControlDown() || evt.isMetaDown()){
        return;
      }
      final KeyEvent evt2 = evt;     
      SwingWorker worker = new SwingWorker() {
        protected Object doInBackground() throws Exception {
          log("[KeyEvent]" + evt2.getKeyChar() + "  |Prediction started: " + System.currentTimeMillis());
          errorCheckerService.runManualErrorCheck();
          // Provide completions only if it's enabled
          if(ExperimentalMode.codeCompletionsEnabled)
            log("Typing: " + fetchPhrase(evt2) + " "
                + (evt2.getKeyChar() == KeyEvent.VK_ENTER) + " T: " + System.currentTimeMillis());
          return null;
        }
      };
      worker.execute();
    }

   
  }
View Full Code Here

      public void changedUpdate(DocumentEvent e) {
        updateSelection();
      }
     
      private void updateSelection(){
        SwingWorker worker = new SwingWorker() {
          protected Object doInBackground() throws Exception {
            String text = searchField.getText().toLowerCase();
            tempNode = new DefaultMutableTreeNode();
            filterTree(text, tempNode, soNode);
            return null;
          }

          protected void done() {           
            soTree.setModel(new DefaultTreeModel(tempNode));
            ((DefaultTreeModel) soTree.getModel()).reload();
            for (int i = 0; i < soTree.getRowCount(); i++) {
              soTree.expandRow(i);
            }
            internalSelection = true;
            soTree.setSelectionRow(0);
          }
        };
        worker.execute();
      }
    });

    frmOutlineView.addWindowFocusListener(new WindowFocusListener() {
      public void windowLostFocus(WindowEvent e) {
        close();
      }

      public void windowGainedFocus(WindowEvent e) {
      }
    });

    soTree.addTreeSelectionListener(new TreeSelectionListener() {

      public void valueChanged(TreeSelectionEvent e) {

        if (internalSelection) {
          internalSelection = (false);
          return;
        }
        // log(e);
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
            if (soTree.getLastSelectedPathComponent() == null) {
              return;
            }
            DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) soTree
                .getLastSelectedPathComponent();
            if (tnode.getUserObject() instanceof ASTNodeWrapper) {
              ASTNodeWrapper awrap = (ASTNodeWrapper) tnode.getUserObject();
              // log(awrap);
              errorCheckerService.highlightNode(awrap);
            }
          }
        };
        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.
    // Also, need to do the update in the UI thread to prevent concurrency issues.
    final int fheight = this.getHeight();
    SwingWorker worker = new SwingWorker() {

      protected Object doInBackground() throws Exception {
        SketchCode sc = editor.getSketch().getCurrentCode();
        int totalLines = 0, currentTab = editor.getSketch()
            .getCurrentCodeIndex();
        try {
          totalLines = Base.countLines(sc.getDocument()
              .getText(0, sc.getDocument().getLength())) + 1;
        } catch (BadLocationException e) {
          e.printStackTrace();
        }
        // System.out.println("Total lines: " + totalLines);
        synchronized (errorPoints) {
          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 as well as default imports
          synchronized (problems) {
            for (Problem problem : problems) {
              if (problem.getTabIndex() == currentTab) {
                // Ratio of error line to total lines
                float y = (problem.getLineNumber() - errorCheckerService.defaultImportsOffset)
                    / ((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);
              }
            }
          }
        }
        return null;
      }

      protected void done() {
        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

      // Find out which error/warning the user has clicked
      // and then scroll to that
      @SuppressWarnings("rawtypes")
      @Override
      public void mouseClicked(final MouseEvent e) {
        SwingWorker worker = new SwingWorker() {

          protected Object doInBackground() throws Exception {
            for (ErrorMarker eMarker : errorPoints) {
              // -2 and +2 are extra allowance, clicks in the
              // vicinity of the markers register that way
              if (e.getY() >= eMarker.getY() - 2
                  && e.getY() <= eMarker.getY() + 2 + errorMarkerHeight) {
                errorCheckerService.scrollToErrorLine(eMarker.getProblem());
                return null;
              }
            }
            return null;
          }
        };

        try {
          worker.execute();
        } catch (Exception exp) {
          System.out.println("Errorbar mouseClicked is slacking."
              + exp.getMessage());
          // e.printStackTrace();
        }

      }
    });

    // Tooltip on hover
    this.addMouseMotionListener(new MouseMotionListener() {

      @SuppressWarnings("rawtypes")
      @Override
      public void mouseMoved(final MouseEvent evt) {
        // System.out.println(e);
        SwingWorker worker = new SwingWorker() {

          protected Object doInBackground() throws Exception {
            for (ErrorMarker eMarker : errorPoints) {
              if (evt.getY() >= eMarker.getY() - 2
                  && evt.getY() <= eMarker.getY() + 2 + errorMarkerHeight) {
                Problem p = eMarker.getProblem();
                String msg = (p.isError() ? "Error: " : "Warning: ")
                    + p.getMessage();
                setToolTipText(msg);
                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                break;
              }
            }
            return null;
          }
        };
       
        try {
          worker.execute();
        } catch (Exception exp) {
          System.out
              .println("Errorbar mousemoved Worker is slacking."
                  + exp.getMessage());
          // e.printStackTrace();
View Full Code Here

    //log("Total CU " + compilationUnit.types().size());
    if(compilationUnit.types() == null || compilationUnit.types().isEmpty()){
      logE("No CU found!");
    }
    visitRecur((ASTNode) compilationUnit.types().get(0), codeTree);
    SwingWorker worker = new SwingWorker() {

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

      protected void done() {
        if (codeTree != null) {
          if(SHOWAST){
            if (jtree.hasFocus() || frmASTView.hasFocus())
              return;
            jtree.setModel(new DefaultTreeModel(codeTree));
            ((DefaultTreeModel) jtree.getModel()).reload();
            jtree.validate();
            if (!frmASTView.isVisible()) {
              frmASTView.setVisible(true);
            }
          }
//          if (!frameAutoComp.isVisible()) {
//
//            frameAutoComp.setVisible(true);
//           
//          }
//          if (!frmJavaDoc.isVisible()) {
//            long t = System.currentTimeMillis();
//            loadJavaDoc();
//            log("Time taken: "
//                + (System.currentTimeMillis() - t));
//            frmJavaDoc.setBounds(new Rectangle(errorCheckerService.getEditor()
//                .getX() + errorCheckerService.getEditor().getWidth(),
//                                               errorCheckerService.getEditor()
//                                                   .getY(), 450, 600));
//            frmJavaDoc.setVisible(true);
//          }
        }
      }
    };
    worker.execute();
//    logE("++>" + System.getProperty("java.class.path"));
//    log(System.getProperty("java.class.path"));
//    log("-------------------------------");
    return codeTree;
  }
View Full Code Here

    jtree.addTreeSelectionListener(new TreeSelectionListener() {
     
      @Override
      public void valueChanged(TreeSelectionEvent e) {
        log(e);
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
            if(jtree
                .getLastSelectedPathComponent() == null){
              return;
            }
            DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) jtree
                .getLastSelectedPathComponent();   
            if (tnode.getUserObject() instanceof ASTNodeWrapper) {
              ASTNodeWrapper awrap = (ASTNodeWrapper) tnode.getUserObject();
              errorCheckerService.highlightNode(awrap);
             
              //--
              try {
                int javaLineNumber = getLineNumber(awrap.getNode());
                int pdeOffs[] = errorCheckerService
                    .calculateTabIndexAndLineNumber(javaLineNumber);
                PlainDocument javaSource = new PlainDocument();
                javaSource.insertString(0, errorCheckerService.sourceCode, null);
                Element lineElement = javaSource.getDefaultRootElement()
                    .getElement(javaLineNumber-1);
                if(lineElement == null) {
                  return;
                }
               
                String javaLine = javaSource.getText(lineElement.getStartOffset(),
                                                     lineElement.getEndOffset()
                                                         - lineElement.getStartOffset());
                editor.getSketch().setCurrentCode(pdeOffs[0]);
                String pdeLine = editor.getLineText(pdeOffs[1]);
                //String lookingFor = nodeName.toString();
                //log(lookingFor + ", " + nodeName.getStartPosition());
                log("JL " + javaLine + " LSO " + lineElement.getStartOffset() + ","
                    + lineElement.getEndOffset());
                log("PL " + pdeLine);
              } catch (BadLocationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
          }
        };
        worker.execute();
      }
    });
   
    btnRename.addActionListener(new ActionListener() {
     
      @Override
      public void actionPerformed(ActionEvent e) {      
        if(txtRenameField.getText().length() == 0)
          return;
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
           refactorIt();
          }
        };
        worker.execute();
      }
    });

    btnListOccurrence.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
            handleShowUsage();
          }
        };
        worker.execute();
      }
    });
       
    treeRename.addTreeSelectionListener(new TreeSelectionListener() {
     
      @Override
      public void valueChanged(TreeSelectionEvent e) {
        log(e);
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
            if(treeRename
                .getLastSelectedPathComponent() == null){
              return;
            }
            DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) treeRename
                .getLastSelectedPathComponent();   
           
            if (tnode.getUserObject() instanceof ASTNodeWrapper) {
              ASTNodeWrapper awrap = (ASTNodeWrapper) tnode.getUserObject();
              //errorCheckerService.highlightNode(awrap);
              awrap.highlightNode(thisASTGenerator);
            }
          }
        };
        worker.execute();
      }
    });
  }
View Full Code Here

TOP

Related Classes of javax.swing.SwingWorker

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.