Added minimal sizes and some more side panel code

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@485 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-06-19 18:31:03 +02:00
parent d0d349e5a8
commit 2db77addd9
3 changed files with 196 additions and 30 deletions

View file

@ -2,30 +2,40 @@ package jrummikub.view.impl;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage;
import javax.swing.BoxLayout; import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollBar;
import javax.swing.JViewport;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder; import javax.swing.border.MatteBorder;
import com.sun.org.apache.bcel.internal.generic.DMUL; @SuppressWarnings("serial")
class SidePanel extends JPanel { class SidePanel extends JPanel {
RuleInfoPanel ruleInfoPanel; RuleInfoPanel ruleInfoPanel;
PlayerListPanel playerListPanel; PlayerListPanel playerListPanel;
JScrollPane playerListScrollPane; BottomScrollPane playerListScrollPane;
public SidePanel() { public SidePanel() {
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
setBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK));
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
ruleInfoPanel = new RuleInfoPanel(); ruleInfoPanel = new RuleInfoPanel();
@ -33,6 +43,7 @@ class SidePanel extends JPanel {
c.gridy = 0; c.gridy = 0;
c.weightx = 1; c.weightx = 1;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
ruleInfoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK));
add(ruleInfoPanel, c); add(ruleInfoPanel, c);
playerListPanel = new PlayerListPanel(); playerListPanel = new PlayerListPanel();
@ -42,25 +53,152 @@ class SidePanel extends JPanel {
c.weightx = 1; c.weightx = 1;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
playerListScrollPane = new JScrollPane(playerListPanel); playerListScrollPane = new BottomScrollPane(playerListPanel);
playerListScrollPane.setViewportBorder(null); playerListScrollPane
.setBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK));
add(playerListScrollPane, c); add(playerListScrollPane, c);
} }
@SuppressWarnings("serial")
class BottomScrollPane extends JPanel {
JComponent content;
JViewport viewport;
JScrollBar scrollBar;
boolean scrollToBottom;
public BottomScrollPane(JComponent content) {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.weightx = 1;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
viewport = new JViewport();
add(viewport, c);
this.content = content;
viewport.setView(content);
scrollBar = new JScrollBar(JScrollBar.VERTICAL);
scrollBar.setBorder(new LineBorder(Color.BLACK, 0));
c.weightx = 0;
add(scrollBar, c);
ComponentAdapter resizeListener = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
onResize();
}
};
addComponentListener(resizeListener);
content.addComponentListener(resizeListener);
scrollBar.addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent arg0) {
scrollViewport();
}
});
scrollToBottom();
}
public void scrollToBottom() {
scrollToBottom = true;
}
private void onResize() {
int oldValue = 0;
if (!scrollToBottom) {
oldValue = scrollBar.getMaximum() - scrollBar.getVisibleAmount() - scrollBar.getValue();
}
scrollToBottom = false;
int max = content.getHeight();
int extent = viewport.getHeight();
int value = Math.max(0, max - extent - oldValue);
scrollBar.setVisible(extent != max);
scrollBar.setValues(value, extent, 0, max);
scrollViewport();
}
private void scrollViewport() {
viewport.setViewPosition(new Point(0, scrollBar.getValue()));
}
}
class RuleInfoPanel extends JPanel { class RuleInfoPanel extends JPanel {
JLabel dummy; JLabel ruleInfo;
JCheckBox showRules;
public RuleInfoPanel() { public RuleInfoPanel() {
setLayout(new GridLayout(1, 1)); setLayout(new GridBagLayout());
setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY)); GridBagConstraints c = new GridBagConstraints();
dummy = new JLabel( showRules = new JCheckBox("Regeln");
showRules.setSelected(true);
c.gridx = 0;
c.weightx = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.WEST;
setupTriangleIcons(showRules);
c.insets = new Insets(0, 4, 0, 4);
add(showRules, c);
showRules.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg) {
boolean selected = showRules.isSelected();
ruleInfo.setVisible(selected);
showRules.setPressedIcon(selected ? showRules.getIcon()
: showRules.getSelectedIcon());
}
});
ruleInfo = new JLabel(
"<html><center>All work and no play<br>makes Jack a dull boy"); "<html><center>All work and no play<br>makes Jack a dull boy");
dummy.setHorizontalAlignment(JLabel.CENTER); ruleInfo.setHorizontalAlignment(JLabel.CENTER);
add(dummy); add(ruleInfo, c);
// setPreferredSize(new Dimension(1, 50));
} }
private void setupTriangleIcons(JCheckBox test) {
BufferedImage img1 = new BufferedImage(8, 8,
BufferedImage.TYPE_3BYTE_BGR);
BufferedImage img2 = new BufferedImage(8, 8,
BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = img1.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getBackground());
g.fillRect(0, 0, 8, 8);
g.setColor(Color.BLACK);
Polygon p = new Polygon();
p.addPoint(0, 0);
p.addPoint(8, 4);
p.addPoint(0, 8);
g.fillPolygon(p);
g = img2.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getBackground());
g.fillRect(0, 0, 8, 8);
g.setColor(Color.BLACK);
p = new Polygon();
p.addPoint(0, 0);
p.addPoint(4, 8);
p.addPoint(8, 0);
g.fillPolygon(p);
test.setIcon(new ImageIcon(img1));
test.setSelectedIcon(new ImageIcon(img2));
test.setPressedIcon(new ImageIcon(img1));
test.setRolloverEnabled(false);
test.setFocusPainted(false);
}
} }
class PlayerListItem extends JPanel { class PlayerListItem extends JPanel {
@ -68,7 +206,6 @@ class SidePanel extends JPanel {
public PlayerListItem() { public PlayerListItem() {
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
setBorder(new MatteBorder(1, 0, 0, 0, Color.GRAY));
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.gridx = 0; c.gridx = 0;
@ -87,11 +224,13 @@ class SidePanel extends JPanel {
JPanel startSpacer; JPanel startSpacer;
public PlayerListPanel() { public PlayerListPanel() {
setBackground(Color.RED); setBackground(Color.GRAY);
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
startSpacer = new JPanel(); startSpacer = new JPanel();
startSpacer.setBackground(Color.GRAY);
startSpacer.setPreferredSize(new Dimension(0, 0));
c.gridx = 0; c.gridx = 0;
c.gridy = 0; c.gridy = 0;
c.weightx = 1; c.weightx = 1;
@ -101,12 +240,19 @@ class SidePanel extends JPanel {
c.weighty = 0; c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
for (int i = 1; i <= 16; i++) { for (int i = 1; i <= 15; i++) {
c.gridx = 0; c.gridx = 0;
c.gridy = i; c.gridy = i;
c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0);
add(new PlayerListItem(), c); add(new PlayerListItem(), c);
} }
} }
@Override
public Dimension getPreferredSize() {
Dimension oldPref = super.getPreferredSize();
return new Dimension(0, oldPref.height);
}
} }
} }

View file

@ -360,7 +360,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
hoveredConnectorArea); hoveredConnectorArea);
} }
if (pauseMode) { if (pauseMode) {
g.setTransform(oldTransform);
return; return;
} }

