コード例 #1
0
ファイル: States.java プロジェクト: yxm4109/babiloo
 // TODO consider moving to another more Swing-related class
 public static void assertIsEDT() {
   if (!SwingUtilities.isEventDispatchThread()) {
     doThrow(
         "Expected to be called from EDT. Was \""
             + Thread.currentThread().getClass().getName()
             + "\" with name \""
             + Thread.currentThread().getName()
             + "\"");
   }
 }
コード例 #2
0
 public void dispose() {
   LOG.assertTrue(EventQueue.isDispatchThread(), Thread.currentThread().getName());
   myAbstractTreeBuilder = null;
   // this will also dispose wrapped TreeModel
   myTreeModelWrapper.dispose();
   myFileEditor = null;
 }
コード例 #3
0
  /**
   * Tests out the panel from the command line.
   *
   * @param args ignored.
   */
  public static void main(String[] args) {

    try {
      final JFrame jf = new JFrame("Generator Property Iterator");
      jf.getContentPane().setLayout(new BorderLayout());
      GeneratorPropertyIteratorPanel gp = new GeneratorPropertyIteratorPanel();
      jf.getContentPane().add(gp, BorderLayout.CENTER);
      jf.addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
              jf.dispose();
              System.exit(0);
            }
          });
      jf.pack();
      jf.setVisible(true);
      System.err.println("Short nap");
      Thread.currentThread().sleep(3000);
      System.err.println("Done");
      gp.setExperiment(new Experiment());
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println(ex.getMessage());
    }
  }
コード例 #4
0
ファイル: DocumentMaker.java プロジェクト: wallisc/ExamMakr
  /**
   * Returns the number of pages for textPane
   *
   * @param nTextPane the text pane to count pages for
   * @return Number of pages
   */
  public int pageCount(JEditorPane nTextPane) {
    // What to print: the Printable object.
    Printable printable = nTextPane.getPrintable(null, null);

    // Print parameters: page width and height.
    PageFormat format = new PageFormat();
    int width = (int) format.getWidth();
    int height = (int) format.getHeight();
    int pages = 0;

    // Stop generating images when the preview thread is interrupted.
    for (; !Thread.currentThread().isInterrupted(); pages++) {

      // Where to print: the Graphics object.
      final Image pageImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics graphic = pageImage.getGraphics();

      try {
        // How to print: generate preview image of the n-th page.
        if (printable.print(graphic, format, pages) != Printable.PAGE_EXISTS) {
          break;
        }
      } catch (Exception e) {
        break;
      }
    }
    return pages;
  }
コード例 #5
0
  public static void main(String[] args) {
    JFrame frame = new JFrame("options");

    frame.setSize(new Dimension(500, 300));
    frame.getContentPane().add(new PackagerOptionsPanel(null));

    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
          }

          @Override
          public void windowClosed(WindowEvent e) {
            System.exit(0);
          }
        });

    try {
      SwingUtilities.invokeAndWait(new PackAndShowFrameWorker(frame));
    } catch (InterruptedException e) {
      // Immediately reasserts the exception by interrupting the caller thread itself
      Thread.currentThread().interrupt();

      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
コード例 #6
0
  @Override
  public synchronized void run() {
    try {
      for (int i = 0; i < NUM_PIPES; i++) {
        while (Thread.currentThread() == reader[i]) {
          try {
            this.wait(100);
          } catch (InterruptedException ie) {
          }
          if (pin[i].available() != 0) {
            String input = this.readLine(pin[i]);
            appendMsg(htmlize(input));
            if (textArea.getDocument().getLength() > 0) {
              textArea.setCaretPosition(textArea.getDocument().getLength() - 1);
            }
          }
          if (quit) {
            return;
          }
        }
      }

    } catch (Exception e) {
      Debug.error(me + "Console reports an internal error:\n%s", e.getMessage());
    }
  }
コード例 #7
0
  private void initUI() {

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    infoPanel.setBackground(Color.WHITE);
    infoPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

    infoPanel.add(
        new JLabel(
            new ImageIcon(
                Thread.currentThread().getContextClassLoader().getResource("siw-logo3_2.gif"))));

    JLabel textLabel = new JLabel("<html>Confirmation</html>");

    infoPanel.add(textLabel);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(0, 1));

    buttonPanel.add(reportLabel);

    this.setLayout(new BorderLayout());
    this.add(infoPanel, BorderLayout.NORTH);
    this.add(buttonPanel, BorderLayout.CENTER);
  }
コード例 #8
0
  private boolean loadWebPage(final JWebBrowser webBrowser) {
    try {
      final String language = Locale.getDefault().getLanguage();
      File html =
          Externalization.extractFile(
              "slash/navigation/converter/gui/mapview/routeconverter.html",
              language,
              new TokenResolver() {
                public String resolveToken(String tokenName) {
                  if (tokenName.equals("locale")) return language;
                  if (tokenName.equals("percent")) return Platform.isWindows() ? "99" : "100";
                  if (tokenName.equals("mapserver"))
                    return preferences.get(MAP_SERVER_PREFERENCE, "maps.google.com");
                  return tokenName;
                }
              });
      if (html == null) throw new IllegalArgumentException("Cannot extract routeconverter.html");
      Externalization.extractFile("slash/navigation/converter/gui/mapview/contextmenucontrol.js");

      final String url = html.toURI().toURL().toExternalForm();
      webBrowser.runInSequence(
          new Runnable() {
            public void run() {
              webBrowser.navigate(url);
            }
          });
      log.fine(System.currentTimeMillis() + " loadWebPage thread " + Thread.currentThread());
    } catch (Throwable t) {
      log.severe("Cannot create WebBrowser: " + t.getMessage());
      setInitializationCause(t);
      return false;
    }
    return true;
  }
コード例 #9
0
 public void run() {
   int tmprCount = 0;
   boolean running = true;
   for (runCount = 0; runCount < maxRun; runCount++) {
     running = (runner == Thread.currentThread());
     if (running) {
       initialise();
       saveCA();
       iterations++;
       while ((iterations < maxit)) {
         experiment.iterate();
         saveCA();
         drawCA();
         // if ((runCount%10) == 0)
         // drawLines();
         iterations++;
         // newframe = 0;
         // while(newframe<500000) newframe++;
         // if((iterations%5)==0)postscriptPrint("CA"+iterations+".eps");
         // This will produce a postscript output of the tissue
       }
       tmprCount = runCount;
       saveStats();
       // if ((runCount%25) == 0) drawLines(maxit,runCount);
     }
   }
   // this will print out aborted results
   // to stop that check if maxit was achieved
   if (!started) runCount = tmprCount + 1; // just in case stop was pressed
   // iterations should anyway be equal to maxit
   showStats();
   stop();
 }
コード例 #10
0
ファイル: MsnTreeTest.java プロジェクト: hbt/jmsnmessenger
  public static void main(String[] args) {
    //        BuddyTree buddy;
    Properties prop;
    msn = new MSNMessenger("*****@*****.**", "marinescommand");

    msn.setInitialStatus(UserStatus.ONLINE);
    msn.addMsnListener(new MSNAdapter(msn));
    msn.login();

    System.out.println("Waiting for the response....");

    MsnTreeTest test = new MsnTreeTest();
    try {
      Thread.currentThread().sleep(6000);
    } catch (InterruptedException ex) {
    }
    if (msn.isLoggedIn()) {
      BuddyList bl = msn.getBuddyGroup().getForwardList();
      for (int i = 0; i < bl.size(); i++) {
        if (!bl.get(i).getStatus().equalsIgnoreCase(UserStatus.OFFLINE)) {
          System.out.println(bl.get(i).getLoginName());
        } else {
          System.out.println("User offline: " + bl.get(i).getLoginName());
        }
      }
    } else {
      System.out.println("terminator");
    }
  }
コード例 #11
0
 /**
  * Standard sleeping function used to give the effect of scrolling
  *
  * @param time The duration of the sleep period (1000= 1 second)
  */
 public static void pauseMatrix(int time) {
   try {
     Thread.sleep(time);
   } catch (InterruptedException ex) {
     Thread.currentThread().interrupt();
   }
 }
コード例 #12
0
 public void run() {
   try {
     thread.sleep(1111);
   } catch (Exception e) {
     return;
   }
   Thread me = Thread.currentThread();
   while (thread == me) {
     for (int i = 0; i < ImageOps.imgName.length; i++) {
       imgCombo.setSelectedIndex(i);
       for (int j = 0; j < ImageOps.opsName.length; j++) {
         opsCombo.setSelectedIndex(j);
         if (j <= 1) {
           for (int k = 50; k <= 200; k += 10) {
             demo.slider1.setValue(k);
             try {
               thread.sleep(200);
             } catch (InterruptedException e) {
               return;
             }
           }
         }
         try {
           thread.sleep(4444);
         } catch (InterruptedException e) {
           return;
         }
       }
     }
   }
   thread = null;
 }
コード例 #13
0
ファイル: Check.java プロジェクト: charlesa101/insubstantial
 public static Icon getIcon(String iconName) {
   ClassLoader cl = Thread.currentThread().getContextClassLoader();
   URL url = cl.getResource("test/check/icons/" + iconName + ".gif");
   if (url != null) return new ImageIcon(url);
   url = cl.getResource("test/check/icons/" + iconName + ".png");
   if (url != null) return new ImageIcon(url);
   return null;
 }
コード例 #14
0
ファイル: CoreTask.java プロジェクト: MegaBedder/FreeRapid
 /**
  * Metoda overi, zda se jedna o Runtime
  *
  * @param cause
  * @return
  */
 protected boolean handleRuntimeException(Throwable cause) {
   if (cause instanceof RuntimeException) {
     GlobalEDTExceptionHandler exceptionHandler = new GlobalEDTExceptionHandler();
     exceptionHandler.uncaughtException(Thread.currentThread(), cause);
     return true;
   }
   return false;
 }
コード例 #15
0
 public boolean isReadAccessAllowed() {
   Thread currentThread = Thread.currentThread();
   return ourDispatchThread == currentThread
       || isExceptionalThreadWithReadAccess()
       || myActionsLock.isReadLockAcquired()
       || myActionsLock.isWriteLockAcquired()
       || isDispatchThread();
 }
コード例 #16
0
 public void drainQueuedUsageNodes() {
   assert !ApplicationManager.getApplication().isDispatchThread() : Thread.currentThread();
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           myTransferToEDTQueue.drain();
         }
       });
 }
コード例 #17
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
 /**
  * Display on screen, pause for t milliseconds, and turn on <em>animation mode</em>: subsequent
  * calls to drawing methods such as <tt>line()</tt>, <tt>circle()</tt>, and <tt>square()</tt> will
  * not be displayed on screen until the next call to <tt>show()</tt>. This is useful for producing
  * animations (clear the screen, draw a bunch of shapes, display on screen for a fixed amount of
  * time, and repeat). It also speeds up drawing a huge number of shapes (call <tt>show(0)</tt> to
  * defer drawing on screen, draw the shapes, and call <tt>show(0)</tt> to display them all on
  * screen at once).
  *
  * @param t number of milliseconds
  */
 public static void show(int t) {
   defer = false;
   draw();
   try {
     Thread.currentThread().sleep(t);
   } catch (InterruptedException e) {
     System.out.println("Error sleeping");
   }
   defer = true;
 }
コード例 #18
0
 public void assertReadAccessAllowed() {
   if (myHeadlessMode) return;
   if (!isReadAccessAllowed()) {
     LOG.error(
         "Read access is allowed from event dispatch thread or inside read-action only (see com.intellij.openapi.application.Application.runReadAction())",
         "Current thread: " + describe(Thread.currentThread()),
         "Our dispatch thread:" + describe(ourDispatchThread),
         "SystemEventQueueThread: " + describe(getEventQueueThread()));
   }
 }
コード例 #19
0
  private static void assertIsDispatchThread(String message) {
    if (ShutDownTracker.isShutdownHookRunning()) return;
    final Thread currentThread = Thread.currentThread();
    if (ourDispatchThread == currentThread) return;

    if (EventQueue.isDispatchThread()) {
      ourDispatchThread = currentThread;
    }
    if (ourDispatchThread == currentThread) return;

    Integer safeCounter = ourEdtSafe.get();
    if (safeCounter != null && safeCounter > 0) return;

    LOG.error(
        message,
        "Current thread: " + describe(Thread.currentThread()),
        "Our dispatch thread:" + describe(ourDispatchThread),
        "SystemEventQueueThread: " + describe(getEventQueueThread()));
  }
コード例 #20
0
ファイル: Sayac.java プロジェクト: maeyler/PlainJava
 public void run() {
   System.out.println("start");
   while (Thread.currentThread() == thd) {
     try {
       setDate();
       Thread.sleep(10 * 1000);
     } catch (InterruptedException e) {
     }
   }
   System.out.println("Stop");
 }
コード例 #21
0
  public void run() {
    Thread thisThread = Thread.currentThread();

    while (timerThread == thisThread) {
      getTvPanel().repaint();
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
    }
  }
コード例 #22
0
  private void initUI() {

    this.setLayout(new BorderLayout());

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    infoPanel.setBackground(Color.WHITE);
    infoPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

    infoPanel.add(
        new JLabel(
            new ImageIcon(
                Thread.currentThread().getContextClassLoader().getResource("siw-logo3_2.gif"))));

    JLabel infoLabel =
        new JLabel("<html>Please select a project and context<br> Version must be a number</html>");
    infoPanel.add(infoLabel);

    this.add(infoPanel, BorderLayout.NORTH);

    JPanel entryPanel = new JPanel();
    entryPanel.setLayout(null);

    projectNameField.setText("");
    JLabel projectNameLabel = new JLabel("Project Name");
    projectNameLabel.setBounds(new Rectangle(30, 80, 135, 20));
    projectNameField.setBounds(new Rectangle(180, 80, 175, 20));

    JLabel projectVersionLabel = new JLabel("Project Version");
    projectVersionLabel.setBounds(new Rectangle(30, 125, 135, 20));
    projectVersionField.setBounds(new Rectangle(180, 125, 175, 20));

    JLabel contextLabel = new JLabel("Context");
    contextLabel.setBounds(new Rectangle(30, 165, 135, 20));
    contextComboBox.setBounds(new Rectangle(180, 165, 175, 20));

    JLabel packageLabel = new JLabel("Select Package");
    packageLabel.setBounds(new Rectangle(30, 210, 135, 20));
    packageComboBox.setBounds(new Rectangle(180, 210, 250, 20));

    entryPanel.add(projectNameLabel, null);
    entryPanel.add(projectNameField, null);
    entryPanel.add(projectVersionLabel, null);
    entryPanel.add(projectVersionField, null);
    entryPanel.add(contextLabel, null);
    entryPanel.add(contextComboBox, null);
    entryPanel.add(packageLabel, null);
    entryPanel.add(packageComboBox, null);

    this.add(entryPanel, BorderLayout.CENTER);

    projectVersionField.addKeyListener(this);
    projectNameField.addKeyListener(this);
  }
