Source Code Cross Referenced for HTMLTextPresenter.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » contentassist » display » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.ui.editor.contentassist.display 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.pde.internal.ui.editor.contentassist.display;
011:
012:        import java.io.IOException;
013:        import java.io.Reader;
014:        import java.io.StringReader;
015:        import java.util.Iterator;
016:
017:        import org.eclipse.pde.internal.ui.util.LineBreakingReader;
018:        import org.eclipse.swt.custom.StyleRange;
019:        import org.eclipse.swt.graphics.Drawable;
020:        import org.eclipse.swt.graphics.GC;
021:        import org.eclipse.swt.widgets.Display;
022:
023:        import org.eclipse.jface.text.DefaultInformationControl;
024:        import org.eclipse.jface.text.Region;
025:        import org.eclipse.jface.text.TextPresentation;
026:
027:        public class HTMLTextPresenter implements 
028:                DefaultInformationControl.IInformationPresenter,
029:                DefaultInformationControl.IInformationPresenterExtension {
030:
031:            private static final String LINE_DELIM = System.getProperty(
032:                    "line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
033:
034:            private int fCounter;
035:            private boolean fEnforceUpperLineLimit;
036:
037:            public HTMLTextPresenter(boolean enforceUpperLineLimit) {
038:                super ();
039:                fEnforceUpperLineLimit = enforceUpperLineLimit;
040:            }
041:
042:            protected Reader createReader(String hoverInfo,
043:                    TextPresentation presentation) {
044:                return new HTML2TextReader(new StringReader(hoverInfo),
045:                        presentation);
046:            }
047:
048:            protected void adaptTextPresentation(TextPresentation presentation,
049:                    int offset, int insertLength) {
050:
051:                int yoursStart = offset;
052:                int yoursEnd = offset + insertLength - 1;
053:                yoursEnd = Math.max(yoursStart, yoursEnd);
054:
055:                Iterator e = presentation.getAllStyleRangeIterator();
056:                while (e.hasNext()) {
057:
058:                    StyleRange range = (StyleRange) e.next();
059:
060:                    int myStart = range.start;
061:                    int myEnd = range.start + range.length - 1;
062:                    myEnd = Math.max(myStart, myEnd);
063:
064:                    if (myEnd < yoursStart)
065:                        continue;
066:
067:                    if (myStart < yoursStart)
068:                        range.length += insertLength;
069:                    else
070:                        range.start += insertLength;
071:                }
072:            }
073:
074:            private void append(StringBuffer buffer, String string,
075:                    TextPresentation presentation) {
076:
077:                int length = string.length();
078:                buffer.append(string);
079:
080:                if (presentation != null)
081:                    adaptTextPresentation(presentation, fCounter, length);
082:
083:                fCounter += length;
084:            }
085:
086:            private String getIndent(String line) {
087:                int length = line.length();
088:
089:                int i = 0;
090:                while (i < length && Character.isWhitespace(line.charAt(i)))
091:                    ++i;
092:
093:                return (i == length ? line : line.substring(0, i)) + " "; //$NON-NLS-1$
094:            }
095:
096:            /*
097:             * @see IHoverInformationPresenter#updatePresentation(Display display, String, TextPresentation, int, int)
098:             */
099:            public String updatePresentation(Display display, String hoverInfo,
100:                    TextPresentation presentation, int maxWidth, int maxHeight) {
101:                return updatePresentation((Drawable) display, hoverInfo,
102:                        presentation, maxWidth, maxHeight);
103:            }
104:
105:            /*
106:             * @see IHoverInformationPresenterExtension#updatePresentation(Drawable drawable, String, TextPresentation, int, int)
107:             * @since 3.2
108:             */
109:            public String updatePresentation(Drawable drawable,
110:                    String hoverInfo, TextPresentation presentation,
111:                    int maxWidth, int maxHeight) {
112:
113:                if (hoverInfo == null)
114:                    return null;
115:
116:                GC gc = new GC(drawable);
117:                try {
118:
119:                    StringBuffer buffer = new StringBuffer();
120:                    int maxNumberOfLines = Math.round(maxHeight
121:                            / gc.getFontMetrics().getHeight());
122:
123:                    fCounter = 0;
124:                    LineBreakingReader reader = new LineBreakingReader(
125:                            createReader(hoverInfo, presentation), gc, maxWidth);
126:
127:                    boolean lastLineFormatted = false;
128:                    String lastLineIndent = null;
129:
130:                    String line = reader.readLine();
131:                    boolean lineFormatted = reader.isFormattedLine();
132:                    boolean firstLineProcessed = false;
133:
134:                    while (line != null) {
135:
136:                        if (fEnforceUpperLineLimit && maxNumberOfLines <= 0)
137:                            break;
138:
139:                        if (firstLineProcessed) {
140:                            if (!lastLineFormatted)
141:                                append(buffer, LINE_DELIM, null);
142:                            else {
143:                                append(buffer, LINE_DELIM, presentation);
144:                                if (lastLineIndent != null)
145:                                    append(buffer, lastLineIndent, presentation);
146:                            }
147:                        }
148:
149:                        append(buffer, line, null);
150:                        firstLineProcessed = true;
151:
152:                        lastLineFormatted = lineFormatted;
153:                        if (!lineFormatted)
154:                            lastLineIndent = null;
155:                        else if (lastLineIndent == null)
156:                            lastLineIndent = getIndent(line);
157:
158:                        line = reader.readLine();
159:                        lineFormatted = reader.isFormattedLine();
160:
161:                        maxNumberOfLines--;
162:                    }
163:
164:                    if (line != null) {
165:                        append(buffer, LINE_DELIM, lineFormatted ? presentation
166:                                : null);
167:                        append(buffer, "...", presentation); //$NON-NLS-1$
168:                    }
169:
170:                    return trim(buffer, presentation);
171:
172:                } catch (IOException e) {
173:
174:                    // ignore TODO do something else?
175:                    return null;
176:
177:                } finally {
178:                    gc.dispose();
179:                }
180:            }
181:
182:            private String trim(StringBuffer buffer,
183:                    TextPresentation presentation) {
184:
185:                int length = buffer.length();
186:
187:                int end = length - 1;
188:                while (end >= 0 && Character.isWhitespace(buffer.charAt(end)))
189:                    --end;
190:
191:                if (end == -1)
192:                    return ""; //$NON-NLS-1$
193:
194:                if (end < length - 1)
195:                    buffer.delete(end + 1, length);
196:                else
197:                    end = length;
198:
199:                int start = 0;
200:                while (start < end
201:                        && Character.isWhitespace(buffer.charAt(start)))
202:                    ++start;
203:
204:                buffer.delete(0, start);
205:                presentation
206:                        .setResultWindow(new Region(start, buffer.length()));
207:                return buffer.toString();
208:            }
209:        }
w___ww_.__java2java__.co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.