<commit_before>package org.myrobotlab.swing;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.myrobotlab.kinematics.Pose;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.service.Runtime;
import org.myrobotlab.service.Servo;
import org.myrobotlab.service.ServoMixer;
import org.myrobotlab.service.SwingGui;
import org.myrobotlab.service.interfaces.ServoControl;
import org.slf4j.Logger;

public class ServoMixerGui extends ServiceGui implements ActionListener, ChangeListener, MouseListener {
  
  public final static Logger log = LoggerFactory.getLogger(ServoMixerGui.class.toString());
  static final long serialVersionUID = 1L;  
  private final String boundServiceName;
  private final ServoMixer servoMixer;
  
  JButton savePoseButton = new JButton("Save Pose");
  JButton loadPoseButton = new JButton("Load Pose");
  JTextField poseName = new JTextField("defaultPose", 16);
  JPanel servoControlPanel = new JPanel();
  JPanel poseControls = new JPanel();
  
  public ServoMixerGui(String boundServiceName, SwingGui myService) {
    super(boundServiceName, myService);
    this.boundServiceName = boundServiceName;
    servoMixer = (ServoMixer) Runtime.getService(boundServiceName);
    display.setLayout(new BorderLayout());
    createServoGuiLayout();
  }
  
  private void createServoGuiLayout() {
    
    servoControlPanel.setLayout(new FlowLayout());
    List<ServoControl> servos = servoMixer.listAllServos();
    for (ServoControl sc : servos) {
      // TODO: create a better single servo control panel here.
      
      JPanel servoMiniControl = new JPanel();
      servoMiniControl.setLayout(new BoxLayout(servoMiniControl, BoxLayout.Y_AXIS));
      JLabel servoLabel = new JLabel(sc.getName());
      JSlider servoSlider = new JSlider(JSlider.VERTICAL, 0, 180, (int)(sc.getPos()));
      servoSlider.setName(sc.getName());
      servoSlider.addChangeListener(this);

      servoMiniControl.add(servoLabel);
      servoMiniControl.add(servoSlider);
      
      servoControlPanel.add(servoMiniControl);
      
    }
    // add a control bar to the bottom
    
    poseControls.setLayout(new FlowLayout());
    JLabel saveLabel = new JLabel("Save Pose");
   

    // 
    poseControls.add(saveLabel);
    poseControls.add(poseName);
    poseControls.add(savePoseButton);
    poseControls.add(loadPoseButton);
    
    // add callbacks
    savePoseButton.addActionListener(this);
    loadPoseButton.addActionListener(this);
    
    display.add(servoControlPanel, BorderLayout.PAGE_START);
    display.add(poseControls, BorderLayout.PAGE_END);
  }
  
  public void refreshPanel() {<commit_msg>adding vertical labels for the servo controls to save space on the screen.<commit_after>package org.myrobotlab.swing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.myrobotlab.kinematics.Pose;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.service.Runtime;
import org.myrobotlab.service.Servo;
import org.myrobotlab.service.ServoMixer;
import org.myrobotlab.service.SwingGui;
import org.myrobotlab.service.interfaces.ServoControl;
import org.slf4j.Logger;

import com.jidesoft.swing.JideLabel;

public class ServoMixerGui extends ServiceGui implements ActionListener, ChangeListener, MouseListener {
  
  public final static Logger log = LoggerFactory.getLogger(ServoMixerGui.class.toString());
  static final long serialVersionUID = 1L;  
  private final String boundServiceName;
  private final ServoMixer servoMixer;
  
  JButton savePoseButton = new JButton("Save Pose");
  JButton loadPoseButton = new JButton("Load Pose");
  JTextField poseName = new JTextField("defaultPose", 16);
  JPanel servoControlPanel = new JPanel();
  JPanel poseControls = new JPanel();
  
  public ServoMixerGui(String boundServiceName, SwingGui myService) {
    super(boundServiceName, myService);
    this.boundServiceName = boundServiceName;
    servoMixer = (ServoMixer) Runtime.getService(boundServiceName);
    display.setLayout(new BorderLayout());
    createServoGuiLayout();
  }
  
  private void createServoGuiLayout() {
    
    servoControlPanel.setLayout(new FlowLayout());
    List<ServoControl> servos = servoMixer.listAllServos();
    for (ServoControl sc : servos) {
      // TODO: create a better single servo control panel here.
      
      JPanel servoMiniControl = new JPanel();
      // servoMiniControl.setLayout(new BoxLayout(servoMiniControl, BoxLayout.Y_AXIS));
      servoMiniControl.setLayout(new BorderLayout());
      // TODO: make this lable render vertically
      JideLabel servoLabel = new JideLabel(sc.getName());
      servoLabel.setOrientation(JideLabel.VERTICAL);
      JSlider servoSlider = new JSlider(JSlider.VERTICAL, 0, 180, (int)(sc.getPos()));
      servoSlider.setName(sc.getName());
      servoSlider.addChangeListener(this);
      servoMiniControl.add(servoSlider, BorderLayout.PAGE_START);
      servoMiniControl.add(servoLabel, BorderLayout.PAGE_END);
      
      servoControlPanel.add(servoMiniControl);
      
    }
    // add a control bar to the bottom
    
    poseControls.setLayout(new FlowLayout());
    JLabel saveLabel = new JLabel("Save Pose");
   

    // 
    poseControls.add(saveLabel);
    poseControls.add(poseName);
    poseControls.add(savePoseButton);
    poseControls.add(loadPoseButton);
    
    // add callbacks
    savePoseButton.addActionListener(this);
    loadPoseButton.addActionListener(this);
    
    display.add(servoControlPanel, BorderLayout.PAGE_START);
    display.add(poseControls, BorderLayout.PAGE_END);
  }
  
  public void refreshPanel() {
{'fraction_non_alphanumeric': 0.09712009803921569, 'fraction_numerical': 0.0024509803921568627, 'mean_word_length': 4.491169049621531, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '822597', 'n_tokens_mistral': 2041, 'n_tokens_neox': 2011, 'n_words': 405}