View Javadoc

1   /*
2    * $Id: CommentNode.java,v 1.10 2007/07/04 19:42:48 edankert Exp $
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  package org.xmlhammer.gui.output;
22  
23  import java.net.URI;
24  
25  import javax.swing.ImageIcon;
26  import javax.swing.JFrame;
27  import javax.swing.JPopupMenu;
28  
29  import org.bounce.RunnableAction;
30  import org.bounce.MenuUtilities;
31  import org.bounce.image.ImageLoader;
32  import org.xmlhammer.model.project.Comment;
33  
34  /***
35   * The node for the XML Comment.
36   *
37   * @version	$Revision: 1.10 $, $Date: 2007/07/04 19:42:48 $
38   * @author Edwin Dankert <edankert@gmail.com>
39   */
40  public class CommentNode extends ResultNode {
41  	private static final long serialVersionUID = 5817597938649902807L;
42  
43      private static final ImageIcon ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/write_obj_disabled.gif");
44      private static CommentDetailsDialog dialog = null;
45  
46      private Comment comment = null;
47      private URI uri = null;
48      private String value = null;
49  
50      public CommentNode(URI uri, Comment comment) {
51  		this.comment = comment;
52          this.uri = uri;
53  	}
54  	
55  	public String getName() {
56  		return "";
57  	}
58  	
59  	public String getValue() {
60          if ( value == null) {
61              value = getFirstLine(comment.getNodeValue());
62          }
63  
64          return value;
65  	}
66  	
67  	public String getDescription() {
68  		return getValue();
69  	}
70  	
71  	public ImageIcon getIcon() {
72  		return ICON;
73  	}
74  
75      @Override
76      public JPopupMenu getPopupMenu(JFrame parent) {
77          JPopupMenu popup = new JPopupMenu();
78          popup.add(getOpenURIAction(uri, 0, 0));
79          popup.add(getEditURIAction(uri, 0, 0));
80          popup.addSeparator();
81          popup.add(getCopyAction());
82          popup.addSeparator();
83          popup.add(getPropertiesAction(getDialog(parent)));
84          
85          MenuUtilities.alignMenu(popup);
86  
87          return popup;
88      }
89      
90      @Override
91      public RunnableAction getDefaultAction(JFrame parent) {
92          return getPropertiesAction(getDialog(parent));
93      }
94      
95      private CommentDetailsDialog getDialog(JFrame parent) {
96          if (dialog == null) {
97              dialog = new CommentDetailsDialog(parent);
98          }
99          
100         dialog.setComment(comment);
101 
102         return dialog;
103     }
104     
105     public String getCopyValue() {
106         StringBuffer buffer = new StringBuffer("<!--");
107         buffer.append(comment.getNodeValue());
108         buffer.append("-->");
109         
110         return buffer.toString();
111     }
112 }