001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.i18n.wizard;
043:
044: import java.util.Comparator;
045: import java.util.Map;
046: import java.util.Set;
047: import java.util.TreeMap;
048: import org.netbeans.modules.i18n.HardCodedString;
049: import org.netbeans.modules.i18n.I18nString;
050:
051: import org.netbeans.modules.i18n.I18nSupport;
052:
053: import org.openide.loaders.DataObject;
054:
055: /**
056: * Object representing source dependent i18n data passed to i18n wizard
057: * descriptor and its panels via readSettings and storeSettings methods.
058: * It's the "value part" of <code>Map</code> (keyed by DataObject)
059: * passed as settings for wizard descriptor and to individual panels.
060: *
061: * @author Peter Zavadsky
062: * @see ResourceWizardPanel where lifecycle begins.
063: * @see org.openide.WizardDescriptor
064: * @see org.openide.WizardDescriptor.Panel#readSettings
065: * @see org.openide.WizardDecritptor.Panel#storeSettings
066: */
067: final class SourceData {
068:
069: /** Resource where to put i18n string */
070: private DataObject resource;
071:
072: /** Support used by i18n-zing. */
073: private I18nSupport support;
074:
075: /** Mapping found hard coded strings to i18n strings. */
076: private Map<HardCodedString, I18nString> stringMap = new TreeMap<HardCodedString, I18nString>(
077: new HardStringComparator());
078:
079: private static class HardStringComparator implements
080: Comparator<HardCodedString> {
081: public int compare(HardCodedString hcs1, HardCodedString hcs2) {
082: return hcs1.getStartPosition().getOffset()
083: - hcs2.getStartPosition().getOffset();
084: }
085: }
086:
087: /** Hard coded strings user selected to non-proceed. */
088: private Set<HardCodedString> removedStrings;
089:
090: /** Constructor. */
091: public SourceData(DataObject resource) {
092: this .resource = resource;
093: }
094:
095: /** Constructor. */
096: public SourceData(DataObject resource, I18nSupport support) {
097: this .resource = resource;
098: this .support = support;
099:
100: support.getResourceHolder().setResource(resource);
101: }
102:
103: /** Getter for <code>resource</code> property. */
104: public DataObject getResource() {
105: return resource;
106: }
107:
108: /** Getter for <code>resource</code> property. */
109: public I18nSupport getSupport() {
110: return support;
111: }
112:
113: /** Getter for <code>stringMap</code> property. */
114: public Map<HardCodedString, I18nString> getStringMap() {
115: return stringMap;
116: }
117:
118: /** Setter for <code>stringMap</code> prtoperty. */
119: public void setStringMap(Map<HardCodedString, I18nString> stringMap) {
120: this .stringMap.clear();
121: this .stringMap.putAll(stringMap);
122: }
123:
124: /** Getter for <code>removedStrings</code> property. */
125: public Set<HardCodedString> getRemovedStrings() {
126: return removedStrings;
127: }
128:
129: /** Setter for <code>removedStrings</code> property. */
130: public void setRemovedStrings(Set<HardCodedString> removedStrings) {
131: this.removedStrings = removedStrings;
132: }
133:
134: }
|