Changeset f37caa2


Ignore:
Timestamp:
Jun 13, 2010, 1:45:07 PM (10 years ago)
Author:
Michael Seifert <mseifert@…>
Branches:
master
Children:
63329fa
Parents:
0438dfb
Message:

Changed default LookAndFeel? to Nimbus, if available;

Added states to the GUI;

Progress of parsing is no longer shown in a window. Added a status bar instead;

MoveScreen? actions no longer count towards a player's actions;

Added license headers;

Added javadoc comments;

Addes unit tests

Location:
src
Files:
2 added
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/erichseifert/warp/ProgressListener.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp;
    223
     24/**
     25 * Interface used for listening for progress changes of a computing process.
     26 */
    327public interface ProgressListener {
    428
     29        /**
     30         * This method is invoked, if a number of elements has been processed.
     31         * @param elementsProcessed Total number of processed elements.
     32         * @param elementsTotal Total number of elements.
     33         */
    534        void progressUpdated(int elementsProcessed, int elementsTotal);
    635}
  • src/main/java/de/erichseifert/warp/ReplayDataChangeListener.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp;
    223
  • src/main/java/de/erichseifert/warp/ReplayDescriptor.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp;
    223
  • src/main/java/de/erichseifert/warp/WARP.java

    r0438dfb rf37caa2  
    2929import javax.swing.UIManager;
    3030import javax.swing.UnsupportedLookAndFeelException;
     31import javax.swing.UIManager.LookAndFeelInfo;
    3132
    3233import de.erichseifert.warp.gui.ReplayParserGUI;
     
    6667                                if (storage.contains(replayFile)) {
    6768                                        elementsProcessed++;
     69                                        listener.progressUpdated(elementsProcessed, replayFiles.size());
    6870                                        continue;
    6971                                }
     
    105107                try {
    106108                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     109                        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
     110                        if ("Nimbus".equals(info.getName())) {
     111                            UIManager.setLookAndFeel(info.getClassName());
     112                            break;
     113                        }
     114                    }
    107115                } catch (ClassNotFoundException e) {
    108116                        // TODO Auto-generated catch block
  • src/main/java/de/erichseifert/warp/gui/ReplayParserGUI.java

    r0438dfb rf37caa2  
    2525import java.awt.Component;
    2626import java.awt.Dimension;
     27import java.awt.GridLayout;
    2728import java.awt.Toolkit;
    2829import java.awt.event.ActionEvent;
     
    4243import javax.swing.JMenuBar;
    4344import javax.swing.JMenuItem;
     45import javax.swing.JOptionPane;
    4446import javax.swing.JPanel;
     47import javax.swing.JProgressBar;
    4548import javax.swing.JScrollPane;
    4649import javax.swing.JSplitPane;
     
    4952import javax.swing.JToolBar;
    5053import javax.swing.ListSelectionModel;
     54import javax.swing.SwingConstants;
     55import javax.swing.border.EmptyBorder;
    5156import javax.swing.event.ListSelectionEvent;
    5257import javax.swing.event.ListSelectionListener;
     
    5762import javax.swing.table.TableRowSorter;
    5863
     64import de.erichseifert.warp.ProgressListener;
    5965import de.erichseifert.warp.Replay;
    6066import de.erichseifert.warp.ReplayDataChangeListener;
     
    7076 * to display important information. Both components are organized in a <code>JSplitPane</code>.
    7177 */
    72 public class ReplayParserGUI extends JFrame implements ReplayDataChangeListener {
     78public class ReplayParserGUI extends JFrame implements ReplayDataChangeListener, ProgressListener {
     79        private static enum State {
     80                PARSING(true, "Parsing replays..."),
     81                READY(false, "Ready");
     82
     83                private final boolean progressBarNeeded;
     84                private final String statusMessage;
     85
     86                private State(boolean progressBarNeeded, String statusMessage) {
     87                        this.progressBarNeeded = progressBarNeeded;
     88                        this.statusMessage = statusMessage;
     89                }
     90
     91                public boolean isProgressBarNeeded() {
     92                        return progressBarNeeded;
     93                }
     94
     95                public String getStatusMessage() {
     96                        return statusMessage;
     97                }
     98        }
     99
    73100        private final WARP warp;
    74101
     
    80107        private final TableRowSorter<TableModel> replayTableSorter;
    81108        private final ReplayRowFilter<TableModel> replayTableFilter;
     109        private final JProgressBar parsingProgress;
     110        private final JLabel statusMessage;
    82111
    83112        /**
     
    104133                                int option = fileChooser.showOpenDialog(ReplayParserGUI.this);
    105134                                if (option == JFileChooser.APPROVE_OPTION) {
    106                                         ParseReplayWindow parsingProgress = new ParseReplayWindow(ReplayParserGUI.this);
    107                                         parsingProgress.setVisible(true);
    108 
    109                                         ReplayParserGUI.this.warp.parseDir(fileChooser.getSelectedFile(), parsingProgress);
     135                                        setState(State.PARSING);
     136                                        ReplayParserGUI.this.warp.parseDir(fileChooser.getSelectedFile(), ReplayParserGUI.this);
    110137                                }
    111138                        }
     
    238265                JScrollPane replayTableScroller = new JScrollPane(replayTable);
    239266                splitPane.add(replayTableScroller, JSplitPane.RIGHT);
     267
     268                JPanel statusPanel = new JPanel(new GridLayout(2, 1));
     269                getContentPane().add(statusPanel, BorderLayout.SOUTH);
     270                parsingProgress = new JProgressBar();
     271                parsingProgress.setIndeterminate(false);
     272                parsingProgress.setStringPainted(true);
     273                statusPanel.add(parsingProgress);
     274
     275                statusMessage = new JLabel("Parsing replays...");
     276                statusMessage.setHorizontalTextPosition(SwingConstants.LEADING);
     277                statusMessage.setBorder(new EmptyBorder(5, 5, 5, 5));
     278                statusPanel.add(statusMessage);
     279
     280                setState(State.READY);
    240281        }
    241282
     
    261302        }
    262303
     304        @Override
     305        public void progressUpdated(int elementsProcessed, int elementsTotal) {
     306                parsingProgress.setValue(elementsProcessed);
     307                parsingProgress.setMaximum(elementsTotal);
     308                if (elementsProcessed == elementsTotal) {
     309                        setState(State.READY);
     310                        JOptionPane.showMessageDialog(this, "All replays have been parsed.", "Parsing complete", JOptionPane.INFORMATION_MESSAGE);
     311                }
     312        }
     313
    263314        private static Object[] descriptorToRow(ReplayDescriptor descriptor) {
    264315                return new Object[] {
     
    268319                };
    269320        }
     321
     322        private void setState(State state) {
     323                if (state.isProgressBarNeeded()) {
     324                        parsingProgress.setEnabled(true);
     325                }
     326                else {
     327                        parsingProgress.setEnabled(false);
     328                }
     329
     330                statusMessage.setText(state.getStatusMessage());
     331        }
    270332}
  • src/main/java/de/erichseifert/warp/io/BufferedStorage.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp.io;
    223
  • src/main/java/de/erichseifert/warp/io/MemoryStorage.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp.io;
    223
  • src/main/java/de/erichseifert/warp/io/ReplayStorage.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp.io;
    223
  • src/main/java/de/erichseifert/warp/io/SerializingStorage.java

    r0438dfb rf37caa2  
     1/**
     2 * WARP: WARP is a Replay Manager for Java(R)
     3 *
     4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net>
     5 *
     6 * This file is part of WARP.
     7 *
     8 * WARP is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * WARP is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with WARP.  If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
    122package de.erichseifert.warp.io;
    223
  • src/main/java/de/erichseifert/warp/replays/sc2replay/actions/SC2ActionFilter.java

    r0438dfb rf37caa2  
    3939                }
    4040                else if (action instanceof MoveScreen) {
    41                         return 1;
     41                        return 0;
    4242                }
    4343                else if (action instanceof Order) {
  • src/main/java/de/erichseifert/warp/util/FileUtil.java

    r0438dfb rf37caa2  
    3838import java.util.Map;
    3939
    40 public class FileUtil {
     40/**
     41 * Class that provides utility methods for files.
     42 */
     43public abstract class FileUtil {
    4144
     45        private FileUtil() {
     46        }
     47
     48        /**
     49         * Parses properties that contain multiple values per key from the
     50         * specified input stream.
     51         * @param stream InputStream.
     52         * @return Properties.
     53         * @throws IOException
     54         */
    4255        public static final Map<String, List<String>> parseFile(InputStream stream) throws IOException {
    4356                InputStreamReader ifs = new InputStreamReader(stream);
     
    6073        }
    6174
     75        /**
     76         * Returns the relative path from the specified child to the specified
     77         * parent file.
     78         * @param parent Parent file.
     79         * @param child Child file.
     80         * @return Relative path.
     81         */
    6282        public static String getPathRelativeTo(File parent, File child) {
    6383                String path = child.getName();
  • src/main/java/de/erichseifert/warp/util/ReplayUtil.java

    r0438dfb rf37caa2  
    118118        }
    119119
     120        /**
     121         * Shifts the specified byte array by the specified number of bits to
     122         * the left.
     123         * This method does not alter the original array.
     124         * @param bytes Byte array to be shifted.
     125         * @param bits Shift amount.
     126         * @return Shifted array.
     127         */
    120128        public static byte[] shiftLeft(byte[] bytes, int bits) {
    121129                // TODO Add support for shifts of more than 8 bits.
  • src/test/java/de/erichseifert/warp/util/UtilTests.java

    r0438dfb rf37caa2  
    2727@RunWith(Suite.class)
    2828@Suite.SuiteClasses({
     29        FileUtilTest.class,
     30        GUIUtilTest.class,
    2931        ReplayUtilTest.class
    3032})
Note: See TracChangeset for help on using the changeset viewer.