source: trunk/src/org/expeditee/items/Circle.java@ 1415

Last change on this file since 1415 was 1415, checked in by bln4, 5 years ago

Renamed Frame.getItems() to Frame.getSortedItems() to better represent its functionality.

-> org.apollo.ApolloGestureActions
-> org.apollo.ApolloSystem
-> org.expeditee.actions.Actions
-> org.expeditee.actions.Debug
-> org.expeditee.actions.ExploratorySearchActions
-> org.expeditee.actions.JfxBrowserActions
-> org.expeditee.actions.Misc
-> org.expeditee.actions.Navigation
-> org.expeditee.actions.ScriptBase
-> org.expeditee.actions.Simple
-> org.expeditee.agents.ComputeTree
-> org.expeditee.agents.CopyTree
-> org.expeditee.agents.DisplayComet
-> org.expeditee.agents.DisplayTree
-> org.expeditee.agents.DisplayTreeLeaves
-> org.expeditee.agents.GraphFramesetLinks
-> org.expeditee.agents.TreeProcessor
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.DisplayController
-> org.expeditee.gui.FrameCreator
-> org.expeditee.gui.FrameIO
-> org.expeditee.io.DefaultTreeWriter
-> org.expeditee.io.JavaWriter
-> org.expeditee.io.PDF2Writer
-> org.expeditee.io.TXTWriter
-> org.expeditee.io.WebParser
-> org.expeditee.io.flowlayout.XGroupItem
-> org.expeditee.items.Dot
-> org.expeditee.items.Item
-> org.expeditee.items.ItemUtils
-> org.expeditee.network.FrameShare
-> org.expeditee.stats.TreeStats


Created ItemsList class to wrap ArrayList<Item>. Frames now use this new class to store its body list (used for display) as well as its primaryBody and surrogateBody.

-> org.expeditee.agents.Format
-> org.expeditee.agents.HFormat
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.Frame
-> org.expeditee.gui.FrameUtils


Refactorted Frame.setResort(bool) to Frame.invalidateSorted() to better function how it is intended to with a more accurate name.

-> org.expeditee.agents.Sort


When writing out .exp files and getting attributes to respond to LEFT + RIGHT click, boolean items are by default true. This has always been the case. An ammendment to this is that defaults can now be established.
Also added 'EnterClick' functionality. If cursored over a item with this property and you press enter, it acts as if you have clicked on it instead.

-> org.expeditee.assets.resources-public.framesets.authentication.1.exp to 6.exp
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gio.input.KBMInputEvent
-> org.expeditee.gio.javafx.JavaFXConversions
-> org.expeditee.gio.swing.SwingConversions
-> org.expeditee.gui.AttributeUtils
-> org.expeditee.io.Conversion
-> org.expeditee.io.DefaultFrameWriter
-> org.expeditee.items.Item


Fixed a bug caused by calling Math.abs on Integer.MIN_VALUE returning unexpected result. Due to zero being a thing, you cannot represent Math.abs(Integer.MIN_VALUE) in a Integer object. The solution is to use Integer.MIN_VALUE + 1 instead of Integer.MIN_VALUE.

-> org.expeditee.core.bounds.CombinationBounds
-> org.expeditee.io.flowlayout.DimensionExtent


Recoded the contains function in EllipticalBounds so that intersection tests containing circles work correctly.

-> org.expeditee.core.bounds.EllipticalBounds


Added toString() to PolygonBounds to allow for useful printing during debugging.

-> org.expeditee.core.bounds.PolygonBounds

Implemented Surrogate Mode!

-> org.expeditee.encryption.io.EncryptedExpReader
-> org.expeditee.encryption.io.EncryptedExpWriter
-> org.expeditee.encryption.items.surrogates.EncryptionDetail
-> org.expeditee.encryption.items.surrogates.Label
-> org.expeditee.gui.FrameUtils
-> org.expeditee.gui.ItemsList
-> org.expeditee.items.Item
-> org.expeditee.items.Text


???? Use Integer.MAX_VALUE cast to a float instead of Float.MAX_VALUE. This fixed some bug which I cannot remember.

-> org.expeditee.gio.TextLayoutManager
-> org.expeditee.gio.swing.SwingTextLayoutManager


Improved solution for dealing with the F10 key taking focus away from Expeditee due to it being a assessibility key.

-> org.expeditee.gio.swing.SwingInputManager


Renamed variable visibleItems in FrameGraphics.paintFrame to itemsToPaintCanditates to better represent functional intent.

-> org.expeditee.gui.FrameGraphics


Improved checking for if personal resources exist before recreating them

-> org.expeditee.gui.FrameIO


Repeated messages to message bay now have a visual feedback instead of just a beep. This visual feedback is in the form of a count of the amount of times it has repeated.

-> org.expeditee.gui.MessageBay


Updated comment on the Vector class to explain what vectors are.

-> org.expeditee.gui.Vector


Added constants to represent all of the property keys in DefaultFrameReader and DefaultFrameWriter.

-> org.expeditee.io.DefaultFrameReader
-> org.expeditee.io.DefaultFrameWriter


Updated the KeyList setting to be more heirarcial with how users will store their Secrets.

-> org.expeditee.settings.identity.secrets.KeyList

File size: 8.0 KB
Line 
1/**
2 * Circle.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items;
20
21import java.util.Collection;
22import java.util.LinkedList;
23
24import org.expeditee.core.Colour;
25import org.expeditee.core.Dimension;
26import org.expeditee.core.Fill;
27import org.expeditee.core.Point;
28import org.expeditee.core.Stroke;
29import org.expeditee.core.bounds.AxisAlignedBoxBounds;
30import org.expeditee.core.bounds.EllipticalBounds;
31import org.expeditee.core.bounds.PolygonBounds;
32import org.expeditee.gio.EcosystemManager;
33
34/**
35 * @author root
36 *
37 */
38public class Circle extends XRayable {
39
40 private Item _center;
41
42 private Line _line;
43
44 /**
45 * Construct a circle
46 *
47 * @param _source
48 */
49 public Circle(Text source)
50 {
51 super(source);
52 // Collection<Item> connected = source.getAllConnected();
53 // assert (connected.size() == 4);
54 _line = source.getLines().get(0);
55 _center = _line.getOppositeEnd(_source);
56 _center.addEnclosure(this);
57 _line.setHidden(true);
58 invalidateBounds();
59 }
60
61 public Collection<Item> getItemsToSave() {
62 Collection<Item> toSave = super.getItemsToSave();
63 toSave.add(_center);
64 return toSave;
65 }
66
67 @Override
68 public Collection<Item> getConnected() {
69 Collection<Item> conn = super.getConnected();
70 conn.add(_center);
71 conn.add(_line);
72 return conn;
73 }
74
75 @Override
76 public void addAllConnected(Collection<Item> connected) {
77 super.addAllConnected(connected);
78 if (!connected.contains(_center)) {
79 connected.add(_center);
80 connected.add(_line);
81 }
82 }
83
84 @Override
85 public boolean isFloating() {
86 return _center.isFloating() || super.isFloating();
87 }
88
89 @Override
90 public boolean isEnclosed() {
91 return true;
92 }
93
94 @Override
95 public PolygonBounds getEnclosedShape() {
96 // assert(_poly != null);
97 // Ensure that vector items will gradient fill are painted OK!!
98 return ((EllipticalBounds) updateBounds()).getPolygon(16);
99 }
100
101 @Override
102 public double getEnclosedArea() {
103 double radius = getRadius();
104 return Math.PI * radius * radius;
105 }
106
107 @Override
108 public Collection<Item> getEnclosingDots() {
109 Collection<Item> enclosed = new LinkedList<Item>();
110 enclosed.add(this);
111 enclosed.add(_center);
112 return enclosed;
113 }
114
115 /*
116 * (non-Javadoc)
117 *
118 * @see org.expeditee.items.Item#copy()
119 */
120 @Override
121 public Item copy() {
122 Collection<Item> toCopy = new LinkedList<Item>();
123 toCopy.add(_source);
124 toCopy.add(_line);
125 toCopy.add(_center);
126
127 Collection<Item> newItems = ItemUtils.CopyItems(toCopy);
128 assert (newItems.size() == 3);
129 // find the Source item from the three items
130 Text newSource = null;
131 for (Item i : newItems) {
132 if (i instanceof Text) {
133 newSource = (Text) i;
134 if (ItemUtils.startsWithTag(i, "@c"))
135 break;
136 }
137 }
138 assert (newSource != null);
139 Circle newCircle = new Circle(newSource);
140 Item.DuplicateItem(this, newCircle);
141 newCircle._line.setVisible(_line.isVisible());
142 newCircle._source.setVisible(_source.isVisible());
143 newCircle.invalidateBounds();
144 return newCircle;
145 }
146
147 /**
148 * Gets the radius of this circle.
149 *
150 * @return the radius of the cicle
151 */
152 public double getRadius() {
153 return _line.getLength();
154 }
155
156 @Override
157 public boolean contains(Point p) {
158 double radius = getRadius();
159
160 double distance = Math.sqrt(Math.pow(Math.abs(_center.getX() - p.getX()), 2)
161 + Math.pow(Math.abs(_center.getY() - p.getY()), 2));
162
163 return Math.abs(distance - radius) < getGravity() * 2;
164 }
165
166 /*
167 * (non-Javadoc)
168 *
169 * @see org.expeditee.items.Item#paint(java.awt.Graphics2D)
170 */
171 @Override
172 public void paint() {
173 int radius = (int) Math.round(getRadius());
174 Point centre = new Point(_center.getX(), _center.getY());
175 Dimension diameters = new Dimension(radius * 2, radius * 2);
176 Fill fill = new Fill(getFillColor());
177 Colour lineColour = null;
178 Stroke lineStroke = null;
179 if (isHighlighted()) {
180 lineColour = getHighlightColor();
181 lineStroke = HIGHLIGHT_STROKE;
182 } else if (getThickness() > 0 || getFillColor() == null) {
183 lineColour = getPaintColor();
184 lineStroke = _line.getStroke();
185 }
186
187 EcosystemManager.getGraphicsManager().drawOval(centre, diameters, 0.0f, fill, lineColour, lineStroke);
188
189 if (isHighlighted()) {
190 _center.paint();
191 }
192 }
193
194 @Override
195 public void setHighlightModeAndColour(HighlightMode mode, Colour color) {
196 _center.setHighlightModeAndColour(mode, color);
197 super.setHighlightModeAndColour(mode, color);
198 }
199
200 @Override
201 public void setHighlightColor(Colour c) {
202 _center.setHighlightColor(c);
203 /*return*/ super.setHighlightColor(c);
204 }
205
206 @Override
207 public void setFillColor(Colour c) {
208 super.setFillColor(c);
209 _center.setColor(c);
210 invalidateCommonTrait(ItemAppearence.FillColor);
211 }
212
213 @Override
214 public void setGradientColor(Colour c) {
215 super.setGradientColor(c);
216 invalidateCommonTrait(ItemAppearence.GradientColor);
217 }
218
219 // @Override
220 // public void setPosition(float x, float y) {
221 // // float deltaX = x - _source._x;
222 // // float deltaY = y - _source._y;
223 // // _center.setPosition(_center._x + deltaX, _center._y + deltaY);
224 // _source.setPosition(x, y);
225 //
226 // updatePolygon();
227 // }
228
229 // TODO use an algorithm to get more precicely for contains and intersects
230
231 /*
232 * (non-Javadoc)
233 *
234 * @see org.expeditee.items.Item#setAnnotation(boolean)
235 */
236 @Override
237 public void setAnnotation(boolean val) {
238 // TODO Auto-generated method stub
239
240 }
241
242 /*
243 * (non-Javadoc)
244 *
245 * @see org.expeditee.items.Item#updatePolygon()
246 */
247 @Override
248 public EllipticalBounds updateBounds()
249 {
250 return new EllipticalBounds(_center.getPosition(), (int) (getRadius() * 2));
251 }
252
253 @Override
254 public float getSize() {
255 return (float) getRadius();
256 }
257
258 /** Resizes the circle from the center. */
259 @Override
260 public void setSize(float size)
261 {
262 double ratio = size / getRadius();
263
264 // Extend the line along the same plane as the underlying line
265 _source.translate(_center.getPosition(), ratio);
266
267 invalidateBounds();
268 }
269
270 @Override
271 public void setLinePattern(int[] pattern) {
272 _line.setLinePattern(pattern);
273 }
274
275 @Override
276 public int[] getLinePattern() {
277 return _line.getLinePattern();
278 }
279
280 // TODO: Why is this commented out? cts16
281 @Override
282 public void translate(Point origin, double ratio)
283 {
284 invalidateBounds();
285 // _center.translate(origin, ratio);
286 // super.translate(origin, ratio);
287 }
288
289 @Override
290 public AxisAlignedBoxBounds getDrawingArea() {
291
292 float thickness = getThickness();
293 double radius = getRadius();
294
295 int size = (int) ((2 * radius) + 3.0 + thickness);
296
297 return new AxisAlignedBoxBounds((int) (_center.getX() - radius
298 - 0.5 - (thickness / 2.0)), (int) (_center.getY() - radius
299 - 0.5 - (thickness / 2.0)), size, size);
300 }
301
302 // @Override
303 // public void setPosition(float x, float y){
304 // float deltaX = x - _source._x;
305 // float deltaY = y = _source._y;
306 // _center.setPosition(deltaX, deltaY);
307 // super.setPosition(x,y);
308 // }
309 public Item getCenter() {
310 return _center;
311 }
312
313 @Override
314 public void setPermission(PermissionTriple permissionPair) {
315 super.setPermission(permissionPair);
316 _center.setPermission(permissionPair);
317 _line.setPermission(permissionPair);
318 }
319
320 @Override
321 public void scale(Float scale, int originX, int originY) {
322 getCenter().scale(scale, originX, originY);
323 super.scale(scale, originX, originY);
324 }
325
326 @Override
327 public void setThickness(float thick, boolean setConnected) {
328 super.setThickness(thick, setConnected);
329 _line.refreshStroke(thick);
330 }
331
332 @Override
333 public boolean isConnectedToAnnotation() {
334 return false;
335 }
336}
Note: See TracBrowser for help on using the repository browser.