Rescale collection; add bottom margin to table for collection
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@99 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
51f70cafe3
commit
a274c2b02e
2 changed files with 67 additions and 48 deletions
|
@ -22,7 +22,6 @@ import jrummikub.view.IStoneCollectionPanel;
|
||||||
class StoneCollectionPanel extends AbstractStonePanel implements
|
class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
IStoneCollectionPanel {
|
IStoneCollectionPanel {
|
||||||
private final static int INSET = 7;
|
private final static int INSET = 7;
|
||||||
private final static float STONE_SCALE = 1.1f;
|
|
||||||
|
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
|
@ -30,13 +29,29 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
* Creates a new StoneCollection instance
|
* Creates a new StoneCollection instance
|
||||||
*/
|
*/
|
||||||
StoneCollectionPanel() {
|
StoneCollectionPanel() {
|
||||||
super(STONE_SCALE);
|
|
||||||
|
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
|
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rescale() {
|
||||||
|
setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
||||||
|
* INSET, getStonePainter().getStoneHeight() + 2 * INSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the height to paint the collected stones in
|
||||||
|
*
|
||||||
|
* @param height
|
||||||
|
* the height in pixels
|
||||||
|
*/
|
||||||
|
void setStoneHeight(int height) {
|
||||||
|
getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
|
||||||
|
|
||||||
|
rescale();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the stones to be shown in the collection
|
* Sets the stones to be shown in the collection
|
||||||
*
|
*
|
||||||
|
@ -59,8 +74,7 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
if (selectedStones.isEmpty()) {
|
if (selectedStones.isEmpty()) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
rescale();
|
||||||
* INSET, getStonePainter().getStoneHeight() + 2 * INSET);
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
|
|
|
@ -39,6 +39,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
private final static float HORIZONTAL_MARGIN = 1.5f;
|
private final static float HORIZONTAL_MARGIN = 1.5f;
|
||||||
private final static float VERTICAL_MARGIN = 1;
|
private final static float VERTICAL_MARGIN = 1;
|
||||||
private final static float CONNECTOR_WIDTH = 0.25f;
|
private final static float CONNECTOR_WIDTH = 0.25f;
|
||||||
|
private final float COLLECTION_RATIO = 0.1f;
|
||||||
private final int COLLECTION_GAP = 5;
|
private final int COLLECTION_GAP = 5;
|
||||||
|
|
||||||
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
||||||
|
@ -111,6 +112,46 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Table instance
|
||||||
|
*/
|
||||||
|
TablePanel() {
|
||||||
|
setLayout(null);
|
||||||
|
|
||||||
|
leftPlayerLabel = new JLabel();
|
||||||
|
leftPlayerLabel.setForeground(Color.WHITE);
|
||||||
|
leftPlayerLabel.setHorizontalAlignment(JLabel.LEFT);
|
||||||
|
leftPlayerLabel.setHorizontalTextPosition(JLabel.LEFT);
|
||||||
|
add(leftPlayerLabel);
|
||||||
|
|
||||||
|
topPlayerLabel = new JLabel();
|
||||||
|
topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||||
|
topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||||
|
topPlayerLabel.setVerticalAlignment(JLabel.TOP);
|
||||||
|
topPlayerLabel.setVerticalTextPosition(JLabel.TOP);
|
||||||
|
topPlayerLabel.setForeground(Color.WHITE);
|
||||||
|
add(topPlayerLabel);
|
||||||
|
|
||||||
|
rightPlayerLabel = new JLabel();
|
||||||
|
rightPlayerLabel.setForeground(Color.WHITE);
|
||||||
|
rightPlayerLabel.setHorizontalAlignment(JLabel.RIGHT);
|
||||||
|
rightPlayerLabel.setHorizontalTextPosition(JLabel.RIGHT);
|
||||||
|
add(rightPlayerLabel);
|
||||||
|
|
||||||
|
stoneCollection = new StoneCollectionPanel();
|
||||||
|
add(stoneCollection);
|
||||||
|
|
||||||
|
ComponentListener rescaleListener = new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
rescale();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
addComponentListener(rescaleListener);
|
||||||
|
stoneCollection.addComponentListener(rescaleListener);
|
||||||
|
}
|
||||||
|
|
||||||
private Rectangle2D calculateTableExtent() {
|
private Rectangle2D calculateTableExtent() {
|
||||||
float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
|
float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
|
||||||
float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
|
float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
|
||||||
|
@ -153,54 +194,16 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
|
|
||||||
float widthScale = width / (float) extent.getWidth()
|
float widthScale = width / (float) extent.getWidth()
|
||||||
* StonePainter.WIDTH_SCALE;
|
* StonePainter.WIDTH_SCALE;
|
||||||
float heightScale = height / (float) extent.getHeight()
|
float heightScale = height * (1 - COLLECTION_RATIO)
|
||||||
* StonePainter.HEIGHT_SCALE;
|
/ (float) extent.getHeight() * StonePainter.HEIGHT_SCALE;
|
||||||
|
|
||||||
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
||||||
|
|
||||||
|
stoneCollection.setStoneHeight((int) (height * COLLECTION_RATIO));
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Table instance
|
|
||||||
*/
|
|
||||||
TablePanel() {
|
|
||||||
setLayout(null);
|
|
||||||
|
|
||||||
leftPlayerLabel = new JLabel();
|
|
||||||
leftPlayerLabel.setForeground(Color.WHITE);
|
|
||||||
leftPlayerLabel.setHorizontalAlignment(JLabel.LEFT);
|
|
||||||
leftPlayerLabel.setHorizontalTextPosition(JLabel.LEFT);
|
|
||||||
add(leftPlayerLabel);
|
|
||||||
|
|
||||||
topPlayerLabel = new JLabel();
|
|
||||||
topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
|
|
||||||
topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
|
|
||||||
topPlayerLabel.setVerticalAlignment(JLabel.TOP);
|
|
||||||
topPlayerLabel.setVerticalTextPosition(JLabel.TOP);
|
|
||||||
topPlayerLabel.setForeground(Color.WHITE);
|
|
||||||
add(topPlayerLabel);
|
|
||||||
|
|
||||||
rightPlayerLabel = new JLabel();
|
|
||||||
rightPlayerLabel.setForeground(Color.WHITE);
|
|
||||||
rightPlayerLabel.setHorizontalAlignment(JLabel.RIGHT);
|
|
||||||
rightPlayerLabel.setHorizontalTextPosition(JLabel.RIGHT);
|
|
||||||
add(rightPlayerLabel);
|
|
||||||
|
|
||||||
stoneCollection = new StoneCollectionPanel();
|
|
||||||
add(stoneCollection);
|
|
||||||
|
|
||||||
ComponentListener rescaleListener = new ComponentAdapter() {
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {
|
|
||||||
rescale();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
addComponentListener(rescaleListener);
|
|
||||||
stoneCollection.addComponentListener(rescaleListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean handleOtherClickEvent(Position pos) {
|
protected boolean handleOtherClickEvent(Position pos) {
|
||||||
for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
|
for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
|
||||||
Position p = entry.getValue();
|
Position p = entry.getValue();
|
||||||
|
@ -235,7 +238,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
Rectangle2D extent = calculateTableExtent();
|
Rectangle2D extent = calculateTableExtent();
|
||||||
|
|
||||||
return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
|
return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
|
||||||
* stoneWidth), (int) (height / 2 - extent.getCenterY() * stoneHeight));
|
* stoneWidth),
|
||||||
|
(int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent.getCenterY()
|
||||||
|
* stoneHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) {
|
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) {
|
||||||
|
|
Reference in a new issue