FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/contrib/UpdateListPanel.java at master · dimr/processing · GitHub
dimr
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
contrib
/
UpdateListPanel.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
247 lines (222 loc) · 8.49 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
contrib
/
UpdateListPanel.java
Copy path
File metadata and controls
247 lines (222 loc) · 8.49 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
package
processing
.
app
.
contrib
;
import
java
.
awt
.
Color
;
import
java
.
awt
.
Component
;
import
java
.
util
.
Arrays
;
import
java
.
util
.
Comparator
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
Set
;
import
java
.
util
.
TreeMap
;
import
javax
.
swing
.
BorderFactory
;
import
javax
.
swing
.
GroupLayout
;
import
javax
.
swing
.
Icon
;
import
javax
.
swing
.
JScrollPane
;
import
javax
.
swing
.
JTable
;
import
javax
.
swing
.
ListSelectionModel
;
import
javax
.
swing
.
table
.
DefaultTableCellRenderer
;
import
javax
.
swing
.
table
.
DefaultTableModel
;
import
javax
.
swing
.
table
.
TableCellRenderer
;
import
processing
.
app
.
Base
;
public
class
UpdateListPanel
extends
ListPanel
{
static
final
Color
SECTION_COLOR
=
new
Color
(
0xFFf8f8f8
);
static
final
String
[]
PLURAL_TYPES
= {
ContributionType
.
LIBRARY
.
getPluralTitle
(),
ContributionType
.
MODE
.
getPluralTitle
(),
ContributionType
.
TOOL
.
getPluralTitle
(),
ContributionType
.
EXAMPLES
.
getPluralTitle
(),
};
Set
<
String
>
sectionNames
=
new
HashSet
<
String
>(
Arrays
.
asList
(
PLURAL_TYPES
));
public
UpdateListPanel
(
ContributionTab
contributionTab
,
Contribution
.
Filter
filter
) {
this
.
contributionTab
=
contributionTab
;
this
.
filter
=
filter
;
setOpaque
(
true
);
setBackground
(
Color
.
WHITE
);
model
=
new
DefaultTableModel
() {
@
Override
public
boolean
isCellEditable
(
int
row
,
int
column
) {
return
false
;
}
@
Override
public
Class
<?>
getColumnClass
(
int
columnIndex
) {
return
(
columnIndex
==
0
) ?
Icon
.
class
:
String
.
class
;
}
};
model
.
setColumnIdentifiers
(
new
String
[] {
""
,
"Name"
,
"Author"
,
"Installed"
,
"Available"
});
table
=
new
JTable
(
model
) {
@
Override
public
Component
prepareRenderer
(
TableCellRenderer
renderer
,
int
row
,
int
column
) {
Component
c
=
super
.
prepareRenderer
(
renderer
,
row
,
column
);
String
title
= (
String
)
getValueAt
(
row
,
1
);
if
(
sectionNames
.
contains
(
title
)) {
c
.
setBackground
(
SECTION_COLOR
);
}
else
{
c
.
setBackground
(
Color
.
WHITE
);
}
return
c
;
}
@
Override
public
void
changeSelection
(
int
rowIndex
,
int
columnIndex
,
boolean
toggle
,
boolean
extend
) {
String
title
= (
String
)
getValueAt
(
rowIndex
,
1
);
// Disallow selection on the fake rows
if
(!
sectionNames
.
contains
(
title
)) {
super
.
changeSelection
(
rowIndex
,
columnIndex
,
toggle
,
extend
);
}
}
};
scrollPane
=
new
JScrollPane
(
table
);
scrollPane
.
setBorder
(
BorderFactory
.
createEmptyBorder
());
table
.
setFillsViewportHeight
(
true
);
table
.
setSelectionBackground
(
new
Color
(
0xe0fffd
));
table
.
setSelectionForeground
(
table
.
getForeground
());
table
.
setFont
(
ManagerFrame
.
NORMAL_PLAIN
);
table
.
setRowHeight
(
30
);
table
.
setRowMargin
(
6
);
table
.
getColumnModel
().
setColumnMargin
(-
1
);
table
.
getColumnModel
().
getColumn
(
0
).
setMaxWidth
(
60
);
table
.
setShowGrid
(
false
);
table
.
setCellSelectionEnabled
(
false
);
table
.
setRowSelectionAllowed
(
true
);
table
.
setAutoCreateColumnsFromModel
(
true
);
table
.
setSelectionMode
(
ListSelectionModel
.
SINGLE_SELECTION
);
table
.
setDefaultRenderer
(
String
.
class
,
new
DefaultTableCellRenderer
() {
@
Override
public
Component
getTableCellRendererComponent
(
JTable
table
,
Object
value
,
boolean
isSelected
,
boolean
hasFocus
,
int
row
,
int
column
) {
return
super
.
getTableCellRendererComponent
(
table
,
value
,
isSelected
,
false
,
row
,
column
);
}
});
table
.
getTableHeader
().
setDefaultRenderer
(
new
ContribHeaderRenderer
());
/* {
@Override
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus, int row,
int column) {
super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
JTableHeader tableHeader = table.getTableHeader();
if (tableHeader != null) {
setForeground(tableHeader.getForeground());
}
setIcon(getSortIcon(table, column));
setBackground(new Color(0xebebeb));
return this;
}
});*/
GroupLayout
layout
=
new
GroupLayout
(
this
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
().
addComponent
(
scrollPane
));
layout
.
setVerticalGroup
(
layout
.
createSequentialGroup
().
addComponent
(
scrollPane
));
setLayout
(
layout
);
table
.
setVisible
(
true
);
panelByContribution
=
new
TreeMap
<
Contribution
,
DetailPanel
>(
new
Comparator
<
Contribution
>() {
@
Override
public
int
compare
(
Contribution
o1
,
Contribution
o2
) {
int
diff
=
ContributionManager
.
getTypeIndex
(
o1
.
getType
()) -
ContributionManager
.
getTypeIndex
(
o2
.
getType
());
if
(
diff
==
0
) {
diff
=
o1
.
getName
().
toLowerCase
().
compareTo
(
o2
.
getName
().
toLowerCase
());
}
return
diff
;
}
});
}
// Thread: EDT
@
Override
void
updatePanelOrdering
(
Set
<
Contribution
>
contributionsSet
) {
model
.
getDataVector
().
removeAllElements
();
ContributionType
currentType
=
null
;
String
fontFace
=
"<font face=
\"
"
+
ManagerFrame
.
NORMAL_BOLD
.
getName
() +
"
\"
>"
;
for
(
Contribution
entry
:
contributionsSet
) {
if
(
entry
.
getType
() !=
currentType
) {
currentType
=
entry
.
getType
();
model
.
addRow
(
new
Object
[] {
null
,
currentType
.
getPluralTitle
(),
null
,
null
,
null
});
}
//TODO Make this into a function
StringBuilder
name
=
new
StringBuilder
(
""
);
String
authorList
=
entry
.
getAuthorList
();
if
(
authorList
!=
null
) {
for
(
int
i
=
0
;
i
<
authorList
.
length
();
i
++) {
if
(
authorList
.
charAt
(
i
) ==
'['
||
authorList
.
charAt
(
i
) ==
']'
) {
continue
;
}
if
(
authorList
.
charAt
(
i
) ==
'('
) {
i
++;
while
(
authorList
.
charAt
(
i
) !=
')'
) {
i
++;
}
}
else
{
name
.
append
(
authorList
.
charAt
(
i
));
}
}
}
Icon
icon
=
null
;
if
(
entry
.
isInstalled
()) {
icon
=
upToDateIcon
;
if
(
contribListing
.
hasUpdates
(
entry
)) {
icon
=
updateAvailableIcon
;
}
if
(!
entry
.
isCompatible
(
Base
.
getRevision
())) {
icon
=
incompatibleIcon
;
}
}
if
((
panelByContribution
.
get
(
entry
)).
updateInProgress
||
(
panelByContribution
.
get
(
entry
)).
installInProgress
) {
// Display "Loading icon" if download/install in progress
icon
=
downloadingIcon
;
}
model
.
addRow
(
new
Object
[] {
icon
,
"<html>"
+
fontFace
+
entry
.
getName
() +
"</font></html>"
,
name
,
entry
.
getBenignVersion
(),
contributionTab
.
contribListing
.
getLatestPrettyVersion
(
entry
)
});
}
model
.
fireTableDataChanged
();
UpdateContributionTab
tab
= (
UpdateContributionTab
)
contributionTab
;
((
UpdateStatusPanel
)
tab
.
statusPanel
).
update
();
}
// Thread: EDT
@
Override
public
void
contributionAdded
(
final
Contribution
contribution
) {
if
(
filter
.
matches
(
contribution
)) {
// TODO make this longer and more contorted [fry]
DetailPanel
newPanel
=
contributionTab
.
contribDialog
.
getTab
(
contribution
.
getType
()).
contributionListPanel
.
panelByContribution
.
get
(
contribution
);
if
(
newPanel
==
null
) {
newPanel
=
new
DetailPanel
(
UpdateListPanel
.
this
);
}
if
(!
panelByContribution
.
containsKey
(
contribution
)) {
panelByContribution
.
put
(
contribution
,
newPanel
);
}
visibleContributions
.
add
(
contribution
);
newPanel
.
setContribution
(
contribution
);
add
(
newPanel
);
updatePanelOrdering
(
panelByContribution
.
keySet
());
updateColors
();
// XXX this is the place
}
}
// Thread: EDT
@
Override
public
void
contributionChanged
(
final
Contribution
oldContrib
,
final
Contribution
newContrib
) {
DetailPanel
panel
=
panelByContribution
.
get
(
oldContrib
);
if
(
panel
==
null
) {
contributionAdded
(
newContrib
);
}
else
if
(
newContrib
.
isInstalled
()) {
panelByContribution
.
remove
(
oldContrib
);
visibleContributions
.
remove
(
oldContrib
);
}
updatePanelOrdering
(
visibleContributions
);
}
}
Back
|
FazBrowse Home
|
New Git URL