<commit_before>package com.map;

import static com.map.WaypointList.*;

import com.map.command.*;

import com.Context;
import com.Dashboard;
import com.graph.Graph;
import com.map.coordinateListener;
import com.map.Dot;
import com.serial.*;
import com.ui.DataWindow;
import com.ui.LogViewer;
import com.ui.ninePatch.NinePatchPanel;
import com.ui.SystemConfigWindow;
import com.ui.Theme;
import com.xml;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.logging.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.xml.stream.XMLStreamException;

class WaypointPanel extends NinePatchPanel {
    protected static final int MOVE_STEP = 32;
    protected static final int BDR_SIZE = 25;
    protected static final String NO_WAYPOINT_MSG = "N / A";
    private Context context;
    private MapPanel map;
    private WaypointList waypoints;
    private javax.swing.Timer zoomTimer;
    TelemField latitude;
    TelemField longitude;
    TelemField altitude;
    JLabel waypointIndexDisplay;

    private class TelemField extends JTextField{
        float lastSetValue = Float.NaN;
        @Override
        public void setText(String newString){
            super.setText(newString);
            lastSetValue = Float.NaN;
        }
        void update(float newValue){
            /**
             * editable float fields will get their cursor reset unless
             * updates from possible waypointlistener events only change
             * the text when the dot moves
             */
            if(newValue != lastSetValue){
                setText(Float.toString(newValue));
                lastSetValue = newValue;
            }
        }
    }

