|
@@ -0,0 +1,93 @@
|
|
|
|
+package ui.view;
|
|
|
|
+
|
|
|
|
+import javax.swing.JDialog;
|
|
|
|
+import javax.swing.JFileChooser;
|
|
|
|
+import javax.swing.JFrame;
|
|
|
|
+import javax.swing.JPanel;
|
|
|
|
+import javax.swing.JTextField;
|
|
|
|
+import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
+import javax.swing.ImageIcon;
|
|
|
|
+import javax.swing.JButton;
|
|
|
|
+import org.eclipse.wb.swing.FocusTraversalOnArray;
|
|
|
|
+
|
|
|
|
+import javafx.scene.image.Image;
|
|
|
|
+import javafx.stage.FileChooser;
|
|
|
|
+
|
|
|
|
+import java.awt.Component;
|
|
|
|
+import java.awt.Window;
|
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
|
+import java.awt.event.ActionListener;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.awt.BorderLayout;
|
|
|
|
+import javax.swing.JLabel;
|
|
|
|
+import javax.swing.JRadioButton;
|
|
|
|
+import javax.swing.BoxLayout;
|
|
|
|
+import javax.swing.SwingConstants;
|
|
|
|
+import java.awt.FlowLayout;
|
|
|
|
+import java.awt.Choice;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Popup for setting the Background Image for the current View.
|
|
|
|
+ **/
|
|
|
|
+public class BackgroundPopUp extends JDialog {
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
+ private final JTextField textPath = new JTextField("");
|
|
|
|
+ private final JButton btnBrowse = new JButton("Browse");
|
|
|
|
+ private JPanel panelImageRadio = new JPanel();
|
|
|
|
+
|
|
|
|
+ private String path = "";
|
|
|
|
+ private final JPanel panelBrowse = new JPanel();
|
|
|
|
+ private final JPanel panelOK = new JPanel();
|
|
|
|
+ private final JButton btnOK = new JButton("OK");
|
|
|
|
+ private final JLabel lblImage = new JLabel();
|
|
|
|
+
|
|
|
|
+ private double imgScale = 1;
|
|
|
|
+
|
|
|
|
+ public BackgroundPopUp() {
|
|
|
|
+ super((java.awt.Frame) null, true);
|
|
|
|
+ this.setTitle("Set View Background");
|
|
|
|
+ setBounds(100, 100, 400, 250);
|
|
|
|
+
|
|
|
|
+ getContentPane().add(panelImageRadio, BorderLayout.CENTER);
|
|
|
|
+ panelImageRadio.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
|
|
+ lblImage.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
+
|
|
|
|
+ panelImageRadio.add(lblImage);
|
|
|
|
+ getContentPane().add(panelBrowse, BorderLayout.NORTH);
|
|
|
|
+ panelBrowse.add(btnBrowse);
|
|
|
|
+
|
|
|
|
+ // Browse Row Functions
|
|
|
|
+ btnBrowse.addActionListener(new ActionListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
|
+ FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
|
|
+ fileChooser.setFileFilter(filter);
|
|
|
|
+ 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(
|
|
|
|
+ (int) (icon.getIconWidth() / imgScale), (int) (icon.getIconHeight() / imgScale),
|
|
|
|
+ java.awt.Image.SCALE_SMOOTH)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ textPath.setEditable(false);
|
|
|
|
+
|
|
|
|
+ panelBrowse.add(textPath);
|
|
|
|
+ textPath.setColumns(20);
|
|
|
|
+ panelImageRadio.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { btnBrowse, textPath }));
|
|
|
|
+
|
|
|
|
+ getContentPane().add(panelOK, BorderLayout.SOUTH);
|
|
|
|
+
|
|
|
|
+ panelOK.add(btnOK);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|