[dependency-shot] r416 committed - Add OSGi samples

2 views
Skip to first unread message

depende...@googlecode.com

unread,
Apr 8, 2011, 8:40:17 AM4/8/11
to depende...@googlegroups.com
Revision: 416
Author: mathieuancelin
Date: Fri Apr 8 05:38:44 2011
Log: Add OSGi samples
http://code.google.com/p/dependency-shot/source/detail?r=416

Added:
/trunk/dependency-shot-samples/osgi
/trunk/dependency-shot-samples/osgi/api
/trunk/dependency-shot-samples/osgi/api/pom.xml
/trunk/dependency-shot-samples/osgi/api/src
/trunk/dependency-shot-samples/osgi/api/src/main
/trunk/dependency-shot-samples/osgi/api/src/main/java
/trunk/dependency-shot-samples/osgi/api/src/main/java/com
/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample
/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi
/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api

/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api/Shape.java

/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api/ShapeContainer.java

/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api/ShapeProvider.java
/trunk/dependency-shot-samples/osgi/api/src/main/resources
/trunk/dependency-shot-samples/osgi/api/src/main/resources/META-INF

/trunk/dependency-shot-samples/osgi/api/src/main/resources/META-INF/dependency-shot-samples-osgi-paint-api.bnd
/trunk/dependency-shot-samples/osgi/paint
/trunk/dependency-shot-samples/osgi/paint/pom.xml
/trunk/dependency-shot-samples/osgi/paint/src
/trunk/dependency-shot-samples/osgi/paint/src/main
/trunk/dependency-shot-samples/osgi/paint/src/main/java
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/App.java

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/AppBinder.java

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/circle

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/circle/Circle.java

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/circle/CircleShapeProvider.java

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/gui

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/gui/PaintFrame.java

/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/gui/ShapeComponent.java
/trunk/dependency-shot-samples/osgi/paint/src/main/resources
/trunk/dependency-shot-samples/osgi/paint/src/main/resources/META-INF

/trunk/dependency-shot-samples/osgi/paint/src/main/resources/META-INF/dependency-shot-samples-osgi-paint-core.bnd
/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com
/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com/sample

/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com/sample/osgi

/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com/sample/osgi/paint/circle

/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com/sample/osgi/paint/circle/circle.png
/trunk/dependency-shot-samples/osgi/pom.xml
/trunk/dependency-shot-samples/osgi/run.sh
/trunk/dependency-shot-samples/osgi/square
/trunk/dependency-shot-samples/osgi/square/pom.xml
/trunk/dependency-shot-samples/osgi/square/src
/trunk/dependency-shot-samples/osgi/square/src/main
/trunk/dependency-shot-samples/osgi/square/src/main/java
/trunk/dependency-shot-samples/osgi/square/src/main/java/com
/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample
/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample/osgi

/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample/osgi/paint/square

/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample/osgi/paint/square/Square.java

/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample/osgi/paint/square/SquareBinder.java

/trunk/dependency-shot-samples/osgi/square/src/main/java/com/sample/osgi/paint/square/SquareShapeProvider.java
/trunk/dependency-shot-samples/osgi/square/src/main/resources
/trunk/dependency-shot-samples/osgi/square/src/main/resources/META-INF

/trunk/dependency-shot-samples/osgi/square/src/main/resources/META-INF/dependency-shot-samples-osgi-paint-square.bnd
/trunk/dependency-shot-samples/osgi/square/src/main/resources/com
/trunk/dependency-shot-samples/osgi/square/src/main/resources/com/sample

/trunk/dependency-shot-samples/osgi/square/src/main/resources/com/sample/osgi

/trunk/dependency-shot-samples/osgi/square/src/main/resources/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/square/src/main/resources/com/sample/osgi/paint/square

/trunk/dependency-shot-samples/osgi/square/src/main/resources/com/sample/osgi/paint/square/square.png
/trunk/dependency-shot-samples/osgi/test-container
/trunk/dependency-shot-samples/osgi/test-container/pom.xml
/trunk/dependency-shot-samples/osgi/test-container/src
/trunk/dependency-shot-samples/osgi/test-container/src/main
/trunk/dependency-shot-samples/osgi/test-container/src/main/assembly

/trunk/dependency-shot-samples/osgi/test-container/src/main/assembly/felix.xml
/trunk/dependency-shot-samples/osgi/test-container/src/main/resources

