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: /**
18: * @author Igor V. Stolyarov
19: * @version $Revision$
20: */package java.awt;
21:
22: import java.awt.image.AreaAveragingScaleFilter;
23: import java.awt.image.FilteredImageSource;
24: import java.awt.image.ImageFilter;
25: import java.awt.image.ImageObserver;
26: import java.awt.image.ImageProducer;
27: import java.awt.image.ReplicateScaleFilter;
28:
29: import org.apache.harmony.awt.internal.nls.Messages;
30:
31: public abstract class Image {
32:
33: public static final Object UndefinedProperty = new Object(); //$NON-LOCK-1$
34:
35: public static final int SCALE_DEFAULT = 1;
36:
37: public static final int SCALE_FAST = 2;
38:
39: public static final int SCALE_SMOOTH = 4;
40:
41: public static final int SCALE_REPLICATE = 8;
42:
43: public static final int SCALE_AREA_AVERAGING = 16;
44:
45: protected float accelerationPriority = 0.5f;
46:
47: private static final ImageCapabilities capabilities = new ImageCapabilities(
48: false);
49:
50: public abstract Object getProperty(String name,
51: ImageObserver observer);
52:
53: public abstract ImageProducer getSource();
54:
55: public abstract int getWidth(ImageObserver observer);
56:
57: public abstract int getHeight(ImageObserver observer);
58:
59: public Image getScaledInstance(int width, int height, int hints) {
60: ImageFilter filter;
61: if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
62: filter = new AreaAveragingScaleFilter(width, height);
63: } else {
64: filter = new ReplicateScaleFilter(width, height);
65: }
66: ImageProducer producer = new FilteredImageSource(getSource(),
67: filter);
68: return Toolkit.getDefaultToolkit().createImage(producer);
69: }
70:
71: public abstract Graphics getGraphics();
72:
73: public abstract void flush();
74:
75: public float getAccelerationPriority() {
76: return accelerationPriority;
77: }
78:
79: public void setAccelerationPriority(float priority) {
80: if (priority < 0 || priority > 1) {
81: // awt.10A=Priority must be a value between 0 and 1, inclusive
82: throw new IllegalArgumentException(Messages
83: .getString("awt.10A")); //$NON-NLS-1$
84: }
85: accelerationPriority = priority;
86: }
87:
88: public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
89: // Note: common image is not accelerated.
90: return capabilities;
91: }
92: }
|