|
@@ -0,0 +1,109 @@
|
|
|
|
+package ui.view;
|
|
|
|
+
|
|
|
|
+import java.awt.BorderLayout;
|
|
|
|
+import java.awt.Color;
|
|
|
|
+import java.awt.Dimension;
|
|
|
|
+import java.awt.Image;
|
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
|
+import java.awt.event.ActionListener;
|
|
|
|
+
|
|
|
|
+import javax.swing.ImageIcon;
|
|
|
|
+import javax.swing.JButton;
|
|
|
|
+import javax.swing.JDialog;
|
|
|
|
+import javax.swing.JLabel;
|
|
|
|
+import javax.swing.JPanel;
|
|
|
|
+import javax.swing.JScrollPane;
|
|
|
|
+import javax.swing.JTabbedPane;
|
|
|
|
+import javax.swing.JTextField;
|
|
|
|
+
|
|
|
|
+import ui.controller.Control;
|
|
|
|
+import ui.model.Model;
|
|
|
|
+
|
|
|
|
+public class CanvasResizePopUp extends JDialog {
|
|
|
|
+
|
|
|
|
+ private JPanel mainPanel = new JPanel();
|
|
|
|
+ private JTextField tFieldWidht = new JTextField();
|
|
|
|
+ private JTextField tFieldHeight = new JTextField();
|
|
|
|
+ private JLabel lblWidth = new JLabel("Width:");
|
|
|
|
+ private JLabel lblHeight = new JLabel("Height:");
|
|
|
|
+
|
|
|
|
+ private JPanel buttonPanel = new JPanel();
|
|
|
|
+ private final JButton btnOk = new JButton("OK");
|
|
|
|
+ private final JButton btnCancel = new JButton("Cancel");
|
|
|
|
+
|
|
|
|
+ JTabbedPane tabbedPane;
|
|
|
|
+ JTabbedPane tabbedPane2;
|
|
|
|
+ Model model;
|
|
|
|
+ Control controller;
|
|
|
|
+ MyCanvas canvas;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
+
|
|
|
|
+ public CanvasResizePopUp(Model model, Control controller, MyCanvas canvas, JTabbedPane tabbedPane,
|
|
|
|
+ JTabbedPane tabbedPane2) {
|
|
|
|
+ super((java.awt.Frame) null, true);
|
|
|
|
+ this.tabbedPane = tabbedPane;
|
|
|
|
+ this.tabbedPane2 = tabbedPane2;
|
|
|
|
+ this.model = model;
|
|
|
|
+ this.controller = controller;
|
|
|
|
+ this.canvas = canvas;
|
|
|
|
+
|
|
|
|
+ // properties and stuff
|
|
|
|
+ this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
|
|
|
|
+ .getScaledInstance(30, 30, Image.SCALE_SMOOTH));
|
|
|
|
+ this.setTitle("Set the Size of the View");
|
|
|
|
+ setBounds(200, 100, 200, 100);
|
|
|
|
+
|
|
|
|
+ // MainPanel
|
|
|
|
+ tFieldWidht.setText("" + model.getCanvasX());
|
|
|
|
+ tFieldHeight.setText("" + model.getCanvasY());
|
|
|
|
+ mainPanel.add(lblWidth);
|
|
|
|
+ mainPanel.add(tFieldHeight);
|
|
|
|
+ mainPanel.add(lblHeight);
|
|
|
|
+ mainPanel.add(tFieldWidht);
|
|
|
|
+ mainPanel.setBackground(Color.WHITE);
|
|
|
|
+
|
|
|
|
+ // Button Panel
|
|
|
|
+ btnOk.addActionListener(new ActionListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ controller.setCanvasX(Integer.parseInt(tFieldWidht.getText()));
|
|
|
|
+ controller.setCanvasY(Integer.parseInt(tFieldHeight.getText()));
|
|
|
|
+ canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
|
|
|
|
+ for (int i = 4; i < tabbedPane.getTabCount(); i++) {
|
|
|
|
+ if (tabbedPane.getComponentAt(i) != null) {
|
|
|
|
+ UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i))
|
|
|
|
+ .getViewport().getComponent(0));
|
|
|
|
+ unc.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
|
|
|
|
+ unc.repaint();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (tabbedPane2 != null && tabbedPane2.getSelectedIndex() >= 4) {
|
|
|
|
+ UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
|
|
|
|
+ .getViewport().getComponent(0));
|
|
|
|
+ unc.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
|
|
|
|
+ unc.repaint();
|
|
|
|
+ }
|
|
|
|
+ canvas.repaint();
|
|
|
|
+ dispose();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ btnCancel.addActionListener(new ActionListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ dispose();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ buttonPanel.add(btnOk);
|
|
|
|
+ buttonPanel.add(btnCancel);
|
|
|
|
+ buttonPanel.setBackground(Color.WHITE);
|
|
|
|
+
|
|
|
|
+ // Add to ContentPane
|
|
|
|
+ getContentPane().add(mainPanel, BorderLayout.CENTER);
|
|
|
|
+ getContentPane().add(buttonPanel, BorderLayout.SOUTH);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|