~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to app/src/processing/app/Editor.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import processing.app.syntax.*;
27
27
import processing.app.tools.*;
28
28
import processing.core.*;
 
29
import static processing.app.I18n._;
29
30
 
30
31
import java.awt.*;
31
32
import java.awt.datatransfer.*;
46
47
/**
47
48
 * Main editor panel for the Processing Development Environment.
48
49
 */
 
50
@SuppressWarnings("serial")
49
51
public class Editor extends JFrame implements RunnerListener {
50
52
 
51
53
  Base base;
113
115
 
114
116
  EditorLineStatus lineStatus;
115
117
 
116
 
  JEditorPane editorPane;
 
118
  //JEditorPane editorPane;
117
119
  
118
120
  JEditTextArea textarea;
119
121
  EditorListener listener;
195
197
    //PdeKeywords keywords = new PdeKeywords();
196
198
    //sketchbook = new Sketchbook(this);
197
199
 
198
 
    if (serialMonitor == null)
 
200
    if (serialMonitor == null) {
199
201
      serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
 
202
      serialMonitor.setIconImage(getIconImage());
 
203
    }
200
204
    
201
205
    buildMenuBar();
202
206
 
260
264
      splitPane.setDividerSize(dividerSize);
261
265
    }
262
266
 
263
 
    splitPane.setMinimumSize(new Dimension(600, 400));
 
267
    // the following changed from 600, 400 for netbooks
 
268
    // http://code.google.com/p/arduino/issues/detail?id=52
 
269
    splitPane.setMinimumSize(new Dimension(600, 100));
264
270
    box.add(splitPane);
265
271
 
266
272
    // hopefully these are no longer needed w/ swing
284
290
    setPlacement(location);
285
291
 
286
292
 
287
 
    // If the window is resized too small this will resize it again to the
288
 
    // minimums. Adapted by Chris Lonnen from comments here:
289
 
    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4320050
290
 
    // as a fix for http://dev.processing.org/bugs/show_bug.cgi?id=25
291
 
    final int minW = Preferences.getInteger("editor.window.width.min");
292
 
    final int minH = Preferences.getInteger("editor.window.height.min");
293
 
    addComponentListener(new java.awt.event.ComponentAdapter() {
294
 
        public void componentResized(ComponentEvent event) {
295
 
          setSize((getWidth() < minW) ? minW : getWidth(),
296
 
                  (getHeight() < minH) ? minH : getHeight());
297
 
        }
298
 
      });
299
 
 
 
293
    // Set the minimum size for the editor window
 
294
    setMinimumSize(new Dimension(Preferences.getInteger("editor.window.width.min"),
 
295
                                 Preferences.getInteger("editor.window.height.min")));
300
296
//    System.out.println("t3");
301
297
 
302
298
    // Bring back the general options for the editor
367
363
      }
368
364
 
369
365
      if (successful == 0) {
370
 
        statusError("No files were added to the sketch.");
 
366
        statusError(_("No files were added to the sketch."));
371
367
 
372
368
      } else if (successful == 1) {
373
 
        statusNotice("One file added to the sketch.");
 
369
        statusNotice(_("One file added to the sketch."));
374
370
 
375
371
      } else {
376
 
        statusNotice(successful + " files added to the sketch.");
 
372
        statusNotice(
 
373
            I18n.format(_("{0} files added to the sketch."), successful));
377
374
      }
378
375
      return true;
379
376
    }
484
481
 
