001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: TitledTabProperties.java,v 1.42 2007/01/28 21:25:49 jesper Exp $
023: package net.infonode.tabbedpanel.titledtab;
024:
025: import net.infonode.gui.DimensionProvider;
026: import net.infonode.gui.DynamicUIManager;
027: import net.infonode.gui.DynamicUIManagerListener;
028: import net.infonode.gui.hover.HoverListener;
029: import net.infonode.properties.base.Property;
030: import net.infonode.properties.gui.util.ComponentProperties;
031: import net.infonode.properties.gui.util.ShapedPanelProperties;
032: import net.infonode.properties.propertymap.*;
033: import net.infonode.properties.types.BooleanProperty;
034: import net.infonode.properties.types.DimensionProviderProperty;
035: import net.infonode.properties.types.HoverListenerProperty;
036: import net.infonode.properties.types.IntegerProperty;
037: import net.infonode.tabbedpanel.TabbedUIDefaults;
038: import net.infonode.tabbedpanel.border.TabAreaLineBorder;
039: import net.infonode.tabbedpanel.border.TabHighlightBorder;
040: import net.infonode.util.Alignment;
041: import net.infonode.util.Direction;
042:
043: import javax.swing.border.CompoundBorder;
044:
045: /**
046: * <p>
047: * TitledTabProperties holds all properties for a {@link TitledTab}.
048: * </p>
049: *
050: * <p>
051: * A titled tab can have three states, normal, highlighted and disabled. Each state is represented by a {@link
052: * TitledTabStateProperties} object containing all properties that can be set for a state.
053: * </p>
054: *
055: * <p>
056: * By default the property values in the highlighted and disabled state are references to corresponding values in the
057: * normal state. This means that if you set a property value in the normal state, then highlighted and the disabled
058: * state will use that property value if the property has not been set in the highlighted or disabled state.
059: * </p>
060: *
061: * <p>
062: * Example:<br> Setting the background color in the normal state means that normal, highlighted and disabled state will
063: * use that color as background color. If you set background color for highlighted state, then the highlighted state
064: * will use that color regardless of the background color for the normal state.
065: * </p>
066: *
067: * <p>
068: * By default the tool tip text in all states is the same as the tab text in the normal state. For example, if you
069: * change the tab text in the highlighted state and want the tooltip to display the same text, you must set the "Tool
070: * Tip Text" property {@link TitledTabStateProperties#TOOL_TIP_TEXT} in the highlighted state.
071: * </p>
072: *
073: * @author $Author: jesper $
074: * @version $Revision: 1.42 $
075: * @see TitledTab
076: * @see TitledTabStateProperties
077: */
078: public class TitledTabProperties extends PropertyMapContainer {
079: /**
080: * A property group for all properties in TitledTabProperties
081: */
082: public static final PropertyMapGroup PROPERTIES = new PropertyMapGroup(
083: "Titled Tab Properties",
084: "Properties for the TitledTab class.");
085:
086: /**
087: * Focusabled property
088: *
089: * @see #setFocusable
090: * @see #getFocusable
091: */
092: public static final BooleanProperty FOCUSABLE = new BooleanProperty(
093: PROPERTIES, "Focusable", "Tab focusable",
094: PropertyMapValueHandler.INSTANCE);
095:
096: /**
097: * Focus Marker Enabled property
098: *
099: * @see #setFocusMarkerEnabled
100: * @see #getFocusMarkerEnabled
101: * @since ITP 1.4.0
102: */
103: public static final BooleanProperty FOCUS_MARKER_ENABLED = new BooleanProperty(
104: PROPERTIES,
105: "Focus Marker Enabled",
106: "Enables or disables the focus marker when the tab has focus.",
107: PropertyMapValueHandler.INSTANCE);
108:
109: /**
110: * Normal state properties
111: *
112: * @see #getNormalProperties
113: */
114: public static final PropertyMapProperty NORMAL_PROPERTIES = new PropertyMapProperty(
115: PROPERTIES, "Normal Properties", "Normal tab properties.",
116: TitledTabStateProperties.PROPERTIES);
117:
118: /**
119: * Highlighted state properties
120: *
121: * @see #getHighlightedProperties
122: */
123: public static final PropertyMapProperty HIGHLIGHTED_PROPERTIES = new PropertyMapProperty(
124: PROPERTIES, "Highlighted Properties",
125: "Highlighted tab properties.",
126: TitledTabStateProperties.PROPERTIES);
127:
128: /**
129: * Disabled state properties
130: *
131: * @see #getDisabledProperties
132: */
133: public static final PropertyMapProperty DISABLED_PROPERTIES = new PropertyMapProperty(
134: PROPERTIES, "Disabled Properties",
135: "Disabled tab properties.",
136: TitledTabStateProperties.PROPERTIES);
137:
138: /**
139: * Size policy property
140: *
141: * @see #setSizePolicy
142: * @see #getSizePolicy
143: */
144: public static final TitledTabSizePolicyProperty SIZE_POLICY = new TitledTabSizePolicyProperty(
145: PROPERTIES, "Size Policy", "Tab size policy",
146: PropertyMapValueHandler.INSTANCE);
147:
148: /**
149: * Border size policy property
150: *
151: * @see #setBorderSizePolicy
152: * @see #getBorderSizePolicy
153: */
154: public static final TitledTabBorderSizePolicyProperty BORDER_SIZE_POLICY = new TitledTabBorderSizePolicyProperty(
155: PROPERTIES, "Border Size Policy", "Border size policy.",
156: PropertyMapValueHandler.INSTANCE);
157:
158: /**
159: * Tab minimum size property
160: *
161: * @see #setMinimumSizeProvider(DimensionProvider)
162: * @see #getMinimumSizeProvider()
163: */
164: public static final DimensionProviderProperty MINIMUM_SIZE_PROVIDER = new DimensionProviderProperty(
165: PROPERTIES, "Minimum Size", "Tab minimum size.",
166: PropertyMapValueHandler.INSTANCE);
167:
168: /**
169: * Highlighted raised amount property
170: *
171: * @see #setHighlightedRaised
172: * @see #getHighlightedRaised
173: */
174: public static final IntegerProperty HIGHLIGHTED_RAISED_AMOUNT = IntegerProperty
175: .createPositive(PROPERTIES, "Highlighted Raised",
176: "Number of raised pixels for highlighted tab.", 2,
177: PropertyMapValueHandler.INSTANCE);
178:
179: /**
180: * Hover listener property
181: *
182: * @see #setHoverListener
183: * @see #getHoverListener
184: * @since ITP 1.3.0
185: */
186: public static final HoverListenerProperty HOVER_LISTENER = new HoverListenerProperty(
187: PROPERTIES,
188: "Hover Listener",
189: "Hover Listener to be used for tracking mouse hovering over the tab.",
190: PropertyMapValueHandler.INSTANCE);
191: /**
192: * TitledTab enabled property
193: *
194: * @see #setEnabled
195: * @see #getEnabled
196: * @since ITP 1.5.0
197: */
198: public static final BooleanProperty ENABLED = new BooleanProperty(
199: PROPERTIES, "Enabled", "TitledTab enabled or disabled",
200: PropertyMapValueHandler.INSTANCE);
201:
202: private static final TitledTabProperties DEFAULT_VALUES = new TitledTabProperties(
203: PROPERTIES.getDefaultMap());
204:
205: static {
206: DynamicUIManager.getInstance().addListener(
207: new DynamicUIManagerListener() {
208: public void lookAndFeelChanged() {
209: updateVisualProperties();
210: }
211:
212: public void propertiesChanged() {
213: updateVisualProperties();
214: }
215:
216: public void propertiesChanging() {
217: }
218:
219: public void lookAndFeelChanging() {
220: }
221: });
222:
223: DEFAULT_VALUES.getNormalProperties().getMap()
224: .createRelativeRef(
225: TitledTabStateProperties.TOOL_TIP_TEXT,
226: DEFAULT_VALUES.getNormalProperties().getMap(),
227: TitledTabStateProperties.TEXT);
228:
229: DEFAULT_VALUES.getHighlightedProperties().getMap().addSuperMap(
230: DEFAULT_VALUES.getNormalProperties().getMap());
231: DEFAULT_VALUES.getDisabledProperties().getMap().addSuperMap(
232: DEFAULT_VALUES.getNormalProperties().getMap());
233:
234: {
235: Property[] refProperties = TitledTabStateProperties.PROPERTIES
236: .getProperties();
237:
238: for (int i = 0; i < refProperties.length; i++) {
239: DEFAULT_VALUES.getHighlightedProperties().getMap()
240: .createRelativeRef(
241: refProperties[i],
242: DEFAULT_VALUES.getNormalProperties()
243: .getMap(), refProperties[i]);
244: DEFAULT_VALUES.getDisabledProperties().getMap()
245: .createRelativeRef(
246: refProperties[i],
247: DEFAULT_VALUES.getNormalProperties()
248: .getMap(), refProperties[i]);
249: }
250: }
251:
252: {
253: Property[] refProperties = ComponentProperties.PROPERTIES
254: .getProperties();
255:
256: for (int i = 0; i < refProperties.length; i++) {
257: DEFAULT_VALUES.getHighlightedProperties()
258: .getComponentProperties().getMap()
259: .createRelativeRef(
260: refProperties[i],
261: DEFAULT_VALUES.getNormalProperties()
262: .getComponentProperties()
263: .getMap(), refProperties[i]);
264: DEFAULT_VALUES.getDisabledProperties()
265: .getComponentProperties().getMap()
266: .createRelativeRef(
267: refProperties[i],
268: DEFAULT_VALUES.getNormalProperties()
269: .getComponentProperties()
270: .getMap(), refProperties[i]);
271: }
272: }
273:
274: {
275: Property[] refProperties = ShapedPanelProperties.PROPERTIES
276: .getProperties();
277:
278: for (int i = 0; i < refProperties.length; i++) {
279: DEFAULT_VALUES.getHighlightedProperties()
280: .getShapedPanelProperties().getMap()
281: .createRelativeRef(
282: refProperties[i],
283: DEFAULT_VALUES.getNormalProperties()
284: .getShapedPanelProperties()
285: .getMap(), refProperties[i]);
286: DEFAULT_VALUES.getDisabledProperties()
287: .getShapedPanelProperties().getMap()
288: .createRelativeRef(
289: refProperties[i],
290: DEFAULT_VALUES.getNormalProperties()
291: .getShapedPanelProperties()
292: .getMap(), refProperties[i]);
293: }
294: }
295:
296: updateVisualProperties();
297: updateFunctionalProperties();
298: }
299:
300: /**
301: * Constructs an empty TitledTabProperties object
302: */
303: public TitledTabProperties() {
304: super (PropertyMapFactory.create(PROPERTIES));
305: }
306:
307: /**
308: * Constructs a TitledTabProperties object with the give object as property storage
309: *
310: * @param object object to store properties in
311: */
312: public TitledTabProperties(PropertyMap object) {
313: super (object);
314: }
315:
316: /**
317: * Constructs a TitledTabProperties object that inherits its properties from the given TitledTabProperties object
318: *
319: * @param inheritFrom TitledTabProperties object to inherit properties from
320: */
321: public TitledTabProperties(TitledTabProperties inheritFrom) {
322: super (PropertyMapFactory.create(inheritFrom.getMap()));
323: }
324:
325: /**
326: * Adds a super object from which property values are inherited.
327: *
328: * @param superObject the object from which to inherit property values
329: * @return this
330: */
331: public TitledTabProperties addSuperObject(
332: TitledTabProperties super Object) {
333: getMap().addSuperMap(super Object.getMap());
334: return this ;
335: }
336:
337: /**
338: * Removes the last added super object.
339: *
340: * @return this
341: */
342: public TitledTabProperties removeSuperObject() {
343: getMap().removeSuperMap();
344: return this ;
345: }
346:
347: /**
348: * Removes the given super object.
349: *
350: * @param superObject super object to remove
351: * @return this
352: * @since ITP 1.3.0
353: */
354: public TitledTabProperties removeSuperObject(
355: TitledTabProperties super Object) {
356: getMap().removeSuperMap(super Object.getMap());
357: return this ;
358: }
359:
360: /**
361: * Replaces the given super objects.
362: *
363: * @param oldSuperObject super object to replace
364: * @param newSuperObject new super object
365: * @return this
366: * @since ITP 1.4.0
367: */
368: public TitledTabProperties replaceSuperObject(
369: TitledTabProperties oldSuperObject,
370: TitledTabProperties newSuperObject) {
371: getMap().replaceSuperMap(oldSuperObject.getMap(),
372: newSuperObject.getMap());
373: return this ;
374: }
375:
376: /**
377: * Creates a properties object with default properties based on the current look and feel
378: *
379: * @return properties object
380: */
381: public static TitledTabProperties getDefaultProperties() {
382: return new TitledTabProperties(DEFAULT_VALUES);
383: }
384:
385: /**
386: * Gets the properties for the normal state
387: *
388: * @return the normal state properties
389: */
390: public TitledTabStateProperties getNormalProperties() {
391: return new TitledTabStateProperties(NORMAL_PROPERTIES
392: .get(getMap()));
393: }
394:
395: /**
396: * Gets the properties for the highlighted state
397: *
398: * @return the highlighted state properties
399: */
400: public TitledTabStateProperties getHighlightedProperties() {
401: return new TitledTabStateProperties(HIGHLIGHTED_PROPERTIES
402: .get(getMap()));
403: }
404:
405: /**
406: * Gets the properties for the disabled state
407: *
408: * @return the disabled state properties
409: */
410: public TitledTabStateProperties getDisabledProperties() {
411: return new TitledTabStateProperties(DISABLED_PROPERTIES
412: .get(getMap()));
413: }
414:
415: /**
416: * Sets if this TitledTab should be focusable
417: *
418: * @param value true for focusable, otherwise false
419: * @return this TitledTabProperties
420: */
421: public TitledTabProperties setFocusable(boolean value) {
422: FOCUSABLE.set(getMap(), value);
423:
424: return this ;
425: }
426:
427: /**
428: * Gets if this TitledTab is focusable
429: *
430: * @return true for focusable, otherwise false
431: */
432: public boolean getFocusable() {
433: return FOCUSABLE.get(getMap());
434: }
435:
436: /**
437: * <p>
438: * Sets if this TitledTab should show its built-in focus marker when this tab has focus.
439: * </p>
440: *
441: * <p>
442: * <strong>Note:</strong> Disabling the focus marker is useful when for example creating a
443: * theme that draws its own focus marker.
444: * </p>
445: *
446: * @param value true for enabled, otherwise false
447: * @return this TitledTabProperties
448: * @since ITP 1.4.0
449: */
450: public TitledTabProperties setFocusMarkerEnabled(boolean value) {
451: FOCUS_MARKER_ENABLED.set(getMap(), value);
452:
453: return this ;
454: }
455:
456: /**
457: * <p>
458: * Gets if this TitledTab should show its built-in focus marker when this tab has focus.
459: * </p>
460: *
461: * <p>
462: * <strong>Note:</strong> Disabling the focus marker is useful when for example creating a
463: * theme that draws its own focus marker.
464: * </p>
465: *
466: * @return true for enabled, otherwise false
467: * @since ITP 1.4.0
468: */
469: public boolean getFocusMarkerEnabled() {
470: return FOCUS_MARKER_ENABLED.get(getMap());
471: }
472:
473: /**
474: * Sets the size policy for this TitledTab
475: *
476: * @param sizePolicy the size policy
477: * @return this TitledTabProperties
478: */
479: public TitledTabProperties setSizePolicy(
480: TitledTabSizePolicy sizePolicy) {
481: SIZE_POLICY.set(getMap(), sizePolicy);
482:
483: return this ;
484: }
485:
486: /**
487: * Gets the size policy for this TitledTab
488: *
489: * @return the size policy
490: */
491: public TitledTabSizePolicy getSizePolicy() {
492: return SIZE_POLICY.get(getMap());
493: }
494:
495: /**
496: * Sets the border size policy for this TitledTab
497: *
498: * @param sizePolicy the border size policy
499: * @return this TitledTabProperties
500: */
501: public TitledTabProperties setBorderSizePolicy(
502: TitledTabBorderSizePolicy sizePolicy) {
503: BORDER_SIZE_POLICY.set(getMap(), sizePolicy);
504:
505: return this ;
506: }
507:
508: /**
509: * Gets the border size policy for this TitledTab
510: *
511: * @return the border size policy
512: */
513: public TitledTabBorderSizePolicy getBorderSizePolicy() {
514: return BORDER_SIZE_POLICY.get(getMap());
515: }
516:
517: /**
518: * Sets the tab's minimum size dimension provider
519: *
520: * @param size the minimum size dimension provider or null if tab's default minimum size should be used instead
521: * @return this TitledTabProperties
522: */
523: public TitledTabProperties setMinimumSizeProvider(
524: DimensionProvider size) {
525: MINIMUM_SIZE_PROVIDER.set(getMap(), size);
526:
527: return this ;
528: }
529:
530: /**
531: * Gets the dimension provider for the tab's minimum size
532: *
533: * @return the minimum size provider or null if default tab minimum size is to be used instead
534: */
535: public DimensionProvider getMinimumSizeProvider() {
536: return MINIMUM_SIZE_PROVIDER.get(getMap());
537: }
538:
539: /**
540: * Sets how many pixels higher this TitledTab will be when it is in its highlighted state compared to its normal and
541: * disabled state
542: *
543: * @param amount number of pixels
544: * @return this TitledTabProperties
545: */
546: public TitledTabProperties setHighlightedRaised(int amount) {
547: HIGHLIGHTED_RAISED_AMOUNT.set(getMap(), amount);
548:
549: return this ;
550: }
551:
552: /**
553: * Gets how many pixels higher this TitledTab will be when it is in its highlighted state compared to its normal and
554: * disabled state
555: *
556: * @return number of pixels
557: */
558: public int getHighlightedRaised() {
559: return HIGHLIGHTED_RAISED_AMOUNT.get(getMap());
560: }
561:
562: /**
563: * <p>
564: * Sets if this TitledTab should be enabled or not.
565: * </p>
566: *
567: * <p>
568: * <strong>Note:</strong> Calling {@link TitledTab#setEnabled(boolean)} will modify this property for the tab.
569: * </p>
570: *
571: * @param value true for enabled, otherwise false
572: * @return this TitledTabProperties
573: * @since ITP 1.5.0
574: */
575: public TitledTabProperties setEnabled(boolean value) {
576: ENABLED.set(getMap(), value);
577:
578: return this ;
579: }
580:
581: /**
582: * Gets if this TitledTab is enabled or disabled
583: *
584: * @return true for enabled, otherwise false
585: * @since ITP 1.5.0
586: */
587: public boolean getEnabled() {
588: return ENABLED.get(getMap());
589: }
590:
591: /**
592: * <p>Sets the hover listener that will be triggered when the tab is hovered by the mouse.</p>
593: *
594: * <p>The hovered titled tab will be the source of the hover event sent to the hover listener.</p>
595: *
596: * @param listener the hover listener
597: * @return this TitledTabProperties
598: * @since ITP 1.3.0
599: */
600: public TitledTabProperties setHoverListener(HoverListener listener) {
601: HOVER_LISTENER.set(getMap(), listener);
602: return this ;
603: }
604:
605: /**
606: * <p>Gets the hover listener that will be triggered when the tab is hovered by the mouse.</p>
607: *
608: * <p>The hovered titled tab will be the source of the hover event sent to the hover listener.</p>
609: *
610: * @return the hover listener
611: * @since ITP 1.3.0
612: */
613: public HoverListener getHoverListener() {
614: return HOVER_LISTENER.get(getMap());
615: }
616:
617: private static void updateVisualProperties() {
618: PropertyMapManager.runBatch(new Runnable() {
619: public void run() {
620: int gap = TabbedUIDefaults.getIconTextGap();
621:
622: DEFAULT_VALUES.getNormalProperties()
623: .getShapedPanelProperties().setOpaque(true);
624:
625: DEFAULT_VALUES.getNormalProperties()
626: .setIconTextGap(gap).setTextTitleComponentGap(
627: gap).setIconVisible(true)
628: .setTextVisible(true).setTitleComponentVisible(
629: true).getComponentProperties().setFont(
630: TabbedUIDefaults.getFont())
631: .setForegroundColor(
632: TabbedUIDefaults
633: .getNormalStateForeground())
634: .setBackgroundColor(
635: TabbedUIDefaults
636: .getNormalStateBackground())
637: .setBorder(new TabAreaLineBorder()).setInsets(
638: TabbedUIDefaults.getTabInsets());
639:
640: DEFAULT_VALUES
641: .getHighlightedProperties()
642: .getComponentProperties()
643: .setBackgroundColor(
644: TabbedUIDefaults
645: .getHighlightedStateBackground())
646: .setBorder(
647: new CompoundBorder(
648: new TabAreaLineBorder(),
649: new TabHighlightBorder(
650: TabbedUIDefaults
651: .getHighlight(),
652: true)));
653:
654: DEFAULT_VALUES.getDisabledProperties()
655: .getComponentProperties().setForegroundColor(
656: TabbedUIDefaults
657: .getDisabledForeground())
658: .setBackgroundColor(
659: TabbedUIDefaults
660: .getDisabledBackground());
661: }
662: });
663: }
664:
665: private static void updateFunctionalProperties() {
666: DEFAULT_VALUES.setEnabled(true).setFocusable(true)
667: .setFocusMarkerEnabled(true).setSizePolicy(
668: TitledTabSizePolicy.EQUAL_SIZE)
669: .setBorderSizePolicy(
670: TitledTabBorderSizePolicy.EQUAL_SIZE)
671: .setHighlightedRaised(2);
672:
673: DEFAULT_VALUES
674: .getNormalProperties()
675: .setHorizontalAlignment(Alignment.LEFT)
676: .setVerticalAlignment(Alignment.CENTER)
677: .setIconTextRelativeAlignment(Alignment.LEFT)
678: .setTitleComponentTextRelativeAlignment(Alignment.RIGHT)
679: .setDirection(Direction.RIGHT);
680: }
681: }
|