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: Controller.java,v 1.2 2002/09/29 19:33:23 powerpete Exp $ 19 package de.jface.remind; 20 21 import de.jface.remind.awtui.NoteFrame; 22 import de.jface.remind.core.Note; 23 import de.jface.remind.core.NoteMetaData; 24 import de.jface.remind.core.NoteMetaData.Visibility; 25 import de.jface.remind.core.NoteText; 26 import de.jface.remind.io.StorageException; 27 28 import java.awt.Rectangle; 29 30 import java.util.Iterator; 31 32 import org.apache.log4j.Logger; 33 34 /*** 35 * Class <code>Controller</code> 36 * of project RemotePostIt. 37 * 38 * @author Moritz Petersen 39 * @version $Revision: 1.2 $ 40 */ 41 public class Controller 42 { 43 private static Model model; 44 private static boolean hasChanged; 45 private static Logger log4j = Logger.getLogger(Controller.class); 46 47 public static void init() 48 { 49 model = new Model(); 50 revert(); 51 } 52 53 public static void quit() 54 { 55 save(); 56 System.exit(0); 57 } 58 59 public static void revert() 60 { 61 try 62 { 63 model.open(); 64 } 65 catch (StorageException e) 66 { 67 log4j.fatal("Exception while opening notes.", e); 68 } 69 70 for (Iterator i = model.notes(); i.hasNext();) 71 { 72 openNote((Note) i.next()); 73 } 74 75 hasChanged = false; 76 77 if (!model.hasVisibleNotes()) 78 { 79 newNote(); 80 } 81 } 82 83 public static void newNote() 84 { 85 Note note = model.newNote(); 86 openNote(note); 87 hasChanged = true; 88 } 89 90 private static void openNote(Note note) 91 { 92 new NoteFrame(note); 93 } 94 95 public static void closeNote(Note note) 96 { 97 model.removeNote(note); 98 hasChanged = true; 99 if (!model.hasVisibleNotes()) 100 { 101 quit(); 102 } 103 } 104 105 public static void save() 106 { 107 try 108 { 109 if (hasChanged) 110 { 111 model.close(); 112 hasChanged = false; 113 } 114 } 115 catch (Exception e) 116 { 117 log4j.fatal("Exception while saving notes.", e); 118 } 119 } 120 121 public static void minimizeNote(Note note) 122 { 123 NoteMetaData metaData = note.getMetaData(); 124 metaData.setVisibility(Visibility.MINIMIZED); 125 hasChanged = true; 126 } 127 128 public static void hideNote(Note note) 129 { 130 NoteMetaData metaData = note.getMetaData(); 131 metaData.setVisibility(Visibility.HIDDEN); 132 hasChanged = true; 133 if (!model.hasVisibleNotes()) 134 { 135 quit(); 136 } 137 } 138 139 public static void showNote(Note note) 140 { 141 NoteMetaData metaData = note.getMetaData(); 142 metaData.setVisibility(Visibility.VISIBLE); 143 hasChanged = true; 144 } 145 146 public static void showAllNotes() 147 { 148 for (Iterator i = model.notes(); i.hasNext();) 149 { 150 Note note = (Note) i.next(); 151 } 152 } 153 154 public static void changeText(Note note, String text) 155 { 156 NoteText noteText = note.getText(); 157 158 noteText.setBody(text); 159 hasChanged = true; 160 } 161 162 public static void changeBounds(Note note, Rectangle bounds) 163 { 164 NoteMetaData metaData = note.getMetaData(); 165 166 metaData.setBounds(bounds); 167 hasChanged = true; 168 } 169 } 170 171 // ------1---------2---------3---------4---------5---------6---------7---------8

This page was automatically generated by Maven