Changeset 5114
- Timestamp:
- Oct 2, 2009, 2:29:28 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/web.xml
r4975 r5114 157 157 <url-pattern>/views/experiments/plotter/plot</url-pattern> 158 158 </servlet-mapping> 159 160 <!-- The ExperimentExplorer PlotServlet --> 161 <servlet> 162 <servlet-name>eeplotter</servlet-name> 163 <servlet-class> 164 net.sf.basedb.clients.web.servlet.ExperimentExplorerPlotServlet 165 </servlet-class> 166 </servlet> 167 <servlet-mapping> 168 <servlet-name>eeplotter</servlet-name> 169 <url-pattern>/views/experiments/explorer/plot</url-pattern> 170 </servlet-mapping> 171 159 172 160 173 <!-- Axis2 servlets for web services --> -
trunk/src/clients/web/net/sf/basedb/clients/web/ExperimentExplorer.java
r5109 r5114 23 23 package net.sf.basedb.clients.web; 24 24 25 import java.awt.Color; 25 26 import java.sql.SQLException; 26 27 import java.util.ArrayList; … … 1012 1013 private final Map<Short, AnnotationGroup> assayGroups; 1013 1014 private final Set<AnnotationGroup> groups; 1015 private final AnnotationType annotationType; 1014 1016 1015 1017 @SuppressWarnings("unchecked") … … 1019 1021 this.assayGroups = new HashMap<Short, AnnotationGroup>(); 1020 1022 this.groups = new TreeSet<AnnotationGroup>(); 1023 this.annotationType = annotationType; 1021 1024 1022 1025 Formatter formatter = FormatterFactory.getTypeFormatter(dc.getSessionControl(), annotationType.getValueType()); … … 1043 1046 1044 1047 /** 1048 Get the annotation type this summary is based on. 1049 @since 2.14 1050 */ 1051 public AnnotationType getAnnotationType() 1052 { 1053 return annotationType; 1054 } 1055 1056 /** 1045 1057 Get the annotation group for the bioassay with the 1046 1058 give data cube column. … … 1160 1172 { 1161 1173 return color; 1174 } 1175 1176 /** 1177 Get the AWT color object that corresponds to the HTML color string. 1178 The color string must have been set with a seven-character 1179 string with 2 hex characters for every color component, eg. 1180 '#rrggbb'. 1181 @since 2.14 1182 */ 1183 public Color getAwtColor() 1184 { 1185 int r = Integer.parseInt(color.substring(1, 3), 16); 1186 int g = Integer.parseInt(color.substring(3, 5), 16); 1187 int b = Integer.parseInt(color.substring(5), 16); 1188 return new Color(r, g, b); 1162 1189 } 1163 1190 -
trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java
r4889 r5114 51 51 import net.sf.basedb.util.StaticCache; 52 52 import net.sf.basedb.util.Values; 53 import net.sf.basedb.util.error.ThrowableUtil; 53 54 import net.sf.basedb.util.formatter.Formatter; 54 55 import net.sf.basedb.util.jep.ChannelFunction; … … 71 72 import org.jfree.chart.title.TextTitle; 72 73 73 import java.awt.Color;74 import java.awt.Font;75 import java.awt.Graphics2D;76 import java.awt.font.FontRenderContext;77 import java.awt.geom.Rectangle2D;78 import java.awt.image.BufferedImage;79 74 import java.awt.image.RenderedImage; 80 75 import java.io.InputStream; … … 611 606 try 612 607 { 613 BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 614 Graphics2D graphics = img.createGraphics(); 615 graphics.setBackground(Color.WHITE); 616 graphics.clearRect(0, 0, width, height); 617 graphics.setColor(Color.RED); 618 FontRenderContext context = graphics.getFontRenderContext(); 619 620 Font topFont = new Font("SansSerif", Font.BOLD, 12); 621 Font stackTraceFont = new Font("SansSerif", Font.PLAIN, 12); 622 623 float x = .0f; 624 float y = .0f; 625 String causedBy = ""; 626 do 627 { 628 graphics.setFont(topFont); 629 String msg = causedBy + t.getClass().getSimpleName() + ": " + t.getMessage(); 630 x = 5.0f; 631 Rectangle2D bounds = topFont.getStringBounds(msg, context); 632 y += bounds.getHeight()+5; 633 if (bounds.getWidth() > width - x) 634 { 635 msg = cutMiddle(msg, (width - x) / bounds.getWidth()); 636 } 637 graphics.drawString(msg, x, y); 638 639 graphics.setFont(stackTraceFont); 640 x = 15.0f; 641 for (StackTraceElement st : t.getStackTrace()) 642 { 643 msg = "at " + st.getClassName() + "." + st.getMethodName() + 644 ":" + st.getLineNumber(); 645 bounds = stackTraceFont.getStringBounds(msg, context); 646 y += bounds.getHeight(); 647 if (bounds.getWidth() > width - x) 648 { 649 msg = cutMiddle(msg, (width - x) / bounds.getWidth()); 650 } 651 graphics.drawString(msg, x, y); 652 } 653 t = t.getCause(); 654 causedBy = "Caused by: "; 655 } while (t != null && y < height); 656 image = img; 608 image = ThrowableUtil.stackTraceToImage(t, width, height); 657 609 } 658 610 catch (Throwable t2) … … 774 726 } 775 727 776 777 private String cutMiddle(String msg, double fraction)778 {779 int charactersToCut = (int)(msg.length() * (1 - fraction)) + 3;780 int beginAt = (msg.length() - charactersToCut) / 2;781 return msg.substring(0, beginAt) + "..." + msg.substring(beginAt + charactersToCut);782 }783 784 728 /** 785 729 Special implementation of a <code>SqlResultIterator</code> -
trunk/src/core/net/sf/basedb/core/StringUtil.java
r5014 r5114 157 157 return s; 158 158 } 159 160 /** 161 Trim a string to a maximum length. Strings longer than the specified 162 length will have text cut-out from the middle and replaced by three 163 dots. If no trimming is needed the original string is returned. 164 @param s The string to trim 165 @param length The maximum length of the string 166 @return The trimmed string 167 @since 2.14 168 */ 169 public static final String trimStringMiddle(String s, int length) 170 { 171 if (s != null && s.length() > length) 172 { 173 int charactersToCut = s.length() + 3 - length; 174 int beginAt = (s.length() - charactersToCut) / 2; 175 s = s.substring(0, beginAt) + "..." + s.substring(beginAt + charactersToCut); 176 } 177 return s; 178 } 159 179 160 180 } -
trunk/src/core/net/sf/basedb/util/error/ThrowableUtil.java
r4618 r5114 22 22 package net.sf.basedb.util.error; 23 23 24 import java.awt.Color; 25 import java.awt.Font; 26 import java.awt.Graphics2D; 27 import java.awt.font.FontRenderContext; 28 import java.awt.geom.Rectangle2D; 29 import java.awt.image.BufferedImage; 24 30 import java.io.PrintWriter; 25 31 import java.io.StringWriter; 32 33 import net.sf.basedb.core.StringUtil; 26 34 27 35 /** … … 49 57 return sw.toString(); 50 58 } 59 60 /** 61 Prints as much of a stacktrace as possible to an image. 62 @param t The throwable 63 @param width The width of the image 64 @param height The height of the image 65 @since 2.14 66 */ 67 public static BufferedImage stackTraceToImage(Throwable t, int width, int height) 68 { 69 BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 70 Graphics2D graphics = img.createGraphics(); 71 graphics.setBackground(Color.WHITE); 72 graphics.clearRect(0, 0, width, height); 73 graphics.setColor(Color.RED); 74 FontRenderContext context = graphics.getFontRenderContext(); 75 76 Font topFont = new Font("SansSerif", Font.BOLD, 12); 77 Font stackTraceFont = new Font("SansSerif", Font.PLAIN, 12); 78 79 float x = .0f; 80 float y = .0f; 81 String causedBy = ""; 82 do 83 { 84 graphics.setFont(topFont); 85 String msg = causedBy + t.getClass().getSimpleName() + ": " + t.getMessage(); 86 x = 5.0f; 87 Rectangle2D bounds = topFont.getStringBounds(msg, context); 88 y += bounds.getHeight()+5; 89 if (bounds.getWidth() > width - x) 90 { 91 msg = StringUtil.trimStringMiddle(msg,(int)(msg.length() * (width - x) / bounds.getWidth())); 92 } 93 graphics.drawString(msg, x, y); 94 95 graphics.setFont(stackTraceFont); 96 x = 15.0f; 97 for (StackTraceElement st : t.getStackTrace()) 98 { 99 msg = "at " + st.getClassName() + "." + st.getMethodName() + 100 ":" + st.getLineNumber(); 101 bounds = stackTraceFont.getStringBounds(msg, context); 102 y += bounds.getHeight(); 103 if (bounds.getWidth() > width - x) 104 { 105 msg = StringUtil.trimStringMiddle(msg,(int)(msg.length() * (width - x) / bounds.getWidth())); 106 } 107 graphics.drawString(msg, x, y); 108 } 109 t = t.getCause(); 110 causedBy = "Caused by: "; 111 } while (t != null && y < height); 112 return img; 113 } 114 51 115 } -
trunk/www/views/experiments/explorer/view/view.jsp
r5111 r5114 254 254 } 255 255 } 256 function plotSpotData() 257 { 258 var url = 'plotter.jsp?ID=<%=ID%>'; 259 url += '&bioAssaySetId=<%=bioAssaySetId%>'; 260 url += '&reporterIndex=<%=reporterIndex%>'; 261 url += '&positionIndex=<%=positionIndex%>'; 262 Main.openPopup(url, 'SpotPlot', 1100, 700); 263 } 256 264 </script> 257 265 </base:head> … … 448 456 <table border="0" cellspacing="0" cellpadding="2" class="annotationsummary"> 449 457 <tr> 450 <td class="summaryheader"><%= HTML.encodeTags(at.getName())%></td>458 <td class="summaryheader"><%=Base.getLinkedName(ID, at, false, true)%></td> 451 459 <% 452 460 for (AnnotationGroup ag : summary.getAnnotationGroups()) … … 707 715 tooltip="Show, hide and re-order columns" 708 716 /> 717 <tbl:button 718 image="plotter.gif" 719 onclick="plotSpotData()" 720 title="Plot…" 721 tooltip="Plot selected data from this table" 722 /> 709 723 </tbl:toolbar> 710 724 <tbl:data>
Note: See TracChangeset
for help on using the changeset viewer.