Changeset 1102 for trunk/src/org/expeditee/items/Dot.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Dot.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.Graphics2D;23 import java.awt.Polygon;24 import java.awt.Rectangle;25 21 import java.util.ArrayList; 26 22 import java.util.LinkedList; 27 23 import java.util.List; 28 24 29 import org.expeditee.gui.DisplayIO; 25 import org.expeditee.core.Colour; 26 import org.expeditee.core.Dimension; 27 import org.expeditee.core.Fill; 28 import org.expeditee.core.Point; 29 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 30 import org.expeditee.core.bounds.Bounds; 31 import org.expeditee.core.bounds.PolygonBounds; 32 import org.expeditee.gio.EcosystemManager; 33 import org.expeditee.gio.GraphicsManager; 34 import org.expeditee.gui.DisplayController; 30 35 import org.expeditee.gui.Frame; 31 36 import org.expeditee.gui.FrameGraphics; 32 import org.expeditee.gui.FrameKeyboardActions;33 37 34 38 /** … … 70 74 71 75 @Override 72 public void setColor(Colo r c) {76 public void setColor(Colour c) { 73 77 super.setColor(c); 74 78 … … 79 83 80 84 @Override 81 public void setAnchorLeft( Floatanchor) {85 public void setAnchorLeft(Integer anchor) { 82 86 if (!isLineEnd()) { 83 87 super.setAnchorLeft(anchor); … … 88 92 invalidateCommonTrait(ItemAppearence.PreMoved); 89 93 90 this._anchorLeft = anchor; 91 this._anchorRight = null; 94 this._anchoring.setLeftAnchor(anchor); 92 95 93 96 int oldX = getX(); … … 102 105 103 106 @Override 104 public void setAnchorRight( Floatanchor) {107 public void setAnchorRight(Integer anchor) { 105 108 if (!isLineEnd()) { 106 109 super.setAnchorRight(anchor); … … 110 113 invalidateCommonTrait(ItemAppearence.PreMoved); 111 114 112 this._anchorRight = anchor; 113 this._anchorLeft = null; 115 this._anchoring.setRightAnchor(anchor); 114 116 115 117 int oldX = getX(); 116 118 if (anchor != null) { 117 float deltaX = FrameGraphics.getMaxFrameSize().width - anchor 118 - getBoundsWidth() - oldX; 119 float deltaX = DisplayController.getFramePaintArea().getWidth() - anchor - getBoundsWidth() - oldX; 119 120 120 121 anchorConnected(AnchorEdgeType.Right, deltaX); … … 126 127 127 128 @Override 128 public void setAnchorTop( Floatanchor) {129 public void setAnchorTop(Integer anchor) { 129 130 if (!isLineEnd()) { 130 131 super.setAnchorTop(anchor); … … 134 135 invalidateCommonTrait(ItemAppearence.PreMoved); 135 136 136 this._anchorTop = anchor; 137 this._anchorBottom = null; 137 this._anchoring.setTopAnchor(anchor); 138 138 139 139 int oldY = getY(); … … 148 148 149 149 @Override 150 public void setAnchorBottom( Floatanchor) {150 public void setAnchorBottom(Integer anchor) { 151 151 if (!isLineEnd()) { 152 152 super.setAnchorBottom(anchor); … … 156 156 invalidateCommonTrait(ItemAppearence.PreMoved); 157 157 158 this._anchorBottom = anchor; 159 this._anchorTop = null; 158 this._anchoring.setBottomAnchor(anchor); 160 159 161 160 int oldY = getY(); 162 161 if (anchor != null) { 163 float deltaY = FrameGraphics.getMaxFrameSize().height - anchor 164 - getBoundsHeight() - oldY; 162 float deltaY = DisplayController.getFramePaintArea().getHeight() - anchor - getBoundsHeight() - oldY; 165 163 anchorConnected(AnchorEdgeType.Bottom, deltaY); 166 164 } … … 173 171 174 172 @Override 175 public void paint(Graphics2D g) { 173 public void paint() { 174 GraphicsManager g = EcosystemManager.getGraphicsManager(); 176 175 if (isHighlighted() /* && !FreeItems.getInstance().contains(this) */) { 177 Color highlightColor = getHighlightColor(); 178 g.setColor(highlightColor); 179 g.setStroke(DOT_STROKE); 176 Colour highlightColor = getHighlightColor(); 177 Fill fill = new Fill(highlightColor); 180 178 // g.setStroke() 181 179 // Draw the highlighting rectangle surrounding the dot 182 180 // this is drawn even if its part of a rectangle 183 181 184 if (isVectorItem()) 185 updatePolygon(); 186 187 Rectangle rect = getPolygon().getBounds(); 188 if (_mode == HighlightMode.Enclosed || 189 // Make sure single dots are highlighted filled 190 this.getConnected().size() <= 1) 191 g.fillRect(rect.x, rect.y, rect.width, rect.height); 192 else if (_mode == HighlightMode.Connected){ 193 g.setStroke(HIGHLIGHT_STROKE); 194 g.drawRect(rect.x, rect.y, rect.width, rect.height); 195 }else if (_mode == HighlightMode.Normal) { 196 g.fillOval(rect.x, rect.y, rect.width, rect.height); 182 if (isVectorItem()) invalidateBounds(); 183 184 AxisAlignedBoxBounds bounds = getBoundingBox(); 185 if (_highlightMode == HighlightMode.Enclosed || this.getConnected().size() <= 1) { // Make sure single dots are highlighted filled 186 g.drawRectangle(bounds.getTopLeft(), bounds.getSize(), 0.0f, fill, highlightColor, DOT_STROKE, null); 187 } else if (_highlightMode == HighlightMode.Connected) { 188 g.drawRectangle(bounds.getTopLeft(), bounds.getSize(), 0.0f, null, highlightColor, HIGHLIGHT_STROKE, null); 189 } else if (_highlightMode == HighlightMode.Normal) { 190 g.drawOval(bounds.getCentre(), bounds.getSize(), 0.0f, fill, highlightColor, DOT_STROKE); 197 191 } 198 192 // System.out.println(_mode.toString()); … … 200 194 201 195 // dots on lines are hidden 202 if (getLines().size() > 0) 203 return; 204 205 g.setColor(getPaintColor()); 196 if (getLines().size() > 0) return; 206 197 207 198 int thick = (int) getThickness(); 208 if (thick < MINIMUM_DOT_SIZE) 209 thick = MINIMUM_DOT_SIZE;210 211 int width = thick / 2; 212 199 if (thick < MINIMUM_DOT_SIZE) thick = MINIMUM_DOT_SIZE; 200 201 Fill fill = _filled ? new Fill(getPaintColor()) : null; 202 203 // TODO: On testing, this code doesn't seem to work (can't change to any type except square). cts16 213 204 switch (_type) { 214 case circle: 215 if (_filled) 216 g.fillOval(getX() - width, getY() - width, thick, thick); 217 else { 218 g.drawOval(getX() - width, getY() - width, thick, thick); 219 } 220 break; 221 case diamond: 222 int[] x = new int[4]; 223 int[] y = new int[4]; 224 225 x[0] = x[2] = getX(); 226 x[1] = getX() - width; 227 x[3] = getX() + width; 228 229 y[1] = y[3] = getY(); 230 y[0] = getY() - width; 231 y[2] = getY() + width; 232 233 if (_filled) 234 g.fillPolygon(x, y, 4); 235 else { 236 g.drawPolygon(x, y, 4); 237 } 238 break; 239 case triangle: 240 x = new int[3]; 241 y = new int[3]; 242 243 x[0] = getX(); 244 x[1] = getX() - width; 245 x[2] = getX() + width; 246 247 y[0] = getY() - width; 248 y[1] = y[2] = getY() + width; 249 250 if (_filled) 251 g.fillPolygon(x, y, 3); 252 else { 253 g.drawPolygon(x, y, 3); 254 } 255 break; 256 case roundSquare: 257 int arc = thick / 2; 258 if (_filled) 259 g.fillRoundRect(getX() - width, getY() - width, thick, thick, 260 arc, arc); 261 else { 262 g.drawRoundRect(getX() - width, getY() - width, thick, thick, 263 arc, arc); 264 } 265 break; 266 default: 267 if (_filled) 268 g.fillRect(getX() - width, getY() - width, thick, thick); 269 else { 270 g.drawRect(getX() - width, getY() - width, thick, thick); 271 } 272 205 case circle: 206 g.drawOval( 207 new Point(getX(), getY()), 208 new Dimension(thick, thick), 209 0.0, 210 fill, 211 getPaintColor(), 212 null 213 ); 214 break; 215 case diamond: 216 PolygonBounds diamond = PolygonBounds.getDiamond(thick, thick).translate(getX(), getY()).close(); 217 g.drawPolygon(diamond, null, null, 0.0, fill, getPaintColor(), null); 218 break; 219 case triangle: 220 PolygonBounds triangle = PolygonBounds.getTriangle(thick, thick).translate(getX(), getY()).close(); 221 g.drawPolygon(triangle, null, null, 0.0, fill, getPaintColor(), null); 222 break; 223 case roundSquare: 224 int arc = thick / 4; 225 g.drawRectangle( 226 new Point(getX(), getY()), 227 new Dimension(thick, thick), 228 0.0, 229 fill, 230 getPaintColor(), 231 null, 232 new Dimension(arc, arc) 233 ); 234 break; 235 default: 236 g.drawRectangle( 237 new Point(getX(), getY()), 238 new Dimension(thick, thick), 239 0.0, 240 fill, 241 getPaintColor(), 242 null, 243 null 244 ); 273 245 } 274 246 … … 276 248 277 249 /** 278 * Updates the points of the polygon surrounding this Dot 250 * Updates the bounds surrounding this Dot. 251 * TODO: Standardise Dot minimum size. cts16 279 252 */ 280 public void updatePolygon() { 253 public Bounds updateBounds() 254 { 281 255 int thick = Math.round(getThickness()); 256 282 257 // Sets a minimum size for the dot 283 258 thick = Math.max(thick, getGravity() * 2); 259 260 // Include the gravity in the thickness 261 thick += 2 * getGravity(); 262 284 263 285 264 int x = getX() - thick / 2; 286 265 int y = getY() - thick / 2; 287 288 _poly = new Polygon(); 289 _poly.addPoint(x - getGravity(), y - getGravity()); 290 _poly.addPoint(x + thick + getGravity(), y - getGravity()); 291 _poly.addPoint(x + thick + getGravity(), y + thick + getGravity()); 292 _poly.addPoint(x - getGravity(), y + thick + getGravity()); 266 267 return new AxisAlignedBoxBounds(x, y, thick, thick); 293 268 } 294 269 … … 303 278 304 279 @Override 305 public int setHighlightColor() {306 super.setHighlightColor ();307 308 return Item.DEFAULT_CURSOR;280 public void setHighlightColorToDefault() { 281 super.setHighlightColorToDefault(); 282 283 //return Item.DEFAULT_CURSOR; 309 284 } 310 285 311 286 @Override 312 287 public void setAnnotation(boolean val) { 313 Display IO.setCursorPosition(this.getPosition());314 FrameKeyboardActions.replaceDot(this, '@');288 DisplayController.setCursorPosition(this.getPosition()); 289 Item.replaceDot(this, '@'); 315 290 } 316 291 … … 406 381 if (parent != null && parent != current) { 407 382 this.setParent(parent); 408 if (Display IO.getCurrentSide() == 0)409 this.setX(this.getX() - Display IO.getMiddle());383 if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.LEFT) 384 this.setX(this.getX() - DisplayController.getTwinFramesSeparatorX()); 410 385 else 411 this.setX(this.getX() + Display IO.getMiddle());386 this.setX(this.getX() + DisplayController.getTwinFramesSeparatorX()); 412 387 } 413 388 break; … … 420 395 if (line.getID() < 0 && !current.getItems().contains(line)) { 421 396 line.setID(current.getNextItemID()); 422 line.setHighlightColor ();397 line.setHighlightColorToDefault(); 423 398 // Mike: Why was this line here? 424 399 // anchor(line); … … 436 411 437 412 @Override 438 public void lineColorChanged(Colo r c) {413 public void lineColorChanged(Colour c) { 439 414 if (getColor() != c) { 440 415 setColor(c); … … 450 425 return super.dontSave(); 451 426 } 427 428 @Override 429 public float getSize() 430 { 431 return getThickness(); 432 } 452 433 }
Note:
See TracChangeset
for help on using the changeset viewer.