update
try
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package Applicatie;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
@@ -17,7 +16,6 @@ public class DrawObject {
|
||||
double scale;
|
||||
Image image;
|
||||
protected boolean selected;
|
||||
private Rectangle2D rektAngle;
|
||||
|
||||
public DrawObject(String filename, Point2D position)
|
||||
{
|
||||
@@ -31,14 +29,6 @@ public class DrawObject {
|
||||
{
|
||||
AffineTransform tx = getTransform();
|
||||
g.drawImage(image, tx, null);
|
||||
if(selected) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.setStroke(new BasicStroke(7));
|
||||
rektAngle = new Rectangle2D.Double((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
|
||||
tx = getTransformRectangle(rektAngle.getWidth(),rektAngle.getHeight());
|
||||
Shape transformedRektAngle = tx.createTransformedShape(rektAngle);
|
||||
g.draw(transformedRektAngle);
|
||||
}
|
||||
}
|
||||
|
||||
protected AffineTransform getTransform() {
|
||||
@@ -49,19 +39,6 @@ public class DrawObject {
|
||||
return tx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special transformation for the selection rectangle, because the translation of the image one places the rectangle translated from the image.
|
||||
* @param width
|
||||
* @param height
|
||||
* @return
|
||||
*/
|
||||
private AffineTransform getTransformRectangle(double width, double height) {
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
tx.rotate(Math.toRadians(rotation), width / 2, height / 2);
|
||||
return tx;
|
||||
}
|
||||
|
||||
public boolean contains(Point2D clickPoint) {
|
||||
Shape shape = new Rectangle2D.Double(0,0,image.getWidth(null), image.getHeight(null));
|
||||
return getTransform().createTransformedShape(shape).contains(clickPoint);
|
||||
@@ -108,8 +85,5 @@ public class DrawObject {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public Rectangle2D getRectangle() {
|
||||
return rektAngle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+115
-22
@@ -3,10 +3,7 @@ import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.TexturePaint;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
@@ -21,35 +18,67 @@ import javax.swing.JPanel;
|
||||
import Listeners.Mouse;
|
||||
import Listeners.MouseMotion;
|
||||
import Listeners.MouseWheel;
|
||||
import Objects.Entrance;
|
||||
import Objects.Path;
|
||||
import Objects.Podium;
|
||||
import Objects.Toilet;
|
||||
import Objects.Wall;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Panel extends JPanel {
|
||||
|
||||
BufferedImage background;
|
||||
BufferedImage podiumImage, toiletImage, entranceImage, pathImage,wallImage;
|
||||
|
||||
private int panelInfox, panelInfoy,scrollfactor;
|
||||
|
||||
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
|
||||
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
|
||||
|
||||
ArrayList<DrawObject> objects = new ArrayList<>();
|
||||
DrawObject dragObject = null;
|
||||
private DrawObject selectedObject;
|
||||
private String clickedOption = "drag";
|
||||
|
||||
Point2D cameraPoint = new Point2D.Double(getWidth()/2,getHeight()/2);
|
||||
float cameraScale = 1;
|
||||
|
||||
PropertiesPanel pp;
|
||||
|
||||
|
||||
Point2D lastClickPosition = new Point(0,0);
|
||||
Point lastMousePosition = new Point(0,0);
|
||||
|
||||
Panel()
|
||||
//how to nieuwe dingen aan het panel toe te voegen:
|
||||
//maak bufferedimage global aan, voeg er een image aan toe, en voeg de image aan panelInfo toe en het object aan panelTypes.
|
||||
//en maak een case statement die een new Object returnt in createNewDrawObject.
|
||||
|
||||
|
||||
Panel(PropertiesPanel pp)
|
||||
{
|
||||
this.pp = pp;
|
||||
pp.setPanel(this);
|
||||
try {
|
||||
background = ImageIO.read(new File("images/grass.jpg"));
|
||||
podiumImage = ImageIO.read(new File("images/stageIcon.png"));
|
||||
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
|
||||
entranceImage = ImageIO.read(new File("images/entranceIcon.png"));
|
||||
pathImage = ImageIO.read(new File("images/pathIcon.png"));
|
||||
wallImage = ImageIO.read(new File("images/wallIcon.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
panelInfo.add(podiumImage);
|
||||
panelInfo.add(toiletImage);
|
||||
panelInfo.add(entranceImage);
|
||||
panelInfo.add(pathImage);
|
||||
panelInfo.add(wallImage);
|
||||
|
||||
objects.add(new Podium(new Point2D.Double(100, 100)));
|
||||
objects.add(new Podium(new Point2D.Double(500, 100)));
|
||||
objects.add(new Podium(new Point2D.Double(300, 400)));
|
||||
panelInfox = 0;
|
||||
panelInfoy = 0;
|
||||
scrollfactor = 0;
|
||||
|
||||
// objects.add(new Podium(new Point2D.Double(100, 100)));
|
||||
// objects.add(new Podium(new Point2D.Double(500, 100)));
|
||||
// objects.add(new Podium(new Point2D.Double(300, 400)));
|
||||
|
||||
addMouseListener(new Mouse(this));
|
||||
|
||||
@@ -59,6 +88,35 @@ public class Panel extends JPanel {
|
||||
|
||||
}
|
||||
|
||||
public int getPanelInfoLength()
|
||||
{
|
||||
int panelInfoLength = 0;
|
||||
for(BufferedImage image : panelInfo)
|
||||
{
|
||||
panelInfoLength += image.getWidth();
|
||||
}
|
||||
|
||||
return panelInfoLength;
|
||||
}
|
||||
|
||||
public DrawObject createNewDrawObject(int index)
|
||||
{
|
||||
switch(index)
|
||||
{
|
||||
case 0:
|
||||
return new Podium(null);
|
||||
case 1:
|
||||
return new Toilet(null);
|
||||
case 2:
|
||||
return new Entrance(null);
|
||||
case 3:
|
||||
return new Path(null);
|
||||
case 4:
|
||||
return new Wall(null);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void add(DrawObject dragObject)
|
||||
{
|
||||
@@ -69,21 +127,30 @@ public class Panel extends JPanel {
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
g2.setClip(new Rectangle2D.Double(0,0, 200, getHeight()));
|
||||
g2.setClip(new Rectangle2D.Double(0,0, getWidth(), 300));
|
||||
|
||||
g2.fill(new Ellipse2D.Double(0,0,300,300));
|
||||
// g2.fill(new Ellipse2D.Double(0,0,300,300));
|
||||
|
||||
// g2.drawImage(podiumImage, 0, 0, null);
|
||||
for(BufferedImage image : panelInfo)
|
||||
{
|
||||
g2.drawImage(image, panelInfox + scrollfactor, panelInfoy, null);
|
||||
panelInfox += image.getWidth();
|
||||
}
|
||||
panelInfox = 0;
|
||||
|
||||
g2.setClip(new Rectangle2D.Double(200,0, getWidth()-200, getHeight()));
|
||||
g2.setClip(new Rectangle2D.Double(0,150, getWidth(), getHeight()));
|
||||
AffineTransform oldTransform = g2.getTransform();
|
||||
g2.setTransform(getCamera());
|
||||
|
||||
TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 100, 100));
|
||||
g2.setPaint(p);
|
||||
g2.fill(new Rectangle2D.Double(0,0,1920,1080));
|
||||
g2.fill(new Rectangle2D.Double(-1920,-1080,3840,2160));
|
||||
|
||||
for(DrawObject o : objects)
|
||||
for(DrawObject o : objects){
|
||||
o.draw(g2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
g2.setClip(null);
|
||||
@@ -175,24 +242,50 @@ public class Panel extends JPanel {
|
||||
}
|
||||
|
||||
|
||||
public DrawObject getSelectedObject() {
|
||||
return selectedObject;
|
||||
public BufferedImage getPodiumImage() {
|
||||
return podiumImage;
|
||||
}
|
||||
|
||||
|
||||
public void setSelectedObject(DrawObject selectedObject) {
|
||||
this.selectedObject = selectedObject;
|
||||
public void setPodiumImage(BufferedImage podiumImage) {
|
||||
this.podiumImage = podiumImage;
|
||||
}
|
||||
|
||||
|
||||
public String getClickedOption() {
|
||||
return clickedOption;
|
||||
public ArrayList<BufferedImage> getPanelInfo() {
|
||||
return panelInfo;
|
||||
}
|
||||
|
||||
|
||||
public void setClickedOption(String clickedOption) {
|
||||
this.clickedOption = clickedOption;
|
||||
public void setPanelInfo(ArrayList<BufferedImage> panelInfo) {
|
||||
this.panelInfo = panelInfo;
|
||||
}
|
||||
|
||||
|
||||
public int getScrollfactor() {
|
||||
return scrollfactor;
|
||||
}
|
||||
|
||||
public void setScrollfactor(int scrollfactor) {
|
||||
this.scrollfactor = scrollfactor;
|
||||
}
|
||||
|
||||
public int getPanelInfox() {
|
||||
return panelInfox;
|
||||
}
|
||||
|
||||
public void setPanelInfox(int panelInfox) {
|
||||
this.panelInfox = panelInfox;
|
||||
}
|
||||
|
||||
public PropertiesPanel getPP()
|
||||
{
|
||||
return pp;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
package Applicatie;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PropertiesPanel extends JPanel {
|
||||
|
||||
DrawObject selectedObject = null;
|
||||
Panel p = null;
|
||||
|
||||
JTextField locationXField;
|
||||
JTextField locationYField;
|
||||
JTextField scaleField;
|
||||
JTextField rotationField;
|
||||
|
||||
PropertiesPanel()
|
||||
{
|
||||
super();
|
||||
BoxLayout box = new BoxLayout(this, BoxLayout.PAGE_AXIS);
|
||||
setLayout(box);
|
||||
|
||||
setPreferredSize(new Dimension(200,0));
|
||||
setBorder(BorderFactory.createLineBorder(new Color(180,180,180)));
|
||||
setBackground(new Color(220, 220, 220));
|
||||
|
||||
|
||||
//NAME "PROPERTIES"
|
||||
JPanel propPanel = new JPanel();
|
||||
JLabel propLabel = new JLabel("Properties");
|
||||
propLabel.setFont(new Font("Segoe UI", Font.BOLD, 30));
|
||||
propPanel.setBackground(new Color(220, 220, 220));
|
||||
propPanel.setMaximumSize(new Dimension(200, 60));
|
||||
propPanel.add(propLabel);
|
||||
add(propPanel);
|
||||
|
||||
|
||||
//LOCATION
|
||||
JPanel locationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JLabel locationLabel = new JLabel("Location");
|
||||
locationLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||
locationPanel.setPreferredSize(new Dimension(200, 150));
|
||||
locationPanel.setMaximumSize(new Dimension(200, 150));
|
||||
locationPanel.add(locationLabel);
|
||||
add(locationPanel);
|
||||
{
|
||||
JPanel locationXPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
locationXPanel.setPreferredSize(new Dimension(200, 50));
|
||||
locationPanel.add(locationXPanel);
|
||||
|
||||
JLabel locationXLabel = new JLabel("X");
|
||||
locationXPanel.add(locationXLabel);
|
||||
locationXField = new JTextField();
|
||||
locationXField.setPreferredSize(new Dimension(150, 25));
|
||||
{
|
||||
locationXField.addKeyListener(new KeyListener() {
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
try{
|
||||
locationXField.setBackground(Color.WHITE);
|
||||
double xpos = Double.parseDouble(locationXField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()));
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe) {
|
||||
locationXField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
public void keyReleased(KeyEvent e) {}
|
||||
public void keyPressed(KeyEvent e) {}
|
||||
});
|
||||
}
|
||||
locationXPanel.add(locationXField);
|
||||
}
|
||||
{
|
||||
JPanel locationYPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
locationYPanel.setPreferredSize(new Dimension(200, 50));
|
||||
locationPanel.add(locationYPanel);
|
||||
|
||||
JLabel locationYLabel = new JLabel("Y");
|
||||
locationYPanel.add(locationYLabel);
|
||||
locationYField = new JTextField();
|
||||
locationYField.setPreferredSize(new Dimension(150, 25));
|
||||
{
|
||||
locationYField.addKeyListener(new KeyListener() {
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
try{
|
||||
locationYField.setBackground(Color.WHITE);
|
||||
double ypos = Double.parseDouble(locationYField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos));;
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe) {
|
||||
locationYField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
public void keyReleased(KeyEvent e) {}
|
||||
public void keyPressed(KeyEvent e) {}
|
||||
});
|
||||
}
|
||||
locationYPanel.add(locationYField);
|
||||
}
|
||||
|
||||
|
||||
//SCALE
|
||||
JPanel scalePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JLabel scaleLabel = new JLabel("Scale");
|
||||
scaleLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||
scalePanel.setPreferredSize(new Dimension(200, 100));
|
||||
scalePanel.setMaximumSize(new Dimension(200, 100));
|
||||
scalePanel.add(scaleLabel);
|
||||
add(scalePanel);
|
||||
{
|
||||
JPanel scalePanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
scalePanel2.setPreferredSize(new Dimension(200, 50));
|
||||
scalePanel.add(scalePanel2);
|
||||
|
||||
JLabel scale2Label = new JLabel(" ");
|
||||
scalePanel2.add(scale2Label);
|
||||
scaleField = new JTextField();
|
||||
scaleField.setPreferredSize(new Dimension(150, 25));
|
||||
{
|
||||
scaleField.addKeyListener(new KeyListener() {
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
try{
|
||||
scaleField.setBackground(Color.WHITE);
|
||||
double scale = Double.parseDouble(scaleField.getText());
|
||||
selectedObject.setScale(scale);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe) {
|
||||
scaleField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
public void keyReleased(KeyEvent e) {}
|
||||
public void keyPressed(KeyEvent e) {}
|
||||
});
|
||||
}
|
||||
scalePanel2.add(scaleField);
|
||||
}
|
||||
|
||||
|
||||
//ROTATION
|
||||
JPanel rotationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JLabel rotationLabel = new JLabel("Rotation");
|
||||
rotationLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||
rotationPanel.setPreferredSize(new Dimension(200, 100));
|
||||
rotationPanel.setMaximumSize(new Dimension(200, 100));
|
||||
rotationPanel.add(rotationLabel);
|
||||
add(rotationPanel);
|
||||
{
|
||||
JPanel rotationPanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
rotationPanel2.setPreferredSize(new Dimension(200, 50));
|
||||
rotationPanel.add(rotationPanel2);
|
||||
|
||||
JLabel rotation2Label = new JLabel(" ");
|
||||
rotationPanel2.add(rotation2Label);
|
||||
rotationField = new JTextField();
|
||||
rotationField.setPreferredSize(new Dimension(150, 25));
|
||||
{
|
||||
rotationField.addKeyListener(new KeyListener() {
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
try{
|
||||
rotationField.setBackground(Color.WHITE);
|
||||
int rotation = Integer.parseInt(rotationField.getText()) % 360;
|
||||
rotationField.setText(rotation +"");
|
||||
selectedObject.setRotation(rotation);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe) {
|
||||
rotationField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
public void keyReleased(KeyEvent e) {}
|
||||
public void keyPressed(KeyEvent e) {}
|
||||
});
|
||||
}
|
||||
rotationPanel2.add(rotationField);
|
||||
}
|
||||
|
||||
//SPACER
|
||||
JPanel spacerPanel = new JPanel();
|
||||
spacerPanel.setPreferredSize(new Dimension(200, 50));
|
||||
spacerPanel.setMaximumSize(new Dimension(200, 50));
|
||||
spacerPanel.setBackground(new Color(220, 220, 220));
|
||||
add(spacerPanel);
|
||||
|
||||
//EXAMPLE
|
||||
JPanel examplePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JLabel exampleLabel = new JLabel("Example");
|
||||
exampleLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||
examplePanel.setPreferredSize(new Dimension(200, 100));
|
||||
examplePanel.setMaximumSize(new Dimension(200, 100));
|
||||
examplePanel.add(exampleLabel);
|
||||
add(examplePanel);
|
||||
|
||||
enableComponents(this, false);
|
||||
}
|
||||
|
||||
|
||||
public void setSelected(DrawObject drOb)
|
||||
{
|
||||
selectedObject = drOb;
|
||||
fillFields();
|
||||
enableComponents(this, true);
|
||||
}
|
||||
|
||||
public void clearSelected()
|
||||
{
|
||||
enableComponents(this, false);
|
||||
clearFields(this);
|
||||
selectedObject = null;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
fillFields();
|
||||
}
|
||||
|
||||
private void enableComponents(Container container, boolean enable) {
|
||||
Component[] components = container.getComponents();
|
||||
for (Component component : components) {
|
||||
component.setEnabled(enable);
|
||||
if (component instanceof Container) {
|
||||
enableComponents((Container)component, enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearFields(Container container) {
|
||||
Component[] components = container.getComponents();
|
||||
for (Component component : components) {
|
||||
if (component instanceof JTextField) {
|
||||
((JTextField) component).setText("");
|
||||
}
|
||||
if (component instanceof Container) {
|
||||
clearFields((Container)component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fillFields() {
|
||||
locationXField.setText(Math.round(selectedObject.getPosition().getX()) + "");
|
||||
locationYField.setText(Math.round(selectedObject.getPosition().getY()) + "");
|
||||
scaleField.setText((double)Math.round(selectedObject.getScale()*10)/10 + "");
|
||||
rotationField.setText(Math.round(selectedObject.getRotation()%360) + "");
|
||||
}
|
||||
|
||||
public void setPanel(Panel p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,10 @@ public class Window extends JFrame {
|
||||
|
||||
//CONTENT PANELS
|
||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||
Panel fp = new Panel();
|
||||
PropertiesPanel pp = new PropertiesPanel();
|
||||
Panel fp = new Panel(pp);
|
||||
contentPanel.add(fp, BorderLayout.CENTER);
|
||||
contentPanel.add(pp, BorderLayout.EAST);
|
||||
|
||||
setContentPane(contentPanel);
|
||||
//END CONTENT PANELS
|
||||
|
||||
+34
-36
@@ -3,71 +3,69 @@ package Listeners;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
import Applicatie.Panel;
|
||||
import Objects.Podium;
|
||||
import Objects.Toilet;
|
||||
import Applicatie.Panel;
|
||||
|
||||
public class Mouse extends MouseAdapter {
|
||||
|
||||
private Panel panel;
|
||||
private DrawObject selectedObject;
|
||||
|
||||
public Mouse(Panel panel)
|
||||
{
|
||||
this.panel = panel;
|
||||
selectedObject = null;
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
|
||||
if(e.getX() < 200)
|
||||
if(e.getY() < 150)
|
||||
{
|
||||
if(e.getY() < 300)
|
||||
panel.setDragObject(new Podium(clickPoint));
|
||||
else
|
||||
panel.setDragObject(new Toilet(clickPoint));
|
||||
panel.add(panel.getDragObject());
|
||||
// if(e.getX() < 51) //51 = width podium image
|
||||
// panel.setDragObject(new Podium(clickPoint));
|
||||
// else
|
||||
// panel.setDragObject(new Toilet(clickPoint));
|
||||
int i = 0;
|
||||
int last = 0;
|
||||
for(BufferedImage image : panel.getPanelInfo())
|
||||
{
|
||||
if(e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||
{
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
panel.setDragObject(tempDrawObj);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
last += image.getWidth();
|
||||
|
||||
}
|
||||
if(panel.getDragObject() != null)
|
||||
{
|
||||
panel.add(panel.getDragObject());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(DrawObject o : panel.getObjects())
|
||||
if(o.contains(clickPoint)) {
|
||||
if(o == selectedObject) {
|
||||
boolean upperLeft = clickPoint.getX() > o.getRectangle().getX() && clickPoint.getX() < o.getRectangle().getX()+o.getRectangle().getWidth()/10
|
||||
&& clickPoint.getY() > o.getRectangle().getY() && clickPoint.getY() < o.getRectangle().getY()+o.getRectangle().getHeight()/10;
|
||||
if(upperLeft) {
|
||||
System.out.println("lal");
|
||||
panel.setClickedOption("upperLeft");
|
||||
}
|
||||
else {
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
}
|
||||
if(selectedObject != null)
|
||||
selectedObject.setSelected(false);
|
||||
{
|
||||
if(o.contains(clickPoint))
|
||||
{
|
||||
panel.setDragObject(o);
|
||||
o.setSelected(true);
|
||||
selectedObject = o;
|
||||
System.out.println("selected");
|
||||
panel.getPP().setSelected(o);
|
||||
return;
|
||||
}
|
||||
}
|
||||
panel.getPP().clearSelected();
|
||||
}
|
||||
if(panel.getDragObject() == null && selectedObject != null) {
|
||||
System.out.println("deselected");
|
||||
selectedObject.setSelected(false);
|
||||
selectedObject = null;
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
panel.setDragObject(null);
|
||||
panel.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
+23
-31
@@ -21,41 +21,33 @@ public class MouseMotion extends MouseMotionAdapter {
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
switch(panel.getClickedOption()) {
|
||||
case "drag":
|
||||
if(panel.getDragObject() != null)
|
||||
panel.getDragObject().setPosition(new Point2D.Double(
|
||||
if(panel.getDragObject() != null)
|
||||
{
|
||||
if(SwingUtilities.isLeftMouseButton(e)){
|
||||
|
||||
|
||||
panel.getDragObject().setPosition(new Point2D.Double(
|
||||
panel.getDragObject().getPosition().getX() - (panel.getLastClickPosition().getX() - clickPoint.getX()),
|
||||
panel.getDragObject().getPosition().getY() - (panel.getLastClickPosition().getY() - clickPoint.getY())));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
double tempval = panel.getDragObject().getRotation() + (panel.getLastClickPosition().getX() - clickPoint.getX());
|
||||
panel.getDragObject().setRotation(tempval);
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.setCameraPoint(new Point2D.Double(
|
||||
panel.getCameraPoint().getX() + (panel.getLastMousePosition().getX() - e.getX()),
|
||||
panel.getCameraPoint().getY() + (panel.getLastMousePosition().getY() - e.getY())
|
||||
));
|
||||
panel.repaint();
|
||||
}
|
||||
panel.repaint();
|
||||
|
||||
|
||||
// if(panel.getDragObject() != null)
|
||||
// {
|
||||
// if(SwingUtilities.isLeftMouseButton(e)){
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
//double tempval = panel.getDragObject().getRotation() + (panel.getLastClickPosition().getX() - clickPoint.getX());
|
||||
//panel.getDragObject().setRotation(tempval);
|
||||
//
|
||||
// }
|
||||
// panel.repaint();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// panel.setCameraPoint(new Point2D.Double(
|
||||
// panel.getCameraPoint().getX() + (panel.getLastMousePosition().getX() - e.getX()),
|
||||
// panel.getCameraPoint().getY() + (panel.getLastMousePosition().getY() - e.getY())
|
||||
// ));
|
||||
// panel.repaint();
|
||||
// }
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.getPP().update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ import Applicatie.Panel;
|
||||
|
||||
public class MouseWheel implements MouseWheelListener {
|
||||
private Panel panel;
|
||||
|
||||
private int scrollfactor;
|
||||
|
||||
public MouseWheel(Panel panel)
|
||||
{
|
||||
this.panel = panel;
|
||||
scrollfactor = 20;
|
||||
}
|
||||
|
||||
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
for(DrawObject o : panel.getObjects())
|
||||
@@ -23,14 +25,42 @@ public class MouseWheel implements MouseWheelListener {
|
||||
{
|
||||
double scale = o.getScale()* 1 + (e.getPreciseWheelRotation()/10.0);
|
||||
o.setScale(scale);
|
||||
panel.getPP().update();
|
||||
panel.repaint();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(e.getY() < 150)
|
||||
{
|
||||
|
||||
if(e.getPreciseWheelRotation() < 0)
|
||||
{
|
||||
if(panel.getScrollfactor() + scrollfactor + panel.getPanelInfoLength() < panel.getWidth())
|
||||
{
|
||||
panel.setScrollfactor(panel.getScrollfactor() + scrollfactor);
|
||||
}
|
||||
|
||||
// cameraPoint
|
||||
double cameraScale = panel.getCameraScale() * 1 - (e.getPreciseWheelRotation()/10);
|
||||
panel.setCameraScale((float) cameraScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(panel.getScrollfactor() - scrollfactor >= 0)
|
||||
{
|
||||
panel.setScrollfactor(panel.getScrollfactor() - scrollfactor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// cameraPoint
|
||||
double cameraScale = panel.getCameraScale() * 1 - (e.getPreciseWheelRotation()/10);
|
||||
panel.setCameraScale((float) cameraScale);
|
||||
|
||||
}
|
||||
|
||||
|
||||
panel.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package Objects;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
|
||||
|
||||
public class Entrance extends DrawObject {
|
||||
|
||||
public Entrance(Point2D position) {
|
||||
super("images/entrance.png", position);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package Objects;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
|
||||
|
||||
public class Path extends DrawObject {
|
||||
|
||||
public Path(Point2D position) {
|
||||
super("images/path.jpg", position);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Toilet extends DrawObject {
|
||||
|
||||
public Toilet(Point2D position) {
|
||||
super("images/toilet.png", position);
|
||||
super("images/wc.png", position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package Objects;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
|
||||
|
||||
public class Wall extends DrawObject {
|
||||
|
||||
public Wall(Point2D position) {
|
||||
super("images/wall.png", position);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user