示例#1
0
  /** This is the heart of the event manager, which processes the events for a robot. */
  public void processEvents() {
    // Remove old events
    eventQueue.clear(getTime() - MAX_EVENT_STACK);

    // Process custom events
    for (Condition customEvent : customEvents) {
      boolean conditionSatisfied = callUserCode(customEvent);
      if (conditionSatisfied) {
        addImpl(new CustomEvent(customEvent));
      }
    }

    // Sort the events based on the time and priority of the events
    eventQueue.sort();

    // Process event queue here
    Event currentEvent;
    while ((currentEvent = (eventQueue.size() > 0) ? eventQueue.get(0) : null) != null
        && currentEvent.getPriority() >= currentTopEventPriority) {

      if (currentEvent.getPriority() == currentTopEventPriority) {
        if (currentTopEventPriority > Integer.MIN_VALUE
            && isInterruptible(currentTopEventPriority)) {
          setInterruptible(currentTopEventPriority, false); // we're going to restart it, so reset.

          // We are already in an event handler, took action, and a new event was generated.
          // So we want to break out of the old handler to process it here.
          throw new EventInterruptedException(currentEvent.getPriority());
        }
        break;
      }

      int oldTopEventPriority = currentTopEventPriority;

      currentTopEventPriority = currentEvent.getPriority();
      currentTopEvent = currentEvent;

      eventQueue.remove(currentEvent);
      try {
        dispatch(currentEvent);

        setInterruptible(currentTopEventPriority, false);

      } catch (EventInterruptedException e) {
        currentTopEvent = null;
      } catch (RuntimeException e) {
        currentTopEvent = null;
        throw e;
      } catch (Error e) {
        currentTopEvent = null;
        throw e;
      } finally {
        currentTopEventPriority = oldTopEventPriority;
      }
    }
  }
 @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);
     }
   }
 }
示例#3
0
 /**
  * Internal method for adding an event to the event queue.
  *
  * @param event is the event to add to the event queue.
  */
 private void addImpl(Event event) {
   if (eventQueue != null) {
     if (eventQueue.size() > MAX_QUEUE_SIZE) {
       robotProxy.println(
           "Not adding to "
               + robotProxy.getStatics().getName()
               + "'s queue, exceeded "
               + MAX_QUEUE_SIZE
               + " events in queue.");
     } else {
       HiddenAccess.setEventTime(event, getTime());
       eventQueue.add(event);
     }
   }
 }
示例#4
0
  void processSetProperties(JSONObject data) {
    final String tokenId = data.getString("tokenId");
    final Token token = findTokenFromId(tokenId);
    final Zone zone = findZoneTokenIsOn(token);

    if (token == null) {
      System.out.println("DEBUG: sendTokenInfo(): Unable to find token " + tokenId);
      return;
      // FIXME: log this error
    }

    final JSONObject props = data.getJSONObject("properties");
    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            Set<String> pnames = props.keySet();
            for (String pname : pnames) {
              String val = props.getString(pname);
              token.setProperty(pname, val);
            }

            zone.putToken(token);
          }
        });
  }
示例#5
0
    @Override
    public void keyPressed(KeyEvent evt) {
      switch (evt.getKeyCode()) {
        case KeyEvent.VK_SPACE:
          goToSelectedNode(M_OPEN);

          // f**k me dead
          EventQueue.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  resultTree.requestFocus();
                }
              });

          evt.consume();
          break;
        case KeyEvent.VK_ENTER:
          goToSelectedNode(M_OPEN);
          evt.consume();
          break;
        case KeyEvent.VK_DELETE:
          removeSelectedNode();
          evt.consume();
          break;
        default:
          break;
      }
    }
