diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-19 18:31:03 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-19 18:31:03 +0200 |
commit | 2db77addd9082e33dda6c4ba5e957a6d7c6fa877 (patch) | |
tree | f47c079c8e1ac14c52048d882a46ab6bc6f5bbbf /src | |
parent | d0d349e5a8cd1d48bfe50fc93e762b26ee17a39a (diff) | |
download | JRummikub-2db77addd9082e33dda6c4ba5e957a6d7c6fa877.tar JRummikub-2db77addd9082e33dda6c4ba5e957a6d7c6fa877.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/view/impl/SidePanel.java | 186 | ||||
-rw-r--r-- | src/jrummikub/view/impl/TablePanel.java | 2 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 38 |
3 files changed, 196 insertions, 30 deletions
diff --git a/src/jrummikub/view/impl/SidePanel.java b/src/jrummikub/view/impl/SidePanel.java index 637ac76..3b7c2c9 100644 --- a/src/jrummikub/view/impl/SidePanel.java +++ b/src/jrummikub/view/impl/SidePanel.java @@ -2,30 +2,40 @@ package jrummikub.view.impl; import java.awt.Color; import java.awt.Dimension; +import java.awt.Graphics2D; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.GridLayout; 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.JLabel; 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 com.sun.org.apache.bcel.internal.generic.DMUL; - +@SuppressWarnings("serial") class SidePanel extends JPanel { RuleInfoPanel ruleInfoPanel; PlayerListPanel playerListPanel; - JScrollPane playerListScrollPane; + BottomScrollPane playerListScrollPane; public SidePanel() { setLayout(new GridBagLayout()); - setBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK)); - GridBagConstraints c = new GridBagConstraints(); ruleInfoPanel = new RuleInfoPanel(); @@ -33,6 +43,7 @@ class SidePanel extends JPanel { c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; + ruleInfoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK)); add(ruleInfoPanel, c); playerListPanel = new PlayerListPanel(); @@ -42,25 +53,152 @@ class SidePanel extends JPanel { c.weightx = 1; c.fill = GridBagConstraints.BOTH; - playerListScrollPane = new JScrollPane(playerListPanel); - playerListScrollPane.setViewportBorder(null); + playerListScrollPane = new BottomScrollPane(playerListPanel); + playerListScrollPane + .setBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK)); + 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 { - JLabel dummy; + JLabel ruleInfo; + JCheckBox showRules; public RuleInfoPanel() { - setLayout(new GridLayout(1, 1)); - setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY)); - dummy = new JLabel( + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + 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"); - dummy.setHorizontalAlignment(JLabel.CENTER); - add(dummy); - // setPreferredSize(new Dimension(1, 50)); + ruleInfo.setHorizontalAlignment(JLabel.CENTER); + add(ruleInfo, c); } + 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 { @@ -68,7 +206,6 @@ class SidePanel extends JPanel { public PlayerListItem() { setLayout(new GridBagLayout()); - setBorder(new MatteBorder(1, 0, 0, 0, Color.GRAY)); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; @@ -87,11 +224,13 @@ class SidePanel extends JPanel { JPanel startSpacer; public PlayerListPanel() { - setBackground(Color.RED); + setBackground(Color.GRAY); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); startSpacer = new JPanel(); + startSpacer.setBackground(Color.GRAY); + startSpacer.setPreferredSize(new Dimension(0, 0)); c.gridx = 0; c.gridy = 0; c.weightx = 1; @@ -101,12 +240,19 @@ class SidePanel extends JPanel { c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; - for (int i = 1; i <= 16; i++) { + for (int i = 1; i <= 15; i++) { c.gridx = 0; c.gridy = i; + c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0); add(new PlayerListItem(), c); } } + + @Override + public Dimension getPreferredSize() { + Dimension oldPref = super.getPreferredSize(); + return new Dimension(0, oldPref.height); + } } } diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java index 4b7ab9f..563ad3b 100644 --- a/src/jrummikub/view/impl/TablePanel.java +++ b/src/jrummikub/view/impl/TablePanel.java @@ -360,7 +360,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { hoveredConnectorArea); } + if (pauseMode) { + g.setTransform(oldTransform); return; } diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index cb9bd93..2bfee8e 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -1,6 +1,7 @@ package jrummikub.view.impl; import java.awt.Color; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; @@ -47,8 +48,8 @@ import jrummikub.view.IView; @SuppressWarnings("serial") public class View extends JFrame implements IView { 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 + PLAYER_PANEL_BORDER_WIDTH; + private final static int PLAYER_PANEL_MAX_HEIGHT = 180; + private final static int TABLE_BORDER_WIDTH = 1; private JLayeredPane layeredPane; private JPanel mainLayer; @@ -254,6 +255,7 @@ public class View extends JFrame implements IView { setLayout(null); setSize(1000, 700); + setMinimumSize(new Dimension(750, 550)); setDefaultCloseOperation(EXIT_ON_CLOSE); createFileChooser(); @@ -322,10 +324,10 @@ public class View extends JFrame implements IView { table = new TablePanel(); mainLayer.add(table); + table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, + Color.BLACK)); playerPanel = new PlayerPanel(); - playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, - 0, Color.BLACK)); mainLayer.add(playerPanel); startTurnPanel = new StartTurnPanel(); @@ -342,6 +344,8 @@ public class View extends JFrame implements IView { sidePanel = new SidePanel(); mainLayer.add(sidePanel); + sidePanel.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, + Color.BLACK)); } @Override @@ -360,8 +364,7 @@ public class View extends JFrame implements IView { mainLayer.setBounds(0, 0, width, height); int playerPanelHeight = even(Math.pow((double) width * width * height, - 1 / 3.0) * PLAYER_PANEL_RATIO) - + PLAYER_PANEL_BORDER_WIDTH; + 1 / 3.0) * PLAYER_PANEL_RATIO); if (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); pausePanel.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); - gameListPanel.setBounds(width / 4, height / 4, width / 2, height / 2); + + + rescaleSubpanel(settingsPanel, 1 / 2.0, 1/ 2.0, 475, 300); + 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 |