1 19 20 package org.netbeans.editor; 21 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Graphics ; 25 import java.awt.Rectangle ; 26 import java.awt.Toolkit ; 27 import java.util.Map ; 28 import javax.swing.JPanel ; 29 import javax.swing.border.LineBorder ; 30 import javax.swing.text.AbstractDocument ; 31 import javax.swing.text.JTextComponent ; 32 import javax.swing.text.View ; 33 import org.netbeans.editor.view.spi.LockView; 34 35 40 public class FoldingToolTip extends JPanel { 41 42 View view; 43 EditorUI editorUI; 44 public static final int BORDER_WIDTH = 2; 45 46 47 public FoldingToolTip(View view, EditorUI editorUI) { 48 this.view = view; 49 this.editorUI = editorUI; 50 Coloring defColoring = editorUI.getColoring(SettingsNames.DEFAULT_COLORING); 51 Color foreColor = (defColoring != null) ? defColoring.getForeColor() : null; 52 setBorder(new LineBorder ((foreColor == null) ? Color.BLACK : foreColor)); 53 setOpaque(true); 54 } 55 56 57 public void setSize(Dimension d){ 58 setSize(d.width, d.height); 59 } 60 61 62 public void setSize(int width, int height){ 63 int viewHeight = (int) view.getPreferredSpan(View.Y_AXIS); 64 int viewWidth = (int) view.getPreferredSpan(View.X_AXIS); 65 if (height<30) { 66 putClientProperty(PopupManager.Placement.class, null); 67 }else{ 68 height = Math.min(height, viewHeight); 69 } 70 71 height += 2*BORDER_WIDTH; 72 73 width = Math.min(width, viewWidth); 74 75 super.setSize(width,height); 76 } 77 78 private void updateRenderingHints(Graphics g){ 79 JTextComponent comp = editorUI.getComponent(); 80 if (comp == null) return; 81 Object value = (Map )(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); if (value == null) { 86 value = Settings.getValue(Utilities.getKitClass(comp), SettingsNames.RENDERING_HINTS); 87 } 88 Map renderingHints = (value instanceof Map ) ? (java.util.Map )value : null; 89 90 if (renderingHints != null) { 92 ((java.awt.Graphics2D )g).setRenderingHints(renderingHints); 93 } 94 } 95 96 97 protected void paintComponent(Graphics g) { 98 99 updateRenderingHints(g); 100 101 Rectangle shape = new Rectangle (getSize()); 102 Rectangle clip = g.getClipBounds(); 103 104 Coloring defaultColoring = editorUI.getColoring(SettingsNames.DEFAULT_COLORING); 105 if (defaultColoring!=null && defaultColoring.getBackColor()!=null){ 106 g.setColor(defaultColoring.getBackColor()); 107 }else{ 108 g.setColor(SettingsDefaults.defaultBackColor); 109 } 110 g.fillRect(clip.x, clip.y, clip.width, clip.height); 111 112 g.translate(BORDER_WIDTH, BORDER_WIDTH); 113 114 JTextComponent component = editorUI.getComponent(); 115 if (component == null) return; 116 int sideBarWidth = editorUI.getSideBarWidth(); 117 118 GlyphGutter gg = editorUI.getGlyphGutter(); 119 if (gg!=null){ 120 View docView = null; 121 if (view.getViewCount() == 1){ docView = view.getView(0); 123 } 124 int y = 0; 125 if (docView!=null){ 126 AbstractDocument doc = (AbstractDocument )docView.getDocument(); 127 doc.readLock(); 128 try { 129 LockView lockView = LockView.get(docView); 130 if (lockView != null) { 131 lockView.lock(); 132 try { 133 for (int i = 0; i<docView.getViewCount(); i++ ){ 134 gg.paintGutterForView(g, docView.getView(i), y); 135 y += editorUI.getLineHeight(); 136 } 137 } finally { 138 lockView.unlock(); 139 } 140 } 141 } finally { 142 doc.readUnlock(); 143 } 144 }else{ 145 gg.paintGutterForView(g, view, 0); 146 } 147 148 g.translate(sideBarWidth,0); 149 } 150 151 view.paint(g, shape); 152 153 if (gg!=null){ 154 g.translate(-sideBarWidth,0); 155 } 156 157 g.translate(-BORDER_WIDTH, -BORDER_WIDTH); 158 159 if (defaultColoring!=null && defaultColoring.getBackColor()!=null){ 160 g.setColor(defaultColoring.getBackColor()); 161 }else{ 162 g.setColor(SettingsDefaults.defaultBackColor); 163 } 164 for (int i = 1; i<=BORDER_WIDTH; i++){ 165 g.drawRect(clip.x+i,clip.y+i,clip.width-i*2-1,clip.height-i*2-1); 166 } 167 } 168 169 170 } 171 | Popular Tags |