IconBarpublic class IconBar extends Object
Fields Summary |
---|
private final boolean | OVERRIDE_SHOW_UISWITCHER | CoolBar | coolBar | Composite | parent | Map | itemKeyToControl | IconBarEnabler | currentEnabler | private Composite | cIconBar |
Constructors Summary |
---|
public IconBar(Composite parent)
this.parent = parent;
cIconBar = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
cIconBar.setLayout(layout);
this.itemKeyToControl = new HashMap();
// 3.1 onwards the default is gradient-fill - the disabled icons' transparency no workies
// so disabled buttons look bad on the gradient-filled background
this.coolBar = new CoolBar(cIconBar,Constants.isWindows?SWT.FLAT:SWT.NULL);
initBar();
this.coolBar.setLocked(true);
coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// We could setup a listener on the parameter and dynamically remove/add
// ui switcher button, but it's not worth the effort
boolean enableUISwitcher = OVERRIDE_SHOW_UISWITCHER
|| COConfigurationManager.getBooleanParameter("ui.toolbar.uiswitcher")
|| COConfigurationManager.getBooleanParameter("ui.asked", false);
if (enableUISwitcher) {
ToolBar tbSwitch = new ToolBar(cIconBar, SWT.FLAT);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
tbSwitch.setLayoutData(gridData);
ToolItem tiSwitch = new ToolItem(tbSwitch, SWT.PUSH);
tiSwitch.setImage(ImageRepository.getImage("cb_switch"));
Messages.setLanguageText(tiSwitch, "iconBar.switch.tooltip", true);
tiSwitch.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String uiOld = COConfigurationManager.getStringParameter("ui");
String uiNew = UISwitcherUtil.openSwitcherWindow(true);
if (!uiOld.equals(uiNew)) {
int result = MessageBoxShell.open(IconBar.this.parent.getShell(),
MessageText.getString("dialog.uiswitcher.restart.title"),
MessageText.getString("dialog.uiswitcher.restart.text"),
new String[] {
MessageText.getString("UpdateWindow.restart"),
MessageText.getString("UpdateWindow.restartLater"),
}, 0);
if (result == 0) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.dispose(true, false);
}
}
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
|
Methods Summary |
---|
private org.gudy.azureus2.ui.swt.components.BufferedToolItem | createBufferedToolItem(ToolBar toolBar, int style, java.lang.String key, java.lang.String imageName, java.lang.String toolTipKey)
final BufferedToolItem bufferedToolItem = new BufferedToolItem(toolBar,style);
bufferedToolItem.setData("key",key);
Messages.setLanguageText(bufferedToolItem.getWidget(),toolTipKey,true);
bufferedToolItem.setImage(ImageRepository.getImage(imageName));
bufferedToolItem.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event e) {
if(currentEnabler != null)
currentEnabler.itemActivated((String)bufferedToolItem.getData("key"));
}
});
itemKeyToControl.put(key,bufferedToolItem);
return bufferedToolItem;
| public void | delete()
Utils.disposeComposite(cIconBar);
itemKeyToControl.clear();
currentEnabler = null;
| public Composite | getComposite()
return cIconBar;
| private void | initBar()
//The File Menu
CoolItem coolItem = new CoolItem(coolBar,SWT.NULL);
ToolBar toolBar = new ToolBar(coolBar,SWT.FLAT);
createBufferedToolItem(toolBar,SWT.PUSH,"open","cb_open_no_default","iconBar.open.tooltip");
// XXX TuxPaper: Remove images (open, open_url, open_folder) from CVS and ImageRepository
createBufferedToolItem(toolBar,SWT.PUSH,"new","cb_new","iconBar.new.tooltip");
toolBar.pack();
Point p = toolBar.getSize();
coolItem.setControl(toolBar);
coolItem.setSize(coolItem.computeSize (p.x,p.y));
coolItem.setMinimumSize(p.x,p.y);
coolItem = new CoolItem(coolBar,SWT.NULL);
toolBar = new ToolBar(coolBar,SWT.FLAT);
createBufferedToolItem(toolBar,SWT.PUSH,"top","cb_top","iconBar.top.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"up","cb_up","iconBar.up.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"down","cb_down","iconBar.down.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"bottom","cb_bottom","iconBar.bottom.tooltip");
new BufferedToolItem(toolBar,SWT.SEPARATOR);
createBufferedToolItem(toolBar,SWT.PUSH,"run","cb_run","iconBar.run.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"host","cb_host","iconBar.host.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"publish","cb_publish","iconBar.publish.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"start","cb_start","iconBar.start.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"stop","cb_stop","iconBar.stop.tooltip");
createBufferedToolItem(toolBar,SWT.PUSH,"remove","cb_remove","iconBar.remove.tooltip");
toolBar.pack();
p = toolBar.getSize();
coolItem.setControl(toolBar);
coolItem.setSize(p.x,p.y);
coolItem.setMinimumSize(p.x,p.y);
| public static void | main(java.lang.String[] args)
Display display = new Display();
Shell shell = new Shell(display);
ImageRepository.loadImages(display);
FormLayout layout = new FormLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
shell.setLayout(layout);
IconBar ibar = new IconBar(shell);
FormData formData = new FormData();
formData.left = new FormAttachment(0,0);
formData.right = new FormAttachment(100,0);
ibar.setLayoutData(formData);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
| private void | refreshEnableItems()
Iterator iter = itemKeyToControl.keySet().iterator();
while(iter.hasNext()) {
String key = (String) iter.next();
BufferedToolItem BufferedToolItem = (BufferedToolItem) itemKeyToControl.get(key);
if(BufferedToolItem == null )
continue;
if(currentEnabler != null) {
BufferedToolItem.setEnabled(currentEnabler.isEnabled(key));
BufferedToolItem.setSelection(currentEnabler.isSelected(key));
}
else {
BufferedToolItem.setEnabled(false);
BufferedToolItem.setSelection(false);
}
}
| public void | setCurrentEnabler(IconBarEnabler enabler)
this.currentEnabler = enabler;
refreshEnableItems();
| public void | setEnabled(java.lang.String itemKey, boolean enabled)
BufferedToolItem BufferedToolItem = (BufferedToolItem) itemKeyToControl.get(itemKey);
if(BufferedToolItem != null)
BufferedToolItem.setEnabled(enabled);
| public void | setLayoutData(java.lang.Object layoutData)
cIconBar.setLayoutData(layoutData);
| public void | setSelection(java.lang.String itemKey, boolean selection)
BufferedToolItem BufferedToolItem = (BufferedToolItem) itemKeyToControl.get(itemKey);
if(BufferedToolItem != null)
BufferedToolItem.setSelection(selection);
|
|