Java Code Examples for com.intellij.ui.components.labels.LinkListener

The following examples show how to use com.intellij.ui.components.labels.LinkListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   Source File: NotificationsManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
public DropDownAction(String text, @Nullable LinkListener<Void> listener) {
  super(text, null, listener);

  setHorizontalTextPosition(SwingConstants.LEADING);
  setIconTextGap(0);

  setIcon(new Icon() {
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
      int lineY = getUI().getBaseline(DropDownAction.this, getWidth(), getHeight()) - getIconHeight();
      IconUtil.colorize(myIcon, getTextColor()).paintIcon(c, g, x - 1, lineY);
    }

    @Override
    public int getIconWidth() {
      return myIcon.getIconWidth();
    }

    @Override
    public int getIconHeight() {
      return myIcon.getIconHeight();
    }
  });
}
 
Example 2
Source Project: consulo   Source File: PushLog.java    License: Apache License 2.0 6 votes vote down vote up
private JComponent createStrategyPanel() {
  final JPanel labelPanel = new JPanel(new BorderLayout());
  labelPanel.setBackground(myTree.getBackground());
  final LinkLabel<String> linkLabel = new LinkLabel<>("Edit all targets", null);
  linkLabel.setBorder(new EmptyBorder(2, 2, 2, 2));
  linkLabel.setListener(new LinkListener<String>() {
    @Override
    public void linkSelected(LinkLabel aSource, String aLinkData) {
      if (linkLabel.isEnabled()) {
        startSyncEditing();
      }
    }
  }, null);
  myTree.addPropertyChangeListener(PushLogTreeUtil.EDIT_MODE_PROP, new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      Boolean editMode = (Boolean)evt.getNewValue();
      linkLabel.setEnabled(!editMode);
      linkLabel.setPaintUnderline(!editMode);
      linkLabel.repaint();
    }
  });
  labelPanel.add(linkLabel, BorderLayout.EAST);
  return labelPanel;
}
 
Example 3
@javax.annotation.Nullable
@Override
public JComponent createComponent() {
  final JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
  panel.add(myCheckbox);
  panel.add(myComboBox);
  panel.add(Box.createHorizontalStrut(UIUtil.DEFAULT_HGAP));
  panel.add(new LinkLabel("Edit scopes", null, new LinkListener() {
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      final OptionsEditor optionsEditor = DataManager.getInstance().getDataContext(panel).getData(OptionsEditor.KEY);
      if (optionsEditor != null) {
        SearchableConfigurable configurable = optionsEditor.findConfigurableById(new ScopeChooserConfigurable(myProject).getId());
        if (configurable != null) {
          optionsEditor.select(configurable);
        }
      }
    }
  }));
  return panel;
}
 
Example 4
Source Project: size-analyzer   Source File: AnalyzeSizeToolWindow.java    License: Apache License 2.0 5 votes vote down vote up
private void showCategoryInCategoryPanelFor(DefaultMutableTreeNode categoryNode) {
  CategoryData category = (CategoryData) categoryNode.getUserObject();
  categoryTitle.clear();
  categoryTitle.append(category.toString(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
  if (category.totalSizeSaved() != null) {
    categoryTitle.append(
        "  Estimated savings: " + category.totalSizeSaved(),
        SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }
  categoryTitle.setMaximumSize(categoryTitle.getPreferredSize());

  suggestionsPanel.removeAll();
  for (Enumeration<?> nodeEnumeration = categoryNode.children();
      nodeEnumeration.hasMoreElements(); ) {
    Object nodeValue = nodeEnumeration.nextElement();
    if (nodeValue instanceof DefaultMutableTreeNode) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodeValue;
      String linkTitle = extractLinkTitle(node);
      suggestionsPanel.add(
          new LinkLabel<>(
              linkTitle,
              null,
              new LinkListener<Object>() {
                @Override
                @SuppressWarnings("rawtypes") // Declaration uses raw type, needed for override.
                public void linkSelected(LinkLabel source, Object linkData) {
                  suggestionTree.clearSelection();
                  TreePath selectedNode =
                      new TreePath(((DefaultMutableTreeNode) linkData).getPath());
                  suggestionTree.addSelectionPath(selectedNode);
                  suggestionTree.scrollPathToVisible(selectedNode);
                }
              },
              node));
    }
  }
}
 
Example 5
Source Project: azure-devops-intellij   Source File: Hyperlink.java    License: MIT License 5 votes vote down vote up
public Hyperlink() {
    super("Hyperlink", null);

    super.setListener(new LinkListener<Object>() {
        @Override
        public void linkSelected(final LinkLabel aSource, final Object aLinkData) {
            notifyActionListeners();
        }
    }, null);

    // Make our link focusable via the keyboard (Tab key)
    super.setFocusable(true);
}
 
Example 6
Source Project: robovm-idea   Source File: XcodeSetupDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void createUIComponents() {
    linkLabel = new LinkLabel("Visit the Apple iOS Developer Center", null, new LinkListener() {
        @Override
        public void linkSelected(LinkLabel aSource, Object aLinkData) {
            try {
                Desktop.getDesktop().browse(new URI("https://developer.apple.com/devcenter/ios/index.action"));
            } catch (URISyntaxException | IOException ex) {
                //It looks like there's a problem
            }
        }
    });
}
 
Example 7
Source Project: consulo   Source File: Banner.java    License: Apache License 2.0 5 votes vote down vote up
public void addAction(final Action action) {
  action.addPropertyChangeListener(this);
  final LinkLabel label =
          new LinkLabel(null, null, (LinkListener)(aSource, aLinkData) -> action.actionPerformed(new ActionEvent(Banner.this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY))) {
            @Override
            protected Color getTextColor() {
              return JBColor.BLUE;
            }
          };
  label.setFont(label.getFont().deriveFont(Font.BOLD));
  myActions.put(action, label);
  myActionsPanel.add(label);
  updateAction(action);
}
 
Example 8
Source Project: consulo   Source File: BreakpointEditor.java    License: Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
  AnAction action = ActionManager.getInstance().getAction(XDebuggerActions.VIEW_BREAKPOINTS);
  String shortcutText = action != null ? KeymapUtil.getFirstKeyboardShortcutText(action) : null;
  String text = shortcutText != null ? "More (" + shortcutText + ")" : "More";
  myShowMoreOptionsLink = new LinkLabel(text, null, new LinkListener() {
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      if (myDelegate != null) {
        myDelegate.more();
      }
    }
  });
}
 
