Lines 89-99
Link Here
|
89 |
* and actions. Yherefore you can define your own look and feel directly in the that method. |
89 |
* and actions. Yherefore you can define your own look and feel directly in the that method. |
90 |
* |
90 |
* |
91 |
* Since version 2.6 Widget class implements Accessible interface. |
91 |
* Since version 2.6 Widget class implements Accessible interface. |
|
|
92 |
* Since version 2.34 Widget class implements Lookup.Provider interface and |
93 |
* tries to initialize itself using the lookup passed in the constructor. |
92 |
* |
94 |
* |
93 |
* @author David Kaspar |
95 |
* @author David Kaspar |
|
|
96 |
* @author Benoit Callebaut |
94 |
*/ |
97 |
*/ |
95 |
// TODO - Should Widget be an abstract class? |
98 |
// TODO - Should Widget be an abstract class? |
96 |
public class Widget implements Accessible { |
99 |
public class Widget implements Accessible, Lookup.Provider { |
97 |
|
100 |
|
98 |
static final String MESSAGE_NULL_BOUNDS = "Scene.validate was not called after last change. Widget is not validated. See first Q/A at http://graph.netbeans.org/faq.html page."; |
101 |
static final String MESSAGE_NULL_BOUNDS = "Scene.validate was not called after last change. Widget is not validated. See first Q/A at http://graph.netbeans.org/faq.html page."; |
99 |
|
102 |
|
Lines 145-150
Link Here
|
145 |
|
148 |
|
146 |
private Point location; |
149 |
private Point location; |
147 |
private Rectangle bounds; |
150 |
private Rectangle bounds; |
|
|
151 |
private Shape shape; |
148 |
private Rectangle calculatedPreferredBounds; |
152 |
private Rectangle calculatedPreferredBounds; |
149 |
|
153 |
|
150 |
private boolean requiresFullValidation; |
154 |
private boolean requiresFullValidation; |
Lines 158-183
Link Here
|
158 |
* a property is set by using using resources. |
162 |
* a property is set by using using resources. |
159 |
*/ |
163 |
*/ |
160 |
private ResourceTable resourceTable = null; |
164 |
private ResourceTable resourceTable = null; |
|
|
165 |
protected final Lookup lookup; |
166 |
private AffineTransform transform = new AffineTransform(); |
161 |
|
167 |
|
162 |
/** |
168 |
/** |
163 |
* Creates a new widget which will be used in a specified scene. |
169 |
* Creates a new widget which will be used in a specified scene. |
164 |
* @param scene the scene where the widget is going to be used |
170 |
* @param scene the scene where the widget is going to be used |
|
|
171 |
* @since 2.34 |
165 |
*/ |
172 |
*/ |
166 |
public Widget (Scene scene) { |
173 |
public Widget (Scene scene, Lookup lookup) { |
167 |
if (scene == null) |
174 |
if (scene == null) { |
168 |
scene = (Scene) this; |
175 |
scene = (Scene) this; |
|
|
176 |
} |
169 |
this.scene = scene; |
177 |
this.scene = scene; |
|
|
178 |
this.lookup = lookup; |
170 |
children = new ArrayList<Widget> (); |
179 |
children = new ArrayList<Widget> (); |
171 |
childrenUm = Collections.unmodifiableList (children); |
180 |
childrenUm = Collections.unmodifiableList (children); |
172 |
|
181 |
|
173 |
actionsChain = new WidgetAction.Chain (); |
182 |
actionsChain = new WidgetAction.Chain (); |
174 |
|
183 |
|
|
|
184 |
toolsActions = new HashMap<String, WidgetAction.Chain>(); |
185 |
toolsActions.put(null, actionsChain); |
186 |
|
187 |
for (WidgetAction.ChainProvider provider : lookup.lookupAll(WidgetAction.ChainProvider.class)) { |
188 |
toolsActions.put(provider.getName(), provider.getChain()); |
189 |
} |
175 |
opaque = false; |
190 |
opaque = false; |
176 |
font = null; |
191 |
font = null; |
177 |
background = Color.WHITE; |
192 |
background = Color.WHITE; |
178 |
foreground = Color.BLACK; |
193 |
foreground = Color.BLACK; |
|
|
194 |
|
195 |
border = lookup.lookup(Border.class); |
196 |
if (border == null) { |
179 |
border = BorderFactory.createEmptyBorder (); |
197 |
border = BorderFactory.createEmptyBorder (); |
|
|
198 |
} |
199 |
layout = lookup.lookup(Layout.class); |
200 |
if (layout == null) { |
180 |
layout = LayoutFactory.createAbsoluteLayout (); |
201 |
layout = LayoutFactory.createAbsoluteLayout (); |
|
|
202 |
} |
181 |
preferredLocation = null; |
203 |
preferredLocation = null; |
182 |
preferredBounds = null; |
204 |
preferredBounds = null; |
183 |
checkClipping = false; |
205 |
checkClipping = false; |
Lines 191-196
Link Here
|
191 |
} |
213 |
} |
192 |
|
214 |
|
193 |
/** |
215 |
/** |
|
|
216 |
* Creates a new widget which will be used in a specified scene. |
217 |
* |
218 |
* @param scene the scene where the widget is going to be used |
219 |
*/ |
220 |
public Widget(Scene scene) { |
221 |
this(scene, Lookup.EMPTY); |
222 |
} |
223 |
|
224 |
/** |
225 |
* @since 2.34 |
226 |
*/ |
227 |
public Shape getShape() { |
228 |
shape = getTransform().createTransformedShape (getBounds()); |
229 |
return shape; |
230 |
} |
231 |
|
232 |
/** |
194 |
* Returns a scene where the widget is assigned |
233 |
* Returns a scene where the widget is assigned |
195 |
* @return the scene |
234 |
* @return the scene |
196 |
*/ |
235 |
*/ |
Lines 493-500
Link Here
|
493 |
* Returns a lookup of the widget. |
532 |
* Returns a lookup of the widget. |
494 |
* @return the lookup |
533 |
* @return the lookup |
495 |
*/ |
534 |
*/ |
496 |
public Lookup getLookup () { |
535 |
@Override |
497 |
return Lookup.EMPTY; |
536 |
public Lookup getLookup() { |
|
|
537 |
return lookup; |
498 |
} |
538 |
} |
499 |
|
539 |
|
500 |
/** |
540 |
/** |
Lines 840-845
Link Here
|
840 |
} |
880 |
} |
841 |
|
881 |
|
842 |
/** |
882 |
/** |
|
|
883 |
* @since 2.34 |
884 |
* @return Widget transform |
885 |
*/ |
886 |
public AffineTransform getTransform() { |
887 |
return transform; |
888 |
} |
889 |
|
890 |
/** |
891 |
* @since 2.34 |
892 |
*/ |
893 |
public void setTransform(AffineTransform transform) { |
894 |
this.transform = transform; |
895 |
this.revalidate(); |
896 |
} |
897 |
|
898 |
/** |
843 |
* Returns the border of the widget. |
899 |
* Returns the border of the widget. |
844 |
* @return the border |
900 |
* @return the border |
845 |
*/ |
901 |
*/ |
Lines 1276-1282
Link Here
|
1276 |
* @return true, if the location belong to the widget |
1332 |
* @return true, if the location belong to the widget |
1277 |
*/ |
1333 |
*/ |
1278 |
public boolean isHitAt (Point localLocation) { |
1334 |
public boolean isHitAt (Point localLocation) { |
1279 |
return visible && getBounds ().contains (localLocation); |
1335 |
return visible && getShape().contains (localLocation); |
1280 |
} |
1336 |
} |
1281 |
|
1337 |
|
1282 |
/** |
1338 |
/** |
Lines 1399-1408
Link Here
|
1399 |
return; |
1455 |
return; |
1400 |
|
1456 |
|
1401 |
assert bounds != null : MESSAGE_NULL_BOUNDS; // NOI18N |
1457 |
assert bounds != null : MESSAGE_NULL_BOUNDS; // NOI18N |
1402 |
Graphics2D gr = scene.getGraphics (); |
1458 |
Graphics2D gr = getGraphics (); |
1403 |
|
1459 |
|
1404 |
AffineTransform previousTransform = gr.getTransform(); |
1460 |
AffineTransform previousTransform = gr.getTransform(); |
1405 |
gr.translate (location.x, location.y); |
1461 |
gr.translate (location.x, location.y); |
|
|
1462 |
gr.transform (transform); |
1406 |
|
1463 |
|
1407 |
Shape tempClip = null; |
1464 |
Shape tempClip = null; |
1408 |
if (checkClipping) { |
1465 |
if (checkClipping) { |