|
@@ -2,7 +2,6 @@ package ui.view;
|
|
|
|
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JFileChooser;
|
|
-import javax.swing.JFrame;
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
@@ -10,21 +9,19 @@ import javax.swing.ImageIcon;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
import org.eclipse.wb.swing.FocusTraversalOnArray;
|
|
import org.eclipse.wb.swing.FocusTraversalOnArray;
|
|
|
|
|
|
-import javafx.scene.image.Image;
|
|
|
|
-import javafx.stage.FileChooser;
|
|
|
|
|
|
+import classes.CpsUpperNode;
|
|
|
|
|
|
import java.awt.Component;
|
|
import java.awt.Component;
|
|
-import java.awt.Window;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionListener;
|
|
-import java.io.File;
|
|
|
|
|
|
+import java.awt.event.ComponentAdapter;
|
|
|
|
+import java.awt.event.ComponentEvent;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.BorderLayout;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JRadioButton;
|
|
import javax.swing.JRadioButton;
|
|
-import javax.swing.BoxLayout;
|
|
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.SwingConstants;
|
|
-import java.awt.FlowLayout;
|
|
|
|
-import java.awt.Choice;
|
|
|
|
|
|
+import java.awt.GridLayout;
|
|
|
|
+import java.awt.Color;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Popup for setting the Background Image for the current View.
|
|
* Popup for setting the Background Image for the current View.
|
|
@@ -45,20 +42,53 @@ public class BackgroundPopUp extends JDialog {
|
|
private final JButton btnOK = new JButton("OK");
|
|
private final JButton btnOK = new JButton("OK");
|
|
private final JLabel lblImage = new JLabel();
|
|
private final JLabel lblImage = new JLabel();
|
|
|
|
|
|
|
|
+ private ImageIcon icon = null;
|
|
private double imgScale = 1;
|
|
private double imgScale = 1;
|
|
|
|
+ private final JButton btnCancel = new JButton("Cancel");
|
|
|
|
+ private final JPanel panelRadio = new JPanel();
|
|
|
|
+ private final JRadioButton rdbtnImagePixel = new JRadioButton("Use Image Size");
|
|
|
|
+ private final JRadioButton rdbtnStretched = new JRadioButton("Strech Image");
|
|
|
|
+ private final JRadioButton rdbtnCustom = new JRadioButton("Custom Size");
|
|
|
|
|
|
- public BackgroundPopUp() {
|
|
|
|
|
|
+ // Modes
|
|
|
|
+ public static final int IMAGE_PIXELS = 0, STRETCHED = 1, CUSTOM = 2;
|
|
|
|
+ private int mode = 0;
|
|
|
|
+
|
|
|
|
+ public BackgroundPopUp(MyCanvas canvas, CpsUpperNode uNode) {
|
|
super((java.awt.Frame) null, true);
|
|
super((java.awt.Frame) null, true);
|
|
|
|
+ getContentPane().setBackground(Color.WHITE);
|
|
this.setTitle("Set View Background");
|
|
this.setTitle("Set View Background");
|
|
setBounds(100, 100, 400, 250);
|
|
setBounds(100, 100, 400, 250);
|
|
|
|
|
|
|
|
+ panelBrowse.setBorder(null);
|
|
|
|
+ panelImageRadio.setBorder(null);
|
|
|
|
+ panelOK.setBorder(null);
|
|
|
|
+ panelRadio.setBorder(null);
|
|
|
|
+
|
|
getContentPane().add(panelImageRadio, BorderLayout.CENTER);
|
|
getContentPane().add(panelImageRadio, BorderLayout.CENTER);
|
|
- panelImageRadio.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
|
|
- lblImage.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
|
|
+ panelImageRadio.setLayout(new BorderLayout(0, 0));
|
|
|
|
+ lblImage.setBackground(Color.WHITE);
|
|
|
|
+ lblImage.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
+
|
|
|
|
+ panelImageRadio.add(lblImage, BorderLayout.CENTER);
|
|
|
|
+
|
|
|
|
+ panelImageRadio.add(panelRadio, BorderLayout.EAST);
|
|
|
|
+ panelRadio.setLayout(new GridLayout(0, 1, 0, 0));
|
|
|
|
+ rdbtnImagePixel.setBackground(Color.WHITE);
|
|
|
|
+ rdbtnImagePixel.setSelected(true);
|
|
|
|
+
|
|
|
|
+ panelRadio.add(rdbtnImagePixel);
|
|
|
|
+ rdbtnStretched.setBackground(Color.WHITE);
|
|
|
|
+
|
|
|
|
+ panelRadio.add(rdbtnStretched);
|
|
|
|
+ rdbtnCustom.setBackground(Color.WHITE);
|
|
|
|
+
|
|
|
|
+ panelRadio.add(rdbtnCustom);
|
|
|
|
+ panelBrowse.setBackground(Color.WHITE);
|
|
|
|
|
|
- panelImageRadio.add(lblImage);
|
|
|
|
getContentPane().add(panelBrowse, BorderLayout.NORTH);
|
|
getContentPane().add(panelBrowse, BorderLayout.NORTH);
|
|
- panelBrowse.add(btnBrowse);
|
|
|
|
|
|
+ panelBrowse.setLayout(new BorderLayout(0, 0));
|
|
|
|
+ panelBrowse.add(btnBrowse, BorderLayout.WEST);
|
|
|
|
|
|
// Browse Row Functions
|
|
// Browse Row Functions
|
|
btnBrowse.addActionListener(new ActionListener() {
|
|
btnBrowse.addActionListener(new ActionListener() {
|
|
@@ -68,26 +98,77 @@ public class BackgroundPopUp extends JDialog {
|
|
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) {
|
|
- textPath.setText(fileChooser.getSelectedFile().getPath());
|
|
|
|
- ImageIcon icon = new ImageIcon(textPath.getText());
|
|
|
|
- imgScale = Math.max(icon.getIconWidth(), icon.getIconHeight()) / 200;
|
|
|
|
- lblImage.setIcon(new ImageIcon(new ImageIcon(textPath.getText()).getImage().getScaledInstance(
|
|
|
|
|
|
+ path = fileChooser.getSelectedFile().getPath();
|
|
|
|
+ textPath.setText(path);
|
|
|
|
+ icon = new ImageIcon(textPath.getText());
|
|
|
|
+
|
|
|
|
+ // Calculate the Image scale to fit the Panel
|
|
|
|
+ if (Math.min(panelImageRadio.getWidth() - panelRadio.getWidth(),
|
|
|
|
+ panelImageRadio.getHeight()) == (panelImageRadio.getWidth() - panelRadio.getWidth())) {
|
|
|
|
+ imgScale = (double) Math.min(icon.getIconWidth(), icon.getIconHeight())
|
|
|
|
+ / panelImageRadio.getWidth();
|
|
|
|
+ } else {
|
|
|
|
+ imgScale = (double) Math.min(icon.getIconWidth(), icon.getIconHeight())
|
|
|
|
+ / panelImageRadio.getHeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ lblImage.setIcon(new ImageIcon(new ImageIcon(path).getImage().getScaledInstance(
|
|
(int) (icon.getIconWidth() / imgScale), (int) (icon.getIconHeight() / imgScale),
|
|
(int) (icon.getIconWidth() / imgScale), (int) (icon.getIconHeight() / imgScale),
|
|
- java.awt.Image.SCALE_SMOOTH)));
|
|
|
|
|
|
+ java.awt.Image.SCALE_FAST)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
textPath.setEditable(false);
|
|
textPath.setEditable(false);
|
|
|
|
|
|
- panelBrowse.add(textPath);
|
|
|
|
|
|
+ panelBrowse.add(textPath, BorderLayout.CENTER);
|
|
textPath.setColumns(20);
|
|
textPath.setColumns(20);
|
|
panelImageRadio.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { btnBrowse, textPath }));
|
|
panelImageRadio.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { btnBrowse, textPath }));
|
|
|
|
+ panelOK.setBackground(Color.WHITE);
|
|
|
|
|
|
getContentPane().add(panelOK, BorderLayout.SOUTH);
|
|
getContentPane().add(panelOK, BorderLayout.SOUTH);
|
|
-
|
|
|
|
panelOK.add(btnOK);
|
|
panelOK.add(btnOK);
|
|
|
|
+ btnOK.addActionListener(new ActionListener() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ if (canvas != null) {
|
|
|
|
+ canvas.setBackgroundImage(path, mode, icon.getIconWidth(), icon.getIconHeight());
|
|
|
|
+ canvas.repaint();
|
|
|
|
+ } else if (uNode != null) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ dispose();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ panelOK.add(btnCancel);
|
|
|
|
+ btnCancel.addActionListener(new ActionListener() {
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ dispose();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ this.addComponentListener(new ComponentAdapter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void componentResized(ComponentEvent e) {
|
|
|
|
+ if (icon != null) {
|
|
|
|
+ // Calculate the Image scale to fit the Panel
|
|
|
|
+ if (Math.min(panelImageRadio.getWidth() - panelRadio.getWidth(),
|
|
|
|
+ panelImageRadio.getHeight()) == (panelImageRadio.getWidth() - panelRadio.getWidth())) {
|
|
|
|
+ imgScale = (double) Math.min(icon.getIconWidth(), icon.getIconHeight())
|
|
|
|
+ / panelImageRadio.getWidth();
|
|
|
|
+ } else {
|
|
|
|
+ imgScale = (double) Math.min(icon.getIconWidth(), icon.getIconHeight())
|
|
|
|
+ / panelImageRadio.getHeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ lblImage.setIcon(new ImageIcon(new ImageIcon(path).getImage().getScaledInstance(
|
|
|
|
+ (int) (icon.getIconWidth() / imgScale), (int) (icon.getIconHeight() / imgScale),
|
|
|
|
+ java.awt.Image.SCALE_SMOOTH)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|