<commit_before>/*
 * Copyright (c) 2013 by <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.hansolo.enzo.radialmenu;

import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.ParallelTransition;
import javafx.animation.RotateTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.Transition;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ObjectPropertyBase;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventTarget;
import javafx.event.EventType;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.util.Duration;

import java.util.*;


/**
 * Created with IntelliJ IDEA.
 * User: hansolo
 * Date: 21.09.12
 * Time: 13:25
 * To change this template use File | Settings | File Templates.
 */
public class RadialMenu extends Region {
    public static enum State {
        OPENED,
        CLOSED
    }

    private ObservableMap<Parent, MenuItem> items;
    private State                           defaultState;
    private ObjectProperty<State>           state;
    private double                          degrees;
    private int                             positions;
    private Timeline[]                      openTimeLines;
    private Timeline[]                      closeTimeLines;
    private Options                         options;
    private MenuButton                      mainMenuButton;
    private Group                           cross;
    private boolean                         firstTime;
    private EventHandler<MouseEvent>        mouseHandler;


    // ******************** Constructors **************************************
    public RadialMenu(final Options OPTIONS, final MenuItem... ITEMS) {
        this(OPTIONS, Arrays.asList(ITEMS));
    }
    public RadialMenu(final Options OPTIONS, final List<MenuItem> ITEMS) {
        options               = OPTIONS;
        items                 = FXCollections.observableHashMap();
        getStylesheets().add(getClass().getResource("radialmenu.css").toExternalForm());
        getStyleClass().addAll("radial-menu");
        state                 = new SimpleObjectProperty<>(this, "state", State.CLOSED);
        degrees               = Math.max(Math.min(360, options.getDegrees()), 0);
        positions             = Double.compare(degrees, 360.0) == 0 ? ITEMS.size() : ITEMS.size() - 1;
        openTimeLines         = new Timeline[ITEMS.size()];
        closeTimeLines        = new Timeline[ITEMS.size()];
        cross                 = new Group();
        firstTime             = true;
        initHandler();
        initMainButton();
        initMenuItems(ITEMS);
        initGraphics();
        registerListeners();
    }


    // ******************** Initialization ************************************
    private void initMainButton() {
        // Define main menu button
        mainMenuButton = new MenuButton(this);
        mainMenuButton.setPrefSize(options.getButtonSize(), options.getButtonSize());
    }

    private void initMenuItems(final List<MenuItem> ITEMS) {
        Map<Parent, MenuItem> itemMap = new HashMap<>(ITEMS.size());

        for (int i = 0 ; i < ITEMS.size() ; i++) {
            MenuItem item = ITEMS.get(i);
            item.setPrefSize(item.getSize() * 0.77778, item.getSize() * 0.77778);

            // Create graphical representation of each menu item
            final StackPane ITEM_CONTAINER = new StackPane();
            ITEM_CONTAINER.getChildren().add(item);

            if (SymbolType.NONE == item.getSymbolType() && item.getThumbnailImageName().isEmpty()) {
                Text text = new Text(item.getText());
                text.setFont(Font.font("Open Sans", FontWeight.BOLD, item.getSize() * 0.5));
                text.setFill(item.getForegroundColor());
                text.setMouseTransparent(true);
                ITEM_CONTAINER.getChildren().add(text);
            } else if (!item.getThumbnailImageName().isEmpty()) {
                try {
                    ITEM_CONTAINER.getChildren().add(createThumbnail(item));
                } catch (IllegalArgumentException exception) {
                    Text text = new Text(Integer.toString(i));
                    text.setFont(Font.font("Open Sans", FontWeight.BOLD, item.getSize() * 0.5));
                    text.setFill(item.getForegroundColor());<commit_msg>another little fix in RadialMenu<commit_after>/*
 * Copyright (c) 2013 by <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.hansolo.enzo.radialmenu;

import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.ParallelTransition;
import javafx.animation.RotateTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.Transition;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ObjectPropertyBase;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventTarget;
import javafx.event.EventType;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.util.Duration;

import java.util.*;


/**
 * Created with IntelliJ IDEA.
 * User: hansolo
 * Date: 21.09.12
 * Time: 13:25
 * To change this template use File | Settings | File Templates.
 */
public class RadialMenu extends Region {
    public static enum State {
        OPENED,
        CLOSED
    }

    private ObservableMap<Parent, MenuItem> items;
    private State                           defaultState;
    private ObjectProperty<State>           state;
    private double                          degrees;
    private int                             positions;
    private Timeline[]                      openTimeLines;
    private Timeline[]                      closeTimeLines;
    private Options                         options;
    private MenuButton                      mainMenuButton;
    private Group                           cross;
    private boolean                         firstTime;
    private EventHandler<MouseEvent>        mouseHandler;


    // ******************** Constructors **************************************
    public RadialMenu(final Options OPTIONS, final MenuItem... ITEMS) {
        this(OPTIONS, Arrays.asList(ITEMS));
    }
    public RadialMenu(final Options OPTIONS, final List<MenuItem> ITEMS) {
        options               = OPTIONS;
        items                 = FXCollections.observableHashMap();
        getStylesheets().add(getClass().getResource("radialmenu.css").toExternalForm());
        getStyleClass().addAll("radial-menu");
        state                 = new SimpleObjectProperty<>(this, "state", State.CLOSED);
        degrees               = Math.max(Math.min(360, options.getDegrees()), 0);
        cross                 = new Group();
        firstTime             = true;
        initHandler();
        initMainButton();
        initMenuItems(ITEMS);
        initGraphics();
        registerListeners();
    }


    // ******************** Initialization ************************************
    private void initMainButton() {
        // Define main menu button
        mainMenuButton = new MenuButton(this);
        mainMenuButton.setPrefSize(options.getButtonSize(), options.getButtonSize());
    }

    private void initMenuItems(final List<MenuItem> ITEMS) {
        Map<Parent, MenuItem> itemMap = new HashMap<>(ITEMS.size());
        positions      = Double.compare(degrees, 360.0) == 0 ? ITEMS.size() : ITEMS.size() - 1;
        openTimeLines  = new Timeline[ITEMS.size()];
        closeTimeLines = new Timeline[ITEMS.size()];

        for (int i = 0 ; i < ITEMS.size() ; i++) {
            MenuItem item = ITEMS.get(i);
            item.setPrefSize(item.getSize() * 0.77778, item.getSize() * 0.77778);

            // Create graphical representation of each menu item
            final StackPane ITEM_CONTAINER = new StackPane();
            ITEM_CONTAINER.getChildren().add(item);

            if (SymbolType.NONE == item.getSymbolType() && item.getThumbnailImageName().isEmpty()) {
                Text text = new Text(item.getText());
                text.setFont(Font.font("Open Sans", FontWeight.BOLD, item.getSize() * 0.5));
                text.setFill(item.getForegroundColor());
                text.setMouseTransparent(true);
                ITEM_CONTAINER.getChildren().add(text);
            } else if (!item.getThumbnailImageName().isEmpty()) {
                try {
                    ITEM_CONTAINER.getChildren().add(createThumbnail(item));
                } catch (IllegalArgumentException exception) {
                    Text text = new Text(Integer.toString(i));
                    text.setFont(Font.font("Open Sans", FontWeight.BOLD, item.getSize() * 0.5));
                    text.setFill(item.getForegroundColor());
{'fraction_non_alphanumeric': 0.11879242586638085, 'fraction_numerical': 0.008217220435869954, 'mean_word_length': 2.614267269205939, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3518916', 'n_tokens_mistral': 3075, 'n_tokens_neox': 2931, 'n_words': 723}