Revision: 1670 http://svn.sourceforge.net/spring-rich-c/?rev=1670&view=rev Author: kevinstembridge Date: 2007-01-15 14:29:36 -0800 (Mon, 15 Jan 2007)
Log Message: ----------- Added javadoc Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/CommandFaceDescriptor.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/CommandFaceDescriptor.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/CommandFaceDescriptor.java 2007-01-15 22:23:43 UTC (rev 1669) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/CommandFaceDescriptor.java 2007-01-15 22:29:36 UTC (rev 1670) @@ -28,25 +28,35 @@ import org.springframework.richclient.core.DescribedElement; import org.springframework.richclient.core.DescriptionConfigurable; import org.springframework.richclient.core.VisualizedElement; -import org.springframework.richclient.factory.LabelInfoFactory; -import org.springframework.util.Assert; +import org.springframework.richclient.util.Assert; /** + * A parameter object that contains the information to describe the visual representation of a + * command object. + * + * * @author Keith Donald */ public class CommandFaceDescriptor extends AbstractPropertyChangePublisher implements DescribedElement, VisualizedElement, CommandLabelConfigurable, DescriptionConfigurable, CommandIconConfigurable { + /** The property name used when firing events for the [EMAIL PROTECTED] labelInfo} property. */ public static final String LABEL_INFO_PROPERTY = "labelInfo"; + /** The property name used when firing events for the [EMAIL PROTECTED] icon} property. */ public static final String ICON_PROPERTY = "icon"; + /** The property name used when firing events for the [EMAIL PROTECTED] largeIcon} property. */ public static final String LARGE_ICON_PROPERTY = "largeIcon"; + /** The property name used when firing events for the [EMAIL PROTECTED] iconInfo} property. */ public static final String ICON_INFO_PROPERTY = "iconInfo"; + /** The property name used when firing events for the [EMAIL PROTECTED] largeIconInfo} property. */ public static final String LARGE_ICON_INFO_PROPERTY = "largeIconInfo"; + /** A convenience instance to be used when no face descriptor information is available. */ + //FIXME this is a mutable class, probably shouldn't be using a common instance for blank descriptors public static final CommandFaceDescriptor BLANK_FACE_DESCRIPTOR = new CommandFaceDescriptor(); private String caption; @@ -59,10 +69,28 @@ private CommandButtonIconInfo largeIconInfo = CommandButtonIconInfo.BLANK_ICON_INFO; + /** + * Creates a new [EMAIL PROTECTED] CommandFaceDescriptor} that uses the given encoded label descriptor + * to provide the label properties. + * + * @param encodedLabel The encoded label descriptor. May be null or empty to define a blank label. + * + * @see CommandButtonLabelInfo#valueOf(String) + */ public CommandFaceDescriptor(String encodedLabel) { this(encodedLabel, null, null); } + /** + * Creates a new [EMAIL PROTECTED] CommandFaceDescriptor} that uses the given encoded label descriptor + * to provide the label properties, along with the given icon and caption. + * + * @param encodedLabel The encoded label descriptor. May be null or empty. + * @param icon The main default icon to be displayed by the command. May be null. + * @param caption The caption to be displayed on rollover of the command. May be null or empty. + * + * @see CommandButtonLabelInfo#valueOf(String) + */ public CommandFaceDescriptor(String encodedLabel, Icon icon, String caption) { this.labelInfo = CommandButtonLabelInfo.valueOf(encodedLabel); if (icon != null) { @@ -71,88 +99,195 @@ this.caption = caption; } + /** + * Creates a new [EMAIL PROTECTED] CommandFaceDescriptor} with a blank label and no icon or caption. + */ public CommandFaceDescriptor() { this(CommandButtonLabelInfo.BLANK_BUTTON_LABEL); } + /** + * Creates a new [EMAIL PROTECTED] CommandFaceDescriptor} whose label information is provided by the + * given [EMAIL PROTECTED] CommandButtonLabelInfo} instance. + * + * @param labelInfo The label information for the command. + */ public CommandFaceDescriptor(CommandButtonLabelInfo labelInfo) { Assert.notNull(labelInfo, "The labelInfo property is required"); this.labelInfo = labelInfo; } + /** + * Returns true if no command label information is provided by this descriptor. + * + * @return true if there is no label information, false otherwise. + */ public boolean isBlank() { return labelInfo == CommandButtonLabelInfo.BLANK_BUTTON_LABEL; } + /** + * Returns the label text specified by this descriptor. + * + * @return The label text. May be null or empty. + */ public String getText() { return labelInfo.getText(); } + /** + * [EMAIL PROTECTED] + */ public String getDisplayName() { return getText(); } + /** + * [EMAIL PROTECTED] + */ public String getCaption() { return caption; } + /** + * [EMAIL PROTECTED] + */ public String getDescription() { return description; } + /** + * Returns the mnemonic to be associated with the command. + * + * @return The command mnemonic. + */ public int getMnemonic() { return labelInfo.getMnemonic(); } + /** + * Returns the zero-based index of the mnemonic character within the label text associated with + * the command. + * + * @return The mnemonic index, or -1 if no mnemonic index is associated with the command. + */ public int getMnemonicIndex() { return labelInfo.getMnemonicIndex(); } + /** + * [EMAIL PROTECTED] + */ public Image getImage() { - return iconInfo.getImage(); + + if (this.iconInfo == null) { + return null; + } + else { + return iconInfo.getImage(); + } + } + /** + * [EMAIL PROTECTED] + */ public Icon getIcon() { - return iconInfo.getIcon(); + + if (this.iconInfo == null) { + return null; + } + else { + return iconInfo.getIcon(); + } + } + /** + * Returns the main default large icon associated with the command. + * + * @return The large icon, or null. + */ public Icon getLargeIcon() { - return largeIconInfo.getIcon(); + + if (this.largeIconInfo == null) { + return null; + } + else { + return largeIconInfo.getIcon(); + } + } + /** + * Returns the keystroke accelerator associated with the command. + * + * @return The keystroke accelerator, or null. + */ public KeyStroke getAccelerator() { return labelInfo.getAccelerator(); } + /** + * Returns the command button label info object. + * + * @return The command button label info, or null. + */ protected CommandButtonLabelInfo getLabelInfo() { return labelInfo; } + /** + * Returns the label information for the command. + * + * @return The label information, never null. + */ protected CommandButtonIconInfo getIconInfo() { return iconInfo; } + /** + * Returns the large icon information object for the command. + * + * @return The large icon information, or null. + */ protected CommandButtonIconInfo getLargeIconInfo() { return largeIconInfo; } + /** + * [EMAIL PROTECTED] + */ public void setCaption(String shortDescription) { String old = this.caption; this.caption = shortDescription; firePropertyChange(DescribedElement.CAPTION_PROPERTY, old, this.caption); } + /** + * [EMAIL PROTECTED] + */ public void setDescription(String longDescription) { String old = this.description; this.description = longDescription; firePropertyChange(DescribedElement.DESCRIPTION_PROPERTY, old, this.description); } + /** + * Sets the label information for the command using the given encoded label descriptor. + * + * @param encodedLabelInfo The encoded label descriptor. May be null or empty. + * + * @see CommandButtonLabelInfo#valueOf(String) + */ public void setButtonLabelInfo(String encodedLabelInfo) { - CommandButtonLabelInfo labelInfo = CommandButtonLabelInfo.valueOf(encodedLabelInfo); - setLabelInfo(labelInfo); + CommandButtonLabelInfo newLabelInfo = CommandButtonLabelInfo.valueOf(encodedLabelInfo); + setLabelInfo(newLabelInfo); } + /** + * [EMAIL PROTECTED] + */ public void setLabelInfo(CommandButtonLabelInfo labelInfo) { if (labelInfo == null) { labelInfo = CommandButtonLabelInfo.BLANK_BUTTON_LABEL; @@ -162,6 +297,9 @@ firePropertyChange(LABEL_INFO_PROPERTY, old, this.labelInfo); } + /** + * [EMAIL PROTECTED] + */ public void setIconInfo(CommandButtonIconInfo iconInfo) { if (iconInfo == null) { iconInfo = CommandButtonIconInfo.BLANK_ICON_INFO; @@ -171,6 +309,9 @@ firePropertyChange(ICON_INFO_PROPERTY, old, this.iconInfo); } + /** + * [EMAIL PROTECTED] + */ public void setLargeIconInfo(CommandButtonIconInfo largeIconInfo) { if (largeIconInfo == null) { largeIconInfo = CommandButtonIconInfo.BLANK_ICON_INFO; @@ -180,6 +321,11 @@ firePropertyChange(LARGE_ICON_INFO_PROPERTY, old, this.largeIconInfo); } + /** + * Set the main default icon to be associated with the command. + * + * @param icon The main default icon. May be null. + */ public void setIcon(Icon icon) { Icon old = null; if (iconInfo == CommandButtonIconInfo.BLANK_ICON_INFO) { @@ -195,6 +341,11 @@ firePropertyChange(ICON_PROPERTY, old, icon); } + /** + * Sets the main default large icon for the command. + * + * @param icon The large icon. May be null. + */ public void setLargeIcon(Icon icon) { Icon old = null; if (largeIconInfo == CommandButtonIconInfo.BLANK_ICON_INFO) { @@ -210,28 +361,75 @@ firePropertyChange(LARGE_ICON_PROPERTY, old, icon); } + /** + * Configures the given button with the label information contained in this descriptor. + * + * @param button The button to be configured. Must not be null. + * + * @throws IllegalArgumentException if [EMAIL PROTECTED] button} is null. + */ public void configureLabel(AbstractButton button) { + Assert.required(button, "button"); labelInfo.configure(button); } + /** + * Configures the given button with the icon information contained in this descriptor. + * + * @param button The button to be configured. Must not be null. + * + * @throws IllegalArgumentException if [EMAIL PROTECTED] button} is null. + */ public void configureIcon(AbstractButton button) { + Assert.required(button, "button"); configureIconInfo(button, false); } + /** + * Configures the given button with the icon information contained in this descriptor. + * + * @param button The button to be configured. Must not be null. + * @param useLargeIcons Set to true to configure the button with large icons. False will use + * default size icons. + * + * @throws IllegalArgumentException if [EMAIL PROTECTED] button} is null. + */ public void configureIconInfo(AbstractButton button, boolean useLargeIcons) { + + Assert.required(button, "button"); + if (useLargeIcons) { largeIconInfo.configure(button); } else { iconInfo.configure(button); } + } - public void configure(AbstractButton button, AbstractCommand command, CommandButtonConfigurer strategy) { - Assert.notNull(strategy, "The button configurer strategy is required"); - strategy.configure(button, command, this); + /** + * Configures the given button and command using the given configurer and the information + * contained in this instance. + * + * @param button The button to be configured. Must not be null. + * @param command The command to be configured. May be null. + * @param configurer The configurer. Must not be null. + * + * @throws IllegalArgumentException if [EMAIL PROTECTED] button} or [EMAIL PROTECTED] configurer} are null. + */ + public void configure(AbstractButton button, AbstractCommand command, CommandButtonConfigurer configurer) { + Assert.required(button, "button"); + Assert.required(configurer, "configurer"); + configurer.configure(button, command, this); } + /** + * Configures the given action with the information contained in this descriptor. + * + * @param action The action to be configured. Must not be null. + * + * @throws IllegalArgumentException if [EMAIL PROTECTED] action} is null. + */ public void configure(Action action) { Assert.notNull(action, "The swing action to configure is required"); action.putValue(Action.NAME, getText()); @@ -243,6 +441,9 @@ action.putValue(Action.LONG_DESCRIPTION, description); } + /** + * [EMAIL PROTECTED] + */ public String toString() { return new ToStringCreator(this).append("caption", caption).append("description", description).append( "buttonLabelInfo", labelInfo).append("buttonIconInfo", iconInfo).toString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs