< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/MuxingAttributeSet.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2014, 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


  59     protected synchronized void setAttributes(AttributeSet[] attrs) {
  60         this.attrs = attrs;
  61     }
  62 
  63     /**
  64      * Returns the <code>AttributeSet</code>s multiplexing too. When the
  65      * <code>AttributeSet</code>s need to be referenced, this should be called.
  66      */
  67     protected synchronized AttributeSet[] getAttributes() {
  68         return attrs;
  69     }
  70 
  71     /**
  72      * Inserts <code>as</code> at <code>index</code>. This assumes
  73      * the value of <code>index</code> is between 0 and attrs.length,
  74      * inclusive.
  75      */
  76     protected synchronized void insertAttributeSetAt(AttributeSet as,
  77                                                      int index) {
  78         int numAttrs = attrs.length;
  79         AttributeSet newAttrs[] = new AttributeSet[numAttrs + 1];
  80         if (index < numAttrs) {
  81             if (index > 0) {
  82                 System.arraycopy(attrs, 0, newAttrs, 0, index);
  83                 System.arraycopy(attrs, index, newAttrs, index + 1,
  84                                  numAttrs - index);
  85             }
  86             else {
  87                 System.arraycopy(attrs, 0, newAttrs, 1, numAttrs);
  88             }
  89         }
  90         else {
  91             System.arraycopy(attrs, 0, newAttrs, 0, numAttrs);
  92         }
  93         newAttrs[index] = as;
  94         attrs = newAttrs;
  95     }
  96 
  97     /**
  98      * Removes the AttributeSet at <code>index</code>. This assumes
  99      * the value of <code>index</code> is greater than or equal to 0,


   1 /*
   2  * Copyright (c) 2001, 2018, 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


  59     protected synchronized void setAttributes(AttributeSet[] attrs) {
  60         this.attrs = attrs;
  61     }
  62 
  63     /**
  64      * Returns the <code>AttributeSet</code>s multiplexing too. When the
  65      * <code>AttributeSet</code>s need to be referenced, this should be called.
  66      */
  67     protected synchronized AttributeSet[] getAttributes() {
  68         return attrs;
  69     }
  70 
  71     /**
  72      * Inserts <code>as</code> at <code>index</code>. This assumes
  73      * the value of <code>index</code> is between 0 and attrs.length,
  74      * inclusive.
  75      */
  76     protected synchronized void insertAttributeSetAt(AttributeSet as,
  77                                                      int index) {
  78         int numAttrs = attrs.length;
  79         AttributeSet[] newAttrs = new AttributeSet[numAttrs + 1];
  80         if (index < numAttrs) {
  81             if (index > 0) {
  82                 System.arraycopy(attrs, 0, newAttrs, 0, index);
  83                 System.arraycopy(attrs, index, newAttrs, index + 1,
  84                                  numAttrs - index);
  85             }
  86             else {
  87                 System.arraycopy(attrs, 0, newAttrs, 1, numAttrs);
  88             }
  89         }
  90         else {
  91             System.arraycopy(attrs, 0, newAttrs, 0, numAttrs);
  92         }
  93         newAttrs[index] = as;
  94         attrs = newAttrs;
  95     }
  96 
  97     /**
  98      * Removes the AttributeSet at <code>index</code>. This assumes
  99      * the value of <code>index</code> is greater than or equal to 0,


< prev index next >