給eclipse 做個日曆的外掛程式

來源:互聯網
上載者:User
昨天看了 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());
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.