1 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
2  * Copyright 2004-2005 Cendio AB.
3  * Copyright 2012 Brian P. Hinz
4  *
5  * This is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this software; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18  * USA.
19  */
20 
21 package com.tigervnc.rfb;
22 
23 public class IntParameter extends VoidParameter {
IntParameter(String name_, String desc_, int v, int minValue_, int maxValue_, Configuration.ConfigurationObject co)24   public IntParameter(String name_, String desc_, int v,
25                       int minValue_, int maxValue_,
26                       Configuration.ConfigurationObject co)
27   {
28     super(name_, desc_, co);
29     value = v;
30     defValue = v;
31     minValue = minValue_;
32     maxValue = maxValue_;
33   }
34 
IntParameter(String name_, String desc_, int v)35   public IntParameter(String name_, String desc_, int v)
36   {
37     this(name_, desc_, v, Integer.MIN_VALUE, Integer.MAX_VALUE,
38          Configuration.ConfigurationObject.ConfGlobal);
39   }
40 
setParam(String v)41   public boolean setParam(String v) {
42     if (immutable) return true;
43     vlog.debug("set "+getName()+"(Int) to "+v);
44     try {
45       int i;
46       i = Integer.parseInt(v);
47       if (i < minValue || i > maxValue)
48         return false;
49       value = i;
50       return true;
51     } catch (NumberFormatException e) {
52       throw new Exception(e.toString());
53     }
54   }
55 
setParam(int v)56   public boolean setParam(int v) {
57     if (immutable) return true;
58     vlog.debug("set "+getName()+"(Int) to "+v);
59     if (v < minValue || v > maxValue)
60       return false;
61     value = v;
62     return true;
63   }
64 
getDefaultStr()65   public String getDefaultStr() { return Integer.toString(defValue); }
getValueStr()66   public String getValueStr() { return Integer.toString(value); }
67 
68   //public int int() { return value; }
getValue()69   public int getValue() { return value; }
70 
71   protected int value;
72   protected int defValue;
73   protected int minValue;
74   protected int maxValue;
75 }
76