001: /*
002: * CharacterRange.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.util;
013:
014: import workbench.resource.ResourceMgr;
015:
016: /**
017: * @author support@sql-workbench.net
018: */
019: public class CharacterRange {
020: /**
021: * Includes all characters
022: */
023: public static final CharacterRange RANGE_NONE = new CharacterRange(
024: 0);
025:
026: /**
027: * Excludes all control characters (< 32)
028: */
029: public static final CharacterRange RANGE_CONTROL = new CharacterRange(
030: 1);
031:
032: /**
033: * Excludes everyting < 32 and > 126
034: */
035: public static final CharacterRange RANGE_7BIT = new CharacterRange(
036: 2);
037:
038: /**
039: * Excludes everyting < 32 and > 255
040: */
041: public static final CharacterRange RANGE_8BIT = new CharacterRange(
042: 3);
043:
044: /**
045: * Excludes everyting < 32 and > 255
046: * and anything > 126 and < 161
047: */
048: public static final CharacterRange RANGE_8BIT_EXTENDED = new CharacterRange(
049: 4);
050:
051: private int typeIndex = 0;
052:
053: private CharacterRange(int index) {
054: typeIndex = index;
055: }
056:
057: public static boolean isValidId(int id) {
058: return id >= 0 && id <= 4;
059: }
060:
061: public static CharacterRange[] getRanges() {
062: return new CharacterRange[] { RANGE_NONE, RANGE_CONTROL,
063: RANGE_7BIT, RANGE_8BIT, RANGE_8BIT_EXTENDED };
064: }
065:
066: public static CharacterRange getRangeById(int index) {
067: switch (index) {
068: case 0:
069: return RANGE_NONE;
070: case 1:
071: return RANGE_CONTROL;
072: case 2:
073: return RANGE_7BIT;
074: case 3:
075: return RANGE_8BIT;
076: case 4:
077: return RANGE_8BIT_EXTENDED;
078: }
079: return null;
080: }
081:
082: public int getId() {
083: return typeIndex;
084: }
085:
086: public boolean isOutsideRange(char c) {
087: switch (typeIndex) {
088: case 0:
089: return false;
090: case 1:
091: return (c < 32);
092: case 2:
093: return (c < 32 || c > 126);
094: case 3:
095: return (c < 32 || c > 255);
096: case 4:
097: return (c < 32 || (c > 126 && c < 161) || c > 255);
098: }
099: return false;
100: }
101:
102: public String getFilterDescription() {
103: switch (typeIndex) {
104: case 0:
105: return ResourceMgr.getString("LblNone");
106: case 1:
107: return ResourceMgr.getString("LblExportRangeCtrl");
108: case 2:
109: return ResourceMgr.getString("LblExportRange7Bit");
110: case 3:
111: return ResourceMgr.getString("LblExportRange8Bit");
112: case 4:
113: return ResourceMgr.getString("LblExportRange8BitExtended");
114: }
115: return "";
116: }
117:
118: public String toString() {
119: return getFilterDescription();
120: }
121: }
|