1 11 package org.eclipse.ui.internal.presentations.r21.widgets; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.events.MouseAdapter; 19 import org.eclipse.swt.events.MouseEvent; 20 import org.eclipse.swt.events.MouseListener; 21 import org.eclipse.swt.graphics.Color; 22 import org.eclipse.swt.graphics.Point; 23 import org.eclipse.swt.graphics.Rectangle; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Control; 26 import org.eclipse.ui.internal.layout.SizeCache; 27 import org.eclipse.ui.internal.presentations.util.ProxyControl; 28 import org.eclipse.ui.presentations.IStackPresentationSite; 29 30 51 public final class R21PaneFolder { 52 private CTabFolder tabFolder; 54 55 57 private ViewForm viewForm; 59 60 private ProxyControl contentProxy; 61 62 private ProxyControl viewFormTopLeftProxy; 63 64 private ProxyControl viewFormTopRightProxy; 65 66 private ProxyControl viewFormTopCenterProxy; 67 68 private SizeCache topRightCache = new SizeCache(); 70 71 private SizeCache topCenterCache = new SizeCache(); 72 73 private SizeCache topLeftCache = new SizeCache(); 74 75 private int tabPos; 76 77 private boolean putTrimOnTop = false; 78 79 82 private List buttonListeners = new ArrayList (1); 83 84 private int state = IStackPresentationSite.STATE_RESTORED; 85 86 91 private int mousedownState = -1; 92 93 private MouseListener mouseListener = new MouseAdapter() { 125 public void mouseDown(MouseEvent e) { 126 mousedownState = getState(); 127 } 128 129 public void mouseDoubleClick(MouseEvent e) { 130 } 131 }; 132 133 140 public R21PaneFolder(Composite parent, int flags) { 141 { 143 tabFolder = new CTabFolder(parent, flags); 144 145 150 tabFolder.addMouseListener(mouseListener); 153 } 154 155 { 157 viewForm = new ViewForm(tabFolder, SWT.NONE); 158 159 viewFormTopLeftProxy = new ProxyControl(viewForm); 161 viewFormTopCenterProxy = new ProxyControl(viewForm); 162 viewFormTopRightProxy = new ProxyControl(viewForm); 163 164 contentProxy = new ProxyControl(viewForm); 165 viewForm.setContent(contentProxy.getControl()); 166 } 167 } 168 169 174 public Composite getControl() { 175 return tabFolder; 176 } 177 178 184 public void setTopCenter(Control topCenter) { 185 topCenterCache.setControl(topCenter); 186 if (topCenter != null) { 187 if (!putTrimOnTop) { 188 viewFormTopCenterProxy.setTarget(topCenterCache); 189 viewForm.setTopCenter(viewFormTopCenterProxy.getControl()); 190 } 191 } else { 192 if (!putTrimOnTop) { 193 viewForm.setTopCenter(null); 194 } 195 } 196 } 197 198 203 public void setTopRight(Control topRight) { 204 topRightCache.setControl(topRight); 205 if (topRight != null) { 206 if (!putTrimOnTop) { 207 viewFormTopRightProxy.setTarget(topRightCache); 208 viewForm.setTopRight(viewFormTopRightProxy.getControl()); 209 } 210 } else { 211 if (!putTrimOnTop) { 212 viewForm.setTopRight(null); 213 } 214 } 215 } 216 217 222 public void setTopLeft(Control topLeft) { 223 if (topLeftCache.getControl() != topLeft) { 224 topLeftCache.setControl(topLeft); 225 if (topLeft != null) { 227 viewFormTopLeftProxy.setTarget(topLeftCache); 228 viewForm.setTopLeft(viewFormTopLeftProxy.getControl()); 229 } else { 230 viewFormTopLeftProxy.setTargetControl(null); 231 viewForm.setTopLeft(null); 232 } 233 } 234 } 235 236 240 public void flush() { 241 topLeftCache.flush(); 242 topRightCache.flush(); 243 topCenterCache.flush(); 244 } 245 246 251 public void layout(boolean flushCache) { 252 if (flushCache) { 254 flush(); 255 } 256 257 Rectangle tabFolderClientArea = tabFolder.getClientArea(); 258 259 if (tabFolder.getItemCount() < 2) { 261 263 int delta = getTabHeight() + 1; 264 tabFolderClientArea.height += delta; 265 266 if (getTabPosition() == SWT.TOP) { 267 tabFolderClientArea.y -= delta; 268 } 269 } 270 271 viewForm.setBounds(tabFolderClientArea); 272 viewFormTopRightProxy.layout(); 273 viewFormTopLeftProxy.layout(); 274 viewFormTopCenterProxy.layout(); 275 } 276 277 282 public Rectangle getClientArea() { 283 Rectangle bounds = contentProxy.getControl().getBounds(); 284 285 Rectangle formArea = viewForm.getBounds(); 286 287 bounds.x += formArea.x; 288 bounds.y += formArea.y; 289 290 return bounds; 291 } 292 293 298 public int getState() { 299 return state; 300 } 301 302 305 protected void notifyButtonListeners(int buttonId) { 306 if (mousedownState == getState()) { 307 Iterator iter = buttonListeners.iterator(); 308 309 while (iter.hasNext()) { 310 R21PaneFolderButtonListener listener = (R21PaneFolderButtonListener) iter 311 .next(); 312 313 listener.stateButtonPressed(buttonId); 314 } 315 } 316 } 317 318 323 protected void notifyShowListeners(CTabFolderEvent event) { 324 Iterator iter = buttonListeners.iterator(); 325 326 while (iter.hasNext()) { 327 R21PaneFolderButtonListener listener = (R21PaneFolderButtonListener) iter 328 .next(); 329 330 listener.showList(event); 331 } 332 } 333 334 339 protected void notifyCloseListeners(CTabItem tabItem) { 340 Iterator iter = buttonListeners.iterator(); 341 342 while (iter.hasNext()) { 343 R21PaneFolderButtonListener listener = (R21PaneFolderButtonListener) iter 344 .next(); 345 346 listener.closeButtonPressed(tabItem); 347 } 348 } 349 350 353 public void addButtonListener(R21PaneFolderButtonListener listener) { 354 buttonListeners.add(listener); 355 } 356 357 360 public void removeButtonListener(R21PaneFolderButtonListener listener) { 361 buttonListeners.remove(listener); 362 } 363 364 367 public void setTabPosition(int newTabPosition) { 368 tabPos = newTabPosition; 369 tabFolder.setTabPosition(tabPos); 370 } 371 372 375 public int getTabPosition() { 376 return tabPos; 377 } 378 379 382 public boolean isDisposed() { 383 return tabFolder == null || tabFolder.isDisposed(); 384 } 385 386 391 public CTabItem createItem(int style, int index) { 392 return new CTabItem(tabFolder, style, index); 393 } 394 395 397 400 public void setSelection(int selection) { 401 tabFolder.setSelection(selection); 402 } 403 404 411 public Rectangle computeTrim(int i, int j, int k, int l) { 412 return tabFolder.computeTrim(i, j, k, l); 413 } 414 415 418 public void setSelectionForeground(Color fgColor) { 419 tabFolder.setSelectionForeground(fgColor); 420 } 421 422 426 public CTabItem getItem(int idx) { 427 return tabFolder.getItem(idx); 428 } 429 430 433 public int getSelectionIndex() { 434 return tabFolder.getSelectionIndex(); 435 } 436 437 440 public int getTabHeight() { 441 return tabFolder.getTabHeight(); 442 } 443 444 448 public int indexOf(CTabItem toFind) { 449 return tabFolder.indexOf(toFind); 450 } 451 452 455 public void setTabHeight(int height) { 456 tabFolder.setTabHeight(height); 457 } 458 459 462 public int getItemCount() { 463 return tabFolder.getItemCount(); 464 } 465 466 469 public CTabItem[] getItems() { 470 return tabFolder.getItems(); 471 } 472 473 477 public CTabItem getItem(Point toGet) { 478 return tabFolder.getItem(toGet); 479 } 480 481 484 public CTabItem getSelection() { 485 return tabFolder.getSelection(); 486 } 487 } 488 | Popular Tags |