|
@@ -29,6 +29,7 @@ import javax.swing.JOptionPane;
|
|
|
import javax.swing.JRadioButton;
|
|
|
import javax.swing.SwingConstants;
|
|
|
import java.awt.GridLayout;
|
|
|
+import java.awt.Image;
|
|
|
import java.awt.Color;
|
|
|
import java.awt.FlowLayout;
|
|
|
|
|
@@ -51,6 +52,7 @@ public class BackgroundPopUp extends JDialog {
|
|
|
private final JButton btnOK = new JButton("OK");
|
|
|
private final JLabel lblImage = new JLabel();
|
|
|
|
|
|
+ private boolean imageChanged = false;
|
|
|
private ImageIcon icon = null;
|
|
|
private double imgScale = 1;
|
|
|
private final JButton btnCancel = new JButton("Cancel");
|
|
@@ -62,6 +64,7 @@ public class BackgroundPopUp extends JDialog {
|
|
|
// Modes
|
|
|
public static final int IMAGE_PIXELS = 0, STRETCHED = 1, CUSTOM = 2;
|
|
|
private int mode = 0;
|
|
|
+
|
|
|
private final JPanel panel = new JPanel();
|
|
|
private final JTextField imageWidth = new JTextField();
|
|
|
private final JTextField imageHeight = new JTextField();
|
|
@@ -72,6 +75,20 @@ public class BackgroundPopUp extends JDialog {
|
|
|
super((java.awt.Frame) null, true);
|
|
|
getContentPane().setBackground(Color.WHITE);
|
|
|
this.setTitle("Set View Background");
|
|
|
+ // Show background Image
|
|
|
+ if (canvas != null) {
|
|
|
+ path = canvas.getBackgroundPath();
|
|
|
+ } else if (uNode != null) {
|
|
|
+ path = uNode.getImagePath();
|
|
|
+ }
|
|
|
+ if (!path.isEmpty()) {
|
|
|
+ textPath.setText(path);
|
|
|
+ icon = new ImageIcon(path);
|
|
|
+ imageWidth.setText("" + icon.getIconWidth());
|
|
|
+ imageHeight.setText("" + icon.getIconHeight());
|
|
|
+ }
|
|
|
+ this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
|
|
|
+ .getScaledInstance(30, 30, Image.SCALE_SMOOTH));
|
|
|
setBounds(100, 100, 600, 340);
|
|
|
|
|
|
panelBrowse.setBorder(null);
|
|
@@ -134,6 +151,8 @@ public class BackgroundPopUp extends JDialog {
|
|
|
imageWidth.setText("" + icon.getIconWidth());
|
|
|
imageHeight.setText("" + icon.getIconHeight());
|
|
|
|
|
|
+ imageChanged = true;
|
|
|
+
|
|
|
// Calculate the Image scale to fit the Panel
|
|
|
if (Math.min(panelImageRadio.getWidth() - panelRadio.getWidth(),
|
|
|
panelImageRadio.getHeight()) == (panelImageRadio.getWidth() - panelRadio.getWidth())) {
|
|
@@ -163,7 +182,7 @@ public class BackgroundPopUp extends JDialog {
|
|
|
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
- //Bild ausgewählt?
|
|
|
+ // Bild ausgewählt?
|
|
|
if (!path.isEmpty()) {
|
|
|
if (rdbtnImagePixel.isSelected()) {
|
|
|
mode = 0;
|
|
@@ -174,21 +193,22 @@ public class BackgroundPopUp extends JDialog {
|
|
|
}
|
|
|
|
|
|
if (canvas != null) {
|
|
|
- copieImage();
|
|
|
+ if (imageChanged) {
|
|
|
+ copieImage();
|
|
|
+ }
|
|
|
canvas.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()),
|
|
|
Integer.parseInt(imageHeight.getText()));
|
|
|
canvas.repaint();
|
|
|
} else if (uNode != null) {
|
|
|
- copieImage();
|
|
|
+ if (imageChanged) {
|
|
|
+ copieImage();
|
|
|
+ }
|
|
|
uNode.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()),
|
|
|
Integer.parseInt(imageHeight.getText()));
|
|
|
}
|
|
|
dispose();
|
|
|
} else {
|
|
|
- JOptionPane.showMessageDialog(null,
|
|
|
- "No image selected!",
|
|
|
- "Warning!",
|
|
|
- JOptionPane.WARNING_MESSAGE);
|
|
|
+ JOptionPane.showMessageDialog(null, "No image selected!", "Warning!", JOptionPane.WARNING_MESSAGE);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -246,7 +266,7 @@ public class BackgroundPopUp extends JDialog {
|
|
|
inStream.close();
|
|
|
if (outStream != null)
|
|
|
outStream.close();
|
|
|
-
|
|
|
+
|
|
|
} catch (IOException eex) {
|
|
|
eex.printStackTrace();
|
|
|
}
|