Merge kenneth en develop

This commit is contained in:
Yorick
2015-04-07 11:55:55 +02:00
17 changed files with 264 additions and 40 deletions
+1
View File
@@ -24,6 +24,7 @@ import javax.swing.JPanel;
import Listeners.Mouse;
import Listeners.MouseMotion;
import Listeners.MouseWheel;
import Objects.DrawObject;
import Objects.Entrance;
import Objects.Food;
import Objects.OldPath;
+179 -7
View File
@@ -20,8 +20,10 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import Objects.DrawObject;
import Objects.Path;
@SuppressWarnings("serial")
public class PropertiesPanel extends JPanel
{
@@ -35,11 +37,16 @@ public class PropertiesPanel extends JPanel
JLabel nameLabel;
JPanel areaPanel;
JTextField locationXField;
JTextField locationYField;
JTextField scaleField;
JTextField rotationField;
JTextField areaTopField;
JTextField areaBottomField;
JTextField areaLeftField;
JTextField areaRightField;
PropertiesPanel()
{
@@ -80,9 +87,13 @@ public class PropertiesPanel extends JPanel
buttonPanel.setMaximumSize(new Dimension(200, 40));
buttonPanel.add(buttonLabel);
add(buttonPanel);
//AREA PANEL: AVAILABLE FOR ACTIONLISTENER
areaPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
areaPanel.setVisible(false);
// DELETE
JPanel deletePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
// BUTTONS ROW 1
JPanel row1ButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton deleteButton = new JButton("Delete");
deleteButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
deleteButton.addActionListener(new ActionListener()
@@ -96,10 +107,165 @@ public class PropertiesPanel extends JPanel
}
}
});
deletePanel.setPreferredSize(new Dimension(200, 50));
deletePanel.setMaximumSize(new Dimension(200, 50));
deletePanel.add(deleteButton);
add(deletePanel);
JButton areaButton = new JButton("Area");
areaButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
areaButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
areaPanel.setVisible(!areaPanel.isVisible());
}
});
row1ButtonPanel.setPreferredSize(new Dimension(200, 50));
row1ButtonPanel.setMaximumSize(new Dimension(200, 50));
row1ButtonPanel.add(deleteButton);
row1ButtonPanel.add(areaButton);
add(row1ButtonPanel);
//AREA PANEL
JLabel areaLabel = new JLabel("Area size");
areaLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
areaPanel.setPreferredSize(new Dimension(200, 150));
areaPanel.setMaximumSize(new Dimension(200, 250));
areaPanel.add(areaLabel);
add(areaPanel);
{
JPanel areaTopPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
areaTopPanel.setPreferredSize(new Dimension(200, 50));
areaPanel.add(areaTopPanel);
JLabel areaTopLabel = new JLabel("Top");
areaTopPanel.add(areaTopLabel);
areaTopField = new JTextField();
areaTopField.setPreferredSize(new Dimension(140, 25));
{
areaTopField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e)
{
try
{
areaTopField.setBackground(Color.WHITE);
int top = Integer.parseInt(areaTopField.getText());
selectedObject.setAreaTop(top);
p.update();
} catch (NumberFormatException nfe)
{
areaTopField.setBackground(Color.RED);
}
}
public void keyPressed(KeyEvent e){}
});
}
areaTopPanel.add(areaTopField);
}
{
JPanel areaBottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
areaBottomPanel.setPreferredSize(new Dimension(200, 50));
areaPanel.add(areaBottomPanel);
JLabel areaBottomLabel = new JLabel("Bottom");
areaBottomPanel.add(areaBottomLabel);
areaBottomField = new JTextField();
areaBottomField.setPreferredSize(new Dimension(120, 25));
{
areaBottomField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e)
{
try
{
areaBottomField.setBackground(Color.WHITE);
int bottom = Integer.parseInt(areaBottomField.getText());
selectedObject.setAreaBottom(bottom);
p.update();
} catch (NumberFormatException nfe)
{
areaBottomField.setBackground(Color.RED);
}
}
public void keyPressed(KeyEvent e){}
});
}
areaBottomPanel.add(areaBottomField);
}
{
JPanel areaLeftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
areaLeftPanel.setPreferredSize(new Dimension(200, 50));
areaPanel.add(areaLeftPanel);
JLabel areaLeftLabel = new JLabel("Left");
areaLeftPanel.add(areaLeftLabel);
areaLeftField = new JTextField();
areaLeftField.setPreferredSize(new Dimension(138, 25));
{
areaLeftField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e)
{
try
{
areaLeftField.setBackground(Color.WHITE);
int left = Integer.parseInt(areaLeftField.getText());
selectedObject.setAreaLeft(left);
p.update();
} catch (NumberFormatException nfe)
{
areaLeftField.setBackground(Color.RED);
}
}
public void keyPressed(KeyEvent e){}
});
}
areaLeftPanel.add(areaLeftField);
}
{
JPanel areaRightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
areaRightPanel.setPreferredSize(new Dimension(200, 50));
areaPanel.add(areaRightPanel);
JLabel areaRightLabel = new JLabel("Right");
areaRightPanel.add(areaRightLabel);
areaRightField = new JTextField();
areaRightField.setPreferredSize(new Dimension(130, 25));
{
areaRightField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e)
{
try
{
areaRightField.setBackground(Color.WHITE);
int right = Integer.parseInt(areaRightField.getText());
selectedObject.setAreaRight(right);
p.update();
} catch (NumberFormatException nfe)
{
areaRightField.setBackground(Color.RED);
}
}
public void keyPressed(KeyEvent e){}
});
}
areaRightPanel.add(areaRightField);
}
// SPACER
add(Box.createRigidArea(spacerDimension));
@@ -355,7 +521,7 @@ public class PropertiesPanel extends JPanel
}
nameLabel.setText("No Selection");
areaPanel.setVisible(false);
}
private void fillFields()
@@ -367,6 +533,12 @@ public class PropertiesPanel extends JPanel
locationYField.setText(Math.round(selectedObject.getPosition().getY()) + "");
scaleField.setText((double) Math.round(selectedObject.getScale() * 10) / 10 + "");
rotationField.setText(Math.round(selectedObject.getRotation() % 360) + "");
areaTopField.setText(selectedObject.getAreaTop() + "");
areaBottomField.setText(selectedObject.getAreaBottom() + "");
areaLeftField.setText(selectedObject.getAreaLeft() + "");
areaRightField.setText(selectedObject.getAreaRight() + "");
}
public void setPanel(Panel p)
+1 -1
View File
@@ -6,8 +6,8 @@ import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import Applicatie.DrawObject;
import Applicatie.Panel;
import Objects.DrawObject;
import Objects.Stage;
public class Mouse extends MouseAdapter
+1 -1
View File
@@ -5,8 +5,8 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
import Applicatie.Panel;
import Objects.DrawObject;
public class MouseMotion extends MouseMotionAdapter
{
+1 -1
View File
@@ -4,8 +4,8 @@ import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
import Applicatie.Panel;
import Objects.DrawObject;
public class MouseWheel implements MouseWheelListener
{
@@ -1,4 +1,4 @@
package Applicatie;
package Objects;
import java.awt.BasicStroke;
import java.awt.Color;
@@ -18,14 +18,23 @@ public abstract class DrawObject
Point2D position;
double rotation;
double scale;
int width;
int height;
private Image image;
protected boolean selected;
protected int areaTop;
protected int areaBottom;
protected int areaLeft;
protected int areaRight;
private Rectangle2D rektAngle;
private Rectangle2D upperLeftCorner;
private Rectangle2D upperRightCorner;
private Rectangle2D bottomLeftCorner;
private Rectangle2D bottomRightCorner;
private Ellipse2D rotateDot;
static final int UPPERLEFT = 0;
static final int UPPERRIGHT = 1;
static final int BOTTOMLEFT = 2;
@@ -35,10 +44,19 @@ public abstract class DrawObject
public DrawObject(String filename, Point2D position)
{
image = new ImageIcon(filename).getImage();
width = image.getWidth(null);
height = image.getHeight(null);
scale = 1;
rotation = 0;
this.position = position;
rectangleColor = Color.BLACK;
areaTop = 0;
areaBottom = 0;
areaLeft = 0;
areaRight = 0;
}
public abstract String getName();
@@ -49,14 +67,13 @@ public abstract class DrawObject
g.drawImage(image, tx, null);
if (selected)
{
// g.rotate(Math.toRadians(rotation), image.getWidth(null)/2,
// image.getHeight(null)/2);
// g.rotate(Math.toRadians(rotation), width/2,
// height/2);
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null) / 2, position.getY() + image.getHeight(null) / 2);
//g.transform(rotate);
// g.transform(rotate);
g.setColor(rectangleColor);
g.setStroke(new BasicStroke(7));
rektAngle = new Rectangle2D.Double((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
rektAngle = new Rectangle2D.Double((int) position.getX() - areaLeft, (int) position.getY() - areaTop, width + areaLeft + areaRight, height + areaTop + areaBottom);
tx = getTransformRectangle();
rektAngle.setFrame(tx.createTransformedShape(rektAngle).getBounds());
g.draw(rektAngle);
@@ -81,7 +98,7 @@ public abstract class DrawObject
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
tx.translate(position.getX(), position.getY());
tx.rotate(Math.toRadians(rotation), image.getWidth(null) / 2, image.getHeight(null) / 2);
tx.rotate(Math.toRadians(rotation), (width + areaLeft + areaRight) / 2, (height + areaTop + areaBottom) / 2);
return tx;
}
@@ -112,13 +129,13 @@ public abstract class DrawObject
Shape shape;
if (rektAngle == null)
{
shape = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
shape = new Rectangle2D.Double(0 - areaLeft, 0 - areaTop, width + areaLeft + areaRight, height + areaTop + areaBottom);
return getTransform().createTransformedShape(shape).contains(clickPoint);
}
else
{
shape = new Rectangle2D.Double(-9, -9, image.getWidth(null) + 13, image.getHeight(null) + 13);
shape = new Rectangle2D.Double(-9 - areaLeft, -9 - areaTop, width + 13 + areaLeft + areaRight, height + 13 + areaTop + areaBottom);
return getTransformSelection().createTransformedShape(shape).contains(clickPoint);
}
@@ -139,8 +156,9 @@ public abstract class DrawObject
}
/**
* Method that gets all the corner coordinates index: 0 -> top left 1 -> top
* right 3 -> bottom left 4 -> bottom right
* <<<<<<< HEAD:Applicatie/DrawObject.java Method that gets all the corner
* coordinates index: 0 -> top left 1 -> top right 3 -> bottom left 4 ->
* bottom right
*
* @return corner coordinates
*/
@@ -161,17 +179,20 @@ public abstract class DrawObject
}
/**
* Checking collision.
* @param object. the drawObject to check collision with.
* ======= >>>>>>> origin/kenneth:Objects/DrawObject.java Checking
* collision.
*
* @param object
* . the drawObject to check collision with.
* @return if there is a collision.
*/
public boolean collision(DrawObject object)
{
Shape ownShape = getRectangle();
Rectangle2D otherRectangle = object.getTransform().createTransformedShape(object.getImageRectangle()).getBounds2D();
if(ownShape.intersects(otherRectangle))
if (ownShape.intersects(otherRectangle))
return true;
else
else
return false;
}
@@ -282,9 +303,50 @@ public abstract class DrawObject
{
this.rectangleColor = rectangleColor;
}
public Rectangle2D getImageRectangle() {
return new Rectangle2D.Double(0,0, image.getWidth(null), image.getHeight(null));
public Rectangle2D getImageRectangle()
{
return new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
}
public int getAreaTop()
{
return areaTop;
}
public void setAreaTop(int areaTop)
{
this.areaTop = areaTop;
}
public int getAreaBottom()
{
return areaBottom;
}
public void setAreaBottom(int areaBottom)
{
this.areaBottom = areaBottom;
}
public int getAreaLeft()
{
return areaLeft;
}
public void setAreaLeft(int areaLeft)
{
this.areaLeft = areaLeft;
}
public int getAreaRight()
{
return areaRight;
}
public void setAreaRight(int areaRight)
{
this.areaRight = areaRight;
}
}
-2
View File
@@ -2,8 +2,6 @@ package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Entrance extends DrawObject
{
-2
View File
@@ -1,8 +1,6 @@
package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Food extends DrawObject {
-2
View File
@@ -2,8 +2,6 @@ package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class OldPath extends DrawObject
{
+1
View File
@@ -21,6 +21,7 @@ import javax.imageio.ImageIO;
*/
public class Path {
private ArrayList<Point2D> points;
private ArrayList<Shape> lines;
private Point2D tempPoint;
-2
View File
@@ -2,8 +2,6 @@ package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Stage extends DrawObject
{
public Stage(Point2D position)
-2
View File
@@ -2,8 +2,6 @@ package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Toilet extends DrawObject
{
-2
View File
@@ -2,8 +2,6 @@ package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Wall extends DrawObject
{
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB