| @@ -1,34 +1,37 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.actions; | ||
|
|
||
| import slash.navigation.gui.Application; | ||
| import slash.navigation.gui.SingleFrameApplication; | ||
|
|
||
| /** | ||
| * Exit the {@link SingleFrameApplication}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class ExitAction extends FrameAction { | ||
| public void run() { | ||
| Application.getInstance().exit(getEvent()); | ||
| } | ||
| } | ||
|
|
| @@ -1,61 +1,64 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.actions; | ||
|
|
||
| import slash.navigation.gui.Application; | ||
| import slash.navigation.gui.SingleFrameApplication; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.event.ActionEvent; | ||
| import java.awt.event.ActionListener; | ||
|
|
||
| import static slash.navigation.gui.helpers.UIHelper.startWaitCursor; | ||
| import static slash.navigation.gui.helpers.UIHelper.stopWaitCursor; | ||
|
|
||
| /** | ||
| * An {@link Action} and {@link ActionListener} that starts and stops the wait cursor on the application frame. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public abstract class FrameAction extends AbstractAction implements ActionListener { | ||
| private static ThreadLocal<ActionEvent> ACTION_EVENT = new ThreadLocal<ActionEvent>(); | ||
|
|
||
| protected JFrame getFrame() { | ||
| Application application = Application.getInstance(); | ||
| if (application instanceof SingleFrameApplication) | ||
| return ((SingleFrameApplication) application).getFrame(); | ||
| throw new UnsupportedOperationException("FrameAction only works on SingleFrameApplication"); | ||
| } | ||
|
|
||
| protected ActionEvent getEvent() { | ||
| return ACTION_EVENT.get(); | ||
| } | ||
|
|
||
| public final void actionPerformed(ActionEvent e) { | ||
| ACTION_EVENT.set(e); | ||
| startWaitCursor(getFrame().getRootPane()); | ||
| try { | ||
| run(); | ||
| } finally { | ||
| stopWaitCursor(getFrame().getRootPane()); | ||
| } | ||
| } | ||
|
|
||
| public abstract void run(); | ||
| } |
| @@ -1,50 +1,52 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.actions; | ||
|
|
||
| import slash.navigation.gui.Application; | ||
|
|
||
| import javax.help.CSH; | ||
| import javax.help.HelpBroker; | ||
| import javax.help.HelpSet; | ||
| import javax.swing.*; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import static javax.swing.JOptionPane.ERROR_MESSAGE; | ||
|
|
||
| /** | ||
| * Open the {@link HelpSet help}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class HelpTopicsAction extends FrameAction { | ||
| private static final Logger log = Logger.getLogger(HelpTopicsAction.class.getName()); | ||
|
|
||
| public void run() { | ||
| try { | ||
| HelpBroker broker = Application.getInstance().getContext().getHelpBroker(); | ||
| new CSH.DisplayHelpFromFocus(broker).actionPerformed(getEvent()); | ||
| } catch (Exception e) { | ||
| String message = "Could not initialize help: " + e.getLocalizedMessage(); | ||
| log.severe(message); | ||
| JOptionPane.showMessageDialog(null, message, "Error", ERROR_MESSAGE); | ||
| } | ||
| } | ||
| } |
| @@ -1,75 +1,75 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.events; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static slash.navigation.gui.events.Range.asContinuousMonotonicallyIncreasingRanges; | ||
|
|
||
| /** | ||
| * Allows to perform customizable {@link RangeOperation}s on indexed elements | ||
| * with another customizable operation after a continuous range. | ||
| * Use to reduce the number of notifications that Swing UI Models fire. | ||
| * | ||
| * @author Christian Pesch | ||
| * @see RangeOperation | ||
| */ | ||
|
|
||
| public class ContinousRange { | ||
| private final int[] indices; | ||
| private final RangeOperation operation; | ||
|
|
||
| public ContinousRange(int[] indices, RangeOperation operation) { | ||
| this.indices = indices; | ||
| this.operation = operation; | ||
| } | ||
|
|
||
| public void performMonotonicallyIncreasing() { | ||
| perform(asContinuousMonotonicallyIncreasingRanges(indices)); | ||
| } | ||
|
|
||
| public void performMonotonicallyIncreasing(int maximumRangeLength) { | ||
| perform(asContinuousMonotonicallyIncreasingRanges(indices, maximumRangeLength)); | ||
| } | ||
|
|
||
| public void performMonotonicallyDecreasing() { | ||
| perform(Range.asContinuousMonotonicallyDecreasingRanges(indices)); | ||
| } | ||
|
|
||
| private void perform(List<List<Integer>> ranges) { | ||
| for (List<Integer> range : ranges) { | ||
| for (Integer index : range) { | ||
| operation.performOnIndex(index); | ||
| if (operation.isInterrupted()) | ||
| return; | ||
| } | ||
| if(range.size() == 0) | ||
| continue; | ||
| int firstValue = range.get(0); | ||
| int lastValue = range.get(range.size() - 1); | ||
| int from = Math.min(firstValue, lastValue); | ||
| int to = Math.max(firstValue, lastValue); | ||
| operation.performOnRange(from, to); | ||
| if (operation.isInterrupted()) | ||
| return; | ||
| } | ||
| } | ||
| } |
| @@ -1,113 +1,107 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.events; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static slash.common.io.Transfer.toArray; | ||
|
|
||
| /** | ||
| * Provides Python range() like functionality. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class Range { | ||
|
|
||
| public static List<List<Integer>> asContinuousMonotonicallyIncreasingRanges(int[] indices) { | ||
| return asContinuousMonotonicallyIncreasingRanges(indices, Integer.MAX_VALUE); | ||
| } | ||
|
|
||
| public static List<List<Integer>> asContinuousMonotonicallyIncreasingRanges(int[] indices, int maximumRangeLength) { | ||
| Arrays.sort(indices); | ||
| List<List<Integer>> result = new ArrayList<List<Integer>>(); | ||
| List<Integer> range = new ArrayList<Integer>(); | ||
| for (int index : indices) { | ||
| if ((range.size() == 0 || index == range.get(range.size() - 1) + 1) && range.size() < maximumRangeLength) { | ||
| range.add(index); | ||
| } else { | ||
| result.add(range); | ||
| range = new ArrayList<Integer>(); | ||
| range.add(index); | ||
| } | ||
| } | ||
| result.add(range); | ||
| return result; | ||
| } | ||
|
|
||
| public static List<List<Integer>> asContinuousMonotonicallyDecreasingRanges(int[] indices) { | ||
| indices = revert(indices); | ||
| List<List<Integer>> result = new ArrayList<List<Integer>>(); | ||
| List<Integer> range = new ArrayList<Integer>(); | ||
| for (int index : indices) { | ||
| if (range.size() == 0 || index == range.get(range.size() - 1) - 1) { | ||
| range.add(index); | ||
| } else { | ||
| result.add(range); | ||
| range = new ArrayList<Integer>(); | ||
| range.add(index); | ||
| } | ||
| } | ||
| result.add(range); | ||
| return result; | ||
| } | ||
|
|
||
| public static int[] revert(int[] indices) { | ||
| Arrays.sort(indices); | ||
| int[] reverted = new int[indices.length]; | ||
| for (int i = 0; i < indices.length; i++) { | ||
| reverted[i] = indices[indices.length - i - 1]; | ||
| } | ||
| return reverted; | ||
| } | ||
|
|
||
| public static int[] increment(int[] indices, int delta) { | ||
| int[] incremented = new int[indices.length]; | ||
| for (int i = 0; i < indices.length; i++) { | ||
| incremented[i] = indices[i] + delta; | ||
| } | ||
| return incremented; | ||
| } | ||
|
|
||
| public static int[] allButEveryNthAndFirstAndLast(int maximum, int nth) { | ||
| if (nth < 1) | ||
| throw new IllegalArgumentException("nth has to be more than zero"); | ||
|
|
||
| List<Integer> result = new ArrayList<Integer>(); | ||
| for (int i = 1; i < maximum; i += nth) { | ||
| int intervalMaximum = i + nth - 1; | ||
| if (intervalMaximum > maximum) | ||
| intervalMaximum = maximum; | ||
| for (int j = i; j < intervalMaximum; j++) { | ||
| result.add(j); | ||
| } | ||
| } | ||
| return toArray(result); | ||
| } | ||
| } |
| @@ -1,35 +1,35 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.events; | ||
|
|
||
| /** | ||
| * Operation to perform on indexed elements. | ||
| * | ||
| * @author Christian Pesch | ||
| * | ||
| * @see ContinousRange | ||
| */ | ||
|
|
||
| public interface RangeOperation { | ||
| void performOnIndex(int index); | ||
| void performOnRange(int firstIndex, int lastIndex); | ||
| boolean isInterrupted(); | ||
| } |
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.helpers; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.*; | ||
| import java.net.URL; | ||
| import java.util.Locale; | ||
| import java.util.logging.Logger; | ||
| import java.util.prefs.Preferences; | ||
|
|
||
| /** | ||
| * Helpers used throughout the UI | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class UIHelper { | ||
| private static final Preferences preferences = Preferences.userNodeForPackage(UIHelper.class); | ||
| private static final Logger log = Logger.getLogger(UIHelper.class.getName()); | ||
| private static final String LOOK_AND_FEEL_CLASS_PREFERENCE = "lookAndFeelClass"; | ||
|
|
||
| // for language support which is not defined by a constant in Locale | ||
| public static final Locale ARABIA = new Locale("ar", "SA"); | ||
| public static final Locale CZECH = new Locale("cs", "CZ"); | ||
| public static final Locale CROATIA = new Locale("hr", "HR"); | ||
| public static final Locale NEDERLANDS = new Locale("nl", "NL"); | ||
| public static final Locale SERBIA = new Locale("sr", "SR"); | ||
| public static final Locale SLOVAKIA = new Locale("sk", "SK"); | ||
| public static final Locale SPAIN = new Locale("es", "ES"); | ||
|
|
||
| public static void setLookAndFeel() { | ||
| try { | ||
| String lookAndFeelClass = preferences.get(LOOK_AND_FEEL_CLASS_PREFERENCE, "default"); | ||
| if("default".equals(lookAndFeelClass)) | ||
| lookAndFeelClass = UIManager.getSystemLookAndFeelClassName(); | ||
| UIManager.setLookAndFeel(lookAndFeelClass); | ||
| } catch (Exception e) { | ||
| // intentionally do nothing | ||
| } | ||
| JFrame.setDefaultLookAndFeelDecorated(true); | ||
| JDialog.setDefaultLookAndFeelDecorated(true); | ||
| } | ||
|
|
||
| public static void startWaitCursor(JComponent component) { | ||
| RootPaneContainer root = (RootPaneContainer) component.getTopLevelAncestor(); | ||
| startWaitCursor(root.getGlassPane()); | ||
| root.getGlassPane().setVisible(true); | ||
| } | ||
|
|
||
| private static void startWaitCursor(Component component) { | ||
| component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); | ||
| } | ||
|
|
||
| public static void stopWaitCursor(JComponent component) { | ||
| RootPaneContainer root = (RootPaneContainer) component.getTopLevelAncestor(); | ||
| stopWaitCursor(root.getGlassPane()); | ||
| root.getGlassPane().setVisible(false); | ||
| } | ||
|
|
||
| private static void stopWaitCursor(Component component) { | ||
| component.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); | ||
| } | ||
|
|
||
| public static ImageIcon loadIcon(String name) { | ||
| URL iconURL = UIHelper.class.getClassLoader().getResource(name); | ||
| return new ImageIcon(iconURL); | ||
| } | ||
|
|
||
| public static JFileChooser createJFileChooser() { | ||
| JFileChooser chooser; | ||
| try { | ||
| try { | ||
| chooser = new JFileChooser(); | ||
| } | ||
| catch (NullPointerException npe) { | ||
| log.info("Working around http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6210674 by using Metal UI"); | ||
| UIManager.getDefaults().put("FileChooserUI", "javax.swing.plaf.metal.MetalFileChooserUI"); | ||
| chooser = new JFileChooser(); | ||
| } | ||
| } | ||
| catch (Exception e) { | ||
| log.info("Working around http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6544857 by using restricted file system view"); | ||
| chooser = new JFileChooser(new RestrictedFileSystemView()); | ||
| } | ||
| return chooser; | ||
| } | ||
| } |
| @@ -1,36 +1,39 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.undo; | ||
|
|
||
| import slash.navigation.gui.Application; | ||
| import slash.navigation.gui.actions.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| /** | ||
| * {@link Action} that redos the last undone operation. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class RedoAction extends FrameAction { | ||
| public void run() { | ||
| UndoManager undoManager = Application.getInstance().getContext().getUndoManager(); | ||
| undoManager.redo(); | ||
| } | ||
| } |
| @@ -1,36 +1,39 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.undo; | ||
|
|
||
| import slash.navigation.gui.Application; | ||
| import slash.navigation.gui.actions.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| /** | ||
| * {@link Action} that undos the last operation. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class UndoAction extends FrameAction { | ||
| public void run() { | ||
| UndoManager undoManager = Application.getInstance().getContext().getUndoManager(); | ||
| undoManager.undo(); | ||
| } | ||
| } |
| @@ -1,91 +1,93 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.undo; | ||
|
|
||
| import slash.navigation.gui.Application; | ||
|
|
||
| import javax.swing.event.ChangeListener; | ||
| import javax.swing.event.EventListenerList; | ||
| import javax.swing.undo.UndoableEdit; | ||
| import java.util.prefs.Preferences; | ||
|
|
||
| /** | ||
| * Manages the {@link UndoAction} and {@link RedoAction} of an {@link Application}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class UndoManager { | ||
| private static final Preferences preferences = Preferences.userNodeForPackage(UndoManager.class); | ||
| private javax.swing.undo.UndoManager delegate = new javax.swing.undo.UndoManager(); | ||
| private EventListenerList listenerList = new EventListenerList(); | ||
|
|
||
| public UndoManager() { | ||
| delegate.setLimit(preferences.getInt("undoLimit", -1)); | ||
| } | ||
|
|
||
| public boolean canUndo() { | ||
| return delegate.canUndo(); | ||
| } | ||
|
|
||
| public boolean canRedo() { | ||
| return delegate.canRedo(); | ||
| } | ||
|
|
||
| public String getUndoPresentationName() { | ||
| return delegate.getUndoPresentationName(); | ||
| } | ||
|
|
||
| public String getRedoPresentationName() { | ||
| return delegate.getRedoPresentationName(); | ||
| } | ||
|
|
||
| public void undo() { | ||
| delegate.undo(); | ||
| fireChanged(); | ||
| } | ||
|
|
||
| public void redo() { | ||
| delegate.redo(); | ||
| fireChanged(); | ||
| } | ||
|
|
||
| public void addEdit(UndoableEdit undoableEdit) { | ||
| delegate.addEdit(undoableEdit); | ||
| fireChanged(); | ||
| } | ||
|
|
||
| public void discardAllEdits() { | ||
| delegate.discardAllEdits(); | ||
| fireChanged(); | ||
| } | ||
|
|
||
| protected void fireChanged() { | ||
| Object[] listeners = listenerList.getListenerList(); | ||
| for (int i = listeners.length - 2; i >= 0; i -= 2) { | ||
| if (listeners[i] == ChangeListener.class) { | ||
| ((ChangeListener) listeners[i + 1]).stateChanged(null); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void addChangeListener(ChangeListener l) { | ||
| listenerList.add(ChangeListener.class, l); | ||
| } | ||
| } |
| @@ -1,76 +1,75 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.navigation.gui.events; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static slash.common.TestCase.assertIntArrayEquals; | ||
|
|
||
| public class RangeTest { | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test | ||
| public void testAsContinuousMonotonicallyIncreasingRanges() { | ||
| assertEquals(asList(asList(0, 1)), Range.asContinuousMonotonicallyIncreasingRanges(new int[]{0, 1})); | ||
| assertEquals(asList(asList(0), asList(2)), Range.asContinuousMonotonicallyIncreasingRanges(new int[]{0, 2})); | ||
| assertEquals(asList(asList(0), asList(2, 3), asList(5, 6, 7)), Range.asContinuousMonotonicallyIncreasingRanges(new int[]{6, 0, 5, 2, 7, 3})); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test | ||
| public void testAsContinuousMonotonicallyIncreasingRangesWithLimit() { | ||
| assertEquals(asList(asList(0), asList(1), asList(2)), Range.asContinuousMonotonicallyIncreasingRanges(new int[]{0, 1, 2}, 1)); | ||
| assertEquals(asList(asList(0, 1), asList(2, 3), asList(4)), Range.asContinuousMonotonicallyIncreasingRanges(new int[]{0, 1, 2, 3, 4}, 2)); | ||
| assertEquals(asList(asList(0, 1), asList(3), asList(5, 6)), Range.asContinuousMonotonicallyIncreasingRanges(new int[]{0, 1, 3, 5, 6}, 2)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test | ||
| public void testAsContinuousMonotonicallyDecreasingRanges() { | ||
| assertEquals(asList(asList(1, 0)), Range.asContinuousMonotonicallyDecreasingRanges(new int[]{0, 1})); | ||
| assertEquals(asList(asList(2), asList(0)), Range.asContinuousMonotonicallyDecreasingRanges(new int[]{0, 2})); | ||
| assertEquals(asList(asList(7, 6, 5), asList(3, 2), asList(0)), Range.asContinuousMonotonicallyDecreasingRanges(new int[]{3, 6, 0, 7, 5, 2})); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllButEveryNthAndFirstAndLast() { | ||
| assertIntArrayEquals(new int[]{}, Range.allButEveryNthAndFirstAndLast(0, 1)); | ||
| assertIntArrayEquals(new int[]{}, Range.allButEveryNthAndFirstAndLast(0, 100)); | ||
| assertIntArrayEquals(new int[]{}, Range.allButEveryNthAndFirstAndLast(1, 1)); | ||
| assertIntArrayEquals(new int[]{}, Range.allButEveryNthAndFirstAndLast(1, 100)); | ||
| assertIntArrayEquals(new int[]{}, Range.allButEveryNthAndFirstAndLast(2, 1)); | ||
| assertIntArrayEquals(new int[]{1}, Range.allButEveryNthAndFirstAndLast(2, 2)); | ||
| assertIntArrayEquals(new int[]{1}, Range.allButEveryNthAndFirstAndLast(2, 3)); | ||
| assertIntArrayEquals(new int[]{1}, Range.allButEveryNthAndFirstAndLast(2, 100)); | ||
| assertIntArrayEquals(new int[]{1}, Range.allButEveryNthAndFirstAndLast(3, 2)); | ||
| assertIntArrayEquals(new int[]{1, 2}, Range.allButEveryNthAndFirstAndLast(3, 3)); | ||
| assertIntArrayEquals(new int[]{1, 2}, Range.allButEveryNthAndFirstAndLast(3, 4)); | ||
| assertIntArrayEquals(new int[]{1, 2}, Range.allButEveryNthAndFirstAndLast(3, 100)); | ||
| assertIntArrayEquals(new int[]{1, 3, 5}, Range.allButEveryNthAndFirstAndLast(6, 2)); | ||
| assertIntArrayEquals(new int[]{1, 2, 4, 5}, Range.allButEveryNthAndFirstAndLast(6, 3)); | ||
| assertIntArrayEquals(new int[]{1, 3, 5, 7, 9}, Range.allButEveryNthAndFirstAndLast(10, 2)); | ||
| assertIntArrayEquals(new int[]{1, 2, 4, 5, 7, 8}, Range.allButEveryNthAndFirstAndLast(10, 3)); | ||
| assertIntArrayEquals(new int[]{1, 2, 3, 5, 6, 7, 9}, Range.allButEveryNthAndFirstAndLast(10, 4)); | ||
| } | ||
| } |
| @@ -20,6 +20,8 @@ | ||
|
|
||
| package slash.common.io; | ||
|
|
||
| import slash.common.system.Platform; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.io.FileWriter; | ||
| @@ -1,77 +1,77 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.common.system; | ||
|
|
||
| /** | ||
| * Provides platform detection functionality. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class Platform { | ||
| public static boolean isLinux() { | ||
| return getOperationSystem().contains("linux"); | ||
| } | ||
|
|
||
| public static boolean isMac() { | ||
| return getOperationSystem().contains("mac"); | ||
| } | ||
|
|
||
| public static boolean isWindows() { | ||
| return getOperationSystem().contains("windows"); | ||
| } | ||
|
|
||
| public static String getPlatform() { | ||
| return System.getProperty("os.name") + " " + | ||
| System.getProperty("os.version") + " " + | ||
| System.getProperty("os.arch"); | ||
| } | ||
|
|
||
| public static String getJava() { | ||
| return "Java " + System.getProperty("java.version") + " (" + System.getProperty("sun.arch.data.model") + "-bit)"; | ||
| } | ||
|
|
||
| public static boolean isCurrentAtLeastMinimumVersion(String currentVersion, String minimumVersion) { | ||
| return currentVersion.compareTo(minimumVersion) >= 0; | ||
| } | ||
|
|
||
| private static String canonical(String value) { | ||
| return value.toLowerCase().replaceAll("[\\\\/ ]", "_"); | ||
| } | ||
|
|
||
| public static String getOperationSystem() { | ||
| String osName = System.getProperty("os.name"); | ||
| if (osName.startsWith("Windows")) | ||
| return "windows"; | ||
| return canonical(osName); | ||
| } | ||
|
|
||
| public static String getArchitecture() { | ||
| String osArch = System.getProperty("os.arch"); | ||
| if (osArch.endsWith("86")) | ||
| return "x86"; | ||
| return canonical(osArch); | ||
| } | ||
|
|
||
| public static long getMaximumMemory() { | ||
| return Runtime.getRuntime().maxMemory() / (1024 * 1000 /* to get 2^n numbers */); | ||
| } | ||
| } |
| @@ -1,176 +1,178 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.common.system; | ||
|
|
||
| import slash.common.type.CompactCalendar; | ||
|
|
||
| import java.text.DateFormat; | ||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| import static slash.common.io.Transfer.trim; | ||
|
|
||
| /** | ||
| * Provides version parsing functionality. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class Version { | ||
| private static final String ROUTECONVERTER_VERSION_KEY = "routeconverter.version"; | ||
| private static final String JAVA_VERSION_KEY = "java.version"; | ||
|
|
||
| static Map<String, String> parseParameters(String parameters) { | ||
| StringTokenizer tokenizer = new StringTokenizer(parameters, ","); | ||
| Map<String, String> map = new HashMap<String, String>(); | ||
| while (tokenizer.hasMoreTokens()) { | ||
| String nv = tokenizer.nextToken(); | ||
| StringTokenizer nvTokenizer = new StringTokenizer(nv, "="); | ||
| if (!nvTokenizer.hasMoreTokens()) | ||
| continue; | ||
| String key = nvTokenizer.nextToken(); | ||
| if (!nvTokenizer.hasMoreTokens()) | ||
| continue; | ||
| String value = nvTokenizer.nextToken(); | ||
| map.put(key, value); | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| private static String getValue(String parameters, String key) { | ||
| Map<String, String> map = parseParameters(parameters); | ||
| return trim(map.get(key)); | ||
| } | ||
|
|
||
| public static String getLatestRouteConverterVersion(String parameters) { | ||
| return getValue(parameters, ROUTECONVERTER_VERSION_KEY); | ||
| } | ||
|
|
||
| public static String getLatestJavaVersion(String parameters) { | ||
| return getValue(parameters, JAVA_VERSION_KEY); | ||
| } | ||
|
|
||
| private static final SimpleDateFormat BUILD_DATE = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| private String version, date, name; | ||
|
|
||
| public Version(String version, String date, String name) { | ||
| this.version = version; | ||
| this.date = date; | ||
| this.name = name; | ||
| } | ||
|
|
||
| public Version(String version) { | ||
| this(version, null, null); | ||
| } | ||
|
|
||
| public String getMajor() { | ||
| int dot = version.indexOf('.'); | ||
| if (dot != -1) | ||
| return version.substring(0, dot); | ||
| return version; | ||
| } | ||
|
|
||
| public String getMinor() { | ||
| int dot = version.indexOf('.'); | ||
| if (dot != -1) | ||
| version = version.substring(dot + 1); | ||
| return version; | ||
| } | ||
|
|
||
| private String sameLength(String reference, String hasToHaveSameLength) { | ||
| while (hasToHaveSameLength.length() < reference.length()) | ||
| hasToHaveSameLength = "0" + hasToHaveSameLength; | ||
| return hasToHaveSameLength; | ||
| } | ||
|
|
||
| private String removeSnapshot(String string) { | ||
| int index = string.indexOf("-"); | ||
| if (index != -1) | ||
| string = string.substring(0, index); | ||
| int dot = string.indexOf("."); | ||
| if (dot != -1) | ||
| string = string.substring(0, dot); | ||
| return string; | ||
| } | ||
|
|
||
| public boolean isLaterVersionThan(Version other) { | ||
| String major = getMajor(); | ||
| String otherMajor = sameLength(major, other.getMajor()); | ||
| int result = otherMajor.compareTo(major); | ||
| if (result != 0) | ||
| return result <= 0; | ||
|
|
||
| String minor = removeSnapshot(getMinor()); | ||
| String otherMinor = sameLength(minor, removeSnapshot(other.getMinor())); | ||
| result = otherMinor.compareTo(minor); | ||
| return result <= 0; | ||
| } | ||
|
|
||
| public String getVersion() { | ||
| if (version != null) { | ||
| if (version.contains("-SNAPSHOT")) | ||
| return version; | ||
| int index = version.indexOf('-'); | ||
| if (index != -1) | ||
| return version.substring(0, index); | ||
| else | ||
| return version; | ||
| } | ||
| return "?"; | ||
| } | ||
|
|
||
| public String getDate() { | ||
| if (date != null) { | ||
| try { | ||
| DateFormat format = DateFormat.getDateInstance(DateFormat.LONG); | ||
| format.setTimeZone(CompactCalendar.UTC); | ||
| Date java = BUILD_DATE.parse(date); | ||
| return format.format(java); | ||
| } catch (ParseException e) { | ||
| // intentionally ignored | ||
| } | ||
| } | ||
| return "?"; | ||
| } | ||
|
|
||
| public String getOperationSystem() { | ||
| if (name != null) { | ||
| return name.substring(0, name.length() - 2); | ||
| } | ||
| return "?"; | ||
| } | ||
|
|
||
| public String getBits() { | ||
| if (name != null) { | ||
| return name.substring(name.length() - 2, name.length()); | ||
| } | ||
| return "?"; | ||
| } | ||
|
|
||
| public static Version parseVersionFromManifest() { | ||
| Package aPackage = Version.class.getPackage(); | ||
| return new Version(aPackage.getSpecificationVersion(), | ||
| aPackage.getImplementationVersion(), | ||
| aPackage.getImplementationVendor()); | ||
| } | ||
| } |
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Contains systems helpers. | ||
| * <p> | ||
| * This package facilitates helpers for determining platform and versions | ||
| */ | ||
| package slash.common.system; |
| @@ -1,132 +1,132 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.common.type; | ||
|
|
||
| import java.util.Calendar; | ||
| import java.util.Collections; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.TimeZone; | ||
|
|
||
| /** | ||
| * A compact representation of a calendar, that saves some memory. | ||
| * A {@link Calendar} needs about 250 bytes, this guy needs only 20. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class CompactCalendar { | ||
| public static final TimeZone UTC = TimeZone.getTimeZone("UTC"); | ||
|
|
||
| private final long timeInMillis; | ||
| private final String timeZoneId; | ||
|
|
||
| public static CompactCalendar fromMillisAndTimeZone(long timeInMillis, String timeZoneId) { | ||
| return new CompactCalendar(timeInMillis, timeZoneId); | ||
| } | ||
|
|
||
| public static CompactCalendar fromCalendar(Calendar calendar) { | ||
| return fromMillisAndTimeZone(calendar.getTimeInMillis(), calendar.getTimeZone().getID()); | ||
| } | ||
|
|
||
| public static CompactCalendar fromDate(Date date) { | ||
| Calendar calendar = Calendar.getInstance(UTC); | ||
| calendar.setTime(date); | ||
| return fromCalendar(calendar); | ||
| } | ||
|
|
||
|
|
||
| public static CompactCalendar fromMillis(long timeInMillis) { | ||
| Calendar calendar = Calendar.getInstance(UTC); | ||
| calendar.setTimeInMillis(timeInMillis); | ||
| return fromCalendar(calendar); | ||
| } | ||
|
|
||
| public static CompactCalendar getInstance(String timeZoneId) { | ||
| return fromCalendar(Calendar.getInstance(TimeZone.getTimeZone(timeZoneId))); | ||
| } | ||
|
|
||
| private CompactCalendar(long timeInMillis, String timeZoneId) { | ||
| this.timeInMillis = timeInMillis; | ||
| this.timeZoneId = timeZoneId.equals("UTC") ? "UTC" : timeZoneId.intern(); | ||
| } | ||
|
|
||
| public long getTimeInMillis() { | ||
| return timeInMillis; | ||
| } | ||
|
|
||
| public String getTimeZoneId() { | ||
| return timeZoneId; | ||
| } | ||
|
|
||
| public Calendar getCalendar() { | ||
| Calendar result = Calendar.getInstance(getTimeZone()); | ||
| result.setTimeInMillis(getTimeInMillis()); | ||
| return result; | ||
| } | ||
|
|
||
| public Date getTime() { | ||
| return getCalendar().getTime(); | ||
| } | ||
|
|
||
| private static volatile Map<String, TimeZone> timeZones = Collections.emptyMap(); | ||
|
|
||
| private TimeZone getTimeZone() { | ||
| if ("UTC".equals(getTimeZoneId())) | ||
| return UTC; | ||
| // try global read-only map. No synchronization necessary because the field is volatile. | ||
| // (this is only *guaranteed* to work with the Java 5 revised memory model, but works on older JVMs anyway) | ||
| TimeZone result = timeZones.get(getTimeZoneId()); | ||
| if (result != null) | ||
| return result; | ||
| synchronized (CompactCalendar.class) { | ||
| // the time zone might have been added while we waited for monitor entry | ||
| result = timeZones.get(getTimeZoneId()); | ||
| if (result != null) | ||
| return result; | ||
| // add new timezone to new version of global map. | ||
| // The following call is allegedly expensive (that's why we go through all this trouble) | ||
| result = TimeZone.getTimeZone(getTimeZoneId()); | ||
| Map<String, TimeZone> newTimeZones = new HashMap<String, TimeZone>(timeZones); | ||
| newTimeZones.put(getTimeZoneId(), result); | ||
| newTimeZones = Collections.unmodifiableMap(newTimeZones); // paranoia | ||
| timeZones = newTimeZones; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
|
|
||
| CompactCalendar that = (CompactCalendar) o; | ||
|
|
||
| return timeInMillis == that.timeInMillis && !(timeZoneId != null ? | ||
| !timeZoneId.equals(that.timeZoneId) : that.timeZoneId != null); | ||
| } | ||
|
|
||
| public int hashCode() { | ||
| int result = (int) (timeInMillis ^ (timeInMillis >>> 32)); | ||
| result = 31 * result + (timeZoneId != null ? timeZoneId.hashCode() : 0); | ||
| return result; | ||
| } | ||
| } |
| @@ -1,40 +1,46 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.common.type; | ||
|
|
||
| import org.apache.commons.codec.DecoderException; | ||
|
|
||
| import static org.apache.commons.codec.binary.Hex.decodeHex; | ||
| import static org.apache.commons.codec.binary.Hex.encodeHex; | ||
|
|
||
| /** | ||
| * Helps to encode bytes to hexadecimal encoded numbers and back. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class HexadecimalNumber { | ||
| public static String encodeByte(byte aByte) { | ||
| return new String(encodeHex(new byte[]{aByte})).toUpperCase(); | ||
| } | ||
|
|
||
| public static byte[] decodeBytes(String string) { | ||
| try { | ||
| return decodeHex(string.toCharArray()); | ||
| } catch (DecoderException e) { | ||
| throw new IllegalArgumentException("Not an even number of hex digits: " + string); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Contains type helpers. | ||
| * <p> | ||
| * This package facilitates types such as hexadecimal numbers, compact calenders and ISO8601 times. | ||
| */ | ||
| package slash.common.type; |
| @@ -20,7 +20,7 @@ | ||
|
|
||
| package slash.common; | ||
|
|
||
| import slash.common.type.CompactCalendar; | ||
|
|
||
| import java.text.DateFormat; | ||
| import java.util.Calendar; | ||
| @@ -1,46 +1,46 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.common.system; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static slash.common.system.Platform.isCurrentAtLeastMinimumVersion; | ||
|
|
||
| public class PlatformTest { | ||
| @Test | ||
| public void testIsCurrentAtLeastMinimumVersion() { | ||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6", "1.6")); | ||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6.0", "1.6.0")); | ||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6.0_14", "1.6.0_14")); | ||
|
|
||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6.0", "1.6")); | ||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6.0_14", "1.6")); | ||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6.0_14", "1.6.0")); | ||
| assertTrue(isCurrentAtLeastMinimumVersion("1.6.0_15", "1.6.0_14")); | ||
|
|
||
| assertFalse(isCurrentAtLeastMinimumVersion("1.6", "1.6.0")); | ||
| assertFalse(isCurrentAtLeastMinimumVersion("1.6", "1.6.0_14")); | ||
| assertFalse(isCurrentAtLeastMinimumVersion("1.6.0", "1.6.0_14")); | ||
| assertFalse(isCurrentAtLeastMinimumVersion("1.6.0_13", "1.6.0_14")); | ||
| } | ||
| } |
| @@ -1,133 +1,134 @@ | ||
| /* | ||
| This file is part of RouteConverter. | ||
| RouteConverter is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| RouteConverter is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with RouteConverter; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| Copyright (C) 2007 Christian Pesch. All Rights Reserved. | ||
| */ | ||
|
|
||
| package slash.common.system; | ||
|
|
||
| import org.junit.Test; | ||
| import slash.common.system.Version; | ||
|
|
||
| import java.text.DateFormat; | ||
| import java.util.Date; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static slash.common.TestCase.calendar; | ||
|
|
||
| public class VersionTest { | ||
|
|
||
| @Test | ||
| public void testParseParameters() { | ||
| Map<String, String> params = Version.parseParameters("b=c,routeconverter.version=1.3,a=b"); | ||
| assertEquals("c", params.get("b")); | ||
| assertEquals("1.3", params.get("routeconverter.version")); | ||
| assertEquals("b", params.get("a")); | ||
| assertNull( params.get("c")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseVersion() { | ||
| assertEquals("1.3", Version.getLatestRouteConverterVersion("b=c,routeconverter.version=1.3,a=b")); | ||
| assertEquals("2", Version.getLatestRouteConverterVersion("x=y,routeconverter.version=2,y=z")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetVersion() { | ||
| assertEquals("1.2.3", new Version("1.2.3").getVersion()); | ||
| assertEquals("1.2", new Version("1.2-3").getVersion()); | ||
| assertEquals("1.2-SNAPSHOT-3", new Version("1.2-SNAPSHOT-3").getVersion()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetMajor() { | ||
| assertEquals("1", new Version("1").getMajor()); | ||
| assertEquals("1", new Version("1.2").getMajor()); | ||
| assertEquals("1", new Version("1.2.3").getMajor()); | ||
| assertEquals("1", new Version("1.2-SNAPSHOT-3").getMajor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetMinor() { | ||
| assertEquals("1", new Version("1").getMinor()); | ||
| assertEquals("2", new Version("1.2").getMinor()); | ||
| assertEquals("2-3", new Version("1.2-3").getMinor()); | ||
| assertEquals("2.3-4", new Version("1.2.3-4").getMinor()); | ||
| assertEquals("2-SNAPSHOT-3", new Version("1.2-SNAPSHOT-3").getMinor()); | ||
| assertEquals("2.3-SNAPSHOT-4", new Version("1.2.3-SNAPSHOT-4").getMinor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetDate() { | ||
| Date date = calendar(2009, 11, 23, 13, 53, 49, 0, "UTC").getCalendar().getTime(); | ||
| DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); | ||
| String expected = dateFormat.format(date); | ||
| String actual = new Version(null, "2009-11-23 13:53:49", null).getDate(); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetPlatform() { | ||
| assertEquals("Windows", new Version(null, null, "Windows64").getOperationSystem()); | ||
| assertEquals("Linux", new Version(null, null, "Linux32").getOperationSystem()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetBits() { | ||
| assertEquals("64", new Version(null, null, "Windows64").getBits()); | ||
| assertEquals("32", new Version(null, null, "Linux32").getBits()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsLatestVersion() { | ||
| assertTrue(new Version("1").isLaterVersionThan(new Version("1"))); | ||
| assertTrue(new Version("2").isLaterVersionThan(new Version("1.3"))); | ||
| assertTrue(new Version("10").isLaterVersionThan(new Version("9"))); | ||
| assertTrue(new Version("11").isLaterVersionThan(new Version("10"))); | ||
|
|
||
| assertTrue(new Version("1.3").isLaterVersionThan(new Version("1"))); | ||
| assertTrue(new Version("1.3").isLaterVersionThan(new Version("1.3"))); | ||
| assertTrue(new Version("1.10").isLaterVersionThan(new Version("1.9"))); | ||
| assertTrue(new Version("1.100").isLaterVersionThan(new Version("1.99"))); | ||
|
|
||
| assertTrue(new Version("1.3.1").isLaterVersionThan(new Version("1.3"))); | ||
| assertTrue(new Version("1.3.10").isLaterVersionThan(new Version("1.3.9"))); | ||
|
|
||
| assertTrue(new Version("1.3-SNAPSHOT-1").isLaterVersionThan(new Version("1.3"))); | ||
| assertTrue(new Version("1.3-SNAPSHOT-2").isLaterVersionThan(new Version("1.3-SNAPSHOT-1"))); | ||
|
|
||
| assertTrue(new Version("0.3").isLaterVersionThan(new Version("0.2"))); | ||
| assertTrue(new Version("1.3").isLaterVersionThan(new Version("1.2"))); | ||
| assertTrue(new Version("2.3").isLaterVersionThan(new Version("2.2"))); | ||
|
|
||
| assertTrue(new Version("1.1").isLaterVersionThan(new Version("0.9"))); | ||
| assertTrue(new Version("1.30.1").isLaterVersionThan(new Version("1.29.2"))); | ||
|
|
||
| assertTrue(new Version("1.30.1").isLaterVersionThan(new Version("1.29.2"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsNotLatestVersion() { | ||
| assertFalse(new Version("1").isLaterVersionThan(new Version("1.3"))); | ||
| assertFalse(new Version("1.2").isLaterVersionThan(new Version("1.3"))); | ||
| assertFalse(new Version("1.2.1").isLaterVersionThan(new Version("1.3"))); | ||
| assertFalse(new Version("1.2-SNAPSHOT-1").isLaterVersionThan(new Version("1.3"))); | ||
| } | ||
| } |