⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boardselectiondialog.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        texMapWidth.setText(new Integer(mapSettings.getMapWidth()).toString());        texMapHeight.setText(new Integer(mapSettings.getMapHeight()).toString());    }        /**     * Fills the Map Buttons scroll pane with the appropriate amount of buttons     * in the appropriate layout     */    private void refreshMapButtons() {        panMapButtons.removeAll();                panMapButtons.setLayout(new GridLayout(mapSettings.getMapHeight(), mapSettings.getMapWidth()));                for (int i = 0; i < mapSettings.getMapHeight(); i++) {            for (int j = 0; j < mapSettings.getMapWidth(); j++) {                Button button = new Button(new Integer(i * mapSettings.getMapWidth() + j).toString());                button.addActionListener(this);                panMapButtons.add(button);            }        }                scrMapButtons.validate();    }        private void refreshBoardsSelected() {        lisBoardsSelected.removeAll();        int index = 0;        for (Enumeration i = mapSettings.getBoardsSelected(); i.hasMoreElements();) {            lisBoardsSelected.add((index++) + ": " + (String)i.nextElement()); //$NON-NLS-1$        }        lisBoardsSelected.select(0);        refreshSelectAllCheck();    }        private void refreshSelectAllCheck() {        chkSelectAll.setState(lisBoardsSelected.getSelectedIndexes().length == lisBoardsSelected.getItemCount());    }        private void refreshBoardsAvailable() {        lisBoardsAvailable.removeAll();        for (Enumeration i = mapSettings.getBoardsAvailable(); i.hasMoreElements();) {            lisBoardsAvailable.add((String)i.nextElement());        }    }        /**     * Changes all selected boards to be the specified board     */    private void change(String board) {        int[] selected = lisBoardsSelected.getSelectedIndexes();        for (int i = 0; i < selected.length; i++) {            String name = board;            if ( !MapSettings.BOARD_RANDOM.equals(name) &&                 !MapSettings.BOARD_SURPRISE.equals(name) &&                 chkRotateBoard.getState() ) {                name = Board.BOARD_REQUEST_ROTATION + name;            }            lisBoardsSelected.replaceItem(selected[i] + ": " + name, selected[i]); //$NON-NLS-1$            mapSettings.getBoardsSelectedVector().setElementAt(name, selected[i]);            lisBoardsSelected.select(selected[i]);        }    }        /**     * Applies the currently selected map size settings and refreshes the list     * of maps from the server.     */    private void apply() {        int boardWidth;        int boardHeight;        int mapWidth;        int mapHeight;                // read map size settings        try {            boardWidth = Integer.parseInt(texBoardWidth.getText());            boardHeight = Integer.parseInt(texBoardHeight.getText());            mapWidth = Integer.parseInt(texMapWidth.getText());            mapHeight = Integer.parseInt(texMapHeight.getText());        } catch (NumberFormatException ex) {            new AlertDialog(client.frame, Messages.getString("BoardSelectionDialog.InvalidMapSize"), Messages.getString("BoardSelectionDialog.InvalidNumberOfmaps")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$            return;        }                // check settings        if (boardHeight <= 0 || boardHeight <= 0 || mapWidth <= 0 || mapHeight <= 0) {            new AlertDialog(client.frame, Messages.getString("BoardSelectionDialog.InvalidMapSize"), Messages.getString("BoardSelectionDialog.MapSizeMustBeGreateter0")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$            return;        }                butOkay.setEnabled(false);                mapSettings.setBoardSize(boardWidth, boardHeight);        mapSettings.setMapSize(mapWidth, mapHeight);                randomMapDialog.setMapSettings(mapSettings);        refreshMapSize();        refreshMapButtons();                lisBoardsSelected.removeAll();        lisBoardsSelected.add(Messages.getString("BoardSelectionDialog.Updating")); //$NON-NLS-1$                lisBoardsAvailable.removeAll();        lisBoardsAvailable.add(Messages.getString("BoardSelectionDialog.Updating")); //$NON-NLS-1$                client.getClient().sendMapQuery(mapSettings);    }        /**     * Updates to show the map settings that have, presumably, just been sent     * by the server.     */    public void update(MapSettings mapSettings, boolean updateSize) {        this.mapSettings = (MapSettings)mapSettings.clone();        if (updateSize) {            refreshMapSize();            refreshMapButtons();        }        refreshBoardsSelected();        refreshBoardsAvailable();        butOkay.setEnabled(true);    }        /**     * Checks and sends the new map settings to the server     */    public void send() {        // check that they haven't modified the map size settings        if (!texBoardWidth.getText().equals(Integer.toString(mapSettings.getBoardWidth()))        || !texBoardHeight.getText().equals(Integer.toString(mapSettings.getBoardHeight()))        || !texMapWidth.getText().equals(Integer.toString(mapSettings.getMapWidth()))        || !texMapHeight.getText().equals(Integer.toString(mapSettings.getMapHeight()))) {            new AlertDialog(client.frame, Messages.getString("BoardSelectionDialog.UpdateMapSize.title"), Messages.getString("BoardSelectionDialog.UpdateMapSize.message")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$            return;        }                if (mapSettings.getBoardsAvailableVector().size() <= 0) {            new AlertDialog(client.frame, Messages.getString("BoardSelectionDialog.NoBoardOfSelectedSize.title"), Messages.getString("BoardSelectionDialog.NoBoardOfSelectedSize.message")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$            return;        }                client.getClient().sendMapSettings(mapSettings);        this.setVisible(false);        mapPreviewW.setVisible(false);    }        public void previewBoard() {        String boardName = lisBoardsAvailable.getSelectedItem();        if (lisBoardsAvailable.getSelectedIndex() > 2) {            IBoard board = new Board(new Integer(texBoardWidth.getText()), new Integer(texBoardHeight.getText()));            board.load(boardName+".board");            if (chkRotateBoard.getState()) {                BoardUtilities.flip(board, true, true);            }            MapPreview mapPreview = null;            try {                mapPreview = new MapPreview(mapPreviewW, board);            } catch (IOException e) {                e.printStackTrace();            }            mapPreviewW.removeAll();            mapPreviewW.add(mapPreview);            mapPreviewW.setVisible(true);            mapPreview.initializeMap();        }    }        public void actionPerformed(ActionEvent e) {                if (e.getSource() == butChange || e.getSource() == lisBoardsAvailable) {            if (lisBoardsAvailable.getSelectedIndex() != -1) {                change(lisBoardsAvailable.getSelectedItem());            }        } else if (e.getSource() == butUpdate) {            apply();        } else if (e.getSource() == butOkay) {            send();        } else if (e.getSource() == butCancel) {            this.setVisible(false);            mapPreviewW.setVisible(false);        } else if (e.getSource() == butRandomMap) {            randomMapDialog.setVisible(true);        } else if (e.getSource() == butPreview) {            previewBoard();        } else {            try {                int board = Integer.parseInt(e.getActionCommand());                this.lisBoardsSelected.select(board);            } catch (NumberFormatException n) {            } catch (ArrayIndexOutOfBoundsException a) {            }        }    }    public void itemStateChanged(java.awt.event.ItemEvent itemEvent) {        if (itemEvent.getSource() == chkSelectAll) {            lisBoardsSelected.setMultipleMode(chkSelectAll.getState());            for (int i = 0; i < lisBoardsSelected.getItemCount(); i++) {                if (chkSelectAll.getState()) {                    lisBoardsSelected.select(i);                } else {                    lisBoardsSelected.deselect(i);                }            }        } else if (itemEvent.getSource() == lisBoardsSelected) {//            System.out.println(itemEvent.paramString());//            System.out.flush();//            final int[] selected = lisBoardsSelected.getSelectedIndexes();//            for (int i = 0; i < selected.length; i++) {//                lisBoardsSelected.deselect(selected[i]);//            }            if (bDelayedSingleSelect) {                lisBoardsSelected.setMultipleMode(false);            }            refreshSelectAllCheck();        }    }        public void updateMapSettings(MapSettings mapSettings) {        this.mapSettings = mapSettings;        refreshMapSize();        refreshMapButtons();                lisBoardsSelected.removeAll();        lisBoardsSelected.add(Messages.getString("BoardSelectionDialog.Updating")); //$NON-NLS-1$                lisBoardsAvailable.removeAll();        lisBoardsAvailable.add(Messages.getString("BoardSelectionDialog.Updating")); //$NON-NLS-1$                client.getClient().sendMapQuery(mapSettings);    }        /**     * I hate AWT. -jy     * This is a hacked up version of a simple select list that supports     * holding control down to select multiple items.  AWT Lists don't     * support this natively.     *      * The trick is to turn on multiple mode on the list if the user presses     * control.  But we can't turn multi mode off as soon as they release, or     * any existing multi-select will be wiped out.  Instead we set a flag     * to indicate any later selection should trigger a set to single-select      */    public void keyPressed(KeyEvent ev) {        if (ev.getKeyCode() == KeyEvent.VK_CONTROL) {            System.out.println("Multiple on!"); //$NON-NLS-1$            lisBoardsSelected.setMultipleMode(true);            bDelayedSingleSelect = false;        }    }    public void keyReleased(KeyEvent ev) {        if (ev.getKeyCode() == KeyEvent.VK_CONTROL) {            System.out.println("Multiple off!"); //$NON-NLS-1$            bDelayedSingleSelect = true;        }    }    public void keyTyped(KeyEvent arg0) {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -