1 19 20 21 package org.netbeans.modules.i18n; 22 23 24 import java.io.IOException ; 25 import javax.swing.JPanel ; 26 import javax.swing.text.StyledDocument ; 27 28 import org.openide.cookies.EditorCookie; 29 import org.openide.loaders.DataObject; 30 31 32 38 public abstract class I18nSupport { 39 40 41 private I18nFinder finder; 42 43 44 private I18nReplacer replacer; 45 46 47 protected DataObject sourceDataObject; 48 49 50 protected StyledDocument document; 51 52 53 protected final ResourceHolder resourceHolder; 54 55 56 60 public I18nSupport(DataObject sourceDataObject) { 61 this.sourceDataObject = sourceDataObject; 62 63 EditorCookie editorCookie = (EditorCookie)sourceDataObject.getCookie(EditorCookie.class); 64 65 if(editorCookie == null) 66 throw new IllegalArgumentException ("I18N: Illegal data object type"+ sourceDataObject); 68 this.document = editorCookie.getDocument(); 69 70 this.resourceHolder = createResourceHolder(); 71 } 72 73 74 76 private void loadDocument() throws IOException { 77 if(document == null) { 78 EditorCookie editorCookie = (EditorCookie)sourceDataObject.getCookie(EditorCookie.class); 79 80 if(editorCookie == null) 81 throw new IllegalArgumentException ("I18N: Illegal data object type"+ sourceDataObject); 83 document = editorCookie.openDocument(); 84 } 85 } 86 87 88 protected abstract I18nFinder createFinder(); 89 90 91 protected abstract I18nReplacer createReplacer(); 92 93 94 protected abstract ResourceHolder createResourceHolder(); 95 96 97 public final I18nFinder getFinder() { 98 if(finder == null) 99 finder = createFinder(); 100 101 return finder; 102 } 103 104 105 public final I18nReplacer getReplacer() { 106 if(replacer == null) 107 replacer = createReplacer(); 108 109 return replacer; 110 } 111 112 113 public final DataObject getSourceDataObject() { 114 return sourceDataObject; 115 } 116 117 118 public final StyledDocument getDocument() { 119 return document; 120 } 121 122 124 public I18nString getDefaultI18nString() { 125 return getDefaultI18nString(null); 126 } 127 128 129 public abstract I18nString getDefaultI18nString(HardCodedString hcString); 130 131 132 public abstract JPanel getInfo(HardCodedString hcString); 133 134 135 public ResourceHolder getResourceHolder() { 136 return resourceHolder; 137 } 138 139 141 public PropertyPanel getPropertyPanel() { 142 return new PropertyPanel(); 143 } 144 145 148 public boolean hasAdditionalCustomizer() { 149 return false; 150 } 151 152 155 public JPanel getAdditionalCustomizer() { 156 return null; 157 } 158 159 162 public void performAdditionalChanges() { 163 } 164 165 166 170 public interface I18nFinder { 171 172 174 public HardCodedString findNextHardCodedString(); 175 176 178 public HardCodedString[] findAllHardCodedStrings(); 179 180 182 public HardCodedString findNextI18nString(); 183 184 186 public HardCodedString[] findAllI18nStrings(); 187 } 188 189 194 public interface I18nReplacer { 195 196 197 public void replace(HardCodedString hardString, I18nString i18nString); 198 } 199 200 201 public static abstract class Factory { 202 203 205 public I18nSupport create(DataObject dataObject) throws IOException { 206 I18nSupport support = createI18nSupport(dataObject); 207 support.loadDocument(); 208 209 return support; 210 }; 211 212 213 protected abstract I18nSupport createI18nSupport(DataObject dataObject); 214 215 216 public abstract Class getDataObjectClass(); 217 218 } 220 } 221 222 | Popular Tags |