Package javax.swing

Examples of javax.swing.SwingWorker$SwingWorkerPropertyChangeSupport


     * The 'correct' way of updating swing components is therefore, to do
     * the updating through a SwingWorker, inside done(). The updating then
     * takes place in a thread safe manner.
     */

    SwingWorker worker = new SwingWorker() {

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

      protected void done() {

        try {
          errorTable.setModel(tableModel);
          errorTable.getColumnModel().getColumn(0)
              .setPreferredWidth(300);
          errorTable.getColumnModel().getColumn(1)
              .setPreferredWidth(100);
          errorTable.getColumnModel().getColumn(2)
              .setPreferredWidth(50);
          errorTable.getTableHeader().setReorderingAllowed(false);
          errorTable.validate();
          errorTable.updateUI();
          errorTable.repaint();
        } catch (Exception e) {
          System.out.println("Exception at updatTable " + e);
          // e.printStackTrace();
        }
        // errorTable.getModel()

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


    this.addMouseListener(new MouseAdapter() {
      @SuppressWarnings("rawtypes")
      @Override
      public void mouseClicked(final MouseEvent e) {
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
            for (ErrorMarker eMarker : errorPoints) {
              if (e.getY() >= eMarker.y
                  && e.getY() <= eMarker.y
                      + errorMarkerHeight) {
                int currentTabErrorIndex = errorPoints
                    .indexOf(eMarker);
                // System.out.println("Index: " +
                // currentTabErrorIndex);
                int currentTab = editor.getSketch()
                    .getCodeIndex(
                        editor.getSketch()
                            .getCurrentCode());

                int totalErrorIndex = currentTabErrorIndex;
                for (int i = 0; i < errorCheckerService.problemsList
                    .size(); i++) {
                  Problem p = errorCheckerService.problemsList
                      .get(i);
                  if (p.tabIndex < currentTab)
                    totalErrorIndex++;
                  if (p.tabIndex == currentTab)
                    break;
                }
                errorCheckerService
                    .scrollToErrorLine(totalErrorIndex);
              }
            }

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

      }
    });

    this.addMouseMotionListener(new MouseMotionListener() {

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

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

          protected void done() {

            for (ErrorMarker eMarker : errorPoints) {
              if (e.getY() >= eMarker.y
                  && e.getY() <= eMarker.y
                      + errorMarkerHeight) {
                // System.out.println("Index: " +
                // errorPoints.indexOf(y));
                int currentTab = editor.getSketch()
                    .getCodeIndex(
                        editor.getSketch()
                            .getCurrentCode());
                int currentTabErrorCount = 0;

                for (int i = 0; i < errorPoints.size(); i++) {
                  Problem p = errorPoints.get(i).problem;
                  if (p.tabIndex == currentTab) {
                    if (currentTabErrorCount == errorPoints
                        .indexOf(eMarker)) {
                      // System.out.println("Roger that.");
                      String msg = (p.iProblem.isError() ? "Error: "
                          : "Warning: ")
                          + p.iProblem.getMessage();
                      setToolTipText(msg);

                      return;
                    } else {
                      currentTabErrorCount++;
                      // System.out.println("Still looking..");
                    }
                  }

                }
              }
            }

          }
        };
        try {
          worker.execute();
        } catch (Exception exp) {
          System.out
              .println("Errorbar mousemoved Worker is slacking."
                  + exp.getMessage());
          // e.printStackTrace();
View Full Code Here

    this.addMouseListener(new MouseAdapter() {
      @SuppressWarnings("rawtypes")
      @Override
      public void mouseClicked(final MouseEvent e) {
        SwingWorker worker = new SwingWorker() {

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

          protected void done() {
            for (ErrorMarker eMarker : errorPoints) {
              if (e.getY() >= eMarker.y - 2
                  && e.getY() <= eMarker.y + 2
                      + errorMarkerHeight) {
                int currentTabErrorIndex = errorPoints
                    .indexOf(eMarker);
                // System.out.println("Index: " +
                // currentTabErrorIndex);
                int currentTab = editor.getSketch()
                    .getCodeIndex(
                        editor.getSketch()
                            .getCurrentCode());

                int totalErrorIndex = currentTabErrorIndex;
                for (int i = 0; i < errorCheckerService.problemsList
                    .size(); i++) {
                  Problem p = errorCheckerService.problemsList
                      .get(i);
                  if (p.tabIndex < currentTab)
                    totalErrorIndex++;
                  if (p.tabIndex == currentTab)
                    break;
                }
                errorCheckerService
                    .scrollToErrorLine(totalErrorIndex);
              }
            }

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

      }
    });

    this.addMouseMotionListener(new MouseMotionListener() {

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

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

          protected void done() {

            for (ErrorMarker eMarker : errorPoints) {
              if (e.getY() >= eMarker.y - 2
                  && e.getY() <= eMarker.y + 2
                      + errorMarkerHeight) {
                // System.out.println("Index: " +
                // errorPoints.indexOf(y));
                int currentTab = editor.getSketch()
                    .getCodeIndex(
                        editor.getSketch()
                            .getCurrentCode());
                int currentTabErrorCount = 0;

                for (int i = 0; i < errorPoints.size(); i++) {
                  Problem p = errorPoints.get(i).problem;
                  if (p.tabIndex == currentTab) {
                    if (currentTabErrorCount == errorPoints
                        .indexOf(eMarker)) {
                      // System.out.println("Roger that.");
                      String msg = (p.iProblem.isError() ? "Error: "
                          : "Warning: ")
                          + p.message;
                      setToolTipText(msg);
                      setCursor(Cursor
                          .getPredefinedCursor(Cursor.HAND_CURSOR));
                      return;
                    } else {
                      currentTabErrorCount++;
                      // System.out.println("Still looking..");
                    }
                  }

                }
              }
              // Reset cursor and tooltip
              else {
                setToolTipText("");
                setCursor(Cursor
                    .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              }
            }

          }
        };
        try {
          worker.execute();
        } catch (Exception exp) {
          System.out
              .println("Errorbar mousemoved Worker is slacking."
                  + exp.getMessage());
          // e.printStackTrace();
View Full Code Here

     * The 'correct' way of updating swing components is therefore, to do
     * the updating through a SwingWorker, inside done(). The updating then
     * takes place in a thread safe manner.
     */

    SwingWorker worker = new SwingWorker() {

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

      protected void done() {

        try {
          setModel(tableModel);
          for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
            getColumnModel().getColumn(i).setPreferredWidth(
                columnWidths[i]);
          }
          getTableHeader().setReorderingAllowed(false);
          validate();
          updateUI();
          repaint();
        } catch (Exception e) {
          System.out.println("Exception at updatTable " + 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

  }

  // runClient method {{{
  protected void runClient()
  {
    m_sw = new SwingWorker() {
      @Override
      public Object doInBackground()
      {
        try {
          m_cli.run();
View Full Code Here

        }
       
      highlightStrings.add(textToMatchAgainst);
      highlightColors.add(color);
           
      SwingWorker worker = new SwingWorker() {           
          @Override           
            public Object doInBackground() {
                try {
                    Thread.sleep(10000); // 10 seconds of highlighting
                } catch (InterruptedException e) { /*Who cares*/ }
                return null;
            }
            @Override
            public void done()
            {
              highlightColors.remove(highlightStrings.indexOf(textToMatchAgainst));
                highlightStrings.remove(highlightStrings.indexOf(textToMatchAgainst));
                repaint();
            }
        };
        worker.execute();
     
      this.repaint();
    }
View Full Code Here

        }
        public void action(ActionEvent e) throws Throwable {
            // Here we use the SwingWorker helper class to run the validation routine in a
            // background thread, otherwise the GUI would wait and the progress bar would not be
            // displayed properly
            SwingWorker worker = new SwingWorker<String, Object>() {
                protected String doInBackground() throws Exception {
                    // For shapefiles with many features its nice to display a progress bar
                    final JProgressWindow progress = new JProgressWindow(null);
                    progress.setTitle("Validating feature geometry");

                    int numInvalid = validateFeatureGeometry(progress);
                    if (numInvalid == 0) {
                        return "All feature geometries are valid";
                    } else {
                        return "Invalid geometries: " + numInvalid;
                    }
                }
                protected void done() {
                    try {
                        Object result = get();
                        JOptionPane.showMessageDialog(null, result, "Geometry results",
                                        JOptionPane.INFORMATION_MESSAGE);
                    } catch (Exception ignore) {
                    }
                }
            };
            // This statement runs the validation method in a background thread
            worker.execute();
        }
View Full Code Here

    dialog.getContentPane().add(previewPanel, BorderLayout.CENTER);
    dialog.getContentPane().add(progress, BorderLayout.SOUTH);
    dialog.setSize(600, 800);
    dialog.setVisible(true);

    SwingWorker swingWorker = new SwingWorker() {
      @Override
      protected Object doInBackground() throws Exception {
        Source source = createXSLStream();
        progress.setValue(10);

        Transformer transformer = TransformerFactory.newInstance().newTemplates(source).newTransformer();
        Fop fop = fopFactory.newFop(agent);
        StreamSource streamSource = createVelocityStream();
        progress.setValue(50);

        SAXResult saxr = new SAXResult(fop.getDefaultHandler());
        progress.setValue(65);

        transformer.transform(streamSource, saxr);
        progress.setValue(90);

        previewPanel.setScaleFactor(0.5);
        previewPanel.setDisplayMode(PreviewPanel.CONTINUOUS);
        previewPanel.reload();
        progress.setValue(100);
        return null;
      }
    };

    swingWorker.execute();

    return dialog;
  }
View Full Code Here

            final JLabel amountLabel){
        this.thoughtLoadAction = thoughtLoadAction;
        this.tabIndex = tabIndex;
        this.statusLabel = statusLabel;
        this.amountLabel = amountLabel;
        @SuppressWarnings("rawtypes")
      SwingWorker startedWorker = null;       
        switch(thoughtLoadAction){
        case LAST_THOUGHTS:
          startedWorker = bgWorker.getLastThoughts(this);
          break;
View Full Code Here

            } else {
                thoughtIsFavorite = (Boolean)tableModel.getValueAt(rowModelIndex, columnModelIndex);           
                thought = (Thought)tableModel.getValueAt(rowModelIndex, tableProperties.getThoughtColIndex());
                thought.setFavorite(thoughtIsFavorite);
                startTabIcon(tabIndex, getWaitImage());
                @SuppressWarnings("rawtypes")
        SwingWorker startedWorker = bgWorker.favoriteThought(thought, this, MainWindow.this);
                workerID = getWorkerID();
            startedWorkers.put(workerID, startedWorker);  
            }
      }
View Full Code Here

TOP

Related Classes of javax.swing.SwingWorker$SwingWorkerPropertyChangeSupport

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.