1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: DateCriteriaView.java,v 1.3 2002/09/05 15:41:47 ludovicc Exp $
37 */
38 package samples.filefind;
39
40 import java.awt.GridBagLayout;
41 import javax.swing.JLabel;
42
43 import org.scopemvc.core.*;
44 import org.scopemvc.view.swing.*;
45 import org.scopemvc.view.swing.*;
46 import org.scopemvc.view.swing.SPanel;
47 import samples.util.GridBagHelper;
48
49 /***
50 * @author <A HREF="mailto:daniel.michalik@autel.cz">Daniel Michalik</A>
51 * @created 05 September 2002
52 * @version $Revision: 1.3 $ $Date: 2002/09/05 15:41:47 $
53 */
54 public class DateCriteriaView extends SPanel {
55
56 /***
57 * A ModelChangeListener to enable/disable controls as the model changes
58 * state.
59 */
60 ModelChangeListener myModelChangeListener =
61 new ModelChangeListener() {
62 public void modelChanged(ModelChangeEvent e) {
63 SearchViewModel m = (SearchViewModel) e.getModel();
64 if (!m.isDateCriteriaEnabled()) {
65 return;
66 }
67 DateCriteriaModel d = m.getDateCriteria();
68 lastDays.setEditable(d.isLastDaysEnabled());
69 lastMonths.setEditable(d.isLastMonthsEnabled());
70 dateTo.setEditable(d.isIntervalEnabled());
71 dateFrom.setEditable(d.isIntervalEnabled());
72 }
73 };
74
75 private STextField lastDays;
76 private STextField lastMonths;
77 private STextField dateTo;
78 private STextField dateFrom;
79
80
81 /***
82 * Constructor for the DateCriteriaView object
83 */
84 public DateCriteriaView() {
85
86 // Bind this SPanel to the dateCriteria submodel of the SearchViewModel
87 setSelectorString("dateCriteria");
88
89 GridBagLayout gridbag = new GridBagLayout();
90 gridbag.columnWidths = new int[]{0, 11, 30, 11, 0};
91 gridbag.columnWeights = new double[]{0, 0, 0, 0, 1};
92 gridbag.rowHeights = new int[]{0, 5, 0, 5, 0, 5, 0, 11};
93 gridbag.rowWeights = new double[]{0, 0, 0, 0, 0, 0, 0, 1};
94 setLayout(gridbag);
95 GridBagHelper hlp = new GridBagHelper();
96
97 SRadioButton b = new SRadioButton();
98 b.setText("In Last");
99 b.setSelector(DateCriteriaModel.LAST_MONTHS_ENABLED);
100 add(b, hlp.xy(0, 0, "we"));
101
102 lastMonths = new STextField();
103 lastMonths.setSelector(DateCriteriaModel.LAST_MONTHS);
104 lastMonths.setColumns(4);
105 add(lastMonths, hlp.xy(2, 0, "w"));
106
107 add(new JLabel("Months"), hlp.xywh(2, 0, 3, 1, "e"));
108
109 b = new SRadioButton();
110 b.setText("In Last");
111 b.setSelector(DateCriteriaModel.LAST_DAYS_ENABLED);
112 add(b, hlp.xy(0, 2, "w"));
113
114 lastDays = new STextField();
115 lastDays.setSelector(DateCriteriaModel.LAST_DAYS);
116 lastDays.setColumns(4);
117 add(lastDays, hlp.xy(2, 2, "w"));
118
119 add(new JLabel("Days"), hlp.xywh(2, 2, 3, 1, "e"));
120
121 b = new SRadioButton();
122 b.setText("Between");
123 b.setSelector(DateCriteriaModel.INTERVAL_ENABLED);
124 add(b, hlp.xy(0, 4, "we"));
125
126 dateFrom = new STextField();
127 dateFrom.setSelector(DateCriteriaModel.DATE_FROM);
128 dateFrom.setColumns(7);
129 add(dateFrom, hlp.xy(2, 4, "we"));
130
131 dateTo = new STextField();
132 dateTo.setSelector(DateCriteriaModel.DATE_TO);
133 dateTo.setColumns(7);
134 add(dateTo, hlp.xy(2, 6, "we"));
135
136 add(new JLabel("and"), hlp.xy(0, 6, "e"));
137 }
138
139
140 /***
141 * Override to add a listener that will enable/disable controls as the model
142 * changes state.
143 *
144 * @param inModel The new boundModel value
145 */
146 public void setBoundModel(Object inModel) {
147 super.setBoundModel(inModel);
148 ModelChangeEventSource m = (ModelChangeEventSource) inModel;
149 m.addModelChangeListener(myModelChangeListener);
150 }
151 }
This page was automatically generated by Maven