SwingSpaceTimePlot.java
package org.opentrafficsim.swing.graphs;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPopupMenu;
import org.opentrafficsim.draw.graphs.AbstractSpaceTimePlot;
/**
* Embed a SpaceTimePlot in a Swing JPanel.
* <p>
* Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
* BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
* </p>
* @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
* @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
* @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
*/
public class SwingSpaceTimePlot extends SwingPlot
{
/** */
private static final long serialVersionUID = 20190823L;
/**
* Construct a new Swing container for SpaceTimePlot.
* @param plot the plot to embed
*/
public SwingSpaceTimePlot(final AbstractSpaceTimePlot plot)
{
super(plot);
}
@Override
protected void addPopUpMenuItems(final JPopupMenu popupMenu)
{
JCheckBoxMenuItem fixedDomainCheckBox = new JCheckBoxMenuItem("Fixed time range", false);
fixedDomainCheckBox.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
{
boolean fixed = ((JCheckBoxMenuItem) e.getSource()).isSelected();
getPlot().updateFixedDomainRange(fixed);
}
});
popupMenu.insert(fixedDomainCheckBox, 0);
popupMenu.insert(new JPopupMenu.Separator(), 1);
}
@Override
public AbstractSpaceTimePlot getPlot()
{
return (AbstractSpaceTimePlot) super.getPlot();
}
}