Make a calendar plugin for eclipse

Source: Internet
Author: User
Tags stringbuffer
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 ());
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.