1/*
2 * Copyright 2007, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.awt;
18
19import java.awt.Graphics2D;
20import java.awt.Toolkit;
21
22import org.apache.harmony.awt.wtk.GraphicsFactory;
23
24import android.graphics.Canvas;
25import android.graphics.Paint;
26
27public class AwtFactory {
28
29    private static GraphicsFactory gf;
30
31    /**
32     * Use this method to get acces to AWT drawing primitives and to
33     * render into the surface area of a Android widget. Origin and
34     * clip of the returned graphics object are the same as in the
35     * corresponding Android widget.
36     *
37     * @param c Canvas of the android widget to draw into
38     * @param p The default drawing parameters such as font,
39     * stroke, foreground and background colors, etc.
40     * @return The AWT Graphics object that makes all AWT
41     * drawing primitives available in the androind world.
42     */
43    public static Graphics2D getAwtGraphics(Canvas c, Paint p) {
44        // AWT?? TODO: test it!
45        if (null == gf) {
46            Toolkit tk = Toolkit.getDefaultToolkit();
47            gf = tk.getGraphicsFactory();
48        }
49        return gf.getGraphics2D(c, p);
50    }
51
52}
53