public void widgetSelected( SelectionEvent e ) { final Shell dialog = new Shell( shell, SWT.DIALOG_TRIM ); dialog.setText( BaseMessages.getString( PKG, "JobGetPOP.SelectDate" ) ); dialog.setImage( GUIResource.getInstance().getImageSpoon() ); dialog.setLayout( new GridLayout( 3, false ) ); final DateTime calendar = new DateTime( dialog, SWT.CALENDAR ); final DateTime time = new DateTime( dialog, SWT.TIME | SWT.TIME ); new Label( dialog, SWT.NONE ); new Label( dialog, SWT.NONE ); Button ok = new Button( dialog, SWT.PUSH ); ok.setText( BaseMessages.getString( PKG, "System.Button.OK" ) ); ok.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, false ) ); ok.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { Calendar cal = Calendar.getInstance(); cal.set( Calendar.YEAR, calendar.getYear() ); cal.set( Calendar.MONTH, calendar.getMonth() ); cal.set( Calendar.DAY_OF_MONTH, calendar.getDay() ); cal.set( Calendar.HOUR_OF_DAY, time.getHours() ); cal.set( Calendar.MINUTE, time.getMinutes() ); cal.set( Calendar.SECOND, time.getSeconds() ); wReadFrom.setText( new SimpleDateFormat( JobEntryGetPOP.DATE_PATTERN ).format( cal.getTime() ) ); dialog.close(); } } ); dialog.setDefaultButton( ok ); dialog.pack(); dialog.open(); } } );
@Override String getNameText () { if (isTime ()) { return getHours () + ":" + getMinutes () + ":" + getSeconds (); } else { return (getMonth () + 1) + "/" + getDay () + "/" + getYear (); } }
void showCalendar() { if (isDropped ()) return; savedYear = getYear (); savedMonth = getMonth (); savedDay = getDay (); if (getShell() != popupShell.getParent ()) { disposePopupShell(); createPopupShell (savedYear, savedMonth, savedDay); } Point dateBounds = getSize (); Point calendarSize = popupCalendar.computeSize (SWT.DEFAULT, SWT.DEFAULT, false); popupCalendar.setBounds (1, 1, Math.max (dateBounds.x - 2, calendarSize.x), calendarSize.y); popupCalendar.setDate(savedYear, savedMonth, savedDay); Rectangle parentRect = display.map (getParent (), null, getBounds ()); Rectangle displayRect = getMonitor ().getClientArea (); int width = Math.max (dateBounds.x, calendarSize.x + 2); int height = calendarSize.y + 2; int x = parentRect.x; int y = parentRect.y + dateBounds.y; if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height; if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - calendarSize.x; popupShell.setBounds (x, y, width, height); popupShell.setVisible (true); if (isFocusControl()) popupCalendar.setFocus (); display.addFilter(SWT.MouseDown, clickListener); }
void popupCalendarEvent (Event event) { switch (event.type) { case SWT.Dispose: if (popupShell != null && !popupShell.isDisposed () && !isDisposed () && getShell () != popupShell.getParent ()) { int year = popupCalendar.getYear (); int month = popupCalendar.getMonth (); int day = popupCalendar.getDay (); popupShell = null; popupCalendar = null; createPopupShell (year, month, day); handleFocus (SWT.FocusIn); break; popupCalendar.monthChanged = false; } else { dropDownCalendar (false); int year = popupCalendar.getYear (); int month = popupCalendar.getMonth (); int day = popupCalendar.getDay (); setDate (year, month, day); Event e = new Event (); e.time = event.time; e.stateMask = event.stateMask; e.doit = event.doit; notifyListeners (SWT.Selection, e); event.doit = e.doit; break;
if (drop == isDropped ()) return; hideDropDownCalendar (); return; setCurrentDate (); if (getShell () != popupShell.getParent ()) { recreateCalendar (); Point containerBounds = getSizeInPixels (); Point calendarSize = popupCalendar.computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT, false); popupCalendar.setBoundsInPixels (1, 1, Math.max (containerBounds.x - 2, calendarSize.x), calendarSize.y); popupCalendar.setDate (savedYear, savedMonth, savedDay); focusDayOnPopupCalendar (); Display display = getDisplay (); Rectangle coordsRelativeToScreen = display.mapInPixels (getParent (), null, getBoundsInPixels ()); Rectangle displayRect = DPIUtil.autoScaleUp(getMonitor ().getClientArea ()); showPopupShell (containerBounds, calendarSize, coordsRelativeToScreen, displayRect);
private void recreateCalendar () { int year = popupCalendar.getYear (); int month = popupCalendar.getMonth (); int day = popupCalendar.getDay (); popupCalendar.removeListener (SWT.Dispose, popupListener); popupShell.dispose (); popupShell = null; popupCalendar = null; createPopupShell (year, month, day); }
void createPopupShell (int year, int month, int day) { popupShell = new Shell (getShell (), SWT.NO_TRIM | SWT.ON_TOP); popupCalendar = new DateTime (popupShell, SWT.CALENDAR); if (font != null) popupCalendar.setFont (font); if (fg != null) popupCalendar.setForeground (fg); if (bg != null) popupCalendar.setBackground (bg); mouseEventListener = new Listener () { @Override public void handleEvent (Event event) { if (event.widget instanceof Control) { Control c = (Control)event.widget; if (c != down && c.getShell () != popupShell) dropDownCalendar (false); } } }; int [] listeners = {SWT.Close, SWT.MouseUp, SWT.Paint}; for (int i=0; i < listeners.length; i++) { popupShell.addListener (listeners [i], popupListener); } listeners = new int [] {SWT.MouseDown, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.FocusOut, SWT.Dispose}; for (int i=0; i < listeners.length; i++) { popupCalendar.addListener (listeners [i], popupListener); } addListener (SWT.Dispose, popupListener); if (year != -1) popupCalendar.setDate (year, month, day); }
public static Object getValue(ActionContext actionContext){ DateTime dt = (DateTime) actionContext.get("control"); GregorianCalendar c = new GregorianCalendar(); c.set(Calendar.HOUR_OF_DAY, dt.getHours()); c.set(Calendar.MINUTE, dt.getMinutes()); c.set(Calendar.SECOND, dt.getSeconds()); Date time = c.getTime(); SimpleDateFormat sf = new SimpleDateFormat((String) actionContext.get("pattern")); return sf.format(time); }
super (parent, checkStyle (style)); if (isDate () || isTime ()) { createText (); if (isCalendar ()) { OS.gtk_calendar_mark_day (calendarHandle, Calendar.getInstance ().get (Calendar.DAY_OF_MONTH)); if (isDateWithDropDownButton ()) { createDropDownButton (); createPopupShell (-1, -1, -1); addListener (SWT.Resize, new Listener () { @Override public void handleEvent (Event event) { initAccessible (); if (isDateWithDropDownButton ()) { Point size = computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT); setBoundsInPixels (0, 0, size.x, size.y);
public void handleEvent(Event event) { int year = popupCalendar.getYear (); int month = popupCalendar.getMonth (); int day = popupCalendar.getDay (); setDate(year, month, day); Event e = new Event (); e.time = event.time; notifyListeners (SWT.Selection, e); hideCalendar(); } });
/** * Sets the receiver's date, or day of the month, to the specified day. * <p> * The first day of the month is 1, and the last day depends on the month and year. * If the specified day is not valid for the receiver's month and year, then it is ignored. * </p> * * @param day a positive integer beginning with 1 * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see #setDate */ public void setDay (int day) { checkWidget (); if (!isValidDate (getYear (), getMonth (), day)) return; if (isCalendar ()) { this.day = day; OS.gtk_calendar_select_day (calendarHandle, day); } else { calendar.set (Calendar.DAY_OF_MONTH, day); updateControl (); } }
/** * Sets the receiver's month. * <p> * The first month of the year is 0, and the last month is 11. * If the specified month is not valid for the receiver's day and year, then it is ignored. * </p> * * @param month an integer between 0 and 11 * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see #setDate */ public void setMonth (int month) { checkWidget (); if (!isValidDate (getYear (), month, getDay ())) return; if (isCalendar ()) { this.month = month; OS.gtk_calendar_select_month (calendarHandle, month, year); } else { calendar.set (Calendar.MONTH, month); updateControl (); } }
/** * Sets the receiver's year. * <p> * The first year is 1752 and the last year is 9999. * If the specified year is not valid for the receiver's day and month, then it is ignored. * </p> * * @param year an integer between 1752 and 9999 * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see #setDate */ public void setYear (int year) { checkWidget (); if (!isValidDate (year, getMonth (), getDay ())) return; if (isCalendar ()) { this.year = year; OS.gtk_calendar_select_month (calendarHandle, month, year); } else { calendar.set (Calendar.YEAR, year); updateControl (); } }
boolean alt = (nsEvent.modifierFlags() & OS.NSAlternateKeyMask) != 0; if (alt && (keyCode == SWT.ARROW_UP || keyCode == SWT.ARROW_DOWN)) { if (isDropped ()) { hideCalendar(); } else { showCalendar(); popupCalendar.setDate (savedYear, savedMonth, savedDay); setDate(savedYear, savedMonth, savedDay); hideCalendar(); return; int month = getMonth(); int day = getDay(); int year = getYear(); popupCalendar.setDate(year, month, day);
checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Selection, typedListener); addListener (SWT.DefaultSelection, typedListener);
void createPopupShell(int year, int month, int day) { popupShell = new Shell (getShell (), SWT.NO_TRIM | SWT.ON_TOP); popupShell.isPopup = true; popupShell.window.setHasShadow(true); popupCalendar = new DateTime (popupShell, SWT.CALENDAR); if (font != null) popupCalendar.setFont (font); popupCalendar.addListener (SWT.Selection, new Listener() { public void handleEvent(Event event) { int year = popupCalendar.getYear (); addListener (SWT.Dispose, new Listener() { public void handleEvent(Event event) { if (popupShell != null && !popupShell.isDisposed ()) { addListener(SWT.FocusOut, new Listener() { public void handleEvent(Event event) { hideCalendar(); if (year != -1) popupCalendar.setDate(year, month, day);
int getArrow (long /*int*/ widget) { int adj_value = (int) OS.gtk_adjustment_get_value (OS.gtk_spin_button_get_adjustment (widget)); int new_value = 0; if (isDate ()) { // getMonth () return 0 as first month and 11 as last one, whereas adjusment does not, so adding one makes them comaprable new_value = getMonth ()+1; } else if (isTime ()) { // as getHours () has 24h format but spinner 12h format, new_value needs to be converted to 12h format if (getHours () > 12 ){ new_value = getHours () - 12; } else { new_value = getHours (); // This fix does not compares adj_value to new_value when getArrow is called on widget creation } if (new_value == 0) new_value = 12; } if (adj_value == 0 && firstTime) return 0; firstTime = false; if ( adj_value == new_value) return 0; return adj_value > new_value ? SWT.ARROW_UP : SWT.ARROW_DOWN; }
/** * Sets the receiver's hours. * <p> * Hours is an integer between 0 and 23. * </p> * * @param hours an integer between 0 and 23 * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the * thread that created the receiver</li> * </ul> */ public void setHours( int hours ) { checkWidget(); if( checkTime( hours, getMinutes(), getSeconds() ) ) { rightNow.set( Calendar.HOUR_OF_DAY, hours ); applyLimits(); } }
/** * Sets the receiver's minutes. * <p> * Minutes is an integer between 0 and 59. * </p> * * @param minutes an integer between 0 and 59 * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the * thread that created the receiver</li> * </ul> */ public void setMinutes( int minutes ) { checkWidget(); if( checkTime( getHours(), minutes, getSeconds() ) ) { rightNow.set( Calendar.MINUTE, minutes ); applyLimits(); } }