Lines 15-21
Link Here
|
15 |
|
15 |
|
16 |
import java.lang.ref.Reference; |
16 |
import java.lang.ref.Reference; |
17 |
import java.lang.ref.ReferenceQueue; |
17 |
import java.lang.ref.ReferenceQueue; |
|
|
18 |
import java.util.ArrayList; |
18 |
import java.util.Enumeration; |
19 |
import java.util.Enumeration; |
|
|
20 |
import java.util.List; |
19 |
|
21 |
|
20 |
import org.netbeans.api.looks.*; |
22 |
import org.netbeans.api.looks.*; |
21 |
|
23 |
|
Lines 99-132
Link Here
|
99 |
* @throws IllegalStateException If a selector returns invalid object |
101 |
* @throws IllegalStateException If a selector returns invalid object |
100 |
*/ |
102 |
*/ |
101 |
static public final Look searchLook (LookSelector selector, Object repObject) throws IllegalArgumentException, IllegalStateException { |
103 |
static public final Look searchLook (LookSelector selector, Object repObject) throws IllegalArgumentException, IllegalStateException { |
102 |
if (repObject == null) |
104 |
List l = searchForLooks (selector, repObject); |
103 |
throw new IllegalArgumentException ("Selector connot be null."); // NOI18N |
105 |
Look look; |
104 |
if (selector == null) { |
106 |
Object o = null; |
105 |
throw new IllegalArgumentException ("Represented object cannot be null."); // NOI18N |
107 |
|
106 |
} |
108 |
if (!l.isEmpty ()) |
107 |
Look look = searchFirstLook (selector, repObject); |
109 |
o = l.iterator ().next (); |
108 |
if (look == null) { |
110 |
|
|
|
111 |
if (o instanceof Look) { |
112 |
look = (Look) o; |
113 |
} else { |
109 |
ErrorManager.getDefault ().log ("There is not any look accordant with object " + |
114 |
ErrorManager.getDefault ().log ("There is not any look accordant with object " + |
110 |
repObject+", BeanLook is used as default."); // NOI18N |
115 |
repObject+", BeanLook is used as default."); // NOI18N |
111 |
look = Looks.beanLook (); |
116 |
look = Looks.beanLook (); |
112 |
} |
117 |
} |
|
|
118 |
|
113 |
return look; |
119 |
return look; |
114 |
} |
120 |
} |
115 |
|
121 |
|
116 |
static private final Look searchFirstLook (LookSelector selector, Object repObject) { |
122 |
/** Returns a list of looks for the represented object in given selector. |
|
|
123 |
* <P> |
124 |
* Search in the selector. All found looks add to list. If there is found a selector |
125 |
* then searches deeply in this selector. |
126 |
* There is not any look then returns the empty list. |
127 |
* @param selector look selector |
128 |
* @param repObject represented object |
129 |
* @throws IllegalArgumentException If selector or repObject is null |
130 |
* @throws IllegalStateException If a selector returns invalid object |
131 |
* @return list of the looks for represented object in given selector |
132 |
*/ |
133 |
static public final List searchForLooks (LookSelector selector, Object repObject) throws IllegalArgumentException, IllegalStateException { |
134 |
ArrayList list = new ArrayList (); |
135 |
if (repObject == null) |
136 |
throw new IllegalArgumentException ("Selector connot be null."); // NOI18N |
137 |
if (selector == null) { |
138 |
throw new IllegalArgumentException ("Represented object cannot be null."); // NOI18N |
139 |
} |
140 |
searchAllLooks (selector, repObject, list); |
141 |
return list; |
142 |
} |
143 |
|
144 |
static private final void searchAllLooks (LookSelector selector, Object repObject, ArrayList list) { |
117 |
Enumeration descriptors = selector.getLookDescriptors (repObject); |
145 |
Enumeration descriptors = selector.getLookDescriptors (repObject); |
118 |
Object lookDescriptor = null; |
146 |
Object lookDescriptor = null; |
119 |
while (descriptors.hasMoreElements ()) { |
147 |
while (descriptors.hasMoreElements ()) { |
120 |
lookDescriptor = descriptors.nextElement (); |
148 |
lookDescriptor = descriptors.nextElement (); |
121 |
if (lookDescriptor instanceof Look) |
149 |
if (lookDescriptor instanceof Look) |
122 |
return (Look) lookDescriptor; |
150 |
list.add (lookDescriptor); |
123 |
else if (lookDescriptor instanceof LookSelector) |
151 |
else if (lookDescriptor instanceof LookSelector) |
124 |
return searchFirstLook ((LookSelector) lookDescriptor, repObject); |
152 |
searchAllLooks ((LookSelector) lookDescriptor, repObject, list); |
125 |
else |
153 |
else |
126 |
throw new IllegalStateException ("Unknown instance of LookDescriptor: " + lookDescriptor); //NOI18N |
154 |
throw new IllegalStateException ("Unknown instance of LookDescriptor: " + lookDescriptor); //NOI18N |
127 |
} |
155 |
} |
128 |
// there is no look in this selector |
|
|
129 |
return null; |
130 |
} |
156 |
} |
131 |
|
157 |
|
132 |
} |
158 |
} |