Changeset 6252
- Timestamp:
- Mar 14, 2013, 12:46:14 PM (10 years ago)
- Location:
- branches/3.2-stable
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2-stable/doc/src/docbook/user/webclient.xml
r5971 r6252 852 852 <listitem> 853 853 <para> 854 The number of decimals to display for numerical floating point values. 855 The default is 2. 854 The base number of decimals to display for numerical floating point values. 855 The default is 2. This setting is used for values between 1 and 10. For higher 856 or lower values, the number of decimals is adapted in order to not loose 857 information (eg. 0.0059 instead of 0.01) or give the impression of very 858 high precision (eg. 135000 instead of 135000.00). 856 859 </para> 857 860 </listitem> -
branches/3.2-stable/src/clients/web/net/sf/basedb/clients/web/formatter/FormatterFactory.java
r5440 r6252 33 33 import net.sf.basedb.core.Unit; 34 34 import net.sf.basedb.util.ColorGenerator; 35 import net.sf.basedb.util.formatter.AdaptiveNumberFormatter; 35 36 import net.sf.basedb.util.formatter.BooleanFormatter; 36 37 import net.sf.basedb.util.formatter.DateFormatter; … … 71 72 if (formatter == null) 72 73 { 73 formatter = new NumberFormatter(FormatterSettings.getNumDecimals(sc), false);74 formatter = new AdaptiveNumberFormatter(FormatterSettings.getNumDecimals(sc), false); 74 75 sc.setSessionSetting("formatter.float", formatter); 75 76 } … … 94 95 if (formatter == null) 95 96 { 96 formatter = new NumberFormatter(FormatterSettings.getNumDecimals(sc), true);97 formatter = new AdaptiveNumberFormatter(FormatterSettings.getNumDecimals(sc), true); 97 98 sc.setSessionSetting("formatter.double", formatter); 98 99 } -
branches/3.2-stable/src/core/net/sf/basedb/util/formatter/PrefixSuffixFormatter.java
r4544 r6252 51 51 private final Formatter<T> parent; 52 52 private final String suffix; 53 private final boolean usePrefixForNull; 54 private final boolean useSuffixForNull; 53 55 54 56 /** 55 Create a new formatter. 57 Create a new formatter. Prefix and suffix are included for null values. 56 58 @param prefix The prefix, or null to not use any prefix 57 59 @param parent The parent formatter, if null a {@link ToStringFormatter} … … 61 63 public PrefixSuffixFormatter(String prefix, Formatter<T> parent, String suffix) 62 64 { 65 this(prefix, true, parent, suffix, true); 66 } 67 68 /** 69 Create a new formatter. 70 @param prefix The prefix, or null to not use any prefix 71 @param usePrefixForNull If set, the prefix is always included, otherwise only for non-null 72 values 73 @param parent The parent formatter, if null a {@link ToStringFormatter} 74 is automatically created 75 @param suffix The suffix, or null to not use any suffix 76 @param useSuffixForNull If set, the suffix is always included, otherwise only for non-null 77 values 78 */ 79 public PrefixSuffixFormatter(String prefix, boolean usePrefixForNull, Formatter<T> parent, String suffix, boolean useSuffixForNull) 80 { 63 81 this.prefix = prefix == null ? "" : prefix; 82 this.usePrefixForNull = usePrefixForNull; 64 83 this.parent = parent == null ? new ToStringFormatter<T>() : parent; 65 84 this.suffix = suffix == null ? "" : suffix; 85 this.useSuffixForNull = useSuffixForNull; 66 86 } 87 67 88 68 89 /* … … 72 93 public String format(T value) 73 94 { 74 return prefix + parent.format(value) + suffix; 95 StringBuilder sb = new StringBuilder(); 96 if (value != null || usePrefixForNull) sb.append(prefix); 97 sb.append(parent.format(value)); 98 if (value != null || useSuffixForNull) sb.append(suffix); 99 return sb.toString(); 75 100 } 76 101 public T parseString(String value) -
branches/3.2-stable/www/biomaterials/events/view_event.jsp
r6251 r6252 56 56 import="net.sf.basedb.util.Values" 57 57 import="net.sf.basedb.util.formatter.Formatter" 58 import="net.sf.basedb.util.formatter.NumberFormatter" 59 import="net.sf.basedb.util.formatter.PrefixSuffixFormatter" 58 60 import="net.sf.basedb.clients.web.formatter.FormatterFactory" 59 61 import="net.sf.basedb.clients.web.formatter.FormatterSettings" … … 88 90 { 89 91 Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); 90 int numDecimals = FormatterSettings.getNumDecimals(sc); 92 Formatter<Number> numberFormatter = FormatterFactory.getNumberFormatter(sc); 93 Formatter<Number> quantityFormatter = new PrefixSuffixFormatter(null, false, numberFormatter, " µg", false); 94 91 95 Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); 92 96 … … 255 259 <tr> 256 260 <th>Used quantity</th> 257 <td><%= Values.formatNumber(event.getUsedQuantity(bioMaterial), numDecimals, " µg")%></td>261 <td><%=quantityFormatter.format(event.getUsedQuantity(bioMaterial))%></td> 258 262 </tr> 259 263 <tr> … … 304 308 <%=Base.getLinkedName(ID, source, source == null, true)%> 305 309 <%=sourceType != null ? "(" + sourceType + ")" : "" %> 306 <%= Values.formatNumber(evtSrc.getUsedQuantity(), numDecimals, " µg")%>310 <%=quantityFormatter.format(evtSrc.getUsedQuantity())%> 307 311 <br> 308 312 <% -
branches/3.2-stable/www/biomaterials/extracts/view_extract.jsp
r6251 r6252 67 67 import="net.sf.basedb.util.formatter.Formatter" 68 68 import="net.sf.basedb.util.formatter.WellCoordinateFormatter" 69 import="net.sf.basedb.util.formatter.PrefixSuffixFormatter" 69 70 import="net.sf.basedb.clients.web.formatter.FormatterFactory" 70 71 import="net.sf.basedb.clients.web.formatter.FormatterSettings" … … 101 102 { 102 103 Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); 103 int numDecimals = FormatterSettings.getNumDecimals(sc); 104 Formatter<Number> numberFormatter = FormatterFactory.getNumberFormatter(sc); 105 Formatter<Number> quantityFormatter = new PrefixSuffixFormatter(null, false, numberFormatter, " µg", false); 106 104 107 Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); 105 108 … … 348 351 <tr> 349 352 <th>Original quantity</th> 350 <td><%= Values.formatNumber(extract.getOriginalQuantity(), numDecimals, " µg")%></td>353 <td><%=quantityFormatter.format(extract.getOriginalQuantity())%></td> 351 354 </tr> 352 355 <tr> 353 356 <th class="subprompt">- remaining</th> 354 <td><%= Values.formatNumber(extract.getRemainingQuantity(), numDecimals, " µg")%></td>357 <td><%=quantityFormatter.format(extract.getRemainingQuantity())%></td> 355 358 </tr> 356 359 <tr> … … 475 478 %> 476 479 </tbl:cell> 477 <tbl:cell column="quantity"><%= Values.formatNumber(item.getUsedQuantity(), numDecimals)%></tbl:cell>480 <tbl:cell column="quantity"><%=numberFormatter.format(item.getUsedQuantity())%></tbl:cell> 478 481 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 479 482 </tbl:row> … … 588 591 %> 589 592 </tbl:cell> 590 <tbl:cell column="quantity"><%= Values.formatNumber(item.getUsedQuantity(), numDecimals)%></tbl:cell>593 <tbl:cell column="quantity"><%=numberFormatter.format(item.getUsedQuantity())%></tbl:cell> 591 594 <tbl:cell column="description"><%=HTML.encodeTags(child == null ? "" : child.getDescription())%></tbl:cell> 592 595 </tbl:row> -
branches/3.2-stable/www/biomaterials/samples/view_sample.jsp
r6251 r6252 63 63 import="net.sf.basedb.util.formatter.Formatter" 64 64 import="net.sf.basedb.util.formatter.WellCoordinateFormatter" 65 import="net.sf.basedb.util.formatter.PrefixSuffixFormatter" 65 66 import="net.sf.basedb.clients.web.formatter.FormatterFactory" 66 67 import="net.sf.basedb.clients.web.formatter.FormatterSettings" … … 97 98 { 98 99 Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); 99 int numDecimals = FormatterSettings.getNumDecimals(sc); 100 Formatter<Number> numberFormatter = FormatterFactory.getNumberFormatter(sc); 101 Formatter<Number> quantityFormatter = new PrefixSuffixFormatter(null, false, numberFormatter, " µg", false); 102 100 103 Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); 101 104 … … 333 336 <tr> 334 337 <th>Original quantity</th> 335 <td><%= Values.formatNumber(sample.getOriginalQuantity(), numDecimals, " µg")%></td>338 <td><%=quantityFormatter.format(sample.getOriginalQuantity())%></td> 336 339 </tr> 337 340 <tr> 338 341 <th class="subprompt">- remaining</th> 339 <td><%= Values.formatNumber(sample.getRemainingQuantity(), numDecimals, " µg")%></td>342 <td><%=quantityFormatter.format(sample.getRemainingQuantity())%></td> 340 343 </tr> 341 344 <tr> … … 460 463 %> 461 464 </tbl:cell> 462 <tbl:cell column="quantity"><%= Values.formatNumber(item.getUsedQuantity(), numDecimals)%></tbl:cell>465 <tbl:cell column="quantity"><%=numberFormatter.format(item.getUsedQuantity())%></tbl:cell> 463 466 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 464 467 </tbl:row> … … 561 564 %> 562 565 </tbl:cell> 563 <tbl:cell column="quantity"><%= Values.formatNumber(item.getUsedQuantity(), numDecimals)%></tbl:cell>566 <tbl:cell column="quantity"><%=numberFormatter.format(item.getUsedQuantity())%></tbl:cell> 564 567 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 565 568 </tbl:row> -
branches/3.2-stable/www/filemanager/files/list_files.jsp
r6158 r6252 236 236 int numListed = 0; 237 237 Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc); 238 int numDecimals = FormatterSettings.getNumDecimals(sc);239 238 JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, current); 240 239 ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); … … 1015 1014 icon = "file_compressed.png"; 1016 1015 } 1017 String fileSize = Values.formatBytes(item.getSize(), numDecimals);1016 String fileSize = Values.formatBytes(item.getSize(), 2); 1018 1017 index++; 1019 1018 numListed++; … … 1097 1096 /></tbl:cell> 1098 1097 <tbl:cell column="size"><span title="<%=item.getSize()%> bytes"><%=fileSize%></span></tbl:cell> 1099 <tbl:cell column="compressedSize"><span title="<%=item.getCompressedSize()%> bytes"><%=Values.formatBytes(item.getCompressedSize(), numDecimals)%></span></tbl:cell>1098 <tbl:cell column="compressedSize"><span title="<%=item.getCompressedSize()%> bytes"><%=Values.formatBytes(item.getCompressedSize(), 2)%></span></tbl:cell> 1100 1099 <tbl:cell column="compressed"><%=item.isCompressed() ? "yes" : "no"%></tbl:cell> 1101 1100 <tbl:cell column="writeProtected"><%=item.isWriteProtected() ? "yes" : "no"%></tbl:cell> -
branches/3.2-stable/www/filemanager/files/view_file.jsp
r5951 r6252 435 435 <tr> 436 436 <th class="subprompt">- compressed size</th> 437 <td title="<%=file.getCompressedSize()%> bytes"><%=Values.formatBytes(file.getCompressedSize() )%></td>437 <td title="<%=file.getCompressedSize()%> bytes"><%=Values.formatBytes(file.getCompressedSize(), 2)%></td> 438 438 </tr> 439 439 <% -
branches/3.2-stable/www/views/physicalbioassays/view_bioassay.jsp
r6251 r6252 98 98 { 99 99 Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); 100 int numDecimals = FormatterSettings.getNumDecimals(sc);100 Formatter<Number> numberFormatter = FormatterFactory.getNumberFormatter(sc); 101 101 Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); 102 102 … … 433 433 </tbl:cell> 434 434 <tbl:cell column="tag" visible="<%=bm != null && bm.getType() == Item.EXTRACT%>"><base:propertyvalue item="<%=bm%>" property="tag" /></tbl:cell> 435 <tbl:cell column="quantity"><%= Values.formatNumber(item.getUsedQuantity(), numDecimals)%></tbl:cell>435 <tbl:cell column="quantity"><%=numberFormatter.format(item.getUsedQuantity())%></tbl:cell> 436 436 <tbl:cell column="description"><%=HTML.encodeTags(bm == null ? "" : bm.getDescription())%></tbl:cell> 437 437 </tbl:row>
Note: See TracChangeset
for help on using the changeset viewer.