From: Frederick W. <fre...@us...> - 2012-02-10 17:58:59
|
LocalisedText.properties | 1 rails/ui/swing/ORPanel.java | 18 +++-- rails/ui/swing/ORWindow.java | 39 +++++++---- rails/ui/swing/RemainingTilesWindow.java | 80 +++++++++++++++++++----- rails/ui/swing/elements/DockingFrame.java | 98 ++++++++++++++++++++++++------ 5 files changed, 184 insertions(+), 52 deletions(-) New commits: commit feb1ae94d3506dcd676c09e9b439e8df894c2d6a Author: Frederick Weld <fre...@gm...> Date: Fri Feb 10 18:25:48 2012 +0100 Included "Remaining Tiles" into docking layout (as a dockable) Change only applies to the docking layout. Now, the remaining tiles panel is part of the ORWindow. Its activation/positioning is done in the context of the docking framework instead of the ORPanel menu and the JFrame. Additionally, docking framework handles the tiles / messages window as closable dockables. A dedicated menu option is available for toggling the visibility. diff --git a/LocalisedText.properties b/LocalisedText.properties index 4f344b2..a0f256f 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -295,6 +295,7 @@ Dockable.orWindow.buttonPanel = Commands Dockable.orWindow.mapPanel = Map Dockable.orWindow.messagePanel = Messages Dockable.orWindow.orPanel = Companies +Dockable.orWindow.remainingTilesPanel = Tiles Dockable.orWindow.upgradePanel = Upgrades DockingFrame.menu.layout = Layout DockingFrame.menu.layout.applyFrom = Apply From... diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java index bd3ea58..280ef18 100644 --- a/rails/ui/swing/ORPanel.java +++ b/rails/ui/swing/ORPanel.java @@ -171,11 +171,17 @@ implements ActionListener, KeyListener, RevenueListener { infoMenu = new JMenu(LocalText.getText("Info")); infoMenu.setEnabled(true); - remainingTilesMenuItem = - new JMenuItem(LocalText.getText("RemainingTiles")); - remainingTilesMenuItem.addActionListener(this); - remainingTilesMenuItem.setActionCommand(REM_TILES_CMD); - infoMenu.add(remainingTilesMenuItem); + + //only add remaining tiles display option for conventional layout + //as this is always included as a dockable panel in the docking frame layout + if (!parent.isDockingFrameworkEnabled()) { + remainingTilesMenuItem = + new JMenuItem(LocalText.getText("RemainingTiles")); + remainingTilesMenuItem.addActionListener(this); + remainingTilesMenuItem.setActionCommand(REM_TILES_CMD); + infoMenu.add(remainingTilesMenuItem); + } + menuBar.add(infoMenu); addCompanyInfo(); @@ -1360,4 +1366,4 @@ implements ActionListener, KeyListener, RevenueListener { public JMenuBar getMenuBar() { return menuBar; } -} \ No newline at end of file +} diff --git a/rails/ui/swing/ORWindow.java b/rails/ui/swing/ORWindow.java index 278e9b0..acee3e9 100644 --- a/rails/ui/swing/ORWindow.java +++ b/rails/ui/swing/ORWindow.java @@ -63,8 +63,8 @@ public class ORWindow extends DockingFrame implements ActionPerformer { orUIManager.setGameUIManager(gameUIManager); messagePanel = new MessagePanel(); - JScrollPane slider = new JScrollPane(messagePanel); - messagePanel.setParentSlider(slider); + JScrollPane messagePanelSlider = new JScrollPane(messagePanel); + messagePanel.setParentSlider(messagePanelSlider); upgradePanel = new UpgradesPanel(orUIManager); addMouseListener(upgradePanel); @@ -72,22 +72,33 @@ public class ORWindow extends DockingFrame implements ActionPerformer { mapPanel = new MapPanel(gameUIManager); orPanel = new ORPanel(this, orUIManager); - + //create docking / conventional layout if (isDockingFrameworkEnabled()) { + + //initialize remaining tile panel as it is no optional part in the docking layout + JScrollPane remainingTilesPanelSlider = + new RemainingTilesWindow(this).getScrollPane(); //generate layout - addDockable ( slider, LocalText.getText("Dockable.orWindow.messagePanel"), - 0, 0, 100, 10); - addDockable ( upgradePanel, LocalText.getText("Dockable.orWindow.upgradePanel"), - 0, 10, 20, 70); - addDockable ( mapPanel, LocalText.getText("Dockable.orWindow.mapPanel"), - 20, 10, 80, 70); - addDockable ( orPanel, LocalText.getText("Dockable.orWindow.orPanel"), - 0, 80, 100, 15); + addDockable ( messagePanelSlider, + LocalText.getText("Dockable.orWindow.messagePanel"), + 0, 0, 100, 10, DockableProperty.closeable); + addDockable ( upgradePanel, + LocalText.getText("Dockable.orWindow.upgradePanel"), + 0, 10, 20, 70, DockableProperty.standard); + addDockable ( mapPanel, + LocalText.getText("Dockable.orWindow.mapPanel"), + 20, 10, 80, 70, DockableProperty.standard); + addDockable ( remainingTilesPanelSlider, + LocalText.getText("Dockable.orWindow.remainingTilesPanel"), + 100, 0, 120, 100, DockableProperty.initially_hidden); + addDockable ( orPanel, + LocalText.getText("Dockable.orWindow.orPanel"), + 0, 80, 100, 15, DockableProperty.standard); addDockable ( orPanel.getButtonPanel(), LocalText.getText("Dockable.orWindow.buttonPanel"), - 0, 95, 100, 5); + 0, 95, 100, 5, DockableProperty.standard); deployDockables(); //take over or panel's menu bar as the frame menu bar @@ -99,7 +110,7 @@ public class ORWindow extends DockingFrame implements ActionPerformer { // CONVENTIONAL LAYOUT getContentPane().setLayout(new BorderLayout()); - getContentPane().add(slider, BorderLayout.NORTH); + getContentPane().add(messagePanelSlider, BorderLayout.NORTH); getContentPane().add(mapPanel, BorderLayout.CENTER); getContentPane().add(upgradePanel, BorderLayout.WEST); getContentPane().add(orPanel, BorderLayout.SOUTH); @@ -268,4 +279,4 @@ public class ORWindow extends DockingFrame implements ActionPerformer { + gameUIManager.getGameManager().getGameName() ; } -} \ No newline at end of file +} diff --git a/rails/ui/swing/RemainingTilesWindow.java b/rails/ui/swing/RemainingTilesWindow.java index f969505..0c3924f 100644 --- a/rails/ui/swing/RemainingTilesWindow.java +++ b/rails/ui/swing/RemainingTilesWindow.java @@ -44,6 +44,7 @@ public class RemainingTilesWindow extends JFrame implements WindowListener, tilePanel = new AlignedWidthPanel(); slider = new JScrollPane(tilePanel); slider.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + slider.setPreferredSize(new Dimension(200,200)); tilePanel.setParentSlider(slider); //use flow layout as it provides for necessary line breaks @@ -53,7 +54,7 @@ public class RemainingTilesWindow extends JFrame implements WindowListener, //setup the JFrame and assign the contents (slider containing tilePane) //only for conventional layout as this is a dockable pane for the docking layout - if (true || !orWindow.isDockingFrameworkEnabled()) { + if (!orWindow.isDockingFrameworkEnabled()) { setTitle("Rails: Remaining Tiles"); setVisible(false); setContentPane(slider); diff --git a/rails/ui/swing/elements/DockingFrame.java b/rails/ui/swing/elements/DockingFrame.java index 8cc1203..78edec1 100644 --- a/rails/ui/swing/elements/DockingFrame.java +++ b/rails/ui/swing/elements/DockingFrame.java @@ -4,6 +4,8 @@ import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import javax.swing.JComponent; @@ -30,14 +32,17 @@ import bibliothek.gui.dock.common.action.predefined.CBlank; import bibliothek.gui.dock.common.event.CDockableStateListener; import bibliothek.gui.dock.common.intern.CDockable; import bibliothek.gui.dock.common.intern.DefaultCDockable; +import bibliothek.gui.dock.common.intern.DefaultCommonDockable; import bibliothek.gui.dock.common.intern.ui.CSingleParentRemover; import bibliothek.gui.dock.common.menu.CThemeMenuPiece; +import bibliothek.gui.dock.common.menu.SingleCDockableListMenuPiece; import bibliothek.gui.dock.common.mode.ExtendedMode; import bibliothek.gui.dock.common.theme.ThemeMap; import bibliothek.gui.dock.event.DockStationAdapter; import bibliothek.gui.dock.facile.menu.RootMenuPiece; import bibliothek.gui.dock.facile.menu.SubmenuPiece; import bibliothek.gui.dock.station.LayoutLocked; +import bibliothek.gui.dock.support.menu.SeparatingMenuPiece; import org.apache.log4j.Logger; @@ -53,6 +58,7 @@ import org.apache.log4j.Logger; * */ public abstract class DockingFrame extends JFrame { + public static enum DockableProperty { standard, closeable, initially_hidden }; private static final long serialVersionUID = 1L; private static final String layoutDirectoryName = "DockableLayout"; private static final String layoutFileSuffix = "_layout.rails_ini"; @@ -64,7 +70,13 @@ public abstract class DockingFrame extends JFrame { private boolean isDockingFrameworkEnabled; private CControl control = null; private CGrid gridLayout = null; - + + /** + * All dockables under the control (currently only single dockables) + */ + List<DefaultSingleCDockable> dockables = new ArrayList<DefaultSingleCDockable>(); + List<DefaultSingleCDockable> dockables_initiallyHidden = new ArrayList<DefaultSingleCDockable>(); + /** * Decision whether docking framework should be activated for a frame * has to be done at the beginning as later switching is not supported @@ -101,19 +113,34 @@ public abstract class DockingFrame extends JFrame { * Registers a component that is to become a dockable. * The dockable is only deployed to the frame if deployDockables is called. */ - protected void addDockable(JComponent c, String dockableTitle, int x, int y, int width, int height) { + protected void addDockable(JComponent c, + String dockableTitle, + int x, int y, int width, int height, + DockableProperty dockableProperty) { DefaultSingleCDockable d = new DefaultSingleCDockable( dockableTitle, dockableTitle ); d.add( c, BorderLayout.CENTER ); - d.setCloseable( false ); + d.setTitleIcon(null); + d.setCloseable( + ( dockableProperty == DockableProperty.closeable + || dockableProperty == DockableProperty.initially_hidden ) + ); gridLayout.add( x, y, width, height, d ); + dockables.add(d); + if (dockableProperty == DockableProperty.initially_hidden) { + dockables_initiallyHidden.add(d); + } } /** - * Deploys to the frame all dockables that have been added before + * Deploys to the frame all dockables that have been added before. + * Dockables are initially set to invisible if this is as specified */ protected void deployDockables() { control.getContentArea().deploy( gridLayout ); + for (CDockable d : dockables_initiallyHidden) { + if (d.isCloseable()) d.setVisible(false); + } } /** @@ -123,12 +150,26 @@ public abstract class DockingFrame extends JFrame { RootMenuPiece layoutMenu = new RootMenuPiece( LocalText.getText("DockingFrame.menu.layout"), false); + layoutMenu.add( new SubmenuPiece( LocalText.getText("DockingFrame.menu.layout.theme"), false, new CThemeMenuPiece( control ) )); - layoutMenu.getMenu().addSeparator(); + + SingleCDockableListMenuPiece closeableDockableMenuPiece = + new SingleCDockableListMenuPiece(control) { + @Override + protected void show(Dockable dockable) { + super.show(dockable); + //ensure that, if the dockable is externalized, the max button is disabled + if (dockable instanceof DefaultCommonDockable) { + adjustExternalizedActions((DefaultCommonDockable)dockable); + } + } + }; + layoutMenu.add(new SeparatingMenuPiece(closeableDockableMenuPiece,true,true,true)); + JMenuItem resetMenuItem = new JMenuItem ( LocalText.getText("DockingFrame.menu.layout.reset")); resetMenuItem.addActionListener(new ActionListener() { @@ -224,22 +265,42 @@ public abstract class DockingFrame extends JFrame { return; } - //ensure that all dockables that are externalized according to layout - //information don't have the default maximize button (as it won't work - //for the adjusted externalization setup) - for (int i = 0 ; i < control.getCDockableCount() ; i++ ) { - CDockable d = control.getCDockable(i); - if (d instanceof DefaultCDockable) { - DefaultCDockable dd = (DefaultCDockable)d; - if (ExtendedMode.EXTERNALIZED.equals(d.getExtendedMode())) { - dd.putAction( CDockable.ACTION_KEY_MAXIMIZE, CBlank.BLANK ); - } else { - dd.putAction( CDockable.ACTION_KEY_MAXIMIZE, null ); - } + adjustExternalizedActions(); + } + + /** + * Ensures for all dockables that, if they are externalized, they do not have + * the default maximize button + * (as it won't work for the adjusted externalization setup). + */ + private void adjustExternalizedActions() { + for (CDockable d : dockables) { + adjustExternalizedActions(d); + } + } + + /** + * Ensure that externalized dockable does not have default maximize button + * (as it won't work for the adjusted externalization setup). + * @param d Dockable for which the actions are to be adjusted + */ + private void adjustExternalizedActions(CDockable d) { + if (d instanceof DefaultSingleCDockable) { + DefaultSingleCDockable sd = (DefaultSingleCDockable)d; + if (ExtendedMode.EXTERNALIZED.equals(sd.getExtendedMode())) { + sd.putAction( CDockable.ACTION_KEY_MAXIMIZE, CBlank.BLANK ); + } else { + sd.putAction( CDockable.ACTION_KEY_MAXIMIZE, null ); } } } + private void adjustExternalizedActions(Dockable d) { + if (d instanceof DefaultCommonDockable) { + adjustExternalizedActions(((DefaultCommonDockable)d).getDockable()); + } + } + /** * Lets user choose a layout in a file chooser popup and then loads/applies it */ @@ -340,6 +401,9 @@ public abstract class DockingFrame extends JFrame { // and enable events after we finished controller.meltLayout(); } + + //ensure the correct availability of the maximize button + adjustExternalizedActions(dockable); } } commit e2fd3ff42eea4edeee1d7a97f579e750af729d84 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 9 20:13:41 2012 +0100 Enabled variable layout of "Remaining Tiles" incl. vertical scroll bar diff --git a/rails/ui/swing/RemainingTilesWindow.java b/rails/ui/swing/RemainingTilesWindow.java index 9c9d2ff..f969505 100644 --- a/rails/ui/swing/RemainingTilesWindow.java +++ b/rails/ui/swing/RemainingTilesWindow.java @@ -1,7 +1,9 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/RemainingTilesWindow.java,v 1.8 2009/12/15 18:56:11 evos Exp $*/ package rails.ui.swing; -import java.awt.GridLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Image; import java.awt.event.*; import java.awt.image.BufferedImage; @@ -20,39 +22,49 @@ import rails.ui.swing.elements.Field; import rails.ui.swing.hexmap.GUIHex; /** - * This Window displays the available operations that may be performed during an - * Operating Round. This window also contains the Game Map. + * This Window displays the availability of tiles. */ public class RemainingTilesWindow extends JFrame implements WindowListener, ActionListener { private static final long serialVersionUID = 1L; private GameUIManager gameUIManager; private ORUIManager orUIManager; + private AlignedWidthPanel tilePanel; + private JScrollPane slider; private List<Field> labels = new ArrayList<Field>(); private List<TileI> shownTiles = new ArrayList<TileI>(); - private final static int COLUMNS = 10; - protected static Logger log = Logger.getLogger(RemainingTilesWindow.class.getPackage().getName()); public RemainingTilesWindow(ORWindow orWindow) { super(); - getContentPane().setLayout(new GridLayout(0, COLUMNS, 5, 5)); + tilePanel = new AlignedWidthPanel(); + slider = new JScrollPane(tilePanel); + slider.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + tilePanel.setParentSlider(slider); - setTitle("Rails: Remaining Tiles"); - setVisible(false); - setSize(800, 600); - addWindowListener(this); + //use flow layout as it provides for necessary line breaks + tilePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); init(orWindow.getGameUIManager()); - this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - this.setLocationRelativeTo(orWindow); - pack(); - setVisible(true); + //setup the JFrame and assign the contents (slider containing tilePane) + //only for conventional layout as this is a dockable pane for the docking layout + if (true || !orWindow.isDockingFrameworkEnabled()) { + setTitle("Rails: Remaining Tiles"); + setVisible(false); + setContentPane(slider); + setSize(800, 600); + addWindowListener(this); + + this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + this.setLocationRelativeTo(orWindow); + + setVisible(true); + } } private void init(GameUIManager gameUIManager) { @@ -87,7 +99,7 @@ public class RemainingTilesWindow extends JFrame implements WindowListener, label.setHorizontalTextPosition(Field.CENTER); label.setVisible(true); - getContentPane().add(label); + tilePanel.add(label); shownTiles.add(tile); labels.add(label); @@ -134,4 +146,41 @@ public class RemainingTilesWindow extends JFrame implements WindowListener, * */ public void finish() {} + + /** + * @return The scroll pane which holds as child the tile panel + */ + public JScrollPane getScrollPane() { + return slider; + } + + /** + * custom content pane that will align its width with the parent scroll pane + * needed to ensure only vertical scroll bar is used + */ + private static class AlignedWidthPanel extends JPanel { + private static final long serialVersionUID = 1L; + private JScrollPane parentSlider = null; + @Override + public Dimension getPreferredSize() { + //width based on parent slider + int width = parentSlider.getSize().width + - parentSlider.getVerticalScrollBar().getWidth() + - 5; + if (width <= 0) width = 1; + + //height based on contained components + //(no need to take into account width discrepancies since + // method is invoked several times) + int height = 1; //minimum height + for (Component c : this.getComponents()) { + height = Math.max(height, c.getY() + c.getHeight()); + } + return new Dimension (width , height); + } + public void setParentSlider(JScrollPane parentSlider) { + this.parentSlider = parentSlider; + } + } + } |