diff --git a/runelite-client/src/main/java/net/runelite/client/ui/components/DimmableJPanel.java b/runelite-client/src/main/java/net/runelite/client/ui/components/DimmableJPanel.java new file mode 100644 index 0000000000..c36dd72abe --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/components/DimmableJPanel.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018, Levi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.ui.components; + +import java.awt.Color; +import javax.swing.JPanel; +import lombok.Getter; + +public class DimmableJPanel extends JPanel +{ + // Dimming state, allows for restoring original colors before dimming + @Getter + private boolean dimmed = false; + private Color dimmedForeground = null; + private Color dimmedBackground = null; + private Color undimmedForeground = null; + private Color undimmedBackground = null; + + @Override + public void setForeground(Color color) + { + undimmedForeground = color; + dimmedForeground = color.darker(); + super.setForeground(color); + } + + @Override + public void setBackground(Color color) + { + undimmedBackground = color; + dimmedBackground = color.darker(); + super.setBackground(color); + } + + @Override + public Color getForeground() + { + return dimmed ? dimmedForeground : undimmedForeground; + } + + @Override + public Color getBackground() + { + return dimmed ? dimmedBackground : undimmedBackground; + } + + /** + * Dimming sets all parts of this component with darker colors except for the central label + * This is useful for showing that progress is paused + * Setting dim to false will restore the original colors from before the component was dimmed. + * @param dimmed + */ + public void setDimmed(boolean dimmed) + { + this.dimmed = dimmed; + + if (dimmed) + { + super.setBackground(dimmedBackground); + super.setForeground(dimmedForeground); + } + else + { + super.setBackground(undimmedBackground); + super.setForeground(undimmedForeground); + } + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/components/ProgressBar.java b/runelite-client/src/main/java/net/runelite/client/ui/components/ProgressBar.java index c94845ee1e..0c36df1161 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/components/ProgressBar.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/components/ProgressBar.java @@ -29,7 +29,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import lombok.Setter; @@ -39,7 +38,7 @@ import net.runelite.client.ui.components.shadowlabel.JShadowedLabel; /** * A progress bar to be displayed underneath the GE offer item panels */ -public class ProgressBar extends JPanel +public class ProgressBar extends DimmableJPanel { @Setter private int maximumValue; @@ -50,11 +49,16 @@ public class ProgressBar extends JPanel private final JLabel leftLabel = new JShadowedLabel(); private final JLabel rightLabel = new JShadowedLabel(); private final JLabel centerLabel = new JShadowedLabel(); + private String centerLabelText = ""; + private String dimmedText = ""; public ProgressBar() { setLayout(new BorderLayout()); + // The background color should be overridden setBackground(Color.GREEN.darker()); + setForeground(Color.GREEN.brighter()); + setPreferredSize(new Dimension(100, 16)); leftLabel.setFont(FontManager.getRunescapeSmallFont()); @@ -70,10 +74,10 @@ public class ProgressBar extends JPanel centerLabel.setHorizontalAlignment(SwingConstants.CENTER); centerLabel.setBorder(new EmptyBorder(2, 0, 0, 0)); + // Adds components to be automatically redrawn when paintComponents is called add(leftLabel, BorderLayout.WEST); add(centerLabel, BorderLayout.CENTER); add(rightLabel, BorderLayout.EAST); - } @Override @@ -88,20 +92,45 @@ public class ProgressBar extends JPanel super.paintComponents(g); } + @Override + public void setDimmed(boolean dimmed) + { + super.setDimmed(dimmed); + + if (dimmed) + { + leftLabel.setForeground(Color.GRAY); + rightLabel.setForeground(Color.GRAY); + centerLabel.setText(dimmedText); + } + else + { + leftLabel.setForeground(Color.WHITE); + rightLabel.setForeground(Color.WHITE); + centerLabel.setText(centerLabelText); + } + } public void setLeftLabel(String txt) { - this.leftLabel.setText(txt); + leftLabel.setText(txt); } public void setRightLabel(String txt) { - this.rightLabel.setText(txt); + rightLabel.setText(txt); } public void setCenterLabel(String txt) { - this.centerLabel.setText(txt); + centerLabelText = txt; + centerLabel.setText(isDimmed() ? dimmedText : txt); + } + + public void setDimmedText(String txt) + { + dimmedText = txt; + centerLabel.setText(isDimmed() ? txt : centerLabelText); } public double getPercentage()