1 package demo.notification.whiteboard; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Frame ; 5 import java.awt.Menu ; 6 import java.awt.MenuBar ; 7 import java.awt.MenuItem ; 8 import java.awt.event.ActionEvent ; 9 import java.awt.event.ActionListener ; 10 import java.util.ArrayList ; 11 import java.util.Collections ; 12 import java.util.List ; 13 14 import org.apache.log.Hierarchy; 15 import org.apache.log.Logger; 16 17 21 22 public class WorkgroupFrame extends Frame implements IWorkgroupFrame { 23 24 Logger logger_ = Hierarchy.getDefaultHierarchy().getLoggerFor("WorkgroupFrame"); 25 26 BrushSizeDrawCanvas drawCanvas_; 27 SelectDialog dialog; 28 GhostPainter ghost; 29 WorkgroupController controller_; 31 32 public BrushSizeDrawCanvas getDrawCanvas() { 33 return drawCanvas_; 34 } 35 36 public Frame getFrame() { 37 return this; 38 } 39 40 public List getList() { 41 String [] s = controller_.getListOfWhiteboards(); 42 List v = new ArrayList (); 43 for (int n=0; n<s.length; n++) { 44 v.add(s[n]); 45 } 46 return Collections.unmodifiableList(v); 47 } 48 49 public void setCurrentBoardText(String name) { 50 currentBoard.setText(name); 51 } 52 53 public void setLeaveMenuItem(boolean value) { 54 leaveMenuItem_.setEnabled(value); 55 } 56 57 58 public WorkgroupFrame(WorkgroupController wg, String name) { 59 super(name); 60 61 logger_.debug("init"); 62 63 controller_ = wg; 64 65 initComponents(); 66 pack (); 67 } 68 69 public WorkgroupFrame(WorkgroupController wg) { 70 this(wg, "Whiteboard"); 71 } 72 73 private void initComponents () { 74 addWindowListener (new java.awt.event.WindowAdapter () { 75 public void windowClosing (java.awt.event.WindowEvent evt) { 76 exitForm(evt); 77 } 78 }); 79 setLayout (new java.awt.BorderLayout ()); 80 81 drawCanvas_ = new BrushSizeDrawCanvas(controller_, 400,400); 82 add(drawCanvas_, BorderLayout.CENTER); 83 84 menuBar1 = new MenuBar (); 85 menu1 = new Menu (); 86 menu1.setLabel ("Menu"); 87 select = new MenuItem (); 88 select.setLabel ("Select"); 89 select.setName ("select"); 90 select.addActionListener (new ActionListener () { 91 public void actionPerformed (ActionEvent evt) { 92 selectActionPerformed (evt); 93 } 94 }); 95 menu1.add(select); 96 97 leaveMenuItem_ = new java.awt.MenuItem (); 98 leaveMenuItem_.setEnabled (false); 99 leaveMenuItem_.setLabel ("Leave"); 100 leaveMenuItem_.setName ("leave"); 101 leaveMenuItem_.addActionListener (new ActionListener () { 102 public void actionPerformed (ActionEvent evt) { 103 leaveActionPerformed (evt); 104 } 105 }); 106 menu1.add(leaveMenuItem_); 107 108 activateGhost = new java.awt.MenuItem (); 109 activateGhost.setLabel("Start Daemon"); 110 activateGhost.addActionListener (new java.awt.event.ActionListener () { 111 public void actionPerformed(java.awt.event.ActionEvent e) { 112 activateGhostActionPerformed(); 113 } 114 }); 115 117 exit = new java.awt.MenuItem (); 118 exit.setLabel ("Exit"); 119 exit.setName ("exit"); 120 exit.addActionListener (new java.awt.event.ActionListener () { 121 public void actionPerformed (java.awt.event.ActionEvent evt) { 122 exitActionPerformed (evt); 123 } 124 }); 125 menu1.add(exit); 126 127 menuBar1.add(menu1); 128 129 setMenuBar(menuBar1); 130 panel1 = new java.awt.Panel (); 131 panel1.setLayout (new java.awt.FlowLayout ()); 132 133 136 draw = new java.awt.Button (); 137 draw.setLabel ("Draw"); 138 draw.addActionListener (new java.awt.event.ActionListener () { 139 public void actionPerformed (java.awt.event.ActionEvent evt) { 140 drawActionPerformed (evt); 141 } 142 }); 143 panel1.add (draw); 144 145 delete = new java.awt.Button (); 146 delete.setLabel ("Delete"); 147 delete.setName ("delete"); 148 delete.addActionListener (new java.awt.event.ActionListener () { 149 public void actionPerformed (java.awt.event.ActionEvent evt) { 150 deleteActionPerformed (evt); 151 } 152 }); 153 panel1.add (delete); 154 155 clear = new java.awt.Button (); 156 clear.setLabel ("Clear"); 157 clear.setName ("clear"); 158 clear.addActionListener (new java.awt.event.ActionListener () { 159 public void actionPerformed (java.awt.event.ActionEvent evt) { 160 clearActionPerformed (evt); 161 } 162 }); 163 panel1.add (clear); 164 165 currentBoard = new java.awt.TextField (12); 166 currentBoard.setName("currentboard"); 167 currentBoard.setEditable(false); 168 currentBoard.setText("No Selection"); 169 panel1.add(currentBoard); 170 171 add (panel1, "South"); 172 } 173 174 private void activateGhostActionPerformed() { 175 if (activateGhost.getLabel() == "Start Daemon" ) { 176 ghost = new GhostPainter(this,400,400); 177 ghost.start(); 178 activateGhost.setLabel("Stop Daemon"); 179 } else { 181 ghost.shutdown(); 182 activateGhost.setLabel("Start Daemon"); 183 } 185 } 186 187 194 private void clearActionPerformed (java.awt.event.ActionEvent evt) { 195 drawCanvas_.clearAll(); 196 } 197 198 private void deleteActionPerformed (java.awt.event.ActionEvent evt) { 199 drawCanvas_.setDrawColor(0,0,0); 200 drawCanvas_.setBrushSize(5); 201 } 202 203 private void drawActionPerformed (java.awt.event.ActionEvent evt) { 204 drawCanvas_.setDrawColor(255,255,255); 205 drawCanvas_.setBrushSize(1); 206 } 207 208 private void exitActionPerformed (java.awt.event.ActionEvent evt) { 209 controller_.exit(); 210 } 211 212 private void leaveActionPerformed (java.awt.event.ActionEvent evt) { 213 leaveMenuItem_.setEnabled(false); 214 currentBoard.setText("No Selection"); 215 controller_.leaveWhiteboard(); 216 } 217 218 private void selectActionPerformed (java.awt.event.ActionEvent evt) { 219 dialog = new SelectDialog(this, controller_); 220 dialog.show(); 221 } 222 223 224 private void exitForm(java.awt.event.WindowEvent evt) { 225 controller_.exit(); 226 } 227 228 private java.awt.Panel panel1; 229 private java.awt.Button draw,delete,clear; 230 private java.awt.MenuBar menuBar1; 231 private java.awt.Menu menu1; 232 private java.awt.MenuItem select,exit,activateGhost,leaveMenuItem_; 233 private java.awt.TextField currentBoard; 234 } 235 236 | Popular Tags |