下面列出了怎么用java.awt.Taskbar.Feature的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean isSupported(Feature feature) {
switch (feature) {
case ICON_BADGE_NUMBER:
case MENU:
case PROGRESS_VALUE:
case USER_ATTENTION:
return true;
default:
return false;
}
}
@Override
public void setIconBadge(String badge) {
boolean visible = false;
long val = 0;
if (badge != null) {
try {
val = Long.parseLong(badge);
visible = true;
} catch (NumberFormatException e) {
throw new UnsupportedOperationException("The " + Feature.ICON_BADGE_TEXT
+ " feature is not supported on the current platform!");
}
}
setBadge(val, visible);
}
@Override
public boolean isSupported(Feature feature) {
switch(feature) {
case ICON_BADGE_TEXT:
case ICON_BADGE_NUMBER:
case ICON_IMAGE:
case MENU:
case PROGRESS_VALUE:
case USER_ATTENTION:
return true;
default:
return false;
}
}
@Override
public boolean isSupported(Feature feature) {
switch(feature) {
case ICON_BADGE_IMAGE_WINDOW:
case PROGRESS_STATE_WINDOW:
case PROGRESS_VALUE_WINDOW:
return supported;
case USER_ATTENTION_WINDOW:
return true;
default:
return false;
}
}
public static void main(String[] args) {
if (Taskbar.isTaskbarSupported()) {
System.out.println("Taskbar is supported - feature support breakdown:");
Taskbar taskbar = Taskbar.getTaskbar();
stream(Feature.values())
.forEach(feature -> System.out.printf(" - %s: %s%n", feature, taskbar.isSupported(feature)));
} else {
System.out.println("Taskbar is not on your platform. :(");
}
}
public void update(Downloader d, String file) {
titleLbl.setText(file);
if (d.getProgress() > 0) {
setTitle("[" + d.getProgress() + "%]" + file);
} else {
setTitle(file);
}
String statTxt = "";
if (d.isConverting()) {
statTxt = StringResource.get("TITLE_CONVERT");
} else if (d.isAssembling()) {
statTxt = StringResource.get("STAT_ASSEMBLING");
} else {
statTxt = StringResource.get("STAT_DOWNLOADING");
}
lblStat.setText(statTxt);
// StringBuilder sb = new StringBuilder();
// sb.append((d.isAssembling() ? StringResource.get("STAT_ASSEMBLING")
// : StringResource.get("DWN_DOWNLOAD")));
// sb.append(" ");
// sb.append(FormatUtilities.formatSize(d.getDownloaded()));
// sb.append(" ");
// sb.append(d.getType()==XDMConstants.HTTP?)
lblDet.setText((d.isAssembling() ? StringResource.get("STAT_ASSEMBLING") : StringResource.get("DWN_DOWNLOAD"))
+ " " + FormatUtilities.formatSize(d.getDownloaded()) + " "
+ ((d.getType() == XDMConstants.HTTP || d.getType() == XDMConstants.DASH)
? "/ " + FormatUtilities.formatSize(d.getSize())
: "( " + d.getProgress() + " % )"));
lblSpeed.setText(FormatUtilities.formatSize(d.getDownloadSpeed()) + "/s");
lblETA.setText("ETA " + d.getEta());
prgCircle.setValue(d.getProgress());
SegmentDetails segDet = d.getSegmentDetails();
long sz = ((d.getType() == XDMConstants.HTTP || d.getType() == XDMConstants.FTP
|| d.getType() == XDMConstants.DASH) ? d.getSize() : 100);
segProgress.setValues(segDet, sz);
if (Taskbar.isTaskbarSupported()) {
Taskbar taskbar = Taskbar.getTaskbar();
if(taskbar.isSupported(Feature.PROGRESS_VALUE_WINDOW)) {
taskbar.setWindowProgressValue(this, d.getProgress());
}
}
}
/**
* Tests support of {@code Feature} on current platform.
* @param f feature to test
* @return true if feature supported supported
*/
default public boolean isSupported(Feature f) { return false; }
/**
* Tests support of {@code Feature} on current platform.
* @param f feature to test
* @return true if feature supported supported
*/
default public boolean isSupported(Feature f) { return false; }