|
@@ -17,8 +17,15 @@ import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ComponentAdapter;
|
|
import java.awt.event.ComponentAdapter;
|
|
import java.awt.event.ComponentEvent;
|
|
import java.awt.event.ComponentEvent;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.OutputStream;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.BorderLayout;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
|
|
+import javax.swing.JOptionPane;
|
|
import javax.swing.JRadioButton;
|
|
import javax.swing.JRadioButton;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.SwingConstants;
|
|
import java.awt.GridLayout;
|
|
import java.awt.GridLayout;
|
|
@@ -59,6 +66,8 @@ public class BackgroundPopUp extends JDialog {
|
|
private final JTextField imageWidth = new JTextField();
|
|
private final JTextField imageWidth = new JTextField();
|
|
private final JTextField imageHeight = new JTextField();
|
|
private final JTextField imageHeight = new JTextField();
|
|
|
|
|
|
|
|
+ JFileChooser fileChooser;
|
|
|
|
+
|
|
public BackgroundPopUp(MyCanvas canvas, CpsUpperNode uNode) {
|
|
public BackgroundPopUp(MyCanvas canvas, CpsUpperNode uNode) {
|
|
super((java.awt.Frame) null, true);
|
|
super((java.awt.Frame) null, true);
|
|
getContentPane().setBackground(Color.WHITE);
|
|
getContentPane().setBackground(Color.WHITE);
|
|
@@ -115,16 +124,16 @@ public class BackgroundPopUp extends JDialog {
|
|
btnBrowse.addActionListener(new ActionListener() {
|
|
btnBrowse.addActionListener(new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
- JFileChooser fileChooser = new JFileChooser();
|
|
|
|
|
|
+ fileChooser = new JFileChooser();
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
fileChooser.setFileFilter(filter);
|
|
fileChooser.setFileFilter(filter);
|
|
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
|
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
|
path = fileChooser.getSelectedFile().getPath();
|
|
path = fileChooser.getSelectedFile().getPath();
|
|
textPath.setText(path);
|
|
textPath.setText(path);
|
|
icon = new ImageIcon(textPath.getText());
|
|
icon = new ImageIcon(textPath.getText());
|
|
- imageWidth.setText(""+icon.getIconWidth());
|
|
|
|
- imageHeight.setText(""+icon.getIconHeight());
|
|
|
|
-
|
|
|
|
|
|
+ imageWidth.setText("" + icon.getIconWidth());
|
|
|
|
+ imageHeight.setText("" + icon.getIconHeight());
|
|
|
|
+
|
|
// Calculate the Image scale to fit the Panel
|
|
// Calculate the Image scale to fit the Panel
|
|
if (Math.min(panelImageRadio.getWidth() - panelRadio.getWidth(),
|
|
if (Math.min(panelImageRadio.getWidth() - panelRadio.getWidth(),
|
|
panelImageRadio.getHeight()) == (panelImageRadio.getWidth() - panelRadio.getWidth())) {
|
|
panelImageRadio.getHeight()) == (panelImageRadio.getWidth() - panelRadio.getWidth())) {
|
|
@@ -154,21 +163,33 @@ public class BackgroundPopUp extends JDialog {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
- if (rdbtnImagePixel.isSelected()) {
|
|
|
|
- mode = 0;
|
|
|
|
- } else if (rdbtnStretched.isSelected()) {
|
|
|
|
- mode = 1;
|
|
|
|
- } else if (rdbtnCustom.isSelected()) {
|
|
|
|
- mode = 2;
|
|
|
|
- }
|
|
|
|
|
|
+ //Bild ausgewählt?
|
|
|
|
+ if (!path.isEmpty()) {
|
|
|
|
+ if (rdbtnImagePixel.isSelected()) {
|
|
|
|
+ mode = 0;
|
|
|
|
+ } else if (rdbtnStretched.isSelected()) {
|
|
|
|
+ mode = 1;
|
|
|
|
+ } else if (rdbtnCustom.isSelected()) {
|
|
|
|
+ mode = 2;
|
|
|
|
+ }
|
|
|
|
|
|
- if (canvas != null) {
|
|
|
|
- canvas.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()), Integer.parseInt(imageHeight.getText()));
|
|
|
|
- canvas.repaint();
|
|
|
|
- } else if (uNode != null) {
|
|
|
|
- uNode.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()), Integer.parseInt(imageHeight.getText()));
|
|
|
|
|
|
+ if (canvas != null) {
|
|
|
|
+ copieImage();
|
|
|
|
+ canvas.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()),
|
|
|
|
+ Integer.parseInt(imageHeight.getText()));
|
|
|
|
+ canvas.repaint();
|
|
|
|
+ } else if (uNode != null) {
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
- dispose();
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -202,4 +223,32 @@ public class BackgroundPopUp extends JDialog {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ protected void copieImage() {
|
|
|
|
+ InputStream inStream = null;
|
|
|
|
+ OutputStream outStream = null;
|
|
|
|
+ try {
|
|
|
|
+ File source = new File(path);
|
|
|
|
+ File dest = new File(System.getProperty("user.home") + "/HolonGUI/Images/");
|
|
|
|
+ dest.mkdirs();
|
|
|
|
+ dest = new File(dest, source.getName());
|
|
|
|
+ path = "" + dest;
|
|
|
|
+
|
|
|
|
+ inStream = new FileInputStream(source);
|
|
|
|
+ outStream = new FileOutputStream(dest);
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+
|
|
|
|
+ int length;
|
|
|
|
+ while ((length = inStream.read(buffer)) > 0) {
|
|
|
|
+ outStream.write(buffer, 0, length);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (inStream != null)
|
|
|
|
+ inStream.close();
|
|
|
|
+ if (outStream != null)
|
|
|
|
+ outStream.close();
|
|
|
|
+
|
|
|
|
+ } catch (IOException eex) {
|
|
|
|
+ eex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|