CanvasResizePopUp.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package ui.view;
  2. import ui.controller.Control;
  3. import ui.model.Model;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. public class CanvasResizePopUp extends JDialog {
  9. /**
  10. *
  11. */
  12. private static final long serialVersionUID = 1L;
  13. private final JButton btnOk = new JButton("OK");
  14. private final JButton btnCancel = new JButton("Cancel");
  15. JTabbedPane tabbedPane;
  16. JTabbedPane tabbedPane2;
  17. Model model;
  18. Control controller;
  19. MyCanvas canvas;
  20. private JPanel mainPanel = new JPanel();
  21. private JTextField tFieldWidht = new JTextField();
  22. private JTextField tFieldHeight = new JTextField();
  23. private JLabel lblWidth = new JLabel("Width:");
  24. private JLabel lblHeight = new JLabel("Height:");
  25. private JPanel buttonPanel = new JPanel();
  26. public CanvasResizePopUp(Model model, Control controller, MyCanvas canvas, JTabbedPane tabbedPane,
  27. JTabbedPane tabbedPane2, JFrame parentFrame) {
  28. super((java.awt.Frame) null, true);
  29. this.tabbedPane = tabbedPane;
  30. this.tabbedPane2 = tabbedPane2;
  31. this.model = model;
  32. this.controller = controller;
  33. this.canvas = canvas;
  34. // properties and stuff
  35. this.setIconImage(Util.loadImage("/Images/Holeg.png",30,30));
  36. this.setTitle("Set the Size of the View");
  37. setBounds(200, 100, 200, 100);
  38. setLocationRelativeTo(parentFrame);
  39. // MainPanel
  40. tFieldWidht.setText("" + model.getCanvasX());
  41. tFieldHeight.setText("" + model.getCanvasY());
  42. mainPanel.add(lblWidth);
  43. mainPanel.add(tFieldHeight);
  44. mainPanel.add(lblHeight);
  45. mainPanel.add(tFieldWidht);
  46. mainPanel.setBackground(Color.WHITE);
  47. // Button Panel
  48. btnOk.addActionListener(new ActionListener() {
  49. @Override
  50. public void actionPerformed(ActionEvent e) {
  51. controller.setCanvasX(Integer.parseInt(tFieldWidht.getText()));
  52. controller.setCanvasY(Integer.parseInt(tFieldHeight.getText()));
  53. canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  54. for (int i = 4; i < tabbedPane.getTabCount(); i++) {
  55. if (tabbedPane.getComponentAt(i) != null) {
  56. UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i))
  57. .getViewport().getComponent(0));
  58. unc.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  59. unc.repaint();
  60. }
  61. }
  62. if (tabbedPane2 != null && tabbedPane2.getSelectedIndex() >= 4) {
  63. UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
  64. .getViewport().getComponent(0));
  65. unc.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  66. unc.repaint();
  67. }
  68. canvas.repaint();
  69. dispose();
  70. }
  71. });
  72. btnCancel.addActionListener(new ActionListener() {
  73. @Override
  74. public void actionPerformed(ActionEvent e) {
  75. dispose();
  76. }
  77. });
  78. buttonPanel.add(btnOk);
  79. buttonPanel.add(btnCancel);
  80. buttonPanel.setBackground(Color.WHITE);
  81. // Add to ContentPane
  82. getContentPane().add(mainPanel, BorderLayout.CENTER);
  83. getContentPane().add(buttonPanel, BorderLayout.SOUTH);
  84. }
  85. }