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 ;
@@ -1838,7 +1839,7 @@ class DefaultRunHandler implements Runnable {
1838
1839
public void run () {
1839
1840
try {
1840
1841
sketch .prepare ();
1841
- String appletClassName = sketch .build (false );
1842
+ sketch .build (false );
1842
1843
statusNotice ("Done compiling." );
1843
1844
} catch (Exception e ) {
1844
1845
status .unprogress ();
@@ -1855,7 +1856,7 @@ class DefaultPresentHandler implements Runnable {
1855
1856
public void run () {
1856
1857
try {
1857
1858
sketch .prepare ();
1858
- String appletClassName = sketch .build (true );
1859
+ sketch .build (true );
1859
1860
statusNotice ("Done compiling." );
1860
1861
} catch (Exception e ) {
1861
1862
status .unprogress ();
@@ -2628,105 +2629,138 @@ public void statusEmpty() {
2628
2629
* Returns the edit popup menu.
2629
2630
*/
2630
2631
class TextAreaPopup extends JPopupMenu {
2631
- //String currentDir = System.getProperty("user.dir");
2632
- String referenceFile = null ;
2632
+ //private String currentDir = System.getProperty("user.dir");
2633
+ private String referenceFile = null ;
2633
2634
2634
- JMenuItem cutItem ;
2635
- JMenuItem copyItem ;
2636
- JMenuItem discourseItem ;
2637
- JMenuItem referenceItem ;
2635
+ private JMenuItem cutItem ;
2636
+ private JMenuItem copyItem ;
2637
+ private JMenuItem discourseItem ;
2638
+ private JMenuItem referenceItem ;
2639
+ private JMenuItem openURLItem ;
2640
+ private JSeparator openURLItemSeparator ;
2638
2641
2642
+ private String clickedURL ;
2639
2643
2640
2644
public TextAreaPopup () {
2641
- JMenuItem item ;
2642
-
2645
+ openURLItem = new JMenuItem ("Open URL" );
2646
+ openURLItem .addActionListener (new ActionListener () {
2647
+ @ Override
2648
+ public void actionPerformed (ActionEvent e ) {
2649
+ Base .openURL (clickedURL );
2650
+ }
2651
+ });
2652
+ add (openURLItem );
2653
+
2654
+ openURLItemSeparator = new JSeparator ();
2655
+ add (openURLItemSeparator );
2656
+
2643
2657
cutItem = new JMenuItem ("Cut" );
2644
2658
cutItem .addActionListener (new ActionListener () {
2645
2659
public void actionPerformed (ActionEvent e ) {
2646
2660
handleCut ();
2647
2661
}
2648
2662
});
2649
- this . add (cutItem );
2663
+ add (cutItem );
2650
2664
2651
2665
copyItem = new JMenuItem ("Copy" );
2652
2666
copyItem .addActionListener (new ActionListener () {
2653
2667
public void actionPerformed (ActionEvent e ) {
2654
2668
handleCopy ();
2655
2669
}
2656
2670
});
2657
- this . add (copyItem );
2671
+ add (copyItem );
2658
2672
2659
2673
discourseItem = new JMenuItem ("Copy for Forum" );
2660
2674
discourseItem .addActionListener (new ActionListener () {
2661
2675
public void actionPerformed (ActionEvent e ) {
2662
2676
handleDiscourseCopy ();
2663
2677
}
2664
2678
});
2665
- this . add (discourseItem );
2679
+ add (discourseItem );
2666
2680
2667
2681
discourseItem = new JMenuItem ("Copy as HTML" );
2668
2682
discourseItem .addActionListener (new ActionListener () {
2669
2683
public void actionPerformed (ActionEvent e ) {
2670
2684
handleHTMLCopy ();
2671
2685
}
2672
2686
});
2673
- this . add (discourseItem );
2687
+ add (discourseItem );
2674
2688
2675
- item = new JMenuItem ("Paste" );
2689
+ JMenuItem item = new JMenuItem ("Paste" );
2676
2690
item .addActionListener (new ActionListener () {
2677
2691
public void actionPerformed (ActionEvent e ) {
2678
2692
handlePaste ();
2679
2693
}
2680
2694
});
2681
- this . add (item );
2695
+ add (item );
2682
2696
2683
2697
item = new JMenuItem ("Select All" );
2684
2698
item .addActionListener (new ActionListener () {
2685
2699
public void actionPerformed (ActionEvent e ) {
2686
2700
handleSelectAll ();
2687
2701
}
2688
2702
});
2689
- this . add (item );
2703
+ add (item );
2690
2704
2691
- this . addSeparator ();
2705
+ addSeparator ();
2692
2706
2693
2707
item = new JMenuItem ("Comment/Uncomment" );
2694
2708
item .addActionListener (new ActionListener () {
2695
2709
public void actionPerformed (ActionEvent e ) {
2696
2710
handleCommentUncomment ();
2697
2711
}
2698
2712
});
2699
- this . add (item );
2713
+ add (item );
2700
2714
2701
2715
item = new JMenuItem ("Increase Indent" );
2702
2716
item .addActionListener (new ActionListener () {
2703
2717
public void actionPerformed (ActionEvent e ) {
2704
2718
handleIndentOutdent (true );
2705
2719
}
2706
2720
});
2707
- this . add (item );
2721
+ add (item );
2708
2722
2709
2723
item = new JMenuItem ("Decrease Indent" );
2710
2724
item .addActionListener (new ActionListener () {
2711
2725
public void actionPerformed (ActionEvent e ) {
2712
2726
handleIndentOutdent (false );
2713
2727
}
2714
2728
});
2715
- this . add (item );
2729
+ add (item );
2716
2730
2717
- this . addSeparator ();
2731
+ addSeparator ();
2718
2732
2719
2733
referenceItem = new JMenuItem ("Find in Reference" );
2720
2734
referenceItem .addActionListener (new ActionListener () {
2721
2735
public void actionPerformed (ActionEvent e ) {
2722
2736
handleFindReference ();
2723
2737
}
2724
2738
});
2725
- this . add (referenceItem );
2739
+ add (referenceItem );
2726
2740
}
2727
2741
2742
+ private boolean clickedURL (String line , int offset ) {
2743
+ String [] parse = SyntaxUtilities .parseCommentUrls (line );
2744
+ if (parse ==null )
2745
+ return false ;
2746
+ int pos = parse [0 ].length ()+parse [1 ].length ();
2747
+ if (offset <pos || offset >pos +2 )
2748
+ return false ;
2749
+ clickedURL = parse [1 ];
2750
+ return true ;
2751
+ }
2752
+
2728
2753
// if no text is selected, disable copy and cut menu items
2729
2754
public void show (Component component , int x , int y ) {
2755
+ int line = textarea .getLineOfOffset (textarea .xyToOffset (x , y ));
2756
+ if (clickedURL (textarea .getLineText (line ), textarea .xToOffset (line , x ))) {
2757
+ openURLItem .setVisible (true );
2758
+ openURLItemSeparator .setVisible (true );
2759
+ } else {
2760
+ openURLItem .setVisible (false );
2761
+ openURLItemSeparator .setVisible (false );
2762
+ }
2763
+
2730
2764
if (textarea .isSelectionActive ()) {
2731
2765
cutItem .setEnabled (true );
2732
2766
copyItem .setEnabled (true );
0 commit comments