Succesful merge but with nullpointerexceptions
@@ -24,6 +24,7 @@ import Objects.Podium;
|
||||
import Objects.Toilet;
|
||||
import Objects.Wall;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Panel extends JPanel {
|
||||
|
||||
BufferedImage background;
|
||||
@@ -40,6 +41,8 @@ public class Panel extends JPanel {
|
||||
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);
|
||||
@@ -48,8 +51,11 @@ public class Panel extends JPanel {
|
||||
//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()
|
||||
|
||||
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"));
|
||||
@@ -272,5 +278,14 @@ public class Panel extends JPanel {
|
||||
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
|
||||
|
||||
@@ -53,8 +53,15 @@ public class Mouse extends MouseAdapter {
|
||||
else
|
||||
{
|
||||
for(DrawObject o : panel.getObjects())
|
||||
{
|
||||
if(o.contains(clickPoint))
|
||||
{
|
||||
panel.setDragObject(o);
|
||||
panel.getPP().setSelected(o);
|
||||
return;
|
||||
}
|
||||
}
|
||||
panel.getPP().clearSelected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,5 +48,6 @@ public class MouseMotion extends MouseMotionAdapter {
|
||||
}
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.getPP().update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class MouseWheel implements MouseWheelListener {
|
||||
{
|
||||
double scale = o.getScale()* 1 + (e.getPreciseWheelRotation()/10.0);
|
||||
o.setScale(scale);
|
||||
panel.getPP().update();
|
||||
panel.repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 972 B |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 494 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 737 B |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |