| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -434,7 +434,7 @@ public void processKeyEvent(KeyEvent evt) { | |||
| 434 | 434 | public EditorFooter createFooter() { | |
| 435 | 435 | EditorFooter ef = new EditorFooter(this); | |
| 436 | 436 | console = new EditorConsole(this); | |
| 437 | - ef.addPanel(Language.text("editor.footer.console"), console); | ||
| 437 | + ef.addPanel(console, Language.text("editor.footer.console"), "/lib/footer/console"); | ||
| 438 | 438 | return ef; | |
| 439 | 439 | ||
| 440 | 440 | /* | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,9 +3,7 @@ | |||
| 3 | 3 | /* | |
| 4 | 4 | Part of the Processing project - http://processing.org | |
| 5 | 5 | ||
| 6 | - Copyright (c) 2013-15 The Processing Foundation | ||
| 7 | - Copyright (c) 2004-13 Ben Fry and Casey Reas | ||
| 8 | - Copyright (c) 2001-04 Massachusetts Institute of Technology | ||
| 6 | + Copyright (c) 2015 The Processing Foundation | ||
| 9 | 7 | ||
| 10 | 8 | This program is free software; you can redistribute it and/or modify | |
| 11 | 9 | it under the terms of the GNU General Public License as published by | |
@@ -57,7 +55,11 @@ public class EditorFooter extends Box { | |||
| 57 | 55 | // amount of extra space between individual tabs | |
| 58 | 56 | static final int TAB_BETWEEN = 3; | |
| 59 | 57 | // amount of margin on the left/right for the text on the tab | |
| 60 | - static final int TEXT_MARGIN = 16; | ||
| 58 | + static final int MARGIN = 16; | ||
| 59 | + | ||
| 60 | + static final int ICON_WIDTH = 14; | ||
| 61 | + static final int ICON_HEIGHT = 13; | ||
| 62 | + static final int ICON_TOP = 5; | ||
| 61 | 63 | ||
| 62 | 64 | Color[] textColor = new Color[2]; | |
| 63 | 65 | Color[] tabColor = new Color[2]; | |
@@ -102,8 +104,20 @@ public EditorFooter(Editor eddie) { | |||
| 102 | 104 | } | |
| 103 | 105 | ||
| 104 | 106 | ||
| 105 | - public void addPanel(String name, Component comp) { | ||
| 106 | - tabs.add(new Tab(name, comp)); | ||
| 107 | + /** Add a panel with no icon. */ | ||
| 108 | + public void addPanel(Component comp, String name) { | ||
| 109 | + addPanel(comp, name, null); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * Add a panel with a name and icon. | ||
| 115 | + * @param comp Component that will be shown when this tab is selected | ||
| 116 | + * @param name Title to appear on the tab itself | ||
| 117 | + * @param icon Prefix of the file name for the icon | ||
| 118 | + */ | ||
| 119 | + public void addPanel(Component comp, String name, String icon) { | ||
| 120 | + tabs.add(new Tab(comp, name, icon)); | ||
| 107 | 121 | cardPanel.add(name, comp); | |
| 108 | 122 | } | |
| 109 | 123 | ||
@@ -237,21 +251,27 @@ private void placeTabs(int left, Graphics2D g) { | |||
| 237 | 251 | int x = left; | |
| 238 | 252 | ||
| 239 | 253 | for (Tab tab : tabs) { | |
| 240 | - int state = tab.isCurrent() ? SELECTED : UNSELECTED; | ||
| 241 | 254 | tab.left = x; | |
| 242 | - x += TEXT_MARGIN; | ||
| 243 | - x += tab.textWidth + TEXT_MARGIN; | ||
| 255 | + x += MARGIN; | ||
| 256 | + if (tab.hasIcon()) { | ||
| 257 | + x += ICON_WIDTH + MARGIN; | ||
| 258 | + } | ||
| 259 | + x += tab.textWidth + MARGIN; | ||
| 244 | 260 | tab.right = x; | |
| 245 | 261 | ||
| 246 | 262 | // if drawing and not just placing | |
| 247 | 263 | if (g != null) { | |
| 264 | + tab.draw(g); | ||
| 265 | + /* | ||
| 266 | + int state = tab.isCurrent() ? SELECTED : UNSELECTED; | ||
| 248 | 267 | g.setColor(tabColor[state]); | |
| 249 | 268 | if (tab.notification) { | |
| 250 | 269 | g.setColor(errorColor); | |
| 251 | 270 | } | |
| 252 | - drawTab(g, tab.left, tab.right, tab.isFirst(), tab.isLast()); | ||
| 271 | + //drawTab(g, tab.left, tab.right, tab.isFirst(), tab.isLast()); | ||
| 272 | + tab.draw(g); | ||
| 253 | 273 | ||
| 254 | - int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2; | ||
| 274 | + int textLeft = tab.getTextLeft(); | ||
| 255 | 275 | if (tab.notification && state == UNSELECTED) { | |
| 256 | 276 | g.setColor(Color.LIGHT_GRAY); | |
| 257 | 277 | } else { | |
@@ -260,19 +280,22 @@ private void placeTabs(int left, Graphics2D g) { | |||
| 260 | 280 | int tabHeight = TAB_BOTTOM - TAB_TOP; | |
| 261 | 281 | int baseline = TAB_TOP + (tabHeight + fontAscent) / 2; | |
| 262 | 282 | g.drawString(tab.name, textLeft, baseline); | |
| 283 | + */ | ||
| 263 | 284 | } | |
| 264 | 285 | x += TAB_BETWEEN; | |
| 265 | 286 | } | |
| 266 | 287 | } | |
| 267 | 288 | ||
| 268 | 289 | ||
| 290 | + /* | ||
| 269 | 291 | private void drawTab(Graphics g, int left, int right, | |
| 270 | 292 | boolean leftNotch, boolean rightNotch) { | |
| 271 | 293 | Graphics2D g2 = (Graphics2D) g; | |
| 272 | 294 | g2.fill(Toolkit.createRoundRect(left, TAB_TOP, right, TAB_BOTTOM, 0, 0, | |
| 273 | 295 | rightNotch ? CURVE_RADIUS : 0, | |
| 274 | 296 | leftNotch ? CURVE_RADIUS : 0)); | |
| 275 | 297 | } | |
| 298 | + */ | ||
| 276 | 299 | ||
| 277 | 300 | ||
| 278 | 301 | public Dimension getPreferredSize() { | |
@@ -299,13 +322,26 @@ class Tab { | |||
| 299 | 322 | Component comp; | |
| 300 | 323 | boolean notification; | |
| 301 | 324 | ||
| 325 | + Image enabledIcon; | ||
| 326 | + Image selectedIcon; | ||
| 327 | + | ||
| 302 | 328 | int left; | |
| 303 | 329 | int right; | |
| 304 | 330 | int textWidth; | |
| 305 | 331 | ||
| 306 | - Tab(String name, Component comp) { | ||
| 307 | - this.name = name; | ||
| 332 | + Tab(Component comp, String name, String icon) { | ||
| 308 | 333 | this.comp = comp; | |
| 334 | + this.name = name; | ||
| 335 | + | ||
| 336 | + if (icon != null) { | ||
| 337 | + Mode mode = editor.getMode(); | ||
| 338 | + final int res = Toolkit.highResDisplay() ? 2 : 1; | ||
| 339 | + enabledIcon = mode.loadImage(icon + "-enabled-" + res + "x.png"); | ||
| 340 | + selectedIcon = mode.loadImage(icon + "-selected-" + res + "x.png"); | ||
| 341 | + if (selectedIcon == null) { | ||
| 342 | + selectedIcon = enabledIcon; // use this as the default | ||
| 343 | + } | ||
| 344 | + } | ||
| 309 | 345 | } | |
| 310 | 346 | ||
| 311 | 347 | boolean contains(int x) { | |
@@ -323,5 +359,45 @@ boolean isFirst() { | |||
| 323 | 359 | boolean isLast() { | |
| 324 | 360 | return tabs.get(tabs.size() - 1) == this; | |
| 325 | 361 | } | |
| 362 | + | ||
| 363 | + int getTextLeft() { | ||
| 364 | + int links = left; | ||
| 365 | + if (enabledIcon != null) { | ||
| 366 | + links += ICON_WIDTH; | ||
| 367 | + } | ||
| 368 | + return links + ((right - links) - textWidth) / 2; | ||
| 369 | + } | ||
| 370 | + | ||
| 371 | + boolean hasIcon() { | ||
| 372 | + return enabledIcon != null; | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + void draw(Graphics g) { | ||
| 376 | + int state = isCurrent() ? SELECTED : UNSELECTED; | ||
| 377 | + g.setColor(tabColor[state]); | ||
| 378 | + if (notification) { | ||
| 379 | + g.setColor(errorColor); | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + Graphics2D g2 = (Graphics2D) g; | ||
| 383 | + g2.fill(Toolkit.createRoundRect(left, TAB_TOP, right, TAB_BOTTOM, 0, 0, | ||
| 384 | + isLast() ? CURVE_RADIUS : 0, | ||
| 385 | + isFirst() ? CURVE_RADIUS : 0)); | ||
| 386 | + | ||
| 387 | + if (hasIcon()) { | ||
| 388 | + Image icon = isCurrent() ? selectedIcon : enabledIcon; | ||
| 389 | + g.drawImage(icon, left + MARGIN, ICON_TOP, ICON_WIDTH, ICON_HEIGHT, null); | ||
| 390 | + } | ||
| 391 | + | ||
| 392 | + int textLeft = getTextLeft(); | ||
| 393 | + if (notification && state == UNSELECTED) { | ||
| 394 | + g.setColor(Color.LIGHT_GRAY); | ||
| 395 | + } else { | ||
| 396 | + g.setColor(textColor[state]); | ||
| 397 | + } | ||
| 398 | + int tabHeight = TAB_BOTTOM - TAB_TOP; | ||
| 399 | + int baseline = TAB_TOP + (tabHeight + fontAscent) / 2; | ||
| 400 | + g.drawString(name, textLeft, baseline); | ||
| 401 | + } | ||
| 326 | 402 | } | |
| 327 | 403 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments