001: package tools.tracesviewer;
002:
003: import java.awt.*;
004:
005: public class StraightArrow extends Arrow {
006:
007: public Dimension dimensionInfo;
008:
009: public StraightArrow(boolean selected, String arrowName, int xmin,
010: int xmax, int ymin, int ymax, boolean flag, boolean info) {
011: super (selected, arrowName, flag, xmin, xmax, ymin, ymax, info);
012:
013: }
014:
015: public int xmin() {
016: return Math.min(xmin, xmax);
017: }
018:
019: public int xmax() {
020: return Math.max(xmin, xmax);
021: }
022:
023: public int ymin() {
024: return Math.min(ymin, ymax);
025: }
026:
027: public int ymax() {
028: return Math.max(ymin, ymax);
029: }
030:
031: public void draw(Graphics g) {
032: // Set the color of this arrow:
033: if (selected)
034: g.setColor(Color.red);
035: else
036: g.setColor(color);
037:
038: Font font = g.getFont();
039: Font newFont = new Font(font.getName(),
040: Font.BOLD | Font.ITALIC, 14);
041: g.setFont(newFont);
042:
043: int y = (ymin + ymax) / 2;
044: if (tracesMessage.getStatusInfo() != null)
045: if (tracesMessage.getStatusInfo().indexOf("Dropped") == -1) {
046: g.drawLine(xmin, y, xmax, y);
047: g.drawLine(Math.min(xmin, xmax) + 2, y - 1, Math.max(
048: xmin, xmax) - 2, y - 1);
049: g.drawLine(Math.min(xmin, xmax) + 2, y + 1, Math.max(
050: xmin, xmax) - 2, y + 1);
051:
052: } else {
053:
054: if (xmin < xmax) {
055: int x = xmin;
056: while ((x + 8) < xmax) {
057: g.drawLine(x, y, x + 8, y);
058: g.drawLine(x, y - 1, x + 8, y - 1);
059: g.drawLine(x, y + 1, x + 8, y + 1);
060: x += 16;
061: }
062:
063: } else {
064: int x = xmin;
065: while ((x - 8) > xmax) {
066: g.drawLine(x, y, x - 8, y);
067: g.drawLine(x, y - 1, x - 8, y - 1);
068: g.drawLine(x, y + 1, x - 8, y + 1);
069: x -= 16;
070: }
071:
072: }
073:
074: }
075: else {
076: g.drawLine(xmin, y, xmax, y);
077: g.drawLine(Math.min(xmin, xmax) + 2, y - 1, Math.max(xmin,
078: xmax) - 2, y - 1);
079: g.drawLine(Math.min(xmin, xmax) + 2, y + 1, Math.max(xmax,
080: xmax) - 2, y + 1);
081:
082: }
083:
084: String timeString = "Time : " + tracesMessage.getTime() + " ms";
085:
086: int timeStringWidth = g.getFontMetrics(g.getFont())
087: .stringWidth(timeString);
088: int fistLineStringWidth = g.getFontMetrics(g.getFont())
089: .stringWidth(tracesMessage.getFirstLine());
090:
091: if (xmax > xmin) {
092: g.drawString(tracesMessage.getFirstLine(), xmin
093: + tracesCanvas.HORIZONTAL_GAP / 2
094: - fistLineStringWidth / 2, y - 5);
095:
096: g.drawString(timeString, xmin + tracesCanvas.HORIZONTAL_GAP
097: / 2 - timeStringWidth / 2, y
098: + g.getFontMetrics(g.getFont()).getHeight());
099:
100: g.drawLine(xmax, y, xmax - 10, y - 5);
101: g.drawLine(xmax - 1, y, xmax - 11, y - 5);
102: g.drawLine(xmax - 2, y, xmax - 12, y - 5);
103: g.drawLine(xmax, y, xmax - 10, y + 5);
104: g.drawLine(xmax - 1, y, xmax - 11, y + 5);
105: g.drawLine(xmax - 2, y, xmax - 12, y + 5);
106:
107: } else {
108: g.drawString(tracesMessage.getFirstLine(), xmax
109: + tracesCanvas.HORIZONTAL_GAP / 2
110: - fistLineStringWidth / 2, y - 2);
111:
112: g.drawString(timeString, xmax + tracesCanvas.HORIZONTAL_GAP
113: / 2 - timeStringWidth / 2, y + 2
114: + g.getFontMetrics(g.getFont()).getHeight());
115:
116: g.drawLine(xmax, y, xmax + 10, y + 5);
117: g.drawLine(xmax + 1, y, xmax + 11, y + 5);
118: g.drawLine(xmax + 2, y, xmax + 12, y + 5);
119: g.drawLine(xmax, y, xmax + 10, y - 5);
120: g.drawLine(xmax + 1, y, xmax + 11, y - 5);
121: g.drawLine(xmax + 2, y, xmax + 12, y - 5);
122: } // else
123:
124: // draw the info sign if needed
125: if (statusInfo) {
126: //System.out.println("Display info sign ready");
127: String statusString = tracesMessage.getStatusInfo();
128: if (statusString == null || statusString.trim().equals("")) {
129: // System.out.println("No information: problem for displaying the info sign");
130: } else {
131: //g.setColor(new Color(0,0,125)) ;
132: g.setColor(Color.yellow);
133: //g.fillOval(xmax() - 20 , y - 20 , 15, 15) ;
134: xminInfo = xmax() - 25;
135: xmaxInfo = xmax();
136: yminInfo = y - 30;
137: ymaxInfo = y - 3;
138: //x, y, width, height
139: g.fillOval(xmax() - 25, y - 25, 20, 20);
140: //g.setColor(Color.black) ;
141: //g.drawOval(xmax() - 20 , y - 20 , 15, 15) ;
142: g.setColor(Color.black);
143: Font f = g.getFont();
144: g.setFont(new Font(f.getName(),
145: Font.BOLD | Font.ITALIC, f.getSize()));
146: g.drawString("i", xmax() - 17, y - 11);
147: g.setFont(f);
148: }
149: }
150: if (displayInfo) {
151: //System.out.println("Display info ready");
152: String statusString = tracesMessage.getStatusInfo();
153: if (statusString == null || statusString.trim().equals("")) {
154: // System.out.println("No information: problem for displaying info");
155: } else {
156: Font f = g.getFont();
157: g.setFont(new Font(f.getName(),
158: Font.BOLD | Font.ITALIC, f.getSize()));
159:
160: int statusStringWidth = g.getFontMetrics(g.getFont())
161: .stringWidth(statusString);
162: int statusStringHeight = g.getFontMetrics(g.getFont())
163: .getHeight();
164:
165: int boxWidth = Math.max(tracesCanvas.HORIZONTAL_GAP,
166: statusStringWidth + 10);
167:
168: // shadow
169: g.setColor(Color.gray);
170: g.fillRoundRect(xmin() + 15, y
171: - TracesCanvas.VERTICAL_GAP / 2 + 15, boxWidth,
172: TracesCanvas.VERTICAL_GAP, 10, 10);
173: // box
174: g.setColor(Color.yellow);
175: g.fillRoundRect(xmin() + 10, y
176: - TracesCanvas.VERTICAL_GAP / 2 + 10, boxWidth,
177: TracesCanvas.VERTICAL_GAP, 10, 10);
178:
179: // thick border
180: g.setColor(Color.black);
181: g.drawRoundRect(xmin() + 10, y
182: - TracesCanvas.VERTICAL_GAP / 2 + 10, boxWidth,
183: TracesCanvas.VERTICAL_GAP, 10, 10);
184: g.drawRoundRect(xmin() + 11, y
185: - TracesCanvas.VERTICAL_GAP / 2 + 11,
186: boxWidth - 2, TracesCanvas.VERTICAL_GAP, 9, 9);
187:
188: // info string
189: g.setColor(Color.black);
190:
191: if (boxWidth == tracesCanvas.HORIZONTAL_GAP)
192: g.drawString(statusString, xmin() + 10 + 2
193: + tracesCanvas.HORIZONTAL_GAP / 2
194: - statusStringWidth / 2, y + 10
195: + statusStringHeight / 2);
196:
197: else
198: g.drawString(statusString, xmin() + 10 + 5, y + 10
199: + statusStringHeight / 2);
200: }
201: }
202: if (displayTipTool) {
203: //System.out.println("Display Tip tool ready");
204:
205: Font f = g.getFont();
206: g.setFont(new Font(f.getName(), Font.BOLD | Font.ITALIC, f
207: .getSize() - 2));
208:
209: String text;
210: if (statusInfo)
211: text = "Left click to select the message, Right click to display generated event.";
212: else
213: text = "Left click to select the message";
214:
215: int textWidth = g.getFontMetrics(g.getFont()).stringWidth(
216: text);
217: int textHeight = g.getFontMetrics(g.getFont()).getHeight();
218:
219: if (xmin < xmax) {
220: // x,y,width,height
221:
222: // shadow
223: g.setColor(Color.gray);
224: g.fillRoundRect(xmin() - 47, y + 21, textWidth + 5,
225: textHeight + 2, 10, 10);
226: // box
227: g.setColor(Color.yellow);
228: g.fillRoundRect(xmin() - 50, y + 21, textWidth + 4,
229: textHeight - 2, 10, 10);
230:
231: // thick border
232: g.setColor(Color.black);
233: g.drawRoundRect(xmin() - 50, y + 21, textWidth + 5,
234: textHeight - 3, 10, 10);
235: g.drawRoundRect(xmin() - 50, y + 21, textWidth + 5,
236: textHeight - 3, 9, 9);
237:
238: // String, x,y
239: g.setColor(Color.black);
240: g.drawString(text, xmin - 46, y + 16 + textHeight);
241: } else {
242: // shadow
243: g.setColor(Color.gray);
244: g.fillRoundRect(xmin() - 47, y + 21, textWidth + 5,
245: textHeight + 2, 10, 10);
246: // box
247: g.setColor(Color.yellow);
248: g.fillRoundRect(xmin() - 50, y + 21, textWidth + 4,
249: textHeight - 2, 10, 10);
250:
251: // thick border
252: g.setColor(Color.black);
253: g.drawRoundRect(xmin() - 50, y + 21, textWidth + 5,
254: textHeight - 3, 10, 10);
255: g.drawRoundRect(xmin() - 50, y + 21, textWidth + 5,
256: textHeight - 3, 9, 9);
257:
258: // String, x,y
259: g.setColor(Color.black);
260: g.drawString(text, xmin() - 46, y + 16 + textHeight);
261: }
262: }
263: }
264:
265: }
|