1 package debugger.gui.debugging.debugviews;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.MouseAdapter;
6 import java.awt.event.MouseEvent;
7 import java.util.ArrayList;
8
9
15
16 public class PrimaryTextPanel extends JPanel {
17 public static final int OPEN_NONE = 0;
18 public static final int OPEN_LEFT = 1;
19 public static final int OPEN_RIGHT = 2;
20 public static final int OPEN_BOTH = 3;
21
22 private boolean isHighlighted = false;
23 private boolean red = false;
24 private String text = "";
25 private Font font = new Font("Arial", Font.PLAIN, 11);
26 private int openMode = OPEN_NONE;
27 private ArrayList annotations = null;
28 private InfoWindow infoWindow = null;
29
30 public boolean isRed() {
31 return red;
32 }
33
34 public void setRed(boolean red) {
35 this.red = red;
36 }
37
38 public boolean isTextVisible() {
39 return textVisible;
40 }
41
42 public void setTextVisible(boolean textVisible) {
43 this.textVisible = textVisible;
44 }
45
46 private boolean textVisible = true;
47
48 public PrimaryTextPanel(String text, boolean isHighlighted, int openMode) {
49 this.text = text;
50 this.isHighlighted = isHighlighted;
51 this.openMode = openMode;
52 this.addMouseListener(new MouseAdapter() {
53 public void mouseClicked(MouseEvent e) {
54 if (infoWindow == null) {
55 infoWindow = new InfoWindow(PrimaryTextPanel.this, null);
56 int x = PrimaryTextPanel.this.getLocationOnScreen().x;
57 int y = PrimaryTextPanel.this.getLocationOnScreen().y;
58 Dimension size = PrimaryTextPanel.this.getSize();
59 if (x + infoWindow.getSize().width < Toolkit.getDefaultToolkit().getScreenSize().width)
60 infoWindow.setLocation(x, y + (int) size.getHeight());
61 else
62 infoWindow.setLocation(x + size.width - infoWindow.getSize().width, y + (int) size.getHeight());
63 infoWindow.setVisible(true);
64 } else if (!infoWindow.isVisible()) {
65 int x = PrimaryTextPanel.this.getLocationOnScreen().x;
66 int y = PrimaryTextPanel.this.getLocationOnScreen().y;
67 Dimension size = PrimaryTextPanel.this.getSize();
68 if (x + infoWindow.getSize().width < Toolkit.getDefaultToolkit().getScreenSize().width)
69 infoWindow.setLocation(x, y + (int) size.getHeight());
70 else
71 infoWindow.setLocation(x + size.width - infoWindow.getSize().width, y + (int) size.getHeight());
72 infoWindow.setVisible(true);
73 }
74 }
75 });
76 }
77
78 public ArrayList getAnnotations() {
79 return annotations;
80 }
81
82 public void setAnnotations(ArrayList annotations) {
83 this.annotations = annotations;
84 }
85
86 public void setOpenMode(int openMode) {
87 this.openMode = openMode;
88 }
89
90 public int getOpenMode() {
91 return openMode;
92 }
93
94 public boolean isHighlighted() {
95 return isHighlighted;
96 }
97
98 public void setHighlighted(boolean highlighted) {
99 isHighlighted = highlighted;
100 }
101
102 public String getText() {
103 return text;
104 }
105
106 public void setText(String text) {
107 this.text = text;
108 }
109
110 public void paint(Graphics g) {
111 int width = this.getSize().width;
112 int height = this.getSize().height;
113 if (!isHighlighted) {
114 if (textVisible)
115 g.setColor(Color.gray);
116 else
117 g.setColor(new Color(200, 200, 200));
118 g.fillRect(0, 0, width - 1, height - 1);
119 g.setColor(new Color(200, 200, 200));
120 if (openMode == OPEN_NONE)
121 g.fillRect(1, 1, width - 3, height - 3);
122 else if (openMode == OPEN_RIGHT)
123 g.fillRect(1, 1, width - 1, height - 3);
124 else if (openMode == OPEN_LEFT)
125 g.fillRect(0, 1, width - 2, height - 3);
126 else if (openMode == OPEN_BOTH) g.fillRect(0, 1, width, height - 3);
127 } else if (!red) {
128 g.setColor(new Color(51, 204, 51));
129 g.fillRect(0, 0, width - 1, height - 1);
130 if (openMode == OPEN_NONE)
132 g.fillRect(1, 1, width - 3, height - 3);
133 else if (openMode == OPEN_RIGHT)
134 g.fillRect(1, 1, width - 1, height - 3);
135 else if (openMode == OPEN_LEFT)
136 g.fillRect(0, 1, width - 2, height - 3);
137 else if (openMode == OPEN_BOTH) g.fillRect(0, 1, width, height - 3);
138 }
139 if (!isHighlighted && red) {
140 g.setColor(new Color(204, 51, 51));
141 g.fillRect(0, 0, width - 1, height - 1);
142 g.setColor(new Color(220, 220, 220));
143 if (openMode == OPEN_NONE)
144 g.fillRect(1, 1, width - 3, height - 3);
145 else if (openMode == OPEN_RIGHT)
146 g.fillRect(1, 1, width - 1, height - 3);
147 else if (openMode == OPEN_LEFT)
148 g.fillRect(0, 1, width - 2, height - 3);
149 else if (openMode == OPEN_BOTH) g.fillRect(0, 1, width, height - 3);
150 }
151 if (textVisible)
152 g.setColor(Color.black);
153 g.setFont(font);
154 g.drawString(text, 3, height - 6);
155 }
156
157 public Dimension getSize() {
158 FontMetrics fontMetrics = getFontMetrics(font);
159 int width = fontMetrics.stringWidth(text);
160 int height = fontMetrics.getAscent();
161 return new Dimension(width + 6, height + 6);
162 }
163
164 public Dimension getPreferredSize() {
165 return getSize();
166 }
167
168 public Dimension getMinimumSize() {
169 return getSize();
170 }
171
172 public Dimension getMaximumSize() {
173 return getSize();
174 }
175 }