* @return composite holding the statusbar
*/
public Composite initStatusBar(final Composite parent) {
this.display = parent.getDisplay();
this.uiFunctions = UIFunctionsManager.getUIFunctions();
ImageLoader imageLoader = ImageLoader.getInstance();
FormData formData;
Color fgColor = parent.getForeground();
statusBar = new Composite(parent, SWT.NONE);
statusBar.setForeground(fgColor);
isAZ3 = "az3".equalsIgnoreCase(COConfigurationManager.getStringParameter("ui"));
statusBar.getShell().addListener(SWT.Deiconify, new Listener() {
public void handleEvent(Event event) {
Utils.execSWTThreadLater(0, new AERunnable() {
public void runSupport() {
if (!statusBar.isDisposed()) {
statusBar.layout();
}
}
});
}
});
GridLayout layout_status = new GridLayout();
layout_status.numColumns = 20;
layout_status.horizontalSpacing = 0;
layout_status.verticalSpacing = 0;
layout_status.marginHeight = 0;
if (Constants.isOSX) {
// OSX has a resize widget on the bottom right. It's about 15px wide.
try {
layout_status.marginRight = 15;
} catch (NoSuchFieldError e) {
// Pre SWT 3.1
layout_status.marginWidth = 15;
}
} else {
layout_status.marginWidth = 0;
}
statusBar.setLayout(layout_status);
//Either the Status Text
statusText = new CLabel(statusBar, borderFlag);
statusText.setForeground(fgColor);
statusText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
| GridData.VERTICAL_ALIGN_FILL));
addStatusBarMenu(statusText);
GC gc = new GC(statusText);
// add 6, because CLabel forces a 3 pixel indent
int height = Math.max(16, gc.getFontMetrics().getHeight()) + 6;
gc.dispose();
formData = new FormData();
formData.height = height;
formData.bottom = new FormAttachment(100, 0); // 2 params for Pre SWT 3.0
formData.left = new FormAttachment(0, 0); // 2 params for Pre SWT 3.0
formData.right = new FormAttachment(100, 0); // 2 params for Pre SWT 3.0
statusBar.setLayoutData(formData);
Listener listener = new Listener() {
public void handleEvent(Event e) {
if (clickListener == null) {
if (updateWindow != null) {
updateWindow.show();
}
} else {
clickListener.UIStatusTextClicked();
}
}
};
statusText.addListener(SWT.MouseUp, listener);
statusText.addListener(SWT.MouseDoubleClick, listener);
// final int progressFlag = (Constants.isOSX) ? SWT.INDETERMINATE : SWT.HORIZONTAL;
// KN: Don't know why OSX is treated differently but this check was already here from the previous code
if (true == Constants.isOSX) {
progressBar = new AZProgressBar(statusBar, true);
} else {
progressBar = new AZProgressBar(statusBar, false);
}
progressBar.setVisible(false);
progressGridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
progressGridData.widthHint = 5;
progressBar.setLayoutData(progressGridData);
if ( isAZ3 ){
try{
addFeedBack();
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
/*
* Progress reporting window image label
*/
progressViewerImageLabel = new CLabelPadding(statusBar, SWT.NONE);
// image set below after adding listener
progressViewerImageLabel.setToolTipText(MessageText.getString("Progress.reporting.statusbar.button.tooltip"));
progressViewerImageLabel.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
/*
* Opens the progress viewer if any of the reporters in the array is NOT already opened
* KN: TODO -- This is only a partial solution to minimize the occurrence of the main progress window
* opening more than once. The one remaining case where multiple windows will still open is
* when you have one opened already... then run another process such as a torrent file download...
* at this point this new process is not in the already opened window so the check would
* allow the second window to open.
*/
IProgressReporter[] reporters = PRManager.getReportersArray(false);
if (reporters.length == 0) {
/*
* If there's nothing to see then open the window; the default widow will say there's nothing to see
* KN: calling isShowingEmpty return true is there is already a window opened showing the empty panel
*/
if (false == ProgressReporterWindow.isShowingEmpty()) {
ProgressReporterWindow.open(reporters,
ProgressReporterWindow.SHOW_TOOLBAR);
}
} else {
for (int i = 0; i < reporters.length; i++) {
if (false == ProgressReporterWindow.isOpened(reporters[i])) {
ProgressReporterWindow.open(reporters,
ProgressReporterWindow.SHOW_TOOLBAR);
break;
}
}
}
}
});
progressViewerImageLabel.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.releaseImage("progress_error");
imageLoader.releaseImage("progress_info");
imageLoader.releaseImage("progress_viewer");
}
});
this.plugin_label_composite = new Composite(statusBar, SWT.NONE);
this.plugin_label_composite.setForeground(fgColor);
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = 0;
gridLayout.marginBottom = 0;
gridLayout.marginTop = 0;
gridLayout.marginLeft = 0;
gridLayout.marginRight = 0;
gridLayout.numColumns = 20; // Something nice and big. :)
GridData gridData = new GridData(GridData.FILL_VERTICAL);
gridData.heightHint = height;
gridData.minimumHeight = height;
plugin_label_composite.setLayout(gridLayout);
plugin_label_composite.setLayoutData(gridData);
srStatus = new CLabelPadding(statusBar, borderFlag);
srStatus.setText(MessageText.getString("SpeedView.stats.ratio"));
COConfigurationManager.addAndFireParameterListener("Status Area Show SR",
new ParameterListener() {
public void parameterChanged(String parameterName) {
srStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
natStatus = new CLabelPadding(statusBar, borderFlag);
natStatus.setText("");
COConfigurationManager.addAndFireParameterListener("Status Area Show NAT",
new ParameterListener() {
public void parameterChanged(String parameterName) {
natStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
dhtStatus = new CLabelPadding(statusBar, borderFlag);
dhtStatus.setText("");
dhtStatus.setToolTipText(MessageText.getString("MainWindow.dht.status.tooltip"));
COConfigurationManager.addAndFireParameterListener("Status Area Show DDB",
new ParameterListener() {
public void parameterChanged(String parameterName) {
dhtStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
ipBlocked = new CLabelPadding(statusBar, borderFlag);
ipBlocked.setText("{} IPs:"); //$NON-NLS-1$
Messages.setLanguageText(ipBlocked, "MainWindow.IPs.tooltip");
ipBlocked.addListener(SWT.MouseDoubleClick, new ListenerNeedingCoreRunning() {
public void handleEvent(AzureusCore core, Event event) {
BlockedIpsWindow.showBlockedIps(core, parent.getShell());
}
});
COConfigurationManager.addAndFireParameterListener("Status Area Show IPF",
new ParameterListener() {
public void parameterChanged(String parameterName) {
ipBlocked.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
statusDown = new CLabelPadding(statusBar, borderFlag);
statusDown.setImage(imageLoader.getImage("down"));
//statusDown.setText(/*MessageText.getString("ConfigView.download.abbreviated") +*/"n/a");
Messages.setLanguageText(statusDown,
"MainWindow.status.updowndetails.tooltip");
Listener lStats = new Listener() {
public void handleEvent(Event e) {
uiFunctions.openView(UIFunctions.VIEW_STATS, null);
}
};
statusUp = new CLabelPadding(statusBar, borderFlag);
statusUp.setImage(imageLoader.getImage("up"));
//statusUp.setText(/*MessageText.getString("ConfigView.upload.abbreviated") +*/"n/a");
Messages.setLanguageText(statusUp,
"MainWindow.status.updowndetails.tooltip");
statusDown.addListener(SWT.MouseDoubleClick, lStats);
statusUp.addListener(SWT.MouseDoubleClick, lStats);
Listener lDHT = new Listener() {
public void handleEvent(Event e) {
uiFunctions.openView(UIFunctions.VIEW_STATS, "dht");
}
};
dhtStatus.addListener(SWT.MouseDoubleClick, lDHT);
Listener lSR = new Listener() {
public void handleEvent(Event e) {
uiFunctions.openView(UIFunctions.VIEW_STATS, "transfers");
OverallStats stats = StatsFactory.getStats();
if (stats == null) {
return;
}
long ratio = (1000 * stats.getUploadedBytes() / (stats.getDownloadedBytes() + 1));
if (ratio < 900) {
Utils.launch(Constants.AZUREUS_WIKI + "Share_Ratio");
}
}
};
srStatus.addListener(SWT.MouseDoubleClick, lSR);
Listener lNAT = new ListenerNeedingCoreRunning() {
public void handleEvent(AzureusCore core, Event e) {
uiFunctions.openView(UIFunctions.VIEW_CONFIG,
ConfigSection.SECTION_CONNECTION);
if (PluginInitializer.getDefaultInterface().getConnectionManager().getNATStatus() != ConnectionManager.NAT_OK) {
Utils.launch(Constants.AZUREUS_WIKI + "NAT_problem");
}
}
};
natStatus.addListener(SWT.MouseDoubleClick, lNAT);
boolean bSpeedMenu = COConfigurationManager.getBooleanParameter("GUI_SWT_bOldSpeedMenu");
if (bSpeedMenu) {
// Status Bar Menu construction
final Menu menuUpSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
menuUpSpeed.addListener(SWT.Show, new Listener() {
public void handleEvent(Event e) {
if (!AzureusCoreFactory.isCoreRunning()) {
return;
}
AzureusCore core = AzureusCoreFactory.getSingleton();
GlobalManager globalManager = core.getGlobalManager();
SelectableSpeedMenu.generateMenuItems(menuUpSpeed, core,
globalManager, true);
}
});
statusUp.setMenu(menuUpSpeed);
} else {
statusUp.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
return;
}
Event event = new Event();
event.type = SWT.MouseUp;
event.widget = e.widget;
event.stateMask = e.stateMask;
event.button = e.button;
e.widget.getDisplay().post(event);
CoreWaiterSWT.waitForCoreRunning(new AzureusCoreRunningListener() {
public void azureusCoreRunning(AzureusCore core) {
SelectableSpeedMenu.invokeSlider(core, true);
}
});
}
});
}
if (bSpeedMenu) {
final Menu menuDownSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
menuDownSpeed.addListener(SWT.Show, new Listener() {
public void handleEvent(Event e) {
if (!AzureusCoreFactory.isCoreRunning()) {
return;
}
AzureusCore core = AzureusCoreFactory.getSingleton();
GlobalManager globalManager = core.getGlobalManager();
SelectableSpeedMenu.generateMenuItems(menuDownSpeed, core,
globalManager, false);
}
});
statusDown.setMenu(menuDownSpeed);
} else {
statusDown.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
return;
}
Event event = new Event();
event.type = SWT.MouseUp;
event.widget = e.widget;
event.stateMask = e.stateMask;
event.button = e.button;
e.widget.getDisplay().post(event);
CoreWaiterSWT.waitForCoreRunning(new AzureusCoreRunningListener() {
public void azureusCoreRunning(AzureusCore core) {
SelectableSpeedMenu.invokeSlider(core, false);
}
});
}
});
}
statusWarnings = new CLabelPadding(statusBar, borderFlag);
warningIcon = imageLoader.getImage("image.sidebar.vitality.alert");
infoIcon = imageLoader.getImage("image.sidebar.vitality.info");
updateStatusWarnings();
Messages.setLanguageText(statusWarnings,
"MainWindow.status.warning.tooltip");
Alerts.addMessageHistoryListener(new AlertHistoryListener() {
public void alertHistoryAdded(LogAlert params) {