View file

@ -1,6 +1,7 @@
package jrummikub.view.impl; package jrummikub.view.impl;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
@ -47,8 +48,8 @@ import jrummikub.view.IView;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class View extends JFrame implements IView { public class View extends JFrame implements IView {
private final static float PLAYER_PANEL_RATIO = 0.14f; private final static float PLAYER_PANEL_RATIO = 0.14f;
private final static int PLAYER_PANEL_BORDER_WIDTH = 1; private final static int PLAYER_PANEL_MAX_HEIGHT = 180;
private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH; private final static int TABLE_BORDER_WIDTH = 1;
private JLayeredPane layeredPane; private JLayeredPane layeredPane;
private JPanel mainLayer; private JPanel mainLayer;
@ -254,6 +255,7 @@ public class View extends JFrame implements IView {
setLayout(null); setLayout(null);
setSize(1000, 700); setSize(1000, 700);
setMinimumSize(new Dimension(750, 550));
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
createFileChooser(); createFileChooser();
@ -322,10 +324,10 @@ public class View extends JFrame implements IView {
table = new TablePanel(); table = new TablePanel();
mainLayer.add(table); mainLayer.add(table);
table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
Color.BLACK));
playerPanel = new PlayerPanel(); playerPanel = new PlayerPanel();
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
0, Color.BLACK));
mainLayer.add(playerPanel); mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel(); startTurnPanel = new StartTurnPanel();
@ -342,6 +344,8 @@ public class View extends JFrame implements IView {
sidePanel = new SidePanel(); sidePanel = new SidePanel();
mainLayer.add(sidePanel); mainLayer.add(sidePanel);
sidePanel.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
Color.BLACK));
} }
@Override @Override
@ -360,8 +364,7 @@ public class View extends JFrame implements IView {
mainLayer.setBounds(0, 0, width, height); mainLayer.setBounds(0, 0, width, height);
int playerPanelHeight = even(Math.pow((double) width * width * height, int playerPanelHeight = even(Math.pow((double) width * width * height,
1 / 3.0) * PLAYER_PANEL_RATIO) 1 / 3.0) * PLAYER_PANEL_RATIO);
+ PLAYER_PANEL_BORDER_WIDTH;
if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT) if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT; playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
@ -378,10 +381,25 @@ public class View extends JFrame implements IView {
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight); startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
pausePanel.setBounds(0, tableHeight, width, playerPanelHeight); pausePanel.setBounds(0, tableHeight, width, playerPanelHeight);
winPanel.setBounds(0, tableHeight, width, playerPanelHeight); winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2);
scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2);
loginPanel.setBounds(width / 3, height / 3, width / 3, height / 3); rescaleSubpanel(settingsPanel, 1 / 2.0, 1/ 2.0, 475, 300);
gameListPanel.setBounds(width / 4, height / 4, width / 2, height / 2); rescaleSubpanel(scorePanel, 3 / 4.0, 1/ 2.0, 450, 300);
rescaleSubpanel(loginPanel, 1 / 3.0, 1/ 3.0, 200, 200);
rescaleSubpanel(gameListPanel, 1 / 2.0, 1/ 2.0, 475, 300);
}
private void rescaleSubpanel(JPanel sub, double widthFactor,
double heightFactor, int minWidth, int minHeight) {
int width = getContentPane().getWidth(), height = getContentPane()
.getHeight();
int panelWidth = Math.max(minWidth, (int) (width * widthFactor));
int panelHeight = Math.max(minHeight, (int) (height * heightFactor));
int x = (width - panelWidth) / 2;
int y = (height - panelHeight) / 2;
sub.setBounds(x, y, panelWidth, panelHeight);
} }
@Override @Override