485
482
  protected JMenu buildFileMenu() {
486
483
    JMenuItem item;
487
 
    fileMenu = new JMenu("File");
 
484
    fileMenu = new JMenu(_("File"));
488
485
 
489
 
    item = newJMenuItem("New", 'N');
 
486
    item = newJMenuItem(_("New"), 'N');
490
487
    item.addActionListener(new ActionListener() {
491
488
        public void actionPerformed(ActionEvent e) {
492
489
          base.handleNew();
494
491
      });
495
492
    fileMenu.add(item);
496
493
 
497
 
    item = Editor.newJMenuItem("Open...", 'O');
 
494
    item = Editor.newJMenuItem(_("Open..."), 'O');
498
495
    item.addActionListener(new ActionListener() {
499
496
        public void actionPerformed(ActionEvent e) {
500
497
          base.handleOpenPrompt();
503
500
    fileMenu.add(item);
504
501
 
505
502
    if (sketchbookMenu == null) {
506
 
      sketchbookMenu = new JMenu("Sketchbook");
 
503
      sketchbookMenu = new JMenu(_("Sketchbook"));
507
504
      base.rebuildSketchbookMenu(sketchbookMenu);
508
505
    }
509
506
    fileMenu.add(sketchbookMenu);
510
507
 
511
508
    if (examplesMenu == null) {
512
 
      examplesMenu = new JMenu("Examples");
 
509
      examplesMenu = new JMenu(_("Examples"));
513
510
      base.rebuildExamplesMenu(examplesMenu);
514
511
    }
515
512
    fileMenu.add(examplesMenu);
516
513
 
517
 
    item = Editor.newJMenuItem("Close", 'W');
 
514
    item = Editor.newJMenuItem(_("Close"), 'W');
518
515
    item.addActionListener(new ActionListener() {
519
516
        public void actionPerformed(ActionEvent e) {
520
517
          base.handleClose(Editor.this);
522
519
      });
523
520
    fileMenu.add(item);
524
521
 
525
 
    saveMenuItem = newJMenuItem("Save", 'S');
 
522
    saveMenuItem = newJMenuItem(_("Save"), 'S');
526
523
    saveMenuItem.addActionListener(new ActionListener() {
527
524
        public void actionPerformed(ActionEvent e) {
528
525
          handleSave(false);
530
527
      });
531
528
    fileMenu.add(saveMenuItem);
532
529
 
533
 
    saveAsMenuItem = newJMenuItemShift("Save As...", 'S');
 
530
    saveAsMenuItem = newJMenuItemShift(_("Save As..."), 'S');
534
531
    saveAsMenuItem.addActionListener(new ActionListener() {
535
532
        public void actionPerformed(ActionEvent e) {
536
533
          handleSaveAs();
538
535
      });
539
536
    fileMenu.add(saveAsMenuItem);
540
537
 
541
 
    item = newJMenuItem("Upload", 'U');
 
538
    item = newJMenuItem(_("Upload"), 'U');
542
539
    item.addActionListener(new ActionListener() {
543
540
        public void actionPerformed(ActionEvent e) {
544
541
          handleExport(false);
546
543
      });
547
544
    fileMenu.add(item);
548
545
 
549
 
    item = newJMenuItemShift("Upload Using Programmer", 'U');
 
546
    item = newJMenuItemShift(_("Upload Using Programmer"), 'U');
550
547
    item.addActionListener(new ActionListener() {
551
548
        public void actionPerformed(ActionEvent e) {
552
549
          handleExport(true);
556
553
 
557
554
    fileMenu.addSeparator();
558
555
 
559
 
    item = newJMenuItemShift("Page Setup", 'P');
 
556
    item = newJMenuItemShift(_("Page Setup"), 'P');
560
557
    item.addActionListener(new ActionListener() {
561
558
        public void actionPerformed(ActionEvent e) {
562
559
          handlePageSetup();
564
561
      });
565
562
    fileMenu.add(item);
566
563
 
567
 
    item = newJMenuItem("Print", 'P');
 
564
    item = newJMenuItem(_("Print"), 'P');
568
565
    item.addActionListener(new ActionListener() {
569
566
        public void actionPerformed(ActionEvent e) {
570
567
          handlePrint();
576
573
    if (!Base.isMacOS()) {
577
574
      fileMenu.addSeparator();
578
575
 
579
 
      item = newJMenuItem("Preferences", ',');
 
576
      item = newJMenuItem(_("Preferences"), ',');
580
577
      item.addActionListener(new ActionListener() {
581
578
          public void actionPerformed(ActionEvent e) {
582
579
            base.handlePrefs();
586
583
 
587
584
      fileMenu.addSeparator();
588
585
 
589
 
      item = newJMenuItem("Quit", 'Q');
 
586
      item = newJMenuItem(_("Quit"), 'Q');
590
587
      item.addActionListener(new ActionListener() {
591
588
          public void actionPerformed(ActionEvent e) {
592
589
            base.handleQuit();
600
597
 
601
598
  protected JMenu buildSketchMenu() {
602
599
    JMenuItem item;
603
 
    sketchMenu = new JMenu("Sketch");
 
600
    sketchMenu = new JMenu(_("Sketch"));
604
601
 
605
 
    item = newJMenuItem("Verify / Compile", 'R');
 
602
    item = newJMenuItem(_("Verify / Compile"), 'R');
606
603
    item.addActionListener(new ActionListener() {
607
604
        public void actionPerformed(ActionEvent e) {
608
605
          handleRun(false);
629
626
    sketchMenu.addSeparator();
630
627
 
631
628
    if (importMenu == null) {
632
 
      importMenu = new JMenu("Import Library...");
 
629
      importMenu = new JMenu(_("Import Library..."));
633
630
      base.rebuildImportMenu(importMenu);
634
631
    }
635
632
    sketchMenu.add(importMenu);
636
633
 
637
 
    item = newJMenuItem("Show Sketch Folder", 'K');
 
634
    item = newJMenuItem(_("Show Sketch Folder"), 'K');
638
635
    item.addActionListener(new ActionListener() {
639
636
        public void actionPerformed(ActionEvent e) {
640
637
          Base.openFolder(sketch.getFolder());
643
640
    sketchMenu.add(item);
644
641
    item.setEnabled(Base.openFolderAvailable());
645
642
 
646
 
    item = new JMenuItem("Add File...");
 
643
    item = new JMenuItem(_("Add File..."));
647
644
    item.addActionListener(new ActionListener() {
648
645
        public void actionPerformed(ActionEvent e) {
649
646
          sketch.handleAddFile();
656
653
 
657
654
 
658
655
  protected JMenu buildToolsMenu() {
659
 
    toolsMenu = new JMenu("Tools");
 
656
    toolsMenu = new JMenu(_("Tools"));
660
657
    JMenu menu = toolsMenu;
661
658
    JMenuItem item;
662
659
 
663
660
    addInternalTools(menu);
664
661
    
665
 
    item = newJMenuItemShift("Serial Monitor", 'M');
 
662
    item = newJMenuItemShift(_("Serial Monitor"), 'M');
666
663
    item.addActionListener(new ActionListener() {
667
664
        public void actionPerformed(ActionEvent e) {
668
665
          handleSerial();
682
679
    // API, if possible (i.e. if it supports custom actions, etc.)
683
680
    
684
681
    if (boardsMenu == null) {
685
 
      boardsMenu = new JMenu("Board");
 
682
      boardsMenu = new JMenu(_("Board"));
686
683
      base.rebuildBoardsMenu(boardsMenu);
687
684
    }
688
685
    menu.add(boardsMenu);
690
687
    if (serialMenuListener == null)
691
688
      serialMenuListener  = new SerialMenuListener();
692
689
    if (serialMenu == null)
693
 
      serialMenu = new JMenu("Serial Port");
 
690
      serialMenu = new JMenu(_("Serial Port"));
694
691
    populateSerialMenu();
695
692
    menu.add(serialMenu);
696
 
    
697
693
    menu.addSeparator();
698
694
    
699
 
    JMenu programmerMenu = new JMenu("Programmer");
 
695
    JMenu programmerMenu = new JMenu(_("Programmer"));
700
696
    base.rebuildProgrammerMenu(programmerMenu);
701
697
    menu.add(programmerMenu);
702
698
 
703
 
    item = new JMenuItem("Burn Bootloader");
 
699
    item = new JMenuItem(_("Burn Bootloader"));
704
700
    item.addActionListener(new ActionListener() {
705
701
      public void actionPerformed(ActionEvent e) {
706
702
        handleBurnBootloader();
907
903
 
908
904
    public void actionPerformed(ActionEvent e) {
909
905
      selectSerialPort(((JCheckBoxMenuItem)e.getSource()).getText());
 
906
      base.onBoardOrPortChange();
910
907
    }
911
908
 
912
909
    /*
923
920
  
924
921
  protected void selectSerialPort(String name) {
925
922
    if(serialMenu == null) {
926
 
      System.out.println("serialMenu is null");
 
923
      System.out.println(_("serialMenu is null"));
927
924
      return;
928
925
    }
929
926
    if (name == null) {
930
 
      System.out.println("name is null");
 
927
      System.out.println(_("name is null"));
931
928
      return;
932
929
    }
933
930
    JCheckBoxMenuItem selection = null;
934
931
    for (int i = 0; i < serialMenu.getItemCount(); i++) {
935
932
      JCheckBoxMenuItem item = ((JCheckBoxMenuItem)serialMenu.getItem(i));
936
933
      if (item == null) {
937
 
        System.out.println("name is null");
 
934
        System.out.println(_("name is null"));
938
935
        continue;
939
936
      }
940
937
      item.setState(false);
986
983
 
987
984
    catch (Exception exception)
988
985
    {
989
 
      System.out.println("error retrieving port list");
 
986
      System.out.println(_("error retrieving port list"));
990
987
      exception.printStackTrace();
991
988
    }
992
989
        
997
994
    //serialMenu.addSeparator();
998
995
    //serialMenu.add(item);
999
996
  }
1000
 
  
1001
 
  
 
997
 
 
998
 
1002
999
  protected JMenu buildHelpMenu() {
1003
1000
    // To deal with a Mac OS X 10.5 bug, add an extra space after the name
1004
1001
    // so that the OS doesn't try to insert its slow help menu.
1005
 
    JMenu menu = new JMenu("Help ");
 
1002
    JMenu menu = new JMenu(_("Help"));
1006
1003
    JMenuItem item;
1007
1004
 
1008
1005
    /*
1041
1038
    menu.add(item);
1042
1039
    */
1043
1040
 
1044
 
    item = new JMenuItem("Getting Started");
 
1041
    item = new JMenuItem(_("Getting Started"));
1045
1042
    item.addActionListener(new ActionListener() {
1046
1043
        public void actionPerformed(ActionEvent e) {
1047
1044
          Base.showGettingStarted();
1049
1046
      });
1050
1047
    menu.add(item);
1051
1048
 
1052
 
    item = new JMenuItem("Environment");
 
1049
    item = new JMenuItem(_("Environment"));
1053
1050
    item.addActionListener(new ActionListener() {
1054
1051
        public void actionPerformed(ActionEvent e) {
1055
1052
          Base.showEnvironment();
1057
1054
      });
1058
1055
    menu.add(item);
1059
1056
 
1060
 
    item = new JMenuItem("Troubleshooting");
 
1057
    item = new JMenuItem(_("Troubleshooting"));
1061
1058
    item.addActionListener(new ActionListener() {
1062
1059
        public void actionPerformed(ActionEvent e) {
1063
1060
          Base.showTroubleshooting();
1065
1062
      });
1066
1063
    menu.add(item);
1067
1064
 
1068
 
    item = new JMenuItem("Reference");
 
1065
    item = new JMenuItem(_("Reference"));
1069
1066
    item.addActionListener(new ActionListener() {
1070
1067
        public void actionPerformed(ActionEvent e) {
1071
1068
          Base.showReference();
1073
1070
      });
1074
1071
    menu.add(item);
1075
1072
 
1076
 
    item = newJMenuItemShift("Find in Reference", 'F');
 
1073
    item = newJMenuItemShift(_("Find in Reference"), 'F');
1077
1074
    item.addActionListener(new ActionListener() {
1078
1075
        public void actionPerformed(ActionEvent e) {
1079
1076
          if (textarea.isSelectionActive()) {
1083
1080
      });
1084
1081
    menu.add(item);
1085
1082
 
1086
 
    item = new JMenuItem("Frequently Asked Questions");
 
1083
    item = new JMenuItem(_("Frequently Asked Questions"));
1087
1084
    item.addActionListener(new ActionListener() {
1088
1085
        public void actionPerformed(ActionEvent e) {
1089
1086
          Base.showFAQ();
1091
1088
      });
1092
1089
    menu.add(item);
1093
1090
 
1094
 
    item = new JMenuItem("Visit Arduino.cc");
 
1091
    item = new JMenuItem(_("Visit Arduino.cc"));
1095
1092
    item.addActionListener(new ActionListener() {
1096
1093
        public void actionPerformed(ActionEvent e) {
1097
 
          Base.openURL("http://arduino.cc/");
 
1094
          Base.openURL(_("http://arduino.cc/"));
1098
1095
        }
1099
1096
      });
1100
1097
    menu.add(item);
1102
1099
    // macosx already has its own about menu
1103
1100
    if (!Base.isMacOS()) {
1104
1101
      menu.addSeparator();
1105
 
      item = new JMenuItem("About Arduino");
 
1102
      item = new JMenuItem(_("About Arduino"));
1106
1103
      item.addActionListener(new ActionListener() {
1107
1104
          public void actionPerformed(ActionEvent e) {
1108
1105
            base.handleAbout();
1116
1113
 
1117
1114
 
1118
1115
  protected JMenu buildEditMenu() {
1119
 
    JMenu menu = new JMenu("Edit");
 
1116
    JMenu menu = new JMenu(_("Edit"));
1120
1117
    JMenuItem item;
1121
1118
 
1122
 
    undoItem = newJMenuItem("Undo", 'Z');
 
1119
    undoItem = newJMenuItem(_("Undo"), 'Z');
1123
1120
    undoItem.addActionListener(undoAction = new UndoAction());
1124
1121
    menu.add(undoItem);
1125
1122
 
1126
 
    redoItem = newJMenuItem("Redo", 'Y');
 
1123
    if (!Base.isMacOS()) {
 
1124
        redoItem = newJMenuItem(_("Redo"), 'Y');
 
1125
    } else {
 
1126
        redoItem = newJMenuItemShift(_("Redo"), 'Z');
 
1127
    }
1127
1128
    redoItem.addActionListener(redoAction = new RedoAction());
1128
1129
    menu.add(redoItem);
1129
1130
 
1131
1132
 
1132
1133
    // TODO "cut" and "copy" should really only be enabled
1133
1134
    // if some text is currently selected
1134
 
    item = newJMenuItem("Cut", 'X');
 
1135
    item = newJMenuItem(_("Cut"), 'X');
1135
1136
    item.addActionListener(new ActionListener() {
1136
1137
        public void actionPerformed(ActionEvent e) {
1137
1138
          handleCut();
1139
1140
      });
1140
1141
    menu.add(item);
1141
1142
 
1142
 
    item = newJMenuItem("Copy", 'C');
 
1143
    item = newJMenuItem(_("Copy"), 'C');
1143
1144
    item.addActionListener(new ActionListener() {
1144
1145
        public void actionPerformed(ActionEvent e) {
1145
1146
          textarea.copy();
1147
1148
      });
1148
1149
    menu.add(item);
1149
1150
 
1150
 
    item = newJMenuItemShift("Copy for Forum", 'C');
 
1151
    item = newJMenuItemShift(_("Copy for Forum"), 'C');
1151
1152
    item.addActionListener(new ActionListener() {
1152
1153
        public void actionPerformed(ActionEvent e) {
1153
1154
//          SwingUtilities.invokeLater(new Runnable() {
1159
1160
      });
1160
1161
    menu.add(item);
1161
1162
 
1162
 
    item = newJMenuItemAlt("Copy as HTML", 'C');
 
1163
    item = newJMenuItemAlt(_("Copy as HTML"), 'C');
1163
1164
    item.addActionListener(new ActionListener() {
1164
1165
        public void actionPerformed(ActionEvent e) {
1165
1166
//          SwingUtilities.invokeLater(new Runnable() {
1171
1172
      });
1172
1173
    menu.add(item);
1173
1174
 
1174
 
    item = newJMenuItem("Paste", 'V');
 
1175
    item = newJMenuItem(_("Paste"), 'V');
1175
1176
    item.addActionListener(new ActionListener() {
1176
1177
        public void actionPerformed(ActionEvent e) {
1177
1178
          textarea.paste();
1180
1181
      });
1181
1182
    menu.add(item);
1182
1183
 
1183
 
    item = newJMenuItem("Select All", 'A');
 
1184
    item = newJMenuItem(_("Select All"), 'A');
1184
1185
    item.addActionListener(new ActionListener() {
1185
1186
        public void actionPerformed(ActionEvent e) {
1186
1187
          textarea.selectAll();
1190
1191
 
1191
1192
    menu.addSeparator();
1192
1193
 
1193
 
    item = newJMenuItem("Comment/Uncomment", '/');
 
1194
    item = newJMenuItem(_("Comment/Uncomment"), '/');
1194
1195
    item.addActionListener(new ActionListener() {
1195
1196
        public void actionPerformed(ActionEvent e) {
1196
1197
          handleCommentUncomment();
1198
1199
    });
1199
1200
    menu.add(item);
1200
1201
 
1201
 
    item = newJMenuItem("Increase Indent", ']');
 
1202
    item = newJMenuItem(_("Increase Indent"), ']');
1202
1203
    item.addActionListener(new ActionListener() {
1203
1204
        public void actionPerformed(ActionEvent e) {
1204
1205
          handleIndentOutdent(true);
1206
1207
    });
1207
1208
    menu.add(item);
1208
1209
 
1209
 
    item = newJMenuItem("Decrease Indent", '[');
 
1210
    item = newJMenuItem(_("Decrease Indent"), '[');
1210
1211
    item.addActionListener(new ActionListener() {
1211
1212
        public void actionPerformed(ActionEvent e) {
1212
1213
          handleIndentOutdent(false);
1216
1217
 
1217
1218
    menu.addSeparator();
1218
1219
 
1219
 
    item = newJMenuItem("Find...", 'F');
 
1220
    item = newJMenuItem(_("Find..."), 'F');
1220
1221
    item.addActionListener(new ActionListener() {
1221
1222
        public void actionPerformed(ActionEvent e) {
1222
1223
          if (find == null) {
1231
1232
 
1232
1233
    // TODO find next should only be enabled after a
1233
1234
    // search has actually taken place
1234
 
    item = newJMenuItem("Find Next", 'G');
1235
 
    item.addActionListener(new ActionListener() {
1236
 
        public void actionPerformed(ActionEvent e) {
1237
 
          if (find != null) {
1238
 
            //find.find(true);
1239
 
            //FindReplace find = new FindReplace(Editor.this); //.show();
1240
 
            find.find(true);
1241
 
          }
 
1235
    item = newJMenuItem(_("Find Next"), 'G');
 
1236
    item.addActionListener(new ActionListener() {
 
1237
        public void actionPerformed(ActionEvent e) {
 
1238
          if (find != null) {
 
1239
            find.findNext();
 
1240
          }
 
1241
        }
 
1242
      });
 
1243
    menu.add(item);
 
1244
 
 
1245
    item = newJMenuItemShift(_("Find Previous"), 'G');
 
1246
    item.addActionListener(new ActionListener() {
 
1247
        public void actionPerformed(ActionEvent e) {
 
1248
          if (find != null) {
 
1249
            find.findPrevious();
 
1250
          }
 
1251
        }
 
1252
      });
 
1253
    menu.add(item);
 
1254
 
 
1255
    item = newJMenuItem(_("Use Selection For Find"), 'E');
 
1256
    item.addActionListener(new ActionListener() {
 
1257
        public void actionPerformed(ActionEvent e) {
 
1258
          if (find == null) {
 
1259
            find = new FindReplace(Editor.this);
 
1260
          }
 
1261
          find.setFindText( getSelectedText() );
1242
1262
        }
1243
1263
      });
1244
1264
    menu.add(item);
1318
1338
      } else {
1319
1339
        this.setEnabled(false);
1320
1340
        undoItem.setEnabled(false);
1321
 
        undoItem.setText("Undo");
 
1341
        undoItem.setText(_("Undo"));
1322
1342
        putValue(Action.NAME, "Undo");
1323
1343
        if (sketch != null) {
1324
1344
          sketch.setModified(false);  // 0107
1353
1373
      } else {
1354
1374
        this.setEnabled(false);
1355
1375
        redoItem.setEnabled(false);
1356
 
        redoItem.setText("Redo");
 
1376
        redoItem.setText(_("Redo"));
1357
1377
        putValue(Action.NAME, "Redo");
1358
1378
      }
1359
1379
    }
1793
1813
    String text = textarea.getSelectedText().trim();
1794
1814
 
1795
1815
    if (text.length() == 0) {
1796
 
      statusNotice("First select a word to find in the reference.");
 
1816
      statusNotice(_("First select a word to find in the reference."));
1797
1817
 
1798
1818
    } else {
1799
1819
      String referenceFile = PdeKeywords.getReference(text);
1800
1820
      //System.out.println("reference file is " + referenceFile);
1801
1821
      if (referenceFile == null) {
1802
 
        statusNotice("No reference available for \"" + text + "\"");
 
1822
        statusNotice(
 
1823
          I18n.format(_("No reference available for \"{0}\""), text)
 
1824
        );
1803
1825
      } else {
1804
 
        Base.showReference(referenceFile + ".html");
 
1826
        Base.showReference(I18n.format(_("{0}.html"), referenceFile));
1805
1827
      }
1806
1828
    }
1807
1829
  }
1818
1840
    internalCloseRunner();
1819
1841
    running = true;
1820
1842
    toolbar.activate(EditorToolbar.RUN);
1821
 
    statusNotice("Compiling...");
 
1843
    status.progress(_("Compiling sketch..."));
1822
1844
 
1823
1845
    // do this to advance/clear the terminal window / dos prompt / etc
1824
1846
    for (int i = 0; i < 10; i++) System.out.println();
1838
1860
    public void run() {
1839
1861
      try {
1840
1862
        sketch.prepare();
1841
 
        String appletClassName = sketch.build(false);
1842
 
        statusNotice("Done compiling.");
 
1863
        sketch.build(false);
 
1864
        statusNotice(_("Done compiling."));
1843
1865
      } catch (Exception e) {
 
1866
        status.unprogress();
1844
1867
        statusError(e);
1845
1868
      }
1846
1869
 
 
1870
      status.unprogress();
1847
1871
      toolbar.deactivate(EditorToolbar.RUN);
1848
1872
    }
1849
1873
  }
1853
1877
    public void run() {
1854
1878
      try {
1855
1879
        sketch.prepare();
1856
 
        String appletClassName = sketch.build(true);
1857
 
        statusNotice("Done compiling.");
 
1880
        sketch.build(true);
 
1881
        statusNotice(_("Done compiling."));
1858
1882
      } catch (Exception e) {
 
1883
        status.unprogress();
1859
1884
        statusError(e);
1860
1885
      }
1861
1886
 
 
1887
      status.unprogress();
1862
1888
      toolbar.deactivate(EditorToolbar.RUN);
1863
1889
    }
1864
1890
  }
1944
1970
    // As of Processing 1.0.10, this always happens immediately.
1945
1971
    // http://dev.processing.org/bugs/show_bug.cgi?id=1456
1946
1972
 
1947
 
    String prompt = "Save changes to " + sketch.getName() + "?  ";
 
1973
    String prompt = I18n.format(_("Save changes to \"{0}\"?  "), sketch.getName());
1948
1974
 
1949
1975
    if (!Base.isMacOS()) {
1950
1976
      int result =
1951
 
        JOptionPane.showConfirmDialog(this, prompt, "Close",
 
1977
        JOptionPane.showConfirmDialog(this, prompt, _("Close"),
1952
1978
                                      JOptionPane.YES_NO_CANCEL_OPTION,
1953
1979
                                      JOptionPane.QUESTION_MESSAGE);
1954
1980
 
1977
2003
      // Pane formatting adapted from the quaqua guide
1978
2004
      // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
1979
2005
      JOptionPane pane =
1980
 
        new JOptionPane("<html> " +
1981
 
                        "<head> <style type=\"text/css\">"+
1982
 
                        "b { font: 13pt \"Lucida Grande\" }"+
1983
 
                        "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
1984
 
                        "</style> </head>" +
1985
 
                        "<b>Do you want to save changes to this sketch<BR>" +
1986
 
                        " before closing?</b>" +
1987
 
                        "<p>If you don't save, your changes will be lost.",
 
2006
        new JOptionPane(_("<html> " +
 
2007
                          "<head> <style type=\"text/css\">"+
 
2008
                          "b { font: 13pt \"Lucida Grande\" }"+
 
2009
                          "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
 
2010
                          "</style> </head>" +
 
2011
                          "<b>Do you want to save changes to this sketch<BR>" +
 
2012
                          " before closing?</b>" +
 
2013
                          "<p>If you don't save, your changes will be lost."),
1988
2014
                        JOptionPane.QUESTION_MESSAGE);
1989
2015
 
1990
2016
      String[] options = new String[] {
1991
 
        "Save", "Cancel", "Don't Save"
 
2017
        _("Save"), _("Cancel"), _("Don't Save")
1992
2018
      };
1993
2019
      pane.setOptions(options);
1994
2020
 
2040
2066
   * modifications (if any) to the previous sketch need to be saved.
2041
2067
   */
2042
2068
  protected boolean handleOpenInternal(String path) {
2043
 
    // rename .pde files to .ino
2044
 
    File[] oldFiles = (new File(path)).getParentFile().listFiles(new FilenameFilter() {
2045
 
      public boolean accept(File dir, String name) {
2046
 
        return (name.toLowerCase().endsWith(".pde"));
2047
 
      }
2048
 
    });
2049
 
    
2050
 
    if (oldFiles != null && oldFiles.length > 0) {
2051
 
      if (!Preferences.getBoolean("editor.update_extension")) {
2052
 
        Object[] options = { "OK", "Cancel" };
2053
 
        String prompt =
2054
 
          "In Arduino 1.0, the file extension for sketches changed\n" +
2055
 
          "from \".pde\" to \".ino\".  This version of the software only\n" +
2056
 
          "supports the new extension.  Rename the files in this sketch\n" +
2057
 
          "(and future sketches) and continue?";
2058
 
        
2059
 
        int result = JOptionPane.showOptionDialog(this,
2060
 
                                                  prompt,
2061
 
                                                  "New extension",
2062
 
                                                  JOptionPane.YES_NO_OPTION,
2063
 
                                                  JOptionPane.QUESTION_MESSAGE,
2064
 
                                                  null,
2065
 
                                                  options,
2066
 
                                                  options[0]);
2067
 
        if (result != JOptionPane.YES_OPTION) {
2068
 
          return false;
2069
 
        }
2070
 
        
2071
 
        Preferences.setBoolean("editor.update_extension", true);
2072
 
      }
2073
 
      
2074
 
      for (int i = 0; i < oldFiles.length; i++) {
2075
 
        String oldPath = oldFiles[i].getPath();
2076
 
        File newFile = new File(oldPath.substring(0, oldPath.length() - 4) + ".ino");
2077
 
        try {
2078
 
          Base.copyFile(oldFiles[i], newFile);
2079
 
        } catch (IOException e) {
2080
 
          Base.showWarning("Error", "Could not copy to a proper location.", e);
2081
 
          return false;
2082
 
        }
2083
 
 
2084
 
        // remove the original file, so user doesn't get confused
2085
 
        oldFiles[i].delete();
2086
 
 
2087
 
        // update with the new path
2088
 
        if (oldFiles[i].compareTo(new File(path)) == 0) {
2089
 
          path = newFile.getAbsolutePath();             
2090
 
        }
2091
 
      }
2092
 
    }
2093
 
    
2094
2069
    // check to make sure that this .pde file is
2095
2070
    // in a folder of the same name
2096
2071
    File file = new File(path);
2097
 
    File parentFile = new File(file.getParent());
2098
 
    String parentName = parentFile.getName();
2099
 
    String pdeName = parentName + ".ino";
2100
 
    File altFile = new File(file.getParent(), pdeName);
 
2072
    String fileName = file.getName();
 
2073
    File parent = file.getParentFile();
 
2074
    String parentName = parent.getName();
 
2075
    String pdeName = parentName + ".pde";
 
2076
    File altPdeFile = new File(parent, pdeName);
 
2077
    String inoName = parentName + ".ino";
 
2078
    File altInoFile = new File(parent, pdeName);
2101
2079
    
2102
 
    if (pdeName.equals(file.getName())) {
 
2080
    if (pdeName.equals(fileName) || inoName.equals(fileName)) {
2103
2081
      // no beef with this guy
2104
2082
 
2105
 
    } else if (altFile.exists()) {
2106
 
      // user selected a .java from the same sketch,
2107
 
      // but open the .pde instead
2108
 
      path = altFile.getAbsolutePath();
2109
 
      //System.out.println("found alt file in same folder");
2110
 
 
2111
 
    } else if (!path.endsWith(".ino")) {
2112
 
      Base.showWarning("Bad file selected",
2113
 
                       "Processing can only open its own sketches\n" +
2114
 
                       "and other files ending in .ino", null);
 
2083
    } else if (altPdeFile.exists()) {
 
2084
      // user selected a .java from the same sketch, but open the .pde instead
 
2085
      path = altPdeFile.getAbsolutePath();
 
2086
    } else if (altInoFile.exists()) {
 
2087
      path = altInoFile.getAbsolutePath();
 
2088
    } else if (!path.endsWith(".ino") && !path.endsWith(".pde")) {
 
2089
      Base.showWarning(_("Bad file selected"),
 
2090
                       _("Processing can only open its own sketches\n" +
 
2091
                         "and other files ending in .ino or .pde"), null);
2115
2092
      return false;
2116
2093
 
2117
2094
    } else {
2118
2095
      String properParent =
2119
 
        file.getName().substring(0, file.getName().length() - 4);
 
2096
        fileName.substring(0, fileName.length() - 4);
2120
2097
 
2121
 
      Object[] options = { "OK", "Cancel" };
2122
 
      String prompt =
2123
 
        "The file \"" + file.getName() + "\" needs to be inside\n" +
2124
 
        "a sketch folder named \"" + properParent + "\".\n" +
2125
 
        "Create this folder, move the file, and continue?";
 
2098
      Object[] options = { _("OK"), _("Cancel") };
 
2099
      String prompt = I18n.format(
 
2100
        _("The file \"{0}\" needs to be inside\n" +
 
2101
          "a sketch folder named \"{1}\".\n" +
 
2102
          "Create this folder, move the file, and continue?"),
 
2103
        fileName,
 
2104
        properParent
 
2105
      );
2126
2106
 
2127
2107
      int result = JOptionPane.showOptionDialog(this,
2128
2108
                                                prompt,
2129
 
                                                "Moving",
 
2109
                                                _("Moving"),
2130
2110
                                                JOptionPane.YES_NO_OPTION,
2131
2111
                                                JOptionPane.QUESTION_MESSAGE,
2132
2112
                                                null,
2137
2117
        // create properly named folder
2138
2118
        File properFolder = new File(file.getParent(), properParent);
2139
2119
        if (properFolder.exists()) {
2140
 
          Base.showWarning("Error",
2141
 
                           "A folder named \"" + properParent + "\" " +
2142
 
                           "already exists. Can't open sketch.", null);
 
2120
          Base.showWarning(_("Error"),
 
2121
                           I18n.format(
 
2122
                             _("A folder named \"{0}\" already exists. " +
 
2123
                               "Can't open sketch."),
 
2124
                             properParent
 
2125
                           ),
 
2126
                           null);
2143
2127
          return false;
2144
2128
        }
2145
2129
        if (!properFolder.mkdirs()) {
2146
2130
          //throw new IOException("Couldn't create sketch folder");
2147
 
          Base.showWarning("Error",
2148
 
                           "Could not create the sketch folder.", null);
 
2131
          Base.showWarning(_("Error"),
 
2132
                           _("Could not create the sketch folder."), null);
2149
2133
          return false;
2150
2134
        }
2151
2135
        // copy the sketch inside
2154
2138
        try {
2155
2139
          Base.copyFile(origPdeFile, properPdeFile);
2156
2140
        } catch (IOException e) {
2157
 
          Base.showWarning("Error", "Could not copy to a proper location.", e);
 
2141
          Base.showWarning(_("Error"), _("Could not copy to a proper location."), e);
2158
2142
          return false;
2159
2143
        }
2160
2144
 
2172
2156
    try {
2173
2157
      sketch = new Sketch(this, path);
2174
2158
    } catch (IOException e) {
2175
 
      Base.showWarning("Error", "Could not create the sketch.", e);
 
2159
      Base.showWarning(_("Error"), _("Could not create the sketch."), e);
2176
2160
      return false;
2177
2161
    }
2178
2162
    header.rebuild();
2179
2163
    // Set the title of the window to "sketch_070752a - Processing 0126"
2180
 
    setTitle(sketch.getName() + " | Arduino " + Base.VERSION_NAME);
 
2164
    setTitle(
 
2165
      I18n.format(
 
2166
        _("{0} | Arduino {1}"),
 
2167
        sketch.getName(),
 
2168
        Base.VERSION_NAME
 
2169
      )
 
2170
    );
2181
2171
    // Disable untitled setting from previous document, if any
2182
2172
    untitled = false;
2183
2173
 
2215
2205
      // need to get the name, user might also cancel here
2216
2206
 
2217
2207
    } else if (immediately) {
2218
 
      handleSave2();
 
2208
      return handleSave2();
2219
2209
 
2220
2210
    } else {
2221
2211
      SwingUtilities.invokeLater(new Runnable() {
2228
2218
  }
2229
2219
 
2230
2220
 
2231
 
  protected void handleSave2() {
 
2221
  protected boolean handleSave2() {
2232
2222
    toolbar.activate(EditorToolbar.SAVE);
2233
 
    statusNotice("Saving...");
 
2223
    statusNotice(_("Saving..."));
 
2224
    boolean saved = false;
2234
2225
    try {
2235
 
      if (sketch.save()) {
2236
 
        statusNotice("Done Saving.");
2237
 
      } else {
 
2226
      saved = sketch.save();
 
2227
      if (saved)
 
2228
        statusNotice(_("Done Saving."));
 
2229
      else
2238
2230
        statusEmpty();
2239
 
      }
2240
2231
      // rebuild sketch menu in case a save-as was forced
2241
2232
      // Disabling this for 0125, instead rebuild the menu inside
2242
2233
      // the Save As method of the Sketch object, since that's the
2255
2246
    }
2256
2247
    //toolbar.clear();
2257
2248
    toolbar.deactivate(EditorToolbar.SAVE);
 
2249
    return saved;
2258
2250
  }
2259
2251
 
2260
2252
 
2266
2258
 
2267
2259
    //SwingUtilities.invokeLater(new Runnable() {
2268
2260
    //public void run() {
2269
 
    statusNotice("Saving...");
 
2261
    statusNotice(_("Saving..."));
2270
2262
    try {
2271
2263
      if (sketch.saveAs()) {
2272
 
        statusNotice("Done Saving.");
 
2264
        statusNotice(_("Done Saving."));
2273
2265
        // Disabling this for 0125, instead rebuild the menu inside
2274
2266
        // the Save As method of the Sketch object, since that's the
2275
2267
        // only one who knows whether something was renamed.
2276
2268
        //sketchbook.rebuildMenusAsync();
2277
2269
      } else {
2278
 
        statusNotice("Save Canceled.");
 
2270
        statusNotice(_("Save Canceled."));
2279
2271
        return false;
2280
2272
      }
2281
2273
    } catch (Exception e) {
2300
2292
 
2301
2293
    String result = (String)
2302
2294
      JOptionPane.showInputDialog(this,
2303
 
                                  "Serial port " +
2304
 
                                  Preferences.get("serial.port") +
2305
 
                                  " not found.\n" +
2306
 
                                  "Retry the upload with another serial port?",
2307
 
                                  "Serial port not found",
 
2295
        I18n.format(
 
2296
          _("Serial port {0} not found.\n" +
 
2297
            "Retry the upload with another serial port?"),
 
2298
          Preferences.get("serial.port")
 
2299
        ),
 
2300
                                  "Serial port not found",
2308
2301
                                  JOptionPane.PLAIN_MESSAGE,
2309
2302
                                  null,
2310
2303
                                  names,
2311
2304
                                  0);
2312
2305
    if (result == null) return false;
2313
2306
    selectSerialPort(result);
 
2307
    base.onBoardOrPortChange();
2314
2308
    return true;
2315
2309
  }
2316
2310
 
2334
2328
    //if (!handleExportCheckModified()) return;
2335
2329
    toolbar.activate(EditorToolbar.EXPORT);
2336
2330
    console.clear();
2337
 
    statusNotice("Uploading to I/O Board...");
 
2331
    status.progress(_("Uploading to I/O Board..."));
2338
2332
 
2339
2333
    new Thread(usingProgrammer ? exportAppHandler : exportHandler).start();
2340
2334
  }
2351
2345
          
2352
2346
        boolean success = sketch.exportApplet(false);
2353
2347
        if (success) {
2354
 
          statusNotice("Done uploading.");
 
2348
          statusNotice(_("Done uploading."));
2355
2349
        } else {
2356
2350
          // error message will already be visible
2357
2351
        }
2359
2353
        populateSerialMenu();
2360
2354
        if (serialMenu.getItemCount() == 0) statusError(e);
2361
2355
        else if (serialPrompt()) run();
2362
 
        else statusNotice("Upload canceled.");
 
2356
        else statusNotice(_("Upload canceled."));
2363
2357
      } catch (RunnerException e) {
2364
2358
        //statusError("Error during upload.");
2365
2359
        //e.printStackTrace();
 
2360
        status.unprogress();
2366
2361
        statusError(e);
2367
2362
      } catch (Exception e) {
2368
2363
        e.printStackTrace();
2369
2364
      }
 
2365
      status.unprogress();
2370
2366
      uploading = false;
2371
2367
      //toolbar.clear();
2372
2368
      toolbar.deactivate(EditorToolbar.EXPORT);
2385
2381
          
2386
2382
        boolean success = sketch.exportApplet(true);
2387
2383
        if (success) {
2388
 
          statusNotice("Done uploading.");
 
2384
          statusNotice(_("Done uploading."));
2389
2385
        } else {
2390
2386
          // error message will already be visible
2391
2387
        }
2393
2389
        populateSerialMenu();
2394
2390
        if (serialMenu.getItemCount() == 0) statusError(e);
2395
2391
        else if (serialPrompt()) run();
2396
 
        else statusNotice("Upload canceled.");
 
2392
        else statusNotice(_("Upload canceled."));
2397
2393
      } catch (RunnerException e) {
2398
2394
        //statusError("Error during upload.");
2399
2395
        //e.printStackTrace();
 
2396
        status.unprogress();
2400
2397
        statusError(e);
2401
2398
      } catch (Exception e) {
2402
2399
        e.printStackTrace();
2403
2400
      }
 
2401
      status.unprogress();
2404
2402
      uploading = false;
2405
2403
      //toolbar.clear();
2406
2404
      toolbar.deactivate(EditorToolbar.EXPORT);
2417
2415
  protected boolean handleExportCheckModified() {
2418
2416
    if (!sketch.isModified()) return true;
2419
2417
 
2420
 
    Object[] options = { "OK", "Cancel" };
 
2418
    Object[] options = { _("OK"), _("Cancel") };
2421
2419
    int result = JOptionPane.showOptionDialog(this,
2422
 
                                              "Save changes before export?",
2423
 
                                              "Save",
 
2420
                                              _("Save changes before export?"),
 
2421
                                              _("Save"),
2424
2422
                                              JOptionPane.OK_CANCEL_OPTION,
2425
2423
                                              JOptionPane.QUESTION_MESSAGE,
2426
2424
                                              null,
2434
2432
      // why it's not CANCEL_OPTION is beyond me (at least on the mac)
2435
2433
      // but f-- it.. let's get this shite done..
2436
2434
      //} else if (result == JOptionPane.CANCEL_OPTION) {
2437
 
      statusNotice("Export canceled, changes must first be saved.");
 
2435
      statusNotice(_("Export canceled, changes must first be saved."));
2438
2436
      //toolbar.clear();
2439
2437
      return false;
2440
2438
    }
2456
2454
 
2457
2455
  protected void handleBurnBootloader() {
2458
2456
    console.clear();
2459
 
    statusNotice("Burning bootloader to I/O Board (this may take a minute)...");
 
2457
    statusNotice(_("Burning bootloader to I/O Board (this may take a minute)..."));
2460
2458
    SwingUtilities.invokeLater(new Runnable() {
2461
2459
      public void run() {
2462
2460
        try {
2463
2461
          Uploader uploader = new AvrdudeUploader();
2464
2462
          if (uploader.burnBootloader()) {
2465
 
            statusNotice("Done burning bootloader.");
 
2463
            statusNotice(_("Done burning bootloader."));
2466
2464
          } else {
2467
 
            statusError("Error while burning bootloader.");
 
2465
            statusError(_("Error while burning bootloader."));
2468
2466
            // error message will already be visible
2469
2467
          }
2470
2468
        } catch (RunnerException e) {
2471
 
          statusError("Error while burning bootloader.");
 
2469
          statusError(_("Error while burning bootloader."));
2472
2470
          e.printStackTrace();
2473
2471
          //statusError(e);
2474
2472
        } catch (Exception e) {
2475
 
          statusError("Error while burning bootloader.");
 
2473
          statusError(_("Error while burning bootloader."));
2476
2474
          e.printStackTrace();
2477
2475
        }
2478
2476
      }});
2499
2497
   * Handler for File &rarr; Print.
2500
2498
   */
2501
2499
  public void handlePrint() {
2502
 
    statusNotice("Printing...");
 
2500
    statusNotice(_("Printing..."));
2503
2501
    //printerJob = null;
2504
2502
    if (printerJob == null) {
2505
2503
      printerJob = PrinterJob.getPrinterJob();
2516
2514
    if (printerJob.printDialog()) {
2517
2515
      try {
2518
2516
        printerJob.print();
2519
 
        statusNotice("Done printing.");
 
2517
        statusNotice(_("Done printing."));
2520
2518
 
2521
2519
      } catch (PrinterException pe) {
2522
 
        statusError("Error while printing.");
 
2520
        statusError(_("Error while printing."));
2523
2521
        pe.printStackTrace();
2524
2522
      }
2525
2523
    } else {
2526
 
      statusNotice("Printing canceled.");
 
2524
      statusNotice(_("Printing canceled."));
2527
2525
    }
2528
2526
    //printerJob = null;  // clear this out?
2529
2527
  }
2571
2569
          }
2572
2570
        }
2573
2571
        if (line < 0 || line >= textarea.getLineCount()) {
2574
 
          System.err.println("Bad error line: " + line);
 
2572
          System.err.println(I18n.format(_("Bad error line: {0}"), line));
2575
2573
        } else {
2576
2574
          textarea.select(textarea.getLineStartOffset(line),
2577
2575
                          textarea.getLineStopOffset(line) - 1);
2615
2613
 
2616
2614
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2617
2615
 
 
2616
  protected void onBoardOrPortChange() {
 
2617
    Map<String, String> boardPreferences =  Base.getBoardPreferences();
 
2618
    lineStatus.setBoardName(boardPreferences.get("name"));
 
2619
    lineStatus.setSerialPort(Preferences.get("serial.port"));
 
2620
    lineStatus.repaint();
 
2621
  }
2618
2622
 
 
2623
  
2619
2624
  /**
2620
2625
   * Returns the edit popup menu.
2621
2626
   */
2622
2627
  class TextAreaPopup extends JPopupMenu {
2623
 
    //String currentDir = System.getProperty("user.dir");
2624
 
    String referenceFile = null;
2625
 
 
2626
 
    JMenuItem cutItem;
2627
 
    JMenuItem copyItem;
2628
 
    JMenuItem discourseItem;
2629
 
    JMenuItem referenceItem;
2630
 
 
 
2628
    //private String currentDir = System.getProperty("user.dir");
 
2629
    private String referenceFile = null;
 
2630
 
 
2631
    private JMenuItem cutItem;
 
2632
    private JMenuItem copyItem;
 
2633
    private JMenuItem discourseItem;
 
2634
    private JMenuItem referenceItem;
 
2635
    private JMenuItem openURLItem;
 
2636
    private JSeparator openURLItemSeparator;
 
2637
 
 
2638
    private String clickedURL;
2631
2639
 
2632
2640
    public TextAreaPopup() {
2633
 
      JMenuItem item;
2634
 
 
2635
 
      cutItem = new JMenuItem("Cut");
 
2641
      openURLItem = new JMenuItem(_("Open URL"));
 
2642
      openURLItem.addActionListener(new ActionListener() {
 
2643
        public void actionPerformed(ActionEvent e) {
 
2644
          Base.openURL(clickedURL);
 
2645
        }
 
2646
      });
 
2647
      add(openURLItem);
 
2648
      
 
2649
      openURLItemSeparator = new JSeparator();
 
2650
      add(openURLItemSeparator);
 
2651
      
 
2652
      cutItem = new JMenuItem(_("Cut"));
2636
2653
      cutItem.addActionListener(new ActionListener() {
2637
2654
          public void actionPerformed(ActionEvent e) {
2638
2655
            handleCut();
2639
2656
          }
2640
2657
      });
2641
 
      this.add(cutItem);
 
2658
      add(cutItem);
2642
2659
 
2643
 
      copyItem = new JMenuItem("Copy");
 
2660
      copyItem = new JMenuItem(_("Copy"));
2644
2661
      copyItem.addActionListener(new ActionListener() {
2645
2662
          public void actionPerformed(ActionEvent e) {
2646
2663
            handleCopy();
2647
2664
          }
2648
2665
        });
2649
 
      this.add(copyItem);
 
2666
      add(copyItem);
2650
2667
 
2651
 
      discourseItem = new JMenuItem("Copy for Forum");
 
2668
      discourseItem = new JMenuItem(_("Copy for Forum"));
2652
2669
      discourseItem.addActionListener(new ActionListener() {
2653
2670
          public void actionPerformed(ActionEvent e) {
2654
2671
            handleDiscourseCopy();
2655
2672
          }
2656
2673
        });
2657
 
      this.add(discourseItem);
 
2674
      add(discourseItem);
2658
2675
 
2659
 
      discourseItem = new JMenuItem("Copy as HTML");
 
2676
      discourseItem = new JMenuItem(_("Copy as HTML"));
2660
2677
      discourseItem.addActionListener(new ActionListener() {
2661
2678
          public void actionPerformed(ActionEvent e) {
2662
2679
            handleHTMLCopy();
2663
2680
          }
2664
2681
        });
2665
 
      this.add(discourseItem);
 
2682
      add(discourseItem);
2666
2683
 
2667
 
      item = new JMenuItem("Paste");
 
2684
      JMenuItem item = new JMenuItem(_("Paste"));
2668
2685
      item.addActionListener(new ActionListener() {
2669
2686
          public void actionPerformed(ActionEvent e) {
2670
2687
            handlePaste();
2671
2688
          }
2672
2689
        });
2673
 
      this.add(item);
 
2690
      add(item);
2674
2691
 
2675
 
      item = new JMenuItem("Select All");
 
2692
      item = new JMenuItem(_("Select All"));
2676
2693
      item.addActionListener(new ActionListener() {
2677
2694
        public void actionPerformed(ActionEvent e) {
2678
2695
          handleSelectAll();
2679
2696
        }
2680
2697
      });
2681
 
      this.add(item);
2682
 
 
2683
 
      this.addSeparator();
2684
 
 
2685
 
      item = new JMenuItem("Comment/Uncomment");
 
2698
      add(item);
 
2699
 
 
2700
      addSeparator();
 
2701
 
 
2702
      item = new JMenuItem(_("Comment/Uncomment"));
2686
2703
      item.addActionListener(new ActionListener() {
2687
2704
          public void actionPerformed(ActionEvent e) {
2688
2705
            handleCommentUncomment();
2689
2706
          }
2690
2707
      });
2691
 
      this.add(item);
 
2708
      add(item);
2692
2709
 
2693
 
      item = new JMenuItem("Increase Indent");
 
2710
      item = new JMenuItem(_("Increase Indent"));
2694
2711
      item.addActionListener(new ActionListener() {
2695
2712
          public void actionPerformed(ActionEvent e) {
2696
2713
            handleIndentOutdent(true);
2697
2714
          }
2698
2715
      });
2699
 
      this.add(item);
 
2716
      add(item);
2700
2717
 
2701
 
      item = new JMenuItem("Decrease Indent");
 
2718
      item = new JMenuItem(_("Decrease Indent"));
2702
2719
      item.addActionListener(new ActionListener() {
2703
2720
          public void actionPerformed(ActionEvent e) {
2704
2721
            handleIndentOutdent(false);
2705
2722
          }
2706
2723
      });
2707
 
      this.add(item);
2708
 
 
2709
 
      this.addSeparator();
2710
 
 
2711
 
      referenceItem = new JMenuItem("Find in Reference");
 
2724
      add(item);
 
2725
 
 
2726
      addSeparator();
 
2727
 
 
2728
      referenceItem = new JMenuItem(_("Find in Reference"));
2712
2729
      referenceItem.addActionListener(new ActionListener() {
2713
2730
          public void actionPerformed(ActionEvent e) {
2714
2731
            handleFindReference();
2715
2732
          }
2716
2733
        });
2717
 
      this.add(referenceItem);
 
2734
      add(referenceItem);
2718
2735
    }
2719
2736
 
2720
2737
    // if no text is selected, disable copy and cut menu items
2721
2738
    public void show(Component component, int x, int y) {
 
2739
      int lineNo = textarea.getLineOfOffset(textarea.xyToOffset(x, y));
 
2740
      int offset = textarea.xToOffset(lineNo, x);
 
2741
      String line = textarea.getLineText(lineNo);
 
2742
      clickedURL = textarea.checkClickedURL(line, offset);
 
2743
      if (clickedURL != null) {
 
2744
        openURLItem.setVisible(true);
 
2745
        openURLItemSeparator.setVisible(true);
 
2746
      } else {
 
2747
        openURLItem.setVisible(false);
 
2748
        openURLItemSeparator.setVisible(false);
 
2749
      }
 
2750
      
2722
2751
      if (textarea.isSelectionActive()) {
2723
2752
        cutItem.setEnabled(true);
2724
2753
        copyItem.setEnabled(true);