Skip navigation links

Package uk.ac.starlink.diva

Provides a toolkit for creating and interacting with simple Figures and also a methodology for connecting to the life cycle of those Figures.

See: Description

Package uk.ac.starlink.diva Description

Provides a toolkit for creating and interacting with simple Figures and also a methodology for connecting to the life cycle of those Figures. I.e. getting notification of their creation, modification and destruction.

Using the Figure toolkit

The only general access method is to use the DrawGraphicsMenu class to add a menu to a JMenuBar that provides actions to create and configure Figures.

An simple example using this can be found in the TestDrawActions class displayed here:

import diva.canvas.JCanvas;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JMenuBar;

public class TestDrawActions
    extends JCanvas
    implements Draw
{
    protected DrawGraphicsPane graphicsPane = null;

    public TestDrawActions()
    {
        //  Add a DrawGraphicsPane to use for displaying
        //  interactive graphics elements.
        graphicsPane = new DrawGraphicsPane( DrawActions.getTypedDecorator() );
        setCanvasPane( graphicsPane );
    }

    public DrawGraphicsPane getGraphicsPane()
    {
        return graphicsPane;
    }
    
    public Component getComponent()
    {
        return this;
    }

    public static void main( String[] args )
    {
        TestDrawActions canvas = new TestDrawActions();
        DrawActions drawActions = new DrawActions( canvas );
        JFrame frame = new JFrame( "TestDrawActions" );
        frame.setSize( new Dimension( 200, 200 ) );
        frame.getContentPane().setLayout( new BorderLayout() );
        frame.getContentPane().add( canvas, BorderLayout.CENTER );
        JMenuBar menuBar = new JMenuBar();
        frame.setJMenuBar( menuBar );
        menuBar.add( new DrawGraphicsMenu( drawActions ) );
        frame.setVisible( true );
    }
}

The important points are that you should use the toolkit to draw on an JCanvas that implements Draw and that has its CanvasPane set to an instance of DrawGraphicsPane.

The toolkit itself is made available by adding an instance of DrawActions to an instance of DrawGraphicsMenu. DrawGraphicsMenu is a JMenu so can be added to JMenuBar as shown.

Skip navigation links

Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.