/trunk/dependency-shot-samples/osgi/test-container/src/main/resources/META-INF

/trunk/dependency-shot-samples/osgi/test-container/src/main/resources/META-INF/dependency-shot-osgi.bnd

/trunk/dependency-shot-samples/osgi/test-container/src/main/resources/config.properties
/trunk/dependency-shot-samples/osgi/triangle
/trunk/dependency-shot-samples/osgi/triangle/pom.xml
/trunk/dependency-shot-samples/osgi/triangle/src
/trunk/dependency-shot-samples/osgi/triangle/src/main
/trunk/dependency-shot-samples/osgi/triangle/src/main/java
/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com
/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample
/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample/osgi

/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample/osgi/paint/triangle

/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample/osgi/paint/triangle/Triangle.java

/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample/osgi/paint/triangle/TriangleBinder.java

/trunk/dependency-shot-samples/osgi/triangle/src/main/java/com/sample/osgi/paint/triangle/TriangleShapeProvider.java
/trunk/dependency-shot-samples/osgi/triangle/src/main/resources
/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/META-INF

/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/META-INF/dependency-shot-samples-osgi-paint-triangle.bnd
/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/com
/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/com/sample

/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/com/sample/osgi

/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/com/sample/osgi/paint

/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/com/sample/osgi/paint/triangle

/trunk/dependency-shot-samples/osgi/triangle/src/main/resources/com/sample/osgi/paint/triangle/triangle.png
Modified:
/trunk/dependency-shot-samples/pom.xml

