succesfully merged Banaan

This commit is contained in:
Yorick
2015-03-16 22:21:52 +01:00
6 changed files with 417 additions and 234 deletions
+76 -49
View File
@@ -27,18 +27,16 @@ public class PropertiesPanel extends JPanel {
JTextField scaleField;
JTextField rotationField;
PropertiesPanel()
{
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)));
setPreferredSize(new Dimension(200, 0));
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
setBackground(new Color(220, 220, 220));
//NAME "PROPERTIES"
// NAME "PROPERTIES"
JPanel propPanel = new JPanel();
JLabel propLabel = new JLabel("Properties");
propLabel.setFont(new Font("Segoe UI", Font.BOLD, 30));
@@ -47,8 +45,7 @@ public class PropertiesPanel extends JPanel {
propPanel.add(propLabel);
add(propPanel);
//LOCATION
// LOCATION
JPanel locationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel locationLabel = new JLabel("Location");
locationLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
@@ -69,17 +66,25 @@ public class PropertiesPanel extends JPanel {
locationXField.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
try{
try {
locationXField.setBackground(Color.WHITE);
double xpos = Double.parseDouble(locationXField.getText());
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()));
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) {
}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
});
}
locationXPanel.add(locationXField);
@@ -97,24 +102,32 @@ public class PropertiesPanel extends JPanel {
locationYField.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
try{
try {
locationYField.setBackground(Color.WHITE);
double ypos = Double.parseDouble(locationYField.getText());
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos));;
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) {}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
}
});
}
locationYPanel.add(locationYField);
}
//SCALE
// SCALE
JPanel scalePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel scaleLabel = new JLabel("Scale");
scaleLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
@@ -135,24 +148,30 @@ public class PropertiesPanel extends JPanel {
scaleField.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
try{
try {
scaleField.setBackground(Color.WHITE);
double scale = Double.parseDouble(scaleField.getText());
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) {
}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
});
}
scalePanel2.add(scaleField);
}
//ROTATION
// ROTATION
JPanel rotationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel rotationLabel = new JLabel("Rotation");
rotationLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
@@ -173,31 +192,38 @@ public class PropertiesPanel extends JPanel {
rotationField.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
try{
try {
rotationField.setBackground(Color.WHITE);
int rotation = Integer.parseInt(rotationField.getText()) % 360;
rotationField.setText(rotation +"");
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) {
}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
});
}
rotationPanel2.add(rotationField);
}
//SPACER
// 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
// EXAMPLE
JPanel examplePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel exampleLabel = new JLabel("Example");
exampleLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
@@ -209,16 +235,13 @@ public class PropertiesPanel extends JPanel {
enableComponents(this, false);
}
public void setSelected(DrawObject drOb)
{
public void setSelected(DrawObject drOb) {
selectedObject = drOb;
fillFields();
enableComponents(this, true);
}
public void clearSelected()
{
public void clearSelected() {
enableComponents(this, false);
clearFields(this);
selectedObject = null;
@@ -233,7 +256,7 @@ public class PropertiesPanel extends JPanel {
for (Component component : components) {
component.setEnabled(enable);
if (component instanceof Container) {
enableComponents((Container)component, enable);
enableComponents((Container) component, enable);
}
}
}
@@ -245,24 +268,28 @@ public class PropertiesPanel extends JPanel {
((JTextField) component).setText("");
}
if (component instanceof Container) {
clearFields((Container)component);
clearFields((Container) component);
}
}
}
private void fillFields() {
if(selectedObject != null)
{
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) + "");
if (selectedObject != null) {
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)
{
public void setPanel(Panel p) {
this.p = p;
}
}