FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing4/app/src/processing/app/syntax/PdeTextArea.java at main · processing/processing4 · GitHub
processing
processing4
Repository navigation
Code
Issues
259
(259)
Pull requests
31
(31)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing4
/
app
/
src
/
processing
/
app
/
syntax
/
PdeTextArea.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
200 lines (156 loc) · 5.44 KB
Breadcrumbs
processing4
/
app
/
src
/
processing
/
app
/
syntax
/
PdeTextArea.java
Copy path
File metadata and controls
200 lines (156 loc) · 5.44 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
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-16 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
.
syntax
;
import
java
.
awt
.*;
import
java
.
awt
.
event
.
MouseEvent
;
import
java
.
awt
.
event
.
MouseMotionAdapter
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
import
processing
.
app
.
ui
.
Editor
;
import
processing
.
app
.
ui
.
Theme
;
import
processing
.
app
.
laf
.
PdeScrollBarUI
;
/**
* Extensions to JEditTextArea to for the PDE. These were moved out of
* JavaTextArea because they were not Java-specific and would be helpful
* for other Mode implementations.
*/
public
class
PdeTextArea
extends
JEditTextArea
{
protected
final
Editor
editor
;
protected
Image
gutterGradient
;
/// the text marker for highlighting breakpoints in the gutter
static
public
final
String
BREAK_MARKER
=
"<>"
;
/// the text marker for highlighting the current line in the gutter
static
public
final
String
STEP_MARKER
=
"->"
;
/// maps line index to gutter text
protected
final
Map
<
Integer
,
String
>
gutterText
=
new
HashMap
<>();
public
PdeTextArea
(
TextAreaDefaults
defaults
,
InputHandler
inputHandler
,
Editor
editor
) {
super
(
defaults
,
inputHandler
);
this
.
editor
=
editor
;
// vertical.setUI(new ThemeScrollBarUI("editor"));
// horizontal.setUI(new ThemeScrollBarUI("editor"));
// change cursor to pointer in the gutter area
painter
.
addMouseMotionListener
(
gutterCursorMouseAdapter
);
// already added by call to super(), removing [fry 220112]
//add(CENTER, painter);
updateTheme
();
}
@
Override
protected
TextAreaPainter
createPainter
(
final
TextAreaDefaults
defaults
) {
return
new
PdeTextAreaPainter
(
this
,
defaults
);
}
public
Image
getGutterGradient
() {
return
gutterGradient
;
}
@
Override
public
void
updateTheme
() {
painter
.
updateTheme
();
gutterGradient
=
Theme
.
makeGradient
(
"editor"
,
Editor
.
LEFT_GUTTER
,
500
);
if
(
vertical
.
getUI
()
instanceof
PdeScrollBarUI
) {
// System.out.println("PdeTextArea.updateTheme() just updating");
((
PdeScrollBarUI
)
vertical
.
getUI
()).
updateTheme
();
((
PdeScrollBarUI
)
horizontal
.
getUI
()).
updateTheme
();
}
else
{
// System.out.println("PdeTextArea.updateTheme() setting ui");
vertical
.
setUI
(
new
PdeScrollBarUI
(
"editor.scrollbar"
));
horizontal
.
setUI
(
new
PdeScrollBarUI
(
"editor.scrollbar"
));
}
repaint
();
}
/**
* Set the gutter text of a specific line.
*
* @param lineIdx
* the line index (0-based)
* @param text
* the text
*/
public
void
setGutterText
(
int
lineIdx
,
String
text
) {
gutterText
.
put
(
lineIdx
,
text
);
painter
.
invalidateLine
(
lineIdx
);
}
/**
* Clear the gutter text of a specific line.
*
* @param lineIdx
* the line index (0-based)
*/
public
void
clearGutterText
(
int
lineIdx
) {
gutterText
.
remove
(
lineIdx
);
painter
.
invalidateLine
(
lineIdx
);
}
/**
* Clear all gutter text.
*/
public
void
clearGutterText
() {
for
(
int
lineIdx
:
gutterText
.
keySet
()) {
painter
.
invalidateLine
(
lineIdx
);
}
gutterText
.
clear
();
}
/**
* Retrieve the gutter text of a specific line.
* @param lineIdx the line index (0-based)
* @return the gutter text
*/
public
String
getGutterText
(
int
lineIdx
) {
return
gutterText
.
get
(
lineIdx
);
}
/**
* Convert a character offset to a horizontal pixel position inside
* the text area. Overridden to take gutter width into account.
* @param line the 0-based line number
* @param offset the character offset (0 is the first character on a line)
* @return the horizontal position
*/
@
Override
public
int
_offsetToX
(
int
line
,
int
offset
) {
return
super
.
_offsetToX
(
line
,
offset
) +
Editor
.
LEFT_GUTTER
;
}
/**
* Convert a horizontal pixel position to a character offset. Overridden to
* take gutter width into account.
* @param line the 0-based line number
* @param x the horizontal pixel position
* @return the character offset (0 is the first character on a line)
*/
@
Override
public
int
xToOffset
(
int
line
,
int
x
) {
return
super
.
xToOffset
(
line
,
x
-
Editor
.
LEFT_GUTTER
);
}
/**
* Sets default cursor (instead of text cursor) in the gutter area.
*/
protected
final
MouseMotionAdapter
gutterCursorMouseAdapter
=
new
MouseMotionAdapter
() {
private
int
lastX
;
// previous horizontal position of the mouse cursor
@
Override
public
void
mouseMoved
(
MouseEvent
me
) {
if
(
me
.
getX
() <
Editor
.
LEFT_GUTTER
) {
if
(
lastX
>=
Editor
.
LEFT_GUTTER
) {
painter
.
setCursor
(
new
Cursor
(
Cursor
.
DEFAULT_CURSOR
));
}
}
else
{
if
(
lastX
<
Editor
.
LEFT_GUTTER
) {
painter
.
setCursor
(
new
Cursor
(
Cursor
.
TEXT_CURSOR
));
}
}
lastX
=
me
.
getX
();
}
};
public
Editor
getEditor
() {
return
editor
;
}
}
Back
|
FazBrowse Home
|
New Git URL