protected void preCache(List<Position> grid, Position centerPosition)
        throws InterruptedException {
      // Pre-cache the tiles that will be needed for the intersection calculations.
      double n = 0;
      final long start = System.currentTimeMillis();
      for (Position gridPos : grid) // for each grid point.
      {
        final double progress = 100 * (n++ / grid.size());
        terrain.cacheIntersectingTiles(centerPosition, gridPos);

        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                progressBar.setValue((int) progress);
                progressBar.setString(null);
              }
            });
      }

      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              progressBar.setValue(100);
            }
          });

      long end = System.currentTimeMillis();
      System.out.printf(
          "Pre-caching time %d milliseconds, cache usage %f, tiles %d\n",
          end - start, terrain.getCacheUsage(), terrain.getNumCacheEntries());
    }
 protected void doUpdateDescription(final Sector sector) {
   if (sector != null) {
     try {
       long size = retrievable.getEstimatedMissingDataSize(sector, 0, cache);
       final String formattedSize = BulkDownloadPanel.makeSizeDescription(size);
       SwingUtilities.invokeLater(
           new Runnable() {
             public void run() {
               descriptionLabel.setText(formattedSize);
             }
           });
     } catch (Exception e) {
       SwingUtilities.invokeLater(
           new Runnable() {
             public void run() {
               descriptionLabel.setText("-");
             }
           });
     }
   } else
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             descriptionLabel.setText("-");
           }
         });
 }
Ejemplo n.º 3
0
  /**
   * Sets the output text.
   *
   * @param t output text
   * @param s text size
   */
  public final void setText(final byte[] t, final int s) {
    // remove invalid characters and compare old with new string
    int ns = 0;
    final int ts = text.size();
    final byte[] tt = text.text();
    boolean eq = true;
    for (int r = 0; r < s; ++r) {
      final byte b = t[r];
      // support characters, highlighting codes, tabs and newlines
      if (b >= ' ' || b <= TokenBuilder.MARK || b == 0x09 || b == 0x0A) {
        t[ns++] = t[r];
      }
      eq &= ns < ts && ns < s && t[ns] == tt[ns];
    }
    eq &= ns == ts;

    // new text is different...
    if (!eq) {
      text = new BaseXTextTokens(Arrays.copyOf(t, ns));
      rend.setText(text);
      scroll.pos(0);
    }
    if (undo != null) undo.store(t.length != ns ? Arrays.copyOf(t, ns) : t, 0);
    SwingUtilities.invokeLater(calc);
  }
    protected void computeAndShowIntersections(final Position curPos) {
      this.previousCurrentPosition = curPos;

      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              setCursor(WaitCursor);
            }
          });

      // Dispatch the calculation threads in a separate thread to avoid locking up the user
      // interface.
      this.calculationDispatchThread =
          new Thread(
              new Runnable() {
                public void run() {
                  try {
                    performIntersectionTests(curPos);
                  } catch (InterruptedException e) {
                    System.out.println("Operation was interrupted");
                  }
                }
              });

      this.calculationDispatchThread.start();
    }
Ejemplo n.º 5
0
 public void done() {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           currentPage++;
           pageChanged();
         }
       });
 }
Ejemplo n.º 6
0
 public void setMaximum(final int max) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           progress.setMaximum(max);
           progress.setValue(0);
         }
       });
 }
Ejemplo n.º 7
0
 private void append(String string) {
   final String s = new String(string);
   Runnable appendString =
       new Runnable() {
         public void run() {
           textPane.append(s);
         }
       };
   SwingUtilities.invokeLater(appendString);
 }
Ejemplo n.º 8
0
 private void setMessage(String string) {
   final String s = new String(string);
   Runnable setString =
       new Runnable() {
         public void run() {
           message.setText(s);
         }
       };
   SwingUtilities.invokeLater(setString);
 }
Ejemplo n.º 9
0
 /** Jumps to the end of the text. */
 public final void scrollToEnd() {
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           text.pos(text.size());
           text.setCaret();
           showCursor(2);
         }
       });
 }
Ejemplo n.º 10
0
 public void error(final String message) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           dispose();
           JOptionPane.showMessageDialog(
               null, message, "Installation aborted", JOptionPane.ERROR_MESSAGE);
           System.exit(1);
         }
       });
 }
    protected void performIntersectionTests(final Position curPos) throws InterruptedException {
      // Clear the results lists when the user selects a new location.
      this.firstIntersectionPositions.clear();
      this.sightLines.clear();

      // Raise the selected location and the grid points a little above ground just to show we can.
      final double height = 5; // meters

      // Form the grid.
      double gridRadius = GRID_RADIUS.degrees;
      Sector sector =
          Sector.fromDegrees(
              curPos.getLatitude().degrees - gridRadius, curPos.getLatitude().degrees + gridRadius,
              curPos.getLongitude().degrees - gridRadius,
                  curPos.getLongitude().degrees + gridRadius);

      this.grid = buildGrid(sector, height, GRID_DIMENSION, GRID_DIMENSION);
      this.numGridPoints = grid.size();

      // Compute the position of the selected location (incorporate its height).
      this.referencePosition = new Position(curPos.getLatitude(), curPos.getLongitude(), height);
      this.referencePoint =
          terrain.getSurfacePoint(curPos.getLatitude(), curPos.getLongitude(), height);

      //            // Pre-caching is unnecessary and is useful only when it occurs before the
      // intersection
      //            // calculations. It will incur extra overhead otherwise. The normal intersection
      // calculations
      //            // cause the same caching, making subsequent calculations on the same area
      // faster.
      //            this.preCache(grid, this.referencePosition);

      // On the EDT, show the grid.
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              progressBar.setValue(0);
              progressBar.setString(null);
              clearLayers();
              showGrid(grid, referencePosition);
              getWwd().redraw();
            }
          });

      // Perform the intersection calculations.
      this.startTime = System.currentTimeMillis();
      for (Position gridPos : this.grid) // for each grid point.
      {
        //noinspection ConstantConditions
        if (NUM_THREADS > 0) this.threadPool.execute(new Intersector(gridPos));
        else performIntersection(gridPos);
      }
    }
Ejemplo n.º 12
0
 // {{{ handlePluginUpdate() method
 @EBHandler
 public void handlePluginUpdate(PluginUpdate msg) {
   if (!queuedUpdate) {
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             queuedUpdate = false;
             manager.update();
           }
         });
     queuedUpdate = true;
   }
 } // }}}
Ejemplo n.º 13
0
 private void invokeSetPath() {
   // gotta do this after the dust settles
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           TreePath path = model.getPath(selectedRow);
           if (path != null) {
             int rowno = table.setSelectionPath(path);
             if (rowno >= 0) ensureRowIsVisible(rowno);
             if (debugSetPath) System.out.println("----reset selectedRow = " + rowno + " " + path);
           }
         }
       });
 }
Ejemplo n.º 14
0
 public void run() {
   while (runner.isAlive()) {
     try {
       Thread.sleep(1000);
     } catch (Exception ex) {
     }
   }
   Runnable update =
       new Runnable() {
         public void run() {
           running = false;
           setStatus();
         }
       };
   SwingUtilities.invokeLater(update);
 }
Ejemplo n.º 15
0
  /**
   * The animation changed. Handle the change.
   *
   * @param evt The event
   */
  private void handleAnimationPropertyChange(PropertyChangeEvent evt) {
    //        System.err.println ("Handlechange:" +evt.getPropertyName());
    if (evt.getPropertyName().equals(Animation.ANI_VALUE)) {
      debug("handleAnimationPropertyChange value :" + evt.getPropertyName());
      Real eventValue = (Real) evt.getNewValue();
      // if there's nothing to do, return;
      if ((eventValue == null) || eventValue.isMissing()) {
        return;
      }

      /** The Animation associated with this widget */
      DateTime time = null;
      try {
        time = new DateTime(eventValue);
      } catch (VisADException ve) {;
      }
      final DateTime theDateTime = time;
      final int theIndex = ((anime != null) ? anime.getCurrent() : -1);
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              boolean oldValue = ignoreTimesCbxEvents;
              try {
                ignoreTimesCbxEvents = true;
                //                        synchronized (timesCbxMutex) {
                xcnt++;

                timesCbx.setSelectedItem(theDateTime);
                //                        }
                if ((boxPanel != null) && (theIndex >= 0)) {
                  boxPanel.setOnIndex(theIndex);
                }
                timesCbx.repaint();
              } finally {
                ignoreTimesCbxEvents = oldValue;
              }
            }
          });
      shareValue();
    } else if (evt.getPropertyName().equals(Animation.ANI_SET)) {
      if (ignoreAnimationSetChange) {
        return;
      }
      updateIndicatorInner((Set) evt.getNewValue(), true);
    }
  }
Ejemplo n.º 16
0
 /** Performs stop action. */
 void stop(boolean stop, final AbstractThread thread) {
   final ResourceBundle bundle = NbBundle.getBundle(JPDADebugger.class);
   if (stop) {
     removeStepRequest();
     setLastAction(ACTION_BREAKPOINT_HIT);
     setDebuggerState(DEBUGGER_STOPPED);
     operator.stopRequest();
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             thread.setCurrent(true);
             updateWatches();
             threadGroup.refresh();
           }
         });
   } else operator.resume();
 }
Ejemplo n.º 17
0
  /** simply dump status info to the textarea */
  private void sout(final String s) {
    Runnable soutRunner =
        new Runnable() {
          public void run() {
            if (ttaStatus.getText().equals("")) {
              ttaStatus.setText(s);
            } else {
              ttaStatus.setText(ttaStatus.getText() + "\n" + s);
            }
          }
        };

    if (ThreadUtils.isInEDT()) {
      soutRunner.run();
    } else {
      SwingUtilities.invokeLater(soutRunner);
    }
  }
Ejemplo n.º 18
0
  public void installUI(JComponent c) {
    super.installUI(c);
    arrowIcon =
        new MotifComboBoxArrowIcon(
            UIManager.getColor("controlHighlight"),
            UIManager.getColor("controlShadow"),
            UIManager.getColor("control"));

    Runnable initCode =
        new Runnable() {
          public void run() {
            if (motifGetEditor() != null) {
              motifGetEditor().setBackground(UIManager.getColor("text"));
            }
          }
        };

    SwingUtilities.invokeLater(initCode);
  }
Ejemplo n.º 19
0
  /*
   *  A document change may affect the number of displayed lines of text.
   *  Therefore the lines numbers will also change.
   */
  private void documentChanged() {
    //  Preferred size of the component has not been updated at the time
    //  the DocumentEvent is fired

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            int preferredHeight = component.getPreferredSize().height;

            //  Document change has caused a change in the number of lines.
            //  Repaint to reflect the new line numbers

            if (lastHeight != preferredHeight) {
              setPreferredWidth();
              repaint();
              lastHeight = preferredHeight;
            }
          }
        });
  }
Ejemplo n.º 20
0
  /*
   *  A document change may affect the number of displayed lines of text.
   *  Therefore the lines numbers will also change.
   */
  private void documentChanged() {
    //  View of the component has not been updated at the time
    //  the DocumentEvent is fired

    SwingUtilities.invokeLater(
        () -> {
          try {
            int endPos = component.getDocument().getLength();
            Rectangle rect = component.modelToView(endPos);

            if (rect != null && rect.y != lastHeight) {
              setPreferredWidth();
              repaint();
              lastHeight = rect.y;
            }
          } catch (BadLocationException ex) {
            /* nothing to do */
          }
        });
  }
Ejemplo n.º 21
0
  /**
   * _more_
   *
   * @param timeSet _more_
   * @param timeSetChange _more_
   */
  private void updateIndicatorInner(Set timeSet, boolean timeSetChange) {
    //      timeSet  = checkAnimationSet(timeSet);
    timesArray = Animation.getDateTimeArray(timeSet);

    // Stop running if there are no times
    if ((timesArray.length == 0) && timeSetChange) {
      setRunning(false);
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            // Only set the list data if we have created the gui contents
            if (madeContents) {
              setTimesInTimesBox();
              updateRunButton();
            }
          }
        });
    updateBoxPanel(timesArray);
  }
Ejemplo n.º 22
0
  /**
   * Sets curent line. It means: change debugger state to stopped, shows message, sets current
   * thread and updates watches.
   */
  private void makeCurrent(
      final String threadName,
      final String className,
      final String methodName,
      final String lineNumber,
      final boolean hasSource,
      final ThreadReference tr) {
    setDebuggerState(DEBUGGER_STOPPED);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            // show message
            if (isFollowedByEditor()) {
              if (hasSource) {
                println(
                    new MessageFormat(bundle.getString("CTL_Thread_stopped"))
                        .format(new Object[] {threadName, className, methodName, lineNumber}),
                    ERR_OUT + STL_OUT);
              } else {
                println(
                    new MessageFormat(bundle.getString("CTL_Thread_stopped_no_source"))
                        .format(new Object[] {threadName, className, methodName, lineNumber}),
                    ERR_OUT + STL_OUT);
              }
            } else
              println(
                  new MessageFormat(bundle.getString("CTL_Thread_stopped"))
                      .format(new Object[] {threadName, className, methodName, lineNumber}),
                  ERR_OUT + STL_OUT);

            // refresh all
            JPDAThread tt = threadManager.getThread(tr);
            tt.setCurrent(true);
            updateWatches();
          }
        });
  }
  public void end() {
    final int[] selected = table.getSelectedRows();

    model.clear(rows.size());
    Iterator i = rows.iterator();
    while (i.hasNext()) {
      model.addEntry((Map) i.next());
    }
    rows.clear();

    if (SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              model.fireListeners();
              fixSelection(selected);
            }
          });
    } else {
      model.fireListeners();
      fixSelection(selected);
    }
  }
Ejemplo n.º 24
0
  public static void main(String[] args) {
    Runnable r =
        new Runnable() {

          @Override
          public void run() {
            BattleshipBoard cb = new BattleshipBoard();

            JFrame f = new JFrame("BattleShips");
            f.add(cb.getGui());
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            f.setLocationByPlatform(true);

            // ensures the frame is the minimum size it needs to be
            // in order display the components within it
            f.pack();
            // ensures the minimum size is enforced.
            f.setMinimumSize(f.getSize());
            f.setVisible(true);
          }
        };
    SwingUtilities.invokeLater(r);
  }
    /** Keeps the progress meter current. When calculations are complete, displays the results. */
    protected synchronized void updateProgress() {
      // Update the progress bar only once every 250 milliseconds to avoid stealing time from
      // calculations.
      if (this.sightLines.size() >= this.numGridPoints) endTime = System.currentTimeMillis();
      else if (System.currentTimeMillis() < this.lastTime + 250) return;
      this.lastTime = System.currentTimeMillis();

      // On the EDT, update the progress bar and if calculations are complete, update the World
      // Window.
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              int progress = (int) (100d * getSightlinesSize() / (double) numGridPoints);
              progressBar.setValue(progress);

              if (progress >= 100) {
                setCursor(Cursor.getDefaultCursor());
                progressBar.setString((endTime - startTime) + " ms");
                showResults();
                System.out.printf("Calculation time %d milliseconds\n", endTime - startTime);
              }
            }
          });
    }