=======================================
--- /dev/null
+++ /trunk/dependency-shot-samples/osgi/api/pom.xml Fri Apr 8 05:38:44 2011
@@ -0,0 +1,47 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>dependency-shot-samples-osgi</artifactId>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>dependency-shot-samples-osgi-paint-api</artifactId>
+ <packaging>bundle</packaging>
+ <name>Dependency-Shot (JSR-330) :: OSGi Sample :: Paint API</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.1.0</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>osgi</id>
+ <phase>package</phase>
+ <goals>
+ <goal>bundle</goal>
+ </goals>
+ <configuration>
+ <unpackBundle>true</unpackBundle>
+ <excludeDependencies>
+ org.osgi.core,org.osgi.compendium
+ </excludeDependencies>
+ <instructions>
+
<_include>-target/classes/META-INF/${project.artifactId}.bnd</_include>
+ </instructions>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+
+ </dependencies>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api/Shape.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,14 @@
+package com.sample.osgi.paint.api;
+
+import java.awt.Graphics2D;
+import java.awt.Point;
+import javax.swing.Icon;
+
+public interface Shape {
+
+ String getName();
+
+ Icon getIcon();
+
+ void draw(Graphics2D g2, Point p);
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api/ShapeContainer.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,12 @@
+package com.sample.osgi.paint.api;
+
+import java.util.List;
+
+public interface ShapeContainer extends Shape {
+
+ List<Shape> getShapes();
+
+ void addShape(Shape shape);
+
+ void clearShapes();
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/api/src/main/java/com/sample/osgi/paint/api/ShapeProvider.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,9 @@
+package com.sample.osgi.paint.api;
+
+public interface ShapeProvider {
+
+ String getId();
+
+ Shape getShape();
+
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/api/src/main/resources/META-INF/dependency-shot-samples-osgi-paint-api.bnd
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,1 @@
+Export-Package com.sample.osgi.paint.api
=======================================
--- /dev/null
+++ /trunk/dependency-shot-samples/osgi/paint/pom.xml Fri Apr 8 05:38:44
2011
@@ -0,0 +1,85 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>dependency-shot-samples-osgi</artifactId>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>dependency-shot-samples-osgi-paint-core</artifactId>
+ <packaging>bundle</packaging>
+ <name>Dependency-Shot (JSR-330) :: OSGi Sample :: Paint Core</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.1.0</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>osgi</id>
+ <phase>package</phase>
+ <goals>
+ <goal>bundle</goal>
+ </goals>
+ <configuration>
+ <unpackBundle>true</unpackBundle>
+ <excludeDependencies>
+ org.osgi.core,org.osgi.compendium
+ </excludeDependencies>
+ <instructions>
+
<_include>-target/classes/META-INF/${project.artifactId}.bnd</_include>
+ </instructions>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>dependency-shot-osgi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>dependency-shot-samples-osgi-paint-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+
<artifactId>dependency-shot-samples-osgi-paint-square</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+
<artifactId>dependency-shot-samples-osgi-paint-triangle</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/App.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,45 @@
+package com.sample.osgi.paint;
+
+import com.sample.osgi.paint.api.ShapeProvider;
+import com.sample.osgi.paint.circle.CircleShapeProvider;
+import com.sample.osgi.paint.gui.PaintFrame;
+import com.sample.osgi.paint.square.SquareShapeProvider;
+import cx.ath.mancel01.dependencyshot.DependencyShot;
+import cx.ath.mancel01.dependencyshot.api.DSInjector;
+import cx.ath.mancel01.dependencyshot.api.event.Observes;
+import
cx.ath.mancel01.dependencyshot.dynamic.event.BundleContainerInitialized;
+import cx.ath.mancel01.dependencyshot.dynamic.registry.ServiceRegistry;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+@Singleton
+public class App {
+
+ @Inject PaintFrame frame;
+
+ @PostConstruct
+ public void start() {
+ frame.start();
+ }
+
+ @PreDestroy
+ public void stop() {
+ frame.stop();
+ }
+
+ public void onStartup(@Observes BundleContainerInitialized event) {
+ System.out.println("CDI Container for bundle "
+ + event.getBundleContext().getBundle() + " started");
+ }
+
+ public static void main(String... args) {
+ DSInjector injector = DependencyShot.getInjector(new AppBinder());
+ injector.fire(new BundleContainerInitialized(null));
+ ServiceRegistry registry =
injector.getInstance(ServiceRegistry.class);
+ registry.registerService(ShapeProvider.class, ShapeProvider.class);
+ registry.registerService(ShapeProvider.class,
CircleShapeProvider.class);
+ registry.registerService(ShapeProvider.class,
SquareShapeProvider.class);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/AppBinder.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,20 @@
+package com.sample.osgi.paint;
+
+import com.sample.osgi.paint.api.ShapeProvider;
+import com.sample.osgi.paint.circle.CircleShapeProvider;
+import com.sample.osgi.paint.gui.PaintFrame;
+import cx.ath.mancel01.dependencyshot.dynamic.config.DynamicBinder;
+
+/**
+ *
+ * @author mathieuancelin
+ */
+public class AppBinder extends DynamicBinder {
+
+ @Override
+ public void configure() {
+ bind(ShapeProvider.class).to(CircleShapeProvider.class);
+ registerEventListener(App.class);
+ registerEventListener(PaintFrame.class);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/circle/Circle.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,40 @@
+package com.sample.osgi.paint.circle;
+
+import com.sample.osgi.paint.api.Shape;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.geom.Ellipse2D;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+public class Circle implements Shape {
+
+ private Icon icon;
+
+ public Circle() {
+ icon = new ImageIcon(getClass().getResource("circle.png"));
+ }
+
+ public String getName() {
+ return "Circle";
+ }
+
+ public Icon getIcon() {
+ return icon;
+ }
+
+ public void draw(Graphics2D g2, Point p) {
+ int x = p.x - 25;
+ int y = p.y - 25;
+ GradientPaint gradient = new GradientPaint(x, y, Color.RED, x +
50, y, Color.WHITE);
+ g2.setPaint(gradient);
+ g2.fill(new Ellipse2D.Double(x, y, 50, 50));
+ BasicStroke wideStroke = new BasicStroke(2.0f);
+ g2.setColor(Color.black);
+ g2.setStroke(wideStroke);
+ g2.draw(new Ellipse2D.Double(x, y, 50, 50));
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/circle/CircleShapeProvider.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,19 @@
+package com.sample.osgi.paint.circle;
+
+import com.sample.osgi.paint.api.Shape;
+import com.sample.osgi.paint.api.ShapeProvider;
+import cx.ath.mancel01.dependencyshot.dynamic.config.Publish;
+
+@Publish
+public class CircleShapeProvider implements ShapeProvider {
+
+ @Override
+ public Shape getShape() {
+ return new Circle();
+ }
+
+ @Override
+ public String getId() {
+ return Circle.class.getName();
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/gui/PaintFrame.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,191 @@
+package com.sample.osgi.paint.gui;
+
+import com.sample.osgi.paint.api.Shape;
+import com.sample.osgi.paint.api.ShapeProvider;
+import cx.ath.mancel01.dependencyshot.api.event.Observes;
+import cx.ath.mancel01.dependencyshot.dynamic.event.ServiceArrival;
+import cx.ath.mancel01.dependencyshot.dynamic.event.ServiceDeparture;
+import cx.ath.mancel01.dependencyshot.dynamic.integration.Services;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JToolBar;
+
+
+@Singleton
+public class PaintFrame extends JFrame implements MouseListener {
+
+ private static final int BOX = 54;
+ private JToolBar toolbar;
+ private String selected;
+ private JPanel panel;
+
+ @Inject
+ private Services<ShapeProvider> registeredProviders;
+
+ @Inject
+ private ShapeProvider defaultProvider;
+
+ private ActionListener actionListener = new ShapeActionListener();
+
+ private Map<String, ShapeProvider> providers = new HashMap<String,
ShapeProvider>();
+
+ private Map<String, Collection<ShapeComponent>> goneComponents
+ = new HashMap<String, Collection<ShapeComponent>>();
+
+ public PaintFrame() {
+ super("PaintFrame");
+ toolbar = new JToolBar("Toolbar");
+ panel = new JPanel();
+ panel.setBackground(Color.WHITE);
+ panel.setLayout(null);
+ panel.setMinimumSize(new Dimension(400, 400));
+ panel.addMouseListener(this);
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(toolbar, BorderLayout.NORTH);
+ getContentPane().add(panel, BorderLayout.CENTER);
+ setSize(400, 400);
+ this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+ this.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent evt) {
+ dispose();
+ }
+ });
+ }
+
+ public void selectShape(String name) {
+ selected = name;
+ }
+
+ public void bindService(@Observes ServiceArrival event) {
+ System.out.println("bind : " + event.getServiceClassNames());
+ addShape(event.type(ShapeProvider.class).getService());
+ }
+
+ public void unbindService(@Observes ServiceDeparture event) {
+ System.out.println("unbind : " + event.getServiceClassNames());
+ removeShape(event.type(ShapeProvider.class).getService().getId());
+ }
+
+ private void addShape(ShapeProvider provider) {
+ if (!providers.containsKey(provider.getId())) {
+ providers.put(provider.getId(), provider);
+ Shape shape = provider.getShape();
+ JButton button = new JButton(shape.getIcon());
+ button.setActionCommand(provider.getId());
+ button.setToolTipText(shape.getName());
+ button.addActionListener(actionListener);
+ toolbar.add(button);
+ toolbar.validate();
+ if (goneComponents.containsKey(provider.getId())) {
+ for (ShapeComponent comp :
goneComponents.get(provider.getId())) {
+ panel.add(comp);
+ }
+ panel.validate();
+ goneComponents.get(provider.getId()).clear();
+ }
+ repaint();
+ }
+ }
+
+ private void removeShape(String name) {
+ providers.remove(name);
+ if (!goneComponents.containsKey(name)) {
+ goneComponents.put(name, new ArrayList<ShapeComponent>());
+ }
+ for (Component comp : panel.getComponents()) {
+ ShapeComponent shapeComp = (ShapeComponent) comp;
+ if (shapeComp.getShapeId().equals(name)) {
+ goneComponents.get(name).add(shapeComp);
+ panel.remove(comp);
+ }
+ panel.validate();
+ panel.repaint();
+ }
+ if ((selected != null) && selected.equals(name)) {
+ selected = null;
+ }
+ for (int i = 0; i < toolbar.getComponentCount(); i++) {
+ JButton sb = (JButton) toolbar.getComponent(i);
+ if (sb.getActionCommand().equals(name)) {
+ toolbar.remove(i);
+ toolbar.invalidate();
+ validate();
+ repaint();
+ break;
+ }
+ }
+ if ((selected == null) && (toolbar.getComponentCount() > 0)) {
+ ((JButton) toolbar.getComponent(0)).doClick();
+ }
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent evt) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent evt) {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent evt) {
+ if (selected == null) {
+ return;
+ }
+ if (panel.contains(evt.getX(), evt.getY())) {
+ ShapeComponent sc = null;
+ if (providers.containsKey(selected)) {
+ sc = new
ShapeComponent(providers.get(selected).getShape());
+ sc.setBounds(evt.getX() - BOX / 2, evt.getY() - BOX / 2,
BOX, BOX);
+ panel.add(sc, 0);
+ panel.validate();
+ panel.repaint(sc.getBounds());
+ }
+ }
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent evt) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent evt) {
+ }
+
+ public void start() {
+ addShape(defaultProvider);
+ for (ShapeProvider provider : registeredProviders) {
+ addShape(provider);
+ }
+ this.setVisible(true);
+ }
+
+ public void stop() {
+ this.dispose();
+ }
+
+ private class ShapeActionListener implements ActionListener {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ selectShape(evt.getActionCommand());
+ }
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/java/com/sample/osgi/paint/gui/ShapeComponent.java
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,29 @@
+package com.sample.osgi.paint.gui;
+
+import com.sample.osgi.paint.api.Shape;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import javax.swing.JComponent;
+
+public class ShapeComponent extends JComponent {
+
+ private Shape shape;
+
+ public ShapeComponent(Shape shape) {
+ this.shape = shape;
+ }
+
+ public String getShapeId() {
+ return shape.getClass().getName();
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Graphics2D g2 = (Graphics2D) g;
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ shape.draw(g2, new Point(getWidth() / 2, getHeight() / 2));
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/resources/META-INF/dependency-shot-samples-osgi-paint-core.bnd
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,3 @@
+DynamicImport-Package *
+Dependency-Shot-Enabled : true
+Dynamic-Binder : com.sample.osgi.paint.AppBinder
=======================================
--- /dev/null
+++
/trunk/dependency-shot-samples/osgi/paint/src/main/resources/com/sample/osgi/paint/circle/circle.png
Fri Apr 8 05:38:44 2011
@@ -0,0 +1,39 @@
+‰PNG
+
+
+IHDR 5 5 áæ£p bKGD ÿ ÿ ÿ ½§“
pHYs šœ tIME × : x1˜0
+tEXtComment Created with The
GIMPïd%n äIDAThÞÝÚ lÕW Çñ×¹½À6:R~ J©+l‹. sCÅE ‡Ù’±1Ü SX¦hbfd d üG£#D3\æt ÔE
É$lK0F2b °8†aË P\¦"?K)PÆ-PzÛã ßo»k ö² ¸×OòM¾§÷¶ç¼ûœ Ïyž'Ä
+´B •¸ u
+ dÓ Ó§ ;cŒ- Ý v A¦ bÆYî¯à† ó{ !4tògl– ã™~ ¥?–
+!Œ¯baž¹9ª ? ͉±´Tqr '³œí £‘Ê<a c S×I¦ûïq"ò;¬ˆ1¾ Y¡B Uµ,oâëùÔÚ£i½“}÷°ï> Ž¥ í ÏÙ
+íö£X͸ \ÿ Ÿ9Âõi y¬Ä³1Æ=—
+jl O
+gi WÃ š òÞ—94ø< ï
+ªçóKÆý”YÿfJÚÝ |;Ƹê’@
+ êjøc#“`:M?àýÏq¼ÈA÷ Õõ ÕT/áñF&§ÝoÀü cã€A
+
+áS Í­ «"¿” -àÀE ºh¨®ç1&¿Ì¢6Fc fÆ wö5ÞL__¨ a^ meØg9ù.
+ hr ´š77ñèH¶a<Þ
+!Üß/¨ê æåXÕÆ Y´læŸ×%ÿÅ˦)äþÁ¢ ñ
+®Âº¾À. U §OñÛ3d¿Åñµì¿†NW@#éØË²›x.=[_ !Ü~QP!„º 6ŸbðCä^àÈ ¢+¬¿ó›1¬I-öZ ¡¦h¨q¬Ïqí ÚV— P—ÞáG•¼žº^kŠ‚ª añ >9‚Η8zu
A-
++y¢‚C˜ Bx¼W¨ BÕ ž†åœ¬§C j
+ LfQÚ\
+B¨» Ô ~vš!³iû §•°¶ñ—kX‡J<y^¨ Âøý<
+ß/q .MMvÃ< † ÆŸ 5šïµSq/ùÛJtÚõÔ v a}ºÍ ç
+¨³Ì § W¥lôq^H_
+!d»¡B ÓZ ^O¼31gÙ¨ ·34¤nÔ´n¨z
+†Ùtd•Ÿ†²6}}  ê ÷Á=e²–zj8ÛÓ×é !T
+á:˜\b m±š“L¿<n !ŒÊ`b'™O ‡—)ÔrZ »Òæ ™Ô‡2^Ù«ëV\“IãrjÊÔJ gÓ B¨ iÔ±œUÁÁB¨lúÃÿ eÒ]£<÷ò^  a ™ƒtPÛµad$ zyB™se ¡ aG™ urKúÚœÁÎ » ¹2 ZÁU‘ÛÒæîLŒ1—á]Ø^Dp³ õL
+ÏbGŒ±9“®§õðF™B
+ý0澱𒸠֖équŠÙ
+
+]Podøàod¶– Ø
+Üš®§ l醊1æ;ù5,cH9A½“„ʲXÕ•Z-\C+ m¯‘ÝU&֚Ä<3S¯hÅ9 — ãžÈ/`!CË ê ,K­´²0GÜs·{>к‘A¿O‚ð%«Û¹« »“h„ç{ú~
+¬µ?² ž`Ø †/1¬ ¥isQÏLþ9çRš4ÞpŒÌ#Œ<]b>áA*¾És‘út·{ñ|
^úù4?🭠y¬G}ĕ֭,iã®ÔgýjŒ1_ TŒ±12=Ðú*•ORÝ^ «çkǘŸ®£™ ÊÖ_Ð-Š1îŽ<ˆÜÏ ñ u§® u”Š1,ÞË’tû~8Æøvo—D½€mÄ,äÖQõ%nØ[dÍÑ@i+•õü¤‰¹©
+fÅ ÿÔ×ÍW `SѸ k'1q-Ã/ Ð\îø"«Z“ y#¦ö T T
+¶CâÞo<Æà¯pËtnÞ–$¼ \«©
+Î ×ðLgrMß‚I½M¹B]tmRšcý1ªàó
+^Ì{ $9Ø~U¼¬ öiîmJ,“M§Û"¼x¾]nÀ R°Q’”äw¥žÇ8ŽÎ`ß šfpp$§ YE¶ ±o2)ÇÍ)L>= žý(%rý­÷«“dð
+”Tbvk$‡«91ŠÓcÉ!ßÎÙC i%
+bÌ1&Äÿ½ ´` ~ cÜý‘Ç5På¦!„/H.kw§€Å¦ºvJªÄ^—Tfö;T .a
+íD ÖÏ Fµ›%aÆfìŽ16 tÿÿ ‡¿X%MK ‚ IEND®B`‚
=======================================
--- /dev/null
+++ /trunk/dependency-shot-samples/osgi/pom.xml Fri Apr 8 05:38:44 2011
@@ -0,0 +1,21 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>dependency-shot-samples</artifactId>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <packaging>pom</packaging>
+ <artifactId>dependency-shot-samples-osgi</artifactId>
+ <name>Dependency-Shot (JSR-330) :: OSGi Sample</name>
+ <url>http://code.google.com/p/dependency-shot/</url>
+ <modules>
+ <module>api</module>
+ <module>paint</module>
+ <module>square</module>
+ <module>triangle</module>
+ <module>test-container</module>
+ </modules>
+</project>
=======================================
--- /dev/null
+++ /trunk/dependency-shot-samples/osgi/run.sh Fri Apr 8 05:38:44 2011
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+
+clear;
+#export
DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,address=8000"
+#mvn clean install;
+cd ./test-container/target/dependency-shot-samples-osgi-test-container-1.0-SNAPSHOT-all/dependency-shot-samples-osgi-test-container-1.0-SNAPSHOT/;
+java $DEBUG_OPTS -jar bin/felix.jar;
=======================================
--- /dev/null
+++ /trunk/dependency-shot-samples/osgi/square/pom.xml Fri Apr 8 05:38:44
2011
@@ -0,0 +1,75 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>dependency-shot-samples-osgi</artifactId>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>dependency-shot-samples-osgi-paint-square</artifactId>
+ <packaging>bundle</packaging>
+ <name>Dependency-Shot (JSR-330) :: OSGi Sample :: Square</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.1.0</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>osgi</id>
+ <phase>package</phase>
+ <goals>
+ <goal>bundle</goal>
+ </goals>
+ <configuration>
+ <unpackBundle>true</unpackBundle>
+ <excludeDependencies>
+ org.osgi.core,org.osgi.compendium
+ </excludeDependencies>
+ <instructions>
+
<_include>-target/classes/META-INF/${project.artifactId}.bnd</_include>
+ </instructions>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>dependency-shot-osgi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>dependency-shot-samples-osgi-paint-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
=======================================
***Additional files exist in this changeset.***
Reply all
Reply to author
Forward
0 new messages