FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/syntax/PdeTextArea.java at master · processing/processing · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
processing
/
processing
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
1.5k
Star
6.5k
Code
Issues
0
Pull requests
0
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
syntax
/
PdeTextArea.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
183 lines (143 loc) · 4.85 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
syntax
/
PdeTextArea.java
Copy path
File metadata and controls
183 lines (143 loc) · 4.85 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
/* -*- 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
.
Cursor
;
import
java
.
awt
.
Image
;
import
java
.
awt
.
event
.
MouseEvent
;
import
java
.
awt
.
event
.
MouseMotionAdapter
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
import
processing
.
app
.
Mode
;
import
processing
.
app
.
ui
.
Editor
;
/**
* 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
;
// change cursor to pointer in the gutter area
painter
.
addMouseMotionListener
(
gutterCursorMouseAdapter
);
add
(
CENTER
,
painter
);
// load settings from theme.txt
Mode
mode
=
editor
.
getMode
();
gutterGradient
=
mode
.
makeGradient
(
"editor"
,
Editor
.
LEFT_GUTTER
,
500
);
}
@
Override
protected
TextAreaPainter
createPainter
(
final
TextAreaDefaults
defaults
) {
return
new
PdeTextAreaPainter
(
this
,
defaults
);
}
public
Image
getGutterGradient
() {
return
gutterGradient
;
}
public
void
setMode
(
Mode
mode
) {
((
PdeTextAreaPainter
)
painter
).
setMode
(
mode
);
}
/**
* 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 he 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