Search in sources :

Example 41 with Label

use of java.awt.Label in project JSettlers2 by jdmonin.

the class NewGameOptionsFrame method readOptsValuesFromControls.

/**
 * Read option values from controls, as prep to request the new game.
 * If there is a problem (out of range, bad character in integer field, etc),
 * set {@link #msgText} and set focus on the field.
 * @param checkOptionsMinVers Warn the user if the options will require a
 *           minimum client version?  Won't do so if {@link #forPractice} is set,
 *           because this isn't a problem for local practice games.
 *           The warning is skipped if that minimum is an old version
 *           <= {@link Version#versionNumberMaximumNoWarn()}.
 * @return true if all were read OK, false if a problem (such as NumberFormatException)
 */
private boolean readOptsValuesFromControls(final boolean checkOptionsMinVers) {
    if (readOnly)
        // shouldn't be called in that case
        return false;
    boolean allOK = true;
    for (Component ctrl : controlsOpts.keySet()) {
        if (ctrl instanceof Label)
            continue;
        SOCGameOption op = controlsOpts.get(ctrl);
        if (op.key.equals("SC")) {
            // Special case: AWT event listeners have already set its value from controls
            if (!op.getBoolValue())
                op.setStringValue("");
            continue;
        }
        if (ctrl instanceof Checkbox) {
            op.setBoolValue(((Checkbox) ctrl).getState());
        } else if (ctrl instanceof TextField) {
            String txt = ((TextField) ctrl).getText().trim();
            if ((op.optType == SOCGameOption.OTYPE_STR) || (op.optType == SOCGameOption.OTYPE_STRHIDE)) {
                try {
                    op.setStringValue(txt);
                } catch (IllegalArgumentException ex) {
                    allOK = false;
                    // only a single line of text allowed
                    msgText.setText(strings.get("game.options.singleline"));
                    ctrl.requestFocusInWindow();
                }
            } else {
            // OTYPE_INT, OTYPE_INTBOOL; defer setting until after all checkboxes have been read
            }
        } else if (ctrl instanceof Choice) {
            // this works with OTYPE_INT, OTYPE_INTBOOL, OTYPE_ENUM, OTYPE_ENUMBOOL
            // 0 to n-1
            int chIdx = ((Choice) ctrl).getSelectedIndex();
            if (chIdx != -1)
                op.setIntValue(chIdx + op.minIntValue);
            else
                allOK = false;
        }
    }
    // Use 0 if blank (still checks if in range).
    for (Component ctrl : controlsOpts.keySet()) {
        if (!(ctrl instanceof TextField))
            continue;
        SOCGameOption op = controlsOpts.get(ctrl);
        if (op.optType == SOCGameOption.OTYPE_INTBOOL) {
            if (!op.getBoolValue())
                continue;
        } else if (op.optType != SOCGameOption.OTYPE_INT) {
            continue;
        }
        String txt = ((TextField) ctrl).getText().trim();
        try {
            int iv;
            if (txt.length() > 0)
                iv = Integer.parseInt(txt);
            else
                iv = 0;
            op.setIntValue(iv);
            if (iv != op.getIntValue()) {
                allOK = false;
                msgText.setText(// "out of range"
                strings.get("game.options.outofrange", op.minIntValue, op.maxIntValue));
                ctrl.requestFocusInWindow();
            }
        } catch (NumberFormatException ex) {
            allOK = false;
            // "please use only digits here"
            msgText.setText(strings.get("game.options.onlydigits"));
            ctrl.requestFocusInWindow();
        }
    }
    if (allOK && checkOptionsMinVers && !forPractice) {
        int optsVers = SOCVersionedItem.itemsMinimumVersion(controlsOpts);
        if ((optsVers > -1) && (optsVers > Version.versionNumberMaximumNoWarn())) {
            allOK = false;
            new VersionConfirmDialog(this, optsVers).setVisible(true);
        }
    }
    return allOK;
}
Also used : Choice(java.awt.Choice) Checkbox(java.awt.Checkbox) SOCGameOption(soc.game.SOCGameOption) Label(java.awt.Label) TextField(java.awt.TextField) Component(java.awt.Component)

Example 42 with Label

