Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.geom.Ellipse2D;
- public class EllipseNode extends GraphElement
- {
- Ellipse2D ellipse;
- protected String label;
- private boolean hasLabel;
- boolean selected = false;
- public EllipseNode (double x, double y)
- {
- super(x, y);
- ellipse = new Ellipse2D.Double(super.xPos, super.yPos, super.Width, super.Height);
- hasLabel = false;
- selected = false;
- }
- public void setLabel(String s)
- {
- hasLabel = true;
- label = s;
- }
- public double getXpos()
- {
- return xPos;
- }
- public double getYpos()
- {
- return yPos;
- }
- public double getWidth()
- {
- return super.Width;
- }
- public double getHeight()
- {
- return super.Height;
- }
- @Override
- void draw(Graphics2D g2)
- {
- g2.setColor(Color.BLACK);
- if (selected) g2.setColor(Color.BLUE);
- if (ellipse != null)
- g2.draw (ellipse);
- if (hasLabel)
- if (label.length() > 0)
- g2.drawString(label, (int) xPos + 10, (int) yPos + 20);
- }
- @Override
- void setSelected(double x, double y)
- {
- if (isSelected(x, y))
- {
- System.out.println ("This selected");
- this.selected = true;
- }
- else
- { System.out.println ("This unselected");
- this.selected = false;
- }
- }
- @Override
- boolean isSelected(double x, double y)
- {
- if (( x > xPos && x < xPos + super.Width) & ( y > yPos && y < yPos + super.Height))
- return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment