23
23
package com .biglybt .ui .swt .views .tableitems .mytorrents ;
24
24
25
25
import org .eclipse .swt .graphics .Color ;
26
+ import org .eclipse .swt .graphics .Image ;
26
27
28
+ import com .biglybt .core .config .COConfigurationManager ;
29
+ import com .biglybt .core .config .ParameterListener ;
27
30
import com .biglybt .core .disk .DiskManagerFileInfo ;
28
31
import com .biglybt .core .util .Debug ;
29
32
import com .biglybt .core .util .DisplayFormatters ;
30
33
import com .biglybt .ui .swt .Utils ;
34
+ import com .biglybt .ui .swt .imageloader .ImageLoader ;
31
35
import com .biglybt .ui .swt .mainwindow .Colors ;
32
36
import com .biglybt .ui .swt .views .table .CoreTableColumnSWT ;
33
-
37
+ import com . biglybt . ui . swt . views . table . TableCellSWT ;
34
38
import com .biglybt .plugin .startstoprules .defaultplugin .DefaultRankCalculator ;
35
39
import com .biglybt .plugin .startstoprules .defaultplugin .StartStopRulesDefaultPlugin ;
36
40
37
41
import com .biglybt .pif .download .Download ;
38
42
import com .biglybt .pif .download .DownloadTypeIncomplete ;
43
+ import com .biglybt .pif .ui .menus .MenuItem ;
44
+ import com .biglybt .pif .ui .menus .MenuItemFillListener ;
45
+ import com .biglybt .pif .ui .menus .MenuItemListener ;
39
46
import com .biglybt .pif .ui .tables .*;
40
47
import com .biglybt .pifimpl .local .PluginCoreUtils ;
41
48
47
54
*/
48
55
public class DownSpeedItem
49
56
extends CoreTableColumnSWT
50
- implements TableCellAddedListener
57
+ implements TableCellAddedListener , ParameterListener
51
58
{
52
59
public static final Class DATASOURCE_TYPE = DownloadTypeIncomplete .class ;
53
60
54
61
public static final String COLUMN_ID = "downspeed" ;
55
62
56
- /** Default Constructor */
57
- public DownSpeedItem (String sTableID ) {
58
- super (DATASOURCE_TYPE , COLUMN_ID , ALIGN_TRAIL , 60 , sTableID );
59
- setType (TableColumn .TYPE_TEXT );
60
- addDataSourceType (DiskManagerFileInfo .class );
61
- setRefreshInterval (INTERVAL_LIVE );
62
- setUseCoreDataSource (false );
63
- }
63
+ private static final String CFG_SHOW_ICON = "DownSpeedColumn.showIcon" ;
64
+
65
+ private static Image disabled_img ;
66
+
67
+ static {
68
+ ImageLoader imageLoader = ImageLoader .getInstance ();
69
+
70
+ disabled_img = imageLoader .getImage ("Blocked_x" );
71
+ }
72
+
73
+ private boolean showIcon ;
74
+
75
+ public
76
+ DownSpeedItem (
77
+ String sTableID )
78
+ {
79
+ super (DATASOURCE_TYPE , COLUMN_ID , ALIGN_TRAIL , 60 , sTableID );
80
+ setType (TableColumn .TYPE_TEXT );
81
+ addDataSourceType (DiskManagerFileInfo .class );
82
+ setRefreshInterval (INTERVAL_LIVE );
83
+ setUseCoreDataSource (false );
84
+
85
+ showIcon = COConfigurationManager .getBooleanParameter (CFG_SHOW_ICON );
86
+
87
+ COConfigurationManager .addWeakParameterListener (this , false , CFG_SHOW_ICON );
88
+
89
+ TableContextMenuItem menuShowIcon = addContextMenuItem (
90
+ "pairing.ui.icon.show" , MENU_STYLE_HEADER );
91
+ menuShowIcon .setStyle (TableContextMenuItem .STYLE_CHECK );
92
+ menuShowIcon .addFillListener (new MenuItemFillListener () {
93
+ @ Override
94
+ public void menuWillBeShown (MenuItem menu , Object data ) {
95
+ menu .setData (Boolean .valueOf (showIcon ));
96
+ }
97
+ });
98
+
99
+ menuShowIcon .addMultiListener (new MenuItemListener () {
100
+ @ Override
101
+ public void selected (MenuItem menu , Object target ) {
102
+ COConfigurationManager .setParameter (CFG_SHOW_ICON ,
103
+ ((Boolean ) menu .getData ()).booleanValue ());
104
+ }
105
+ });
106
+ }
107
+
108
+ @ Override
109
+ public void
110
+ parameterChanged (
111
+ String parameterName )
112
+ {
113
+ setShowIcon ( COConfigurationManager .getBooleanParameter (CFG_SHOW_ICON ));
114
+ }
115
+
116
+ private void
117
+ setShowIcon (
118
+ boolean b )
119
+ {
120
+ showIcon = b ;
121
+ invalidateCells ();
122
+ }
123
+
124
+ @ Override
125
+ public void reset () {
126
+ super .reset ();
127
+
128
+ COConfigurationManager .removeParameter ( CFG_SHOW_ICON );
129
+ }
64
130
65
131
@ Override
66
132
public void fillTableColumnInfo (TableColumnInfo info ) {
@@ -71,78 +137,100 @@ public void fillTableColumnInfo(TableColumnInfo info) {
71
137
info .setProficiency (TableColumnInfo .PROFICIENCY_BEGINNER );
72
138
}
73
139
74
- @ Override
75
- public void cellAdded (TableCell cell ) {
76
- cell .addRefreshListener (new RefreshListener ());
77
- }
78
-
79
- private static class RefreshListener implements TableCellRefreshListener {
80
- private int iLastState ;
81
- private int loop = 0 ;
82
-
83
- @ Override
84
- public void refresh (TableCell cell ) {
85
- Object ds = cell .getDataSource ();
86
-
87
-
88
- if ( ds instanceof com .biglybt .pif .disk .DiskManagerFileInfo ){
89
-
90
- try {
91
- DiskManagerFileInfo fileInfo = PluginCoreUtils .unwrap ((com .biglybt .pif .disk .DiskManagerFileInfo )ds );
92
-
93
- int speed = fileInfo .getWriteBytesPerSecond ();
94
-
95
- if ( !cell .setSortValue ( speed ) && cell .isValid ()){
140
+ @ Override
141
+ public void cellAdded (TableCell cell ) {
142
+ cell .addRefreshListener (new RefreshListener ());
143
+ }
96
144
97
- return ;
145
+ private class
146
+ RefreshListener
147
+ implements TableCellRefreshListener
148
+ {
149
+ private int iLastState ;
150
+ private int loop = 0 ;
151
+
152
+ @ Override
153
+ public void refresh (TableCell cell ) {
154
+ Object ds = cell .getDataSource ();
155
+
156
+
157
+ if ( ds instanceof com .biglybt .pif .disk .DiskManagerFileInfo ){
158
+
159
+ try {
160
+ DiskManagerFileInfo fileInfo = PluginCoreUtils .unwrap ((com .biglybt .pif .disk .DiskManagerFileInfo )ds );
161
+
162
+ int speed = fileInfo .getWriteBytesPerSecond ();
163
+
164
+ if ( !cell .setSortValue ( speed ) && cell .isValid ()){
165
+
166
+ return ;
167
+ }
168
+
169
+ cell .setText ( speed ==0 ?"" :DisplayFormatters .formatByteCountToKiBEtcPerSec ( speed ));
170
+
171
+ }catch ( Throwable e ){
172
+
173
+ }
174
+ }else {
175
+ Download dm = (Download )ds ;
176
+ long value ;
177
+ int iState ;
178
+ if (dm == null ) {
179
+ iState = -1 ;
180
+ value = 0 ;
181
+ } else {
182
+ iState = dm .getState ();
183
+ value = dm .getStats ().getDownloadAverage ();
184
+ }
185
+
186
+ boolean bChangeColor = (++loop % 10 ) == 0 ;
187
+
188
+ if ( cell instanceof TableCellSWT && dm != null ) {
189
+
190
+ TableCellSWT swtCell = (TableCellSWT )cell ;
191
+
192
+ Image icon = null ;
193
+
194
+ if ( dm .getDownloadRateLimitBytesPerSecond () == -1 ){
195
+
196
+ value = -1 ; // sort below everything else
197
+
198
+ if ( showIcon ){
199
+
200
+ icon = disabled_img ;
201
+ }
202
+ }
203
+
204
+ swtCell .setIcon (icon );
205
+ }
206
+
207
+ if (cell .setSortValue (value ) || !cell .isValid () || (iState != iLastState )) {
208
+ cell .setText (value <= 0 ? (showIcon ?" " :"" ) : DisplayFormatters .formatByteCountToKiBEtcPerSec (value ));
209
+ bChangeColor = true ;
210
+ }
211
+
212
+ if (bChangeColor && dm != null ) {
213
+ changeColor (cell , dm , iState );
214
+ loop = 0 ;
215
+ }
98
216
}
217
+ }
99
218
100
- cell .setText ( speed ==0 ?"" :DisplayFormatters .formatByteCountToKiBEtcPerSec ( speed ));
101
-
102
- }catch ( Throwable e ){
103
-
104
- }
105
- }else {
106
- Download dm = (Download )ds ;
107
- long value ;
108
- int iState ;
109
- if (dm == null ) {
110
- iState = -1 ;
111
- value = 0 ;
112
- } else {
113
- iState = dm .getState ();
114
- value = dm .getStats ().getDownloadAverage ();
115
- }
116
-
117
- boolean bChangeColor = (++loop % 10 ) == 0 ;
118
-
119
- if (cell .setSortValue (value ) || !cell .isValid () || (iState != iLastState )) {
120
- cell .setText (value == 0 ? "" : DisplayFormatters .formatByteCountToKiBEtcPerSec (value ));
121
- bChangeColor = true ;
122
- }
123
-
124
- if (bChangeColor && dm != null ) {
125
- changeColor (cell , dm , iState );
126
- loop = 0 ;
127
- }
128
- }
129
- }
130
-
131
- private void changeColor (TableCell cell , Download dl , int iState ) {
132
- try {
133
- DefaultRankCalculator calc = StartStopRulesDefaultPlugin .getRankCalculator (dl );
134
-
135
- Color newFG = null ;
136
- if (calc != null && dl .getState () == Download .ST_DOWNLOADING
219
+ private void changeColor (TableCell cell , Download dl , int iState ) {
220
+ try {
221
+ DefaultRankCalculator calc = StartStopRulesDefaultPlugin .getRankCalculator (dl );
222
+
223
+ Color newFG = null ;
224
+ if (calc != null && dl .getState () == Download .ST_DOWNLOADING
137
225
&& !calc .getActivelyDownloading ())
138
226
newFG = Colors .colorWarning ;
139
227
140
- cell .setForeground (Utils .colorToIntArray (newFG ));
228
+ cell .setForeground (Utils .colorToIntArray (newFG ));
141
229
142
- iLastState = iState ;
143
- } catch (Exception e ) {
144
- Debug .printStackTrace ( e );
145
- }
146
- }
147
- }
230
+ iLastState = iState ;
231
+ } catch (Exception e ) {
232
+ Debug .printStackTrace ( e );
233
+ }
234
+ }
235
+ }
148
236
}
0 commit comments