stylesheet.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 938 行 · 第 1/2 页

JAVA
938
字号
  }    /**   * Takes a set of attributes and turns it into a background   * color specification. This is used to specify things like, brigher, more hue   * etc.   *    * @param a - the set to get the background color for   * @return the background color for the set   */  public Color getBackground(AttributeSet a)  {    return super.getBackground(a);       }    /**   * Gets the box formatter to use for the given set of CSS attributes.   *    * @param a - the given set   * @return the box formatter   */  public BoxPainter getBoxPainter(AttributeSet a)  {    return new BoxPainter(a);       }    /**   * Gets the list formatter to use for the given set of CSS attributes.   *    * @param a - the given set   * @return the list formatter   */  public ListPainter getListPainter(AttributeSet a)  {    return new ListPainter(a);           }    /**   * Sets the base font size between 1 and 7.   *    * @param sz - the new font size for the base.   */  public void setBaseFontSize(int sz)  {    if (sz <= 7 && sz >= 1)      baseFontSize = sz;  }    /**   * Sets the base font size from the String. It can either identify   * a specific font size (between 1 and 7) or identify a relative   * font size such as +1 or -2.   *    * @param size - the new font size as a String.   */  public void setBaseFontSize(String size)  {    size.trim();    int temp = 0;    try      {        if (size.length() == 2)          {            int i = new Integer(size.substring(1)).intValue();            if (size.startsWith("+"))              temp = baseFontSize + i;            else if (size.startsWith("-"))              temp = baseFontSize - i;          }        else if (size.length() == 1)          temp = new Integer(size.substring(0)).intValue();        if (temp <= 7 && temp >= 1)          baseFontSize = temp;      }    catch (NumberFormatException nfe)      {        // Do nothing here      }  }    /**   * TODO   *    * @param pt - TODO   * @return TODO   */  public static int getIndexOfSize(float pt)  {    // FIXME: Not implemented.    return 0;  }    /**   * Gets the point size, given a size index.   *    * @param index - the size index   * @return the point size.   */  public float getPointSize(int index)  {    // FIXME: Not implemented.    return 0;      }    /**   * Given the string of the size, returns the point size value.   *    * @param size - the string representation of the size.   * @return - the point size value.   */  public float getPointSize(String size)  {    // FIXME: Not implemented.    return 0;      }    /**   * Converst a color string to a color. If it is not found, null is returned.   *    * @param color - the color string such as "RED" or "#NNNNNN"   * @return the Color, or null if not found.   */  public Color stringToColor(String color)  {    color = color.toLowerCase();    if (color.equals("black") || color.equals("#000000"))      return Color.BLACK;    else if (color.equals("aqua") || color.equals("#00FFFF"))      return new Color(127, 255, 212);    else if (color.equals("gray") || color.equals("#808080"))      return Color.GRAY;    else if (color.equals("navy") || color.equals("#000080"))      return new Color(0, 0, 128);    else if (color.equals("silver") || color.equals("#C0C0C0"))      return Color.LIGHT_GRAY;    else if (color.equals("green") || color.equals("#008000"))      return Color.GREEN;    else if (color.equals("olive") || color.equals("#808000"))      return new Color(128, 128, 0);    else if (color.equals("teal") || color.equals("#008080"))      return new Color(0, 128, 128);    else if (color.equals("blue") || color.equals("#0000FF"))      return Color.BLUE;    else if (color.equals("lime") || color.equals("#00FF00"))      return new Color(0, 255, 0);    else if (color.equals("purple") || color.equals("#800080"))      return new Color(128, 0, 128);    else if (color.equals("white") || color.equals("#FFFFFF"))      return Color.WHITE;    else if (color.equals("fuchsia") || color.equals("#FF00FF"))      return Color.MAGENTA;    else if (color.equals("maroon") || color.equals("#800000"))      return new Color(128, 0, 0);    else if (color.equals("Red") || color.equals("#FF0000"))      return Color.RED;    else if (color.equals("Yellow") || color.equals("#FFFF00"))      return Color.YELLOW;    return null;   }    /**   * This class carries out some of the duties of CSS formatting. This enables views   * to present the CSS formatting while not knowing how the CSS values are cached.   *    * This object is reponsible for the insets of a View and making sure   * the background is maintained according to the CSS attributes.   *    * @author Lillian Angel (langel@redhat.com)   */  public static class BoxPainter extends Object implements Serializable  {        /**     * Attribute set for painter     */    AttributeSet as;        /**     * Package-private constructor.     *      * @param as - AttributeSet for painter     */    BoxPainter(AttributeSet as)    {      this.as = as;    }        /**     * Gets the inset needed on a given side to account for the margin, border     * and padding.     *      * @param size - the size of the box to get the inset for. View.TOP, View.LEFT,     * View.BOTTOM or View.RIGHT.     * @param v - the view making the request. This is used to get the AttributeSet,     * amd may be used to resolve percentage arguments.     * @return the inset     * @throws IllegalArgumentException - for an invalid direction.     */    public float getInset(int size, View v)    {      // FIXME: Not implemented.      return 0;           }        /**     * Paints the CSS box according to the attributes given. This should     * paint the border, padding and background.     *      * @param g - the graphics configuration     * @param x - the x coordinate     * @param y - the y coordinate     * @param w - the width of the allocated area     * @param h - the height of the allocated area     * @param v - the view making the request     */    public void paint(Graphics g, float x, float y, float w, float h, View v)    {      // FIXME: Not implemented.    }  }    /**   * This class carries out some of the CSS list formatting duties. Implementations   * of this class enable views to present the CSS formatting while not knowing anything   * about how the CSS values are being cached.   *    * @author Lillian Angel (langel@redhat.com)   */  public static class ListPainter extends Object implements Serializable  {        /**     * Attribute set for painter     */    AttributeSet as;        /**     * Package-private constructor.     *      * @param as - AttributeSet for painter     */    ListPainter(AttributeSet as)    {      this.as = as;    }        /**     * Paints the CSS list decoration according to the attributes given.     *      * @param g - the graphics configuration     * @param x - the x coordinate     * @param y - the y coordinate     * @param w - the width of the allocated area     * @param h - the height of the allocated area     * @param v - the view making the request     * @param item - the list item to be painted >=0.     */    public void paint(Graphics g, float x, float y, float w, float h, View v,                      int item)    {      // FIXME: Not implemented.    }  }    /**   * The parser callback for the CSSParser.   */  class CssParser implements CSSParser.CSSParserCallback  {    /**      * A vector of all the selectors.      * Each element is an array of all the selector tokens      * in a single rule.      */    Vector selectors;    /** A vector of all the selector tokens in a rule. */    Vector selectorTokens;    /**  Name of the current property. */    String propertyName;    /** The set of CSS declarations */    MutableAttributeSet declaration;    /**      * True if parsing a declaration, that is the Reader will not      * contain a selector.      */    boolean parsingDeclaration;    /** True if the attributes are coming from a linked/imported style. */    boolean isLink;    /** The base URL */    URL base;    /** The parser */    CSSParser parser;    /**     * Constructor     */    CssParser()    {      selectors = new Vector();      selectorTokens = new Vector();      parser = new CSSParser();      base = StyleSheet.this.base;      declaration = new SimpleAttributeSet();    }    /**     * Parses the passed in CSS declaration into an AttributeSet.     *      * @param s - the declaration     * @return the set of attributes containing the property and value.     */    public AttributeSet parseDeclaration(String s)    {      try      {        return parseDeclaration(new StringReader(s));      }      catch (IOException e)      {         // Do nothing here.      }      return null;    }    /**     * Parses the passed in CSS declaration into an AttributeSet.     *      * @param r - the reader     * @return the attribute set     * @throws IOException from the reader     */    public AttributeSet parseDeclaration(Reader r) throws IOException    {      parse(base, r, true, false);      return declaration;    }    /**     * Parse the given CSS stream     *      * @param base - the url     * @param r - the reader     * @param parseDec - True if parsing a declaration     * @param isLink - True if parsing a link     */   public void parse(URL base, Reader r, boolean parseDec, boolean isLink) throws IOException   {     parsingDeclaration = parseDec;     this.isLink = isLink;     this.base = base;          // flush out all storage     propertyName = null;     selectors.clear();     selectorTokens.clear();     declaration.removeAttributes(declaration);          parser.parse(r, this, parseDec);   }   /**    * Invoked when a valid @import is encountered,     * will call importStyleSheet if a MalformedURLException     * is not thrown in creating the URL.    *    * @param s - the string after @import    */    public void handleImport(String s)    {      if (s != null)        {          try            {              if (s.startsWith("url(") && s.endsWith(")"))                s = s.substring(4, s.length() - 1);              if (s.indexOf("\"") >= 0)                s = s.replaceAll("\"","");              URL url = new URL(s);              if (url == null && base != null)                url = new URL(base, s);                            importStyleSheet(url);            }          catch (MalformedURLException e)            {              // Do nothing here.            }        }    }   /**     * A selector has been encountered.     *      * @param s - a selector (e.g. P or UL or even P,)     */   public void handleSelector(String s)   {     if (s.endsWith(","))       s = s.substring(0, s.length() - 1);          selectorTokens.addElement(s);     addSelector();   }   /**    * Invoked when the start of a rule is encountered.    */   public void startRule()   {     addSelector();   }   /**    * Invoked when a property name is encountered.    *    * @param s - the property    */   public void handleProperty(String s)   {     propertyName = s;   }  /**   * Invoked when a property value is encountered.   *   * @param s - the value   */   public void handleValue(String s)   {     // call addCSSAttribute     // FIXME: Not implemented   }      /**    * Invoked when the end of a rule is encountered.    */   public void endRule()   {     // FIXME: Not implemented     // add rules     propertyName = null;   }   /**    * Adds the selector to the vector.    */   private void addSelector()   {     int length = selectorTokens.size();     if (length > 0)       {         Object[] sel = new Object[length];         System.arraycopy(selectorTokens.toArray(), 0, sel, 0, length);         selectors.add(sel);         selectorTokens.clear();       }   }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?