| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,17 +144,19 @@ public boolean isShiftDown() { | |||
| 144 | 144 | ||
| 145 | 145 | @Override | |
| 146 | 146 | public void mousePressed(MouseEvent e) { | |
| 147 | - if (isEnabled()) { | ||
| 148 | - pressed = true; | ||
| 149 | - repaint(); | ||
| 150 | - } | ||
| 147 | + setPressed(true); | ||
| 151 | 148 | } | |
| 152 | 149 | ||
| 153 | 150 | ||
| 154 | 151 | @Override | |
| 155 | 152 | public void mouseReleased(MouseEvent e) { | |
| 153 | + setPressed(false); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + | ||
| 157 | + public void setPressed(boolean pressed) { | ||
| 156 | 158 | if (isEnabled()) { | |
| 157 | - pressed = false; | ||
| 159 | + this.pressed = pressed; | ||
| 158 | 160 | repaint(); | |
| 159 | 161 | } | |
| 160 | 162 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,41 +23,93 @@ | |||
| 23 | 23 | ||
| 24 | 24 | package processing.app; | |
| 25 | 25 | ||
| 26 | - //import java.awt.event.ActionEvent; | ||
| 26 | + import java.awt.Component; | ||
| 27 | + import java.awt.event.ActionEvent; | ||
| 27 | 28 | ||
| 29 | + import javax.swing.Box; | ||
| 30 | + import javax.swing.JLabel; | ||
| 28 | 31 | import javax.swing.JPanel; | |
| 29 | 32 | ||
| 30 | 33 | ||
| 31 | 34 | /** | |
| 32 | 35 | * Run/Stop button plus Mode selection | |
| 33 | 36 | */ | |
| 34 | - public class EditorToolbar extends JPanel { | ||
| 37 | + abstract public class EditorToolbar extends JPanel { | ||
| 35 | 38 | protected Editor editor; | |
| 36 | 39 | protected Base base; | |
| 37 | 40 | protected Mode mode; | |
| 38 | 41 | ||
| 39 | - EditorButton runButton; | ||
| 40 | - EditorButton stopButton; | ||
| 42 | + protected EditorButton runButton; | ||
| 43 | + protected EditorButton stopButton; | ||
| 44 | + | ||
| 45 | + protected Box box; | ||
| 46 | + protected JLabel label; | ||
| 41 | 47 | ||
| 42 | 48 | ||
| 43 | 49 | public EditorToolbar(Editor editor) { | |
| 44 | 50 | this.editor = editor; | |
| 45 | 51 | base = editor.getBase(); | |
| 46 | 52 | mode = editor.getMode(); | |
| 47 | 53 | ||
| 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 | ||
| 56 | 105 | } | |
| 57 | 106 | ||
| 58 | 107 | ||
| 59 | 108 | public void activateRun() { | |
| 60 | - | ||
| 109 | + //runButton.setPressed(true); | ||
| 110 | + // Rectangle bounds = runButton.getBounds(); | ||
| 111 | + // remove(runButton); | ||
| 112 | + swapButton(stopButton); | ||
| 61 | 113 | } | |
| 62 | 114 | ||
| 63 | 115 | ||
@@ -67,13 +119,17 @@ public void deactivateRun() { | |||
| 67 | 119 | ||
| 68 | 120 | ||
| 69 | 121 | public void activateStop() { | |
| 70 | - | ||
| 71 | 122 | } | |
| 72 | 123 | ||
| 73 | 124 | ||
| 74 | - public void deactivateStop() { | ||
| 75 | - | ||
| 125 | + public void deactivateStop() { | ||
| 126 | + swapButton(runButton); | ||
| 76 | 127 | } | |
| 128 | + | ||
| 129 | + | ||
| 130 | + abstract public void handleRun(); | ||
| 131 | + | ||
| 132 | + abstract public void handleStop(); | ||
| 77 | 133 | } | |
| 78 | 134 | //public abstract class EditorToolbar extends JComponent implements MouseInputListener, KeyListener { | |
| 79 | 135 | // | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1214,10 +1214,14 @@ public void run() { | |||
| 1214 | 1214 | ||
| 1215 | 1215 | ||
| 1216 | 1216 | /** | |
| 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. | ||
| 1218 | 1219 | * @since 3.0a6 | |
| 1219 | 1220 | */ | |
| 1220 | 1221 | public ImageIcon loadIcon(String filename) { | |
| 1222 | + if (filename.startsWith("/lib/")) { | ||
| 1223 | + return Toolkit.getLibIcon(filename.substring(5)); | ||
| 1224 | + } | ||
| 1221 | 1225 | File file = new File(folder, filename); | |
| 1222 | 1226 | if (!file.exists()) { | |
| 1223 | 1227 | // EditorConsole.systemErr.println("file does not exist: " + file.getAbsolutePath()); | |
@@ -1230,6 +1234,7 @@ public ImageIcon loadIcon(String filename) { | |||
| 1230 | 1234 | ||
| 1231 | 1235 | /** | |
| 1232 | 1236 | * Get an image object from the mode folder. | |
| 1237 | + * Or when prefixed with /lib, load it from the main /lib folder. | ||
| 1233 | 1238 | */ | |
| 1234 | 1239 | public Image loadImage(String filename) { | |
| 1235 | 1240 | ImageIcon icon = loadIcon(filename); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments