/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The default Spinner UI delegate.
*
* @author Hans Muller
* @since 1.4
*/
{
/**
* The spinner that we're a UI delegate for. Initialized by
* the <code>installUI</code> method, and reset to null
* by <code>uninstallUI</code>.
*
* @see #installUI
* @see #uninstallUI
*/
/**
* arrow buttons. These listeners are shared by all
* spinner arrow buttons.
*
* @see #createNextButton
* @see #createPreviousButton
*/
private static final ArrowButtonHandler nextButtonHandler = new ArrowButtonHandler("increment", true);
private static final ArrowButtonHandler previousButtonHandler = new ArrowButtonHandler("decrement", false);
/**
* Used by the default LayoutManager class - SpinnerLayout for
* missing (null) editor/nextButton/previousButton children.
*/
/**
* Returns a new instance of BasicSpinnerUI. SpinnerListUI
* delegates are allocated one per JSpinner.
*
* @param c the JSpinner (not used)
* @see ComponentUI#createUI
* @return a new BasicSpinnerUI object
*/
return new BasicSpinnerUI();
}
if (c != null) {
}
}
/**
* Calls <code>installDefaults</code>, <code>installListeners</code>,
* and then adds the components returned by <code>createNextButton</code>,
* <code>createPreviousButton</code>, and <code>createEditor</code>.
*
* @param c the JSpinner
* @see #installDefaults
* @see #installListeners
* @see #createNextButton
* @see #createPreviousButton
* @see #createEditor
*/
}
/**
* Calls <code>uninstallDefaults</code>, <code>uninstallListeners</code>,
* and then removes all of the spinners children.
*
* @param c the JSpinner (not used)
*/
c.removeAll();
}
/**
* Initializes <code>PropertyChangeListener</code> with
* a shared object that delegates interesting PropertyChangeEvents
* to protected methods.
* <p>
* This method is called by <code>installUI</code>.
*
* @see #replaceEditor
* @see #uninstallListeners
*/
protected void installListeners() {
"Spinner.disableOnBoundaryValues", false)) {
}
}
}
}
/**
* Removes the <code>PropertyChangeListener</code> added
* by installListeners.
* <p>
* This method is called by <code>uninstallUI</code>.
*
* @see #installListeners
*/
protected void uninstallListeners() {
}
}
}
/**
* Initialize the <code>JSpinner</code> <code>border</code>,
* <code>foreground</code>, and <code>background</code>, properties
* based on the corresponding "Spinner.*" properties from defaults table.
* The <code>JSpinners</code> layout is set to the value returned by
* <code>createLayout</code>. This method is called by <code>installUI</code>.
*
* @see #uninstallDefaults
* @see #installUI
* @see #createLayout
* @see LookAndFeel#installBorder
* @see LookAndFeel#installColors
*/
protected void installDefaults() {
LookAndFeel.installColorsAndFont(spinner, "Spinner.background", "Spinner.foreground", "Spinner.font");
}
/**
* Sets the <code>JSpinner's</code> layout manager to null. This
* method is called by <code>uninstallUI</code>.
*
* @see #installDefaults
* @see #uninstallUI
*/
protected void uninstallDefaults() {
}
}
return handler;
}
/**
* Installs the necessary listeners on the next button, <code>c</code>,
* to update the <code>JSpinner</code> in response to a user gesture.
*
* @param c Component to install the listeners on
* @throws NullPointerException if <code>c</code> is null.
* @see #createNextButton
* @since 1.5
*/
}
/**
* Installs the necessary listeners on the previous button, <code>c</code>,
* to update the <code>JSpinner</code> in response to a user gesture.
*
* @param c Component to install the listeners on.
* @throws NullPointerException if <code>c</code> is null.
* @see #createPreviousButton
* @since 1.5
*/
}
if (c instanceof JButton) {
}
}
/**
* Creates a <code>LayoutManager</code> that manages the <code>editor</code>,
* <code>nextButton</code>, and <code>previousButton</code>
* children of the JSpinner. These three children must be
* added with a constraint that identifies their role:
* "Editor", "Next", and "Previous". The default layout manager
* can handle the absence of any of these children.
*
* @return a LayoutManager for the editor, next button, and previous button.
* @see #createNextButton
* @see #createPreviousButton
* @see #createEditor
*/
return getHandler();
}
/**
* Creates a <code>PropertyChangeListener</code> that can be
* added to the JSpinner itself. Typically, this listener
* will call replaceEditor when the "editor" property changes,
* since it's the <code>SpinnerUI's</code> responsibility to
* add the editor to the JSpinner (and remove the old one).
* This method is called by <code>installListeners</code>.
*
* @return A PropertyChangeListener for the JSpinner itself
* @see #installListeners
*/
return getHandler();
}
/**
* Creates a decrement button, i.e. component that replaces the spinner
* value with the object returned by <code>spinner.getPreviousValue</code>.
* By default the <code>previousButton</code> is a {@code JButton}. If the
* decrement button is not needed this method should return {@code null}.
*
* @return a component that will replace the spinner's value with the
* previous value in the sequence, or {@code null}
* @see #installUI
* @see #createNextButton
* @see #installPreviousButtonListeners
*/
c.setName("Spinner.previousButton");
return c;
}
/**
* Creates an increment button, i.e. component that replaces the spinner
* value with the object returned by <code>spinner.getNextValue</code>.
* By default the <code>nextButton</code> is a {@code JButton}. If the
* increment button is not needed this method should return {@code null}.
*
* @return a component that will replace the spinner's value with the
* next value in the sequence, or {@code null}
* @see #installUI
* @see #createPreviousButton
* @see #installNextButtonListeners
*/
c.setName("Spinner.nextButton");
return c;
}
if (buttonBorder instanceof UIResource) {
// Wrap the border to avoid having the UIResource be replaced by
// the ButtonUI. This is the opposite of using BorderUIResource.
} else {
}
b.setInheritsPopupMenu(true);
return b;
}
/**
* This method is called by installUI to get the editor component
* of the <code>JSpinner</code>. By default it just returns
* <code>JSpinner.getEditor()</code>. Subclasses can override
* <code>createEditor</code> to return a component that contains
* the spinner's editor or null, if they're going to handle adding
* the editor to the <code>JSpinner</code> in an
* <code>installUI</code> override.
* <p>
* Typically this method would be overridden to wrap the editor
* with a container with a custom border, since one can't assume
* that the editors border can be set directly.
* <p>
* The <code>replaceEditor</code> method is called when the spinners
* editor is changed with <code>JSpinner.setEditor</code>. If you've
* overriden this method, then you'll probably want to override
* <code>replaceEditor</code> as well.
*
* @return the JSpinners editor JComponent, spinner.getEditor() by default
* @see #installUI
* @see #replaceEditor
* @see JSpinner#getEditor
*/
editor.setInheritsPopupMenu(true);
return editor;
}
/**
* Called by the <code>PropertyChangeListener</code> when the
* <code>JSpinner</code> editor property changes. It's the responsibility
* of this method to remove the old editor and add the new one. By
* default this operation is just:
* <pre>
* spinner.remove(oldEditor);
* spinner.add(newEditor, "Editor");
* </pre>
* The implementation of <code>replaceEditor</code> should be coordinated
* with the <code>createEditor</code> method.
*
* @see #createEditor
* @see #createPropertyChangeListener
*/
newEditor.setInheritsPopupMenu(true);
}
// if editor alignment isn't set in LAF, we get 0 (CENTER) here
}
}
/**
* Remove the border around the inner editor component for LaFs
* that install an outside border around the spinner,
*/
}
}
}
}
/**
* Remove the border around the inner editor component for LaFs
* that install an outside border around the spinner,
*/
}
}
}
}
}
}
}
}
/**
* Updates the enabled state of the children Components based on the
* enabled state of the <code>JSpinner</code>.
*/
private void updateEnabledState() {
}
/**
* Recursively updates the enabled state of the child
* <code>Component</code>s of <code>c</code>.
*/
"Spinner.disableOnBoundaryValues", false)) {
child.setEnabled(false);
}
child.setEnabled(false);
}
else {
}
}
else {
}
}
}
}
/**
* Installs the keyboard Actions onto the JSpinner.
*
* @since 1.5
*/
protected void installKeyboardActions() {
iMap);
"Spinner.actionMap");
}
/**
* Returns the InputMap to install for <code>condition</code>.
*/
"Spinner.ancestorInputMap");
}
return null;
}
}
/**
* Returns the baseline.
*
* @throws NullPointerException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
* @see javax.swing.JComponent#getBaseline(int, int)
* @since 1.6
*/
if (baseline >= 0) {
}
}
return -1;
}
/**
* Returns an enum indicating how the baseline of the component
* changes as the size changes.
*
* @throws NullPointerException {@inheritDoc}
* @see javax.swing.JComponent#getBaseline(int, int)
* @since 1.6
*/
JComponent c) {
super.getBaselineResizeBehavior(c);
}
/**
* A handler for spinner arrow button mouse and action events. When
* a left mouse pressed event occurs we look up the (enabled) spinner
* that's the source of the event and start the autorepeat timer. The
* timer fires action events until any button is released at which
* point the timer is stopped and the reference to the spinner cleared.
* The timer doesn't start until after a 300ms delay, so often the
* source of the initial (and final) action event is just the button
* logic for mouse released - which means that we're relying on the fact
* that our mouse listener runs after the buttons mouse listener.
* <p>
* Note that one instance of this handler is shared by all slider previous
* arrow buttons and likewise for all of the next buttons,
* so it doesn't have any state that persists beyond the limits
*/
final boolean isNext;
super(name);
}
}
}
// Most likely resulting from being in ActionMap.
spinner = eventToSpinner(e);
}
} else {
&& autoRepeatTimer.isRunning()) {
arrowButton = null;
}
}
try {
if (calendarField != -1) {
}
}
} catch (IllegalArgumentException iae) {
} catch (ParseException pe) {
}
}
}
/**
* If the spinner's editor is a DateEditor, this selects the field
* associated with the value that is being incremented.
*/
try {
}
}
catch (IllegalArgumentException iae) {}
}
}
}
}
/**
* Selects the passed in field, returning true if it is found,
* false otherwise.
*/
do {
}
return true;
}
return false;
}
/**
* Returns the calendarField under the start of the selection, or
* -1 if there is no valid calendar field under the selection (or
* the spinner isn't editing dates.
*/
ftf.getFormatter();
if (formatter instanceof InternationalFormatter) {
int calendarField;
}
else {
}
if (calendarField != -1) {
return calendarField;
}
}
}
}
}
return -1;
}
spinner = eventToSpinner(e);
}
}
arrowButton = null;
}
}
}
}
if (autoRepeatTimer.isRunning()) {
}
}
/**
* Requests focus on a child of the spinner if the spinner doesn't
* have focus.
*/
private void focusSpinnerIfNecessary() {
if (spinner.isRequestFocusEnabled() && (
if (!root.isFocusCycleRoot()) {
}
}
}
}
}
}
if (spinner == eventToSpinner(e)) {
if (autoRepeatTimer.isRunning()) {
}
if (arrowButton != null) {
model.setPressed(false);
arrowButton = null;
}
}
}
}
//
// LayoutManager
//
nextButton = c;
}
previousButton = c;
}
editor = c;
}
}
if (c == nextButton) {
nextButton = null;
}
else if (c == previousButton) {
}
else if (c == editor) {
}
}
}
/* Force the editors height to be a multiple of 2
*/
return size;
}
return preferredLayoutSize(parent);
}
if (c != null) {
}
}
return;
}
// The arrowButtonInsets value is used instead of the JSpinner's
// insets if not null. Defining this to be (0, 0, 0, 0) causes the
// buttons to be aligned with the outer edge of the spinner's
// border, and leaving it as "null" places the buttons completely
// inside the spinner's border.
if (buttonInsets == null) {
}
/* Deal with the spinner's componentOrientation property.
*/
} else {
}
}
//
// PropertyChangeListener
//
{
if (spinnerUI instanceof BasicSpinnerUI) {
JTextField tf =
}
}
JTextField tf =
}
}
}
}
}
JTextField tf =
}
}
}
}
}
}
} else if (e.getSource() instanceof JComponent) {
if (spinnerUI instanceof BasicSpinnerUI) {
}
}
}
}
// Syncronizes the ToolTip text for the components within the spinner
// to be the same value as the spinner ToolTip text.
}
} else if (children[i] instanceof JComponent) {
}
}
}
"Spinner.disableOnBoundaryValues", false) &&
spinnerUI instanceof BasicSpinnerUI) {
}
}
}
}
}