Source Code Cross Referenced for Text.java in  » Net » Terracotta » demo » sharededitor » models » 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 » Net » Terracotta » demo.sharededitor.models 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         @COPYRIGHT@
003:         */
004:        package demo.sharededitor.models;
005:
006:        import java.awt.Color;
007:        import java.awt.Font;
008:        import java.awt.Graphics2D;
009:        import java.awt.Image;
010:        import java.awt.Rectangle;
011:        import java.awt.Shape;
012:        import java.awt.font.FontRenderContext;
013:        import java.awt.font.TextAttribute;
014:        import java.awt.font.TextLayout;
015:        import java.awt.geom.AffineTransform;
016:        import java.awt.geom.Rectangle2D;
017:        import java.text.AttributedCharacterIterator;
018:        import java.text.AttributedString;
019:
020:        import demo.sharededitor.ui.Fontable;
021:        import demo.sharededitor.ui.Texturable;
022:
023:        public class Text extends BaseObject implements  Fontable, Texturable {
024:            private Shape shape = null;
025:
026:            protected Shape getShape() {
027:                return shape;
028:            }
029:
030:            private Shape[] anchors = new Shape[0];
031:
032:            protected Shape[] getAnchors() {
033:                return anchors;
034:            }
035:
036:            public boolean isAt(int x, int y) {
037:                if (shape == null)
038:                    return false;
039:
040:                Shape bounds = new Rectangle2D.Double(shape.getBounds().x - 5,
041:                        shape.getBounds().y - 5, shape.getBounds().width + 5,
042:                        shape.getBounds().height + 5);
043:                return bounds.contains(x, y);
044:            }
045:
046:            public synchronized void move(int dx, int dy) {
047:                this .x += dx;
048:                this .y += dy;
049:                notifyListeners(this );
050:            }
051:
052:            public synchronized void resize(int x, int y) {
053:                // we purposely don't allow the resizing operation for Text objects
054:            }
055:
056:            public synchronized void clearTexture() {
057:                super .clearTexture();
058:            }
059:
060:            public synchronized void setTexture(Image image) {
061:                super .setTexture(image);
062:                notifyListeners(this );
063:            }
064:
065:            private String fontName;
066:
067:            private int fontSize;
068:
069:            public synchronized void setFontInfo(String name, int size,
070:                    String text) {
071:                this .text = text;
072:                this .fontName = name;
073:                this .fontSize = size;
074:                notifyListeners(this );
075:            }
076:
077:            public synchronized void setFontName(String name) {
078:                this .fontName = name;
079:                notifyListeners(this );
080:            }
081:
082:            public synchronized void setFontSize(int size) {
083:                this .fontSize = size;
084:                notifyListeners(this );
085:            }
086:
087:            private String text;
088:
089:            public synchronized void setText(String text) {
090:                this .text = text;
091:                notifyListeners(this );
092:            }
093:
094:            public String getText() {
095:                return this .text;
096:            }
097:
098:            public synchronized void appendToText(char c) {
099:                if (!this .isInverted)
100:                    this .text += c;
101:                else {
102:                    this .text = c + "";
103:                    this .isInverted = false;
104:                }
105:                notifyListeners(this );
106:            }
107:
108:            private int x, y;
109:
110:            private synchronized void renderText(FontRenderContext frc,
111:                    boolean showCursor) {
112:                String text = this .text;
113:                if (showCursor || (text.length() == 0)) {
114:                    if (text.length() > 0)
115:                        text = this .isInverted ? text : text + "|";
116:                    else
117:                        text = "_";
118:                }
119:
120:                AttributedString as = new AttributedString(text);
121:                as.addAttribute(TextAttribute.FONT, new Font(this .fontName,
122:                        Font.PLAIN, this .fontSize));
123:                AttributedCharacterIterator aci = as.getIterator();
124:                TextLayout tl = new TextLayout(aci, frc);
125:                this .shape = tl.getOutline(AffineTransform
126:                        .getTranslateInstance(x, y));
127:            }
128:
129:            public void draw(Graphics2D g, boolean showAnchors) {
130:                renderText(g.getFontRenderContext(), showAnchors);
131:                super .draw(g, showAnchors);
132:                if (showAnchors) {
133:                    Rectangle bounds = shape.getBounds();
134:                    Shape border = new Rectangle2D.Double(bounds.x - 5,
135:                            bounds.y - 5, bounds.width + 5, bounds.height + 5);
136:                    if (this .isInverted) {
137:                        g.setXORMode(Color.LIGHT_GRAY);
138:                        g.fillRect(bounds.x - 5, bounds.y - 5,
139:                                bounds.width + 5, bounds.height + 5);
140:                        g.setPaintMode();
141:                    }
142:                    g.setColor(Color.LIGHT_GRAY);
143:                    g.draw(border);
144:                }
145:            }
146:
147:            private boolean isInverted;
148:
149:            public synchronized void selectAction(boolean flag) {
150:                if (!this .isInverted)
151:                    return;
152:                this .isInverted = false;
153:            }
154:
155:            public synchronized void alternateSelectAction(boolean flag) {
156:                if (this .isInverted)
157:                    return;
158:                this .isInverted = true;
159:            }
160:
161:            public Text() {
162:                this .isInverted = false;
163:                this .text = "";
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.