|
@@ -5,6 +5,7 @@ import javax.swing.JFileChooser;
|
|
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;
|
|
|
|
+import javax.swing.ButtonGroup;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
import org.eclipse.wb.swing.FocusTraversalOnArray;
|
|
import org.eclipse.wb.swing.FocusTraversalOnArray;
|
|
@@ -22,6 +23,7 @@ import javax.swing.JRadioButton;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.SwingConstants;
|
|
import java.awt.GridLayout;
|
|
import java.awt.GridLayout;
|
|
import java.awt.Color;
|
|
import java.awt.Color;
|
|
|
|
+import java.awt.FlowLayout;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Popup for setting the Background Image for the current View.
|
|
* Popup for setting the Background Image for the current View.
|
|
@@ -53,12 +55,15 @@ public class BackgroundPopUp extends JDialog {
|
|
// Modes
|
|
// Modes
|
|
public static final int IMAGE_PIXELS = 0, STRETCHED = 1, CUSTOM = 2;
|
|
public static final int IMAGE_PIXELS = 0, STRETCHED = 1, CUSTOM = 2;
|
|
private int mode = 0;
|
|
private int mode = 0;
|
|
|
|
+ private final JPanel panel = new JPanel();
|
|
|
|
+ private final JTextField imageWidth = new JTextField();
|
|
|
|
+ private final JTextField imageHeight = new JTextField();
|
|
|
|
|
|
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);
|
|
this.setTitle("Set View Background");
|
|
this.setTitle("Set View Background");
|
|
- setBounds(100, 100, 400, 250);
|
|
|
|
|
|
+ setBounds(100, 100, 600, 340);
|
|
|
|
|
|
panelBrowse.setBorder(null);
|
|
panelBrowse.setBorder(null);
|
|
panelImageRadio.setBorder(null);
|
|
panelImageRadio.setBorder(null);
|
|
@@ -73,7 +78,10 @@ public class BackgroundPopUp extends JDialog {
|
|
panelImageRadio.add(lblImage, BorderLayout.CENTER);
|
|
panelImageRadio.add(lblImage, BorderLayout.CENTER);
|
|
|
|
|
|
panelImageRadio.add(panelRadio, BorderLayout.EAST);
|
|
panelImageRadio.add(panelRadio, BorderLayout.EAST);
|
|
|
|
+
|
|
|
|
+ // Radio Buttons
|
|
panelRadio.setLayout(new GridLayout(0, 1, 0, 0));
|
|
panelRadio.setLayout(new GridLayout(0, 1, 0, 0));
|
|
|
|
+
|
|
rdbtnImagePixel.setBackground(Color.WHITE);
|
|
rdbtnImagePixel.setBackground(Color.WHITE);
|
|
rdbtnImagePixel.setSelected(true);
|
|
rdbtnImagePixel.setSelected(true);
|
|
|
|
|
|
@@ -81,11 +89,24 @@ public class BackgroundPopUp extends JDialog {
|
|
rdbtnStretched.setBackground(Color.WHITE);
|
|
rdbtnStretched.setBackground(Color.WHITE);
|
|
|
|
|
|
panelRadio.add(rdbtnStretched);
|
|
panelRadio.add(rdbtnStretched);
|
|
- rdbtnCustom.setBackground(Color.WHITE);
|
|
|
|
-
|
|
|
|
- panelRadio.add(rdbtnCustom);
|
|
|
|
panelBrowse.setBackground(Color.WHITE);
|
|
panelBrowse.setBackground(Color.WHITE);
|
|
|
|
|
|
|
|
+ ButtonGroup bgroup = new ButtonGroup();
|
|
|
|
+ bgroup.add(rdbtnImagePixel);
|
|
|
|
+ bgroup.add(rdbtnStretched);
|
|
|
|
+ panelRadio.add(rdbtnCustom);
|
|
|
|
+ rdbtnCustom.setBackground(new Color(255, 255, 255));
|
|
|
|
+ bgroup.add(rdbtnCustom);
|
|
|
|
+ panel.setBackground(Color.WHITE);
|
|
|
|
+
|
|
|
|
+ panelRadio.add(panel);
|
|
|
|
+ panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
|
|
+ panel.add(imageWidth);
|
|
|
|
+ imageWidth.setColumns(10);
|
|
|
|
+ panel.add(imageHeight);
|
|
|
|
+ imageHeight.setColumns(10);
|
|
|
|
+
|
|
|
|
+ // Browse Panel
|
|
getContentPane().add(panelBrowse, BorderLayout.NORTH);
|
|
getContentPane().add(panelBrowse, BorderLayout.NORTH);
|
|
panelBrowse.setLayout(new BorderLayout(0, 0));
|
|
panelBrowse.setLayout(new BorderLayout(0, 0));
|
|
panelBrowse.add(btnBrowse, BorderLayout.WEST);
|
|
panelBrowse.add(btnBrowse, BorderLayout.WEST);
|
|
@@ -101,7 +122,9 @@ public class BackgroundPopUp extends JDialog {
|
|
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());
|
|
|
|
+
|
|
// 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())) {
|
|
@@ -112,9 +135,9 @@ public class BackgroundPopUp extends JDialog {
|
|
/ panelImageRadio.getHeight();
|
|
/ panelImageRadio.getHeight();
|
|
}
|
|
}
|
|
|
|
|
|
- lblImage.setIcon(new ImageIcon(new ImageIcon(path).getImage().getScaledInstance(
|
|
|
|
- (int) (icon.getIconWidth() / imgScale), (int) (icon.getIconHeight() / imgScale),
|
|
|
|
- java.awt.Image.SCALE_FAST)));
|
|
|
|
|
|
+ lblImage.setIcon(new ImageIcon(
|
|
|
|
+ new ImageIcon(path).getImage().getScaledInstance((int) (icon.getIconWidth() / imgScale),
|
|
|
|
+ (int) (icon.getIconHeight() / imgScale), java.awt.Image.SCALE_FAST)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -131,8 +154,16 @@ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (canvas != null) {
|
|
if (canvas != null) {
|
|
- canvas.setBackgroundImage(path, mode, icon.getIconWidth(), icon.getIconHeight());
|
|
|
|
|
|
+ canvas.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()), Integer.parseInt(imageHeight.getText()));
|
|
canvas.repaint();
|
|
canvas.repaint();
|
|
} else if (uNode != null) {
|
|
} else if (uNode != null) {
|
|
|
|
|
|
@@ -163,9 +194,9 @@ public class BackgroundPopUp extends JDialog {
|
|
/ panelImageRadio.getHeight();
|
|
/ panelImageRadio.getHeight();
|
|
}
|
|
}
|
|
|
|
|
|
- lblImage.setIcon(new ImageIcon(new ImageIcon(path).getImage().getScaledInstance(
|
|
|
|
- (int) (icon.getIconWidth() / imgScale), (int) (icon.getIconHeight() / imgScale),
|
|
|
|
- java.awt.Image.SCALE_SMOOTH)));
|
|
|
|
|
|
+ lblImage.setIcon(new ImageIcon(
|
|
|
|
+ new ImageIcon(path).getImage().getScaledInstance((int) (icon.getIconWidth() / imgScale),
|
|
|
|
+ (int) (icon.getIconHeight() / imgScale), java.awt.Image.SCALE_SMOOTH)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|