コード例 #1
0
  @Override
  public ActionCallback show() {
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    if (myTypeAheadCallback != null) {
      IdeFocusManager.getInstance(myProject).typeAheadUntil(myTypeAheadCallback);
    }
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    final ActionCallback result = new ActionCallback();

    final AnCancelAction anCancelAction = new AnCancelAction();
    final JRootPane rootPane = getRootPane();
    anCancelAction.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)), rootPane);
    myDisposeActions.add(
        new Runnable() {
          @Override
          public void run() {
            anCancelAction.unregisterCustomShortcutSet(rootPane);
          }
        });

    if (!myCanBeParent && myWindowManager != null) {
      myWindowManager.doNotSuggestAsParent(myDialog.getWindow());
    }

    final CommandProcessorEx commandProcessor =
        ApplicationManager.getApplication() != null
            ? (CommandProcessorEx) CommandProcessor.getInstance()
            : null;
    final boolean appStarted = commandProcessor != null;

    if (myDialog.isModal() && !isProgressDialog()) {
      if (appStarted) {
        commandProcessor.enterModal();
        LaterInvocator.enterModal(myDialog);
      }
    }

    if (appStarted) {
      hidePopupsIfNeeded();
    }

    try {
      myDialog.show();
    } finally {
      if (myDialog.isModal() && !isProgressDialog()) {
        if (appStarted) {
          commandProcessor.leaveModal();
          LaterInvocator.leaveModal(myDialog);
        }
      }

      myDialog.getFocusManager().doWhenFocusSettlesDown(result.createSetDoneRunnable());
    }

    return result;
  }
コード例 #2
0
  public void run() {
    do {
      try {
        Thread.sleep(time);
      } catch (InterruptedException e) {
        // Auto-generated catch block
        throw new RuntimeException(e);
      }

      if (run != this.runtime.runNumber) {
        break;
      }

      if (EventQueue.isDispatchThread()) {
        runner.run(Context.enter());
      } else {
        try {
          EventQueue.invokeAndWait(runner);
        } catch (Exception e) {

          e.printStackTrace();
        }
      }
    } while (loop);
  }
コード例 #3
0
 /** Repaints immediately the component. */
 public void immediateRepaint() {
   if (EventQueue.isDispatchThread()) {
     Rectangle visRect = getRenderRect();
     if (doubleBufferedRendering)
       repaint(
           visRect.x, visRect.y,
           visRect.width, visRect.height);
     else
       paintImmediately(
           visRect.x, visRect.y,
           visRect.width, visRect.height);
   } else {
     try {
       EventQueue.invokeAndWait(
           new Runnable() {
             public void run() {
               Rectangle visRect = getRenderRect();
               if (doubleBufferedRendering)
                 repaint(
                     visRect.x, visRect.y,
                     visRect.width, visRect.height);
               else
                 paintImmediately(
                     visRect.x, visRect.y,
                     visRect.width, visRect.height);
             }
           });
     } catch (Exception e) {
     }
   }
 }
コード例 #4
0
  public synchronized void expand() {
    if (EventQueue.isDispatchThread()) {
      EventQueue.invokeLater(
          new Runnable() {

            @Override
            public void run() {
              _expand();
            }
          });
    } else {
      try {
        EventQueue.invokeAndWait(
            new Runnable() {

              @Override
              public void run() {
                _expand();
              }
            });
      } catch (InterruptedException | InvocationTargetException e) {
        System.err.println(e);
      }
    }
  }
コード例 #5
0
  void appendOutput(final String line) {
    if (!EventQueue.isDispatchThread()) {
      EventQueue.invokeLater(
          new Runnable() {
            public void run() {
              appendOutput(line);
            }
          });

      return;
    }
    if (!isShowing()) { // ignore request, dialog is closed
      return;
    }

    // Can now accept user input
    outputArea.setEditable(true);
    Document doc = outputArea.getDocument();

    if (doc != null) {
      try {
        doc.insertString(doc.getLength(), line + "\n", null); // NOI18N
      } catch (BadLocationException e) {
      }
    }
  }
