<commit_before>package org.helioviewer.jhv.gui.components;

import java.awt.Dimension;
import java.awt.FlowLayout;
//import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
//import java.util.LinkedHashMap;
//import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToolBar;

import org.helioviewer.jhv.Settings;
import org.helioviewer.jhv.base.Colors;
import org.helioviewer.jhv.camera.Interaction;
import org.helioviewer.jhv.display.Display;
import org.helioviewer.jhv.gui.JHVFrame;
import org.helioviewer.jhv.gui.actions.ClearAnnotationsAction;
import org.helioviewer.jhv.gui.actions.ResetCameraAction;
import org.helioviewer.jhv.gui.actions.ResetCameraAxisAction;
import org.helioviewer.jhv.gui.actions.SDOCutOutAction;
import org.helioviewer.jhv.gui.actions.ZoomFOVAnnotationAction;
import org.helioviewer.jhv.gui.actions.ZoomFitAction;
import org.helioviewer.jhv.gui.actions.ZoomInAction;
import org.helioviewer.jhv.gui.actions.ZoomOneToOneAction;
import org.helioviewer.jhv.gui.actions.ZoomOutAction;
import org.helioviewer.jhv.io.SampClient;
import org.helioviewer.jhv.layers.ImageLayers;
import org.helioviewer.jhv.layers.MovieDisplay;

import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideToggleButton;

@SuppressWarnings("serial")
public class ToolBar extends JToolBar {

    private static DisplayMode displayMode = DisplayMode.ICONANDTEXT;

    private enum DisplayMode {
        ICONANDTEXT, ICONONLY
    }

    static class ButtonText {

        private final String icon;
        private final String text;
        final String tip;

        ButtonText(String _icon, String _text, String _tip) {
            icon = _icon;
            text = _text;
            tip = _tip;
        }

        @Override
        public String toString() {
            return displayMode == DisplayMode.ICONONLY ? icon : icon + "<br/>" + text;
        }
    }

    private final ButtonText ANNOTATION = new ButtonText(Buttons.annotate, "Annotation", "Annotation (Press Shift to draw)");
    private final ButtonText AXIS = new ButtonText(Buttons.axis, "Axis", "Axis");
    private final ButtonText CUTOUT = new ButtonText(Buttons.cutOut, "SDO Cut-out", "Send layers to SDO cut-out service");
    private final ButtonText DIFFROTATION = new ButtonText(Buttons.diffRotation, "Differential", "Toggle differential rotation");
    private final ButtonText MULTIVIEW = new ButtonText(Buttons.multiview, "Multiview", "Multiview");
    private final ButtonText OFFDISK = new ButtonText(Buttons.offDisk, "Corona", "Toggle off-disk corona");
    private final ButtonText PAN = new ButtonText(Buttons.pan, "Pan", "Pan");
    private final ButtonText PROJECTION = new ButtonText(Buttons.projection, "Projection", "Projection");
    private final ButtonText RESETCAMERA = new ButtonText(Buttons.resetCamera, "Reset Camera", "Reset camera position to default");
    private final ButtonText RESETCAMERAAXIS = new ButtonText(Buttons.resetCameraAxis, "Reset Camera Axis", "Reset camera axis");
    private final ButtonText ROTATE = new ButtonText(Buttons.rotate, "Rotate", "Rotate");
    private final ButtonText SAMP = new ButtonText(Buttons.samp, "SAMP", "Send SAMP message");
    private final ButtonText TRACK = new ButtonText(Buttons.track, "Track", "Track solar rotation");
    private final ButtonText ZOOMFIT = new ButtonText(Buttons.zoomFit, "Zoom-Fit", "Zoom to fit");
    private final ButtonText ZOOMIN = new ButtonText(Buttons.zoomIn, "Zoom In", "Zoom in");
    private final ButtonText ZOOMONE = new ButtonText(Buttons.zoomOne, "Actual Size", "Zoom to native resolution");
    private final ButtonText ZOOMOUT = new ButtonText(Buttons.zoomOut, "Zoom Out", "Zoom out");

//  private final LinkedHashMap<ButtonText, ActionListener> pluginButtons = new LinkedHashMap<>();

    private static JideButton toolButton(ButtonText text) {
        JideButton b = new JideButton(text.toString());
        b.setToolTipText(text.tip);
        return b;
    }

    private static JideToggleButton toolToggleButton(ButtonText text) {
        JideToggleButton b = new JideToggleButton(text.toString());
        b.setToolTipText(text.tip);
        return b;
    }

