public void actionPerformed(ActionEvent e) { ActionButton button = (ActionButton) e.getSource(); GameAction action = (GameAction) button.getPossibleActions().get(0); if (action instanceof GameAction && (action.getMode() == GameAction.FORCED_UNDO)) { if (!timeWarpMode) { activateTimeWarp(); } } gameUIManager.processAction(action); }
@Override public void updateLog() { // set the content of the pane to the current editorPane.setText(ReportBuffer.getReportItems()); scrollDown(); forwardButton.setEnabled(false); backwardButton.setEnabled(false); boolean haveRedo = false; List<GameAction> gameActions = PossibleActions.getInstance().getType(GameAction.class); boolean undoFlag = false; for (GameAction action : gameActions) { switch (action.getMode()) { case GameAction.UNDO: undoFlag = true; backwardButton.setPossibleAction(action); backwardButton.setEnabled(true); break; case GameAction.FORCED_UNDO: if (undoFlag) break; // only activate forced undo, if no other undo available backwardButton.setPossibleAction(action); backwardButton.setEnabled(true); break; case GameAction.REDO: forwardButton.setPossibleAction(action); forwardButton.setEnabled(true); haveRedo = true; break; } } if (!haveRedo) deactivateTimeWarp(); }
@Override public void init() { super.init(); setLayout(new BorderLayout()); JPanel messagePanel = new JPanel(); messagePanel.setLayout(new BorderLayout()); message = new JLabel(); message.setText(LocalText.getText("REPORT_TIMEWARP_ACTIVE")); message.setHorizontalAlignment(JLabel.CENTER); messagePanel.add(message, "North"); JPanel timeWarpButtons = new JPanel(); returnButton = new JButton(LocalText.getText("REPORT_LEAVE_TIMEWARP")); returnButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { gotoLastIndex(); } }); timeWarpButtons.add(returnButton); playFromHereButton = new JButton(LocalText.getText("REPORT_PLAY_FROM_HERE")); playFromHereButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { deactivateTimeWarp(); } }); timeWarpButtons.add(playFromHereButton); messagePanel.add(timeWarpButtons, "South"); add(messagePanel, "North"); editorPane = new JEditorPane(); editorPane.setEditable(false); editorPane.setContentType("text/html"); editorPane.addHyperlinkListener(this); editorPane.setOpaque(false); editorPane.setBorder(null); // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); reportPane = new JScrollPane(editorPane); add(reportPane, "Center"); buttonPanel = new JPanel(); add(buttonPanel, "South"); backwardButton = new ActionButton(LocalText.getText("REPORT_MOVE_BACKWARD")); backwardButton.addActionListener(this); buttonPanel.add(backwardButton); forwardButton = new ActionButton(LocalText.getText("REPORT_MOVE_FORWARD")); forwardButton.addActionListener(this); buttonPanel.add(forwardButton); commentButton = new JButton(LocalText.getText("REPORT_COMMENT")); commentButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { String newComment = (String) JOptionPane.showInputDialog( ReportWindowDynamic.this, LocalText.getText("REPORT_COMMENT_ASK"), LocalText.getText("REPORT_COMMENT_TITLE"), JOptionPane.PLAIN_MESSAGE, null, null, ReportBuffer.getComment()); if (newComment != null) { ReportBuffer.addComment(newComment); updateLog(); scrollDown(); } } }); buttonPanel.add(commentButton); }