01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.harmony.pack200;
18:
19: import java.beans.PropertyChangeListener;
20: import java.beans.PropertyChangeSupport;
21: import java.util.SortedMap;
22: import java.util.TreeMap;
23:
24: /**
25: * Provides generic JavaBeans support for the Pack/UnpackAdapters
26: */
27: public abstract class Pack200Adapter {
28:
29: protected static final int DEFAULT_BUFFER_SIZE = 8192;
30:
31: private PropertyChangeSupport support = new PropertyChangeSupport(
32: this );
33:
34: private SortedMap<String, String> properties = new TreeMap<String, String>();
35:
36: public SortedMap<String, String> properties() {
37: return properties;
38: }
39:
40: public void addPropertyChangeListener(
41: PropertyChangeListener listener) {
42: support.addPropertyChangeListener(listener);
43: }
44:
45: protected void firePropertyChange(String propertyName,
46: Object oldValue, Object newValue) {
47: support.firePropertyChange(propertyName, oldValue, newValue);
48: }
49:
50: public void removePropertyChangeListener(
51: PropertyChangeListener listener) {
52: support.removePropertyChangeListener(listener);
53: }
54:
55: /**
56: * Completion between 0..1
57: * @param value
58: */
59: protected void completed(double value) {
60: firePropertyChange(
61: "pack.progress", null, String.valueOf((int) (100 * value))); //$NON-NLS-1$
62: }
63: }
|