Exemplo n.º 1
0
  /**
   * A method to update the current month. Sets the variable that controls the month and updates the
   * text.
   *
   * @param newMonth an integer value between 0 and 11.
   */
  public void updateMonth(int newMonth) {
    pastMonthOffset = currentMonthOffset;
    currentMonthOffset = CakeCal.getDayOfWeek(new SimpleDate((newMonth), 1, currentYear));
    miniDays[(currentDay - 1) + pastMonthOffset].setForeground(Color.black);
    currentMonth = newMonth;
    miniCalTitle.setText(curMonths[currentMonth - 1] + ", " + currentYear);
    events =
        calendar.getEvents(
            Period.parse(
                currentYear
                    + "."
                    + currentMonth
                    + ".1:00.00-"
                    + currentYear
                    + "."
                    + currentMonth
                    + "."
                    + curMonths[currentMonth - 1]
                    + ":24.00"));
    panelEvent.update();

    if (currentDay > (CakeCal.getMonths(currentYear))[currentMonth - 1]) {
      currentDay = (CakeCal.getMonths(currentYear))[currentMonth - 1];
    }
    updateDays();
    mview.updateMonth();
    dayView.updateDay();
    weekView.updateWeek();
    this.updateDays();
  }
Exemplo n.º 2
0
  /** Updates the days, and how they are viewed. */
  public void updateDays() {

    curMonths = CakeCal.getMonths(currentYear); // create the days in the particular month

    for (int i = 0; i < 42; i++) {
      if (i >= currentMonthOffset && i < curMonths[currentMonth - 1] + currentMonthOffset) {
        miniDays[i].setText(i - currentMonthOffset + 1 + "");
        miniDays[i].setName(i - currentMonthOffset + 1 + "");
        if (mview.hasEvents(new SimpleDate(currentMonth, i, currentYear)) == true) {
          miniDays[i].setToolTipText("You have events scheduled here.");
        } else {
          miniDays[i].setToolTipText("No events have been scheduled");
        }

        Border line = BorderFactory.createEtchedBorder(Color.BLACK, Color.BLACK);
        TitledBorder title = BorderFactory.createTitledBorder(line);
        miniDays[currentDay + (currentMonthOffset - 1)].setBorder(title);
        miniDays[currentDay + (currentMonthOffset - 1)].setFont(new Font("Verdana", Font.BOLD, 12));
      } else {
        miniDays[i].setToolTipText(null);
        miniDays[i].setText(" ");
        miniDays[i].setName(" ");
      }

      if (i == currentDay + currentMonthOffset - 1) {
        miniDays[i].setForeground(Color.red);
      }

      // Setting properly (one-digit) alignment in the mini calendar
      if (miniDays[i].getText().length() == 1) {
        String s = " " + miniDays[i].getText();
        miniDays[i].setText(s);
      }

      float[] n = new float[3];
      Color.RGBtoHSB(212, 208, 200, n);
      miniDays[i].setOpaque(true);
      miniDays[i].setBackground(Color.WHITE);
      miniDays[i].setForeground(Color.BLACK);
      miniDays[i].setFont(null);

      Border line = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
      TitledBorder title = BorderFactory.createTitledBorder(line);
      miniDays[i].setBorder(title);

      if (currentMonth == TODAYMONTH && currentYear == TODAYYEAR) {
        miniDays[(TODAYDAY - 1) + currentMonthOffset].setForeground(Color.RED);
        miniDays[(TODAYDAY - 1) + currentMonthOffset].setFont(new Font("Verdana", Font.BOLD, 12));
      }
    }

    if (DayToErase > 0) {
      miniDays[DayToErase].setForeground(Color.black);
      DayToErase = -1;
    }

    // This var holds the number of dates of the previous month
    int previousMonthDates = curMonths[((currentMonth - 2) + 12) % 12];

    float[] n = new float[3];
    Color.RGBtoHSB(200, 200, 200, n);

    for (int k = currentMonthOffset - 1; k >= 0; k--) {
      miniDays[k].setText(previousMonthDates + "");
      miniDays[k].setForeground(Color.GRAY);
      miniDays[k].setBackground(Color.getHSBColor(n[0], n[1], n[2]));
      previousMonthDates--;
    }

    int count = 1;
    for (int k = (curMonths[currentMonth - 1] + currentMonthOffset); k < 42; k++) {
      miniDays[k].setText(count + "");
      miniDays[k].setForeground(Color.GRAY);
      miniDays[k].setBackground(Color.getHSBColor(n[0], n[1], n[2]));
      count++;
    }

    String shortDate = " " + Cakeday.MONTHS[currentMonth - 1];
    title.setTitle(shortDate);

    bottomRight.setBorder(title);

    bottomRight.repaint();
    // ------------END OF---TITLED BORDER-------------

    // -------Updates the year in the JTextField in the mini calendar------//
    yearField.setText("" + currentYear);
    // -------Updates the year in the JTextField in the mini calendar------//

    smallMonth.repaint();

    weekView.updateWeek();
    dayView.updateDay();

    miniMonth.repaint();
  }