示例#6
0
  /**
   * Constructor.
   *
   * @param session Session object for this service
   * @param urlname URLName object to be used for this service
   */
  protected Service(Session session, URLName urlname) {
    this.session = session;
    debug = session.getDebug();
    url = urlname;

    /*
     * Initialize the URLName with default values.
     * The URLName will be updated when connect is called.
     */
    String protocol = null;
    String host = null;
    int port = -1;
    String user = null;
    String password = null;
    String file = null;

    // get whatever information we can from the URL
    // XXX - url should always be non-null here, Session
    //       passes it into the constructor
    if (url != null) {
      protocol = url.getProtocol();
      host = url.getHost();
      port = url.getPort();
      user = url.getUsername();
      password = url.getPassword();
      file = url.getFile();
    }

    // try to get protocol-specific default properties
    if (protocol != null) {
      if (host == null) host = session.getProperty("mail." + protocol + ".host");
      if (user == null) user = session.getProperty("mail." + protocol + ".user");
    }

    // try to get mail-wide default properties
    if (host == null) host = session.getProperty("mail.host");

    if (user == null) user = session.getProperty("mail.user");

    // try using the system username
    if (user == null) {
      try {
        user = System.getProperty("user.name");
      } catch (SecurityException sex) {
        // XXX - it's not worth creating a MailLogger just for this
        // logger.log(Level.CONFIG, "Can't get user.name property", sex);
      }
    }

    url = new URLName(protocol, host, port, file, user, password);

    // create or choose the appropriate event queue
    String scope = session.getProperties().getProperty("mail.event.scope", "folder");
    Executor executor = (Executor) session.getProperties().get("mail.event.executor");
    if (scope.equalsIgnoreCase("application")) q = EventQueue.getApplicationEventQueue(executor);
    else if (scope.equalsIgnoreCase("session")) q = session.getEventQueue();
    else // if (scope.equalsIgnoreCase("store") ||
      //     scope.equalsIgnoreCase("folder"))
      q = new EventQueue(executor);
  }
示例#7
0
  /**
   * Main method. Begins the GUI, and the rest of the program.
   *
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    // playSound();
    try {
      for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException ex) {
      Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
    }
    // </editor-fold>

    /* Create and display the form */
    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            new mainForm().setVisible(true);
          }
        });
  }
示例#8
0
  /** Is called when the applet wants to be resized. */
  @Override
  public void appletResize(int width, int height) {
    currentAppletSize.width = width;
    currentAppletSize.height = height;
    final Dimension currentSize = new Dimension(currentAppletSize.width, currentAppletSize.height);

    if (loader != null) {
      AppContext appCtxt = loader.getAppContext();
      if (appCtxt != null) appEvtQ = (java.awt.EventQueue) appCtxt.get(AppContext.EVENT_QUEUE_KEY);
    }

    final AppletPanel ap = this;
    if (appEvtQ != null) {
      appEvtQ.postEvent(
          new InvocationEvent(
              Toolkit.getDefaultToolkit(),
              new Runnable() {
                @Override
                public void run() {
                  if (ap != null) {
                    ap.dispatchAppletEvent(APPLET_RESIZE, currentSize);
                  }
                }
              }));
    }
  }
示例#9
0
 synchronized void append(String val) {
   values.add(val);
   if (queue) {
     queue = false;
     EventQueue.invokeLater(this);
   }
 }
示例#10
0
  // {{{ BrowserView constructor
  BrowserView(final VFSBrowser browser) {
    this.browser = browser;

    tmpExpanded = new HashSet<String>();
    DockableWindowManager dwm = jEdit.getActiveView().getDockableWindowManager();
    KeyListener keyListener = dwm.closeListener(VFSBrowser.NAME);

    parentDirectories = new ParentDirectoryList();
    parentDirectories.addKeyListener(keyListener);
    parentDirectories.setName("parent");

    parentDirectories.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    parentDirectories.setCellRenderer(new ParentDirectoryRenderer());
    parentDirectories.setVisibleRowCount(5);
    parentDirectories.addMouseListener(new ParentMouseHandler());

    final JScrollPane parentScroller = new JScrollPane(parentDirectories);
    parentScroller.setMinimumSize(new Dimension(0, 0));

    table = new VFSDirectoryEntryTable(this);
    table.addMouseListener(new TableMouseHandler());
    table.addKeyListener(new TableKeyListener());
    table.setName("file");
    JScrollPane tableScroller = new JScrollPane(table);
    tableScroller.setMinimumSize(new Dimension(0, 0));
    tableScroller.getViewport().setBackground(table.getBackground());
    tableScroller.getViewport().addMouseListener(new TableMouseHandler());
    splitPane =
        new JSplitPane(
            browser.isHorizontalLayout() ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT,
            parentScroller,
            tableScroller);
    splitPane.setOneTouchExpandable(true);

    EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            String prop =
                browser.isHorizontalLayout()
                    ? "vfs.browser.horizontalSplitter"
                    : "vfs.browser.splitter";
            int loc = jEdit.getIntegerProperty(prop, -1);
            if (loc == -1) loc = parentScroller.getPreferredSize().height;

            splitPane.setDividerLocation(loc);
            parentDirectories.ensureIndexIsVisible(parentDirectories.getModel().getSize());
          }
        });

    if (browser.isMultipleSelectionEnabled())
      table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    else table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    setLayout(new BorderLayout());

    add(BorderLayout.CENTER, splitPane);

    propertiesChanged();
  } // }}}
