Home » openjdk-7 » javax » swing » text » rtf » [javadoc | source]

    1   /*
    2    * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   package javax.swing.text.rtf;
   26   
   27   import java.util.Dictionary;
   28   import java.util.Enumeration;
   29   import javax.swing.text.AttributeSet;
   30   import javax.swing.text.MutableAttributeSet;
   31   
   32   
   33   /* This AttributeSet is made entirely out of tofu and Ritz Crackers
   34      and yet has a remarkably attribute-set-like interface! */
   35   class MockAttributeSet
   36       implements AttributeSet, MutableAttributeSet
   37   {
   38       public Dictionary<Object, Object> backing;
   39   
   40       public boolean isEmpty()
   41       {
   42            return backing.isEmpty();
   43       }
   44   
   45       public int getAttributeCount()
   46       {
   47            return backing.size();
   48       }
   49   
   50       public boolean isDefined(Object name)
   51       {
   52            return ( backing.get(name) ) != null;
   53       }
   54   
   55       public boolean isEqual(AttributeSet attr)
   56       {
   57            throw new InternalError("MockAttributeSet: charade revealed!");
   58       }
   59   
   60       public AttributeSet copyAttributes()
   61       {
   62            throw new InternalError("MockAttributeSet: charade revealed!");
   63       }
   64   
   65       public Object getAttribute(Object name)
   66       {
   67           return backing.get(name);
   68       }
   69   
   70       public void addAttribute(Object name, Object value)
   71       {
   72           backing.put(name, value);
   73       }
   74   
   75       public void addAttributes(AttributeSet attr)
   76       {
   77           Enumeration as = attr.getAttributeNames();
   78           while(as.hasMoreElements()) {
   79               Object el = as.nextElement();
   80               backing.put(el, attr.getAttribute(el));
   81           }
   82       }
   83   
   84       public void removeAttribute(Object name)
   85       {
   86           backing.remove(name);
   87       }
   88   
   89       public void removeAttributes(AttributeSet attr)
   90       {
   91            throw new InternalError("MockAttributeSet: charade revealed!");
   92       }
   93   
   94       public void removeAttributes(Enumeration<?> en)
   95       {
   96            throw new InternalError("MockAttributeSet: charade revealed!");
   97       }
   98   
   99       public void setResolveParent(AttributeSet pp)
  100       {
  101            throw new InternalError("MockAttributeSet: charade revealed!");
  102       }
  103   
  104   
  105       public Enumeration getAttributeNames()
  106       {
  107            return backing.keys();
  108       }
  109   
  110       public boolean containsAttribute(Object name, Object value)
  111       {
  112            throw new InternalError("MockAttributeSet: charade revealed!");
  113       }
  114   
  115       public boolean containsAttributes(AttributeSet attr)
  116       {
  117            throw new InternalError("MockAttributeSet: charade revealed!");
  118       }
  119   
  120       public AttributeSet getResolveParent()
  121       {
  122            throw new InternalError("MockAttributeSet: charade revealed!");
  123       }
  124   }

Home » openjdk-7 » javax » swing » text » rtf » [javadoc | source]