Skip to content

Commit 85346dc

Browse files
committed
working on new toolbar
1 parent cddd23c commit 85346dc

File tree

11 files changed

+98
-22
lines changed

11 files changed

+98
-22
lines changed

app/src/processing/app/EditorButton.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,19 @@ public boolean isShiftDown() {
144144

145145
@Override
146146
public void mousePressed(MouseEvent e) {
147-
if (isEnabled()) {
148-
pressed = true;
149-
repaint();
150-
}
147+
setPressed(true);
151148
}
152149

153150

154151
@Override
155152
public void mouseReleased(MouseEvent e) {
153+
setPressed(false);
154+
}
155+
156+
157+
public void setPressed(boolean pressed) {
156158
if (isEnabled()) {
157-
pressed = false;
159+
this.pressed = pressed;
158160
repaint();
159161
}
160162
}

app/src/processing/app/EditorToolbar.java

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,93 @@
2323

2424
package processing.app;
2525

26-
//import java.awt.event.ActionEvent;
26+
import java.awt.Component;
27+
import java.awt.event.ActionEvent;
2728

29+
import javax.swing.Box;
30+
import javax.swing.JLabel;
2831
import javax.swing.JPanel;
2932

3033

3134
/**
3235
* Run/Stop button plus Mode selection
3336
*/
34-
public class EditorToolbar extends JPanel {
37+
abstract public class EditorToolbar extends JPanel {
3538
protected Editor editor;
3639
protected Base base;
3740
protected Mode mode;
3841

39-
EditorButton runButton;
40-
EditorButton stopButton;
42+
protected EditorButton runButton;
43+
protected EditorButton stopButton;
44+
45+
protected Box box;
46+
protected JLabel label;
4147

4248

4349
public EditorToolbar(Editor editor) {
4450
this.editor = editor;
4551
base = editor.getBase();
4652
mode = editor.getMode();
4753

48-
// runButton = new EditorButton() {
49-
//
50-
// @Override
51-
// public void actionPerformed(ActionEvent e) {
52-
// // TODO Auto-generated method stub
53-
//
54-
// }
55-
// };
54+
runButton = new EditorButton(mode,
55+
"/lib/toolbar/run",
56+
Language.text("toolbar.run"),
57+
Language.text("toolbar.present")) {
58+
59+
@Override
60+
public void actionPerformed(ActionEvent e) {
61+
handleRun();
62+
}
63+
};
64+
65+
stopButton = new EditorButton(mode,
66+
"/lib/toolbar/stop",
67+
Language.text("toolbar.stop")) {
68+
69+
@Override
70+
public void actionPerformed(ActionEvent e) {
71+
handleStop();
72+
}
73+
};
74+
75+
box = Box.createHorizontalBox();
76+
box.add(runButton);
77+
box.add(label = new JLabel());
78+
box.add(Box.createHorizontalGlue());
79+
80+
Component items = createModeButtons();
81+
if (items != null) {
82+
box.add(items);
83+
}
84+
box.add(createModeSelector());
85+
86+
add(box);
87+
}
88+
89+
90+
public Component createModeButtons() {
91+
return null;
92+
}
93+
94+
95+
public Component createModeSelector() {
96+
return null;
97+
}
98+
99+
100+
protected void swapButton(EditorButton replacement) {
101+
box.remove(0);
102+
box.add(replacement, 0);
103+
box.revalidate();
104+
box.repaint(); // may be needed
56105
}
57106

58107

59108
public void activateRun() {
60-
109+
//runButton.setPressed(true);
110+
// Rectangle bounds = runButton.getBounds();
111+
// remove(runButton);
112+
swapButton(stopButton);
61113
}
62114

63115

@@ -67,13 +119,17 @@ public void deactivateRun() {
67119

68120

69121
public void activateStop() {
70-
71122
}
72123

73124

74-
public void deactivateStop() {
75-
125+
public void deactivateStop() {
126+
swapButton(runButton);
76127
}
128+
129+
130+
abstract public void handleRun();
131+
132+
abstract public void handleStop();
77133
}
78134
//public abstract class EditorToolbar extends JComponent implements MouseInputListener, KeyListener {
79135
//

app/src/processing/app/Mode.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,14 @@ public void run() {
12141214

12151215

12161216
/**
1217-
* Get an ImageIcon object from the mode folder.
1217+
* Get an ImageIcon object from the Mode folder.
1218+
* Or when prefixed with /lib, load it from the main /lib folder.
12181219
* @since 3.0a6
12191220
*/
12201221
public ImageIcon loadIcon(String filename) {
1222+
if (filename.startsWith("/lib/")) {
1223+
return Toolkit.getLibIcon(filename.substring(5));
1224+
}
12211225
File file = new File(folder, filename);
12221226
if (!file.exists()) {
12231227
// EditorConsole.systemErr.println("file does not exist: " + file.getAbsolutePath());
@@ -1230,6 +1234,7 @@ public ImageIcon loadIcon(String filename) {
12301234

12311235
/**
12321236
* Get an image object from the mode folder.
1237+
* Or when prefixed with /lib, load it from the main /lib folder.
12331238
*/
12341239
public Image loadImage(String filename) {
12351240
ImageIcon icon = loadIcon(filename);

0 commit comments

Comments
 (0)