From b209ee036de6cb8acec56e037a61e83a98331d63 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 8 Jun 2005 23:20:18 +0000 Subject: [PATCH] Beginnings of a new unified way of configuring not only puzzles but associated options depending on the context of the puzzle, for example the wager, or tournament options. Kept the default layout as a vgroup for backwards compatability (although I think the only thing that needs that is the ToyBoxConfigurator, and I've been wanting to make that bad boy line up nicely for a while now, so this backwards compatible stuff will only be needed for a short while). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3590 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../parlor/client/GameConfigurator.java | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/java/com/threerings/parlor/client/GameConfigurator.java b/src/java/com/threerings/parlor/client/GameConfigurator.java index 81e63fd58..f700caa20 100644 --- a/src/java/com/threerings/parlor/client/GameConfigurator.java +++ b/src/java/com/threerings/parlor/client/GameConfigurator.java @@ -21,7 +21,13 @@ package com.threerings.parlor.client; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; + +import javax.swing.JComponent; import javax.swing.JPanel; + import com.samskivert.swing.VGroupLayout; import com.threerings.parlor.game.data.GameConfig; @@ -39,6 +45,15 @@ import com.threerings.parlor.util.ParlorContext; */ public class GameConfigurator extends JPanel { + // initializer + { + // BACKcompatible, older code (and toybox) expects the layout + // to be a vgroup, so we default to that + VGroupLayout layout = new VGroupLayout(VGroupLayout.NONE); + layout.setOffAxisPolicy(VGroupLayout.STRETCH); + setLayout(layout); + } + /** * Initializes this game configurator, creates its user interface * elements and prepares it for display. @@ -48,18 +63,12 @@ public class GameConfigurator extends JPanel // save this for later _ctx = ctx; - // set up our layout manager - VGroupLayout layout = new VGroupLayout(VGroupLayout.NONE); - layout.setOffAxisPolicy(VGroupLayout.STRETCH); - setLayout(layout); - // create our interface elements createConfigInterface(); } /** - * The default implementation creates a label indicating that no game - * specific configurations are available. + * The default implementation creates nothing. */ protected void createConfigInterface () { @@ -94,6 +103,40 @@ public class GameConfigurator extends JPanel return _config; } + /** + * Add a control to the interface. This should be the standard way + * that configurator controls are added, but note also that external + * entities may add their own controls that are related to the game, + * but do not directly alter the game config, so that all the controls + * are added in a uniform manner and are well aligned. + */ + public void addControl (JComponent label, JComponent control) + { + // BACKcompatible, newer code will call this method, and so + // we need to switch the layout to gridbag instead of vgroup + if (!(getLayout() instanceof GridBagLayout)) { + setLayout(new GridBagLayout()); + } + + // Set up the constraints. There's really no point in saving + // this somewhere, as they're cloned anyway with every component + // insertion. + GridBagConstraints lc = new GridBagConstraints(); + lc.gridx = 0; + lc.anchor = GridBagConstraints.NORTHWEST; + lc.insets = _labelInsets; + + GridBagConstraints cc = new GridBagConstraints(); + cc.gridx = 1; + cc.anchor = GridBagConstraints.NORTHWEST; + cc.insets = _controlInsets; + cc.gridwidth = GridBagConstraints.REMAINDER; + + // add the components + add(label, lc); + add(control, cc); + } + /** * Derived classes will want to override this method, flushing values * from the user interface to the game config object so that it is @@ -109,4 +152,10 @@ public class GameConfigurator extends JPanel /** Our game configuration. */ protected GameConfig _config; + + /** Insets for configuration labels. */ + protected Insets _labelInsets = new Insets(1, 0, 1, 4); + + /** Insets for configuration controls. */ + protected Insets _controlInsets = new Insets(1, 4, 1, 0); }