| 141 | | |
| 142 | | |
| 143 | | if(selection != null && selection.contains(node)) { |
| 144 | | // draw description |
| 145 | | String desc = node.get("note"); |
| 146 | | if(desc != null) { |
| 147 | | // format with html |
| 148 | | StringBuilder sb = new StringBuilder("<html>"); |
| 149 | | //sb.append(desc.replaceAll("\\|", "<br>")); |
| 150 | | sb.append(desc.replaceAll("<hr />", "<hr>")); |
| 151 | | sb.append("</html>"); |
| 152 | | desc = sb.toString(); |
| 153 | | |
| 154 | | // determine tooltip dimensions |
| 155 | | int tooltipWidth = 0; |
| 156 | | Rectangle2D fontBounds = null; |
| 157 | | String[] lines = desc.split("<hr>"); |
| 158 | | for (int j = 0; j < lines.length; j++) { |
| 159 | | String line = lines[j]; |
| 160 | | fontBounds = g.getFontMetrics().getStringBounds(line, g); |
| 161 | | tooltipWidth = Math.max(tooltipWidth, (int)fontBounds.getWidth()); |
| 162 | | } |
| | 142 | } |
| | 143 | |
| | 144 | if(selection == null) |
| | 145 | return; |
| | 146 | |
| | 147 | // This loop renders the selection border and tooltips so they get drawn |
| | 148 | // on top of the bug icons |
| | 149 | for (int i = 0; i < nodes.length; i++) { |
| | 150 | Node node = (Node) nodes[i]; |
| | 151 | |
| | 152 | if(node.deleted || !selection.contains(node)) |
| | 153 | continue; |
| | 154 | |
| | 155 | // draw selection border |
| | 156 | Point p = mv.getPoint(node); |
| | 157 | |
| | 158 | ImageIcon icon = ("1".equals(node.get("state"))) ? iconValid : iconError; |
| | 159 | int width = icon.getIconWidth(); |
| | 160 | int height = icon.getIconHeight(); |
| | 161 | |
| | 162 | g.setColor(ColorHelper.html2color(Main.pref.get("color.selected"))); |
| | 163 | g.drawRect(p.x - (width / 2), p.y - (height / 2), 16, 16); |
| | 164 | |
| | 165 | // draw description |
| | 166 | String desc = node.get("note"); |
| | 167 | if(desc == null) |
| | 168 | continue; |
| 175 | | // draw selection border |
| 176 | | g.setColor(ColorHelper.html2color(Main.pref.get("color.selected"))); |
| 177 | | g.drawRect(p.x - (width / 2), p.y - (height / 2), 16, 16); |
| | 176 | // draw description as a tooltip |
| | 177 | tooltip.setTipText(desc); |
| | 178 | |
| | 179 | int tx = p.x + (width / 2) + 5; |
| | 180 | int ty = (int)(p.y - height / 2) -1; |
| | 181 | g.translate(tx, ty); |
| | 182 | |
| | 183 | // This limits the width of the tooltip to 2/3 of the drawing |
| | 184 | // area, which makes longer tooltips actually readable (they |
| | 185 | // would disappear if scrolled to much too the right) |
| | 186 | |
| | 187 | // Need to do this twice as otherwise getPreferredSize doesn't take |
| | 188 | // the reduced width into account |
| | 189 | for(int x = 0; x < 2; x++) { |
| | 190 | Dimension d = tooltip.getUI().getPreferredSize(tooltip); |
| | 191 | d.width = Math.min(d.width, (int)(mv.getWidth()*2/3)); |
| | 192 | tooltip.setSize(d); |
| | 193 | tooltip.paint(g); |