<commit_before>/*
 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
 */

package com.intellij.ide.palette.impl;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.palette.PaletteDragEventListener;
import com.intellij.ide.palette.PaletteItem;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author yole
 */
public class PaletteManager implements ProjectComponent {
  private Project myProject;
  private FileEditorManager myFileEditorManager;
  private PaletteWindow myPaletteWindow;
  private ToolWindow myPaletteToolWindow;
  private PaletteManager.MyFileEditorManagerListener myListener;
  private List<KeyListener> myKeyListeners = new CopyOnWriteArrayList<KeyListener>();
  private List<PaletteDragEventListener> myDragEventListeners = new CopyOnWriteArrayList<PaletteDragEventListener>();
  private List<ListSelectionListener> mySelectionListeners = new CopyOnWriteArrayList<ListSelectionListener>();

  public PaletteManager(Project project, FileEditorManager fileEditorManager) {
    myProject = project;
    myFileEditorManager = fileEditorManager;
    myListener = new MyFileEditorManagerListener();
    myFileEditorManager.addFileEditorManagerListener(myListener);
  }

  public void projectOpened() {
    StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
      public void run() {
        myPaletteWindow = new PaletteWindow(myProject);
        myPaletteToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(IdeBundle.message("toolwindow.palette"),
                                                                                          myPaletteWindow,
                                                                                          ToolWindowAnchor.RIGHT);
        myPaletteToolWindow.setIcon(IconLoader.getIcon("/general/toolWindowPalette.png"));
        myPaletteToolWindow.setAvailable(false, null);
      }
    });
  }

  public void projectClosed() {<commit_msg>avoid NPE if editor event comes at an unexpected moment<commit_after>/*
 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
 */

package com.intellij.ide.palette.impl;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.palette.PaletteDragEventListener;
import com.intellij.ide.palette.PaletteItem;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author yole
 */
public class PaletteManager implements ProjectComponent {
  private Project myProject;
  private FileEditorManager myFileEditorManager;
  private PaletteWindow myPaletteWindow;
  private ToolWindow myPaletteToolWindow;
  private PaletteManager.MyFileEditorManagerListener myListener;
  private List<KeyListener> myKeyListeners = new CopyOnWriteArrayList<KeyListener>();
  private List<PaletteDragEventListener> myDragEventListeners = new CopyOnWriteArrayList<PaletteDragEventListener>();
  private List<ListSelectionListener> mySelectionListeners = new CopyOnWriteArrayList<ListSelectionListener>();

  public PaletteManager(Project project, FileEditorManager fileEditorManager) {
    myProject = project;
    myFileEditorManager = fileEditorManager;
    myListener = new MyFileEditorManagerListener();
  }

  public void projectOpened() {
    StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
      public void run() {
        myPaletteWindow = new PaletteWindow(myProject);
        myPaletteToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(IdeBundle.message("toolwindow.palette"),
                                                                                          myPaletteWindow,
                                                                                          ToolWindowAnchor.RIGHT);
        myPaletteToolWindow.setIcon(IconLoader.getIcon("/general/toolWindowPalette.png"));
        myPaletteToolWindow.setAvailable(false, null);
        myFileEditorManager.addFileEditorManagerListener(myListener);
      }
    });
  }

  public void projectClosed() {
{'fraction_non_alphanumeric': 0.08263009845288326, 'fraction_numerical': 0.0028129395218002813, 'mean_word_length': 4.20970695970696, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5828269', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1506, 'n_words': 261}