diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java index 592a9c6..632c56d 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java @@ -2,15 +2,20 @@ package org.nanoboot.utils.timecalc.swing.common; import org.nanoboot.utils.timecalc.app.GetProperty; import org.nanoboot.utils.timecalc.entity.Visibility; +import org.nanoboot.utils.timecalc.swing.progress.ProgressSmileyIcon; +import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley; import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import org.nanoboot.utils.timecalc.utils.property.Property; import org.nanoboot.utils.timecalc.utils.property.StringProperty; +import javax.swing.ImageIcon; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -33,6 +38,7 @@ public class Widget extends JPanel implements protected int side = 0; protected double donePercent = 0; protected boolean mouseOver = false; + protected JLabel smileyIcon; public Widget() { setBackground(BACKGROUND_COLOR); @@ -109,4 +115,53 @@ public class Widget extends JPanel implements public Property getProperty() { return visibilityProperty; } + + protected void paintSmiley(Visibility visibility, Graphics2D brush, int x, int y) { + if(!mouseOver) { + if(this.smileyIcon != null) { + this.remove(smileyIcon); + } + + //nothing more to do + return; + } + boolean colored = smileysColoredProperty.isEnabled(); + if(visibility.isGray()) { + colored = false; + } + + if(!colored){ + if(!visibility.isStronglyColored()) { + brush.setColor(Color.GRAY); + } + if(visibility.isGray()) { + brush.setColor(Color.LIGHT_GRAY); + } + if(visibility.isStronglyColored()) { + brush.setColor(Color.BLACK); + } + Color currentColor= brush.getColor(); + brush.setColor(visibility.isStronglyColored() ? Color.WHITE : BACKGROUND_COLOR); + brush.fillRect( + x,y, + 20, + 20 + ); + brush.setColor(currentColor); + brush.setFont(MEDIUM_FONT); + brush.drawString( + ProgressSmiley.forProgress(donePercent).getCharacter(), + x,y + 16 + ); + } + if(colored) { + ImageIcon imageIcon = ProgressSmileyIcon.forSmiley(ProgressSmiley.forProgress(donePercent)).getIcon(); + if(this.smileyIcon != null) { + this.remove(smileyIcon); + } + this.smileyIcon = new JLabel(imageIcon); + smileyIcon.setBounds(x,y,15, 15); + this.add(smileyIcon); + } + } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java index af63388..d39acbb 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java @@ -46,7 +46,6 @@ public class Battery extends Widget { private int totalHeight = 0; private int totalWidth; private String label = null; - private JLabel smileyIcon; protected Battery(String name) { this.name = name; @@ -200,53 +199,15 @@ public class Battery extends Widget { brush.setFont(BIG_FONT); brush.drawString( CHARCHING, ((int) (totalWidth * 0.45)), - (donePercent < 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1) + 10 + (donePercent < 0.5 ? totalHeight / 4 * 3 : + totalHeight / 4 * 1) + 10 ); - if(mouseOver && smileysColoredProperty.isDisabled()){//no colored - //paint smiley - if(!visibility.isStronglyColored()) { - brush.setColor(Color.GRAY); - } - if(visibility.isGray()) { - brush.setColor(Color.LIGHT_GRAY); - } - if(visibility.isStronglyColored()) { - brush.setColor(Color.BLACK); - } - Color currentColor= brush.getColor(); - brush.setColor(visibility.isStronglyColored() ? Color.WHITE : BACKGROUND_COLOR); - brush.fillRect( - ((int) (totalWidth * 0.45)) + 15, - (donePercent < 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1) + 8 - 16, - 20, - 20 - ); - brush.setColor(currentColor); - brush.setColor(Color.BLACK); - brush.setFont(MEDIUM_FONT); - brush.drawString( - ProgressSmiley.forProgress(donePercent).getCharacter(), - ((int) (totalWidth * 0.45)) + 15, - (donePercent < 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1) + 8 - ); - - } + paintSmiley(visibility, brush, ((int) (totalWidth * 0.45)) + 15, + (donePercent < 0.5 ? totalHeight / 4 * 3 : + totalHeight / 4 * 1) + 8 - 16); brush.setFont(currentFont); - } - if(mouseOver && smileysColoredProperty.isEnabled()) {//colored - ImageIcon imageIcon = ProgressSmileyIcon.forSmiley(ProgressSmiley.forProgress(donePercent)).getIcon(); - if(this.smileyIcon != null) { - this.remove(smileyIcon); - } - this.smileyIcon = new JLabel(imageIcon); - smileyIcon.setBounds(((int) (totalWidth * 0.45)) + 15, - (donePercent < 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1) - 7,15, 15); - this.add(smileyIcon); - } else { - if(this.smileyIcon != null) { - this.remove(smileyIcon); - } + } { Color currentColor = brush.getColor(); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java index 9ebbac5..3c451eb 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java @@ -15,8 +15,6 @@ import java.awt.RenderingHints; public class ProgressCircle extends Widget { - private JLabel smileyIcon; - public ProgressCircle() { setPreferredSize(new Dimension(200, 200)); } @@ -52,46 +50,9 @@ public class ProgressCircle extends Widget { NumberFormats.FORMATTER_ZERO_DECIMAL_PLACES .format(donePercent * 100) + "%", (int) (side / 8d * 0d), (int) (side / 8d * 7.5d)); - if(mouseOver && smileysColoredProperty.isDisabled()){//no colored - if(!visibility.isStronglyColored()) { - brush.setColor(Color.GRAY); - } - if(visibility.isGray()) { - brush.setColor(Color.LIGHT_GRAY); - } - if(visibility.isStronglyColored()) { - brush.setColor(Color.BLACK); - } - Color currentColor= brush.getColor(); - brush.setColor(visibility.isStronglyColored() ? Color.WHITE : BACKGROUND_COLOR); - brush.fillRect( - (int) (side / 8d * 0d) + 30, - (int) (side / 8d * 7.5d - 16d), - 20, - 20 - ); - brush.setColor(currentColor); - brush.setFont(MEDIUM_FONT); - brush.drawString( - ProgressSmiley.forProgress(donePercent).getCharacter(), - (int) (side / 8d * 0d) + 30, - (int) (side / 8d * 7.5d) - ); - } - if(mouseOver && smileysColoredProperty.isEnabled()) {//colored - ImageIcon imageIcon = ProgressSmileyIcon.forSmiley(ProgressSmiley.forProgress(donePercent)).getIcon(); - if(this.smileyIcon != null) { - this.remove(smileyIcon); - } - this.smileyIcon = new JLabel(imageIcon); - smileyIcon.setBounds((int) (side / 8d * 0d) + 30, - (int) (side / 8d * 7.5d) - 15,15, 15); - this.add(smileyIcon); - } else { - if(this.smileyIcon != null) { - this.remove(smileyIcon); - } - } + paintSmiley(visibility, brush, (int) (side / 8d * 0d) + 30, + (int) (side / 8d * 7.5d - 16d)); + } } \ No newline at end of file diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java index c53fc9d..976539d 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java @@ -16,7 +16,6 @@ import java.awt.RenderingHints; public class ProgressSquare extends Widget { private int square; - private JLabel smileyIcon; public ProgressSquare() { setPreferredSize(new Dimension(400, 400)); @@ -85,46 +84,8 @@ public class ProgressSquare extends Widget { .format(donePercent * 100) + "%", (int) (side / 8d * 3d), (int) (side / 8d * (donePercent > 0.5 ? 3d : 5d))); - if(mouseOver && smileysColoredProperty.isDisabled()){//no colored - if(!visibility.isStronglyColored()) { - brush.setColor(Color.GRAY); - } - if(visibility.isGray()) { - brush.setColor(Color.LIGHT_GRAY); - } - if(visibility.isStronglyColored()) { - brush.setColor(Color.BLACK); - } - Color currentColor= brush.getColor(); - brush.setColor(visibility.isStronglyColored() ? Color.WHITE : BACKGROUND_COLOR); - brush.fillRect( - (int) (side / 8d * 3d) + 65, - (int) ((side / 8d * (donePercent > 0.5 ? 3d : 5d)) - 16d), - 20, - 20 - ); - brush.setColor(currentColor); - brush.setFont(MEDIUM_FONT); - brush.drawString( - ProgressSmiley.forProgress(donePercent).getCharacter(), - (int) (side / 8d * 3d) + 65, - (int) (side / 8d * (donePercent > 0.5 ? 3d : 5d)) - ); - } - if(mouseOver && smileysColoredProperty.isEnabled()) {//colored - ImageIcon imageIcon = ProgressSmileyIcon.forSmiley(ProgressSmiley.forProgress(donePercent)).getIcon(); - if(this.smileyIcon != null) { - this.remove(smileyIcon); - } - this.smileyIcon = new JLabel(imageIcon); - smileyIcon.setBounds((int) (side / 8d * 3d) + 65, - (int) (side / 8d * (donePercent > 0.5 ? 3d : 5d)) - 15,15, 15); - this.add(smileyIcon); - } else { - if(this.smileyIcon != null) { - this.remove(smileyIcon); - } - } + paintSmiley(visibility, brush, (int) (side / 8d * 3d) + 65, + (int) ((side / 8d * (donePercent > 0.5 ? 3d : 5d)) - 16d)); } diff --git a/timecalc.conf b/timecalc.conf index cfe4305..b172370 100644 --- a/timecalc.conf +++ b/timecalc.conf @@ -8,7 +8,7 @@ visibility.only-grey-or-none.enabled=false jokes.enabled=true commands.enabled=true toasts.enabled=true -smileys.colored=false +smileys.colored=true #todo smileys.enabled=true