Mercurial > projects > dwt-addons
comparison dwtx/jface/text/AbstractInformationControl.d @ 156:a9566845f1cb
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 25 Aug 2008 19:03:46 +0200 |
parents | 75302ef3f92f |
children | f8d52b926852 |
comparison
equal
deleted
inserted
replaced
155:8442b6b2da2d | 156:a9566845f1cb |
---|---|
302 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field | 302 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field |
303 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired | 303 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired |
304 * | 304 * |
305 * @deprecated clients should use one of the public constructors | 305 * @deprecated clients should use one of the public constructors |
306 */ | 306 */ |
307 this(Shell parentShell, int shellStyle, final String statusFieldText, final ToolBarManager toolBarManager) { | 307 this(Shell parentShell, int shellStyle, String statusFieldText, ToolBarManager toolBarManager) { |
308 Assert.isTrue(statusFieldText is null || toolBarManager is null); | 308 Assert.isTrue(statusFieldText is null || toolBarManager is null); |
309 fResizeHandleSize= -1; | 309 fResizeHandleSize= -1; |
310 fToolBarManager= toolBarManager; | 310 fToolBarManager= toolBarManager; |
311 | 311 |
312 if ((shellStyle & DWT.NO_TRIM) !is 0) | 312 if ((shellStyle & DWT.NO_TRIM) !is 0) |
331 setColor(fContentComposite, foreground, background); | 331 setColor(fContentComposite, foreground, background); |
332 | 332 |
333 createStatusComposite(statusFieldText, toolBarManager, foreground, background); | 333 createStatusComposite(statusFieldText, toolBarManager, foreground, background); |
334 } | 334 } |
335 | 335 |
336 private void createStatusComposite(final String statusFieldText, final ToolBarManager toolBarManager, Color foreground, Color background) { | 336 private void createStatusComposite(String statusFieldText, ToolBarManager toolBarManager, Color foreground, Color background) { |
337 if (toolBarManager is null && statusFieldText is null) | 337 if (toolBarManager is null && statusFieldText is null) |
338 return; | 338 return; |
339 | 339 |
340 fStatusComposite= new Composite(fShell, DWT.NONE); | 340 fStatusComposite= new Composite(fShell, DWT.NONE); |
341 GridData gridData= new GridData(DWT.FILL, DWT.BOTTOM, true, false); | 341 GridData gridData= new GridData(DWT.FILL, DWT.BOTTOM, true, false); |
354 } else { | 354 } else { |
355 createToolBar(toolBarManager); | 355 createToolBar(toolBarManager); |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 private void createStatusLabel(final String statusFieldText, Color foreground, Color background) { | 359 private void createStatusLabel(String statusFieldText, Color foreground, Color background) { |
360 fStatusLabel= new Label(fStatusComposite, DWT.RIGHT); | 360 fStatusLabel= new Label(fStatusComposite, DWT.RIGHT); |
361 fStatusLabel.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); | 361 fStatusLabel.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); |
362 fStatusLabel.setText(statusFieldText); | 362 fStatusLabel.setText(statusFieldText); |
363 | 363 |
364 FontData[] fontDatas= JFaceResources.getDialogFont().getFontData(); | 364 FontData[] fontDatas= JFaceResources.getDialogFont().getFontData(); |
371 fStatusLabel.setBackground(background); | 371 fStatusLabel.setBackground(background); |
372 setColor(fStatusComposite, foreground, background); | 372 setColor(fStatusComposite, foreground, background); |
373 } | 373 } |
374 | 374 |
375 private void createToolBar(ToolBarManager toolBarManager) { | 375 private void createToolBar(ToolBarManager toolBarManager) { |
376 final Composite bars= new Composite(fStatusComposite, DWT.NONE); | 376 Composite bars= new Composite(fStatusComposite, DWT.NONE); |
377 bars.setLayoutData(new GridData(DWT.FILL, DWT.FILL, false, false)); | 377 bars.setLayoutData(new GridData(DWT.FILL, DWT.FILL, false, false)); |
378 | 378 |
379 GridLayout layout= new GridLayout(3, false); | 379 GridLayout layout= new GridLayout(3, false); |
380 layout.marginHeight= 0; | 380 layout.marginHeight= 0; |
381 layout.marginWidth= 0; | 381 layout.marginWidth= 0; |
395 | 395 |
396 addMoveSupport(spacer); | 396 addMoveSupport(spacer); |
397 addResizeSupportIfNecessary(bars); | 397 addResizeSupportIfNecessary(bars); |
398 } | 398 } |
399 | 399 |
400 private void addResizeSupportIfNecessary(final Composite bars) { | 400 private void addResizeSupportIfNecessary(Composite bars) { |
401 // XXX: workarounds for | 401 // XXX: workarounds for |
402 // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=219139 : API to add resize grip / grow box in lower right corner of shell | 402 // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=219139 : API to add resize grip / grow box in lower right corner of shell |
403 // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=23980 : platform specific shell resize behavior | 403 // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=23980 : platform specific shell resize behavior |
404 String platform= DWT.getPlatform(); | 404 String platform= DWT.getPlatform(); |
405 final bool isWin= platform.equals("win32"); //$NON-NLS-1$ | 405 bool isWin= platform.equals("win32"); //$NON-NLS-1$ |
406 if (!isWin && !platform.equals("gtk")) //$NON-NLS-1$ | 406 if (!isWin && !platform.equals("gtk")) //$NON-NLS-1$ |
407 return; | 407 return; |
408 | 408 |
409 final Canvas resizer= new Canvas(bars, DWT.NONE); | 409 Canvas resizer= new Canvas(bars, DWT.NONE); |
410 | 410 |
411 int size= getResizeHandleSize(bars); | 411 int size= getResizeHandleSize(bars); |
412 | 412 |
413 GridData data= new GridData(DWT.END, DWT.END, false, true); | 413 GridData data= new GridData(DWT.END, DWT.END, false, true); |
414 data.widthHint= size; | 414 data.widthHint= size; |
415 data.heightHint= size; | 415 data.heightHint= size; |
416 resizer.setLayoutData(data); | 416 resizer.setLayoutData(data); |
417 resizer.addPaintListener(new class() PaintListener { | 417 resizer.addPaintListener(new class(isWin,resizer) PaintListener { |
418 bool isWin_; | |
419 Canvas resizer_; | |
420 this(bool a, Canvas b ){ | |
421 isWin_=a; | |
422 resizer_=b; | |
423 } | |
418 public void paintControl(PaintEvent e) { | 424 public void paintControl(PaintEvent e) { |
419 Point s= resizer.getSize(); | 425 Point s= resizer_.getSize(); |
420 int x= s.x - 2; | 426 int x= s.x - 2; |
421 int y= s.y - 2; | 427 int y= s.y - 2; |
422 int min= Math.min(x, y); | 428 int min= Math.min(x, y); |
423 if (isWin) { | 429 if (isWin_) { |
424 // draw dots | 430 // draw dots |
425 e.gc.setBackground(resizer.getDisplay().getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); | 431 e.gc.setBackground(resizer_.getDisplay().getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); |
426 int end= min - 1; | 432 int end= min - 1; |
427 for (int i= 0; i <= 2; i++) | 433 for (int i= 0; i <= 2; i++) |
428 for (int j= 0; j <= 2 - i; j++) | 434 for (int j= 0; j <= 2 - i; j++) |
429 e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2); | 435 e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2); |
430 end--; | 436 end--; |
431 e.gc.setBackground(resizer.getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW)); | 437 e.gc.setBackground(resizer_.getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW)); |
432 for (int i= 0; i <= 2; i++) | 438 for (int i= 0; i <= 2; i++) |
433 for (int j= 0; j <= 2 - i; j++) | 439 for (int j= 0; j <= 2 - i; j++) |
434 e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2); | 440 e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2); |
435 | 441 |
436 } else { | 442 } else { |
437 // draw diagonal lines | 443 // draw diagonal lines |
438 e.gc.setForeground(resizer.getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW)); | 444 e.gc.setForeground(resizer_.getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW)); |
439 for (int i= 1; i < min; i+= 4) { | 445 for (int i= 1; i < min; i+= 4) { |
440 e.gc.drawLine(i, y, x, i); | 446 e.gc.drawLine(i, y, x, i); |
441 } | 447 } |
442 e.gc.setForeground(resizer.getDisplay().getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); | 448 e.gc.setForeground(resizer_.getDisplay().getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); |
443 for (int i= 2; i < min; i+= 4) { | 449 for (int i= 2; i < min; i+= 4) { |
444 e.gc.drawLine(i, y, x, i); | 450 e.gc.drawLine(i, y, x, i); |
445 } | 451 } |
446 } | 452 } |
447 } | 453 } |
448 }); | 454 }); |
449 | 455 |
450 resizer.setCursor(new Cursor(resizer.getDisplay(), DWT.CURSOR_SIZESE)); | 456 resizer.setCursor(new Cursor(resizer.getDisplay(), DWT.CURSOR_SIZESE)); |
451 MouseAdapter resizeSupport= new class() MouseAdapter { | 457 MouseAdapter resizeSupport= new class(resizer) MouseAdapter { |
458 Canvas resizer_; | |
459 this(Canvas a){ | |
460 resizer_=a; | |
461 } | |
452 private MouseMoveListener fResizeListener; | 462 private MouseMoveListener fResizeListener; |
453 | 463 |
454 public void mouseDown(MouseEvent e) { | 464 public void mouseDown(MouseEvent e) { |
455 Point shellSize= fShell.getSize(); | 465 Point shellSize= fShell.getSize(); |
456 final int shellX= shellSize.x; | 466 int shellX= shellSize.x; |
457 final int shellY= shellSize.y; | 467 int shellY= shellSize.y; |
458 Point mouseLoc= resizer.toDisplay(e.x, e.y); | 468 Point mouseLoc= resizer_.toDisplay(e.x, e.y); |
459 final int mouseX= mouseLoc.x; | 469 int mouseX= mouseLoc.x; |
460 final int mouseY= mouseLoc.y; | 470 int mouseY= mouseLoc.y; |
461 fResizeListener= new class() MouseMoveListener { | 471 fResizeListener= new class(shellX,shellY,mouseX,mouseY) MouseMoveListener { |
472 int shellX_; | |
473 int shellY_; | |
474 int mouseX_; | |
475 int mouseY_; | |
476 this(int a, int b, int c, int d ){ | |
477 shellX_=a; | |
478 shellY_=b; | |
479 mouseX_=c; | |
480 mouseY_=d; | |
481 } | |
462 public void mouseMove(MouseEvent e2) { | 482 public void mouseMove(MouseEvent e2) { |
463 Point mouseLoc2= resizer.toDisplay(e2.x, e2.y); | 483 Point mouseLoc2= resizer_.toDisplay(e2.x, e2.y); |
464 int dx= mouseLoc2.x - mouseX; | 484 int dx= mouseLoc2.x - mouseX_; |
465 int dy= mouseLoc2.y - mouseY; | 485 int dy= mouseLoc2.y - mouseY_; |
466 setSize(shellX + dx, shellY + dy); | 486 setSize(shellX_ + dx, shellY_ + dy); |
467 } | 487 } |
468 }; | 488 }; |
469 resizer.addMouseMoveListener(fResizeListener); | 489 resizer_.addMouseMoveListener(fResizeListener); |
470 } | 490 } |
471 | 491 |
472 public void mouseUp(MouseEvent e) { | 492 public void mouseUp(MouseEvent e) { |
473 resizer.removeMouseMoveListener(fResizeListener); | 493 resizer_.removeMouseMoveListener(fResizeListener); |
474 fResizeListener= null; | 494 fResizeListener= null; |
475 } | 495 } |
476 }; | 496 }; |
477 resizer.addMouseListener(resizeSupport); | 497 resizer.addMouseListener(resizeSupport); |
478 } | 498 } |
494 /** | 514 /** |
495 * Adds support to move the shell by dragging the given control. | 515 * Adds support to move the shell by dragging the given control. |
496 * | 516 * |
497 * @param control the control that can be used to move the shell | 517 * @param control the control that can be used to move the shell |
498 */ | 518 */ |
499 private void addMoveSupport(final Control control) { | 519 private void addMoveSupport(Control control) { |
500 MouseAdapter moveSupport= new class() MouseAdapter { | 520 MouseAdapter moveSupport= new class(control) MouseAdapter { |
501 private MouseMoveListener fMoveListener; | 521 private MouseMoveListener fMoveListener; |
502 | 522 Control control_; |
523 this(Control a){ | |
524 control_=a; | |
525 } | |
503 public void mouseDown(MouseEvent e) { | 526 public void mouseDown(MouseEvent e) { |
504 Point shellLoc= fShell.getLocation(); | 527 Point shellLoc= fShell.getLocation(); |
505 final int shellX= shellLoc.x; | 528 final int shellX= shellLoc.x; |
506 final int shellY= shellLoc.y; | 529 final int shellY= shellLoc.y; |
507 Point mouseLoc= control.toDisplay(e.x, e.y); | 530 Point mouseLoc= control_.toDisplay(e.x, e.y); |
508 final int mouseX= mouseLoc.x; | 531 final int mouseX= mouseLoc.x; |
509 final int mouseY= mouseLoc.y; | 532 final int mouseY= mouseLoc.y; |
510 fMoveListener= new class() MouseMoveListener { | 533 fMoveListener= new class() MouseMoveListener { |
511 public void mouseMove(MouseEvent e2) { | 534 public void mouseMove(MouseEvent e2) { |
512 Point mouseLoc2= control.toDisplay(e2.x, e2.y); | 535 Point mouseLoc2= control_.toDisplay(e2.x, e2.y); |
513 int dx= mouseLoc2.x - mouseX; | 536 int dx= mouseLoc2.x - mouseX; |
514 int dy= mouseLoc2.y - mouseY; | 537 int dy= mouseLoc2.y - mouseY; |
515 fShell.setLocation(shellX + dx, shellY + dy); | 538 fShell.setLocation(shellX + dx, shellY + dy); |
516 } | 539 } |
517 }; | 540 }; |
518 control.addMouseMoveListener(fMoveListener); | 541 control_.addMouseMoveListener(fMoveListener); |
519 } | 542 } |
520 | 543 |
521 public void mouseUp(MouseEvent e) { | 544 public void mouseUp(MouseEvent e) { |
522 control.removeMouseMoveListener(fMoveListener); | 545 control_.removeMouseMoveListener(fMoveListener); |
523 fMoveListener= null; | 546 fMoveListener= null; |
524 } | 547 } |
525 }; | 548 }; |
526 control.addMouseListener(moveSupport); | 549 control.addMouseListener(moveSupport); |
527 } | 550 } |
767 | 790 |
768 /** | 791 /** |
769 * {@inheritDoc} | 792 * {@inheritDoc} |
770 * This method is not intended to be overridden by subclasses. | 793 * This method is not intended to be overridden by subclasses. |
771 */ | 794 */ |
772 public void addFocusListener(final FocusListener listener) { | 795 public void addFocusListener(FocusListener listener) { |
773 if (fFocusListeners.isEmpty()) { | 796 if (fFocusListeners.isEmpty()) { |
774 fShellListener= new class() Listener { | 797 fShellListener= new class() Listener { |
775 | 798 |
776 public void handleEvent(Event event) { | 799 public void handleEvent(Event event) { |
777 Object[] listeners= fFocusListeners.getListeners(); | 800 Object[] listeners= fFocusListeners.getListeners(); |