Lines 41-47
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.modules.editor.hints; |
42 |
package org.netbeans.modules.editor.hints; |
43 |
|
43 |
|
44 |
import java.awt.*; |
44 |
import java.awt.AWTEvent; |
|
|
45 |
import java.awt.Color; |
46 |
import java.awt.Component; |
47 |
import java.awt.Container; |
48 |
import java.awt.Cursor; |
49 |
import java.awt.Dimension; |
50 |
import java.awt.HeadlessException; |
51 |
import java.awt.Point; |
52 |
import java.awt.Rectangle; |
53 |
import java.awt.Toolkit; |
45 |
import java.awt.event.AWTEventListener; |
54 |
import java.awt.event.AWTEventListener; |
46 |
import java.awt.event.KeyEvent; |
55 |
import java.awt.event.KeyEvent; |
47 |
import java.awt.event.KeyListener; |
56 |
import java.awt.event.KeyListener; |
Lines 53-58
Link Here
|
53 |
import java.io.IOException; |
62 |
import java.io.IOException; |
54 |
import java.lang.ref.Reference; |
63 |
import java.lang.ref.Reference; |
55 |
import java.lang.ref.WeakReference; |
64 |
import java.lang.ref.WeakReference; |
|
|
65 |
import java.util.Collection; |
66 |
import java.util.List; |
67 |
import java.util.Map; |
68 |
import java.util.concurrent.atomic.AtomicBoolean; |
56 |
import java.util.logging.Level; |
69 |
import java.util.logging.Level; |
57 |
import java.util.logging.LogRecord; |
70 |
import java.util.logging.LogRecord; |
58 |
import java.util.logging.Logger; |
71 |
import java.util.logging.Logger; |
Lines 62-67
Link Here
|
62 |
import javax.swing.text.JTextComponent; |
75 |
import javax.swing.text.JTextComponent; |
63 |
import javax.swing.text.Position; |
76 |
import javax.swing.text.Position; |
64 |
import org.netbeans.api.editor.EditorRegistry; |
77 |
import org.netbeans.api.editor.EditorRegistry; |
|
|
78 |
import org.netbeans.api.editor.mimelookup.MimeLookup; |
65 |
import org.netbeans.editor.AnnotationDesc; |
79 |
import org.netbeans.editor.AnnotationDesc; |
66 |
import org.netbeans.editor.Annotations; |
80 |
import org.netbeans.editor.Annotations; |
67 |
import org.netbeans.editor.BaseDocument; |
81 |
import org.netbeans.editor.BaseDocument; |
Lines 71-77
Link Here
|
71 |
import org.netbeans.modules.editor.hints.borrowed.ListCompletionView; |
85 |
import org.netbeans.modules.editor.hints.borrowed.ListCompletionView; |
72 |
import org.netbeans.modules.editor.hints.borrowed.ScrollCompletionPane; |
86 |
import org.netbeans.modules.editor.hints.borrowed.ScrollCompletionPane; |
73 |
import org.netbeans.spi.editor.hints.ChangeInfo; |
87 |
import org.netbeans.spi.editor.hints.ChangeInfo; |
|
|
88 |
import org.netbeans.spi.editor.hints.Context; |
89 |
import org.netbeans.spi.editor.hints.ErrorDescription; |
74 |
import org.netbeans.spi.editor.hints.Fix; |
90 |
import org.netbeans.spi.editor.hints.Fix; |
|
|
91 |
import org.netbeans.spi.editor.hints.PositionRefresher; |
75 |
import org.openide.ErrorManager; |
92 |
import org.openide.ErrorManager; |
76 |
import org.openide.cookies.EditCookie; |
93 |
import org.openide.cookies.EditCookie; |
77 |
import org.openide.cookies.EditorCookie; |
94 |
import org.openide.cookies.EditorCookie; |
Lines 81-86
Link Here
|
81 |
import org.openide.loaders.DataObjectNotFoundException; |
98 |
import org.openide.loaders.DataObjectNotFoundException; |
82 |
import org.openide.text.Annotation; |
99 |
import org.openide.text.Annotation; |
83 |
import org.openide.util.Exceptions; |
100 |
import org.openide.util.Exceptions; |
|
|
101 |
import org.openide.util.Lookup; |
84 |
import org.openide.util.NbBundle; |
102 |
import org.openide.util.NbBundle; |
85 |
import org.openide.util.RequestProcessor; |
103 |
import org.openide.util.RequestProcessor; |
86 |
import org.openide.util.Task; |
104 |
import org.openide.util.Task; |
Lines 114-124
Link Here
|
114 |
private JLabel hintIcon; |
132 |
private JLabel hintIcon; |
115 |
private ScrollCompletionPane hintListComponent; |
133 |
private ScrollCompletionPane hintListComponent; |
116 |
private JLabel errorTooltip; |
134 |
private JLabel errorTooltip; |
|
|
135 |
private AtomicBoolean cancel; |
117 |
|
136 |
|
118 |
/** Creates a new instance of HintsUI */ |
137 |
/** Creates a new instance of HintsUI */ |
119 |
private HintsUI() { |
138 |
private HintsUI() { |
120 |
EditorRegistry.addPropertyChangeListener(this); |
139 |
EditorRegistry.addPropertyChangeListener(this); |
121 |
propertyChange(null); |
140 |
propertyChange(null); |
|
|
141 |
cancel = new AtomicBoolean(false); |
122 |
} |
142 |
} |
123 |
|
143 |
|
124 |
public JTextComponent getComponent() { |
144 |
public JTextComponent getComponent() { |
Lines 138-143
Link Here
|
138 |
this.compRef = new WeakReference<JTextComponent>(comp); |
158 |
this.compRef = new WeakReference<JTextComponent>(comp); |
139 |
register(); |
159 |
register(); |
140 |
} |
160 |
} |
|
|
161 |
} |
162 |
|
163 |
private AnnotationHolder getAnnotationHolder(Document doc) { |
164 |
DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); |
165 |
if (od == null) { |
166 |
return null; |
167 |
} |
168 |
return AnnotationHolder.getInstance(od.getPrimaryFile()); |
141 |
} |
169 |
} |
142 |
|
170 |
|
143 |
private void register() { |
171 |
private void register() { |
Lines 422-434
Link Here
|
422 |
} |
450 |
} |
423 |
|
451 |
|
424 |
private ParseErrorAnnotation findAnnotation(Document doc, AnnotationDesc desc, int lineNum) { |
452 |
private ParseErrorAnnotation findAnnotation(Document doc, AnnotationDesc desc, int lineNum) { |
425 |
DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); |
453 |
AnnotationHolder annotations = getAnnotationHolder(doc); |
426 |
|
454 |
|
427 |
if (od == null) |
|
|
428 |
return null; |
429 |
|
430 |
AnnotationHolder annotations = AnnotationHolder.getInstance(od.getPrimaryFile()); |
431 |
|
432 |
if (annotations != null) { |
455 |
if (annotations != null) { |
433 |
for (Annotation a : annotations.getAnnotations()) { |
456 |
for (Annotation a : annotations.getAnnotations()) { |
434 |
if (a instanceof ParseErrorAnnotation) { |
457 |
if (a instanceof ParseErrorAnnotation) { |
Lines 444-458
Link Here
|
444 |
|
467 |
|
445 |
return null; |
468 |
return null; |
446 |
} |
469 |
} |
447 |
|
470 |
|
448 |
boolean invokeDefaultAction(boolean onlyActive) { |
471 |
boolean invokeDefaultAction(boolean onlyActive) { |
449 |
JTextComponent comp = getComponent(); |
472 |
JTextComponent comp = getComponent(); |
450 |
if (comp == null) { |
473 |
if (comp == null) { |
451 |
Logger.getLogger(HintsUI.class.getName()).log(Level.WARNING, "HintsUI.invokeDefaultAction called, but comp == null"); |
474 |
Logger.getLogger(HintsUI.class.getName()).log(Level.WARNING, "HintsUI.invokeDefaultAction called, but comp == null"); |
452 |
return false; |
475 |
return false; |
453 |
} |
476 |
} |
454 |
|
477 |
|
455 |
Document doc = comp.getDocument(); |
478 |
Document doc = comp.getDocument(); |
|
|
479 |
|
480 |
cancel.set(false); |
481 |
refresh(doc, comp.getCaretPosition()); |
456 |
|
482 |
|
457 |
if (doc instanceof BaseDocument) { |
483 |
if (doc instanceof BaseDocument) { |
458 |
Annotations annotations = ((BaseDocument) doc).getAnnotations(); |
484 |
Annotations annotations = ((BaseDocument) doc).getAnnotations(); |
Lines 507-513
Link Here
|
507 |
if (comp == null) { |
533 |
if (comp == null) { |
508 |
return; |
534 |
return; |
509 |
} |
535 |
} |
510 |
boolean bulbShowing = hintIcon != null && hintIcon.isShowing(); |
536 |
// boolean bulbShowing = hintIcon != null && hintIcon.isShowing(); |
511 |
boolean errorTooltipShowing = errorTooltip != null && errorTooltip.isShowing(); |
537 |
boolean errorTooltipShowing = errorTooltip != null && errorTooltip.isShowing(); |
512 |
boolean popupShowing = hintListComponent != null && hintListComponent.isShowing(); |
538 |
boolean popupShowing = hintListComponent != null && hintListComponent.isShowing(); |
513 |
|
539 |
|
Lines 541-546
Link Here
|
541 |
} else if ( e.getKeyCode() == KeyEvent.VK_ESCAPE ) { |
567 |
} else if ( e.getKeyCode() == KeyEvent.VK_ESCAPE ) { |
542 |
if ( popupShowing ) { |
568 |
if ( popupShowing ) { |
543 |
removePopup(); |
569 |
removePopup(); |
|
|
570 |
} else { |
571 |
//user is tired of waiting for refresh before popup is shown |
572 |
cancel.set(true); |
544 |
} |
573 |
} |
545 |
} else if ( popupShowing ) { |
574 |
} else if ( popupShowing ) { |
546 |
InputMap input = hintListComponent.getInputMap(); |
575 |
InputMap input = hintListComponent.getInputMap(); |
Lines 712-715
Link Here
|
712 |
return input; |
741 |
return input; |
713 |
} |
742 |
} |
714 |
|
743 |
|
|
|
744 |
private void refresh(Document doc, int pos) { |
745 |
Context context = ContextAccessor.getDefault().newContext(pos, cancel); |
746 |
String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(doc); |
747 |
Lookup lookup = MimeLookup.getLookup(mimeType); |
748 |
Collection<? extends PositionRefresher> refreshers = lookup.lookupAll(PositionRefresher.class); |
749 |
//set errors from all available refreshers |
750 |
for (PositionRefresher ref : refreshers) { |
751 |
Map<String, List<ErrorDescription>> layer2Errs = ref.getErrorDescriptionsAt(context, doc); |
752 |
getAnnotationHolder(doc).setErrorsForLine(pos, layer2Errs); |
753 |
} |
754 |
} |
755 |
|
715 |
} |
756 |
} |