46
46
/**
47
47
* Main editor panel for the Processing Development Environment.
48
48
*/
49
+ @ SuppressWarnings ("serial" )
49
50
public class Editor extends JFrame implements RunnerListener {
50
51
51
52
Base base ;
@@ -113,7 +114,7 @@ public class Editor extends JFrame implements RunnerListener {
113
114
114
115
EditorLineStatus lineStatus ;
115
116
116
- JEditorPane editorPane ;
117
+ // JEditorPane editorPane;
117
118
118
119
JEditTextArea textarea ;
119
120
EditorListener listener ;
@@ -195,8 +196,10 @@ public void windowDeactivated(WindowEvent e) {
195
196
//PdeKeywords keywords = new PdeKeywords();
196
197
//sketchbook = new Sketchbook(this);
197
198
198
- if (serialMonitor == null )
199
+ if (serialMonitor == null ) {
199
200
serialMonitor = new SerialMonitor (Preferences .get ("serial.port" ));
201
+ serialMonitor .setIconImage (getIconImage ());
202
+ }
200
203
201
204
buildMenuBar ();
202
205
@@ -907,6 +910,7 @@ class SerialMenuListener implements ActionListener {
907
910
908
911
public void actionPerformed (ActionEvent e ) {
909
912
selectSerialPort (((JCheckBoxMenuItem )e .getSource ()).getText ());
913
+ base .onBoardOrPortChange ();
910
914
}
911
915
912
916
/*
@@ -1818,7 +1822,7 @@ public void handleRun(final boolean verbose) {
1818
1822
internalCloseRunner ();
1819
1823
running = true ;
1820
1824
toolbar .activate (EditorToolbar .RUN );
1821
- statusNotice ("Compiling..." );
1825
+ status . progress ("Compiling sketch ..." );
1822
1826
1823
1827
// do this to advance/clear the terminal window / dos prompt / etc
1824
1828
for (int i = 0 ; i < 10 ; i ++) System .out .println ();
@@ -1838,12 +1842,14 @@ class DefaultRunHandler implements Runnable {
1838
1842
public void run () {
1839
1843
try {
1840
1844
sketch .prepare ();
1841
- String appletClassName = sketch .build (false );
1845
+ sketch .build (false );
1842
1846
statusNotice ("Done compiling." );
1843
1847
} catch (Exception e ) {
1848
+ status .unprogress ();
1844
1849
statusError (e );
1845
1850
}
1846
1851
1852
+ status .unprogress ();
1847
1853
toolbar .deactivate (EditorToolbar .RUN );
1848
1854
}
1849
1855
}
@@ -1853,12 +1859,14 @@ class DefaultPresentHandler implements Runnable {
1853
1859
public void run () {
1854
1860
try {
1855
1861
sketch .prepare ();
1856
- String appletClassName = sketch .build (true );
1862
+ sketch .build (true );
1857
1863
statusNotice ("Done compiling." );
1858
1864
} catch (Exception e ) {
1865
+ status .unprogress ();
1859
1866
statusError (e );
1860
1867
}
1861
1868
1869
+ status .unprogress ();
1862
1870
toolbar .deactivate (EditorToolbar .RUN );
1863
1871
}
1864
1872
}
@@ -2311,6 +2319,7 @@ public boolean serialPrompt() {
2311
2319
0 );
2312
2320
if (result == null ) return false ;
2313
2321
selectSerialPort (result );
2322
+ base .onBoardOrPortChange ();
2314
2323
return true ;
2315
2324
}
2316
2325
@@ -2334,7 +2343,7 @@ synchronized public void handleExport(final boolean usingProgrammer) {
2334
2343
//if (!handleExportCheckModified()) return;
2335
2344
toolbar .activate (EditorToolbar .EXPORT );
2336
2345
console .clear ();
2337
- statusNotice ("Uploading to I/O Board..." );
2346
+ status . progress ("Uploading to I/O Board..." );
2338
2347
2339
2348
new Thread (usingProgrammer ? exportAppHandler : exportHandler ).start ();
2340
2349
}
@@ -2363,10 +2372,12 @@ public void run() {
2363
2372
} catch (RunnerException e ) {
2364
2373
//statusError("Error during upload.");
2365
2374
//e.printStackTrace();
2375
+ status .unprogress ();
2366
2376
statusError (e );
2367
2377
} catch (Exception e ) {
2368
2378
e .printStackTrace ();
2369
2379
}
2380
+ status .unprogress ();
2370
2381
uploading = false ;
2371
2382
//toolbar.clear();
2372
2383
toolbar .deactivate (EditorToolbar .EXPORT );
@@ -2397,10 +2408,12 @@ public void run() {
2397
2408
} catch (RunnerException e ) {
2398
2409
//statusError("Error during upload.");
2399
2410
//e.printStackTrace();
2411
+ status .unprogress ();
2400
2412
statusError (e );
2401
2413
} catch (Exception e ) {
2402
2414
e .printStackTrace ();
2403
2415
}
2416
+ status .unprogress ();
2404
2417
uploading = false ;
2405
2418
//toolbar.clear();
2406
2419
toolbar .deactivate (EditorToolbar .EXPORT );
@@ -2615,110 +2628,141 @@ public void statusEmpty() {
2615
2628
2616
2629
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2617
2630
2631
+ protected void onBoardOrPortChange () {
2632
+ Map <String , String > boardPreferences = Base .getBoardPreferences ();
2633
+ lineStatus .setBoardName (boardPreferences .get ("name" ));
2634
+ lineStatus .setSerialPort (Preferences .get ("serial.port" ));
2635
+ lineStatus .repaint ();
2636
+ }
2618
2637
2638
+
2619
2639
/**
2620
2640
* Returns the edit popup menu.
2621
2641
*/
2622
2642
class TextAreaPopup extends JPopupMenu {
2623
- //String currentDir = System.getProperty("user.dir");
2624
- String referenceFile = null ;
2643
+ //private String currentDir = System.getProperty("user.dir");
2644
+ private String referenceFile = null ;
2625
2645
2626
- JMenuItem cutItem ;
2627
- JMenuItem copyItem ;
2628
- JMenuItem discourseItem ;
2629
- JMenuItem referenceItem ;
2646
+ private JMenuItem cutItem ;
2647
+ private JMenuItem copyItem ;
2648
+ private JMenuItem discourseItem ;
2649
+ private JMenuItem referenceItem ;
2650
+ private JMenuItem openURLItem ;
2651
+ private JSeparator openURLItemSeparator ;
2630
2652
2653
+ private String clickedURL ;
2631
2654
2632
2655
public TextAreaPopup () {
2633
- JMenuItem item ;
2634
-
2656
+ openURLItem = new JMenuItem ("Open URL" );
2657
+ openURLItem .addActionListener (new ActionListener () {
2658
+ public void actionPerformed (ActionEvent e ) {
2659
+ Base .openURL (clickedURL );
2660
+ }
2661
+ });
2662
+ add (openURLItem );
2663
+
2664
+ openURLItemSeparator = new JSeparator ();
2665
+ add (openURLItemSeparator );
2666
+
2635
2667
cutItem = new JMenuItem ("Cut" );
2636
2668
cutItem .addActionListener (new ActionListener () {
2637
2669
public void actionPerformed (ActionEvent e ) {
2638
2670
handleCut ();
2639
2671
}
2640
2672
});
2641
- this . add (cutItem );
2673
+ add (cutItem );
2642
2674
2643
2675
copyItem = new JMenuItem ("Copy" );
2644
2676
copyItem .addActionListener (new ActionListener () {
2645
2677
public void actionPerformed (ActionEvent e ) {
2646
2678
handleCopy ();
2647
2679
}
2648
2680
});
2649
- this . add (copyItem );
2681
+ add (copyItem );
2650
2682
2651
2683
discourseItem = new JMenuItem ("Copy for Forum" );
2652
2684
discourseItem .addActionListener (new ActionListener () {
2653
2685
public void actionPerformed (ActionEvent e ) {
2654
2686
handleDiscourseCopy ();
2655
2687
}
2656
2688
});
2657
- this . add (discourseItem );
2689
+ add (discourseItem );
2658
2690
2659
2691
discourseItem = new JMenuItem ("Copy as HTML" );
2660
2692
discourseItem .addActionListener (new ActionListener () {
2661
2693
public void actionPerformed (ActionEvent e ) {
2662
2694
handleHTMLCopy ();
2663
2695
}
2664
2696
});
2665
- this . add (discourseItem );
2697
+ add (discourseItem );
2666
2698
2667
- item = new JMenuItem ("Paste" );
2699
+ JMenuItem item = new JMenuItem ("Paste" );
2668
2700
item .addActionListener (new ActionListener () {
2669
2701
public void actionPerformed (ActionEvent e ) {
2670
2702
handlePaste ();
2671
2703
}
2672
2704
});
2673
- this . add (item );
2705
+ add (item );
2674
2706
2675
2707
item = new JMenuItem ("Select All" );
2676
2708
item .addActionListener (new ActionListener () {
2677
2709
public void actionPerformed (ActionEvent e ) {
2678
2710
handleSelectAll ();
2679
2711
}
2680
2712
});
2681
- this . add (item );
2713
+ add (item );
2682
2714
2683
- this . addSeparator ();
2715
+ addSeparator ();
2684
2716
2685
2717
item = new JMenuItem ("Comment/Uncomment" );
2686
2718
item .addActionListener (new ActionListener () {
2687
2719
public void actionPerformed (ActionEvent e ) {
2688
2720
handleCommentUncomment ();
2689
2721
}
2690
2722
});
2691
- this . add (item );
2723
+ add (item );
2692
2724
2693
2725
item = new JMenuItem ("Increase Indent" );
2694
2726
item .addActionListener (new ActionListener () {
2695
2727
public void actionPerformed (ActionEvent e ) {
2696
2728
handleIndentOutdent (true );
2697
2729
}
2698
2730
});
2699
- this . add (item );
2731
+ add (item );
2700
2732
2701
2733
item = new JMenuItem ("Decrease Indent" );
2702
2734
item .addActionListener (new ActionListener () {
2703
2735
public void actionPerformed (ActionEvent e ) {
2704
2736
handleIndentOutdent (false );
2705
2737
}
2706
2738
});
2707
- this . add (item );
2739
+ add (item );
2708
2740
2709
- this . addSeparator ();
2741
+ addSeparator ();
2710
2742
2711
2743
referenceItem = new JMenuItem ("Find in Reference" );
2712
2744
referenceItem .addActionListener (new ActionListener () {
2713
2745
public void actionPerformed (ActionEvent e ) {
2714
2746
handleFindReference ();
2715
2747
}
2716
2748
});
2717
- this . add (referenceItem );
2749
+ add (referenceItem );
2718
2750
}
2719
2751
2720
2752
// if no text is selected, disable copy and cut menu items
2721
2753
public void show (Component component , int x , int y ) {
2754
+ int lineNo = textarea .getLineOfOffset (textarea .xyToOffset (x , y ));
2755
+ int offset = textarea .xToOffset (lineNo , x );
2756
+ String line = textarea .getLineText (lineNo );
2757
+ clickedURL = textarea .checkClickedURL (line , offset );
2758
+ if (clickedURL != null ) {
2759
+ openURLItem .setVisible (true );
2760
+ openURLItemSeparator .setVisible (true );
2761
+ } else {
2762
+ openURLItem .setVisible (false );
2763
+ openURLItemSeparator .setVisible (false );
2764
+ }
2765
+
2722
2766
if (textarea .isSelectionActive ()) {
2723
2767
cutItem .setEnabled (true );
2724
2768
copyItem .setEnabled (true );
0 commit comments