Skip to content

Commit cbf2629

Browse files
committed
Added blocked icons for up/down speed when disabled
1 parent 3f5cc58 commit cbf2629

File tree

5 files changed

+312
-146
lines changed

5 files changed

+312
-146
lines changed
614 Bytes
Loading

uis/src/com/biglybt/ui/icons/icons.properties

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ net_Tor_s=com/biglybt/ui/icons/net_Tor_s.png
8484
net_Tor_b=com/biglybt/ui/icons/net_Tor_b.png
8585
net_None_x=com/biglybt/ui/icons/net_None_x.png
8686

87+
Blocked_x=com/biglybt/ui/icons/Blocked_x.png
8788

8889
transparent=com/biglybt/ui/icons/transparent16x16.png
8990

uis/src/com/biglybt/ui/swt/UIConfigDefaultsSWT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public static void initialize() {
7575
def.addParameter("RankColumn.showUpDownIcon.small", false );
7676
def.addParameter("SeedsColumn.showNetworkIcon", true );
7777
def.addParameter("PeersColumn.showNetworkIcon", true );
78-
78+
def.addParameter("DownSpeedColumn.showIcon", true );
79+
def.addParameter("UpSpeedColumn.showIcon", true );
80+
7981
def.addParameter("DND Always In Incomplete", false);
8082

8183
def.addParameter("Message Popup Autoclose in Seconds", 15);

uis/src/com/biglybt/ui/swt/views/tableitems/mytorrents/DownSpeedItem.java

+165-77
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@
2323
package com.biglybt.ui.swt.views.tableitems.mytorrents;
2424

2525
import org.eclipse.swt.graphics.Color;
26+
import org.eclipse.swt.graphics.Image;
2627

28+
import com.biglybt.core.config.COConfigurationManager;
29+
import com.biglybt.core.config.ParameterListener;
2730
import com.biglybt.core.disk.DiskManagerFileInfo;
2831
import com.biglybt.core.util.Debug;
2932
import com.biglybt.core.util.DisplayFormatters;
3033
import com.biglybt.ui.swt.Utils;
34+
import com.biglybt.ui.swt.imageloader.ImageLoader;
3135
import com.biglybt.ui.swt.mainwindow.Colors;
3236
import com.biglybt.ui.swt.views.table.CoreTableColumnSWT;
33-
37+
import com.biglybt.ui.swt.views.table.TableCellSWT;
3438
import com.biglybt.plugin.startstoprules.defaultplugin.DefaultRankCalculator;
3539
import com.biglybt.plugin.startstoprules.defaultplugin.StartStopRulesDefaultPlugin;
3640

3741
import com.biglybt.pif.download.Download;
3842
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;
3946
import com.biglybt.pif.ui.tables.*;
4047
import com.biglybt.pifimpl.local.PluginCoreUtils;
4148

@@ -47,20 +54,79 @@
4754
*/
4855
public class DownSpeedItem
4956
extends CoreTableColumnSWT
50-
implements TableCellAddedListener
57+
implements TableCellAddedListener, ParameterListener
5158
{
5259
public static final Class DATASOURCE_TYPE = DownloadTypeIncomplete.class;
5360

5461
public static final String COLUMN_ID = "downspeed";
5562

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+
}
64130

65131
@Override
66132
public void fillTableColumnInfo(TableColumnInfo info) {
@@ -71,78 +137,100 @@ public void fillTableColumnInfo(TableColumnInfo info) {
71137
info.setProficiency(TableColumnInfo.PROFICIENCY_BEGINNER);
72138
}
73139

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+
}
96144

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+
}
98216
}
217+
}
99218

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
137225
&& !calc.getActivelyDownloading())
138226
newFG = Colors.colorWarning;
139227

140-
cell.setForeground(Utils.colorToIntArray(newFG));
228+
cell.setForeground(Utils.colorToIntArray(newFG));
141229

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+
}
148236
}

0 commit comments

Comments
 (0)