コード例 #6
0
ファイル: HtmlPanel.java プロジェクト: bogas04/gngr
 public void scrollBy(final int x, final int y) {
   if (EventQueue.isDispatchThread()) {
     this.scrollByImpl(x, y);
   } else {
     EventQueue.invokeLater(() -> scrollByImpl(x, y));
   }
 }
コード例 #7
0
ファイル: HtmlPanel.java プロジェクト: bogas04/gngr
 /**
  * Clears the current document if any. If called outside the GUI thread, the operation will be
  * scheduled to be performed in the GUI thread.
  */
 public void clearDocument() {
   if (java.awt.EventQueue.isDispatchThread()) {
     this.clearDocumentImpl();
   } else {
     java.awt.EventQueue.invokeLater(() -> HtmlPanel.this.clearDocumentImpl());
   }
 }
コード例 #8
0
  /**
   * Show the specified message in a modal dialog. If the user clicks on the "Cancel" button, then
   * throw an exception. This gives the user the option of not continuing the execution, something
   * that is particularly useful if continuing execution will result in repeated warnings. NOTE: If
   * this is called outside the swing event thread, then no cancel button is presented and no
   * CancelException will be thrown. This is because the displaying of the message must be deferred
   * to the swing event thread, according to the swing architecture, or we could get deadlock or
   * rendering problems.
   *
   * @param info The message.
   * @exception ptolemy.util.CancelException If the user clicks on the "Cancel" button.
   */
  protected void _warning(final String info) throws CancelException {
    // In swing, updates to showing graphics must be done in the
    // event thread.  If we are in the event thread, then proceed.
    // Otherwise, defer.
    if (EventQueue.isDispatchThread()) {
      super._warning(info);
    } else {
      Runnable doWarning =
          new Runnable() {
            public void run() {
              Object[] options = {"OK"};
              Object[] message = new Object[1];

              // If the message lines are longer than 80 characters, we split it
              // into shorter new line separated strings.
              // Running vergil on a HSIF .xml file will create a line longer
              // than 80 characters
              message[0] = StringUtilities.ellipsis(info, StringUtilities.ELLIPSIS_LENGTH_LONG);

              // Show the MODAL dialog
              /*int selected =*/ JOptionPane.showOptionDialog(
                  getContext(),
                  message,
                  "Warning",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.WARNING_MESSAGE,
                  null,
                  options,
                  options[0]);
            }
          };

      Top.deferIfNecessary(doWarning);
    }
  }
コード例 #9
0
ファイル: HtmlPanel.java プロジェクト: bogas04/gngr
 /**
  * Scrolls to the element identified by the given ID in the current document.
  *
  * <p>If this method is invoked outside the GUI thread, the operation is scheduled to be performed
  * as soon as possible in the GUI thread.
  *
  * @param nameOrId The name or ID of the element in the document.
  */
 public void scrollToElement(final String nameOrId) {
   if (EventQueue.isDispatchThread()) {
     this.scrollToElementImpl(nameOrId);
   } else {
     EventQueue.invokeLater(() -> scrollToElementImpl(nameOrId));
   }
 }
コード例 #10
0
ファイル: RADComponentNode.java プロジェクト: PrimoS/Netbeans
 @Override
 public Node.PropertySet[] getPropertySets() {
   final Node.PropertySet[][] props = new Node.PropertySet[1][];
   Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           FormLAF.executeWithLAFLocks(
               new Runnable() {
                 @Override
                 public void run() {
                   props[0] = component.getProperties();
                 }
               });
         }
       };
   if (EventQueue.isDispatchThread()) {
     runnable.run();
   } else {
     try {
       // We have made some attempts to keep initialization
       // of properties outside AWT thread, but it always
       // deadlocked with AWT thread for various reasons.
       EventQueue.invokeAndWait(runnable);
     } catch (InterruptedException iex) {
       FormUtils.LOGGER.log(Level.INFO, iex.getMessage(), iex);
     } catch (InvocationTargetException itex) {
       FormUtils.LOGGER.log(Level.INFO, itex.getMessage(), itex);
     }
   }
   return props[0];
 }
コード例 #11
0
 public void run() {
   if (!EventQueue.isDispatchThread()) {
     EventQueue.invokeLater(this);
   } else {
     doRun();
   }
 }
コード例 #12
0
ファイル: Report.java プロジェクト: JSansalone/NetBeansIDE
  public boolean containsFailed() {
    assert EventQueue.isDispatchThread();

    /* Called from the EventDispatch thread */

    return (failures + errors) != 0;
  }
コード例 #13
0
 /**
  * Instantiates the given TutorialApplication class, then invokes {@code #startup} with the given
  * arguments. Typically this method is called from an application's #main method.
  *
  * @param appClass the class of the application to launch
  * @param args optional launch arguments, often the main method's arguments.
  */
 public static synchronized void launch(
     final Class /*<? extends TutorialApplication>*/ appClass, final String[] args) {
   Runnable runnable =
       new Runnable() {
         public void run() {
           TutorialApplication application = null;
           try {
             application = (TutorialApplication) appClass.newInstance();
           } catch (InstantiationException e) {
             e.printStackTrace();
             LOGGER.log(Level.SEVERE, "Can't instantiate " + appClass, e);
             return;
           } catch (IllegalAccessException e) {
             e.printStackTrace();
             LOGGER.log(Level.SEVERE, "Illegal Access during launch of " + appClass, e);
             return;
           }
           try {
             application.initializeLookAndFeel();
             application.startup(args);
           } catch (Exception e) {
             String message = "Failed to launch " + appClass;
             // String message = String.format("Failed to launch %s ", appClass);
             LOGGER.log(Level.SEVERE, message, e);
             throw new Error(message, e);
           }
         }
       };
   if (EventQueue.isDispatchThread()) {
     runnable.run();
   } else {
     EventQueue.invokeLater(runnable);
   }
 }
コード例 #14
0
  /**
   * Create a splash screen (borderless graphic for display while other operations are taking
   * place).
   *
   * @param filename a class-relative path to the splash graphic
   * @param callingClass the class to which the graphic filename location is relative
   */
  public SplashScreen(String filename, Class callingClass) {
    super(new Frame());
    URL imageURL = callingClass.getResource(filename);
    image = Toolkit.getDefaultToolkit().createImage(imageURL);
    // Load the image
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
      mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    // Center the window on the screen
    int imgWidth = image.getWidth(this);
    int imgHeight = image.getHeight(this);
    setSize(imgWidth, imgHeight);
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screenDim.width - imgWidth) / 2, (screenDim.height - imgHeight) / 2);

    setVisible(true);
    repaint();
    // if on a single processor machine, wait for painting (see Fast Java Splash Screen.pdf)
    if (!EventQueue.isDispatchThread()) {
      synchronized (this) {
        while (!this.paintCalled) {
          try {
            this.wait();
          } catch (InterruptedException e) {
          }
        }
      }
    }
  }
