1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.Text;
43
44 class TextDetailsDialog 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 private JTextField srcField = null;
50 private JTextField classField = null;
51 private JTextField pathField = null;
52 private CheckLabel elementContentWhitespaceField = null;
53
54 private JTextArea dataField = null;
55 private JTextArea wholeTextField = null;
56
57 private JEditorPane contextPane = null;
58
59 TextDetailsDialog(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 elementContentWhitespaceField = new CheckLabel("Element Content Whitespace");
85 form.add(new JLabel(), LABEL_CONSTRAINTS);
86 form.add(elementContentWhitespaceField, FormLayout.RIGHT);
87
88 dataField = new JTextArea();
89 dataField.setEditable(false);
90 dataField.setLineWrap(false);
91 form.add(new JLabel("Data:"), LABEL_CONSTRAINTS);
92
93 JPanel panel = new JPanel(new BorderLayout());
94 panel.add(dataField, BorderLayout.CENTER);
95
96 JScrollPane scroller = new JScrollPane( panel);
97 scroller.setPreferredSize(EDITORPANE_SIZE);
98 form.add(scroller, FormLayout.RIGHT_FILL);
99
100 wholeTextField = new JTextArea();
101 wholeTextField.setEditable(false);
102 wholeTextField.setLineWrap(false);
103 form.add(new JLabel("Whole Text:"), LABEL_CONSTRAINTS);
104
105 panel = new JPanel(new BorderLayout());
106 panel.add(wholeTextField, BorderLayout.CENTER);
107
108 scroller = new JScrollPane( panel);
109 scroller.setPreferredSize(EDITORPANE_SIZE);
110 form.add(scroller, FormLayout.RIGHT_FILL);
111
112 form.add(Box.createVerticalStrut(10), FormLayout.FULL);
113
114 form.add(new JLabel("Context:"), FormLayout.FULL);
115
116
117 nodePanel = new NodePanel();
118 nodePanel.setBorder( new EmptyBorder(10, 10, 10, 10));
119
120 contextPane = new JEditorPane();
121 contextPane.setEditorKit(new XMLEditorKit());
122 contextPane.setEditable(false);
123 contextPane.setFont(new Font("monospaced", Font.PLAIN, 12));
124 contextPane.getDocument().putProperty(PlainDocument.tabSizeAttribute, new Integer(2));
125
126 scroller = new JScrollPane(new ScrollableEditorPanel(contextPane));
127 scroller.setPreferredSize(AttributeNode.EDITORPANE_SIZE);
128
129
130 scroller.setRowHeaderView(new LineNumberMargin(contextPane));
131
132 general.add(form, BorderLayout.NORTH);
133 general.add(scroller, BorderLayout.CENTER);
134
135 addTab("General", general);
136 addTab("Node", nodePanel);
137
138 pack();
139
140 setSize(new Dimension( 500, getSize().height));
141 setLocationRelativeTo(parent);
142 }
143
144 public void setText( Text text) {
145 setTitle("Text Details");
146 nodePanel.setNode(text);
147
148 srcField.setText(text.getSrc());
149 srcField.setCaretPosition(0);
150 classField.setText(text.getClazz());
151 classField.setCaretPosition(0);
152 pathField.setText( text.getPath());
153 pathField.setCaretPosition(0);
154
155 elementContentWhitespaceField.setSelected(text.isElementContentWhitespace());
156
157 dataField.setText( text.getData());
158 dataField.setCaretPosition(0);
159
160 wholeTextField.setText( text.getWholeText());
161 wholeTextField.setCaretPosition(0);
162
163 contextPane.setText(text.getContext());
164 contextPane.setCaretPosition(0);
165 }
166
167 @Override
168 protected String getBaseHelpID() {
169 return "output.result.text";
170 }
171 }