Link Here
|
47 |
import java.util.logging.Level; |
47 |
import java.util.logging.Level; |
48 |
import org.netbeans.modules.editor.*; |
48 |
import org.netbeans.modules.editor.*; |
49 |
import java.awt.BorderLayout; |
49 |
import java.awt.BorderLayout; |
|
|
50 |
import java.awt.Color; |
51 |
import java.awt.Component; |
52 |
import java.awt.Graphics; |
53 |
import java.awt.Graphics2D; |
54 |
import java.awt.Insets; |
55 |
import java.beans.PropertyChangeEvent; |
56 |
import java.beans.PropertyChangeListener; |
50 |
import java.lang.ref.Reference; |
57 |
import java.lang.ref.Reference; |
51 |
import java.lang.ref.WeakReference; |
58 |
import java.lang.ref.WeakReference; |
52 |
import java.util.ArrayList; |
59 |
import java.util.ArrayList; |
53 |
import java.util.Arrays; |
60 |
import java.util.Arrays; |
54 |
import java.util.Collection; |
61 |
import java.util.Collection; |
55 |
import java.util.HashMap; |
62 |
import java.util.HashMap; |
|
|
63 |
import java.util.Iterator; |
56 |
import java.util.List; |
64 |
import java.util.List; |
57 |
import java.util.Map; |
65 |
import java.util.Map; |
58 |
import java.util.WeakHashMap; |
66 |
import java.util.WeakHashMap; |
Link Here
|
61 |
import javax.swing.JComponent; |
69 |
import javax.swing.JComponent; |
62 |
import javax.swing.JPanel; |
70 |
import javax.swing.JPanel; |
63 |
import javax.swing.SwingUtilities; |
71 |
import javax.swing.SwingUtilities; |
|
|
72 |
import javax.swing.border.LineBorder; |
64 |
import javax.swing.event.ChangeEvent; |
73 |
import javax.swing.event.ChangeEvent; |
65 |
import javax.swing.event.ChangeListener; |
74 |
import javax.swing.event.ChangeListener; |
|
|
75 |
import javax.swing.text.AttributeSet; |
66 |
import javax.swing.text.JTextComponent; |
76 |
import javax.swing.text.JTextComponent; |
|
|
77 |
import javax.swing.text.StyleConstants; |
67 |
import org.netbeans.api.editor.mimelookup.MimeLookup; |
78 |
import org.netbeans.api.editor.mimelookup.MimeLookup; |
68 |
import org.netbeans.api.editor.mimelookup.MimePath; |
79 |
import org.netbeans.api.editor.mimelookup.MimePath; |
|
|
80 |
import org.netbeans.api.editor.settings.AttributesUtilities; |
81 |
import org.netbeans.api.editor.settings.FontColorNames; |
82 |
import org.netbeans.api.editor.settings.FontColorSettings; |
69 |
import org.netbeans.editor.WeakEventListenerList; |
83 |
import org.netbeans.editor.WeakEventListenerList; |
70 |
import org.openide.filesystems.FileObject; |
84 |
import org.openide.filesystems.FileObject; |
71 |
import org.openide.util.Lookup; |
85 |
import org.openide.util.Lookup; |
72 |
import org.openide.util.LookupEvent; |
86 |
import org.openide.util.LookupEvent; |
73 |
import org.openide.util.LookupListener; |
87 |
import org.openide.util.LookupListener; |
|
|
88 |
import org.openide.util.WeakListeners; |
74 |
|
89 |
|
75 |
/** |
90 |
/** |
76 |
* Editor Customizable Side Bar. |
91 |
* Editor Customizable Side Bar. |
Link Here
|
95 |
private static final Map<MimePath, Lookup.Result<SideBarFactoriesProvider>> LR = new WeakHashMap<MimePath, Lookup.Result<SideBarFactoriesProvider>>(5); |
110 |
private static final Map<MimePath, Lookup.Result<SideBarFactoriesProvider>> LR = new WeakHashMap<MimePath, Lookup.Result<SideBarFactoriesProvider>>(5); |
96 |
private static final Map<Lookup.Result<SideBarFactoriesProvider>, LookupListener> LL = new WeakHashMap<Lookup.Result<SideBarFactoriesProvider>, LookupListener>(5); |
111 |
private static final Map<Lookup.Result<SideBarFactoriesProvider>, LookupListener> LL = new WeakHashMap<Lookup.Result<SideBarFactoriesProvider>, LookupListener>(5); |
97 |
|
112 |
|
|
|
113 |
private static final String COLOR_WEST_SIDEBARS = "west-sidebars-color"; // NOI18N |
114 |
|
98 |
private CustomizableSideBar() { |
115 |
private CustomizableSideBar() { |
99 |
} |
116 |
} |
100 |
|
117 |
|
Link Here
|
195 |
for(SideBarPosition pos : sideBarsMap.keySet()) { |
212 |
for(SideBarPosition pos : sideBarsMap.keySet()) { |
196 |
List<JComponent> sideBars = sideBarsMap.get(pos); |
213 |
List<JComponent> sideBars = sideBarsMap.get(pos); |
197 |
|
214 |
|
198 |
JPanel panel = new JPanel(); |
215 |
JPanel panel = pos.getPosition() == SideBarPosition.WEST ? |
|
|
216 |
new WestSidebarHolder(target) : |
217 |
new JPanel(); |
199 |
panel.setLayout(new BoxLayout(panel, pos.getAxis())); |
218 |
panel.setLayout(new BoxLayout(panel, pos.getAxis())); |
200 |
|
219 |
|
201 |
for(JComponent c : sideBars) { |
220 |
for(JComponent c : sideBars) { |
202 |
panel.add(c); |
221 |
panel.add(c); |
203 |
} |
222 |
} |
Link Here
|
211 |
} |
230 |
} |
212 |
} |
231 |
} |
213 |
|
232 |
|
|
|
233 |
/** |
234 |
* Degenerated "right line border"; displays line at the right only. Pads |
235 |
* the line with the editor component's background, so the divisor and editor's |
236 |
* graphics (i.e. brace ruler) are separated. |
237 |
*/ |
238 |
private final static class WestSidebarHolder extends JPanel implements LookupListener, PropertyChangeListener, Runnable { |
239 |
/** |
240 |
* The text editor, whose background will be used as a padding |
241 |
*/ |
242 |
private final JComponent bkgSource; |
243 |
|
244 |
private final Lookup.Result<FontColorSettings> colorResult; |
245 |
|
246 |
private Color lineColor; |
247 |
|
248 |
private Color textBkColor; |
249 |
|
250 |
private int thickness = 1; |
251 |
|
252 |
@SuppressWarnings("LeakingThisInConstructor") |
253 |
public WestSidebarHolder(JTextComponent target) { |
254 |
this.bkgSource = target; |
255 |
|
256 |
String mimeType = NbEditorUtilities.getMimeType(target); |
257 |
colorResult = MimeLookup.getLookup(mimeType).lookupResult(FontColorSettings.class); |
258 |
colorResult.addLookupListener(WeakListeners.create(LookupListener.class, this, colorResult)); |
259 |
bkgSource.addPropertyChangeListener(WeakListeners.propertyChange(this, "background", bkgSource)); |
260 |
getInsets().set(0, 0, 0, 1); |
261 |
setOpaque(true); |
262 |
} |
263 |
|
264 |
@Override |
265 |
public void resultChanged(LookupEvent ev) { |
266 |
run(); |
267 |
} |
268 |
|
269 |
@Override |
270 |
public void propertyChange(PropertyChangeEvent evt) { |
271 |
if (evt.getSource() == bkgSource && "background".equals(evt.getPropertyName())) { |
272 |
run(); |
273 |
} |
274 |
} |
275 |
|
276 |
@Override |
277 |
public void run() { |
278 |
if (!SwingUtilities.isEventDispatchThread()) { |
279 |
SwingUtilities.invokeLater(this); |
280 |
return; |
281 |
} |
282 |
updateUIConfig(); |
283 |
} |
284 |
|
285 |
public int getThickness() { |
286 |
return thickness; |
287 |
} |
288 |
|
289 |
@Override |
290 |
public void addNotify() { |
291 |
super.addNotify(); |
292 |
updateUIConfig(); |
293 |
} |
294 |
|
295 |
@Override |
296 |
protected void paintComponent(Graphics g) { |
297 |
super.paintComponent(g); |
298 |
if (lineColor == null) { |
299 |
return; |
300 |
} |
301 |
// paint the border: |
302 |
paintBorder(this, g, 0, 0, getWidth(), getHeight()); |
303 |
} |
304 |
|
305 |
private void updateUIConfig() { |
306 |
Iterator<? extends FontColorSettings> it = colorResult.allInstances().iterator(); |
307 |
if (!it.hasNext()) { |
308 |
return; |
309 |
} |
310 |
FontColorSettings fcs = it.next(); |
311 |
Color line; |
312 |
Color back; |
313 |
|
314 |
AttributeSet as = fcs.getFontColors(COLOR_WEST_SIDEBARS); |
315 |
if (as == null) { |
316 |
// backwards - compatible behaviour: use the line number stuff: |
317 |
as = fcs.getFontColors(FontColorNames.LINE_NUMBER_COLORING); |
318 |
back = (Color)as.getAttribute(StyleConstants.Background); |
319 |
line = null; |
320 |
} else { |
321 |
Object o; |
322 |
back = (Color)as.getAttribute(StyleConstants.Background); |
323 |
line = (Color)as.getAttribute(StyleConstants.Foreground); |
324 |
} |
325 |
textBkColor = bkgSource.getBackground(); |
326 |
if (back == null) { |
327 |
back = textBkColor; |
328 |
} |
329 |
setBackground(back); |
330 |
if (line == null || line.equals(back)) { |
331 |
lineColor = null; |
332 |
} else { |
333 |
this.lineColor = line; |
334 |
} |
335 |
revalidate(); |
336 |
} |
337 |
|
338 |
@Override |
339 |
public Insets getInsets() { |
340 |
Insets s = super.getInsets(); |
341 |
if (lineColor != null) { |
342 |
s.right += getThickness() + 1; |
343 |
} |
344 |
return s; |
345 |
} |
346 |
|
347 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
348 |
int thick = getThickness(); |
349 |
if (thick < 1 || !(g instanceof Graphics2D)) { |
350 |
return; |
351 |
} |
352 |
Graphics2D g2d = (Graphics2D)g.create(); |
353 |
g2d.setColor(this.lineColor); |
354 |
int x2 = x + width - ((thick +1) / 2); |
355 |
g2d.drawLine(x2 - 1, |
356 |
0, x2 - 1, y + height - 1); |
357 |
g2d.setColor(textBkColor); |
358 |
g2d.drawLine(x2, 0, x2, y + height - 1); |
359 |
} |
360 |
} |
361 |
|
214 |
@SuppressWarnings("deprecation") |
362 |
@SuppressWarnings("deprecation") |
215 |
private static Map<SideBarPosition, List<JComponent>> createSideBarsMap(JTextComponent target) { |
363 |
private static Map<SideBarPosition, List<JComponent>> createSideBarsMap(JTextComponent target) { |
216 |
String mimeType = NbEditorUtilities.getMimeType(target); |
364 |
String mimeType = NbEditorUtilities.getMimeType(target); |