View Javadoc
1   package org.opentrafficsim.swing.graphs;
2   
3   import java.awt.event.ActionEvent;
4   import java.awt.event.ActionListener;
5   
6   import javax.swing.JCheckBoxMenuItem;
7   import javax.swing.JPopupMenu;
8   
9   import org.opentrafficsim.draw.graphs.AbstractSpaceTimePlot;
10  
11  /**
12   * Embed a SpaceTimePlot in a Swing JPanel.
13   * <p>
14   * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
19   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
20   */
21  public class SwingSpaceTimePlot extends SwingPlot
22  {
23  
24      /**  */
25      private static final long serialVersionUID = 20190823L;
26  
27      /**
28       * Construct a new Swing container for SpaceTimePlot.
29       * @param plot SpaceTimePlot; the plot to embed
30       */
31      public SwingSpaceTimePlot(final AbstractSpaceTimePlot plot)
32      {
33          super(plot);
34      }
35  
36      /** {@inheritDoc} */
37      @Override
38      protected void addPopUpMenuItems(final JPopupMenu popupMenu)
39      {
40          JCheckBoxMenuItem fixedDomainCheckBox = new JCheckBoxMenuItem("Fixed time range", false);
41          fixedDomainCheckBox.addActionListener(new ActionListener()
42          {
43              /** {@inheritDoc} */
44              @Override
45              public void actionPerformed(final ActionEvent e)
46              {
47                  boolean fixed = ((JCheckBoxMenuItem) e.getSource()).isSelected();
48                  getPlot().updateFixedDomainRange(fixed);
49              }
50          });
51          popupMenu.insert(fixedDomainCheckBox, 0);
52          popupMenu.insert(new JPopupMenu.Separator(), 1);
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public AbstractSpaceTimePlot getPlot()
58      {
59          return (AbstractSpaceTimePlot) super.getPlot();
60      }
61  
62  }