예제 #1
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);
                  }
                }
              }));
    }
  }
예제 #2
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);
  }
  public static void main(String[] args) {

    StringBuffer result = new StringBuffer("<html><body><h1>Fibonacci Sequence</h1><ol>");

    long f1 = 0;
    long f2 = 1;

    for (int i = 0; i < 50; i++) {
      result.append("<li>");
      result.append(f1);
      long temp = f2;
      f2 = f1 + f2;
      f1 = temp;
    }

    result.append("</ol></body></html>");

    JEditorPane jep = new JEditorPane("text/html", result.toString());
    jep.setEditable(false);

    //  new FibonocciRectangles().execute();
    JScrollPane scrollPane = new JScrollPane(jep);
    JFrame f = new JFrame("Fibonacci Sequence");
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    f.setContentPane(scrollPane);
    f.setSize(512, 342);
    EventQueue.invokeLater(new FrameShower(f));
  }
예제 #4
0
 synchronized void append(String val) {
   values.add(val);
   if (queue) {
     queue = false;
     EventQueue.invokeLater(this);
   }
 }
예제 #5
0
파일: Server.java 프로젝트: w4-pwr/studia
 public static void main(String[] args) {
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           new Server();
         }
       });
 }
예제 #6
0
 public static void main(String... args) {
   EventQueue.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           createAndShowGUI();
         }
       });
 }
예제 #7
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);
         }
       });
 }
예제 #8
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);
         }
       });
 }
예제 #10
0
파일: EmuThread.java 프로젝트: rexut/jkcemu
 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);
           }
         });
   }
 }
예제 #11
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);
 }
예제 #12
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);
  }
예제 #13
0
파일: EmuThread.java 프로젝트: rexut/jkcemu
 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);
           }
         });
   }
 }
예제 #14
0
  /**
   * Notify all ConnectionListeners. Service implementations are expected to use this method to
   * broadcast connection events.
   *
   * <p>The provided default implementation queues the event into an internal event queue. An event
   * dispatcher thread dequeues events from the queue and dispatches them to the registered
   * ConnectionListeners. Note that the event dispatching occurs in a separate thread, thus avoiding
   * potential deadlock problems.
   *
   * @param type the ConnectionEvent type
   */
  protected void notifyConnectionListeners(int type) {
    /*
     * Don't bother queuing an event if there's no listeners.
     * Yes, listeners could be removed after checking, which
     * just makes this an expensive no-op.
     */
    if (connectionListeners.size() > 0) {
      ConnectionEvent e = new ConnectionEvent(this, type);
      queueEvent(e, connectionListeners);
    }

    /* Fix for broken JDK1.1.x Garbage collector :
     *  The 'conservative' GC in JDK1.1.x occasionally fails to
     *  garbage-collect Threads which are in the wait state.
     *  This would result in thread (and consequently memory) leaks.
     *
     * We attempt to fix this by sending a 'terminator' event
     * to the queue, after we've sent the CLOSED event. The
     * terminator event causes the event-dispatching thread to
     * self destruct.
     */
    if (type == ConnectionEvent.CLOSED) q.terminateQueue();
  }
예제 #15
0
    private static void init() {
      final File basePath = basePath();
      basePath.mkdirs();

      final File namesFile = new File(basePath, "names.dat");
      final File attributesFile = new File(basePath, "attrib.dat");
      final File contentsFile = new File(basePath, "content.dat");
      final File recordsFile = new File(basePath, "records.dat");

      if (!namesFile.exists()) {
        invalidateIndex();
      }

      try {
        if (getCorruptionMarkerFile().exists()) {
          invalidateIndex();
          throw new IOException("Corruption marker file found");
        }

        PagedFileStorage.StorageLockContext storageLockContext =
            new PagedFileStorage.StorageLock(false).myDefaultStorageLockContext;
        myNames = new PersistentStringEnumerator(namesFile, storageLockContext);
        myAttributes = new Storage(attributesFile.getCanonicalPath(), REASONABLY_SMALL);
        myContents =
            new RefCountingStorage(
                contentsFile.getCanonicalPath(),
                CapacityAllocationPolicy
                    .FIVE_PERCENT_FOR_GROWTH); // sources usually zipped with 4x ratio
        boolean aligned = PagedFileStorage.BUFFER_SIZE % RECORD_SIZE == 0;
        assert aligned; // for performance
        myRecords =
            new ResizeableMappedFile(
                recordsFile, 20 * 1024, storageLockContext, PagedFileStorage.BUFFER_SIZE, aligned);

        if (myRecords.length() == 0) {
          cleanRecord(0); // Clean header
          cleanRecord(1); // Create root record
          setCurrentVersion();
        }

        if (getVersion() != VERSION) {
          throw new IOException("FS repository version mismatch");
        }

        if (myRecords.getInt(HEADER_CONNECTION_STATUS_OFFSET) != SAFELY_CLOSED_MAGIC) {
          throw new IOException("FS repository wasn't safely shut down");
        }
        markDirty();
        scanFreeRecords();
      } catch (Exception e) { // IOException, IllegalArgumentException
        LOG.info(
            "Filesystem storage is corrupted or does not exist. [Re]Building. Reason: "
                + e.getMessage());
        try {
          closeFiles();

          boolean deleted = FileUtil.delete(getCorruptionMarkerFile());
          deleted &= deleteWithSubordinates(namesFile);
          deleted &= AbstractStorage.deleteFiles(attributesFile.getCanonicalPath());
          deleted &= AbstractStorage.deleteFiles(contentsFile.getCanonicalPath());
          deleted &= deleteWithSubordinates(recordsFile);

          if (!deleted) {
            throw new IOException("Cannot delete filesystem storage files");
          }
        } catch (final IOException e1) {
          final Runnable warnAndShutdown =
              new Runnable() {
                @Override
                public void run() {
                  if (ApplicationManager.getApplication().isUnitTestMode()) {
                    //noinspection CallToPrintStackTrace
                    e1.printStackTrace();
                  } else {
                    final String message =
                        "Files in "
                            + basePath.getPath()
                            + " are locked.\n"
                            + ApplicationNamesInfo.getInstance().getProductName()
                            + " will not be able to start up.";
                    if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
                      JOptionPane.showMessageDialog(
                          JOptionPane.getRootFrame(),
                          message,
                          "Fatal Error",
                          JOptionPane.ERROR_MESSAGE);
                    } else {
                      //noinspection UseOfSystemOutOrSystemErr
                      System.err.println(message);
                    }
                  }
                  Runtime.getRuntime().halt(1);
                }
              };

          if (EventQueue.isDispatchThread()) {
            warnAndShutdown.run();
          } else {
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(warnAndShutdown);
          }

          throw new RuntimeException("Can't rebuild filesystem storage ", e1);
        }

        init();
      }
    }
예제 #16
0
파일: EmuThread.java 프로젝트: rexut/jkcemu
  @Override
  public void run() {
    this.emuRunning = true;
    while (this.emuRunning) {
      try {

        /*
         * Pruefen, ob ein Programm geladen oder der Emulator
         * tatsaechlich zurueckgesetzt werden soll
         */
        LoadData loadData = null;
        synchronized (this.monitor) {
          loadData = this.loadData;
          if (loadData != null) {
            this.loadData = null;
          } else {
            if (this.resetLevel == ResetLevel.POWER_ON) {
              Arrays.fill(this.ram, (byte) 0);
            }
          }
        }
        if (loadData != null) {
          loadData.loadIntoMemory(this);
          this.z80cpu.setRegPC(loadData.getStartAddr());
          if (this.emuSys != null) {
            int spInitValue = this.emuSys.getAppStartStackInitValue();
            if (spInitValue > 0) {
              this.z80cpu.setRegSP(spInitValue);
            }
          }
        } else {
          if ((this.resetLevel == ResetLevel.COLD_RESET)
              || (this.resetLevel == ResetLevel.POWER_ON)) {
            this.z80cpu.resetCPU(true);
          } else {
            this.z80cpu.resetCPU(false);
          }
          if (this.emuSys != null) {
            this.emuSys.reset(this.resetLevel, Main.getProperties());
            this.z80cpu.setRegPC(this.emuSys.getResetStartAddress(this.resetLevel));
          }
        }

        // RAM-Floppies und Druckmanager zuruecksetzen
        this.printMngr.reset();
        this.ramFloppy1.reset();
        this.ramFloppy2.reset();
        if ((this.emuSys != null)
            && (this.resetLevel == ResetLevel.POWER_ON)
            && Main.getBooleanProperty("jkcemu.ramfloppy.clear_on_power_on", false)) {
          if (this.emuSys.supportsRAMFloppy1() && (this.ramFloppy1.getUsedSize() > 0)) {
            this.ramFloppy1.clear();
          }
          if (this.emuSys.supportsRAMFloppy2() && (this.ramFloppy2.getUsedSize() > 0)) {
            this.ramFloppy2.clear();
          }
        }

        // Fenster informieren
        final Frame[] frms = Frame.getFrames();
        if (frms != null) {
          EventQueue.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  for (Frame f : frms) {
                    if (f instanceof BasicFrm) {
                      ((BasicFrm) f).resetFired();
                    }
                  }
                }
              });
        }

        // in die Z80-Emulation verzweigen
        this.resetLevel = ResetLevel.NO_RESET;
        this.z80cpu.run();
      } catch (Z80ExternalException ex) {
      } catch (Exception ex) {
        this.emuRunning = false;
        EventQueue.invokeLater(new ErrorMsg(this.screenFrm, ex));
      }
    }
  }
예제 #17
0
 /** Stop the event dispatcher thread so the queue can be garbage collected. */
 protected void finalize() throws Throwable {
   super.finalize();
   q.terminateQueue();
 }