[Schmitzm-commits] r2322 - in trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv: . gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sat Jun 1 00:21:31 CEST 2013


Author: mojays
Date: 2013-06-01 00:21:31 +0200 (Sat, 01 Jun 2013)
New Revision: 2322

Added:
   trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/CsvSettings.java
Modified:
   trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationDialog.java
   trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationPanel.java
   trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewDialog.java
   trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewPanel.java
Log:
CSVColumnAllocationPanel/Dialog: method to disable an allocation field
CSVPreviewPanel/Dialog: method to configure GUI by new CsvSettings object

Added: trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/CsvSettings.java
===================================================================
--- trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/CsvSettings.java	                        (rev 0)
+++ trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/CsvSettings.java	2013-05-31 22:21:31 UTC (rev 2322)
@@ -0,0 +1,121 @@
+package de.schmitzm.csv;
+
+import java.nio.charset.Charset;
+import java.util.Map;
+
+/**
+ * This class provides parameters (in one object) which are needed for
+ * import and interprete a CSV file. 
+ * @author Martin O.J. Schmitz
+ *
+ */
+public class CsvSettings {
+  /** Default delimiter used for CSV-Import. */
+  public static final char DEFAULT_CSV_DELIM = ';';
+  /** Default quote character which mask strings. */
+  public static final char DEFAULT_CSV_QUOTE_CHAR = '"';
+  /** Default character used as decimal sign. */
+  public static final char DEFAULT_CSV_DECIMAL_CHAR = ',';
+  /** Default character used as "No data" value. */
+  public static final String DEFAULT_CSV_NODATA_VALUE = "";
+
+  
+  protected char delim = DEFAULT_CSV_DELIM;
+  protected char quote = DEFAULT_CSV_QUOTE_CHAR;
+  protected char decimal = DEFAULT_CSV_DECIMAL_CHAR;
+  protected String nodata = DEFAULT_CSV_NODATA_VALUE;
+  protected Charset charset = Charset.defaultCharset();
+  protected Map<String,String> mappingFieldToCsv = null;
+  
+  
+  /**
+   * Returns the column delimiter.
+   */
+  public char getDelimiter() {
+    return delim;
+  }
+
+  /**
+   * Sets the column delimiter.
+   */
+  public void setDelimiter(char delim) {
+    this.delim = delim;
+  }
+  
+  /**
+   * Returns the character used to mask.
+   */
+  public char getQuoteChar() {
+    return quote;
+  }
+  
+  /**
+   * Sets the character used to mask.
+   */
+  public void setQuoteChar(char quote) {
+    this.quote = quote;
+  }
+  
+  /**
+   * Returns the decimal sign (used for string conversion).
+   */
+  public char getDecimal() {
+    return decimal;
+  }
+
+  /**
+   * Sets the decimal sign (used for string conversion).
+   */
+  public void setDecimal(char decimal) {
+    this.decimal = decimal;
+  }
+  
+  /**
+   * Returns the value interpreted as "no data".
+   */
+  public String getNodata() {
+    return nodata;
+  }
+
+  /**
+   * Sets the value interpreted as "no data".
+   */
+  public void setNodata(String nodata) {
+    this.nodata = nodata;
+  }
+  
+  /**
+   * Returns the {@link Charset} used for import from file.
+   * @return {@link Charset#defaultCharset()} is no {@link Charset} is set
+   */
+  public Charset getCharset() {
+    if ( charset == null )
+      return Charset.defaultCharset();
+    return charset;
+  }
+  /**
+   * Sets the {@link Charset} used for import from file.
+   * If set to {@code null}, {@link #getCharset()} will return {@link Charset#defaultCharset()}.
+   */
+  public void setCharset(Charset charset) {
+    this.charset = charset;
+  }
+  
+  /**
+   * Returns a mapping from a destination field to a CSV column name,
+   * which should be imported to the field.
+   */
+  public Map<String, String> getMappingFieldToCsv() {
+    return mappingFieldToCsv;
+  }
+
+  /**
+   * Sets a mapping from a destination field to a CSV column name,
+   * which should be imported to the field.
+   */
+  public void setMappingFieldToCsv(Map<String, String> mappingFieldToCsv) {
+    this.mappingFieldToCsv = mappingFieldToCsv;
+  }
+  
+  
+}

Modified: trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationDialog.java
===================================================================
--- trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationDialog.java	2013-05-31 22:18:53 UTC (rev 2321)
+++ trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationDialog.java	2013-05-31 22:21:31 UTC (rev 2322)
@@ -180,4 +180,11 @@
   public Map<String,String> getMappingCsvToUnitAbbr() {
     return allocationPanel.getMappingCsvToUnitAbbr();
   }
-}
+
+  /**
+   * Enables or disables an allocation combo box.
+   */
+  public void setAllocationEnabled(String fieldID, boolean enabled) {
+    allocationPanel.setAllocationEnabled(fieldID, enabled);
+  }
+}
\ No newline at end of file

Modified: trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationPanel.java
===================================================================
--- trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationPanel.java	2013-05-31 22:18:53 UTC (rev 2321)
+++ trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVColumnAllocationPanel.java	2013-05-31 22:21:31 UTC (rev 2322)
@@ -308,4 +308,22 @@
     }
     return allocationAbbr;
   }
+  
+  /**
+   * Enables or disables an allocation combo box.
+   */
+  public void setAllocationEnabled(String fieldID, boolean enabled) {
+    SelectionInputOption.Combo<String> allocComboBox = allocationColumns.get(fieldID);
+    SelectionInputOption.Combo<Unit<?>> allocUnitComboBox = allocationUnits.get(fieldID);
+    if ( allocComboBox != null ) {
+      allocComboBox.setEnabled(enabled);
+      if ( !enabled )
+        allocComboBox.setSelectedItem(null);
+    }
+    if ( allocUnitComboBox != null ){
+      allocUnitComboBox.setEnabled(enabled);
+      if ( !enabled )
+        allocUnitComboBox.setSelectedItem(null);
+    }
+  }
 }

Modified: trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewDialog.java
===================================================================
--- trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewDialog.java	2013-05-31 22:18:53 UTC (rev 2321)
+++ trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewDialog.java	2013-05-31 22:21:31 UTC (rev 2322)
@@ -36,6 +36,7 @@
 import java.io.InputStream;
 import java.nio.charset.Charset;
 
+import de.schmitzm.csv.CsvSettings;
 import de.schmitzm.swing.OkCancelDialog;
 import de.schmitzm.swing.SwingUtil;
 
@@ -195,4 +196,21 @@
     previewPanel.setCsvParameters(delimiter, decimalSign, quoteSign, charset, noData);
   }
 
+  /**
+   * Sets the CSV parameter used to generate the preview. If a method
+   * parameter is {@code null}, the respective parameter remains unchanged.
+   * The preview is automatically updated after changing the parameters. 
+   */
+  public void setCsvParameters(CsvSettings settings) {
+    previewPanel.setCsvParameters(settings);
+  }
+  
+  /**
+   * Puts the settings specified in the panel to {@link CsvSettings} object.
+   * @param settings settings object to put the settings in (if {@code null}
+   *                 a new object is created)
+   */
+  public CsvSettings copyToSettings(CsvSettings settings) {
+    return previewPanel.copyToSettings(settings);
+  }
 }

Modified: trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewPanel.java
===================================================================
--- trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewPanel.java	2013-05-31 22:18:53 UTC (rev 2321)
+++ trunk/schmitzm-excelcsv/src/main/java/de/schmitzm/csv/gui/CSVPreviewPanel.java	2013-05-31 22:21:31 UTC (rev 2322)
@@ -50,6 +50,7 @@
 import javax.swing.event.DocumentListener;
 
 import net.miginfocom.swing.MigLayout;
+import de.schmitzm.csv.CsvSettings;
 import de.schmitzm.csv.CsvUtil;
 import de.schmitzm.csv.gui.CSVPreviewPanel.ParameterChangeListener;
 import de.schmitzm.swing.JPanel;
@@ -302,6 +303,38 @@
   }
 
   /**
+   * Sets the CSV parameter used to generate the preview. If a method
+   * parameter is {@code null}, the respective parameter remains unchanged.
+   * The preview is automatically updated after changing the parameters. 
+   */
+  public void setCsvParameters(CsvSettings settings) {
+    if ( settings == null )
+      return;
+    setCsvParameters( settings.getDelimiter(),
+                      settings.getDecimal(),
+                      settings.getQuoteChar(),
+                      settings.getCharset(),
+                      settings.getNodata() );
+  }
+  
+  /**
+   * Puts the settings specified in the panel to {@link CsvSettings} object.
+   * @param settings settings object to put the settings in (if {@code null}
+   *                 a new object is created)
+   */
+  public CsvSettings copyToSettings(CsvSettings settings) {
+    if ( settings == null )
+      settings = new CsvSettings();
+    settings.setDelimiter(getCsvDelimiter());
+    settings.setDecimal(getCsvDecimalSign());
+    settings.setQuoteChar(getCsvQuoteSign());
+    settings.setCharset(getCsvCharset());
+    settings.setNodata(getNoDataValue());
+    
+    return settings;
+  }
+
+  /**
    * Listener whichs reacts on changes of CSV parameter GUI components with
    * update of preview table. 
    * @author Martin O.J. Schmitz



More information about the Schmitzm-commits mailing list