chatBox.add(gameLog, SBoxLayout.constraint(SLayout.EXPAND_X, SLayout.EXPAND_Y));
chatBox.setMinimumSize(chatText.getPlayerChatText().getMinimumSize());
chatBox.setMaximumSize(new Dimension(screenSize.width, Integer.MAX_VALUE));
// Give the user the ability to make the the game area less tall
final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, chatBox);
splitPane.setBorder(null);
// Works for showing the resize, but is extremely flickery
//splitPane.setContinuousLayout(true);
pane.addComponentListener(new SplitPaneResizeListener(screen, splitPane));
containerPanel = createContainerPanel();
// Avoid panel drawing overhead
final Container windowContent = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL);
mainFrame.getMainFrame().setContentPane(windowContent);
// Finally add the left pane, and the games screen + chat combo
// Make the panel take any horizontal resize
windowContent.add(leftColumn, SBoxLayout.constraint(SLayout.EXPAND_X, SLayout.EXPAND_Y));
leftColumn.setMinimumSize(new Dimension());
/*
* Put the splitpane and the container panel to a subcontainer to make
* squeezing the window affect the left pane first rather than the right
*/
JComponent rightSide = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL);
rightSide.add(splitPane, SBoxLayout.constraint(SLayout.EXPAND_Y));
rightSide.add(containerPanel, SBoxLayout.constraint(SLayout.EXPAND_Y));
rightSide.setMinimumSize(rightSide.getPreferredSize());
windowContent.add(rightSide, SBoxLayout.constraint(SLayout.EXPAND_Y));
/*
* Handle focus assertion and window closing
*/
mainFrame.getMainFrame().addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(final WindowEvent ev) {
chatText.getPlayerChatText().requestFocus();
}
@Override
public void windowActivated(final WindowEvent ev) {
chatText.getPlayerChatText().requestFocus();
}
@Override
public void windowGainedFocus(final WindowEvent ev) {
chatText.getPlayerChatText().requestFocus();
}
@Override
public void windowClosing(final WindowEvent e) {
requestQuit();
}
});
mainFrame.getMainFrame().pack();
setInitialWindowStates();
/*
* A bit roundabout way to calculate the desired minsize, but
* different java versions seem to take the window decorations
* in account in rather random ways.
*/
final int width = mainFrame.getMainFrame().getWidth()
- minimap.getComponent().getWidth() - containerPanel.getWidth();
final int height = mainFrame.getMainFrame().getHeight() - gameLog.getHeight();
mainFrame.getMainFrame().setMinimumSize(new Dimension(width, height));
mainFrame.getMainFrame().setVisible(true);
/*
* For small screens. Setting the maximum window size does
* not help - pack() happily ignores it.
*/
Rectangle maxBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
Dimension current = mainFrame.getMainFrame().getSize();
mainFrame.getMainFrame().setSize(Math.min(current.width, maxBounds.width),
Math.min(current.height, maxBounds.height));
/*
* Needed for small screens; Sometimes the divider is placed
* incorrectly unless we explicitly set it. Try to fit it on the
* screen and show a bit of the chat.
*/
splitPane.setDividerLocation(Math.min(stendhal.getScreenSize().height,
maxBounds.height - 80));
directionRelease = null;
// register the slash actions in the client side command line parser