コード例 #23
0
 public void run() {
   Thread t = Thread.currentThread();
   while (t == gameloop) {
     try {
       Thread.sleep(20);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     repaint();
   }
 }
コード例 #24
0
 /** Toggles state on call in different thread. */
 public void run() {
   try {
     doRun();
   } finally {
     synchronized (this) {
       if (Thread.currentThread().equals(muteRunner)) {
         muteRunner = null;
         setEnabled(true);
       }
     }
   }
 }
コード例 #25
0
ファイル: Animation.java プロジェクト: maeyler/Automata
 public void run() {
   if (Thread.currentThread() != T) throw new Error("do not call directly -- use start()");
   while (T != null) {
     int d = anim.doTick();
     if (d < 50) d = 50;
     if (d > 2000) d = 2000;
     try {
       Thread.sleep(d);
     } catch (Exception ex) {
     }
   }
 }
コード例 #26
0
 {
   URL url;
   // Load the image icons
   url = Thread.currentThread().getContextClassLoader().getResource("images/nav_left_blue.png");
   if (url != null) {
     packetReceivedIcon = new ImageIcon(url);
   }
   url = Thread.currentThread().getContextClassLoader().getResource("images/nav_right_red.png");
   if (url != null) {
     packetSentIcon = new ImageIcon(url);
   }
   url = Thread.currentThread().getContextClassLoader().getResource("images/photo_portrait.png");
   if (url != null) {
     presencePacketIcon = new ImageIcon(url);
   }
   url =
       Thread.currentThread()
           .getContextClassLoader()
           .getResource("images/question_and_answer.png");
   if (url != null) {
     iqPacketIcon = new ImageIcon(url);
   }
   url = Thread.currentThread().getContextClassLoader().getResource("images/message.png");
   if (url != null) {
     messagePacketIcon = new ImageIcon(url);
   }
   url = Thread.currentThread().getContextClassLoader().getResource("images/unknown.png");
   if (url != null) {
     unknownPacketTypeIcon = new ImageIcon(url);
   }
 }
コード例 #27
0
  public void runWriteAction(@NotNull final Runnable action) {
    assertCanRunWriteAction();

    ActivityTracker.getInstance().inc();
    fireBeforeWriteActionStart(action);
    final AtomicBoolean stopped = new AtomicBoolean(false);

    if (ourDumpThreadsOnLongWriteActionWaiting > 0) {
      executeOnPooledThread(
          new Runnable() {
            @Override
            public void run() {
              while (!stopped.get()) {
                try {
                  Thread.sleep(ourDumpThreadsOnLongWriteActionWaiting);
                  if (!stopped.get()) {
                    PerformanceWatcher.getInstance().dumpThreads(true);
                  }
                } catch (InterruptedException ignored) {
                }
              }
            }
          });
    }

    LOG.assertTrue(
        myActionsLock.isWriteLockAcquired(Thread.currentThread())
            || !Thread.holdsLock(PsiLock.LOCK),
        "Thread must not hold PsiLock while performing writeAction");
    try {
      myActionsLock.writeLock().acquire();
    } catch (InterruptedException e) {
      throw new RuntimeInterruptedException(e);
    }
    stopped.set(true);

    try {
      myWriteActionsStack.push(action);

      fireWriteActionStarted(action);

      action.run();
    } finally {
      try {
        fireWriteActionFinished(action);

        myWriteActionsStack.pop();
      } finally {
        myActionsLock.writeLock().release();
      }
    }
  }
コード例 #28
0
 @TestOnly
 public static void dispatchAllInvocationEventsInIdeEventQueue() throws InterruptedException {
   assert SwingUtilities.isEventDispatchThread() : Thread.currentThread();
   final EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
   while (true) {
     AWTEvent event = eventQueue.peekEvent();
     if (event == null) break;
     AWTEvent event1 = eventQueue.getNextEvent();
     if (event1 instanceof InvocationEvent) {
       IdeEventQueue.getInstance().dispatchEvent(event1);
     }
   }
 }
コード例 #29
0
  @Override
  public void run() {

    int i = 0;
    if (command.equalsIgnoreCase("Open")) {
      synchronized (door) {
        while (i < 5) {
          System.out.println("i value" + i);
          door.setDoorStatus("OPENING");
          try {
            Thread.currentThread().sleep(500); // 2000
          } catch (InterruptedException e) {
            return; // e.printStackTrace();
          }
          i = i + 2;
        }

        door.setDoorStatus("OPENED");
        door.notifyAll();
      }
    } else {

      synchronized (door) {
        while (i < 5) {
          System.out.println("i value" + i);
          door.setDoorStatus("CLOSING");
          try {
            Thread.currentThread().sleep(500); // 2000
          } catch (InterruptedException e) {
            return; // e.printStackTrace();
          }
          i = i + 2;
        }

        door.setDoorStatus("CLOSED");
        door.notifyAll();
      }
    }
  }
コード例 #30
0
 public void start() {
   int i = 0;
   while (true) {
     lbl_rollNo.setFont(fonts.get(i));
     i = (i + 1) % fonts.size();
     // Code to sleep for 3 seconds
     try {
       Thread.currentThread().sleep(3000);
     } catch (InterruptedException iex) {
       iex.printStackTrace();
     }
   }
 }