Lines 60-65
Link Here
|
60 |
import java.io.ObjectOutputStream; |
60 |
import java.io.ObjectOutputStream; |
61 |
import java.io.ObjectStreamException; |
61 |
import java.io.ObjectStreamException; |
62 |
import java.io.Serializable; |
62 |
import java.io.Serializable; |
|
|
63 |
import java.lang.annotation.ElementType; |
64 |
import java.lang.annotation.Retention; |
65 |
import java.lang.annotation.RetentionPolicy; |
66 |
import java.lang.annotation.Target; |
63 |
import java.lang.ref.Reference; |
67 |
import java.lang.ref.Reference; |
64 |
import java.lang.ref.WeakReference; |
68 |
import java.lang.ref.WeakReference; |
65 |
import java.lang.reflect.InvocationTargetException; |
69 |
import java.lang.reflect.InvocationTargetException; |
Lines 85-90
Link Here
|
85 |
import javax.swing.Timer; |
89 |
import javax.swing.Timer; |
86 |
import javax.swing.plaf.basic.BasicHTML; |
90 |
import javax.swing.plaf.basic.BasicHTML; |
87 |
import javax.swing.text.Keymap; |
91 |
import javax.swing.text.Keymap; |
|
|
92 |
import org.openide.awt.ActionID; |
88 |
import org.openide.awt.Actions; |
93 |
import org.openide.awt.Actions; |
89 |
import org.openide.awt.UndoRedo; |
94 |
import org.openide.awt.UndoRedo; |
90 |
import org.openide.nodes.Node; |
95 |
import org.openide.nodes.Node; |
Lines 92-97
Link Here
|
92 |
import org.openide.nodes.NodeListener; |
97 |
import org.openide.nodes.NodeListener; |
93 |
import org.openide.util.ContextAwareAction; |
98 |
import org.openide.util.ContextAwareAction; |
94 |
import org.openide.util.HelpCtx; |
99 |
import org.openide.util.HelpCtx; |
|
|
100 |
import org.openide.util.ImageUtilities; |
95 |
import org.openide.util.Lookup; |
101 |
import org.openide.util.Lookup; |
96 |
import org.openide.util.NbBundle; |
102 |
import org.openide.util.NbBundle; |
97 |
import org.openide.util.NbPreferences; |
103 |
import org.openide.util.NbPreferences; |
Lines 422-427
Link Here
|
422 |
} |
428 |
} |
423 |
|
429 |
|
424 |
/** |
430 |
/** |
|
|
431 |
* Rather than overriding this method, consider using {@link Description}. |
425 |
* Overwrite when you want to change default persistence type. Default |
432 |
* Overwrite when you want to change default persistence type. Default |
426 |
* persistence type is PERSISTENCE_ALWAYS. |
433 |
* persistence type is PERSISTENCE_ALWAYS. |
427 |
* Return value should be constant over a given TC's lifetime. |
434 |
* Return value should be constant over a given TC's lifetime. |
Lines 429-434
Link Here
|
429 |
* @since 4.20 |
436 |
* @since 4.20 |
430 |
*/ |
437 |
*/ |
431 |
public int getPersistenceType() { |
438 |
public int getPersistenceType() { |
|
|
439 |
Description info = getClass().getAnnotation(Description.class); |
440 |
if (info != null) { |
441 |
return info.persistenceType(); |
442 |
} |
443 |
|
432 |
//First check for 'PersistenceType' client property for compatibility. |
444 |
//First check for 'PersistenceType' client property for compatibility. |
433 |
if (warnedClasses.add(getClass()) && !TopComponent.class.equals(getClass())) { |
445 |
if (warnedClasses.add(getClass()) && !TopComponent.class.equals(getClass())) { |
434 |
Logger.getAnonymousLogger().warning( |
446 |
Logger.getAnonymousLogger().warning( |
Lines 652-664
Link Here
|
652 |
* <attr name="displayName" bundlevalue="your.pkg.Bundle#key"/> |
664 |
* <attr name="displayName" bundlevalue="your.pkg.Bundle#key"/> |
653 |
* <attr name="iconBase" stringvalue="your/pkg/YourComponent.png"/> |
665 |
* <attr name="iconBase" stringvalue="your/pkg/YourComponent.png"/> |
654 |
* <!-- if desired: <attr name="noIconInMenu" boolvalue="false"/> --> |
666 |
* <!-- if desired: <attr name="noIconInMenu" boolvalue="false"/> --> |
|
|
667 |
* <!-- if desired: <attr name="preferredID" stringvalue="id.of.your.tc"/> --> |
655 |
* </file> |
668 |
* </file> |
656 |
* </pre> |
669 |
* </pre> |
|
|
670 |
* The <code>preferredID</code> attribute is supported since version |
671 |
* 6.37. If specified the action first seeks for existing <code>preferredID</code> |
672 |
* component and if found, it opens and activates it. |
673 |
* <p> |
674 |
* Rather than doing all this in XML, consider using {@link OpenActionRegistration}. |
675 |
* |
657 |
* |
676 |
* |
658 |
* @param component the component to open |
677 |
* @param component the component to open |
659 |
* @param displayName the display name of the action |
678 |
* @param displayName the display name of the action |
660 |
* @param image the image to associated with the action |
679 |
* @param image the image to associated with the action |
661 |
* @param noIconInMenu true if this icon shall not have an item in menu |
680 |
* @param noIconInMenu true if this icon shall not have an item in menu |
|
|
681 |
* @see OpenActionRegistration |
662 |
* |
682 |
* |
663 |
* @since 6.24 |
683 |
* @since 6.24 |
664 |
*/ |
684 |
*/ |
Lines 704-709
Link Here
|
704 |
} |
724 |
} |
705 |
|
725 |
|
706 |
/** |
726 |
/** |
|
|
727 |
* Rather than overriding this method, consider using {@link Description}. |
707 |
* Subclasses are encouraged to override this method to provide preferred value |
728 |
* Subclasses are encouraged to override this method to provide preferred value |
708 |
* for unique TopComponent ID returned by {@link org.openide.windows.WindowManager#findTopComponentID}. |
729 |
* for unique TopComponent ID returned by {@link org.openide.windows.WindowManager#findTopComponentID}. |
709 |
* |
730 |
* |
Lines 716-722
Link Here
|
716 |
* @since 4.13 |
737 |
* @since 4.13 |
717 |
*/ |
738 |
*/ |
718 |
protected String preferredID() { |
739 |
protected String preferredID() { |
719 |
Class clazz = getClass(); |
740 |
Class<?> clazz = getClass(); |
|
|
741 |
Description id = clazz.getAnnotation(Description.class); |
742 |
if (id != null) { |
743 |
return id.preferredID(); |
744 |
} |
720 |
|
745 |
|
721 |
if (getPersistenceType() != PERSISTENCE_NEVER && warnedTCPIClasses.add(clazz)) { |
746 |
if (getPersistenceType() != PERSISTENCE_NEVER && warnedTCPIClasses.add(clazz)) { |
722 |
Logger.getAnonymousLogger().warning( |
747 |
Logger.getAnonymousLogger().warning( |
Lines 1027-1034
Link Here
|
1027 |
firePropertyChange("icon", old, icon); // NOI18N |
1052 |
firePropertyChange("icon", old, icon); // NOI18N |
1028 |
} |
1053 |
} |
1029 |
|
1054 |
|
1030 |
/** @return The icon of the top component */ |
1055 |
/** |
|
|
1056 |
* Rather than overriding this method, consider using {@link Description}. |
1057 |
* @return The icon of the top component |
1058 |
*/ |
1031 |
public Image getIcon() { |
1059 |
public Image getIcon() { |
|
|
1060 |
Description id; |
1061 |
if (icon == null && (id = getClass().getAnnotation(Description.class)) != null) { |
1062 |
icon = ImageUtilities.loadImage(id.iconBase(), true); |
1063 |
} |
1032 |
return icon; |
1064 |
return icon; |
1033 |
} |
1065 |
} |
1034 |
|
1066 |
|
Lines 1357-1362
Link Here
|
1357 |
*/ |
1389 |
*/ |
1358 |
public TopComponent cloneComponent(); |
1390 |
public TopComponent cloneComponent(); |
1359 |
} |
1391 |
} |
|
|
1392 |
|
1393 |
/** Provides basic information about the persistence of a {@link TopComponent}. |
1394 |
* Using this annotation is preferred to overriding {@link #preferredID()} |
1395 |
* or calling {@link #setIcon(java.awt.Image)}. |
1396 |
* @since 6.37 |
1397 |
*/ |
1398 |
@Retention(RetentionPolicy.RUNTIME) |
1399 |
@Target(ElementType.TYPE) |
1400 |
public static @interface Description { |
1401 |
/** The default value for {@link TopComponent#preferredID()}. |
1402 |
*/ |
1403 |
public String preferredID(); |
1404 |
/** The icon to load for {@link TopComponent#getIcon()}. |
1405 |
*/ |
1406 |
public String iconBase() default ""; |
1407 |
/** Default value for {@link TopComponent#getPersistenceType()}. |
1408 |
* |
1409 |
* @return one of {@link TopComponent#PERSISTENCE_ALWAYS}, |
1410 |
* {@link TopComponent#PERSISTENCE_NEVER}, |
1411 |
* {@link TopComponent#PERSISTENCE_ONLY_OPENED} |
1412 |
* |
1413 |
*/ |
1414 |
public int persistenceType() default PERSISTENCE_ALWAYS; |
1415 |
} |
1416 |
|
1417 |
/** Registers {@link TopComponent} into specified location among |
1418 |
* existing {@link Mode window system modes}. The mode itself needs |
1419 |
* to be created by other means, this just adds reference to the |
1420 |
* component to it. |
1421 |
* |
1422 |
* @since 6.37 |
1423 |
*/ |
1424 |
@Retention(RetentionPolicy.SOURCE) |
1425 |
@Target({ ElementType.TYPE, ElementType.METHOD }) |
1426 |
public static @interface Registration { |
1427 |
/** Name of the mode the component shall be opened in */ |
1428 |
String mode(); |
1429 |
/** Shall the component be opened at start */ |
1430 |
boolean openAtStartup(); |
1431 |
} |
1432 |
|
1433 |
/** Creates an action that can open the component. |
1434 |
* The action is generated only |
1435 |
* if {@link ActionID} annotation is used on the same element, otherwise |
1436 |
* a compilation error is raised. Also the {@link Description} shall be |
1437 |
* present. |
1438 |
* @since 6.37 |
1439 |
*/ |
1440 |
@Retention(RetentionPolicy.SOURCE) |
1441 |
@Target({ ElementType.TYPE, ElementType.METHOD }) |
1442 |
public static @interface OpenActionRegistration { |
1443 |
/** Display name of the action, usually can refer to value from a |
1444 |
* <code>Bundle.properties</code> using <code>#KEY</code>. |
1445 |
*/ |
1446 |
String displayName(); |
1447 |
|
1448 |
/** The identification of an existing component to seek for. |
1449 |
*/ |
1450 |
String preferredID() default ""; |
1451 |
} |
1360 |
|
1452 |
|
1361 |
/** Registry of all top components. |
1453 |
/** Registry of all top components. |
1362 |
* There is one instance that can be obtained via {@link TopComponent#getRegistry} |
1454 |
* There is one instance that can be obtained via {@link TopComponent#getRegistry} |