示例#11
0
文件: Server.java 项目: w4-pwr/studia
 public static void main(String[] args) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           new Server();
         }
       });
 }
示例#12
0
 public static void main(String... args) {
   EventQueue.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           createAndShowGUI();
         }
       });
 }
示例#13
0
 @Override
 public void actionPerformed(ActionEvent e) {
   EventQueue.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           fireEditingStopped();
         }
       });
 }
 protected void callSelectListeners(final SelectEvent event) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           for (SelectListener listener : eventListeners.getListeners(SelectListener.class)) {
             listener.selected(event);
           }
         }
       });
 }
 protected void callPositionListeners(final PositionEvent event) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           for (PositionListener listener : eventListeners.getListeners(PositionListener.class)) {
             listener.moved(event);
           }
         }
       });
 }
示例#16
0
 public static void main(String[] args) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           JFrame frame = new PostTestFrame();
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);
         }
       });
 }
示例#17
0
 synchronized void clear() {
   clear = true;
   curLength = 0;
   lengths.clear();
   values.clear();
   if (queue) {
     queue = false;
     EventQueue.invokeLater(this);
   }
 }
 public static void main(String[] args) throws Exception {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           JFrame frame = new SwingWorkerFrame();
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);
         }
       });
 }
 protected void callRenderingExceptionListeners(final Throwable exception) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           for (RenderingExceptionListener listener :
               eventListeners.getListeners(RenderingExceptionListener.class)) {
             listener.exceptionThrown(exception);
           }
         }
       });
 }
示例#20
0
 public void fireShowJoystickError(final String msg) {
   final Component owner = this.joyFrm;
   if ((owner != null) && (msg != null)) {
     EventQueue.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             BasicDlg.showErrorDlg(owner, msg);
           }
         });
   }
 }
示例#21
0
 /**
  * Add the event and vector of listeners to the queue to be delivered.
  *
  * @param event the event
  * @param vector the vector of listeners
  */
 protected void queueEvent(MailEvent event, Vector vector) {
   /*
    * Copy the vector in order to freeze the state of the set
    * of EventListeners the event should be delivered to prior
    * to delivery.  This ensures that any changes made to the
    * Vector from a target listener's method during the delivery
    * of this event will not take effect until after the event is
    * delivered.
    */
   Vector v = (Vector) vector.clone();
   q.enqueue(event, v);
 }
 /** Launch the application. */
 public static void main(String[] args) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           try {
             TestSauvegardeChargement window = new TestSauvegardeChargement();
             window.frame.setVisible(true);
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       });
 }
示例#23
0
 /**
  * Launch the application
  *
  * @param args
  */
 public static void main(String args[]) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           try {
             DateTimer frame = new DateTimer();
             frame.setVisible(true);
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       });
 }
示例#24
0
  public static void main(String[] args) {
    EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            try {
              SotrudnikDialog frame = new SotrudnikDialog();
              frame.setVisible(true);

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
  }
示例#25
0
  public static void main(String[] args) {
    EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            // int rows, int cols, int hgap, int vgap
            new Test(
                AwtLayoutAdapter.of(GridLayout2.of(40, 10, 4, 2)), generateRandomComponents(400));
            // new Test(new GridLayout(4, 4, 4, 2), generateRandomComponents(14));
            // new Test(4, new Insets(1, 2, 1, 2), generateRandomComponents(14));

            // new Test(new GridLayout(3, 2, 2, 2), generateChangePasswordComponents());
            // new Test(new GridLayout2(3, 2, 2, 2), generateChangePasswordComponents());
            // new Test(2, new Insets(1, 1, 1, 1), generateChangePasswordComponents());
          }
        });
  }
