pax_global_header 0000666 0000000 0000000 00000000064 11607311021 0014502 g ustar 00root root 0000000 0000000 52 comment=3856777a0ab3accc88c725c4e86847e18a35d283
swtcalendar-0.5/ 0000775 0000000 0000000 00000000000 11607311021 0013655 5 ustar 00root root 0000000 0000000 swtcalendar-0.5/MIT.txt 0000664 0000000 0000000 00000002022 11607311021 0015043 0 ustar 00root root 0000000 0000000 Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. swtcalendar-0.5/README.txt 0000664 0000000 0000000 00000001641 11607311021 0015355 0 ustar 00root root 0000000 0000000 Introduction
SWTCalendar is a port of Kai Toedter's JCalendar to Eclipse's SWT.
It is a GUI date picker for Java using SWT as the GUI toolkit.
SWTCalendar was designed to be a flexible component so developer can
embed a date picker in their application or create their own standalone date picker dialog.
Compile and Building
A build file is included in the distribution of SWTCalender.
It is required that you have ANT installed. Create a "lib" dir and put your copy of swt.jar in the "lib" directory.
You can name your own directory on where you want the swt.jar to reside as long as you modify the Ant script to reflect
your directory structure. Copy the required swt DLL file on the root directory.
The "jar" target builds the jar file from source.
Demos
"demo1" and "demo2" target of ant runs the examples included distribution.
Installation
Just put swtcalendar.jar in your classpath :)
swtcalendar-0.5/build.xml 0000664 0000000 0000000 00000002071 11607311021 0015476 0 ustar 00root root 0000000 0000000
swtcalendar-0.5/src/ 0000775 0000000 0000000 00000000000 11607311021 0014444 5 ustar 00root root 0000000 0000000 swtcalendar-0.5/src/demo/ 0000775 0000000 0000000 00000000000 11607311021 0015370 5 ustar 00root root 0000000 0000000 swtcalendar-0.5/src/demo/DialogDemo.java 0000664 0000000 0000000 00000003540 11607311021 0020241 0 ustar 00root root 0000000 0000000 package demo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
import org.vafada.swtcalendar.SWTCalendarEvent;
import org.vafada.swtcalendar.SWTCalendarListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DialogDemo {
public static void main(String[] args) {
final SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy");
final Display display = new Display();
Shell shell = new Shell(display);
FillLayout layout = new FillLayout();
shell.setLayout(layout);
final Text t = new Text(shell, SWT.BORDER);
Button b = new Button(shell, SWT.PUSH);
b.setText("Change Date");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
final SWTCalendarDialog cal = new SWTCalendarDialog(display);
cal.addDateChangedListener(new SWTCalendarListener() {
public void dateChanged(SWTCalendarEvent calendarEvent) {
t.setText(formatter.format(calendarEvent.getCalendar().getTime()));
}
});
if (t.getText() != null && t.getText().length() > 0) {
try {
Date d = formatter.parse(t.getText());
cal.setDate(d);
} catch (ParseException pe) {
}
}
cal.open();
}
});
shell.open();
shell.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
swtcalendar-0.5/src/demo/EmbeddedDemo.java 0000664 0000000 0000000 00000006532 11607311021 0020537 0 ustar 00root root 0000000 0000000 package demo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
import org.vafada.swtcalendar.SWTCalendar;
import org.vafada.swtcalendar.SWTCalendarEvent;
import org.vafada.swtcalendar.SWTCalendarListener;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
public class EmbeddedDemo {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.CLOSE);
RowLayout rowLayout = new RowLayout();
rowLayout.type = SWT.VERTICAL;
shell.setLayout(rowLayout);
final Label l = new Label(shell, SWT.NONE);
RowData data = new RowData(200, SWT.DEFAULT);
l.setLayoutData(data);
Composite localePanel = new Composite(shell, SWT.NONE);
localePanel.setLayout(new RowLayout());
Label localeLabel = new Label(localePanel, SWT.NONE);
localeLabel.setText("Locale:");
final Combo localeCombo = new Combo(localePanel, SWT.DROP_DOWN | SWT.READ_ONLY);
Locale[] temp = Calendar.getAvailableLocales();
int count = 0;
for (int i = 0; i < temp.length; i++) {
if (temp[i].getCountry().length() > 0) {
count++;
}
}
final Locale[] locales = new Locale[count];
count = 0;
for (int i = 0; i < temp.length; i++) {
if (temp[i].getCountry().length() > 0) {
locales[count] = temp[i];
localeCombo.add(locales[count].getDisplayName());
count++;
}
}
for (int i = 0; i < locales.length; i++) {
if (locales[i].equals(Locale.getDefault())) {
localeCombo.select(i);
break;
}
}
final SWTCalendar c = new SWTCalendar(shell, SWT.NONE | SWTCalendar.RED_SUNDAY);
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
l.setText(df.format(c.getCalendar().getTime()));
c.addSWTCalendarListener(new SWTCalendarListener() {
public void dateChanged(SWTCalendarEvent calendarEvent) {
Locale _locale = locales[localeCombo.getSelectionIndex()];
DateFormat df2 = DateFormat.getDateInstance(DateFormat.LONG, _locale);
l.setText(df2.format(calendarEvent.getCalendar().getTime()));
}
});
localeCombo.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
Locale _locale = locales[localeCombo.getSelectionIndex()];
DateFormat df2 = DateFormat.getDateInstance(DateFormat.LONG, _locale);
l.setText(df2.format(c.getCalendar().getTime()));
c.setLocale(_locale);
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
swtcalendar-0.5/src/demo/SWTCalendarDialog.java 0000664 0000000 0000000 00000002450 11607311021 0021463 0 ustar 00root root 0000000 0000000 package demo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.vafada.swtcalendar.SWTCalendar;
import org.vafada.swtcalendar.SWTCalendarListener;
import java.util.Calendar;
import java.util.Date;
public class SWTCalendarDialog {
private Shell shell;
private SWTCalendar swtcal;
private Display display;
public SWTCalendarDialog(Display display) {
this.display = display;
shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.CLOSE);
shell.setLayout(new RowLayout());
swtcal = new SWTCalendar(shell);
}
public void open() {
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
public Calendar getCalendar() {
return swtcal.getCalendar();
}
public void setDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
swtcal.setCalendar(calendar);
}
public void addDateChangedListener(SWTCalendarListener listener) {
swtcal.addSWTCalendarListener(listener);
}
}
swtcalendar-0.5/src/org/ 0000775 0000000 0000000 00000000000 11607311021 0015233 5 ustar 00root root 0000000 0000000 swtcalendar-0.5/src/org/vafada/ 0000775 0000000 0000000 00000000000 11607311021 0016455 5 ustar 00root root 0000000 0000000 swtcalendar-0.5/src/org/vafada/swtcalendar/ 0000775 0000000 0000000 00000000000 11607311021 0020764 5 ustar 00root root 0000000 0000000 swtcalendar-0.5/src/org/vafada/swtcalendar/RepeatingButton.java 0000664 0000000 0000000 00000012560 11607311021 0024745 0 ustar 00root root 0000000 0000000 /*
* RepeatingButton.java - A push button that repeats selection event based on timer.
* Author: Sergey Prigogin
* swtcalendar.sourceforge.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.vafada.swtcalendar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import java.util.ArrayList;
/**
* Push button that repeats selection event based on timer.
*/
public class RepeatingButton extends Button {
public static final int DEFAULT_INITIAL_REPEAT_DELAY = 200; // Milliseconds
public static final int DEFAULT_REPEAT_DELAY = 50; // Milliseconds
private int initialRepeatDelay = DEFAULT_INITIAL_REPEAT_DELAY;
private int repeatDelay = DEFAULT_REPEAT_DELAY;
private ArrayList selectionListeners = new ArrayList(3);
private Repeater repeater;
/**
* @param parent Parent container.
* @param style Button style.
*/
public RepeatingButton(Composite parent, int style) {
super(parent, style);
addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
cancelRepeater();
if (event.button == 1) { // Left click
buttonPressed(event.stateMask, event.time);
repeater = new Repeater(event.stateMask);
getDisplay().timerExec(initialRepeatDelay, repeater);
}
}
public void mouseUp(MouseEvent event) {
if (event.button == 1) { // Left click
cancelRepeater();
}
}
});
addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
cancelRepeater();
}
});
}
public void addSelectionListener(SelectionListener listener) {
selectionListeners.add(listener);
}
public void removeSelectionListener(SelectionListener listener) {
selectionListeners.remove(listener);
}
/**
* @return Returns the initial repeat delay in milliseconds.
*/
public int getInitialRepeatDelay() {
return initialRepeatDelay;
}
/**
* @param initialRepeatDelay The new initial repeat delay in milliseconds.
*/
public void setInitialRepeatDelay(int initialRepeatDelay) {
this.initialRepeatDelay = initialRepeatDelay;
}
/**
* @return Returns the repeat delay in millisecons.
*/
public int getRepeatDelay() {
return repeatDelay;
}
/**
* @param repeatDelay The new repeat delay in milliseconds.
*/
public void setRepeatDelay(int repeatDelay) {
this.repeatDelay = repeatDelay;
}
private void buttonPressed(int stateMask, int time) {
SelectionListener[] listeners = new SelectionListener[selectionListeners.size()];
selectionListeners.toArray(listeners);
for (int i = 0; i < listeners.length; i++) {
SelectionListener l = listeners[i];
Event event = new Event();
event.type = SWT.Selection;
event.display = getDisplay();
event.widget = this;
event.stateMask = stateMask;
event.time = time;
l.widgetSelected(new SelectionEvent(event));
}
}
private void cancelRepeater() {
if (repeater != null) {
repeater.cancel();
repeater = null;
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Widget#checkSubclass()
*/
protected void checkSubclass() {
}
private class Repeater implements Runnable {
private boolean canceled;
private int stateMask;
public Repeater(int stateMask) {
super();
this.stateMask = stateMask;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
if (!canceled) {
buttonPressed(stateMask, (int) System.currentTimeMillis());
getDisplay().timerExec(repeatDelay, this);
}
}
public void cancel() {
canceled = true;
}
}
} swtcalendar-0.5/src/org/vafada/swtcalendar/SWTCalendar.java 0000664 0000000 0000000 00000020537 11607311021 0023745 0 ustar 00root root 0000000 0000000 /*
* SWTCalendar.java - A calendar component for SWT
* Author: Mark Bryan Yu
* Modified by: Sergey Prigogin
* swtcalendar.sourceforge.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.vafada.swtcalendar;
import java.util.Calendar;
import java.util.Locale;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Spinner;
public class SWTCalendar extends Composite {
/**
* Style constant for making Sundays red.
*/
public static final int RED_SUNDAY = SWTDayChooser.RED_SUNDAY;
/**
* Style constant for making weekends red.
*/
public static final int RED_WEEKEND = SWTDayChooser.RED_WEEKEND;
private boolean settingDate;
private Spinner yearChooser;
private SWTMonthChooser monthChooser;
private SWTDayChooser dayChooser;
private boolean settingYearMonth;
/**
* Constructs a calendar control.
*
* @param parent a parent container.
* @param style FLAT to make the buttons flat, or NONE.
*/
public SWTCalendar(Composite parent, int style) {
super(parent, (style & ~(SWT.FLAT | RED_WEEKEND)));
Calendar calendar = Calendar.getInstance();
{
final GridLayout gridLayout = new GridLayout();
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 2;
gridLayout.verticalSpacing = 2;
setLayout(gridLayout);
}
final Composite header = new Composite(this, SWT.NONE);
{
{
final GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
header.setLayoutData(gridData);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
header.setLayout(gridLayout);
}
final RepeatingButton prevMonthButton = new RepeatingButton(header, SWT.ARROW | SWT.LEFT | SWT.CENTER | (style & SWT.FLAT));
prevMonthButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
prevMonthButton.setRepeatDelay(100);
prevMonthButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
previousMonth();
}
});
final Composite composite = new Composite(header, SWT.NONE);
composite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_CENTER));
{
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
composite.setLayout(gridLayout);
}
header.setTabList(new Control[]{composite});
monthChooser = new SWTMonthChooser(composite);
monthChooser.setLayoutData(new GridData(GridData.FILL_VERTICAL));
monthChooser.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!settingYearMonth) {
dayChooser.setMonth(monthChooser.getMonth());
}
}
});
yearChooser = new Spinner(composite, SWT.BORDER);
yearChooser.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
yearChooser.setMinimum(1);
yearChooser.setMaximum(9999);
yearChooser.setIncrement(1);
yearChooser.setPageIncrement(10);
yearChooser.setSelection(calendar.get(Calendar.YEAR));
yearChooser.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!settingYearMonth) {
dayChooser.setYear(yearChooser.getSelection());
}
}
});
final RepeatingButton nextMonthButton = new RepeatingButton(header, SWT.ARROW | SWT.RIGHT | SWT.CENTER | (style & SWT.FLAT));
nextMonthButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
nextMonthButton.setRepeatDelay(100);
nextMonthButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
nextMonth();
}
});
}
{
dayChooser = new SWTDayChooser(this, SWT.BORDER | (style & RED_WEEKEND));
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
dayChooser.setLayoutData(gridData);
dayChooser.addSWTCalendarListener(new SWTCalendarListener() {
public void dateChanged(SWTCalendarEvent event) {
refreshYearMonth(event.getCalendar());
}
});
}
setTabList(new Control[]{header, dayChooser});
setFont(parent.getFont());
}
public SWTCalendar(Composite parent) {
this(parent, SWT.FLAT);
}
public void setCalendar(Calendar cal) {
settingDate = true;
try {
refreshYearMonth(cal);
dayChooser.setCalendar(cal);
} finally {
settingDate = false;
}
}
private void refreshYearMonth(Calendar cal) {
settingYearMonth = true;
yearChooser.setSelection(cal.get(Calendar.YEAR));
monthChooser.setMonth(cal.get(Calendar.MONTH));
settingYearMonth = false;
}
public void nextMonth() {
Calendar cal = dayChooser.getCalendar();
cal.add(Calendar.MONTH, 1);
refreshYearMonth(cal);
dayChooser.setCalendar(cal);
}
public void previousMonth() {
Calendar cal = dayChooser.getCalendar();
cal.add(Calendar.MONTH, -1);
refreshYearMonth(cal);
dayChooser.setCalendar(cal);
}
public Calendar getCalendar() {
return dayChooser.getCalendar();
}
public void addSWTCalendarListener(SWTCalendarListener listener) {
dayChooser.addSWTCalendarListener(listener);
}
public void removeSWTCalendarListener(SWTCalendarListener listener) {
dayChooser.removeSWTCalendarListener(listener);
}
public void setLocale(Locale locale) {
monthChooser.setLocale(locale);
dayChooser.setLocale(locale);
yearChooser.setSelection(getCalendar().get(Calendar.YEAR));
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font)
*/
public void setFont(Font font) {
super.setFont(font);
monthChooser.setFont(font);
yearChooser.setFont(font);
dayChooser.setFont(font);
}
public boolean isSettingDate() {
return settingDate;
}
}
swtcalendar-0.5/src/org/vafada/swtcalendar/SWTCalendarEvent.java 0000664 0000000 0000000 00000003160 11607311021 0024740 0 ustar 00root root 0000000 0000000 /*
* SWTCalendarEvent.java - The event created when the user changes the date.
* Mark Bryan Yu
* swtcalendar.sourceforge.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.vafada.swtcalendar;
import org.eclipse.swt.events.TypedEvent;
import org.eclipse.swt.widgets.Event;
import java.util.Calendar;
public class SWTCalendarEvent extends TypedEvent {
static final long serialVersionUID = -4525931268845275613L;
public SWTCalendarEvent(Event event) {
super(event);
}
public Calendar getCalendar() {
return (Calendar) this.data;
}
}
swtcalendar-0.5/src/org/vafada/swtcalendar/SWTCalendarListener.java 0000664 0000000 0000000 00000002656 11607311021 0025455 0 ustar 00root root 0000000 0000000 /*
* SWTCalendarListener.java - An interface for notifying for date changed
* Mark Bryan Yu
* swtcalendar.sourceforge.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.vafada.swtcalendar;
import org.eclipse.swt.internal.SWTEventListener;
public interface SWTCalendarListener extends SWTEventListener {
public void dateChanged(SWTCalendarEvent event);
}
swtcalendar-0.5/src/org/vafada/swtcalendar/SWTDayChooser.java 0000664 0000000 0000000 00000051015 11607311021 0024267 0 ustar 00root root 0000000 0000000 /*
* SWTDayChooser.java - A day chooser component for SWT
* Author: Mark Bryan Yu
* Modified by: Sergey Prigogin
* swtcalendar.sourceforge.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.vafada.swtcalendar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
public class SWTDayChooser extends Composite
implements MouseListener, FocusListener, TraverseListener, KeyListener {
/**
* Style constant for making Sundays red.
*/
public static final int RED_SUNDAY = 1 << 24; // == SWT.EMBEDDED
/**
* Style constant for making Saturdays red.
*/
public static final int RED_SATURDAY = 1 << 28; // == SWT.VIRTUAL
/**
* Style constant for making weekends red.
*/
public static final int RED_WEEKEND = RED_SATURDAY | RED_SUNDAY;
private Label[] dayTitles;
private DayControl[] days;
private int dayOffset;
private Color activeSelectionBackground;
private Color inactiveSelectionBackground;
private Color activeSelectionForeground;
private Color inactiveSelectionForeground;
private Color otherMonthColor;
private Calendar calendar;
private Calendar today;
private Locale locale;
private List listeners;
private int style;
public SWTDayChooser(Composite parent, int style) {
super(parent, style & ~RED_WEEKEND);
this.style = style;
listeners = new ArrayList(3);
setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
otherMonthColor = new Color(getDisplay(), 128, 128, 128);
activeSelectionBackground = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
inactiveSelectionBackground = getDisplay().getSystemColor(SWT.COLOR_GRAY);
activeSelectionForeground = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
inactiveSelectionForeground = getForeground();
locale = Locale.getDefault();
GridLayout gridLayout = new GridLayout();
gridLayout.makeColumnsEqualWidth = true;
gridLayout.numColumns = 7;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
setLayout(gridLayout);
dayTitles = new Label[7];
for (int i = 0; i < dayTitles.length; i++) {
Label label = new Label(this, SWT.CENTER);
dayTitles[i] = label;
label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
label.addMouseListener(this);
}
{
final Composite spacer = new Composite(this, SWT.NO_FOCUS);
spacer.setBackground(getBackground());
final GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 2;
gridData.horizontalSpan = 7;
spacer.setLayoutData(gridData);
spacer.setLayout(new GridLayout());
spacer.addMouseListener(this);
}
{
final Label label = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR);
final GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 7;
label.setLayoutData(gridData);
}
days = new DayControl[42];
for (int i = 0; i < days.length; i++) {
DayControl day = new DayControl(this);
days[i] = day;
day.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
day.addMouseListener(this);
}
setTabList(new Control[0]);
setFont(parent.getFont());
init();
addMouseListener(this);
addFocusListener(this);
addTraverseListener(this);
addKeyListener(this);
addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
otherMonthColor.dispose();
}
});
}
protected void init() {
calendar = Calendar.getInstance(locale);
calendar.setLenient(true);
today = (Calendar) calendar.clone();
int firstDayOfWeek = calendar.getFirstDayOfWeek();
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
String[] dayNames = dateFormatSymbols.getShortWeekdays();
int minLength = Integer.MAX_VALUE;
for (int i = 0; i < dayNames.length; i++) {
int len = dayNames[i].length();
if (len > 0 && len < minLength) {
minLength = len;
}
}
if (minLength > 2) {
for (int i = 0; i < dayNames.length; i++) {
if (dayNames[i].length() > 0) {
//as suggested by yunjie liu, Because in Chinese the dayNames display as *** ,but only the third word are the keywords.
if (locale.equals(Locale.CHINA)) {
if (dayNames[i].length() > 2) {
dayNames[i] = dayNames[i].substring(2, 3);
}
}else {
if (dayNames[i].length() > 0) {
dayNames[i] = dayNames[i].substring(0, 1);
}
}
}
}
}
int d = firstDayOfWeek;
for (int i = 0; i < dayTitles.length; i++) {
Label label = dayTitles[i];
label.setText(dayNames[d]);
label.setBackground(getBackground());
if (d == Calendar.SUNDAY && (style & RED_SUNDAY) != 0 ||
d == Calendar.SATURDAY && (style & RED_SATURDAY) != 0) {
label.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
} else {
label.setForeground(getForeground());
}
d++;
if (d > dayTitles.length) {
d -= dayTitles.length;
}
}
drawDays();
}
protected void drawDays() {
calendar.get(Calendar.DAY_OF_YEAR); // Force calendar update
Calendar cal = (Calendar) calendar.clone();
int firstDayOfWeek = cal.getFirstDayOfWeek();
cal.set(Calendar.DAY_OF_MONTH, 1);
dayOffset = firstDayOfWeek - cal.get(Calendar.DAY_OF_WEEK);
if (dayOffset >= 0) {
dayOffset -= 7;
}
cal.add(Calendar.DAY_OF_MONTH, dayOffset);
Color foregroundColor = getForeground();
for (int i = 0; i < days.length; cal.add(Calendar.DAY_OF_MONTH, 1)) {
DayControl dayControl = days[i++];
dayControl.setText(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)));
if (isSameDay(cal, today)) {
dayControl.setBorderColor(getDisplay().getSystemColor(SWT.COLOR_BLACK));
} else {
dayControl.setBorderColor(getBackground());
}
if (isSameMonth(cal, calendar)) {
int d = cal.get(Calendar.DAY_OF_WEEK);
if (d == Calendar.SUNDAY && (style & RED_SUNDAY) != 0 ||
d == Calendar.SATURDAY && (style & RED_SATURDAY) != 0) {
dayControl.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
} else {
dayControl.setForeground(foregroundColor);
}
} else {
dayControl.setForeground(otherMonthColor);
}
if (isSameDay(cal, calendar)) {
dayControl.setBackground(getSelectionBackgroundColor());
dayControl.setForeground(getSelectionForegroundColor());
} else {
dayControl.setBackground(getBackground());
}
}
}
private static boolean isSameDay(Calendar cal1, Calendar cal2) {
return cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR);
}
private static boolean isSameMonth(Calendar cal1, Calendar cal2) {
return cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR);
}
public void setMonth(int month) {
calendar.set(Calendar.MONTH, month);
drawDays();
dateChanged();
}
public void setYear(int year) {
calendar.set(Calendar.YEAR, year);
drawDays();
dateChanged();
}
public void setCalendar(Calendar cal) {
calendar = (Calendar) cal.clone();
calendar.setLenient(true);
drawDays();
dateChanged();
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
*/
public void mouseDown(MouseEvent event) {
if (event.button == 1) { // Left click
setFocus();
if (event.widget instanceof DayControl) {
int index = findDay(event.widget);
selectDay(index + 1 + dayOffset);
}
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
*/
public void mouseDoubleClick(MouseEvent event) {
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
public void mouseUp(MouseEvent event) {
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
*/
public void focusGained(FocusEvent event) {
DayControl selectedDay = getSelectedDayControl();
selectedDay.setBackground(getSelectionBackgroundColor());
selectedDay.setForeground(getSelectionForegroundColor());
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
*/
public void focusLost(FocusEvent event) {
DayControl selectedDay = getSelectedDayControl();
selectedDay.setBackground(getSelectionBackgroundColor());
selectedDay.setForeground(getSelectionForegroundColor());
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
*/
public void keyTraversed(TraverseEvent event) {
switch (event.detail) {
case SWT.TRAVERSE_ARROW_PREVIOUS:
case SWT.TRAVERSE_ARROW_NEXT:
case SWT.TRAVERSE_PAGE_PREVIOUS:
case SWT.TRAVERSE_PAGE_NEXT:
event.doit = false;
break;
case SWT.TRAVERSE_TAB_NEXT:
case SWT.TRAVERSE_TAB_PREVIOUS:
event.doit = true;
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
*/
public void keyPressed(KeyEvent event) {
switch (event.keyCode) {
case SWT.ARROW_LEFT:
selectDay(calendar.get(Calendar.DAY_OF_MONTH) - 1);
break;
case SWT.ARROW_RIGHT:
selectDay(calendar.get(Calendar.DAY_OF_MONTH) + 1);
break;
case SWT.ARROW_UP:
selectDay(calendar.get(Calendar.DAY_OF_MONTH) - 7);
break;
case SWT.ARROW_DOWN:
selectDay(calendar.get(Calendar.DAY_OF_MONTH) + 7);
break;
case SWT.PAGE_UP:
setMonth(calendar.get(Calendar.MONTH) - 1);
break;
case SWT.PAGE_DOWN:
setMonth(calendar.get(Calendar.MONTH) + 1);
break;
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
*/
public void keyReleased(KeyEvent event) {
}
/**
* Finds position of a control in days
array.
*
* @param dayControl a control to find.
* @return an index of dayControl
in days
array, or -1 if not found.
*/
private int findDay(Widget dayControl) {
for (int i = 0; i < days.length; i++) {
if (days[i] == dayControl) {
return i;
}
}
return -1;
}
private void selectDay(int day) {
calendar.get(Calendar.DAY_OF_YEAR); // Force calendar update
if (day >= calendar.getActualMinimum(Calendar.DAY_OF_MONTH) && day <= calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) {
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
// Stay on the same month.
DayControl selectedDay = getSelectedDayControl();
selectedDay.setBackground(getBackground());
if (dayOfWeek == Calendar.SUNDAY) {
selectedDay.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
} else {
selectedDay.setForeground(getForeground());
}
calendar.set(Calendar.DAY_OF_MONTH, day);
selectedDay = getSelectedDayControl();
selectedDay.setBackground(getSelectionBackgroundColor());
selectedDay.setForeground(getSelectionForegroundColor());
} else {
// Move to a different month.
calendar.set(Calendar.DAY_OF_MONTH, day);
drawDays();
}
dateChanged();
}
private DayControl getSelectedDayControl() {
return days[calendar.get(Calendar.DAY_OF_MONTH) - 1 - dayOffset];
}
private Color getSelectionBackgroundColor() {
return isFocusControl() ? activeSelectionBackground : inactiveSelectionBackground;
}
private Color getSelectionForegroundColor() {
return isFocusControl() ? activeSelectionForeground : inactiveSelectionForeground;
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#isFocusControl()
*/
public boolean isFocusControl() {
for (Control control = getDisplay().getFocusControl(); control != null; control = control.getParent()) {
if (control == this) {
return true;
}
}
return false;
}
public void addSWTCalendarListener(SWTCalendarListener listener) {
this.listeners.add(listener);
}
public void removeSWTCalendarListener(SWTCalendarListener listener) {
this.listeners.remove(listener);
}
private void dateChanged() {
if (!listeners.isEmpty()) {
SWTCalendarListener[] listenersArray = new SWTCalendarListener[listeners.size()];
listeners.toArray(listenersArray);
for (int i = 0; i < listenersArray.length; i++) {
Event event = new Event();
event.widget = this;
event.display = getDisplay();
event.time = (int) System.currentTimeMillis();
event.data = calendar.clone();
listenersArray[i].dateChanged(new SWTCalendarEvent(event));
}
}
}
public Calendar getCalendar() {
return (Calendar) calendar.clone();
}
public void setLocale(Locale locale) {
this.locale = locale;
init();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font)
*/
public void setFont(Font font) {
super.setFont(font);
for (int i = 0; i < dayTitles.length; i++) {
dayTitles[i].setFont(font);
}
for (int i = 0; i < days.length; i++) {
days[i].setFont(font);
}
}
static private class DayControl extends Composite implements Listener {
private Composite filler;
private Label label;
public DayControl(Composite parent) {
super(parent, SWT.NO_FOCUS);
{
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 1;
gridLayout.marginHeight = 1;
setLayout(gridLayout);
}
filler = new Composite(this, SWT.NO_FOCUS);
filler.setLayoutData(new GridData(GridData.FILL_BOTH));
{
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 2;
gridLayout.marginHeight = 0;
filler.setLayout(gridLayout);
}
filler.addListener(SWT.MouseDown, this);
filler.addListener(SWT.MouseUp, this);
filler.addListener(SWT.MouseDoubleClick, this);
label = new DayLabel(filler, SWT.RIGHT | SWT.NO_FOCUS);
label.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_CENTER));
label.addListener(SWT.MouseDown, this);
label.addListener(SWT.MouseUp, this);
label.addListener(SWT.MouseDoubleClick, this);
setBorderColor(parent.getBackground());
setBackground(parent.getBackground());
setFont(parent.getFont());
}
public void setText(String text) {
label.setText(text);
}
public String getText() {
return label.getText();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font)
*/
public void setFont(Font font) {
super.setFont(font);
filler.setFont(font);
label.setFont(font);
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setBackground(org.eclipse.swt.graphics.Color)
*/
public void setBackground(Color color) {
filler.setBackground(color);
label.setBackground(color);
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setForeground(org.eclipse.swt.graphics.Color)
*/
public void setForeground(Color color) {
label.setForeground(color);
}
public void setBorderColor(Color color) {
super.setBackground(color);
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event event) {
notifyListeners(event.type, event);
}
}
static private class DayLabel extends Label {
public DayLabel(Composite parent, int style) {
super(parent, style);
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
*/
public Point computeSize(int wHint, int hHint, boolean changed) {
if (wHint == SWT.DEFAULT) {
GC gc = new GC(this);
wHint = gc.textExtent("22").x; //$NON-NLS-1$
gc.dispose();
}
return super.computeSize(wHint, hHint, changed);
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Widget#checkSubclass()
*/
protected void checkSubclass() {
}
}
}
swtcalendar-0.5/src/org/vafada/swtcalendar/SWTMonthChooser.java 0000664 0000000 0000000 00000007223 11607311021 0024641 0 ustar 00root root 0000000 0000000 /*
* SWTMonthChooser.java - A month chooser component for SWT
* Author: Mark Bryan Yu
* Modified by: Sergey Prigogin
* swtcalendar.sourceforge.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.vafada.swtcalendar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;
public class SWTMonthChooser extends Composite {
private SWTDayChooser dayChooser;
private Combo comboBox;
private Locale locale;
public SWTMonthChooser(Composite parent) {
super(parent, SWT.NONE);
locale = Locale.getDefault();
setLayout(new FillLayout());
comboBox = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
initNames();
setMonth(Calendar.getInstance().get(Calendar.MONTH));
setFont(parent.getFont());
}
private void initNames() {
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
String[] monthNames = dateFormatSymbols.getMonths();
int month = comboBox.getSelectionIndex();
if (comboBox.getItemCount() > 0) {
comboBox.removeAll();
}
for (int i = 0; i < monthNames.length; i++) {
String name = monthNames[i];
if (name.length() > 0) {
comboBox.add(name);
}
}
if (month < 0) {
month = 0;
} else if (month >= comboBox.getItemCount()) {
month = comboBox.getItemCount() - 1;
}
comboBox.select(month);
}
public void addSelectionListener(SelectionListener listener) {
comboBox.addSelectionListener(listener);
}
public void removeSelectionListener(SelectionListener listener) {
comboBox.removeSelectionListener(listener);
}
public void setMonth(int newMonth) {
comboBox.select(newMonth);
}
public int getMonth() {
return comboBox.getSelectionIndex();
}
public void setLocale(Locale locale) {
this.locale = locale;
initNames();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font)
*/
public void setFont(Font font) {
super.setFont(font);
comboBox.setFont(getFont());
}
}