Ejemplo n.º 26
0
 @Override
 public final void componentResized(final ComponentEvent e) {
   scroll.pos(0);
   SwingUtilities.invokeLater(calc);
 }
Ejemplo n.º 27
0
 public void run() {
   while (connected) {
     try {
       Object obj = in.readObject();
       if (obj.toString().equals("-101")) {
         connected = false;
         in.close();
         out.close();
         socket.close();
         SwingUtilities.invokeLater(
             new Runnable() {
               public void run() {
                 Cashier.closee = true;
                 JOptionPane.showMessageDialog(
                     null,
                     "Disconnected from server. Please Restart",
                     "Error:",
                     JOptionPane.PLAIN_MESSAGE);
                 try {
                   m.stop();
                 } catch (Exception w) {
                 }
               }
             });
       } else if (obj.toString().split("::")[0].equals("broadcast")) {
         // System.out.println("braodcast received");
         bc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else if (obj.toString().split("::")[0].equals("chat")) {
         // System.out.println("chat received:
         // "+obj.toString().substring(obj.toString().indexOf("::")+2));
         cc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else if (obj.toString().split("::")[0].equals("rankings")) {
         String hhh = obj.toString().split("::")[1];
         final JDialog jd = new JDialog();
         jd.setUndecorated(false);
         JPanel pan = new JPanel(new BorderLayout());
         JLabel ppp = new JLabel();
         ppp.setFont(new Font("Arial", Font.BOLD, 20));
         ppp.setText(
             "<html><pre>Thanks for playing !!!<br/>1st: "
                 + hhh.split(":")[0]
                 + "<br/>2nd: "
                 + hhh.split(":")[1]
                 + "<br/>3rd: "
                 + hhh.split(":")[2]
                 + "</pre></html>");
         pan.add(ppp, BorderLayout.CENTER);
         JButton ok = new JButton("Ok");
         ok.addActionListener(
             new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                 jd.setVisible(false);
                 try {
                   m.stop();
                 } catch (Exception w) {
                 }
               }
             });
         pan.add(ok, BorderLayout.SOUTH);
         jd.setContentPane(pan);
         jd.setModalityType(JDialog.ModalityType.APPLICATION_MODAL);
         jd.pack();
         jd.setLocationRelativeTo(null);
         jd.setVisible(true);
       } else if (obj.toString().split("::")[0].equals("rank")) {
         rc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else {
         User hhh = null;
         try {
           hhh = (User) obj;
           /*if(usrD==1)
           {
               reply=obj;
               ccl.interrupt();
           }
           else*/
           {
             try {
               m.ur.changeData((User) obj);
             } catch (Exception w) {
               try {
                 maain.ur.changeData((User) obj);
               } catch (Exception ppp) {
                 ppp.printStackTrace();
               }
             }
           }
         } catch (Exception p) {
           int iid = -1;
           try {
             iid = Integer.parseInt(obj.toString());
             obj = in.readObject();
             if (obj.toString().equals("-102")) {
               // ccl.interrupt();
               SwingUtilities.invokeLater(
                   new Runnable() {
                     public void run() {
                       Cashier.closee = true;
                       JOptionPane.showMessageDialog(
                           null, "Server Not Running.", "Error:", JOptionPane.PLAIN_MESSAGE);
                     }
                   });
             }
             // Thread th = ((Thread)rev.remove(iid));
             rev2.put(iid, obj);
             // System.out.println("Put: "+iid+"   :   "+obj.toString()+"   :
             // "+Thread.currentThread());
             // th.interrupt();
             // ccl.interrupt();
           } catch (Exception ppp) {
               /*ppp.printStackTrace();*/
             System.out.println(
                 "Shit: "
                     + iid
                     + "   :   "
                     + obj.toString()
                     + "   :   "
                     + Thread.currentThread());
           }
         }
       }
       try {
         Thread.sleep(500);
       } catch (Exception n) {
       }
     } catch (Exception m) {
     }
   }
 }