コード例 #15
0
    @Override
    public void run() {
      if (!EventQueue.isDispatchThread()) {
        ProgressHandle ph;
        ph =
            ProgressHandleFactory.createHandle(
                NbBundle.getMessage(ResultsTopComponent.class, "PreparingResultsWindow.msg"));
        ph.start();
        n = new ResultsNode(query);
        rtcsc = query.getColumns();
        List cols = Arrays.asList(rtcsc);
        Iterator colsIt = cols.iterator();
        alps = new ArrayList();
        while (colsIt.hasNext()) {
          RtcQueryColumn rsc = (RtcQueryColumn) colsIt.next();
          alps.add(rsc.getColumnIdentifier());
          alps.add(rsc.getColumnDisplayName());
        }
        actualCols = alps.toArray(new String[] {});
        EventQueue.invokeLater(this);
        ph.finish();
      } else {
        outlineView.setPropertyColumns(alps.toArray(new String[] {}));
        Outline outline = outlineView.getOutline();
        removeDefaultColumn(outline);
        ETableColumnModel etcm = (ETableColumnModel) outline.getColumnModel();

        // TODO: szymon : change j to proper sort order
        int j = 1;
        for (int i = 1; i < rtcsc.length; i++) {
          ETableColumn etc = (ETableColumn) etcm.getColumn(i);
          if (alps.get(i * 2 - 2).equals("id")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("internalSeverity")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("internalPriority")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("workItemType")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("internalState")) {
            etc.setMaxWidth(85);
          }
          if (alps.get(i * 2 - 2).equals("summary")) {
            etc.setMaxWidth(550);
            etc.setWidth(475);
            etc.setMinWidth(400);
          }
          if (rtcsc[i].isSortColumn()) {
            etcm.setColumnSorted(etc, rtcsc[i].isAscending(), j);
            j++;
          }
        }

        manager.setRootContext(n);
      }
    }
コード例 #16
0
    public void navigabilityChanged(final Wizard wizard) {
      final Runnable runnable =
          new Runnable() {
            @Override
            public void run() {
              if (wizard.isBusy()) {
                next.setEnabled(false);
                prev.setEnabled(false);
                finish.setEnabled(false);
                cancel.setEnabled(false);
                parent.getOuterPanel().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                wasBusy = true;
                return;
              } else if (wasBusy) {
                cancel.setEnabled(true);
                parent.getOuterPanel().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              }
              configureNavigationButtons(wizard, prev, next, finish);

              parent.updateProblem();
            }
          };
      if (EventQueue.isDispatchThread()) runnable.run();
      else EventQueue.invokeLater(runnable);
    }
コード例 #17
0
 @Override
 public IterationValueImpl[] getChildValues(RtcQueryAttributeValue value)
     throws IllegalArgumentException {
   assert (!EventQueue.isDispatchThread());
   ProcessManager pm = area.getLookup().lookup(ProcessManager.class);
   if (value instanceof DevelopmentLineValueImpl) {
     ArrayList<IterationValueImpl> chs = new ArrayList<IterationValueImpl>();
     DevelopmentLine line = ((DevelopmentLineValueImpl) value).getLine();
     for (Iteration impl : pm.getIterations(line)) {
       if (impl instanceof IterationImpl) {
         chs.add(new IterationValueImpl((IterationImpl) impl));
       }
     }
     return chs.toArray(new IterationValueImpl[] {});
   } else {
     if (value instanceof IterationValueImpl) {
       ArrayList<IterationValueImpl> chs = new ArrayList<IterationValueImpl>();
       IterationImpl impl = ((IterationValueImpl) value).getRtcIteration();
       for (Iteration it : pm.getIterations(impl)) {
         if (it instanceof IterationImpl) {
           if (!it.isArchived()) {
             chs.add(new IterationValueImpl((IterationImpl) it));
           }
         }
       }
       return chs.toArray(new IterationValueImpl[] {});
     }
   }
   throw new IllegalArgumentException();
 }
コード例 #18
0
 public void dispose() {
   LOG.assertTrue(EventQueue.isDispatchThread(), Thread.currentThread().getName());
   myAbstractTreeBuilder = null;
   // this will also dispose wrapped TreeModel
   myTreeModelWrapper.dispose();
   myFileEditor = null;
 }
コード例 #19
0
 @Override
 public void paint(final Graphics g) {
   super.paint(g);
   if (!EventQueue.isDispatchThread()) {
     throw new RuntimeException("Wrong thread");
   }
   test();
 }
コード例 #20
0
 @Override
 public void loadCommitsData(
     @NotNull List<Integer> hashes,
     @NotNull Consumer<List<T>> consumer,
     @Nullable ProgressIndicator indicator) {
   assert EventQueue.isDispatchThread();
   loadCommitsData(getCommitsMap(hashes), consumer, indicator);
 }
