1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
import jalview.util.Platform; |
59 |
|
|
60 |
|
import java.awt.Color; |
61 |
|
import java.awt.Dimension; |
62 |
|
import java.awt.GridLayout; |
63 |
|
import java.awt.event.ActionEvent; |
64 |
|
import java.awt.event.MouseEvent; |
65 |
|
import java.awt.event.MouseListener; |
66 |
|
|
67 |
|
import javax.swing.AbstractAction; |
68 |
|
import javax.swing.BorderFactory; |
69 |
|
import javax.swing.InputMap; |
70 |
|
import javax.swing.JComponent; |
71 |
|
import javax.swing.JFrame; |
72 |
|
import javax.swing.JLabel; |
73 |
|
import javax.swing.JPanel; |
74 |
|
import javax.swing.JScrollPane; |
75 |
|
import javax.swing.JSplitPane; |
76 |
|
import javax.swing.JTextArea; |
77 |
|
import javax.swing.KeyStroke; |
78 |
|
import javax.swing.SwingUtilities; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@see |
84 |
|
|
85 |
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 14 |
Complexity Density: 0.3 |
|
86 |
|
public class MouseEventDemo extends JPanel implements MouseListener |
87 |
|
{ |
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.6 |
|
88 |
|
private class BlankArea extends JLabel |
89 |
|
{ |
90 |
|
Dimension minSize = new Dimension(200, 100); |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
92 |
0 |
public BlankArea(Color color)... |
93 |
|
{ |
94 |
0 |
setBackground(color); |
95 |
0 |
setOpaque(true); |
96 |
0 |
setBorder(BorderFactory.createLineBorder(Color.black)); |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0 |
@Override... |
100 |
|
public Dimension getMinimumSize() |
101 |
|
{ |
102 |
0 |
return minSize; |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0 |
@Override... |
106 |
|
public Dimension getPreferredSize() |
107 |
|
{ |
108 |
0 |
return minSize; |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
static int counter = 0; |
113 |
|
|
114 |
|
BlankArea blankArea; |
115 |
|
|
116 |
|
JTextArea textArea; |
117 |
|
|
118 |
|
static final String NEWLINE = System.getProperty("line.separator"); |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
0 |
public static void main(String[] args)... |
124 |
|
{ |
125 |
|
|
126 |
|
|
127 |
0 |
javax.swing.SwingUtilities.invokeLater(new Runnable() |
128 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
129 |
0 |
@Override... |
130 |
|
public void run() |
131 |
|
{ |
132 |
0 |
createAndShowGUI(); |
133 |
|
} |
134 |
|
}); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
141 |
0 |
private static void createAndShowGUI()... |
142 |
|
{ |
143 |
|
|
144 |
0 |
JFrame frame = new JFrame("MouseEventDemo (C to clear)"); |
145 |
0 |
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
146 |
|
|
147 |
|
|
148 |
0 |
JComponent newContentPane = new MouseEventDemo(); |
149 |
0 |
newContentPane.setOpaque(true); |
150 |
0 |
frame.setContentPane(newContentPane); |
151 |
|
|
152 |
|
|
153 |
0 |
frame.pack(); |
154 |
0 |
frame.setVisible(true); |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
157 |
0 |
public MouseEventDemo()... |
158 |
|
{ |
159 |
0 |
super(new GridLayout(0, 1)); |
160 |
|
|
161 |
0 |
textArea = new JTextArea(); |
162 |
0 |
textArea.setEditable(false); |
163 |
0 |
JScrollPane scrollPane = new JScrollPane(textArea); |
164 |
0 |
scrollPane.setVerticalScrollBarPolicy( |
165 |
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
166 |
0 |
scrollPane.setPreferredSize(new Dimension(400, 75)); |
167 |
|
|
168 |
0 |
blankArea = new BlankArea(Color.YELLOW); |
169 |
0 |
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, |
170 |
|
blankArea, scrollPane); |
171 |
0 |
splitPane.setVisible(true); |
172 |
0 |
splitPane.setDividerLocation(0.2d); |
173 |
0 |
splitPane.setResizeWeight(0.5d); |
174 |
0 |
add(splitPane); |
175 |
|
|
176 |
0 |
addKeyBinding(); |
177 |
|
|
178 |
0 |
blankArea.addMouseListener(this); |
179 |
0 |
addMouseListener(this); |
180 |
0 |
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
183 |
0 |
private void addKeyBinding()... |
184 |
|
{ |
185 |
0 |
addKeyBinding(KeyStroke.getKeyStroke('C')); |
186 |
0 |
addKeyBinding(KeyStroke.getKeyStroke('c')); |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
@param |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
192 |
0 |
void addKeyBinding(final KeyStroke ks)... |
193 |
|
{ |
194 |
0 |
InputMap inputMap = this.getInputMap(JComponent.WHEN_FOCUSED); |
195 |
0 |
inputMap.put(ks, ks); |
196 |
0 |
this.getActionMap().put(ks, new AbstractAction() |
197 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
198 |
0 |
@Override... |
199 |
|
public void actionPerformed(ActionEvent e) |
200 |
|
{ |
201 |
0 |
textArea.setText(""); |
202 |
0 |
log(""); |
203 |
|
} |
204 |
|
}); |
205 |
|
} |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
207 |
0 |
void logEvent(String eventDescription, MouseEvent e)... |
208 |
|
{ |
209 |
0 |
log("------- " + counter++ + ": " + eventDescription); |
210 |
0 |
log("e.isPopupTrigger: " + e.isPopupTrigger()); |
211 |
0 |
log("SwingUtilities.isRightMouseButton: " |
212 |
|
+ SwingUtilities.isRightMouseButton(e)); |
213 |
0 |
log("SwingUtilities.isLeftMouseButton: " |
214 |
|
+ SwingUtilities.isLeftMouseButton(e)); |
215 |
0 |
log("Platform.isControlDown: " + Platform.isControlDown(e)); |
216 |
0 |
log("e.isControlDown: " + e.isControlDown()); |
217 |
0 |
log("e.isAltDown: " + e.isAltDown()); |
218 |
0 |
log("e.isMetaDown: " + e.isMetaDown()); |
219 |
0 |
log("e.isShiftDown: " + e.isShiftDown()); |
220 |
0 |
log("e.getClickCount: " + e.getClickCount()); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
@param |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
226 |
0 |
void log(String msg)... |
227 |
|
{ |
228 |
0 |
textArea.append(msg + NEWLINE); |
229 |
0 |
textArea.setCaretPosition(textArea.getDocument().getLength()); |
230 |
|
} |
231 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
232 |
0 |
@Override... |
233 |
|
public void mousePressed(MouseEvent e) |
234 |
|
{ |
235 |
0 |
logEvent("Mouse pressed", e); |
236 |
|
} |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
238 |
0 |
@Override... |
239 |
|
public void mouseReleased(MouseEvent e) |
240 |
|
{ |
241 |
0 |
logEvent("Mouse released", e); |
242 |
|
} |
243 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
244 |
0 |
@Override... |
245 |
|
public void mouseEntered(MouseEvent e) |
246 |
|
{ |
247 |
|
} |
248 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
249 |
0 |
@Override... |
250 |
|
public void mouseExited(MouseEvent e) |
251 |
|
{ |
252 |
|
} |
253 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
254 |
0 |
@Override... |
255 |
|
public void mouseClicked(MouseEvent e) |
256 |
|
{ |
257 |
0 |
logEvent("Mouse clicked", e); |
258 |
|
} |
259 |
|
} |