KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > BooleanModel


1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 /**
14  * Represents a boolean value that can be monitored for state changes.
15  * The getState() method inherited from Model will always return a non-null
16  * Boolean object.
17  *
18  * @since 3.0
19  */

20 public class BooleanModel extends Model {
21     
22     /**
23      * Creates a new BooleanModel with the given initial state
24      *
25      * @param initialState initial value of the model
26      */

27     public BooleanModel(boolean initialState) {
28         super(new Boolean JavaDoc(initialState));
29     }
30     
31     /**
32      * Sets the value and notifies all change listeners
33      *
34      * @param newValue new
35      */

36     public void set(boolean newValue) {
37         set(newValue, null);
38     }
39     
40     /**
41      * Sets the value and notifies all change listeners except
42      * the listener that caused the change.
43      *
44      * @param newValue new boolean value
45      * @param origin change listener that caused the change, or null if
46      * the change was not caused by a change listener.
47      *
48      */

49     public void set(boolean newValue, IChangeListener origin) {
50         super.setState(new Boolean JavaDoc(newValue), origin);
51     }
52     
53     /**
54      * Returns the current value as a boolean
55      *
56      * @return the current value
57      */

58     public boolean get() {
59         return ((Boolean JavaDoc)getState()).booleanValue();
60     }
61 }
62
Popular Tags