Yesterday I saw a post at the ColdFusion Forum (http://www.5d.cn/bbs/newsdetail.asp?id=980498), which evoked the idea of writing a simple eclipse plug-in.
This is the program I wrote last night.
It's not very necessary, but it's a bit of a use, I've changed the program and written an eclipse plugin
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");
Indent the 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"/>
Test Cases:
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 ());
}
}