Richard S. Hall | 46754b5 | 2007-07-16 18:36:11 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 19 | package org.apache.felix.example.extenderbased.square; |
| 20 | |
| 21 | import java.awt.BasicStroke; |
| 22 | import java.awt.Color; |
| 23 | import java.awt.GradientPaint; |
| 24 | import java.awt.Graphics2D; |
| 25 | import java.awt.Point; |
| 26 | import java.awt.geom.*; |
| 27 | import org.apache.felix.example.extenderbased.host.extension.SimpleShape; |
| 28 | import 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 | **/ |
| 34 | public 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 | } |