Exemplo n.º 1
0
 /**
  * Gets the BDFontMetrics object for the supplied font. This method caches font metrics to ensure
  * native fonts are not loaded twice for the same font.
  */
 static synchronized BDFontMetrics getFontMetrics(Font font) {
   /* See if metrics has been stored in font already. */
   BDFontMetrics fm = null;
   // BDFontMetrics fm = (BDFontMetrics)font.metrics;
   // if (fm == null) {
   /* See if a font metrics of the same native name and size has already been loaded.
   If it has then we use that one. */
   String nativeName =
       (String) fontNameMap.get(font.getName().toLowerCase() + "." + font.getStyle());
   if (nativeName == null) nativeName = (String) fontNameMap.get("default." + font.getStyle());
   String key = nativeName + "." + font.getSize();
   fm = (BDFontMetrics) fontMetricsMap.get(key);
   if (fm == null) fontMetricsMap.put(key, fm = new BDFontMetrics(font, nativeName));
   // font.metrics = fm;
   // }
   return fm;
 }
Exemplo n.º 2
0
  /**
   * Set current font. Default to Plain Courier 11 if null.
   *
   * @param font new font.
   */
  public void setFont(Font font) {

    if (font != null) {
      m_localGraphicsState.setFont(font);
      if (font.getName().equals(m_psGraphicsState.getFont().getName())
          && (m_psGraphicsState.getFont().getStyle() == font.getStyle())
          && (m_psGraphicsState.getFont().getSize() == yScale(font.getSize()))) return;
      m_psGraphicsState.setFont(
          new Font(font.getName(), font.getStyle(), yScale(getFont().getSize())));
    } else {
      m_localGraphicsState.setFont(new Font("Courier", Font.PLAIN, 11));
      m_psGraphicsState.setFont(getFont());
    }

    m_printstream.println("/(" + replacePSFont(getFont().getPSName()) + ")" + " findfont");
    m_printstream.println(yScale(getFont().getSize()) + " scalefont setfont");
  }
Exemplo n.º 3
0
 public void adjustFont(int w, int h) {
   if (h <= 0) return;
   int oldH = rHeight;
   if (font == null) {
     font = getFont();
     fontH = font.getSize();
     rHeight = fontH;
   }
   nHeight = h;
   if (fontH >= h) rHeight = h - 2;
   else rHeight = fontH;
   if ((rHeight < 10) && (fontH > 10)) rHeight = 10;
   if (oldH != rHeight) {
     // Font  curFont = font.deriveFont((float) rHeight);
     Font curFont = DisplayOptions.getFont(font.getName(), font.getStyle(), rHeight);
     setFont(curFont);
   }
   if (rHeight > h) rHeight = h;
 }
Exemplo n.º 4
0
  /**
   * Execute applet events. Here is the state transition diagram
   *
   * <pre>{@literal
   *   Note: (XXX) is the action
   *         APPLET_XXX is the state
   *  (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT --
   *  (applet start called) --> APPLET_START -- (applet stop called) --> APPLET_STOP --
   *  (applet destroyed called) --> APPLET_DESTROY --> (applet gets disposed) -->
   *   APPLET_DISPOSE --> ...
   * }</pre>
   *
   * In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays in the
   * APPLET_START state unless the applet goes away(refresh page or leave the page). So the applet
   * stop method called and the applet enters APPLET_STOP state. Then if the applet is revisited, it
   * will call applet start method and enter the APPLET_START state and stay there.
   *
   * <p>In the modern lifecycle model. When the applet first time visited, it is same as legacy
   * lifecycle model. However, when the applet page goes away. It calls applet stop method and
   * enters APPLET_STOP state and then applet destroyed method gets called and enters APPLET_DESTROY
   * state.
   *
   * <p>This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump
   * from APPLET_STOP to APPLET_DESTROY and to APPLET_INIT .
   *
   * <p>Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla
   * case). Same as APPLET_LOAD to APPLET_DISPOSE since all of this are triggered by browser.
   */
  @Override
  public void run() {

    Thread curThread = Thread.currentThread();
    if (curThread == loaderThread) {
      // if we are in the loader thread, cause
      // loading to occur.  We may exit this with
      // status being APPLET_DISPOSE, APPLET_ERROR,
      // or APPLET_LOAD
      runLoader();
      return;
    }

    boolean disposed = false;
    while (!disposed && !curThread.isInterrupted()) {
      AppletEvent evt;
      try {
        evt = getNextEvent();
      } catch (InterruptedException e) {
        showAppletStatus("bail");
        return;
      }

      // showAppletStatus("EVENT = " + evt.getID());
      try {
        switch (evt.getID()) {
          case APPLET_LOAD:
            if (!okToLoad()) {
              break;
            }
            // This complexity allows loading of applets to be
            // interruptable.  The actual thread loading runs
            // in a separate thread, so it can be interrupted
            // without harming the applet thread.
            // So that we don't have to worry about
            // concurrency issues, the main applet thread waits
            // until the loader thread terminates.
            // (one way or another).
            if (loaderThread == null) {
              setLoaderThread(new Thread(null, this, "AppletLoader", 0, false));
              loaderThread.start();
              // we get to go to sleep while this runs
              loaderThread.join();
              setLoaderThread(null);
            } else {
              // REMIND: issue an error -- this case should never
              // occur.
            }
            break;

          case APPLET_INIT:
            // AppletViewer "Restart" will jump from destroy method to
            // init, that is why we need to check status w/ APPLET_DESTROY
            if (status != APPLET_LOAD && status != APPLET_DESTROY) {
              showAppletStatus("notloaded");
              break;
            }
            applet.resize(defaultAppletSize);

            if (PerformanceLogger.loggingEnabled()) {
              PerformanceLogger.setTime("Applet Init");
              PerformanceLogger.outputLog();
            }
            applet.init();

            // Need the default(fallback) font to be created in this AppContext
            Font f = getFont();
            if (f == null
                || "dialog".equals(f.getFamily().toLowerCase(Locale.ENGLISH))
                    && f.getSize() == 12
                    && f.getStyle() == Font.PLAIN) {
              setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
            }

            // Validate the applet in event dispatch thread
            // to avoid deadlock.
            try {
              final AppletPanel p = this;
              Runnable r =
                  new Runnable() {
                    @Override
                    public void run() {
                      p.validate();
                    }
                  };
              AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
            } catch (InterruptedException ie) {
            } catch (InvocationTargetException ite) {
            }

            status = APPLET_INIT;
            showAppletStatus("inited");
            break;

          case APPLET_START:
            {
              if (status != APPLET_INIT && status != APPLET_STOP) {
                showAppletStatus("notinited");
                break;
              }
              applet.resize(currentAppletSize);
              applet.start();

              // Validate and show the applet in event dispatch thread
              // to avoid deadlock.
              try {
                final AppletPanel p = this;
                final Applet a = applet;
                Runnable r =
                    new Runnable() {
                      @Override
                      public void run() {
                        p.validate();
                        a.setVisible(true);

                        // Fix for BugTraq ID 4041703.
                        // Set the default focus for an applet.
                        if (hasInitialFocus()) {
                          setDefaultFocus();
                        }
                      }
                    };
                AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
              } catch (InterruptedException ie) {
              } catch (InvocationTargetException ite) {
              }

              status = APPLET_START;
              showAppletStatus("started");
              break;
            }

          case APPLET_STOP:
            if (status != APPLET_START) {
              showAppletStatus("notstarted");
              break;
            }
            status = APPLET_STOP;

            // Hide the applet in event dispatch thread
            // to avoid deadlock.
            try {
              final Applet a = applet;
              Runnable r =
                  new Runnable() {
                    @Override
                    public void run() {
                      a.setVisible(false);
                    }
                  };
              AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
            } catch (InterruptedException ie) {
            } catch (InvocationTargetException ite) {
            }

            // During Applet.stop(), any AccessControlException on an involved Class remains in
            // the "memory" of the AppletClassLoader.  If the same instance of the ClassLoader is
            // reused, the same exception will occur during class loading.  Set the
            // AppletClassLoader's
            // exceptionStatusSet flag to allow recognition of what had happened
            // when reusing AppletClassLoader object.
            try {
              applet.stop();
            } catch (java.security.AccessControlException e) {
              setExceptionStatus(e);
              // rethrow exception to be handled as it normally would be.
              throw e;
            }
            showAppletStatus("stopped");
            break;

          case APPLET_DESTROY:
            if (status != APPLET_STOP && status != APPLET_INIT) {
              showAppletStatus("notstopped");
              break;
            }
            status = APPLET_DESTROY;

            // During Applet.destroy(), any AccessControlException on an involved Class remains in
            // the "memory" of the AppletClassLoader.  If the same instance of the ClassLoader is
            // reused, the same exception will occur during class loading.  Set the
            // AppletClassLoader's
            // exceptionStatusSet flag to allow recognition of what had happened
            // when reusing AppletClassLoader object.
            try {
              applet.destroy();
            } catch (java.security.AccessControlException e) {
              setExceptionStatus(e);
              // rethrow exception to be handled as it normally would be.
              throw e;
            }
            showAppletStatus("destroyed");
            break;

          case APPLET_DISPOSE:
            if (status != APPLET_DESTROY && status != APPLET_LOAD) {
              showAppletStatus("notdestroyed");
              break;
            }
            status = APPLET_DISPOSE;

            try {
              final Applet a = applet;
              Runnable r =
                  new Runnable() {
                    @Override
                    public void run() {
                      remove(a);
                    }
                  };
              AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
            } catch (InterruptedException ie) {
            } catch (InvocationTargetException ite) {
            }
            applet = null;
            showAppletStatus("disposed");
            disposed = true;
            break;

          case APPLET_QUIT:
            return;
        }
      } catch (Exception e) {
        status = APPLET_ERROR;
        if (e.getMessage() != null) {
          showAppletStatus("exception2", e.getClass().getName(), e.getMessage());
        } else {
          showAppletStatus("exception", e.getClass().getName());
        }
        showAppletException(e);
      } catch (ThreadDeath e) {
        showAppletStatus("death");
        return;
      } catch (Error e) {
        status = APPLET_ERROR;
        if (e.getMessage() != null) {
          showAppletStatus("error2", e.getClass().getName(), e.getMessage());
        } else {
          showAppletStatus("error", e.getClass().getName());
        }
        showAppletException(e);
      }
      clearLoadAbortRequest();
    }
  }
