diff options
Diffstat (limited to 'src/jrummikub/view/impl/PlayerPanel.java')
-rw-r--r-- | src/jrummikub/view/impl/PlayerPanel.java | 123 |
1 files changed, 62 insertions, 61 deletions
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index 6bc3d09..1d62aab 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -107,40 +107,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { }); leftPanel.add(sortByColorButton); - leftPanel.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - Insets insets = leftPanel.getInsets(); - int x = insets.left, y = insets.top, width = leftPanel.getWidth() - - insets.left - insets.right, height = leftPanel.getHeight() - - insets.top - insets.bottom; - - if (width > SIDE_PANEL_MAX_WIDTH) { - x += (width - SIDE_PANEL_MAX_WIDTH) / 4; - width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2; - } - - int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT); - int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2; - int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight; - float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; - if (fontSize > MAX_BUTTON_FONT_SIZE) - fontSize = MAX_BUTTON_FONT_SIZE; - - currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight); - sortByNumberButton.setBounds(x, y + firstLineHeight - + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); - sortByColorButton - .setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y - + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, - buttonHeight); - - sortByNumberButton.setFont(sortByNumberButton.getFont().deriveFont( - fontSize)); - sortByColorButton.setFont(sortByColorButton.getFont().deriveFont( - fontSize)); - } - }); + leftPanel.addComponentListener(new LeftPanelResizeListener()); } private void createRightPanel() { @@ -164,33 +131,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { rightPanel.add(endTurnButton); - rightPanel.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - Insets insets = rightPanel.getInsets(); - int x = insets.left, y = insets.top, width = rightPanel.getWidth() - - insets.left - insets.right, height = rightPanel.getHeight() - - insets.top - insets.bottom; - - if (width > SIDE_PANEL_MAX_WIDTH) { - x += (width - SIDE_PANEL_MAX_WIDTH) / 4; - width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2; - } - - int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT); - int buttonWidth = width; - int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight; - float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; - if (fontSize > MAX_BUTTON_FONT_SIZE) - fontSize = MAX_BUTTON_FONT_SIZE; - - timeBar.setBounds(x, y, width, firstLineHeight); - endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, - buttonWidth, buttonHeight); - endTurnButton.setFont(endTurnButton.getFont().deriveFont( - fontSize)); - } - }); + rightPanel.addComponentListener(new RightPanelResizeListener()); } private void rescale() { @@ -232,4 +173,64 @@ class PlayerPanel extends JPanel implements IPlayerPanel { addComponentListener(rescaleListener); board.addComponentListener(rescaleListener); } + + private class LeftPanelResizeListener extends ComponentAdapter { + @Override + public void componentResized(ComponentEvent e) { + Insets insets = leftPanel.getInsets(); + int x = insets.left, y = insets.top, width = leftPanel.getWidth() + - insets.left - insets.right, height = leftPanel.getHeight() + - insets.top - insets.bottom; + + if (width > SIDE_PANEL_MAX_WIDTH) { + x += (width - SIDE_PANEL_MAX_WIDTH) / 4; + width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2; + } + + int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT); + int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2; + int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight; + float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; + if (fontSize > MAX_BUTTON_FONT_SIZE) + fontSize = MAX_BUTTON_FONT_SIZE; + + currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight); + sortByNumberButton.setBounds(x, y + firstLineHeight + + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); + sortByColorButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y + + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); + + sortByNumberButton.setFont(sortByNumberButton.getFont().deriveFont( + fontSize)); + sortByColorButton.setFont(sortByColorButton.getFont() + .deriveFont(fontSize)); + } + } + + private class RightPanelResizeListener extends ComponentAdapter { + @Override + public void componentResized(ComponentEvent e) { + Insets insets = rightPanel.getInsets(); + int x = insets.left, y = insets.top, width = rightPanel.getWidth() + - insets.left - insets.right, height = rightPanel.getHeight() + - insets.top - insets.bottom; + + if (width > SIDE_PANEL_MAX_WIDTH) { + x += (width - SIDE_PANEL_MAX_WIDTH) / 4; + width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2; + } + + int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT); + int buttonWidth = width; + int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight; + float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; + if (fontSize > MAX_BUTTON_FONT_SIZE) + fontSize = MAX_BUTTON_FONT_SIZE; + + timeBar.setBounds(x, y, width, firstLineHeight); + endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, + buttonWidth, buttonHeight); + endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize)); + } + } } |