<commit_before>/*
 * Copyright 2015 <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 com.igormaznitsa.nbmindmap.gui;

import com.igormaznitsa.nbmindmap.gui.mmview.*;
import com.igormaznitsa.nbmindmap.model.Extra;
import com.igormaznitsa.nbmindmap.model.MindMap;
import com.igormaznitsa.nbmindmap.model.MindMapTopic;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public final class MindMapPanel extends JPanel {

  private static final long serialVersionUID = 7474413542713752159L;

  private volatile MindMap model;
  private volatile String errorText;

  private final Configuration config;

  private final List<MindMapListener> mindMapListeners = new CopyOnWriteArrayList<MindMapListener>();

  private final float SCALE_STEP = 0.5f;

  private static final Color COLOR_MOUSE_DRAG_SELECTION = new Color(0x80000000, true);

  private final JTextArea textEditor = new JTextArea();
  private final JPanel textEditorPanel = new JPanel(new BorderLayout(0, 0));
  private AbstractElement elementUnderEdit = null;

  private final List<MindMapTopic> selectedTopics = new ArrayList<MindMapTopic>();

  private MouseSelectedArea mouseDragSelection = null;
  private AbstractElement draggedElement = null;
  private Point draggedElementPoint = null;

  public MindMapPanel() {
    super(null);
    this.config = new Configuration(this);

    this.textEditor.setMargin(new Insets(5, 5, 5, 5));
    this.textEditor.addKeyListener(new KeyAdapter() {

      @Override
      public void keyPressed(final KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
          e.consume();
        }
      }

      @Override
      public void keyReleased(final KeyEvent e) {
        switch (e.getKeyCode()) {
          case KeyEvent.VK_ENTER: {
            e.consume();
            if (((KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK) & e.getModifiersEx()) == 0) {
              endEdit(true);
            }
            else {
              textEditor.insert("\n", textEditor.getCaretPosition());<commit_msg>added new topic creation from editor for TAB pressing<commit_after>/*
 * Copyright 2015 <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 com.igormaznitsa.nbmindmap.gui;

import com.igormaznitsa.nbmindmap.gui.mmview.*;
import com.igormaznitsa.nbmindmap.model.Extra;
import com.igormaznitsa.nbmindmap.model.MindMap;
import com.igormaznitsa.nbmindmap.model.MindMapTopic;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public final class MindMapPanel extends JPanel {

  private static final long serialVersionUID = 7474413542713752159L;

  private volatile MindMap model;
  private volatile String errorText;

  private final Configuration config;

  private final List<MindMapListener> mindMapListeners = new CopyOnWriteArrayList<MindMapListener>();

  private final float SCALE_STEP = 0.5f;

  private static final Color COLOR_MOUSE_DRAG_SELECTION = new Color(0x80000000, true);

  private final JTextArea textEditor = new JTextArea();
  private final JPanel textEditorPanel = new JPanel(new BorderLayout(0, 0));
  private AbstractElement elementUnderEdit = null;

  private final List<MindMapTopic> selectedTopics = new ArrayList<MindMapTopic>();

  private MouseSelectedArea mouseDragSelection = null;
  private AbstractElement draggedElement = null;
  private Point draggedElementPoint = null;

  public MindMapPanel() {
    super(null);
    this.config = new Configuration(this);

    this.textEditor.setMargin(new Insets(5, 5, 5, 5));
    this.textEditor.setTabSize(4);
    this.textEditor.addKeyListener(new KeyAdapter() {

      @Override
      public void keyPressed(final KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
          e.consume();
        }
      }

      @Override
      public void keyReleased(final KeyEvent e) {
        switch (e.getKeyCode()) {
          case KeyEvent.VK_TAB : {
            e.consume();
            final MindMapTopic edited = elementUnderEdit.getModel();
            endEdit(true);
            makeNewChildAndStartEdit(edited, null);
          }break;
          case KeyEvent.VK_ENTER: {
            e.consume();
            if (((KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK) & e.getModifiersEx()) == 0) {
              endEdit(true);
            }
            else {
              textEditor.insert("\n", textEditor.getCaretPosition());
{'fraction_non_alphanumeric': 0.09098063906815677, 'fraction_numerical': 0.014953565244766253, 'mean_word_length': 3.7882441597588548, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6078368', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1830, 'n_words': 511}