| @@ -1,54 +1,54 @@ | ||
| /* | ||
| 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.converter.gui.actions; | ||
|
|
||
| import slash.navigation.converter.gui.helper.BatchPositionAugmenter; | ||
| import slash.navigation.converter.gui.models.PositionsModel; | ||
| import slash.navigation.gui.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.event.ActionListener; | ||
|
|
||
| /** | ||
| * {@link ActionListener} that adds postal addresses from Google Maps as comments to | ||
| * the selected rows of a {@link JTable} with the help of a {@link slash.navigation.converter.gui.helper.BatchPositionAugmenter}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class AddPostalAddressToPositionsAction extends FrameAction { | ||
| private final JTable table; | ||
| private final PositionsModel positionsModel; | ||
| private final BatchPositionAugmenter augmenter; | ||
|
|
||
| public AddPostalAddressToPositionsAction(JTable table, PositionsModel positionsModel, BatchPositionAugmenter augmenter) { | ||
| this.table = table; | ||
| this.positionsModel = positionsModel; | ||
| this.augmenter = augmenter; | ||
| } | ||
|
|
||
| public void run() { | ||
| int[] selectedRows = table.getSelectedRows(); | ||
| if (selectedRows.length > 0) { | ||
| augmenter.addPostalAddresses(table, positionsModel, selectedRows); | ||
| } | ||
| } | ||
| } |
| @@ -1,54 +1,54 @@ | ||
| /* | ||
| 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.converter.gui.actions; | ||
|
|
||
| import slash.navigation.converter.gui.helper.BatchPositionAugmenter; | ||
| import slash.navigation.converter.gui.models.PositionsModel; | ||
| import slash.navigation.gui.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.event.ActionListener; | ||
|
|
||
| /** | ||
| * {@link ActionListener} that adds speeds to the selected rows of a {@link JTable} | ||
| * with the help of a {@link slash.navigation.converter.gui.helper.BatchPositionAugmenter}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class AddSpeedToPositionsAction extends FrameAction { | ||
| private final JTable table; | ||
| private final PositionsModel positionsModel; | ||
| private final BatchPositionAugmenter augmenter; | ||
|
|
||
| public AddSpeedToPositionsAction(JTable table, PositionsModel positionsModel, BatchPositionAugmenter augmenter) { | ||
| this.table = table; | ||
| this.positionsModel = positionsModel; | ||
| this.augmenter = augmenter; | ||
| } | ||
|
|
||
| public void run() { | ||
| int[] selectedRows = table.getSelectedRows(); | ||
| if (selectedRows.length > 0) { | ||
| augmenter.addSpeeds(table, positionsModel, selectedRows); | ||
| } | ||
| } | ||
| } |
| @@ -1,44 +1,44 @@ | ||
| /* | ||
| 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.converter.gui.actions; | ||
|
|
||
| import slash.navigation.converter.gui.panels.ConvertPanel; | ||
| import slash.navigation.gui.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| /** | ||
| * {@link Action} that imports files to the current position list at the selected row. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class ImportPositionListAction extends FrameAction { | ||
| private final ConvertPanel convertPanel; | ||
|
|
||
| public ImportPositionListAction(ConvertPanel convertPanel) { | ||
| this.convertPanel = convertPanel; | ||
| } | ||
|
|
||
| public void run() { | ||
| convertPanel.importPositionList(); | ||
| } | ||
| } |
| @@ -1,67 +1,67 @@ | ||
| /* | ||
| 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.converter.gui.actions; | ||
|
|
||
| import slash.navigation.base.BaseRoute; | ||
| import slash.navigation.converter.gui.helper.AbstractListDataListener; | ||
| import slash.navigation.converter.gui.models.FormatAndRoutesModel; | ||
| import slash.navigation.converter.gui.models.PositionsModel; | ||
| import slash.navigation.gui.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
| import javax.swing.event.ListDataEvent; | ||
| import java.awt.event.ActionListener; | ||
|
|
||
| /** | ||
| * {@link ActionListener} that inserts the position list of a {@link PositionsModel} at | ||
| * the selected row of a {@link JTable} and removes it from the {@link FormatAndRoutesModel}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class MergePositionListAction extends FrameAction { | ||
| private final JTable table; | ||
| private final BaseRoute sourceRoute; | ||
| private final FormatAndRoutesModel formatAndRoutesModel; | ||
|
|
||
| public MergePositionListAction(JTable table, BaseRoute sourceRoute, FormatAndRoutesModel formatAndRoutesModel) { | ||
| this.table = table; | ||
| this.sourceRoute = sourceRoute; | ||
| this.formatAndRoutesModel = formatAndRoutesModel; | ||
| initialize(); | ||
| } | ||
|
|
||
| protected void initialize() { | ||
| setEnabled(!sourceRoute.equals(formatAndRoutesModel.getSelectedRoute())); | ||
| formatAndRoutesModel.addListDataListener(new AbstractListDataListener() { | ||
| public void process(ListDataEvent e) { | ||
| setEnabled(!sourceRoute.equals(formatAndRoutesModel.getSelectedRoute())); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public void run() { | ||
| int selectedRow = Math.min(table.getSelectedRow() + 1, table.getRowCount()); | ||
| formatAndRoutesModel.getPositionsModel().add(selectedRow, sourceRoute.getPositions()); | ||
| formatAndRoutesModel.removePositionList(sourceRoute); | ||
| } | ||
| } |
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| 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.converter.gui.actions; | ||
|
|
||
| import slash.navigation.catalog.model.CategoryTreeNode; | ||
| import slash.navigation.converter.gui.RouteConverter; | ||
| import slash.navigation.converter.gui.helper.RouteServiceOperator; | ||
| import slash.navigation.converter.gui.models.CatalogModel; | ||
| import slash.navigation.gui.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| import static java.text.MessageFormat.format; | ||
| import static javax.swing.JOptionPane.QUESTION_MESSAGE; | ||
| import static javax.swing.JOptionPane.showInputDialog; | ||
| import static slash.common.io.Transfer.trim; | ||
| import static slash.navigation.converter.gui.helper.JTreeHelper.getSelectedCategoryTreeNode; | ||
|
|
||
| /** | ||
| * {@link Action} that renames a category of the {@link RouteServiceOperator}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class RenameCategoryAction extends FrameAction { | ||
| private final JTree tree; | ||
|
|
||
| public RenameCategoryAction(JTree tree) { | ||
| this.tree = tree; | ||
| } | ||
|
|
||
| public void run() { | ||
| RouteConverter r = RouteConverter.getInstance(); | ||
| CategoryTreeNode selected = getSelectedCategoryTreeNode(tree); | ||
| String name = (String) showInputDialog(r.getFrame(), | ||
| format(RouteConverter.getBundle().getString("rename-category-label"), selected.getName()), | ||
| r.getFrame().getTitle(), QUESTION_MESSAGE, null, null, selected.getName()); | ||
| if (trim(name) == null) | ||
| return; | ||
|
|
||
| ((CatalogModel) tree.getModel()).rename(selected, name); | ||
| } | ||
| } |
| @@ -1,85 +1,85 @@ | ||
| /* | ||
| 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.converter.gui.actions; | ||
|
|
||
| import slash.navigation.base.BaseNavigationFormat; | ||
| import slash.navigation.base.BaseNavigationPosition; | ||
| import slash.navigation.base.BaseRoute; | ||
| import slash.navigation.base.NavigationFormat; | ||
| import slash.navigation.converter.gui.models.FormatAndRoutesModel; | ||
| import slash.navigation.converter.gui.models.PositionsModel; | ||
| import slash.navigation.gui.FrameAction; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.event.ActionListener; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * {@link ActionListener} that splits the position list of a {@link PositionsModel} at | ||
| * the selected rows of a {@link JTable} and adds them as separate position lists to a | ||
| * {@link FormatAndRoutesModel}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class SplitPositionListAction extends FrameAction { | ||
| private final JTable table; | ||
| private final PositionsModel positionsModel; | ||
| private final FormatAndRoutesModel formatAndRoutesModel; | ||
|
|
||
| public SplitPositionListAction(JTable table, PositionsModel positionsModel, FormatAndRoutesModel formatAndRoutesModel) { | ||
| this.table = table; | ||
| this.positionsModel = positionsModel; | ||
| this.formatAndRoutesModel = formatAndRoutesModel; | ||
| } | ||
|
|
||
| public void run() { | ||
| int[] selectedRows = table.getSelectedRows(); | ||
| if (selectedRows.length > 0) { | ||
| BaseRoute selectedRoute = formatAndRoutesModel.getSelectedRoute(); | ||
| int routeInsertIndex = formatAndRoutesModel.getSize(); | ||
|
|
||
| for (int i = selectedRows.length - 1; i >= 0; i--) { | ||
| int fromIndex = selectedRows[i]; | ||
| fromIndex = Math.max(fromIndex, 0); | ||
| int toIndex = i + 1 < selectedRows.length ? selectedRows[i + 1] : positionsModel.getRowCount(); | ||
| toIndex = Math.max(toIndex, 0); | ||
| if (fromIndex == 0 && toIndex == 0) | ||
| break; | ||
|
|
||
| List<BaseNavigationPosition> positions = positionsModel.getPositions(fromIndex, toIndex); | ||
| positionsModel.remove(fromIndex, toIndex); | ||
| NavigationFormat format = formatAndRoutesModel.getFormat(); | ||
| @SuppressWarnings({"unchecked"}) | ||
| BaseRoute<BaseNavigationPosition, BaseNavigationFormat> target = | ||
| format.createRoute(selectedRoute.getCharacteristics(), selectedRoute.getName() + "(" + (i + 1) + ")", positions); | ||
| formatAndRoutesModel.addPositionList(routeInsertIndex, target); | ||
| } | ||
|
|
||
| final int selectedRow = Math.max(selectedRows[selectedRows.length - 1] - 1, 0); | ||
| SwingUtilities.invokeLater(new Runnable() { | ||
| public void run() { | ||
| table.getSelectionModel().setSelectionInterval(selectedRow, selectedRow); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| 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.converter.gui.helper; | ||
|
|
||
| import slash.navigation.catalog.model.CategoryTreeNode; | ||
|
|
||
| import javax.swing.*; | ||
| import javax.swing.event.TableModelEvent; | ||
| import javax.swing.tree.TreePath; | ||
| import java.awt.*; | ||
|
|
||
| /** | ||
| * A helper for simplified {@link JTree} operations. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class JTreeHelper { | ||
| public static CategoryTreeNode getSelectedCategoryTreeNode(JTree tree) { | ||
| TreePath treePath = tree.getSelectionPath(); | ||
| // if there is no selected root take the local root | ||
| Object treeNode = treePath != null ? | ||
| treePath.getLastPathComponent() : | ||
| tree.getModel().getChild(tree.getModel().getRoot(), 0); | ||
| if (!(treeNode instanceof CategoryTreeNode)) | ||
| return null; | ||
| return (CategoryTreeNode) treeNode; | ||
| } | ||
| } |
| @@ -1,42 +1,36 @@ | ||
| /* | ||
| 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.converter.gui.models; | ||
|
|
||
| import slash.navigation.catalog.domain.Catalog; | ||
| import slash.navigation.catalog.model.CategoryTreeNode; | ||
|
|
||
| import javax.swing.tree.TreeModel; | ||
|
|
||
| /** | ||
| * Acts as a {@link TreeModel} for the categories and routes of a {@link Catalog}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public interface CatalogModel extends TreeModel { | ||
| void rename(CategoryTreeNode category, String name); | ||
| } |
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| 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.converter.gui.models; | ||
|
|
||
| import slash.navigation.catalog.domain.Catalog; | ||
| import slash.navigation.catalog.model.CategoryTreeNode; | ||
| import slash.navigation.converter.gui.helper.RouteServiceOperator; | ||
|
|
||
| import javax.swing.*; | ||
| import javax.swing.tree.DefaultTreeModel; | ||
| import javax.swing.tree.TreeModel; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Acts as a {@link TreeModel} for the categories and routes of a {@link Catalog}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class CatalogModelImpl extends DefaultTreeModel implements CatalogModel { | ||
| private final RouteServiceOperator operator; | ||
|
|
||
| public CatalogModelImpl(CategoryTreeNode root, RouteServiceOperator operator) { | ||
| super(root); | ||
| root.setTreeModel(this); | ||
| this.operator = operator; | ||
| } | ||
|
|
||
| public boolean isLeaf(Object node) { | ||
| // this would go through the whole tree ((CategoryTreeNode) node).getChildCount() == 0; | ||
| return false; | ||
| } | ||
|
|
||
| // Undoable operations | ||
|
|
||
| public void rename(final CategoryTreeNode category, final String name) { | ||
| operator.executeOperation(new RouteServiceOperator.NewOperation() { | ||
| public String getName() { | ||
| return "RenameCategory"; | ||
| } | ||
|
|
||
| public void run() throws IOException { | ||
| category.getCategory().update(null, name); | ||
|
|
||
| SwingUtilities.invokeLater(new Runnable() { | ||
| public void run() { | ||
| category.clearChildren(); | ||
| nodeChanged(category); | ||
| // TODO nodeStructureChanged(category); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| } |
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| 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.converter.gui.undo; | ||
|
|
||
| import slash.navigation.catalog.model.CategoryTreeNode; | ||
|
|
||
| import javax.swing.undo.AbstractUndoableEdit; | ||
| import javax.swing.undo.CannotRedoException; | ||
| import javax.swing.undo.CannotUndoException; | ||
| import javax.swing.undo.UndoableEdit; | ||
|
|
||
| /** | ||
| * Acts as a {@link UndoableEdit} for renaming the category of a {@link UndoCatalogModel}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| class RenameCategory extends AbstractUndoableEdit { | ||
| private UndoCatalogModel catalogModel; | ||
| private CategoryTreeNode category; | ||
| private String oldName, newName; | ||
|
|
||
| public RenameCategory(UndoCatalogModel catalogModel, CategoryTreeNode category, String oldName, String newName) { | ||
| this.catalogModel = catalogModel; | ||
| this.category = category; | ||
| this.oldName = oldName; | ||
| this.newName = newName; | ||
| } | ||
|
|
||
| public String getUndoPresentationName() { | ||
| return "rename-category-undo"; | ||
| } | ||
|
|
||
| public String getRedoPresentationName() { | ||
| return "rename-category-redo"; | ||
| } | ||
|
|
||
| public void undo() throws CannotUndoException { | ||
| super.undo(); | ||
| catalogModel.rename(category, oldName, false); | ||
| } | ||
|
|
||
| public void redo() throws CannotRedoException { | ||
| super.redo(); | ||
| catalogModel.rename(category, newName, false); | ||
| } | ||
| } |
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| 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.converter.gui.undo; | ||
|
|
||
| import slash.navigation.catalog.domain.Catalog; | ||
| import slash.navigation.catalog.model.CategoryTreeNode; | ||
| import slash.navigation.converter.gui.helper.RouteServiceOperator; | ||
| import slash.navigation.converter.gui.models.CatalogModel; | ||
| import slash.navigation.converter.gui.models.CatalogModelImpl; | ||
| import slash.navigation.gui.UndoManager; | ||
|
|
||
| import javax.swing.event.TreeModelListener; | ||
| import javax.swing.tree.TreeModel; | ||
| import javax.swing.tree.TreePath; | ||
|
|
||
| /** | ||
| * Acts as a {@link TreeModel} for the categories and routes of a {@link Catalog}. | ||
| * | ||
| * @author Christian Pesch | ||
| */ | ||
|
|
||
| public class UndoCatalogModel implements CatalogModel { | ||
| private final CatalogModelImpl delegate; | ||
| private final UndoManager undoManager; | ||
|
|
||
| public UndoCatalogModel(UndoManager undoManager, CategoryTreeNode root, RouteServiceOperator operator) { | ||
| this.delegate = new CatalogModelImpl(root, operator); | ||
| this.undoManager = undoManager; | ||
| } | ||
|
|
||
| // TreeModel | ||
|
|
||
| public Object getRoot() { | ||
| return delegate.getRoot(); | ||
| } | ||
|
|
||
| public Object getChild(Object parent, int index) { | ||
| return delegate.getChild(parent, index); | ||
| } | ||
|
|
||
| public int getChildCount(Object parent) { | ||
| return delegate.getChildCount(parent); | ||
| } | ||
|
|
||
| public boolean isLeaf(Object node) { | ||
| return delegate.isLeaf(node); | ||
| } | ||
|
|
||
| public void valueForPathChanged(TreePath path, Object newValue) { | ||
| delegate.valueForPathChanged(path, newValue); | ||
| } | ||
|
|
||
| public int getIndexOfChild(Object parent, Object child) { | ||
| return delegate.getIndexOfChild(parent, child); | ||
| } | ||
|
|
||
| public void addTreeModelListener(TreeModelListener l) { | ||
| delegate.addTreeModelListener(l); | ||
| } | ||
|
|
||
| public void removeTreeModelListener(TreeModelListener l) { | ||
| delegate.removeTreeModelListener(l); | ||
| } | ||
|
|
||
| // Undoable operations | ||
|
|
||
| public void rename(CategoryTreeNode category, String name) { | ||
| rename(category, name, true); | ||
| } | ||
|
|
||
| void rename(CategoryTreeNode category, String newName, boolean trackUndo) { | ||
| String oldName = category.getName(); | ||
| delegate.rename(category, newName); | ||
| if (trackUndo) | ||
| undoManager.addEdit(new RenameCategory(this, category, oldName, newName)); | ||
| } | ||
| } |