ThinProgressBar: Manually paint
the old method caused it to expand randomly, which would make it show an abnormally high value. This also makes update not required, fixing the bug where it wouldn't render correctly when update was called after a layout was invalidated, but before it was recalculated.
This commit is contained in:
@@ -226,7 +226,6 @@ public class GrandExchangeOfferSlot extends JPanel
|
||||
progressBar.setForeground(getProgressColor(newOffer));
|
||||
progressBar.setMaximumValue(newOffer.getTotalQuantity());
|
||||
progressBar.setValue(newOffer.getQuantitySold());
|
||||
progressBar.update();
|
||||
|
||||
/* Couldn't set the tooltip for the container panel as the children override it, so I'm setting
|
||||
* the tooltips on the children instead. */
|
||||
|
||||
@@ -250,7 +250,6 @@ public class FarmingTabPanel extends TabContentPanel
|
||||
panel.getProgress().setForeground(state.getCropState().getColor().darker());
|
||||
panel.getProgress().setMaximumValue(stages - 1);
|
||||
panel.getProgress().setValue(stage);
|
||||
panel.getProgress().update();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -144,8 +144,6 @@ public class BirdHouseTabPanel extends TabContentPanel
|
||||
panel.getEstimate().setText("Unknown");
|
||||
break;
|
||||
}
|
||||
|
||||
panel.getProgress().update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,69 +25,71 @@
|
||||
*/
|
||||
package net.runelite.client.ui.components;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JPanel;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* A progress bar to be displayed underneath the GE offer item panels
|
||||
*/
|
||||
public class ThinProgressBar extends JPanel
|
||||
{
|
||||
@Setter
|
||||
private int maximumValue;
|
||||
@Getter
|
||||
private int maximumValue = 1;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private int value;
|
||||
|
||||
private final JPanel topBar = new JPanel();
|
||||
|
||||
public ThinProgressBar()
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(Color.GREEN.darker());
|
||||
|
||||
topBar.setPreferredSize(new Dimension(100, 4));
|
||||
topBar.setBackground(ColorScheme.PROGRESS_COMPLETE_COLOR);
|
||||
|
||||
add(topBar, BorderLayout.WEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI based on the percentage progress
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
double percentage = getPercentage();
|
||||
int topWidth = (int) (getSize().width * (percentage / 100));
|
||||
|
||||
topBar.setPreferredSize(new Dimension(topWidth, 4));
|
||||
topBar.repaint();
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
setForeground(Color.GREEN);
|
||||
setMaximumSize(new Dimension(Integer.MAX_VALUE, 4));
|
||||
setMinimumSize(new Dimension(0, 4));
|
||||
setPreferredSize(new Dimension(0, 4));
|
||||
setSize(new Dimension(0, 4));
|
||||
setOpaque(true);
|
||||
}
|
||||
|
||||
public double getPercentage()
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (value * 100) / maximumValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForeground(Color color)
|
||||
{
|
||||
if (topBar != null)
|
||||
{
|
||||
topBar.setBackground(color);
|
||||
}
|
||||
super.setForeground(color);
|
||||
setBackground(color.darker());
|
||||
}
|
||||
|
||||
public void setMaximumValue(int maximumValue)
|
||||
{
|
||||
if (maximumValue < 1)
|
||||
{
|
||||
maximumValue = 1;
|
||||
}
|
||||
this.maximumValue = maximumValue;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setValue(int value)
|
||||
{
|
||||
this.value = value;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
int div = (value * w) / maximumValue;
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(div, 0, w, h);
|
||||
g.setColor(getForeground());
|
||||
g.fillRect(0, 0, div, h);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user