Class NewPanel

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.ItemListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

    public final class NewPanel
    extends FreeColPanel
    implements java.awt.event.ItemListener
    This dialog allows the user to start a single player or multiplayer game, to join a running game, and to fetch a list of games from the meta-server.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  NewPanel.NewPanelAction
      The actions for this panel.
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.swing.JComboBox<NationOptions.Advantages> advantagesBox
      A box to choose the national advantages setting.
      private javax.swing.JLabel advantagesLabel
      The label for the national advantages.
      private javax.swing.ButtonGroup buttonGroup
      A button group for the main choices.
      private OptionGroup difficulty
      A current difficulty level, driven by the contents of the difficulty box..
      private javax.swing.JComboBox<OptionGroup> difficultyBox
      A box to choose the difficulty from.
      private javax.swing.JButton difficultyButton
      A button to show/edit difficulty level.
      private javax.swing.JLabel difficultyLabel
      A label for the difficulty level selection.
      private Specification fixedSpecification
      A particular specification to use for the new game.
      private java.awt.Component[] gameComponents
      Container for components to enable when choosing game parameters.
      private java.awt.Component[] joinComponents
      Container for the components to enable when Join is selected.
      private javax.swing.JTextField joinNameField
      Join multiplayer server name selection.
      private javax.swing.JLabel joinNameLabel
      Join multiplayer server name label.
      private javax.swing.JTextField joinPortField
      Join multiplayer server port selection.
      private javax.swing.JLabel joinPortLabel
      Join multiplayer server port label.
      private static java.util.logging.Logger logger  
      private javax.swing.JTextField nameBox
      Field to input the player name.
      private javax.swing.JCheckBox publicServer
      The check box to select a public server with.
      private javax.swing.JComboBox<FreeColTcFile> rulesBox
      A box to choose the rules from.
      private javax.swing.JLabel rulesLabel
      The label for the rules selection.
      private javax.swing.JComboBox<java.net.InetAddress> serverAddressBox  
      private java.awt.Component[] serverComponents
      Container for components to enable if server parameters can be set.
      private javax.swing.JTextField serverPortField
      Start server port number label and field to input through.
      private javax.swing.JLabel serverPortLabel
      Start server name label.
      private Specification specification
      The current specification, driven by the contents of the TC box.
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent ae)
      private boolean checkDifficulty()
      Check if the difficulty box changed.
      private boolean checkTC()
      Check if the TC changed.
      private void enableComponents()
      Enable components according to the selected button.
      private void enableComponents​(java.awt.Component[] components, boolean enable)
      Dis/Enable a group of components.
      private NationOptions.Advantages getSelectedAdvantages()
      Gets the currently selected Advantages type from the nationalAdvantages box.
      private OptionGroup getSelectedDifficulty()
      Gets the currently selected difficulty from the difficultyBox.
      private java.lang.String getSelectedName()
      Get the selected player name from the nameBox.
      private int getSelectedPort​(javax.swing.JTextField field)
      Get the value of a port field.
      private FreeColTcFile getSelectedTC()
      Gets the currently selected total-conversion from the rulesBox.
      Specification getSpecification()
      Get the specification.
      void itemStateChanged​(java.awt.event.ItemEvent e)
      private void update​(boolean changed)
      Update specification and difficulty as needed.
      private void updateDifficultyBox()
      Update just the difficulty box state.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • fixedSpecification

        private final Specification fixedSpecification
        A particular specification to use for the new game. If not null, the specification box just contains this spec, but if null the user chooses from available specs using the specification box.
      • specification

        private Specification specification
        The current specification, driven by the contents of the TC box.
      • difficulty

        private OptionGroup difficulty
        A current difficulty level, driven by the contents of the difficulty box.. Difficulty levels are relative to the rules, so this can be invalidated by a change to the current specification.
      • nameBox

        private final javax.swing.JTextField nameBox
        Field to input the player name.
      • buttonGroup

        private final javax.swing.ButtonGroup buttonGroup
        A button group for the main choices.
      • advantagesLabel

        private final javax.swing.JLabel advantagesLabel
        The label for the national advantages.
      • advantagesBox

        private final javax.swing.JComboBox<NationOptions.Advantages> advantagesBox
        A box to choose the national advantages setting.
      • serverPortLabel

        private final javax.swing.JLabel serverPortLabel
        Start server name label.
      • serverPortField

        private final javax.swing.JTextField serverPortField
        Start server port number label and field to input through.
      • serverAddressBox

        private final javax.swing.JComboBox<java.net.InetAddress> serverAddressBox
      • rulesLabel

        private final javax.swing.JLabel rulesLabel
        The label for the rules selection.
      • rulesBox

        private final javax.swing.JComboBox<FreeColTcFile> rulesBox
        A box to choose the rules from.
      • publicServer

        private final javax.swing.JCheckBox publicServer
        The check box to select a public server with.
      • difficultyLabel

        private final javax.swing.JLabel difficultyLabel
        A label for the difficulty level selection.
      • difficultyBox

        private final javax.swing.JComboBox<OptionGroup> difficultyBox
        A box to choose the difficulty from.
      • difficultyButton

        private final javax.swing.JButton difficultyButton
        A button to show/edit difficulty level.
      • joinNameLabel

        private final javax.swing.JLabel joinNameLabel
        Join multiplayer server name label.
      • joinNameField

        private final javax.swing.JTextField joinNameField
        Join multiplayer server name selection.
      • joinPortLabel

        private final javax.swing.JLabel joinPortLabel
        Join multiplayer server port label.
      • joinPortField

        private final javax.swing.JTextField joinPortField
        Join multiplayer server port selection.
      • joinComponents

        private final java.awt.Component[] joinComponents
        Container for the components to enable when Join is selected.
      • serverComponents

        private final java.awt.Component[] serverComponents
        Container for components to enable if server parameters can be set.
      • gameComponents

        private final java.awt.Component[] gameComponents
        Container for components to enable when choosing game parameters.
    • Constructor Detail

      • NewPanel

        public NewPanel​(FreeColClient freeColClient)
        Creates a new game panel.
        Parameters:
        freeColClient - The FreeColClient for the game.
      • NewPanel

        public NewPanel​(FreeColClient freeColClient,
                        Specification specification)
        Creates a new game panel.
        Parameters:
        freeColClient - The FreeColClient for the game.
        specification - An optional Specification value for the new game.
    • Method Detail

      • update

        private void update​(boolean changed)
        Update specification and difficulty as needed.
        Parameters:
        changed - If true force an update.
      • checkTC

        private boolean checkTC()
        Check if the TC changed.
        Returns:
        True if the TC changed.
      • checkDifficulty

        private boolean checkDifficulty()
        Check if the difficulty box changed.
        Returns:
        True if the difficulty changed.
      • updateDifficultyBox

        private void updateDifficultyBox()
        Update just the difficulty box state.
      • getSelectedName

        private java.lang.String getSelectedName()
        Get the selected player name from the nameBox.
        Returns:
        The selected player name.
      • getSelectedAdvantages

        private NationOptions.Advantages getSelectedAdvantages()
        Gets the currently selected Advantages type from the nationalAdvantages box.
        Returns:
        The selected advantages type.
      • getSelectedTC

        private FreeColTcFile getSelectedTC()
        Gets the currently selected total-conversion from the rulesBox.
        Returns:
        The selected TC.
      • getSelectedDifficulty

        private OptionGroup getSelectedDifficulty()
        Gets the currently selected difficulty from the difficultyBox.
        Returns:
        The difficulty OptionGroup.
      • getSelectedPort

        private int getSelectedPort​(javax.swing.JTextField field)
        Get the value of a port field.
        Parameters:
        field - The field to read.
        Returns:
        The port number in the field, or negative on error.
      • enableComponents

        private void enableComponents()
        Enable components according to the selected button.
      • enableComponents

        private void enableComponents​(java.awt.Component[] components,
                                      boolean enable)
        Dis/Enable a group of components.
        Parameters:
        components - The Components to set.
        enable - Enable if true.
      • getSpecification

        public Specification getSpecification()
        Get the specification. Either the one set for this panel, or the one implied by the currently selected TC.
        Overrides:
        getSpecification in class FreeColPanel
        Returns:
        The current Specification.
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent ae)
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Overrides:
        actionPerformed in class FreeColPanel
      • itemStateChanged

        public void itemStateChanged​(java.awt.event.ItemEvent e)
        Specified by:
        itemStateChanged in interface java.awt.event.ItemListener