Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. package com.mateusz.paint.view;
  2.  
  3. import java.awt.Color;
  4. import java.awt.GridLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JButton;
  9. import javax.swing.JColorChooser;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import org.apache.log4j.Logger;
  13. import com.mateusz.paint.model.StaticStuff;
  14.  
  15. public class ToolsMenu extends JPanel
  16. {
  17.  
  18. private JButton colorButton, rectangleButton, circleButton, pencilButton, lineButton, rubberButton,
  19. fillClosedShapeButton;
  20. private Color selectedColor = StaticStuff.shapeColor;
  21. private JLabel tipText;
  22.  
  23. final static Logger logger = Logger.getLogger(ToolsMenu.class);
  24.  
  25. public ToolsMenu()
  26. {
  27. }
  28.  
  29. public void setTools()
  30. {
  31. int numberOfColumns = 1; // = 0 many columns as necessary
  32. int numberOfRows = 0; // 0 = many rows as necessary
  33. this.setLayout(new GridLayout(numberOfRows, numberOfColumns));
  34.  
  35. tipText = new JLabel("Color Chooser: ");
  36. rectangleButton = new JButton(new ImageIcon("images/tools/rectangle.png"));
  37. circleButton = new JButton(new ImageIcon("images/tools/circle.png"));
  38. pencilButton = new JButton(new ImageIcon("images/tools/pencil.png"));
  39. lineButton = new JButton(new ImageIcon("images/tools/line.png"));
  40. rubberButton = new JButton(new ImageIcon("images/tools/rubber.png"));
  41. fillClosedShapeButton = new JButton(new ImageIcon("images/tools/fill.png"));
  42.  
  43. colorButton = new JButton();
  44. colorButton.setForeground(selectedColor);
  45. colorButton.setBackground(selectedColor);
  46.  
  47. initColorButtonListener();
  48. initCircleButtonListener();
  49. initFillClosedShapeButtonListener();
  50. initLineButtonListener();
  51. initPencilButtonListener();
  52. initRectangleButtonListener();
  53. initRubberButtonListener();
  54.  
  55. this.add(circleButton);
  56. this.add(rectangleButton);
  57. this.add(pencilButton);
  58. this.add(lineButton);
  59. this.add(rubberButton);
  60. this.add(fillClosedShapeButton);
  61. this.add(tipText);
  62. this.add(colorButton);
  63. }
  64.  
  65. public void initColorButtonListener()
  66. {
  67. colorButton.addActionListener(new ActionListener()
  68. {
  69.  
  70. @Override
  71. public void actionPerformed(ActionEvent e)
  72. {
  73. selectedColor = JColorChooser.showDialog(ToolsMenu.this, "Chose color:", selectedColor);
  74. StaticStuff.shapeColor = selectedColor;
  75. colorButton.setForeground(selectedColor);
  76. colorButton.setBackground(selectedColor);
  77. }
  78. });
  79. }
  80.  
  81.  
  82. public void initRectangleButtonListener()
  83. {
  84. rectangleButton.addActionListener(new ActionListener()
  85. {
  86.  
  87. @Override
  88. public void actionPerformed(ActionEvent event)
  89. {
  90. logger.debug("rectangle");
  91. }
  92. });
  93. }
  94.  
  95. public void initCircleButtonListener()
  96. {
  97.  
  98. circleButton.addActionListener(new ActionListener()
  99. {
  100.  
  101. @Override
  102. public void actionPerformed(ActionEvent event)
  103. {
  104. logger.debug("circle");
  105. }
  106. });
  107. }
  108.  
  109. public void initPencilButtonListener()
  110. {
  111. pencilButton.addActionListener(new ActionListener()
  112. {
  113.  
  114. @Override
  115. public void actionPerformed(ActionEvent event)
  116. {
  117. logger.debug("pencil");
  118. }
  119. });
  120. }
  121.  
  122. public void initLineButtonListener()
  123. {
  124. lineButton.addActionListener(new ActionListener()
  125. {
  126.  
  127. @Override
  128. public void actionPerformed(ActionEvent event)
  129. {
  130. logger.debug("line");
  131. }
  132. });
  133. }
  134.  
  135. public void initRubberButtonListener()
  136. {
  137. rubberButton.addActionListener(new ActionListener()
  138. {
  139.  
  140. @Override
  141. public void actionPerformed(ActionEvent event)
  142. {
  143. logger.debug("rubber");
  144. }
  145. });
  146. }
  147.  
  148. public void initFillClosedShapeButtonListener()
  149. {
  150.  
  151. fillClosedShapeButton.addActionListener(new ActionListener()
  152. {
  153.  
  154. @Override
  155. public void actionPerformed(ActionEvent event)
  156. {
  157. logger.debug("fill closed shape");
  158. }
  159. });
  160. }
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement