001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.metadata.swing;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.swing.*;
027: import org.openharmonise.vfs.gui.*;
028: import org.openharmonise.vfs.metadata.*;
029:
030: /**
031: * @author Matthew Large
032: * @version $Revision: 1.1 $
033: *
034: */
035: public class HelpIcon extends JToggleButton implements ActionListener {
036:
037: private Property m_prop = null;
038: private String m_sSummary = "No description available.";
039: private String m_sTitle = "Property Help";
040:
041: public HelpIcon(String sTitle, String sSummary) {
042: super ();
043: this .m_sSummary = sSummary;
044: if (sTitle.trim().equals("title")) {
045: this .m_sTitle = "Title";
046: } else {
047: this .m_sTitle = sTitle;
048: }
049: this .setup();
050: }
051:
052: /**
053: *
054: */
055: public HelpIcon(Property prop) {
056: super ();
057: this .m_prop = prop;
058: if (prop.getSummary() != null && prop.getSummary().length() > 0) {
059: this .m_sSummary = prop.getSummary();
060: }
061: if (prop.getDisplayName() != null
062: && prop.getDisplayName().length() > 0) {
063: if (prop.getDisplayName().trim().equals("title")) {
064: this .m_sTitle = "Title";
065: } else {
066: this .m_sTitle = prop.getDisplayName();
067: }
068: } else {
069: if (prop.getName().trim().equals("title")) {
070: this .m_sTitle = "Title";
071: } else {
072: this .m_sTitle = prop.getName();
073: }
074: }
075: this .setup();
076: }
077:
078: public String getSummary() {
079: return this .m_sSummary;
080: }
081:
082: public String getTitle() {
083: return this .m_sTitle;
084: }
085:
086: private void setup() {
087:
088: this .setIcon(IconManager.getInstance().getIcon(
089: "16-command-help.gif"));
090: this .setPreferredSize(new Dimension(20, 20));
091: this .setToolTipText(this .m_sSummary);
092: this .addActionListener(this );
093: this .setFocusable(false);
094: }
095:
096: /* (non-Javadoc)
097: * @see javax.swing.JComponent#createToolTip()
098: */
099: public JToolTip createToolTip() {
100: JMultiLineToolTip toolTip = new JMultiLineToolTip();
101: toolTip.setFixedWidth(300);
102: return toolTip;
103: }
104:
105: /**
106: * @param arg0
107: */
108: private HelpIcon(String arg0) {
109: super (arg0);
110: }
111:
112: /* (non-Javadoc)
113: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
114: */
115: public void actionPerformed(ActionEvent arg0) {
116: HelpPopup.getInstance().setHelpInfo(this);
117: }
118:
119: }
|