Example usage for javax.swing.text SimpleAttributeSet getAttributeNames

List of usage examples for javax.swing.text SimpleAttributeSet getAttributeNames

Introduction

In this page you can find the example usage for javax.swing.text SimpleAttributeSet getAttributeNames.

Prototype

public Enumeration<?> getAttributeNames() 

Source Link

Document

Gets the names of the attributes in the set.

Usage

From source file:com.hexidec.ekit.component.HTMLUtilities.java

public SimpleAttributeSet removeAttribute(SimpleAttributeSet sourceAS, SimpleAttributeSet removeAS) {
    try {//from   w w  w.  ja v  a2s .co m
        String[] sourceKeys = new String[sourceAS.getAttributeCount()];
        String[] sourceValues = new String[sourceAS.getAttributeCount()];
        Enumeration sourceEn = sourceAS.getAttributeNames();
        int i = 0;
        while (sourceEn.hasMoreElements()) {
            Object temp = new Object();
            temp = sourceEn.nextElement();
            sourceKeys[i] = (String) temp.toString();
            sourceValues[i] = new String();
            sourceValues[i] = (String) sourceAS.getAttribute(temp).toString();
            i++;
        }
        String[] removeKeys = new String[removeAS.getAttributeCount()];
        String[] removeValues = new String[removeAS.getAttributeCount()];
        Enumeration removeEn = removeAS.getAttributeNames();
        int j = 0;
        while (removeEn.hasMoreElements()) {
            removeKeys[j] = (String) removeEn.nextElement().toString();
            removeValues[j] = (String) removeAS.getAttribute(removeKeys[j]).toString();
            j++;
        }
        SimpleAttributeSet result = new SimpleAttributeSet();
        boolean hit = false;
        for (int countSource = 0; countSource < sourceKeys.length; countSource++) {
            hit = false;
            if (sourceKeys[countSource] == "name" | sourceKeys[countSource] == "resolver") {
                hit = true;
            } else {
                for (int countRemove = 0; countRemove < removeKeys.length; countRemove++) {
                    if (removeKeys[countRemove] != "NULL") {
                        if (sourceKeys[countSource].toString() == removeKeys[countRemove].toString()) {
                            if (removeValues[countRemove] != "NULL") {
                                if (sourceValues[countSource].toString() == removeValues[countRemove]
                                        .toString()) {
                                    hit = true;
                                }
                            } else if (removeValues[countRemove] == "NULL") {
                                hit = true;
                            }
                        }
                    } else if (removeKeys[countRemove] == "NULL") {
                        if (sourceValues[countSource].toString() == removeValues[countRemove].toString()) {
                            hit = true;
                        }
                    }
                }
            }
            if (!hit) {
                result.addAttribute(sourceKeys[countSource].toString(), sourceValues[countSource].toString());
            }
        }
        return result;
    } catch (ClassCastException cce) {
        return null;
    }
}