    public WaypointPanel(Context cxt, MapPanel mapPanel) {
        super(cxt.theme.panelPatch);
        map = mapPanel;
        context = cxt;
        makeActions();
        waypoints = context.getWaypointList();
        setOpaque(false);
        LayoutManager layout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
        setLayout(layout);
        setBorder(BorderFactory.createEmptyBorder(BDR_SIZE,BDR_SIZE,BDR_SIZE,BDR_SIZE));
        buildPanel();
        addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
                //do nothing here to prevent clicks from falling through
                //to the map panel in the background
            }
        });

        waypoints.addListener(new WaypointListener() {
            @Override 
            public void unusedEvent() {
            	updateDisplay();
            }
        });
        
        updateDisplay();
    }

    private void makeActions() {
        nextTileServer = new AbstractAction() {
            java.util.List<String> serverLabels
                = new LinkedList<String>(map.tileServerNames());
            
            { 
            	updateLabel();
            }
            
            private void updateLabel() {
                putValue(Action.NAME, serverLabels.get(0));
            }
            
            public void actionPerformed(ActionEvent e) {
                // cycle current server to the back of the list
                String server = serverLabels.get(0);
                serverLabels.remove(0);
                serverLabels.add(server);
                // switch the map's server
                map.switchToServer(server);

                updateLabel();
                map.repaint();
            }
        };
    }

    /**
     * Update the selected dot text field displays
     */
    public void updateDisplay() {
        int selectedWaypoint = waypoints.getSelected();
        ExtendedWaypoint w = waypoints.get(selectedWaypoint);
        Dot dot = w.dot();

        String indexField = (selectedWaypoint+1) + " / " + waypoints.size();
        // special dots that don't represent waypoints show names instead of index
        switch(w.type()){
            case ROVER: indexField = "Robot"; break;
            case HOME: indexField = "Home "; break;
        }
        waypointIndexDisplay.setText(indexField);

        latitude.update(  (float)dot.getLatitude() );
        longitude.update( (float)dot.getLongitude() );
        altitude.update(  (float)fixedToDouble(dot.getAltitude()) );

        latitude.setForeground(Color.BLACK);
        longitude.setForeground(Color.BLACK);
        altitude.setForeground(Color.BLACK);
        if(selectedWaypoint < 0){
            latitude.setEditable(false);
            longitude.setEditable(false);
            altitude.setEditable(false);
        } else {
            latitude.setEditable(true);
            longitude.setEditable(true);
            altitude.setEditable(true);
        }

    }

    private void buildPanel() {
        final Theme theme = context.theme;
        final Dimension space = new Dimension(0,5);
        final Dimension buttonSize = new Dimension(140, 25);

        //make all the buttons
        JButton tileButton 	= theme.makeButton(nextTileServer);
        JButton dataPanel 	= theme.makeButton(openDataPanel);
        JButton graphButton = theme.makeButton(buildGraph);
        JButton reTarget 	= theme.makeButton(reTargetRover);
        JButton looping 	= theme.makeButton(toggleLooping);
        JButton config      = theme.makeButton(openConfigWindow);
        JButton logPanelButton = theme.makeButton(logPanelAction);
        JButton clearWaypoints = theme.makeButton(clearWaypointsAction);
        JButton zoomInButton = theme.makeButton(zoomInAction);
        		zoomInButton.addMouseListener(zoomInMouseAdapter);
        JButton zoomOutButton = theme.makeButton(zoomOutAction);
        		zoomOutButton.addMouseListener(zoomOutMouseAdapter);
        JButton zoomFullButton = theme.makeButton(zoomFullAction);


        JComponent[] format = new JComponent[] {
            tileButton, dataPanel, graphButton,
            reTarget, looping, config, logPanelButton, clearWaypoints
        };
        for(JComponent jc : format) {
            jc.setAlignmentX(Component.CENTER_ALIGNMENT);
            jc.setMaximumSize(buttonSize);
        }
        
        //make zoom button panel
        JPanel zoom = new JPanel(new FlowLayout());
        zoom.setOpaque(false);
        zoom.add(zoomInButton);
        zoom.add(zoomFullButton);
        zoom.add(zoomOutButton);
        
        //add selectedWaypoint flow layout
        JPanel selector = new JPanel(new BorderLayout());
        selector.setOpaque(false);
        waypointIndexDisplay = new JLabel(NO_WAYPOINT_MSG);
        waypointIndexDisplay.setHorizontalAlignment(SwingConstants.CENTER);
        selector.add(theme.makeButton(previousWaypoint), BorderLayout.LINE_START);
        selector.add(waypointIndexDisplay, BorderLayout.CENTER);
        selector.add(theme.makeButton(nextWaypoint), BorderLayout.LINE_END);

        //Make edit boxes
        class EditBoxSpec {
            public final JTextField ref;
            public final String label;
            public EditBoxSpec(JTextField ref, String label) {
                this.ref = ref;
                this.label = label;
            }
        }
        ArrayList<EditBoxSpec> editorBoxes = new ArrayList<EditBoxSpec>();
        latitude  = new TelemField();
        longitude = new TelemField();
        altitude  = new TelemField();
        editorBoxes.add(new EditBoxSpec(latitude , "Lat: "));
        editorBoxes.add(new EditBoxSpec(longitude, "Lng: "));
        editorBoxes.add(new EditBoxSpec(altitude , context.getResource("waypointExtra")+" "));
        ArrayList<JPanel> editorPanels = new ArrayList<JPanel>();
        for(EditBoxSpec box : editorBoxes) {
            //construct panel
            JPanel panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
            panel.setOpaque(false);
            //add label box
            JLabel label = new JLabel(box.label);
            label.setFont(context.theme.text);
            panel.add(label);
            //add textField
            JTextField tf = box.ref;
            tf.setBorder(BorderFactory.createLineBorder(Color.gray));
            panel.add(tf);
            //Setup text field listener
            coordinateListener listener = new coordinateListener(tf, this);
            tf.getDocument().addDocumentListener(listener);
            tf.addActionListener(listener);
            //add to layout
            editorPanels.add(panel);
        }

        //rows, cols, hgap, vgap
        JPanel waypointOptions = new JPanel(new GridLayout(3,2,5,5));
        waypointOptions.setOpaque(false);
        waypointOptions.add(theme.makeButton(newWaypoint));
        waypointOptions.add(theme.makeButton(interpretLocationAction));
      
        waypointOptions.add(theme.makeButton(undoCommandAction));
        waypointOptions.add(theme.makeButton(redoCommandAction));
        
        waypointOptions.add(theme.makeButton(saveWaypoints));
        waypointOptions.add(theme.makeButton(loadWaypoints));
<commit_msg>Update button construction for waypoint options<commit_after>package com.map;

import static com.map.WaypointList.*;

import com.map.command.*;

import com.Context;
import com.Dashboard;
import com.graph.Graph;
import com.map.coordinateListener;
import com.map.Dot;
import com.serial.*;
import com.ui.DataWindow;
import com.ui.LogViewer;
import com.ui.ninePatch.NinePatchPanel;
import com.ui.SystemConfigWindow;
import com.ui.Theme;
import com.xml;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.logging.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.xml.stream.XMLStreamException;

class WaypointPanel extends NinePatchPanel {
    protected static final int MOVE_STEP = 32;
    protected static final int BDR_SIZE = 25;
    protected static final String NO_WAYPOINT_MSG = "N / A";
    private Context context;
    private MapPanel map;
    private WaypointList waypoints;
    private javax.swing.Timer zoomTimer;
    TelemField latitude;
    TelemField longitude;
    TelemField altitude;
    JLabel waypointIndexDisplay;

    private class TelemField extends JTextField{
        float lastSetValue = Float.NaN;
        @Override
        public void setText(String newString){
            super.setText(newString);
            lastSetValue = Float.NaN;
        }
        void update(float newValue){
            /**
             * editable float fields will get their cursor reset unless
             * updates from possible waypointlistener events only change
             * the text when the dot moves
             */
            if(newValue != lastSetValue){
                setText(Float.toString(newValue));
                lastSetValue = newValue;
            }
        }
    }

    public WaypointPanel(Context cxt, MapPanel mapPanel) {
        super(cxt.theme.panelPatch);
        map = mapPanel;
        context = cxt;
        makeActions();
        waypoints = context.getWaypointList();
        setOpaque(false);
        LayoutManager layout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
        setLayout(layout);
        setBorder(BorderFactory.createEmptyBorder(BDR_SIZE,BDR_SIZE,BDR_SIZE,BDR_SIZE));
        buildPanel();
        addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
                //do nothing here to prevent clicks from falling through
                //to the map panel in the background
            }
        });

        waypoints.addListener(new WaypointListener() {
            @Override 
            public void unusedEvent() {
            	updateDisplay();
            }
        });
        
        updateDisplay();
    }

    private void makeActions() {
        nextTileServer = new AbstractAction() {
            java.util.List<String> serverLabels
                = new LinkedList<String>(map.tileServerNames());
            
            { 
            	updateLabel();
            }
            
            private void updateLabel() {
                putValue(Action.NAME, serverLabels.get(0));
            }
            
            public void actionPerformed(ActionEvent e) {
                // cycle current server to the back of the list
                String server = serverLabels.get(0);
                serverLabels.remove(0);
                serverLabels.add(server);
                // switch the map's server
                map.switchToServer(server);

                updateLabel();
                map.repaint();
            }
        };
    }

    /**
     * Update the selected dot text field displays
     */
    public void updateDisplay() {
        int selectedWaypoint = waypoints.getSelected();
        ExtendedWaypoint w = waypoints.get(selectedWaypoint);
        Dot dot = w.dot();

        String indexField = (selectedWaypoint+1) + " / " + waypoints.size();
        // special dots that don't represent waypoints show names instead of index
        switch(w.type()){
            case ROVER: indexField = "Robot"; break;
            case HOME: indexField = "Home "; break;
        }
        waypointIndexDisplay.setText(indexField);

        latitude.update(  (float)dot.getLatitude() );
        longitude.update( (float)dot.getLongitude() );
        altitude.update(  (float)fixedToDouble(dot.getAltitude()) );

        latitude.setForeground(Color.BLACK);
        longitude.setForeground(Color.BLACK);
        altitude.setForeground(Color.BLACK);
        if(selectedWaypoint < 0){
            latitude.setEditable(false);
            longitude.setEditable(false);
            altitude.setEditable(false);
        } else {
            latitude.setEditable(true);
            longitude.setEditable(true);
            altitude.setEditable(true);
        }

    }

    private void buildPanel() {
        final Theme theme = context.theme;
        final Dimension space = new Dimension(0,5);
        final Dimension buttonSize = new Dimension(140, 25);

        //Make all buttons
        JButton tileButton 	= theme.makeButton(nextTileServer);
        JButton dataPanel 	= theme.makeButton(openDataPanel);
        JButton graphButton = theme.makeButton(buildGraph);
        JButton reTarget 	= theme.makeButton(reTargetRover);
        JButton looping 	= theme.makeButton(toggleLooping);
        JButton config      = theme.makeButton(openConfigWindow);
        JButton logPanelButton = theme.makeButton(logPanelAction);
        
        JButton zoomInButton = theme.makeButton(zoomInAction);
        		zoomInButton.addMouseListener(zoomInMouseAdapter);
        JButton zoomOutButton = theme.makeButton(zoomOutAction);
        		zoomOutButton.addMouseListener(zoomOutMouseAdapter);
        JButton zoomFullButton = theme.makeButton(zoomFullAction);

        //Waypoint Options
        JButton clearWaypoints = theme.makeButton(clearWaypointsAction);
        JButton newButton = theme.makeButton(newWaypoint);
        JButton enterButton = theme.makeButton(interpretLocationAction);
        JButton undoButton = theme.makeButton(undoCommandAction);
        JButton redoButton = theme.makeButton(redoCommandAction);
        JButton saveButton = theme.makeButton(saveWaypoints);
        JButton loadButton = theme.makeButton(loadWaypoints);
        
        JComponent[] format = new JComponent[] {
            tileButton, dataPanel, graphButton,
            reTarget, looping, config, logPanelButton, clearWaypoints
        };
        for(JComponent jc : format) {
            jc.setAlignmentX(Component.CENTER_ALIGNMENT);
            jc.setMaximumSize(buttonSize);
        }
        
        //make zoom button panel
        JPanel zoom = new JPanel(new FlowLayout());
        zoom.setOpaque(false);
        zoom.add(zoomInButton);
        zoom.add(zoomFullButton);
        zoom.add(zoomOutButton);
        
        //add selectedWaypoint flow layout
        JPanel selector = new JPanel(new BorderLayout());
        selector.setOpaque(false);
        waypointIndexDisplay = new JLabel(NO_WAYPOINT_MSG);
        waypointIndexDisplay.setHorizontalAlignment(SwingConstants.CENTER);
        selector.add(theme.makeButton(previousWaypoint), BorderLayout.LINE_START);
        selector.add(waypointIndexDisplay, BorderLayout.CENTER);
        selector.add(theme.makeButton(nextWaypoint), BorderLayout.LINE_END);

        //Make edit boxes
        class EditBoxSpec {
            public final JTextField ref;
            public final String label;
            public EditBoxSpec(JTextField ref, String label) {
                this.ref = ref;
                this.label = label;
            }
        }
        
        ArrayList<EditBoxSpec> editorBoxes = new ArrayList<EditBoxSpec>();
        latitude  = new TelemField();
        longitude = new TelemField();
        altitude  = new TelemField();
        editorBoxes.add(new EditBoxSpec(latitude , "Lat: "));
        editorBoxes.add(new EditBoxSpec(longitude, "Lng: "));
        editorBoxes.add(new EditBoxSpec(altitude , context.getResource("waypointExtra")+" "));
        ArrayList<JPanel> editorPanels = new ArrayList<JPanel>();
        for(EditBoxSpec box : editorBoxes) {
            //construct panel
            JPanel panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
            panel.setOpaque(false);
            //add label box
            JLabel label = new JLabel(box.label);
            label.setFont(context.theme.text);
            panel.add(label);
            //add textField
            JTextField tf = box.ref;
            tf.setBorder(BorderFactory.createLineBorder(Color.gray));
            panel.add(tf);
            //Setup text field listener
            coordinateListener listener = new coordinateListener(tf, this);
            tf.getDocument().addDocumentListener(listener);
            tf.addActionListener(listener);
            //add to layout
            editorPanels.add(panel);
        }

        JPanel waypointOptions = new JPanel(new GridLayout(3,2,5,5));
        waypointOptions.setOpaque(false);
        waypointOptions.add(newButton);
        waypointOptions.add(enterButton);      
        waypointOptions.add(undoButton);
        waypointOptions.add(redoButton);
        waypointOptions.add(saveButton);
        waypointOptions.add(loadButton);

{'fraction_non_alphanumeric': 0.09248648648648648, 'fraction_numerical': 0.00227027027027027, 'mean_word_length': 2.2727755174243764, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '785038', 'n_tokens_mistral': 5019, 'n_tokens_neox': 4861, 'n_words': 1048}