All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.ihmc.simulationconstructionset.gui.TrackCheckBox Maven / Gradle / Ivy

There is a newer version: 0.25.2
Show newest version
package us.ihmc.simulationconstructionset.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;

import us.ihmc.jMonkeyEngineToolkit.camera.CameraPropertiesHolder;

public class TrackCheckBox extends JCheckBox implements ActionListener
{
   private static final String TRACK = "Track";
   private static final long serialVersionUID = -9012772363648771937L;
   private ActiveCameraHolder cameraHolder;

   public TrackCheckBox(ActiveCameraHolder cameraHolder)
   {
      super(TRACK);
      setName(TRACK);

      this.cameraHolder = cameraHolder;

      CameraPropertiesHolder camera = cameraHolder.getCameraPropertiesForActiveCamera();
      setSelected(camera.isTracking());
      addActionListener(this);
   }

   @Override
   public void actionPerformed(ActionEvent actionEvent)
   {
      CameraPropertiesHolder camera = cameraHolder.getCameraPropertiesForActiveCamera();
      camera.setTracking(isSelected());

   }

   public void makeCameraConsistent()
   {
      EventDispatchThreadHelper.invokeAndWait(new Runnable()
      {
         @Override
         public void run()
         {
            CameraPropertiesHolder camera = cameraHolder.getCameraPropertiesForActiveCamera();
            camera.setTracking(isSelected());
         }
      });
   }

   public void makeCheckBoxConsistent()
   {
      EventDispatchThreadHelper.invokeAndWait(new Runnable()
      {
         @Override
         public void run()
         {
            CameraPropertiesHolder camera = cameraHolder.getCameraPropertiesForActiveCamera();
            if (camera != null)
               setSelected(camera.isTracking());
         }
      });
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy