Exemple #1
29
 public static void addAppointments(Iterable<Appointment> appointments) {
   String key;
   for (Appointment appointment : appointments) {
     key = Client.dateToString(appointment.getStartDate());
     System.out.println(key);
     if (Client.appointments.containsKey(key)) {
       if (!Client.appointments.get(key).contains(appointment)) {
         Client.appointments.get(key).add(appointment);
       }
     } else {
       Client.appointments.put(key, new ArrayList<Appointment>());
       Client.appointments.get(key).add(appointment);
     }
   }
 }
 /**
  * Pops view, resuming and returning the next view in stack
  *
  * @return next view
  */
 public static View popView() {
   View popped = viewStack.pop();
   popped.deinitialize();
   View view = viewStack.peek();
   view.resume();
   calendar.setContentPane((Container) view);
   calendar.pack();
   Utils.centerOnScreen(calendar);
   if (view.shouldBeFullscreen()) {
     calendar.setExtendedState(Frame.MAXIMIZED_BOTH);
   }
   return view;
 }
 /**
  * Pushes view on {@link #viewStack}, displays and returns view afterwards.
  *
  * @param view
  * @return topmost view
  * @see no.ntnu.fp.Client#viewStack
  */
 public static View pushView(View view) {
   view.initialize();
   calendar.setContentPane((Container) view);
   if (viewStack.size() > 0) {
     viewStack.peek().pause();
   }
   viewStack.push(view);
   calendar.repaint();
   calendar.pack();
   Utils.centerOnScreen(calendar);
   if (view.shouldBeFullscreen()) {
     calendar.setExtendedState(Frame.MAXIMIZED_BOTH);
   }
   return view;
 }
 /**
  * Logs in user, eventually
  *
  * @param username
  * @param password
  */
 public static Boolean login(String username, String password) {
   Boolean status;
   if (username.equals("sigve") && password.equals("1337")) {
     setUser(User.getUser(1)); // get user 1 for now
     GregorianCalendar now = new GregorianCalendar(2012, 3, 23); // arbitrary date for now
     System.out.println("User logged in");
     pushView(new CalendarView());
     Client.setNotifications(Message.getMessages(Client.user));
     Client.setActiveWeek(
         now.get(GregorianCalendar.YEAR),
         now.get(GregorianCalendar.MONTH),
         now.get(GregorianCalendar.DATE));
     status = true;
   } else {
     System.out.println("Wrong username and/or password");
     status = false;
   }
   return status;
 }
 public static void setActiveWeek(int year, int month, int date) {
   activeWeek.set(year, month, date);
   GregorianCalendar endOfActiveWeek = (GregorianCalendar) activeWeek.clone();
   endOfActiveWeek.add(GregorianCalendar.DATE, 7);
   Client.addAppointments(Appointment.getAppointments(user, activeWeek, endOfActiveWeek));
   while (
   /*activeWeek.get(GregorianCalendar.DAY_OF_MONTH) != 1 && */ activeWeek.get(
           GregorianCalendar.DAY_OF_WEEK)
       != /*activeWeek.getFirstDayOfWeek()*/ GregorianCalendar.MONDAY) {
     activeWeek.add(GregorianCalendar.DAY_OF_MONTH, -1);
   }
   System.out.println(Client.dateToString(activeWeek));
   for (ActiveWeekListener listener : activeWeekListeners) {
     listener.setActiveWeek(
         activeWeek.get(GregorianCalendar.YEAR),
         activeWeek.get(GregorianCalendar.MONTH),
         activeWeek.get(GregorianCalendar.DATE));
   }
 }
 public MiniCalendarView(int year, int month) {
   setLayout(new GridBagLayout());
   setPreferredSize(GUI_CONSTANTS.miniCalendarViewDimension);
   setUp();
   Client.addActiveWeekListener(this);
 }
 /**
  * makes a new Calendar, pushes to stack, and makes it visible
  *
  * @throws IOException
  * @throws ConnectException
  * @throws ClassNotFoundException
  * @see#viewStack
  */
 public static void main(String[] args)
     throws ConnectException, IOException, ClassNotFoundException {
   calendar = new Client();
   pushView(new LoginView());
   calendar.setVisible(true);
 }
Exemple #8
-18
 public static void setActiveWeek(GregorianCalendar g) {
   GregorianCalendar endG = (GregorianCalendar) g.clone();
   endG.add(GregorianCalendar.DATE, 7);
   Client.addAppointments(Appointment.getAppointments(user, g, endG));
   setActiveWeek(
       g.get(GregorianCalendar.YEAR),
       g.get(GregorianCalendar.MONTH),
       g.get(GregorianCalendar.DATE));
 }