components/visual-panels/core/src/java/util/com/oracle/solaris/vp/util/swing/time/SimpleTimeSelectionModel.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.util.swing.time;
       
    27 
       
    28 import javax.swing.event.*;
       
    29 import com.oracle.solaris.vp.util.swing.event.ChangeListeners;
       
    30 
       
    31 @SuppressWarnings({"serial"})
       
    32 public class SimpleTimeSelectionModel implements TimeSelectionModel {
       
    33     //
       
    34     // Instance data
       
    35     //
       
    36 
       
    37     private int selectedField;
       
    38     private ChangeListeners listeners = new ChangeListeners();
       
    39     private ChangeEvent event = new ChangeEvent(this);
       
    40 
       
    41     //
       
    42     // Constructors
       
    43     //
       
    44 
       
    45     /**
       
    46      * Constructs a {@code SimpleTimeSelectionModel} with the given selected
       
    47      * {@code Calendar} field.
       
    48      *
       
    49      * @param	    selectedField
       
    50      *		    see {@link TimeSelectionModel#setSelectedField}
       
    51      */
       
    52     public SimpleTimeSelectionModel(int selectedField) {
       
    53 	setSelectedField(selectedField);
       
    54     }
       
    55 
       
    56     /**
       
    57      * Constructs an unselected {@code SimpleTimeSelectionModel}.
       
    58      */
       
    59     public SimpleTimeSelectionModel() {
       
    60 	this(-1);
       
    61     }
       
    62 
       
    63     //
       
    64     // TimeSelectionModel methods
       
    65     //
       
    66 
       
    67     @Override
       
    68     public void addChangeListener(ChangeListener listener) {
       
    69 	listeners.add(listener);
       
    70     }
       
    71 
       
    72     @Override
       
    73     public int getSelectedField() {
       
    74 	return selectedField;
       
    75     }
       
    76 
       
    77     @Override
       
    78     public void removeChangeListener(ChangeListener listener) {
       
    79 	listeners.remove(listener);
       
    80     }
       
    81 
       
    82     @Override
       
    83     public void setSelectedField(int selectedField) {
       
    84 	if (this.selectedField != selectedField) {
       
    85 	    this.selectedField = selectedField;
       
    86 	    fireStateChanged();
       
    87 	}
       
    88     }
       
    89 
       
    90     //
       
    91     // SimpleTimeSelectionModel methods
       
    92     //
       
    93 
       
    94     protected void fireStateChanged() {
       
    95 	listeners.stateChanged(event);
       
    96     }
       
    97 }