Home | History | Annotate | Download | only in swing
      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 2009 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 package org.opensolaris.os.vp.panels.example.time2.client.swing;
     28 
     29 import java.awt.Component;
     30 import java.io.IOException;
     31 import java.util.Date;
     32 import org.opensolaris.os.vp.panel.common.action.*;
     33 import org.opensolaris.os.vp.panel.common.control.*;
     34 import org.opensolaris.os.vp.panel.swing.control.SwingSettingsControl;
     35 
     36 public class TimeControl
     37     extends SwingSettingsControl<TimePanelDescriptor, TimePanel> {
     38 
     39     //
     40     // Instance data
     41     //
     42 
     43     private Date date;
     44 
     45     //
     46     // Constructors
     47     //
     48 
     49     public TimeControl(TimePanelDescriptor descriptor) {
     50 	super(descriptor.getId(), descriptor.getName(), descriptor);
     51     }
     52 
     53     //
     54     // Control methods
     55     //
     56 
     57     @Override
     58     protected void save() throws ActionAbortedException, ActionFailedException,
     59 	ActionUnauthorizedException {
     60 
     61 	Date newDate = (Date)getComponent().getSpinnerDateModel().getValue();
     62 
     63 	if (!newDate.equals(date)) {
     64 	    long time = date.getTime();
     65 	    try {
     66 		getPanelDescriptor().getTimeBean().setTime(time);
     67 	    } catch (IOException e) {
     68 		throw new ActionFailedException(e);
     69 	    } catch (SecurityException e) {
     70 		throw new ActionUnauthorizedException(e);
     71 	    }
     72 	}
     73     }
     74 
     75     //
     76     // SwingControl methods
     77     //
     78 
     79     @Override
     80     protected TimePanel createComponent() {
     81 	TimePanel panel = new TimePanel();
     82 
     83 	addDefaultApplyAction(panel);
     84 	addDefaultCancelAction(panel, true);
     85 	addDefaultOkayAction(panel, true);
     86 
     87 	return panel;
     88     }
     89 
     90     @Override
     91     protected void initComponent() {
     92 	long time = getPanelDescriptor().getTimeBean().getTime();
     93 	date = new Date(time);
     94 	getComponent().getSpinnerDateModel().setValue(date);
     95     }
     96 }
     97