Skip to content

Commit 8ea35d4

Browse files
committed
Merge remote-tracking branch 'cmaglie/schematics-view' into new-extension
2 parents 0fca78c + 88794ec commit 8ea35d4

File tree

9 files changed

+192
-43
lines changed

9 files changed

+192
-43
lines changed

app/src/processing/app/Editor.java

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
/**
4747
* Main editor panel for the Processing Development Environment.
4848
*/
49+
@SuppressWarnings("serial")
4950
public class Editor extends JFrame implements RunnerListener {
5051

5152
Base base;
@@ -113,7 +114,7 @@ public class Editor extends JFrame implements RunnerListener {
113114

114115
EditorLineStatus lineStatus;
115116

116-
JEditorPane editorPane;
117+
//JEditorPane editorPane;
117118

118119
JEditTextArea textarea;
119120
EditorListener listener;
@@ -1838,7 +1839,7 @@ class DefaultRunHandler implements Runnable {
18381839
public void run() {
18391840
try {
18401841
sketch.prepare();
1841-
String appletClassName = sketch.build(false);
1842+
sketch.build(false);
18421843
statusNotice("Done compiling.");
18431844
} catch (Exception e) {
18441845
status.unprogress();
@@ -1855,7 +1856,7 @@ class DefaultPresentHandler implements Runnable {
18551856
public void run() {
18561857
try {
18571858
sketch.prepare();
1858-
String appletClassName = sketch.build(true);
1859+
sketch.build(true);
18591860
statusNotice("Done compiling.");
18601861
} catch (Exception e) {
18611862
status.unprogress();
@@ -2628,105 +2629,130 @@ public void statusEmpty() {
26282629
* Returns the edit popup menu.
26292630
*/
26302631
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;
26332634

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;
26382641

2642+
private String clickedURL;
26392643

26402644
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+
26432657
cutItem = new JMenuItem("Cut");
26442658
cutItem.addActionListener(new ActionListener() {
26452659
public void actionPerformed(ActionEvent e) {
26462660
handleCut();
26472661
}
26482662
});
2649-
this.add(cutItem);
2663+
add(cutItem);
26502664

26512665
copyItem = new JMenuItem("Copy");
26522666
copyItem.addActionListener(new ActionListener() {
26532667
public void actionPerformed(ActionEvent e) {
26542668
handleCopy();
26552669
}
26562670
});
2657-
this.add(copyItem);
2671+
add(copyItem);
26582672

26592673
discourseItem = new JMenuItem("Copy for Forum");
26602674
discourseItem.addActionListener(new ActionListener() {
26612675
public void actionPerformed(ActionEvent e) {
26622676
handleDiscourseCopy();
26632677
}
26642678
});
2665-
this.add(discourseItem);
2679+
add(discourseItem);
26662680

26672681
discourseItem = new JMenuItem("Copy as HTML");
26682682
discourseItem.addActionListener(new ActionListener() {
26692683
public void actionPerformed(ActionEvent e) {
26702684
handleHTMLCopy();
26712685
}
26722686
});
2673-
this.add(discourseItem);
2687+
add(discourseItem);
26742688

2675-
item = new JMenuItem("Paste");
2689+
JMenuItem item = new JMenuItem("Paste");
26762690
item.addActionListener(new ActionListener() {
26772691
public void actionPerformed(ActionEvent e) {
26782692
handlePaste();
26792693
}
26802694
});
2681-
this.add(item);
2695+
add(item);
26822696

26832697
item = new JMenuItem("Select All");
26842698
item.addActionListener(new ActionListener() {
26852699
public void actionPerformed(ActionEvent e) {
26862700
handleSelectAll();
26872701
}
26882702
});
2689-
this.add(item);
2703+
add(item);
26902704

2691-
this.addSeparator();
2705+
addSeparator();
26922706

26932707
item = new JMenuItem("Comment/Uncomment");
26942708
item.addActionListener(new ActionListener() {
26952709
public void actionPerformed(ActionEvent e) {
26962710
handleCommentUncomment();
26972711
}
26982712
});
2699-
this.add(item);
2713+
add(item);
27002714

27012715
item = new JMenuItem("Increase Indent");
27022716
item.addActionListener(new ActionListener() {
27032717
public void actionPerformed(ActionEvent e) {
27042718
handleIndentOutdent(true);
27052719
}
27062720
});
2707-
this.add(item);
2721+
add(item);
27082722

27092723
item = new JMenuItem("Decrease Indent");
27102724
item.addActionListener(new ActionListener() {
27112725
public void actionPerformed(ActionEvent e) {
27122726
handleIndentOutdent(false);
27132727
}
27142728
});
2715-
this.add(item);
2729+
add(item);
27162730

2717-
this.addSeparator();
2731+
addSeparator();
27182732

27192733
referenceItem = new JMenuItem("Find in Reference");
27202734
referenceItem.addActionListener(new ActionListener() {
27212735
public void actionPerformed(ActionEvent e) {
27222736
handleFindReference();
27232737
}
27242738
});
2725-
this.add(referenceItem);
2739+
add(referenceItem);
27262740
}
27272741

27282742
// if no text is selected, disable copy and cut menu items
27292743
public void show(Component component, int x, int y) {
2744+
int lineNo = textarea.getLineOfOffset(textarea.xyToOffset(x, y));
2745+
int offset = textarea.xToOffset(lineNo, x);
2746+
String line = textarea.getLineText(lineNo);
2747+
clickedURL = textarea.checkClickedURL(line, offset);
2748+
if (clickedURL != null) {
2749+
openURLItem.setVisible(true);
2750+
openURLItemSeparator.setVisible(true);
2751+
} else {
2752+
openURLItem.setVisible(false);
2753+
openURLItemSeparator.setVisible(false);
2754+
}
2755+
27302756
if (textarea.isSelectionActive()) {
27312757
cutItem.setEnabled(true);
27322758
copyItem.setEnabled(true);

app/src/processing/app/Preferences.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,9 @@ static public SyntaxStyle getStyle(String what /*, String dflt*/) {
772772
s = st.nextToken();
773773
boolean bold = (s.indexOf("bold") != -1);
774774
boolean italic = (s.indexOf("italic") != -1);
775+
boolean underlined = (s.indexOf("underlined") != -1);
775776
//System.out.println(what + " = " + str + " " + bold + " " + italic);
776777

777-
return new SyntaxStyle(color, italic, bold);
778+
return new SyntaxStyle(color, italic, bold, underlined);
778779
}
779780
}

app/src/processing/app/Theme.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ static public SyntaxStyle getStyle(String what) {
196196
s = st.nextToken();
197197
boolean bold = (s.indexOf("bold") != -1);
198198
boolean italic = (s.indexOf("italic") != -1);
199+
boolean underlined = (s.indexOf("underlined") != -1);
199200

200-
return new SyntaxStyle(color, italic, bold);
201+
return new SyntaxStyle(color, italic, bold, underlined);
201202
}
202203
}

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,17 @@ public void focusLost(FocusEvent evt)
20452045
}
20462046
}
20472047

2048+
public String checkClickedURL(String line, int offset) {
2049+
String[] parse = SyntaxUtilities.parseCommentUrls(line);
2050+
if (parse==null)
2051+
return null;
2052+
int start = parse[0].length();
2053+
int stop = start + parse[1].length();
2054+
if (offset<start|| offset>stop)
2055+
return null;
2056+
return parse[1];
2057+
}
2058+
20482059
class MouseHandler extends MouseAdapter
20492060
{
20502061
public void mousePressed(MouseEvent evt)
@@ -2111,6 +2122,13 @@ private void doDoubleClick(MouseEvent evt, int line,
21112122
if (getLineLength(line) == 0)
21122123
return;
21132124

2125+
// Check for click on urls
2126+
String clickedURL = checkClickedURL(getLineText(line), offset);
2127+
if (clickedURL != null) {
2128+
Base.openURL(clickedURL);
2129+
return;
2130+
}
2131+
21142132
try {
21152133
int bracket = TextUtilities.findMatchingBracket(document,
21162134
Math.max(0,dot - 1));

app/src/processing/app/syntax/PdeTextAreaDefaults.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public PdeTextAreaDefaults() {
169169
// ??
170170
styles[Token.LABEL] = Theme.getStyle("label");
171171

172+
// http://arduino.cc/
173+
styles[Token.URL] = Theme.getStyle("url");
174+
172175
// + - = /
173176
styles[Token.OPERATOR] = Theme.getStyle("operator");
174177

app/src/processing/app/syntax/SyntaxStyle.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
package processing.app.syntax;
1111

1212
import java.awt.*;
13+
import java.awt.font.TextAttribute;
14+
import java.util.Hashtable;
15+
import java.util.Map;
16+
1317
import javax.swing.JComponent;
1418

1519

@@ -27,11 +31,12 @@ public class SyntaxStyle
2731
* @param italic True if the text should be italics
2832
* @param bold True if the text should be bold
2933
*/
30-
public SyntaxStyle(Color color, boolean italic, boolean bold)
34+
public SyntaxStyle(Color color, boolean italic, boolean bold, boolean underlined)
3135
{
3236
this.color = color;
3337
this.italic = italic;
3438
this.bold = bold;
39+
this.underlined = underlined;
3540
}
3641

3742
/**
@@ -47,7 +52,7 @@ public Color getColor()
4752
*/
4853
public boolean isPlain()
4954
{
50-
return !(bold || italic);
55+
return !(bold || italic || underlined);
5156
}
5257

5358
/**
@@ -67,7 +72,14 @@ public boolean isBold()
6772
}
6873

6974
/**
70-
* Returns the specified font, but with the style's bold and
75+
* @return true if underline is enabled for this style.
76+
*/
77+
public boolean isUnderlined() {
78+
return underlined;
79+
}
80+
81+
/**
82+
* Returns the specified font, but with the style's bold, underline and
7183
* italic flags applied.
7284
*/
7385
public Font getStyledFont(Font font)
@@ -78,10 +90,16 @@ public Font getStyledFont(Font font)
7890
if(font.equals(lastFont))
7991
return lastStyledFont;
8092
lastFont = font;
93+
8194
lastStyledFont = new Font(font.getFamily(),
8295
(bold ? Font.BOLD : 0)
8396
| (italic ? Font.ITALIC : 0),
8497
font.getSize());
98+
if (underlined) {
99+
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
100+
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
101+
lastStyledFont = lastStyledFont.deriveFont(attr);
102+
}
85103
return lastStyledFont;
86104
}
87105

@@ -100,6 +118,11 @@ public FontMetrics getFontMetrics(Font font, JComponent comp)
100118
(bold ? Font.BOLD : 0)
101119
| (italic ? Font.ITALIC : 0),
102120
font.getSize());
121+
if (underlined) {
122+
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
123+
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
124+
lastStyledFont = lastStyledFont.deriveFont(attr);
125+
}
103126
//fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont);
104127
fontMetrics = comp.getFontMetrics(lastStyledFont);
105128
return fontMetrics;
@@ -125,13 +148,16 @@ public String toString()
125148
{
126149
return getClass().getName() + "[color=" + color +
127150
(italic ? ",italic" : "") +
128-
(bold ? ",bold" : "") + "]";
151+
(bold ? ",bold" : "") +
152+
(underlined ? ",underlined" : "") +
153+
"]";
129154
}
130155

131156
// private members
132157
private Color color;
133158
private boolean italic;
134159
private boolean bold;
160+
private boolean underlined;
135161
private Font lastFont;
136162
private Font lastStyledFont;
137163
private FontMetrics fontMetrics;

0 commit comments

Comments
 (0)