📄 htmlcompactweekview.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Christopher Kohlhaas |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by the |
| Free Software Foundation. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.components.calendarview.html;
import java.util.*;
import org.rapla.components.calendarview.Block;
import org.rapla.components.calendarview.Builder;
import org.rapla.components.calendarview.swing.SwingWeekView;
public class HTMLCompactWeekView extends AbstractHTMLView {
public final static int ROWS = 6; //without the header row
public final static int COLUMNS = 7;
/** shared calendar instance. Only used for temporary stored values. */
HTMLSmallDaySlot[] slots = {};
String[] slotNames = {};
private ArrayList rows = new ArrayList();
private boolean[] excluded = new boolean[COLUMNS];
void calcMinMaxDates(Date date) {
Calendar calendar = createCalendar();
calendar.setTime(date);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
startDate = null;
endDate = null;
for (int i=0;i<COLUMNS;i++) {
if ( this.startDate == null ) {
this.startDate = calendar.getTime();
}
calendar.add(Calendar.DATE,1);
this.endDate = calendar.getTime();
}
}
public void setSlots( String[] slotNames ) {
this.slotNames = slotNames;
}
public Collection getBlocks() {
ArrayList list = new ArrayList();
for (int i=0;i<slots.length;i++) {
list.addAll(slots[i]);
}
return Collections.unmodifiableCollection( list );
}
/** must be called after the slots are filled*/
private boolean isExcluded( int column) {
return excluded[ column ];
}
public void rebuild() {
String[] headerNames = new String[COLUMNS];
blockCalendar.setTime(getStartDate());
for (int i=0;i<COLUMNS;i++) {
int index = weekdayMapper.indexForDay( blockCalendar.get ( Calendar.DAY_OF_WEEK ) );
headerNames[index] = SwingWeekView.formatDayOfWeekDateMonth
(blockCalendar.getTime()
,locale
,timeZone
);
blockCalendar.add(Calendar.DATE, 1);
int weekday = weekdayMapper.dayForIndex( i );
if ( excludeDays.contains(new Integer( weekday )) ) {
excluded[i] = true;
} else {
excluded[i] = false;
}
}
rows.clear();
for ( int i=0; i<slotNames.length; i++ ) {
addRow();
}
// calculate the blocks
Iterator it= builders.iterator();
while (it.hasNext()) {
Builder b= (Builder)it.next();
b.prepareBuild(getStartDate(),getEndDate());
}
// build Blocks
it= builders.iterator();
while (it.hasNext()) {
Builder b= (Builder)it.next();
if (b.isEnabled()) { b.build(this); }
}
Calendar calendar = createCalendar();
calendar.setTime(startDate);
calendar.set( Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
// resource header
// add headers
StringBuffer result = new StringBuffer();
result.append("<table class=\"month_table\">\n");
result.append("<tr>\n");
result.append("<td class=\"empty_header\" width=\"14%\">");
result.append("</td>");
for (int i=0;i<COLUMNS;i++) {
if (isExcluded(i)) {
continue;
}
result.append("<td class=\"month_header\" width=\"14%\">");
result.append("<nobr>");
result.append(headerNames[i]);
result.append("</nobr>");
result.append("</td>");
}
result.append("\n</tr>");
int rowsize = rows.size();
slots = new HTMLSmallDaySlot[rowsize * COLUMNS];
for (int row=0;row<rowsize;row++) {
result.append("<tr>\n");
result.append("<td class=\"month_cell\" valign=\"top\" height=\"40\">\n");
if ( slotNames.length > row ) {
result.append( slotNames[ row ] );
}
result.append("</td>\n");
for (int column=0;column < COLUMNS; column++) {
List blocks = (List) rows.get( row );
int fieldNumber = row * COLUMNS + column;
slots[fieldNumber] = createField( blocks, column );
if ( !isExcluded( column ) ) {
result.append("<td class=\"month_cell\" valign=\"top\" height=\"40\">\n");
slots[fieldNumber].paint( result );
result.append("</td>\n");
}
}
result.append("</tr>\n");
}
result.append("</table>");
m_html = result.toString();
}
private HTMLSmallDaySlot createField(List blocks, int column) {
HTMLSmallDaySlot c = new HTMLSmallDaySlot("");
if ( blocks != null) {
Iterator it = blocks.iterator();
while (it.hasNext()){
HTMLBlock block = (HTMLBlock)it.next();
blockCalendar.setTime(block.getStart());
int day = blockCalendar.get(Calendar.DAY_OF_WEEK);
if ( weekdayMapper.indexForDay(day) == column ) {
c.putBlock( block );
}
}
}
c.sort();
return c;
};
public void addBlock(Block block, int slot) {
checkBlock( block );
while ( rows.size() <= slot ) {
addRow();
}
ArrayList blocks = (ArrayList) rows.get( slot );
blocks.add( block );
blockCalendar.setTime(block.getStart());
int weekday = blockCalendar.get(Calendar.DAY_OF_WEEK);
excluded[weekdayMapper.indexForDay( weekday )] = false;
}
private void addRow() {
rows.add( rows.size(), new ArrayList());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -