comparison dwtx/ui/forms/widgets/FormText.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 56fea7e5f0f9
children c3583c6ec027
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
77 import dwtx.ui.internal.forms.widgets.TextSegment; 77 import dwtx.ui.internal.forms.widgets.TextSegment;
78 78
79 import dwt.dwthelper.utils; 79 import dwt.dwthelper.utils;
80 import dwt.dwthelper.InputStream; 80 import dwt.dwthelper.InputStream;
81 import tango.io.Stdout; 81 import tango.io.Stdout;
82 import tango.util.collection.HashMap; 82 import dwtx.dwtxhelper.Collection;
83 import tango.util.collection.ArraySeq;
84 83
85 /** 84 /**
86 * This class is a read-only text control that is capable of rendering wrapped 85 * This class is a read-only text control that is capable of rendering wrapped
87 * text. Text can be rendered as-is or by parsing the formatting XML tags. 86 * text. Text can be rendered as-is or by parsing the formatting XML tags.
88 * Independently, words that start with http:// can be converted into hyperlinks 87 * Independently, words that start with http:// can be converted into hyperlinks
204 203
205 private FormTextModel model; 204 private FormTextModel model;
206 205
207 private ListenerList listeners; 206 private ListenerList listeners;
208 207
209 private HashMap!(String,Object) resourceTable; 208 private Hashtable resourceTable;
210 209
211 private IHyperlinkSegment entered; 210 private IHyperlinkSegment entered;
212 211
213 private IHyperlinkSegment armed; 212 private IHyperlinkSegment armed;
214 213
362 * form text parent control 361 * form text parent control
363 * @param style 362 * @param style
364 * the widget style 363 * the widget style
365 */ 364 */
366 public this(Composite parent, int style) { 365 public this(Composite parent, int style) {
367 resourceTable = new HashMap!(String,Object); 366 resourceTable = new Hashtable();
368 super(parent, DWT.NO_BACKGROUND | DWT.WRAP | style); 367 super(parent, DWT.NO_BACKGROUND | DWT.WRAP | style);
369 setLayout(new FormTextLayout()); 368 setLayout(new FormTextLayout());
370 model = new FormTextModel(); 369 model = new FormTextModel();
371 addDisposeListener(new class DisposeListener { 370 addDisposeListener(new class DisposeListener {
372 public void widgetDisposed(DisposeEvent e) { 371 public void widgetDisposed(DisposeEvent e) {
560 * attribute. 559 * attribute.
561 * @param image 560 * @param image
562 * an object of a type <samp>Image </samp>. 561 * an object of a type <samp>Image </samp>.
563 */ 562 */
564 public void setImage(String key, Image image) { 563 public void setImage(String key, Image image) {
565 resourceTable.add("i." ~ key, image); //$NON-NLS-1$ 564 resourceTable.put("i." ~ key, image); //$NON-NLS-1$
566 } 565 }
567 566
568 /** 567 /**
569 * Registers the color referenced by the provided key. 568 * Registers the color referenced by the provided key.
570 * <p> 569 * <p>
580 * if the key needs to be cleared. 579 * if the key needs to be cleared.
581 */ 580 */
582 public void setColor(String key, Color color) { 581 public void setColor(String key, Color color) {
583 String fullKey = "c." ~ key; //$NON-NLS-1$ 582 String fullKey = "c." ~ key; //$NON-NLS-1$
584 if (color is null) 583 if (color is null)
585 resourceTable.removeKey(fullKey); 584 resourceTable.remove(fullKey);
586 else 585 else
587 resourceTable.add(fullKey, color); 586 resourceTable.put(fullKey, color);
588 } 587 }
589 588
590 /** 589 /**
591 * Registers the font referenced by the provided key. 590 * Registers the font referenced by the provided key.
592 * <p> 591 * <p>
602 * if the key needs to be cleared. 601 * if the key needs to be cleared.
603 */ 602 */
604 public void setFont(String key, Font font) { 603 public void setFont(String key, Font font) {
605 String fullKey = "f." ~ key; //$NON-NLS-1$ 604 String fullKey = "f." ~ key; //$NON-NLS-1$
606 if (font is null) 605 if (font is null)
607 resourceTable.removeKey(fullKey); 606 resourceTable.remove(fullKey);
608 else 607 else
609 resourceTable.add(fullKey, font); 608 resourceTable.put(fullKey, font);
610 model.clearCache(fullKey); 609 model.clearCache(fullKey);
611 } 610 }
612 611
613 /** 612 /**
614 * Registers the control referenced by the provided key. 613 * Registers the control referenced by the provided key.
627 * @since 3.1 626 * @since 3.1
628 */ 627 */
629 public void setControl(String key, Control control) { 628 public void setControl(String key, Control control) {
630 String fullKey = "o." ~ key; //$NON-NLS-1$ 629 String fullKey = "o." ~ key; //$NON-NLS-1$
631 if (control is null) 630 if (control is null)
632 resourceTable.removeKey(fullKey); 631 resourceTable.remove(fullKey);
633 else 632 else
634 resourceTable.add(fullKey, control); 633 resourceTable.put(fullKey, control);
635 } 634 }
636 635
637 /** 636 /**
638 * Sets the font to use to render the default text (text that does not have 637 * Sets the font to use to render the default text (text that does not have
639 * special font property assigned). Bold font will be constructed from this 638 * special font property assigned). Bold font will be constructed from this
646 super.setFont(font); 645 super.setFont(font);
647 model.clearCache(null); 646 model.clearCache(null);
648 Font boldFont = cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID); 647 Font boldFont = cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID);
649 if (boldFont !is null) { 648 if (boldFont !is null) {
650 FormFonts.getInstance().markFinished(boldFont); 649 FormFonts.getInstance().markFinished(boldFont);
651 resourceTable.removeKey(FormTextModel.BOLD_FONT_ID); 650 resourceTable.remove(FormTextModel.BOLD_FONT_ID);
652 } 651 }
653 ensureBoldFontPresent(getFont()); 652 ensureBoldFontPresent(getFont());
654 } 653 }
655 654
656 /** 655 /**
1550 setCursor(model.getHyperlinkSettings().getHyperlinkCursor()); 1549 setCursor(model.getHyperlinkSettings().getHyperlinkCursor());
1551 } 1550 }
1552 } 1551 }
1553 1552
1554 private void ensureBoldFontPresent(Font regularFont) { 1553 private void ensureBoldFontPresent(Font regularFont) {
1555 Font boldFont = resourceTable.containsKey(FormTextModel.BOLD_FONT_ID) ? cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID) : null; 1554 Font boldFont = cast(Font) resourceTable.get(FormTextModel.BOLD_FONT_ID);
1556 if (boldFont !is null) 1555 if (boldFont !is null)
1557 return; 1556 return;
1558 boldFont = FormFonts.getInstance().getBoldFont(getDisplay(), regularFont); 1557 boldFont = FormFonts.getInstance().getBoldFont(getDisplay(), regularFont);
1559 resourceTable.add(FormTextModel.BOLD_FONT_ID, boldFont); 1558 resourceTable.put(FormTextModel.BOLD_FONT_ID, boldFont);
1560 } 1559 }
1561 1560
1562 private void paint(PaintEvent e) { 1561 private void paint(PaintEvent e) {
1563 GC gc = e.gc; 1562 GC gc = e.gc;
1564 gc.setFont(getFont()); 1563 gc.setFont(getFont());
1667 if (disposeBoldFont) { 1666 if (disposeBoldFont) {
1668 Font boldFont = cast(Font) resourceTable 1667 Font boldFont = cast(Font) resourceTable
1669 .get(FormTextModel.BOLD_FONT_ID); 1668 .get(FormTextModel.BOLD_FONT_ID);
1670 if (boldFont !is null) { 1669 if (boldFont !is null) {
1671 FormFonts.getInstance().markFinished(boldFont); 1670 FormFonts.getInstance().markFinished(boldFont);
1672 resourceTable.removeKey(FormTextModel.BOLD_FONT_ID); 1671 resourceTable.remove(FormTextModel.BOLD_FONT_ID);
1673 } 1672 }
1674 } 1673 }
1675 ArraySeq!(String) imagesToRemove = new ArraySeq!(String); 1674 ArrayList imagesToRemove = new ArrayList();
1676 foreach( key, obj; resourceTable ){ 1675 for (Enumeration enm = resourceTable.keys(); enm.hasMoreElements();) {
1676 String key = stringcast( enm.nextElement());
1677 if (key.startsWith(ImageSegment.SEL_IMAGE_PREFIX)) { 1677 if (key.startsWith(ImageSegment.SEL_IMAGE_PREFIX)) {
1678 Object obj = resourceTable.get(key);
1678 if (auto image = cast(Image)obj ) { 1679 if (auto image = cast(Image)obj ) {
1679 if (!image.isDisposed()) { 1680 if (!image.isDisposed()) {
1680 image.dispose(); 1681 image.dispose();
1681 imagesToRemove.append(key); 1682 imagesToRemove.add(key);
1682 } 1683 }
1683 } 1684 }
1684 } 1685 }
1685 } 1686 }
1686 for (int i = 0; i < imagesToRemove.size(); i++) { 1687 for (int i = 0; i < imagesToRemove.size(); i++) {
1687 resourceTable.removeKey(imagesToRemove.get(i)); 1688 resourceTable.remove(imagesToRemove.get(i));
1688 } 1689 }
1689 } 1690 }
1690 1691
1691 /* 1692 /*
1692 * (non-Javadoc) 1693 * (non-Javadoc)