MCPcopy
hub / github.com/arduino/Arduino / initialize

Method initialize

app/src/processing/app/EditorStatus.java:241–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

239 }
240
241 private void initialize() {
242 cancelButton = new JButton(I18n.PROMPT_CANCEL);
243 okButton = new JButton(I18n.PROMPT_OK);
244
245 cancelButton.addActionListener(e -> {
246 if (mode == EDIT) {
247 unedit();
248 }
249 });
250
251 okButton.addActionListener(e -> {
252 // answering to rename/new code question
253 if (mode == EDIT) { // this if() isn't (shouldn't be?) necessary
254 String answer = editField.getText();
255 editor.getSketchController().nameCode(answer);
256 unedit();
257 }
258 });
259
260 if (OSUtils.isMacOS()) {
261 cancelButton.setBackground(BGCOLOR[EDIT]);
262 okButton.setBackground(BGCOLOR[EDIT]);
263 }
264 setLayout(null);
265
266 add(cancelButton);
267 add(okButton);
268
269 cancelButton.setVisible(false);
270 okButton.setVisible(false);
271
272 editField = new JTextField();
273
274 editField.addKeyListener(new KeyAdapter() {
275
276 // Grab ESC with keyPressed, because it's not making it to keyTyped
277 public void keyPressed(KeyEvent event) {
278 if (event.getKeyChar() == KeyEvent.VK_ESCAPE) {
279 unedit();
280 event.consume();
281 }
282 }
283
284 // use keyTyped to catch when the feller is actually
285 // added to the text field. with keyTyped, as opposed to
286 // keyPressed, the keyCode will be zero, even if it's
287 // enter or backspace or whatever, so the keychar should
288 // be used instead. grr.
289 public void keyTyped(KeyEvent event) {
290 int c = event.getKeyChar();
291
292 if (c == KeyEvent.VK_ENTER) { // accept the input
293 String answer = editField.getText();
294 editor.getSketchController().nameCode(answer);
295 unedit();
296 event.consume();
297
298 // easier to test the affirmative case than the negative

Callers 1

EditorStatusMethod · 0.95

Calls 13

uneditMethod · 0.95
isMacOSMethod · 0.95
getBoardPreferencesMethod · 0.95
getBooleanMethod · 0.95
nameCodeMethod · 0.80
getSketchControllerMethod · 0.80
setVisibleMethod · 0.80
addKeyListenerMethod · 0.80
setValueMethod · 0.80
trMethod · 0.80
getTextMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected