view m-toolbox/classes/@LTPDAprefs/setPreference.m @ 40:977eb37f31cb database-connection-manager

User friendlier errors from utils.mysql.connect
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 18:04:03 +0100
parents f0afece42f48
children
line wrap: on
line source

% SETPREFERENCE A static method which sets a new value to the specified preference.
%
% Call:        LTPDAprefs.setPreference(category, property, value)
%
% Parameters:
%       category - Category of the preference
%       property - Property of the preference
%       value    - new value
%
% Version:
%     $Id: setPreference.m,v 1.4 2011/04/09 17:04:22 hewitson Exp $
%

function setPreference(category, property, value)
  prefs = getappdata(0, 'LTPDApreferences');
  if isempty(prefs)
    error('### No LTPDA Preferences found in memory. Please run ltpda_startup.');
  end
  
  switch category
    
    case 'display'
      cprefs = prefs.getDisplayPrefs;
      switch property
        case 'verboseLevel'
          cprefs.setDisplayVerboseLevel(java.lang.Integer(value));
          displayValueSet(category, property, double(cprefs.getDisplayVerboseLevel));
        case 'wrapstrings'
          cprefs.setDisplayWrapStrings(java.lang.Integer(value));
          displayValueSet(category, property, double(cprefs.getDisplayWrapStrings));
        otherwise
          help LTPDAprefs
          error('Unknown property [%s] for category [%s]', property, category);
      end
      
    case 'plot'
      pprefs = prefs.getPlotPrefs;
      switch property
        case 'axesFontSize'
          pprefs.setPlotDefaultAxesFontSize(java.lang.Integer(value));
          displayValueSet(category, property, double(pprefs.getPlotDefaultAxesFontSize));
        case 'axesFontWeight'
          pprefs.setPlotDefaultAxesFontWeight(value);
          displayValueSet(category, property, char(pprefs.getPlotDefaultAxesFontWeight));
        case 'axesLineWidth'
          pprefs.setPlotDefaultAxesLineWidth(java.lang.Integer(value));
          displayValueSet(category, property, double(pprefs.getPlotDefaultAxesLineWidth));
        case 'lineLineWidth'
          pprefs.setPlotDefaultLineLineWidth(java.lang.Integer(value));
          displayValueSet(category, property, double(pprefs.getPlotDefaultLineLineWidth));
        case 'lineMarkerSize'
          pprefs.setPlotDefaultLineMarkerSize(java.lang.Integer(value));
          displayValueSet(category, property, double(pprefs.getPlotDefaultLineMarkerSize));
        case 'gridStyle'
          pprefs.setPlotDefaultAxesGridLineStyle(value);
          displayValueSet(category, property, char(pprefs.getPlotDefaultAxesGridLineStyle));
        case 'minorGridStyle'
          pprefs.setPlotDefaultAxesMinorGridLineStyle(value);
          displayValueSet(category, property, char(pprefs.getPlotDefaultAxesMinorGridLineStyle));
        case 'legendFontSize'
          pprefs.setPlotDefaultLegendFontSize(java.lang.Integer(value));
          displayValueSet(category, property, char(pprefs.getPlotDefaultLegendFontSize));
        case 'includeDescription'
          pprefs.setPlotDefaultIncludeDescription(java.lang.Boolean(value));
          displayValueSet(category, property, char(pprefs.getPlotDefaultIncludeDescription));
        otherwise
          help LTPDAprefs
          error('Unknown property [%s] for category [%s]', property, category);
      end
      
      
    case 'time'
      tprefs = prefs.getTimePrefs;
      switch property
        case 'timezone'
          tprefs.setTimeTimezone(value);
          displayValueSet(category, property, char(tprefs.getTimeTimezone));
        case 'timeformat'
          tprefs.setTimestringFormat(value);
          displayValueSet(category, property, char(tprefs.getTimestringFormat));
        otherwise
          help LTPDAprefs
          error('Unknown property [%s] for category [%s]', property, category);
      end
      
    case 'misc'
      mprefs = prefs.getMiscPrefs;
      switch property
        case 'default_window'
          mprefs.setDefaultWindow(value);
          displayValueSet(category, property, char(mprefs.getDefaultWindow));
        otherwise
          help LTPDAprefs
          error('Unknown property [%s] for category [%s]', property, category);
      end
      
    otherwise
      help LTPDAprefs
      error('Unknown preference category %s', category)
  end
  
  function displayValueSet(category, property, value)
    if ischar(value)
      fprintf('* set %s/%s to [%s]\n', category, property, value);
    else
      fprintf('* set %s/%s to [%d]\n', category, property, value);
    end
  end
  
end