This commit is contained in:
Yorick
2015-03-17 13:39:16 +01:00
13 changed files with 231 additions and 164 deletions
+105 -80
View File
@@ -21,7 +21,8 @@ import javax.swing.JPanel;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class PropertiesPanel extends JPanel {
public class PropertiesPanel extends JPanel
{
DrawObject selectedObject = null;
Panel p = null;
@@ -35,7 +36,8 @@ public class PropertiesPanel extends JPanel {
JTextField scaleField;
JTextField rotationField;
PropertiesPanel() {
PropertiesPanel()
{
super();
BoxLayout box = new BoxLayout(this, BoxLayout.PAGE_AXIS);
setLayout(box);
@@ -78,8 +80,10 @@ public class PropertiesPanel extends JPanel {
JPanel deletePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton deleteButton = new JButton("Delete");
deleteButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p.removeObject(selectedObject);
}
});
@@ -109,27 +113,30 @@ public class PropertiesPanel extends JPanel {
locationXField = new JTextField();
locationXField.setPreferredSize(new Dimension(150, 25));
{
locationXField.addKeyListener(new KeyListener() {
locationXField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e) {
public void keyTyped(KeyEvent e)
{
}
public void keyReleased(KeyEvent e) {
try {
public void keyReleased(KeyEvent e)
{
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) {
} catch (NumberFormatException nfe)
{
locationXField.setBackground(Color.RED);
}
}
public void keyPressed(KeyEvent e) {
public void keyPressed(KeyEvent e)
{
}
});
}
locationXPanel.add(locationXField);
@@ -144,28 +151,32 @@ public class PropertiesPanel extends JPanel {
locationYField = new JTextField();
locationYField.setPreferredSize(new Dimension(150, 25));
{
locationYField.addKeyListener(new KeyListener() {
locationYField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e) {
try {
public void keyTyped(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
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) {
} catch (NumberFormatException nfe)
{
locationYField.setBackground(Color.RED);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
public void keyPressed(KeyEvent e)
{
}
});
}
@@ -190,26 +201,29 @@ public class PropertiesPanel extends JPanel {
scaleField = new JTextField();
scaleField.setPreferredSize(new Dimension(150, 25));
{
scaleField.addKeyListener(new KeyListener() {
scaleField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e) {
public void keyTyped(KeyEvent e)
{
}
try {
public void keyReleased(KeyEvent e)
{
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) {
} catch (NumberFormatException nfe)
{
scaleField.setBackground(Color.RED);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
public void keyPressed(KeyEvent e)
{
}
});
}
@@ -234,27 +248,30 @@ public class PropertiesPanel extends JPanel {
rotationField = new JTextField();
rotationField.setPreferredSize(new Dimension(150, 25));
{
rotationField.addKeyListener(new KeyListener() {
rotationField.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e) {
public void keyTyped(KeyEvent e)
{
}
try {
public void keyReleased(KeyEvent e)
{
try
{
rotationField.setBackground(Color.WHITE);
int rotation = Integer.parseInt(rotationField
.getText()) % 360;
int rotation = Integer.parseInt(rotationField.getText()) % 360;
rotationField.setText(rotation + "");
selectedObject.setRotation(rotation);
p.update();
} catch (NumberFormatException nfe) {
} catch (NumberFormatException nfe)
{
rotationField.setBackground(Color.RED);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
public void keyPressed(KeyEvent e)
{
}
});
}
@@ -264,53 +281,63 @@ public class PropertiesPanel extends JPanel {
// SPACER
add(Box.createRigidArea(spacerDimension));
// 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);
// AGENDA
JPanel agendaPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel agendaLabel = new JLabel("Agenda");
agendaLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
agendaPanel.setPreferredSize(new Dimension(200, 100));
agendaPanel.setMaximumSize(new Dimension(200, 100));
agendaPanel.add(agendaLabel);
add(agendaPanel);
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;
}
public void update() {
public void update()
{
fillFields();
}
private void enableComponents(Container container, boolean enable) {
private void enableComponents(Container container, boolean enable)
{
Component[] components = container.getComponents();
for (Component component : components) {
for (Component component : components)
{
component.setEnabled(enable);
if (component instanceof Container) {
if (component instanceof Container)
{
enableComponents((Container) component, enable);
}
}
}
private void clearFields(Container container) {
private void clearFields(Container container)
{
Component[] components = container.getComponents();
for (Component component : components) {
if (component instanceof JTextField) {
for (Component component : components)
{
if (component instanceof JTextField)
{
((JTextField) component).setText("");
((JTextField) component).setBackground(Color.WHITE);
}
if (component instanceof Container) {
if (component instanceof Container)
{
clearFields((Container) component);
}
}
@@ -319,25 +346,23 @@ public class PropertiesPanel extends JPanel {
}
private void fillFields() {
if (selectedObject != null) {
private void fillFields()
{
if (selectedObject != null)
{
nameLabel.setText(selectedObject.getName());
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)
+ "");
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;
}
}