diff --git a/Applicatie/Panel.java b/Applicatie/Panel.java index 46f813f..2b57635 100644 --- a/Applicatie/Panel.java +++ b/Applicatie/Panel.java @@ -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; diff --git a/Applicatie/PropertiesPanel.java b/Applicatie/PropertiesPanel.java index ba9b0b8..8ac8164 100644 --- a/Applicatie/PropertiesPanel.java +++ b/Applicatie/PropertiesPanel.java @@ -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) diff --git a/Listeners/Mouse.java b/Listeners/Mouse.java index 6f50d83..e611c2c 100644 --- a/Listeners/Mouse.java +++ b/Listeners/Mouse.java @@ -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 diff --git a/Listeners/MouseMotion.java b/Listeners/MouseMotion.java index a40a559..cd6ae6f 100644 --- a/Listeners/MouseMotion.java +++ b/Listeners/MouseMotion.java @@ -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 { diff --git a/Listeners/MouseWheel.java b/Listeners/MouseWheel.java index c841884..4f6fcea 100644 --- a/Listeners/MouseWheel.java +++ b/Listeners/MouseWheel.java @@ -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 { diff --git a/Applicatie/DrawObject.java b/Objects/DrawObject.java similarity index 77% rename from Applicatie/DrawObject.java rename to Objects/DrawObject.java index a72e375..706447e 100644 --- a/Applicatie/DrawObject.java +++ b/Objects/DrawObject.java @@ -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; } } diff --git a/Objects/Entrance.java b/Objects/Entrance.java index 69a7033..eab28db 100644 --- a/Objects/Entrance.java +++ b/Objects/Entrance.java @@ -2,8 +2,6 @@ package Objects; import java.awt.geom.Point2D; -import Applicatie.DrawObject; - public class Entrance extends DrawObject { diff --git a/Objects/Food.java b/Objects/Food.java index cdd5028..d6bdb65 100644 --- a/Objects/Food.java +++ b/Objects/Food.java @@ -1,8 +1,6 @@ package Objects; import java.awt.geom.Point2D; -import Applicatie.DrawObject; - public class Food extends DrawObject { diff --git a/Objects/OldPath.java b/Objects/OldPath.java index eea51b7..3acdf12 100644 --- a/Objects/OldPath.java +++ b/Objects/OldPath.java @@ -2,8 +2,6 @@ package Objects; import java.awt.geom.Point2D; -import Applicatie.DrawObject; - public class OldPath extends DrawObject { diff --git a/Objects/Path.java b/Objects/Path.java index b6e7da0..67cbe12 100644 --- a/Objects/Path.java +++ b/Objects/Path.java @@ -21,6 +21,7 @@ import javax.imageio.ImageIO; */ public class Path { + private ArrayList points; private ArrayList lines; private Point2D tempPoint; diff --git a/Objects/Stage.java b/Objects/Stage.java index 9827adc..2c3b82c 100644 --- a/Objects/Stage.java +++ b/Objects/Stage.java @@ -2,8 +2,6 @@ package Objects; import java.awt.geom.Point2D; -import Applicatie.DrawObject; - public class Stage extends DrawObject { public Stage(Point2D position) diff --git a/Objects/Toilet.java b/Objects/Toilet.java index f0a0aa8..3a8708a 100644 --- a/Objects/Toilet.java +++ b/Objects/Toilet.java @@ -2,8 +2,6 @@ package Objects; import java.awt.geom.Point2D; -import Applicatie.DrawObject; - public class Toilet extends DrawObject { diff --git a/Objects/Wall.java b/Objects/Wall.java index 6c213d4..e79b3c1 100644 --- a/Objects/Wall.java +++ b/Objects/Wall.java @@ -2,8 +2,6 @@ package Objects; import java.awt.geom.Point2D; -import Applicatie.DrawObject; - public class Wall extends DrawObject { diff --git a/images/KENNY_Entrance.png b/images/KENNY_Entrance.png deleted file mode 100644 index 6bc4bad..0000000 Binary files a/images/KENNY_Entrance.png and /dev/null differ diff --git a/images/KENNY_Food.png b/images/KENNY_Food.png deleted file mode 100644 index a4e4a7b..0000000 Binary files a/images/KENNY_Food.png and /dev/null differ diff --git a/images/KENNY_Toilet.png b/images/KENNY_Toilet.png deleted file mode 100644 index 7d5d4a7..0000000 Binary files a/images/KENNY_Toilet.png and /dev/null differ diff --git a/images/toilet.png b/images/toilet.png deleted file mode 100644 index ac4027b..0000000 Binary files a/images/toilet.png and /dev/null differ