Exemplo n.º 3
0
  /**
   * On the mini month this method will always highlight the current day in red
   *
   * @param s The new day
   */
  public void highlightToday(int s) {

    // Creates border on the selected day
    for (int i = 0; i < 42; i++) {
      float[] n = new float[3];
      Color.RGBtoHSB(212, 208, 200, n);
      miniDays[i].setOpaque(true);
      miniDays[i].setForeground(Color.BLACK);
      miniDays[i].setFont(null);

      Border line = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
      TitledBorder title = BorderFactory.createTitledBorder(line);
      miniDays[i].setBorder(title);
    }

    // Creates the font for the selected day
    miniDays[(currentDay - 1) + currentMonthOffset].setForeground(Color.black);
    miniDays[(s - 1) + currentMonthOffset].setForeground(Color.BLACK);
    miniDays[(s - 1) + currentMonthOffset].setFont(new Font("Verdana", Font.BOLD, 12));
    miniDays[(s - 1) + currentMonthOffset].setOpaque(true);

    // Set the border of the selected date in the mini calendar
    Border line = BorderFactory.createEtchedBorder(Color.BLACK, Color.BLACK);
    TitledBorder title = BorderFactory.createTitledBorder(line);
    miniDays[(s - 1) + currentMonthOffset].setBorder(title);

    // miniDays[(s-1) + currentMonthOffset].setBackground(Color.WHITE);

    currentDay = s;
    if (currentMonth == TODAYMONTH && currentYear == TODAYYEAR) {
      // Highlights the current day in red when the current month and year is selected
      miniDays[(TODAYDAY - 1) + currentMonthOffset].setForeground(Color.RED);
      miniDays[(TODAYDAY - 1) + currentMonthOffset].setFont(new Font("Verdana", Font.BOLD, 12));
      DayToErase = (TODAYDAY - 1) + currentMonthOffset;
    } else if (DayToErase > 0) {
      // changes the current day back to black when the current month and year are not highlighted.
      miniDays[DayToErase].setForeground(Color.black);
      DayToErase = -1;
    }

    // This var holds the number of dates of the previous month
    int previousMonthDates = curMonths[((currentMonth - 2) + 12) % 12];

    for (int k = currentMonthOffset - 1; k >= 0; k--) {
      miniDays[k].setText(previousMonthDates + "");
      miniDays[k].setForeground(Color.GRAY);
      previousMonthDates--;
    }

    // Testing

    // Testing
    // System.out.println("curMonths[currentMonth - 1] ==" + curMonths[currentMonth - 1]);

    int count = 1;
    for (int k = (curMonths[currentMonth - 1] + currentMonthOffset); k < 42; k++) {
      miniDays[k].setText(count + "");
      miniDays[k].setForeground(Color.GRAY);
      count++;
    }
    // Testing

    smallMonth.repaint();

    miniMonth.repaint();
    panelEvent.update();
    weekView.updateWeek();
  }