blob: caa820a3ecffe4ef0e6cdaef499c6e674cafb9b2 [file] [log] [blame]
Richard S. Hall46754b52007-07-16 18:36:11 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.example.extenderbased.square;
20
21import java.awt.BasicStroke;
22import java.awt.Color;
23import java.awt.GradientPaint;
24import java.awt.Graphics2D;
25import java.awt.Point;
26import java.awt.geom.*;
27import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
28import org.osgi.framework.*;
29
30/**
31 * This class implements the square <tt>SimpleShape</tt> extension.
32 * It simply provides a <tt>draw()</tt> that paints a square.
33**/
34public class Square implements SimpleShape
35{
36 /**
37 * Implements the <tt>SimpleShape.draw()</tt> method for painting
38 * the shape.
39 * @param g2 The graphics object used for painting.
40 * @param p The position to paint the triangle.
41 **/
42 public void draw(Graphics2D g2, Point p)
43 {
44 int x = p.x - 25;
45 int y = p.y - 25;
46 GradientPaint gradient = new GradientPaint(
47 x, y, Color.BLUE, x + 50, y, Color.WHITE);
48 g2.setPaint(gradient);
49 g2.fill(new Rectangle2D.Double(x, y, 50, 50));
50 BasicStroke wideStroke = new BasicStroke(2.0f);
51 g2.setColor(Color.black);
52 g2.setStroke(wideStroke);
53 g2.draw(new Rectangle2D.Double(x, y, 50, 50));
54 }
55}