1 239 stephen /* 2 239 stephen * CDDL HEADER START 3 239 stephen * 4 239 stephen * The contents of this file are subject to the terms of the 5 239 stephen * Common Development and Distribution License (the "License"). 6 239 stephen * You may not use this file except in compliance with the License. 7 239 stephen * 8 239 stephen * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 239 stephen * or http://www.opensolaris.org/os/licensing. 10 239 stephen * See the License for the specific language governing permissions 11 239 stephen * and limitations under the License. 12 239 stephen * 13 239 stephen * When distributing Covered Code, include this CDDL HEADER in each 14 239 stephen * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 239 stephen * If applicable, add the following below this CDDL HEADER, with the 16 239 stephen * fields enclosed by brackets "[]" replaced with your own identifying 17 239 stephen * information: Portions Copyright [yyyy] [name of copyright owner] 18 239 stephen * 19 239 stephen * CDDL HEADER END 20 239 stephen */ 21 239 stephen 22 239 stephen /* 23 239 stephen * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 239 stephen * Use is subject to license terms. 25 239 stephen */ 26 239 stephen 27 239 stephen package org.opensolaris.os.vp.panels.example.time2.client.swing; 28 239 stephen 29 239 stephen import java.awt.Component; 30 239 stephen import java.io.IOException; 31 239 stephen import java.util.Date; 32 239 stephen import org.opensolaris.os.vp.panel.common.action.*; 33 239 stephen import org.opensolaris.os.vp.panel.common.control.*; 34 239 stephen import org.opensolaris.os.vp.panel.swing.control.SwingSettingsControl; 35 239 stephen 36 239 stephen public class TimeControl 37 239 stephen extends SwingSettingsControl<TimePanelDescriptor, TimePanel> { 38 239 stephen 39 239 stephen // 40 239 stephen // Instance data 41 239 stephen // 42 239 stephen 43 239 stephen private Date date; 44 239 stephen 45 239 stephen // 46 239 stephen // Constructors 47 239 stephen // 48 239 stephen 49 239 stephen public TimeControl(TimePanelDescriptor descriptor) { 50 239 stephen super(descriptor.getId(), descriptor.getName(), descriptor); 51 239 stephen } 52 239 stephen 53 239 stephen // 54 239 stephen // Control methods 55 239 stephen // 56 239 stephen 57 239 stephen @Override 58 239 stephen protected void save() throws ActionAbortedException, ActionFailedException, 59 239 stephen ActionUnauthorizedException { 60 239 stephen 61 239 stephen Date newDate = (Date)getComponent().getSpinnerDateModel().getValue(); 62 244 stephen 63 239 stephen if (!newDate.equals(date)) { 64 239 stephen long time = date.getTime(); 65 239 stephen try { 66 239 stephen getPanelDescriptor().getTimeBean().setTime(time); 67 239 stephen } catch (IOException e) { 68 239 stephen throw new ActionFailedException(e); 69 239 stephen } catch (SecurityException e) { 70 239 stephen throw new ActionUnauthorizedException(e); 71 239 stephen } 72 239 stephen } 73 239 stephen } 74 239 stephen 75 239 stephen // 76 239 stephen // SwingControl methods 77 239 stephen // 78 239 stephen 79 239 stephen @Override 80 244 stephen protected TimePanel createComponent() { 81 239 stephen TimePanel panel = new TimePanel(); 82 244 stephen 83 244 stephen addDefaultApplyAction(panel); 84 244 stephen addDefaultCancelAction(panel, true); 85 244 stephen addDefaultOkayAction(panel, true); 86 244 stephen 87 244 stephen return panel; 88 239 stephen } 89 239 stephen 90 239 stephen @Override 91 239 stephen protected void initComponent() { 92 239 stephen long time = getPanelDescriptor().getTimeBean().getTime(); 93 239 stephen date = new Date(time); 94 239 stephen getComponent().getSpinnerDateModel().setValue(date); 95 239 stephen } 96 239 stephen } 97