Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/FormTextModel.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 | 7ffeace6c47f |
children | 0ea0c9f9008f |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
24 import dwt.DWT; | 24 import dwt.DWT; |
25 import dwtx.ui.forms.HyperlinkSettings; | 25 import dwtx.ui.forms.HyperlinkSettings; |
26 | 26 |
27 import dwt.dwthelper.utils; | 27 import dwt.dwthelper.utils; |
28 import dwt.dwthelper.InputStream; | 28 import dwt.dwthelper.InputStream; |
29 import dwtx.dwtxhelper.Collection; | |
29 | 30 |
30 static import tango.text.xml.Document; | 31 static import tango.text.xml.Document; |
31 static import tango.io.Buffer; | 32 static import tango.io.Buffer; |
32 | 33 |
33 import tango.util.collection.ArraySeq; | |
34 public class FormTextModel { | 34 public class FormTextModel { |
35 // private static const DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory | 35 // private static const DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory |
36 // .newInstance(); | 36 // .newInstance(); |
37 | 37 |
38 alias tango.text.xml.Document.Document!(char) Document; | 38 alias tango.text.xml.Document.Document!(char) Document; |
39 alias Document.NodeImpl Node; | 39 alias Document.NodeImpl Node; |
40 | 40 |
41 private bool whitespaceNormalized = true; | 41 private bool whitespaceNormalized = true; |
42 | 42 |
43 private alias ArraySeq!(Paragraph) TArraySeqParagraph; | 43 private Vector paragraphs; |
44 private TArraySeqParagraph paragraphs; | |
45 | 44 |
46 private IFocusSelectable[] selectableSegments; | 45 private IFocusSelectable[] selectableSegments; |
47 | 46 |
48 private int selectedSegmentIndex = -1; | 47 private int selectedSegmentIndex = -1; |
49 | 48 |
67 * @see ITextModel#getParagraphs() | 66 * @see ITextModel#getParagraphs() |
68 */ | 67 */ |
69 public Paragraph[] getParagraphs() { | 68 public Paragraph[] getParagraphs() { |
70 if (paragraphs is null) | 69 if (paragraphs is null) |
71 return new Paragraph[0]; | 70 return new Paragraph[0]; |
72 return paragraphs | 71 return arraycast!(Paragraph)(paragraphs |
73 .toArray(); | 72 .toArray()); |
74 } | 73 } |
75 | 74 |
76 public String getAccessibleText() { | 75 public String getAccessibleText() { |
77 if (paragraphs is null) | 76 if (paragraphs is null) |
78 return ""; //$NON-NLS-1$ | 77 return ""; //$NON-NLS-1$ |
141 // auto root = doc.query.root.dup; | 140 // auto root = doc.query.root.dup; |
142 // auto children = root.childs.dup; | 141 // auto children = root.childs.dup; |
143 // processSubnodes(paragraphs, children, expandURLs); | 142 // processSubnodes(paragraphs, children, expandURLs); |
144 // } | 143 // } |
145 | 144 |
146 /+ private void processSubnodes(TArraySeqParagraph plist, NodeList children, bool expandURLs) { | 145 /+ private void processSubnodes(Vector plist, NodeList children, bool expandURLs) { |
147 //o for (int i = 0; i < children.getLength(); i++) { | 146 //o for (int i = 0; i < children.getLength(); i++) { |
148 //o Node child = children.item(i); | 147 //o Node child = children.item(i); |
149 foreach( child; children ){ | 148 foreach( child; children ){ |
150 //o if (child.getNodeType() is Node.TEXT_NODE) { | 149 //o if (child.getNodeType() is Node.TEXT_NODE) { |
151 if (child.type is XmlNodeType.Data) { | 150 if (child.type is XmlNodeType.Data) { |
542 return; | 541 return; |
543 | 542 |
544 regularText = getNormalizedText(regularText); | 543 regularText = getNormalizedText(regularText); |
545 | 544 |
546 Paragraph p = new Paragraph(true); | 545 Paragraph p = new Paragraph(true); |
547 paragraphs.append(p); | 546 paragraphs.add(p); |
548 int pstart = 0; | 547 int pstart = 0; |
549 | 548 |
550 for (int i = 0; i < regularText.length; i++) { | 549 for (int i = 0; i < regularText.length; i++) { |
551 char c = regularText.charAt(i); | 550 char c = regularText.charAt(i); |
552 if (p is null) { | 551 if (p is null) { |
553 p = new Paragraph(true); | 552 p = new Paragraph(true); |
554 paragraphs.append(p); | 553 paragraphs.add(p); |
555 } | 554 } |
556 if (c is '\n') { | 555 if (c is '\n') { |
557 String text = regularText.substring(pstart, i); | 556 String text = regularText.substring(pstart, i); |
558 pstart = i + 1; | 557 pstart = i + 1; |
559 p.parseRegularText(text, convertURLs, true, getHyperlinkSettings(), | 558 p.parseRegularText(text, convertURLs, true, getHyperlinkSettings(), |
579 this.hyperlinkSettings = settings; | 578 this.hyperlinkSettings = settings; |
580 } | 579 } |
581 | 580 |
582 private void reset() { | 581 private void reset() { |
583 if (paragraphs is null) | 582 if (paragraphs is null) |
584 paragraphs = new TArraySeqParagraph; | 583 paragraphs = new Vector; |
585 paragraphs.clear(); | 584 paragraphs.clear(); |
586 selectedSegmentIndex = -1; | 585 selectedSegmentIndex = -1; |
587 savedSelectedLinkIndex = -1; | 586 savedSelectedLinkIndex = -1; |
588 selectableSegments = null; | 587 selectableSegments = null; |
589 } | 588 } |
590 | 589 |
591 IFocusSelectable[] getFocusSelectableSegments() { | 590 IFocusSelectable[] getFocusSelectableSegments() { |
592 if (selectableSegments !is null || paragraphs is null) | 591 if (selectableSegments !is null || paragraphs is null) |
593 return selectableSegments; | 592 return selectableSegments; |
594 IFocusSelectable[] result; | 593 Vector result = new Vector(); |
595 for (int i = 0; i < paragraphs.size(); i++) { | 594 for (int i = 0; i < paragraphs.size(); i++) { |
596 Paragraph p = cast(Paragraph) paragraphs.get(i); | 595 Paragraph p = cast(Paragraph) paragraphs.get(i); |
597 ParagraphSegment[] segments = p.getSegments(); | 596 ParagraphSegment[] segments = p.getSegments(); |
598 for (int j = 0; j < segments.length; j++) { | 597 for (int j = 0; j < segments.length; j++) { |
599 if (null !is cast(IFocusSelectable)segments[j] ) | 598 if (null !is cast(IFocusSelectable)segments[j] ) |
600 result ~= cast(IFocusSelectable)segments[j]; | 599 result.add(segments[j]); |
601 } | 600 } |
602 } | 601 } |
603 selectableSegments = result; | 602 selectableSegments = arraycast!(IFocusSelectable)(result.toArray()); |
604 return selectableSegments; | 603 return selectableSegments; |
605 } | 604 } |
606 | 605 |
607 public IHyperlinkSegment getHyperlink(int index) { | 606 public IHyperlinkSegment getHyperlink(int index) { |
608 IFocusSelectable[] selectables = getFocusSelectableSegments(); | 607 IFocusSelectable[] selectables = getFocusSelectableSegments(); |