FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/ui/EditorFooter.java at master · 2php/processing · GitHub
2php
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
ui
/
EditorFooter.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
422 lines (326 loc) · 11.1 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
ui
/
EditorFooter.java
Copy path
File metadata and controls
422 lines (326 loc) · 11.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2015 The Processing Foundation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package
processing
.
app
.
ui
;
import
java
.
awt
.
CardLayout
;
import
java
.
awt
.
Color
;
import
java
.
awt
.
Component
;
import
java
.
awt
.
Dimension
;
import
java
.
awt
.
Font
;
import
java
.
awt
.
Graphics
;
import
java
.
awt
.
Graphics2D
;
import
java
.
awt
.
Image
;
import
java
.
awt
.
event
.
MouseAdapter
;
import
java
.
awt
.
event
.
MouseEvent
;
import
java
.
awt
.
font
.
FontRenderContext
;
import
java
.
awt
.
geom
.
Ellipse2D
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
javax
.
swing
.*;
import
processing
.
app
.
Mode
;
import
processing
.
app
.
Sketch
;
import
processing
.
app
.
contrib
.
ContributionManager
;
/**
* Console/error/whatever tabs at the bottom of the editor window.
* This shares a lot of code with EditorHeader and the Manager tabs as well.
*/
public
class
EditorFooter
extends
Box
{
// height of this tab bar
static
final
int
HIGH
=
32
;
static
final
int
CURVE_RADIUS
=
6
;
static
final
int
TAB_TOP
=
2
;
static
final
int
TAB_BOTTOM
=
29
;
// amount of extra space between individual tabs
static
final
int
TAB_BETWEEN
=
2
;
// amount of margin on the left/right for the text on the tab
static
final
int
MARGIN
=
14
;
static
final
int
ICON_WIDTH
=
16
;
static
final
int
ICON_HEIGHT
=
16
;
static
final
int
ICON_TOP
=
7
;
static
final
int
ICON_MARGIN
=
7
;
static
final
int
UNSELECTED
=
0
;
static
final
int
SELECTED
=
1
;
Color
[]
textColor
=
new
Color
[
2
];
Color
[]
tabColor
=
new
Color
[
2
];
Color
updateColor
;
int
updateLeft
;
Editor
editor
;
List
<
Tab
>
tabs
=
new
ArrayList
<>();
Font
font
;
int
fontAscent
;
Image
offscreen
;
int
sizeW
,
sizeH
;
int
imageW
,
imageH
;
Image
gradient
;
Color
bgColor
;
JPanel
cardPanel
;
CardLayout
cardLayout
;
Controller
controller
;
int
updateCount
;
public
EditorFooter
(
Editor
eddie
) {
super
(
BoxLayout
.
Y_AXIS
);
this
.
editor
=
eddie
;
updateMode
();
cardLayout
=
new
CardLayout
();
cardPanel
=
new
JPanel
(
cardLayout
);
add
(
cardPanel
);
controller
=
new
Controller
();
add
(
controller
);
}
/** Add a panel with no icon. */
public
void
addPanel
(
Component
comp
,
String
name
) {
addPanel
(
comp
,
name
,
null
);
}
/**
* Add a panel with a name and icon.
* @param comp Component that will be shown when this tab is selected
* @param name Title to appear on the tab itself
* @param icon Prefix of the file name for the icon
*/
public
void
addPanel
(
Component
comp
,
String
name
,
String
icon
) {
tabs
.
add
(
new
Tab
(
comp
,
name
,
icon
));
cardPanel
.
add
(
name
,
comp
);
}
// public void setPanel(int index) {
// cardLayout.show(cardPanel, tabs.get(index).name);
// }
public
void
setPanel
(
Component
comp
) {
for
(
Tab
tab
:
tabs
) {
if
(
tab
.
comp
==
comp
) {
cardLayout
.
show
(
cardPanel
,
tab
.
name
);
repaint
();
}
}
}
public
void
setNotification
(
Component
comp
,
boolean
note
) {
for
(
Tab
tab
:
tabs
) {
if
(
tab
.
comp
==
comp
) {
tab
.
notification
=
note
;
repaint
();
}
}
}
public
void
setUpdateCount
(
int
count
) {
this
.
updateCount
=
count
;
repaint
();
}
public
void
updateMode
() {
Mode
mode
=
editor
.
getMode
();
textColor
[
SELECTED
] =
mode
.
getColor
(
"footer.text.selected.color"
);
textColor
[
UNSELECTED
] =
mode
.
getColor
(
"footer.text.unselected.color"
);
font
=
mode
.
getFont
(
"footer.text.font"
);
tabColor
[
SELECTED
] =
mode
.
getColor
(
"footer.tab.selected.color"
);
tabColor
[
UNSELECTED
] =
mode
.
getColor
(
"footer.tab.unselected.color"
);
updateColor
=
mode
.
getColor
(
"footer.updates.color"
);
gradient
=
mode
.
makeGradient
(
"footer"
,
400
,
HIGH
);
// Set the default background color in case the window size reported
// incorrectly by the OS, or we miss an update event of some kind
// https://github.com/processing/processing/issues/3919
bgColor
=
mode
.
getColor
(
"footer.gradient.bottom"
);
setBackground
(
bgColor
);
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
class
Controller
extends
JComponent
{
Controller
() {
addMouseListener
(
new
MouseAdapter
() {
public
void
mousePressed
(
MouseEvent
e
) {
int
x
=
e
.
getX
();
for
(
Tab
tab
:
tabs
) {
if
(
tab
.
contains
(
x
)) {
//editor.setFooterPanel(tab.index);
cardLayout
.
show
(
cardPanel
,
tab
.
name
);
repaint
();
}
}
if
(
updateCount
>
0
&&
x
>
updateLeft
) {
ContributionManager
.
openUpdates
();
}
}
});
}
public
void
paintComponent
(
Graphics
screen
) {
if
(
screen
==
null
)
return
;
Sketch
sketch
=
editor
.
getSketch
();
if
(
sketch
==
null
)
return
;
// possible?
Dimension
size
=
getSize
();
if
((
size
.
width
!=
sizeW
) || (
size
.
height
!=
sizeH
)) {
// component has been resized
if
((
size
.
width
>
imageW
) || (
size
.
height
>
imageH
)) {
// nix the image and recreate, it's too small
offscreen
=
null
;
}
else
{
// if the image is larger than necessary, no need to change
sizeW
=
size
.
width
;
sizeH
=
size
.
height
;
}
}
if
(
offscreen
==
null
) {
sizeW
=
size
.
width
;
sizeH
=
size
.
height
;
imageW
=
sizeW
;
imageH
=
sizeH
;
if
(
Toolkit
.
highResDisplay
()) {
offscreen
=
createImage
(
imageW
*
2
,
imageH
*
2
);
}
else
{
offscreen
=
createImage
(
imageW
,
imageH
);
}
}
Graphics
g
=
offscreen
.
getGraphics
();
g
.
setFont
(
font
);
// need to set this each time through
if
(
fontAscent
==
0
) {
fontAscent
= (
int
)
Toolkit
.
getAscent
(
g
);
}
Graphics2D
g2
=
Toolkit
.
prepareGraphics
(
g
);
g
.
setColor
(
tabColor
[
SELECTED
]);
g
.
fillRect
(
0
,
0
,
imageW
,
2
);
g
.
drawImage
(
gradient
,
0
,
2
,
imageW
,
imageH
,
this
);
// reset all tab positions
for
(
Tab
tab
:
tabs
) {
tab
.
textWidth
= (
int
)
font
.
getStringBounds
(
tab
.
name
,
g2
.
getFontRenderContext
()).
getWidth
();
}
// now actually draw the tabs
drawTabs
(
Editor
.
LEFT_GUTTER
,
g2
);
drawUpdates
(
g2
);
// // draw the two pixel line that extends left/right below the tabs
// g.setColor(tabColor[SELECTED]);
// // can't be done with lines, b/c retina leaves tiny hairlines
// g.fillRect(Editor.LEFT_GUTTER, TAB_BOTTOM,
// editor.getTextArea().getWidth() - Editor.LEFT_GUTTER, 2);
screen
.
drawImage
(
offscreen
,
0
,
0
,
imageW
,
imageH
,
null
);
}
/**
* @param left starting position from the left
* @param g graphics context, or null if we're not drawing
*/
private
void
drawTabs
(
int
left
,
Graphics2D
g
) {
int
x
=
left
;
for
(
Tab
tab
:
tabs
) {
tab
.
left
=
x
;
x
+=
MARGIN
;
if
(
tab
.
hasIcon
()) {
x
+=
ICON_WIDTH
+
MARGIN
;
}
x
+=
tab
.
textWidth
+
MARGIN
;
tab
.
right
=
x
;
tab
.
draw
(
g
);
x
+=
TAB_BETWEEN
;
}
}
private
void
drawUpdates
(
Graphics2D
g2
) {
if
(
updateCount
!=
0
) {
FontRenderContext
frc
=
g2
.
getFontRenderContext
();
final
int
GAP
=
5
;
final
String
updateLabel
=
"Updates"
;
String
updatesStr
=
""
+
updateCount
;
double
countWidth
=
font
.
getStringBounds
(
updatesStr
,
frc
).
getWidth
();
if
(
fontAscent
>
countWidth
) {
countWidth
=
fontAscent
;
}
float
diameter
= (
float
) (
countWidth
*
1.65f
);
float
ex
=
getWidth
() -
Editor
.
RIGHT_GUTTER
-
diameter
;
float
ey
= (
getHeight
() -
diameter
) /
2
;
g2
.
setColor
(
updateColor
);
g2
.
fill
(
new
Ellipse2D
.
Float
(
ex
,
ey
,
diameter
,
diameter
));
g2
.
setColor
(
textColor
[
SELECTED
]);
int
baseline
= (
getHeight
() +
fontAscent
) /
2
;
g2
.
drawString
(
updatesStr
, (
int
) (
ex
+ (
diameter
-
countWidth
)/
2
),
baseline
);
double
updatesWidth
=
font
.
getStringBounds
(
updateLabel
,
frc
).
getWidth
();
g2
.
setColor
(
textColor
[
UNSELECTED
]);
updateLeft
= (
int
) (
ex
-
updatesWidth
-
GAP
);
g2
.
drawString
(
updateLabel
,
updateLeft
,
baseline
);
}
}
public
Dimension
getPreferredSize
() {
return
new
Dimension
(
300
,
HIGH
);
}
public
Dimension
getMinimumSize
() {
return
getPreferredSize
();
}
public
Dimension
getMaximumSize
() {
return
new
Dimension
(
super
.
getMaximumSize
().
width
,
HIGH
);
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
class
Tab
{
String
name
;
Component
comp
;
boolean
notification
;
Image
enabledIcon
;
Image
selectedIcon
;
int
left
;
int
right
;
int
textWidth
;
Tab
(
Component
comp
,
String
name
,
String
icon
) {
this
.
comp
=
comp
;
this
.
name
=
name
;
if
(
icon
!=
null
) {
Mode
mode
=
editor
.
getMode
();
enabledIcon
=
mode
.
loadImageX
(
icon
+
"-enabled"
);
selectedIcon
=
mode
.
loadImageX
(
icon
+
"-selected"
);
if
(
selectedIcon
==
null
) {
selectedIcon
=
enabledIcon
;
// use this as the default
}
}
}
boolean
contains
(
int
x
) {
return
x
>=
left
&&
x
<=
right
;
}
boolean
isCurrent
() {
return
comp
.
isVisible
();
}
boolean
isFirst
() {
return
tabs
.
get
(
0
) ==
this
;
}
boolean
isLast
() {
return
tabs
.
get
(
tabs
.
size
() -
1
) ==
this
;
}
int
getTextLeft
() {
int
links
=
left
;
if
(
enabledIcon
!=
null
) {
links
+=
ICON_WIDTH
+
ICON_MARGIN
;
}
return
links
+ ((
right
-
links
) -
textWidth
) /
2
;
}
boolean
hasIcon
() {
return
enabledIcon
!=
null
;
}
void
draw
(
Graphics
g
) {
int
state
=
isCurrent
() ?
SELECTED
:
UNSELECTED
;
g
.
setColor
(
tabColor
[
state
]);
// if (notification) {
// g.setColor(errorColor);
// }
Graphics2D
g2
= (
Graphics2D
)
g
;
g2
.
fill
(
Toolkit
.
createRoundRect
(
left
,
TAB_TOP
,
right
,
TAB_BOTTOM
,
0
,
0
,
isLast
() ?
CURVE_RADIUS
:
0
,
isFirst
() ?
CURVE_RADIUS
:
0
));
if
(
hasIcon
()) {
Image
icon
= (
isCurrent
() ||
notification
) ?
selectedIcon
:
enabledIcon
;
g
.
drawImage
(
icon
,
left
+
MARGIN
,
ICON_TOP
,
ICON_WIDTH
,
ICON_HEIGHT
,
null
);
}
int
textLeft
=
getTextLeft
();
if
(
notification
&&
state
==
UNSELECTED
) {
g
.
setColor
(
textColor
[
SELECTED
]);
}
else
{
g
.
setColor
(
textColor
[
state
]);
}
int
tabHeight
=
TAB_BOTTOM
-
TAB_TOP
;
int
baseline
=
TAB_TOP
+ (
tabHeight
+
fontAscent
) /
2
;
g
.
drawString
(
name
,
textLeft
,
baseline
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL