Source code: com/flexstor/common/gui/imprt/SourcePanel.java
1 /*
2 * SourcePanel.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.Label;
19 import java.awt.Panel;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.util.Observable;
25 import java.util.Observer;
26
27 import com.flexstor.common.awt.AWTUtil;
28 import com.flexstor.common.awt.ActionComponentI;
29 import com.flexstor.common.awt.FlexBorderPanel;
30 import com.flexstor.common.awt.FlexPanel;
31 import com.flexstor.common.awt.event.FlexTextEvent;
32 import com.flexstor.common.awt.event.FlexTextListener;
33 import com.flexstor.common.awt.field.ActionButton;
34 import com.flexstor.common.awt.field.FlexTextField;
35 import com.flexstor.common.parsers.FileNameValidator;
36 import com.flexstor.common.resources.Resources;
37 import com.flexstor.common.settings.ImportSettingsI;
38 //import com.flexstor.common.settings.Settings;
39
40
41 public class SourcePanel extends FlexPanel
42 implements ItemListener, Observer, FlexTextListener, ActionListener
43 {
44
45
46
47 protected FlexTextField tfHiResLoc = new FlexTextField(1000);
48 protected FlexTextField tfLoResLoc = new FlexTextField(1000);
49 // protected FlexTextField tfDriveLoc = new FlexTextField(1000);
50 protected FlexTextField tfLowResExt = new FlexTextField(4);
51 protected FlexTextField tfLowResDir = new FlexTextField(30);
52
53 protected ActionButton bHiResBrowse = new ActionButton(Resources.get(6548), ActionComponentI.ACTION_BROWSE_HIGHRES );
54 protected ActionButton bLoResBrowse = new ActionButton(Resources.get(6548), ActionComponentI.ACTION_BROWSE_LOWRES );
55 // protected ActionButton bDriveLocBrowse = new ActionButton(Resources.get(6548), ActionComponentI.ACTION_BROWSE_LOCAL );
56
57 // protected Checkbox cbLocal = new Checkbox(Resources.get(6552));
58
59 protected SettingsModelI sModel = null;
60
61 protected boolean bHasRights = false;
62
63 protected Checkbox cbExcludeLow = new Checkbox( Resources.get( 6575 ) );
64 protected Checkbox cbLowFilesInHigh = new Checkbox( Resources.get( 6576 ) );
65 protected Checkbox cbLowDirInHighDir = new Checkbox( Resources.get( 6580 ) );
66
67 /**
68 * The GridBagLayout : Layout used for laying the components on this panel.
69 *
70 * @since 3.0
71 */
72
73 protected GridBagLayout gbl = null;
74
75 /**
76 * The GridBagConstraints : Class encapsulate all the constraints to be applied
77 * on laying out a component.
78 *
79 * @since 3.0
80 */
81 protected GridBagConstraints gbc = null;
82 protected java.awt.Frame parentFrame = null;
83
84 public SourcePanel( java.awt.Frame pFrame, SettingsModelI amdl, boolean HasRights )
85 {
86 parentFrame = pFrame;
87 sModel = amdl;
88 bHasRights = HasRights;
89 // Create Components
90 setLayout(new java.awt.BorderLayout());
91
92 add( "North" , createNorthPanel() );
93 add( "Center" , createCentralPanel() );
94 }
95
96 private FlexBorderPanel createNorthPanel()
97 {
98 Label lhrBase = new Label( Resources.get( 6534 ) );
99
100 gbl = new GridBagLayout();
101
102 tfHiResLoc.setDisplayLength( 25 );
103
104 FlexBorderPanel panel = new FlexBorderPanel( Resources.get( 6589 ) );
105 try
106 {
107 panel.setPadding( 8, 1, 8, 4 );
108 panel.setBevelStyle(FlexBorderPanel.BEVEL_LINE);
109 panel.setAlignStyle(FlexBorderPanel.ALIGN_LEFT);
110 }
111 catch ( Exception e ){}
112
113 panel.setLayout ( gbl );
114
115 gbc = AWTUtil.getGbc( 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
116 gbc.insets = new Insets( 8, 8, 8, 4 );
117 gbl.setConstraints( lhrBase, gbc );
118 panel.add( lhrBase );
119
120 gbc = AWTUtil.getGbc( 1, 0, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE );
121 gbc.insets = new Insets( 8, 0, 8, 4 );
122 gbl.setConstraints( tfHiResLoc, gbc );
123 panel.add( tfHiResLoc );
124
125 gbc = AWTUtil.getGbc( 2, 0, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
126 gbc.insets = new Insets( 8, 0, 8, 4 );
127 gbl.setConstraints( bHiResBrowse, gbc );
128 panel.add( bHiResBrowse );
129 bHiResBrowse.addActionListener ( this );
130
131 tfHiResLoc.addTextListener ( this );
132 return panel;
133 }
134 private FlexBorderPanel createCentralPanel()
135 {
136
137 tfLoResLoc.setDisplayLength( 25 );
138
139 FlexBorderPanel panel = new FlexBorderPanel( Resources.get( 6577 ) );
140 try
141 {
142 panel.setPadding( 8, 1, 8, 4 );
143 panel.setBevelStyle( FlexBorderPanel.BEVEL_LINE );
144 panel.setAlignStyle( FlexBorderPanel.ALIGN_LEFT );
145 }
146 catch ( Exception e ){}
147
148 panel.setLayout( new BorderLayout() );
149
150 Panel panel1 = getLTPanel();
151 Panel panel2 = getCBPanel();
152
153 panel.add("North", panel2);
154 panel.add("Center", panel1);
155
156 //labels and textfields
157
158 return panel;
159 }
160 private Panel getCBPanel()
161 {
162 FlexBorderPanel cbPanel = new FlexBorderPanel("");
163 try
164 {
165 cbPanel.setPadding( 1, 1, 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
173 cbPanel.setLayout ( gbl );
174
175 gbc = AWTUtil.getGbc( 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
176 gbc.insets = new Insets( 8, 10, 8, 4 );
177 gbl.setConstraints( cbLowFilesInHigh, gbc );
178 cbPanel.add( cbLowFilesInHigh );
179
180 gbc = AWTUtil.getGbc( 0, 2, 0.5, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
181 gbc.insets = new Insets( 8, 10, 8, 4 );
182 gbl.setConstraints( cbLowDirInHighDir, gbc );
183 cbPanel.add( cbLowDirInHighDir );
184
185 gbc = AWTUtil.getGbc( 0, 3, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
186 gbc.insets = new Insets( 8, 10, 8, 4 );
187 gbl.setConstraints( cbExcludeLow, gbc );
188 cbPanel.add( cbExcludeLow );
189
190 cbLowFilesInHigh.addItemListener ( this );
191 cbLowDirInHighDir.addItemListener ( this );
192 cbExcludeLow.addItemListener ( this );
193 return cbPanel;
194
195 }
196 private FlexBorderPanel getLTPanel ()
197 {
198 Label llrBase = new Label( Resources.get( 6535 ) );
199 Label llrExt = new Label( Resources.get( 6570 ) );
200 Label llrDir = new Label( Resources.get( 6578 ) );
201
202 // tfLoResLoc.setPartialDisable ( true );
203
204 tfLowResExt.setCustomValidator( new FileNameValidator(". /") );
205 tfLowResDir.setDisplayLength( 25 );
206 tfLowResDir.setCustomValidator( new FileNameValidator(". /") );
207
208
209 FlexBorderPanel panel = new FlexBorderPanel("");
210 try
211 {
212 panel.setPadding( 1, 1, 4, 4 );
213 panel.setBevelStyle( FlexBorderPanel.BEVEL_LINE );
214 panel.setAlignStyle( FlexBorderPanel.ALIGN_LEFT );
215 }
216 catch ( Exception e ){}
217
218 gbl = new GridBagLayout();
219
220 panel.setLayout ( gbl );
221
222 gbc = AWTUtil.getGbc( 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
223 gbc.insets = new Insets( 4, 8, 4, 4 );
224 gbl.setConstraints( llrBase, gbc );
225 panel.add( llrBase );
226
227 gbc = AWTUtil.getGbc( 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
228 gbc.insets = new Insets( 4, 0, 4, 4 );
229 gbl.setConstraints( tfLoResLoc, gbc );
230 panel.add( tfLoResLoc );
231
232 gbc = AWTUtil.getGbc( 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
233 gbc.insets = new Insets( 4, 0, 4, 4 );
234 gbl.setConstraints( bLoResBrowse, gbc );
235 panel.add( bLoResBrowse );
236
237 gbc = AWTUtil.getGbc( 0, 2, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
238 gbc.insets = new Insets( 7, 8, 7, 4 );
239 gbl.setConstraints( llrExt, gbc );
240 panel.add( llrExt );
241
242 gbc = AWTUtil.getGbc( 1, 2, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
243 gbc.insets = new Insets( 7, 0, 7, 4 );
244 gbl.setConstraints( tfLowResExt, gbc );
245 panel.add( tfLowResExt );
246
247 gbc = AWTUtil.getGbc( 0,3, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
248 gbc.insets = new Insets( 7, 8, 7, 4 );
249 gbl.setConstraints( llrDir, gbc );
250 panel.add( llrDir );
251
252 gbc = AWTUtil.getGbc( 1,3, 0,0, GridBagConstraints.WEST, GridBagConstraints.NONE );
253 gbc.insets = new Insets( 7, 0, 7, 4 );
254 gbl.setConstraints( tfLowResDir, gbc );
255 panel.add( tfLowResDir );
256
257 bLoResBrowse.addActionListener ( this );
258
259 tfLowResExt.addTextListener ( this );
260 tfLoResLoc.addTextListener ( this );
261 tfLowResDir.addTextListener ( this );
262
263
264 return panel;
265 }
266 // public void addNotify()
267 // {
268 // super.addNotify();
269 // loadData();
270 // }
271 /*
272 private FlexBorderPanel createSouthPanel()
273 {
274
275 gbl = new GridBagLayout();
276
277 Label drive = new Label( Resources.get( 6553 ) );
278
279 tfDriveLoc.setDisplayLength( 25 );
280 tfDriveLoc.setPartialDisable( true );
281
282 FlexBorderPanel panel = new FlexBorderPanel( Resources.get( 6579 ) );
283 try
284 {
285 panel.setPadding(1, 1, 4, 4); // t b l r
286 panel.setBevelStyle(FlexBorderPanel.BEVEL_LINE);
287 panel.setAlignStyle(FlexBorderPanel.ALIGN_LEFT);
288 }
289 catch ( Exception e ){}
290
291 panel.setLayout( gbl );
292
293 gbc = AWTUtil.getGbc( 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
294 gbc.insets = new Insets( 4, 8, 4, 4 );
295 gbl.setConstraints( cbLocal, gbc );
296 panel.add( cbLocal );
297
298 gbc = AWTUtil.getGbc( 1, 0, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE );
299 gbc.insets = new Insets( 4, 0, 4, 4 );
300 gbl.setConstraints( tfDriveLoc, gbc );
301 panel.add( tfDriveLoc );
302
303 gbc = AWTUtil.getGbc( 2, 0, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE );
304 gbc.insets = new Insets( 4, 0, 4, 4 );
305 gbl.setConstraints( bDriveLocBrowse, gbc );
306 panel.add( bDriveLocBrowse );
307
308 // lets listen
309 bDriveLocBrowse.addActionListener( this );
310 tfLowResExt.addFocusListener ( this );
311 tfLowResDir.addFocusListener ( this );
312 cbExcludeLow.addItemListener ( this );
313 cbLowFilesInHigh.addItemListener ( this );
314 cbLowDirInHighDir.addItemListener( this );
315
316 cbLocal.addItemListener ( this );
317 tfDriveLoc.addTextListener ( this );
318
319 return panel;
320 }
321 */
322 public void loadData ()
323 {
324 if ( sModel == null )
325 return;
326
327 tfHiResLoc.setText ( sModel.getHighResBaseLoc() );
328 tfLoResLoc.setText ( sModel.getLowResBaseLoc() );
329
330 tfLowResExt.setText ( sModel.getLRExtension() );
331 tfLowResDir.setText ( sModel.getLRDirectory() );
332
333 cbExcludeLow.setState ( sModel.canPerform ( ImportSettingsI.EXCLUDE_LOW ) );
334 cbLowFilesInHigh.setState ( sModel.canPerform ( ImportSettingsI.LOW_IN_HIGH ) );
335 cbLowDirInHighDir.setState( sModel.canPerform ( ImportSettingsI.LOW_DIR_IN_HIGH_DIR ) );
336 }
337
338 public void update(Observable obs, Object obj)
339 {
340
341 if ( sModel == null )
342 return;
343
344 Notification cmd = (Notification)obj;
345
346 String command = ( String )cmd.getCommand();
347 if ( command.equals ( ImportSettingsI.SETTING_CHANGED ) )
348 {
349 loadData();
350 }
351 }
352
353 /**
354 * checkRights
355 * Sets up the components on the panel as either enabled or disabled
356 * depending on the Rights for the current user, some components are not
357 * affected by the rights, or are set again in another method.
358 * This method gets called when the panel is first initialized, and also
359 * after a location change (from update)
360 **/
361 /*
362 private void checkRights()
363 {
364 tfHiResLoc.setEnabled(bHasRights); //Hi Res Base Location TextField
365 bHiResBrowse.setEnabled(bHasRights);// Hi Res Browse Button
366 tfLoResLoc.setEnabled(bHasRights);// Low Res Location TextField
367 bLoResBrowse.setEnabled(bHasRights);// Low Res Browse Button
368 tfLowResExt.setEnabled(true);
369 cbLocal.setEnabled(true);
370 tfDriveLoc.setEnabled(true);
371 bDriveLocBrowse.setEnabled(true);
372 }
373 */
374 /**
375 * itemStateChanged - implements ItemListener
376 **/
377 public void itemStateChanged(ItemEvent e)
378 {
379 String itemText;
380 Checkbox cb;
381 Object obj = e.getSource();
382
383
384 if( obj instanceof Checkbox )
385 {
386 Checkbox chkBox = ( Checkbox ) obj;
387 if ( chkBox == cbLowFilesInHigh )
388 {
389 if ( sModel != null )
390 sModel.setBoxChecked ( ImportSettingsI.LOW_IN_HIGH, cbLowFilesInHigh.getState(), true );
391 tfLoResLoc.setEnabled ( !cbLowFilesInHigh.getState() );
392 bLoResBrowse.setEnabled ( !cbLowFilesInHigh.getState() );
393 }
394 else if ( chkBox == cbLowDirInHighDir )
395 {
396 if ( sModel != null )
397 sModel.setBoxChecked ( ImportSettingsI.LOW_DIR_IN_HIGH_DIR, cbLowDirInHighDir.getState(), true );
398 tfLoResLoc.setEnabled ( !cbLowDirInHighDir.getState() );
399 bLoResBrowse.setEnabled( !cbLowDirInHighDir.getState() );
400
401 }
402 else if ( chkBox == cbExcludeLow )
403 {
404 if ( sModel != null )
405 sModel.setBoxChecked( ImportSettingsI.EXCLUDE_LOW, cbExcludeLow.getState(), true );
406 }
407 } // checkbox
408
409 }// itemStateChanged
410
411
412 public void textValueChangeBegin ( FlexTextEvent e )
413 {
414 }
415
416 public void textValueChangeEnd ( FlexTextEvent e )
417 {
418 java.awt.Component component = ( java.awt.Component ) e.getSource();
419
420 if ( component == tfHiResLoc )
421 {
422 sModel.setHighResBaseLoc ( tfHiResLoc.getText(), true );
423 }
424 else if ( component == tfLoResLoc )
425 {
426 sModel.setLowResBaseLoc ( tfLoResLoc.getText(), true );
427 }
428 else if ( component == tfLowResExt )
429 {
430 sModel.setLRExtension ( tfLowResExt.getText(), true );
431 }
432 else if ( component == tfLowResDir )
433 {
434 sModel.setLRDirectory ( tfLowResDir.getText(), true );
435 }
436 }
437
438 public java.awt.Insets getInsets()
439 {
440 return new java.awt.Insets( 5,5,5,5 );
441 }
442 public void actionPerformed( ActionEvent event )
443 {
444 ActionButton button = ( ActionButton )event.getSource();
445 String sBrowser = null;
446 String title = Resources.get( 6548 );
447 /*
448 switch ( button.getActionId() )
449 {
450
451 case ActionComponentI.ACTION_BROWSE_HIGHRES :
452 if ( sModel != null )
453 sModel.enableInput ( false );
454
455 String location = showBrowseDialog( 6734 );
456
457 if ( sModel != null )
458 sModel.enableInput ( true );
459
460 if ( location != null )
461 {
462 tfHiResLoc.setText ( location );
463 sModel.setHighResBaseLoc ( location, true );
464 }
465 break;
466 case ActionComponentI.ACTION_BROWSE_LOWRES :
467
468 if ( sModel != null )
469 sModel.enableInput ( false );
470
471 location = showBrowseDialog( 6735 );
472
473 if ( sModel != null )
474 sModel.enableInput ( true );
475
476 if ( location != null )
477 {
478 tfLoResLoc.setText ( location );
479 sModel.setLowResBaseLoc ( location, true );
480 }
481 break;
482 }
483 */
484 }
485
486 /**
487 * showBrowseDialog
488 * Puts up a browse dialog where the user can pick a directory or a file
489 * @return A String which is the file or directory chosen in the browse dialog
490 **/
491 /*
492 public String showBrowseDialog( int resID )
493 {
494
495 try
496 {
497 String[] sers = null;
498 String strInitialPath = null;
499 // Currently for all the browse button shown on the panel need remote paths only.
500 int nFetchScope = BrowseController.ACCESS_REMOTE;
501
502 if ( resID == 6734 )
503 strInitialPath = Settings.getString ( Settings.DEFAULT_IMPORT_HIGH_RES_LOCATION );
504 else if ( resID == 6735 )
505 strInitialPath = Settings.getString ( Settings.DEFAULT_IMPORT_LOW_RES_LOCATION );
506
507 if ( ( sModel != null ) && ( sModel.getPersistManager() != null ) )
508 sers = sModel.getPersistManager().getServers();
509
510 BrowseResult result = ( new BrowseController( parentFrame,
511 Resources.get( resID ),
512 nFetchScope,
513 sers,
514 new BrowseFilter( BrowseFilter.DIRECTORY ),
515 strInitialPath,
516 true ) ).getResult();
517
518 if ( result != null )
519 {
520 String path = result.getPath();
521 if ( result.isSetAsDefault () )
522 {
523 // user has checked the box 'set as default' on the browse dialog.
524 if ( resID == 6734 )
525 Settings.addString ( Settings.DEFAULT_IMPORT_HIGH_RES_LOCATION, path );
526 else if ( resID == 6735 )
527 Settings.addString ( Settings.DEFAULT_IMPORT_LOW_RES_LOCATION, path );
528 }
529 return path;
530
531 }
532 }
533 catch ( BrowseAccessorException ex )
534 {
535 // Unable to browse location. %%1
536 MessageBox.showMessageDialog( parentFrame, 0, MessageBox.OK, ex.getMessage() );
537 }
538
539 return null;
540 }
541 */
542 public void configureComponents ()
543 {
544 }
545
546 }
547