diff options
author | Dave Orme | 2006-03-17 23:51:13 +0000 |
---|---|---|
committer | Dave Orme | 2006-03-17 23:51:13 +0000 |
commit | c86069e56d64fa7a860d145892249406df6eb55f (patch) | |
tree | 57a528a2167b16fee95e5eb0b382c0952df6d5b6 | |
parent | a523d852f0fb5bcb040e00018771133a80359927 (diff) | |
download | org.eclipse.e4.databinding-c86069e56d64fa7a860d145892249406df6eb55f.tar.gz org.eclipse.e4.databinding-c86069e56d64fa7a860d145892249406df6eb55f.tar.xz org.eclipse.e4.databinding-c86069e56d64fa7a860d145892249406df6eb55f.zip |
Added example day/time and month view controls to examples
10 files changed, 909 insertions, 0 deletions
diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/Day.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/Day.java new file mode 100644 index 00000000..b43ded94 --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/Day.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2005 David Orme <djo@coconut-palm-software.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Orme - Initial API and implementation + */ +package org.eclipse.jface.examples.databinding.compositetable.day; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontMetrics; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +/** + * @author djo + */ +public class Day extends Canvas { + + private boolean focusControl = false; + + private final Color WHITE; + private final Color BLACK; + private final Color CELL_BACKGROUND; + private final Color CELL_BORDER_EMPHASIZED; + private final Color CELL_BORDER_LIGHT; + + private final int TIME_BAR_WIDTH=6; + + /** + * Constructor EmptyTablePlaceholder. Construct an EmptyTablePlaceholder control. + * + * @param parent The parent control + * @param style Style bits. These are the same as what Canvas accepts. + */ + public Day(Composite parent, int style) { + super(parent, style); + + addTraverseListener(traverseListener); + addFocusListener(focusListener); + addPaintListener(paintListener); + addDisposeListener(disposeListener); + + Display display = Display.getCurrent(); + + WHITE = display.getSystemColor(SWT.COLOR_WHITE); + BLACK = display.getSystemColor(SWT.COLOR_BLACK); + + // Bluish color scheme by default; change as necessary. + CELL_BACKGROUND = new Color(display, 250, 250, 255); + CELL_BORDER_EMPHASIZED = new Color(display, 100, 100, 255); + CELL_BORDER_LIGHT = new Color(display, 200, 200, 255); + + setBackground(CELL_BACKGROUND); + } + + /** + * Make sure we remove our listeners... + */ + private DisposeListener disposeListener = new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + removeTraverseListener(traverseListener); + removeFocusListener(focusListener); + removePaintListener(paintListener); + removeDisposeListener(disposeListener); + + // Dispose colors here + CELL_BACKGROUND.dispose(); + CELL_BORDER_EMPHASIZED.dispose(); + CELL_BORDER_LIGHT.dispose(); + } + }; + + private Point preferredSize = new Point(-1, -1); + + public Point computeSize(int wHint, int hHint, boolean changed) { + if (preferredSize.x == -1 || changed) { + preferredSize.x = getSize().x; + Display display = Display.getCurrent(); + GC gc = new GC(display); + try { + Font font = display.getSystemFont(); + gc.setFont(font); + FontMetrics fm = gc.getFontMetrics(); + preferredSize.y = fm.getHeight(); + } finally { + gc.dispose(); + } + } + return preferredSize; + } + + /** + * Paint the control. + */ + private PaintListener paintListener = new PaintListener() { + public void paintControl(PaintEvent e) { + GC gc = e.gc; + Color oldForeground = gc.getForeground(); + Color oldBackground = gc.getBackground(); + Point controlSize = getSize(); + + // Draw basic background here + try { + // Draw "time bar" on left side + gc.setBackground(WHITE); + gc.setForeground(WHITE); + gc.fillRectangle(0, 0, TIME_BAR_WIDTH, controlSize.y); + gc.setForeground(BLACK); + gc.drawLine(TIME_BAR_WIDTH+1, 0, TIME_BAR_WIDTH+1, controlSize.y); + gc.drawLine(controlSize.x-1, 0, controlSize.x-1, controlSize.y); + if (hourStart) { + gc.setForeground(CELL_BORDER_EMPHASIZED); + } else { + gc.setForeground(CELL_BORDER_LIGHT); + } + gc.drawLine(TIME_BAR_WIDTH+2, 0, controlSize.x-2, 0); + } finally { + gc.setBackground(oldBackground); + gc.setForeground(oldForeground); + } + + // Draw focus rubberband if we're focused + int oldLineStyle = gc.getLineStyle(); + int oldLineWidth = gc.getLineWidth(); + try { + if (focusControl) { + gc.setLineStyle(SWT.LINE_DASH); + gc.setLineWidth(2); + Point parentSize = getSize(); + gc.drawRectangle(TIME_BAR_WIDTH+2, 2, parentSize.x-TIME_BAR_WIDTH-4, parentSize.y-3); + } + + gc.setForeground(CELL_BACKGROUND); + } finally { + gc.setForeground(oldForeground); + gc.setLineStyle(oldLineStyle); + gc.setLineWidth(oldLineWidth); + } + } + }; + + /** + * When we gain/lose focus, redraw ourselves appropriately + */ + private FocusListener focusListener = new FocusListener() { + public void focusGained(FocusEvent e) { + focusControl = true; + redraw(); + } + public void focusLost(FocusEvent e) { + focusControl = false; + redraw(); + } + }; + + /** + * Permit focus events via keyboard. + */ + private TraverseListener traverseListener = new TraverseListener() { + public void keyTraversed(TraverseEvent e) { + } + }; + + private boolean hourStart = true; + + public void setHourStart(boolean isHourStart) { + this.hourStart = isHourStart; + } + + public boolean isHourStart() { + return hourStart; + } +} + + diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/DayEditor.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/DayEditor.java new file mode 100644 index 00000000..1b96941c --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/DayEditor.java @@ -0,0 +1,70 @@ +package org.eclipse.jface.examples.databinding.compositetable.day; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import org.eclipse.jface.examples.databinding.compositetable.CompositeTable; +import org.eclipse.jface.examples.databinding.compositetable.IRowConstructionListener; +import org.eclipse.jface.examples.databinding.compositetable.IRowContentProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; + +public class DayEditor extends Composite { + private CompositeTable compositeTable = null; + + public DayEditor(Composite parent, int style) { + super(parent, style); + this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + this.setLayout(new FillLayout()); + } + + /** + * Method setTimeBreakdown. Call this method exactly once after constructing + * the day control in order to set the number of day columns to display. + * <p> + * This method may be executed exactly once. Executing more than once will + * result in undefined behavior. + * + * @param numberOfColumns The number of columns to display. + * @param numberOfDivisionsInHour 1 == one line per hour; 2 == every 1/2 hour; 4 = every 1/4 hour; etc... + */ + public void setTimeBreakdown(int numberOfColumns, int numberOfDivisionsInHour) { + if (numberOfDivisionsInHour < 1) { + throw new IllegalArgumentException("There must be at least one division in the hour"); + } + createCompositeTable(numberOfColumns, numberOfDivisionsInHour); + } + + /** + * This method initializes compositeTable + * + * @param numberOfColumns The number of day columns to display + */ + private void createCompositeTable(final int numberOfColumns, final int numberOfDivisionsInHour) { + compositeTable = new CompositeTable(this, SWT.NONE); + compositeTable.setNumRowsInCollection(24*numberOfDivisionsInHour); + compositeTable.setRunTime(true); + compositeTable.addRowConstructionListener(new IRowConstructionListener() { + public void rowConstructed(Control newRow) { + Days days = (Days) newRow; + days.setNumberOfColumns(numberOfColumns); + } + }); + compositeTable.addRowContentProvider(new IRowContentProvider() { + Calendar calendar = new GregorianCalendar(); + + public void refresh(CompositeTable sender, int currentObjectOffset, Control row) { + calendar.set(Calendar.HOUR_OF_DAY, currentObjectOffset / numberOfDivisionsInHour); + calendar.set(Calendar.MINUTE, (int)((double)currentObjectOffset%numberOfDivisionsInHour/numberOfDivisionsInHour*60)); + Days days = (Days) row; + days.setCurrentTime(calendar.getTime()); + } + }); + new Days(compositeTable, SWT.NONE); + } + + +} // @jve:decl-index=0:visual-constraint="10,10" diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/DayEditorTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/DayEditorTest.java new file mode 100644 index 00000000..dffda48d --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/DayEditorTest.java @@ -0,0 +1,56 @@ +package org.eclipse.jface.examples.databinding.compositetable.day; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +public class DayEditorTest { + + private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10" + private DayEditor dayEditor = null; + + /** + * This method initializes dayEditor + * + */ + private void createDayEditor() { + dayEditor = new DayEditor(sShell, SWT.NONE); + dayEditor.setTimeBreakdown(7, 4); + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + /* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments) + * for the correct SWT library path in order to run with the SWT dlls. + * The dlls are located in the SWT plugin jar. + * For example, on Windows the Eclipse SWT 3.1 plugin jar is: + * installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar + */ + Display display = Display.getDefault(); + DayEditorTest thisClass = new DayEditorTest(); + thisClass.createSShell(); + thisClass.sShell.open(); + while (!thisClass.sShell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + /** + * This method initializes sShell + */ + private void createSShell() { + sShell = new Shell(); + sShell.setText("Day Editor Test"); + sShell.setLayout(new FillLayout()); + createDayEditor(); + sShell.setSize(new org.eclipse.swt.graphics.Point(800,592)); + } + +} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/Days.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/Days.java new file mode 100644 index 00000000..0ec7ce59 --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/day/Days.java @@ -0,0 +1,154 @@ +package org.eclipse.jface.examples.databinding.compositetable.day; + +import java.text.DateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; +import java.util.LinkedList; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; + +public class Days extends Composite { + + /** + * The 0th control in the layout may have a java.lang.Integer LayoutData + * indicating its preferred width. Otherwise, DaysLayout will ask the + * control to compute its preferred size and will use the width returned + * by that computation. All other controls will be equally allotted + * horizontal width in the parent control. + */ + private static class DaysLayout extends Layout { + Point preferredSize = new Point(-1, -1); + + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + if (preferredSize.x == -1 || flushCache) { + preferredSize.x = wHint; + preferredSize.y = -1; // NOTE: This assumes at least one child control + Control[] children = composite.getChildren(); + for (int i = 0; i < children.length; i++) { + Control child = children[i]; + preferredSize.y = Math.max(preferredSize.y, child.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y); + } + } + return preferredSize; + } + + protected void layout(Composite composite, boolean flushCache) { + Point parentSize = composite.getSize(); + Control[] children = composite.getChildren(); + + // layout 0th control + Integer preferredWidth = (Integer) children[0].getLayoutData(); + if (preferredWidth == null) { + preferredWidth = new Integer(children[0].computeSize(SWT.DEFAULT, SWT.DEFAULT).x); + } + children[0].setBounds(0, 0, preferredWidth.intValue(), parentSize.y); + + // layout the rest of the controls + int controlWidth = (parentSize.x - preferredWidth.intValue()) / (children.length-1); + int extraWidth = (parentSize.x - preferredWidth.intValue()) % (children.length-1); + int leftPosition = preferredWidth.intValue(); + + for (int i = 1; i < children.length; i++) { + Control control = children[i]; + int width = controlWidth; + if (extraWidth > 0) { + ++width; + --extraWidth; + } + control.setBounds(leftPosition, 0, width, parentSize.y); + leftPosition += width; + } + } + } + + private LinkedList days = new LinkedList(); + private Label timeLabel = null; + + public Days(Composite parent, int style) { + super(parent, style); + initialize(); + } + + /** + * Initialize the control + */ + private void initialize() { + timeLabel = new Label(this, SWT.RIGHT); + timeLabel.setText("23:00"); + Integer preferredWidth = new Integer(timeLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT, false).x + 5); + timeLabel.setLayoutData(preferredWidth); + setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + days.addLast(new Day(this, SWT.NONE)); + setSize(new Point(537,16)); + setLayout(new DaysLayout()); + } + + private int numberOfColumns = 1; + + /** + * Gets the number of columns that will be displayed in this row. The default + * number of columns is 1. + * + * @return numberOfColumns The number of days to display. + */ + public int getNumberOfColumns() { + return numberOfColumns; + } + + /** + * Sets the number of columns that will be displayed in this row. The default + * number of columns is 1. This method may only be called *once* at the beginning + * of the control's life cycle, and the value passed must be >1.<p> + * + * Calling this method more than once results in undefined behavior. + * + * @param numberOfColumns The number of days to display. + */ + public void setNumberOfColumns(int numberOfColumns) { + this.numberOfColumns = numberOfColumns; + for (int i=numberOfColumns-1; i > 0; --i) { + days.add(new Day(this, SWT.NONE)); + } + } + + private Date currentTime = new Date(); + + public Date getCurrentTime() { + return currentTime; + } + + public void setCurrentTime(Date currentTime) { + this.currentTime = currentTime; + Calendar calendar = new GregorianCalendar(); + calendar.setTime(currentTime); + + // Only the hours will display in the label + if (calendar.get(Calendar.MINUTE) == 0) { + DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); + String time = df.format(currentTime); + timeLabel.setText(time); + setHourStartOnDays(true); + } else { + timeLabel.setText(""); + setHourStartOnDays(false); + } + } + + private void setHourStartOnDays(boolean isHourStart) { + for (Iterator daysIter = days.iterator(); daysIter.hasNext();) { + Day day = (Day) daysIter.next(); + day.setHourStart(isHourStart); + } + } + +} // @jve:decl-index=0:visual-constraint="10,10" + + diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/Day.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/Day.java new file mode 100644 index 00000000..bcc5a5b5 --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/Day.java @@ -0,0 +1,71 @@ +package org.eclipse.jface.examples.databinding.compositetable.month; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; + +public class Day extends Composite { + + private static final int _SIZE_MULTIPLIER = 7; + private Label dayNumber = null; + private Point textBounds; + private Label label1 = null; + private Label notes = null; + public Day(Composite parent, int style) { + super(parent, style); + initialize(); + } + + private void initialize() { + GridData gridData1 = new org.eclipse.swt.layout.GridData(); + gridData1.horizontalSpan = 2; + gridData1.verticalAlignment = org.eclipse.swt.layout.GridData.FILL; + gridData1.grabExcessVerticalSpace = true; + gridData1.grabExcessHorizontalSpace = true; + gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; + GridData gridData = new org.eclipse.swt.layout.GridData(); + gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER; + label1 = new Label(this, SWT.NONE); + label1.setLayoutData(gridData); + label1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + dayNumber = new Label(this, SWT.NONE); + dayNumber.setFont(JFaceResources.getFontRegistry().get(JFaceResources.BANNER_FONT)); + dayNumber.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + dayNumber.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION)); + dayNumber.setText("31"); + notes = new Label(this, SWT.WRAP); + notes.setText("8:45a Stand-up meeting\n9:00a Pair with Andy"); + notes.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + notes.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND)); + notes.setLayoutData(gridData1); + textBounds = dayNumber.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + this.setLayout(gridLayout); + setSize(new org.eclipse.swt.graphics.Point(106,101)); + } + + public Point computeSize(int wHint, int hHint, boolean changed) { + Point size = new Point(0, 0); + size.x = textBounds.x * _SIZE_MULTIPLIER; + size.y = textBounds.y * _SIZE_MULTIPLIER/2; + return size; + } + + public int getDayNumber() { + return -1; + } + + public void setDayNumber() { + + } + +} // @jve:decl-index=0:visual-constraint="10,10" diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/MonthCalendar.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/MonthCalendar.java new file mode 100644 index 00000000..a124b5be --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/MonthCalendar.java @@ -0,0 +1,57 @@ +package org.eclipse.jface.examples.databinding.compositetable.month; + +import org.eclipse.jface.examples.databinding.compositetable.CompositeTable; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +public class MonthCalendar extends Composite { + + private CompositeTable compositeTable = null; + private WeekHeader weekHeader = null; + private Week week = null; + + public MonthCalendar(Composite parent, int style) { + super(parent, style); + initialize(); + } + + private void initialize() { + this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + createCompositeTable(); + this.setLayout(new FillLayout()); + setSize(new org.eclipse.swt.graphics.Point(756,642)); + } + + /** + * This method initializes compositeTable + * + */ + private void createCompositeTable() { + compositeTable = new CompositeTable(this, SWT.NONE); + compositeTable.setNumRowsInCollection(5); + compositeTable.setMaxRowsVisible(5); + compositeTable.setFittingVertically(true); + compositeTable.setRunTime(true); + createWeekHeader(); + createWeek(); + } + + /** + * This method initializes weekHeader + * + */ + private void createWeekHeader() { + weekHeader = new WeekHeader(compositeTable, SWT.NONE); + } + + /** + * This method initializes week + * + */ + private void createWeek() { + week = new Week(compositeTable, SWT.NONE); + } + +} // @jve:decl-index=0:visual-constraint="10,10" diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/MonthCalendarTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/MonthCalendarTest.java new file mode 100644 index 00000000..7e6dbee2 --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/MonthCalendarTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2005 David Orme <djo@coconut-palm-software.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Orme - Initial API and implementation + */ +package org.eclipse.jface.examples.databinding.compositetable.month; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +public class MonthCalendarTest { + + private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10" + private MonthCalendar monthCalendar = null; + + /** + * This method initializes monthCalendar + * + */ + private void createMonthCalendar() { + monthCalendar = new MonthCalendar(sShell, SWT.NONE); + } + + /** + * @param args + */ + public static void main(String[] args) { + Display display = Display.getDefault(); + MonthCalendarTest thisClass = new MonthCalendarTest(); + thisClass.createSShell(); + thisClass.sShell.open(); + + while (!thisClass.sShell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + /** + * This method initializes sShell + */ + private void createSShell() { + sShell = new Shell(); + sShell.setText("Shell"); + sShell.setLayout(new FillLayout()); + createMonthCalendar(); + sShell.setSize(new org.eclipse.swt.graphics.Point(624,578)); + } + +} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/PrintCalendar.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/PrintCalendar.java new file mode 100644 index 00000000..51528c4f --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/PrintCalendar.java @@ -0,0 +1,80 @@ +package org.eclipse.jface.examples.databinding.compositetable.month; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +public class PrintCalendar { + /** The names of the months */ + String[] months = { + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" + }; + + /** The days in each month. */ + public final static int[] dom = { + 31, 28, 31, 30, /* jan feb mar apr */ + 31, 30, 31, 31, /* may jun jul aug */ + 30, 31, 30, 31 /* sep oct nov dec */ + }; + + /** Compute which days to put where, in the Cal panel */ + public void print(int mm, int yy) { + /** The number of days to leave blank at the start of this month */ + int leadGap = 0; + + System.out.print(months[mm]); // print month and year + System.out.print(" "); + System.out.print(yy); + System.out.println(); + + if (mm < 0 || mm > 11) + throw new IllegalArgumentException("Month " + mm + " bad, must be 0-11"); + GregorianCalendar calendar = new GregorianCalendar(yy, mm, 1); + + System.out.println("Su Mo Tu We Th Fr Sa"); + + // Compute how much to leave before the first. + // get(DAY_OF_WEEK) returns 0 for Sunday, which is just right. + leadGap = calendar.get(Calendar.DAY_OF_WEEK)-1; + + int daysInMonth = dom[mm]; + if (calendar.isLeapYear(calendar.get(Calendar.YEAR)) && mm == 1) + ++daysInMonth; + + // Blank out the labels before 1st day of month + for (int i = 0; i < leadGap; i++) { + System.out.print(" "); + } + + // Fill in numbers for the day of month. + for (int i = 1; i <= daysInMonth; i++) { + + // This "if" statement is simpler than fiddling with NumberFormat + if (i<=9) + System.out.print(' '); + System.out.print(i); + + if ((leadGap + i) % 7 == 0) // wrap if end of line. + System.out.println(); + else + System.out.print(' '); + } + System.out.println(); + } + + /** For testing, a main program */ + public static void main(String[] av) { + int month, year; + + PrintCalendar cp = new PrintCalendar(); + + // print the current month. + if (av.length == 2) { + cp.print(Integer.parseInt(av[0])-1, Integer.parseInt(av[1])); + } else { + Calendar c = Calendar.getInstance(); + cp.print(c.get(Calendar.MONTH), c.get(Calendar.YEAR)); + } + } +} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/Week.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/Week.java new file mode 100644 index 00000000..5281bbb2 --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/Week.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2005 David Orme <djo@coconut-palm-software.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Orme - Initial API and implementation + */ +package org.eclipse.jface.examples.databinding.compositetable.month; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +public class Week extends Composite { + + private Day day = null; + private Day day1 = null; + private Day day2 = null; + private Day day3 = null; + private Day day4 = null; + private Day day5 = null; + private Day day6 = null; + + public Week(Composite parent, int style) { + super(parent, style); + initialize(); + } + + private void initialize() { + createDay(); + createDay1(); + createDay2(); + createDay3(); + createDay4(); + createDay5(); + createDay6(); + this.setSize(new org.eclipse.swt.graphics.Point(797,238)); + } + + /** + * This method initializes day + * + */ + private void createDay() { + day = new Day(this, SWT.NONE); + day.setBounds(new org.eclipse.swt.graphics.Rectangle(8,14,91,89)); + } + + /** + * This method initializes day1 + * + */ + private void createDay1() { + day1 = new Day(this, SWT.NONE); + day1.setBounds(new org.eclipse.swt.graphics.Rectangle(112,14,92,93)); + } + + /** + * This method initializes day2 + * + */ + private void createDay2() { + day2 = new Day(this, SWT.NONE); + day2.setBounds(new org.eclipse.swt.graphics.Rectangle(227,14,97,93)); + } + + /** + * This method initializes day3 + * + */ + private void createDay3() { + day3 = new Day(this, SWT.NONE); + day3.setBounds(new org.eclipse.swt.graphics.Rectangle(347,13,101,94)); + } + + /** + * This method initializes day4 + * + */ + private void createDay4() { + day4 = new Day(this, SWT.NONE); + day4.setBounds(new org.eclipse.swt.graphics.Rectangle(467,13,100,96)); + } + + /** + * This method initializes day5 + * + */ + private void createDay5() { + day5 = new Day(this, SWT.NONE); + day5.setBounds(new org.eclipse.swt.graphics.Rectangle(582,16,89,92)); + } + + /** + * This method initializes day6 + * + */ + private void createDay6() { + day6 = new Day(this, SWT.NONE); + day6.setBounds(new org.eclipse.swt.graphics.Rectangle(686,19,88,90)); + } + +} // @jve:decl-index=0:visual-constraint="8,13" diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/WeekHeader.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/WeekHeader.java new file mode 100644 index 00000000..591c6aba --- /dev/null +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/compositetable/month/WeekHeader.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2005 David Orme <djo@coconut-palm-software.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * David Orme - Initial API and implementation + */ +package org.eclipse.jface.examples.databinding.compositetable.month; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class WeekHeader extends Composite { + + private Label label = null; + private Label label1 = null; + private Label label2 = null; + private Label label3 = null; + private Label label4 = null; + private Label label5 = null; + private Label label6 = null; + + public WeekHeader(Composite parent, int style) { + super(parent, style); + initialize(); + } + + /** + * This method initializes this + * + */ + private void initialize() { + this.setSize(new org.eclipse.swt.graphics.Point(536,54)); + label = new Label(this, SWT.CENTER); + label.setBounds(new org.eclipse.swt.graphics.Rectangle(23,18,53,18)); + label.setText("Sunday"); + label1 = new Label(this, SWT.CENTER); + label1.setBounds(new org.eclipse.swt.graphics.Rectangle(98,18,79,17)); + label1.setText("Monday"); + label2 = new Label(this, SWT.CENTER); + label2.setBounds(new org.eclipse.swt.graphics.Rectangle(187,18,47,17)); + label2.setText("Tuesday"); + label3 = new Label(this, SWT.CENTER); + label3.setBounds(new org.eclipse.swt.graphics.Rectangle(256,17,67,17)); + label3.setText("Wednesday"); + label4 = new Label(this, SWT.CENTER); + label4.setBounds(new org.eclipse.swt.graphics.Rectangle(338,17,62,20)); + label4.setText("Thursday"); + label5 = new Label(this, SWT.CENTER); + label5.setBounds(new org.eclipse.swt.graphics.Rectangle(415,16,43,21)); + label5.setText("Friday"); + label6 = new Label(this, SWT.CENTER); + label6.setBounds(new org.eclipse.swt.graphics.Rectangle(469,16,61,23)); + label6.setText("Saturday"); + + } + +} // @jve:decl-index=0:visual-constraint="11,16" |