content: package org.netbeans.modules.python.repl;
  
  import com.jediterm.terminal.TtyConnector;
  import com.jediterm.terminal.ui.JediTermWidget;
  import com.jediterm.terminal.ui.TerminalWidget;
  import com.jediterm.terminal.ui.settings.DefaultSettingsProvider;
  import java.awt.EventQueue;
  import java.awt.Font;
  import java.awt.GridLayout;
  import javax.swing.SwingUtilities;
  import org.netbeans.api.progress.ProgressHandle;
  import org.netbeans.api.settings.ConvertAsProperties;
  import org.netbeans.modules.python.PythonUtility;
  import org.netbeans.modules.python.project.PythonProject;
  import org.openide.awt.ActionID;
  import org.openide.awt.ActionReference;
  import org.openide.util.NbBundle.Messages;
  import org.openide.windows.TopComponent;
  
  /**
   * Top component which displays something.
   */
  @ConvertAsProperties(
          dtd = "-//org.netbeans.modules.python.repl//PythonVEnvConsoleAction//EN",
          autostore = false
  )
  @TopComponent.Description(
          preferredID = "PythonVEnvConsoleActionTopComponent",
          iconBase = "org/netbeans/modules/python/term.png",
          persistenceType = TopComponent.PERSISTENCE_ALWAYS
  )
  @TopComponent.Registration(mode = "output", openAtStartup = false)
  @ActionID(category = "Window",
          id = "org.netbeans.modules.python.repl.PythonVEnvConsoleActionTopComponent")
  @ActionReference(path = "Menu/Window/Interactive Python Interpreters",
          position = 333)
  //@TopComponent.OpenActionRegistration(
  //        displayName = "#CTL_PythonVEnvConsoleActionAction",
  //        preferredID = "PythonVEnvConsoleActionTopComponent"
  //)
  @Messages({
      "CTL_PythonVEnvConsoleActionAction=PythonVEnvConsoleAction",
      "CTL_PythonVEnvConsoleActionTopComponent=Python VEnv Console",
      "CTL_Start=Starting",
      "CTL_Opening=Opening venv console",
      "HINT_PythonVEnvConsoleActionTopComponent=This is a PythonVEnvConsoleAction window"
  })
  public final class PythonVEnvConsoleActionTopComponent extends TopComponent {
  
      private static final long serialVersionUID = 1L;
  
      PythonProject project;
      String type;
      static JediTermWidget jediTermWidget;
      static TtyConnector ttyConnector;
  
      public PythonVEnvConsoleActionTopComponent() {
          initComponents();
          setName(Bundle.CTL_PythonVEnvConsoleActionTopComponent());
          setToolTipText(Bundle.HINT_PythonVEnvConsoleActionTopComponent());
  
      }
  
      public PythonVEnvConsoleActionTopComponent(PythonProject project, String type) {
          initComponents();
          this.project = project;
          this.type = type;
          setName("(.venv) " + project.getProjectDirectory().getName());
          setToolTipText(Bundle.HINT_PythonVEnvConsoleActionTopComponent());
  
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
          this.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 400, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 300, Short.MAX_VALUE)
          );
      }// </editor-fold>//GEN-END:initComponents
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      // End of variables declaration//GEN-END:variables
      @Override
      public void componentOpened() {
  
          SwingUtilities.invokeLater(() -> {
              ProgressHandle pg = ProgressHandle.createHandle(Bundle.CTL_Start());
              pg.switchToIndeterminate();
              pg.start();
              pg.progress(Bundle.CTL_Opening());
              setLayout(new GridLayout());
              jediTermWidget = new JediTermWidget(new DefaultSettingsProvider() {
  
                  @Override
                  public Font getTerminalFont() {
                      return new Font(PythonUtility.getTermFontFam(),
                              PythonUtility.geTermFontSt(),
                              PythonUtility.getTermFontSize());
  
                  }
  
              });
              jediTermWidget.addListener((TerminalWidget tw) -> {
                  EventQueue.invokeLater(() -> {
                      close();
                  });
              });
  
              ttyConnector = PythonTerminalConnector.createTtyConnector(type,
                      project);
              jediTermWidget.setTtyConnector(ttyConnector);
              jediTermWidget.start();
              removeAll();
              add(jediTermWidget);
              pg.finish();
          });
      }
  
      @Override
      public void componentClosed() {
          ttyConnector.close();
          jediTermWidget.close();
          removeAll();
      }
  
      void writeProperties(java.util.Properties p) {
          // better to version settings since initial version as advocated at
          // http://wiki.apidesign.org/wiki/PropertyFiles
          p.setProperty("version", "1.0");
          //  store your settings
      }
  
      void readProperties(java.util.Properties p) {
          String version = p.getProperty("version");
          //  read your settings according to their version
      }
  }
  