diff options
author | Anatoly Spektor <aspektor@redhat.com> | 2012-12-05 10:34:53 -0500 |
---|---|---|
committer | Anatoly Spektor <aspektor@redhat.com> | 2012-12-05 10:34:53 -0500 |
commit | c133b51c4b83b7dac7b154c35702a4c92c6f38fc (patch) | |
tree | b8e6f5e9b99d2eed184b7bca097d8d7c74fe9a9f | |
parent | 7be562b76e8b4733518bad9b98f611c68fd54f3a (diff) | |
download | eclipse.platform.swt-c133b51c4b83b7dac7b154c35702a4c92c6f38fc.tar.gz eclipse.platform.swt-c133b51c4b83b7dac7b154c35702a4c92c6f38fc.tar.xz eclipse.platform.swt-c133b51c4b83b7dac7b154c35702a4c92c6f38fc.zip |
Cleaned the code
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java | 484 |
1 files changed, 242 insertions, 242 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java index 801f148030..031117333e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java @@ -124,7 +124,7 @@ public DateTime (Composite parent, int style) { if ((this.style & SWT.CALENDAR) == 0) { /* SWT.DATE and SWT.TIME */ if ((this.style & SWT.DROP_DOWN) != 0) { - createText((this.style & SWT.DROP_DOWN) != 0); +// createText((this.style & SWT.DROP_DOWN) != 0); } else { // FOR SPINNER createSpinText(); } @@ -132,66 +132,66 @@ public DateTime (Composite parent, int style) { initAccessible (); } -void createText(boolean dropDown) { - calendar = Calendar.getInstance(); - formatSymbols = new DateFormatSymbols(); - text = new Text(this, SWT.SINGLE); - /* disable the native drag and drop for the date/time text field */ - OS.gtk_drag_dest_unset(text.handle); - if ((style & SWT.DATE) != 0) { - setFormat((style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT); - } else { /* SWT.TIME */ - setFormat((style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT); - } - text.setText(getFormattedString(style)); - - addListener(SWT.Resize, new Listener() { - public void handleEvent(Event event) { - onResize(event); - } - }); - Listener listener = new Listener() { - public void handleEvent(Event event) { - switch(event.type) { - case SWT.KeyDown: onTextKeyDown(event); break; - case SWT.FocusIn: onTextFocusIn(event); break; - case SWT.FocusOut: onTextFocusOut(event); break; - case SWT.MouseDown: // Fall through - case SWT.MouseUp: onTextMouseClick(event); break; - case SWT.MenuDetect: notifyListeners(SWT.MenuDetect, event); break; - case SWT.Verify: onTextVerify(event); break; - } - } - }; - int [] listeners = new int [] {SWT.KeyDown, SWT.FocusIn, SWT.FocusOut, SWT.MouseDown, SWT.MouseUp, SWT.MenuDetect, SWT.Verify}; - for (int i = 0; i < listeners.length; i++) { - text.addListener(listeners [i], listener); - } - - if ((style & SWT.DATE) != 0 && dropDown) { - createDropDownButton(); - createPopupShell(-1, -1, -1); - } else { - up = new Button(this, SWT.ARROW | SWT.UP); - gtk_widget_set_can_focus (up.handle, false); - //up.setToolTipText(SWT.getMessage ("SWT_Up")); //$NON-NLS-1$ - down = new Button(this, SWT.ARROW | SWT.DOWN); - gtk_widget_set_can_focus (down.handle, false); - //down.setToolTipText(SWT.getMessage ("SWT_Down")); //$NON-NLS-1$ - up.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - incrementField(+1); - text.setFocus(); - } - }); - down.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - incrementField(-1); - text.setFocus(); - } - }); - } -} +//void createText(boolean dropDown) { +// calendar = Calendar.getInstance(); +// formatSymbols = new DateFormatSymbols(); +// text = new Text(this, SWT.SINGLE); +// /* disable the native drag and drop for the date/time text field */ +// OS.gtk_drag_dest_unset(text.handle); +// if ((style & SWT.DATE) != 0) { +// setFormat((style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT); +// } else { /* SWT.TIME */ +// setFormat((style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT); +// } +// text.setText(getFormattedString(style)); +// +// addListener(SWT.Resize, new Listener() { +// public void handleEvent(Event event) { +// onResize(event); +// } +// }); +// Listener listener = new Listener() { +// public void handleEvent(Event event) { +// switch(event.type) { +// case SWT.KeyDown: onTextKeyDown(event); break; +// case SWT.FocusIn: onTextFocusIn(event); break; +// case SWT.FocusOut: onTextFocusOut(event); break; +// case SWT.MouseDown: // Fall through +// case SWT.MouseUp: onTextMouseClick(event); break; +// case SWT.MenuDetect: notifyListeners(SWT.MenuDetect, event); break; +// case SWT.Verify: onTextVerify(event); break; +// } +// } +// }; +// int [] listeners = new int [] {SWT.KeyDown, SWT.FocusIn, SWT.FocusOut, SWT.MouseDown, SWT.MouseUp, SWT.MenuDetect, SWT.Verify}; +// for (int i = 0; i < listeners.length; i++) { +// text.addListener(listeners [i], listener); +// } +// +// if ((style & SWT.DATE) != 0 && dropDown) { +// createDropDownButton(); +// createPopupShell(-1, -1, -1); +// } else { +// up = new Button(this, SWT.ARROW | SWT.UP); +// gtk_widget_set_can_focus (up.handle, false); +// //up.setToolTipText(SWT.getMessage ("SWT_Up")); //$NON-NLS-1$ +// down = new Button(this, SWT.ARROW | SWT.DOWN); +// gtk_widget_set_can_focus (down.handle, false); +// //down.setToolTipText(SWT.getMessage ("SWT_Down")); //$NON-NLS-1$ +// up.addListener(SWT.Selection, new Listener() { +// public void handleEvent(Event event) { +// incrementField(+1); +// text.setFocus(); +// } +// }); +// down.addListener(SWT.Selection, new Listener() { +// public void handleEvent(Event event) { +// incrementField(-1); +// text.setFocus(); +// } +// }); +// } +//} void createDropDownButton() { down = new Button(this, SWT.ARROW | SWT.DOWN); @@ -328,13 +328,13 @@ public Point computeSize (int wHint, int hHint, boolean changed) { height = size.y; } else { /* SWT.DATE and SWT.TIME */ if ((style & SWT.DROP_DOWN) != 0) { - GC gc = new GC(text); - Point textSize = gc.stringExtent(getComputeSizeString(style)); - gc.dispose(); - Rectangle trim = text.computeTrim(0, 0, textSize.x, textSize.y); - Point buttonSize = down.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); - width = trim.width + buttonSize.x; - height = Math.max(trim.height, buttonSize.y); +// GC gc = new GC(text); +// Point textSize = gc.stringExtent(getComputeSizeString(style)); +// gc.dispose(); +// Rectangle trim = text.computeTrim(0, 0, textSize.x, textSize.y); +// Point buttonSize = down.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); +// width = trim.width + buttonSize.x; +// height = Math.max(trim.height, buttonSize.y); } else { // FOR SPINNER Point size = computeNativeSize(handle, wHint, hHint, changed); width = size.x; @@ -380,19 +380,19 @@ void createWidget (int index) { } } -void commitCurrentField() { - if (characterCount > 0) { - characterCount = 0; - int fieldName = fieldNames[currentField]; - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s != -1) value = value.substring(s + 1); - int newValue = unformattedIntValue(fieldName, value, characterCount == 0, calendar.getActualMaximum(fieldName)); - if (newValue != -1) setTextField(fieldName, newValue, true, true); - } -} +//void commitCurrentField() { +// if (characterCount > 0) { +// characterCount = 0; +// int fieldName = fieldNames[currentField]; +// int start = fieldIndices[currentField].x; +// int end = fieldIndices[currentField].y; +// String value = text.getText(start, end - 1); +// int s = value.lastIndexOf(' '); +// if (s != -1) value = value.substring(s + 1); +// int newValue = unformattedIntValue(fieldName, value, characterCount == 0, calendar.getActualMaximum(fieldName)); +// if (newValue != -1) setTextField(fieldName, newValue, true, true); +// } +//} void onDispose (Event event) { if (popupShell != null && !popupShell.isDisposed ()) { @@ -780,21 +780,21 @@ void hookEvents () { } } -void incrementField(int amount) { - int fieldName = fieldNames[currentField]; - int value = calendar.get(fieldName); - if (fieldName == Calendar.HOUR) { - int max = calendar.getMaximum(Calendar.HOUR); - int min = calendar.getMinimum(Calendar.HOUR); - if ((value == max && amount == 1) || (value == min && amount == -1)) { - int temp = currentField; - currentField = getFieldIndex(Calendar.AM_PM); - setTextField(Calendar.AM_PM, (calendar.get(Calendar.AM_PM) + 1) % 2, true, true); - currentField = temp; - } - } - setTextField(fieldName, value + amount, true, true); -} +//void incrementField(int amount) { +// int fieldName = fieldNames[currentField]; +// int value = calendar.get(fieldName); +// if (fieldName == Calendar.HOUR) { +// int max = calendar.getMaximum(Calendar.HOUR); +// int min = calendar.getMinimum(Calendar.HOUR); +// if ((value == max && amount == 1) || (value == min && amount == -1)) { +// int temp = currentField; +// currentField = getFieldIndex(Calendar.AM_PM); +// setTextField(Calendar.AM_PM, (calendar.get(Calendar.AM_PM) + 1) % 2, true, true); +// currentField = temp; +// } +// } +// setTextField(fieldName, value + amount, true, true); +//} boolean isDropped () { return popupShell.getVisible (); @@ -1076,27 +1076,27 @@ public void removeSelectionListener (SelectionListener listener) { eventTable.unhook (SWT.DefaultSelection, listener); } -void selectField(int index) { - if (index != currentField) { - commitCurrentField(); - } - final int start = fieldIndices[index].x; - final int end = fieldIndices[index].y; - Point pt = text.getSelection(); - if (index == currentField && start == pt.x && end == pt.y) return; - currentField = index; - display.asyncExec(new Runnable() { - public void run() { - if (handle != 0) { - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s == -1) s = start; - else s = start + s + 1; - text.setSelection(s, end); - } - } - }); -} +//void selectField(int index) { +// if (index != currentField) { +// commitCurrentField(); +// } +// final int start = fieldIndices[index].x; +// final int end = fieldIndices[index].y; +// Point pt = text.getSelection(); +// if (index == currentField && start == pt.x && end == pt.y) return; +// currentField = index; +// display.asyncExec(new Runnable() { +// public void run() { +// if (handle != 0) { +// String value = text.getText(start, end - 1); +// int s = value.lastIndexOf(' '); +// if (s == -1) s = start; +// else s = start + s + 1; +// text.setSelection(s, end); +// } +// } +// }); +//} void sendSelectionEvent () { int [] y = new int [1]; @@ -1205,47 +1205,47 @@ void setField(int fieldName, int value) { sendSelectionEvent (SWT.Selection); } -void setTextField(int fieldName, int value, boolean commit, boolean adjust) { - if (commit) { - int max = calendar.getActualMaximum(fieldName); - int min = calendar.getActualMinimum(fieldName); - if (fieldName == Calendar.YEAR) { - max = MAX_YEAR; - min = MIN_YEAR; - /* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */ - int currentYear = Calendar.getInstance().get(Calendar.YEAR); - int currentCentury = (currentYear / 100) * 100; - if (value < (currentYear + 30) % 100) value += currentCentury; - else if (value < 100) value += currentCentury - 100; - } - if (value > max) value = min; // wrap - if (value < min) value = max; // wrap - } - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - text.setSelection(start, end); - String newValue = formattedStringValue(fieldName, value, adjust); - StringBuffer buffer = new StringBuffer(newValue); - /* Convert leading 0's into spaces. */ - int prependCount = end - start - buffer.length(); - for (int i = 0; i < prependCount; i++) { - switch (fieldName) { - case Calendar.MINUTE: - case Calendar.SECOND: - buffer.insert(0, 0); - break; - default: - buffer.insert(0, ' '); - break; - } - } - newValue = buffer.toString(); - ignoreVerify = true; - text.insert(newValue); - ignoreVerify = false; - selectField(currentField); - if (commit) setField(fieldName, value); -} +//void setTextField(int fieldName, int value, boolean commit, boolean adjust) { +// if (commit) { +// int max = calendar.getActualMaximum(fieldName); +// int min = calendar.getActualMinimum(fieldName); +// if (fieldName == Calendar.YEAR) { +// max = MAX_YEAR; +// min = MIN_YEAR; +// /* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */ +// int currentYear = Calendar.getInstance().get(Calendar.YEAR); +// int currentCentury = (currentYear / 100) * 100; +// if (value < (currentYear + 30) % 100) value += currentCentury; +// else if (value < 100) value += currentCentury - 100; +// } +// if (value > max) value = min; // wrap +// if (value < min) value = max; // wrap +// } +// int start = fieldIndices[currentField].x; +// int end = fieldIndices[currentField].y; +// text.setSelection(start, end); +// String newValue = formattedStringValue(fieldName, value, adjust); +// StringBuffer buffer = new StringBuffer(newValue); +// /* Convert leading 0's into spaces. */ +// int prependCount = end - start - buffer.length(); +// for (int i = 0; i < prependCount; i++) { +// switch (fieldName) { +// case Calendar.MINUTE: +// case Calendar.SECOND: +// buffer.insert(0, 0); +// break; +// default: +// buffer.insert(0, ' '); +// break; +// } +// } +// newValue = buffer.toString(); +// ignoreVerify = true; +// text.insert(newValue); +// ignoreVerify = false; +// selectField(currentField); +// if (commit) setField(fieldName, value); +//} /** * Sets the receiver's year, month, and day in a single operation. @@ -1475,7 +1475,7 @@ public void setYear (int year) { } void onTextFocusIn(Event event) { - selectField(currentField); + selectSpinField(currentField); if ((style & SWT.DROP_DOWN) == 0) { sendFocusEvent(SWT.FocusIn); } else { @@ -1484,7 +1484,7 @@ void onTextFocusIn(Event event) { } void onTextFocusOut(Event event) { - commitCurrentField(); + commitCurrentSpinField(); if ((style & SWT.DROP_DOWN) == 0) { sendFocusEvent(SWT.FocusOut); } else { @@ -1492,81 +1492,81 @@ void onTextFocusOut(Event event) { } } -void onTextKeyDown(Event event) { - if ((style & SWT.DROP_DOWN) != 0 && (event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) { - boolean dropped = isDropped (); - if (!dropped) { - popupCalendar.calendarDisplayed = true; - setFocus (); - } - dropDownCalendar(!dropped); - return; - } - int fieldName; - switch (event.keyCode) { - case SWT.ARROW_RIGHT: - case SWT.KEYPAD_DIVIDE: - /* A right arrow or a valid separator navigates to the field on the right, with wraping */ - selectField((currentField + 1) % fieldCount); - sendEvent(SWT.Traverse); - break; - case SWT.ARROW_LEFT: - /* Navigate to the field on the left, with wrapping */ - int index = currentField - 1; - selectField(index < 0 ? fieldCount - 1 : index); - sendEvent(SWT.Traverse); - break; - case SWT.ARROW_UP: - case SWT.KEYPAD_ADD: - /* Set the value of the current field to value + 1, with wrapping */ - commitCurrentField(); - incrementField(+1); - break; - case SWT.ARROW_DOWN: - case SWT.KEYPAD_SUBTRACT: - /* Set the value of the current field to value - 1, with wrapping */ - commitCurrentField(); - incrementField(-1); - break; - case SWT.HOME: - /* Set the value of the current field to its minimum */ - fieldName = fieldNames[currentField]; - setTextField(fieldName, calendar.getActualMinimum(fieldName), true, true); - break; - case SWT.END: - /* Set the value of the current field to its maximum */ - fieldName = fieldNames[currentField]; - setTextField(fieldName, calendar.getActualMaximum(fieldName), true, true); - break; - default: - switch (event.character) { - case '/': - case ':': - case '-': - case '.': - /* A valid separator navigates to the field on the right, with wraping */ - selectField((currentField + 1) % fieldCount); - sendEvent(SWT.Traverse); - break; - case SWT.CR: - /* Enter causes default selection */ - postEvent (SWT.DefaultSelection); - break; - } - } -} - -void onTextMouseClick(Event event) { - if (event.button != 1) return; - Point sel = text.getSelection(); - for (int i = 0; i < fieldCount; i++) { - if (sel.x >= fieldIndices[i].x && sel.x <= fieldIndices[i].y) { - currentField = i; - break; - } - } - selectField(currentField); -} +//void onTextKeyDown(Event event) { +// if ((style & SWT.DROP_DOWN) != 0 && (event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) { +// boolean dropped = isDropped (); +// if (!dropped) { +// popupCalendar.calendarDisplayed = true; +// setFocus (); +// } +// dropDownCalendar(!dropped); +// return; +// } +// int fieldName; +// switch (event.keyCode) { +// case SWT.ARROW_RIGHT: +// case SWT.KEYPAD_DIVIDE: +// /* A right arrow or a valid separator navigates to the field on the right, with wraping */ +// selectField((currentField + 1) % fieldCount); +// sendEvent(SWT.Traverse); +// break; +// case SWT.ARROW_LEFT: +// /* Navigate to the field on the left, with wrapping */ +// int index = currentField - 1; +// selectField(index < 0 ? fieldCount - 1 : index); +// sendEvent(SWT.Traverse); +// break; +// case SWT.ARROW_UP: +// case SWT.KEYPAD_ADD: +// /* Set the value of the current field to value + 1, with wrapping */ +// commitCurrentField(); +// incrementField(+1); +// break; +// case SWT.ARROW_DOWN: +// case SWT.KEYPAD_SUBTRACT: +// /* Set the value of the current field to value - 1, with wrapping */ +// commitCurrentField(); +// incrementField(-1); +// break; +// case SWT.HOME: +// /* Set the value of the current field to its minimum */ +// fieldName = fieldNames[currentField]; +// setTextField(fieldName, calendar.getActualMinimum(fieldName), true, true); +// break; +// case SWT.END: +// /* Set the value of the current field to its maximum */ +// fieldName = fieldNames[currentField]; +// setTextField(fieldName, calendar.getActualMaximum(fieldName), true, true); +// break; +// default: +// switch (event.character) { +// case '/': +// case ':': +// case '-': +// case '.': +// /* A valid separator navigates to the field on the right, with wraping */ +// selectField((currentField + 1) % fieldCount); +// sendEvent(SWT.Traverse); +// break; +// case SWT.CR: +// /* Enter causes default selection */ +// postEvent (SWT.DefaultSelection); +// break; +// } +// } +//} + +//void onTextMouseClick(Event event) { +// if (event.button != 1) return; +// Point sel = text.getSelection(); +// for (int i = 0; i < fieldCount; i++) { +// if (sel.x >= fieldIndices[i].x && sel.x <= fieldIndices[i].y) { +// currentField = i; +// break; +// } +// } +// selectField(currentField); +//} void onResize(Event event) { Rectangle rect = getClientArea (); @@ -1594,9 +1594,9 @@ void onTextVerify(Event event) { if (fieldName == Calendar.AM_PM) { String[] ampm = formatSymbols.getAmPmStrings(); if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) { - setTextField(fieldName, Calendar.AM, true, false); + setSpinTextField(fieldName, Calendar.AM, true, false); } else if (newText.equalsIgnoreCase(ampm[Calendar.PM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.PM])) { - setTextField(fieldName, Calendar.PM, true, false); + setSpinTextField(fieldName, Calendar.PM, true, false); } return; } @@ -1622,9 +1622,9 @@ void onTextVerify(Event event) { return; } if (first && newValue == 0 && length > 1) { - setTextField(fieldName, newValue, false, false); + setSpinTextField(fieldName, newValue, false, false); } else if (min <= newValue && newValue <= max) { - setTextField(fieldName, newValue, characterCount == 0, characterCount == 0); + setSpinTextField(fieldName, newValue, characterCount == 0, characterCount == 0); } else { if (newTextLength >= length) { newText = newText.substring(newTextLength - length + 1); @@ -1632,7 +1632,7 @@ void onTextVerify(Event event) { if (newValue != -1) { characterCount = length - 1; if (min <= newValue && newValue <= max) { - setTextField(fieldName, newValue, characterCount == 0, true); + setSpinTextField(fieldName, newValue, characterCount == 0, true); } } } @@ -1712,7 +1712,7 @@ int getArrow (long /*int*/ widget) { */ void createSpinHandle () { long /*int*/ adjustment = 0; - adjustment = OS.gtk_adjustment_new (10, 0, 60, 1, 10, 0); + adjustment = OS.gtk_adjustment_new (10, 0, 99999, 1, 1, 0); handle = OS.gtk_spin_button_new(adjustment, 1, 0); OS.gtk_spin_button_set_numeric (handle, false); OS.gtk_container_add(fixedHandle, handle); @@ -1870,7 +1870,7 @@ void setSelection (int start, int end) { void selectSpinField(int index) { if (index != currentField) { - commitCurrentField(); + commitCurrentSpinField(); } final int start = fieldIndices[index].x; final int end = fieldIndices[index].y; |