Example 9
Source Project: consulo   Source File: RegExHelpPopup.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LinkLabel createRegExLink(@Nonnull String title, @Nullable final Component owner, @Nullable final Logger logger) {
  return new LinkLabel(title, null, new LinkListener() {
    JBPopup helpPopup;
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      try {
        if (helpPopup != null && !helpPopup.isDisposed() && helpPopup.isVisible()) {
          return;
        }
        helpPopup = createRegExHelpPopup();
        Disposer.register(helpPopup, new Disposable() {
          @Override
          public void dispose() {
            destroyPopup();
          }
        });
        helpPopup.showInCenterOf(owner);
      }
      catch (BadLocationException e) {
        if (logger != null) logger.info(e);
      }
    }

    private void destroyPopup() {
      helpPopup = null;
    }
  });
}
 
Example 10
Source Project: consulo   Source File: TodoCheckinHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
  JCheckBox checkBox = new JCheckBox(VcsBundle.message("before.checkin.new.todo.check", ""));
  return new RefreshableOnComponent() {
    @Override
    public JComponent getComponent() {
      JPanel panel = new JPanel(new BorderLayout(4, 0));
      panel.add(checkBox, BorderLayout.WEST);
      setFilterText(myConfiguration.myTodoPanelSettings.todoFilterName);
      if (myConfiguration.myTodoPanelSettings.todoFilterName != null) {
        myTodoFilter = TodoConfiguration.getInstance().getTodoFilter(myConfiguration.myTodoPanelSettings.todoFilterName);
      }

      Consumer<TodoFilter> consumer = todoFilter -> {
        myTodoFilter = todoFilter;
        String name = todoFilter == null ? null : todoFilter.getName();
        myConfiguration.myTodoPanelSettings.todoFilterName = name;
        setFilterText(name);
      };
      LinkLabel linkLabel = new LinkLabel("Configure", null);
      linkLabel.setListener(new LinkListener() {
        @Override
        public void linkSelected(LinkLabel aSource, Object aLinkData) {
          DefaultActionGroup group = SetTodoFilterAction.createPopupActionGroup(myProject, myConfiguration.myTodoPanelSettings, consumer);
          ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.TODO_VIEW_TOOLBAR, group);
          popupMenu.getComponent().show(linkLabel, 0, linkLabel.getHeight());
        }
      }, null);
      panel.add(linkLabel, BorderLayout.CENTER);

      CheckinHandlerUtil.disableWhenDumb(myProject, checkBox, "TODO check is impossible until indices are up-to-date");
      return panel;
    }

    private void setFilterText(String filterName) {
      if (filterName == null) {
        checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", IdeBundle.message("action.todo.show.all")));
      } else {
        checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", "Filter: " + filterName));
      }
    }

    @Override
    public void refresh() {
    }

    @Override
    public void saveState() {
      myConfiguration.CHECK_NEW_TODO = checkBox.isSelected();
    }

    @Override
    public void restoreState() {
      checkBox.setSelected(myConfiguration.CHECK_NEW_TODO);
    }
  };
}