public Stencils()
	{
		super("Stencils");

		try
		{
			String filename = Stencils.class.getResource(
					"/com/mxgraph/examples/swing/shapes.xml").getPath();
			Document doc = mxXmlUtils.parseXml(mxUtils.readFile(filename));

			Element shapes = doc.getDocumentElement();
			NodeList list = shapes.getElementsByTagName("shape");

			for (int i = 0; i < list.getLength(); i++)
			{
				Element shape = (Element) list.item(i);
				mxStencilRegistry.addStencil(shape.getAttribute("name"),
						new mxStencil(shape)
						{
							@Override
							protected mxGraphicsCanvas2D createCanvas(
									final mxGraphics2DCanvas gc)
							{
								// Redirects image loading to graphics canvas
								return new mxGraphicsCanvas2D(gc.getGraphics())
								{
									@Override
									protected Image loadImage(String src)
									{
										// Adds image base path to relative image URLs
										if (!src.startsWith("/")
												&& !src.startsWith("http://")
												&& !src.startsWith("https://")
												&& !src.startsWith("file:"))
										{
											src = gc.getImageBasePath() + src;
										}

										// Call is cached
										return gc.loadImage(src);
									}
								};
							}
						});
			}

			mxGraph graph = new mxGraph();
			Object parent = graph.getDefaultParent();

			graph.getModel().beginUpdate();
			try
			{
				Object v1 = graph
						.insertVertex(parent, null, "Hello", 20, 20, 80, 30,
								"shape=and;fillColor=#ff0000;gradientColor=#ffffff;shadow=1");
				Object v2 = graph.insertVertex(parent, null, "World!", 240,
						150, 80, 30, "shape=xor;shadow=1");
				graph.insertEdge(parent, null, "Edge", v1, v2);
			}
			finally
			{
				graph.getModel().endUpdate();
			}

			mxGraphComponent graphComponent = new mxGraphComponent(graph)
			{
				// Sets global image base path
				@Override
				public mxInteractiveCanvas createCanvas()
				{
					mxInteractiveCanvas canvas = super.createCanvas();
					canvas.setImageBasePath("/com/mxgraph/examples/swing/");

					return canvas;
				}
			};
			getContentPane().add(graphComponent);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}