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     * Represent a column selection for a dots file 
027     *
028     */
029    public class Column {
030    
031        /** column Num **/
032        private int _column = -1;
033    
034        /** column title to display in the legend **/
035        private String _title = "";
036        
037        /**
038         * Constructor
039         *
040         * @param column  column Num 
041         * @param title  column title to display in the legend
042         */  
043        Column (int column, String title)
044        {
045            column =  _column;
046            title = _title;
047        }
048    
049        /**
050         * Constructor
051         *
052         * @param column  column Num 
053         */     
054        Column (int column)
055        {
056            _column =  column;
057            _title = "";
058        }
059    
060        /**
061         * Default Constructor
062         *
063         */     
064        Column ()
065        {
066            _column =  -1;
067            _title = "";
068        }
069    
070        /**
071         * return the column num
072         *
073         */     
074        public int getColumn()
075        {
076            return _column;
077        }
078    
079        /**
080         * return the title
081         *
082         */         
083        public String getTitle()
084        {
085            return _title;
086        }   
087    
088        /**
089         * check is there is a title not equals to ""
090         *
091         */            
092        public boolean isTitleEmpty()
093        {
094            return _title.equals("");
095        }   
096    
097        /**
098         * check is the column num is valid
099         *
100         */                
101        public boolean isValid ()
102        {
103            return (_column > -1);
104        }
105        
106        /**
107         * Display the object
108         *
109         */                
110        public void display ()
111        {
112            System.out.println("Column : <" + _column + ">\tTitle : <" + _title + ">"); 
113        }
114    
115    
116        /**
117         * parse a string and return a Column object
118         *
119         * @param str the string to parse (use the form columnNum:title)
120         */                
121        public static Column parse (String str)
122        {
123            Column res = new Column();      
124            
125            String colList[] = str.split(":");                  
126            try
127                {
128                    res._column = Integer.valueOf(colList[0]).intValue();       
129                }
130            catch(Exception e)
131                {
132                    res._column = -1;
133                }
134    
135    
136            if(colList.length > 1)
137                {
138                    res._title = colList[1];
139                }
140    
141    
142            return res;
143        }
144    }