昨天看了 coldfusion 論壇的一個文章(http://www.5d.cn/bbs/newsdetail.asp?id=980498),誘發了寫一個簡單 eclipse 外掛程式的想法。
這是昨天晚上寫的程式
雖然沒有太大必要,但是還是有點用的,我把這個程式改造了一下,寫了個 eclipse 外掛程式
CalendarView.java
package com.eiffelqiu.tools;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.ui.part.ViewPart;
/**
* Calendar plugin for eclipse
*
* @author Qiu Hai Feng
* @version 1.0, Created on 2003-10-28 15:36:57
*/
public class CalendarView extends ViewPart {
Label label;
public CalendarView() {
}
public void createPartControl(Composite parent) {
label = new Label(parent, SWT.WRAP);
label.setText(CalendarImp.show());
}
public void setFocus() {
}
}
CalendarImp.java
package com.eiffelqiu.tools;
import java.util.*;
/**
* Calendar implementation
*
* @author Qiu Hai Feng
* @version 1.0, Created on 2003-10-28 15:36:57
*/
public class CalendarImp {
/**
* concate calendar output string
*
* @param void
* @return String
*/
public static String show() {
StringBuffer calString = new StringBuffer();
GregorianCalendar nowDate = new GregorianCalendar();
int today = nowDate.get(Calendar.DAY_OF_MONTH);
int month = nowDate.get(Calendar.MONTH);
nowDate.set(Calendar.DAY_OF_MONTH, 1);
int weekday = nowDate.get(Calendar.DAY_OF_WEEK);
calString.append("Sun Mon Tue Wed Thu Fri Sat/n" );
// indent first line of calendar
for (int i = Calendar.SUNDAY; i < weekday; i++)
calString.append(" " );
do {
// print the day
int day = nowDate.get(Calendar.DAY_OF_MONTH);
if (day < 10)
calString.append(" " );
calString.append( " " + day);
// mark current day with *
if (day == today)
calString.append("* " );
else
calString.append(" " );
if (weekday == Calendar.SATURDAY)
calString.append("/n" );
// advanced d to next day
nowDate.add(Calendar.DAY_OF_MONTH, 1);
weekday = nowDate.get(Calendar.DAY_OF_WEEK);
} while (nowDate.get(Calendar.MONTH) == month);
if (weekday != Calendar.SUNDAY)
calString.append("/n" );
return calString.toString();
}
}
plugin.xml
id="com.eiffelqiu.tools"
name="com.eiffelqiu.tools"
version="1.0.0">
id="com.eiffelqiu.tools.calendar"
name="Calendar" />
id="com.eiffelqiu.tools.calendar"
name="Eiffel tools"
category="com.eiffelqiu.tools.calendar"
class="com.eiffelqiu.tools.CalendarView" />
測試案例:
package com.eiffelqiu.tools;
import junit.framework.TestCase;
/**
* Calendar implementation
*
* @author Qiu Hai Feng
* @version 1.0, Created on 2003-10-28 15:36:57
*/
public class CalendarImpTest extends TestCase {
/**
* Constructor for CalendarImpTest.
* @param name
*/
public CalendarImpTest(String name) {
super(name);
}
public static void main(String[] args) {
junit.swingui.TestRunner.run(CalendarImpTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
}
public void testShow() {
assertTrue(!CalendarImp.show().equals(null));
assertEquals(CalendarImp.show(),CalendarImp.show());
}
}