You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2012/12/04 11:36:45 UTC
svn commit: r1416870 -
/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ProgressRenderer.java
Author: lofwyr
Date: Tue Dec 4 10:36:44 2012
New Revision: 1416870
URL: http://svn.apache.org/viewvc?rev=1416870&view=rev
Log:
TOBAGO-1218: ArithmeticException: divide by zero
This happens when the range model has min == max
Modified:
myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ProgressRenderer.java
Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ProgressRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ProgressRenderer.java?rev=1416870&r1=1416869&r2=1416870&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ProgressRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ProgressRenderer.java Tue Dec 4 10:36:44 2012
@@ -66,10 +66,10 @@ public class ProgressRenderer extends La
String value1 = Integer.toString(model.getValue());
String value2 = Integer.toString(model.getMaximum() - model.getValue());
+ final int diff = model.getMaximum() - model.getMinimum();
Object title = component.getAttributes().get(ATTR_TIP);
- if (title == null) {
- title = Integer.toString(100 * model.getValue()
- / (model.getMaximum() - model.getMinimum())) + " %";
+ if (title == null && diff > 0) {
+ title = Integer.toString(100 * model.getValue() / diff) + " %";
}
Integer width = LayoutUtil.getLayoutWidth(component);
@@ -78,8 +78,7 @@ public class ProgressRenderer extends La
String width2 = value2;
if (width != null) {
- int value = (width -1) * model.getValue()
- / (model.getMaximum() - model.getMinimum());
+ int value = diff > 0 ? (width - 1) * model.getValue() / diff : width;
width1 = Integer.toString(value);
width2 = Integer.toString((width - 2) - value);
}
@@ -88,7 +87,9 @@ public class ProgressRenderer extends La
writer.startElement(HtmlConstants.SPAN, component);
writer.writeClassAttribute();
- writer.writeAttribute(HtmlAttributes.TITLE, String.valueOf(title), true);
+ if (title != null) {
+ writer.writeAttribute(HtmlAttributes.TITLE, String.valueOf(title), true);
+ }
writer.startElement(HtmlConstants.IMG, null);
StyleClasses color1Classes = new StyleClasses();
@@ -96,7 +97,9 @@ public class ProgressRenderer extends La
color1Classes.addMarkupClass(component, "progress", "color1");
writer.writeClassAttribute(color1Classes);
writer.writeAttribute(HtmlAttributes.SRC, image, false);
- writer.writeAttribute(HtmlAttributes.ALT, String.valueOf(title), true);
+ if (title != null) {
+ writer.writeAttribute(HtmlAttributes.ALT, String.valueOf(title), true);
+ }
writer.writeAttribute(HtmlAttributes.STYLE, "width:" + width1 + "px", false);
writer.writeAttribute(HtmlAttributes.BORDER, 0);
writer.endElement(HtmlConstants.IMG);
@@ -107,7 +110,9 @@ public class ProgressRenderer extends La
color2Classes.addMarkupClass(component, "progress", "color2");
writer.writeClassAttribute(color2Classes);
writer.writeAttribute(HtmlAttributes.SRC, image, false);
- writer.writeAttribute(HtmlAttributes.ALT, String.valueOf(title), true);
+ if (title != null) {
+ writer.writeAttribute(HtmlAttributes.ALT, String.valueOf(title), true);
+ }
writer.writeAttribute(HtmlAttributes.STYLE, "width:" + width2 + "px", false);
writer.writeAttribute(HtmlAttributes.BORDER, 0);
writer.endElement(HtmlConstants.IMG);