[Schmitzm-commits] r108 - in trunk: dist src/schmitzm/geotools/styling src/schmitzm/jfree

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue May 12 14:24:27 CEST 2009


Author: mojays
Date: 2009-05-12 14:24:24 +0200 (Tue, 12 May 2009)
New Revision: 108

Modified:
   trunk/dist/schmitzm-src.zip
   trunk/dist/schmitzm.jar
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/schmitzm/jfree/JFreeChartUtil.java
Log:
StylingUtil
- new method to create a BrewerPalette

Modified: trunk/dist/schmitzm-src.zip
===================================================================
(Binary files differ)

Modified: trunk/dist/schmitzm.jar
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-05-11 13:14:20 UTC (rev 107)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-05-12 12:24:24 UTC (rev 108)
@@ -34,6 +34,9 @@
 import javax.xml.transform.TransformerException;
 
 import org.apache.log4j.Logger;
+import org.geotools.brewer.color.BrewerPalette;
+import org.geotools.brewer.color.PaletteSuitability;
+import org.geotools.brewer.color.SampleScheme;
 import org.geotools.coverage.Category;
 import org.geotools.coverage.GridSampleDimension;
 import org.geotools.coverage.grid.GridCoverage2D;
@@ -1274,4 +1277,33 @@
 		}
 		return null;
 	}
+	
+	/**
+	 * Creates a new {@link BrewerPalette} with only one scheme (which includes
+	 * all colors). The suitablity of the palette is set to "unknown" for all
+	 * viewer types.
+	 * @param name   name for the palette (also the description is set to this value)
+	 * @param colors colors for the palette
+	 */
+	public static BrewerPalette createBrewerPalette(String name, Color[] colors) throws IOException {
+	  BrewerPalette palette = new BrewerPalette();
+      palette.setColors(colors);
+      palette.setName(name);
+      palette.setDescription(name);
+
+      // set suitability to UNKNOWN for all viewers
+      PaletteSuitability suitability = new PaletteSuitability();
+      suitability.setSuitability(colors.length, new String[] {"?","?","?","?","?","?"} );
+      palette.setPaletteSuitability(suitability);
+
+      // set the only scheme for the palette (include all colors)
+      int[] schema = new int[colors.length];
+      for (int j=0; j<schema.length; j++)
+        schema[j] = j;
+      SampleScheme sampleScheme = new SampleScheme();
+      sampleScheme.setSampleScheme(schema.length, schema);
+      palette.setColorScheme(sampleScheme);
+      
+      return palette;
+	}
 }

Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-05-11 13:14:20 UTC (rev 107)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-05-12 12:24:24 UTC (rev 108)
@@ -10,11 +10,26 @@
  **/
 package schmitzm.jfree;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 import java.util.Locale;
 import java.util.Vector;
 
+import org.apache.poi.hssf.extractor.ExcelExtractor;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.io.CSV;
 
 import schmitzm.lang.ResourceProvider;
 import schmitzm.lang.LangUtil;
@@ -31,4 +46,78 @@
    *  hinterlegt. */
   public static ResourceProvider RESOURCE = new ResourceProvider( LangUtil.extendPackagePath(JFreeChartUtil.class,"resource.locales.JFreeResourceBundle"), Locale.ENGLISH );
 
+//###################
+//  BISHER NUR WILDE TESTS
+//###################
+//  /**
+//   * Converts a Excel file to CVS format.
+//   * @param xlsInput  stream to Excel source
+//   * @param sheetName name of the sheet in the Excel source (if {@code null} the
+//   *                  first sheet is used)
+//   * @param headRow   indicates whether the first row contains the column names
+//   * @param csvHeader indicates whether the column names are also taken to the CVS (note:
+//   *                  if {@code true} and {@code headRow = false} dummy column
+//   *                  names "A", "B", ... are generates in CVS!)
+//   * @param delimChr  character takes as delimiter in CSV  
+//   * @param strEncChr character String values are encapsulated with (if {@code null}, Strings
+//   *                  are not encapsulated)                  
+//   */
+//  public static InputStream createCSVFromXLS(InputStream xlsInput, String sheetName, boolean headRow, boolean csvHeader, String delimChr, String strEncChar) throws IOException {
+//    PipedOutputStream csvOutput = new PipedOutputStream();
+//   
+//    // read XLS and create a CSV
+//    HSSFWorkbook wb    = new HSSFWorkbook( new POIFSFileSystem(xlsInput) );
+//    HSSFSheet    sheet = ( sheetName != null ) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
+//    
+//    int firstRow = sheet.getFirstRowNum();
+//    int lastRow  = sheet.getLastRowNum();
+////    int rowCount = sheet.getPhysicalNumberOfRows();
+//    for (int y=firstRow; y <= lastRow; y++) {
+//      HSSFRow row = sheet.getRow(y);
+//      int firstCol = row.getFirstCellNum();
+//      int lastCol  = row.getLastCellNum();
+//      for (int x=firstCol; x <= lastCol; x++) {
+//        HSSFCell cell = row.getCell(x);
+////        String csvValue = convertCellValueToString(cell,???);
+//      }
+//    }
+//   
+//    return new PipedInputStream(csvOutput);
+//  }
+//  
+//  public static String convertCellValueToString(HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator) {
+//    String strValue = "";
+//    switch( cell.getCellType() ) {
+//      case HSSFCell.CELL_TYPE_BOOLEAN: strValue = ""+cell.getBooleanCellValue();
+//                                       break;
+//      case HSSFCell.CELL_TYPE_NUMERIC: strValue = ""+cell.getNumericCellValue();
+//                                       break;
+//      case HSSFCell.CELL_TYPE_FORMULA: strValue = ""+cell.getNumericCellValue();
+//    }
+//    return strValue;
+//    
+//  }
+//
+//  /**
+//   * Creates a Dataset from Excel file.
+//   * @param xlsInput  stream to Excel source
+//   * @param sheetName name of the sheet in the Excel source (if {@code null} the
+//   *                  first sheet is used)
+//   */
+//  public static CategoryDataset createDatasetFromXLS(InputStream xlsInput, String sheetName) throws IOException {
+//    PipedOutputStream csvOutput = new PipedOutputStream();
+//    InputStreamReader csvInput  = new InputStreamReader( new PipedInputStream(csvOutput) ); 
+//    
+//
+////    return new CSV(';','"').readCategoryDataset(csvInput);
+//
+//    HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(xlsInput));
+//    ExcelExtractor extractor = new ExcelExtractor(wb);
+//    
+//    extractor.setFormulasNotResults(false);
+//    extractor.setIncludeSheetNames(false);
+//    String text = extractor.getText();
+//    System.out.println(text);
+//    return null;
+//  }
 }



More information about the Schmitzm-commits mailing list