1 | package org.expeditee.core;
|
---|
2 |
|
---|
3 | import org.expeditee.core.bounds.AxisAlignedBoxBounds;
|
---|
4 | import org.expeditee.gio.TextLayoutManager;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Purely a handle type for the TextLayoutManager.
|
---|
8 | *
|
---|
9 | * @author cts16
|
---|
10 | *
|
---|
11 | */
|
---|
12 | public class TextLayout {
|
---|
13 |
|
---|
14 | private static TextLayoutManager _manager;
|
---|
15 |
|
---|
16 | public static void setManager(TextLayoutManager manager)
|
---|
17 | {
|
---|
18 | if (_manager == null) _manager = manager;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public static TextLayoutManager getManager()
|
---|
22 | {
|
---|
23 | return _manager;
|
---|
24 | }
|
---|
25 |
|
---|
26 | private static long nextHandle = 1;
|
---|
27 |
|
---|
28 | private long _handle;
|
---|
29 |
|
---|
30 | private String _line;
|
---|
31 | private Font _font;
|
---|
32 | private int _startCharIndex;
|
---|
33 | private int _endCharIndex;
|
---|
34 |
|
---|
35 | public static TextLayout get(String line, Font font, int startCharIndex, int endCharIndex)
|
---|
36 | {
|
---|
37 | if (_manager == null) return null;
|
---|
38 |
|
---|
39 | return new TextLayout(line, font, startCharIndex, endCharIndex);
|
---|
40 | }
|
---|
41 |
|
---|
42 | private TextLayout(String line, Font font, int startCharIndex, int endCharIndex)
|
---|
43 | {
|
---|
44 | _handle = nextHandle;
|
---|
45 | nextHandle++;
|
---|
46 |
|
---|
47 | _line = new String(line);
|
---|
48 | _font = new Font(font);
|
---|
49 | _startCharIndex = startCharIndex;
|
---|
50 | _endCharIndex = endCharIndex;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public long getHandle()
|
---|
54 | {
|
---|
55 | return _handle;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public float getAdvance()
|
---|
59 | {
|
---|
60 | return _manager.getAdvance(this);
|
---|
61 | }
|
---|
62 |
|
---|
63 | public int getCharacterCount()
|
---|
64 | {
|
---|
65 | return _manager.getCharacterCount(this);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public TextHitInfo getNextLeftHit(int offset)
|
---|
69 | {
|
---|
70 | return _manager.getNextLeftHit(this, offset);
|
---|
71 | }
|
---|
72 |
|
---|
73 | public TextHitInfo getNextLeftHit(TextHitInfo hit)
|
---|
74 | {
|
---|
75 | return _manager.getNextLeftHit(this, hit);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public TextHitInfo getNextRightHit(int offset)
|
---|
79 | {
|
---|
80 | return _manager.getNextRightHit(this, offset);
|
---|
81 | }
|
---|
82 |
|
---|
83 | public TextHitInfo getNextRightHit(TextHitInfo hit)
|
---|
84 | {
|
---|
85 | return _manager.getNextRightHit(this, hit);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public float[] getCaretInfo(TextHitInfo hit)
|
---|
89 | {
|
---|
90 | return _manager.getCaretInfo(this, hit);
|
---|
91 | }
|
---|
92 |
|
---|
93 | public TextHitInfo hitTestChar(float x, float y)
|
---|
94 | {
|
---|
95 | return _manager.hitTestChar(this, x, y);
|
---|
96 | }
|
---|
97 |
|
---|
98 | public AxisAlignedBoxBounds getPixelBounds(float x, float y)
|
---|
99 | {
|
---|
100 | return _manager.getPixelBounds(this, x, y);
|
---|
101 | }
|
---|
102 |
|
---|
103 | public AxisAlignedBoxBounds getLogicalHighlightShape(int firstEndpoint, int secondEndpoint)
|
---|
104 | {
|
---|
105 | return _manager.getLogicalHighlightShape(this, firstEndpoint, secondEndpoint);
|
---|
106 | }
|
---|
107 |
|
---|
108 | public float getAscent()
|
---|
109 | {
|
---|
110 | return _manager.getAscent(this);
|
---|
111 | }
|
---|
112 |
|
---|
113 | public float getDescent()
|
---|
114 | {
|
---|
115 | return _manager.getDescent(this);
|
---|
116 | }
|
---|
117 |
|
---|
118 | public float getLeading()
|
---|
119 | {
|
---|
120 | return _manager.getLeading(this);
|
---|
121 | }
|
---|
122 |
|
---|
123 | public String getLine()
|
---|
124 | {
|
---|
125 | return new String(_line);
|
---|
126 | }
|
---|
127 |
|
---|
128 | public Font getFont()
|
---|
129 | {
|
---|
130 | return new Font(_font);
|
---|
131 | }
|
---|
132 |
|
---|
133 | public int getStartCharIndex()
|
---|
134 | {
|
---|
135 | return _startCharIndex;
|
---|
136 | }
|
---|
137 |
|
---|
138 | public int getEndCharIndex()
|
---|
139 | {
|
---|
140 | return _endCharIndex;
|
---|
141 | }
|
---|
142 |
|
---|
143 | public void release()
|
---|
144 | {
|
---|
145 | _manager.releaseLayout(this);
|
---|
146 | }
|
---|
147 |
|
---|
148 | @Override
|
---|
149 | protected void finalize()
|
---|
150 | {
|
---|
151 | release();
|
---|
152 | }
|
---|
153 | }
|
---|