<commit_before>

/*
 * HyperstackControls.java
 *
 * Created on Jul 15, 2010, 2:54:37 PM
 */
package org.micromanager.imageDisplay;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.swtdesigner.SwingResourceManager;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.ParseException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import org.json.JSONException;
import org.json.JSONObject;

import org.micromanager.internalinterfaces.DisplayControls;
import org.micromanager.MMStudioMainFrame;
import org.micromanager.utils.MDUtils;
import org.micromanager.utils.NumberUtils;
import org.micromanager.utils.ReportingUtils;


public class HyperstackControls extends DisplayControls {

   private final VirtualAcquisitionDisplay display_;
   private EventBus bus_;

   // Controls common to both control sets
   private ScrollerPanel scrollerPanel_;
   private JLabel pixelInfoLabel_;
   private JButton showFolderButton_;
   private JButton saveButton_;
   private JLabel statusLineLabel_;

   // Standard control set
   private JLabel fpsLabel_;
   private javax.swing.JTextField fpsField_;
   private JButton abortButton_;
   private javax.swing.JToggleButton pauseAndResumeToggleButton_;

   // Snap/live control set
   private JButton snapButton_;
   private JButton snapToAlbumButton_;
   private JButton liveButton_;

   /**
    * @param shouldUseLiveButtons - indicates if we should use the buttons for 
    *        the "Snap/Live" window or the buttons for normal displays.
    */
   public HyperstackControls(VirtualAcquisitionDisplay display, 
         EventBus bus, boolean shouldUseLiveButtons) {
      super(new FlowLayout(FlowLayout.LEADING));
      bus_ = bus;
      initComponents(shouldUseLiveButtons);
      display_ = display;
      bus_.register(this);
   }

   private void initComponents(final boolean shouldUseLiveButtons) {
      // This layout minimizes space between components.
      JPanel subPanel = new JPanel(new MigLayout("", "0[]", "0[]0[]0[]0"));
      subPanel.setPreferredSize(new Dimension(512, 100));

      pixelInfoLabel_ = new JLabel("                                     ");
      pixelInfoLabel_.setFont(new java.awt.Font("Lucida Grande", 0, 10));
      subPanel.add(pixelInfoLabel_, "span, wrap");

      scrollerPanel_ = new ScrollerPanel(
               bus_, new String[]{"channel", "position", "time", "z"}, 
               new Integer[]{1, 1, 1, 1});
      subPanel.add(scrollerPanel_, "span, growx, wrap 0px");

      showFolderButton_ = new JButton();
      saveButton_ = new JButton();
      statusLineLabel_ = new JLabel();

      subPanel.add(showFolderButton_);
      subPanel.add(saveButton_);

      showFolderButton_.setBackground(new java.awt.Color(255, 255, 255));
      showFolderButton_.setIcon(
            new javax.swing.ImageIcon(
               getClass().getResource("/org/micromanager/icons/folder.png")));
      showFolderButton_.setToolTipText("Show containing folder");
      showFolderButton_.setFocusable(false);
      showFolderButton_.setHorizontalTextPosition(
            javax.swing.SwingConstants.CENTER);
      showFolderButton_.setMaximumSize(new java.awt.Dimension(30, 28));
      showFolderButton_.setMinimumSize(new java.awt.Dimension(30, 28));
      showFolderButton_.setPreferredSize(new java.awt.Dimension(30, 28));
      showFolderButton_.setVerticalTextPosition(
            javax.swing.SwingConstants.BOTTOM);
      showFolderButton_.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            showFolderButtonActionPerformed(evt);
         }
      });

      saveButton_.setBackground(new java.awt.Color(255, 255, 255));
      saveButton_.setIcon(
            new javax.swing.ImageIcon(
               getClass().getResource("/org/micromanager/icons/disk.png")));
      saveButton_.setToolTipText("Save as...");
      saveButton_.setFocusable(false);
      saveButton_.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      saveButton_.setMaximumSize(new java.awt.Dimension(30, 28));
      saveButton_.setMinimumSize(new java.awt.Dimension(30, 28));
      saveButton_.setPreferredSize(new java.awt.Dimension(30, 28));
      saveButton_.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      saveButton_.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            saveButtonActionPerformed(evt, shouldUseLiveButtons);
         }
      });

      if (shouldUseLiveButtons) {
         makeSnapLiveButtons(subPanel);
      }
      else {
         makeStandardButtons(subPanel);
      }
      
      statusLineLabel_.setFont(new java.awt.Font("Lucida Grande", 0, 10));
      statusLineLabel_.setHorizontalTextPosition(
            javax.swing.SwingConstants.LEFT);
      subPanel.add(statusLineLabel_);

      add(subPanel);
   }

   /**
    * Generate the controls used for the "Snap/Live" window.
    */
   private void makeSnapLiveButtons(JPanel subPanel) {
      snapButton_ = new JButton();
      snapButton_.setFocusable(false);
      snapButton_.setIconTextGap(6);
      snapButton_.setText("Snap");
      snapButton_.setMinimumSize(new Dimension(99,28));
      snapButton_.setPreferredSize(new Dimension(99,28));
      snapButton_.setMaximumSize(new Dimension(99,28));
      snapButton_.setIcon(SwingResourceManager.getIcon(
            MMStudioMainFrame.class, "/org/micromanager/icons/camera.png"));
      snapButton_.setFont(new Font("Arial", Font.PLAIN, 10));
      snapButton_.setToolTipText("Snap single image");
      snapButton_.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            MMStudioMainFrame.getInstance().doSnap();
         }

      });

      liveButton_ = new JButton();
      liveButton_.setIcon(SwingResourceManager.getIcon(
            MMStudioMainFrame.class,
            "/org/micromanager/icons/camera_go.png"));
      liveButton_.setIconTextGap(6);
      liveButton_.setText("Live");
      liveButton_.setMinimumSize(new Dimension(99,28));
      liveButton_.setPreferredSize(new Dimension(99,28));
      liveButton_.setMaximumSize(new Dimension(99,28));
      liveButton_.setFocusable(false);
      liveButton_.setToolTipText("Continuous live view");
      liveButton_.setFont(new Font("Arial", Font.PLAIN, 10));
      liveButton_.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            liveButtonAction();
         }
      });
    
      snapToAlbumButton_ = new JButton("Album");
      snapToAlbumButton_.setIcon(SwingResourceManager.getIcon(MMStudioMainFrame.class,
              "/org/micromanager/icons/camera_plus_arrow.png"));
      snapToAlbumButton_.setIconTextGap(6);
      snapToAlbumButton_.setToolTipText("Add current image to album");
      snapToAlbumButton_.setFocusable(false);
      snapToAlbumButton_.setMaximumSize(new Dimension(90, 28));
      snapToAlbumButton_.setMinimumSize(new Dimension(90, 28));
      snapToAlbumButton_.setPreferredSize(new Dimension(90, 28));
      snapToAlbumButton_.setFont(new Font("Arial", Font.PLAIN, 10));
      snapToAlbumButton_.addActionListener(new ActionListener() {<commit_msg>Revert "[imageRefactor] Changed the "snap to album" icon in the snap/live view."<commit_after>

/*
 * HyperstackControls.java
 *
 * Created on Jul 15, 2010, 2:54:37 PM
 */
package org.micromanager.imageDisplay;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.swtdesigner.SwingResourceManager;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.ParseException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import org.json.JSONException;
import org.json.JSONObject;

import org.micromanager.internalinterfaces.DisplayControls;
import org.micromanager.MMStudioMainFrame;
import org.micromanager.utils.MDUtils;
import org.micromanager.utils.NumberUtils;
import org.micromanager.utils.ReportingUtils;


public class HyperstackControls extends DisplayControls {

   private final VirtualAcquisitionDisplay display_;
   private EventBus bus_;

   // Controls common to both control sets
   private ScrollerPanel scrollerPanel_;
   private JLabel pixelInfoLabel_;
   private JButton showFolderButton_;
   private JButton saveButton_;
   private JLabel statusLineLabel_;

   // Standard control set
   private JLabel fpsLabel_;
   private javax.swing.JTextField fpsField_;
   private JButton abortButton_;
   private javax.swing.JToggleButton pauseAndResumeToggleButton_;

   // Snap/live control set
   private JButton snapButton_;
   private JButton snapToAlbumButton_;
   private JButton liveButton_;

   /**
    * @param shouldUseLiveButtons - indicates if we should use the buttons for 
    *        the "Snap/Live" window or the buttons for normal displays.
    */
   public HyperstackControls(VirtualAcquisitionDisplay display, 
         EventBus bus, boolean shouldUseLiveButtons) {
      super(new FlowLayout(FlowLayout.LEADING));
      bus_ = bus;
      initComponents(shouldUseLiveButtons);
      display_ = display;
      bus_.register(this);
   }

   private void initComponents(final boolean shouldUseLiveButtons) {
      // This layout minimizes space between components.
      JPanel subPanel = new JPanel(new MigLayout("", "0[]", "0[]0[]0[]0"));
      subPanel.setPreferredSize(new Dimension(512, 100));

      pixelInfoLabel_ = new JLabel("                                     ");
      pixelInfoLabel_.setFont(new java.awt.Font("Lucida Grande", 0, 10));
      subPanel.add(pixelInfoLabel_, "span, wrap");

      scrollerPanel_ = new ScrollerPanel(
               bus_, new String[]{"channel", "position", "time", "z"}, 
               new Integer[]{1, 1, 1, 1});
      subPanel.add(scrollerPanel_, "span, growx, wrap 0px");

      showFolderButton_ = new JButton();
      saveButton_ = new JButton();
      statusLineLabel_ = new JLabel();

      subPanel.add(showFolderButton_);
      subPanel.add(saveButton_);

      showFolderButton_.setBackground(new java.awt.Color(255, 255, 255));
      showFolderButton_.setIcon(
            new javax.swing.ImageIcon(
               getClass().getResource("/org/micromanager/icons/folder.png")));
      showFolderButton_.setToolTipText("Show containing folder");
      showFolderButton_.setFocusable(false);
      showFolderButton_.setHorizontalTextPosition(
            javax.swing.SwingConstants.CENTER);
      showFolderButton_.setMaximumSize(new java.awt.Dimension(30, 28));
      showFolderButton_.setMinimumSize(new java.awt.Dimension(30, 28));
      showFolderButton_.setPreferredSize(new java.awt.Dimension(30, 28));
      showFolderButton_.setVerticalTextPosition(
            javax.swing.SwingConstants.BOTTOM);
      showFolderButton_.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            showFolderButtonActionPerformed(evt);
         }
      });

      saveButton_.setBackground(new java.awt.Color(255, 255, 255));
      saveButton_.setIcon(
            new javax.swing.ImageIcon(
               getClass().getResource("/org/micromanager/icons/disk.png")));
      saveButton_.setToolTipText("Save as...");
      saveButton_.setFocusable(false);
      saveButton_.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      saveButton_.setMaximumSize(new java.awt.Dimension(30, 28));
      saveButton_.setMinimumSize(new java.awt.Dimension(30, 28));
      saveButton_.setPreferredSize(new java.awt.Dimension(30, 28));
      saveButton_.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      saveButton_.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            saveButtonActionPerformed(evt, shouldUseLiveButtons);
         }
      });

      if (shouldUseLiveButtons) {
         makeSnapLiveButtons(subPanel);
      }
      else {
         makeStandardButtons(subPanel);
      }
      
      statusLineLabel_.setFont(new java.awt.Font("Lucida Grande", 0, 10));
      statusLineLabel_.setHorizontalTextPosition(
            javax.swing.SwingConstants.LEFT);
      subPanel.add(statusLineLabel_);

      add(subPanel);
   }

   /**
    * Generate the controls used for the "Snap/Live" window.
    */
   private void makeSnapLiveButtons(JPanel subPanel) {
      snapButton_ = new JButton();
      snapButton_.setFocusable(false);
      snapButton_.setIconTextGap(6);
      snapButton_.setText("Snap");
      snapButton_.setMinimumSize(new Dimension(99,28));
      snapButton_.setPreferredSize(new Dimension(99,28));
      snapButton_.setMaximumSize(new Dimension(99,28));
      snapButton_.setIcon(SwingResourceManager.getIcon(
            MMStudioMainFrame.class, "/org/micromanager/icons/camera.png"));
      snapButton_.setFont(new Font("Arial", Font.PLAIN, 10));
      snapButton_.setToolTipText("Snap single image");
      snapButton_.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            MMStudioMainFrame.getInstance().doSnap();
         }

      });

      liveButton_ = new JButton();
      liveButton_.setIcon(SwingResourceManager.getIcon(
            MMStudioMainFrame.class,
            "/org/micromanager/icons/camera_go.png"));
      liveButton_.setIconTextGap(6);
      liveButton_.setText("Live");
      liveButton_.setMinimumSize(new Dimension(99,28));
      liveButton_.setPreferredSize(new Dimension(99,28));
      liveButton_.setMaximumSize(new Dimension(99,28));
      liveButton_.setFocusable(false);
      liveButton_.setToolTipText("Continuous live view");
      liveButton_.setFont(new Font("Arial", Font.PLAIN, 10));
      liveButton_.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            liveButtonAction();
         }
      });
    
      snapToAlbumButton_ = new JButton("Album");
      snapToAlbumButton_.setIcon(SwingResourceManager.getIcon(MMStudioMainFrame.class,
              "/org/micromanager/icons/arrow_right.png"));
      snapToAlbumButton_.setIconTextGap(6);
      snapToAlbumButton_.setToolTipText("Add current image to album");
      snapToAlbumButton_.setFocusable(false);
      snapToAlbumButton_.setMaximumSize(new Dimension(90, 28));
      snapToAlbumButton_.setMinimumSize(new Dimension(90, 28));
      snapToAlbumButton_.setPreferredSize(new Dimension(90, 28));
      snapToAlbumButton_.setFont(new Font("Arial", Font.PLAIN, 10));
      snapToAlbumButton_.addActionListener(new ActionListener() {
{'fraction_non_alphanumeric': 0.10412715023873373, 'fraction_numerical': 0.015697560337497547, 'mean_word_length': 3.510324483775811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4044545', 'n_tokens_mistral': 4596, 'n_tokens_neox': 4341, 'n_words': 787}