Exemplo n.º 5
0
  public void fillPopupMenu() {
    JMenuItem item;
    TextImageIcon textIcon;
    StatementHistory history;
    int rowCount = 0;
    int numRows = 0;
    Insets margin = new Insets(0, 0, 0, 0);

    // Get the font defined in the displayOptions panel for menus
    Font ft = DisplayOptions.getFont("Menu1");
    // We need a fairly small font, so make it 2 smaller.
    int size = ft.getSize();
    // If larger than 12, subtract 2
    if (size > 12) size -= 2;
    Font font = DisplayOptions.getFont(ft.getName(), ft.getStyle(), size);

    // This flag is used so that we only fill the menu when needed
    if (menuAlreadyFilled) return;

    menuAlreadyFilled = true;

    history = sshare.statementHistory();

    ArrayList list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    // Only show the Saved Statements section if there are some.
    if (list != null && list.size() != 0) {
      item = popup.add("Saved Statements");
      rowCount++;
      //	    item.setForeground(Color.blue);
      //	    item.setBackground(bgColor);
      item.setFont(font);
      item.setMargin(margin);
      popup.add(item);

      for (int i = 0; i < list.size(); i++) {
        ArrayList nameNlabel = (ArrayList) list.get(i);
        // first item in nameNlabel is name and second is label
        item = popup.add("  " + (String) nameNlabel.get(1));
        rowCount++;
        item.setActionCommand("save:" + (String) nameNlabel.get(0));
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
    }
    // the rest of menu (return object types, statement types, etc.)
    ShufflerService shufflerService = sshare.shufflerService();
    ArrayList objTypes = shufflerService.getAllMenuObjectTypes();

    for (int i = 0; i < objTypes.size(); i++) {
      String objType = (String) objTypes.get(i);

      // Do not display menu for DB_AVAIL_SUB_TYPES
      if (objType.equals(Shuf.DB_AVAIL_SUB_TYPES)) continue;

      // addSeparator looks bad using GridLayout because it creates rows
      // and columns which are all equal in size.  It cannot have a row
      // with a separator which is a different height than the other
      // rectangles it creates. So just use dashes.
      item = popup.add(separator);
      item.setFont(font);
      item.setMargin(margin);
      rowCount++;
      item = popup.add(shufflerService.getCategoryLabel(objType));
      rowCount++;
      //	    item.setForeground(Color.blue);
      item.setActionCommand("title:" + objType);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
      item.setFont(font);
      item.setMargin(margin);

      ArrayList menuStrings = shufflerService.getmenuStringsThisObj(objType);

      // If current rowCount plus the next section size is too big,
      // specify the numRows to the current value of rowCount -1.
      // That is, put this next section in a new column.
      // 47 is emperical number of rows to fit 90% full screen.
      if (numRows == 0 && rowCount - 1 + menuStrings.size() > 44) {

        numRows = rowCount - 2;
      }

      for (int j = 0; j < menuStrings.size(); j++) {
        String menuString = (String) menuStrings.get(j);
        item = popup.add("  " + menuString);
        rowCount++;
        item.setActionCommand("command:" + objType + "/" + menuString);
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
      // The spotter menu changes dynamically when
      // the list of saved statements changes.
      history.addStatementListener(
          new StatementAdapter() {
            public void saveListChanged() {
              refreshSaveMenu();
            }
          });
    }

    if (numRows == 0) numRows = rowCount;

    GridLayoutCol lm = new GridLayoutCol(numRows, 0);
    popup.setLayout(lm);
  }
Exemplo n.º 6
0
 /**
  * Derive a new version of this font based on a new size
  *
  * @param size The size of the new font
  * @return The new font data
  */
 public FontData deriveFont(float size) {
   return deriveFont(size, javaFont.getStyle());
 }