33/*
44 Part of the Processing project - http://processing.org
55
6+ Copyright (c) 2013-15 The Processing Foundation
67 Copyright (c) 2004-13 Ben Fry and Casey Reas
78 Copyright (c) 2001-04 Massachusetts Institute of Technology
89
3536 * Sketch tabs at the top of the editor window.
3637 */
3738public class EditorHeader extends JComponent {
39+ // height of this tab bar
40+ static final int HIGH = 36 ;
3841 // standard UI sizing (OS-specific, but generally consistent)
39- static final int SCROLLBAR_WIDTH = 16 ;
42+ // static final int SCROLLBAR_WIDTH = 16;
4043 // amount of space on the left edge before the tabs start
41- static final int MARGIN_WIDTH = 6 ;
44+ static final int MARGIN_WIDTH = Editor .GUTTER ;
45+
46+ static final int ARROW_TAB_WIDTH = 23 ;
4247 // distance from the righthand side of a tab to the drop-down arrow
43- static final int ARROW_GAP_WIDTH = 8 ;
48+ // static final int ARROW_GAP_WIDTH = 8;
4449 // indent x/y for notch on the tab
45- static final int NOTCH = 0 ;
50+ static final int ARROW_TOP = 14 ;
51+ static final int ARROW_BOTTOM = 23 ;
52+ static final int ARROW_WIDTH = 9 ;
53+
54+ // static final int NOTCH = 0;
4655 // how far to raise the tab from the bottom of this Component
47- static final int TAB_HEIGHT = 25 ;
48- // line that continues across all of the tabs for the current one
49- static final int TAB_STRETCH = 3 ;
56+ static final int TAB_HEIGHT = HIGH ;
57+ // // line that continues across all of the tabs for the current one
58+ // static final int TAB_STRETCH = 3;
5059 // amount of extra space between individual tabs
51- static final int TAB_BETWEEN = 2 ;
60+ static final int TAB_BETWEEN = 4 ;
5261 // amount of margin on the left/right for the text on the tab
53- static final int TEXT_MARGIN = 10 ;
62+ static final int TEXT_MARGIN = 16 ;
5463 // width of the tab when no text visible
5564 // (total tab width will be this plus TEXT_MARGIN*2)
56- static final int NO_TEXT_WIDTH = 10 ;
65+ static final int NO_TEXT_WIDTH = 16 ;
5766
5867 Color bgColor ;
5968// boolean hiding;
@@ -62,6 +71,7 @@ public class EditorHeader extends JComponent {
6271 Color textColor [] = new Color [2 ];
6372 Color tabColor [] = new Color [2 ];
6473 Color modifiedColor ;
74+ Color arrowColor ;
6575
6676 Editor editor ;
6777
@@ -80,7 +90,7 @@ public class EditorHeader extends JComponent {
8090
8191 //
8292
83- static final String STATUS [] = { "unsel" , "sel" };
93+ // static final String STATUS[] = { "unsel", "sel" };
8494 static final int UNSELECTED = 0 ;
8595 static final int SELECTED = 1 ;
8696
@@ -90,13 +100,13 @@ public class EditorHeader extends JComponent {
90100// static final int RIGHT = 2;
91101// static final int MENU = 3;
92102
93- static final int PIECE_WIDTH = 4 ;
94- static final int PIECE_HEIGHT = 33 ;
95- Image [][] pieces ;
103+ // static final int PIECE_WIDTH = 4;
104+ // static final int PIECE_HEIGHT = 33;
105+ // Image[][] pieces;
96106
97- static final int ARROW_WIDTH = 14 ;
98- static final int ARROW_HEIGHT = 14 ;
99- static Image tabArrow ;
107+ // static final int ARROW_WIDTH = 14;
108+ // static final int ARROW_HEIGHT = 14;
109+ // static Image tabArrow;
100110
101111 //
102112
@@ -105,11 +115,15 @@ public class EditorHeader extends JComponent {
105115 int imageW , imageH ;
106116
107117 String lastNoticeName ;
118+
119+ Image gradient ;
108120
109121
110122 public EditorHeader (Editor eddie ) {
111123 this .editor = eddie ;
112124
125+ gradient = editor .getMode ().getGradient ("header" , 400 , HIGH );
126+
113127 updateMode ();
114128
115129 addMouseListener (new MouseAdapter () {
@@ -167,47 +181,21 @@ public void mouseMoved(MouseEvent e) {
167181
168182 public void updateMode () {
169183 Mode mode = editor .getMode ();
170- // int res = Toolkit.isRetina() ? 2 : 1;
171- // String suffix = "-2x.png"; // wishful thinking
172- // // Some modes may not have a 2x version. If a mode doesn't have a 1x
173- // // version, this will cause an error... they should always have 1x.
174- // if (res == 2) {
175- // if (!mode.getContentFile(tabFile(0, 0) + suffix).exists()) {
176- // res = 1;
177- // }
178- // }
179- // if (res == 1) {
180- // suffix = ".png";
181- // if (!mode.getContentFile(tabFile(0, 0) + suffix).exists()) {
182- // suffix = ".gif";
183- // }
184+ // if (tabArrow == null) {
185+ // String suffix = Toolkit.highResDisplay() ? "-2x.png" : ".png";
186+ // tabArrow = Toolkit.getLibImage("tab-arrow" + suffix);
184187// }
185- //
186- // pieces = new Image[STATUS.length][WHERE.length];
187- // for (int status = 0; status < STATUS.length; status++) {
188- // for (int where = 0; where < WHERE.length; where++) {
189- // //String filename = "theme/tab-" + STATUS[i] + "-" + WHERE[j] + ".gif";
190- // pieces[status][where] = mode.loadImage(tabFile(status, where) + suffix);
191- // }
192- // }
193-
194- if (tabArrow == null ) {
195- String suffix = Toolkit .highResDisplay () ? "-2x.png" : ".png" ;
196- tabArrow = Toolkit .getLibImage ("tab-arrow" + suffix );
197- }
198188
199189 bgColor = mode .getColor ("header.bgcolor" );
200190
201- // hiding = Preferences.getBoolean("buttons.hide.image");
202- // hideColor = mode.getColor("buttons.hide.color");
203-
204191 textColor [SELECTED ] = mode .getColor ("header.text.selected.color" );
205192 textColor [UNSELECTED ] = mode .getColor ("header.text.unselected.color" );
206193 font = mode .getFont ("header.text.font" );
207194
208195 tabColor [SELECTED ] = mode .getColor ("header.tab.selected.color" );
209196 tabColor [UNSELECTED ] = mode .getColor ("header.tab.unselected.color" );
210197
198+ arrowColor = mode .getColor ("header.tab.arrow.color" );
211199 modifiedColor = mode .getColor ("editor.selection.color" );
212200 }
213201
@@ -249,32 +237,13 @@ public void paintComponent(Graphics screen) {
249237
250238 Graphics g = offscreen .getGraphics ();
251239 g .setFont (font ); // need to set this each time through
252- // metrics = g.getFontMetrics();
253- // fontAscent = metrics.getAscent();
254240 if (fontAscent == 0 ) {
255241 fontAscent = (int ) Toolkit .getAscent (g );
256242 }
257243
258244 Graphics2D g2 = Toolkit .prepareGraphics (g );
259- /*
260- if (Toolkit.highResDisplay()) {
261- // scale everything 2x, will be scaled down when drawn to the screen
262- g2.scale(2, 2);
263- }
264- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
265- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
266- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
267- RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
268- */
269-
270- // set the background for the offscreen
271- //g.setColor(hiding ? hideColor : bgColor);
272- g .setColor (new Color (0 , 0 , 0 , 0 ));
273- g .fillRect (0 , 0 , imageW , imageH );
274-
275- // if (!hiding) {
276- // editor.getMode().drawBackground(g, Preferences.GRID_SIZE);
277- // }
245+
246+ g .drawImage (gradient , 0 , 0 , imageW , imageH , this );
278247
279248 if (tabs .length != sketch .getCodeCount ()) {
280249 tabs = new Tab [sketch .getCodeCount ()];
@@ -284,8 +253,7 @@ public void paintComponent(Graphics screen) {
284253 visitOrder = new Tab [sketch .getCodeCount () - 1 ];
285254 }
286255
287- int leftover =
288- ARROW_GAP_WIDTH + ARROW_WIDTH + MARGIN_WIDTH ; // + SCROLLBAR_WIDTH;
256+ int leftover = TAB_BETWEEN + ARROW_TAB_WIDTH ; // + MARGIN_WIDTH; // + SCROLLBAR_WIDTH;
289257 int tabMax = getWidth () - leftover ;
290258
291259 // reset all tab positions
@@ -335,13 +303,24 @@ public void paintComponent(Graphics screen) {
335303 placeTabs (MARGIN_WIDTH , tabMax , g2 );
336304
337305 // draw the dropdown menu target
338- menuLeft = tabs [tabs .length - 1 ].right + ARROW_GAP_WIDTH ;
339- menuRight = menuLeft + ARROW_WIDTH ;
340- int arrowY = (getHeight () - TAB_HEIGHT - TAB_STRETCH ) + (TAB_HEIGHT - ARROW_HEIGHT )/2 ;
341- g .drawImage (tabArrow , menuLeft , arrowY ,
342- ARROW_WIDTH , ARROW_HEIGHT , null );
343- // g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU],
344- // menuLeft, 0, null);
306+ menuLeft = tabs [tabs .length - 1 ].right + TAB_BETWEEN ;
307+ menuRight = menuLeft + ARROW_TAB_WIDTH ;
308+ g .setColor (tabColor [UNSELECTED ]);
309+ drawTab (g , menuLeft , menuRight );
310+ // int arrowY = (getHeight() - TAB_HEIGHT - TAB_STRETCH) + (TAB_HEIGHT - ARROW_HEIGHT)/2;
311+ // g.drawImage(tabArrow, menuLeft, arrowY,
312+ // ARROW_WIDTH, ARROW_HEIGHT, null);
313+ // TODO draw arrow here
314+
315+ g .setColor (arrowColor );
316+ GeneralPath trianglePath = new GeneralPath ();
317+ float x1 = menuLeft + (ARROW_TAB_WIDTH - ARROW_WIDTH ) / 2f ;
318+ float x2 = menuLeft + (ARROW_TAB_WIDTH + ARROW_WIDTH ) / 2f ;
319+ trianglePath .moveTo (x1 , ARROW_TOP );
320+ trianglePath .lineTo (x2 , ARROW_TOP );
321+ trianglePath .lineTo ((x1 + x2 ) / 2 , ARROW_BOTTOM );
322+ trianglePath .closePath ();
323+ g2 .fill (trianglePath );
345324
346325 screen .drawImage (offscreen , 0 , 0 , imageW , imageH , null );
347326 }
@@ -351,9 +330,9 @@ private boolean placeTabs(int left, int right, Graphics2D g) {
351330 Sketch sketch = editor .getSketch ();
352331 int x = left ;
353332
354- final int bottom = getHeight () - TAB_STRETCH ;
333+ final int bottom = getHeight (); // - TAB_STRETCH;
355334 final int top = bottom - TAB_HEIGHT ;
356- GeneralPath path = null ;
335+ // GeneralPath path = null;
357336
358337 for (int i = 0 ; i < sketch .getCodeCount (); i ++) {
359338 SketchCode code = sketch .getCode (i );
@@ -366,13 +345,13 @@ private boolean placeTabs(int left, int right, Graphics2D g) {
366345// int pieceWidth = pieceCount * PIECE_WIDTH;
367346
368347 int state = (code == sketch .getCurrentCode ()) ? SELECTED : UNSELECTED ;
369- if (g != null ) {
370- //g.drawImage(pieces[state][LEFT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
371- path = new GeneralPath ();
372- path .moveTo (x , bottom );
373- path .lineTo (x , top + NOTCH );
374- path .lineTo (x + NOTCH , top );
375- }
348+ // if (g != null) {
349+ // //g.drawImage(pieces[state][LEFT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
350+ // path = new GeneralPath();
351+ // path.moveTo(x, bottom);
352+ // path.lineTo(x, top + NOTCH);
353+ // path.lineTo(x + NOTCH, top);
354+ // }
376355 tab .left = x ;
377356 x += TEXT_MARGIN ;
378357// x += PIECE_WIDTH;
@@ -392,15 +371,17 @@ private boolean placeTabs(int left, int right, Graphics2D g) {
392371 tab .right = x ;
393372
394373 if (g != null ) {
395- path .lineTo (x - NOTCH , top );
396- path .lineTo (x , top + NOTCH );
397- path .lineTo (x , bottom );
398- path .closePath ();
399374 g .setColor (tabColor [state ]);
400- g .fill (path );
401- // have to draw an extra outline to make things line up on retina
402- g .draw (path );
403- //g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
375+ drawTab (g , tab .left , tab .right );
376+ // path.lineTo(x - NOTCH, top);
377+ // path.lineTo(x, top + NOTCH);
378+ // path.lineTo(x, bottom);
379+ // path.closePath();
380+ // g.setColor(tabColor[state]);
381+ // g.fill(path);
382+ // // have to draw an extra outline to make things line up on retina
383+ // g.draw(path);
384+ // //g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
404385
405386 if (tab .textVisible ) {
406387 int textLeft = tab .left + ((tab .right - tab .left ) - tab .textWidth ) / 2 ;
@@ -417,7 +398,8 @@ private boolean placeTabs(int left, int right, Graphics2D g) {
417398
418399 if (code .isModified ()) {
419400 g .setColor (modifiedColor );
420- g .drawLine (tab .left + NOTCH , top , tab .right - NOTCH , top );
401+ //g.drawLine(tab.left + NOTCH, top, tab.right - NOTCH, top);
402+ g .drawLine (tab .left , top , tab .right , top );
421403 }
422404 }
423405
@@ -428,14 +410,22 @@ private boolean placeTabs(int left, int right, Graphics2D g) {
428410 x += TAB_BETWEEN ;
429411 }
430412
431- // Draw this last because of half-pixel overlaps on retina displays
432- if (g != null ) {
433- g .setColor (tabColor [SELECTED ]);
434- g .fillRect (0 , bottom , getWidth (), TAB_STRETCH );
435- }
413+ // removed 150130
414+ // // Draw this last because of half-pixel overlaps on retina displays
415+ // if (g != null) {
416+ // g.setColor(tabColor[SELECTED]);
417+ // g.fillRect(0, bottom, getWidth(), TAB_STRETCH);
418+ // }
436419
437420 return x <= right ;
438421 }
422+
423+
424+ private void drawTab (Graphics g , int left , int right ) {
425+ final int bottom = getHeight (); // - TAB_STRETCH;
426+ final int top = bottom - TAB_HEIGHT ;
427+ g .fillRect (left , top , right - left , bottom - top );
428+ }
439429
440430
441431 /**
@@ -623,23 +613,17 @@ public void deselectMenu() {
623613
624614
625615 public Dimension getPreferredSize () {
626- return getMinimumSize ( );
616+ return new Dimension ( 300 , HIGH );
627617 }
628618
629619
630620 public Dimension getMinimumSize () {
631- // if (Base.isMacOS()) {
632- return new Dimension (300 , Preferences .GRID_SIZE );
633- // }
634- // return new Dimension(300, Preferences.GRID_SIZE - 1);
621+ return getPreferredSize ();
635622 }
636623
637624
638625 public Dimension getMaximumSize () {
639- // if (Base.isMacOS()) {
640- return new Dimension (3000 , Preferences .GRID_SIZE );
641- // }
642- // return new Dimension(3000, Preferences.GRID_SIZE - 1);
626+ return new Dimension (super .getMaximumSize ().width , HIGH );
643627 }
644628
645629
0 commit comments