View Javadoc

1   /*
2    * $Id: ResultNode.java,v 1.7 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  import java.util.StringTokenizer;
25  
26  import javax.swing.Icon;
27  import javax.swing.JDialog;
28  import javax.swing.JFrame;
29  import javax.swing.JPopupMenu;
30  import javax.swing.tree.DefaultMutableTreeNode;
31  
32  import org.bounce.RunnableAction;
33  import org.xmlhammer.gui.output.actions.CopyAction;
34  import org.xmlhammer.gui.output.actions.EditURIAction;
35  import org.xmlhammer.gui.output.actions.OpenURIAction;
36  import org.xmlhammer.gui.output.actions.PropertiesAction;
37  
38  /***
39   * The base node for Result Nodes.
40   *
41   * @version	$Revision: 1.7 $, $Date: 2007/07/04 19:42:48 $
42   * @author Edwin Dankert <edankert@gmail.com>
43   */
44  public abstract class ResultNode extends DefaultMutableTreeNode {
45      private static OpenURIAction openURIAction = null;
46      private static EditURIAction editURIAction = null;
47      private static CopyAction copyAction = null;
48      private static PropertiesAction propertiesAction = null;
49      
50  	public abstract String getName();
51  	public abstract String getValue();
52  	public abstract String getDescription();
53  	public abstract Icon getIcon();
54      
55      public abstract RunnableAction getDefaultAction(JFrame parent);
56      public abstract JPopupMenu getPopupMenu(JFrame parent);
57      
58      public static String getFirstLine(String lines) {
59          StringTokenizer tokenizer = new StringTokenizer(lines, "\n\r");
60          
61          while (tokenizer.hasMoreTokens()) {
62              String line = tokenizer.nextToken().trim();
63              if (line.length() > 0) {
64                  return line;
65              }
66          }
67          
68          return "";
69      }
70      
71      protected OpenURIAction getOpenURIAction(URI uri, int line, int column) {
72          if (openURIAction == null) {
73              openURIAction = new OpenURIAction();
74          }
75          
76          openURIAction.setLocation(uri, line, column);
77          
78          return openURIAction;
79      }
80      
81      protected EditURIAction getEditURIAction(URI uri, int line, int column) {
82          if (editURIAction == null) {
83              editURIAction = new EditURIAction();
84          }
85          
86          editURIAction.setLocation(uri, line, column);
87  
88          return editURIAction;
89      }
90  
91      protected CopyAction getCopyAction() {
92          if (copyAction == null) {
93              copyAction = new CopyAction();
94          }
95          
96          copyAction.setText(getCopyValue());
97          
98          return copyAction;
99      }
100     
101     public abstract String getCopyValue();
102 
103     protected PropertiesAction getPropertiesAction(JDialog dialog) {
104         if (propertiesAction == null) {
105             propertiesAction = new PropertiesAction();
106         }
107         
108         propertiesAction.setDialog(dialog);
109         
110         return propertiesAction;
111     }
112 }