2323
2424package processing .app ;
2525
26- import java .awt .*;
26+ import java .awt .BorderLayout ;
27+ import java .awt .Color ;
28+ import java .awt .Dimension ;
29+ import java .awt .Font ;
30+ import java .awt .FontMetrics ;
31+ import java .awt .Graphics ;
32+ import java .awt .Image ;
2733import java .awt .event .*;
34+ import java .util .ArrayList ;
35+ import java .util .Arrays ;
36+ import java .util .List ;
2837
2938import javax .swing .Box ;
3039import javax .swing .JLabel ;
@@ -42,7 +51,7 @@ abstract public class EditorToolbar extends JPanel {
4251 // horizontal gap between buttons
4352 static final int GAP = 9 ;
4453 // gap from the run button to the sketch label
45- static final int LABEL_GAP = GAP ;
54+ // static final int LABEL_GAP = GAP;
4655
4756 protected Editor editor ;
4857 protected Base base ;
@@ -66,42 +75,28 @@ public EditorToolbar(Editor editor) {
6675 base = editor .getBase ();
6776 mode = editor .getMode ();
6877
69- //setOpaque(false);
70- //gradient = createGradient();
71- //System.out.println(gradient);
72-
7378 gradient = mode .getGradient ("toolbar" , 400 , HIGH );
7479// reverseGradient = mode.getGradient("reversed", 100, EditorButton.DIM);
7580
76- runButton = new EditorButton (mode ,
77- "/lib/toolbar/run" ,
78- Language .text ("toolbar.run" ),
79- Language .text ("toolbar.present" )) {
80-
81- @ Override
82- public void actionPerformed (ActionEvent e ) {
83- handleRun (e .getModifiers ());
84- }
85- };
81+ rebuild ();
82+ }
8683
87- stopButton = new EditorButton (mode ,
88- "/lib/toolbar/stop" ,
89- Language .text ("toolbar.stop" )) {
9084
91- @ Override
92- public void actionPerformed (ActionEvent e ) {
93- handleStop ();
94- }
95- };
85+ public void rebuild () {
86+ removeAll (); // remove previous components, if any
87+ List <EditorButton > buttons = createButtons ();
9688
9789 box = Box .createHorizontalBox ();
9890 box .add (Box .createHorizontalStrut (Editor .LEFT_GUTTER ));
9991
100- box .add (runButton );
101- box .add (Box .createHorizontalStrut (GAP ));
102- box .add (stopButton );
92+ for (EditorButton button : buttons ) {
93+ box .add (button );
94+ box .add (Box .createHorizontalStrut (GAP ));
95+ }
96+ // // remove the last gap
97+ // box.remove(box.getComponentCount() - 1);
10398
104- box .add (Box .createHorizontalStrut (LABEL_GAP ));
99+ // box.add(Box.createHorizontalStrut(LABEL_GAP));
105100 label = new JLabel ();
106101 label .setFont (mode .getFont ("toolbar.rollover.font" ));
107102 label .setForeground (mode .getColor ("toolbar.rollover.color" ));
@@ -144,6 +139,29 @@ public void paintComponent(Graphics g) {
144139 }
145140
146141
142+ public List <EditorButton > createButtons () {
143+ runButton = new EditorButton (mode ,
144+ "/lib/toolbar/run" ,
145+ Language .text ("toolbar.run" ),
146+ Language .text ("toolbar.present" )) {
147+ @ Override
148+ public void actionPerformed (ActionEvent e ) {
149+ handleRun (e .getModifiers ());
150+ }
151+ };
152+
153+ stopButton = new EditorButton (mode ,
154+ "/lib/toolbar/stop" ,
155+ Language .text ("toolbar.stop" )) {
156+ @ Override
157+ public void actionPerformed (ActionEvent e ) {
158+ handleStop ();
159+ }
160+ };
161+ return new ArrayList <>(Arrays .asList (runButton , stopButton ));
162+ }
163+
164+
147165 public void addModeButtons (Box box ) {
148166 }
149167
0 commit comments