Drawing an on-screen ornament
Jump to navigation
Jump to search
This code shows you how to draw something that appears on-screen in a fixed location on the screen. In this example, I have made a line that stays on-screen, from (75, 25) to (100, 100), even if you zoom or pan around. This is the technique you would use, for example, to draw a North arrow.
package com.example;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
import com.vividsolutions.jump.workbench.ui.renderer.SimpleRenderer;
public class AzimuthRenderer extends SimpleRenderer {
public final static String CONTENT_ID = "AZIMUTH";
public AzimuthRenderer(LayerViewPanel panel) {
super(CONTENT_ID, panel);
}
protected void paint(Graphics2D g) throws Exception {
g.setColor(Color.red);
g.setStroke(new BasicStroke(4));
g.drawLine(75, 25, 100, 100);
}
}
package com.example;
import com.vividsolutions.jump.workbench.ui.TaskFrame;
import com.vividsolutions.jump.workbench.ui.plugin.InstallRendererPlugIn;
import com.vividsolutions.jump.workbench.ui.renderer.Renderer;
/**
* Ensures that all TaskFrames get a scale bar.
*/
public class InstallAzimuthPlugIn extends InstallRendererPlugIn {
public InstallAzimuthPlugIn() {
super(AzimuthRenderer.CONTENT_ID, true);
}
protected Renderer.Factory createFactory(final TaskFrame frame) {
return new Renderer.Factory() {
public Renderer create() {
return new AzimuthRenderer(frame.getLayerViewPanel());
}
};
}
}
package com.example;
import com.vividsolutions.jump.workbench.plugin.Extension;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
public class AzimuthExtension extends Extension {
public void configure(PlugInContext context) throws Exception {
new InstallAzimuthPlugIn().initialize(context);
}
}