    public ToolBar() {
        setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
        setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Colors.lightGray));
        setRollover(true);

        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                maybeShowPopup(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                maybeShowPopup(e);
            }
        });

        try {
            displayMode = DisplayMode.valueOf(Settings.getProperty("display.toolbar").toUpperCase());
        } catch (Exception ignore) {
        }
        setDisplayMode(displayMode);
    }

    private JideToggleButton coronaButton;
    private JideToggleButton diffRotationButton;
    private JideToggleButton multiviewButton;
    private JideToggleButton trackingButton;

    public JideToggleButton getShowCoronaButton() {
        return coronaButton;
    }

    public JideToggleButton getDiffRotationButton() {
        return diffRotationButton;
    }

    public JideToggleButton getMultiviewButton() {
        return multiviewButton;
    }

    public JideToggleButton getTrackingButton() {
        return trackingButton;
    }

    private void createNewToolBar() {
        Interaction.Mode interactionMode = JHVFrame.getInteraction().getMode();
        try {
            interactionMode = Interaction.Mode.valueOf(Settings.getProperty("display.interaction").toUpperCase());
        } catch (Exception ignore) {
        }

        Dimension dim = new Dimension(32, 32);

        // Zoom
        JideButton zoomIn = toolButton(ZOOMIN);
        zoomIn.addActionListener(new ZoomInAction());
        JideButton zoomOut = toolButton(ZOOMOUT);
        zoomOut.addActionListener(new ZoomOutAction());
        JideButton zoomFit = toolButton(ZOOMFIT);
        zoomFit.addActionListener(new ZoomFitAction());
        JideButton zoomOne = toolButton(ZOOMONE);
        zoomOne.addActionListener(new ZoomOneToOneAction());
        JideButton resetCamera = toolButton(RESETCAMERA);
        resetCamera.addActionListener(new ResetCameraAction());
        JideButton resetCameraAxis = toolButton(RESETCAMERAAXIS);
        resetCameraAxis.addActionListener(new ResetCameraAxisAction());

        addButton(zoomIn);
        addButton(zoomOut);
        addButton(zoomFit);
        addButton(zoomOne);
        addButton(resetCamera);
        addButton(resetCameraAxis);

        add(new JToolBar.Separator(dim));

        // Interaction
        ButtonGroup group = new ButtonGroup();

        JideToggleButton pan = toolToggleButton(PAN);
        pan.addActionListener(e -> JHVFrame.getInteraction().setMode(Interaction.Mode.PAN));
        JideToggleButton rotate = toolToggleButton(ROTATE);
        rotate.addActionListener(e -> JHVFrame.getInteraction().setMode(Interaction.Mode.ROTATE));
        JideToggleButton axis = toolToggleButton(AXIS);
        axis.addActionListener(e -> JHVFrame.getInteraction().setMode(Interaction.Mode.AXIS));

        group.add(pan);
        group.add(rotate);
        group.add(axis);
        addButton(pan);
        addButton(rotate);
        addButton(axis);

        switch (interactionMode) {
            case PAN -> pan.setSelected(true);
            case AXIS -> axis.setSelected(true);
            case ROTATE -> rotate.setSelected(true);
        }
        JHVFrame.getInteraction().setMode(interactionMode);

        add(new JToolBar.Separator(dim));

        trackingButton = toolToggleButton(TRACK);
        trackingButton.setSelected(Display.getCamera().getTrackingMode());
        trackingButton.addItemListener(e -> Display.getCamera().setTrackingMode(trackingButton.isSelected()));
        addButton(trackingButton);

        diffRotationButton = toolToggleButton(DIFFROTATION);
        diffRotationButton.setSelected(ImageLayers.getDiffRotationMode());
        diffRotationButton.addItemListener(e -> {
            ImageLayers.setDiffRotationMode(diffRotationButton.isSelected());
            MovieDisplay.display();
        });
        addButton(diffRotationButton);

        coronaButton = toolToggleButton(OFFDISK);
        coronaButton.setSelected(Display.getShowCorona());
        coronaButton.addItemListener(e -> {
            Display.setShowCorona(coronaButton.isSelected());
            MovieDisplay.display();
        });
        addButton(coronaButton);

        multiviewButton = toolToggleButton(MULTIVIEW);
        multiviewButton.setSelected(Display.multiview);
        multiviewButton.addItemListener(e -> {
            Display.multiview = multiviewButton.isSelected();
            ImageLayers.arrangeMultiView(Display.multiview);
        });
        addButton(multiviewButton);

        add(new JToolBar.Separator(dim));

        JideButton projectionButton = toolButton(PROJECTION);
        addButton(projectionButton);

        JPopupMenu projectionPopup = new JPopupMenu();
        ButtonGroup projectionGroup = new ButtonGroup();
        for (Display.ProjectionMode el : Display.ProjectionMode.values()) {
            projectionPopup.add(el.radio);
            projectionGroup.add(el.radio);
        }<commit_msg>Tweak toolbar button order<commit_after>package org.helioviewer.jhv.gui.components;

import java.awt.Dimension;
import java.awt.FlowLayout;
//import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
//import java.util.LinkedHashMap;
//import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToolBar;

import org.helioviewer.jhv.Settings;
import org.helioviewer.jhv.base.Colors;
import org.helioviewer.jhv.camera.Interaction;
import org.helioviewer.jhv.display.Display;
import org.helioviewer.jhv.gui.JHVFrame;
import org.helioviewer.jhv.gui.actions.ClearAnnotationsAction;
import org.helioviewer.jhv.gui.actions.ResetCameraAction;
import org.helioviewer.jhv.gui.actions.ResetCameraAxisAction;
import org.helioviewer.jhv.gui.actions.SDOCutOutAction;
import org.helioviewer.jhv.gui.actions.ZoomFOVAnnotationAction;
import org.helioviewer.jhv.gui.actions.ZoomFitAction;
import org.helioviewer.jhv.gui.actions.ZoomInAction;
import org.helioviewer.jhv.gui.actions.ZoomOneToOneAction;
import org.helioviewer.jhv.gui.actions.ZoomOutAction;
import org.helioviewer.jhv.io.SampClient;
import org.helioviewer.jhv.layers.ImageLayers;
import org.helioviewer.jhv.layers.MovieDisplay;

import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideToggleButton;

@SuppressWarnings("serial")
public class ToolBar extends JToolBar {

    private static DisplayMode displayMode = DisplayMode.ICONANDTEXT;

    private enum DisplayMode {
        ICONANDTEXT, ICONONLY
    }

    static class ButtonText {

        private final String icon;
        private final String text;
        final String tip;

        ButtonText(String _icon, String _text, String _tip) {
            icon = _icon;
            text = _text;
            tip = _tip;
        }

        @Override
        public String toString() {
            return displayMode == DisplayMode.ICONONLY ? icon : icon + "<br/>" + text;
        }
    }

    private final ButtonText ANNOTATION = new ButtonText(Buttons.annotate, "Annotation", "Annotation (Press Shift to draw)");
    private final ButtonText AXIS = new ButtonText(Buttons.axis, "Axis", "Axis");
    private final ButtonText CUTOUT = new ButtonText(Buttons.cutOut, "SDO Cut-out", "Send layers to SDO cut-out service");
    private final ButtonText DIFFROTATION = new ButtonText(Buttons.diffRotation, "Differential", "Toggle differential rotation");
    private final ButtonText MULTIVIEW = new ButtonText(Buttons.multiview, "Multiview", "Multiview");
    private final ButtonText OFFDISK = new ButtonText(Buttons.offDisk, "Corona", "Toggle off-disk corona");
    private final ButtonText PAN = new ButtonText(Buttons.pan, "Pan", "Pan");
    private final ButtonText PROJECTION = new ButtonText(Buttons.projection, "Projection", "Projection");
    private final ButtonText RESETCAMERA = new ButtonText(Buttons.resetCamera, "Reset Camera", "Reset camera position to default");
    private final ButtonText RESETCAMERAAXIS = new ButtonText(Buttons.resetCameraAxis, "Reset Camera Axis", "Reset camera axis");
    private final ButtonText ROTATE = new ButtonText(Buttons.rotate, "Rotate", "Rotate");
    private final ButtonText SAMP = new ButtonText(Buttons.samp, "SAMP", "Send SAMP message");
    private final ButtonText TRACK = new ButtonText(Buttons.track, "Track", "Track solar rotation");
    private final ButtonText ZOOMFIT = new ButtonText(Buttons.zoomFit, "Zoom-Fit", "Zoom to fit");
    private final ButtonText ZOOMIN = new ButtonText(Buttons.zoomIn, "Zoom In", "Zoom in");
    private final ButtonText ZOOMONE = new ButtonText(Buttons.zoomOne, "Actual Size", "Zoom to native resolution");
    private final ButtonText ZOOMOUT = new ButtonText(Buttons.zoomOut, "Zoom Out", "Zoom out");

//  private final LinkedHashMap<ButtonText, ActionListener> pluginButtons = new LinkedHashMap<>();

    private static JideButton toolButton(ButtonText text) {
        JideButton b = new JideButton(text.toString());
        b.setToolTipText(text.tip);
        return b;
    }

    private static JideToggleButton toolToggleButton(ButtonText text) {
        JideToggleButton b = new JideToggleButton(text.toString());
        b.setToolTipText(text.tip);
        return b;
    }

    public ToolBar() {
        setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
        setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Colors.lightGray));
        setRollover(true);

        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                maybeShowPopup(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                maybeShowPopup(e);
            }
        });

        try {
            displayMode = DisplayMode.valueOf(Settings.getProperty("display.toolbar").toUpperCase());
        } catch (Exception ignore) {
        }
        setDisplayMode(displayMode);
    }

    private JideToggleButton coronaButton;
    private JideToggleButton diffRotationButton;
    private JideToggleButton multiviewButton;
    private JideToggleButton trackingButton;

    public JideToggleButton getShowCoronaButton() {
        return coronaButton;
    }

    public JideToggleButton getDiffRotationButton() {
        return diffRotationButton;
    }

    public JideToggleButton getMultiviewButton() {
        return multiviewButton;
    }

    public JideToggleButton getTrackingButton() {
        return trackingButton;
    }

    private void createNewToolBar() {
        Interaction.Mode interactionMode = JHVFrame.getInteraction().getMode();
        try {
            interactionMode = Interaction.Mode.valueOf(Settings.getProperty("display.interaction").toUpperCase());
        } catch (Exception ignore) {
        }

        Dimension dim = new Dimension(32, 32);

        // Zoom
        JideButton zoomIn = toolButton(ZOOMIN);
        zoomIn.addActionListener(new ZoomInAction());
        JideButton zoomOut = toolButton(ZOOMOUT);
        zoomOut.addActionListener(new ZoomOutAction());
        JideButton zoomFit = toolButton(ZOOMFIT);
        zoomFit.addActionListener(new ZoomFitAction());
        JideButton zoomOne = toolButton(ZOOMONE);
        zoomOne.addActionListener(new ZoomOneToOneAction());
        JideButton resetCamera = toolButton(RESETCAMERA);
        resetCamera.addActionListener(new ResetCameraAction());
        JideButton resetCameraAxis = toolButton(RESETCAMERAAXIS);
        resetCameraAxis.addActionListener(new ResetCameraAxisAction());

        addButton(zoomIn);
        addButton(zoomOut);
        addButton(zoomFit);
        addButton(zoomOne);
        add(new JToolBar.Separator(dim));
        addButton(resetCameraAxis);
        addButton(resetCamera);
        add(new JToolBar.Separator(dim));

        // Interaction
        ButtonGroup group = new ButtonGroup();

        JideToggleButton pan = toolToggleButton(PAN);
        pan.addActionListener(e -> JHVFrame.getInteraction().setMode(Interaction.Mode.PAN));
        JideToggleButton rotate = toolToggleButton(ROTATE);
        rotate.addActionListener(e -> JHVFrame.getInteraction().setMode(Interaction.Mode.ROTATE));
        JideToggleButton axis = toolToggleButton(AXIS);
        axis.addActionListener(e -> JHVFrame.getInteraction().setMode(Interaction.Mode.AXIS));

        group.add(pan);
        group.add(rotate);
        group.add(axis);

        addButton(pan);
        addButton(rotate);
        addButton(axis);
        add(new JToolBar.Separator(dim));

        switch (interactionMode) {
            case PAN -> pan.setSelected(true);
            case AXIS -> axis.setSelected(true);
            case ROTATE -> rotate.setSelected(true);
        }
        JHVFrame.getInteraction().setMode(interactionMode);

        trackingButton = toolToggleButton(TRACK);
        trackingButton.setSelected(Display.getCamera().getTrackingMode());
        trackingButton.addItemListener(e -> Display.getCamera().setTrackingMode(trackingButton.isSelected()));

        diffRotationButton = toolToggleButton(DIFFROTATION);
        diffRotationButton.setSelected(ImageLayers.getDiffRotationMode());
        diffRotationButton.addItemListener(e -> {
            ImageLayers.setDiffRotationMode(diffRotationButton.isSelected());
            MovieDisplay.display();
        });

        coronaButton = toolToggleButton(OFFDISK);
        coronaButton.setSelected(Display.getShowCorona());
        coronaButton.addItemListener(e -> {
            Display.setShowCorona(coronaButton.isSelected());
            MovieDisplay.display();
        });

        multiviewButton = toolToggleButton(MULTIVIEW);
        multiviewButton.setSelected(Display.multiview);
        multiviewButton.addItemListener(e -> {
            Display.multiview = multiviewButton.isSelected();
            ImageLayers.arrangeMultiView(Display.multiview);
        });

        addButton(trackingButton);
        addButton(diffRotationButton);
        addButton(coronaButton);
        addButton(multiviewButton);
        add(new JToolBar.Separator(dim));

        JideButton projectionButton = toolButton(PROJECTION);
        addButton(projectionButton);

        JPopupMenu projectionPopup = new JPopupMenu();
        ButtonGroup projectionGroup = new ButtonGroup();
        for (Display.ProjectionMode el : Display.ProjectionMode.values()) {
            projectionPopup.add(el.radio);
            projectionGroup.add(el.radio);
        }
{'fraction_non_alphanumeric': 0.09925662234321013, 'fraction_numerical': 0.0010470107842110773, 'mean_word_length': 3.3733974358974357, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '5390435', 'n_tokens_mistral': 5546, 'n_tokens_neox': 5425, 'n_words': 1065}