コード例 #1
0
  public NavBarItem(NavBarPanel panel, Object object, int idx, Disposable parent) {
    // count++;
    // System.out.println(count);
    myPanel = panel;
    myUI = panel.getNavBarUI();
    myObject = object;
    myIndex = idx;
    isPopupElement = idx == -1;
    if (object != null) {
      final NavBarPresentation presentation = myPanel.getPresentation();
      myText = presentation.getPresentableText(object);
      Icon icon = presentation.getIcon(object);
      myIcon = icon != null ? icon : EmptyIcon.create(5);
      myAttributes = presentation.getTextAttributes(object, false);
    } else {
      myText = "Sample";
      myIcon = PlatformIcons.DIRECTORY_CLOSED_ICON;
      myAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    }
    Disposer.register(parent == null ? panel : parent, this);

    setOpaque(false);
    setIpad(myUI.getElementIpad(isPopupElement));

    if (!isPopupElement) {
      setMyBorder(null);
      setBorder(null);
      setPaintFocusBorder(false);
    }
    update();
  }
コード例 #2
0
  public void focusLost(final FocusEvent e) {
    if (myPanel.getProject().isDisposed()) {
      myPanel.setContextComponent(null);
      myPanel.hideHint();
      return;
    }
    final DialogWrapper dialog = DialogWrapper.findInstance(e.getOppositeComponent());
    shouldFocusEditor = dialog != null;
    if (dialog != null) {
      Disposer.register(
          dialog.getDisposable(),
          new Disposable() {
            @Override
            public void dispose() {
              if (dialog.getExitCode() == DialogWrapper.CANCEL_EXIT_CODE) {
                shouldFocusEditor = false;
              }
            }
          });
    }

    // required invokeLater since in current call sequence KeyboardFocusManager is not initialized
    // yet
    // but future focused component
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            processFocusLost(e);
          }
        });
  }
コード例 #3
0
  @Override
  public void keyPressed(final KeyEvent e) {
    if (!(e.isAltDown() || e.isMetaDown() || e.isControlDown() || myPanel.isNodePopupActive())) {
      if (!Character.isLetter(e.getKeyChar())) {
        return;
      }

      final IdeFocusManager focusManager = IdeFocusManager.getInstance(myPanel.getProject());
      final ActionCallback firstCharTyped = new ActionCallback();
      focusManager.typeAheadUntil(firstCharTyped);
      myPanel.moveDown();
      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              try {
                final Robot robot = new Robot();
                final boolean shiftOn = e.isShiftDown();
                final int code = e.getKeyCode();
                if (shiftOn) {
                  robot.keyPress(KeyEvent.VK_SHIFT);
                }
                robot.keyPress(code);
                robot.keyRelease(code);

                // don't release Shift
                firstCharTyped.setDone();
              } catch (AWTException ignored) {
              }
            }
          });
    }
  }
コード例 #4
0
 @Override
 public void propertyChange(PropertyChangeEvent evt) {
   if (myPanel.isShowing()) {
     final String name = evt.getPropertyName();
     if ("focusOwner".equals(name) || "permanentFocusOwner".equals(name)) {
       myPanel.getUpdateQueue().restartRebuild();
     }
   }
 }
コード例 #5
0
  @Override
  public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
    if (shouldSkipAction(action)) return;

    if (myPanel.isInFloatingMode()) {
      myPanel.hideHint();
    } else {
      myPanel.cancelPopup();
    }
  }
コード例 #6
0
 @Override
 public void actionPerformed(ActionEvent e) {
   final NavBarKeyboardCommand cmd = NavBarKeyboardCommand.fromString(e.getActionCommand());
   if (cmd != null) {
     switch (cmd) {
       case LEFT:
         myPanel.moveLeft();
         break;
       case RIGHT:
         myPanel.moveRight();
         break;
       case HOME:
         myPanel.moveHome();
         break;
       case END:
         myPanel.moveEnd();
         break;
       case DOWN:
         myPanel.moveDown();
         break;
       case UP:
         myPanel.moveDown();
         break;
       case ENTER:
         myPanel.enter();
         break;
       case ESCAPE:
         myPanel.escape();
         break;
       case NAVIGATE:
         myPanel.navigate();
         break;
     }
   }
 }
コード例 #7
0
 NavBarListener(NavBarPanel panel) {
   myPanel = panel;
   for (NavBarKeyboardCommand command : NavBarKeyboardCommand.values()) {
     registerKey(command);
   }
   myPanel.addFocusListener(this);
 }
