Simplify Color & Rectangle handling, fix bug.

We can just keep Color in its ARGB format and have a single static brightness()
helper. Reactangle grew a union method which allows us to avoid AWT's Rectangle
entirely.

stringsToList() needed to return null for null array input, and I went ahead
and used Arrays.asList while I was in there because we know the provenance of
the input array, no one will mutate it.
This commit is contained in:
Michael Bayne
2018-09-05 16:06:27 -07:00
parent f8efdea9ed
commit 108f87d4c7
9 changed files with 63 additions and 206 deletions
@@ -10,7 +10,6 @@ import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
@@ -888,9 +887,8 @@ public abstract class Getdown extends Thread
_status.setSize(size);
_layers.setPreferredSize(size);
Rectangle patchNotes = new Rectangle(_ifc.patchNotes.x, _ifc.patchNotes.y,
_ifc.patchNotes.width, _ifc.patchNotes.height);
_patchNotes.setBounds(patchNotes);
_patchNotes.setBounds(_ifc.patchNotes.x, _ifc.patchNotes.y,
_ifc.patchNotes.width, _ifc.patchNotes.height);
_patchNotes.setVisible(false);
// we were displaying progress while the UI wasn't up. Now that it is, whatever progress
@@ -142,7 +142,7 @@ public class GetdownApp
});
_frame.setUndecorated(_ifc.hideDecorations);
try {
_frame.setBackground(new Color(_ifc.background.rgba(), true));
_frame.setBackground(new Color(_ifc.background, true));
} catch (UnsupportedOperationException e) {
log.warning("Failed to set background", e);
} catch (IllegalComponentStateException e) {
@@ -49,9 +49,10 @@ public class RotatingBackgrounds
minDisplayTime = new int[backgrounds.size()];
images = new Image[backgrounds.size()];
for (int ii = 0; ii < backgrounds.size(); ii++) {
String[] pieces = backgrounds.get(ii).split(";");
String background = backgrounds.get(ii);
String[] pieces = background.split(";");
if (pieces.length != 2) {
log.warning("Unable to parse background image '" + backgrounds.get(ii) + "'");
log.warning("Unable to parse background image '" + background + "'");
makeEmpty();
return;
}
@@ -59,8 +60,7 @@ public class RotatingBackgrounds
try {
minDisplayTime[ii] = Integer.parseInt(pieces[1]);
} catch (NumberFormatException e) {
log.warning("Unable to parse background image display time '" +
backgrounds.get(ii) + "'");
log.warning("Unable to parse background image display time '" + background + "'");
makeEmpty();
return;
}
@@ -11,7 +11,6 @@ import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
@@ -30,6 +29,7 @@ import com.samskivert.util.StringUtil;
import com.samskivert.util.Throttle;
import com.threerings.getdown.data.Application.UpdateInterface;
import com.threerings.getdown.util.Rectangle;
import static com.threerings.getdown.Log.log;
@@ -64,9 +64,7 @@ public class StatusPanel extends JComponent
int width = img == null ? -1 : img.getWidth(this);
int height = img == null ? -1 : img.getHeight(this);
if (width == -1 || height == -1) {
Rectangle progress = new Rectangle(ifc.progress.x, ifc.progress.y, ifc.progress.width, ifc.progress.height);
Rectangle status = new Rectangle(ifc.status.x, ifc.status.y, ifc.status.width, ifc.status.height);
Rectangle bounds = progress.union(status);
Rectangle bounds = ifc.progress.union(ifc.status);
// assume the x inset defines the frame padding; add it on the left, right, and bottom
_psize = new Dimension(bounds.x + bounds.width + bounds.x,
bounds.y + bounds.height + bounds.x);
@@ -109,7 +107,7 @@ public class StatusPanel extends JComponent
_progress = percent;
if (!_ifc.hideProgressText) {
String msg = MessageFormat.format(get("m.complete"), percent);
_newplab = createLabel(msg, new Color(_ifc.progressText.rgba(), true));
_newplab = createLabel(msg, new Color(_ifc.progressText, true));
}
needsRepaint = true;
}
@@ -134,7 +132,7 @@ public class StatusPanel extends JComponent
int minutes = (int)(remaining / 60), seconds = (int)(remaining % 60);
String remstr = minutes + ":" + ((seconds < 10) ? "0" : "") + seconds;
String msg = MessageFormat.format(get("m.remain"), remstr);
_newrlab = createLabel(msg, new Color(_ifc.statusText.rgba(), true));
_newrlab = createLabel(msg, new Color(_ifc.statusText, true));
}
needsRepaint = true;
@@ -228,7 +226,7 @@ public class StatusPanel extends JComponent
gfx.drawImage(_barimg, _ifc.progress.x, _ifc.progress.y, null);
gfx.setClip(null);
} else {
gfx.setColor(new Color(_ifc.progressBar.rgba(), true));
gfx.setColor(new Color(_ifc.progressBar, true));
gfx.fillRect(_ifc.progress.x, _ifc.progress.y,
_progress * _ifc.progress.width / 100,
_ifc.progress.height);
@@ -272,7 +270,7 @@ public class StatusPanel extends JComponent
status += " .";
}
}
_newlab = createLabel(status, new Color(_ifc.statusText.rgba(), true));
_newlab = createLabel(status, new Color(_ifc.statusText, true));
// set the width of the label to the width specified
int width = _ifc.status.width;
if (width == 0) {
@@ -306,8 +304,8 @@ public class StatusPanel extends JComponent
protected Label createLabel (String text, Color color)
{
Label label = new Label(text, color, FONT);
if (_ifc.textShadow != null) {
label.setAlternateColor(new Color(_ifc.textShadow.rgba(), true));
if (_ifc.textShadow != 0) {
label.setAlternateColor(new Color(_ifc.textShadow, true));
label.setStyle(LabelStyleConstants.SHADOW);
}
return label;