Skip to content

Commit

Permalink
Add dimming UI to progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
LeviSchuck authored and Adam- committed Jul 18, 2018
1 parent 9fa8e12 commit aa8d2e5
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2018, Levi <[email protected]>
* 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand All @@ -39,7 +38,7 @@
/**
* 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;
Expand All @@ -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());
Expand All @@ -70,10 +74,10 @@ public ProgressBar()
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
Expand All @@ -88,20 +92,45 @@ public void paint(Graphics g)
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()
Expand Down

0 comments on commit aa8d2e5

Please sign in to comment.