001 /**########################################################################### 002 ## ## 003 ## JQuickPlot - Java Quick XY Plots ## 004 ## ## 005 ## Copyright (C) 2008 Frederic Roudaut <frederic.roudaut@free.fr> ## 006 ## ## 007 ## ## 008 ## This program is free software; you can redistribute it and/or modify it ## 009 ## under the terms of the GNU General Public License version 2 as ## 010 ## published by the Free Software Foundation; version 2. ## 011 ## ## 012 ## This program is distributed in the hope that it will be useful, but ## 013 ## WITHOUT ANY WARRANTY; without even the implied warranty of ## 014 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## 015 ## General Public License for more details. ## 016 ## ## 017 ############################################################################**/ 018 019 package JQuickPlot; 020 021 import java.lang.String; 022 import java.util.ArrayList; 023 import java.util.List; 024 025 026 /** 027 028 * Represent a column List selection for a dots file 029 * 030 */ 031 public class ColumnList { 032 033 /** A List of Columns **/ 034 private List _columnList; 035 036 /** 037 * Default Constructor 038 * 039 */ 040 public ColumnList() 041 { 042 _columnList = new ArrayList(); 043 } 044 045 /** 046 * Add a Column 047 * 048 * @param column column Num 049 * @param title column title to display in the legend 050 */ 051 public boolean addColumn(int column, String title) 052 { 053 return _columnList.add(new Column(column, title)); 054 } 055 056 /** 057 * Add a Column 058 * 059 * @param column column Num 060 */ 061 public boolean addColumn(int column) 062 { 063 return _columnList.add(new Column(column)); 064 } 065 066 /** 067 * Add a Column 068 * 069 * @param column Column object to add 070 */ 071 public boolean add(Column column) 072 { 073 return _columnList.add(column); 074 } 075 076 /** 077 * get a column object from its position 078 * 079 * @param pos position in the Columns List 080 */ 081 public Column get(int pos) 082 { 083 return (Column) _columnList.get(pos); 084 } 085 086 /** 087 * get the size of the Columns List 088 * 089 */ 090 public int size() 091 { 092 return _columnList.size(); 093 } 094 095 /** 096 * check if the the Columns List is empty 097 * 098 */ 099 public boolean isEmpty() 100 { 101 return _columnList.isEmpty(); 102 } 103 104 /** 105 * parse a string and return a Column List object 106 * 107 * @param str the string to parse (use the form columnNum:title;columnNum:title ... ) 108 */ 109 public static ColumnList parse (String str) 110 { 111 String colList[] = str.split(";"); 112 113 ColumnList res = new ColumnList(); 114 for (int i=0; i < colList.length; i++) 115 { 116 Column col = Column.parse(colList[i]); 117 if(col.isValid()) 118 res.add(col); 119 } 120 121 return res; 122 } 123 124 /** 125 * Display the object 126 * 127 */ 128 public void display () 129 { 130 131 for (int i=0; i < size(); i++) 132 { 133 get(i).display(); 134 } 135 136 } 137 138 /** 139 * Main for test purpose 140 * 141 */ 142 public static void main(String args[]) 143 { 144 145 System.out.println("\ncl1"); 146 ColumnList cl1 = ColumnList.parse("1:column1;2:column2"); 147 cl1.display(); 148 149 System.out.println("\ncl2"); 150 ColumnList cl2 = ColumnList.parse("1:column1;"); 151 cl2.display(); 152 153 System.out.println("\ncl3"); 154 ColumnList cl3 = ColumnList.parse("1:;"); 155 cl3.display(); 156 157 System.out.println("\ncl4"); 158 ColumnList cl4 = ColumnList.parse("1;"); 159 cl4.display(); 160 161 System.out.println("\ncl5"); 162 ColumnList cl5 = ColumnList.parse("1:"); 163 cl5.display(); 164 165 System.out.println("\ncl6"); 166 ColumnList cl6 = ColumnList.parse("1:"); 167 cl6.display(); 168 169 System.out.println("\ncl7"); 170 ColumnList cl7 = ColumnList.parse(":"); 171 cl7.display(); 172 173 System.out.println("\ncl8"); 174 ColumnList cl8 = ColumnList.parse(";"); 175 cl8.display(); 176 177 System.out.println("\ncl9"); 178 ColumnList cl9 = ColumnList.parse(""); 179 cl9.display(); 180 181 System.out.println("\ncl10"); 182 ColumnList cl10 = ColumnList.parse(";:"); 183 cl10.display(); 184 185 System.out.println("\ncl11"); 186 ColumnList cl11 = ColumnList.parse(":rrrr"); 187 cl11.display(); 188 189 } 190 191 192 } 193 194