<commit_before>package com.drone.ui;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.drone.Drone;
import com.drone.GaugeConfiguration;
import com.drone.navdata.DroneNavData;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class AddGaugeDialog extends Window {
    private static final long serialVersionUID = -2633336549420617084L;

    private GaugePanel panel;
    private Drone drone;

    private ComboBox gaugeSelector;

    public AddGaugeDialog(GaugePanel panel, Drone drone) {
        super("Add gauge");
        this.panel = panel;
        setWidth(200, Unit.PIXELS);
        setResizable(false);
        setClosable(true);
        center();

        this.drone = drone;

        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);

        List<GaugeConfiguration> availableGauges = determineAvailableGauges();

        gaugeSelector = new ComboBox("Gauges");
        gaugeSelector.setNullSelectionAllowed(false);
        layout.addComponent(gaugeSelector);

        for (GaugeConfiguration configuration : availableGauges) {
            gaugeSelector.addItem(configuration);
            gaugeSelector.setItemCaption(configuration, configuration
                    .property().getName());
        }

        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.setSpacing(true);

        Button add = new Button(FontAwesome.PLUS);
        Button close = new Button(FontAwesome.MINUS);

        add.addClickListener(e -> onAddClicked());
        close.addClickListener(e -> close());

        buttonLayout.addComponents(add, close);
        layout.addComponent(buttonLayout);

        setContent(layout);
    }

    private void onAddClicked() {
        panel.addGauge((GaugeConfiguration) gaugeSelector.getValue());
        close();
    }

    private List<GaugeConfiguration> determineAvailableGauges() {
        List<GaugeConfiguration> droneProperties = new ArrayList<>();

        Class<?> navDataInterface = null;

        for (Class<?> droneInterface : drone.getNavData().getClass()
                .getInterfaces()) {
            if (droneInterface.equals(DroneNavData.class)) {
                navDataInterface = droneInterface;
            }
        }

        if (navDataInterface == null) {
            throw new RuntimeException(
                    "Drone's nav data does not implement DroneNavData interface");
        }

        for (Method method : navDataInterface.getMethods()) {
            if (method.isAnnotationPresent(GaugeConfiguration.class)) {
                droneProperties.add(method
                        .getAnnotation(GaugeConfiguration.class));<commit_msg>little styling<commit_after>package com.drone.ui;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.drone.Drone;
import com.drone.GaugeConfiguration;
import com.drone.navdata.DroneNavData;
import com.vaadin.addon.touchkit.ui.HorizontalButtonGroup;
import com.vaadin.addon.touchkit.ui.Popover;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.VerticalLayout;

public class AddGaugeDialog extends Popover {
    private static final long serialVersionUID = -2633336549420617084L;

    private GaugePanel panel;
    private Drone drone;

    private ComboBox gaugeSelector;

    public AddGaugeDialog(GaugePanel panel, Drone drone) {
        this.panel = panel;
        setWidth(200, Unit.PIXELS);
        setResizable(false);
        setClosable(true);
        center();

        this.drone = drone;

        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);

        List<GaugeConfiguration> availableGauges = determineAvailableGauges();

        gaugeSelector = new ComboBox("Gauges");
        gaugeSelector.setWidth(100, Unit.PERCENTAGE);
        gaugeSelector.setNullSelectionAllowed(false);
        layout.addComponent(gaugeSelector);

        for (GaugeConfiguration configuration : availableGauges) {
            gaugeSelector.addItem(configuration);
            gaugeSelector.setItemCaption(configuration, configuration
                    .property().getName());
        }

        HorizontalButtonGroup buttonLayout = new HorizontalButtonGroup();

        Button add = new Button(FontAwesome.PLUS);
        Button close = new Button(FontAwesome.MINUS);

        add.addClickListener(e -> onAddClicked());
        close.addClickListener(e -> close());

        buttonLayout.addComponents(add, close);
        layout.addComponent(buttonLayout);

        layout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);

        setContent(layout);
    }

    private void onAddClicked() {
        panel.addGauge((GaugeConfiguration) gaugeSelector.getValue());
        close();
    }

    private List<GaugeConfiguration> determineAvailableGauges() {
        List<GaugeConfiguration> droneProperties = new ArrayList<>();

        Class<?> navDataInterface = null;

        for (Class<?> droneInterface : drone.getNavData().getClass()
                .getInterfaces()) {
            if (droneInterface.equals(DroneNavData.class)) {
                navDataInterface = droneInterface;
            }
        }

        if (navDataInterface == null) {
            throw new RuntimeException(
                    "Drone's nav data does not implement DroneNavData interface");
        }

        for (Method method : navDataInterface.getMethods()) {
            if (method.isAnnotationPresent(GaugeConfiguration.class)) {
                droneProperties.add(method
                        .getAnnotation(GaugeConfiguration.class));
{'fraction_non_alphanumeric': 0.09616032334119232, 'fraction_numerical': 0.00791512293701583, 'mean_word_length': 2.8316129032258064, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '2645239', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1548, 'n_words': 307}