コード例 #21
0
 @Override
 public EventList<LocalFileItem> getSwingModel() {
   assert EventQueue.isDispatchThread();
   if (swingEventList == null) {
     swingEventList = GlazedListsFactory.swingThreadProxyEventList(readOnlyList);
   }
   return swingEventList;
 }
コード例 #22
0
  /**
   * Ask the user a yes/no/cancel question, and return true if the answer is yes.
   *
   * @param question The yes/no/cancel question.
   * @return True if the answer is yes.
   * @exception ptolemy.util.CancelException If the user clicks on the "Cancel" button.
   */
  protected boolean _yesNoCancelQuestion(final String question) throws CancelException {
    // In swing, updates to showing graphics must be done in the
    // event thread.  If we are in the event thread, then proceed.
    // Otherwise, invoke and wait.
    if (EventQueue.isDispatchThread()) {
      return super._yesNoCancelQuestion(question);
    } else {
      // Place to store results from doYesNoCancel thread.
      // results[0] is the return value ("Yes" or "No").
      // results[1] is the error value ("Cancel").
      final Boolean[] results = new Boolean[2];

      Runnable doYesNoCancel =
          new Runnable() {
            public void run() {
              Object[] message = new Object[1];
              message[0] = StringUtilities.ellipsis(question, StringUtilities.ELLIPSIS_LENGTH_LONG);

              Object[] options = {"Yes", "No", "Cancel"};

              // Show the MODAL dialog
              int selected =
                  JOptionPane.showOptionDialog(
                      getContext(),
                      message,
                      "Warning",
                      JOptionPane.YES_NO_CANCEL_OPTION,
                      JOptionPane.WARNING_MESSAGE,
                      null,
                      options,
                      options[0]);

              if (selected == 0) {
                results[0] = Boolean.TRUE;
              } else if (selected == 2) {
                results[1] = Boolean.TRUE;
              } else {
                results[0] = Boolean.FALSE;
              }
            }
          };

      try {
        // Note: usually we use invokeLater() (see
        // Top.deferIfNecessary()).  However, here, we need
        // the return value.
        SwingUtilities.invokeAndWait(doYesNoCancel);
      } catch (Exception ex) {
        // do nothing.
      }

      if ((results[1] != null) && results[1].booleanValue()) {
        throw new ptolemy.util.CancelException();
      }

      return results[0].booleanValue();
    }
  }
コード例 #23
0
ファイル: HtmlPanel.java プロジェクト: bogas04/gngr
  /**
   * Sets an HTML DOM node and invalidates the component so it is rendered as soon as possible in
   * the GUI thread.
   *
   * <p>If this method is called from a thread that is not the GUI dispatch thread, the document is
   * scheduled to be set later. Note that {@link #setPreferredWidth(int) preferred size}
   * calculations should be done in the GUI dispatch thread for this reason.
   *
   * @param node This should normally be a Document instance obtained with {@link
   *     org.lobobrowser.html.parser.DocumentBuilderImpl}.
   *     <p>
   * @param rcontext A renderer context.
   * @see org.lobobrowser.html.parser.DocumentBuilderImpl#parse(org.xml.sax.InputSource)
   * @see org.lobobrowser.html.test.SimpleHtmlRendererContext
   */
  public void setDocument(final Document node, final HtmlRendererContext rcontext) {
    setCursor(Cursor.getDefaultCursor());

    if (java.awt.EventQueue.isDispatchThread()) {
      this.setDocumentImpl(node, rcontext);
    } else {
      java.awt.EventQueue.invokeLater(() -> HtmlPanel.this.setDocumentImpl(node, rcontext));
    }
  }
コード例 #24
0
 @NotNull
 public ModalityState getDefaultModalityState() {
   if (EventQueue.isDispatchThread()) {
     return getCurrentModalityState();
   } else {
     ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
     return progress == null ? getNoneModalityState() : progress.getModalityState();
   }
 }
コード例 #25
0
ファイル: DialogMessageLogger.java プロジェクト: kullen/MRI
 public void setVisible(boolean visible) {
   if (java.awt.EventQueue.isDispatchThread()) {
     // System.err.println("DialogMessageLogger.setVisible(): on EDT");
     outputDialog.setVisible(visible);
   } else {
     // System.err.println("DialogMessageLogger.setVisible(): on non-EDT");
     java.awt.EventQueue.invokeLater(new SetVisibleRunnable(visible));
   }
 }
コード例 #26
0
ファイル: DialogMessageLogger.java プロジェクト: kullen/MRI
 public void sendLn(String message) {
   if (java.awt.EventQueue.isDispatchThread()) {
     // System.err.println("sendLn(): on EDT");
     outputTextArea.append(message + "\n");
   } else {
     // System.err.println("sendLn(): on non-EDT");
     java.awt.EventQueue.invokeLater(new SendRunnable(message + "\n"));
   }
 }
コード例 #27
0
  void scaleImages(String nameOfChangedImage) {

    if (SnapshotGallery.sharedInstance().isEmpty()) {
      return;
    }

    if (EventQueue.isDispatchThread()) setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    float w = 0, h = 0;
    Insets insets = getInsets();
    int w1 = insets.left + insets.right;
    int h1 = insets.top + insets.bottom + IMAGE_HEIGHT;
    int n = SnapshotGallery.sharedInstance().size();
    String name = null;
    ImageIcon icon = null;
    Image image = null;
    float r = 1;
    for (int i = n - 1; i >= 0; i--) {
      name = SnapshotGallery.sharedInstance().getImageName(i);
      image = SnapshotGallery.sharedInstance().getThumbnail(i);
      if (image == null || name.equals(nameOfChangedImage)) {
        icon = SnapshotGallery.sharedInstance().loadAnnotatedImage(i);
        w = icon.getIconWidth();
        h = icon.getIconHeight();
        r = IMAGE_HEIGHT / h;
        w *= r;
        // This scaling method causes out-of-memory error:
        // icon.getImage().getScaledInstance((int) w, IMAGE_HEIGHT, Image.SCALE_SMOOTH);
        image = ModelerUtilities.scale((BufferedImage) icon.getImage(), r, r);
        SnapshotGallery.sharedInstance().putThumbnail(icon.getDescription(), image);
        image.flush();
        icon.getImage().flush();
      } else {
        w = image.getWidth(this);
        h = image.getHeight(this);
      }
      if (getLayout() instanceof FlowLayout) {
        w1 += (int) w + ((FlowLayout) getLayout()).getHgap();
      } else {
        w1 += (int) w + IMAGE_GAP;
      }
    }
    setPreferredSize(new Dimension(w1, h1));
    if (EventQueue.isDispatchThread()) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }
コード例 #28
0
 private static void assertIsDispatchThread() {
   Application app = ApplicationManager.getApplication();
   if (app != null) {
     if (!app.isUnitTestMode()) {
       app.assertIsDispatchThread();
     }
   } else {
     assert EventQueue.isDispatchThread();
   }
 }
コード例 #29
0
 @Override
 public RtcQueryAttributeValue[] getValues() {
   assert (!EventQueue.isDispatchThread());
   RtcIterationPossibleValues pv = new RtcIterationPossibleValues(area);
   ArrayList<RtcQueryAttributeValueImpl> impls2 = new ArrayList<RtcQueryAttributeValueImpl>();
   for (DevelopmentLine dl : pv.getPossibleValues()) {
     impls2.add(new DevelopmentLineValueImpl(dl));
   }
   return impls2.toArray(new RtcQueryAttributeValue[] {});
 }
コード例 #30
0
 @Override
 public void parentNotify(Container parent) throws VetoException {
   if (EventQueue.isDispatchThread()) {
     super.parentNotify(parent);
     // call getSwingComponent() early to ensure JComponent creation
     getSwingComponent();
   } else {
     throw new VetoException("Trying to install GUI component in GUI incompatible container.");
   }
 }