|
@@ -8,8 +8,6 @@ import java.awt.Color;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JTabbedPane;
|
|
|
|
|
|
-import java.awt.Toolkit;
|
|
|
-
|
|
|
import javax.swing.JTextField;
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
@@ -23,7 +21,7 @@ import java.awt.Insets;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
/**
|
|
|
- * PopUp for Creation of SmartDevices, which allos configuration of a new SmartDevice
|
|
|
+ * PopUp for Creation of SmartDevices, which allows configuration of a new SmartDevice
|
|
|
*
|
|
|
* @author Andreas T. Meyer-Berg
|
|
|
*/
|
|
@@ -52,6 +50,18 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
* Visualisation Panel which visualizes the Model
|
|
|
*/
|
|
|
private VisualisationPanel p;
|
|
|
+ /**
|
|
|
+ * Width of the model, which is the maximum x-Position
|
|
|
+ */
|
|
|
+ private int maxX;
|
|
|
+ /**
|
|
|
+ * Height of the model, which is the maximum y-Position
|
|
|
+ */
|
|
|
+ private int maxY;
|
|
|
+ /**
|
|
|
+ * Visualization radius of SmartDevices which
|
|
|
+ */
|
|
|
+ private int visualisationRadius;
|
|
|
/**
|
|
|
* Creates a new SmartDeviceCreationPopUp
|
|
|
* @param currentX default xPosition of the new SmartDevice
|
|
@@ -64,13 +74,15 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
*/
|
|
|
public SmartDeviceCreationPopUp(int currentX, int currentY, int maxX, int maxY, int visualisationRadius, Controller c, VisualisationPanel panel) {
|
|
|
setModal(true);
|
|
|
- setType(Type.POPUP);
|
|
|
+ //setType(Type.POPUP); -> Crashes on Linux
|
|
|
this.c = c;
|
|
|
this.p = panel;
|
|
|
+ this.maxX = maxX;
|
|
|
+ this.maxY = maxY;
|
|
|
|
|
|
setSize(640, 480);
|
|
|
setResizable(false);
|
|
|
- setIconImage(Toolkit.getDefaultToolkit().getImage(SmartDeviceCreationPopUp.class.getResource("/javax/swing/plaf/metal/icons/ocean/computer.gif")));
|
|
|
+ //setIconImage(Toolkit.getDefaultToolkit().getImage(SmartDeviceCreationPopUp.class.getResource("/javax/swing/plaf/metal/icons/ocean/computer.gif")));
|
|
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
setTitle("SmartDevice Configuration Panel");
|
|
|
|
|
@@ -94,15 +106,15 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
gbc_lblName.gridy = 0;
|
|
|
panelGeneral.add(lblName, gbc_lblName);
|
|
|
|
|
|
- tfName = new JTextField();
|
|
|
- GridBagConstraints gbc_tfName = new GridBagConstraints();
|
|
|
- gbc_tfName.anchor = GridBagConstraints.NORTHWEST;
|
|
|
- gbc_tfName.insets = new Insets(0, 0, 5, 0);
|
|
|
- gbc_tfName.gridx = 1;
|
|
|
- gbc_tfName.gridy = 0;
|
|
|
- panelGeneral.add(tfName, gbc_tfName);
|
|
|
- tfName.setColumns(20);
|
|
|
- tfName.setText("SmartDevice name");
|
|
|
+ tfName = new JTextField();
|
|
|
+ GridBagConstraints gbc_tfName = new GridBagConstraints();
|
|
|
+ gbc_tfName.anchor = GridBagConstraints.NORTHWEST;
|
|
|
+ gbc_tfName.insets = new Insets(0, 0, 5, 0);
|
|
|
+ gbc_tfName.gridx = 1;
|
|
|
+ gbc_tfName.gridy = 0;
|
|
|
+ panelGeneral.add(tfName, gbc_tfName);
|
|
|
+ tfName.setColumns(20);
|
|
|
+ tfName.setText("SmartDevice name");
|
|
|
|
|
|
JLabel lblXposition = new JLabel("x-position: ["+visualisationRadius+","+(maxX-visualisationRadius)+"]");
|
|
|
GridBagConstraints gbc_lblXposition = new GridBagConstraints();
|
|
@@ -184,7 +196,7 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
*/
|
|
|
int x = Integer.parseInt(tfXposition.getText());
|
|
|
//filter invalid positions
|
|
|
- if(x<p.getVisualisationRadius()||p.getWidth()-p.getVisualisationRadius()<x)
|
|
|
+ if(x<visualisationRadius||maxX-visualisationRadius<x)
|
|
|
throw new NumberFormatException("Number not in bounds");
|
|
|
newDevice.setX(x);
|
|
|
tfXposition.setBackground(Color.WHITE);
|
|
@@ -198,7 +210,7 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
*/
|
|
|
int y = Integer.parseInt(tfYposition.getText());
|
|
|
//filter invalid positions
|
|
|
- if(y<p.getVisualisationRadius()||p.getWidth()-p.getVisualisationRadius()<y)
|
|
|
+ if(y<visualisationRadius||maxY-visualisationRadius<y)
|
|
|
throw new NumberFormatException("Number not in bounds");
|
|
|
newDevice.setY(y);
|
|
|
tfYposition.setBackground(Color.WHITE);
|
|
@@ -207,7 +219,7 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
tfYposition.setBackground(Color.RED);
|
|
|
}
|
|
|
if(valid){
|
|
|
- //Add new Device, update Visualisation and dispose the PopUp
|
|
|
+ //Add new Device, update Visualization and dispose the PopUp
|
|
|
c.addSmartDevice(newDevice);
|
|
|
p.repaint();
|
|
|
this.setVisible(false);
|