1 14 package org.wings.style; 15 16 import org.wings.SComponent; 17 import org.wings.SFrame; 18 19 import java.io.Serializable ; 20 21 37 public class CSSSelector implements Serializable { 38 39 42 protected String selectorString; 43 46 protected SComponent addressedComponent; 47 48 54 public CSSSelector(String selectorString) { 55 this.selectorString = selectorString; 56 } 57 58 64 public CSSSelector(SComponent addressedComponent) { 65 this.addressedComponent = addressedComponent; 66 } 67 68 71 public String getSelectorString() { 72 if (selectorString != null) 73 return selectorString; 74 else 75 return getSelectorString(addressedComponent); 76 } 77 78 83 public static String getSelectorString(SComponent addressedComponent) { 84 if (addressedComponent == null) 85 return ""; 86 else if (addressedComponent instanceof SFrame) 87 return "body"; 88 else 89 return "#" + addressedComponent.getName(); 90 } 91 92 public boolean equals(Object o) { 93 if (this == o) return true; 94 if (!(o instanceof CSSSelector)) return false; 95 96 final CSSSelector cssSelector = (CSSSelector) o; 97 final String selectorString = getSelectorString(); 98 return (selectorString.equals(cssSelector.getSelectorString())); 99 } 100 101 public int hashCode() { 102 if (selectorString != null) 103 return selectorString.hashCode(); 104 else if (addressedComponent != null) 105 return addressedComponent.hashCode(); 106 else 107 return 0; 108 } 109 110 114 public static class Pseudo extends CSSSelector { 115 116 122 public Pseudo(String pseudoSelectorName) { 123 super(pseudoSelectorName); 124 this.selectorString = pseudoSelectorName; 125 } 126 } 127 } 128 | Popular Tags |