Skip to content

Commit 71dd5dd

Browse files
committed
Selected board and serial port on status bar.
1 parent 8059abe commit 71dd5dd

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

app/src/processing/app/Base.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,13 @@ public void rebuildExamplesMenu(JMenu menu) {
993993
}
994994

995995

996+
public void onBoardOrPortChange() {
997+
for (Editor editor : editors) {
998+
editor.onBoardOrPortChange();
999+
}
1000+
}
1001+
1002+
9961003
public void rebuildBoardsMenu(JMenu menu) {
9971004
//System.out.println("rebuilding boards menu");
9981005
menu.removeAll();
@@ -1005,6 +1012,7 @@ public void actionPerformed(ActionEvent actionevent) {
10051012
//System.out.println("Switching to " + target + ":" + board);
10061013
Preferences.set("target", (String) getValue("target"));
10071014
Preferences.set("board", (String) getValue("board"));
1015+
onBoardOrPortChange();
10081016
}
10091017
};
10101018
action.putValue("target", target.getName());

app/src/processing/app/Editor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ class SerialMenuListener implements ActionListener {
907907

908908
public void actionPerformed(ActionEvent e) {
909909
selectSerialPort(((JCheckBoxMenuItem)e.getSource()).getText());
910+
base.onBoardOrPortChange();
910911
}
911912

912913
/*
@@ -2623,7 +2624,14 @@ public void statusEmpty() {
26232624

26242625
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26252626

2627+
protected void onBoardOrPortChange() {
2628+
Map<String, String> boardPreferences = Base.getBoardPreferences();
2629+
lineStatus.setBoardName(boardPreferences.get("name"));
2630+
lineStatus.setSerialPort(Preferences.get("serial.port"));
2631+
lineStatus.repaint();
2632+
}
26262633

2634+
26272635
/**
26282636
* Returns the edit popup menu.
26292637
*/

app/src/processing/app/EditorLineStatus.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import processing.app.syntax.*;
2626

2727
import java.awt.*;
28+
import java.awt.geom.Rectangle2D;
29+
import java.util.Map;
30+
2831
import javax.swing.*;
2932

3033

@@ -39,10 +42,14 @@ public class EditorLineStatus extends JComponent {
3942

4043
Color foreground;
4144
Color background;
45+
Color messageForeground;
46+
4247
Font font;
4348
int high;
4449

4550
String text = "";
51+
String name = "";
52+
String serialport = "";
4653

4754

4855
public EditorLineStatus(JEditTextArea textarea) {
@@ -87,6 +94,11 @@ public void set(int newStart, int newStop) {
8794

8895

8996
public void paintComponent(Graphics g) {
97+
if (name=="" && serialport=="") {
98+
Map<String, String> boardPreferences = Base.getBoardPreferences();
99+
setBoardName(boardPreferences.get("name"));
100+
setSerialPort(Preferences.get("serial.port"));
101+
}
90102
g.setColor(background);
91103
Dimension size = getSize();
92104
g.fillRect(0, 0, size.width, size.height);
@@ -96,11 +108,20 @@ public void paintComponent(Graphics g) {
96108
int baseline = (high + g.getFontMetrics().getAscent()) / 2;
97109
g.drawString(text, 6, baseline);
98110

111+
g.setColor(messageForeground);
112+
String tmp = "board: " + name + " on " + serialport;
113+
114+
Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null);
115+
116+
g.drawString(tmp, size.width - (int) bounds.getWidth() -20 , baseline);
117+
99118
if (Base.isMacOS()) {
100119
g.drawImage(resize, size.width - 20, 0, this);
101120
}
102121
}
103122

123+
public void setBoardName(String name) { this.name = name; }
124+
public void setSerialPort(String serialport) { this.serialport = serialport; }
104125

105126
public Dimension getPreferredSize() {
106127
return new Dimension(300, high);

0 commit comments

Comments
 (0)