Coverage Report - org.xmlhammer.gui.history.HistoryUtilities
 
Classes in this File Line Coverage Branch Coverage Complexity
HistoryUtilities
89% 
91% 
0
 
 1  
 /*
 2  
  * $Id: HistoryUtilities.java,v 1.12 2007/09/26 12:29:29 edankert Exp $
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License 
 5  
  * Version 1.1 (the "License"); you may not use this file except in 
 6  
  * compliance with the License. You may obtain a copy of the License at 
 7  
  * http://www.mozilla.org/MPL/ 
 8  
  *
 9  
  * Software distributed under the License is distributed on an "AS IS" basis, 
 10  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 11  
  * for the specific language governing rights and limitations under the License.
 12  
  *
 13  
  * The Original Code is XML Hammer code. (org.xmlhammer.*)
 14  
  *
 15  
  * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
 16  
  * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
 17  
  * All Rights Reserved.
 18  
  *
 19  
  * Contributor(s): Edwin Dankert <edankert@gmail.com>
 20  
  */
 21  
 package org.xmlhammer.gui.history;
 22  
 
 23  
 import java.net.URI;
 24  
 import java.util.List;
 25  
 
 26  
 import org.bounce.util.URIUtils;
 27  
 import org.xmlhammer.PreferencesHandler;
 28  
 import org.xmlhammer.model.preferences.HistoryList;
 29  
 
 30  
 public class HistoryUtilities {
 31  22
     private static HistoryUtilities utils = null;
 32  22
     private HistoryListModel searches = null;
 33  22
     private HistoryListModel sources = null;
 34  22
     private HistoryListModel results = null;
 35  22
     private HistoryListModel schemas = null;
 36  22
     private HistoryListModel patterns = null;
 37  22
     private HistoryListModel expressions = null;
 38  22
     private HistoryListModel directories = null;
 39  22
     private HistoryListModel extensions = null;
 40  22
     private HistoryListModel stylesheets = null;
 41  22
     private HistoryListModel doctypeSystems = null;
 42  22
     private HistoryListModel doctypePublics = null;
 43  22
     private HistoryListModel cdataSectionElements = null;
 44  22
     private HistoryListModel medias = null;
 45  22
     private HistoryListModel titles = null;
 46  22
     private HistoryListModel charsets = null;
 47  
 //    private DefaultListModel LookIn = null;
 48  
     
 49  22
     private HistoryUtilities() {
 50  22
     }
 51  
     
 52  
     public static HistoryUtilities getInstance() {
 53  8096
         if ( utils == null) {
 54  22
             utils = new HistoryUtilities();
 55  
         }
 56  
         
 57  8096
         return utils;
 58  
     }
 59  
     
 60  
     // Add a recently opened project.
 61  
     public void addOpenedProject(URI uri) {
 62  572
         if ( uri != null) {
 63  462
             add(PreferencesHandler.getInstance().getPreferences().getHistory().getProjects(), URIUtils.toString(uri));
 64  
         }
 65  572
     }
 66  
 
 67  
     private void add(HistoryList hist, String value) {
 68  462
         if (value != null && value.length() > 0) {
 69  462
             List<String> list = hist.getValue();
 70  
             
 71  462
             for (String item : list) {
 72  1276
                 if (item.equals(value)) {
 73  0
                     list.remove(item);
 74  0
                     break;
 75  
                 }
 76  1276
             }
 77  
             
 78  462
             list.add(0, value);
 79  
 
 80  420
             if (hist.getSize() < list.size()) {
 81  
                 // remove the last item!
 82  0
                 list.remove(list.size()-1);
 83  42
             }
 84  
         }
 85  462
     }
 86  
 
 87  
 //    private void add( DefaultListModel model, HistoryList hist, String value) {
 88  
 //        if ( value != null && value.length() > 0) {
 89  
 //            List<String> list = hist.getValue();
 90  
 //            
 91  
 //            for ( String item : list) {
 92  
 //                if ( item.equals( value)) {
 93  
 //                    list.remove( item);
 94  
 //                    model.removeElement( value);
 95  
 //                    break;
 96  
 //                }
 97  
 //            }
 98  
 //            
 99  
 //            if ( hist.getSize() < list.size()) {
 100  
 //                // remove the last item!
 101  
 //                String last = list.get( list.size()-1);
 102  
 //    
 103  
 //                model.removeElement(last);
 104  
 //                list.remove(last);
 105  
 //            }
 106  
 //            
 107  
 //            list.add( 0, value);
 108  
 //            model.add( 0, value);
 109  
 //        }
 110  
 //    }
 111  
 
 112  
 //    // Add a recently opened URI.
 113  
 //    public void addInput( URI uri) {
 114  
 //        if ( uri != null) {
 115  
 //            add( (DefaultListModel)getInputsModel(), preferences.getHistory().getInputs(), uri.toString());
 116  
 //        }
 117  
 //    }
 118  
 //
 119  
 //    // Add a recently opened URI.
 120  
 //    public void addSchema( URI uri) {
 121  
 //        if ( uri != null) {
 122  
 //            add( (DefaultListModel)getSchemasModel(), preferences.getHistory().getSchemas(), uri.toString());
 123  
 //        }
 124  
 //    }
 125  
 //
 126  
 //    public void addDirectory( String uri) {
 127  
 //        add( (DefaultListModel)getDirectories(), preferences.getHistory().getDirectories(), uri);
 128  
 //    }
 129  
 //
 130  
 //    // Add a pattern.
 131  
 //    public void addPattern( String pattern) {
 132  
 //        add( (DefaultListModel)getPatterns(), preferences.getHistory().getPatterns(), pattern);
 133  
 //    }
 134  
 //
 135  
 //    // Add a expression.
 136  
 //    public void addExpression( String expression) {
 137  
 //        add( (DefaultListModel)getExpressions(), preferences.getHistory().getExpressions(), expression);
 138  
 //    }
 139  
         
 140  
     public HistoryListModel getSearches() {
 141  0
         if (searches == null) {
 142  0
             searches = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getSearches());
 143  
         }
 144  
 
 145  0
         return searches;
 146  
     }
 147  
 
 148  
     public HistoryListModel getSourcesModel() {
 149  792
         if ( sources == null) {
 150  22
             sources = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getSources());
 151  
         }
 152  
 
 153  792
         return sources;
 154  
     }
 155  
 
 156  
     public HistoryListModel getResultsModel() {
 157  0
         if (results == null) {
 158  0
             results = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getResults());
 159  
         }
 160  
 
 161  0
         return results;
 162  
     }
 163  
 
 164  
     public HistoryListModel getSchemasModel() {
 165  594
         if ( schemas == null) {
 166  22
             schemas = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getSchemas());
 167  
         }
 168  
 
 169  594
         return schemas;
 170  
     }
 171  
 
 172  
     public HistoryListModel getExpressions() {
 173  154
         if ( expressions == null) {
 174  22
             expressions = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getExpressions());
 175  
         }
 176  
 
 177  154
         return expressions;
 178  
     }
 179  
 
 180  
     public HistoryListModel getPatterns() {
 181  792
         if ( patterns == null) {
 182  22
             patterns = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getPatterns());
 183  
         }
 184  
         
 185  792
         return patterns;
 186  
     }
 187  
 
 188  
     public HistoryListModel getDirectories() {
 189  1078
         if ( directories == null) {
 190  22
             directories = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getDirectories());
 191  
         }
 192  
 
 193  1078
         return directories;
 194  
     }
 195  
     
 196  
     public HistoryListModel getExtensions() {
 197  286
         if ( extensions == null) {
 198  22
             extensions = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getExtensions());
 199  
         }
 200  
 
 201  286
         return extensions;
 202  
     }
 203  
 
 204  
     public HistoryListModel getStylesheets() {
 205  528
         if (stylesheets == null) {
 206  22
             stylesheets = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getStylesheets());
 207  
         }
 208  
 
 209  528
         return stylesheets;
 210  
     }
 211  
 
 212  
     public HistoryListModel getDoctypeSystems() {
 213  814
         if (doctypeSystems == null) {
 214  22
             doctypeSystems = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getDoctypeSystems());
 215  
         }
 216  
 
 217  814
         return doctypeSystems;
 218  
     }
 219  
 
 220  
     public HistoryListModel getDoctypePublics() {
 221  1100
         if (doctypePublics == null) {
 222  22
             doctypePublics = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getDoctypePublics());
 223  
         }
 224  
 
 225  1100
         return doctypePublics;
 226  
     }
 227  
 
 228  
     public HistoryListModel getCDataSectionElements() {
 229  528
         if (cdataSectionElements == null) {
 230  22
             cdataSectionElements = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getCdataSectionElements());
 231  
         }
 232  
 
 233  528
         return cdataSectionElements;
 234  
     }
 235  
 
 236  
     public HistoryListModel getMedias() {
 237  286
         if (medias == null) {
 238  22
             medias = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getMedias());
 239  
         }
 240  
 
 241  286
         return medias;
 242  
     }
 243  
 
 244  
     public HistoryListModel getTitles() {
 245  286
         if (titles == null) {
 246  22
             titles = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getTitles());
 247  
         }
 248  
 
 249  286
         return titles;
 250  
     }
 251  
 
 252  
     public HistoryListModel getCharsets() {
 253  286
         if (charsets == null) {
 254  22
             charsets = createModel(PreferencesHandler.getInstance().getPreferences().getHistory().getCharsets());
 255  
         }
 256  
 
 257  286
         return charsets;
 258  
     }
 259  
 
 260  
     private HistoryListModel createModel( HistoryList hist) {
 261  286
         return new HistoryListModel( hist);
 262  
     }
 263  
  }