/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
** GNU General Public License version 2.0 (GPL)
**
** as published by the Free Software Foundation
** http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
** LICENSE.GPL included in the packaging of this file.
**
** or the
**
** Agreement for Purchase and Licensing
**
** as offered by Software- und Organisations-Service GmbH
** in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
package net.cwroethel.swt.popupcalendar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
/*******************************************************************************
* Copyright (c) 2005 Will Roethel. 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: Will Roethel -
* initial API and implementation
******************************************************************************/
/**
* DateChooser component to quickly select todays date. The TodaySelector is
* comprised of only one button. If the button is pressed an SelectionEvent with
* event detail id DateChooserAction.todaySelected is fired.
*
* @author Will Roethel, http://www.cwroethel.net
* @version $Revision: 1.2 $
*/
public class TodaySelector extends DateChooserPanel {
private TodaySelectorStyle style;
/**
* Default constructor.
*/
public TodaySelector(Composite parent) {
super(parent, SWT.LEFT_TO_RIGHT);
style = new TodaySelectorStyle();
init();
}
/**
* Constructor overriding the default style.
*
* @param newStyle TodaySelectorStyle
*/
public TodaySelector(Composite parent, TodaySelectorStyle style) {
super(parent, SWT.LEFT_TO_RIGHT);
this.style = style;
init();
}
/**
* Set up the gui components and draw the panel.
*/
private void init() {
// again - our defaults
GridLayout thisLayout = new GridLayout(1, false);
thisLayout.horizontalSpacing = 0;
thisLayout.verticalSpacing = 0;
thisLayout.marginWidth = 0;
thisLayout.marginHeight = 0;
setLayout(thisLayout);
setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
// add the button
Button todayButton = new Button(this, SWT.PUSH);
GridData data = new GridData(GridData.CENTER | GridData.FILL_HORIZONTAL);
todayButton.setLayoutData(data);
style.setStyle(todayButton, TodaySelectorStyle.TODAYBUTTON);
// add the selection listener and send a signal to all listeners if
// today button was selected.
todayButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent selectionEvent) {
Event event = new Event();
event.widget = TodaySelector.this;
event.detail = DateChooserAction.todaySelected;
selectionEvent = new SelectionEvent(event);
sendSelectionEvent(selectionEvent);
}
});
}
}