下面列出了javax.swing.text.html.ParagraphView#com.intellij.ui.components.labels.LinkListener 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
});
}
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;
}
@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;
}
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));
}
}
}
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);
}
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
}
}
});
}
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);
}
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();
}
}
});
}
@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;
}
});
}
@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);
}
};
}