| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,8 @@ | |||
| 38 | 38 | import java.util.Timer; | |
| 39 | 39 | ||
| 40 | 40 | import javax.swing.*; | |
| 41 | + import javax.swing.border.Border; | ||
| 42 | + import javax.swing.border.EmptyBorder; | ||
| 41 | 43 | import javax.swing.event.*; | |
| 42 | 44 | import javax.swing.plaf.basic.BasicSplitPaneDivider; | |
| 43 | 45 | import javax.swing.plaf.basic.BasicSplitPaneUI; | |
@@ -172,7 +174,9 @@ public void windowDeactivated(WindowEvent e) { | |||
| 172 | 174 | ||
| 173 | 175 | buildMenuBar(); | |
| 174 | 176 | ||
| 175 | - backgroundGradient = Toolkit.getLibImage("vertical-gradient.png"); | ||
| 177 | + /* | ||
| 178 | + //backgroundGradient = Toolkit.getLibImage("vertical-gradient.png"); | ||
| 179 | + backgroundGradient = mode.getGradient("editor", 400, 400); | ||
| 176 | 180 | JPanel contentPain = new JPanel() { | |
| 177 | 181 | @Override | |
| 178 | 182 | public void paintComponent(Graphics g) { | |
@@ -183,8 +187,10 @@ public void paintComponent(Graphics g) { | |||
| 183 | 187 | // g.fillRect(0, 0, dim.width, dim.height); | |
| 184 | 188 | } | |
| 185 | 189 | }; | |
| 190 | + */ | ||
| 186 | 191 | //contentPain.setBorder(new EmptyBorder(0, 0, 0, 0)); | |
| 187 | 192 | //System.out.println(contentPain.getBorder()); | |
| 193 | + JPanel contentPain = new JPanel(); | ||
| 188 | 194 | ||
| 189 | 195 | // JFrame f = new JFrame(); | |
| 190 | 196 | // f.setContentPane(new JPanel() { | |
@@ -207,6 +213,7 @@ public void paintComponent(Graphics g) { | |||
| 207 | 213 | // pain.setOpaque(false); | |
| 208 | 214 | // pain.setLayout(new BorderLayout()); | |
| 209 | 215 | // contentPain.add(pain, BorderLayout.CENTER); | |
| 216 | + // contentPain.setBorder(new EmptyBorder(10, 10, 10, 10)); | ||
| 210 | 217 | ||
| 211 | 218 | Box box = Box.createVerticalBox(); | |
| 212 | 219 | Box upper = Box.createVerticalBox(); | |
@@ -257,21 +264,20 @@ public void paintComponent(Graphics g) { | |||
| 257 | 264 | // remove any ugly borders added by PLAFs | |
| 258 | 265 | splitPane.setBorder(null); | |
| 259 | 266 | // necessary to let the gradient show through | |
| 260 | - splitPane.setOpaque(false); | ||
| 261 | - | ||
| 267 | + // splitPane.setOpaque(false); | ||
| 268 | + | ||
| 269 | + // remove an ugly border around anything in a SplitPane !$*&!% | ||
| 270 | + UIManager.getDefaults().put("SplitPane.border", BorderFactory.createEmptyBorder()); | ||
| 271 | + // override the look of the SplitPane so that it's identical across OSes | ||
| 262 | 272 | splitPane.setUI(new BasicSplitPaneUI() { | |
| 263 | 273 | public BasicSplitPaneDivider createDefaultDivider() { | |
| 264 | 274 | return new BasicSplitPaneDivider(this) { | |
| 265 | 275 | final Color dividerColor = mode.getColor("divider.color"); //new Color(204, 204, 204); | |
| 266 | 276 | final Color dotColor = mode.getColor("divider.dot.color"); //new Color(80, 80, 80); | |
| 267 | 277 | int dotSize = mode.getInteger("divider.dot.diameter"); //3; | |
| 268 | 278 | ||
| 269 | - //public void setBorder(Border b) { } | ||
| 270 | - | ||
| 271 | 279 | @Override | |
| 272 | 280 | public void paint(Graphics g) { | |
| 273 | - //Graphics2D g2 = Toolkit.prepareGraphics(g); | ||
| 274 | - //Toolkit.prepareGraphics(g); | ||
| 275 | 281 | Graphics2D g2 = (Graphics2D) g; | |
| 276 | 282 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |
| 277 | 283 | RenderingHints.VALUE_ANTIALIAS_ON); | |
@@ -284,10 +290,7 @@ public void paint(Graphics g) { | |||
| 284 | 290 | g.setColor(dotColor); | |
| 285 | 291 | int x = w/2 - dotSize/2; | |
| 286 | 292 | int y = h/2 - dotSize/2; | |
| 287 | - //g2.fillOval(x, y, width, height); | ||
| 288 | 293 | g.fillOval(x, y, dotSize, dotSize); | |
| 289 | - | ||
| 290 | - super.paint(g); | ||
| 291 | 294 | } | |
| 292 | 295 | }; | |
| 293 | 296 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,34 +23,54 @@ | |||
| 23 | 23 | ||
| 24 | 24 | package processing.app; | |
| 25 | 25 | ||
| 26 | - import java.awt.Component; | ||
| 26 | + import java.awt.*; | ||
| 27 | 27 | import java.awt.event.ActionEvent; | |
| 28 | + import java.awt.image.BufferedImage; | ||
| 29 | + import java.awt.image.WritableRaster; | ||
| 30 | + import java.util.Arrays; | ||
| 28 | 31 | ||
| 29 | 32 | import javax.swing.Box; | |
| 30 | 33 | import javax.swing.JLabel; | |
| 31 | 34 | import javax.swing.JPanel; | |
| 32 | 35 | ||
| 36 | + import processing.core.PApplet; | ||
| 37 | + | ||
| 33 | 38 | ||
| 34 | 39 | /** | |
| 35 | 40 | * Run/Stop button plus Mode selection | |
| 36 | 41 | */ | |
| 37 | 42 | abstract public class EditorToolbar extends JPanel { | |
| 43 | + static final int HIGH = 80; | ||
| 44 | + | ||
| 38 | 45 | protected Editor editor; | |
| 39 | 46 | protected Base base; | |
| 40 | 47 | protected Mode mode; | |
| 41 | 48 | ||
| 42 | 49 | protected EditorButton runButton; | |
| 43 | 50 | protected EditorButton stopButton; | |
| 51 | + protected EditorButton currentButton; | ||
| 44 | 52 | ||
| 45 | 53 | protected Box box; | |
| 46 | 54 | protected JLabel label; | |
| 47 | 55 | ||
| 56 | + // int GRADIENT_TOP = 192; | ||
| 57 | + // int GRADIENT_BOTTOM = 246; | ||
| 58 | + protected Image backgroundGradient; | ||
| 59 | + protected Image reverseGradient; | ||
| 60 | + | ||
| 48 | 61 | ||
| 49 | 62 | public EditorToolbar(Editor editor) { | |
| 50 | 63 | this.editor = editor; | |
| 51 | 64 | base = editor.getBase(); | |
| 52 | 65 | mode = editor.getMode(); | |
| 53 | 66 | ||
| 67 | + //setOpaque(false); | ||
| 68 | + //gradient = createGradient(); | ||
| 69 | + //System.out.println(gradient); | ||
| 70 | + | ||
| 71 | + backgroundGradient = mode.getGradient("header", 400, HIGH); | ||
| 72 | + reverseGradient = mode.getGradient("reversed", 100, EditorButton.DIM); | ||
| 73 | + | ||
| 54 | 74 | runButton = new EditorButton(mode, | |
| 55 | 75 | "/lib/toolbar/run", | |
| 56 | 76 | Language.text("toolbar.run"), | |
@@ -74,34 +94,49 @@ public void actionPerformed(ActionEvent e) { | |||
| 74 | 94 | ||
| 75 | 95 | box = Box.createHorizontalBox(); | |
| 76 | 96 | box.add(runButton); | |
| 77 | - box.add(label = new JLabel()); | ||
| 78 | - box.add(Box.createHorizontalGlue()); | ||
| 79 | 97 | ||
| 98 | + label = new JLabel(); | ||
| 99 | + label.setFont(mode.getFont("toolbar.sketch.font")); | ||
| 100 | + label.setForeground(mode.getColor("toolbar.sketch.color")); | ||
| 101 | + box.add(label); | ||
| 102 | + currentButton = runButton; | ||
| 103 | + | ||
| 104 | + box.add(Box.createHorizontalGlue()); | ||
| 80 | 105 | Component items = createModeButtons(); | |
| 81 | 106 | if (items != null) { | |
| 82 | 107 | box.add(items); | |
| 83 | 108 | } | |
| 84 | - box.add(createModeSelector()); | ||
| 85 | - | ||
| 86 | - add(box); | ||
| 109 | + ModeSelector ms = new ModeSelector(); | ||
| 110 | + box.add(ms); | ||
| 111 | + add(box); | ||
| 87 | 112 | } | |
| 88 | 113 | ||
| 89 | 114 | ||
| 90 | - public Component createModeButtons() { | ||
| 91 | - return null; | ||
| 115 | + public void paintComponent(Graphics g) { | ||
| 116 | + // super.paintComponent(g); | ||
| 117 | + Dimension size = getSize(); | ||
| 118 | + g.drawImage(backgroundGradient, 0, 0, size.width, size.height, this); | ||
| 92 | 119 | } | |
| 93 | 120 | ||
| 94 | 121 | ||
| 95 | - public Component createModeSelector() { | ||
| 122 | + public Component createModeButtons() { | ||
| 96 | 123 | return null; | |
| 97 | 124 | } | |
| 98 | - | ||
| 125 | + | ||
| 126 | + | ||
| 127 | + // public Component createModeSelector() { | ||
| 128 | + // return new ModeSelector(); | ||
| 129 | + // } | ||
| 130 | + | ||
| 99 | 131 | ||
| 100 | 132 | protected void swapButton(EditorButton replacement) { | |
| 101 | - box.remove(0); | ||
| 102 | - box.add(replacement, 0); | ||
| 103 | - box.revalidate(); | ||
| 104 | - box.repaint(); // may be needed | ||
| 133 | + if (currentButton != replacement) { | ||
| 134 | + box.remove(0); | ||
| 135 | + box.add(replacement, 0); | ||
| 136 | + box.revalidate(); | ||
| 137 | + box.repaint(); // may be needed | ||
| 138 | + currentButton = replacement; | ||
| 139 | + } | ||
| 105 | 140 | } | |
| 106 | 141 | ||
| 107 | 142 | ||
@@ -129,8 +164,109 @@ public void deactivateStop() { | |||
| 129 | 164 | ||
| 130 | 165 | abstract public void handleRun(); | |
| 131 | 166 | ||
| 167 | + | ||
| 132 | 168 | abstract public void handleStop(); | |
| 169 | + | ||
| 170 | + | ||
| 171 | + class ModeSelector extends JPanel { | ||
| 172 | + Image offscreen; | ||
| 173 | + int width, height; | ||
| 174 | + | ||
| 175 | + String title; | ||
| 176 | + Font titleFont; | ||
| 177 | + Color titleColor; | ||
| 178 | + int titleAscent; | ||
| 179 | + int titleWidth; | ||
| 180 | + | ||
| 181 | + final int MODE_GAP_WIDTH = 13; | ||
| 182 | + final int ARROW_GAP_WIDTH = 6; | ||
| 183 | + final int ARROW_WIDTH = 8; | ||
| 184 | + final int ARROW_TOP = 21; | ||
| 185 | + final int ARROW_BOTTOM = 29; | ||
| 186 | + | ||
| 187 | + int[] triangleX = new int[3]; | ||
| 188 | + int[] triangleY = new int[] { ARROW_TOP, ARROW_TOP, ARROW_BOTTOM }; | ||
| 189 | + | ||
| 190 | + | ||
| 191 | + @SuppressWarnings("deprecation") | ||
| 192 | + public ModeSelector() { | ||
| 193 | + title = mode.getTitle(); //.toUpperCase(); | ||
| 194 | + titleFont = mode.getFont("mode.title.font"); | ||
| 195 | + titleColor = mode.getColor("mode.title.color"); | ||
| 196 | + | ||
| 197 | + // getGraphics() is null and no offscreen yet | ||
| 198 | + titleWidth = getToolkit().getFontMetrics(titleFont).stringWidth(title); | ||
| 199 | + | ||
| 200 | + // setOpaque(false); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + @Override | ||
| 204 | + public void paintComponent(Graphics screen) { | ||
| 205 | + // Toolkit.debugOpacity(this); | ||
| 206 | + | ||
| 207 | + Dimension size = getSize(); | ||
| 208 | + width = 0; | ||
| 209 | + if (width != size.width || height != size.height) { | ||
| 210 | + if (Toolkit.highResDisplay()) { | ||
| 211 | + offscreen = createImage(size.width*2, size.height*2); | ||
| 212 | + } else { | ||
| 213 | + offscreen = createImage(size.width, size.height); | ||
| 214 | + } | ||
| 215 | + width = size.width; | ||
| 216 | + height = size.height; | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + Graphics g = offscreen.getGraphics(); | ||
| 220 | + /*Graphics2D g2 =*/ Toolkit.prepareGraphics(g); | ||
| 221 | + //Toolkit.clearGraphics(g, width, height); | ||
| 222 | + // g.clearRect(0, 0, width, height); | ||
| 223 | + // g.setColor(Color.GREEN); | ||
| 224 | + // g.fillRect(0, 0, width, height); | ||
| 225 | + | ||
| 226 | + g.setFont(titleFont); | ||
| 227 | + if (titleAscent == 0) { | ||
| 228 | + titleAscent = (int) Toolkit.getAscent(g); //metrics.getAscent(); | ||
| 229 | + } | ||
| 230 | + FontMetrics metrics = g.getFontMetrics(); | ||
| 231 | + titleWidth = metrics.stringWidth(title); | ||
| 232 | + | ||
| 233 | + g.drawImage(reverseGradient, 0, 0, width, height, this); | ||
| 234 | + | ||
| 235 | + g.setColor(titleColor); | ||
| 236 | + g.drawString(title, MODE_GAP_WIDTH, (height + titleAscent) / 2); | ||
| 237 | + | ||
| 238 | + int x = MODE_GAP_WIDTH + titleWidth + ARROW_GAP_WIDTH; | ||
| 239 | + triangleX[0] = x; | ||
| 240 | + triangleX[1] = x + ARROW_WIDTH; | ||
| 241 | + triangleX[2] = x + ARROW_WIDTH/2; | ||
| 242 | + g.fillPolygon(triangleX, triangleY, 3); | ||
| 243 | + | ||
| 244 | + // screen.clearRect(0, 0, width, height); | ||
| 245 | + screen.drawImage(offscreen, 0, 0, width, height, this); | ||
| 246 | + // screen.setColor(Color.RED); | ||
| 247 | + // screen.drawRect(0, 0, width-1, height-1); | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + @Override | ||
| 251 | + public Dimension getPreferredSize() { | ||
| 252 | + return new Dimension(MODE_GAP_WIDTH + titleWidth + | ||
| 253 | + ARROW_GAP_WIDTH + ARROW_WIDTH + MODE_GAP_WIDTH, | ||
| 254 | + EditorButton.DIM); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + @Override | ||
| 258 | + public Dimension getMinimumSize() { | ||
| 259 | + return getPreferredSize(); | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + @Override | ||
| 263 | + public Dimension getMaximumSize() { | ||
| 264 | + return getPreferredSize(); | ||
| 265 | + } | ||
| 266 | + } | ||
| 133 | 267 | } | |
| 268 | + | ||
| 269 | + | ||
| 134 | 270 | //public abstract class EditorToolbar extends JComponent implements MouseInputListener, KeyListener { | |
| 135 | 271 | // | |
| 136 | 272 | // /** Width of each toolbar button. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,8 @@ | |||
| 25 | 25 | ||
| 26 | 26 | import java.awt.*; | |
| 27 | 27 | import java.awt.event.*; | |
| 28 | + import java.awt.image.BufferedImage; | ||
| 29 | + import java.awt.image.WritableRaster; | ||
| 28 | 30 | import java.io.*; | |
| 29 | 31 | import java.util.*; | |
| 30 | 32 | ||
@@ -40,6 +42,7 @@ | |||
| 40 | 42 | import processing.app.contrib.ExamplesContribution; | |
| 41 | 43 | import processing.app.syntax.*; | |
| 42 | 44 | import processing.core.PApplet; | |
| 45 | + import processing.core.PConstants; | ||
| 43 | 46 | ||
| 44 | 47 | ||
| 45 | 48 | public abstract class Mode { | |
@@ -1342,6 +1345,39 @@ public SyntaxStyle getStyle(String attribute) { | |||
| 1342 | 1345 | // return new SyntaxStyle(color, italic, bold); | |
| 1343 | 1346 | return new SyntaxStyle(color, bold); | |
| 1344 | 1347 | } | |
| 1348 | + | ||
| 1349 | + | ||
| 1350 | + public Image getGradient(String attribute, int wide, int high) { | ||
| 1351 | + int top = getColor(attribute + ".gradient.top").getRGB(); | ||
| 1352 | + int bot = getColor(attribute + ".gradient.bottom").getRGB(); | ||
| 1353 | + | ||
| 1354 | + // float r1 = (top >> 16) & 0xff; | ||
| 1355 | + // float g1 = (top >> 8) & 0xff; | ||
| 1356 | + // float b1 = top & 0xff; | ||
| 1357 | + // float r2 = (bot >> 16) & 0xff; | ||
| 1358 | + // float g2 = (bot >> 8) & 0xff; | ||
| 1359 | + // float b2 = bot & 0xff; | ||
| 1360 | + | ||
| 1361 | + BufferedImage outgoing = | ||
| 1362 | + new BufferedImage(wide, high, BufferedImage.TYPE_INT_RGB); | ||
| 1363 | + int[] row = new int[wide]; | ||
| 1364 | + WritableRaster wr = outgoing.getRaster(); | ||
| 1365 | + for (int i = 0; i < high; i++) { | ||
| 1366 | + // Arrays.fill(row, (255 - (i + GRADIENT_TOP)) << 24); | ||
| 1367 | + // int r = (int) PApplet.map(i, 0, high-1, r1, r2); | ||
| 1368 | + int rgb = PApplet.lerpColor(top, bot, i / (float)(high-1), PConstants.RGB); | ||
| 1369 | + Arrays.fill(row, rgb); | ||
| 1370 | + // System.out.println(PApplet.hex(row[0])); | ||
| 1371 | + wr.setDataElements(0, i, wide, 1, row); | ||
| 1372 | + } | ||
| 1373 | + // Graphics g = outgoing.getGraphics(); | ||
| 1374 | + // for (int i = 0; i < steps; i++) { | ||
| 1375 | + // g.setColor(new Color(1, 1, 1, 255 - (i + GRADIENT_TOP))); | ||
| 1376 | + // //g.fillRect(0, i, EditorButton.DIM, 10); | ||
| 1377 | + // g.drawLine(0, i, EditorButton.DIM, i); | ||
| 1378 | + // } | ||
| 1379 | + return outgoing; | ||
| 1380 | + } | ||
| 1345 | 1381 | ||
| 1346 | 1382 | ||
| 1347 | 1383 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |
| Back | FazBrowse Home | New Git URL |
0 commit comments