Package net.java.dev.designgridlayout

Examples of net.java.dev.designgridlayout.DesignGridLayout


    private void createAndShowGUI(String windowTitle) {
        this.frame.setTitle(windowTitle);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        final JButton jbutRandomLayout = new JButton();
        jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JList jl = new JList(Board.QUADRANT_NAMES) {
                @Override
                public JToolTip createToolTip() {
                    return new QuadrantGoalsToolTip(this, Integer.parseInt(this.getToolTipText()));
                };
            };
            jl.setCellRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    list.setToolTipText(String.valueOf(index));
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                };
            });
            jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jl.setVisibleRowCount(1);
            jl.setSelectedIndex(this.board.getQuadrantNum(i));
            jl.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (true == doRefreshJlistQuadrants) {
                        makeBoardQuadrants();
                        refreshJComboPlaceRobot();
                    }
                }
            });
            this.jlistQuadrants[i] = jl;
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        final JButton jbutRemoveWalls = new JButton();
        jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutRemoveGoals = new JButton();
        jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutCopyBoardDumpToClipboard = new JButton();
        jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutCreateBoardFromDump = new JButton();
        jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJlistQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutRotateBoardLeft = new JButton();
        jbutRotateBoardLeft.setText(getAnticlockwiseArrow(jbutRotateBoardLeft.getFont()));
        this.addKeyBindingTooltip(jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        final JButton jbutRotateBoardRight = new JButton();
        jbutRotateBoardRight.setText(getClockwiseArrow(jbutRotateBoardRight.getFont()));
        this.addKeyBindingTooltip(jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        this.jspinWidth.setModel(new SpinnerNumberModel(Board.WIDTH_STANDARD, Board.WIDTH_MIN, Board.WIDTH_MAX, 1));
        this.jspinWidth.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });
        this.jspinHeight.setModel(new SpinnerNumberModel(Board.HEIGHT_STANDARD, Board.HEIGHT_MIN, Board.HEIGHT_MAX, 1));
        this.jspinHeight.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });

        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        this.jlistGoalRobots.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((index - 1) + ";" + jlistGoalShapes.getSelectedIndex());
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        this.jlistGoalShapes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((jlistGoalRobots.getSelectedIndex() - 1) + ";" + index);
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);

        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        final JLabel jlabelBoardTiles = new JLabel(L10N.getString("lbl.BoardTiles.text"));
        editBoardOriginalLayout.row().left().add(jlabelBoardTiles);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[0]), new JScrollPane(this.jlistQuadrants[1])).add(jbutRandomLayout, 2);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[3]), new JScrollPane(this.jlistQuadrants[2])).empty(2);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(jbutRemoveWalls).add(jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Width.text"))).addMulti(this.jspinWidth);
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Height.text"))).addMulti(this.jspinHeight);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.ListGoalColors.text"))).add(new JLabel(L10N.getString("lbl.ListGoalShapes.text")));
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(jbutCopyBoardDumpToClipboard).add(jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(jbutRotateBoardLeft, jbutRotateBoardRight);
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.PreferSolutionWith.text")), this.jcomboOptSolutionMode);
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().grid().add(new JLabel(" "));
        optionsLayout.row().grid().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(this.jcheckOptShowColorNames);
        optionsLayout.row().grid().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().grid().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(getRightwardsArrow(this.jbutNextMove.getFont()));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(getRightwardsBarArrow(this.jbutAllMoves.getFont()));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(getLeftwardsArrow(this.jbutPrevMove.getFont()));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(getLeftwardsBarArrow(this.jbutNoMoves.getFont()));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        ((DefaultCaret)this.jtextSolution.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); // autoscroll
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here


    private void createAndShowGUI(String windowTitle) {
        this.frame.setTitle(windowTitle);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        final JButton jbutRandomLayout = new JButton();
        jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JList jl = new JList(Board.QUADRANT_NAMES) {
                @Override
                public JToolTip createToolTip() {
                    return new QuadrantGoalsToolTip(this, Integer.parseInt(this.getToolTipText()));
                };
            };
            jl.setCellRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    list.setToolTipText(String.valueOf(index));
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                };
            });
            jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jl.setVisibleRowCount(1);
            jl.setSelectedIndex(this.board.getQuadrantNum(i));
            jl.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (true == doRefreshJlistQuadrants) {
                        makeBoardQuadrants();
                        refreshJComboPlaceRobot();
                    }
                }
            });
            this.jlistQuadrants[i] = jl;
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        final JButton jbutRemoveWalls = new JButton();
        jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutRemoveGoals = new JButton();
        jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutCopyBoardDumpToClipboard = new JButton();
        jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutCreateBoardFromDump = new JButton();
        jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJlistQuadrants();
                                    jspinWidth.getModel().setValue(Integer.valueOf(board.width));
                                    jspinHeight.getModel().setValue(Integer.valueOf(board.height));
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutRotateBoardLeft = new JButton();
        jbutRotateBoardLeft.setText(getAnticlockwiseArrow(jbutRotateBoardLeft.getFont()));
        this.addKeyBindingTooltip(jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        final JButton jbutRotateBoardRight = new JButton();
        jbutRotateBoardRight.setText(getClockwiseArrow(jbutRotateBoardRight.getFont()));
        this.addKeyBindingTooltip(jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        this.jspinWidth.setModel(new SpinnerNumberModel(Board.WIDTH_STANDARD, Board.WIDTH_MIN, Board.WIDTH_MAX, 1));
        this.jspinWidth.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                final int width = ((SpinnerNumberModel)jspinWidth.getModel()).getNumber().intValue();
                if (width != board.width) {
                    makeFreestyleBoard();
                }
            }
        });
        this.jspinHeight.setModel(new SpinnerNumberModel(Board.HEIGHT_STANDARD, Board.HEIGHT_MIN, Board.HEIGHT_MAX, 1));
        this.jspinHeight.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                final int height = ((SpinnerNumberModel)jspinHeight.getModel()).getNumber().intValue();
                if (height != board.height) {
                    makeFreestyleBoard();
                }
            }
        });

        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        this.jlistGoalRobots.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((index - 1) + ";" + jlistGoalShapes.getSelectedIndex());
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        this.jlistGoalShapes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((jlistGoalRobots.getSelectedIndex() - 1) + ";" + index);
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);

        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        final JLabel jlabelBoardTiles = new JLabel(L10N.getString("lbl.BoardTiles.text"));
        editBoardOriginalLayout.row().left().add(jlabelBoardTiles);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[0]), new JScrollPane(this.jlistQuadrants[1])).add(jbutRandomLayout, 2);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[3]), new JScrollPane(this.jlistQuadrants[2])).empty(2);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(jbutRemoveWalls).add(jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Width.text"))).addMulti(this.jspinWidth);
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Height.text"))).addMulti(this.jspinHeight);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.ListGoalColors.text"))).add(new JLabel(L10N.getString("lbl.ListGoalShapes.text")));
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(jbutCopyBoardDumpToClipboard).add(jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(jbutRotateBoardLeft, jbutRotateBoardRight);
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.PreferSolutionWith.text")), this.jcomboOptSolutionMode);
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().grid().add(new JLabel(" "));
        optionsLayout.row().grid().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(this.jcheckOptShowColorNames);
        optionsLayout.row().grid().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().grid().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(getRightwardsArrow(this.jbutNextMove.getFont()));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(getRightwardsBarArrow(this.jbutAllMoves.getFont()));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(getLeftwardsArrow(this.jbutPrevMove.getFont()));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(getLeftwardsBarArrow(this.jbutNoMoves.getFont()));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        ((DefaultCaret)this.jtextSolution.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); // autoscroll
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

    private void createAndShowGUI(String windowTitle) {
        this.frame.setTitle(windowTitle);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        final JButton jbutRandomLayout = new JButton();
        jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JList jl = new JList(Board.QUADRANT_NAMES) {
                @Override
                public JToolTip createToolTip() {
                    return new QuadrantGoalsToolTip(this, Integer.parseInt(this.getToolTipText()));
                };
            };
            jl.setCellRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    list.setToolTipText(String.valueOf(index));
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                };
            });
            jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jl.setVisibleRowCount(1);
            jl.setSelectedIndex(this.board.getQuadrantNum(i));
            jl.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (true == doRefreshJlistQuadrants) {
                        makeBoardQuadrants();
                        refreshJComboPlaceRobot();
                    }
                }
            });
            this.jlistQuadrants[i] = jl;
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        final JButton jbutRemoveWalls = new JButton();
        jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutRemoveGoals = new JButton();
        jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutCopyBoardDumpToClipboard = new JButton();
        jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutCreateBoardFromDump = new JButton();
        jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJlistQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutRotateBoardLeft = new JButton();
        jbutRotateBoardLeft.setText(L10N.getString("btn.RotateBoardLeft.text"));
        this.addKeyBindingTooltip(jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        final JButton jbutRotateBoardRight = new JButton();
        jbutRotateBoardRight.setText(L10N.getString("btn.RotateBoardRight.text"));
        this.addKeyBindingTooltip(jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        this.jspinWidth.setModel(new SpinnerNumberModel(Board.WIDTH_STANDARD, Board.WIDTH_MIN, Board.WIDTH_MAX, 1));
        this.jspinWidth.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });
        this.jspinHeight.setModel(new SpinnerNumberModel(Board.HEIGHT_STANDARD, Board.HEIGHT_MIN, Board.HEIGHT_MAX, 1));
        this.jspinHeight.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });

        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        this.jlistGoalRobots.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((index - 1) + ";" + jlistGoalShapes.getSelectedIndex());
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        this.jlistGoalShapes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((jlistGoalRobots.getSelectedIndex() - 1) + ";" + index);
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);

        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        final JLabel jlabelBoardTiles = new JLabel(L10N.getString("lbl.BoardTiles.text"));
        editBoardOriginalLayout.row().left().add(jlabelBoardTiles);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[0]), new JScrollPane(this.jlistQuadrants[1])).add(jbutRandomLayout, 2);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[3]), new JScrollPane(this.jlistQuadrants[2])).empty(2);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(jbutRemoveWalls).add(jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Width.text")), 2).add(this.jspinWidth).empty();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Height.text")), 2).add(this.jspinHeight).empty();
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.ListGoalColors.text"))).add(new JLabel(L10N.getString("lbl.ListGoalShapes.text")));
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(jbutCopyBoardDumpToClipboard).add(jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(jbutRotateBoardLeft, jbutRotateBoardRight);
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().left().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().left().addMulti(new JLabel(L10N.getString("lbl.PreferSolutionWith.text")), this.jcomboOptSolutionMode);
        optionsLayout.row().left().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().left().add(new JLabel(" "));
        optionsLayout.row().left().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().left().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().left().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().left().add(this.jcheckOptShowColorNames);
        optionsLayout.row().left().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().left().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(L10N.getString("btn.NextMove.text"));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(L10N.getString("btn.AllMoves.text"));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(L10N.getString("btn.PrevMove.text"));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(L10N.getString("btn.NoMoves.text"));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        ((DefaultCaret)this.jtextSolution.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); // autoscroll
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);

        final JPanel preparePanel = new JPanel();
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.BoardTiles.text")));
        prepareLayout.row().grid().addMulti(this.jcomboQuadrants[0], this.jcomboQuadrants[1]).add(jbutRandomLayout);
        prepareLayout.row().grid().addMulti(this.jcomboQuadrants[3], this.jcomboQuadrants[2]).empty();
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text"))).addMulti(this.jcomboRobots);
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.PreferSolutionWith.text"))).addMulti(this.jcomboOptSolutionMode);
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(this.jcheckOptAllowRebounds);
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(this.jcheckOptShowColorNames);
        prepareLayout.row().grid().add(this.jcheckOptShowSolutions);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(L10N.getString("btn.NextMove.text"));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(L10N.getString("btn.AllMoves.text"));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(L10N.getString("btn.PrevMove.text"));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(L10N.getString("btn.NoMoves.text"));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        final JPanel playPanel = new JPanel();
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoardOptions.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
        this.jtabPreparePlay.setSelectedIndex(1);   //Play
        this.jtabPreparePlay.addChangeListener(new TabListener());
