Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gui/imprt/PreferencePanel.java


1   /*
2    * PreferencePanel.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:30 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gui.imprt;
12  
13  import java.awt.BorderLayout;
14  import java.awt.Checkbox;
15  import java.awt.GridBagConstraints;
16  import java.awt.GridBagLayout;
17  import java.awt.Insets;
18  import java.awt.Panel;
19  import java.awt.event.ItemEvent;
20  import java.awt.event.ItemListener;
21  import java.beans.PropertyChangeEvent;
22  import java.beans.PropertyChangeListener;
23  import java.util.Observable;
24  import java.util.Observer;
25  
26  import com.flexstor.common.awt.AWTUtil;
27  import com.flexstor.common.awt.DatePanel;
28  import com.flexstor.common.awt.FlexBorderPanel;
29  import com.flexstor.common.awt.FlexPanel;
30  import com.flexstor.common.resources.Resources;
31  import com.flexstor.common.settings.ImportSettingsI;
32  
33  
34  
35  
36  public class PreferencePanel
37     extends FlexPanel
38     implements  PropertyChangeListener, Observer, ItemListener
39  {
40     protected  Checkbox cbThumbinfo  = new Checkbox(Resources.get(6572));
41     protected  Checkbox cbMatchinfo  = new Checkbox(Resources.get(6573));
42  
43     protected  Checkbox chToClassify    = new Checkbox(Resources.get(6546));
44     protected  Checkbox chBoxDefault = new Checkbox(Resources.get(6547));
45  
46     protected  boolean             bValid          = false;
47     protected  DatePanel         pnlDate         = null;
48     protected  ConfirmationPanel pnlConfirmation = null;
49  
50     /**
51      * The GridBagLayout : Layout used for laying the components on this panel.
52      *
53      * @since 3.0
54      */
55  
56     protected GridBagLayout gbl      = new GridBagLayout();
57  
58     /**
59      * The GridBagConstraints : Class encapsulate all the constraints to be applied
60      * on laying out a component.
61      *
62      * @since 3.0
63      */
64     protected GridBagConstraints gbc = new GridBagConstraints();
65  
66  
67     protected SettingsModelI model     = null;
68     protected java.awt.Frame parentFrame = null;
69  
70     public PreferencePanel( java.awt.Frame parentFrame, SettingsModelI model )
71     {
72  
73       this.parentFrame       = parentFrame;
74       this.model             = model;
75       setLayout ( new BorderLayout() );
76       add ( "North", getNorthPanel() );
77       add ( "Center", getEmailPanel() );
78       add ( "South", getRestPanel() );
79     }
80  
81     public void loadData ()
82     {
83       if ( model == null )
84         return;
85  
86       cbThumbinfo.setState  ( model.canPerform ( ImportSettingsI.THUMB_INFO ) );
87       cbMatchinfo.setState  ( model.canPerform ( ImportSettingsI.MATCH_INFO ) );
88  
89       chToClassify.setState   ( !model.isFromRetrieval() );
90  //   model.setBoxChecked ( ImportSettingsI.TO_CLASSIFY, !model.isFromRetrieval(), false );
91  
92       chBoxDefault.setState ( model.canPerform ( ImportSettingsI.SET_AS_DEFAULT ) );
93  
94  //   pnlDate
95       Object date = model.getImportTime();
96  
97       if ( date instanceof java.util.Date )
98       {
99         pnlDate.setDate ( ( java.util.Date ) date );
100      }
101      pnlConfirmation.setAddress  ( model.getEmailAddress() );
102      pnlConfirmation.setConfirm  ( model.canPerform ( ImportSettingsI.EMAIL_CONFIRM ) );
103 
104    }
105 
106 
107    public void update(Observable obs, Object obj)
108    {
109      if ( model == null )
110       return; // nothing to do here !
111 
112      Notification cmd = ( Notification )obj;
113      String     command = ( String )cmd.getCommand();
114      if ( command.equals ( ImportSettingsI.SETTING_CHANGED ) )
115      {
116        loadData();
117      }
118    }
119 
120    public Panel getNorthPanel()
121    {
122       Panel panel = new Panel();
123       panel.setLayout ( new BorderLayout() );
124       panel.add ( "Center", getCapturePanel() );
125       return panel;
126    }
127 
128    public FlexBorderPanel getCapturePanel()
129    {
130       FlexBorderPanel cbPanel = new FlexBorderPanel( Resources.get(6571) );
131       try
132       {
133        cbPanel.setPadding( 1, 1, 4, 4 );
134        cbPanel.setBevelStyle( FlexBorderPanel.BEVEL_LINE );
135        cbPanel.setAlignStyle( FlexBorderPanel.ALIGN_LEFT );
136       }
137       catch ( Exception e ){}
138 
139       gbl = new GridBagLayout();
140 
141       cbPanel.setLayout ( gbl );
142 
143       gbc = AWTUtil.getGbc( 0, 1, 0, 0, gbc.WEST, gbc.NONE );
144       gbc.insets = new Insets( 8, 7, 8, 4 );
145       gbl.setConstraints( cbThumbinfo, gbc );
146       cbPanel.add( cbThumbinfo );
147 
148       gbc = AWTUtil.getGbc( 0, 2, 0.5, 0, gbc.WEST, gbc.NONE );
149       gbc.insets = new Insets( 8, 7, 8, 4 );
150       gbl.setConstraints( cbMatchinfo, gbc );
151       cbPanel.add( cbMatchinfo );
152 
153       cbThumbinfo.addItemListener ( this );
154       cbMatchinfo.addItemListener ( this );
155 
156       return cbPanel;
157 
158    }
159    public FlexBorderPanel getEmailPanel()
160    {
161         FlexBorderPanel cbPanel = new FlexBorderPanel("");
162 
163         try
164         {
165          cbPanel.setPadding( 10,6,4,4 );
166          cbPanel.setBevelStyle( FlexBorderPanel.BEVEL_LINE );
167          cbPanel.setAlignStyle( FlexBorderPanel.ALIGN_LEFT );
168         }
169         catch ( Exception e ){}
170 
171         gbl = new GridBagLayout();
172         cbPanel.setLayout ( gbl );
173 
174         pnlDate = new DatePanel( null, Resources.get ( 6361 ) );
175         pnlDate.setLowerLimit( new java.util.Date() );  // restrict to dates in the future
176 
177         // The date panel should not be enabled if setting dialog is
178         // brought up from the admin tool !
179 
180         if ( model != null )
181         {
182            pnlDate.enableInput ( model.canImport() );
183         }
184 
185         gbc.gridwidth = 2;
186         gbc.insets = new Insets(8,0,0,0);
187         gbc = AWTUtil.getGbc(0,2,1,1,gbc.NORTHWEST,gbc.HORIZONTAL);//gbc.BOTH
188         gbl.setConstraints(pnlDate, gbc);
189         cbPanel.add(pnlDate);
190 
191         pnlConfirmation = new ConfirmationPanel(null);
192         gbc = AWTUtil.getGbc(0,1,1,1,gbc.NORTHWEST,GridBagConstraints.HORIZONTAL); //gbc.BOTH
193         gbc.gridwidth = 2;
194         gbc.insets = new Insets(8,0,0,0);
195         gbl.setConstraints(pnlConfirmation, gbc);
196         cbPanel.add(pnlConfirmation);
197 
198         pnlConfirmation.addPropertyChangeListener(this);
199         pnlDate.addPropertyChangeListener(this);
200 
201         return cbPanel;
202    }
203    public Panel getRestPanel()
204    {
205       //
206       FlexBorderPanel cbPanel = new FlexBorderPanel( "");
207       try
208       {
209        cbPanel.setPadding( 1, 1, 4, 4 );
210        cbPanel.setBevelStyle( FlexBorderPanel.BEVEL_LINE );
211        cbPanel.setAlignStyle( FlexBorderPanel.ALIGN_LEFT );
212       }
213       catch ( Exception e ){}
214 
215       gbl = new GridBagLayout();
216 
217       cbPanel.setLayout ( gbl );
218 
219       gbc = AWTUtil.getGbc( 0, 1, 0, 0, gbc.WEST, gbc.NONE );
220       gbc.insets = new Insets( 4, 10, 4, 4 );
221       gbl.setConstraints( chToClassify, gbc );
222       cbPanel.add( chToClassify );
223 
224       gbc = AWTUtil.getGbc( 0, 2, 0.5, 0, gbc.WEST, gbc.NONE );
225       gbc.insets = new Insets( 4, 10, 4, 4 );
226       gbl.setConstraints( chBoxDefault, gbc );
227       cbPanel.add( chBoxDefault );
228 
229       chToClassify.addItemListener ( this );
230       chBoxDefault.addItemListener ( this );
231 
232       // If import is from main tool bar, the files (assets) should go to
233       // system disguise only and should not be classified. The user should
234       // always see this box checked if its from main tool bar and unckecked
235       // if its from search retrieval. Right now we do not allow user to change
236       // it, although we can make current behavior default and allow the user to
237       // make a choice to either classify it or not, but thats future talks folks !!
238       chToClassify.setEnabled ( false );
239       return cbPanel;
240    }
241 
242 
243    public java.awt.Dimension getMinimumSize()
244    {
245       return new java.awt.Dimension(320, 415);
246    }
247 
248 
249   /**
250    * isSetDefaults() - returns the value of the chBoxDefault check box.
251    * Needed for saving the default Settings Dialog state.
252    */
253    public boolean isSetDefault()
254    {
255       return chBoxDefault.getState();
256    }
257 
258    /**
259     * getMailString() - return the string selected in the deliveryChoice
260     * box.  Needed for saving the default Settings Dialog state.
261     */
262    public String getMailString()
263    {
264       String dt = pnlConfirmation.getAddress();
265 
266       if ( dt == null )
267         return "nobody@nowhere.com";
268 
269       return dt;
270    }
271 
272   /**
273    * getImportTime - returns a String representing the  military time
274    * for e-mail delivery.  The deliveryChoice index + 5 is the military
275    * time to send the e-mail.  This string is needed by the e-mail class
276    * called by the import processor
277    */
278    public Object getImportTime()
279    {
280       if ( pnlDate.getDate() == null )
281         return new Object();
282       return pnlDate.getDate();
283    }
284 
285 
286    /**
287     * getThumbInfo - Returns the state of the Capture thumbnail X,Y resolution checkbox
288     * as a string, because the value will be added to Settings
289     **/
290    public boolean getThumbInfo()
291    {
292      return cbThumbinfo.getState();
293    }
294    public boolean getMatchInfo()
295    {
296      return cbMatchinfo.getState();
297    }
298 
299 
300    protected boolean canPerformDefaultAction()
301    {
302        return bValid;
303    }
304 
305    public void propertyChange(PropertyChangeEvent e)
306    {
307       if ( model != null )
308       {
309         model.setEmailAddress ( getMailString(), true );
310         if ( getImportTime() instanceof java.util.Date )
311           model.setImportTime   ( getImportTime(), true, false );
312         model.setBoxChecked   ( ImportSettingsI.EMAIL_CONFIRM, pnlConfirmation.emailToBeSent(), true );
313       }
314    }
315 
316    public void configureComponents ()
317    {
318         if ( model != null )
319         {
320            pnlDate.enableInput ( model.canImport() );
321         }
322    }
323    public void itemStateChanged ( ItemEvent event )
324    {
325       if ( model == null )
326        return;
327 
328       java.awt.Component component = ( java.awt.Component )event.getSource();
329       if ( component == cbThumbinfo )
330       {
331         model.setBoxChecked ( ImportSettingsI.THUMB_INFO, cbThumbinfo.getState(), true );
332       }
333       else if ( component == cbMatchinfo )
334       {
335         model.setBoxChecked ( ImportSettingsI.MATCH_INFO, cbMatchinfo.getState(), true  );
336       }
337       else if ( component == chBoxDefault )
338       {
339         model.setBoxChecked ( ImportSettingsI.SET_AS_DEFAULT, chBoxDefault.getState(), true  );
340       }
341    }
342 
343 } // ImprtPrefsPanel
344 
345 
346