View Javadoc

1   /*
2    * $Id: CommentDetailsDialog.java,v 1.9 2008/05/19 20:41:08 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.awt.BorderLayout;
24  import java.awt.Dimension;
25  import java.awt.Font;
26  
27  import javax.swing.Box;
28  import javax.swing.JEditorPane;
29  import javax.swing.JFrame;
30  import javax.swing.JLabel;
31  import javax.swing.JPanel;
32  import javax.swing.JScrollPane;
33  import javax.swing.JTextArea;
34  import javax.swing.JTextField;
35  import javax.swing.text.PlainDocument;
36  
37  import org.bounce.FormLayout;
38  import org.bounce.text.LineNumberMargin;
39  import org.bounce.text.ScrollableEditorPanel;
40  import org.bounce.text.xml.XMLEditorKit;
41  import org.xmlhammer.model.project.Comment;
42  
43  class CommentDetailsDialog extends DetailsDialog {
44      private static final long serialVersionUID = 6396657641170177743L;
45      private NodePanel nodePanel = null;
46      private static final Dimension EDITORPANE_SIZE = new Dimension( 100, 80);        
47      
48      private JTextField srcField = null;
49      private JTextField classField = null;
50      private JTextField pathField = null;
51      
52      private JTextArea dataField = null;
53      
54      private JEditorPane contextPane = null;
55      
56      CommentDetailsDialog(JFrame parent) {
57          super(parent, "Comment Details");
58          
59          DetailsPanel general = new DetailsPanel(new BorderLayout(), "general");
60          JPanel form = new JPanel( new FormLayout(5, 5));
61  
62          srcField = new JTextField();
63          srcField.setEditable(false);
64          form.add(new JLabel("URI:"), LABEL_CONSTRAINTS);
65          form.add(srcField, FormLayout.RIGHT_FILL);
66  
67          classField = new JTextField();
68          classField.setEditable(false);
69          form.add(new JLabel("Class:"), LABEL_CONSTRAINTS);
70          form.add(classField, FormLayout.RIGHT_FILL);
71  
72          form.add(Box.createVerticalStrut(10), FormLayout.FULL);
73  
74          pathField = new JTextField();
75          pathField.setEditable(false);
76          form.add(new JLabel("Path:"), LABEL_CONSTRAINTS);
77          form.add(pathField, FormLayout.RIGHT_FILL);
78  
79          form.add(Box.createVerticalStrut(10), FormLayout.FULL);
80  
81          dataField = new JTextArea();
82          dataField.setEditable(false);
83          dataField.setLineWrap(false);
84          form.add(new JLabel("Data:"), LABEL_CONSTRAINTS);
85          
86          JPanel panel = new JPanel(new BorderLayout());
87          panel.add(dataField, BorderLayout.CENTER);
88  
89          JScrollPane scroller = new JScrollPane( panel);
90          scroller.setPreferredSize(EDITORPANE_SIZE);
91          form.add(scroller, FormLayout.RIGHT_FILL);
92  
93          form.add(Box.createVerticalStrut(10), FormLayout.FULL);
94  
95          form.add(new JLabel("Context:"), FormLayout.FULL);
96  //            form.add(new JLabel(), FormLayout.RIGHT_FILL);
97  
98          nodePanel = new NodePanel();
99  
100         contextPane = new JEditorPane();
101         contextPane.setEditorKit(new XMLEditorKit());
102         contextPane.setEditable(false);
103         contextPane.setFont(new Font("monospaced", Font.PLAIN, 12));
104         contextPane.getDocument().putProperty(PlainDocument.tabSizeAttribute, new Integer(2));
105 
106         scroller = new JScrollPane(new ScrollableEditorPanel(contextPane));
107         scroller.setPreferredSize(AttributeNode.EDITORPANE_SIZE);
108 
109         // Add the number margin as a Row Header View
110         scroller.setRowHeaderView(new LineNumberMargin(contextPane));
111 
112         general.add(form, BorderLayout.NORTH);
113         general.add(scroller, BorderLayout.CENTER);
114 
115         addTab("General", general);
116         addTab("Node", nodePanel);
117         
118         pack();
119         
120         setSize( new Dimension( 500, getSize().height));
121         setLocationRelativeTo(parent);
122     }
123     
124     public void setComment( Comment comment) {
125         setTitle("Comment Details");
126         nodePanel.setNode(comment);
127 
128         srcField.setText(comment.getSrc());
129         srcField.setCaretPosition(0);
130         classField.setText(comment.getClazz());
131         classField.setCaretPosition(0);
132         pathField.setText( comment.getPath());
133         pathField.setCaretPosition(0);
134 
135         dataField.setText( comment.getData());
136         dataField.setCaretPosition(0);
137 
138         contextPane.setText(comment.getContext());
139         contextPane.setCaretPosition(0);
140     }
141 
142     @Override
143     protected String getBaseHelpID() {
144         return "output.result.comment";
145     }
146 }