给eclipse 做个日历的插件

昨天看了 coldfusion 论坛的一个帖子(http://www.5d.cn/bbs/newsdetail.asp?id=980498),诱发了写一个简单 eclipse 插件的想法。

这是昨天晚上写的程序

给eclipse 做个日历的插件_第1张图片

虽然没有太大必要,但是还是有点用的,我把这个程序改造了一下,写了个 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());
}

你可能感兴趣的:(eclipse,exception,String,calendar,import,ColdFusion)