1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package ui.view;
- import ui.controller.Control;
- import ui.model.Model;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class CanvasResizePopUp extends JDialog {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- 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 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();
- public CanvasResizePopUp(Model model, Control controller, MyCanvas canvas, JTabbedPane tabbedPane,
- JTabbedPane tabbedPane2, JFrame parentFrame) {
- 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(Util.loadImage("/Images/Holeg.png",30,30));
- this.setTitle("Set the Size of the View");
- setBounds(200, 100, 200, 100);
- setLocationRelativeTo(parentFrame);
- // 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);
- }
- }
|