@Override
  public void setPressed(boolean b) {
    if ((isPressed() == b) || !isEnabled()) {
      return;
    }

    if (!b && isArmed()) {
      updateState();
    }

    if (b) {
      stateMask |= PRESSED;
    } else {
      stateMask &= ~PRESSED;
    }

    fireStateChanged();

    if (!isPressed() && isArmed()) {
      int modifiers = 0;
      AWTEvent currentEvent = EventQueue.getCurrentEvent();
      if (currentEvent instanceof InputEvent) {
        modifiers = ((InputEvent) currentEvent).getModifiers();
      } else if (currentEvent instanceof ActionEvent) {
        modifiers = ((ActionEvent) currentEvent).getModifiers();
      }
      fireActionPerformed(
          new ActionEvent(
              this,
              ActionEvent.ACTION_PERFORMED,
              getActionCommand(),
              EventQueue.getMostRecentEventTime(),
              modifiers));
    }
  }
Example #2
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) {
     }
   }
 }
Example #3
0
 public void scrollBy(final int x, final int y) {
   if (EventQueue.isDispatchThread()) {
     this.scrollByImpl(x, y);
   } else {
     EventQueue.invokeLater(() -> scrollByImpl(x, y));
   }
 }
    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);
    }
Example #5
0
 /**
  * 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());
   }
 }
 private void AceptarActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_AceptarActionPerformed
   if (Ver_alumno.isSelected()) {
     setVisible(false);
     java.awt.EventQueue.invokeLater(
         new Runnable() {
           public void run() {
             new VerAlumnos().setVisible(true);
           }
         });
   } else {
     if (Act_Alumno.isSelected()) {
       setVisible(false);
       java.awt.EventQueue.invokeLater(
           new Runnable() {
             public void run() {
               new Actualizar_Alumno().setVisible(true);
             }
           });
     } else {
       if (Crear_Alumno.isSelected()) {
         setVisible(false);
         java.awt.EventQueue.invokeLater(
             new Runnable() {
               public void run() {
                 new Crear_Alumnos().setVisible(true);
               }
             });
       }
     }
   }
 } // GEN-LAST:event_AceptarActionPerformed
Example #7
0
 /**
  * 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));
   }
 }
Example #8
0
  /**
   * Allows a custom EventQueue implementation to replace this one. All pending events are
   * transferred to the new queue. Calls to postEvent, getNextEvent, and peekEvent and others are
   * forwarded to the pushed queue until it is removed with a pop().
   *
   * @exception NullPointerException if newEventQueue is null.
   */
  public synchronized void push(EventQueue newEventQueue) {
    if (newEventQueue == null) throw new NullPointerException();

    /* Make sure we are at the top of the stack because callers can
    only get a reference to the one at the bottom using
    Toolkit.getDefaultToolkit().getSystemEventQueue() */
    if (next != null) {
      next.push(newEventQueue);
      return;
    }

    /* Make sure we have a live dispatch thread to drive the queue */
    if (dispatchThread == null) dispatchThread = new EventDispatchThread(this);

    synchronized (newEventQueue) {
      // The RI transfers the events without calling the new eventqueue's
      // push(), but using getNextEvent().
      while (peekEvent() != null) {
        try {
          newEventQueue.postEventImpl(getNextEvent());
        } catch (InterruptedException ex) {
          // What should we do with this?
          ex.printStackTrace();
        }
      }
      newEventQueue.prev = this;
    }

    next = newEventQueue;
  }
  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) {
      }
    }
  }
 public void run() {
   if (!EventQueue.isDispatchThread()) {
     EventQueue.invokeLater(this);
   } else {
     doRun();
   }
 }
  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);
  }
 public void startModelValidating() {
   if (!isModelValid() && !validationStarted) {
     validationStarted = true;
     EventQueue.invokeLater(
         () -> {
           Scripts.LocalContext context = Scripts.getContext();
           RP.execute(
               () -> {
                 Scripts.setContext(context);
                 try {
                   validateModel();
                 } catch (Exception ex) {
                   Logger.getLogger(PlatypusDataObject.class.getName())
                       .log(Level.WARNING, ex.getMessage(), ex);
                 } finally {
                   Scripts.setContext(null);
                   EventQueue.invokeLater(
                       () -> {
                         validationStarted = false;
                         setModelValid(true);
                       });
                 }
               });
         });
   }
 }
  public void doTest() throws Exception {

    try {

      robot.waitForIdle(delay);

      for (DialogOwner owner : DialogOwner.values()) {

        EventQueue.invokeLater(
            () -> {
              createGUI(owner);
            });

        robot.waitForIdle(delay);

        dialog.activated.waitForFlagTriggered();
        assertTrue(
            dialog.activated.flag(),
            "Dialog did not trigger " + "Window Activated event when it became visible");

        dialog.closeGained.waitForFlagTriggered();
        assertTrue(
            dialog.closeGained.flag(),
            "The 1st button did not " + "gain focus when the dialog became visible");

        dialog.checkUnblockedDialog(robot, "");
        robot.waitForIdle(delay);
      }

    } finally {
      EventQueue.invokeAndWait(this::closeAll);
    }
  }
Example #14
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);
      }
    }
  }
Example #15
0
 /** see: http://www.javakey.net/4-java-gui/686df4a3d194cade.htm */
 private synchronized void startModal() {
   if (this.isVisible() && !this.isShowing()) {
     Container parent = this.getParent();
     while (parent != null) {
       if (parent.isVisible() == false) {
         parent.setVisible(true);
       }
       parent = parent.getParent();
     }
   }
   try {
     if (SwingUtilities.isEventDispatchThread()) {
       EventQueue theQueue = getToolkit().getSystemEventQueue();
       while (this.isVisible()) {
         AWTEvent event = theQueue.getNextEvent();
         Object source = event.getSource();
         if (event instanceof ActiveEvent) {
           ((ActiveEvent) event).dispatch();
         } else if (source instanceof Component) {
           ((Component) source).dispatchEvent(event);
         } else if (source instanceof MenuComponent) {
           ((MenuComponent) source).dispatchEvent(event);
         } else {
           System.err.println("Unable to dispatch: " + event);
         }
       }
     } else {
       while (this.isVisible()) {
         wait();
       }
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
 private void wakeupEDT() {
   if (log.isLoggable(PlatformLogger.Level.FINEST)) {
     log.finest("wakeupEDT(): EDT == " + dispatchThread);
   }
   EventQueue eq = dispatchThread.getEventQueue();
   eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT));
 }
    @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);
      }
    }
 /**
  * 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);
   }
 }
Example #19
0
  /**
   * This arranges for runnable to have its run method called in the dispatch thread of the
   * EventQueue. This will happen after all pending events are processed.
   *
   * @since 1.2
   */
  public static void invokeLater(Runnable runnable) {
    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();

    InvocationEvent ie = new InvocationEvent(eq, runnable, null, false);

    eq.postEvent(ie);
  }
Example #20
0
 @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];
 }
Example #21
0
  private void createGUI() throws Exception {

    EventQueue.invokeAndWait(this::showParent);
    robot.waitForIdle(delay);
    EventQueue.invokeLater(this::showChild);
    robot.waitForIdle(delay);
  }
Example #22
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;
  }
  /** Initializes the core phone objects. */
  private void initializePhone() {
    // Load Preferences
    loadPreferences();

    if (preferences == null) {
      return;
    }

    guiManager = new GuiManager();
    guiManager.addUserActionListener(this);
    logManager = new LogManagerImpl(this);

    this.getLogManager().setRemoteLogging(true);

    try {
      EventQueue.invokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              registerMenu = new JCheckBoxMenuItem(PhoneRes.getIString("phone.enabled"));
            }
          });
    } catch (Exception e) {
      Log.error(e);
    }

    registerMenu.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (getStatus() == SipRegisterStatus.Unregistered
                || getStatus() == SipRegisterStatus.RegistrationFailed) {

              register();
            } else {
              handleUnregisterRequest();
            }
          }
        });

    SIPConfig.setPreferredNetworkAddress(preferences.getPreferredAddress());
    NetworkAddressManager.start();

    try {
      EventQueue.invokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              // Initialize Missed calls
              missedCalls = new MissedCalls();
            }
          });
    } catch (Exception e) {
      Log.error(e);
    }

    final JMenu actionsMenu =
        SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
    actionsMenu.add(registerMenu);
  }
Example #24
0
  /**
   * 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));
    }
  }
Example #25
0
 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));
   }
 }
Example #26
0
 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"));
   }
 }
Example #27
0
 public void handleDocumentRendering(
     final NavigatorFrame frame,
     final ClientletResponse response,
     final ComponentContent content) {
   if (EventQueue.isDispatchThread()) {
     this.handleDocumentRenderingImpl(frame, response, content);
   } else {
     EventQueue.invokeLater(
         () -> BrowserPanel.this.handleDocumentRenderingImpl(frame, response, content));
   }
 }
Example #28
0
 /**
  * Construct a logger.
  *
  * @param titleMessage for the title bar of the dialog box
  * @param width initial width of the resizeable dialog box
  * @param height initial height of the resizeable dialog box
  * @param exitApplicationOnClose if true, when the dialog box is closed (X-d out), will exit the
  *     application with success status
  * @param visible if true, will be made visible after construction
  */
 public DialogMessageLogger(
     String titleMessage, int width, int height, boolean exitApplicationOnClose, boolean visible) {
   if (java.awt.EventQueue.isDispatchThread()) {
     System.err.println("DialogMessageLogger(): constructing on EDT");
     createGUI(titleMessage, width, height, exitApplicationOnClose, visible);
   } else {
     System.err.println("DialogMessageLogger(): constructing on non-EDT");
     java.awt.EventQueue.invokeLater(
         new CreateGUIRunnable(titleMessage, width, height, exitApplicationOnClose, visible));
   }
 }
 // Post the given event to the corresponding event queue for the given component.
 void postEvent(@Nullable Component c, @Nonnull AWTEvent event) {
   // Force an update of the input state, so that we're in synch internally. Otherwise we might
   // post more events before
   // this one gets processed and end up using stale values for those events.
   inputState.update(event);
   EventQueue eventQueue = eventQueueFor(c);
   if (eventQueue != null) {
     eventQueue.postEvent(event);
   }
   pause(settings.delayBetweenEvents());
 }
 /**
  * Pass an event onto the AWT component.
  *
  * @see java.awt.Component#processEvent(java.awt.AWTEvent)
  */
 protected final void processEvent(AWTEvent event) {
   AppContext ac = SunToolkit.targetToAppContext(target);
   if (ac == null) {
     target.dispatchEvent(SwingToolkit.convertEvent(event, target));
   } else {
     EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY);
     if (eq == null) {
       target.dispatchEvent(SwingToolkit.convertEvent(event, target));
     } else {
       eq.postEvent(SwingToolkit.convertEvent(event, target));
     }
   }
 }