Showing the changes to java/pkg/java/awt/ColorPaintContext.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,83 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | package java.awt; | ||
| 29 | |||
| 30 | import java.awt.image.ColorModel; | ||
| 31 | import java.awt.image.Raster; | ||
| 32 | import java.awt.image.WritableRaster; | ||
| 33 | import sun.awt.image.IntegerComponentRaster; | ||
| 34 | import java.util.Arrays; | ||
| 35 | |||
| 36 | class ColorPaintContext implements PaintContext { | ||
| 37 | int color; | ||
| 38 | WritableRaster savedTile; | ||
| 39 | |||
| 40 | protected ColorPaintContext(int color, ColorModel cm) { | ||
| 41 | this.color = color; | ||
| 42 | } | ||
| 43 | |||
| 44 | public void dispose() { | ||
| 45 | } | ||
| 46 | |||
| 47 | /* | ||
| 48 | * Returns the RGB value representing the color in the default sRGB | ||
| 49 | * {@link ColorModel}. | ||
| 50 | * (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are | ||
| 51 | * blue). | ||
| 52 | * @return the RGB value of the color in the default sRGB | ||
| 53 | * <code>ColorModel</code>. | ||
| 54 | * @see java.awt.image.ColorModel#getRGBdefault | ||
| 55 | * @see #getRed | ||
| 56 | * @see #getGreen | ||
| 57 | * @see #getBlue | ||
| 58 | */ | ||
| 59 | int getRGB() { | ||
| 60 | return color; | ||
| 61 | } | ||
| 62 | |||
| 63 | public ColorModel getColorModel() { | ||
| 64 | return ColorModel.getRGBdefault(); | ||
| 65 | } | ||
| 66 | |||
| 67 | public synchronized Raster getRaster(int x, int y, int w, int h) { | ||
| 68 | WritableRaster t = savedTile; | ||
| 69 | |||
| 70 | if (t == null || w > t.getWidth() || h > t.getHeight()) { | ||
| 71 | t = getColorModel().createCompatibleWritableRaster(w, h); | ||
| 72 | IntegerComponentRaster icr = (IntegerComponentRaster) t; | ||
| 73 | Arrays.fill(icr.getDataStorage(), color); | ||
| 74 | // Note - markDirty is probably unnecessary since icr is brand new | ||
| 75 | icr.markDirty(); | ||
| 76 | if (w <= 64 && h <= 64) { | ||
| 77 | savedTile = t; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return t; | ||
| 82 | } | ||
| 83 | } | ||