View Full Code Here

    private void createAndShowGUI(String windowTitle) {
        final JFrame frame = new JFrame(windowTitle);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        this.jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(this.jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJcomboQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JComboBox jc = new JComboBox();
            jc.setModel(new DefaultComboBoxModel(Board.QUADRANT_NAMES));
            jc.setEditable(false);
            jc.setSelectedIndex(this.board.getQuadrantNum(i));
            jc.setActionCommand(AC_BOARD_QUADRANTS);
            jc.addActionListener(this);
            this.jcomboQuadrants.add(jc);
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        this.jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        this.jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        this.jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        this.jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        this.jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        this.jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        this.jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(this.jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        this.jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(this.jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJcomboQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        this.jbutRotateBoardLeft.setText(L10N.getString("btn.RotateBoardLeft.text"));
        this.addKeyBindingTooltip(this.jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJcomboQuadrants();
                    }
                }
        );

        this.jbutRotateBoardRight.setText(L10N.getString("btn.RotateBoardRight.text"));
        this.addKeyBindingTooltip(this.jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJcomboQuadrants();
                    }
                }
        );
       
        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);


        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        editBoardOriginalLayout.row().left().add(this.jlabelBoardTiles);
        editBoardOriginalLayout.emptyRow();
        editBoardOriginalLayout.row().grid().add(this.jcomboQuadrants.get(0), this.jcomboQuadrants.get(1)).empty(2);
        editBoardOriginalLayout.row().grid().add(this.jcomboQuadrants.get(3), this.jcomboQuadrants.get(2)).empty(2);
        editBoardOriginalLayout.emptyRow();
        editBoardOriginalLayout.row().left().add(this.jbutRandomLayout);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(this.jbutRemoveWalls).add(this.jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(this.jlabelListGoalColors).add(this.jlabelListGoalShapes);
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.row().grid().add(this.jbutCopyBoardDumpToClipboard).add(this.jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(this.jbutRotateBoardLeft, this.jbutRotateBoardRight);
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.PreferSolutionWith.text"))).addMulti(this.jcomboOptSolutionMode);
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().grid().add(new JLabel(" "));
        optionsLayout.row().grid().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(this.jcheckOptShowColorNames);
        optionsLayout.row().grid().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().grid().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(L10N.getString("btn.NextMove.text"));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(L10N.getString("btn.AllMoves.text"));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(L10N.getString("btn.PrevMove.text"));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(L10N.getString("btn.NoMoves.text"));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

    private void createAndShowGUI(String windowTitle) {
        this.frame.setTitle(windowTitle);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        final JButton jbutRandomLayout = new JButton();
        jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JList jl = new JList(Board.QUADRANT_NAMES) {
                @Override
                public JToolTip createToolTip() {
                    return new QuadrantGoalsToolTip(this, Integer.parseInt(this.getToolTipText()));
                };
            };
            jl.setCellRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    list.setToolTipText(String.valueOf(index));
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                };
            });
            jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jl.setVisibleRowCount(1);
            jl.setSelectedIndex(this.board.getQuadrantNum(i));
            jl.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (true == doRefreshJlistQuadrants) {
                        makeBoardQuadrants();
                        refreshJComboPlaceRobot();
                    }
                }
            });
            this.jlistQuadrants[i] = jl;
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        final JButton jbutRemoveWalls = new JButton();
        jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutRemoveGoals = new JButton();
        jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutCopyBoardDumpToClipboard = new JButton();
        jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutCreateBoardFromDump = new JButton();
        jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJlistQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutRotateBoardLeft = new JButton();
        jbutRotateBoardLeft.setText(getAnticlockwiseArrow(jbutRotateBoardLeft.getFont()));
        this.addKeyBindingTooltip(jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        final JButton jbutRotateBoardRight = new JButton();
        jbutRotateBoardRight.setText(getClockwiseArrow(jbutRotateBoardRight.getFont()));
        this.addKeyBindingTooltip(jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        this.jspinWidth.setModel(new SpinnerNumberModel(Board.WIDTH_STANDARD, Board.WIDTH_MIN, Board.WIDTH_MAX, 1));
        this.jspinWidth.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });
        this.jspinHeight.setModel(new SpinnerNumberModel(Board.HEIGHT_STANDARD, Board.HEIGHT_MIN, Board.HEIGHT_MAX, 1));
        this.jspinHeight.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });

        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        this.jlistGoalRobots.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((index - 1) + ";" + jlistGoalShapes.getSelectedIndex());
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        this.jlistGoalShapes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((jlistGoalRobots.getSelectedIndex() - 1) + ";" + index);
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);

        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        final JLabel jlabelBoardTiles = new JLabel(L10N.getString("lbl.BoardTiles.text"));
        editBoardOriginalLayout.row().left().add(jlabelBoardTiles);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[0]), new JScrollPane(this.jlistQuadrants[1])).add(jbutRandomLayout, 2);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[3]), new JScrollPane(this.jlistQuadrants[2])).empty(2);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(jbutRemoveWalls).add(jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Width.text"))).addMulti(this.jspinWidth);
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Height.text"))).addMulti(this.jspinHeight);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.ListGoalColors.text"))).add(new JLabel(L10N.getString("lbl.ListGoalShapes.text")));
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(jbutCopyBoardDumpToClipboard).add(jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(jbutRotateBoardLeft, jbutRotateBoardRight);
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.PreferSolutionWith.text")), this.jcomboOptSolutionMode);
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().grid().add(new JLabel(" "));
        optionsLayout.row().grid().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(this.jcheckOptShowColorNames);
        optionsLayout.row().grid().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().grid().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(getRightwardsArrow(this.jbutNextMove.getFont()));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(getRightwardsBarArrow(this.jbutAllMoves.getFont()));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(getLeftwardsArrow(this.jbutPrevMove.getFont()));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(getLeftwardsBarArrow(this.jbutNoMoves.getFont()));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        ((DefaultCaret)this.jtextSolution.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); // autoscroll
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

    private void createAndShowGUI(String windowTitle) {
        final JFrame frame = new JFrame(windowTitle);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        this.jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(this.jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JList jl = new JList(Board.QUADRANT_NAMES) {
                @Override
                public JToolTip createToolTip() {
                    return new QuadrantGoalsToolTip(this, Integer.parseInt(this.getToolTipText()));
                };
            };
            jl.setCellRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    list.setToolTipText(String.valueOf(index));
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                };
            });
            jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jl.setVisibleRowCount(1);
            jl.setSelectedIndex(this.board.getQuadrantNum(i));
            jl.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (true == doRefreshJlistQuadrants) {
                        makeBoardQuadrants();
                        refreshJComboPlaceRobot();
                    }
                }
            });
            this.jlistQuadrants[i] = jl;
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        this.jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        this.jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        this.jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        this.jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        this.jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        this.jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        this.jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(this.jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        this.jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(this.jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJlistQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        this.jbutRotateBoardLeft.setText(L10N.getString("btn.RotateBoardLeft.text"));
        this.addKeyBindingTooltip(this.jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        this.jbutRotateBoardRight.setText(L10N.getString("btn.RotateBoardRight.text"));
        this.addKeyBindingTooltip(this.jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        this.jlistGoalRobots.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((index - 1) + ";" + jlistGoalShapes.getSelectedIndex());
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        this.jlistGoalShapes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((jlistGoalRobots.getSelectedIndex() - 1) + ";" + index);
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);

        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        editBoardOriginalLayout.row().left().add(this.jlabelBoardTiles);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[0]), new JScrollPane(this.jlistQuadrants[1])).add(this.jbutRandomLayout, 2);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[3]), new JScrollPane(this.jlistQuadrants[2])).empty(2);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(this.jbutRemoveWalls).add(this.jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(this.jlabelListGoalColors).add(this.jlabelListGoalShapes);
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.row().grid().add(this.jbutCopyBoardDumpToClipboard).add(this.jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(this.jbutRotateBoardLeft, this.jbutRotateBoardRight);
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().left().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().left().addMulti(new JLabel(L10N.getString("lbl.PreferSolutionWith.text")), this.jcomboOptSolutionMode);
        optionsLayout.row().left().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().left().add(new JLabel(" "));
        optionsLayout.row().left().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().left().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().left().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().left().add(this.jcheckOptShowColorNames);
        optionsLayout.row().left().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().left().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(L10N.getString("btn.NextMove.text"));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(L10N.getString("btn.AllMoves.text"));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(L10N.getString("btn.PrevMove.text"));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(L10N.getString("btn.NoMoves.text"));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

    private void createAndShowGUI(String windowTitle) {
        final JFrame frame = new JFrame(windowTitle);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        this.jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(this.jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJcomboQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JComboBox jc = new JComboBox();
            jc.setModel(new DefaultComboBoxModel(Board.QUADRANT_NAMES));
            jc.setEditable(false);
            jc.setSelectedIndex(this.board.getQuadrantNum(i));
            jc.setActionCommand(AC_BOARD_QUADRANTS);
            jc.addActionListener(this);
            this.jcomboQuadrants.add(jc);
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        this.jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        this.jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        this.jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        this.jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        this.jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        this.jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        this.jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(this.jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        this.jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(this.jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJcomboQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        this.jbutRotateBoardLeft.setText(L10N.getString("btn.RotateBoardLeft.text"));
        this.addKeyBindingTooltip(this.jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJcomboQuadrants();
                    }
                }
        );

        this.jbutRotateBoardRight.setText(L10N.getString("btn.RotateBoardRight.text"));
        this.addKeyBindingTooltip(this.jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJcomboQuadrants();
                    }
                }
        );
       
        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);


        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        editBoardOriginalLayout.row().left().add(this.jlabelBoardTiles);
        editBoardOriginalLayout.emptyRow();
        editBoardOriginalLayout.row().grid().add(this.jcomboQuadrants.get(0), this.jcomboQuadrants.get(1)).empty(2);
        editBoardOriginalLayout.row().grid().add(this.jcomboQuadrants.get(3), this.jcomboQuadrants.get(2)).empty(2);
        editBoardOriginalLayout.emptyRow();
        editBoardOriginalLayout.row().left().add(this.jbutRandomLayout);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(this.jbutRemoveWalls).add(this.jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(this.jlabelListGoalColors).add(this.jlabelListGoalShapes);
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.row().grid().add(this.jbutCopyBoardDumpToClipboard).add(this.jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(this.jbutRotateBoardLeft, this.jbutRotateBoardRight);
        prepareLayout.emptyRow();
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MINIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.PreferSolutionWith.text"))).addMulti(this.jcomboOptSolutionMode);
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().grid().add(new JLabel(" "));
        optionsLayout.row().grid().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(this.jcheckOptShowColorNames);
        optionsLayout.row().grid().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().grid().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(L10N.getString("btn.NextMove.text"));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(L10N.getString("btn.AllMoves.text"));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(L10N.getString("btn.PrevMove.text"));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(L10N.getString("btn.NoMoves.text"));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

    private void createAndShowGUI(String windowTitle) {
        this.frame.setTitle(windowTitle);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        final JPanel preparePanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
       
        final JButton jbutRandomLayout = new JButton();
        jbutRandomLayout.setText(L10N.getString("btn.RandomLayout.text"));
        this.addKeyBindingTooltip(jbutRandomLayout,
                L10N.getString("btn.RandomLayout.acceleratorkey"),
                L10N.getString("btn.RandomLayout.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        makeRandomBoardQuadrants();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );
       
        for (int i = 0;  i < 4;  ++i) {
            final JList jl = new JList(Board.QUADRANT_NAMES) {
                @Override
                public JToolTip createToolTip() {
                    return new QuadrantGoalsToolTip(this, Integer.parseInt(this.getToolTipText()));
                };
            };
            jl.setCellRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    list.setToolTipText(String.valueOf(index));
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                };
            });
            jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jl.setVisibleRowCount(1);
            jl.setSelectedIndex(this.board.getQuadrantNum(i));
            jl.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (true == doRefreshJlistQuadrants) {
                        makeBoardQuadrants();
                        refreshJComboPlaceRobot();
                    }
                }
            });
            this.jlistQuadrants[i] = jl;
        }
       
        final String[] strRobots = { "1", "2", "3", "4", "5" };
        this.jcomboRobots.setModel(new DefaultComboBoxModel(strRobots));
        this.jcomboRobots.setEditable(false);
        this.jcomboRobots.setActionCommand(AC_BOARD_ROBOTS);
        this.jcomboRobots.addActionListener(this);
        this.refreshJcomboRobots();
       
        final JButton jbutRemoveWalls = new JButton();
        jbutRemoveWalls.setText(L10N.getString("btn.RemoveWalls.text"));
        jbutRemoveWalls.setToolTipText(L10N.getString("btn.RemoveWalls.tooltip"));
        jbutRemoveWalls.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeWalls();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutRemoveGoals = new JButton();
        jbutRemoveGoals.setText(L10N.getString("btn.RemoveGoals.text"));
        jbutRemoveGoals.setToolTipText(L10N.getString("btn.RemoveGoals.tooltip"));
        jbutRemoveGoals.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                board.removeGoals();
                board.setFreestyleBoard();
                refreshBoard();
            }
        });

        final JButton jbutCopyBoardDumpToClipboard = new JButton();
        jbutCopyBoardDumpToClipboard.setText(L10N.getString("btn.CopyBoardDumpToClipboard.text"));
        this.addKeyBindingTooltip(jbutCopyBoardDumpToClipboard,
                L10N.getString("btn.CopyBoardDumpToClipboard.acceleratorkey"),
                L10N.getString("btn.CopyBoardDumpToClipboard.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                            String data = board.getGameDump();
                            clip.setContents(new StringSelection(data), null);
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.message"),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.OK.title"),
                                    JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.message") + "\n" + ex.toString(),
                                    L10N.getString("msg.CopyBoardDumpToClipboard.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutCreateBoardFromDump = new JButton();
        jbutCreateBoardFromDump.setText(L10N.getString("btn.CreateBoardFromDump.text"));
        this.addKeyBindingTooltip(jbutCreateBoardFromDump,
                L10N.getString("btn.CreateBoardFromDump.acceleratorkey"),
                L10N.getString("btn.CreateBoardFromDump.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            final String data = JOptionPane.showInputDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.input.message"),
                                    L10N.getString("msg.CreateBoardFromDump.input.title"),
                                    JOptionPane.PLAIN_MESSAGE);
                            if ((null != data) && (0 != data.length())) {
                                final Board newBoard = Board.createBoardGameDump(data);
                                if (null != newBoard) {
                                    board = newBoard;
                                    if (board.isFreestyleBoard()) {
                                        jtabEditBoard.setSelectedIndex(1);
                                    }
                                    refreshBoard();
                                    refreshJcomboRobots();
                                    refreshJComboPlaceRobot();
                                    refreshJlistQuadrants();
                                } else {
                                    throw new IllegalArgumentException();   //show error message
                                }
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(frame,
                                    L10N.getString("msg.CreateBoardFromDump.Error.message"),
                                    L10N.getString("msg.CreateBoardFromDump.Error.title"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
        );

        final JButton jbutRotateBoardLeft = new JButton();
        jbutRotateBoardLeft.setText(L10N.getString("btn.RotateBoardLeft.text"));
        this.addKeyBindingTooltip(jbutRotateBoardLeft,
                L10N.getString("btn.RotateBoardLeft.acceleratorkey"),
                L10N.getString("btn.RotateBoardLeft.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(false);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        final JButton jbutRotateBoardRight = new JButton();
        jbutRotateBoardRight.setText(L10N.getString("btn.RotateBoardRight.text"));
        this.addKeyBindingTooltip(jbutRotateBoardRight,
                L10N.getString("btn.RotateBoardRight.acceleratorkey"),
                L10N.getString("btn.RotateBoardRight.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        board = board.rotate90(true);
                        refreshBoard();
                        refreshJComboPlaceRobot();
                        refreshJlistQuadrants();
                    }
                }
        );

        this.jspinWidth.setModel(new SpinnerNumberModel(Board.WIDTH_STANDARD, Board.WIDTH_MIN, Board.WIDTH_MAX, 1));
        this.jspinWidth.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });
        this.jspinHeight.setModel(new SpinnerNumberModel(Board.HEIGHT_STANDARD, Board.HEIGHT_MIN, Board.HEIGHT_MAX, 1));
        this.jspinHeight.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                makeFreestyleBoard();
            }
        });

        final Vector<String> dataGoalRobots = new Vector<String>();
        for (int color = -1;  color < 4;  ++color) {
            dataGoalRobots.add(Board.getColorLongL10N(color));
        }
        this.jlistGoalRobots.setListData(dataGoalRobots);
        this.jlistGoalRobots.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalRobots.setSelectedIndex(0 + 1);
        this.jlistGoalRobots.setVisibleRowCount(dataGoalRobots.size());
        this.jlistGoalRobots.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((index - 1) + ";" + jlistGoalShapes.getSelectedIndex());
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalRobots = new JScrollPane(this.jlistGoalRobots);

        final Vector<String> dataGoalShapes = new Vector<String>();
        for (int shape = 0;  shape < 4;  ++shape) {
            dataGoalShapes.add(Board.getGoalShapeL10N(shape));
        }
        this.jlistGoalShapes.setListData(dataGoalShapes);
        this.jlistGoalShapes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.jlistGoalShapes.setSelectedIndex(0);
        this.jlistGoalShapes.setVisibleRowCount(dataGoalShapes.size());
        this.jlistGoalShapes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                list.setToolTipText((jlistGoalRobots.getSelectedIndex() - 1) + ";" + index);
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            };
        });
        final JScrollPane jscrollGoalShapes = new JScrollPane(this.jlistGoalShapes);

        final JPanel editBoardOriginalPanel = new JPanel();
        final DesignGridLayout editBoardOriginalLayout = new DesignGridLayout(editBoardOriginalPanel);
        final JLabel jlabelBoardTiles = new JLabel(L10N.getString("lbl.BoardTiles.text"));
        editBoardOriginalLayout.row().left().add(jlabelBoardTiles);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[0]), new JScrollPane(this.jlistQuadrants[1])).add(jbutRandomLayout, 2);
        editBoardOriginalLayout.row().grid().add(new JScrollPane(this.jlistQuadrants[3]), new JScrollPane(this.jlistQuadrants[2])).empty(2);

        final JPanel editBoardFreestylePanel = new JPanel();
        final DesignGridLayout editBoardFreestyleLayout = new DesignGridLayout(editBoardFreestylePanel);
        editBoardFreestyleLayout.row().grid().add(jbutRemoveWalls).add(jbutRemoveGoals);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Width.text"))).addMulti(this.jspinWidth);
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.Height.text"))).addMulti(this.jspinHeight);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(new JLabel(L10N.getString("lbl.ListGoalColors.text"))).add(new JLabel(L10N.getString("lbl.ListGoalShapes.text")));
        editBoardFreestyleLayout.row().grid().add(jscrollGoalRobots).add(jscrollGoalShapes);
        editBoardFreestyleLayout.emptyRow();
        editBoardFreestyleLayout.row().grid().add(jbutCopyBoardDumpToClipboard).add(jbutCreateBoardFromDump);

        this.jtabEditBoard.addTab(L10N.getString("tab.OriginalBoard.text"),
                null, editBoardOriginalPanel, L10N.getString("tab.OriginalBoard.tooltip"));
        this.jtabEditBoard.addTab(L10N.getString("tab.FreestyleBoard.text"),
                null, editBoardFreestylePanel, L10N.getString("tab.FreestyleBoard.tooltip"));
        this.jtabEditBoard.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                jcomboGameIDs.setEnabled( ! SwingGUI.this.isFreestyleBoard());
            }
        });
       
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobots.text")), 2).add(this.jcomboRobots).empty();
        prepareLayout.row().grid().add(new JLabel(L10N.getString("lbl.RotateBoard.text")), 2).add(jbutRotateBoardLeft, jbutRotateBoardRight);
        prepareLayout.row().grid().add(this.jtabEditBoard);


        final JPanel optionsPanel = new JPanel();   //-----------------------------------------------
        final DesignGridLayout optionsLayout = new DesignGridLayout(optionsPanel);
       
        final Solver.SOLUTION_MODE[] solModes = Solver.SOLUTION_MODE.values();
        this.jcomboOptSolutionMode.setModel(new DefaultComboBoxModel(solModes));
        this.jcomboOptSolutionMode.setSelectedItem(Solver.SOLUTION_MODE.MAXIMUM);
       
        this.jcheckOptAllowRebounds.setText(L10N.getString("chk.AllowReboundMoves.text"));
        this.jcheckOptAllowRebounds.setSelected(true);

        this.jcheckOptShowColorNames.setText(L10N.getString("chk.ShowColorNames.text"));
        this.jcheckOptShowColorNames.setSelected(false);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        this.jcheckOptShowOnlyActiveGoal.setText(L10N.getString("chk.ShowOnlyActiveGoal.text"));
        this.jcheckOptShowOnlyActiveGoal.setSelected(true);
        this.jcheckOptShowOnlyActiveGoal.setActionCommand(AC_SHOW_ACTIVE_GOAL);
        this.jcheckOptShowOnlyActiveGoal.addActionListener(this);

        this.jcheckOptShowSolutions.setText(L10N.getString("chk.ShowSolutions.text"));
        this.jcheckOptShowSolutions.setSelected(false);
       
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.SolverOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.PreferSolutionWith.text")), this.jcomboOptSolutionMode);
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.NumberOfRobotsMoved.text")));
        optionsLayout.row().grid().add(new JLabel(" "));
        optionsLayout.row().grid().add(this.jcheckOptAllowRebounds);
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JSeparator());
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(new JLabel(L10N.getString("lbl.GUIOptions.text")));
        optionsLayout.emptyRow();
        optionsLayout.row().grid().add(this.jcheckOptShowColorNames);
        optionsLayout.row().grid().add(this.jcheckOptShowOnlyActiveGoal);
        optionsLayout.row().grid().add(this.jcheckOptShowSolutions);
       
       
        final JPanel playPanel = new JPanel();      //-----------------------------------------------
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
       
        final JButton jbutRandomRobots = new JButton(L10N.getString("btn.RandomRobots.text"));
        this.addKeyBindingTooltip(jbutRandomRobots,
                L10N.getString("btn.RandomRobots.acceleratorkey"),
                L10N.getString("btn.RandomRobots.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton(L10N.getString("btn.RandomGoal.text"));
        this.addKeyBindingTooltip(jbutRandomGoal,
                L10N.getString("btn.RandomGoal.acceleratorkey"),
                L10N.getString("btn.RandomGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        String prtt = "<html>" + L10N.getString("cmb.PlaceRobot.tooltip") + " &nbsp; <small><strong>";
        final JButton jbutPlaceRobot = new JButton("place robot accelerator keys");
        jbutPlaceRobot.setPreferredSize(new Dimension())//invisible button
        prtt += this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.1.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 1) { jcomboPlaceRobot.setSelectedIndex(1); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.2.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 2) { jcomboPlaceRobot.setSelectedIndex(2); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.3.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 3) { jcomboPlaceRobot.setSelectedIndex(3); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.4.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 4) { jcomboPlaceRobot.setSelectedIndex(4); }
                    }
                }
        );
        prtt += " &nbsp; " + this.addKeyBindingTooltip(jbutPlaceRobot, L10N.getString("cmb.PlaceRobot.5.acceleratorkey"), "",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (jcomboPlaceRobot.getItemCount() > 5) { jcomboPlaceRobot.setSelectedIndex(5); }
                    }
                }
        );
        this.jcomboPlaceRobot.setToolTipText(prtt + "</strong></small></html>");
       
        final JButton jbutSelectGoal = new JButton(L10N.getString("btn.SelectGoal.text"));
        this.addKeyBindingTooltip(jbutSelectGoal,
                L10N.getString("btn.SelectGoal.acceleratorkey"),
                L10N.getString("btn.SelectGoal.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        selectGoal = !selectGoal;
                        refreshBoard();
                    }
                }
        );
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem(L10N.getString("cmb.SelectSolution.text"));
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText(L10N.getString("cmb.SelectSolution.tooltip"));
       
        this.jbutSolutionHint.setText(L10N.getString("btn.Hint.text"));
        this.addKeyBindingTooltip(this.jbutSolutionHint,
                L10N.getString("btn.Hint.acceleratorkey"),
                L10N.getString("btn.Hint.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
        this.jbutNextMove.setText(L10N.getString("btn.NextMove.text"));
        this.addKeyBindingTooltip(this.jbutNextMove,
                L10N.getString("btn.NextMove.acceleratorkey"),
                L10N.getString("btn.NextMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
        this.jbutAllMoves.setText(L10N.getString("btn.AllMoves.text"));
        this.addKeyBindingTooltip(this.jbutAllMoves,
                L10N.getString("btn.AllMoves.acceleratorkey"),
                L10N.getString("btn.AllMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
        this.jbutPrevMove.setText(L10N.getString("btn.PrevMove.text"));
        this.addKeyBindingTooltip(this.jbutPrevMove,
                L10N.getString("btn.PrevMove.acceleratorkey"),
                L10N.getString("btn.PrevMove.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
        this.jbutNoMoves.setText(L10N.getString("btn.NoMoves.text"));
        this.addKeyBindingTooltip(this.jbutNoMoves,
                L10N.getString("btn.NoMoves.acceleratorkey"),
                L10N.getString("btn.NoMoves.tooltip"),
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        ((DefaultCaret)this.jtextSolution.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); // autoscroll
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(panelSolutionText, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        playLayout.row().grid().addMulti(new JLabel(L10N.getString("lbl.SetStartingPosition.text")), jbutPlaceRobot);
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(jbutSelectGoal);
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.GameID.text"))).add(this.jcomboGameIDs, 3);
        playLayout.emptyRow();
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel(L10N.getString("lbl.ShowComputedSolutions.text")));
        playLayout.row().grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().grid().add(scrollSolutionText);
       
       
        this.jtabPreparePlay.addTab(L10N.getString("tab.PrepareBoard.text"), preparePanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.Options.text"), optionsPanel);
        this.jtabPreparePlay.addTab(L10N.getString("tab.PlayGame.text"), playPanel);
View Full Code Here

        this.jcheckOptShowColorNames.setSelected(true);
        this.jcheckOptShowColorNames.setActionCommand(AC_SHOW_COLOR_NAMES);
        this.jcheckOptShowColorNames.addActionListener(this);

        final JPanel preparePanel = new JPanel();
        final DesignGridLayout prepareLayout = new DesignGridLayout(preparePanel);
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.row().grid().add(new JLabel("board tiles")).add(jbutRandomLayout);
        prepareLayout.row().grid().add(this.jcomboQuadrants[0]).add(this.jcomboQuadrants[1]);
        prepareLayout.row().grid().add(this.jcomboQuadrants[3]).add(this.jcomboQuadrants[2]);
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(new JLabel("number of robots")).add(this.jcomboRobots);
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.row().grid().add(new JLabel("solver options"));
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(new JLabel("prefer solution with")).add(this.jcomboOptSolutionMode);
        prepareLayout.row().grid().add(new JLabel("number of robots moved"));
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(this.jcheckOptAllowRebounds);
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(new JSeparator());
        prepareLayout.row().grid().add(new JLabel("GUI options"));
        prepareLayout.row().grid().add(new JLabel(" "));
        prepareLayout.row().grid().add(this.jcheckOptShowColorNames);
       
        final JButton jbutRandomRobots = new JButton("Random robots");
        this.addKeyBindingTooltip(jbutRandomRobots, KeyEvent.VK_R,
                "place the robots randomly on the board",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeRobot = -1;
                        refreshJComboPlaceRobot();
                        updateBoardRandomRobots();
                    }
                }
        );
       
        final JButton jbutRandomGoal = new JButton("Random goal");
        this.addKeyBindingTooltip(jbutRandomGoal, KeyEvent.VK_G,
                "pick a goal at random",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        placeGoal = false;
                        updateBoardRandomGoal();
                    }
                }
        );
       
        this.refreshJComboPlaceRobot();   //this.jcomboPlaceRobot
        this.jcomboPlaceRobot.setEditable(false);
        this.jcomboPlaceRobot.setActionCommand(AC_PLACE_ROBOT);
        this.jcomboPlaceRobot.addActionListener(this);
        this.jcomboPlaceRobot.setToolTipText("first select a robot here and then click on its new board position");
        this.setJComboCenterAlignment(this.jcomboPlaceRobot);
       
        this.jbutPlaceGoal.setActionCommand(AC_PLACE_GOAL);
        this.jbutPlaceGoal.addActionListener(this);
        this.jbutPlaceGoal.setToolTipText("first click here and then select a goal on the board");
       
        this.jcomboGameIDs.setModel(new DefaultComboBoxModel());
        this.jcomboGameIDs.setEditable(true);
        this.jcomboGameIDs.setActionCommand(AC_GAME_ID);
        this.jcomboGameIDs.addActionListener(this);
       
        this.jcomboSelectSolution.setModel(new DefaultComboBoxModel());
        this.jcomboSelectSolution.setPrototypeDisplayValue("99)  99/9/#####")//longest string possible here
        this.jcomboSelectSolution.addItem("Select solution");
        this.jcomboSelectSolution.setEditable(false);
        this.jcomboSelectSolution.setActionCommand(AC_SELECT_SOLUTION);
        this.jcomboSelectSolution.addActionListener(this);
        this.jcomboSelectSolution.setToolTipText("SPOILER WARNING. clicking this reveals hints about the solutions");
        this.setJComboCenterAlignment(this.jcomboSelectSolution);
       
        this.addKeyBindingTooltip(this.jbutSolutionHint, KeyEvent.VK_H,
                "click 3 times to get more detailed hints",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showHint();
                    }
                }
        );
       
        this.addKeyBindingTooltip(this.jbutNextMove, KeyEvent.VK_N,
                "show next move",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showNextMove(true);
                    }
                }
        );
       
        this.addKeyBindingTooltip(this.jbutAllMoves, KeyEvent.VK_M,
                "show all moves",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutNextMove.isEnabled()) {
                            showNextMove(true);
                        }
                    }
                }
        );
       
        this.addKeyBindingTooltip(this.jbutPrevMove, KeyEvent.VK_B,
                "undo last move",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        showPrevMove(true);
                    }
                }
        );
       
        this.addKeyBindingTooltip(this.jbutNoMoves, KeyEvent.VK_V,
                "undo all moves",
                new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        while (jbutPrevMove.isEnabled()) {
                            showPrevMove(true);
                        }
                    }
                }
        );
       
        this.jtextSolution.setEditable(false);
        final JPanel panelSolutionText = new JPanel(new BorderLayout());
        panelSolutionText.add(this.jtextSolution, BorderLayout.CENTER);
        final JScrollPane scrollSolutionText = new JScrollPane(this.jtextSolution, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollSolutionText.setPreferredSize(new Dimension(10, 10)); //workaround for layout problem ?!?!
        scrollSolutionText.setMinimumSize(new Dimension(10, 10));   //workaround for layout problem ?!?!
       
        final RowGroup playSolutionGroup = new RowGroup();
        final JCheckBox groupBox = new JCheckBox("show computed solutions");
        groupBox.addItemListener(new ShowHideAction(playSolutionGroup));
       
        final JPanel playPanel = new JPanel();
        final DesignGridLayout playLayout = new DesignGridLayout(playPanel);
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(new JLabel("set starting position"));
        playLayout.row().grid().add(jbutRandomRobots).add(jbutRandomGoal);
        playLayout.row().grid().add(this.jcomboPlaceRobot).add(this.jbutPlaceGoal);
        playLayout.row().grid().add(new JLabel("game ID")).add(this.jcomboGameIDs, 3);
        playLayout.row().grid().add(new JLabel(" "));
        playLayout.row().grid().add(new JSeparator());
        playLayout.row().grid().add(groupBox);
        playLayout.row().group(playSolutionGroup).grid().add(this.jcomboSelectSolution).add(this.jbutSolutionHint);
        playLayout.row().group(playSolutionGroup).grid().add(this.jbutNoMoves).add(this.jbutPrevMove).add(this.jbutNextMove).add(this.jbutAllMoves);
        playLayout.row().group(playSolutionGroup).grid().add(scrollSolutionText);
        groupBox.setSelected(true); //false
        //playSolutionGroup.hide();
       
        this.jtabPreparePlay.addTab("Prepare board / Options", preparePanel);
        this.jtabPreparePlay.addTab("Play game", playPanel);
View Full Code Here

TOP

Related Classes of net.java.dev.designgridlayout.DesignGridLayout

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.