FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/ui/MarkerColumn.java at master · hayscoding/processing · GitHub
hayscoding
processing
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
ui
/
MarkerColumn.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
220 lines (173 loc) · 6.04 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
ui
/
MarkerColumn.java
Copy path
File metadata and controls
220 lines (173 loc) · 6.04 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
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-19 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 version 2
as published by the Free Software Foundation.
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.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package
processing
.
app
.
ui
;
import
java
.
awt
.
Color
;
import
java
.
awt
.
Cursor
;
import
java
.
awt
.
Dimension
;
import
java
.
awt
.
Graphics
;
import
java
.
awt
.
event
.
MouseAdapter
;
import
java
.
awt
.
event
.
MouseEvent
;
import
java
.
awt
.
event
.
MouseMotionAdapter
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
stream
.
Collectors
;
import
javax
.
swing
.
JPanel
;
import
processing
.
app
.
Mode
;
import
processing
.
app
.
Problem
;
import
processing
.
app
.
Sketch
;
import
processing
.
app
.
SketchCode
;
import
processing
.
app
.
syntax
.
PdeTextArea
;
import
processing
.
app
.
ui
.
Editor
;
import
processing
.
core
.
PApplet
;
/**
* Implements the column to the right of the editor window that displays ticks
* for errors and warnings.
* <br>
* All errors and warnings of a sketch are drawn on the bar, clicking on one,
* scrolls to the tab and location. Error messages displayed on hover. Markers
* are not in sync with the error line. Similar to Eclipse's right error bar
* which displays the overall errors in a document
*/
public
class
MarkerColumn
extends
JPanel
{
protected
Editor
editor
;
// static final int WIDE = 12;
private
Color
errorColor
;
private
Color
warningColor
;
// Stores error markers displayed PER TAB along the error bar.
private
List
<
LineMarker
>
errorPoints
=
new
ArrayList
<>();
public
MarkerColumn
(
Editor
editor
,
int
height
) {
this
.
editor
=
editor
;
Mode
mode
=
editor
.
getMode
();
errorColor
=
mode
.
getColor
(
"editor.column.error.color"
);
warningColor
=
mode
.
getColor
(
"editor.column.warning.color"
);
addMouseListener
(
new
MouseAdapter
() {
public
void
mouseClicked
(
MouseEvent
e
) {
scrollToMarkerAt
(
e
.
getY
());
}
});
addMouseMotionListener
(
new
MouseMotionAdapter
() {
public
void
mouseMoved
(
final
MouseEvent
e
) {
showMarkerHover
(
e
.
getY
());
}
});
}
@
Override
public
void
repaint
() {
recalculateMarkerPositions
();
super
.
repaint
();
}
@
Override
public
void
paintComponent
(
Graphics
g
) {
PdeTextArea
pta
=
editor
.
getPdeTextArea
();
if
(
pta
!=
null
) {
g
.
drawImage
(
pta
.
getGutterGradient
(),
0
,
0
,
getWidth
(),
getHeight
(),
this
);
}
int
currentTabIndex
=
editor
.
getSketch
().
getCurrentCodeIndex
();
for
(
LineMarker
m
:
errorPoints
) {
Problem
problem
=
m
.
problem
;
if
(
problem
.
getTabIndex
() !=
currentTabIndex
)
continue
;
if
(
problem
.
isError
()) {
g
.
setColor
(
errorColor
);
}
else
{
g
.
setColor
(
warningColor
);
}
g
.
drawLine
(
2
,
m
.
y
,
getWidth
() -
2
,
m
.
y
);
}
}
public
void
updateErrorPoints
(
final
List
<
Problem
>
problems
) {
errorPoints
=
problems
.
stream
()
.
map
(
LineMarker
::
new
)
.
collect
(
Collectors
.
toList
());
repaint
();
}
/** Find out which error/warning the user has clicked and scroll to it */
private
void
scrollToMarkerAt
(
final
int
y
) {
try
{
LineMarker
m
=
findClosestMarker
(
y
);
if
(
m
!=
null
) {
editor
.
highlight
(
m
.
problem
);
}
}
catch
(
Exception
ex
) {
ex
.
printStackTrace
();
}
}
/** Show tooltip on hover. */
private
void
showMarkerHover
(
final
int
y
) {
try
{
LineMarker
m
=
findClosestMarker
(
y
);
if
(
m
!=
null
) {
Problem
p
=
m
.
problem
;
editor
.
statusToolTip
(
MarkerColumn
.
this
,
p
.
getMessage
(),
p
.
isError
());
setCursor
(
Cursor
.
getPredefinedCursor
(
Cursor
.
HAND_CURSOR
));
}
}
catch
(
Exception
ex
) {
ex
.
printStackTrace
();
}
}
private
void
recalculateMarkerPositions
() {
if
(
errorPoints
!=
null
&&
errorPoints
.
size
() >
0
) {
Sketch
sketch
=
editor
.
getSketch
();
SketchCode
code
=
sketch
.
getCurrentCode
();
int
currentTab
=
sketch
.
getCurrentCodeIndex
();
int
totalLines
=
PApplet
.
max
(
1
,
code
.
getLineCount
());
// do not divide by zero
int
visibleLines
=
editor
.
getTextArea
().
getVisibleLines
();
totalLines
=
PApplet
.
max
(
totalLines
,
visibleLines
);
int
topMargin
=
20
;
// top scroll button
int
bottomMargin
=
40
;
// bottom scroll button and horizontal scrollbar
int
height
=
getHeight
() -
topMargin
-
bottomMargin
;
for
(
LineMarker
m
:
errorPoints
) {
Problem
problem
=
m
.
problem
;
if
(
problem
.
getTabIndex
() !=
currentTab
)
continue
;
// Ratio of error line to total lines
float
ratio
= (
problem
.
getLineNumber
() +
1
) / ((
float
)
totalLines
);
// Ratio multiplied by height of the error bar
float
y
=
topMargin
+
ratio
*
height
;
m
.
y
= (
int
)
y
;
}
}
}
private
LineMarker
findClosestMarker
(
final
int
y
) {
LineMarker
closest
=
null
;
int
closestDist
=
Integer
.
MAX_VALUE
;
for
(
LineMarker
m
:
errorPoints
) {
int
dist
=
Math
.
abs
(
y
-
m
.
y
);
if
(
dist
<
3
&&
dist
<
closestDist
) {
closest
=
m
;
closestDist
=
dist
;
}
}
return
closest
;
}
public
Dimension
getPreferredSize
() {
return
new
Dimension
(
Editor
.
RIGHT_GUTTER
,
super
.
getPreferredSize
().
height
);
}
public
Dimension
getMinimumSize
() {
return
new
Dimension
(
Editor
.
RIGHT_GUTTER
,
super
.
getMinimumSize
().
height
);
}
/**
* Line markers displayed on the Error Column.
*/
private
static
class
LineMarker
{
/** y co-ordinate of the marker */
int
y
;
/** Problem that the error marker represents */
final
Problem
problem
;
LineMarker
(
Problem
problem
) {
this
.
problem
=
problem
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL