Added foreground image alignment functionality to FPanel.

This commit is contained in:
Doublestrike
2012-02-22 06:15:34 +00:00
parent 41266c279d
commit 11be91cb86

View File

@@ -24,9 +24,12 @@ import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import forge.Command;
@@ -54,6 +57,7 @@ public class FPanel extends JPanel {
private Color borderColor = FSkin.getColor(FSkin.Colors.CLR_BORDERS);
private boolean borderToggle = true;
private int cornerDiameter = 20;
private int foregroundAlign = SwingConstants.CENTER;
// Mouse handling
private boolean selected, hovered;
@@ -144,6 +148,24 @@ public class FPanel extends JPanel {
setForegroundImage(ii0.getImage());
}
/** Aligns NON-STRETCHED foreground image.
* Must use SwingConstants.
* @param i0   int
*/
public void setForegroundAlign(final int i0) {
// Only implemented for BOTTOM at present.
// More implementations can be added as necessary.
// See drawForegroundScaled().
final List<Integer> implemented = new ArrayList<Integer>();
implemented.add(SwingConstants.BOTTOM);
implemented.add(SwingConstants.CENTER);
if (!implemented.contains(i0)) { throw new IllegalArgumentException(); }
this.foregroundAlign = i0;
implemented.clear();
}
/** @param bool0 &emsp; boolean, stretch the foreground to fit */
public void setForegroundStretch(final boolean bool0) {
this.foregroundStretch = bool0;
@@ -268,8 +290,16 @@ public class FPanel extends JPanel {
}
// Scaling step 3: Center image in panel
tempX = (int) ((pnlW - scaledW) / 2);
tempY = (int) ((pnlH - scaledH) / 2);
switch(this.foregroundAlign) {
case SwingConstants.BOTTOM:
tempX = (int) ((pnlW - scaledW) / 2);
tempY = pnlH - scaledH;
break;
default:
tempX = (int) ((pnlW - scaledW) / 2);
tempY = (int) ((pnlH - scaledH) / 2);
}
g2d0.drawImage(foregroundImage, tempX, tempY, scaledW + tempX, scaledH + tempY, 0, 0, imgW, imgH, null);
}