1/* sane - Scanner Access Now Easy. 2 Copyright (C) 1997 Jeffrey S. Freedman 3 This file is part of the SANE package. 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 2 of the 8 License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 As a special exception, the authors of SANE give permission for 19 additional uses of the libraries contained in this release of SANE. 20 21 The exception is that, if you link a SANE library with other files 22 to produce an executable, this does not by itself cause the 23 resulting executable to be covered by the GNU General Public 24 License. Your use of that executable is in no way restricted on 25 account of linking the SANE library code into it. 26 27 This exception does not, however, invalidate any other reasons why 28 the executable file might be covered by the GNU General Public 29 License. 30 31 If you submit changes to SANE to the maintainers to be included in 32 a subsequent release, you agree by submitting the changes that 33 those changes may be distributed with this exception intact. 34 35 If you write modifications of your own for SANE, it is your choice 36 whether to permit this exception to apply to your modifications. 37 If you do not wish that, delete this exception notice. */ 38 39// 40// SaneOption.java - Sane option descriptor. 41// 42// Written: 10/9/97 - JSF 43// 44 45public class SaneOption 46 { 47 // 48 // Sane option types: 49 // 50 public static final int TYPE_BOOL = 0; 51 public static final int TYPE_INT = 1; 52 public static final int TYPE_FIXED = 2; 53 public static final int TYPE_STRING = 3; 54 public static final int TYPE_BUTTON = 4; 55 public static final int TYPE_GROUP = 5; 56 // 57 // Sane value units: 58 // 59 public static final int UNIT_NONE = 0; // the value is unit-less 60 // (e.g., # of scans) 61 public static final int UNIT_PIXEL = 1; // value is number of pixels 62 public static final int UNIT_BIT = 2; // value is number of bits 63 public static final int UNIT_MM = 3; // value is millimeters 64 public static final int UNIT_DPI = 4; // value is res. in dots/inch 65 public static final int UNIT_PERCENT = 5;// value is a percentage 66 // 67 // Option capabilities: 68 // 69 public static final int CAP_SOFT_SELECT = (1 << 0); 70 public static final int CAP_HARD_SELECT = (1 << 1); 71 public static final int CAP_SOFT_DETECT = (1 << 2); 72 public static final int CAP_EMULATED = (1 << 3); 73 public static final int CAP_AUTOMATIC = (1 << 4); 74 public static final int CAP_INACTIVE = (1 << 5); 75 public static final int CAP_ADVANCED = (1 << 6); 76 // 77 // Constraints: 78 // 79 public static final int CONSTRAINT_NONE = 0; 80 public static final int CONSTRAINT_RANGE = 1; 81 public static final int CONSTRAINT_WORD_LIST = 2; 82 public static final int CONSTRAINT_STRING_LIST = 3; 83 // 84 // Actions for controlOption(): 85 // 86 public static final int ACTION_GET_VALUE = 0; 87 public static final int ACTION_SET_VALUE = 1; 88 public static final int ACTION_SET_AUTO = 2; 89 90 // 91 // Flags passed back in 'info' field param. of 92 // setControlOption(): 93 // 94 public static final int INFO_INEXACT = (1 << 0); 95 public static final int INFO_RELOAD_OPTIONS = (1 << 1); 96 public static final int INFO_RELOAD_PARAMS = (1 << 2); 97 98 // 99 // Class members: 100 // 101 public String name; // name of this option (command-line name) 102 public String title; // title of this option (single-line) 103 public String desc; // description of this option (multi-line) 104 public int type; // how are values interpreted? (TYPE_) 105 public int unit; // what is the (physical) unit? (UNIT_) 106 public int size; 107 public int cap; // capabilities 108 public int constraintType; 109 // These are a union in the "C" API: 110 // Null-terminated list: 111 public String[] stringListConstraint; 112 // First element is list-length: 113 public int[] wordListConstraint; 114 public SaneRange rangeConstraint; 115 // 116 // Public methods: 117 // 118 public boolean is_active() 119 { return ((cap) & CAP_INACTIVE) == 0; } 120 public boolean is_settable() 121 { return ((cap) & CAP_SOFT_SELECT) == 0; } 122 // Return string describing units. 123 // "unitLength" is # mm. preferred. 124 public String unitString(double unitLength) 125 { 126 switch (unit) 127 { 128 case UNIT_NONE: return "none"; 129 case UNIT_PIXEL: return "pixel"; 130 case UNIT_BIT: return "bit"; 131 case UNIT_DPI: return "dpi"; 132 case UNIT_PERCENT: return "%"; 133 case UNIT_MM: 134 if (unitLength > 9.9 && unitLength < 10.1) 135 return "cm"; 136 else if (unitLength > 25.3 && unitLength < 25.5) 137 return "in"; 138 return "mm"; 139 } 140 return ""; 141 } 142 } 143