示例#26
0
  // used to actually bring up the window
  public void run() {

    // this creates the window
    Runnable runner =
        new Runnable() {

          public void run() {

            // create the main frame
            frame = new JFrame("Search result: " + myFName);
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

            // create the area to display the text
            JTextArea textArea = new JTextArea();
            textArea.setLineWrap(true);
            textArea.insert(stringToCheck, 0);
            JScrollPane scrollPane = new JScrollPane(textArea);
            frame.add(scrollPane, BorderLayout.CENTER);

            // create the button and the area where it is displated
            JPanel dotPanel = new JPanel(new BorderLayout());
            JButton myButton;
            if (myFileList.size() != 0) myButton = new JButton("Onto next file");
            else myButton = new JButton("Done");
            dotPanel.add(myButton, BorderLayout.CENTER);
            frame.add(dotPanel, BorderLayout.SOUTH);

            // this listens for a user to click the "done" button
            ActionListener buttonListener =
                new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                    iAmDone.release(1);
                    frame.dispose();
                  }
                };

            // add the button and make the frame visible
            myButton.addActionListener(buttonListener);
            frame.setSize(500, 500);
            frame.setVisible(true);
          }
        };

    // run the window
    EventQueue.invokeLater(runner);
  }
示例#27
0
 public void run() {
   try {
     while (true) {
       EventQueue.invokeLater(
           new Runnable() {
             public void run() {
               combo.showPopup();
               int i = Math.abs(generator.nextInt());
               if (i % 2 == 0) combo.insertItemAt(new Integer(i), 0);
               else if (combo.getItemCount() > 0) combo.removeItemAt(i % combo.getItemCount());
             }
           });
       Thread.sleep(1);
     }
   } catch (InterruptedException e) {
   }
 }
示例#28
0
 @Override
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   System.out.println("getTableCellEditorComponent");
   setFont(table.getFont());
   setText(Objects.toString(value, ""));
   EventQueue.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           setCaretPosition(getText().length());
           requestFocusInWindow();
           System.out.println("invokeLater: getTableCellEditorComponent");
         }
       });
   return scroll;
 }
示例#29
0
 private void updJoystickFrm(final int joyNum) {
   final JoystickFrm joyFrm = this.joyFrm;
   if ((joyFrm != null) && (joyNum >= 0) && (joyNum < this.joyThreads.length)) {
     int nJoys = 0;
     EmuSys emuSys = this.emuSys;
     if (emuSys != null) {
       nJoys = emuSys.getSupportedJoystickCount();
     }
     final boolean emulated = (joyNum < nJoys);
     final boolean connected = (this.joyThreads[joyNum] != null);
     EventQueue.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             joyFrm.setJoystickState(joyNum, emulated, connected);
           }
         });
   }
 }
示例#30
0
  /**
   * @param searchNode the result node
   * @param selectNode the node that must be selected, or null
   * @since jEdit 4.3pre12
   */
  public void searchDone(
      final DefaultMutableTreeNode searchNode, final DefaultMutableTreeNode selectNode) {
    stop.setEnabled(false);
    final int nodeCount = searchNode.getChildCount();
    if (nodeCount < 1) {
      searchFailed();
      return;
    }

    caption.setText(
        jEdit.getProperty("hypersearch-results.done", new String[] {trimSearchString()}));

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            if (!multiStatus) {
              for (int i = 0; i < resultTreeRoot.getChildCount(); i++) {
                resultTreeRoot.remove(0);
              }
            }

            resultTreeRoot.add(searchNode);
            resultTreeModel.reload(resultTreeRoot);

            for (int i = 0; i < nodeCount; i++) {
              TreePath lastNode =
                  new TreePath(((DefaultMutableTreeNode) searchNode.getChildAt(i)).getPath());

              resultTree.expandPath(lastNode);
            }
            TreePath treePath;
            if (selectNode == null) {
              treePath = new TreePath(new Object[] {resultTreeRoot, searchNode});
            } else {
              treePath = new TreePath(selectNode.getPath());
            }
            resultTree.setSelectionPath(treePath);
            resultTree.scrollPathToVisible(treePath);
          }
        });
  } // }}}