AMAPstudio

User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
file_preview_and_checking_in_file_chooser [2017/12/08 16:07]
coligny
file_preview_and_checking_in_file_chooser [2018/03/12 15:42] (current)
coligny
Line 1: Line 1:
-====== ​File preview and checking ​in file choosers ======+====== ​Checking the files in file choosers ​/ File previews ​======
  
-fc-5.12.2017+fc-8.12.2017
  
-===== FileAccessory ===== 
- 
-It is possible to add a preview in a Java **JFileChooser** to throw an eye at the files during the selection. 
- 
-<code java> 
-chooser = new JFileChooser(Settings.getProperty("​heterofor.species.path",​ PathManager.getInstallDir()));​ 
-new FileAccessory(chooser);​  
- 
-</​code>​ 
- 
-{{::​capsis-file-accessory-1.png?​300|The preview (here on the right side) tries to shows the file content}} 
  
  
- +===== Checking file format ​on the fly in a CheckingFileChooser:​ 2 methods =====
- +
-===== Checking file format ​in the CheckingFileChooser:​ 2 methods =====+
  
 It is possible to use the **CheckingFileChooser** instead of the JFileChooser to check during selection which files will be loaded without error. The process relies on a method to be redefined called **check (File f)**. When the file given to this method is correct, the method must return true.  It is possible to use the **CheckingFileChooser** instead of the JFileChooser to check during selection which files will be loaded without error. The process relies on a method to be redefined called **check (File f)**. When the file given to this method is correct, the method must return true. 
Line 28: Line 15:
 **Warning**:​ some Java look and feels do not show the icon for each file during selection (e.g. GTK+ under Linux). In this case, the mark can still be seen in the FileAccessory preview. **Warning**:​ some Java look and feels do not show the icon for each file during selection (e.g. GTK+ under Linux). In this case, the mark can still be seen in the FileAccessory preview.
  
-{{::​capsis-file-accessory-windows.png?​300|The green and red marks in Windows'​ Look & Feel}}+{{::​capsis-file-accessory-windows.png?​300|The green and red marks in Windows'​ Look & Feel}}{{::​capsis-file-accessory-gtk-with-green-check.png?​300|Under GTK+ L&F, the mark can be seen in the file preview}}
  
  
  
-==== Simple checking, format only, with a standard RecordSet / FileLoader ​ ====+==== 1. Simple checking, format only, with a standard RecordSet / FileLoader ​ ====
  
 If the file is to be read with a file loader (i.e. jeeb.lib.util RecordSet or FileLoader),​ it is possible to **pass the file loader class** to a CheckingFileChooser. All the listed files will be evaluated with the file loader to evaluate their compatibility. If the file is to be read with a file loader (i.e. jeeb.lib.util RecordSet or FileLoader),​ it is possible to **pass the file loader class** to a CheckingFileChooser. All the listed files will be evaluated with the file loader to evaluate their compatibility.
Line 58: Line 45:
 </​code>​ </​code>​
  
 +{{::​heterofor-samsara-file-preview.png?​300|}}
  
- +==== 2. Advanced checking, with a more complex loading method ​ ====
-==== Advanced checking, with a more complex loading method ​ ====+
  
 When the loading method is complex, it is possible to override the check () method of CheckingFileChooser to propose a complete code to check the file. When the loading method is complex, it is possible to override the check () method of CheckingFileChooser to propose a complete code to check the file.
Line 66: Line 53:
 <code java> <code java>
 // fc-4.12.2017 A file chooser showing which files can be loaded // fc-4.12.2017 A file chooser showing which files can be loaded
-JFileChooser chooser = new CheckingFileChooser(Settings.getProperty("​capsis.inventory.path",​+JFileChooser chooser = new CheckingFileChooser(Settings.getProperty("​samsara2.inventory.path",​
  PathManager.getDir("​data"​))) {  PathManager.getDir("​data"​))) {
  
- public ​boolean ​check(File f) {+ public ​void check(File f) throws Exception ​{
  String fileName = f.getAbsolutePath();​  String fileName = f.getAbsolutePath();​
- try { 
- // Use fake objects to avoid side effects 
- Samsa2Model modelFake = new Samsa2Model();​ 
- Samsa2InitialParameters ipFake = modelFake.getSettings();​ 
  
- // Check if the file can be loaded + // Throws an exception ​if file can not be loaded
- ipFake.vParamMS.virtualStand = false; +
- ipFake.fileName = fileName; +
- ipFake.buildInitScene(modelFake);​+
  
- // Seems ok + // Use fake objects to avoid side effects 
- return true;+ Samsa2Model modelFake = new Samsa2Model();​ 
 + Samsa2InitialParameters ipFake = modelFake.getSettings();
  
- } catch (Throwable e) { + // Check if the file can be loaded 
- // Seems problematic + ipFake.vParamMS.virtualStand = false
- return ​false;+ ipFake.fileName = fileName; 
 + ipFake.buildInitScene(modelFake);
  
- } 
  }  }
 }; };
Line 94: Line 75:
 </​code>​ </​code>​
  
-{{::​capsis-file-accessory-windows.png?​300|The green and red marks in Windows'​ Look & Feel}}{{::​capsis-file-accessory-metal-with-green-and-red-marks.png?​300|A green mark shows which file will be loaded correctly}}{{::​capsis-file-accessory-gtk-with-green-check.png?​300|Under GTK+ L&F, the mark can be seen in the file preview}}+{{::​capsis-file-accessory-windows.png?​300|The green and red marks in Windows'​ Look & Feel}}{{::​capsis-file-accessory-metal-with-green-and-red-marks.png?​300|A green mark shows which file will be loaded correctly}}
  
  
Line 107: Line 88:
  
 {{::​file-accessory-luberon2.png?​300|The files with a green mark are supposed to be loaded correctly if selected}} {{::​file-accessory-luberon2.png?​300|The files with a green mark are supposed to be loaded correctly if selected}}
 +
 +
 +
 +===== FileAccessory without file checking =====
 +
 +It is also possible to add a preview to a standard Java **JFileChooser** to throw an eye at the files during the selection.
 +
 +<code java>
 +chooser = new JFileChooser(Settings.getProperty("​heterofor.species.path",​ PathManager.getInstallDir()));​
 +new FileAccessory(chooser);​
 +
 +</​code>​
 +
 +{{::​capsis-file-accessory-1.png?​300|The preview (here on the right side) tries to shows the file content}}
 +
 +
 +
 +
file_preview_and_checking_in_file_chooser.1512749266.txt · Last modified: 2017/12/08 16:07 by coligny