r2750 - in trunk: jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor jaxx-demo/src/main/java/jaxx/demo/tree jaxx-widgets/src/main/java/jaxx/runtime/swing/editor
Author: tchemit Date: 2013-11-22 17:44:52 +0100 (Fri, 22 Nov 2013) New Revision: 2750 Url: http://nuiton.org/projects/jaxx/repository/revisions/2750 Log: fixes #2924: Introduce a new *Simple* time editor. Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,40 @@ +/* + * #%L + * JAXX :: Demo + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +#configPanel { + border:{new TitledBorder(_("jaxxdemo.numbereditor.configuration"))}; + layout:{new GridLayout(0,1)}; +} + +#editor { + property:"time"; + border:{new TitledBorder(_("jaxxdemo.timeeditor.editor"))}; + bean:{demoModel}; + date:{demoModel.getTime()}; +} + +#resultPane { + border:{new TitledBorder(_("jaxxdemo.timeeditor.model"))}; + layout:{new BorderLayout()}; +} Property changes on: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,85 @@ +<jaxx.demo.DemoPanel layout='{new BorderLayout()}'> + + <import> + jaxx.runtime.swing.editor.SimpleTimeEditor + + static org.nuiton.i18n.I18n._ + </import> + + <!-- model --> + <SimpleTimeEditorDemoModel id='demoModel'/> + + <script><![CDATA[ + +@Override +protected String[] getSources() { + return new String[]{ getDefaultSource(), + "SimpleTimeEditorModel.java", + "SimpleTimeEditorDemo.css" + }; +} + +void $afterCompleteSetup() { + + // init time editor + editor.init(); + + // set current time in model + demoModel.setTime(new java.util.Date()); +} +]]> + </script> + + + <Table insets='0' fill='both' weightx='1' constraints='BorderLayout.NORTH'> + <row> + <cell> + <JPanel id="configPanel"> + + <!--JCheckBox id='useFloat' + text='jaxxdemo.numbereditor.useFloat' + selected='true'/> + + <JCheckBox id='useSign' + text='jaxxdemo.numbereditor.useSign' + selected='true'/> + + <JCheckBox id='showPopupButton' + text='jaxxdemo.numbereditor.showPopupButton' + selected='true'/> + + <JCheckBox id='showResetButton' + text='jaxxdemo.numbereditor.showReset' + selected='true'/> + + <JCheckBox id='autoPopup' + text='jaxxdemo.numbereditor.autoPopup' + selected='false'/--> + + </JPanel> + </cell> + </row> + <row> + <cell> + <SimpleTimeEditor id='editor' constructorParams='this' + border='{new TitledBorder(_("jaxxdemo.timeeditor.editor"))}'/> + <!--property='time'--> + <!--bean='{demoModel}'--> + <!--date="{demoModel.getTime()}"/>--> + </cell> + </row> + <row> + <cell> + + <JPanel id='resultPane'> + + <JLabel constraints='BorderLayout.CENTER' + text='{_("jaxxdemo.timeeditor.value", demoModel.getTime())}'/> + </JPanel> + + </cell> + </row> + </Table> + + +</jaxx.demo.DemoPanel> \ No newline at end of file Property changes on: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,10 @@ +package jaxx.demo.component.jaxx.editor; + +/** + * Created on 11/22/13. + * + * @author Tony CHEMIT <chemit@codelutin.com> + * @since 2.5.31 + */ +public class SimpleTimeEditorDemoHandler { +} Property changes on: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java (from rev 2749, trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java) =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,57 @@ +/* + * #%L + * JAXX :: Demo + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.demo.component.jaxx.editor; + +import jaxx.runtime.swing.editor.SimpleTimeEditor; +import org.jdesktop.beans.AbstractSerializableBean; + +import java.util.Date; + +/** + * Model of a bean using the {@link SimpleTimeEditor}. + * + * @author Tony CHEMIT <chemit@codelutin.com> + * @since 2.5.31 + */ +public class SimpleTimeEditorDemoModel extends AbstractSerializableBean { + + public static final String TIME_PROPERTY = "time"; + + private static final long serialVersionUID = 1L; + + protected Date time; + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + Date old = this.time; + this.time = time; + firePropertyChange(TIME_PROPERTY, old, time); + } + + +} Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java 2013-11-12 09:12:54 UTC (rev 2749) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java 2013-11-22 16:44:52 UTC (rev 2750) @@ -28,13 +28,13 @@ import jaxx.demo.component.jaxx.BoxedDecoratorDemo; import jaxx.demo.component.jaxx.StatusMessagePanelDemo; import jaxx.demo.component.jaxx.editor.BeanComboBoxDemo; -import jaxx.demo.component.jaxx.editor.BeanComboBoxDemoHandler; import jaxx.demo.component.jaxx.editor.ComboEditorDemo; import jaxx.demo.component.jaxx.editor.DatePickerDemo; import jaxx.demo.component.jaxx.editor.FileEditorDemo; import jaxx.demo.component.jaxx.editor.I18nEditorDemo; import jaxx.demo.component.jaxx.editor.ListSelectorDemo; import jaxx.demo.component.jaxx.editor.NumberEditorDemo; +import jaxx.demo.component.jaxx.editor.SimpleTimeEditorDemo; import jaxx.demo.component.jaxx.editor.TimeEditorDemo; import jaxx.demo.component.swing.HidorButtonDemo; import jaxx.demo.component.swing.JButtonDemo; @@ -158,6 +158,7 @@ addMapping(n_("jaxxdemo.component.jaxx.editor"), TimeEditorDemo.class, + SimpleTimeEditorDemo.class, NumberEditorDemo.class, ComboEditorDemo.class, I18nEditorDemo.class, Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,44 @@ +/* + * #%L + * JAXX :: Widgets + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +#hour { + value: {model.getTimeModel() / 60}; + enabled: {isEnabled()}; + model: {new SpinnerNumberModel(0, 0, 23, 1)}; +} + +#labelH { + text: "timeeditor.H"; + horizontalAlignment: center; +} + +#minuteModel { + calendarField: {java.util.Calendar.MINUTE}; + value: {handler.setMinuteModel(model.getDate())}; +} + +#minute { + enabled: {isEnabled()}; + model: {minuteModel}; +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,63 @@ +<!-- + #%L + JAXX :: Widgets + $Id$ + $HeadURL$ + %% + Copyright (C) 2008 - 2013 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program 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 Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<Table constraints='BorderLayout.NORTH' fill='horizontal' insets='0'> + <import> + java.io.Serializable + java.util.Date + java.awt.BorderLayout + javax.swing.SpinnerNumberModel + javax.swing.DefaultBoundedRangeModel + </import> + + <!-- ui handler --> + <SimpleTimeEditorModel id='model'/> + + <!-- spinner minute editor --> + <SpinnerDateModel id="minuteModel"/> + + <SimpleTimeEditorHandler id='handler' constructorParams='this'/> + + <script><![CDATA[ +public void init() { handler.init(); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setProperty(String property ) { model.setProperty(property); } +public void setDate(Date date) { model.setDate(date); } +]]> + </script> + + <row> + <cell weightx='0.5'> + <JSpinner id='hour' + onStateChanged='handler.updateTimeModelFromHour((Integer)hour.getValue())'/> + </cell> + <cell> + <JLabel id='labelH'/> + </cell> + <cell weightx='0.5'> + <JSpinner id='minute' + onStateChanged='handler.updateTimeModelFromMinute(minuteModel.getDate())'/> + </cell> + </row> +</Table> \ No newline at end of file Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,266 @@ +package jaxx.runtime.swing.editor; + +/* + * #%L + * JAXX :: Widgets + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JSpinner; +import javax.swing.SpinnerDateModel; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.util.Calendar; +import java.util.Date; + +/** + * @author Tony CHEMIT <chemit@codelutin.com> + * @since 2.5.31 + */ +public class SimpleTimeEditorHandler { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SimpleTimeEditorHandler.class); + + private final SimpleTimeEditor editor; + + private final SimpleTimeEditorModel model; + + /** the mutator method on the property of boxed bean in the editor */ + protected Method mutator; + + protected final Calendar calendarDate; + + protected final Calendar calendarMinute; + + protected final Calendar calendarHour; + + public SimpleTimeEditorHandler(SimpleTimeEditor editor) { + this.editor = editor; + this.model = editor.getModel(); + this.calendarMinute = Calendar.getInstance(); + this.calendarHour = Calendar.getInstance(); + this.calendarDate = Calendar.getInstance(); + } + + public void init() { + + if (model.getBean() == null) { + throw new NullPointerException("can not have a null bean in ui " + editor); + } + + editor.getMinute().setEditor(new JSpinner.DateEditor(editor.getMinute(), "mm")); +// editor.getHour().setEditor(new JSpinner.DateEditor(editor.getHour(), "HH")); + + +// TuttiUIUtil.autoSelectOnFocus(minuteEditor.getTextField()); +// JSpinner.NumberEditor hourEditor = (JSpinner.NumberEditor) editor.getHour().getEditor(); +// TuttiUIUtil.autoSelectOnFocus(hourEditor.getTextField()); + + // listen when date changes (should come from outside) + model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_DATE, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Date date = (Date) evt.getNewValue(); + + if (date != null) { + calendarDate.setTime(date); + int hours = calendarDate.get(Calendar.HOUR_OF_DAY); + int minutes = calendarDate.get(Calendar.MINUTE); + if (log.isDebugEnabled()) { + log.debug("date changed : new value " + hours + ":" + minutes); + } + model.setTimeModel(hours * 60 + minutes); + + } else { + model.setTimeModel(null); + } + + } + }); + + // When time model change, let's push it back in bean + model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_TIME_MODEL, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Integer time = (Integer) evt.getNewValue(); + + int hours = time / 60; + int minutes = time % 60; + + calendarDate.set(Calendar.HOUR_OF_DAY, hours); + calendarDate.set(Calendar.MINUTE, minutes); + + // push it back into the bean + + Date newValue = calendarDate.getTime(); + + if (log.isDebugEnabled()) { + log.debug(model.getProperty() + " on " + model.getBean().getClass() + " :: " + newValue); + } + + try { + getMutator().invoke(model.getBean(), newValue); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + public SimpleTimeEditor getEditor() { + return editor; + } + + protected Date setMinuteModel(Date incomingDate) { + if (incomingDate == null) { + incomingDate = new Date(); + calendarMinute.setTime(incomingDate); + calendarMinute.set(Calendar.HOUR_OF_DAY, 0); + calendarMinute.set(Calendar.MINUTE, 0); + } else { + calendarMinute.setTime(incomingDate); + calendarMinute.set(Calendar.HOUR_OF_DAY, 0); + } + incomingDate = calendarMinute.getTime(); + return incomingDate; + } + + public void updateTimeModelFromHour(Integer hour) { + model.setTimeModel(hour * 60 + model.getMinute()); + } + + public void updateTimeModelFromMinute(Date minuteDate) { + + calendarMinute.setTime(minuteDate); + int newHour = calendarMinute.get(Calendar.HOUR_OF_DAY); + int newMinute = calendarMinute.get(Calendar.MINUTE); + + int oldHour = model.getHour(); + int oldMinute = model.getMinute(); + + if (oldHour == newHour && oldMinute == newMinute) { + + // do nothing, same data + if (log.isDebugEnabled()) { + log.debug("Do not update time model , stay on same time = " + oldHour + ":" + oldMinute); + } + return; + } + + // by default stay on same hour + int hour = oldHour; + + // by default, use the new minute data + int minute = newMinute; + + if (log.isDebugEnabled()) { + log.debug("hh:mm (old from dateModel) = " + oldHour + ":" + oldMinute); + log.debug("hh:mm (new from minuteModel) = " + newHour + ":" + newMinute); + } + + SpinnerDateModel minuteModel = editor.getMinuteModel(); + + if (newMinute == 0) { + + // minute pass to zero (check if a new hour is required) + if (newHour == 1) { + + if (oldHour == 23) { + + // can't pass from 23:59 to 0:00, stay on 23:59 + if (log.isDebugEnabled()) { + log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); + } + minuteModel.setValue(minuteModel.getPreviousValue()); + return; + } + hour = (oldHour + 1) % 24; + } + } else if (newMinute == 59) { + + // minute pass to 59 (check if a new hour is required) + + if (newHour == 23) { + + if (oldHour == 0) { + + // can't pass from 0:00 to 23:59, stay on 0:00 + if (log.isDebugEnabled()) { + log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); + } + minuteModel.setValue(minuteModel.getNextValue()); + return; + } + + // decrease hour + hour = (oldHour - 1) % 24; + } + } + + // date has changed + if (log.isDebugEnabled()) { + log.debug("Update time model to hh:mm = " + hour + ":" + minute); + } + model.setTimeModel(hour * 60 + minute); + } + + protected void setDate(Date oldValue, Date newValue) { + if (model.getBean() != null) { + + if (log.isDebugEnabled()) { + log.debug(model.getProperty() + " on " + model.getBean().getClass() + " :: " + oldValue + " to " + newValue); + } + + try { + getMutator().invoke(model.getBean(), newValue); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + protected Method getMutator() { + if (mutator == null) { + Object bean = model.getBean(); + if (bean == null) { + throw new NullPointerException("could not find bean in " + editor); + } + String property = model.getProperty(); + if (property == null) { + throw new NullPointerException("could not find property in " + editor); + } + + mutator = BeanUIUtil.getMutator(bean, property); + } + return mutator; + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java 2013-11-22 16:44:52 UTC (rev 2750) @@ -0,0 +1,111 @@ +package jaxx.runtime.swing.editor; + +/* + * #%L + * JAXX :: Widgets + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.jdesktop.beans.AbstractSerializableBean; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author Tony CHEMIT <chemit@codelutin.com> + * @since 2.5.31 + */ +public class SimpleTimeEditorModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_DATE = "date"; + + public static final String PROPERTY_TIME_MODEL = "timeModel"; + + public static final String PROPERTY_PROPERTY = "property"; + + public static final String PROPERTY_BEAN = "bean"; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Property of the bean to use. */ + protected String property; + + /** Time model in minutes. */ + protected Integer timeModel = 0; + + /** Real date which contains the edited time. */ + protected Date date; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + Object oldValue = getProperty(); + this.property = property; + firePropertyChange(PROPERTY_PROPERTY, oldValue, property); + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + Object oldValue = getDate(); + this.date = date; + firePropertyChange(PROPERTY_DATE, oldValue, date); + } + + public Integer getTimeModel() { + return timeModel; + } + + public void setTimeModel(Integer timeModel) { + if (timeModel == null) { + timeModel = 0; + } + Object oldValue = getTimeModel(); + this.timeModel = timeModel; + firePropertyChange(PROPERTY_TIME_MODEL, oldValue, timeModel); + } + + public int getMinute() { + return timeModel % 60; + } + + public int getHour() { + return timeModel / 60; + } + +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.nuiton.org