001/*
002 * $Id: CalendarAdapter.java 3877 2010-11-03 11:36:33Z kleopatra $
003 *
004 * Copyright 2007 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 * 
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 * Lesser General Public License for more details.
016 * 
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020 *
021 */
022package org.jdesktop.swingx.plaf.basic;
023
024import java.util.Calendar;
025
026import org.jdesktop.swingx.JXMonthView;
027import org.jdesktop.swingx.decorator.ComponentAdapter;
028
029/**
030 * ComponentAdapter for a JXMonthView (experimental for internal use of BasicMonthViewUI).<p>
031 * 
032 * For now, this effectively disables all notion of row/column coordinates. It's focused
033 * on an externally provided date (as Calendar) and CalendarState. Yeah, I know, that's
034 * tweaking too much but then, I want to use highlighters which need an adapter...
035 *
036 * 
037 * @author Jeanette Winzenburg
038 */
039class CalendarAdapter extends ComponentAdapter {
040
041    Calendar calendar;
042    CalendarState dayState;
043
044    /**
045     * @param component
046     */
047    public CalendarAdapter(JXMonthView component) {
048        super(component);
049    }
050
051    /**
052     * @param calendar2
053     * @param dayState2
054     * @return
055     */
056    public CalendarAdapter install(Calendar calendar, CalendarState dayState) {
057        this.calendar = calendar;
058        this.dayState = dayState;
059        return this;
060    }
061
062
063    @Override
064    public JXMonthView getComponent() {
065        return (JXMonthView) super.getComponent();
066    }
067    
068    public CalendarState getCalendarState() {
069        return dayState;
070    }
071    
072    public boolean isFlagged() {
073        if (getComponent() == null || calendar == null) {
074            return false;
075        }
076        return getComponent().isFlaggedDate(calendar.getTime());
077    }
078    
079    public boolean isUnselectable() {
080        if (getComponent() == null || calendar == null || !isSelectable()) {
081            return false;
082        }
083        return getComponent().isUnselectableDate(calendar.getTime());
084    }
085
086    /**
087     * @param dayState
088     * @return
089     */
090    private boolean isSelectable() {
091        return (CalendarState.IN_MONTH == getCalendarState()) || (CalendarState.TODAY == getCalendarState());
092    }
093
094    @Override
095    public boolean isSelected() {
096        if (getComponent() == null || calendar == null) {
097            return false;
098        }
099        return getComponent().isSelected(calendar.getTime());
100    }
101    
102    
103    @Override
104    public Object getFilteredValueAt(int row, int column) {
105        return getValueAt(row, column);
106    }
107
108    @Override
109    public Object getValueAt(int row, int column) {
110        return calendar;
111    }
112    
113    @Override
114    public boolean hasFocus() {
115        return false;
116    }
117
118    @Override
119    public boolean isCellEditable(int row, int column) {
120        return false;
121    }
122
123    @Override
124    public boolean isEditable() {
125        return false;
126    }
127}