本文整理汇总了Java中com.intellij.codeInsight.hint.HintManager类的典型用法代码示例。如果您正苦于以下问题:Java HintManager类的具体用法?Java HintManager怎么用?Java HintManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HintManager类属于com.intellij.codeInsight.hint包,在下文中一共展示了HintManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
List<String> refComponents = Arrays.asList(referenceNameToFix.split(Pattern.quote(".")));
List<ElmImportCandidate> candidates = findCandidates(project, refComponents);
if (candidates.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "No module exporting '" + referenceNameToFix + "' found");
} else if (candidates.size() == 1) {
ElmImportCandidate candidate = candidates.get(0);
fixWithCandidate(project, (ElmFile) file, refComponents, candidate);
} else {
List<ElmImportCandidate> sortedCandidates = new ArrayList<>(candidates);
sortedCandidates.sort((a,b) -> a.moduleName.compareTo(b.moduleName));
promptToSelectCandidate(project, (ElmFile) file, refComponents, sortedCandidates);
}
}
示例2: generateMissedTests
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
private static void generateMissedTests(final PsiClass testClass, PsiClass srcClass, Editor srcEditor) {
if (testClass != null) {
final TestFramework framework = TestFrameworks.detectFramework(testClass);
if (framework != null) {
final Project project = testClass.getProject();
final Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, testClass.getContainingFile(), testClass);
if (!FileModificationService.getInstance().preparePsiElementsForWrite(testClass)) return;
final MissedTestsDialog dialog = new MissedTestsDialog(project, srcClass, testClass, framework);
if (dialog.showAndGet()) {
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
JavaTestGenerator.addTestMethods(editor, testClass, framework, dialog.getSelectedMethods(), false, false);
}
});
}
}
else {
HintManager.getInstance().showErrorHint(srcEditor, "Failed to detect test framework for " + testClass.getQualifiedName());
}
}
}
示例3: createTooltip
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
public static HyperlinkLabel createTooltip(final String message) {
final HyperlinkLabel link = new HyperlinkLabel("");
link.setIcon(AllIcons.General.Help_small);
link.setUseIconAsLink(true);
link.setIconTextGap(0);
link.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
final JLabel label = new JLabel(message);
label.setBorder(HintUtil.createHintBorder());
label.setBackground(HintUtil.INFORMATION_COLOR);
label.setOpaque(true);
HintManager.getInstance()
.showHint(label, RelativePoint.getSouthEastOf(link), HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE, -1);
}
});
return link;
}
示例4: executeWriteAction
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@Override
public void executeWriteAction(final Editor editor, DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
int changedLines = 0;
if (selectionModel.hasSelection()) {
changedLines = performAction(editor, new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()));
}
else {
changedLines += performAction(editor, new TextRange(0, editor.getDocument().getTextLength()));
}
if (changedLines == 0) {
HintManager.getInstance().showInformationHint(editor, "All lines already have requested indentation");
}
else {
HintManager.getInstance().showInformationHint(editor, "Changed indentation in " + changedLines + (changedLines == 1 ? " line" : " lines"));
}
}
示例5: performHighlighting
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
protected void performHighlighting() {
boolean clearHighlights = HighlightUsagesHandler.isClearHighlights(myEditor);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()),
myEditor, attributes, clearHighlights, myReadUsages);
HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()),
myEditor, writeAttributes, clearHighlights, myWriteUsages);
if (!clearHighlights) {
WindowManager.getInstance().getStatusBar(myEditor.getProject()).setInfo(myStatusText);
HighlightHandlerBase.setupFindModel(myEditor.getProject()); // enable f3 navigation
}
if (myHintText != null) {
HintManager.getInstance().showInformationHint(myEditor, myHintText);
}
}
示例6: doApplyInformationToEditor
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@Override
public void doApplyInformationToEditor() {
ApplicationManager.getApplication().assertIsDispatchThread();
if (!ApplicationManager.getApplication().isUnitTestMode() && !myEditor.getContentComponent().hasFocus()) return;
// do not show intentions if caret is outside visible area
LogicalPosition caretPos = myEditor.getCaretModel().getLogicalPosition();
Rectangle visibleArea = myEditor.getScrollingModel().getVisibleArea();
Point xy = myEditor.logicalPositionToXY(caretPos);
if (!visibleArea.contains(xy)) return;
TemplateState state = TemplateManagerImpl.getTemplateState(myEditor);
if (myShowBulb && (state == null || state.isFinished()) && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(false)) {
DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject);
codeAnalyzer.setLastIntentionHint(myProject, myFile, myEditor, myIntentionsInfo, myHasToRecreate);
}
}
示例7: show
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@Override
public LightweightHint show(@NotNull Editor editor, @NotNull Point p, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint hintHint) {
myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModelImpl)editor.getMarkupModel()).getErrorStripeRenderer();
myPanel = new TrafficProgressPanel(myTrafficLightRenderer, editor, hintHint);
repaintTooltipWindow();
LineTooltipRenderer.correctLocation(editor, myPanel, p, alignToRight, true, myPanel.getMinWidth());
LightweightHint hint = new LightweightHint(myPanel);
HintManagerImpl hintManager = (HintManagerImpl)HintManager.getInstance();
hintManager.showEditorHint(hint, editor, p,
HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT |
HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
hint.addHintListener(new HintListener() {
@Override
public void hintHidden(EventObject event) {
if (myPanel == null) return; //double hide?
myPanel = null;
onHide.run();
}
});
return hint;
}
示例8: prepareFileForWrite
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@Override
public boolean prepareFileForWrite(@Nullable final PsiFile psiFile) {
if (psiFile == null) return false;
final VirtualFile file = psiFile.getVirtualFile();
final Project project = psiFile.getProject();
if (ReadonlyStatusHandler.ensureFilesWritable(project, file)) {
return true;
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file), true);
if (editor != null && editor.getComponent().isDisplayable()) {
HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("error.hint.file.is.readonly", file.getPresentableUrl()));
}
}
}, project.getDisposed());
return false;
}
示例9: applyAction
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
private void applyAction(final IntentionActionWithTextCaching cachedAction) {
myFinalRunnable = new Runnable() {
@Override
public void run() {
HintManager.getInstance().hideAllHints();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (myProject.isDisposed()) return;
if (DumbService.isDumb(myProject) && !DumbService.isDumbAware(cachedAction)) {
DumbService.getInstance(myProject).showDumbModeNotification(cachedAction.getText() + " is not available during indexing");
return;
}
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final PsiFile file = PsiUtilBase.getPsiFileInEditor(myEditor, myProject);
if (file == null) {
return;
}
ShowIntentionActionsHandler.chooseActionAndInvoke(file, myEditor, cachedAction.getAction(), cachedAction.getText());
}
});
}
};
}
示例10: performOnElement
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
private void performOnElement(@NotNull final Editor editor, @NotNull T first) {
final TextRange textRange = first.getTextRange();
editor.getSelectionModel().setSelection(textRange.getStartOffset(), textRange.getEndOffset());
final String informationHint = getInformationHint(first);
if (informationHint != null) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
HintManager.getInstance().showInformationHint(editor, informationHint);
}
});
}
else {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
HintManager.getInstance().showErrorHint(editor, getErrorHint());
}
});
}
}
示例11: showHint
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
private void showHint(@Nullable final Editor editor,
@NotNull String hint,
@NotNull FindUsagesHandler handler,
@NotNull final RelativePoint popupPosition,
int maxUsages,
@NotNull FindUsagesOptions options,
boolean isWarning) {
JComponent label = createHintComponent(hint, handler, popupPosition, editor, HIDE_HINTS_ACTION, maxUsages, options, isWarning);
if (editor == null || editor.isDisposed() || !editor.getComponent().isShowing()) {
HintManager.getInstance().showHint(label, popupPosition, HintManager.HIDE_BY_ANY_KEY |
HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0);
}
else {
HintManager.getInstance().showInformationHint(editor, label);
}
}
示例12: chooseAmbiguousTargetAndPerform
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project,
final Editor editor,
@NotNull PsiElementProcessor<PsiElement> processor) {
if (editor == null) {
Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(),
Messages.getErrorIcon());
}
else {
int offset = editor.getCaretModel().getOffset();
boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
if (!chosen) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
}
}, project.getDisposed());
}
}
}
示例13: showHint
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
public void showHint() {
myParentEditor.putUserData(KEY, this);
Pair<Point, Short> position = guessPosition();
JRootPane pane = myParentEditor.getComponent().getRootPane();
JComponent layeredPane = pane != null ? pane.getLayeredPane() : myParentEditor.getComponent();
HintHint hintHint = new HintHint(layeredPane, position.first)
.setAwtTooltip(true)
.setContentActive(true)
.setExplicitClose(true)
.setShowImmediately(true)
.setPreferredPosition(position.second == HintManager.ABOVE ? Balloon.Position.above : Balloon.Position.below)
.setTextBg(myParentEditor.getColorsScheme().getDefaultBackground())
.setBorderInsets(new Insets(1, 1, 1, 1));
int hintFlags = HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING;
HintManagerImpl.getInstanceImpl().showEditorHint(this, myParentEditor, position.first, hintFlags, 0, false, hintHint);
}
示例14: guessPosition
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@NotNull
private Pair<Point, Short> guessPosition() {
JRootPane rootPane = myParentEditor.getContentComponent().getRootPane();
JComponent layeredPane = rootPane != null ? rootPane.getLayeredPane() : myParentEditor.getComponent();
LogicalPosition logicalPosition = myParentEditor.getCaretModel().getLogicalPosition();
LogicalPosition pos = new LogicalPosition(logicalPosition.line, logicalPosition.column);
Point p1 = HintManagerImpl.getHintPosition(this, myParentEditor, pos, HintManager.UNDER);
Point p2 = HintManagerImpl.getHintPosition(this, myParentEditor, pos, HintManager.ABOVE);
boolean p1Ok = p1.y + getComponent().getPreferredSize().height < layeredPane.getHeight();
boolean p2Ok = p2.y >= 0;
if (p1Ok) return new Pair<Point, Short>(p1, HintManager.UNDER);
if (p2Ok) return new Pair<Point, Short>(p2, HintManager.ABOVE);
int underSpace = layeredPane.getHeight() - p1.y;
int aboveSpace = p2.y;
return aboveSpace > underSpace
? new Pair<Point, Short>(new Point(p2.x, 0), HintManager.UNDER)
: new Pair<Point, Short>(p1, HintManager.ABOVE);
}
示例15: showHint
import com.intellij.codeInsight.hint.HintManager; //导入依赖的package包/类
@Override
public boolean showHint(@NotNull Editor editor) {
if (!SchemaSettings.getInstance().SHOW_SCHEMA_ADD_IMPORT_HINTS) return false;
if (typeRef.resolve() != null) return false;
List<String> importOptions = calculateImportOptions();
if (importOptions.isEmpty()) return false;
final String message = ShowAutoImportPass.getMessage(importOptions.size() > 1, importOptions.get(0));
final ImportTypeAction action = new ImportTypeAction((SchemaFile) typeRef.getContainingFile(), importOptions, editor);
HintManager.getInstance().showQuestionHint(editor, message,
typeRef.getTextOffset(),
typeRef.getTextRange().getEndOffset(), action);
return false;
}