Browse Source

Remove Background Image Button

Kevin Trometer 7 years ago
parent
commit
3ce4370489
1 changed files with 28 additions and 0 deletions
  1. 28 0
      src/ui/view/BackgroundPopUp.java

+ 28 - 0
src/ui/view/BackgroundPopUp.java

@@ -62,6 +62,8 @@ public class BackgroundPopUp extends JDialog {
 	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");
+	private final JButton removeImageBtn = new JButton("Remove Background Image");
+	private boolean imageBtnClearedPressed = false;
 
 	// Modes
 	public static final int IMAGE_PIXELS = 0, STRETCHED = 1, CUSTOM = 2;
@@ -134,6 +136,22 @@ public class BackgroundPopUp extends JDialog {
 		panel.add(imageHeight);
 		imageHeight.setColumns(10);
 
+		// remove BackgroundImage Button
+		removeImageBtn.setBackground(Color.WHITE);
+		removeImageBtn.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				path = "";
+				textPath.setText("");
+				imageBtnClearedPressed = true;
+				lblImage.setIcon(null);
+			}
+		});
+		JPanel removePanel = new JPanel();
+		removePanel.add(removeImageBtn);
+		removePanel.setBackground(Color.WHITE);
+		panelRadio.add(removePanel);
+
 		// Browse Panel
 		getContentPane().add(panelBrowse, BorderLayout.NORTH);
 		panelBrowse.setLayout(new BorderLayout(0, 0));
@@ -209,6 +227,16 @@ public class BackgroundPopUp extends JDialog {
 								Integer.parseInt(imageHeight.getText()));
 					}
 					dispose();
+				} else if (imageBtnClearedPressed) {
+					if (canvas != null) {
+						controller.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()));
+					}
+					dispose();
 				} else {
 					JOptionPane.showMessageDialog(null, "No image selected!", "Warning!", JOptionPane.WARNING_MESSAGE);
 				}