001 /** 002 * This library is free software; you can redistribute it and/or modify it 003 * under the terms of the GNU Lesser General Public License (LGPL) as 004 * published by the Free Software Foundation; either version 3.0 of the 005 * License, or (at your option) any later version. 006 * 007 * This library is distributed in the hope that it will be useful, but 008 * WITHOUT ANY WARRANTY; without even the implied warranty of 009 * MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU 010 * Lesser General Public License for more details. 011 */ 012 013 /** 014 * Title: JBarcodeBean 015 * Description: Barcode JavaBeans Component 016 * Copyright: Copyright (C) 2004 017 * Company: Dafydd Walters 018 */ 019 package net.sourceforge.jbarcodebean; 020 021 import java.beans.PropertyEditorSupport; 022 023 import net.sourceforge.jbarcodebean.model.BarcodeStrategy; 024 import net.sourceforge.jbarcodebean.model.Codabar; 025 import net.sourceforge.jbarcodebean.model.Codabar_2to1; 026 import net.sourceforge.jbarcodebean.model.Code11; 027 import net.sourceforge.jbarcodebean.model.Code128; 028 import net.sourceforge.jbarcodebean.model.Code39; 029 import net.sourceforge.jbarcodebean.model.Code39_2to1; 030 import net.sourceforge.jbarcodebean.model.Code93; 031 import net.sourceforge.jbarcodebean.model.Code93Extended; 032 import net.sourceforge.jbarcodebean.model.Ean13; 033 import net.sourceforge.jbarcodebean.model.Ean8; 034 import net.sourceforge.jbarcodebean.model.ExtendedCode39; 035 import net.sourceforge.jbarcodebean.model.ExtendedCode39_2to1; 036 import net.sourceforge.jbarcodebean.model.Interleaved25; 037 import net.sourceforge.jbarcodebean.model.Interleaved25_2to1; 038 import net.sourceforge.jbarcodebean.model.MSI; 039 040 /** 041 * A property editor for the {@link BarcodeStrategy} type. 042 * GUI Builders use this class for the 043 * {@link JBarcodeBean#setCodeType(BarcodeStrategy) codeType} property of 044 * the {@link JBarcodeBean} Javabean component. 045 */ 046 public class BarcodeStrategyEditor extends PropertyEditorSupport { 047 048 private static final String EAN_8 = "EAN-8"; 049 private static final String EAN_13 = "EAN-13"; 050 private static final String CODABAR_2_1 = "Codabar 2:1"; 051 private static final String CODABAR_3_1 = "Codabar 3:1"; 052 private static final String MSI_MOD_10_CHECK = "MSI (mod 10 check)"; 053 private static final String INTERLEAVED_25_2_1 = "Interleaved 25 2:1"; 054 private static final String INTERLEAVED_25_3_1 = "Interleaved 25 3:1"; 055 private static final String EXT_CODE_39_2_1 = "Ext Code 39 2:1"; 056 private static final String EXT_CODE_39_3_1 = "Ext Code 39 3:1"; 057 private static final String CODE_39_2_1 = "Code 39 2:1"; 058 private static final String CODE_39_3_1 = "Code 39 3:1"; 059 private static final String CODE_128 = "Code 128"; 060 private static final String CODE_93 = "Code 93"; 061 private static final String CODE_93_EXTENDED = "Code 93 Extended"; 062 private static final String CODE_11 = "Code 11"; 063 064 public String[] getTags() { 065 return new String[] { 066 CODE_11, 067 CODE_128, 068 CODE_39_3_1, 069 CODE_39_2_1, 070 EXT_CODE_39_3_1, 071 EXT_CODE_39_2_1, 072 CODE_93, 073 CODE_93_EXTENDED, 074 INTERLEAVED_25_3_1, 075 INTERLEAVED_25_2_1, 076 MSI_MOD_10_CHECK, 077 CODABAR_3_1, 078 CODABAR_2_1, 079 EAN_13, 080 EAN_8 081 }; 082 } 083 084 public void setAsText(String s) { 085 if (s.equals(CODE_128)) { 086 setValue(new Code128()); 087 } else if (s.equals(CODE_39_3_1)) { 088 setValue(new Code39()); 089 } else if (s.equals(CODE_39_2_1)) { 090 setValue(new Code39_2to1()); 091 } else if (s.equals(EXT_CODE_39_3_1)) { 092 setValue(new ExtendedCode39()); 093 } else if (s.equals(EXT_CODE_39_2_1)) { 094 setValue(new ExtendedCode39_2to1()); 095 } else if (s.equals(INTERLEAVED_25_3_1)) { 096 setValue(new Interleaved25()); 097 } else if (s.equals(INTERLEAVED_25_2_1)) { 098 setValue(new Interleaved25_2to1()); 099 } else if (s.equals(MSI_MOD_10_CHECK)) { 100 setValue(new MSI()); 101 } else if (s.equals(CODABAR_3_1)) { 102 setValue(new Codabar()); 103 } else if (s.equals(CODABAR_2_1)) { 104 setValue(new Codabar_2to1()); 105 } else if (s.equals(EAN_13)) { 106 setValue(new Ean13()); 107 } else if (s.equals(EAN_8)) { 108 setValue(new Ean8()); 109 } else if (s.equals(CODE_93)) { 110 setValue(new Code93()); 111 } else if (s.equals(CODE_93_EXTENDED)) { 112 setValue(new Code93Extended()); 113 } else if (s.equals(CODE_11)) { 114 setValue(new Code11()); 115 } else { 116 // Default to Code 39 117 setValue(new Code39()); 118 } 119 } 120 121 public String getAsText() { 122 BarcodeStrategy s = (BarcodeStrategy)getValue(); 123 if (s.getClass().equals(Code128.class)) { 124 // Code 128 125 return CODE_128; 126 } else if (s.getClass().equals(Code39_2to1.class)) { 127 // Code 3 of 9 2:1 128 return CODE_39_2_1; 129 } else if (s.getClass().equals(Code39.class)) { 130 // Code 3 of 9 3:1 131 return CODE_39_3_1; 132 } else if (s.getClass().equals(ExtendedCode39_2to1.class)) { 133 // Extended Code 3 of 9 2:1 134 return EXT_CODE_39_2_1; 135 } else if (s.getClass().equals(ExtendedCode39.class)) { 136 // Extended Code 3 of 9 3:1 137 return EXT_CODE_39_3_1; 138 } else if (s.getClass().equals(Interleaved25_2to1.class)) { 139 // Interleaved 25 2:1 140 return INTERLEAVED_25_2_1; 141 } else if (s.getClass().equals(Interleaved25.class)) { 142 // Interleaved 25 3:1 143 return INTERLEAVED_25_3_1; 144 } else if (s.getClass().equals(MSI.class)) { 145 // MSI 146 return MSI_MOD_10_CHECK; 147 } else if (s.getClass().equals(Codabar_2to1.class)) { 148 // Codabar 2:1 149 return CODABAR_2_1; 150 } else if (s.getClass().equals(Codabar.class)) { 151 // Codabar 3:1 152 return CODABAR_3_1; 153 } else if (s.getClass().equals(Ean13.class)) { 154 // EAN-13 155 return EAN_13; 156 } else if (s.getClass().equals(Ean8.class)) { 157 // EAN-8 158 return EAN_8; 159 } else if (s.getClass().equals(Code93.class)) { 160 // EAN-8 161 return CODE_93; 162 } else if (s.getClass().equals(Code93Extended.class)) { 163 // EAN-8 164 return CODE_93_EXTENDED; 165 } else if (s.getClass().equals(Code11.class)) { 166 // EAN-8 167 return CODE_11; 168 } else { 169 // Must set to something, so default to Code 39 170 return "Code 39"; 171 } 172 } 173 174 public String getJavaInitializationString() { 175 BarcodeStrategy s = (BarcodeStrategy)getValue(); 176 if (s.getClass().equals(Code128.class)) { 177 // Code 128 178 return "new jbarcodebean.Code128()"; 179 } else if (s.getClass().equals(Code39_2to1.class)) { 180 // Code 3 of 9 2:1 181 return "new jbarcodebean.Code39_2to1()"; 182 } else if (s.getClass().equals(Code39.class)) { 183 // Code 3 of 9 3:1 184 return "new jbarcodebean.Code39()"; 185 } else if (s.getClass().equals(ExtendedCode39_2to1.class)) { 186 // Extended Code 3 of 9 2:1 187 return "new jbarcodebean.ExtendedCode39_2to1()"; 188 } else if (s.getClass().equals(ExtendedCode39.class)) { 189 // Extended Code 3 of 9 3:1 190 return "new jbarcodebean.ExtendedCode39()"; 191 } else if (s.getClass().equals(Interleaved25_2to1.class)) { 192 // Interleaved 25 2:1 193 return "new jbarcodebean.Interleaved25_2to1()"; 194 } else if (s.getClass().equals(Interleaved25.class)) { 195 // Interleaved 25 3:1 196 return "new jbarcodebean.Interleaved25()"; 197 } else if (s.getClass().equals(MSI.class)) { 198 // MSI 199 return "new jbarcodebean.MSI()"; 200 } else if (s.getClass().equals(Codabar_2to1.class)) { 201 // Codabar 2:1 202 return "new jbarcodebean.Codabar_2to1()"; 203 } else if (s.getClass().equals(Codabar.class)) { 204 // Codabar 3:1 205 return "new jbarcodebean.Codabar()"; 206 } else if (s.getClass().equals(Ean13.class)) { 207 // EAN-13 208 return "new jbarcodebean.Ean13()"; 209 } else if (s.getClass().equals(Ean8.class)) { 210 // EAN-8 211 return "new jbarcodebean.Ean8()"; 212 } else if (s.getClass().equals(Code93.class)) { 213 // EAN-8 214 return "new jbarcodebean.Code93()"; 215 } else if (s.getClass().equals(Code93Extended.class)) { 216 // EAN-8 217 return "new jbarcodebean.Code93Extended()"; 218 } else if (s.getClass().equals(Code11.class)) { 219 // EAN-8 220 return "new jbarcodebean.Code11()"; 221 } else { 222 // Must set to something, so default to Code 39 223 return "new jbarcodebean.Code39()"; 224 } 225 } 226 }