Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 683 Details for
Bug 14330
[Widgets] CoolBar - when locked and add new items, new items not locked
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
test case
CoolBarIconTest.java (text/plain), 6.22 KB, created by
Lynne Kues
on 2002-04-22 12:01:18 EDT
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
Lynne Kues
Created:
2002-04-22 12:01:18 EDT
Size:
6.22 KB
patch
obsolete
>package coolbartest; > >import org.eclipse.swt.*; >import org.eclipse.swt.widgets.*; >import org.eclipse.swt.events.*; >import org.eclipse.swt.graphics.*; >import org.eclipse.swt.layout.*; > >public class CoolBarIconTest { > static Display display; > static Shell shell; > static CoolBar coolBar; > static Menu popup = null; > static String[][] toolNames = { > {"new_wiz", null, "save", "saveas", "printer"}, > {"search"}, > {"script_wiz"}, > {"debug", "run"}, > {"opentype"}, > }; > >public static void main (String [] args) { > display = new Display (); > shell = new Shell (display); > shell.setLayout(new GridLayout()); > coolBar = new CoolBar(shell, SWT.FLAT); > GridData data = new GridData(GridData.FILL_BOTH); > data.widthHint = 600; > data.heightHint = 70; > coolBar.setLayoutData(data); > > for (int i = 0; i < toolNames.length; i ++) { > ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); > String[] toolFileNames = toolNames[i]; > int minWidth = 0; > for (int j = 0; j < toolFileNames.length; j++) { > int width = 0; > String fileName = toolFileNames[j]; > if (fileName == null) { > new ToolItem(toolBar, SWT.SEPARATOR); > } else { > ToolItem item = new ToolItem(toolBar, SWT.PUSH); > item.setImage(createCoolBarIcon(display, toolFileNames[j])); > width = item.getWidth(); > } > // find the width of the widest tool > if (width > minWidth) minWidth = width; > } > CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN); > coolItem.setControl(toolBar); > Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); > Point coolSize = coolItem.computeSize (size.x, size.y); > coolItem.setMinimumSize(minWidth, coolSize.y); > coolItem.setPreferredSize(coolSize); > coolItem.setSize(coolSize); > > coolItem.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > if (e.detail == SWT.ARROW) { > handleChevron(e); > } > } > }); > } > final Button addItem = new Button(shell, SWT.PUSH); > > addItem.setText("Add Item"); > addItem.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > addItem.setEnabled(false); > coolBar.setLocked(true); > ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); > String[] toolFileNames = {"newjprj_wiz", "newpack_wiz", "newclass_wiz", "newint_wiz", "newsbook_wiz"}; > for (int i = 0; i < toolFileNames.length; i++) { > ToolItem item = new ToolItem(toolBar, SWT.PUSH); > item.setImage(createCoolBarIcon(display, toolFileNames[i])); > } > int minWidth = toolBar.getItems()[0].getWidth(); > CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN, 2); > coolItem.setControl(toolBar); > Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); > Point coolSize = coolItem.computeSize (size.x, size.y); > coolItem.setMinimumSize(minWidth, coolItem.getMinimumSize().y); > coolItem.setPreferredSize(coolSize); > coolItem.setSize(coolSize); > } > }); > shell.pack(); > shell.open (); > while (!shell.isDisposed ()) { > if (!display.readAndDispatch ()) display.sleep (); > } > display.dispose (); >} > >public static void handleChevron(SelectionEvent event) { > /* If the popup menu is already there, then pop it down. > * This doesn't work... still need to figure this out. */ > if (popup != null) { > popup.dispose(); > popup = null; > return; > } > CoolItem item = (CoolItem) event.widget; > Control control = item.getControl (); > if (!(control instanceof ToolBar)) return; // currently we only deal with toolbar items > > /* Retrieve the current bounding rectangle for the selected cool item. */ > Rectangle itemBounds = item.getBounds (); > > /* Convert to display coordinates (i.e. was relative to CoolBar). */ > Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y)); > itemBounds.x = pt.x; > itemBounds.y = pt.y; > > /* Retrieve the total number of buttons in the toolbar. */ > ToolBar toolBar = (ToolBar) control; > ToolItem[] tools = toolBar.getItems (); > int toolCount = tools.length; > > int i = 0; > while (i < toolCount) { > /* Starting from the leftmost tool, retrieve the tool's bounding rectangle. */ > Rectangle toolBounds = tools[i].getBounds (); > > /* Convert to display coordinates (i.e. was relative to ToolBar). */ > pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y)); > toolBounds.x = pt.x; > toolBounds.y = pt.y; > > /* Figure out the visible portion of the tool by looking at > * the intersection of the tool bounds with the cool item bounds. */ > Rectangle intersection = itemBounds.intersection (toolBounds); > > /* If the tool is not completely within the cool item bounds, then > * the tool is at least partially hidden, and all remaining tools > * are completely hidden. */ > if (!intersection.equals (toolBounds)) break; > i++; > } > > /* Create a pop-up menu with items for each of the hidden buttons. */ > popup = new Menu (coolBar); > for (int j = i; j < toolCount; j++) { > ToolItem tool = tools[j]; > MenuItem menuItem = new MenuItem (popup, SWT.NONE); > menuItem.setImage (tool.getImage()); > } > > /* Display the pop-up menu immediately below the chevron, > * with the left edges aligned. Need to convert the given > * point to display coordinates in order to pass them to > * Menu.setLocation (i.e. was relative to CoolBar). */ > pt = coolBar.toDisplay(new Point(event.x, event.y)); > popup.setLocation (pt.x, pt.y); > popup.setVisible (true); > Display display = coolBar.getDisplay (); > while (popup.isVisible ()) { > if (!display.readAndDispatch ()) display.sleep (); > } > if (popup != null) { > popup.dispose (); > popup = null; > } >} > >static Image createCoolBarIcon(Display display, String fileName) { > try { > ImageData source = new ImageData(CoolBarIconTest.class.getResourceAsStream(fileName + ".gif")); > ImageData mask = source.getTransparencyMask(); > return new Image(display, source, mask); > } catch (Exception e) { > } > return null; >} >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 14330
: 683