1 package debugger.gui.actions.editor;
2
3 import debugger.gui.GuiFactory;
4 import debugger.gui.MainFrame;
5 import debugger.gui.actions.resources.LrResourceSelectedAction;
6 import debugger.resources.ResourcesFactory;
7 import gate.Document;
8 import gate.LanguageResource;
9 import gate.corpora.DocumentImpl;
10 import gate.util.InvalidOffsetException;
11
12 import javax.swing.*;
13
14
20
21 public class ShowResultAction {
22 private static ShowResultAction ourInstance;
23
24 public synchronized static ShowResultAction getInstance() {
25 if (ourInstance == null) {
26 ourInstance = new ShowResultAction();
27 }
28 return ourInstance;
29 }
30
31 private ShowResultAction() {
32 }
33
34 public void actionPerformed(int startOffset, int endOffset) {
35 LanguageResource lr = ResourcesFactory.getCurrentLrModel().getLr();
36 if (lr instanceof Document) {
37 if(!ResourcesFactory.getCurrentLrModel().getStoredContent().equals(((Document)lr).getContent().toString())) {
39 JOptionPane.showMessageDialog(
40 JOptionPane.getRootFrame(),
41 "Document content changed.\n" +
42 "Synchronization of rule matching history with\n" +
43 "changing document content not supported.\n" +
44 "You should rerun pipeline again.",
45 "Warning!",
46 JOptionPane.PLAIN_MESSAGE);
47 ResourcesFactory.getCurrentLrModel().synchronize();
48 LrResourceSelectedAction.getInstance().actionPerformed(ResourcesFactory.getCurrentLrModel());
49 return;
50 }
51
52 int startSelection = startOffset + getSlashNAmount(startOffset, (DocumentImpl) lr);
53 int endSelection = endOffset + getSlashNAmount(endOffset, (DocumentImpl) lr);
54 GuiFactory.getDebugPanel().getTraceHistoryPanel().setText(startSelection, endSelection, (Document) lr);
55 GuiFactory.getResourceView().getResourceTreeCellRenderer().setIndexes(startSelection, endSelection);
56 GuiFactory.getResourceView().repaint();
57 GuiFactory.getResourceView().repaint(); }
64 }
65
66 private int getSlashNAmount(int offset, DocumentImpl document) {
67 int result = 0;
68 try {
69 String temp = document.getContent().getContent(new Long(0), new Long(offset)).toString();
70
71 char[] charArray = temp.toCharArray();
72 for (int i = 0; i < charArray.length; i++) {
73 char c = charArray[i];
74 if (c == '\n') result++;
75 }
76 } catch (Exception e) {
87 e.printStackTrace();
88 }
89 return result;
90 }
91 }
92
93