コード例 #8
0
 static void unsubscribeFrom(NavBarPanel panel) {
   final NavBarListener listener = (NavBarListener) panel.getClientProperty(LISTENER);
   panel.putClientProperty(LISTENER, null);
   if (listener != null) {
     final Project project = panel.getProject();
     KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener);
     FileStatusManager.getInstance(project).removeFileStatusListener(listener);
     PsiManager.getInstance(project).removePsiTreeChangeListener(listener);
     WolfTheProblemSolver.getInstance(project).removeProblemListener(listener);
     ActionManager.getInstance().removeAnActionListener(listener);
     final MessageBusConnection connection = (MessageBusConnection) panel.getClientProperty(BUS);
     panel.putClientProperty(BUS, null);
     if (connection != null) {
       connection.disconnect();
     }
   }
 }
コード例 #9
0
  static void subscribeTo(NavBarPanel panel) {
    if (panel.getClientProperty(LISTENER) != null) {
      unsubscribeFrom(panel);
    }

    final NavBarListener listener = new NavBarListener(panel);
    final Project project = panel.getProject();
    panel.putClientProperty(LISTENER, listener);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
    FileStatusManager.getInstance(project).addFileStatusListener(listener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(listener);
    WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
    ActionManager.getInstance().addAnActionListener(listener);

    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
    connection.subscribe(NavBarModelListener.NAV_BAR, listener);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
    panel.putClientProperty(BUS, connection);
    panel.addKeyListener(listener);

    if (panel.isInFloatingMode()) {
      final Window window = SwingUtilities.windowForComponent(panel);
      if (window != null) {
        window.addWindowFocusListener(listener);
      }
    }
  }
コード例 #10
0
 public void focusGained(final FocusEvent e) {
   if (e.getOppositeComponent() == null && shouldFocusEditor) {
     shouldFocusEditor = false;
     ToolWindowManager.getInstance(myPanel.getProject()).activateEditorComponent();
     return;
   }
   myPanel.updateItems();
   final List<NavBarItem> items = myPanel.getItems();
   if (!myPanel.isInFloatingMode() && items.size() > 0) {
     myPanel.setContextComponent(items.get(items.size() - 1));
   } else {
     myPanel.setContextComponent(null);
   }
 }
コード例 #11
0
  private void processFocusLost(FocusEvent e) {
    final Component opposite = e.getOppositeComponent();

    if (myPanel.isInFloatingMode()
        && opposite != null
        && DialogWrapper.findInstance(opposite) != null) {
      myPanel.hideHint();
      return;
    }

    final boolean nodePopupInactive = !myPanel.isNodePopupActive();
    boolean childPopupInactive = !JBPopupFactory.getInstance().isChildPopupFocused(myPanel);
    if (nodePopupInactive && childPopupInactive) {
      if (opposite != null
          && opposite != myPanel
          && !myPanel.isAncestorOf(opposite)
          && !e.isTemporary()) {
        myPanel.setContextComponent(null);
        myPanel.hideHint();
      }
    }

    myPanel.updateItems();
  }
コード例 #12
0
 public boolean isInactive() {
   final NavBarModel model = myPanel.getModel();
   return model.getSelectedIndex() < myIndex && model.getSelectedIndex() != -1;
 }
コード例 #13
0
 public boolean isFocused() {
   final Component focusOwner =
       KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
   return focusOwner == myPanel && !myPanel.isNodePopupShowing();
 }
コード例 #14
0
 public boolean isSelected() {
   final NavBarModel model = myPanel.getModel();
   return isPopupElement
       ? myPanel.isSelectedInPopup(myObject)
       : model.getSelectedIndex() == myIndex;
 }
コード例 #15
0
 public boolean isNextSelected() {
   return myIndex == myPanel.getModel().getSelectedIndex() - 1;
 }
コード例 #16
0
 @Override
 public void selectionChanged() {
   myPanel.updateItems();
   myPanel.scrollSelectionToVisible();
 }
コード例 #17
0
 private void updateModel() {
   if (myPanel.isShowing()) {
     myPanel.getModel().setChanged(true);
     myPanel.getUpdateQueue().queueModelUpdateFromFocus();
   }
 }
コード例 #18
0
 private void rebuildUI() {
   if (myPanel.isShowing()) {
     myPanel.getUpdateQueue().queueRebuildUi();
   }
 }
コード例 #19
0
 private void registerKey(NavBarKeyboardCommand cmd) {
   myPanel.registerKeyboardAction(this, cmd.name(), cmd.getKeyStroke(), JComponent.WHEN_FOCUSED);
 }
コード例 #20
0
 public boolean isLastElement() {
   return myIndex == myPanel.getModel().size() - 1;
 }