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   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   */
18  public class SwingSpaceTimePlot extends SwingPlot
19  {
20  
21      /**  */
22      private static final long serialVersionUID = 20190823L;
23  
24      /**
25       * Construct a new Swing container for SpaceTimePlot.
26       * @param plot SpaceTimePlot; the plot to embed
27       */
28      public SwingSpaceTimePlot(final AbstractSpaceTimePlot plot)
29      {
30          super(plot);
31      }
32  
33      /** {@inheritDoc} */
34      @Override
35      protected void addPopUpMenuItems(final JPopupMenu popupMenu)
36      {
37          JCheckBoxMenuItem fixedDomainCheckBox = new JCheckBoxMenuItem("Fixed time range", false);
38          fixedDomainCheckBox.addActionListener(new ActionListener()
39          {
40              /** {@inheritDoc} */
41              @SuppressWarnings("synthetic-access")
42              @Override
43              public void actionPerformed(final ActionEvent e)
44              {
45                  boolean fixed = ((JCheckBoxMenuItem) e.getSource()).isSelected();
46                  getPlot().updateFixedDomainRange(fixed);
47              }
48          });
49          popupMenu.insert(fixedDomainCheckBox, 0);
50          popupMenu.insert(new JPopupMenu.Separator(), 1);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public AbstractSpaceTimePlot getPlot()
56      {
57          return (AbstractSpaceTimePlot) super.getPlot();
58      }
59  
60  
61  }