< prev index next >

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

Print this page


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


1497             SearchBuffer.releaseSearchBuffer(sb);
1498         }
1499     }
1500 
1501     /**
1502      * Creates and returns a Style containing all the rules that
1503      * matches <code>selector</code>.
1504      *
1505      * @param elements  a Vector of all the Elements
1506      *                  the style is being asked for. The
1507      *                  first Element is the deepest Element, with the last Element
1508      *                  representing the root.
1509      * @param t         the Tag to use for
1510      *                  the first Element in <code>elements</code>
1511      */
1512     private Style createResolvedStyle(String selector, Vector<Element> elements,
1513                                       HTML.Tag t) {
1514         int numElements = elements.size();
1515         // Build three arrays, one for tags, one for class's, and one for
1516         // id's
1517         String tags[] = new String[numElements];
1518         String ids[] = new String[numElements];
1519         String classes[] = new String[numElements];
1520         for (int counter = 0; counter < numElements; counter++) {
1521             Element e = elements.elementAt(counter);
1522             AttributeSet attr = e.getAttributes();
1523             if (counter == 0 && e.isLeaf()) {
1524                 // For leafs, we use the second tier attributes.
1525                 Object testAttr = attr.getAttribute(t);
1526                 if (testAttr instanceof AttributeSet) {
1527                     attr = (AttributeSet)testAttr;
1528                 }
1529                 else {
1530                     attr = null;
1531                 }
1532             }
1533             if (attr != null) {
1534                 HTML.Tag tag = (HTML.Tag)attr.getAttribute(StyleConstants.
1535                                                            NameAttribute);
1536                 if (tag != null) {
1537                     tags[counter] = tag.toString();
1538                 }
1539                 else {


2430         /**
2431          * Converts the item number into an alphabetic character
2432          *
2433          * @param itemNum number to format
2434          */
2435         String formatAlphaNumerals(int itemNum) {
2436             String result;
2437 
2438             if (itemNum > 26) {
2439                 result = formatAlphaNumerals(itemNum / 26) +
2440                     formatAlphaNumerals(itemNum % 26);
2441             } else {
2442                 // -1 because item is 1 based.
2443                 result = String.valueOf((char)('a' + itemNum - 1));
2444             }
2445 
2446             return result;
2447         }
2448 
2449         /* list of roman numerals */
2450         static final char romanChars[][] = {
2451             {'i', 'v'},
2452             {'x', 'l' },
2453             {'c', 'd' },
2454             {'m', '?' },
2455         };
2456 
2457         /**
2458          * Converts the item number into a roman numeral
2459          *
2460          * @param num  number to format
2461          */
2462         String formatRomanNumerals(int num) {
2463             return formatRomanNumerals(0, num);
2464         }
2465 
2466         /**
2467          * Converts the item number into a roman numeral
2468          *
2469          * @param num  number to format
2470          */


3393         sizeMap = new int[sizeMapDefault.length];
3394         for (int i = 0; i < sizeMapDefault.length; i++) {
3395             sizeMap[i] = Math.max(base * sizeMapDefault[i] /
3396                                   sizeMapDefault[CSS.baseFontSizeIndex],
3397                                   minimalFontSize);
3398         }
3399 
3400     }
3401 
3402     int[] getSizeMap() {
3403         return sizeMap;
3404     }
3405     boolean isW3CLengthUnits() {
3406         return w3cLengthUnits;
3407     }
3408 
3409     /**
3410      * The HTML/CSS size model has seven slots
3411      * that one can assign sizes to.
3412      */
3413     static final int sizeMapDefault[] = { 8, 10, 12, 14, 18, 24, 36 };
3414 
3415     private int sizeMap[] = sizeMapDefault;
3416     private boolean w3cLengthUnits = false;
3417 }
   1 /*
   2  * Copyright (c) 1997, 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


1497             SearchBuffer.releaseSearchBuffer(sb);
1498         }
1499     }
1500 
1501     /**
1502      * Creates and returns a Style containing all the rules that
1503      * matches <code>selector</code>.
1504      *
1505      * @param elements  a Vector of all the Elements
1506      *                  the style is being asked for. The
1507      *                  first Element is the deepest Element, with the last Element
1508      *                  representing the root.
1509      * @param t         the Tag to use for
1510      *                  the first Element in <code>elements</code>
1511      */
1512     private Style createResolvedStyle(String selector, Vector<Element> elements,
1513                                       HTML.Tag t) {
1514         int numElements = elements.size();
1515         // Build three arrays, one for tags, one for class's, and one for
1516         // id's
1517         String[] tags = new String[numElements];
1518         String[] ids = new String[numElements];
1519         String[] classes = new String[numElements];
1520         for (int counter = 0; counter < numElements; counter++) {
1521             Element e = elements.elementAt(counter);
1522             AttributeSet attr = e.getAttributes();
1523             if (counter == 0 && e.isLeaf()) {
1524                 // For leafs, we use the second tier attributes.
1525                 Object testAttr = attr.getAttribute(t);
1526                 if (testAttr instanceof AttributeSet) {
1527                     attr = (AttributeSet)testAttr;
1528                 }
1529                 else {
1530                     attr = null;
1531                 }
1532             }
1533             if (attr != null) {
1534                 HTML.Tag tag = (HTML.Tag)attr.getAttribute(StyleConstants.
1535                                                            NameAttribute);
1536                 if (tag != null) {
1537                     tags[counter] = tag.toString();
1538                 }
1539                 else {


2430         /**
2431          * Converts the item number into an alphabetic character
2432          *
2433          * @param itemNum number to format
2434          */
2435         String formatAlphaNumerals(int itemNum) {
2436             String result;
2437 
2438             if (itemNum > 26) {
2439                 result = formatAlphaNumerals(itemNum / 26) +
2440                     formatAlphaNumerals(itemNum % 26);
2441             } else {
2442                 // -1 because item is 1 based.
2443                 result = String.valueOf((char)('a' + itemNum - 1));
2444             }
2445 
2446             return result;
2447         }
2448 
2449         /* list of roman numerals */
2450         static final char[][] romanChars = {
2451             {'i', 'v'},
2452             {'x', 'l' },
2453             {'c', 'd' },
2454             {'m', '?' },
2455         };
2456 
2457         /**
2458          * Converts the item number into a roman numeral
2459          *
2460          * @param num  number to format
2461          */
2462         String formatRomanNumerals(int num) {
2463             return formatRomanNumerals(0, num);
2464         }
2465 
2466         /**
2467          * Converts the item number into a roman numeral
2468          *
2469          * @param num  number to format
2470          */


3393         sizeMap = new int[sizeMapDefault.length];
3394         for (int i = 0; i < sizeMapDefault.length; i++) {
3395             sizeMap[i] = Math.max(base * sizeMapDefault[i] /
3396                                   sizeMapDefault[CSS.baseFontSizeIndex],
3397                                   minimalFontSize);
3398         }
3399 
3400     }
3401 
3402     int[] getSizeMap() {
3403         return sizeMap;
3404     }
3405     boolean isW3CLengthUnits() {
3406         return w3cLengthUnits;
3407     }
3408 
3409     /**
3410      * The HTML/CSS size model has seven slots
3411      * that one can assign sizes to.
3412      */
3413     static final int[] sizeMapDefault = { 8, 10, 12, 14, 18, 24, 36 };
3414 
3415     private int[] sizeMap = sizeMapDefault;
3416     private boolean w3cLengthUnits = false;
3417 }
< prev index next >