mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-13 02:32:09 +10:00
Percentage values such as transparency Alpha, image Scale, etc, can have decimal values and not just integers
This commit is contained in:
@@ -22,22 +22,31 @@
|
||||
package org.diylc.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class Percentage implements Serializable, Cloneable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int value;
|
||||
private BigDecimal value;
|
||||
|
||||
public Percentage(int value) {
|
||||
public Percentage(BigDecimal value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
public Percentage(double value) {
|
||||
this.value = BigDecimal.valueOf(value);
|
||||
}
|
||||
|
||||
public Percentage(int value) {
|
||||
this.value = BigDecimal.valueOf((long) value);
|
||||
}
|
||||
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
public void setValue(BigDecimal value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -45,7 +54,7 @@ public class Percentage implements Serializable, Cloneable {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + value;
|
||||
result = prime * result + ((value == null) ? 0 : value.stripTrailingZeros().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -58,14 +67,19 @@ public class Percentage implements Serializable, Cloneable {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Percentage other = (Percentage) obj;
|
||||
if (value != other.value)
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (value.compareTo(other.value) != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + "%";
|
||||
if (value == null) return "null%";
|
||||
BigDecimal stripped = value.stripTrailingZeros();
|
||||
return String.format("%s%%", stripped.toPlainString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -59,19 +59,19 @@ public abstract class AbstractTransparentComponent<T> extends AbstractComponent<
|
||||
|
||||
public Composite applyAlpha(Graphics2D g2d, ComponentState componentState) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
int alpha = (OUTLINE_MODE_WHILE_DRAGGING && componentState == ComponentState.DRAGGING) ? 0 :
|
||||
getAlpha().getValue();
|
||||
double alpha = (OUTLINE_MODE_WHILE_DRAGGING && componentState == ComponentState.DRAGGING) ? 0 :
|
||||
getAlpha().getValue().doubleValue();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 100f));
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(alpha / 100d)));
|
||||
}
|
||||
return oldComposite;
|
||||
}
|
||||
|
||||
public Composite applyAlpha(Graphics2D g2d) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
int alpha = getAlpha().getValue();
|
||||
double alpha = getAlpha().getValue().doubleValue();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 100f));
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(alpha / 100d)));
|
||||
}
|
||||
return oldComposite;
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ public class DrawingManager {
|
||||
try {
|
||||
g2dWrapper.transform(mirrorTx);
|
||||
if (Boolean.TRUE.equals(board.getUndersideTransparency())) {
|
||||
g2dWrapper.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, MIRROR_ALPHA.getValue() / 100f));
|
||||
g2dWrapper.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(MIRROR_ALPHA.getValue().doubleValue() / 100d)));
|
||||
}
|
||||
component.draw(g2dWrapper, state, outlineMode, project, g2dWrapper);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -369,6 +369,10 @@
|
||||
<releaseDate>2026-08-22 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Percentage values such as transparency Alpha, image Scale, etc, can have decimal values and not just integers</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Made announcement bubbles and dialogs that contain links clickable</description>
|
||||
|
||||
Reference in New Issue
Block a user