View Javadoc
1 // re/mind - Remote Reminder Software 2 // Copyright (C) 2002 Moritz Petersen 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 // 18 // $Id: NoteFrame.java,v 1.2 2002/09/29 19:33:23 powerpete Exp $ 19 package de.jface.remind.awtui; 20 21 import de.jface.remind.Config; 22 import de.jface.remind.Controller; 23 import de.jface.remind.core.Note; 24 import de.jface.remind.core.NoteMetaData; 25 import de.jface.remind.core.NoteMetaData.Visibility; 26 27 import java.awt.Font; 28 import java.awt.Frame; 29 import java.awt.Menu; 30 import java.awt.MenuItem; 31 import java.awt.MenuShortcut; 32 import java.awt.TextArea; 33 import java.awt.event.ActionEvent; 34 import java.awt.event.ActionListener; 35 import java.awt.event.ComponentAdapter; 36 import java.awt.event.ComponentEvent; 37 import java.awt.event.KeyEvent; 38 import java.awt.event.TextEvent; 39 import java.awt.event.TextListener; 40 import java.awt.event.WindowAdapter; 41 import java.awt.event.WindowEvent; 42 43 import java.text.DateFormat; 44 import java.text.MessageFormat; 45 46 import org.apache.log4j.Logger; 47 48 /*** 49 * Class <code>NoteFrame</code> 50 * of project RemotePostIt. 51 * 52 * @author Moritz Petersen 53 * @version $Revision: 1.2 $ 54 */ 55 public class NoteFrame extends Frame 56 { 57 private TextArea textArea; 58 private Note note; 59 private Logger log4j = Logger.getLogger(getClass()); 60 61 public NoteFrame(Note note) 62 { 63 super(createTitle(note)); 64 65 this.note = note; 66 67 setMenuBar(new MenuBar()); //MenuBar.getInstance()); 68 add(new NoteTextArea(note)); 69 setBounds(note.getMetaData().getBounds()); 70 71 addWindowListener(new NoteWindowListener()); 72 addComponentListener(new NoteComponentListener()); 73 74 setVisibility(note); 75 } 76 77 private void setVisibility(Note note) 78 { 79 log4j.debug("Setting visibility for frame " + this); 80 81 Visibility visibility = note.getMetaData().getVisibility(); 82 83 setVisible(true); 84 85 if (Visibility.HIDDEN.equals(visibility)) 86 { 87 setVisible(false); 88 } 89 else 90 { 91 if (Visibility.MINIMIZED.equals(visibility)) 92 { 93 setState(Frame.ICONIFIED); 94 } 95 else 96 { 97 setState(Frame.NORMAL); 98 } 99 } 100 } 101 102 private static String createTitle(Note note) 103 { 104 final DateFormat formatter = 105 DateFormat.getDateTimeInstance(DateFormat.SHORT, 106 DateFormat.SHORT); 107 String date = formatter.format(note.getMetaData().getDateOfCreation()); 108 109 return MessageFormat.format(Config.FRAME_TITLE, new Object[] { date }); 110 } 111 112 private class NoteWindowListener 113 extends WindowAdapter 114 { 115 /*** 116 * This method handles the WindowEvent of the windowClosing action. 117 * The result of this mehtod will be different, depending on the 118 * operating system. On Apple Macintosh computers, the user will 119 * expect the note to be deleted. On other operating systems, like 120 * Windows or Linux, the user will expect the application to quit. 121 */ 122 public void windowClosing(WindowEvent e) 123 { 124 if (Config.IS_MACINTOSH) 125 { 126 Controller.closeNote(note); 127 dispose(); 128 } 129 else 130 { 131 Controller.quit(); 132 } 133 } 134 135 public void windowIconified(WindowEvent e) 136 { 137 Controller.minimizeNote(note); 138 } 139 140 public void windowDeiconified(WindowEvent e) 141 { 142 Controller.showNote(note); 143 } 144 } 145 146 private class NoteComponentListener 147 extends ComponentAdapter 148 { 149 public void componentResized(ComponentEvent e) 150 { 151 Controller.changeBounds(note, getBounds()); 152 } 153 154 public void componentMoved(ComponentEvent e) 155 { 156 Controller.changeBounds(note, getBounds()); 157 } 158 } 159 160 private class NoteTextArea 161 extends TextArea 162 { 163 public NoteTextArea(Note note) 164 { 165 super(note.getText().getBody(), 1, 1, TextArea.SCROLLBARS_NONE); 166 setBackground(Config.NOTE_COLOR); 167 setFont(new Font(Config.NOTE_FONT_FAMILY, Font.PLAIN, 13)); 168 addTextListener(new NoteTextListener(note)); 169 } 170 171 private class NoteTextListener 172 implements TextListener 173 { 174 private Note note; 175 176 public NoteTextListener(Note note) 177 { 178 this.note = note; 179 } 180 181 public void textValueChanged(TextEvent e) 182 { 183 Controller.changeText(note, getText()); 184 } 185 } 186 } 187 188 private class MenuBar extends java.awt.MenuBar 189 { 190 public MenuBar() 191 { 192 super(); 193 add(new FileMenu()); 194 add(new NoteMenu()); 195 } 196 197 private abstract class AbstractMenuItem 198 extends MenuItem 199 { 200 public AbstractMenuItem(String label, int keyCode) 201 { 202 this(label, keyCode, false); 203 } 204 205 public AbstractMenuItem(String label, int keyCode, 206 boolean useShiftModifier) 207 { 208 super(label, new MenuShortcut(keyCode, useShiftModifier)); 209 initActionListener(); 210 } 211 212 private void initActionListener() 213 { 214 addActionListener(new ActionListener() 215 { 216 public void actionPerformed(ActionEvent e) 217 { 218 performAction(e); 219 } 220 }); 221 } 222 223 protected abstract void performAction(ActionEvent e); 224 } 225 226 private class FileMenu 227 extends Menu 228 { 229 public FileMenu() 230 { 231 super(Config.MENU_FILE_LABEL); 232 add(new NewMenuItem()); 233 add(new CloseMenuItem()); 234 add(new MenuItem("-")); 235 add(new SaveMenuItem()); 236 add(new MenuItem("-")); 237 add(new RevertMenuItem()); 238 239 if (!Config.IS_MACINTOSH) 240 { 241 add(new MenuItem("-")); 242 add(new QuitMenuItem()); 243 } 244 } 245 246 private class NewMenuItem 247 extends AbstractMenuItem 248 { 249 public NewMenuItem() 250 { 251 super(Config.MENUITEM_FILE_NEW_LABEL, KeyEvent.VK_N); 252 } 253 254 protected void performAction(ActionEvent e) 255 { 256 Controller.newNote(); 257 } 258 } 259 260 private class CloseMenuItem 261 extends AbstractMenuItem 262 { 263 public CloseMenuItem() 264 { 265 super(Config.MENUITEM_FILE_CLOSE_LABEL, KeyEvent.VK_W); 266 } 267 268 protected void performAction(ActionEvent e) 269 { 270 Controller.closeNote(note); 271 dispose(); 272 } 273 } 274 275 private class SaveMenuItem 276 extends AbstractMenuItem 277 { 278 public SaveMenuItem() 279 { 280 super(Config.MENUITEM_FILE_SAVE_LABEL, KeyEvent.VK_S); 281 } 282 283 protected void performAction(ActionEvent e) 284 { 285 Controller.save(); 286 } 287 } 288 289 private class RevertMenuItem 290 extends AbstractMenuItem 291 { 292 public RevertMenuItem() 293 { 294 super(Config.MENUITEM_FILE_REVERT_LABEL, KeyEvent.VK_U); 295 } 296 297 protected void performAction(ActionEvent e) 298 { 299 // close all Frames 300 final Frame[] frames = Frame.getFrames(); 301 302 for (int i = 0, max = frames.length; i < max; i++) 303 { 304 Frame frame = frames[i]; 305 306 frame.setVisible(false); 307 frame.dispose(); 308 } 309 310 Controller.revert(); 311 } 312 } 313 314 private class QuitMenuItem 315 extends AbstractMenuItem 316 { 317 public QuitMenuItem() 318 { 319 super(Config.MENUITEM_FILE_QUIT_LABEL, KeyEvent.VK_Q); 320 } 321 322 protected void performAction(ActionEvent e) 323 { 324 Controller.quit(); 325 } 326 } 327 } 328 329 private class NoteMenu 330 extends Menu 331 { 332 public NoteMenu() 333 { 334 super(Config.MENU_NOTE_LABEL); 335 add(new HideMenuItem()); 336 add(new MinimizeMenuItem()); 337 add(new MenuItem("-")); 338 add(new ShowAllMenuItem()); 339 add(new MenuItem("-")); 340 add(new NextNoteMenuItem()); 341 } 342 343 private class HideMenuItem 344 extends AbstractMenuItem 345 { 346 public HideMenuItem() 347 { 348 super(Config.MENUITEM_NOTE_HIDE_LABEL, KeyEvent.VK_I); 349 } 350 351 protected void performAction(ActionEvent e) 352 { 353 setVisible(false); 354 Controller.hideNote(note); 355 } 356 } 357 358 private class MinimizeMenuItem 359 extends AbstractMenuItem 360 { 361 public MinimizeMenuItem() 362 { 363 super(Config.MENUITEM_NOTE_MINIMIZE_LABEL, KeyEvent.VK_M); 364 } 365 366 protected void performAction(ActionEvent e) 367 { 368 setState(Frame.ICONIFIED); 369 Controller.minimizeNote(note); 370 } 371 } 372 373 private class ShowAllMenuItem 374 extends AbstractMenuItem 375 { 376 public ShowAllMenuItem() 377 { 378 super(Config.MENUITEM_NOTE_SHOWALL_LABEL, KeyEvent.VK_M, 379 true); 380 } 381 382 protected void performAction(ActionEvent e) 383 { 384 final Frame[] frames = Frame.getFrames(); 385 386 for (int i = 0, max = frames.length; i < max; i++) 387 { 388 Frame frame = frames[i]; 389 390 log4j.debug("Restoring frame " + frame); 391 392 if (frame.getState() != Frame.NORMAL) 393 { 394 frame.setState(Frame.NORMAL); 395 } 396 397 if (frame.isVisible() != true) 398 { 399 frame.setVisible(true); 400 } 401 } 402 403 Controller.showAllNotes(); 404 } 405 } 406 407 private class NextNoteMenuItem 408 extends AbstractMenuItem 409 { 410 public NextNoteMenuItem() 411 { 412 super(Config.MENUITEM_NOTE_NEXTNOTE_LABEL, 413 KeyEvent.VK_MINUS); 414 } 415 416 protected void performAction(ActionEvent e) 417 { 418 final Frame[] frames = Frame.getFrames(); 419 420 for (int i = 0, max = frames.length; i < max; i++) 421 { 422 Frame frame = frames[i]; 423 424 // dirty trick to identify the current frame...: 425 if (((NoteFrame) frame).note == note) 426 { 427 frames[(i + 1) % max].toFront(); 428 429 return; 430 } 431 } 432 } 433 } 434 } 435 } 436 } 437 438 // ------1---------2---------3---------4---------5---------6---------7---------8

This page was automatically generated by Maven