| 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.Color; |
| 25 |
|
import java.awt.Dimension; |
| 26 |
|
import java.awt.Font; |
| 27 |
|
import java.awt.event.ActionEvent; |
| 28 |
|
import java.awt.event.ActionListener; |
| 29 |
|
import java.io.BufferedReader; |
| 30 |
|
import java.io.IOException; |
| 31 |
|
import java.io.InputStreamReader; |
| 32 |
|
import java.net.MalformedURLException; |
| 33 |
|
import java.net.URI; |
| 34 |
|
|
| 35 |
|
import javax.swing.Box; |
| 36 |
|
import javax.swing.ImageIcon; |
| 37 |
|
import javax.swing.JButton; |
| 38 |
|
import javax.swing.JEditorPane; |
| 39 |
|
import javax.swing.JFrame; |
| 40 |
|
import javax.swing.JLabel; |
| 41 |
|
import javax.swing.JPanel; |
| 42 |
|
import javax.swing.JScrollPane; |
| 43 |
|
import javax.swing.JTextArea; |
| 44 |
|
import javax.swing.JTextField; |
| 45 |
|
import javax.swing.border.EmptyBorder; |
| 46 |
|
import javax.swing.text.BadLocationException; |
| 47 |
|
import javax.swing.text.DefaultHighlighter; |
| 48 |
|
import javax.swing.text.PlainDocument; |
| 49 |
|
|
| 50 |
|
import org.apache.log4j.Logger; |
| 51 |
|
import org.bounce.FormLayout; |
| 52 |
|
import org.bounce.com.sun.syndication.io.XmlReader; |
| 53 |
|
import org.bounce.image.ImageLoader; |
| 54 |
|
import org.bounce.text.LineNumberMargin; |
| 55 |
|
import org.bounce.text.ScrollableEditorPanel; |
| 56 |
|
import org.bounce.text.xml.XMLEditorKit; |
| 57 |
|
import org.bounce.util.URIUtils; |
| 58 |
|
import org.xmlhammer.gui.util.ExternalApplicationLauncher; |
| 59 |
|
import org.xmlhammer.model.project.Exception; |
| 60 |
|
|
| 61 |
0 |
|
| 62 |
0 |
class ExceptionDetailsDialog extends DetailsDialog { |
| 63 |
0 |
private static final long serialVersionUID = 6396657641170177743L; |
| 64 |
0 |
private static final Dimension EDITORPANE_SIZE = new Dimension( 100, 80); |
| 65 |
0 |
|
| 66 |
0 |
private static final ImageIcon EDIT_ICON = ImageLoader.get().getImage("/org/xmlhammer/gui/icons/obj16/write_obj.gif"); |
| 67 |
|
|
| 68 |
|
private static final int MAX_NO_CHARACTERS = 1000; |
| 69 |
|
private static final int MAX_NO_LINES = 1000; |
| 70 |
0 |
|
| 71 |
0 |
private String title = null; |
| 72 |
0 |
|
| 73 |
0 |
private JTextField srcField = null; |
| 74 |
0 |
private JTextField classField = null; |
| 75 |
0 |
|
| 76 |
0 |
private JTextField lineNumberField = null; |
| 77 |
0 |
private JTextField columnNumberField = null; |
| 78 |
0 |
|
| 79 |
0 |
private JTextArea messageArea = null; |
| 80 |
0 |
private JLabel iconLabel = null; |
| 81 |
0 |
|
| 82 |
0 |
private JTextField systemIdField = null; |
| 83 |
0 |
private JTextField publicIdField = null; |
| 84 |
0 |
private JTextArea messageField = null; |
| 85 |
0 |
private JTextArea localizedMessageField = null; |
| 86 |
0 |
|
| 87 |
0 |
private JEditorPane contextPane = null; |
| 88 |
0 |
|
| 89 |
0 |
private URI uri = null; |
| 90 |
0 |
private int line = -1; |
| 91 |
0 |
private int column = -1; |
| 92 |
|
|
| 93 |
0 |
ExceptionDetailsDialog(JFrame parent, String title) { |
| 94 |
0 |
super(parent, title); |
| 95 |
0 |
|
| 96 |
0 |
this.title = title; |
| 97 |
0 |
|
| 98 |
0 |
contextPane = new JEditorPane(); |
| 99 |
0 |
contextPane.setEditorKit(new XMLEditorKit()); |
| 100 |
0 |
contextPane.setEditable(false); |
| 101 |
0 |
contextPane.setFont(new Font("monospaced", Font.PLAIN, 12)); |
| 102 |
0 |
contextPane.getDocument().putProperty(PlainDocument.tabSizeAttribute, new Integer(2)); |
| 103 |
0 |
|
| 104 |
0 |
JPanel panel = new JPanel(new BorderLayout()); |
| 105 |
0 |
|
| 106 |
0 |
messageArea = new JTextArea(); |
| 107 |
0 |
messageArea.setEditable(false); |
| 108 |
0 |
messageArea.setLineWrap(true); |
| 109 |
0 |
messageArea.setWrapStyleWord(true); |
| 110 |
0 |
messageArea.setBackground(panel.getBackground()); |
| 111 |
0 |
messageArea.setMinimumSize(new Dimension(10,10)); |
| 112 |
0 |
|
| 113 |
0 |
JScrollPane scroller = new JScrollPane(new ScrollableEditorPanel(contextPane)); |
| 114 |
0 |
scroller.setPreferredSize(AttributeNode.EDITORPANE_SIZE); |
| 115 |
0 |
|
| 116 |
0 |
|
| 117 |
0 |
scroller.setRowHeaderView(new LineNumberMargin(contextPane)); |
| 118 |
0 |
|
| 119 |
0 |
DetailsPanel context = new DetailsPanel(new BorderLayout(), "context"); |
| 120 |
0 |
iconLabel = new JLabel(); |
| 121 |
0 |
iconLabel.setBorder(new EmptyBorder(2, 0, 5, 5)); |
| 122 |
0 |
iconLabel.setVerticalAlignment(JLabel.TOP); |
| 123 |
0 |
|
| 124 |
0 |
JPanel messagePanel = new JPanel(new BorderLayout()); |
| 125 |
0 |
messagePanel.setBorder(new EmptyBorder(0, 2, 5, 5)); |
| 126 |
0 |
messagePanel.add(messageArea, BorderLayout.CENTER); |
| 127 |
0 |
messagePanel.add(iconLabel, BorderLayout.WEST); |
| 128 |
0 |
context.add(messagePanel, BorderLayout.NORTH); |
| 129 |
|
|
| 130 |
0 |
context.add(scroller, BorderLayout.CENTER); |
| 131 |
0 |
|
| 132 |
0 |
DetailsPanel details = new DetailsPanel(new FormLayout(5, 5), "details"); |
| 133 |
0 |
|
| 134 |
0 |
srcField = new JTextField(); |
| 135 |
0 |
srcField.setEditable(false); |
| 136 |
0 |
details.add(new JLabel("URI:"), LABEL_CONSTRAINTS); |
| 137 |
0 |
details.add(srcField, FormLayout.RIGHT_FILL); |
| 138 |
0 |
|
| 139 |
0 |
classField = new JTextField(); |
| 140 |
0 |
classField.setEditable(false); |
| 141 |
0 |
details.add(new JLabel("Class:"), LABEL_CONSTRAINTS); |
| 142 |
0 |
details.add(classField, FormLayout.RIGHT_FILL); |
| 143 |
0 |
|
| 144 |
0 |
details.add(Box.createVerticalStrut(10), FormLayout.FULL); |
| 145 |
0 |
|
| 146 |
0 |
messageField = new JTextArea(); |
| 147 |
0 |
messageField.setEditable(false); |
| 148 |
0 |
messageField.setLineWrap(true); |
| 149 |
0 |
messageField.setWrapStyleWord(true); |
| 150 |
0 |
details.add(new JLabel("Message:"), LABEL_CONSTRAINTS); |
| 151 |
0 |
|
| 152 |
0 |
panel = new JPanel(new BorderLayout()); |
| 153 |
0 |
panel.add(messageField, BorderLayout.CENTER); |
| 154 |
|
|
| 155 |
0 |
scroller = new JScrollPane( panel); |
| 156 |
0 |
scroller.setPreferredSize(EDITORPANE_SIZE); |
| 157 |
0 |
details.add(scroller, FormLayout.RIGHT_FILL); |
| 158 |
0 |
|
| 159 |
0 |
localizedMessageField = new JTextArea(); |
| 160 |
0 |
localizedMessageField.setEditable(false); |
| 161 |
0 |
localizedMessageField.setLineWrap(true); |
| 162 |
0 |
localizedMessageField.setWrapStyleWord(true); |
| 163 |
0 |
details.add(new JLabel("Localized:"), LABEL_CONSTRAINTS); |
| 164 |
0 |
|
| 165 |
0 |
panel = new JPanel(new BorderLayout()); |
| 166 |
0 |
panel.add(localizedMessageField, BorderLayout.CENTER); |
| 167 |
|
|
| 168 |
0 |
scroller = new JScrollPane( panel); |
| 169 |
0 |
scroller.setPreferredSize(EDITORPANE_SIZE); |
| 170 |
0 |
details.add(scroller, FormLayout.RIGHT_FILL); |
| 171 |
0 |
|
| 172 |
0 |
details.add(Box.createVerticalStrut(10), FormLayout.FULL); |
| 173 |
0 |
|
| 174 |
0 |
lineNumberField = new JTextField(); |
| 175 |
0 |
lineNumberField.setEditable(false); |
| 176 |
0 |
details.add(new JLabel("Line:"), LABEL_CONSTRAINTS); |
| 177 |
0 |
details.add(lineNumberField, FormLayout.RIGHT_FILL); |
| 178 |
0 |
|
| 179 |
0 |
columnNumberField = new JTextField(); |
| 180 |
0 |
columnNumberField.setEditable(false); |
| 181 |
0 |
details.add(new JLabel("Column:"), LABEL_CONSTRAINTS); |
| 182 |
0 |
details.add(columnNumberField, FormLayout.RIGHT_FILL); |
| 183 |
0 |
|
| 184 |
0 |
details.add(Box.createVerticalStrut(10), FormLayout.FULL); |
| 185 |
0 |
|
| 186 |
0 |
systemIdField = new JTextField(); |
| 187 |
0 |
systemIdField.setEditable(false); |
| 188 |
0 |
details.add(new JLabel("SystemId:"), LABEL_CONSTRAINTS); |
| 189 |
0 |
details.add(systemIdField, FormLayout.RIGHT_FILL); |
| 190 |
0 |
|
| 191 |
0 |
publicIdField = new JTextField(); |
| 192 |
0 |
publicIdField.setEditable(false); |
| 193 |
0 |
details.add(new JLabel("PublicId:"), LABEL_CONSTRAINTS); |
| 194 |
0 |
details.add(publicIdField, FormLayout.RIGHT_FILL); |
| 195 |
0 |
|
| 196 |
0 |
details.add(Box.createVerticalStrut(10), FormLayout.FULL); |
| 197 |
0 |
|
| 198 |
0 |
addTab("Context", context); |
| 199 |
0 |
addTab("Details", details); |
| 200 |
0 |
|
| 201 |
0 |
JButton editButton = new JButton("Edit"); |
| 202 |
0 |
editButton.setIcon(EDIT_ICON); |
| 203 |
0 |
editButton.addActionListener( new ActionListener() { |
| 204 |
0 |
public void actionPerformed( ActionEvent e) { |
| 205 |
0 |
edit(); |
| 206 |
0 |
} |
| 207 |
0 |
}); |
| 208 |
|
|
| 209 |
0 |
addLeftButton(editButton); |
| 210 |
0 |
|
| 211 |
0 |
pack(); |
| 212 |
|
|
| 213 |
0 |
setSize(new Dimension(500, getSize().height)); |
| 214 |
0 |
setLocationRelativeTo(parent); |
| 215 |
0 |
} |
| 216 |
|
|
| 217 |
|
private void edit() { |
| 218 |
0 |
ExternalApplicationLauncher.getInstance().edit(uri, line, column); |
| 219 |
0 |
} |
| 220 |
0 |
|
| 221 |
0 |
public void setException(Exception exception, URI baseURI, ImageIcon icon) { |
| 222 |
0 |
setTitle(exception.getClazz()+" - " + title); |
| 223 |
0 |
|
| 224 |
0 |
srcField.setText(exception.getSrc()); |
| 225 |
0 |
srcField.setCaretPosition(0); |
| 226 |
0 |
classField.setText(exception.getClazz()); |
| 227 |
0 |
classField.setCaretPosition(0); |
| 228 |
0 |
|
| 229 |
0 |
systemIdField.setText( exception.getSystemId()); |
| 230 |
0 |
systemIdField.setCaretPosition(0); |
| 231 |
0 |
publicIdField.setText( exception.getPublicId()); |
| 232 |
0 |
publicIdField.setCaretPosition(0); |
| 233 |
0 |
|
| 234 |
0 |
columnNumberField.setText( ""+exception.getColumn()); |
| 235 |
0 |
columnNumberField.setCaretPosition(0); |
| 236 |
0 |
lineNumberField.setText( ""+exception.getLine()); |
| 237 |
0 |
lineNumberField.setCaretPosition(0); |
| 238 |
0 |
|
| 239 |
0 |
messageField.setText( exception.getMessage()); |
| 240 |
0 |
messageField.setCaretPosition(0); |
| 241 |
0 |
|
| 242 |
0 |
localizedMessageField.setText( exception.getLocalizedMessage()); |
| 243 |
0 |
localizedMessageField.setCaretPosition(0); |
| 244 |
0 |
|
| 245 |
0 |
messageArea.setText( exception.getMessage()); |
| 246 |
0 |
messageArea.setCaretPosition(0); |
| 247 |
0 |
|
| 248 |
0 |
iconLabel.setIcon(icon); |
| 249 |
|
|
| 250 |
0 |
try { |
| 251 |
0 |
line = exception.getLine(); |
| 252 |
0 |
column = exception.getColumn(); |
| 253 |
0 |
|
| 254 |
0 |
uri = baseURI; |
| 255 |
|
|
| 256 |
0 |
if (exception.getSystemId() != null) { |
| 257 |
0 |
uri = URIUtils.createURI(exception.getSystemId()); |
| 258 |
|
} |
| 259 |
|
|
| 260 |
0 |
BufferedReader reader = null; |
| 261 |
0 |
String line = null; |
| 262 |
0 |
|
| 263 |
0 |
try { |
| 264 |
0 |
reader = new BufferedReader(new XmlReader(uri.toURL())); |
| 265 |
0 |
line = reader.readLine(); |
| 266 |
0 |
} catch (java.lang.Exception ex) { |
| 267 |
0 |
ex.printStackTrace(); |
| 268 |
|
|
| 269 |
0 |
reader = new BufferedReader(new InputStreamReader(uri.toURL().openStream(), "UTF-8")); |
| 270 |
0 |
line = reader.readLine(); |
| 271 |
0 |
} |
| 272 |
|
|
| 273 |
0 |
StringBuilder builder = new StringBuilder(); |
| 274 |
0 |
int index = 1; |
| 275 |
0 |
int position = -1; |
| 276 |
|
|
| 277 |
0 |
while (line != null) { |
| 278 |
0 |
if (exception.getLine() == index) { |
| 279 |
0 |
if (line.length() > MAX_NO_CHARACTERS) { |
| 280 |
0 |
|
| 281 |
0 |
builder = new StringBuilder(line.substring(Math.max(1, exception.getColumn()-(MAX_NO_CHARACTERS/2)), Math.min(line.length(), exception.getColumn()+(MAX_NO_CHARACTERS/2)))); |
| 282 |
0 |
|
| 283 |
0 |
if (exception.getColumn() > (MAX_NO_CHARACTERS/2)) { |
| 284 |
0 |
position = (MAX_NO_CHARACTERS/2); |
| 285 |
0 |
} else { |
| 286 |
0 |
position = exception.getColumn(); |
| 287 |
0 |
} |
| 288 |
0 |
break; |
| 289 |
|
} |
| 290 |
0 |
|
| 291 |
0 |
position = builder.length()+exception.getColumn(); |
| 292 |
0 |
} |
| 293 |
|
|
| 294 |
0 |
if (index >= Math.max(1, exception.getLine()-(MAX_NO_LINES/2))) { |
| 295 |
0 |
builder.append(line); |
| 296 |
0 |
builder.append("\n"); |
| 297 |
|
} |
| 298 |
|
|
| 299 |
0 |
if (index > Math.max((MAX_NO_LINES/2), exception.getLine()+(MAX_NO_LINES/2))) { |
| 300 |
0 |
break; |
| 301 |
0 |
} |
| 302 |
|
|
| 303 |
0 |
line = reader.readLine(); |
| 304 |
0 |
index++; |
| 305 |
0 |
} |
| 306 |
|
|
| 307 |
0 |
reader.close(); |
| 308 |
0 |
|
| 309 |
0 |
contextPane.setText(builder.toString()); |
| 310 |
|
try { |
| 311 |
0 |
if (position > 0) { |
| 312 |
0 |
contextPane.getHighlighter().addHighlight(position-2, position-1, new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 200, 200))); |
| 313 |
0 |
contextPane.getHighlighter().addHighlight(builder.lastIndexOf("<", position-2), position-2, new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 225, 225))); |
| 314 |
0 |
} |
| 315 |
0 |
} catch (BadLocationException e) { |
| 316 |
0 |
Logger.getLogger(getClass()).debug(e); |
| 317 |
0 |
} |
| 318 |
0 |
contextPane.setCaretPosition(Math.max(0, position-1)); |
| 319 |
0 |
|
| 320 |
0 |
} catch (MalformedURLException e) { |
| 321 |
0 |
Logger.getLogger(getClass()).debug(e); |
| 322 |
0 |
} catch (IOException e) { |
| 323 |
0 |
e.printStackTrace(); |
| 324 |
0 |
Logger.getLogger(getClass()).debug(e); |
| 325 |
0 |
} |
| 326 |
0 |
} |
| 327 |
|
|
| 328 |
|
@Override |
| 329 |
|
protected String getBaseHelpID() { |
| 330 |
0 |
return "output.result.error"; |
| 331 |
|
} |
| 332 |
|
} |