View Javadoc

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