From 2d56ac1b898e94bc258dc5401e9ebe4137866817 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 7 Apr 2015 13:05:13 +0200 Subject: [PATCH 1/2] Added Control Panel and improved Properties Panel. --- Applicatie/ControlPanel.java | 129 ++++++++++++++++++++++++++++++++ Applicatie/Panel.java | 2 - Applicatie/PropertiesPanel.java | 52 +++++++------ Applicatie/Window.java | 9 ++- 4 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 Applicatie/ControlPanel.java diff --git a/Applicatie/ControlPanel.java b/Applicatie/ControlPanel.java new file mode 100644 index 0000000..6362e4c --- /dev/null +++ b/Applicatie/ControlPanel.java @@ -0,0 +1,129 @@ +package Applicatie; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class ControlPanel extends JPanel +{ + private static final long serialVersionUID = 6805244250902524351L; + + public ControlPanel() + { + super(); + BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS); + setLayout(box); + + setPreferredSize(new Dimension(0,50)); + setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180))); + setBackground(new Color(220, 220, 220)); + + + JPanel simulatorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + simulatorPanel.setPreferredSize(new Dimension(350,50)); + simulatorPanel.setMaximumSize(new Dimension(350,50)); + add(simulatorPanel); + { + JLabel simulatorLabel = new JLabel("Simulator: "); + simulatorLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20)); + simulatorPanel.add(simulatorLabel); + + JButton playButton = new JButton("Play"); + playButton.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + playButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) + { + ///TODO implement + } + }); + simulatorPanel.add(playButton); + + JButton pauseButton = new JButton("Pause"); + pauseButton.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + pauseButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) + { + ///TODO implement + } + }); + simulatorPanel.add(pauseButton); + + JButton stopButton = new JButton("Stop"); + stopButton.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + stopButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) + { + ///TODO implement + } + }); + simulatorPanel.add(stopButton); + } + + add(Box.createRigidArea(new Dimension(10,50))); + + JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + timePanel.setPreferredSize(new Dimension(280,50)); + timePanel.setMaximumSize(new Dimension(280,50)); + add(timePanel); + { + JLabel timeLabel = new JLabel("00:00 00-00-000"); + timeLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + timePanel.add(timeLabel); + + JButton dateButton = new JButton("Pick Date"); + dateButton.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + dateButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) + { + ///TODO implement + } + }); + timePanel.add(dateButton); + } + + add(Box.createRigidArea(new Dimension(10,50))); + + JPanel peoplePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + peoplePanel.setPreferredSize(new Dimension(285,50)); + peoplePanel.setMaximumSize(new Dimension(285,50)); + add(peoplePanel); + { + JLabel peopleLabel = new JLabel("0/0 People"); + peopleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + peoplePanel.add(peopleLabel); + + JButton peopleButton = new JButton("Set People"); + peopleButton.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + peopleButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) + { + ///TODO implement + } + }); + peoplePanel.add(peopleButton); + } + + add(Box.createHorizontalGlue()); + + JPanel runningPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + runningPanel.setPreferredSize(new Dimension(195,50)); + runningPanel.setMaximumSize(new Dimension(195,50)); + add(runningPanel); + { + JLabel runningLabel = new JLabel("Simulation stopped"); + runningLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20)); + runningPanel.add(runningLabel); + } + + } +} diff --git a/Applicatie/Panel.java b/Applicatie/Panel.java index f96bcec..d92870d 100644 --- a/Applicatie/Panel.java +++ b/Applicatie/Panel.java @@ -7,7 +7,6 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.TexturePaint; import java.awt.geom.AffineTransform; -import java.awt.geom.GeneralPath; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -125,7 +124,6 @@ public class Panel extends JPanel { switch (index) { - case 0: return new Stage(null); case 1: diff --git a/Applicatie/PropertiesPanel.java b/Applicatie/PropertiesPanel.java index 070e1bd..96d0a22 100644 --- a/Applicatie/PropertiesPanel.java +++ b/Applicatie/PropertiesPanel.java @@ -29,10 +29,11 @@ public class PropertiesPanel extends JPanel DrawObject selectedObject = null; Panel p = null; - Dimension spacerDimension = new Dimension(200, 30); + Dimension spacerDimension = new Dimension(200, 10); JLabel nameLabel; JPanel areaPanel; + Component rigidArea; JTextField locationXField; JTextField locationYField; @@ -86,6 +87,8 @@ public class PropertiesPanel extends JPanel //AREA PANEL: AVAILABLE FOR ACTIONLISTENER areaPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); areaPanel.setVisible(false); + rigidArea = Box.createRigidArea(spacerDimension); + rigidArea.setVisible(false); // BUTTONS ROW 1 JPanel row1ButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); @@ -105,6 +108,7 @@ public class PropertiesPanel extends JPanel public void actionPerformed(ActionEvent e) { areaPanel.setVisible(!areaPanel.isVisible()); + rigidArea.setVisible(!rigidArea.isVisible()); } }); row1ButtonPanel.setPreferredSize(new Dimension(200, 50)); @@ -113,23 +117,24 @@ public class PropertiesPanel extends JPanel row1ButtonPanel.add(areaButton); add(row1ButtonPanel); + add(rigidArea); //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.setPreferredSize(new Dimension(200, 180)); + areaPanel.setMaximumSize(new Dimension(200, 180)); areaPanel.add(areaLabel); add(areaPanel); { JPanel areaTopPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - areaTopPanel.setPreferredSize(new Dimension(200, 50)); + areaTopPanel.setPreferredSize(new Dimension(200, 30)); areaPanel.add(areaTopPanel); - JLabel areaTopLabel = new JLabel("Top"); + JLabel areaTopLabel = new JLabel("Top "); areaTopPanel.add(areaTopLabel); areaTopField = new JTextField(); - areaTopField.setPreferredSize(new Dimension(140, 25)); + areaTopField.setPreferredSize(new Dimension(120, 25)); { areaTopField.addKeyListener(new KeyListener() { @@ -157,7 +162,7 @@ public class PropertiesPanel extends JPanel } { JPanel areaBottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - areaBottomPanel.setPreferredSize(new Dimension(200, 50)); + areaBottomPanel.setPreferredSize(new Dimension(200, 30)); areaPanel.add(areaBottomPanel); JLabel areaBottomLabel = new JLabel("Bottom"); @@ -191,13 +196,13 @@ public class PropertiesPanel extends JPanel } { JPanel areaLeftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - areaLeftPanel.setPreferredSize(new Dimension(200, 50)); + areaLeftPanel.setPreferredSize(new Dimension(200, 30)); areaPanel.add(areaLeftPanel); - JLabel areaLeftLabel = new JLabel("Left"); + JLabel areaLeftLabel = new JLabel("Left "); areaLeftPanel.add(areaLeftLabel); areaLeftField = new JTextField(); - areaLeftField.setPreferredSize(new Dimension(138, 25)); + areaLeftField.setPreferredSize(new Dimension(120, 25)); { areaLeftField.addKeyListener(new KeyListener() { @@ -225,13 +230,13 @@ public class PropertiesPanel extends JPanel } { JPanel areaRightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - areaRightPanel.setPreferredSize(new Dimension(200, 50)); + areaRightPanel.setPreferredSize(new Dimension(200, 30)); areaPanel.add(areaRightPanel); - JLabel areaRightLabel = new JLabel("Right"); + JLabel areaRightLabel = new JLabel("Right "); areaRightPanel.add(areaRightLabel); areaRightField = new JTextField(); - areaRightField.setPreferredSize(new Dimension(130, 25)); + areaRightField.setPreferredSize(new Dimension(120, 25)); { areaRightField.addKeyListener(new KeyListener() { @@ -265,13 +270,13 @@ public class PropertiesPanel extends JPanel 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.setPreferredSize(new Dimension(200, 110)); + locationPanel.setMaximumSize(new Dimension(200, 110)); locationPanel.add(locationLabel); add(locationPanel); { JPanel locationXPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - locationXPanel.setPreferredSize(new Dimension(200, 50)); + locationXPanel.setPreferredSize(new Dimension(200, 30)); locationPanel.add(locationXPanel); JLabel locationXLabel = new JLabel("X"); @@ -309,7 +314,7 @@ public class PropertiesPanel extends JPanel } { JPanel locationYPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - locationYPanel.setPreferredSize(new Dimension(200, 50)); + locationYPanel.setPreferredSize(new Dimension(200, 30)); locationPanel.add(locationYPanel); JLabel locationYLabel = new JLabel("Y"); @@ -353,13 +358,13 @@ public class PropertiesPanel extends JPanel 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.setPreferredSize(new Dimension(200, 70)); + scalePanel.setMaximumSize(new Dimension(200, 70)); scalePanel.add(scaleLabel); add(scalePanel); { JPanel scalePanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - scalePanel2.setPreferredSize(new Dimension(200, 50)); + scalePanel2.setPreferredSize(new Dimension(200, 30)); scalePanel.add(scalePanel2); JLabel scale2Label = new JLabel(" "); @@ -400,13 +405,13 @@ public class PropertiesPanel extends JPanel 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.setPreferredSize(new Dimension(200, 80)); + rotationPanel.setMaximumSize(new Dimension(200, 80)); rotationPanel.add(rotationLabel); add(rotationPanel); { JPanel rotationPanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - rotationPanel2.setPreferredSize(new Dimension(200, 50)); + rotationPanel2.setPreferredSize(new Dimension(200, 30)); rotationPanel.add(rotationPanel2); JLabel rotation2Label = new JLabel(" "); @@ -510,6 +515,7 @@ public class PropertiesPanel extends JPanel nameLabel.setText("No Selection"); areaPanel.setVisible(false); + rigidArea.setVisible(false); } private void fillFields() diff --git a/Applicatie/Window.java b/Applicatie/Window.java index fda7174..fc26d6d 100644 --- a/Applicatie/Window.java +++ b/Applicatie/Window.java @@ -1,6 +1,7 @@ package Applicatie; import java.awt.BorderLayout; +import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; @@ -14,15 +15,19 @@ public class Window extends JFrame Window() { super("Festival Plannner"); setDefaultCloseOperation(EXIT_ON_CLOSE); - setSize(500, 600); + //setSize(500, 600); + setMinimumSize(new Dimension(1160, 680)); setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); // CONTENT PANELS JPanel contentPanel = new JPanel(new BorderLayout()); PropertiesPanel pp = new PropertiesPanel(); Panel fp = new Panel(pp); - contentPanel.add(fp, BorderLayout.CENTER); + ControlPanel cp = new ControlPanel(); + contentPanel.add(cp, BorderLayout.SOUTH); contentPanel.add(pp, BorderLayout.EAST); + contentPanel.add(fp, BorderLayout.CENTER); + addKeyListener(new Keyboard(fp)); setContentPane(contentPanel); From 050493a70bdcccf5bca68da4b9f63e23971351ff Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 7 Apr 2015 13:58:29 +0200 Subject: [PATCH 2/2] Try to fix camera zoom motion. Needs attention --- Applicatie/Panel.java | 1 + Listeners/MouseWheel.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Applicatie/Panel.java b/Applicatie/Panel.java index d92870d..7f25420 100644 --- a/Applicatie/Panel.java +++ b/Applicatie/Panel.java @@ -4,6 +4,7 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.MouseInfo; import java.awt.Point; import java.awt.TexturePaint; import java.awt.geom.AffineTransform; diff --git a/Listeners/MouseWheel.java b/Listeners/MouseWheel.java index 4f6fcea..b71ab7b 100644 --- a/Listeners/MouseWheel.java +++ b/Listeners/MouseWheel.java @@ -1,11 +1,11 @@ package Listeners; +import java.awt.Point; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.geom.Point2D; import Applicatie.Panel; -import Objects.DrawObject; public class MouseWheel implements MouseWheelListener { @@ -46,7 +46,13 @@ public class MouseWheel implements MouseWheelListener if (cameraScale >= 0.1 && cameraScale < 4) { panel.setCameraScale((float) cameraScale); - } + //panel.setCameraPoint(new Point2D.Double(e.getX()-(panel.getWidth()/2)-panel.getCameraPoint().getX(), e.getY()-(panel.getHeight()/2) - panel.getCameraPoint().getY())); + //panel.setCameraPoint( new Point2D.Double( + // -panel.getClickPoint(new Point(e.getX(), e.getY())).getX(), + // -panel.getClickPoint(new Point(e.getX(), e.getY())).getY() + // )); + //TODO FIX + } }