From: <aki...@us...> - 2006-12-23 09:53:58
|
Revision: 1219 http://svn.sourceforge.net/gridarta/?rev=1219&view=rev Author: akirschbaum Date: 2006-12-23 01:53:58 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Rename *editor.CMapTileList to *editor.gui.maptilelist.MapTileListControl. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/maptilelist/ trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListControl.java trunk/daimonin/src/daieditor/gui/maptilelist/ trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListControl.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CMapTileList.java trunk/daimonin/src/daieditor/CMapTileList.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -587,7 +587,7 @@ mainView.showArchPanelQuickObject(gameObject); } - boolean insertArchToMap(final GameObject newarch, final String archname, final GameObject next, final Point pos, final boolean join) { + public boolean insertArchToMap(final GameObject newarch, final String archname, final GameObject next, final Point pos, final boolean join) { return currentMap.insertArchToMap(newarch, archname, next, pos, join); } Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -25,6 +25,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.gui.maptilelist.MapTileListControl; import cfeditor.map.MapControl; import cfeditor.menu.AggregateMenuLocation; import cfeditor.menu.MenuManager; @@ -139,7 +140,7 @@ private final List<MapViewIFrame> mapViews = new ArrayList<MapViewIFrame>(); /** List of objects on map (right side). */ - private CMapTileList mapTileList; + private MapTileListControl mapTileListControl; /** Attributes panel (bottom). */ private CMapArchPanel mapArchPanel; @@ -219,12 +220,12 @@ // Build the placeholder for tile palette archPanel = new CArchPanel(mainControl); - mapTileList = new CMapTileList(mainControl, this); + mapTileListControl = new MapTileListControl(mainControl, this); mapDesktop = new JDesktopPane(); if (!mapTileListBottom) { // the map tile list is on the right side - splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapDesktop, mapTileList); + splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapDesktop, mapTileListControl); splitRightPane.setDividerLocation(divLocationRight); splitRightPane.setDividerSize(BORDER_SIZE); @@ -247,7 +248,7 @@ } else { // the map tile list is merged into the bottom panel mapArchPanel = new CMapArchPanel(mainControl, this); - splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, mapTileList); + splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, mapTileListControl); splitRightPane.setDividerLocation(divLocationRight); splitRightPane.setDividerSize(BORDER_SIZE); @@ -375,15 +376,15 @@ // access mape tile list ... public void setMapTileList(final MapControl map, final GameObject gameObject) { - mapTileList.setMapTileList(map, gameObject); + mapTileListControl.setMapTileList(map, gameObject); } public void refreshMapTileList() { - mapTileList.refresh(); + mapTileListControl.refresh(); } public GameObject getMapTileSelection() { - return mapTileList.getMapTileSelection(); + return mapTileListControl.getMapTileSelection(); } /** @@ -466,7 +467,7 @@ */ void refreshMenusAndToolbars() { archPanel.refresh(); - mapTileList.refresh(); + mapTileListControl.refresh(); mapArchPanel.refresh(); statusBar.refresh(); @@ -474,7 +475,7 @@ } /** Refresh the map arch panel (bottom window). */ - void refreshMapArchPanel() { + public void refreshMapArchPanel() { mapArchPanel.refresh(); } @@ -517,7 +518,7 @@ // set bounds to maximum size if (!mapTileListBottom) { - mapView.setBounds(0, 0, mapTileList.getX() - BORDER_SIZE - 2, mapArchPanel.getY() - BORDER_SIZE - 4); + mapView.setBounds(0, 0, mapTileListControl.getX() - BORDER_SIZE - 2, mapArchPanel.getY() - BORDER_SIZE - 4); } else { mapView.setBounds(0, 0, mapDesktop.getWidth() - 2, mapDesktop.getHeight() - 2); } @@ -941,8 +942,8 @@ MenuManager.getMenuManager().addMenuLocation(currentmapLocation); } - public CMapTileList getMapTileList() { - return mapTileList; + public MapTileListControl getMapTileListControl() { + return mapTileListControl; } private final class LookAndFeelAction extends AbstractAction { Deleted: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -1,479 +0,0 @@ -/* - * Crossfire Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor; - -import cfeditor.gameobject.GameObject; -import cfeditor.map.MapControl; -import cfeditor.map.MapModel; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.Date; -import javax.swing.BorderFactory; -import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import static javax.swing.JViewport.SIMPLE_SCROLL_MODE; -import javax.swing.ScrollPaneConstants; -import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; -import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER; -import javax.swing.SwingConstants; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import net.sf.gridarta.gameobject.GameObjectContainer; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * The panel that displays the arches of the currently selected map square. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CMapTileList extends JPanel implements MapCursorListener { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final CMainView mainView; - - /** The "Import..." button. */ - private final JList list; - - private final DefaultListModel model; - - private int listCounter = 0; - - /** - * Time of last click in the panel (value in msec by Date.getTime()) - * and arch-ID of arch that received last click. - */ - private long lastClick = -1; - - private GameObject lastClickGameObject = null; - - /** The currently selected MapSquare. */ - private transient Point currentSquare = null; - - /** - * Create a CMapTileList. - * @param mainControl MainControl, used for icons - * @param mainView MainView, used for updating UI - */ - public CMapTileList(final CMainControl mainControl, final CMainView mainView) { - this.mainControl = mainControl; - this.mainView = mainView; - setLayout(new BorderLayout()); - - model = new DefaultListModel(); - list = new JList(model); - list.setCellRenderer(new MyCellRenderer()); - list.setBackground(Color.lightGray); - final JScrollPane scrollPane = new JScrollPane(list); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); - add(scrollPane, BorderLayout.CENTER); - - final JPanel arrows = new JPanel(); - if (mainView.isMapTileListBottom()) { - arrows.setLayout(new GridLayout(2, 1)); - } - final JScrollPane scrollPane2 = new JScrollPane(arrows); - scrollPane2.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER); - scrollPane2.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); - scrollPane2.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); - if (!mainView.isMapTileListBottom()) { - add(scrollPane2, BorderLayout.SOUTH); // put up/down buttons south - } else { - add(scrollPane2, BorderLayout.WEST); // put up/down buttons west - scrollPane2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); // don't show the border - } - - final CFancyButton buttonDown = new CFancyButton(null, "Move Tile Position Down", - IGUIConstants.MOVE_DOWN_ICON, - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - final GameObject arch = getMapTileSelection(); - if (arch != null) { - arch.moveDown(); - refresh(); - } - } - }); - buttonDown.setVerticalTextPosition(SwingConstants.BOTTOM); - buttonDown.setHorizontalTextPosition(SwingConstants.CENTER); - if (!mainView.isMapTileListBottom()) { - arrows.add(buttonDown, BorderLayout.EAST); - } - - final CFancyButton buttonUp = new CFancyButton(null, "Move Tile Position Up", - IGUIConstants.MOVE_UP_ICON, - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - final GameObject arch = getMapTileSelection(); - if (arch != null) { - arch.moveUp(); - refresh(); - } - } - }); - buttonUp.setVerticalTextPosition(SwingConstants.BOTTOM); - buttonUp.setHorizontalTextPosition(SwingConstants.CENTER); - if (!mainView.isMapTileListBottom()) { - arrows.add(buttonUp, BorderLayout.WEST); - } else { - arrows.add(buttonUp); - arrows.add(buttonDown); - } - - list.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - mainView.setMapArchPanelObject(getMapTileSelection()); - } - }); - - /** - * listen for mouse events in the panel - */ - list.addMouseListener(new MouseAdapter() { - @Override public void mousePressed(final MouseEvent e) { - if (e.getModifiers() == InputEvent.BUTTON1_MASK && !e.isShiftDown() && !e.isControlDown()) { - // --- left mouse button: select arch --- - // first, check if this is a doubleclick - final long thisClick = (new Date()).getTime(); - if (thisClick - lastClick < IGUIConstants.DOUBLECLICK_MS && lastClickGameObject != null && lastClickGameObject == getMapTileSelection()) { - // doubleclick: open attribute window - mainControl.openAttrDialog(getMapTileSelection()); - } else { - // single click: now make this arch selected - mainView.setMapArchPanelObject(getMapTileSelection()); - } - - // save values for next click - lastClick = thisClick; - lastClickGameObject = getMapTileSelection(); - } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.isShiftDown())) { - // --- right mouse button: insert arch --- - - if (currentSquare != null && mainControl.getArchPanelHighlight() != null) { - mainControl.getCurrentMap().getMapModel().beginTransaction("Insert"); // TODO; I18N/L10N - final int listIndex = getListIndex(e); - if (listIndex >= list.getModel().getSize()) { - mainControl.insertArchToMap(mainControl.getArchPanelHighlight(), mainControl.getPanelArchName(), null, currentSquare, MapModel.JOIN_ENABLE); - } else { - final GameObject entry = (GameObject) model.getElementAt(listIndex); - mainControl.insertArchToMap(mainControl.getArchPanelHighlight(), mainControl.getPanelArchName(), entry, currentSquare, MapModel.JOIN_ENABLE); - } - mainControl.getCurrentMap().getMapModel().endTransaction(); - - // refresh - mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified - mainControl.getMainView().refreshMapTileList(); // update tile window - } - } else { - // --- middle mouse button: delete arch --- - final int listIndex = getListIndex(e); - if (listIndex < list.getModel().getSize()) { - mainControl.getCurrentMap().getMapModel().beginTransaction("Delete"); // TODO; I18N/L10N - deleteIndexFromList(listIndex); - mainControl.getCurrentMap().getMapModel().endTransaction(); - } - } - } - }); - } - - public void selectArchBelow() { - list.setSelectedIndex(list.getSelectedIndex() + 1); - } - - public void selectArchAbove() { - final int index = list.getSelectedIndex(); - if (index > 0) { - list.setSelectedIndex(index - 1); - } - } - - /** - * Determine the list index for a given mouse event. This function differs - * from <code>list.locationTopIndex(e.getPoint())</code> in that it always - * returns a valid list index, or the list size (i.e., one element past the - * last list index) if the point is after the end of the list. - * - * @param e the mouse event containing the position to check - * - * @return the selected list index - */ - private int getListIndex(final MouseEvent e) { - final int lastIndex = list.getModel().getSize() - 1; - if (lastIndex < 0) { - return 0; - } - - final Rectangle bounds = list.getCellBounds(lastIndex, lastIndex); - final int lowestY = (int) (bounds.getY() + bounds.getHeight()); - if ((int) (e.getPoint().getY()) >= lowestY) { - return lastIndex + 1; - } - - final int listIndex = list.locationToIndex(e.getPoint()); - assert listIndex >= 0; // -1 is returned only if the list is empty, but this was already checked - return listIndex; - } - - /** - * Return the currently selected GameObject within this list (currently selected MapSquare). - * @return the currently selected GameObject - */ - @Nullable public GameObject getMapTileSelection() { - return (GameObject) list.getSelectedValue(); - } - - /** - * Delete an GameObject with a specific list index. - * @param index List index of GameObject - */ - private void deleteIndexFromList(final int index) { - if (index < 0) { - return; - } // index is -1 for empty lists, so an IndexOutOfBoundsException would be thrown - final GameObject temp = getMapTileSelection(); - final GameObject entry = (GameObject) model.getElementAt(index); - if (entry != null) { - mainControl.deleteMapArch(entry, currentSquare, MapModel.JOIN_ENABLE); - setMapTileList(mainControl.getCurrentMap(), temp); - } - } - - public int getTileArch(final int oldindex) { - final int index; - if (oldindex == -1) { - index = list.getFirstVisibleIndex(); - } else if (list.getModel().getSize() <= oldindex) { - index = oldindex; - } else { - index = -1; - } - if (index != -1 && list.getModel().getSize() > 0) { - list.setSelectedIndex(index); - } - return list.getSelectedIndex(); - } - - void refresh() { - final GameObject gameObject; - final GameObject sel = getMapTileSelection(); - if (sel != null) { - gameObject = getMapTileSelection(); - } else { - gameObject = null; - } - mainView.setMapTileList(mainControl.getCurrentMap(), gameObject); - repaint(); - } - - /** - * Set the display to the currently selected map tile. - * @param mapControl Map to get display for (includes selection information) - * @param gameObject selected GameObject - */ - public void setMapTileList(final MapControl mapControl, final GameObject gameObject) { - list.setEnabled(false); - model.removeAllElements(); - if (mapControl == null) { - // mouse has been clicked outside the mapview - currentSquare = null; - getTileArch(-1); - list.setEnabled(true); - mainView.refreshMapArchPanel(); - return; - } - - listCounter = 0; - currentSquare = mapControl.getMapCursor().getLocation(); - int postSelect = -1; - boolean foundSIndex = false; - int sIndex = 0; - - // Now go through the list backwards and put all arches - // on the panel in this order - if (currentSquare != null) { - for (final GameObject node : mapControl.getMapModel().getMapSquare(currentSquare).reverse()) { - // add the node - if (node == gameObject) { - postSelect = listCounter; - } - listCounter++; - model.addElement(node); - - // if view-settings are applied, mark topmost "visible" tile for selection - if (mainControl.isTileEditSet() && !foundSIndex && mainControl.isTileEdit(node.getEditType())) { - sIndex = listCounter - 1; // select this tile - foundSIndex = true; // this is it - don't select any other tile - } - - final int tmpSelect = addInvObjects(node.getHead(), gameObject); - if (postSelect == -1 && tmpSelect != -1) { - postSelect = tmpSelect; - } - } - } - - if (postSelect != -1) { - list.setSelectedIndex(postSelect); - } else { - // Per default, the topmost arch matching the view settings is selected. - // (With no view settings applied, the very topmost arch is selected.) - list.setSelectedIndex(sIndex); - } - - // refresh the MapArchPanel to display the new arch - mainView.refreshMapArchPanel(); - - list.setEnabled(true); - } - - /** - * Add inventory objects to an arch in the MapTileList recursively. - * @param node the arch where the inventory gets added - * @param gameObject selected GameObject - * @return <code>-1</code> if <var>selArch</var> was found, else <var>listCounter</var> of the arch - */ - private int addInvObjects(final GameObject node, final GameObject gameObject) { - int selListCounter = -1; - for (final GameObject invObject : node.getHead()) { - if (invObject == gameObject) { - selListCounter = listCounter; - } - listCounter++; - model.addElement(invObject); - - final int tmpListCounter = addInvObjects(invObject, gameObject); - if (tmpListCounter != -1) { - selListCounter = tmpListCounter; - } - } - return selListCounter; - } - - /** {@inheritDoc} */ - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - if (e.getSource().isActive()) { - // Position changed - setMapTileList(mainControl.getCurrentMap(), null); - } else { - // Cursor was disabled - setMapTileList(null, null); - } - } - - /** {@inheritDoc} */ - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - // A mode change can be ignored - } - - /** CellRenderer for rendering ArchObjects on a certain map tile in a list. */ - private final class MyCellRenderer extends DefaultListCellRenderer { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** {@inheritDoc} */ - @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - - GameObject arch = (GameObject) value; - - // arch == null should not happen, but it *can* happen when the active - // window gets changed by user and java is still blitting here - if (arch != null) { - arch = arch.getHead(); - - if (!arch.hasArchetype()) { - setIcon(CMainControl.getNoarchTileIcon()); - } else if (arch.getFaceFlag()) { - setIcon(CMainControl.getNofaceTileIcon()); - } else if (arch.getFaceNr() == -1) { - setIcon(CMainControl.getUnknownTileIcon()); - } else { - setIcon(mainControl.getFace(arch.getFaceNr())); - } - - // In the map-tile-window the object names are displayed - // next to the icons - if (arch.getObjName() != null && arch.getObjName().length() > 0) { - setText(arch.getObjName()); // special name - } else { - final String defname; - if (arch.hasArchetype()) { - defname = arch.getArchetype().getObjName(); - } else { - defname = null; - } - - if (defname != null && defname.length() > 0) { - setText(defname); // default name - } else { - setText(arch.getArchetypeName()); // arch name - } - } - } else { - setIcon(CMainControl.getUnknownTileIcon()); - setText("?"); - } - - int indent = 0; - for (;;) { - final GameObjectContainer<GameObject> env = arch.getContainer(); - if (env == null || !(env instanceof GameObject)) { - break; - } - arch = (GameObject) env; - indent++; - } - if (indent > 1) { - setBorder(BorderFactory.createEmptyBorder(0, (indent - 1) * 16, 0, 0)); // indentation - } - - return this; - } - - } // class MyCellRenderer - -} // class CMapTileList Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -128,7 +128,7 @@ mapCursor = new MapCursor(mapGrid); mapCursor.addMapCursorListener(this); if (!mapControl.isPickmap()) { - mapCursor.addMapCursorListener(mainControl.getMainView().getMapTileList()); + mapCursor.addMapCursorListener(mainControl.getMainView().getMapTileListControl()); mapCursor.addMapCursorListener(mainControl.getMainView().getStatusBar()); mapCursor.addMapCursorListener(mainControl.getMapCursorControl()); } Modified: trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -23,9 +23,9 @@ import cfeditor.CMainControl; import cfeditor.CMainView; -import cfeditor.CMapTileList; import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; +import cfeditor.gui.maptilelist.MapTileListControl; import cfeditor.map.MapControl; import java.awt.Point; import javax.swing.Action; @@ -161,9 +161,9 @@ if (mapCursor.isActive()) { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final CMapTileList mapTileList = mainView.getMapTileList(); - assert mapTileList != null; - final GameObject arch = mapTileList.getMapTileSelection(); + final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); + assert mapTileListControl != null; + final GameObject arch = mapTileListControl.getMapTileSelection(); if (arch != null) { final Point pos = mapCursor.getLocation(); assert pos != null; @@ -216,12 +216,12 @@ if (getMapCursor().isActive()) { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final CMapTileList mapTileList = mainView.getMapTileList(); - assert mapTileList != null; + final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); + assert mapTileListControl != null; if (above) { - mapTileList.selectArchAbove(); + mapTileListControl.selectArchAbove(); } else { - mapTileList.selectArchBelow(); + mapTileListControl.selectArchBelow(); } } } @@ -230,9 +230,9 @@ if (getMapCursor().isActive()) { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final CMapTileList mapTileList = mainView.getMapTileList(); - assert mapTileList != null; - final GameObject arch = mapTileList.getMapTileSelection(); + final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); + assert mapTileListControl != null; + final GameObject arch = mapTileListControl.getMapTileSelection(); if (arch != null) { mainControl.openAttrDialog(arch); } Copied: trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListControl.java (from rev 1218, trunk/crossfire/src/cfeditor/CMapTileList.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListControl.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListControl.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -0,0 +1,484 @@ +/* + * Crossfire Java Editor. + * Copyright (C) 2000 Michael Toennies + * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 The Gridarta Developers + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package cfeditor.gui.maptilelist; + +import cfeditor.CFancyButton; +import cfeditor.CMainControl; +import cfeditor.CMainView; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; +import cfeditor.map.MapControl; +import cfeditor.map.MapModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Date; +import javax.swing.BorderFactory; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import static javax.swing.JViewport.SIMPLE_SCROLL_MODE; +import javax.swing.ScrollPaneConstants; +import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; +import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import net.sf.gridarta.gameobject.GameObjectContainer; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The panel that displays the arches of the currently selected map square. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class MapTileListControl extends JPanel implements MapCursorListener { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final CMainView mainView; + + /** The "Import..." button. */ + private final JList list; + + private final DefaultListModel model; + + private int listCounter = 0; + + /** + * Time of last click in the panel (value in msec by Date.getTime()) + * and arch-ID of arch that received last click. + */ + private long lastClick = -1; + + private GameObject lastClickGameObject = null; + + /** The currently selected MapSquare. */ + private transient Point currentSquare = null; + + /** + * Create a MapTileListControl. + * @param mainControl MainControl, used for icons + * @param mainView MainView, used for updating UI + */ + public MapTileListControl(final CMainControl mainControl, final CMainView mainView) { + this.mainControl = mainControl; + this.mainView = mainView; + setLayout(new BorderLayout()); + + model = new DefaultListModel(); + list = new JList(model); + list.setCellRenderer(new MyCellRenderer()); + list.setBackground(Color.lightGray); + final JScrollPane scrollPane = new JScrollPane(list); + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + scrollPane.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); + add(scrollPane, BorderLayout.CENTER); + + final JPanel arrows = new JPanel(); + if (mainView.isMapTileListBottom()) { + arrows.setLayout(new GridLayout(2, 1)); + } + final JScrollPane scrollPane2 = new JScrollPane(arrows); + scrollPane2.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER); + scrollPane2.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); + scrollPane2.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); + if (!mainView.isMapTileListBottom()) { + add(scrollPane2, BorderLayout.SOUTH); // put up/down buttons south + } else { + add(scrollPane2, BorderLayout.WEST); // put up/down buttons west + scrollPane2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); // don't show the border + } + + final CFancyButton buttonDown = new CFancyButton(null, "Move Tile Position Down", + IGUIConstants.MOVE_DOWN_ICON, + new ActionListener() { + public void actionPerformed(final ActionEvent event) { + final GameObject arch = getMapTileSelection(); + if (arch != null) { + arch.moveDown(); + refresh(); + } + } + }); + buttonDown.setVerticalTextPosition(SwingConstants.BOTTOM); + buttonDown.setHorizontalTextPosition(SwingConstants.CENTER); + if (!mainView.isMapTileListBottom()) { + arrows.add(buttonDown, BorderLayout.EAST); + } + + final CFancyButton buttonUp = new CFancyButton(null, "Move Tile Position Up", + IGUIConstants.MOVE_UP_ICON, + new ActionListener() { + public void actionPerformed(final ActionEvent event) { + final GameObject arch = getMapTileSelection(); + if (arch != null) { + arch.moveUp(); + refresh(); + } + } + }); + buttonUp.setVerticalTextPosition(SwingConstants.BOTTOM); + buttonUp.setHorizontalTextPosition(SwingConstants.CENTER); + if (!mainView.isMapTileListBottom()) { + arrows.add(buttonUp, BorderLayout.WEST); + } else { + arrows.add(buttonUp); + arrows.add(buttonDown); + } + + list.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(final ListSelectionEvent e) { + mainView.setMapArchPanelObject(getMapTileSelection()); + } + }); + + /** + * listen for mouse events in the panel + */ + list.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(final MouseEvent e) { + if (e.getModifiers() == InputEvent.BUTTON1_MASK && !e.isShiftDown() && !e.isControlDown()) { + // --- left mouse button: select arch --- + // first, check if this is a doubleclick + final long thisClick = (new Date()).getTime(); + if (thisClick - lastClick < IGUIConstants.DOUBLECLICK_MS && lastClickGameObject != null && lastClickGameObject == getMapTileSelection()) { + // doubleclick: open attribute window + mainControl.openAttrDialog(getMapTileSelection()); + } else { + // single click: now make this arch selected + mainView.setMapArchPanelObject(getMapTileSelection()); + } + + // save values for next click + lastClick = thisClick; + lastClickGameObject = getMapTileSelection(); + } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.isShiftDown())) { + // --- right mouse button: insert arch --- + + if (currentSquare != null && mainControl.getArchPanelHighlight() != null) { + mainControl.getCurrentMap().getMapModel().beginTransaction("Insert"); // TODO; I18N/L10N + final int listIndex = getListIndex(e); + if (listIndex >= list.getModel().getSize()) { + mainControl.insertArchToMap(mainControl.getArchPanelHighlight(), mainControl.getPanelArchName(), null, currentSquare, MapModel.JOIN_ENABLE); + } else { + final GameObject entry = (GameObject) model.getElementAt(listIndex); + mainControl.insertArchToMap(mainControl.getArchPanelHighlight(), mainControl.getPanelArchName(), entry, currentSquare, MapModel.JOIN_ENABLE); + } + mainControl.getCurrentMap().getMapModel().endTransaction(); + + // refresh + mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified + mainControl.getMainView().refreshMapTileList(); // update tile window + } + } else { + // --- middle mouse button: delete arch --- + final int listIndex = getListIndex(e); + if (listIndex < list.getModel().getSize()) { + mainControl.getCurrentMap().getMapModel().beginTransaction("Delete"); // TODO; I18N/L10N + deleteIndexFromList(listIndex); + mainControl.getCurrentMap().getMapModel().endTransaction(); + } + } + } + }); + } + + public void selectArchBelow() { + list.setSelectedIndex(list.getSelectedIndex() + 1); + } + + public void selectArchAbove() { + final int index = list.getSelectedIndex(); + if (index > 0) { + list.setSelectedIndex(index - 1); + } + } + + /** + * Determine the list index for a given mouse event. This function differs + * from <code>list.locationTopIndex(e.getPoint())</code> in that it always + * returns a valid list index, or the list size (i.e., one element past the + * last list index) if the point is after the end of the list. + * + * @param e the mouse event containing the position to check + * + * @return the selected list index + */ + private int getListIndex(final MouseEvent e) { + final int lastIndex = list.getModel().getSize() - 1; + if (lastIndex < 0) { + return 0; + } + + final Rectangle bounds = list.getCellBounds(lastIndex, lastIndex); + final int lowestY = (int) (bounds.getY() + bounds.getHeight()); + if ((int) (e.getPoint().getY()) >= lowestY) { + return lastIndex + 1; + } + + final int listIndex = list.locationToIndex(e.getPoint()); + assert listIndex >= 0; // -1 is returned only if the list is empty, but this was already checked + return listIndex; + } + + /** + * Return the currently selected GameObject within this list (currently selected MapSquare). + * @return the currently selected GameObject + */ + @Nullable public GameObject getMapTileSelection() { + return (GameObject) list.getSelectedValue(); + } + + /** + * Delete an GameObject with a specific list index. + * @param index List index of GameObject + */ + private void deleteIndexFromList(final int index) { + if (index < 0) { + return; + } // index is -1 for empty lists, so an IndexOutOfBoundsException would be thrown + final GameObject temp = getMapTileSelection(); + final GameObject entry = (GameObject) model.getElementAt(index); + if (entry != null) { + mainControl.deleteMapArch(entry, currentSquare, MapModel.JOIN_ENABLE); + setMapTileList(mainControl.getCurrentMap(), temp); + } + } + + public int getTileArch(final int oldindex) { + final int index; + if (oldindex == -1) { + index = list.getFirstVisibleIndex(); + } else if (list.getModel().getSize() <= oldindex) { + index = oldindex; + } else { + index = -1; + } + if (index != -1 && list.getModel().getSize() > 0) { + list.setSelectedIndex(index); + } + return list.getSelectedIndex(); + } + + public void refresh() { + final GameObject gameObject; + final GameObject sel = getMapTileSelection(); + if (sel != null) { + gameObject = getMapTileSelection(); + } else { + gameObject = null; + } + mainView.setMapTileList(mainControl.getCurrentMap(), gameObject); + repaint(); + } + + /** + * Set the display to the currently selected map tile. + * @param mapControl Map to get display for (includes selection information) + * @param gameObject selected GameObject + */ + public void setMapTileList(final MapControl mapControl, final GameObject gameObject) { + list.setEnabled(false); + model.removeAllElements(); + if (mapControl == null) { + // mouse has been clicked outside the mapview + currentSquare = null; + getTileArch(-1); + list.setEnabled(true); + mainView.refreshMapArchPanel(); + return; + } + + listCounter = 0; + currentSquare = mapControl.getMapCursor().getLocation(); + int postSelect = -1; + boolean foundSIndex = false; + int sIndex = 0; + + // Now go through the list backwards and put all arches + // on the panel in this order + if (currentSquare != null) { + for (final GameObject node : mapControl.getMapModel().getMapSquare(currentSquare).reverse()) { + // add the node + if (node == gameObject) { + postSelect = listCounter; + } + listCounter++; + model.addElement(node); + + // if view-settings are applied, mark topmost "visible" tile for selection + if (mainControl.isTileEditSet() && !foundSIndex && mainControl.isTileEdit(node.getEditType())) { + sIndex = listCounter - 1; // select this tile + foundSIndex = true; // this is it - don't select any other tile + } + + final int tmpSelect = addInvObjects(node.getHead(), gameObject); + if (postSelect == -1 && tmpSelect != -1) { + postSelect = tmpSelect; + } + } + } + + if (postSelect != -1) { + list.setSelectedIndex(postSelect); + } else { + // Per default, the topmost arch matching the view settings is selected. + // (With no view settings applied, the very topmost arch is selected.) + list.setSelectedIndex(sIndex); + } + + // refresh the MapArchPanel to display the new arch + mainView.refreshMapArchPanel(); + + list.setEnabled(true); + } + + /** + * Add inventory objects to an arch in the MapTileList recursively. + * @param node the arch where the inventory gets added + * @param gameObject selected GameObject + * @return <code>-1</code> if <var>selArch</var> was found, else <var>listCounter</var> of the arch + */ + private int addInvObjects(final GameObject node, final GameObject gameObject) { + int selListCounter = -1; + for (final GameObject invObject : node.getHead()) { + if (invObject == gameObject) { + selListCounter = listCounter; + } + listCounter++; + model.addElement(invObject); + + final int tmpListCounter = addInvObjects(invObject, gameObject); + if (tmpListCounter != -1) { + selListCounter = tmpListCounter; + } + } + return selListCounter; + } + + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + if (e.getSource().isActive()) { + // Position changed + setMapTileList(mainControl.getCurrentMap(), null); + } else { + // Cursor was disabled + setMapTileList(null, null); + } + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + // A mode change can be ignored + } + + /** CellRenderer for rendering ArchObjects on a certain map tile in a list. */ + private final class MyCellRenderer extends DefaultListCellRenderer { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** {@inheritDoc} */ + @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + + GameObject arch = (GameObject) value; + + // arch == null should not happen, but it *can* happen when the active + // window gets changed by user and java is still blitting here + if (arch != null) { + arch = arch.getHead(); + + if (!arch.hasArchetype()) { + setIcon(CMainControl.getNoarchTileIcon()); + } else if (arch.getFaceFlag()) { + setIcon(CMainControl.getNofaceTileIcon()); + } else if (arch.getFaceNr() == -1) { + setIcon(CMainControl.getUnknownTileIcon()); + } else { + setIcon(mainControl.getFace(arch.getFaceNr())); + } + + // In the map-tile-window the object names are displayed + // next to the icons + if (arch.getObjName() != null && arch.getObjName().length() > 0) { + setText(arch.getObjName()); // special name + } else { + final String defname; + if (arch.hasArchetype()) { + defname = arch.getArchetype().getObjName(); + } else { + defname = null; + } + + if (defname != null && defname.length() > 0) { + setText(defname); // default name + } else { + setText(arch.getArchetypeName()); // arch name + } + } + } else { + setIcon(CMainControl.getUnknownTileIcon()); + setText("?"); + } + + int indent = 0; + for (;;) { + final GameObjectContainer<GameObject> env = arch.getContainer(); + if (env == null || !(env instanceof GameObject)) { + break; + } + arch = (GameObject) env; + indent++; + } + if (indent > 1) { + setBorder(BorderFactory.createEmptyBorder(0, (indent - 1) * 16, 0, 0)); // indentation + } + + return this; + } + + } // class MyCellRenderer + +} // class MapTileListControl Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -783,7 +783,7 @@ mainView.showArchPanelQuickObject(gameObject); } - boolean insertArchToMap(final GameObject newarch, final String archname, final GameObject next, final Point point) { + public boolean insertArchToMap(final GameObject newarch, final String archname, final GameObject next, final Point point) { return currentMap.getMapModel().insertArchToMap(newarch, archname, next, point); } @@ -1012,7 +1012,7 @@ level.levelCloseNotify(); } else { // Notify the level about the closing - mainView.getMapTileList().setMapTileList(null, null); + mainView.getMapTileListControl().setMapTileList(null, null); level.levelCloseNotify(); while (level.getMapViewFrame() != null) { level.closeView(level.getMapViewFrame()); Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -26,6 +26,7 @@ import daieditor.gameobject.GameObject; import daieditor.gui.AboutDialog; +import daieditor.gui.maptilelist.MapTileListControl; import daieditor.map.MapControl; import daieditor.map.validation.ErrorCollector; import daieditor.map.validation.ErrorHandler; @@ -141,7 +142,7 @@ private final List<MapViewIFrame> mapViews = synchronizedList(new ArrayList<MapViewIFrame>()); /** List of objects on map (right side). */ - private CMapTileList mapTileList; + private MapTileListControl mapTileListControl; /** Attributes panel (bottom). */ private CMapArchPanel mapArchPanel; @@ -219,16 +220,16 @@ statusBar = new CMainStatusbar(mainControl); archPanel = new CArchPanel(mainControl); - mapTileList = new CMapTileList(mainControl, this); + mapTileListControl = new MapTileListControl(mainControl, this); mapDesktop = new JDesktopPane(); mapArchPanel = new CMapArchPanel(mainControl, this); if (mapTileListBottom) { - splitRightPane = new GSplitPane(HORIZONTAL_SPLIT, mapArchPanel, mapTileList); + splitRightPane = new GSplitPane(HORIZONTAL_SPLIT, mapArchPanel, mapTileListControl); splitRightPane.setDividerLocation(divLocationRight); splitDownPane = new GSplitPane(VERTICAL_SPLIT, mapDesktop, splitRightPane); } else { - splitRightPane = new GSplitPane(HORIZONTAL_SPLIT, mapDesktop, mapTileList); + splitRightPane = new GSplitPane(HORIZONTAL_SPLIT, mapDesktop, mapTileListControl); splitRightPane.setDividerLocation(divLocationRight); splitDownPane = new GSplitPane(VERTICAL_SPLIT, splitRightPane, mapArchPanel); } @@ -351,21 +352,21 @@ } // show a arch in the arch map panel - void setMapArchPanelObject(final GameObject arch) { + public void setMapArchPanelObject(final GameObject arch) { mapArchPanel.setMapArchPanelObject(arch); } // access mape tile list ... public void setMapTileList(final MapControl map, final GameObject gameObject) { - mapTileList.setMapTileList(map, gameObject); + mapTileListControl.setMapTileList(map, gameObject); } public void refreshMapTileList() { - mapTileList.refresh(); + mapTileListControl.refresh(); } public GameObject getMapTileSelection() { - return mapTileList.getMapTileSelection(); + return mapTileListControl.getMapTileSelection(); } /** @@ -447,7 +448,7 @@ */ void refreshMenusAndToolbars() { archPanel.refresh(); - //mapTileList.refresh(); + //mapTileListControl.refresh(); mapArchPanel.refresh(); statusBar.refresh(); @@ -455,7 +456,7 @@ } /** Refresh the map arch panel (bottom window). */ - void refreshMapArchPanel() { + public void refreshMapArchPanel() { mapArchPanel.refresh(); } @@ -827,8 +828,8 @@ return statusBar; } - public CMapTileList getMapTileList() { - return mapTileList; + public MapTileListControl getMapTileListControl() { + return mapTileListControl; } /** {@inheritDoc} */ Deleted: trunk/daimonin/src/daieditor/CMapTileList.java =================================================================== --- trunk/daimonin/src/daieditor/CMapTileList.java 2006-12-22 22:24:55 UTC (rev 1218) +++ trunk/daimonin/src/daieditor/CMapTileList.java 2006-12-23 09:53:58 UTC (rev 1219) @@ -1,479 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * Copyright (C) 2005 Christian Hujer - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package daieditor; - -import daieditor.gameobject.GameObject; -import daieditor.map.MapControl; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.Point; -import java.awt.Rectangle; -import static java.awt.event.InputEvent.SHIFT_MASK; -import java.awt.event.MouseEvent; -import static java.awt.event.MouseEvent.BUTTON1; -import static java.awt.event.MouseEvent.BUTTON2; -import static java.awt.event.MouseEvent.BUTTON3; -import java.awt.event.MouseListener; -import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JViewport; -import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import net.sf.gridarta.map.MapSquare; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.swing.ActionMethod; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * The panel that displays the arches of the currently selected map square. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @todo turn this into a tree - */ -public final class CMapTileList extends JPanel implements ListSelectionListener, MouseListener, MapCursorListener { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final CMainView mainView; - - /** The "Import..." button. */ - private final JList list; - - private final DefaultListModel model; - - private int listCounter = 0; - - /** The currently selected MapSquare. */ - private transient MapSquare<GameObject> currentSquare; - - /** - * Create a CMapTileList. - * @param mainControl MainControl, used for icons - * @param mainView MainView, used for updating UI - */ - public CMapTileList(final CMainControl mainControl, final CMainView mainView) { - this.mainControl = mainControl; - this.mainView = mainView; - setLayout(new BorderLayout()); - - model = new DefaultListModel(); - list = new JList(model); - list.setCellRenderer(new MyCellRenderer()); - list.setBackground(Color.lightGray); - final JScrollPane scrollPane = new JScrollPane(list); - scrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - add(scrollPane, BorderLayout.CENTER); - - final JPanel arrows = new JPanel(); - if (mainView.isMapTileListBottom()) { - arrows.setLayout(new GridLayout(4, 1)); - add(arrows, BorderLayout.WEST); // put up/down buttons west - } else { - add(arrows, BorderLayout.SOUTH); // put up/down buttons south - } - for (final String keyPostfix : new String[] { "Top", "Up", "Down", "Bottom" }) { - final JButton button = new JButton(ACTION_FACTORY.createAction(true, "moveTile" + keyPostfix, this)); - arrows.add(button); - button.setMargin(new Insets(0, 0, 0, 0)); - } - final JPanel compass = new JPanel(); - compass.add(new JLabel(CGUIUtils.getSysIcon(IGUIConstants.TILE_NORTH))); - add(compass, BorderLayout.NORTH); - list.addListSelectionListener(this); - list.addMouseListener(this); - list.setFocusable(false); // XXX Workaround for Mantis #0000154 This is not clean and should be removed as soon as cut/copy/paste of arches is possible - } - - /** {@inheritDoc} */ - public void valueChanged(final ListSelectionEvent e) { - mainView.setMapArchPanelObject(getMapTileSelection()); - } - - /** - * Action method for moving an arch topmost within its tile. - */ - @ActionMethod public void moveTileTop() { - final GameObject arch = getMapTileSelection(); - if (arch != null) { - arch.moveTop(); - } - refresh(); - } - - /** - * Action method for moving an arch up within its tile. - */ - @ActionMethod public void moveTileUp() { - final GameObject arch = getMapTileSelection(); - if (arch != null) { - arch.moveUp(); - } - refresh(); - } - - /** - * Action method for moving an arch down within its tile. - */ - @ActionMethod public void moveTileDown() { - final GameObject a... [truncated message content] |