Sfoglia il codice sorgente

Remove Background Image Button

Kevin Trometer 7 anni fa
parent
commit
3ce4370489
1 ha cambiato i file con 28 aggiunte e 0 eliminazioni
  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);
 				}