use of java.awt.Label in project JSettlers2 by jdmonin.

the class NewGameOptionsFrame method initInterface_Opt1.

/**
 * Add one GridBagLayout row with this game option (component and label(s)).
 * The option's descriptive text may have "#" as a placeholder for where
 * int/enum value is specified (IntTextField or Choice-dropdown).
 * @param op  Option data
 * @param oc  Component with option choices (popup menu, textfield, etc).
 *            If oc is a {@link TextField} or {@link Choice}, and hasCB,
 *            changing the component's value will set the checkbox.
 *            <tt>oc</tt> will be added to {@link #optsControls} and {@link #controlsOpts}.
 * @param hasCB  Add a checkbox?  If oc is {@link Checkbox}, set this true;
 *            it won't add a second checkbox.
 *            The checkbox will be added to {@link #boolOptCheckboxes} and {@link #controlsOpts}.
 * @param allowPH  Allow the "#" placeholder within option desc?
 * @param bp  Add to this panel
 * @param gbl Use this layout
 * @param gbc Use these constraints; gridwidth will be set to 1 and then REMAINDER
 */
private void initInterface_Opt1(SOCGameOption op, Component oc, boolean hasCB, boolean allowPH, JPanel bp, GridBagLayout gbl, GridBagConstraints gbc) {
    Label L;
    // reminder: same gbc widths/weights are used in initInterface_UserPrefs/initInterface_Pref1
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    if (hasCB) {
        Checkbox cb;
        if (oc instanceof Checkbox)
            cb = (Checkbox) oc;
        else
            cb = new Checkbox();
        controlsOpts.put(cb, op);
        cb.setState(op.getBoolValue());
        cb.setEnabled(!readOnly);
        gbl.setConstraints(cb, gbc);
        bp.add(cb);
        if (!readOnly) {
            boolOptCheckboxes.put(op.key, cb);
            // for op's ChangeListener and userChanged
            cb.addItemListener(this);
        }
    } else {
        // to fill checkbox's column
        L = new Label();
        gbl.setConstraints(L, gbc);
        bp.add(L);
    }
    final String opDesc = op.getDesc();
    final int placeholderIdx = allowPH ? opDesc.indexOf('#') : -1;
    // with FlowLayout
    Panel optp = new Panel();
    try {
        FlowLayout fl = (FlowLayout) (optp.getLayout());
        fl.setAlignment(FlowLayout.LEFT);
        fl.setVgap(0);
        fl.setHgap(0);
    } catch (Throwable fle) {
    }
    // Any text to the left of placeholder in op.desc?
    if (placeholderIdx > 0) {
        L = new Label(opDesc.substring(0, placeholderIdx));
        L.setForeground(LABEL_TXT_COLOR);
        optp.add(L);
        if (hasCB && !readOnly) {
            controlsOpts.put(L, op);
            // Click label to toggle checkbox
            L.addMouseListener(this);
        }
    }
    // TextField or Choice or JComboBox at placeholder position
    if (!(oc instanceof Checkbox)) {
        controlsOpts.put(oc, op);
        oc.setEnabled(!readOnly);
        optp.add(oc);
        if (hasCB && !readOnly) {
            if (oc instanceof TextField) {
                // for enable/disable
                ((TextField) oc).addTextListener(this);
                // for ESC/ENTER
                ((TextField) oc).addKeyListener(this);
            } else if (oc instanceof Choice) {
                // for related cb, and op.ChangeListener and userChanged
                ((Choice) oc).addItemListener(this);
            } else if (oc instanceof JComboBox) {
                // for related cb, and op.ChangeListener and userChanged
                ((JComboBox) oc).addActionListener(this);
            }
        }
    }
    if (!readOnly)
        optsControls.put(op.key, oc);
    // the text label if there is no placeholder (placeholderIdx == -1).
    if (placeholderIdx + 1 < opDesc.length()) {
        L = new Label(opDesc.substring(placeholderIdx + 1));
        L.setForeground(LABEL_TXT_COLOR);
        optp.add(L);
        if (hasCB && !readOnly) {
            controlsOpts.put(L, op);
            // Click label to toggle checkbox
            L.addMouseListener(this);
        }
    }
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1;
    gbl.setConstraints(optp, gbc);
    bp.add(optp);
}
Also used : Panel(java.awt.Panel) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) Choice(java.awt.Choice) JComboBox(javax.swing.JComboBox) Checkbox(java.awt.Checkbox) Label(java.awt.Label) TextField(java.awt.TextField)

Example 43 with Label

use of java.awt.Label in project JSettlers2 by jdmonin.

the class SOCConnectOrPracticePanel method initInterfaceElements.

/**
 * Interface setup for constructor.
 * Most elements are part of a sub-panel occupying most of this Panel, and using FlowLayout.
 * The exception is a Label at bottom with the version and build number.
 */
private void initInterfaceElements() {
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    // Actual button panel
    Panel bp = new Panel(gbl);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    // "Welcome to JSettlers!  Please choose an option."
    topText = new Label(strings.get("pcli.cpp.welcomeheading"));
    topText.setAlignment(Label.CENTER);
    gbl.setConstraints(topText, gbc);
    bp.add(topText);
    /**
     * Interface setup: Connect to a Server
     */
    // "Connect to a Server"
    connserv = new Button(strings.get("pcli.cpp.connecttoaserv"));
    gbl.setConstraints(connserv, gbc);
    bp.add(connserv);
    connserv.addActionListener(this);
    /**
     * Interface setup: Practice
     */
    // "Practice" - same as SOCPlayerClient button
    prac = new Button(strings.get("pcli.main.practice"));
    gbl.setConstraints(prac, gbc);
    bp.add(prac);
    prac.addActionListener(this);
    /**
     * Interface setup: Start a Server
     */
    // "Start a Server"
    runserv = new Button(strings.get("pcli.cpp.startserv"));
    gbl.setConstraints(runserv, gbc);
    if (!canLaunchServer)
        runserv.setEnabled(false);
    bp.add(runserv);
    /**
     * Interface setup: sub-panels (not initially visible)
     */
    // panel_conn setup
    panel_conn = initInterface_conn();
    panel_conn.setVisible(false);
    gbl.setConstraints(panel_conn, gbc);
    bp.add(panel_conn);
    if (canLaunchServer) {
        runserv.addActionListener(this);
        // panel_run setup
        panel_run = initInterface_run();
        panel_run.setVisible(false);
        gbl.setConstraints(panel_run, gbc);
        bp.add(panel_run);
    } else {
        panel_run = null;
    }
    // Final assembly setup
    add(bp, BorderLayout.CENTER);
    Label verl = new Label(strings.get("pcli.cpp.jsettlers.versionbuild", Version.version(), Version.buildnum()));
    // "JSettlers " + Version.version() + " build " + Version.buildnum()
    verl.setAlignment(Label.CENTER);
    // off-white
    verl.setForeground(new Color(252, 251, 243));
    add(verl, BorderLayout.SOUTH);
}
Also used : Panel(java.awt.Panel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Button(java.awt.Button) Color(java.awt.Color) Label(java.awt.Label)

Example 44 with Label

use of java.awt.Label in project JSettlers2 by jdmonin.

the class SOCConnectOrPracticePanel method initInterface_conn.

/**
 * panel_conn setup
 */
private Panel initInterface_conn() {
    Panel pconn = new Panel();
    Label L;
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    pconn.setLayout(gbl);
    gbc.fill = GridBagConstraints.BOTH;
    // heading row
    // "Connect to Server"
    L = new Label(strings.get("pcli.cpp.connecttoserv"));
    L.setAlignment(Label.CENTER);
    L.setBackground(HEADER_LABEL_BG);
    L.setForeground(HEADER_LABEL_FG);
    gbc.gridwidth = 4;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    // Spacing for rest of form's rows
    L = new Label(" ");
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    // blank row
    L = new Label();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    L = new Label(strings.get("pcli.cpp.server"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_servhost = new TextField(20);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_servhost, gbc);
    // for ESC/ENTER
    conn_servhost.addKeyListener(this);
    pconn.add(conn_servhost);
    L = new Label(strings.get("pcli.cpp.port"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_servport = new TextField(20);
    {
        String svp = Integer.toString(clientNetwork.getPort());
        conn_servport.setText(svp);
        conn_servport.setSelectionStart(0);
        conn_servport.setSelectionEnd(svp.length());
    }
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_servport, gbc);
    // for ESC/ENTER
    conn_servport.addKeyListener(this);
    pconn.add(conn_servport);
    L = new Label(strings.get("pcli.cpp.nickname"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_user = new TextField(20);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_user, gbc);
    conn_user.addKeyListener(this);
    pconn.add(conn_user);
    L = new Label(strings.get("pcli.cpp.password"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_pass = new TextField(20);
    if (SOCPlayerClient.isJavaOnOSX)
        // round bullet (option-8)
        conn_pass.setEchoChar('\u2022');
    else
        conn_pass.setEchoChar('*');
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_pass, gbc);
    conn_pass.addKeyListener(this);
    pconn.add(conn_pass);
    L = new Label(" ");
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_connect = new Button(strings.get("pcli.cpp.connect"));
    conn_connect.addActionListener(this);
    // for win32 keyboard-focus
    conn_connect.addKeyListener(this);
    gbl.setConstraints(conn_connect, gbc);
    pconn.add(conn_connect);
    conn_cancel = new Button(strings.get("base.cancel"));
    conn_cancel.addActionListener(this);
    conn_cancel.addKeyListener(this);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_cancel, gbc);
    pconn.add(conn_cancel);
    return pconn;
}
Also used : Panel(java.awt.Panel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Button(java.awt.Button) Label(java.awt.Label) TextField(java.awt.TextField)

Example 45 with Label

use of java.awt.Label in project JSettlers2 by jdmonin.

the class SOCHandPanel method doLayout.

/**
 * Custom layout for player hand panel.
 * Different arrangements for our hand, other player's hand, or empty seat.
 * See comments for arrangement details.
 */
@Override
public void doLayout() {
    final Dimension dim = getSize();
    // margin from edge of panel; was 8 before 1.1.08
    final int inset = 3;
    // vertical and horizontal spacing between most items
    final int space = 2;
    final FontMetrics fm = this.getFontMetrics(this.getFont());
    // layout's basic line height; most rows have a ColorSquare
    final int lineH = ColorSquare.HEIGHT;
    // face icon width
    final int faceW = 40;
    // player name width, to right of face
    final int pnameW = dim.width - (inset + faceW + inset + inset);
    if (!inPlay) {
        /* just show the 'sit' button */
        /* and the 'robot' button     */
        /* and the pname label        */
        final int sitW;
        if (fm == null)
            sitW = 70;
        else if (sitButIsLock) {
            final int wLock = fm.stringWidth(LOCKSEAT), wUnlock = fm.stringWidth(UNLOCKSEAT);
            sitW = 24 + ((wLock > wUnlock) ? wLock : wUnlock);
        } else {
            sitW = 24 + fm.stringWidth(sitBut.getLabel());
        }
        sitBut.setBounds((dim.width - sitW) / 2, (dim.height - 82) / 2, sitW, 40);
        pname.setBounds(inset + faceW + inset, inset, pnameW, lineH);
    } else {
        // +6 for spacing afterwards
        final int stlmtsW = fm.stringWidth(settlementLab.getText()) + 6;
        // +2 because Label text is inset from column 0
        final int knightsW = fm.stringWidth(knightsLab.getText()) + 2;
        // (for item count labels, either Settlements or Soldiers/Knights is widest text)
        // Top of panel: Face icon, player name to right
        faceImg.setBounds(inset, inset, faceW, faceW);
        pname.setBounds(inset + faceW + inset, inset, pnameW, lineH);
        // To right of face, below player name:
        // Victory Points count, Largest Army, Longest Road
        final int vpW = fm.stringWidth(vpLab.getText().replace(' ', '_'));
        // Bug in stringWidth does not give correct size for ' ' in some versions
        int y = inset + lineH + 2 * space;
        vpLab.setBounds(inset + faceW + inset, y, vpW, lineH);
        vpSq.setBounds(inset + faceW + inset + vpW + space, y, ColorSquare.WIDTH, ColorSquare.HEIGHT);
        final int topStuffW = inset + faceW + inset + vpW + space + ColorSquare.WIDTH + space;
        // always position these: though they may not be visible
        larmyLab.setBounds(topStuffW, y, (dim.width - (topStuffW + inset + space)) / 2, lineH);
        lroadLab.setBounds(topStuffW + ((dim.width - (topStuffW + inset + space)) / 2) + space, y, (dim.width - (topStuffW + inset + space)) / 2, lineH);
        // SVP goes below Victory Points count; usually invisible
        if (svpSq != null) {
            y += (lineH + 1);
            svpLab.setBounds(inset + faceW + inset, y, vpW, lineH);
            svpSq.setBounds(inset + faceW + inset + vpW + space, y, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            if (wonderLab != null) {
                // SC_WOND: Show Wonder Level next to svpSq.
                // Since SC_WOND requires game.hasSeaBoard, svpSq != null for SC_WOND.
                final int x = svpSq.getX() + ColorSquare.WIDTH + space;
                wonderLab.setBounds(x, y, dim.width - x - space, lineH);
            }
        }
        // if (true) {
        if (playerIsClient) {
            /* This is our hand */
            // Top has name, then a row with VP count, largest army, longest road
            // (If game hasn't started yet, "Start Game" button is here instead of that row)
            // SVP is under VP count, if applicable
            // To left below top area: Trade area
            // (Give/Get and SquaresPanel; below that, Offer button and checkboxes, then Clear/Bank buttons)
            // To left below trade area: Resource counts
            // (Clay, Ore, Sheep, Wheat, Wood, Total)
            // To right below top area: Piece counts
            // (Soldiers, Roads, Settlements, Cities, Ships)
            // To right below piece counts: Dev card list, Play button
            // Bottom of panel: 1 button row: Quit to left; Roll, Restart to right
            // Trading SquaresPanel (doesn't include Give/Get labels)
            final Dimension sqpDim = sqPanel.getSize();
            // Bug in stringWidth does not give correct size for ' '
            final int labelspc = fm.stringWidth("_") / 3;
            // width of longest localized string clay/sheep/ore/wheat/wood
            final int sheepW;
            {
                int wmax = 0;
                final Label[] rLabs = { clayLab, oreLab, sheepLab, wheatLab, woodLab };
                for (int i = 0; i < rLabs.length; ++i) {
                    final Label rl = rLabs[i];
                    if (rl != null) {
                        final String txt = rl.getText();
                        if (txt != null) {
                            final int w = fm.stringWidth(rl.getText());
                            if (w > wmax)
                                wmax = w;
                        }
                    }
                }
                if (wmax == 0)
                    // fallback
                    wmax = fm.stringWidth("Sheep:");
                sheepW = wmax + labelspc;
            }
            // Bug in stringWidth
            final int pcW = fm.stringWidth(CARD.replace(' ', '_'));
            // width of trading Give/Get labels
            final int giveW;
            {
                final int gv = fm.stringWidth(GIVE), gt = fm.stringWidth(GET);
                giveW = ((gv > gt) ? gv : gt) + labelspc + 2;
            }
            // int clearW = fm.stringWidth(CLEAR.replace(' ','_'));
            // int bankW = fm.stringWidth(BANK.replace(' ','_'));
            // Clay,Ore,Sheep,Wheat,Wood
            final int resCardsH = 5 * (lineH + space);
            // sqPanel + 2 rows of buttons
            final int tradeH = sqpDim.height + space + (2 * (lineH + space));
            final int sectionSpace = (dim.height - (inset + faceW + resCardsH + tradeH + lineH + inset)) / 3;
            // top of trade area
            final int tradeY = inset + faceW + sectionSpace;
            // top of dev card list
            final int devCardsY = tradeY + tradeH + sectionSpace;
            // Always reposition everything
            startBut.setBounds(inset + faceW + inset, inset + lineH + space, dim.width - (inset + faceW + inset + inset), lineH);
            // Below face, player name, VP count, etc:
            // Section spacer, then:
            // Trade area to left; item counts to right (soldiers,roads,settlements,cities,ships)
            // Trading: Give,Get labels to left of SquaresPanel
            giveLab.setBounds(inset, tradeY, giveW, lineH);
            getLab.setBounds(inset, tradeY + ColorSquareLarger.HEIGHT_L, giveW, lineH);
            sqPanel.setLocation(inset + giveW + space, tradeY);
            // Button rows Below SquaresPanel:
            // Offer button, playerSend checkboxes (3 or 5)
            // Clear, Bank/Port
            // Undo button (below Bank/Port, leaving room on left for resource card counts)
            final int tbW = ((giveW + sqpDim.width) / 2);
            final int tbX = inset;
            int tbY = tradeY + sqpDim.height + space;
            if (offerBut != null) {
                if (game.maxPlayers == 4)
                    offerBut.setBounds(tbX, tbY, tbW, lineH);
                else
                    // 6-player: leave room for 5 checkboxes
                    offerBut.setBounds(tbX, tbY, (2 * tbW) + space - (5 * (1 + ColorSquare.WIDTH)), lineH);
            }
            clearOfferBut.setBounds(tbX, tbY + lineH + space, tbW, lineH);
            bankBut.setBounds(tbX + tbW + space, tbY + lineH + space, tbW, lineH);
            bankUndoBut.setBounds(tbX + tbW + space, tbY + 2 * (lineH + space), tbW, lineH);
            if (!playerTradingDisabled) {
                // Checkboxes to select players to send trade offers
                if (game.maxPlayers == 4) {
                    playerSend[0].setBounds(tbX + tbW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
                    playerSend[1].setBounds(tbX + tbW + space + ((tbW - ColorSquare.WIDTH) / 2), tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
                    playerSend[2].setBounds((tbX + tbW + space + tbW) - ColorSquare.WIDTH, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
                } else {
                    // 6-player: 5 checkboxes
                    int px = tbX + (2 * (space + tbW)) - ColorSquare.WIDTH - 1;
                    for (int pi = 4; pi >= 0; --pi, px -= (ColorSquare.WIDTH + 1)) playerSend[pi].setBounds(px, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
                }
            }
            // Various item counts, to the right of give/get/offer/trade area
            if (clothSq != null) {
                clothLab.setBounds(dim.width - inset - knightsW - ColorSquare.WIDTH - space, tradeY - (lineH + space), knightsW, lineH);
                clothSq.setBounds(dim.width - inset - ColorSquare.WIDTH, tradeY - (lineH + space), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            }
            knightsLab.setBounds(dim.width - inset - knightsW - ColorSquare.WIDTH - space, tradeY, knightsW, lineH);
            knightsSq.setBounds(dim.width - inset - ColorSquare.WIDTH, tradeY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            roadLab.setBounds(dim.width - inset - knightsW - ColorSquare.WIDTH - space, tradeY + lineH + space, knightsW, lineH);
            roadSq.setBounds(dim.width - inset - ColorSquare.WIDTH, tradeY + lineH + space, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            settlementLab.setBounds(dim.width - inset - knightsW - ColorSquare.WIDTH - space, tradeY + (2 * (lineH + space)), knightsW, lineH);
            settlementSq.setBounds(dim.width - inset - ColorSquare.WIDTH, tradeY + (2 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            cityLab.setBounds(dim.width - inset - knightsW - ColorSquare.WIDTH - space, tradeY + (3 * (lineH + space)), knightsW, lineH);
            citySq.setBounds(dim.width - inset - ColorSquare.WIDTH, tradeY + (3 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            if (shipSq != null) {
                shipLab.setBounds(dim.width - inset - knightsW - ColorSquare.WIDTH - space, tradeY + (4 * (lineH + space)), knightsW, lineH);
                shipSq.setBounds(dim.width - inset - ColorSquare.WIDTH, tradeY + (4 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            }
            // Player's resource counts
            // center the group vertical between bottom of Clear button, top of Quit button
            tbY = (((dim.height - lineH - inset) + (tbY + (2 * lineH) + space)) / 2) - (3 * (lineH + space));
            clayLab.setBounds(inset, tbY, sheepW, lineH);
            claySq.setBounds(inset + sheepW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            tbY += (lineH + space);
            oreLab.setBounds(inset, tbY, sheepW, lineH);
            oreSq.setBounds(inset + sheepW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            tbY += (lineH + space);
            sheepLab.setBounds(inset, tbY, sheepW, lineH);
            sheepSq.setBounds(inset + sheepW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            tbY += (lineH + space);
            wheatLab.setBounds(inset, tbY, sheepW, lineH);
            wheatSq.setBounds(inset + sheepW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            tbY += (lineH + space);
            woodLab.setBounds(inset, tbY, sheepW, lineH);
            woodSq.setBounds(inset + sheepW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            // Line between woodSq, resourceSq
            tbY += (lineH + space);
            resourceSqDivLine.setBounds(inset + space, tbY - 1, sheepW + ColorSquare.WIDTH, 1);
            // Total Resources
            ++tbY;
            resourceLab.setBounds(inset, tbY, sheepW, lineH);
            resourceSq.setBounds(inset + sheepW + space, tbY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            // To the right of resource counts:
            // Development Card list, Play button below
            final int clW = dim.width - (inset + sheepW + space + ColorSquare.WIDTH + (4 * space) + inset);
            final int clX = inset + sheepW + space + ColorSquare.WIDTH + (4 * space);
            inventory.setBounds(clX, devCardsY, clW, (4 * (lineH + space)) - 2);
            playCardBut.setBounds(((clW - pcW) / 2) + clX, devCardsY + (4 * (lineH + space)), pcW, lineH);
            // Bottom of panel:
            // 1 button row: Quit to left; Roll, Restart to right
            final int bbW = 50;
            tbY = dim.height - lineH - inset;
            // Label lines up over Roll button
            rollPromptCountdownLab.setBounds(dim.width - (bbW + space + bbW + inset), tbY - lineH, dim.width - 2 * inset, lineH);
            // Bottom row of buttons
            quitBut.setBounds(inset, tbY, bbW, lineH);
            rollBut.setBounds(dim.width - (bbW + space + bbW + inset), tbY, bbW, lineH);
            doneBut.setBounds(dim.width - inset - bbW, tbY, bbW, lineH);
            // since it won't ever be showing
            offerHidesControls = false;
            offerCounterHidesFace = false;
        } else {
            /* This is another player's hand */
            // Top has name, VP count, largest army, longest road; SVP under VP count if applicable
            // Trade offers appear in center when a trade is active
            // Bottom has columns of item counts on left, right, having 3 or 4 rows:
            // Cloth (if that scenario), Soldiers, Res, Dev Cards to left;
            // Ships (if sea board), Roads, Settlements, Cities to right
            // Robot lock button (during play) in bottom center
            // offer-message panel
            int balloonH = dim.height - (inset + (4 * (lineH + space)) + inset);
            if (offer.offerPanel.wantsRejectCountdown())
                balloonH += TradeOfferPanel.LABEL_LINE_HEIGHT;
            // Bug in stringWidth does not give correct size for ' '
            final int dcardsW = fm.stringWidth("Dev._Cards:_");
            if (player.isRobot()) {
                int lowerY = dim.height - ((4 * (lineH + space)) + inset);
                if (game.getPlayer(client.getNickname()) == null) {
                    // If client not seated at this game, show "Take Over" button
                    // just above the lower-left, lower-right columns of item counts
                    int yb = lowerY - 10;
                    if (game.hasSeaBoard)
                        yb -= (lineH + space);
                    takeOverBut.setBounds(10, yb, dim.width - 20, 20);
                } else if (sittingRobotLockBut.isVisible()) {
                    // seatLockBut.setBounds(10, inset+balloonH-10, dim.width-20, 20);
                    // Lock button during play: Bottom of panel, between the 2 columns of item counts
                    sittingRobotLockBut.setBounds(inset + dcardsW + space + ColorSquare.WIDTH + space, lowerY + (lineH + space) + (lineH / 2), (dim.width - (2 * (inset + ColorSquare.WIDTH + (2 * space))) - stlmtsW - dcardsW), 2 * (lineH + space));
                }
            }
            // Are we tall enough for room, after the offer, for other controls?
            // If not, they will be hid when offer is visible.
            int offerMinHeight = TradeOfferPanel.OFFER_HEIGHT + TradeOfferPanel.OFFER_COUNTER_HEIGHT - TradeOfferPanel.OFFER_BUTTONS_HEIGHT;
            if (offer.offerPanel.wantsRejectCountdown())
                offerMinHeight += TradeOfferPanel.LABEL_LINE_HEIGHT;
            offerHidesControls = (dim.height - (inset + faceW + space) - (4 * (lineH + space))) < offerMinHeight;
            if (offerHidesControls) {
                // This flag is set here based on newly calculated layout,
                // for use later when changing offerCounterHidingFace
                offerCounterHidesFace = (dim.height - offerMinHeight) < faceW;
                // pname, vpLab and vpSq, to make room for it.
                if (offerCounterHidingFace) {
                    offer.setBounds(inset, inset, dim.width - (2 * inset), dim.height - (2 * inset));
                } else {
                    offer.setBounds(inset, inset + faceW + space, dim.width - (2 * inset), dim.height - (inset + faceW + 2 * space));
                }
                offer.setCounterHidesBalloonPoint(offerCounterHidingFace);
            } else {
                offer.setBounds(inset, inset + faceW + space, dim.width - (2 * inset), balloonH);
                offerCounterHidesFace = false;
            }
            offer.doLayout();
            final int lowerY = dim.height - ((4 * (lineH + space)) + inset);
            // Lower-left: Column of item counts:
            // Cloth, Soldiers, Resources, Dev Cards
            resourceLab.setBounds(inset, lowerY + (2 * (lineH + space)), dcardsW, lineH);
            resourceSq.setBounds(inset + dcardsW + space, lowerY + (2 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            developmentLab.setBounds(inset, lowerY + (3 * (lineH + space)), dcardsW, lineH);
            developmentSq.setBounds(inset + dcardsW + space, lowerY + (3 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            knightsLab.setBounds(inset, lowerY + (lineH + space), dcardsW, lineH);
            knightsSq.setBounds(inset + dcardsW + space, lowerY + (lineH + space), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            if (clothSq != null) {
                clothLab.setBounds(inset, lowerY, dcardsW, lineH);
                clothSq.setBounds(inset + dcardsW + space, lowerY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            }
            // Ships, Roads, Settlements, Cities
            if (shipSq != null) {
                shipLab.setBounds(dim.width - inset - stlmtsW - ColorSquare.WIDTH - space, lowerY, stlmtsW, lineH);
                shipSq.setBounds(dim.width - inset - ColorSquare.WIDTH, lowerY, ColorSquare.WIDTH, ColorSquare.HEIGHT);
            }
            roadLab.setBounds(dim.width - inset - stlmtsW - ColorSquare.WIDTH - space, lowerY + (lineH + space), stlmtsW, lineH);
            roadSq.setBounds(dim.width - inset - ColorSquare.WIDTH, lowerY + (lineH + space), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            settlementLab.setBounds(dim.width - inset - stlmtsW - ColorSquare.WIDTH - space, lowerY + (2 * (lineH + space)), stlmtsW, lineH);
            settlementSq.setBounds(dim.width - inset - ColorSquare.WIDTH, lowerY + (2 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
            cityLab.setBounds(dim.width - inset - stlmtsW - ColorSquare.WIDTH - space, lowerY + (3 * (lineH + space)), stlmtsW, lineH);
            citySq.setBounds(dim.width - inset - ColorSquare.WIDTH, lowerY + (3 * (lineH + space)), ColorSquare.WIDTH, ColorSquare.HEIGHT);
        }
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Label(java.awt.Label) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension)

Aggregations

Label (java.awt.Label)54 Panel (java.awt.Panel)27 JPanel (javax.swing.JPanel)19 TextField (java.awt.TextField)18 Button (java.awt.Button)17 GridBagConstraints (java.awt.GridBagConstraints)17 BorderLayout (java.awt.BorderLayout)16 GridBagLayout (java.awt.GridBagLayout)16 Choice (java.awt.Choice)12 Dimension (java.awt.Dimension)11 JLabel (javax.swing.JLabel)10 Checkbox (java.awt.Checkbox)9 Component (java.awt.Component)9 Color (java.awt.Color)7 Insets (java.awt.Insets)7 ArrayList (java.util.ArrayList)7 FlowLayout (java.awt.FlowLayout)6 ActionEvent (java.awt.event.ActionEvent)6 JButton (javax.swing.JButton)6 GridLayout (java.awt.GridLayout)5