summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/StoneCollectionPanel.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-06 01:35:21 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-06 01:35:21 +0200
commit794e3573f6d96775b76cfeb1c833d343a52d2055 (patch)
tree7f1bb9d9cbdb9577910355774f9d7392f67921c1 /src/jrummikub/view/impl/StoneCollectionPanel.java
parent193e9247fac9d10e3c32cc7cacb65406ef9d19c8 (diff)
downloadJRummikub-794e3573f6d96775b76cfeb1c833d343a52d2055.tar
JRummikub-794e3573f6d96775b76cfeb1c833d343a52d2055.zip
A lot of view performance optimizations
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@162 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/StoneCollectionPanel.java')
-rw-r--r--src/jrummikub/view/impl/StoneCollectionPanel.java76
1 files changed, 52 insertions, 24 deletions
diff --git a/src/jrummikub/view/impl/StoneCollectionPanel.java b/src/jrummikub/view/impl/StoneCollectionPanel.java
index 253160c..493b299 100644
--- a/src/jrummikub/view/impl/StoneCollectionPanel.java
+++ b/src/jrummikub/view/impl/StoneCollectionPanel.java
@@ -1,14 +1,16 @@
package jrummikub.view.impl;
-import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import javax.swing.ImageIcon;
import javax.swing.border.EmptyBorder;
import jrummikub.model.Position;
@@ -22,7 +24,12 @@ import jrummikub.view.IStoneCollectionPanel;
@SuppressWarnings("serial")
class StoneCollectionPanel extends AbstractStonePanel implements
IStoneCollectionPanel {
- private final static int INSET = 7;
+ private final static ImageIcon BACKGROUND = new ImageIcon(
+ HandPanel.class.getResource("/jrummikub/resource/dark_felt.png"));
+ /**
+ * The width of the border of the collection panel
+ */
+ public final static int INSET = 7;
private Collection<Stone> selectedStones = Collections.emptyList();
@@ -31,13 +38,27 @@ class StoneCollectionPanel extends AbstractStonePanel implements
*/
StoneCollectionPanel() {
setOpaque(false);
- setVisible(false);
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
+
+ addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ rescale();
+ }
+ });
}
private void rescale() {
- setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2
- * INSET, getStonePainter().getStoneHeight() + 2 * INSET);
+ Insets insets = getInsets();
+ int height = getHeight() - insets.top - insets.bottom;
+
+ getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
+ repaint();
+
+ /*
+ * setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2
+ * INSET, getStonePainter().getStoneHeight() + 2 * INSET);
+ */
}
/**
@@ -46,12 +67,12 @@ class StoneCollectionPanel extends AbstractStonePanel implements
* @param height
* the height in pixels
*/
- void setStoneHeight(int height) {
- getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
-
- rescale();
- repaint();
- }
+ /*
+ * void setStoneHeight(int height) { getStonePainter().setScale(height *
+ * StonePainter.HEIGHT_SCALE);
+ *
+ * rescale(); repaint(); //}
+ */
/**
* Sets the stones to be shown in the collection
@@ -71,27 +92,34 @@ class StoneCollectionPanel extends AbstractStonePanel implements
}
setStones(stones);
+ repaint();
+ }
- if (selectedStones.isEmpty()) {
- setVisible(false);
- } else {
- rescale();
- setVisible(true);
+ @Override
+ protected Pair<Integer, Integer> getTranslation() {
+ int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
+ * INSET;
+ int x = (getWidth() - width) / 2;
- repaint();
- }
+ return new Pair<Integer, Integer>(x + INSET, INSET);
}
@Override
public void paintComponent(Graphics g1) {
- Insets insets = getInsets();
- int x = insets.left, y = insets.top, width = getWidth() - insets.left
- - insets.right, height = getHeight() - insets.top - insets.bottom;
- Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
+ int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
+ * INSET, height = getHeight();
+ int x = (getWidth() - width) / 2;
+ Graphics2D g = (Graphics2D) g1.create(x, 0, width, height);
if (!selectedStones.isEmpty()) {
- g1.setColor(new Color(0, 0, 0, 0.25f));
- g1.fillRoundRect(0, 0, getWidth(), getHeight(), INSET, INSET);
+ for (int xpos = 0; xpos < getWidth(); xpos += BACKGROUND.getIconWidth()) {
+ for (int ypos = 0; ypos < getHeight(); ypos += BACKGROUND
+ .getIconHeight()) {
+ BACKGROUND.paintIcon(this, g, xpos, ypos);
+ }
+ }
+
+ g.translate(INSET, INSET);
float xpos = 0;