1 /*
2 * PlbAsset.java
3 * :tabSize=2:indentSize=2:noTabs=true:
4 * :folding=explicit:collapseFolds=0:
5 */
6
7 package net.sf.plb4jedit.plb;
8
9 //{{{ Imports
10 import javax.swing.Icon;
11 import javax.swing.ImageIcon;
12 import javax.swing.text.Position;
13
14 import org.gjt.sp.jedit.Buffer;
15 import org.gjt.sp.jedit.jEdit;
16
17 import sidekick.Asset;
18 /***
19 * represents a single node in the structure browser tree for plb
20 *
21 * @author Peter Schaefer
22 */
23 //}}}
24
25 public class PlbAsset extends Asset {
26 public static final ImageIcon FORM_ICON =
27 new ImageIcon(PlbAsset.class.getResource("/img/form.gif"));
28 public static final ImageIcon INCLUDE_ICON =
29 new ImageIcon(PlbAsset.class.getResource("/img/include.gif"));
30 public static final ImageIcon ROUTINE_ICON =
31 new ImageIcon(PlbAsset.class.getResource("/img/routine.gif"));
32 public static final ImageIcon DIM_ICON =
33 new ImageIcon(PlbAsset.class.getResource("/img/dim.gif"));
34 public static final ImageIcon VARDEF_ICON =
35 new ImageIcon(PlbAsset.class.getResource("/img/vardef.png"));
36 public static final ImageIcon LABEL_ICON =
37 new ImageIcon(PlbAsset.class.getResource("/img/label.png"));
38 public static final ImageIcon UNKNOWN_ICON =
39 new ImageIcon(PlbAsset.class.getResource("/img/unknown.png"));
40 public static final ImageIcon START_ICON =
41 new ImageIcon(PlbAsset.class.getResource("/img/start.png"));
42
43 //{{{ Instance variables
44 private String longString;
45 private String shortString;
46 private SourceLine line;
47 //}}}
48
49 public PlbAsset(String name, int startLine, int endLine) {
50 super(name);
51 Buffer buffer = jEdit.getActiveView().getBuffer();
52 this.start =
53 buffer.createPosition(buffer.getLineStartOffset(startLine - 1));
54 this.end =
55 buffer.createPosition(buffer.getLineEndOffset(endLine - 1) - 1);
56 shortString = longString = name;
57 }
58
59 //{{{ PlbAsset constructor
60 public PlbAsset(SourceLine line) {
61 super(line.getLabel());
62 this.line = line;
63 this.longString = line.getLineNumber() + ": " + line.getLine();
64 if (line.isInclude()) {
65 if (line.getLabel().equals("start")) {
66 this.shortString = line.getLabel() + "/" + line.getRest();
67 } else {
68 this.shortString = line.getRest();
69 }
70 } else {
71 this.shortString = line.getLabel();
72 }
73 // calculation of position must be done after shortString is set!
74 this.start = calculateStartPos(line);
75 this.end = calculateEndPos(line);
76 //Log.log(Log.DEBUG,this,line.getLineNumber()+"/"+this.start.getOffset()+"/"+this.end.getOffset()+"/"+shortString);
77
78 } //}}}
79
80 public Icon getIcon() {
81 if (line == null) {
82 return UNKNOWN_ICON;
83 } else {
84 if (line.getLabel().equals("start"))
85 return START_ICON;
86 else if (line.isFormDef())
87 return FORM_ICON;
88 else if (line.isDimDef())
89 return DIM_ICON;
90 else if (line.isInclude())
91 return INCLUDE_ICON;
92 else if (line.isLroutine())
93 return ROUTINE_ICON;
94 else if (line.isLabel())
95 return LABEL_ICON;
96 else if (line.isVarDef())
97 return VARDEF_ICON;
98 else
99 return UNKNOWN_ICON;
100 }
101 }
102
103 //{{{ getLongString() method
104 public String getLongString() {
105 return longString;
106 } //}}}
107
108 //{{{ getShortString() method
109 public String getShortString() {
110 return shortString;
111 } //}}}
112
113 //{{{ toString() method
114 public String toString() {
115 return getLongString();
116 } //}}}
117
118 private Position calculateStartPos(SourceLine line) {
119 Buffer buffer = jEdit.getActiveView().getBuffer();
120 int lineno =
121 Math.min(buffer.getLineCount() - 1, line.getLineNumber() - 1);
122 int column = Math.max(1, line.getLine().indexOf(getShortString()) + 1);
123 int offset =
124 Math.min(
125 buffer.getLength(),
126 buffer.getLineStartOffset(lineno) + column);
127 return buffer.createPosition(offset);
128 }
129
130 private Position calculateEndPos(SourceLine line) {
131 Buffer buffer = jEdit.getActiveView().getBuffer();
132 int lineno =
133 Math.min(buffer.getLineCount() - 1, line.getLineNumber() - 1);
134 int column = Math.max(1, line.getLine().length() + 1);
135 int offset =
136 Math.min(
137 buffer.getLength(),
138 buffer.getLineStartOffset(lineno) + column);
139 return buffer.createPosition(offset);
140 }
141
142 /* adapted to JaneUtils.java
143 private Position calculateEndPos(SourceLine line) {
144 Buffer buffer = jEdit.getActiveView().getBuffer();
145 if ((line.getLineNumber() - 1) > buffer.getLineCount()) {
146 return buffer.createPosition(buffer.getLength() - 1);
147 }
148 int offset = buffer.getLineStartOffset(line.getLineNumber() - 1);
149 if (offset >= buffer.getLength()) {
150 return buffer.createPosition(buffer.getLength() - 1);
151 }
152 return buffer.createPosition(offset);
153 }
154 */
155
156 }
This page was automatically generated by Maven