From: <aki...@us...> - 2006-12-24 11:59:10
|
Revision: 1266 http://svn.sourceforge.net/gridarta/?rev=1266&view=rev Author: akirschbaum Date: 2006-12-24 03:59:06 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Make connection view highlight affected game objects in the map view. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/daimonin/src/daieditor/CMapArchPanel.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/connectionview/ trunk/src/app/net/sf/gridarta/gui/connectionview/Connection.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gui/ConnectionControl.java trunk/src/app/net/sf/gridarta/gui/ConnectionView.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-24 11:53:19 UTC (rev 1265) +++ trunk/crossfire/ChangeLog 2006-12-24 11:59:06 UTC (rev 1266) @@ -1,5 +1,8 @@ 2006-12-24 Andreas Kirschbaum + * Make connection view highlight affected game objects in the map + view. + * Add some French and Svedish translations. * Update main window title. Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-24 11:53:19 UTC (rev 1265) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -56,7 +56,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; -import net.sf.gridarta.gui.ConnectionControl; +import net.sf.gridarta.gui.connectionview.ConnectionControl; import net.sf.gridarta.gui.GSplitPane; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; Modified: trunk/daimonin/src/daieditor/CMapArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-12-24 11:53:19 UTC (rev 1265) +++ trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -61,7 +61,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; -import net.sf.gridarta.gui.ConnectionControl; +import net.sf.gridarta.gui.connectionview.ConnectionControl; import net.sf.gridarta.gui.GSplitPane; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; Deleted: trunk/src/app/net/sf/gridarta/gui/ConnectionControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/ConnectionControl.java 2006-12-24 11:53:19 UTC (rev 1265) +++ trunk/src/app/net/sf/gridarta/gui/ConnectionControl.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -1,58 +0,0 @@ -/* - * Gridarta Java Editor. - * Copyright (C) 2006 The Gridarta Developers - * - * 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 net.sf.gridarta.gui; - -import net.sf.gridarta.MainControl; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -/** - * The controller for the connection view. - * - * @author Andreas Kirschbaum - */ -public class ConnectionControl { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ConnectionControl.class); - - /** The view for this controller. */ - @NotNull private final ConnectionView view; - - /* - * Create a new instance. - * - * @param mainControl the main control to use - */ - public ConnectionControl(@NotNull final MainControl mainControl) { - view = new ConnectionView(mainControl); - } - - /** - * Return the view for this controller. - * - * @return the view for this controller - */ - @NotNull public ConnectionView getView() { - return view; - } - -} // class ConnectionControl Deleted: trunk/src/app/net/sf/gridarta/gui/ConnectionView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/ConnectionView.java 2006-12-24 11:53:19 UTC (rev 1265) +++ trunk/src/app/net/sf/gridarta/gui/ConnectionView.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -1,129 +0,0 @@ -/* - * Gridarta Java Editor. - * Copyright (C) 2005 Christian Hujer - * Copyright (C) 2006 The Gridarta Developers - * - * 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 net.sf.gridarta.gui; - -import java.awt.BorderLayout; -import java.util.ArrayList; -import java.util.TreeMap; -import java.util.List; -import java.util.Map; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import net.sf.gridarta.MainControl; -import net.sf.gridarta.MainControlListener; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.map.MapArchObject; -import net.sf.gridarta.map.MapControl; -import net.sf.gridarta.map.MapModel; -import net.sf.gridarta.map.MapModelEvent; -import net.sf.gridarta.map.MapModelListener; -import net.sf.gridarta.map.MapSquare; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * A Panel that holds information about the connections of the selected arch on the selected map. - * It is unfinished. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @author Andreas Kirschbaum - * @todo more user interface features - * @todo make this a MapHighlightModel - * @todo better react on changes, don't always scan the whole map - * @todo attach - * @serial exclude - */ -public final class ConnectionView extends JPanel implements MainControlListener, MapModelListener { - - /** The conections. */ - private final Map<Integer, List<GameObject>> connections = new TreeMap<Integer, List<GameObject>>(); - - /** The List with the connections. */ - private JList connectionList = new JList(); - - /** Map control corresponding to {@link #connectionList}. */ - private MapControl mapControl = null; - - /** Create a ConnectionPanel. */ - public ConnectionView(@NotNull final MainControl mainControl) { - setLayout(new BorderLayout()); - add(new JScrollPane(connectionList)); - mainControl.addMainControlListener(this); - } - - /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent e) { - scanMapForConnections(e.getMapModel()); - } - - /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent e) { - scanMapForConnections(e.getMapModel()); - } - - /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent e) { - scanMapForConnections(e.getMapModel()); - } - - /** {@inheritDoc} */ - public void currentMapChanged(@Nullable final MapControl mapControl) { - this.mapControl = mapControl; - scanMapForConnections(mapControl == null ? null : mapControl.getMapModel()); - } - - /** {@inheritDoc} */ - public void mapCreated(@NotNull final MapControl mapControl) { - mapControl.getMapModel().addMapModelListener(this); - } - - /** {@inheritDoc} */ - public void mapClosing(@NotNull final MapControl mapControl) { - mapControl.getMapModel().removeMapModelListener(this); - } - - /** - * Scans a map for the contained connections. - * @param model Model of map to scan - */ - public void scanMapForConnections(final MapModel model) { - connections.clear(); - if (model != null && mapControl != null && mapControl.getMapModel() == model) { - for (final MapSquare<? extends GameObject> mapSquare : (MapModel<? extends GameObject, MapArchObject>) model) { - for (final GameObject archObject : mapSquare) { - final String connectionSpec = archObject.getAttributeString("connected", false); - if (connectionSpec != null && connectionSpec.matches("\\d+(, *\\d+)*")) { - for (String s : connectionSpec.trim().split(",\\s*")) { - final Integer connection = Integer.valueOf(s); - if (!connections.containsKey(connection)) { - connections.put(connection, new ArrayList<GameObject>()); - } - connections.get(connection).add(archObject); - } - } - } - } - } - connectionList.setListData(connections.keySet().toArray()); - } - -} // class ConnectionView Added: trunk/src/app/net/sf/gridarta/gui/connectionview/Connection.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/Connection.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/Connection.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -0,0 +1,90 @@ +/* + * Gridarta Java Editor. + * Copyright (C) 2006 The Gridarta Developers + * + * 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 net.sf.gridarta.gui.connectionview; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import net.sf.gridarta.gameobject.GameObject; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +/** + * The class <code>Connection</code> stores information for a single connected + * value (connection number). + * + * @author Andreas Kirschbaum + */ +public class Connection implements Iterable<GameObject> { + + /** The Logger for printing log messages. */ + private static final Logger _log = Logger.getLogger(Connection.class); + + /** + * The connection number. + */ + private final int connectionNumber; + + /** + * The game objects for this connection. + * + * @note a list is used to allow accessing the game objects by index + * + * @note the initial capacity of 2 assumes that most connection values have + * only two game objects: the triggering object and the triggered object + */ + private final ArrayList<GameObject> gameObjects = new ArrayList<GameObject>(2); + + /** + * Create a new instance. + * + * @param connectionNumber the connection number + */ + public Connection(final int connectionNumber) { + this.connectionNumber = connectionNumber; + } + + /** + * Return the connection number. + * + * @return the connection number + */ + public int getConnectionNumber() { + return connectionNumber; + } + + /** + * Add a game object. + * + * @param gameObject the game object to add + */ + public void addGameObject(@NotNull final GameObject gameObject) { + if (!gameObjects.contains(gameObject)) { + gameObjects.add(gameObject); + } + } + + /** {@inheritDoc} */ + public Iterator<GameObject> iterator() { + return Collections.unmodifiableList(gameObjects).iterator(); + } + +} // class Connection Property changes on: trunk/src/app/net/sf/gridarta/gui/connectionview/Connection.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Copied: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java (from rev 1264, trunk/src/app/net/sf/gridarta/gui/ConnectionControl.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -0,0 +1,95 @@ +/* + * Gridarta Java Editor. + * Copyright (C) 2006 The Gridarta Developers + * + * 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 net.sf.gridarta.gui.connectionview; + +import java.awt.Point; +import java.util.List; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import net.sf.gridarta.MainControl; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.map.MapControl; +import net.sf.gridarta.map.MapModel; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +/** + * The controller for the connection view. + * + * @author Andreas Kirschbaum + */ +public class ConnectionControl { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ConnectionControl.class); + + /** The view for this controller. */ + @NotNull private final ConnectionView view; + + /* + * Create a new instance. + * + * @param mainControl the main control to use + */ + public ConnectionControl(@NotNull final MainControl mainControl) { + view = new ConnectionView(mainControl); + + view.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(final ListSelectionEvent e) { + highlightSelectedEntries(); + } + }); + } + + /** + * Return the view for this controller. + * + * @return the view for this controller + */ + @NotNull public ConnectionView getView() { + return view; + } + + /** + * Set the map selection to the currently selected entries. + */ + private void highlightSelectedEntries() { + final MapControl mapControl = view.getMapControl(); + if (mapControl == null) { + return; + } + + final MapGrid mapGrid = mapControl.getMapGrid(); + mapGrid.unSelect(); + + final Point point = new Point(); + + final List<Connection> connections = view.getSelectedConnections(); + for (final Connection connection : connections) { + for (final GameObject object : connection) { + point.setLocation(object.getMapX(), object.getMapY()); + mapGrid.select(point, point, MapGrid.SelectionMode.ADD); + } + } + } + +} // class ConnectionControl Copied: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java (from rev 1264, trunk/src/app/net/sf/gridarta/gui/ConnectionView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2006-12-24 11:59:06 UTC (rev 1266) @@ -0,0 +1,192 @@ +/* + * Gridarta Java Editor. + * Copyright (C) 2005 Christian Hujer + * Copyright (C) 2006 The Gridarta Developers + * + * 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 net.sf.gridarta.gui.connectionview; + +import java.awt.BorderLayout; +import java.util.ArrayList; +import java.util.TreeMap; +import java.util.List; +import java.util.Map; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.event.ListSelectionListener; +import net.sf.gridarta.MainControl; +import net.sf.gridarta.MainControlListener; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapControl; +import net.sf.gridarta.map.MapModel; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; +import net.sf.gridarta.map.MapSquare; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A Panel that holds information about the connections of the selected arch on the selected map. + * It is unfinished. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum + * @todo more user interface features + * @todo make this a MapHighlightModel + * @todo better react on changes, don't always scan the whole map + * @todo attach + * @serial exclude + */ +public final class ConnectionView extends JPanel implements MainControlListener, MapModelListener { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ConnectionControl.class); + + /** The connections. */ + private final Map<Integer, Connection> connections = new TreeMap<Integer, Connection>(); + + /** The List with the connections. */ + private JList connectionList = new JList(); + + /** Map control corresponding to {@link #connectionList}. */ + private MapControl mapControl = null; + + /** Create a ConnectionPanel. */ + public ConnectionView(@NotNull final MainControl mainControl) { + setLayout(new BorderLayout()); + add(new JScrollPane(connectionList)); + mainControl.addMainControlListener(this); + } + + /** + * Return the current map control. + * + * @return the current map control, or <code>null</code> if none is + * available + */ + @Nullable public MapControl getMapControl() { + return mapControl; + } + + /** + * Register a {@link ListSelectionListener} for the connection list. + * + * @param listener the listener to register + */ + void addListSelectionListener(@NotNull final ListSelectionListener listener) { + connectionList.addListSelectionListener(listener); + } + + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent e) { + if (mapControl == null || e.getMapModel() != mapControl.getMapModel()) { + return; + } + + scanMapForConnections(); + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent e) { + if (mapControl == null || e.getMapModel() != mapControl.getMapModel()) { + return; + } + + scanMapForConnections(); + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent e) { + if (mapControl == null || e.getMapModel() != mapControl.getMapModel()) { + return; + } + + scanMapForConnections(); + } + + /** {@inheritDoc} */ + public void currentMapChanged(@Nullable final MapControl mapControl) { + this.mapControl = mapControl; + scanMapForConnections(); + } + + /** {@inheritDoc} */ + public void mapCreated(@NotNull final MapControl mapControl) { + mapControl.getMapModel().addMapModelListener(this); + } + + /** {@inheritDoc} */ + public void mapClosing(@NotNull final MapControl mapControl) { + mapControl.getMapModel().removeMapModelListener(this); + } + + /** + * Scans the current map ({@link #mapControl}) for the contained + * connections. + */ + public void scanMapForConnections() { + connections.clear(); + if (mapControl != null) { + scanMapForConnections(mapControl.getMapModel()); + } + connectionList.setListData(connections.keySet().toArray()); + } + + /** + * Scans the given map for the contained connections. + * + * @param mapModel the map model to process + */ + public void scanMapForConnections(@NotNull final MapModel mapModel) { + for (final MapSquare<? extends GameObject> mapSquare : (MapModel<? extends GameObject, MapArchObject>) mapModel) { + for (final GameObject gameObject : mapSquare) { + final String connectionSpec = gameObject.getAttributeString("connected", false); + if (connectionSpec != null && connectionSpec.matches("\\d+(, *\\d+)*")) { + for (String s : connectionSpec.trim().split(",\\s*")) { + final Integer connectionNumber = Integer.valueOf(s); + if (!connections.containsKey(connectionNumber)) { + connections.put(connectionNumber, new Connection(connectionNumber)); + } + connections.get(connectionNumber).addGameObject(gameObject); + } + } + } + } + } + + /** + * Return a list of all selected connections. + * + * @return a list of all selected connections + */ + public List<Connection> getSelectedConnections() { + final ArrayList<Connection> result = new ArrayList<Connection>(); + for (final Object selection : connectionList.getSelectedValues()) { + final Connection connection = connections.get((Integer) selection); + if (connection == null) { + log.warn("getSelectedConnections: cannot find connection number " + selection); + } else { + result.add(connection); + } + } + return result; + } + +} // class ConnectionView This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-24 12:25:41
|
Revision: 1267 http://svn.sourceforge.net/gridarta/?rev=1267&view=rev Author: akirschbaum Date: 2006-12-24 04:25:41 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Add affected game object names to connection view. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-24 11:59:06 UTC (rev 1266) +++ trunk/crossfire/ChangeLog 2006-12-24 12:25:41 UTC (rev 1267) @@ -1,5 +1,7 @@ 2006-12-24 Andreas Kirschbaum + * Add affected game object names to connection view. + * Make connection view highlight affected game objects in the map view. Added: trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java 2006-12-24 12:25:41 UTC (rev 1267) @@ -0,0 +1,70 @@ +/* + * Gridarta Java Editor. + * 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 net.sf.gridarta.gui.connectionview; + +import net.sf.gridarta.gameobject.GameObject; +import java.awt.Component; +import java.util.TreeSet; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; + +/** + * CellRenderer for rendering Connection objects in a list. + * + * @author Andreas Kirschbaum + */ +public final class CellRenderer extends DefaultListCellRenderer { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** The StringBuilder used to format entries. */ + private final StringBuilder sb = new StringBuilder(); + + /** Used for sorting game object names. */ + private final TreeSet<String> names = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); + + /** {@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); + + final Connection connection = (Connection) value; + + sb.setLength(0); + sb.append(connection.getConnectionNumber()); + sb.append(":"); + + names.clear(); + for (final GameObject gameObject : connection) { + names.add(gameObject.getBestName()); + } + for (final String name : names) { + sb.append(" "); + sb.append(name); + } + setText(sb.toString()); + + return this; + } + +} // class CellRenderer Property changes on: trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2006-12-24 11:59:06 UTC (rev 1266) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2006-12-24 12:25:41 UTC (rev 1267) @@ -71,6 +71,7 @@ /** Create a ConnectionPanel. */ public ConnectionView(@NotNull final MainControl mainControl) { setLayout(new BorderLayout()); + connectionList.setCellRenderer(new CellRenderer()); add(new JScrollPane(connectionList)); mainControl.addMainControlListener(this); } @@ -146,7 +147,7 @@ if (mapControl != null) { scanMapForConnections(mapControl.getMapModel()); } - connectionList.setListData(connections.keySet().toArray()); + connectionList.setListData(connections.values().toArray()); } /** @@ -179,12 +180,7 @@ public List<Connection> getSelectedConnections() { final ArrayList<Connection> result = new ArrayList<Connection>(); for (final Object selection : connectionList.getSelectedValues()) { - final Connection connection = connections.get((Integer) selection); - if (connection == null) { - log.warn("getSelectedConnections: cannot find connection number " + selection); - } else { - result.add(connection); - } + result.add((Connection) selection); } return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-24 14:25:49
|
Revision: 1270 http://svn.sourceforge.net/gridarta/?rev=1270&view=rev Author: christianhujer Date: 2006-12-24 06:25:46 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Improved event handling code regarding EventListenerList usage. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/filter/BasicFilterConfig.java trunk/crossfire/src/cfeditor/filter/NamedFilterList.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gui/map/MapViewSettings.java trunk/src/app/net/sf/gridarta/gui/map/MapCursor.java trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -1519,12 +1519,8 @@ * @param mapControl the created map */ private void fireMapCreatedEvent(@NotNull final MapControl mapControl) { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MainControlListener.class) { - ((MainControlListener) listeners[i + 1]).mapCreated(mapControl); - } + for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + listener.mapCreated(mapControl); } } @@ -1533,12 +1529,8 @@ * @param mapControl MapControl that's being closed. */ private void fireMapClosingEvent(@NotNull final MapControl mapControl) { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MainControlListener.class) { - ((MainControlListener) listeners[i + 1]).mapClosing(mapControl); - } + for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + listener.mapClosing(mapControl); } } @@ -1546,12 +1538,8 @@ * Notify all listeners about a changed current map. */ private void fireCurrentMapChangedEvent() { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MainControlListener.class) { - ((MainControlListener) listeners[i + 1]).currentMapChanged(currentMap); - } + for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + listener.currentMapChanged(currentMap); } } Modified: trunk/crossfire/src/cfeditor/filter/BasicFilterConfig.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/BasicFilterConfig.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/crossfire/src/cfeditor/filter/BasicFilterConfig.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -50,12 +50,8 @@ } protected void fireEvent(final ConfigEvent e) { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == ConfigListener.class) { - ((ConfigListener) listeners[i + 1]).configChanged(e); - } + for (final ConfigListener listener : listenerList.getListeners(ConfigListener.class)) { + listener.configChanged(e); } } Modified: trunk/crossfire/src/cfeditor/filter/NamedFilterList.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/NamedFilterList.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/crossfire/src/cfeditor/filter/NamedFilterList.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -205,12 +205,8 @@ } private void fireEvent(final NamedFilterEvent event) { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == NamedFilterListener.class) { - ((NamedFilterListener) listeners[i + 1]).nameFilterChanged(event); - } + for (final NamedFilterListener listener : listenerList.getListeners(NamedFilterListener.class)) { + listener.nameFilterChanged(event); } } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -1711,12 +1711,8 @@ * @param mapControl the created map */ private void fireMapCreatedEvent(@NotNull final MapControl mapControl) { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MainControlListener.class) { - ((MainControlListener) listeners[i + 1]).mapCreated(mapControl); - } + for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + listener.mapCreated(mapControl); } } @@ -1725,12 +1721,8 @@ * @param mapControl MapControl that's being closed. */ private void fireMapClosingEvent(@NotNull final MapControl mapControl) { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MainControlListener.class) { - ((MainControlListener) listeners[i + 1]).mapClosing(mapControl); - } + for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + listener.mapClosing(mapControl); } } @@ -1738,12 +1730,8 @@ * Notify all listeners about a changed current map. */ private void fireCurrentMapChangedEvent() { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MainControlListener.class) { - ((MainControlListener) listeners[i + 1]).currentMapChanged(currentMap); - } + for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + listener.currentMapChanged(currentMap); } } Modified: trunk/daimonin/src/daieditor/gui/map/MapViewSettings.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapViewSettings.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/daimonin/src/daieditor/gui/map/MapViewSettings.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -73,12 +73,8 @@ /** Inform all registered listeners that the settings have changed. */ protected void fireSettingsChangedEvent() { final MapViewSettingsEvent e = new MapViewSettingsEvent(this); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MapViewSettingsListener.class) { - ((MapViewSettingsListener) listeners[i + 1]).mapViewSettingsChanged(e); - } + for (final MapViewSettingsListener listener : listenerList.getListeners(MapViewSettingsListener.class)) { + listener.mapViewSettingsChanged(e); } } Modified: trunk/src/app/net/sf/gridarta/gui/map/MapCursor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapCursor.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/src/app/net/sf/gridarta/gui/map/MapCursor.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -307,24 +307,16 @@ /** Inform all registered listeners that the MapCursor's mode has changed. */ private void fireMapCursorChangedModeEvent() { final MapCursorEvent e = new MapCursorEvent(this); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MapCursorListener.class) { - ((MapCursorListener) listeners[i + 1]).mapCursorChangedMode(e); - } + for (final MapCursorListener listener : listenerList.getListeners(MapCursorListener.class)) { + listener.mapCursorChangedMode(e); } } /** Inform all registered listeners that the MapCursor's position has changed. */ private void fireMapCursorChangedPosEvent() { final MapCursorEvent e = new MapCursorEvent(this); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MapCursorListener.class) { - ((MapCursorListener) listeners[i + 1]).mapCursorChangedPos(e); - } + for (final MapCursorListener listener : listenerList.getListeners(MapCursorListener.class)) { + listener.mapCursorChangedPos(e); } } Modified: trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -149,24 +149,16 @@ /** Inform all registered listeners that the flags on MapGrid have changed. */ private void fireMapGridChangedEvent() { final MapGridEvent e = new MapGridEvent(this); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MapGridListener.class) { - ((MapGridListener) listeners[i + 1]).mapGridChanged(e); - } + for (final MapGridListener listener : listenerList.getListeners(MapGridListener.class)) { + listener.mapGridChanged(e); } } /** Inform all registered listeners that the size of MapGrid has changed. */ private void fireMapGridResizeEvent() { final MapGridEvent e = new MapGridEvent(this); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - //noinspection ObjectEquality - if (listeners[i] == MapGridListener.class) { - ((MapGridListener) listeners[i + 1]).mapGridResized(e); - } + for (final MapGridListener listener : listenerList.getListeners(MapGridListener.class)) { + listener.mapGridResized(e); } } Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -272,26 +272,16 @@ */ private void fireMapSquaresChangedEvent(final MapSquare<G>... squares) { final MapModelEvent<G> e = new MapModelEvent<G>(this, MapModelEvent.Type.SQUARES_CHANGED, squares); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - // Using == is okay for listener classes. - //noinspection ObjectEquality - if (listeners[i] == MapModelListener.class) { - ((MapModelListener<G>) listeners[i + 1]).mapSquaresChanged(e); - } + for (final MapModelListener listener : listenerList.getListeners(MapModelListener.class)) { + listener.mapSquaresChanged(e); } } /** Fire a map size changed event. */ private void fireMapSizeChanged() { final MapModelEvent<G> e = new MapModelEvent<G>(this, MapModelEvent.Type.SIZE_CHANGED); - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - // Using == is okay for listener classes. - //noinspection ObjectEquality - if (listeners[i] == MapModelListener.class) { - ((MapModelListener<G>) listeners[i + 1]).mapSizeChanged(e); - } + for (final MapModelListener listener : listenerList.getListeners(MapModelListener.class)) { + listener.mapSizeChanged(e); } } Modified: trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2006-12-24 13:49:28 UTC (rev 1269) +++ trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2006-12-24 14:25:46 UTC (rev 1270) @@ -1506,11 +1506,8 @@ boolean rectSelect; void fireCaretEvent() { - final Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i--) { - if (listeners[i] == CaretListener.class) { - ((CaretListener) listeners[i + 1]).caretUpdate(caretEvent); - } + for (final CaretListener listener : listenerList.getListeners(CaretListener.class)) { + listener.caretUpdate(caretEvent); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-24 15:21:18
|
Revision: 1272 http://svn.sourceforge.net/gridarta/?rev=1272&view=rev Author: christianhujer Date: 2006-12-24 07:21:15 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Optimized imports. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CMapArchPanel.java trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListControl.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -43,12 +43,12 @@ import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * This class handles all the CFArchTypes and makes them conveniently Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -59,8 +59,8 @@ import javax.swing.tree.TreePath; import net.sf.gridarta.help.Help; import net.sf.gridarta.io.IOUtils; +import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.EnumerationIterator; -import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -56,8 +56,8 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.gui.GSplitPane; import net.sf.gridarta.gui.connectionview.ConnectionControl; -import net.sf.gridarta.gui.GSplitPane; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; Modified: trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -41,12 +41,12 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; +import static javax.swing.JViewport.SIMPLE_SCROLL_MODE; import javax.swing.ListSelectionModel; 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 static javax.swing.JViewport.SIMPLE_SCROLL_MODE; import net.sf.gridarta.MainControlListener; import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -44,12 +44,12 @@ import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * This class handles all the CFArchTypes and makes them conveniently Modified: trunk/daimonin/src/daieditor/CMapArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -61,8 +61,8 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.gui.GSplitPane; import net.sf.gridarta.gui.connectionview.ConnectionControl; -import net.sf.gridarta.gui.GSplitPane; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; Modified: trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListControl.java =================================================================== --- trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListControl.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListControl.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -26,10 +26,10 @@ package daieditor.gui.maptilelist; -import daieditor.CopyBuffer; import daieditor.CMainControl; import daieditor.CMainView; import daieditor.CPickmapPanel; +import daieditor.CopyBuffer; import daieditor.gameobject.GameObject; import daieditor.map.MapControl; import java.awt.Point; Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -54,8 +54,8 @@ import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * The <code>MapControl</code>. Modified: trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -29,6 +29,7 @@ import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import org.jetbrains.annotations.NotNull; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -38,7 +39,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.jetbrains.annotations.NotNull; /** * Unit test for {@link MapCursor}. Modified: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -1,11 +1,11 @@ package net.sf.gridarta.gameobject; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.List; -import java.util.ArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/CellRenderer.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -22,11 +22,11 @@ package net.sf.gridarta.gui.connectionview; -import net.sf.gridarta.gameobject.GameObject; import java.awt.Component; import java.util.TreeSet; import javax.swing.DefaultListCellRenderer; import javax.swing.JList; +import net.sf.gridarta.gameobject.GameObject; /** * CellRenderer for rendering Connection objects in a list. Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -28,7 +28,6 @@ import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.gui.map.MapGrid; import net.sf.gridarta.map.MapControl; -import net.sf.gridarta.map.MapModel; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -23,9 +23,9 @@ import java.awt.BorderLayout; import java.util.ArrayList; -import java.util.TreeMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; Modified: trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -37,8 +37,8 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTabbedPane; +import javax.swing.SwingConstants; import javax.swing.WindowConstants; -import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.BadLocationException; Modified: trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2006-12-24 15:13:13 UTC (rev 1271) +++ trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2006-12-24 15:21:15 UTC (rev 1272) @@ -10,6 +10,7 @@ package net.sf.gridarta.textedit.textarea; import java.awt.AWTEvent; +import java.awt.Adjustable; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; @@ -17,7 +18,6 @@ import java.awt.FontMetrics; import java.awt.Insets; import java.awt.LayoutManager; -import java.awt.Adjustable; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-24 15:29:43
|
Revision: 1273 http://svn.sourceforge.net/gridarta/?rev=1273&view=rev Author: christianhujer Date: 2006-12-24 07:29:42 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Solved some todos. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/Archetype.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java trunk/src/app/net/sf/gridarta/map/MapModelEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-12-24 15:21:15 UTC (rev 1272) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-12-24 15:29:42 UTC (rev 1273) @@ -478,7 +478,7 @@ } /** {@inheritDoc} */ - public String getAnimName() { + @Nullable public String getAnimName() { return null; } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-12-24 15:21:15 UTC (rev 1272) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-12-24 15:29:42 UTC (rev 1273) @@ -637,7 +637,7 @@ * Returns object animation <code>animation <var>animName</var></code>. * @return object animation <code>animation <var>animName</var></code> */ - public String getAnimName() { + @Nullable public String getAnimName() { return animName; } Modified: trunk/src/app/net/sf/gridarta/gameobject/Archetype.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/Archetype.java 2006-12-24 15:21:15 UTC (rev 1272) +++ trunk/src/app/net/sf/gridarta/gameobject/Archetype.java 2006-12-24 15:29:42 UTC (rev 1273) @@ -147,9 +147,8 @@ * DaiEditor only: Returns the name of the animation. * @return The name of the animation. * @deprecated compatibility method - * @todo document nullability */ - @Deprecated String getAnimName(); + @Deprecated @Nullable String getAnimName(); /** * Returns the object text of this Archetype as String. Modified: trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java 2006-12-24 15:21:15 UTC (rev 1272) +++ trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java 2006-12-24 15:29:42 UTC (rev 1273) @@ -63,10 +63,9 @@ void parseArchetypeFromStream(BufferedReader in, @NotNull String panelName, @NotNull String folderName, String fname) throws IOException; /** - * I drop this here ... we got 2 functions now but i want the hardcore parsing - * cut off from load parsing + * Does some parsing on archetypes after they've been read. + * It reads the object text, parses it and resets it. * @param archetype archetype to be parsed - * @todo improve this stupid comment */ void postParseArchetype(G archetype); Modified: trunk/src/app/net/sf/gridarta/map/MapModelEvent.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModelEvent.java 2006-12-24 15:21:15 UTC (rev 1272) +++ trunk/src/app/net/sf/gridarta/map/MapModelEvent.java 2006-12-24 15:29:42 UTC (rev 1273) @@ -35,7 +35,6 @@ * Class for Map events. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @note for speed all arrays are used as is, they are not cloned. This applies to the constructor arguments as well as the getter return arguments. - * @todo to improve speed, the event should also be capable of reporting the changed GameObjects * @todo think about an intelligent way to detect whether repainting is required * @serial exclude */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-25 15:03:12
|
Revision: 1274 http://svn.sourceforge.net/gridarta/?rev=1274&view=rev Author: christianhujer Date: 2006-12-25 07:03:10 -0800 (Mon, 25 Dec 2006) Log Message: ----------- Cosmetic: Added missing and fixed wrong end of class comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CGUIUtils.java trunk/crossfire/src/cfeditor/CResourceLoader.java trunk/crossfire/src/cfeditor/CScriptController.java trunk/crossfire/src/cfeditor/CScriptModel.java trunk/crossfire/src/cfeditor/CScriptView.java trunk/crossfire/src/cfeditor/CSettings.java trunk/crossfire/src/cfeditor/JarResources.java trunk/crossfire/src/cfeditor/PluginParameter.java trunk/crossfire/src/cfeditor/PluginParameterFactory.java trunk/crossfire/src/cfeditor/PluginParameterView.java trunk/crossfire/src/cfeditor/gui/ArchComboBox.java trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java trunk/crossfire/src/cfeditor/gui/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/ScriptManager.java trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java trunk/crossfire/src/cfeditor/menu/MenuChangeEvent.java trunk/crossfire/src/cfeditor/menu/MenuEntry.java trunk/crossfire/src/cfeditor/menu/MenuListener.java trunk/crossfire/src/cfeditor/menu/MenuLocation.java trunk/crossfire/src/cfeditor/menu/MenuManager.java trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java trunk/crossfire/src/cfeditor/parameter/ArchParameter.java trunk/crossfire/src/cfeditor/parameter/ArchParameterView.java trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java trunk/crossfire/src/cfeditor/parameter/BooleanParameterView.java trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java trunk/crossfire/src/cfeditor/parameter/FilterParameter.java trunk/crossfire/src/cfeditor/parameter/FilterParameterView.java trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java trunk/crossfire/src/cfeditor/parameter/MapParameter.java trunk/crossfire/src/cfeditor/parameter/MapParameterView.java trunk/crossfire/src/cfeditor/parameter/ParameterDescriptionEditor.java trunk/crossfire/src/cfeditor/parameter/ParameterNameEditor.java trunk/crossfire/src/cfeditor/parameter/ParameterTypeEditor.java trunk/crossfire/src/cfeditor/parameter/StringParameter.java trunk/crossfire/src/cfeditor/parameter/StringParameterView.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java trunk/daimonin/src/daieditor/gameobject/match/AttribGameObjectMatcher.java trunk/daimonin/src/daieditor/gui/map/MapTilePane.java trunk/daimonin/src/daieditor/gui/map/MapUserListener.java trunk/daimonin/src/daieditor/gui/map/event/MouseOpEvent.java trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java trunk/daimonin/src/daieditor/map/validation/checks/MapDifficultyChecker.java trunk/daimonin/src/daieditor/map/validation/checks/SlayingError.java trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java trunk/gridarta.ipr trunk/src/app/net/sf/gridarta/MainControlListener.java trunk/src/app/net/sf/gridarta/gameobject/NamedObjects.java trunk/src/app/net/sf/gridarta/gui/GSplitPane.java trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelection.java trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java trunk/src/app/net/sf/gridarta/help/Help.java trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java trunk/src/app/net/sf/gridarta/io/MapReader.java trunk/src/app/net/sf/gridarta/io/MapWriter.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/CFPythonPopup.java trunk/src/app/net/sf/gridarta/textedit/textarea/CTokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/JavaScriptTokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/PythonTokenMarker.java Modified: trunk/crossfire/src/cfeditor/CGUIUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/CGUIUtils.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/CGUIUtils.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -185,6 +185,6 @@ //noinspection PointlessBitwiseExpression return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0); } - } + } // class CGrayScaleFilter } // class CGUIUtils Modified: trunk/crossfire/src/cfeditor/CResourceLoader.java =================================================================== --- trunk/crossfire/src/cfeditor/CResourceLoader.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/CResourceLoader.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -274,4 +274,5 @@ } return mainDoc; } -} + +} // class CResourceLoader Modified: trunk/crossfire/src/cfeditor/CScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptController.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/CScriptController.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -341,4 +341,5 @@ unRegister(name); register(name); } -} + +} // class CScriptController Modified: trunk/crossfire/src/cfeditor/CScriptModel.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptModel.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/CScriptModel.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -471,4 +471,5 @@ final int index = params.indexOf(param); convertType(index, newType); } -} + +} // class CScriptModel Modified: trunk/crossfire/src/cfeditor/CScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/CScriptView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -259,4 +259,5 @@ } return false; } -} + +} // class CScriptView Modified: trunk/crossfire/src/cfeditor/CSettings.java =================================================================== --- trunk/crossfire/src/cfeditor/CSettings.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/CSettings.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -160,4 +160,5 @@ public synchronized void clearProperty(final String strKey) { properties.remove(strKey); } -} + +} // class CSettings Modified: trunk/crossfire/src/cfeditor/JarResources.java =================================================================== --- trunk/crossfire/src/cfeditor/JarResources.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/JarResources.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -219,4 +219,5 @@ log.info("Found " + args[1] + " (length=" + buff.length + ")."); } } -} + +} // class JarResources Modified: trunk/crossfire/src/cfeditor/PluginParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/PluginParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/PluginParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -114,4 +114,5 @@ @Override public Object clone() throws CloneNotSupportedException { return PluginParameterFactory.createParameter(toXML()); } -} + +} // class PluginParameter Modified: trunk/crossfire/src/cfeditor/PluginParameterFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/PluginParameterFactory.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/PluginParameterFactory.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -97,4 +97,5 @@ public static String[] getTypes() { return parameterTypes.keySet().toArray(new String[parameterTypes.size()]); } -} + +} // class PluginParameterFactory Modified: trunk/crossfire/src/cfeditor/PluginParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/PluginParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/PluginParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -18,4 +18,5 @@ JComponent getValueComponent(Object value, PluginParameter parameter); JComponent getConfigComponent(Object config, PluginParameter parameter); -} + +} // interface PluginParameterView Modified: trunk/crossfire/src/cfeditor/gui/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -270,7 +270,7 @@ } } - } + } // class ArchComboBoxEditor public class ArchComboBoxModel extends AbstractListModel implements ComboBoxModel { @@ -366,7 +366,7 @@ return archList[pos]; } - } + } // class ArchComboBoxModel class MyCellRenderer extends DefaultListCellRenderer { @@ -411,5 +411,7 @@ } return this; } - } -} + + } // class MyCellRenderer + +} // class ArchComboBox Modified: trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -118,7 +118,7 @@ } } - } + } // class ClosingListener /** * the idea for this class stems from limewire's CancelSearchIconProxy @@ -189,5 +189,6 @@ return !(!(xEvent >= x) || !(xEvent <= x + width)) && !(!(yEvent >= y) || !(yEvent <= y + height)); } - } -} + } // class ClosingIcon + +} // class CloseableTabbedPane Modified: trunk/crossfire/src/cfeditor/gui/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -375,4 +375,5 @@ private CScriptModel getScript() { return script; } -} + +} // class ScriptEditor Modified: trunk/crossfire/src/cfeditor/gui/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -170,4 +170,5 @@ scriptPanel.remove(c); } } -} + +} // class ScriptManager Modified: trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -15,60 +15,6 @@ private static final Logger log = Logger.getLogger(AggregateMenuLocation.class); - private class WrappedMenuLocation implements MenuLocation { - - private final String name; - - private final MenuLocation location; - - private WrappedMenuLocation(final MenuLocation location, final String parentName) { - this.location = location; - name = parentName + "." + location.getName(); - } - - public void addMenuEntry(final MenuEntry entry) { - location.addMenuEntry(entry); - } - - public boolean contains(final MenuEntry entry) { - return location.contains(entry); - } - - public Set getMenuEntries() { - return location.getMenuEntries(); - } - - public String getName() { - return name; - } - - public void removeMenuEntry(final MenuEntry entry) { - location.removeMenuEntry(entry); - } - - public void setMenuManager(final MenuManager menuManager) { - location.setMenuManager(menuManager); - } - - public MenuLocation getLocation() { - return location; - } - - @Override public boolean equals(final Object obj) { - if (obj instanceof WrappedMenuLocation) { - final WrappedMenuLocation loc = (WrappedMenuLocation) obj; - return ((loc.name == null ? name == null : loc.name.equals(name)) && - (loc.location == null ? location == null : loc.location.equals(location))); - } - return false; - } - - @Override public int hashCode() { - return (name == null ? 0 : name.hashCode()) - + (location == null ? 0 : location.hashCode()); - } - } - /** * List of handled submenus as AggregateMenuLocation.WrappedMenuLocation * objects. @@ -142,4 +88,60 @@ } } } -} + + private class WrappedMenuLocation implements MenuLocation { + + private final String name; + + private final MenuLocation location; + + private WrappedMenuLocation(final MenuLocation location, final String parentName) { + this.location = location; + name = parentName + "." + location.getName(); + } + + public void addMenuEntry(final MenuEntry entry) { + location.addMenuEntry(entry); + } + + public boolean contains(final MenuEntry entry) { + return location.contains(entry); + } + + public Set getMenuEntries() { + return location.getMenuEntries(); + } + + public String getName() { + return name; + } + + public void removeMenuEntry(final MenuEntry entry) { + location.removeMenuEntry(entry); + } + + public void setMenuManager(final MenuManager menuManager) { + location.setMenuManager(menuManager); + } + + public MenuLocation getLocation() { + return location; + } + + @Override public boolean equals(final Object obj) { + if (obj instanceof WrappedMenuLocation) { + final WrappedMenuLocation loc = (WrappedMenuLocation) obj; + return ((loc.name == null ? name == null : loc.name.equals(name)) && + (loc.location == null ? location == null : loc.location.equals(location))); + } + return false; + } + + @Override public int hashCode() { + return (name == null ? 0 : name.hashCode()) + + (location == null ? 0 : location.hashCode()); + } + + } // class WrappedMenuLocation + +} // class AggregateMenuLocation Modified: trunk/crossfire/src/cfeditor/menu/MenuChangeEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/MenuChangeEvent.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/MenuChangeEvent.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -43,4 +43,5 @@ public int getType() { return type; } -} + +} // class MenuChangeEvent Modified: trunk/crossfire/src/cfeditor/menu/MenuEntry.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/MenuEntry.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/MenuEntry.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -99,4 +99,5 @@ } protected abstract void fireUpdate(); -} + +} // class MenuEntry Modified: trunk/crossfire/src/cfeditor/menu/MenuListener.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/MenuListener.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/MenuListener.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -17,4 +17,5 @@ * @param event the event describe the change */ void menuChanged(MenuChangeEvent event); -} + +} // interface MenuListener Modified: trunk/crossfire/src/cfeditor/menu/MenuLocation.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/MenuLocation.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/MenuLocation.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -49,4 +49,4 @@ */ void setMenuManager(MenuManager menuManager); -} +} // interface MenuLocation Modified: trunk/crossfire/src/cfeditor/menu/MenuManager.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/MenuManager.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/MenuManager.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -241,4 +241,5 @@ public static MenuManager getMenuManager() { return theManager; } -} + +} // class MenuManager Modified: trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -67,4 +67,5 @@ public void setMenuManager(final MenuManager menuManager) { // do nothing, we don't care about our manager (for now) } -} + +} // class SimpleMenuLocation Modified: trunk/crossfire/src/cfeditor/parameter/ArchParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -69,4 +69,5 @@ public static String getParameterType() { return GameObject.class.getName(); } -} + +} // class ArchParameter Modified: trunk/crossfire/src/cfeditor/parameter/ArchParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ArchParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/ArchParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -44,4 +44,5 @@ } }); } -} + +} // class ArchParameterView Modified: trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -13,33 +13,6 @@ public class BooleanParameter extends PluginParameter { - private static class BooleanConfig { - - private String trueText = "Yes"; - - private String falseText = "No"; - - public String getFalseText() { - return falseText; - } - - public void setFalseText(final String falseText) { - if (falseText != null) { - this.falseText = falseText; - } - } - - public String getTrueText() { - return trueText; - } - - public void setTrueText(final String trueText) { - if (trueText != null) { - this.trueText = trueText; - } - } - } - private BooleanConfig config; public BooleanParameter() { @@ -103,4 +76,33 @@ public void setTrueText(final String trueText) { ((BooleanConfig) getConfig()).setTrueText(trueText); } -} + + private static class BooleanConfig { + + private String trueText = "Yes"; + + private String falseText = "No"; + + public String getFalseText() { + return falseText; + } + + public void setFalseText(final String falseText) { + if (falseText != null) { + this.falseText = falseText; + } + } + + public String getTrueText() { + return trueText; + } + + public void setTrueText(final String trueText) { + if (trueText != null) { + this.trueText = trueText; + } + } + + } // class BooleanConfig + +} // class BooleanParameter Modified: trunk/crossfire/src/cfeditor/parameter/BooleanParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/BooleanParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/BooleanParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -60,4 +60,5 @@ parameter.setFalseText(no); } } -} + +} // class BooleanParameterView Modified: trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -13,35 +13,6 @@ public class DoubleParameter extends PluginParameter { - private static class DoubleConfig { - - /* we do not use the Double.MAX or JTextField will be *very* large. So -* we fall back to [0, 1] range (useful for randoms)*/ - double min = 0.0; - - double max = 1.0; - - public double getMax() { - return max; - } - - public void setMax(final double max) { - if (min <= max) { - this.max = max; - } - } - - public double getMin() { - return min; - } - - public void setMin(final double min) { - if (min <= max) { - this.min = min; - } - } - } - public DoubleParameter() { parameterType = getParameterType(); } @@ -114,4 +85,36 @@ setValue(((DoubleConfig) getConfig()).getMin()); } } -} + + private static class DoubleConfig { + + /* we do not use the Double.MAX or JTextField will be *very* large. So + * we fall back to [0, 1] range (useful for randoms) + */ + double min = 0.0; + + double max = 1.0; + + public double getMax() { + return max; + } + + public void setMax(final double max) { + if (min <= max) { + this.max = max; + } + } + + public double getMin() { + return min; + } + + public void setMin(final double min) { + if (min <= max) { + this.min = min; + } + } + + } // class DoubleConfig + +} // class DoubleParameter Modified: trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -26,47 +26,6 @@ private static final Logger log = Logger.getLogger(DoubleParameterView.class); - /** - * Extends JSpinner to work around it's tooltip bug This bug has been fixed - * since Java 5.0 but we need this workaround for java 4.x users. - * @author tchize - */ - private static class TooltipSpinner extends JSpinner { - - private static final long serialVersionUID = 1L; - - private TooltipSpinner() { - super(); - } - - private TooltipSpinner(final SpinnerModel model) { - super(model); - } - - /** - * This override the JSpinner method to force the tooltip in all - * subcomponents. - * @param text the tooltip to show - */ - @Override public void setToolTipText(final String text) { - forceTooltip(this, text); - } - - private void forceTooltip(final JComponent c, final String tip) { - if (c == this) { - super.setToolTipText(tip); - } else { - c.setToolTipText(tip); - } - final Component[] components = c.getComponents(); - for (final Component component : components) { - if (component instanceof JComponent) { - forceTooltip((JComponent) component, tip); - } - } - } - } - private JSpinner value; private JButton config; @@ -137,4 +96,47 @@ } } } -} + + /** + * Extends JSpinner to work around it's tooltip bug This bug has been fixed + * since Java 5.0 but we need this workaround for java 4.x users. + * @author tchize + */ + private static class TooltipSpinner extends JSpinner { + + private static final long serialVersionUID = 1L; + + private TooltipSpinner() { + super(); + } + + private TooltipSpinner(final SpinnerModel model) { + super(model); + } + + /** + * This override the JSpinner method to force the tooltip in all + * subcomponents. + * @param text the tooltip to show + */ + @Override public void setToolTipText(final String text) { + forceTooltip(this, text); + } + + private void forceTooltip(final JComponent c, final String tip) { + if (c == this) { + super.setToolTipText(tip); + } else { + c.setToolTipText(tip); + } + final Component[] components = c.getComponents(); + for (final Component component : components) { + if (component instanceof JComponent) { + forceTooltip((JComponent) component, tip); + } + } + } + + } // class TooltipSpinner + +} // class DoubleParameterView Modified: trunk/crossfire/src/cfeditor/parameter/FilterParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/FilterParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/FilterParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -51,4 +51,5 @@ public static String getParameterType() { return NamedFilterConfig.class.getName(); } -} + +} // class FilterParameter Modified: trunk/crossfire/src/cfeditor/parameter/FilterParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/FilterParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/FilterParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -33,4 +33,5 @@ final PluginParameter parameter) { return new JPanel(); } -} + +} // class FilterParameterView Modified: trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -13,33 +13,6 @@ public class IntegerParameter extends PluginParameter { - private static class IntegerConfig { - - int min = Integer.MIN_VALUE; - - int max = Integer.MAX_VALUE; - - public int getMax() { - return max; - } - - public void setMax(final int max) { - if (min <= max) { - this.max = max; - } - } - - public int getMin() { - return min; - } - - public void setMin(final int min) { - if (min <= max) { - this.min = min; - } - } - } - public IntegerParameter() { parameterType = getParameterType(); } @@ -112,4 +85,33 @@ setValue(((IntegerConfig) getConfig()).getMin()); } } -} + + private static class IntegerConfig { + + int min = Integer.MIN_VALUE; + + int max = Integer.MAX_VALUE; + + public int getMax() { + return max; + } + + public void setMax(final int max) { + if (min <= max) { + this.max = max; + } + } + + public int getMin() { + return min; + } + + public void setMin(final int min) { + if (min <= max) { + this.min = min; + } + } + + } // class IntegerConfig + +} // class IntegerParameter Modified: trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -26,47 +26,6 @@ private static final Logger log = Logger.getLogger(IntegerParameterView.class); - /** - * Extends JSpinner to work around it's tooltip bug This bug has been fixed - * since Java 5.0 but we need this workaround for java 4.x users. - * @author tchize - */ - private static class TooltipSpinner extends JSpinner { - - private static final long serialVersionUID = -797350272052837471L; - - private TooltipSpinner() { - super(); - } - - private TooltipSpinner(final SpinnerModel model) { - super(model); - } - - /** - * This override the JSpinner method to force the tooltip in all - * subcomponents. - * @param text the tooltip to show - */ - @Override public void setToolTipText(final String text) { - forceTooltip(this, text); - } - - private void forceTooltip(final JComponent c, final String tip) { - if (c == this) { - super.setToolTipText(tip); - } else { - c.setToolTipText(tip); - } - final Component[] components = c.getComponents(); - for (final Component component : components) { - if (component instanceof JComponent) { - forceTooltip((JComponent) component, tip); - } - } - } - } - private JSpinner value; private JButton config; @@ -133,4 +92,47 @@ } } } -} + + /** + * Extends JSpinner to work around it's tooltip bug This bug has been fixed + * since Java 5.0 but we need this workaround for java 4.x users. + * @author tchize + */ + private static class TooltipSpinner extends JSpinner { + + private static final long serialVersionUID = -797350272052837471L; + + private TooltipSpinner() { + super(); + } + + private TooltipSpinner(final SpinnerModel model) { + super(model); + } + + /** + * This override the JSpinner method to force the tooltip in all + * subcomponents. + * @param text the tooltip to show + */ + @Override public void setToolTipText(final String text) { + forceTooltip(this, text); + } + + private void forceTooltip(final JComponent c, final String tip) { + if (c == this) { + super.setToolTipText(tip); + } else { + c.setToolTipText(tip); + } + final Component[] components = c.getComponents(); + for (final Component component : components) { + if (component instanceof JComponent) { + forceTooltip((JComponent) component, tip); + } + } + } + + } // class TooltipSpinner + +} // class IntegerParameterView Modified: trunk/crossfire/src/cfeditor/parameter/MapParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/MapParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/MapParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -72,4 +72,5 @@ public void setValueToCurrent() { super.setValue("[Current Map]"); } -} + +} // class MapParameter Modified: trunk/crossfire/src/cfeditor/parameter/MapParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/MapParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/MapParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -94,8 +94,9 @@ } return super.getListCellRendererComponent(list, newVal, index, isSelected, cellHasFocus); } - } + } // class MyCellRenderer + public static class MyComboBoxModel extends DefaultComboBoxModel { private final Object currentMap = new Object(); @@ -142,5 +143,7 @@ @Override public void setSelectedItem(final Object anObject) { selected = anObject; } - } -} + + } // class MyComboBoxModel + +} // class MapParameterView Modified: trunk/crossfire/src/cfeditor/parameter/ParameterDescriptionEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ParameterDescriptionEditor.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/ParameterDescriptionEditor.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -40,4 +40,5 @@ } }); } -} + +} // class ParameterDescriptionEditor Modified: trunk/crossfire/src/cfeditor/parameter/ParameterNameEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ParameterNameEditor.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/ParameterNameEditor.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -40,4 +40,5 @@ } }); } -} + +} // class ParameterNameEditor Modified: trunk/crossfire/src/cfeditor/parameter/ParameterTypeEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ParameterTypeEditor.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/ParameterTypeEditor.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -37,4 +37,5 @@ } }); } -} + +} // class ParameterTypeEditor Modified: trunk/crossfire/src/cfeditor/parameter/StringParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/StringParameter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/StringParameter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -48,4 +48,5 @@ } setValue("[description]"); } -} + +} // class StringParameter Modified: trunk/crossfire/src/cfeditor/parameter/StringParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/StringParameterView.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/crossfire/src/cfeditor/parameter/StringParameterView.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -70,4 +70,5 @@ } }); } -} + +} // class StringParameterView Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -747,8 +747,9 @@ public TreasureObj getTreasureObj() { return content; } - } + } // class TreasureTreeNode + /** * Subclass: UserObject (= content object) for nodes in the CFTreasureListTree * These can be either treasurelists (containers), arches, or yes/no containers. @@ -845,8 +846,9 @@ public String getName() { return name; } - } + } // class TreasureObj + /** * This cell renderer is responsible for drawing the treasure-object * cells in the JTree. @@ -953,6 +955,7 @@ return this; } + } // class TreasureCellRenderer } // class CFTreasureListTree Modified: trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -310,4 +310,5 @@ } catch (final Exception e) { /* ignore */ } } } + } // class FaceObjects Modified: trunk/daimonin/src/daieditor/gameobject/match/AttribGameObjectMatcher.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/match/AttribGameObjectMatcher.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/gameobject/match/AttribGameObjectMatcher.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -53,8 +53,9 @@ lt, ge, gt - } + } // enum Op + /** * Create an AttribGameObjectMatcher. * @param name Attribute name to match Modified: trunk/daimonin/src/daieditor/gui/map/MapTilePane.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -834,6 +834,7 @@ maptail = new StringBuilder(); map = null; } + } // class TileMapHeader } // class MapTilePane Modified: trunk/daimonin/src/daieditor/gui/map/MapUserListener.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapUserListener.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/gui/map/MapUserListener.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -40,6 +40,7 @@ * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> */ public final class MapUserListener implements MouseListener, MouseMotionListener { + /** ToolSelector of ArchPanel. */ private final ToolSelectorPane toolSelectorPane; Modified: trunk/daimonin/src/daieditor/gui/map/event/MouseOpEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/event/MouseOpEvent.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/gui/map/event/MouseOpEvent.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -150,4 +150,5 @@ public void setId(final int id) { this.id = id; } + } // class MouseOpEvent Modified: trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/map/validation/checks/ExitError.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -30,4 +30,4 @@ return exitPath; } -} // class TilePathsError +} // class ExitError Modified: trunk/daimonin/src/daieditor/map/validation/checks/MapDifficultyChecker.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/MapDifficultyChecker.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/map/validation/checks/MapDifficultyChecker.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -27,4 +27,4 @@ } } -} // class TilePathsChecker +} // class MapDifficultyChecker Modified: trunk/daimonin/src/daieditor/map/validation/checks/SlayingError.java =================================================================== --- trunk/daimonin/src/daieditor/map/validation/checks/SlayingError.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/daieditor/map/validation/checks/SlayingError.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -46,4 +46,4 @@ getGameObject().remove(); } -} // class ConnectedInsideContainerError +} // class SlayingError Modified: trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -400,4 +400,5 @@ public static junit.framework.Test suite() { return new JUnit4TestAdapter(MapCursorTest.class); } + } // class MapCursorTest Modified: trunk/gridarta.ipr =================================================================== --- trunk/gridarta.ipr 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/gridarta.ipr 2006-12-25 15:03:10 UTC (rev 1274) @@ -1972,7 +1972,7 @@ <option name="calculateMetrics" value="true" /> <option name="includeTestClasses" value="false" /> <option name="flattenInnerClasses" value="true" /> - <option name="cycleTableSpecificationString" value="" /> + <option name="cycleTableSpecificationString" value="318,318,318,317" /> <option name="shortCycleTableSpecificationString" value="" /> </component> <component name="copyright"> Modified: trunk/src/app/net/sf/gridarta/MainControlListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControlListener.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/MainControlListener.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -54,4 +54,4 @@ */ void mapClosing(@NotNull C mapControl); -} +} // interface MainControlListener Modified: trunk/src/app/net/sf/gridarta/gameobject/NamedObjects.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/NamedObjects.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/gameobject/NamedObjects.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -180,6 +180,7 @@ setText(node.getName()); return this; } + } // class NamedNodeTreeCellRenderer } // class NamedObjects Modified: trunk/src/app/net/sf/gridarta/gui/GSplitPane.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/GSplitPane.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/gui/GSplitPane.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -63,4 +63,4 @@ } } -} // class DSplitPane +} // class GSplitPane Modified: trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -542,10 +542,13 @@ /** All tiles that are preselected get selected. */ ADD, + /** All tiles that are preselected get unselected. */ SUB, + /** All tiles that are preselected change state of selection. */ FLIP - } + } // enum SelectionMode + } // class MapGrid Modified: trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelection.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelection.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelection.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -191,4 +191,4 @@ this.index = index; } -} +} // class MapTileSelection Modified: trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -68,4 +68,4 @@ } } -} +} // class MapTileSelectionCache Modified: trunk/src/app/net/sf/gridarta/help/Help.java =================================================================== --- trunk/src/app/net/sf/gridarta/help/Help.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/help/Help.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -79,4 +79,4 @@ setDefaultCloseOperation(DISPOSE_ON_CLOSE); } -} // class CFHelp +} // class Help Modified: trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -123,4 +123,4 @@ return myInput.readLine(); } -} // class AbstractMapFileDecode +} // class AbstractMapReader Modified: trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -124,4 +124,4 @@ return this; } -} // class AbstractMapFileEncode +} // class AbstractMapWriter Modified: trunk/src/app/net/sf/gridarta/io/MapReader.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/MapReader.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/io/MapReader.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -28,4 +28,4 @@ */ @NotNull List<G> decodeMapFile() throws IOException; -} // interface MapFileDecode +} // interface MapReader Modified: trunk/src/app/net/sf/gridarta/io/MapWriter.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/MapWriter.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/io/MapWriter.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -18,4 +18,4 @@ */ void encodeMapFile(@NotNull M mapModel) throws IOException; -} // interface MapFileEncode +} // interface MapWriter Modified: trunk/src/app/net/sf/gridarta/textedit/scripteditor/CFPythonPopup.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/scripteditor/CFPythonPopup.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/textedit/scripteditor/CFPythonPopup.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -202,6 +202,7 @@ popup.getMenu().setVisible(false); // in some JRE versions, this doesn't happen automatically } } + } // class MenuActionListener /** @@ -219,6 +220,7 @@ //this.addMouseListener(new ListenerMenuClick()); setPreferredSize(new Dimension(220, 200)); } + } // class CFPythonPopupMenu } // class CFPythonPopup Modified: trunk/src/app/net/sf/gridarta/textedit/textarea/CTokenMarker.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/textarea/CTokenMarker.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/textedit/textarea/CTokenMarker.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -277,4 +277,5 @@ lastKeyword = i1; return false; } -} + +} // class CTokenMarker Modified: trunk/src/app/net/sf/gridarta/textedit/textarea/JavaScriptTokenMarker.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/textarea/JavaScriptTokenMarker.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/textedit/textarea/JavaScriptTokenMarker.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -45,4 +45,5 @@ // private members private static KeywordMap javaScriptKeywords; -} + +} // class JavaScriptTokenMarker Modified: trunk/src/app/net/sf/gridarta/textedit/textarea/PythonTokenMarker.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/textarea/PythonTokenMarker.java 2006-12-24 15:29:42 UTC (rev 1273) +++ trunk/src/app/net/sf/gridarta/textedit/textarea/PythonTokenMarker.java 2006-12-25 15:03:10 UTC (rev 1274) @@ -219,4 +219,5 @@ lastKeyword = i1; return false; } -} + +} // class PythonTokenMarker This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 13:27:40
|
Revision: 1280 http://svn.sourceforge.net/gridarta/?rev=1280&view=rev Author: christianhujer Date: 2006-12-26 05:27:40 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Minor documentation improvements to I/O code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/io/CMapReader.java trunk/daimonin/src/daieditor/io/CMapReader.java trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java trunk/src/app/net/sf/gridarta/io/MapReader.java Modified: trunk/crossfire/src/cfeditor/io/CMapReader.java =================================================================== --- trunk/crossfire/src/cfeditor/io/CMapReader.java 2006-12-26 13:04:07 UTC (rev 1279) +++ trunk/crossfire/src/cfeditor/io/CMapReader.java 2006-12-26 13:27:40 UTC (rev 1280) @@ -47,6 +47,7 @@ */ public final class CMapReader extends AbstractMapReader<GameObject, MapArchObject> { + /** Logger. */ private static final Logger log = Logger.getLogger(CMapReader.class); /** @@ -73,19 +74,6 @@ } /** - * Loading a map from the given mapfile. - * This method returns a list of GameObjects. - * @return first <code>GameObject</code> in the list - * @throws FileNotFoundException in case the requested map file was not found - * @throws IOException in case the file couldn't be read or is in wrong format - * @todo create a separate exception for the wrong format - */ - @Override @NotNull public List<GameObject> decodeMapFile() throws IOException { - final List<GameObject> objects = super.decodeMapFile(); - return objects; // return first arch of the list - } - - /** * Our recursive accessible arch reader. * <p/> * WARNING: this implementation should fail with multi head settings Modified: trunk/daimonin/src/daieditor/io/CMapReader.java =================================================================== --- trunk/daimonin/src/daieditor/io/CMapReader.java 2006-12-26 13:04:07 UTC (rev 1279) +++ trunk/daimonin/src/daieditor/io/CMapReader.java 2006-12-26 13:27:40 UTC (rev 1280) @@ -74,14 +74,7 @@ return new MapArchObject(); } - /** - * Loading a map from the given mapfile. - * This method returns a list of GameObjects. - * @return first <code>GameObject</code> in the list - * @throws FileNotFoundException in case the requested map file was not found - * @throws IOException in case the file couldn't be read or is in wrong format - * @todo create a separate exception for the wrong format - */ + /** {@inheritDoc} */ @Override @NotNull public List<GameObject> decodeMapFile() throws IOException { final List<GameObject> objects = super.decodeMapFile(); CMainControl.getInstance().collectTempList(objects, uri); Modified: trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java 2006-12-26 13:04:07 UTC (rev 1279) +++ trunk/src/app/net/sf/gridarta/io/AbstractMapReader.java 2006-12-26 13:27:40 UTC (rev 1280) @@ -79,13 +79,7 @@ */ protected abstract A createMapArchObject(); - /** - * Loading a map from the given mapfile. - * This method returns a list of GameObjects. - * @return first <code>GameObject</code> in the list - * @throws FileNotFoundException in case the requested map file was not found - * @throws IOException in case the file couldn't be read or is in wrong format - */ + /** {@inheritDoc} */ @NotNull public List<G> decodeMapFile() throws IOException { // first of all we read the map arch (if that fails we throw an exception) maparch = createMapArchObject(); Modified: trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java 2006-12-26 13:04:07 UTC (rev 1279) +++ trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java 2006-12-26 13:27:40 UTC (rev 1280) @@ -61,13 +61,18 @@ final MapArchObject mapArch = mapModel.getMapArchObject(); // write map header: map arch - mapArch.writeMapArch(this); // FIXME: It doesn't look like a good idea to mix Push and Pull + // FIXME: It doesn't look like a good idea to mix Push and Pull: + // The map arch is written using push. + // The gameobjects are written using pull. + mapArch.writeMapArch(this); // first, write all one tile parts final Size2D mapSize = mapArch.getMapSize(); + final int width = mapSize.getWidth(); + final int height = mapSize.getHeight(); final Point pos = new Point(); - for (pos.x = 0; pos.x < mapSize.getWidth(); pos.x++) { - for (pos.y = 0; pos.y < mapSize.getHeight(); pos.y++) { + for (pos.x = 0; pos.x < width; pos.x++) { + for (pos.y = 0; pos.y < height; pos.y++) { for (final G gameObject : mapModel.getMapSquare(pos)) { // only non multi suckers if (!gameObject.isMulti()) { @@ -77,9 +82,9 @@ } // y } // x - // second, we drop the multi part suckers out - for (pos.x = 0; pos.x < mapSize.getWidth(); pos.x++) { - for (pos.y = 0; pos.y < mapSize.getHeight(); pos.y++) { + // second, write all multi tile heads (multi tile tails aren't written) + for (pos.x = 0; pos.x < width; pos.x++) { + for (pos.y = 0; pos.y < height; pos.y++) { for (final G gameObject : mapModel.getMapSquare(pos)) { // search only for heads! if (gameObject.isMulti() && gameObject.isHead()) { Modified: trunk/src/app/net/sf/gridarta/io/MapReader.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/MapReader.java 2006-12-26 13:04:07 UTC (rev 1279) +++ trunk/src/app/net/sf/gridarta/io/MapReader.java 2006-12-26 13:27:40 UTC (rev 1280) @@ -21,10 +21,11 @@ A getMapArch(); /** - * Loading a map from the given mapfile. + * Loads a map from the given mapfile. * This method returns a list of GameObjects. * @return first <code>GameObject</code> in the list - * @throws IOException in case the file couldn't be read or is in wrong format + * @throws IOException in case the file couldn't be read + * @throws InvalidMapFormatException in case the file is in wrong format */ @NotNull List<G> decodeMapFile() throws IOException; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 14:19:38
|
Revision: 1283 http://svn.sourceforge.net/gridarta/?rev=1283&view=rev Author: christianhujer Date: 2006-12-26 06:19:38 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Removed several occurrences of File.separator (gridarta will move to URIs). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/ScriptArchData.java trunk/crossfire/src/cfeditor/Spells.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/IGUIConstants.java trunk/daimonin/src/daieditor/MultiPositionData.java trunk/daimonin/src/daieditor/ScriptArchData.java trunk/daimonin/src/daieditor/Spells.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/CommonConstants.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -1175,7 +1175,7 @@ strImageDir = mapDir.getAbsolutePath(); } - String filename = strImageDir + File.separator + mapControl.getMapFileName() + ".png"; + String filename = strImageDir + "/" + mapControl.getMapFileName() + ".png"; try { final JFileChooser fileChooser = new JFileChooser(strImageDir); fileChooser.setDialogTitle("Save Image As"); Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -121,19 +121,19 @@ int DEF_PICKMAP_HEIGHT = 12; /** The directory that contains the common-use icons. */ - String ICON_DIR = "resource" + File.separator + "icons"; + String ICON_DIR = "resource/icons"; /** The directory that contains the system icons. */ - String SYSTEM_DIR = "resource" + File.separator + "system"; + String SYSTEM_DIR = "resource/system"; /** The directory that contains all pickmaps. */ - String PICKMAP_DIR = "resource" + File.separator + "pickmaps"; + String PICKMAP_DIR = "resource/pickmaps"; /** * The directory that contains all configuration files (careful - if you * change this, check directory creation for file writing). */ - String CONFIG_DIR = "resource" + File.separator + "conf"; + String CONFIG_DIR = "resource/conf"; // name of the configuration files: String SPELL_FILE = "spells.xml"; // spell-numbers Modified: trunk/crossfire/src/cfeditor/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/ScriptArchData.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/crossfire/src/cfeditor/ScriptArchData.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -535,7 +535,7 @@ } } else { // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + File.separator + scriptPath; + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; } // now check if the specified path points to an existing script Modified: trunk/crossfire/src/cfeditor/Spells.java =================================================================== --- trunk/crossfire/src/cfeditor/Spells.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/crossfire/src/cfeditor/Spells.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -172,7 +172,7 @@ new File(IGUIConstants.CONFIG_DIR).mkdir(); } - dfile = new File(IGUIConstants.CONFIG_DIR + File.separator + IGUIConstants.SPELL_FILE); + dfile = new File(IGUIConstants.CONFIG_DIR, IGUIConstants.SPELL_FILE); } else { dfile = new File(IGUIConstants.SPELL_FILE); } Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -166,7 +166,7 @@ private void loadTypesFromXML() { try { - final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR; + final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; // parse xml document final Document doc = documentBuilder.parse(new File(baseDir, IGUIConstants.TYPEDEF_FILE)); @@ -285,7 +285,7 @@ private void readArchObjectMatchers() { final GameObjectMatchers aom = new GameObjectMatchers(xpath); - final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR; + final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; try { final Document doc = documentBuilder.parse(new File(baseDir, "GameObjectMatchers.xml")); for (final Element node : new NodeListIterator<Element>(doc.getElementsByTagName("GameObjectMatcher"))) { Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -290,7 +290,7 @@ if (traverse != null) { Arrays.sort(traverse); for (final String entry : traverse) { - loadTreasureList(fname + File.separator + entry, tmpList, needLink); + loadTreasureList(fname + "/" + entry, tmpList, needLink); } } // This was a directory -> nothing to parse Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -1400,31 +1400,30 @@ strImageDir = mapDir.getAbsolutePath(); } - String filename = strImageDir + File.separator + mapControl.getMapFileName() + ".png"; + File file = new File(strImageDir, mapControl.getMapFileName() + ".png"); try { final JFileChooser fileChooser = new JFileChooser(strImageDir); fileChooser.setDialogTitle("Save Image As"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); - fileChooser.setSelectedFile(new File(filename)); + fileChooser.setSelectedFile(file); // set a file filter for "*.png" files fileChooser.setFileFilter(pngFileFilter); final int returnVal = fileChooser.showSaveDialog(mainView); if (returnVal == JFileChooser.APPROVE_OPTION) { // got the filepath, now create image - filename = fileChooser.getSelectedFile().getAbsolutePath(); - strImageDir = fileChooser.getSelectedFile().getParentFile().getAbsolutePath(); - if (!filename.endsWith(".png")) { - filename += ".png"; + file = fileChooser.getSelectedFile(); + if (!file.getName().endsWith(".png")) { + file = new File(file.getParentFile(), file.getName() + ".png"); } - final File file = new File(filename); - if (!file.exists() || ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, "overwriteOtherFile", filename) == JOptionPane.YES_OPTION) { + strImageDir = file.getParentFile().getAbsolutePath(); + if (!file.exists() || ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, "overwriteOtherFile", file) == JOptionPane.YES_OPTION) { mapControl.getMapViewFrame().printFullImage(file); } } } catch (final IOException e) { - ACTION_FACTORY.showMessageDialog(mainView, "createImgIOException", filename, e.getMessage()); + ACTION_FACTORY.showMessageDialog(mainView, "createImgIOException", file, e.getMessage()); } } } Modified: trunk/daimonin/src/daieditor/IGUIConstants.java =================================================================== --- trunk/daimonin/src/daieditor/IGUIConstants.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/IGUIConstants.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -119,19 +119,19 @@ int DEF_PICKMAP_HEIGHT = 20; /** The directory that contains the common-use icons.*/ - String ICON_DIR = "resource" + File.separator + "icons"; + String ICON_DIR = "resource/icons"; /** The directory that contains the system icons. */ - String SYSTEM_DIR = "resource" + File.separator + "system"; + String SYSTEM_DIR = "resource/system"; /** The directory that contains all pickmaps. */ - String PICKMAP_DIR = "dev" + File.separator + "editor" + File.separator + "pickmaps"; + String PICKMAP_DIR = "dev/editor/pickmaps"; /** * The directory that contains all configuration files (careful - if you * change this, check directory creation for file writing). */ - String CONFIG_DIR = "dev" + File.separator + "editor" + File.separator + "conf"; + String CONFIG_DIR = "dev/editor/conf"; // name of the configuration files: String SPELL_FILE = "spells.xml"; // spell-numbers Modified: trunk/daimonin/src/daieditor/MultiPositionData.java =================================================================== --- trunk/daimonin/src/daieditor/MultiPositionData.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/MultiPositionData.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -75,7 +75,7 @@ private void load() { // read datafile line by line, parsing numbers into the array try { - final BufferedReader reader = IOUtils.createReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); + final BufferedReader reader = IOUtils.createReader(CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); try { final Dimension d = new Dimension(); final Point p = new Point(); Modified: trunk/daimonin/src/daieditor/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/ScriptArchData.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/ScriptArchData.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -492,7 +492,7 @@ } } else { // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + File.separator + scriptPath; + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; } // now check if the specified path points to an existing script Modified: trunk/daimonin/src/daieditor/Spells.java =================================================================== --- trunk/daimonin/src/daieditor/Spells.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/Spells.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -140,7 +140,7 @@ final File dfile; // create new file for writing (replaces old one if existent) if (IGUIConstants.CONFIG_DIR != null && IGUIConstants.CONFIG_DIR.length() > 0) { - final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR; + final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; File dir = new File(baseDir); if (!dir.exists() || !dir.isDirectory()) { // FIXME What if dir exists and is not a directory? mkdir will fail then! @@ -150,7 +150,7 @@ dir = new File(IGUIConstants.CONFIG_DIR); dir.mkdir(); } - dfile = new File(baseDir + File.separator + IGUIConstants.SPELL_FILE); + dfile = new File(baseDir, IGUIConstants.SPELL_FILE); } else { dfile = new File(IGUIConstants.SPELL_FILE); } @@ -199,7 +199,7 @@ try { // open reading stream to the spells xml file - final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR; + final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; // parse xml document final Document doc = documentBuilder.parse(new File(baseDir, IGUIConstants.SPELL_FILE)); Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -141,7 +141,7 @@ loadAnimsFromFiles(); } - loadArchesFromArtifacts(mainControl.getArchDefaultFolder() + File.separator + IGUIConstants.ARTIFACTS_FILE, "Artifacts", "artifacts"); + loadArchesFromArtifacts(mainControl.getArchDefaultFolder() + "/" + IGUIConstants.ARTIFACTS_FILE, "Artifacts", "artifacts"); loadArchesFromArtifacts(mainControl.getMapDefaultFolder(), "Artifacts", "maps"); mainControl.setStatusText("Sorting..."); @@ -195,7 +195,7 @@ if (traverse != null) { Arrays.sort(traverse); for (final String entry : traverse) { - loadArchesFromArtifacts(fname + File.separator + entry, panelName, folderName); + loadArchesFromArtifacts(fname + "/" + entry, panelName, folderName); } } // This was a directory -> nothing to parse Modified: trunk/src/app/net/sf/gridarta/CommonConstants.java =================================================================== --- trunk/src/app/net/sf/gridarta/CommonConstants.java 2006-12-26 13:40:07 UTC (rev 1282) +++ trunk/src/app/net/sf/gridarta/CommonConstants.java 2006-12-26 14:19:38 UTC (rev 1283) @@ -24,8 +24,6 @@ package net.sf.gridarta; -import static java.io.File.separator; - /** * Class with constants used in Gridarta and derivates. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> @@ -33,7 +31,7 @@ public abstract class CommonConstants { /** The directory that contains all (html) help files. */ - public static final String HELP_DIR = "resource" + separator + "HelpFiles"; + public static final String HELP_DIR = "resource/HelpFiles"; /** Python menu definitions. */ public static final String PYTHONMENU_FILE = "cfpython_menu.def"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 18:46:53
|
Revision: 1284 http://svn.sourceforge.net/gridarta/?rev=1284&view=rev Author: christianhujer Date: 2006-12-26 10:46:52 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Improved PathManagers and added some test cases for them. Modified Paths: -------------- trunk/crossfire/src/cfeditor/io/PathManager.java trunk/daimonin/src/daieditor/io/PathManager.java trunk/daimonin/src/test/daieditor/io/PathManagerTest.java Modified: trunk/crossfire/src/cfeditor/io/PathManager.java =================================================================== --- trunk/crossfire/src/cfeditor/io/PathManager.java 2006-12-26 14:19:38 UTC (rev 1283) +++ trunk/crossfire/src/cfeditor/io/PathManager.java 2006-12-26 18:46:52 UTC (rev 1284) @@ -89,7 +89,7 @@ /** * Check whether a path is absolute. * Paths starting with "/" are absolute, paths starting with other characters are relative. - * Empty paths are neither relative nor absolute. + * Empty paths are relative. * @param path Path to check * @return <code>true</code> if <var>path</var> is absolute, <code>false</code> otherwise * @see #isRelative(String) which nearly is the opposite of this method @@ -101,7 +101,7 @@ /** * Check whether a path is relative. * Paths not starting with "/" are relative, paths starting with are absolute. - * Empty paths are neither relative nor absolute. + * Empty paths are relative. * @param path Path to check * @return <code>true</code> if <var>path</var> is relative, <code>false</code> otherwise * @see #isAbsolute(String) which nearly is the opposite of this method @@ -209,6 +209,7 @@ String path = str.replaceAll("\\\\", "/"); path = path.endsWith("/") ? path.substring(0, path.length() - 1) : path; path = path.startsWith("file:") ? path.substring("file:".length()) : path; + path = path.replaceAll("//*", "/"); return path; } Modified: trunk/daimonin/src/daieditor/io/PathManager.java =================================================================== --- trunk/daimonin/src/daieditor/io/PathManager.java 2006-12-26 14:19:38 UTC (rev 1283) +++ trunk/daimonin/src/daieditor/io/PathManager.java 2006-12-26 18:46:52 UTC (rev 1284) @@ -89,7 +89,7 @@ /** * Check whether a path is absolute. * Paths starting with "/" are absolute, paths starting with other characters are relative. - * Empty paths are neither relative nor absolute. + * Empty paths are relative. * @param path Path to check * @return <code>true</code> if <var>path</var> is absolute, <code>false</code> otherwise * @see #isRelative(String) which nearly is the opposite of this method @@ -101,7 +101,7 @@ /** * Check whether a path is relative. * Paths not starting with "/" are relative, paths starting with are absolute. - * Empty paths are neither relative nor absolute. + * Empty paths are relative. * @param path Path to check * @return <code>true</code> if <var>path</var> is relative, <code>false</code> otherwise * @see #isAbsolute(String) which nearly is the opposite of this method @@ -209,6 +209,7 @@ String path = str.replaceAll("\\\\", "/"); path = path.endsWith("/") ? path.substring(0, path.length() - 1) : path; path = path.startsWith("file:") ? path.substring("file:".length()) : path; + path = path.replaceAll("//*", "/"); return path; } Modified: trunk/daimonin/src/test/daieditor/io/PathManagerTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/io/PathManagerTest.java 2006-12-26 14:19:38 UTC (rev 1283) +++ trunk/daimonin/src/test/daieditor/io/PathManagerTest.java 2006-12-26 18:46:52 UTC (rev 1284) @@ -1,17 +1,47 @@ package test.daieditor.io; import daieditor.io.PathManager; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.Assert; /** * Test for {@link daieditor.io.PathManager}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class PathManagerTest extends TestCase { +public class PathManagerTest { /** Test case for {@link daieditor.io.PathManager#path(String)}. */ - public void testPath() { - assertEquals("Expecting trailing slash from directories being removed.", "/foo", PathManager.path("/foo/")); + @Test public void testPath() { + Assert.assertEquals("Expecting trailing slash from directories being removed.", "/foo", PathManager.path("/foo/")); + Assert.assertEquals("Expecting file: URIs being converted to URIs without scheme.", "/foo", PathManager.path("file:/foo/")); + Assert.assertEquals("Expecting multiple // characters to be collapsed.", "/foo/bar", PathManager.path("//foo///bar")); } + /** Test case for {@link daieditor.io.PathManager#absoluteToRelative(String, String)}. */ + @Test public void testAbsoluteToRelavive() { + Assert.assertEquals("../stoneglow/stoneglow_0000", PathManager.absoluteToRelative("/relic/castle_0000", "/stoneglow/stoneglow_0000")); + } + + /** Test case for {@link daieditor.io.PathManager#absoluteToRelative(String, String)}. */ + @Test public void testRelativeToAbsolute() { + Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/castle_0000", "../stoneglow/stoneglow_0000")); + Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/castle_0000", "/stoneglow/stoneglow_0000")); + } + + /** Test case for {@link PathManager#isRelative(String)}. */ + @Test public void testIsRelative() { + Assert.assertTrue(PathManager.isRelative("../stoneglow/stoneglow_0000")); + Assert.assertTrue(PathManager.isRelative("stoneglow/stoneglow_0000")); + Assert.assertFalse(PathManager.isRelative("/stoneglow/stoneglow_0000")); + Assert.assertTrue(PathManager.isRelative("")); + } + + /** Test case for {@link PathManager#isAbsolute(String)}. */ + @Test public void testIsAbsolute() { + Assert.assertFalse(PathManager.isAbsolute("../stoneglow/stoneglow_0000")); + Assert.assertFalse(PathManager.isAbsolute("stoneglow/stoneglow_0000")); + Assert.assertTrue(PathManager.isAbsolute("/stoneglow/stoneglow_0000")); + Assert.assertFalse(PathManager.isAbsolute("")); + } + } // class PathManagerTest \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 18:54:47
|
Revision: 1285 http://svn.sourceforge.net/gridarta/?rev=1285&view=rev Author: christianhujer Date: 2006-12-26 10:54:48 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Improved documentation, added some test cases. Modified Paths: -------------- trunk/crossfire/src/cfeditor/io/PathManager.java trunk/daimonin/src/daieditor/io/PathManager.java trunk/daimonin/src/test/daieditor/io/PathManagerTest.java Modified: trunk/crossfire/src/cfeditor/io/PathManager.java =================================================================== --- trunk/crossfire/src/cfeditor/io/PathManager.java 2006-12-26 18:46:52 UTC (rev 1284) +++ trunk/crossfire/src/cfeditor/io/PathManager.java 2006-12-26 18:54:48 UTC (rev 1285) @@ -113,7 +113,8 @@ /** * Converts a relative path to an absolute path. * If the path already is relative, this method simply returns the path. - * @param reference reference file the relative path works on (regular file, not directory) + * If the reference ends on "/", it is treated as being a base directory, otherwise a file that's directory is taken as base. + * @param reference reference file the relative path works on. * @param relative destination file with relative path * @return absolute path from the base directory */ @@ -136,7 +137,8 @@ /** * Converts an absolute path to a relative path. * If the path already is absolute, this method simply returns the path. - * @param reference reference file the relative path works on (regular file, not directory) + * If the reference ends on "/", it is treated as being a base directory, otherwise a file that's directory is taken as base. + * @param reference reference file the relative path works on * @param absolute destination file with relative path * @return absolute path from the base directory */ Modified: trunk/daimonin/src/daieditor/io/PathManager.java =================================================================== --- trunk/daimonin/src/daieditor/io/PathManager.java 2006-12-26 18:46:52 UTC (rev 1284) +++ trunk/daimonin/src/daieditor/io/PathManager.java 2006-12-26 18:54:48 UTC (rev 1285) @@ -113,7 +113,8 @@ /** * Converts a relative path to an absolute path. * If the path already is relative, this method simply returns the path. - * @param reference reference file the relative path works on (regular file, not directory) + * If the reference ends on "/", it is treated as being a base directory, otherwise a file that's directory is taken as base. + * @param reference reference file the relative path works on. * @param relative destination file with relative path * @return absolute path from the base directory */ @@ -136,7 +137,8 @@ /** * Converts an absolute path to a relative path. * If the path already is absolute, this method simply returns the path. - * @param reference reference file the relative path works on (regular file, not directory) + * If the reference ends on "/", it is treated as being a base directory, otherwise a file that's directory is taken as base. + * @param reference reference file the relative path works on * @param absolute destination file with relative path * @return absolute path from the base directory */ Modified: trunk/daimonin/src/test/daieditor/io/PathManagerTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/io/PathManagerTest.java 2006-12-26 18:46:52 UTC (rev 1284) +++ trunk/daimonin/src/test/daieditor/io/PathManagerTest.java 2006-12-26 18:54:48 UTC (rev 1285) @@ -5,27 +5,30 @@ import org.junit.Assert; /** - * Test for {@link daieditor.io.PathManager}. + * Test for {@link PathManager}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class PathManagerTest { - /** Test case for {@link daieditor.io.PathManager#path(String)}. */ + /** Test case for {@link PathManager#path(String)}. */ @Test public void testPath() { Assert.assertEquals("Expecting trailing slash from directories being removed.", "/foo", PathManager.path("/foo/")); Assert.assertEquals("Expecting file: URIs being converted to URIs without scheme.", "/foo", PathManager.path("file:/foo/")); Assert.assertEquals("Expecting multiple // characters to be collapsed.", "/foo/bar", PathManager.path("//foo///bar")); } - /** Test case for {@link daieditor.io.PathManager#absoluteToRelative(String, String)}. */ + /** Test case for {@link PathManager#absoluteToRelative(String, String)}. */ @Test public void testAbsoluteToRelavive() { Assert.assertEquals("../stoneglow/stoneglow_0000", PathManager.absoluteToRelative("/relic/castle_0000", "/stoneglow/stoneglow_0000")); + Assert.assertEquals("../stoneglow/stoneglow_0000", PathManager.absoluteToRelative("/relic/", "/stoneglow/stoneglow_0000")); } - /** Test case for {@link daieditor.io.PathManager#absoluteToRelative(String, String)}. */ + /** Test case for {@link PathManager#absoluteToRelative(String, String)}. */ @Test public void testRelativeToAbsolute() { Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/castle_0000", "../stoneglow/stoneglow_0000")); + Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/", "../stoneglow/stoneglow_0000")); Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/castle_0000", "/stoneglow/stoneglow_0000")); + Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/", "/stoneglow/stoneglow_0000")); } /** Test case for {@link PathManager#isRelative(String)}. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 22:11:08
|
Revision: 1286 http://svn.sourceforge.net/gridarta/?rev=1286&view=rev Author: christianhujer Date: 2006-12-26 14:11:05 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CMainStatusbar to StatusBar for consistent naming. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java Added Paths: ----------- trunk/crossfire/src/cfeditor/StatusBar.java trunk/daimonin/src/daieditor/StatusBar.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CMainStatusbar.java trunk/daimonin/src/daieditor/CMainStatusbar.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-26 18:54:48 UTC (rev 1285) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -1508,7 +1508,7 @@ refreshMenusAndToolbars(); mapCursorControl.refreshMenus(); - //CMainStatusbar.getInstance().setLevelInfo(level); + //StatusBar.getInstance().setLevelInfo(level); fireCurrentMapChangedEvent(); } Deleted: trunk/crossfire/src/cfeditor/CMainStatusbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-12-26 18:54:48 UTC (rev 1285) +++ trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -1,230 +0,0 @@ -/* - * Crossfire 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 cfeditor; - -import cfeditor.gui.map.LevelRenderer; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionListener; -import java.text.NumberFormat; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.BevelBorder; -import net.sf.gridarta.gui.map.MapCursor; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * <code>CMainStatusbar</code> implements the main statusbar of the - * application. Used to show one line text messages to the user about - * progress, state etc. Also includes level info and memory info - * panels. - * @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> - * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> - * @todo Separate labels and methods for mouse coordinates - */ -public final class CMainStatusbar extends JPanel implements MapCursorListener, MouseMotionListener { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** Controller of this statusbar view. */ - private final CMainControl mainControl; - - /** The label that shows the mouse. */ - private final JLabel mouse; - - /** The label that shows the cursor. */ - private final JLabel cursor; - - /** The label that shows the one line text message. */ - private final JLabel status; - - /** The label that shows the memory status. */ - private final JLabel memory; - - /** Temporary used to get map coordinates. */ - private final Point mouseMapTmp = new Point(); - - /** - * Constructs a statusbar that has the given main controller object set - * as its controller. - * @param mainControl The controller of this view. - */ - public CMainStatusbar(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - setBorder(new BevelBorder(BevelBorder.LOWERED)); - - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.anchor = GridBagConstraints.WEST; - gbc.ipadx = 1; - - gbc.weightx = 0.0; - mouse = new JLabel(" "); - mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(mouse, gbc); - - cursor = new JLabel(" "); - cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(cursor, gbc); - - gbc.weightx = 5.0; - status = new JLabel(" "); - status.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(status, gbc); - - gbc.weightx = 0.0; - memory = new JLabel(" "); - memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(memory, gbc); - } - - /** - * Sets the level status text, which usually displays arch numbers. - * @param text String to set - */ - public void setStatusText(final String text) { - status.setText(text); - refresh(); - } - - /** Refreshes the memory usage info panel. */ - void refresh() { - final Runtime runtime = Runtime.getRuntime(); - final long freeMem = runtime.freeMemory(); - final long totMem = runtime.totalMemory(); - final long usedMem = totMem - freeMem; - - memory.setText(ACTION_FACTORY.format("memory", - mainControl.getArchetypeSet().getArchetypeCount(), - mainControl.getFaceObjects().size(), - getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) - )); - } - - /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ - private static final NumberFormat FORMAT = NumberFormat.getInstance(); - - static { - FORMAT.setMinimumFractionDigits(1); - FORMAT.setMaximumFractionDigits(1); - } - - /** The units used by {@link #getMemoryString(long)}. */ - private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; - - /** - * Returns the given memory amount as a string scales the value - * to be bytes, kilobytes or megabytes. - * @param mem memory amount to calculate - * @return String for <var>memory</var> - */ - @Nullable private static String getMemoryString(final long mem) { - for (int i = UNITS.length - 1; i >= 0; i--) { - final int m = 1 << i * 10; - if (mem > m) { - return FORMAT.format((double) mem / m) + UNITS[i]; - } - } - assert false; - return null; - } - - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - /** - * Set coordinates of MapCursor to cursor label and the offset when in drag mode. - * @param mapCursor MapCursor to set coordinates from. - */ - private void mapCursorChanged(final MapCursor mapCursor) { - final String formatCursor; - if (mapCursor.isActive()) { - final Point pos = mapCursor.getLocation(); - assert pos != null; - final int cursorX = pos.x; - final int cursorY = pos.y; - if (mapCursor.isDragging()) { - final Dimension offset = mapCursor.getDragOffset(); - assert offset != null; - final int offsetX = Math.abs(offset.width) + 1; - final int offsetY = Math.abs(offset.height) + 1; - formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); - } else { - formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); - } - } else { - formatCursor = ACTION_FACTORY.format("statusCursorOff"); - } - cursor.setText(formatCursor); - } - - public void mouseDragged(final MouseEvent e) { - mousePosChanged(e); - } - - public void mouseMoved(final MouseEvent e) { - mousePosChanged(e); - } - - /** - * Set new mouse and map coordinates to mouse label. - * @param e Event that was fired from #MapCursor - */ - private void mousePosChanged(final MouseEvent e) { - final Point mousePos = e.getPoint(); - final int mouseX = mousePos.x; - final int mouseY = mousePos.y; - final LevelRenderer renderer = (LevelRenderer) e.getSource(); - final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); - if (mouseMap != null) { - final int mouseMapX = mouseMap.x; - final int mouseMapY = mouseMap.y; - mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); - } else { - mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); - } - } - -} // class CMainStatusbar Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 18:54:48 UTC (rev 1285) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -119,7 +119,7 @@ private static final CMainControl mainControl = CMainControl.getInstance(); /** The main statusbar. */ - private CMainStatusbar statusBar; + private StatusBar statusBar; /** The panel that contains the palette view. */ private CArchPanel archPanel; @@ -215,7 +215,7 @@ pickmapPanel.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); CPickmapPanel.getInstance().addPickmapSelectionListener(pickmapPanel); - statusBar = new CMainStatusbar(mainControl); + statusBar = new StatusBar(mainControl); getContentPane().add(statusBar, BorderLayout.SOUTH); // Build the placeholder for tile palette @@ -919,7 +919,7 @@ } } - public CMainStatusbar getStatusBar() { + public StatusBar getStatusBar() { return statusBar; } Copied: trunk/crossfire/src/cfeditor/StatusBar.java (from rev 1285, trunk/crossfire/src/cfeditor/CMainStatusbar.java) =================================================================== --- trunk/crossfire/src/cfeditor/StatusBar.java (rev 0) +++ trunk/crossfire/src/cfeditor/StatusBar.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -0,0 +1,230 @@ +/* + * Crossfire 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 cfeditor; + +import cfeditor.gui.map.LevelRenderer; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.text.NumberFormat; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * <code>StatusBar</code> implements the main statusbar of the + * application. Used to show one line text messages to the user about + * progress, state etc. Also includes level info and memory info + * panels. + * @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> + * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @todo Separate labels and methods for mouse coordinates + */ +public final class StatusBar extends JPanel implements MapCursorListener, MouseMotionListener { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + /** Controller of this statusbar view. */ + private final CMainControl mainControl; + + /** The label that shows the mouse. */ + private final JLabel mouse; + + /** The label that shows the cursor. */ + private final JLabel cursor; + + /** The label that shows the one line text message. */ + private final JLabel status; + + /** The label that shows the memory status. */ + private final JLabel memory; + + /** Temporary used to get map coordinates. */ + private final Point mouseMapTmp = new Point(); + + /** + * Constructs a statusbar that has the given main controller object set + * as its controller. + * @param mainControl The controller of this view. + */ + public StatusBar(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + setBorder(new BevelBorder(BevelBorder.LOWERED)); + + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.WEST; + gbc.ipadx = 1; + + gbc.weightx = 0.0; + mouse = new JLabel(" "); + mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(mouse, gbc); + + cursor = new JLabel(" "); + cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(cursor, gbc); + + gbc.weightx = 5.0; + status = new JLabel(" "); + status.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(status, gbc); + + gbc.weightx = 0.0; + memory = new JLabel(" "); + memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(memory, gbc); + } + + /** + * Sets the level status text, which usually displays arch numbers. + * @param text String to set + */ + public void setStatusText(final String text) { + status.setText(text); + refresh(); + } + + /** Refreshes the memory usage info panel. */ + void refresh() { + final Runtime runtime = Runtime.getRuntime(); + final long freeMem = runtime.freeMemory(); + final long totMem = runtime.totalMemory(); + final long usedMem = totMem - freeMem; + + memory.setText(ACTION_FACTORY.format("memory", + mainControl.getArchetypeSet().getArchetypeCount(), + mainControl.getFaceObjects().size(), + getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) + )); + } + + /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ + private static final NumberFormat FORMAT = NumberFormat.getInstance(); + + static { + FORMAT.setMinimumFractionDigits(1); + FORMAT.setMaximumFractionDigits(1); + } + + /** The units used by {@link #getMemoryString(long)}. */ + private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; + + /** + * Returns the given memory amount as a string scales the value + * to be bytes, kilobytes or megabytes. + * @param mem memory amount to calculate + * @return String for <var>memory</var> + */ + @Nullable private static String getMemoryString(final long mem) { + for (int i = UNITS.length - 1; i >= 0; i--) { + final int m = 1 << i * 10; + if (mem > m) { + return FORMAT.format((double) mem / m) + UNITS[i]; + } + } + assert false; + return null; + } + + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + /** + * Set coordinates of MapCursor to cursor label and the offset when in drag mode. + * @param mapCursor MapCursor to set coordinates from. + */ + private void mapCursorChanged(final MapCursor mapCursor) { + final String formatCursor; + if (mapCursor.isActive()) { + final Point pos = mapCursor.getLocation(); + assert pos != null; + final int cursorX = pos.x; + final int cursorY = pos.y; + if (mapCursor.isDragging()) { + final Dimension offset = mapCursor.getDragOffset(); + assert offset != null; + final int offsetX = Math.abs(offset.width) + 1; + final int offsetY = Math.abs(offset.height) + 1; + formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); + } else { + formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); + } + } else { + formatCursor = ACTION_FACTORY.format("statusCursorOff"); + } + cursor.setText(formatCursor); + } + + public void mouseDragged(final MouseEvent e) { + mousePosChanged(e); + } + + public void mouseMoved(final MouseEvent e) { + mousePosChanged(e); + } + + /** + * Set new mouse and map coordinates to mouse label. + * @param e Event that was fired from #MapCursor + */ + private void mousePosChanged(final MouseEvent e) { + final Point mousePos = e.getPoint(); + final int mouseX = mousePos.x; + final int mouseY = mousePos.y; + final LevelRenderer renderer = (LevelRenderer) e.getSource(); + final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); + if (mouseMap != null) { + final int mouseMapX = mouseMap.x; + final int mouseMapY = mouseMap.y; + mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); + } else { + mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); + } + } + +} // class StatusBar Property changes on: trunk/crossfire/src/cfeditor/StatusBar.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-26 18:54:48 UTC (rev 1285) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -1698,7 +1698,7 @@ refreshMenusAndToolbars(); mapCursorControl.refreshMenus(); - //CMainStatusbar.getInstance().setLevelInfo(level); + //StatusBar.getInstance().setLevelInfo(level); fireCurrentMapChangedEvent(); } Deleted: trunk/daimonin/src/daieditor/CMainStatusbar.java =================================================================== --- trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-12-26 18:54:48 UTC (rev 1285) +++ trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -1,230 +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.gui.map.LevelRenderer; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionListener; -import java.text.NumberFormat; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.BevelBorder; -import net.sf.gridarta.gui.map.MapCursor; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * <code>CMainStatusbar</code> implements the main statusbar of the - * application. Used to show one line text messages to the user about - * progress, state etc. Also includes level info and memory info - * panels. - * @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> - * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> - * @todo Separate labels and methods for mouse coordinates - */ -public final class CMainStatusbar extends JPanel implements MapCursorListener, MouseMotionListener { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** Controller of this statusbar view. */ - private final CMainControl mainControl; - - /** The label that shows the mouse. */ - private final JLabel mouse; - - /** The label that shows the cursor. */ - private final JLabel cursor; - - /** The label that shows the one line text message. */ - private final JLabel status; - - /** The label that shows the memory status. */ - private final JLabel memory; - - /** Temporary used to get map coordinates. */ - private final Point mouseMapTmp = new Point(); - - /** - * Constructs a statusbar that has the given main controller object set - * as its controller. - * @param mainControl The controller of this view. - */ - public CMainStatusbar(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - setBorder(new BevelBorder(BevelBorder.LOWERED)); - - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.anchor = GridBagConstraints.WEST; - gbc.ipadx = 1; - - gbc.weightx = 0.0; - mouse = new JLabel(" "); - mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(mouse, gbc); - - cursor = new JLabel(" "); - cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(cursor, gbc); - - gbc.weightx = 5.0; - status = new JLabel(" "); - status.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(status, gbc); - - gbc.weightx = 0.0; - memory = new JLabel(" "); - memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(memory, gbc); - } - - /** - * Sets the level status text, which usually displays arch numbers. - * @param text String to set - */ - public void setStatusText(final String text) { - status.setText(text); - refresh(); - } - - /** Refreshes the memory usage info panel. */ - void refresh() { - final Runtime runtime = Runtime.getRuntime(); - final long freeMem = runtime.freeMemory(); - final long totMem = runtime.totalMemory(); - final long usedMem = totMem - freeMem; - - memory.setText(ACTION_FACTORY.format("memory", - mainControl.getArchetypeSet().getArchetypeCount(), - mainControl.getFaceObjects().size(), - getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) - )); - } - - /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ - private static final NumberFormat FORMAT = NumberFormat.getInstance(); - - static { - FORMAT.setMinimumFractionDigits(1); - FORMAT.setMaximumFractionDigits(1); - } - - /** The units used by {@link #getMemoryString(long)}. */ - private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; - - /** - * Returns the given memory amount as a string scales the value - * to be bytes, kilobytes or megabytes. - * @param mem memory amount to calculate - * @return String for <var>memory</var> - */ - @Nullable private static String getMemoryString(final long mem) { - for (int i = UNITS.length - 1; i >= 0; i--) { - final int m = 1 << i * 10; - if (mem > m) { - return FORMAT.format((double) mem / m) + UNITS[i]; - } - } - assert false; - return null; - } - - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - /** - * Set coordinates of MapCursor to cursor label and the offset when in drag mode. - * @param mapCursor MapCursor to set coordinates from. - */ - private void mapCursorChanged(final MapCursor mapCursor) { - final String formatCursor; - if (mapCursor.isActive()) { - final Point pos = mapCursor.getLocation(); - assert pos != null; - final int cursorX = pos.x; - final int cursorY = pos.y; - if (mapCursor.isDragging()) { - final Dimension offset = mapCursor.getDragOffset(); - assert offset != null; - final int offsetX = Math.abs(offset.width) + 1; - final int offsetY = Math.abs(offset.height) + 1; - formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); - } else { - formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); - } - } else { - formatCursor = ACTION_FACTORY.format("statusCursorOff"); - } - cursor.setText(formatCursor); - } - - public void mouseDragged(final MouseEvent e) { - mousePosChanged(e); - } - - public void mouseMoved(final MouseEvent e) { - mousePosChanged(e); - } - - /** - * Set new mouse and map coordinates to mouse label. - * @param e Event that was fired from #MapCursor - */ - private void mousePosChanged(final MouseEvent e) { - final Point mousePos = e.getPoint(); - final int mouseX = mousePos.x; - final int mouseY = mousePos.y; - final LevelRenderer renderer = (LevelRenderer) e.getSource(); - final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); - if (mouseMap != null) { - final int mouseMapX = mouseMap.x; - final int mouseMapY = mouseMap.y; - mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); - } else { - mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); - } - } - -} // class CMainStatusbar Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 18:54:48 UTC (rev 1285) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -121,7 +121,7 @@ private static final CMainControl mainControl = CMainControl.getInstance(); /** The main statusbar. */ - private CMainStatusbar statusBar; + private StatusBar statusBar; /** The panel that contains the palette view. */ public CArchPanel archPanel; @@ -218,7 +218,7 @@ pickmapPanel.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); CPickmapPanel.getInstance().addPickmapSelectionListener(pickmapPanel); - statusBar = new CMainStatusbar(mainControl); + statusBar = new StatusBar(mainControl); archPanel = new CArchPanel(mainControl); mapTileListControl = new MapTileListControl(mainControl, this); mapDesktop = new JDesktopPane(); @@ -824,7 +824,7 @@ rebuildWindowMenu(); } - public CMainStatusbar getStatusBar() { + public StatusBar getStatusBar() { return statusBar; } Copied: trunk/daimonin/src/daieditor/StatusBar.java (from rev 1285, trunk/daimonin/src/daieditor/CMainStatusbar.java) =================================================================== --- trunk/daimonin/src/daieditor/StatusBar.java (rev 0) +++ trunk/daimonin/src/daieditor/StatusBar.java 2006-12-26 22:11:05 UTC (rev 1286) @@ -0,0 +1,230 @@ +/* + * 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.gui.map.LevelRenderer; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.text.NumberFormat; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * <code>StatusBar</code> implements the main statusbar of the + * application. Used to show one line text messages to the user about + * progress, state etc. Also includes level info and memory info + * panels. + * @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> + * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @todo Separate labels and methods for mouse coordinates + */ +public final class StatusBar extends JPanel implements MapCursorListener, MouseMotionListener { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + /** Controller of this statusbar view. */ + private final CMainControl mainControl; + + /** The label that shows the mouse. */ + private final JLabel mouse; + + /** The label that shows the cursor. */ + private final JLabel cursor; + + /** The label that shows the one line text message. */ + private final JLabel status; + + /** The label that shows the memory status. */ + private final JLabel memory; + + /** Temporary used to get map coordinates. */ + private final Point mouseMapTmp = new Point(); + + /** + * Constructs a statusbar that has the given main controller object set + * as its controller. + * @param mainControl The controller of this view. + */ + public StatusBar(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + setBorder(new BevelBorder(BevelBorder.LOWERED)); + + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.WEST; + gbc.ipadx = 1; + + gbc.weightx = 0.0; + mouse = new JLabel(" "); + mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(mouse, gbc); + + cursor = new JLabel(" "); + cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(cursor, gbc); + + gbc.weightx = 5.0; + status = new JLabel(" "); + status.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(status, gbc); + + gbc.weightx = 0.0; + memory = new JLabel(" "); + memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(memory, gbc); + } + + /** + * Sets the level status text, which usually displays arch numbers. + * @param text String to set + */ + public void setStatusText(final String text) { + status.setText(text); + refresh(); + } + + /** Refreshes the memory usage info panel. */ + void refresh() { + final Runtime runtime = Runtime.getRuntime(); + final long freeMem = runtime.freeMemory(); + final long totMem = runtime.totalMemory(); + final long usedMem = totMem - freeMem; + + memory.setText(ACTION_FACTORY.format("memory", + mainControl.getArchetypeSet().getArchetypeCount(), + mainControl.getFaceObjects().size(), + getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) + )); + } + + /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ + private static final NumberFormat FORMAT = NumberFormat.getInstance(); + + static { + FORMAT.setMinimumFractionDigits(1); + FORMAT.setMaximumFractionDigits(1); + } + + /** The units used by {@link #getMemoryString(long)}. */ + private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; + + /** + * Returns the given memory amount as a string scales the value + * to be bytes, kilobytes or megabytes. + * @param mem memory amount to calculate + * @return String for <var>memory</var> + */ + @Nullable private static String getMemoryString(final long mem) { + for (int i = UNITS.length - 1; i >= 0; i--) { + final int m = 1 << i * 10; + if (mem > m) { + return FORMAT.format((double) mem / m) + UNITS[i]; + } + } + assert false; + return null; + } + + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + /** + * Set coordinates of MapCursor to cursor label and the offset when in drag mode. + * @param mapCursor MapCursor to set coordinates from. + */ + private void mapCursorChanged(final MapCursor mapCursor) { + final String formatCursor; + if (mapCursor.isActive()) { + final Point pos = mapCursor.getLocation(); + assert pos != null; + final int cursorX = pos.x; + final int cursorY = pos.y; + if (mapCursor.isDragging()) { + final Dimension offset = mapCursor.getDragOffset(); + assert offset != null; + final int offsetX = Math.abs(offset.width) + 1; + final int offsetY = Math.abs(offset.height) + 1; + formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); + } else { + formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); + } + } else { + formatCursor = ACTION_FACTORY.format("statusCursorOff"); + } + cursor.setText(formatCursor); + } + + public void mouseDragged(final MouseEvent e) { + mousePosChanged(e); + } + + public void mouseMoved(final MouseEvent e) { + mousePosChanged(e); + } + + /** + * Set new mouse and map coordinates to mouse label. + * @param e Event that was fired from #MapCursor + */ + private void mousePosChanged(final MouseEvent e) { + final Point mousePos = e.getPoint(); + final int mouseX = mousePos.x; + final int mouseY = mousePos.y; + final LevelRenderer renderer = (LevelRenderer) e.getSource(); + final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); + if (mouseMap != null) { + final int mouseMapX = mouseMap.x; + final int mouseMapY = mouseMap.y; + mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); + } else { + mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); + } + } + +} // class StatusBar Property changes on: trunk/daimonin/src/daieditor/StatusBar.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 22:13:02
|
Revision: 1287 http://svn.sourceforge.net/gridarta/?rev=1287&view=rev Author: christianhujer Date: 2006-12-26 14:13:00 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Moved StatusBar to gui package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/daimonin/src/daieditor/CMainView.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/StatusBar.java trunk/daimonin/src/daieditor/gui/StatusBar.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/StatusBar.java trunk/daimonin/src/daieditor/StatusBar.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 22:11:05 UTC (rev 1286) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 22:13:00 UTC (rev 1287) @@ -26,6 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.maptilelist.MapTileListControl; +import cfeditor.gui.StatusBar; import cfeditor.map.MapControl; import cfeditor.menu.AggregateMenuLocation; import cfeditor.menu.MenuManager; Deleted: trunk/crossfire/src/cfeditor/StatusBar.java =================================================================== --- trunk/crossfire/src/cfeditor/StatusBar.java 2006-12-26 22:11:05 UTC (rev 1286) +++ trunk/crossfire/src/cfeditor/StatusBar.java 2006-12-26 22:13:00 UTC (rev 1287) @@ -1,230 +0,0 @@ -/* - * Crossfire 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 cfeditor; - -import cfeditor.gui.map.LevelRenderer; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionListener; -import java.text.NumberFormat; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.BevelBorder; -import net.sf.gridarta.gui.map.MapCursor; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * <code>StatusBar</code> implements the main statusbar of the - * application. Used to show one line text messages to the user about - * progress, state etc. Also includes level info and memory info - * panels. - * @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> - * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> - * @todo Separate labels and methods for mouse coordinates - */ -public final class StatusBar extends JPanel implements MapCursorListener, MouseMotionListener { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** Controller of this statusbar view. */ - private final CMainControl mainControl; - - /** The label that shows the mouse. */ - private final JLabel mouse; - - /** The label that shows the cursor. */ - private final JLabel cursor; - - /** The label that shows the one line text message. */ - private final JLabel status; - - /** The label that shows the memory status. */ - private final JLabel memory; - - /** Temporary used to get map coordinates. */ - private final Point mouseMapTmp = new Point(); - - /** - * Constructs a statusbar that has the given main controller object set - * as its controller. - * @param mainControl The controller of this view. - */ - public StatusBar(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - setBorder(new BevelBorder(BevelBorder.LOWERED)); - - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.anchor = GridBagConstraints.WEST; - gbc.ipadx = 1; - - gbc.weightx = 0.0; - mouse = new JLabel(" "); - mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(mouse, gbc); - - cursor = new JLabel(" "); - cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(cursor, gbc); - - gbc.weightx = 5.0; - status = new JLabel(" "); - status.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(status, gbc); - - gbc.weightx = 0.0; - memory = new JLabel(" "); - memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(memory, gbc); - } - - /** - * Sets the level status text, which usually displays arch numbers. - * @param text String to set - */ - public void setStatusText(final String text) { - status.setText(text); - refresh(); - } - - /** Refreshes the memory usage info panel. */ - void refresh() { - final Runtime runtime = Runtime.getRuntime(); - final long freeMem = runtime.freeMemory(); - final long totMem = runtime.totalMemory(); - final long usedMem = totMem - freeMem; - - memory.setText(ACTION_FACTORY.format("memory", - mainControl.getArchetypeSet().getArchetypeCount(), - mainControl.getFaceObjects().size(), - getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) - )); - } - - /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ - private static final NumberFormat FORMAT = NumberFormat.getInstance(); - - static { - FORMAT.setMinimumFractionDigits(1); - FORMAT.setMaximumFractionDigits(1); - } - - /** The units used by {@link #getMemoryString(long)}. */ - private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; - - /** - * Returns the given memory amount as a string scales the value - * to be bytes, kilobytes or megabytes. - * @param mem memory amount to calculate - * @return String for <var>memory</var> - */ - @Nullable private static String getMemoryString(final long mem) { - for (int i = UNITS.length - 1; i >= 0; i--) { - final int m = 1 << i * 10; - if (mem > m) { - return FORMAT.format((double) mem / m) + UNITS[i]; - } - } - assert false; - return null; - } - - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - /** - * Set coordinates of MapCursor to cursor label and the offset when in drag mode. - * @param mapCursor MapCursor to set coordinates from. - */ - private void mapCursorChanged(final MapCursor mapCursor) { - final String formatCursor; - if (mapCursor.isActive()) { - final Point pos = mapCursor.getLocation(); - assert pos != null; - final int cursorX = pos.x; - final int cursorY = pos.y; - if (mapCursor.isDragging()) { - final Dimension offset = mapCursor.getDragOffset(); - assert offset != null; - final int offsetX = Math.abs(offset.width) + 1; - final int offsetY = Math.abs(offset.height) + 1; - formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); - } else { - formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); - } - } else { - formatCursor = ACTION_FACTORY.format("statusCursorOff"); - } - cursor.setText(formatCursor); - } - - public void mouseDragged(final MouseEvent e) { - mousePosChanged(e); - } - - public void mouseMoved(final MouseEvent e) { - mousePosChanged(e); - } - - /** - * Set new mouse and map coordinates to mouse label. - * @param e Event that was fired from #MapCursor - */ - private void mousePosChanged(final MouseEvent e) { - final Point mousePos = e.getPoint(); - final int mouseX = mousePos.x; - final int mouseY = mousePos.y; - final LevelRenderer renderer = (LevelRenderer) e.getSource(); - final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); - if (mouseMap != null) { - final int mouseMapX = mouseMap.x; - final int mouseMapY = mouseMap.y; - mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); - } else { - mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); - } - } - -} // class StatusBar Copied: trunk/crossfire/src/cfeditor/gui/StatusBar.java (from rev 1286, trunk/crossfire/src/cfeditor/StatusBar.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/StatusBar.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/StatusBar.java 2006-12-26 22:13:00 UTC (rev 1287) @@ -0,0 +1,231 @@ +/* + * Crossfire 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 cfeditor.gui; + +import cfeditor.CMainControl; +import cfeditor.gui.map.LevelRenderer; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.text.NumberFormat; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * <code>StatusBar</code> implements the main statusbar of the + * application. Used to show one line text messages to the user about + * progress, state etc. Also includes level info and memory info + * panels. + * @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> + * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @todo Separate labels and methods for mouse coordinates + */ +public final class StatusBar extends JPanel implements MapCursorListener, MouseMotionListener { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + /** Controller of this statusbar view. */ + private final CMainControl mainControl; + + /** The label that shows the mouse. */ + private final JLabel mouse; + + /** The label that shows the cursor. */ + private final JLabel cursor; + + /** The label that shows the one line text message. */ + private final JLabel status; + + /** The label that shows the memory status. */ + private final JLabel memory; + + /** Temporary used to get map coordinates. */ + private final Point mouseMapTmp = new Point(); + + /** + * Constructs a statusbar that has the given main controller object set + * as its controller. + * @param mainControl The controller of this view. + */ + public StatusBar(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + setBorder(new BevelBorder(BevelBorder.LOWERED)); + + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.WEST; + gbc.ipadx = 1; + + gbc.weightx = 0.0; + mouse = new JLabel(" "); + mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(mouse, gbc); + + cursor = new JLabel(" "); + cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(cursor, gbc); + + gbc.weightx = 5.0; + status = new JLabel(" "); + status.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(status, gbc); + + gbc.weightx = 0.0; + memory = new JLabel(" "); + memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(memory, gbc); + } + + /** + * Sets the level status text, which usually displays arch numbers. + * @param text String to set + */ + public void setStatusText(final String text) { + status.setText(text); + refresh(); + } + + /** Refreshes the memory usage info panel. */ + public void refresh() { + final Runtime runtime = Runtime.getRuntime(); + final long freeMem = runtime.freeMemory(); + final long totMem = runtime.totalMemory(); + final long usedMem = totMem - freeMem; + + memory.setText(ACTION_FACTORY.format("memory", + mainControl.getArchetypeSet().getArchetypeCount(), + mainControl.getFaceObjects().size(), + getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) + )); + } + + /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ + private static final NumberFormat FORMAT = NumberFormat.getInstance(); + + static { + FORMAT.setMinimumFractionDigits(1); + FORMAT.setMaximumFractionDigits(1); + } + + /** The units used by {@link #getMemoryString(long)}. */ + private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; + + /** + * Returns the given memory amount as a string scales the value + * to be bytes, kilobytes or megabytes. + * @param mem memory amount to calculate + * @return String for <var>memory</var> + */ + @Nullable private static String getMemoryString(final long mem) { + for (int i = UNITS.length - 1; i >= 0; i--) { + final int m = 1 << i * 10; + if (mem > m) { + return FORMAT.format((double) mem / m) + UNITS[i]; + } + } + assert false; + return null; + } + + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + /** + * Set coordinates of MapCursor to cursor label and the offset when in drag mode. + * @param mapCursor MapCursor to set coordinates from. + */ + private void mapCursorChanged(final MapCursor mapCursor) { + final String formatCursor; + if (mapCursor.isActive()) { + final Point pos = mapCursor.getLocation(); + assert pos != null; + final int cursorX = pos.x; + final int cursorY = pos.y; + if (mapCursor.isDragging()) { + final Dimension offset = mapCursor.getDragOffset(); + assert offset != null; + final int offsetX = Math.abs(offset.width) + 1; + final int offsetY = Math.abs(offset.height) + 1; + formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); + } else { + formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); + } + } else { + formatCursor = ACTION_FACTORY.format("statusCursorOff"); + } + cursor.setText(formatCursor); + } + + public void mouseDragged(final MouseEvent e) { + mousePosChanged(e); + } + + public void mouseMoved(final MouseEvent e) { + mousePosChanged(e); + } + + /** + * Set new mouse and map coordinates to mouse label. + * @param e Event that was fired from #MapCursor + */ + private void mousePosChanged(final MouseEvent e) { + final Point mousePos = e.getPoint(); + final int mouseX = mousePos.x; + final int mouseY = mousePos.y; + final LevelRenderer renderer = (LevelRenderer) e.getSource(); + final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); + if (mouseMap != null) { + final int mouseMapX = mouseMap.x; + final int mouseMapY = mouseMap.y; + mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); + } else { + mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); + } + } + +} // class StatusBar Property changes on: trunk/crossfire/src/cfeditor/gui/StatusBar.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 22:11:05 UTC (rev 1286) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 22:13:00 UTC (rev 1287) @@ -26,6 +26,7 @@ import daieditor.gameobject.GameObject; import daieditor.gui.AboutDialog; +import daieditor.gui.StatusBar; import daieditor.gui.maptilelist.MapTileListControl; import daieditor.map.MapControl; import daieditor.map.validation.ErrorCollector; Deleted: trunk/daimonin/src/daieditor/StatusBar.java =================================================================== --- trunk/daimonin/src/daieditor/StatusBar.java 2006-12-26 22:11:05 UTC (rev 1286) +++ trunk/daimonin/src/daieditor/StatusBar.java 2006-12-26 22:13:00 UTC (rev 1287) @@ -1,230 +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.gui.map.LevelRenderer; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionListener; -import java.text.NumberFormat; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.BevelBorder; -import net.sf.gridarta.gui.map.MapCursor; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * <code>StatusBar</code> implements the main statusbar of the - * application. Used to show one line text messages to the user about - * progress, state etc. Also includes level info and memory info - * panels. - * @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> - * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> - * @todo Separate labels and methods for mouse coordinates - */ -public final class StatusBar extends JPanel implements MapCursorListener, MouseMotionListener { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** Controller of this statusbar view. */ - private final CMainControl mainControl; - - /** The label that shows the mouse. */ - private final JLabel mouse; - - /** The label that shows the cursor. */ - private final JLabel cursor; - - /** The label that shows the one line text message. */ - private final JLabel status; - - /** The label that shows the memory status. */ - private final JLabel memory; - - /** Temporary used to get map coordinates. */ - private final Point mouseMapTmp = new Point(); - - /** - * Constructs a statusbar that has the given main controller object set - * as its controller. - * @param mainControl The controller of this view. - */ - public StatusBar(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - setBorder(new BevelBorder(BevelBorder.LOWERED)); - - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.anchor = GridBagConstraints.WEST; - gbc.ipadx = 1; - - gbc.weightx = 0.0; - mouse = new JLabel(" "); - mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(mouse, gbc); - - cursor = new JLabel(" "); - cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(cursor, gbc); - - gbc.weightx = 5.0; - status = new JLabel(" "); - status.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(status, gbc); - - gbc.weightx = 0.0; - memory = new JLabel(" "); - memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); - add(memory, gbc); - } - - /** - * Sets the level status text, which usually displays arch numbers. - * @param text String to set - */ - public void setStatusText(final String text) { - status.setText(text); - refresh(); - } - - /** Refreshes the memory usage info panel. */ - void refresh() { - final Runtime runtime = Runtime.getRuntime(); - final long freeMem = runtime.freeMemory(); - final long totMem = runtime.totalMemory(); - final long usedMem = totMem - freeMem; - - memory.setText(ACTION_FACTORY.format("memory", - mainControl.getArchetypeSet().getArchetypeCount(), - mainControl.getFaceObjects().size(), - getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) - )); - } - - /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ - private static final NumberFormat FORMAT = NumberFormat.getInstance(); - - static { - FORMAT.setMinimumFractionDigits(1); - FORMAT.setMaximumFractionDigits(1); - } - - /** The units used by {@link #getMemoryString(long)}. */ - private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; - - /** - * Returns the given memory amount as a string scales the value - * to be bytes, kilobytes or megabytes. - * @param mem memory amount to calculate - * @return String for <var>memory</var> - */ - @Nullable private static String getMemoryString(final long mem) { - for (int i = UNITS.length - 1; i >= 0; i--) { - final int m = 1 << i * 10; - if (mem > m) { - return FORMAT.format((double) mem / m) + UNITS[i]; - } - } - assert false; - return null; - } - - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); - } - - /** - * Set coordinates of MapCursor to cursor label and the offset when in drag mode. - * @param mapCursor MapCursor to set coordinates from. - */ - private void mapCursorChanged(final MapCursor mapCursor) { - final String formatCursor; - if (mapCursor.isActive()) { - final Point pos = mapCursor.getLocation(); - assert pos != null; - final int cursorX = pos.x; - final int cursorY = pos.y; - if (mapCursor.isDragging()) { - final Dimension offset = mapCursor.getDragOffset(); - assert offset != null; - final int offsetX = Math.abs(offset.width) + 1; - final int offsetY = Math.abs(offset.height) + 1; - formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); - } else { - formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); - } - } else { - formatCursor = ACTION_FACTORY.format("statusCursorOff"); - } - cursor.setText(formatCursor); - } - - public void mouseDragged(final MouseEvent e) { - mousePosChanged(e); - } - - public void mouseMoved(final MouseEvent e) { - mousePosChanged(e); - } - - /** - * Set new mouse and map coordinates to mouse label. - * @param e Event that was fired from #MapCursor - */ - private void mousePosChanged(final MouseEvent e) { - final Point mousePos = e.getPoint(); - final int mouseX = mousePos.x; - final int mouseY = mousePos.y; - final LevelRenderer renderer = (LevelRenderer) e.getSource(); - final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); - if (mouseMap != null) { - final int mouseMapX = mouseMap.x; - final int mouseMapY = mouseMap.y; - mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); - } else { - mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); - } - } - -} // class StatusBar Copied: trunk/daimonin/src/daieditor/gui/StatusBar.java (from rev 1286, trunk/daimonin/src/daieditor/StatusBar.java) =================================================================== --- trunk/daimonin/src/daieditor/gui/StatusBar.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/StatusBar.java 2006-12-26 22:13:00 UTC (rev 1287) @@ -0,0 +1,231 @@ +/* + * 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.gui; + +import daieditor.CMainControl; +import daieditor.gui.map.LevelRenderer; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.text.NumberFormat; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * <code>StatusBar</code> implements the main statusbar of the + * application. Used to show one line text messages to the user about + * progress, state etc. Also includes level info and memory info + * panels. + * @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> + * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @todo Separate labels and methods for mouse coordinates + */ +public final class StatusBar extends JPanel implements MapCursorListener, MouseMotionListener { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + /** Controller of this statusbar view. */ + private final CMainControl mainControl; + + /** The label that shows the mouse. */ + private final JLabel mouse; + + /** The label that shows the cursor. */ + private final JLabel cursor; + + /** The label that shows the one line text message. */ + private final JLabel status; + + /** The label that shows the memory status. */ + private final JLabel memory; + + /** Temporary used to get map coordinates. */ + private final Point mouseMapTmp = new Point(); + + /** + * Constructs a statusbar that has the given main controller object set + * as its controller. + * @param mainControl The controller of this view. + */ + public StatusBar(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + setBorder(new BevelBorder(BevelBorder.LOWERED)); + + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.WEST; + gbc.ipadx = 1; + + gbc.weightx = 0.0; + mouse = new JLabel(" "); + mouse.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(mouse, gbc); + + cursor = new JLabel(" "); + cursor.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(cursor, gbc); + + gbc.weightx = 5.0; + status = new JLabel(" "); + status.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(status, gbc); + + gbc.weightx = 0.0; + memory = new JLabel(" "); + memory.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(memory, gbc); + } + + /** + * Sets the level status text, which usually displays arch numbers. + * @param text String to set + */ + public void setStatusText(final String text) { + status.setText(text); + refresh(); + } + + /** Refreshes the memory usage info panel. */ + public void refresh() { + final Runtime runtime = Runtime.getRuntime(); + final long freeMem = runtime.freeMemory(); + final long totMem = runtime.totalMemory(); + final long usedMem = totMem - freeMem; + + memory.setText(ACTION_FACTORY.format("memory", + mainControl.getArchetypeSet().getArchetypeCount(), + mainControl.getFaceObjects().size(), + getMemoryString(usedMem), getMemoryString(freeMem), getMemoryString(totMem) + )); + } + + /** The DecimalFormat to use for formatting the numbers in {@link #getMemoryString(long)}.. */ + private static final NumberFormat FORMAT = NumberFormat.getInstance(); + + static { + FORMAT.setMinimumFractionDigits(1); + FORMAT.setMaximumFractionDigits(1); + } + + /** The units used by {@link #getMemoryString(long)}. */ + private static final String[] UNITS = {"Bytes", "KB", "MB", "GB"}; + + /** + * Returns the given memory amount as a string scales the value + * to be bytes, kilobytes or megabytes. + * @param mem memory amount to calculate + * @return String for <var>memory</var> + */ + @Nullable private static String getMemoryString(final long mem) { + for (int i = UNITS.length - 1; i >= 0; i--) { + final int m = 1 << i * 10; + if (mem > m) { + return FORMAT.format((double) mem / m) + UNITS[i]; + } + } + assert false; + return null; + } + + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + mapCursorChanged(e.getSource()); + } + + /** + * Set coordinates of MapCursor to cursor label and the offset when in drag mode. + * @param mapCursor MapCursor to set coordinates from. + */ + private void mapCursorChanged(final MapCursor mapCursor) { + final String formatCursor; + if (mapCursor.isActive()) { + final Point pos = mapCursor.getLocation(); + assert pos != null; + final int cursorX = pos.x; + final int cursorY = pos.y; + if (mapCursor.isDragging()) { + final Dimension offset = mapCursor.getDragOffset(); + assert offset != null; + final int offsetX = Math.abs(offset.width) + 1; + final int offsetY = Math.abs(offset.height) + 1; + formatCursor = ACTION_FACTORY.format("statusSelect", cursorX, cursorY, offsetX, offsetY); + } else { + formatCursor = ACTION_FACTORY.format("statusNormal", cursorX, cursorY); + } + } else { + formatCursor = ACTION_FACTORY.format("statusCursorOff"); + } + cursor.setText(formatCursor); + } + + public void mouseDragged(final MouseEvent e) { + mousePosChanged(e); + } + + public void mouseMoved(final MouseEvent e) { + mousePosChanged(e); + } + + /** + * Set new mouse and map coordinates to mouse label. + * @param e Event that was fired from #MapCursor + */ + private void mousePosChanged(final MouseEvent e) { + final Point mousePos = e.getPoint(); + final int mouseX = mousePos.x; + final int mouseY = mousePos.y; + final LevelRenderer renderer = (LevelRenderer) e.getSource(); + final Point mouseMap = renderer.getTileLocationAt(mousePos, mouseMapTmp); + if (mouseMap != null) { + final int mouseMapX = mouseMap.x; + final int mouseMapY = mouseMap.y; + mouse.setText(ACTION_FACTORY.format("statusMouseOn", mouseX, mouseY, mouseMapX, mouseMapY)); + } else { + mouse.setText(ACTION_FACTORY.format("statusMouseOff", mouseX, mouseY)); + } + } + +} // class StatusBar Property changes on: trunk/daimonin/src/daieditor/gui/StatusBar.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 22:20:12
|
Revision: 1288 http://svn.sourceforge.net/gridarta/?rev=1288&view=rev Author: christianhujer Date: 2006-12-26 14:20:12 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed MapTileList to SelectedSquare Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java trunk/daimonin/src/daieditor/gui/selectedsquare/CellRenderer.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/selectedsquare/ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java trunk/daimonin/src/daieditor/gui/selectedsquare/ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/maptilelist/ trunk/crossfire/src/cfeditor/gui/selectedsquare/MapTileListControl.java trunk/crossfire/src/cfeditor/gui/selectedsquare/MapTileListView.java trunk/daimonin/src/daieditor/gui/maptilelist/ trunk/daimonin/src/daieditor/gui/selectedsquare/MapTileListControl.java trunk/daimonin/src/daieditor/gui/selectedsquare/MapTileListView.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 22:13:00 UTC (rev 1287) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -25,8 +25,8 @@ package cfeditor; import cfeditor.gameobject.GameObject; -import cfeditor.gui.maptilelist.MapTileListControl; import cfeditor.gui.StatusBar; +import cfeditor.gui.selectedsquare.SelectedSquareControl; import cfeditor.map.MapControl; import cfeditor.menu.AggregateMenuLocation; import cfeditor.menu.MenuManager; @@ -141,7 +141,7 @@ private final List<MapViewIFrame> mapViews = new ArrayList<MapViewIFrame>(); /** List of objects on map (right side). */ - private MapTileListControl mapTileListControl; + private SelectedSquareControl selectedSquareControl; /** Attributes panel (bottom). */ private CMapArchPanel mapArchPanel; @@ -221,12 +221,12 @@ // Build the placeholder for tile palette archPanel = new CArchPanel(mainControl); - mapTileListControl = new MapTileListControl(mainControl, this); + selectedSquareControl = new SelectedSquareControl(mainControl, this); mapDesktop = new JDesktopPane(); if (!mapTileListBottom) { // the map tile list is on the right side - splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapDesktop, mapTileListControl.getMapTileListView()); + splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapDesktop, selectedSquareControl.getMapTileListView()); splitRightPane.setDividerLocation(divLocationRight); splitRightPane.setDividerSize(BORDER_SIZE); @@ -249,7 +249,7 @@ } else { // the map tile list is merged into the bottom panel mapArchPanel = new CMapArchPanel(mainControl, this); - splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, mapTileListControl.getMapTileListView()); + splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, selectedSquareControl.getMapTileListView()); splitRightPane.setDividerLocation(divLocationRight); splitRightPane.setDividerSize(BORDER_SIZE); @@ -376,7 +376,7 @@ } public GameObject getMapTileSelection() { - return mapTileListControl.getMapTileSelection(); + return selectedSquareControl.getMapTileSelection(); } /** @@ -509,7 +509,7 @@ // set bounds to maximum size if (!mapTileListBottom) { - mapView.setBounds(0, 0, mapTileListControl.getMapTileListView().getX() - BORDER_SIZE - 2, mapArchPanel.getY() - BORDER_SIZE - 4); + mapView.setBounds(0, 0, selectedSquareControl.getMapTileListView().getX() - BORDER_SIZE - 2, mapArchPanel.getY() - BORDER_SIZE - 4); } else { mapView.setBounds(0, 0, mapDesktop.getWidth() - 2, mapDesktop.getHeight() - 2); } @@ -933,8 +933,8 @@ MenuManager.getMenuManager().addMenuLocation(currentmapLocation); } - public MapTileListControl getMapTileListControl() { - return mapTileListControl; + public SelectedSquareControl getMapTileListControl() { + return selectedSquareControl; } private final class LookAndFeelAction extends AbstractAction { Modified: trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-26 22:13:00 UTC (rev 1287) +++ trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -25,7 +25,7 @@ import cfeditor.CMainView; import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; -import cfeditor.gui.maptilelist.MapTileListControl; +import cfeditor.gui.selectedsquare.SelectedSquareControl; import cfeditor.map.MapControl; import java.awt.Point; import javax.swing.Action; @@ -145,17 +145,17 @@ public void insertArch() { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); - assert mapTileListControl != null; - mapTileListControl.insertGameObjectFromArchPanel(); + final SelectedSquareControl selectedSquareControl = mainView.getMapTileListControl(); + assert selectedSquareControl != null; + selectedSquareControl.insertGameObjectFromArchPanel(); } public void deleteArch() { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); - assert mapTileListControl != null; - mapTileListControl.deleteSelection(); + final SelectedSquareControl selectedSquareControl = mainView.getMapTileListControl(); + assert selectedSquareControl != null; + selectedSquareControl.deleteSelection(); } private void selectTile(final MapGrid.SelectionMode mode) { @@ -200,12 +200,12 @@ if (getMapCursor().isActive()) { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); - assert mapTileListControl != null; + final SelectedSquareControl selectedSquareControl = mainView.getMapTileListControl(); + assert selectedSquareControl != null; if (above) { - mapTileListControl.selectArchAbove(); + selectedSquareControl.selectArchAbove(); } else { - mapTileListControl.selectArchBelow(); + selectedSquareControl.selectArchBelow(); } } } @@ -214,9 +214,9 @@ if (getMapCursor().isActive()) { final CMainView mainView = mainControl.getMainView(); assert mainView != null; - final MapTileListControl mapTileListControl = mainView.getMapTileListControl(); - assert mapTileListControl != null; - final GameObject arch = mapTileListControl.getMapTileSelection(); + final SelectedSquareControl selectedSquareControl = mainView.getMapTileListControl(); + assert selectedSquareControl != null; + final GameObject arch = selectedSquareControl.getMapTileSelection(); if (arch != null) { mainControl.openAttrDialog(arch); } Copied: trunk/crossfire/src/cfeditor/gui/selectedsquare (from rev 1287, trunk/crossfire/src/cfeditor/gui/maptilelist) Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/CellRenderer.java 2006-12-26 22:13:00 UTC (rev 1287) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -20,7 +20,7 @@ * 02111-1307, USA. */ -package cfeditor.gui.maptilelist; +package cfeditor.gui.selectedsquare; import cfeditor.CMainControl; import cfeditor.gameobject.ArchetypeSet; Deleted: trunk/crossfire/src/cfeditor/gui/selectedsquare/MapTileListControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListControl.java 2006-12-26 22:13:00 UTC (rev 1287) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/MapTileListControl.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -1,262 +0,0 @@ -/* - * 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.CMainControl; -import cfeditor.CMainView; -import cfeditor.IGUIConstants; -import cfeditor.gameobject.GameObject; -import cfeditor.map.MapControl; -import cfeditor.map.MapModel; -import java.awt.Point; -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.awt.event.MouseListener; -import java.util.Date; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import net.sf.gridarta.map.MapSquare; -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 { - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final CMainView mainView; - - /** - * 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 view for this controller. */ - private final MapTileListView view; - - /** - * 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; - - view = new MapTileListView(this, mainControl, mainView.isMapTileListBottom()); - } - - ActionListener getButtonDownActionListener() { - return new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final GameObject arch = getMapTileSelection(); - if (arch != null) { - arch.moveDown(); - } - } - }; - } - - ActionListener getButtonUpActionListener() { - return new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final GameObject arch = getMapTileSelection(); - if (arch != null) { - arch.moveUp(); - } - } - }; - } - - ListSelectionListener getListSelectionListener() { - return new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - mainView.setMapArchPanelObject(getMapTileSelection()); - } - }; - } - - MouseListener getMouseListener() { - return new MouseAdapter() { - @Override public void mousePressed(final MouseEvent e) { - if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { - // --- 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) { - // --- right mouse button: insert arch --- - insertGameObjectFromArchPanel(view.getListIndex(e)); - } else { - // --- middle mouse button: delete arch --- - deleteIndex(view.getListIndex(e)); - } - } - }; - } - - public void selectArchBelow() { - view.setSelectedIndex(view.getSelectedIndex() + 1); - } - - public void selectArchAbove() { - view.setSelectedIndex(view.getSelectedIndex() - 1); - } - - /** - * Return the currently selected GameObject within this list (currently selected MapSquare). - * @return the currently selected GameObject - */ - @Nullable public GameObject getMapTileSelection() { - return view.getMapTileSelection(); - } - - /** - * Delete the currently selected game object. - */ - public void deleteSelection() { - deleteIndex(view.getSelectedIndex()); - } - - /** - * Delete an GameObject with a specific list index. - * @param index List index of GameObject - */ - private void deleteIndex(final int index) { - if (index < 0 || index >= view.getModelSize()) { - return; - } - - final MapControl mapControl = view.getCurrentMapControl(); - if (mapControl == null) { - return; - } - - final MapSquare<GameObject> mapSquare = view.getCurrentMapSquare(); - if (mapSquare == null) { - return; - } - - mapControl.getMapModel().beginTransaction("Delete"); // TODO; I18N/L10N - final GameObject entry = view.getListGameObject(index); - if (entry != null) { - mapControl.deleteMapArch(entry, new Point(mapSquare.getMapX(), mapSquare.getMapY()), MapModel.JOIN_ENABLE); - - if (index + 1 < view.getModelSize()) { - view.setSelectedGameObject(view.getListGameObject(index + 1)); - } else if (index > 0) { - view.setSelectedGameObject(view.getListGameObject(index - 1)); - } else { - view.setSelectedGameObject(null); - } - } - mapControl.getMapModel().endTransaction(); - } - - /** - * Insert a new game object. - */ - public void insertGameObjectFromArchPanel() { - insertGameObjectFromArchPanel(view.getSelectedIndex()); - } - - /** - * Insert a new game object. - * - * @param index the list index to insert at - */ - public void insertGameObjectFromArchPanel(final int index) { - final GameObject gameObject = mainControl.getArchPanelHighlight(); - if (gameObject == null) { - return; - } - - final MapControl currentMapControl = view.getCurrentMapControl(); - if (currentMapControl == null) { - return; - } - - final MapSquare<GameObject> currentMapSquare = view.getCurrentMapSquare(); - if (currentMapSquare == null) { - return; - } - - currentMapControl.getMapModel().beginTransaction("Insert"); // TODO; I18N/L10N - final GameObject insertedGameObject; - if (index >= view.getModelSize()) { - insertedGameObject = currentMapControl.insertArchToMap(gameObject, mainControl.getPanelArchName(), null, new Point(currentMapSquare.getMapX(), currentMapSquare.getMapY()), MapModel.JOIN_ENABLE); - } else { - final GameObject entry = view.getListGameObject(index); - insertedGameObject = currentMapControl.insertArchToMap(gameObject, mainControl.getPanelArchName(), entry, new Point(currentMapSquare.getMapX(), currentMapSquare.getMapY()), MapModel.JOIN_ENABLE); - } - view.setSelectedGameObject(insertedGameObject); - currentMapControl.getMapModel().endTransaction(); - - // refresh - currentMapControl.setLevelChangedFlag(); // the map has been modified - } - - /** - * 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) { - - // refresh the MapArchPanel to display the new arch - mainView.refreshMapArchPanel(); - } - - /** - * Return the view for this controller. - * - * @return the view for this controller - */ - public MapTileListView getMapTileListView() { - return view; - } - -} // class MapTileListControl Deleted: trunk/crossfire/src/cfeditor/gui/selectedsquare/MapTileListView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java 2006-12-26 22:13:00 UTC (rev 1287) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/MapTileListView.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -1,526 +0,0 @@ -/* - * 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.IGUIConstants; -import cfeditor.gameobject.GameObject; -import cfeditor.map.MapControl; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.GridLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; -import javax.swing.BorderFactory; -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.ListSelectionModel; -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 net.sf.gridarta.MainControlListener; -import net.sf.gridarta.gui.map.MapCursorEvent; -import net.sf.gridarta.gui.map.MapCursorListener; -import net.sf.gridarta.gui.maptilelist.MapTileSelection; -import net.sf.gridarta.gui.maptilelist.MapTileSelectionCache; -import net.sf.gridarta.map.MapModelEvent; -import net.sf.gridarta.map.MapModelListener; -import net.sf.gridarta.map.MapSquare; -import org.apache.log4j.Logger; -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 MapTileListView extends JPanel implements MainControlListener<MapControl>, MapCursorListener, MapModelListener<GameObject> { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(MapTileListView.class); - - /** The main control for this view. */ - @NotNull final CMainControl mainControl; - - /** The "Import..." button. */ - private final JList list; - - private final DefaultListModel model; - - private int listCounter = 0; - - /** - * The cache to store selections for each map control. - */ - @NotNull private final MapTileSelectionCache<GameObject, MapControl> mapTileSelectionCache = new MapTileSelectionCache<GameObject, MapControl>(); - - /** - * The currently selected map tile. - */ - @Nullable private MapTileSelection<GameObject, MapControl> selectedMapTile = null; - - /** - * Create a new instance. - * - * @param control the controller for this view - * - * @param mainControl the main controller for this view - * - * @param mapTileListBottom set if the map tile list should be at the - * bottom or on the top of the main view - */ - MapTileListView(@NotNull final MapTileListControl control, @NotNull final CMainControl mainControl, final boolean mapTileListBottom) { - this.mainControl = mainControl; - - setLayout(new BorderLayout()); - - model = new DefaultListModel(); - list = new JList(model); - list.setCellRenderer(new CellRenderer(mainControl.getArchetypeSet())); - list.setBackground(Color.lightGray); - list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - 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 (mapTileListBottom) { - 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 (!mapTileListBottom) { - 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, control.getButtonDownActionListener()); - buttonDown.setVerticalTextPosition(SwingConstants.BOTTOM); - buttonDown.setHorizontalTextPosition(SwingConstants.CENTER); - if (!mapTileListBottom) { - arrows.add(buttonDown, BorderLayout.EAST); - } - - final CFancyButton buttonUp = new CFancyButton(null, "Move Tile Position Up", IGUIConstants.MOVE_UP_ICON, control.getButtonUpActionListener()); - buttonUp.setVerticalTextPosition(SwingConstants.BOTTOM); - buttonUp.setHorizontalTextPosition(SwingConstants.CENTER); - if (!mapTileListBottom) { - arrows.add(buttonUp, BorderLayout.WEST); - } else { - arrows.add(buttonUp); - arrows.add(buttonDown); - } - - list.addListSelectionListener(control.getListSelectionListener()); - - /** - * listen for mouse events in the panel - */ - list.addMouseListener(control.getMouseListener()); - - mainControl.addMainControlListener(this); - } - - /** - * Return the currently selected map control. - * - * @return the currently selected map control, or <code>null</code> if no - * tile is selected - */ - @Nullable public MapControl getCurrentMapControl() { - return selectedMapTile == null ? null : selectedMapTile.getMapControl(); - } - - /** - * Return the currently selected map square. - * - * @return the currently selected map square, or <code>null</code> if no - * tile is selected - */ - @Nullable public MapSquare<GameObject> getCurrentMapSquare() { - return selectedMapTile == null ? null : selectedMapTile.getMapSquare(); - } - - /** - * 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 - */ - int getListIndex(final MouseEvent e) { - final int lastIndex = getModelSize() - 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() { - final GameObject gameObject = (GameObject) list.getSelectedValue(); - - if (selectedMapTile != null) { - selectedMapTile.setGameObject(gameObject); - selectedMapTile.setIndex(list.getSelectedIndex()); - } - - return gameObject; - } - - /** - * Re-display the map tile panel for {@link #selectedMapTile}. Possibly updates - * information in <code>selectedMapTile</code>. - */ - private void refresh() { - final MapControl mapControl; - final MapSquare<GameObject> mapSquare; - final GameObject gameObject; - if (selectedMapTile == null) { - mapControl = null; - mapSquare = null; - gameObject = null; - } else { - mapControl = selectedMapTile.getMapControl(); - mapSquare = selectedMapTile.getMapSquare(); - gameObject = selectedMapTile.getGameObject(); - } - - list.setEnabled(false); - model.removeAllElements(); - if (mapControl == null) { - list.setSelectedIndex(0); - list.setEnabled(true); - return; - } - - listCounter = 0; - int postSelect = -1; - boolean foundSIndex = false; - int sIndex = -1; - - // Now go through the list backwards and put all arches - // on the panel in this order - if (mapSquare != null) { - for (final GameObject node : mapSquare.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) { - setSelectedIndex(postSelect); - } else if (sIndex != -1) { - // Per default, the topmost arch matching the view settings is selected. - // (With no view settings applied, the very topmost arch is selected.) - setSelectedIndex(sIndex); - } else if (selectedMapTile != null){ - // use last known good index - setSelectedIndex(selectedMapTile.getIndex()); - } else { - setSelectedIndex(0); - } - - list.setEnabled(true); - } - - /** - * Add inventory objects to an arch in the MapTileListView recursively. - * @param node the arch where the inventory gets added - * @param gameObject selected GameObject - * @return <code>listCounter</code> for <var>gameObject</var>, or <code>-1</code> if not found - */ - private int addInvObjects(final GameObject node, final GameObject gameObject) { - int selListCounter = -1; - for (final GameObject invObject : node.getHead().reverse()) { - 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 currentMapChanged(@Nullable final MapControl mapControl) { - if (setSelectedMapTile(mapTileSelectionCache.findOrCreate(mapControl))) { - refresh(); - } - } - - /** {@inheritDoc} */ - public void mapCreated(@NotNull final MapControl mapControl) { - mapControl.addMapCursorListener(this); - mapControl.addMapModelListener(this); - } - - /** {@inheritDoc} */ - public void mapClosing(@NotNull final MapControl mapControl) { - mapControl.removeMapModelListener(this); - mapControl.removeMapCursorListener(this); - - final MapTileSelection<GameObject, MapControl> closedMapTile = mapTileSelectionCache.find(mapControl); - if (selectedMapTile != null && selectedMapTile == closedMapTile) { - if (setSelectedMapTile(null)) { - refresh(); - } - } - } - - /** {@inheritDoc} */ - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - if (selectedMapTile == null) { - return; - } - - final MapControl mapControl = selectedMapTile.getMapControl(); - - final Point cursorPos = e.getSource().getLocation(); - if (cursorPos == null || !mapControl.isPointValid(cursorPos)) { - if (setSelectedMapSquare(null)) { - refresh(); - } - return; - } - - final MapSquare mapSquare = mapControl.getMapModel().getMapSquare(cursorPos); - if (setSelectedMapSquare(mapSquare)) { - refresh(); - } - } - - /** {@inheritDoc} */ - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - // ignore - } - - /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent<GameObject> e) { - if (selectedMapTile != null && selectedMapTile.getMapControl().getMapModel() == e.getMapModel() && selectedMapTile.validateMapSquare()) { - refresh(); - } - } - - /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent<GameObject> e) { - if (selectedMapTile == null) { - return; - } - - for (final MapSquare mapSquare : e.getSquares()) { - if (selectedMapTile.checkForChangedMapSquare(mapSquare)) { - refresh(); - break; - } - } - } - - /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent<GameObject> e) { - if (selectedMapTile == null) { - return; - } - - for (final GameObject gameObject : e.getGameObjects()) { - final MapSquare mapSquare = gameObject.getMapSquare(); - if (mapSquare != null && selectedMapTile.checkForChangedMapSquare(mapSquare)) { - refresh(); - break; - } - } - } - - /** - * Set a map tile selection. - * - * @param mapTileSelection Selection that's made. - * - * @return <code>true</code> if the selected map tile has changed - */ - private boolean setSelectedMapTile(@Nullable final MapTileSelection<GameObject, MapControl> mapTileSelection) { - if (mapTileSelection == selectedMapTile) { - return false; - } - - selectedMapTile = mapTileSelection; - return true; - } - - /** - * Set the currently selected map square. - * - * @param mapSquare the selected map square - * - * @return <code>true</code> if the state has changed - */ - private boolean setSelectedMapSquare(@Nullable final MapSquare mapSquare) { - if (selectedMapTile == null) { - return false; - } - - return selectedMapTile.setMapSquare(mapSquare); - } - - /** - * Return a game object from the list. - * - * @param index the index in the list - * - * @return the game object, or <code>null</code> if the index is invalid - */ - @Nullable GameObject getListGameObject(final int index) { - final int actualIndex = getValidIndex(index); - return actualIndex < model.getSize() ? (GameObject) model.getElementAt(actualIndex) : null; - } - - /** - * Return the number of currently shown game objects. - * - * @return the number of currently shown game objects - */ - int getModelSize() { - return model.getSize(); - } - - /** - * Set the selected game object. - * - * @param gameObject the game object to select, or <code>null</code> to - * unselect it - */ - void setSelectedGameObject(@Nullable final GameObject gameObject) { - if (selectedMapTile == null) { - return; - } - - if (gameObject != null) { - final MapSquare<GameObject> mapSquare = gameObject.getTopContainer().getMapSquare(); - if (mapSquare == null) { - log.warn("setSelectedGameObject: gameObject " + gameObject + " is not part of a map"); - return; - } - if (selectedMapTile.getMapControl().getMapModel() != mapSquare.getModel()) { - return; - } - - setSelectedMapSquare(mapSquare); - } - - selectedMapTile.setGameObject(gameObject); - } - - /** - * Return the currently selected list index. - * - * @return the currently selected list index - */ - int getSelectedIndex() { - return list.getSelectedIndex(); - } - - /** - * Set the currently selected list index. If an invalid index is given, the - * nearest valid index is used instead. - * - * @param index the index to select - */ - void setSelectedIndex(final int index) { - final int actualIndex = getValidIndex(index); - list.setSelectedIndex(actualIndex); - if (selectedMapTile != null) { - selectedMapTile.setIndex(actualIndex); - } - } - - /** - * Determine a valid list index near a given index. - * - * @param index the index to look up - * - * @return a valid index, or 0 if the list is empty - */ - private int getValidIndex(final int index) { - if (index < 0) { - return 0; - } - if (index >= getModelSize()) { - return Math.max(0, getModelSize() - 1); - } - return index; - } - -} // class MapTileListView Added: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -0,0 +1,262 @@ +/* + * 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.selectedsquare; + +import cfeditor.CMainControl; +import cfeditor.CMainView; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; +import cfeditor.map.MapControl; +import cfeditor.map.MapModel; +import java.awt.Point; +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.awt.event.MouseListener; +import java.util.Date; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import net.sf.gridarta.map.MapSquare; +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 SelectedSquareControl { + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final CMainView mainView; + + /** + * 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 view for this controller. */ + private final SelectedSquareView view; + + /** + * Create a SelectedSquareControl. + * @param mainControl MainControl, used for icons + * @param mainView MainView, used for updating UI + */ + public SelectedSquareControl(final CMainControl mainControl, final CMainView mainView) { + this.mainControl = mainControl; + this.mainView = mainView; + + view = new SelectedSquareView(this, mainControl, mainView.isMapTileListBottom()); + } + + ActionListener getButtonDownActionListener() { + return new ActionListener() { + public void actionPerformed(final ActionEvent e) { + final GameObject arch = getMapTileSelection(); + if (arch != null) { + arch.moveDown(); + } + } + }; + } + + ActionListener getButtonUpActionListener() { + return new ActionListener() { + public void actionPerformed(final ActionEvent e) { + final GameObject arch = getMapTileSelection(); + if (arch != null) { + arch.moveUp(); + } + } + }; + } + + ListSelectionListener getListSelectionListener() { + return new ListSelectionListener() { + public void valueChanged(final ListSelectionEvent e) { + mainView.setMapArchPanelObject(getMapTileSelection()); + } + }; + } + + MouseListener getMouseListener() { + return new MouseAdapter() { + @Override public void mousePressed(final MouseEvent e) { + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { + // --- 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) { + // --- right mouse button: insert arch --- + insertGameObjectFromArchPanel(view.getListIndex(e)); + } else { + // --- middle mouse button: delete arch --- + deleteIndex(view.getListIndex(e)); + } + } + }; + } + + public void selectArchBelow() { + view.setSelectedIndex(view.getSelectedIndex() + 1); + } + + public void selectArchAbove() { + view.setSelectedIndex(view.getSelectedIndex() - 1); + } + + /** + * Return the currently selected GameObject within this list (currently selected MapSquare). + * @return the currently selected GameObject + */ + @Nullable public GameObject getMapTileSelection() { + return view.getMapTileSelection(); + } + + /** + * Delete the currently selected game object. + */ + public void deleteSelection() { + deleteIndex(view.getSelectedIndex()); + } + + /** + * Delete an GameObject with a specific list index. + * @param index List index of GameObject + */ + private void deleteIndex(final int index) { + if (index < 0 || index >= view.getModelSize()) { + return; + } + + final MapControl mapControl = view.getCurrentMapControl(); + if (mapControl == null) { + return; + } + + final MapSquare<GameObject> mapSquare = view.getCurrentMapSquare(); + if (mapSquare == null) { + return; + } + + mapControl.getMapModel().beginTransaction("Delete"); // TODO; I18N/L10N + final GameObject entry = view.getListGameObject(index); + if (entry != null) { + mapControl.deleteMapArch(entry, new Point(mapSquare.getMapX(), mapSquare.getMapY()), MapModel.JOIN_ENABLE); + + if (index + 1 < view.getModelSize()) { + view.setSelectedGameObject(view.getListGameObject(index + 1)); + } else if (index > 0) { + view.setSelectedGameObject(view.getListGameObject(index - 1)); + } else { + view.setSelectedGameObject(null); + } + } + mapControl.getMapModel().endTransaction(); + } + + /** + * Insert a new game object. + */ + public void insertGameObjectFromArchPanel() { + insertGameObjectFromArchPanel(view.getSelectedIndex()); + } + + /** + * Insert a new game object. + * + * @param index the list index to insert at + */ + public void insertGameObjectFromArchPanel(final int index) { + final GameObject gameObject = mainControl.getArchPanelHighlight(); + if (gameObject == null) { + return; + } + + final MapControl currentMapControl = view.getCurrentMapControl(); + if (currentMapControl == null) { + return; + } + + final MapSquare<GameObject> currentMapSquare = view.getCurrentMapSquare(); + if (currentMapSquare == null) { + return; + } + + currentMapControl.getMapModel().beginTransaction("Insert"); // TODO; I18N/L10N + final GameObject insertedGameObject; + if (index >= view.getModelSize()) { + insertedGameObject = currentMapControl.insertArchToMap(gameObject, mainControl.getPanelArchName(), null, new Point(currentMapSquare.getMapX(), currentMapSquare.getMapY()), MapModel.JOIN_ENABLE); + } else { + final GameObject entry = view.getListGameObject(index); + insertedGameObject = currentMapControl.insertArchToMap(gameObject, mainControl.getPanelArchName(), entry, new Point(currentMapSquare.getMapX(), currentMapSquare.getMapY()), MapModel.JOIN_ENABLE); + } + view.setSelectedGameObject(insertedGameObject); + currentMapControl.getMapModel().endTransaction(); + + // refresh + currentMapControl.setLevelChangedFlag(); // the map has been modified + } + + /** + * 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) { + + // refresh the MapArchPanel to display the new arch + mainView.refreshMapArchPanel(); + } + + /** + * Return the view for this controller. + * + * @return the view for this controller + */ + public SelectedSquareView getMapTileListView() { + return view; + } + +} // class SelectedSquareControl Property changes on: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Copied: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java (from rev 1287, trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java 2006-12-26 22:20:12 UTC (rev 1288) @@ -0,0 +1,527 @@ +/* + * 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.selectedsquare; + +import cfeditor.CFancyButton; +import cfeditor.CMainControl; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; +import cfeditor.map.MapControl; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import javax.swing.BorderFactory; +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.ListSelectionModel; +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 net.sf.gridarta.MainControlListener; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.gridarta.gui.maptilelist.MapTileSelection; +import net.sf.gridarta.gui.maptilelist.MapTileSelectionCache; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; +import net.sf.gridarta.map.MapSquare; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The panel that displays the game objects of the currently selected map square. + * Currently it uses a list but in future it will use a tree instead. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class SelectedSquareView extends JPanel implements MainControlListener<MapControl>, MapCursorListener, MapModelListener<GameObject> { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(SelectedSquareView.class); + + /** The main control for this view. */ + @NotNull final CMainControl mainControl; + + /** The "Import..." button. */ + private final JList list; + + private final DefaultListModel model; + + private int listCounter = 0; + + /** + * The cache to store selections for each map control. + */ + @NotNull private final MapTileSelectionCache<GameObject, MapControl> mapTileSelectionCache = new MapTileSelectionCache<GameObject, MapControl>(); + + /** + * The currently selected map tile. + */ + @Nullable private MapTileSelection<GameObject, MapControl> selectedMapTile = null; + + /** + * Create a new instance. + * + * @param control the controller for this view + * + * @param mainControl the main controller for this view + * + * @param mapTileListBottom set if the map tile list should be at the + * bottom or on the top of the main view + */ + SelectedSquareView(@NotNull final SelectedSquareControl control, @NotNull final CMainControl mainControl, final boolean mapTileListBottom) { + this.mainControl = mainControl; + + setLayout(new BorderLayout()); + + model = new DefaultListModel(); + list = new JList(model); + list.setCellRenderer(new CellRenderer(mainControl.getArchetypeSet())); + list.setBackground(Color.lightGray); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + 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 (mapTileListBottom) { + 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 (!mapTileListBottom) { + 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, control.getButtonDownActionListener()); + buttonDown.setVerticalTextPosition(SwingConstants.BOTTOM); + buttonDown.setHorizontalTextPosition(SwingConstants.CENTER); + if (!mapTileListBottom) { + arrows.add(buttonDown, BorderLayout.EAST); + } + + final CFancyButton buttonUp = new CFancyButton(null, "Move Tile Position Up", IGUIConstants.MOVE_UP_ICON, control.getButtonUpActionListener()); + buttonUp.setVerticalTextPosition(SwingConstants.BOTTOM); + buttonUp.setHorizontalTextPosition(SwingConstants.CENTER); + if (!mapTileListBottom) { + arrows.add(buttonUp, BorderLayout.WEST); + } else { + arrows.add(buttonUp); + arrows.add(buttonDown); + } + + list.addListSelectionListener(control.getListSelectionListener()); + + /** + * listen for mouse events in the panel + */ + list.addMouseListener(control.getMouseListener()); + + mainControl.addMainControlListener(this); + } + + /** + * Return the currently selected map control. + * + * @return the currently selected map control, or <code>null</code> if no + * tile is selected + */ + @Nullable public MapControl getCurrentMapControl() { + return selectedMapTile == null ? null : selectedMapTile.getMapControl(); + } + + /** + * Return the currently selected map square. + * + * @return the currently selected map square, or <code>null</code> if no + * tile is selected + */ + @Nullable public MapSquare<GameObject> getCurrentMapSquare() { + return selectedMapTile == null ? null : selectedMapTile.getMapSquare(); + } + + /** + * 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 + */ + int getListIndex(final MouseEvent e) { + final int lastIndex = getModelSize() - 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() { + final GameObject gameObject = (GameObject) list.getSelectedValue(); + + if (selectedMapTile != null) { + selectedMapTile.setGameObject(gameObject); + selectedMapTile.setIndex(list.getSelectedIndex()); + } + + return gameObject; + } + + /** + * Re-display the map tile panel for {@link #selectedMapTile}. Possibly updates + * information in <code>selectedMapTile</code>. + */ + private void refresh() { + final MapControl mapControl; + final MapSquare<GameObject> mapSquare; + final GameObject gameObject; + if (selectedMapTile == null) { + mapControl = null; + mapSquare = null; + gameObject = null; + } else { + mapControl = selectedMapTile.getMapControl(); + mapSquare = selectedMapTile.getMapSquare(); + gameObject = selectedMapTile.getGameObject(); + } + + list.setEnabled(false); + model.removeAllElements(); + if (mapControl == null) { + list.setSelectedIndex(0); + list.setEnabled(true); + return; + } + + listCounter = 0; + int postSelect = -1; + boolean foundSIndex = false; + int sIndex = -1; + + // Now go through the list backwards and put all arches + // on the panel in this order + if (mapSquare != null) { + for (final GameObject node : mapSquare.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) { + setSelectedIndex(postSelect); + } else if (sIndex != -1) { + // Per default, the topmost arch matching the view settings is selected. + // (With no view settings applied, the very topmost arch is selected.) + setSelectedIndex(sIndex); + } else if (selectedMapTile != null){ + // use last known good index + setSelectedIndex(selectedMapTile.getIndex()); + } else { + setSelectedIndex(0); + } + + list.setEnabled(true); + } + + /** + * Add inventory objects to an arch in the SelectedSquareView recursively. + * @param node the arch where the inventory gets added + * @param gameObject selected GameObject + * @return <code>listCounter</code> for <var>gameObject</var>, or <code>-1</code> if not found + */ + private int addInvObjects(final GameObject node, final GameObject gameObject) { + int selListCount... [truncated message content] |
From: <chr...@us...> - 2006-12-26 22:21:26
|
Revision: 1289 http://svn.sourceforge.net/gridarta/?rev=1289&view=rev Author: christianhujer Date: 2006-12-26 14:21:23 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Updated comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2006-12-26 22:20:12 UTC (rev 1288) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2006-12-26 22:21:23 UTC (rev 1289) @@ -45,7 +45,8 @@ import org.jetbrains.annotations.Nullable; /** - * The panel that displays the arches of the currently selected map square. + * The panel that displays the game objects of the currently selected map square. + * Currently it uses a list but in future it will use a tree instead. * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ Modified: trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java 2006-12-26 22:20:12 UTC (rev 1288) +++ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java 2006-12-26 22:21:23 UTC (rev 1289) @@ -46,7 +46,8 @@ import org.jetbrains.annotations.Nullable; /** - * The panel that displays the arches of the currently selected map square. + * The panel that displays the game objects of the currently selected map square. + * Currently it uses a list but in future it will use a tree instead. * @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> Modified: trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java 2006-12-26 22:20:12 UTC (rev 1288) +++ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java 2006-12-26 22:21:23 UTC (rev 1289) @@ -53,7 +53,8 @@ import org.jetbrains.annotations.Nullable; /** - * The panel that displays the arches of the currently selected map square. + * The panel that displays the game objects of the currently selected map square. + * Currently it uses a list but in future it will use a tree instead. * @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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 22:38:51
|
Revision: 1290 http://svn.sourceforge.net/gridarta/?rev=1290&view=rev Author: christianhujer Date: 2006-12-26 14:38:51 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CArchQuickView to ObjectChoiceDisplay. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanel.java trunk/daimonin/src/daieditor/CArchPanel.java Added Paths: ----------- trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CArchQuickView.java trunk/daimonin/src/daieditor/CArchQuickView.java Modified: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-26 22:21:23 UTC (rev 1289) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-26 22:38:51 UTC (rev 1290) @@ -72,7 +72,7 @@ private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); /** The data/view of selected objects in tab panel. */ - private final CArchQuickView archQuickPanel; + private final ObjectChoiceDisplay archQuickPanel; /** The active panel. */ private CArchPanelPan selectedPanel; @@ -86,7 +86,7 @@ this.mainControl = mainControl; tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); - archQuickPanel = new CArchQuickView(mainControl); + archQuickPanel = new ObjectChoiceDisplay(mainControl); // archAndPickPane is the panel containing both archpanel and pickmaps archAndPickPane.addTab("Arch List", tabDesktop); Deleted: trunk/crossfire/src/cfeditor/CArchQuickView.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-12-26 22:21:23 UTC (rev 1289) +++ trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-12-26 22:38:51 UTC (rev 1290) @@ -1,148 +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 java.awt.Color; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import net.sf.gridarta.gameobject.Archetype; -import org.jetbrains.annotations.Nullable; - -/** - * The <code>CArchQuickView</code> holds the tile palette. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class CArchQuickView extends JPanel { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final JLabel archObjNameLabel = new JLabel("Name:"); - - private final JLabel archArchNameLabel = new JLabel("Arch:"); - - private final JLabel archTypeLabel = new JLabel("Type:"); - - private final JLabel archTileLabel = new JLabel("Tile:"); - - private final JLabel archObjNameText = new JLabel(); - - private final JLabel archArchNameText = new JLabel(); - - private final JLabel archTypeText = new JLabel(); - - private final JLabel archTileText = new JLabel(); - - public CArchQuickView(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - - final GridBagConstraints gcl = new GridBagConstraints(); - final GridBagConstraints gcr = new GridBagConstraints(); - gcl.fill = GridBagConstraints.HORIZONTAL; - gcr.fill = GridBagConstraints.HORIZONTAL; - gcl.weightx = 0.0; - gcr.weightx = 1.0; - gcl.anchor = GridBagConstraints.WEST; - gcr.anchor = GridBagConstraints.WEST; - gcl.gridwidth = 1; - gcr.gridwidth = GridBagConstraints.REMAINDER; - - add(archObjNameLabel, gcl); - add(archObjNameText, gcr); - - add(archArchNameLabel, gcl); - add(archArchNameText, gcr); - - add(archTypeLabel, gcl); - add(archTypeText, gcr); - - add(archTileLabel, gcl); - add(archTileText, gcr); - } - - /** - * Show quick info for an object. - * - * @param gameObject the object to show; this may be any part of a multi-part - * object, or <code>null</code> to clear the attributes - */ - void showArchPanelQuickObject(@Nullable final GameObject gameObject) { - if (gameObject == null) { - archObjNameText.setText(null); - archArchNameText.setText(null); - archTypeText.setText(null); - archTileText.setText(null); - } else { - final GameObject headObject = gameObject.getHead(); - String objName = headObject.getObjName(); - if (objName == null || objName.length() == 0) { - final Archetype<GameObject> archetype = headObject.getArchetype(); - if (archetype == null || archetype == headObject) { - objName = null; - } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { - } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { - } else { - objName = null; - } - } - if (objName == null) { - objName = " -none- "; - archObjNameText.setForeground(Color.RED); - } else { - archObjNameText.setForeground(Color.BLACK); - } - archObjNameText.setText(objName); - - archArchNameText.setText(headObject.getArchetypeName()); - - final CFArchType archType = mainControl.getTypeList().getType(headObject); - archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); - - if (headObject.isMulti()) { - archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); - } else { - archTileText.setText("single"); - } - - // notify ReplaceDialog - if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { - ReplaceDialog.getInstance().updateArchSelection(headObject, false); - } - } - } - - void refresh() { - mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); - repaint(); - } - -} // class CArchQuickView Copied: trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java (from rev 1288, trunk/crossfire/src/cfeditor/CArchQuickView.java) =================================================================== --- trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java (rev 0) +++ trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java 2006-12-26 22:38:51 UTC (rev 1290) @@ -0,0 +1,148 @@ +/* + * 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 java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import net.sf.gridarta.gameobject.Archetype; +import org.jetbrains.annotations.Nullable; + +/** + * The ObjectChoiceDisplay shows quick information about the chose object from the Object Chooser. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class ObjectChoiceDisplay extends JPanel { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final JLabel archObjNameLabel = new JLabel("Name:"); + + private final JLabel archArchNameLabel = new JLabel("Arch:"); + + private final JLabel archTypeLabel = new JLabel("Type:"); + + private final JLabel archTileLabel = new JLabel("Tile:"); + + private final JLabel archObjNameText = new JLabel(); + + private final JLabel archArchNameText = new JLabel(); + + private final JLabel archTypeText = new JLabel(); + + private final JLabel archTileText = new JLabel(); + + public ObjectChoiceDisplay(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + + final GridBagConstraints gcl = new GridBagConstraints(); + final GridBagConstraints gcr = new GridBagConstraints(); + gcl.fill = GridBagConstraints.HORIZONTAL; + gcr.fill = GridBagConstraints.HORIZONTAL; + gcl.weightx = 0.0; + gcr.weightx = 1.0; + gcl.anchor = GridBagConstraints.WEST; + gcr.anchor = GridBagConstraints.WEST; + gcl.gridwidth = 1; + gcr.gridwidth = GridBagConstraints.REMAINDER; + + add(archObjNameLabel, gcl); + add(archObjNameText, gcr); + + add(archArchNameLabel, gcl); + add(archArchNameText, gcr); + + add(archTypeLabel, gcl); + add(archTypeText, gcr); + + add(archTileLabel, gcl); + add(archTileText, gcr); + } + + /** + * Show quick info for an object. + * + * @param gameObject the object to show; this may be any part of a multi-part + * object, or <code>null</code> to clear the attributes + */ + void showArchPanelQuickObject(@Nullable final GameObject gameObject) { + if (gameObject == null) { + archObjNameText.setText(null); + archArchNameText.setText(null); + archTypeText.setText(null); + archTileText.setText(null); + } else { + final GameObject headObject = gameObject.getHead(); + String objName = headObject.getObjName(); + if (objName == null || objName.length() == 0) { + final Archetype<GameObject> archetype = headObject.getArchetype(); + if (archetype == null || archetype == headObject) { + objName = null; + } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { + } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { + } else { + objName = null; + } + } + if (objName == null) { + objName = " -none- "; + archObjNameText.setForeground(Color.RED); + } else { + archObjNameText.setForeground(Color.BLACK); + } + archObjNameText.setText(objName); + + archArchNameText.setText(headObject.getArchetypeName()); + + final CFArchType archType = mainControl.getTypeList().getType(headObject); + archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); + + if (headObject.isMulti()) { + archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); + } else { + archTileText.setText("single"); + } + + // notify ReplaceDialog + if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { + ReplaceDialog.getInstance().updateArchSelection(headObject, false); + } + } + } + + void refresh() { + mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); + repaint(); + } + +} // class ObjectChoiceDisplay Property changes on: trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-26 22:21:23 UTC (rev 1289) +++ trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-26 22:38:51 UTC (rev 1290) @@ -70,7 +70,7 @@ private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); /** The data/view of selected objects in tab panel. */ - private final CArchQuickView archQuickPanel; + private final ObjectChoiceDisplay archQuickPanel; /** The active panel. */ private CArchPanelPan selectedPanel; @@ -84,7 +84,7 @@ this.mainControl = mainControl; tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); - archQuickPanel = new CArchQuickView(mainControl); + archQuickPanel = new ObjectChoiceDisplay(mainControl); // archAndPickPane is the panel containing both archpanel and pickmaps archAndPickPane.addTab("Arch List", tabDesktop); Deleted: trunk/daimonin/src/daieditor/CArchQuickView.java =================================================================== --- trunk/daimonin/src/daieditor/CArchQuickView.java 2006-12-26 22:21:23 UTC (rev 1289) +++ trunk/daimonin/src/daieditor/CArchQuickView.java 2006-12-26 22:38:51 UTC (rev 1290) @@ -1,153 +0,0 @@ -/* - * Daimonin 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 daieditor; - -import daieditor.gameobject.GameObject; -import java.awt.Color; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import net.sf.gridarta.gameobject.Archetype; -import org.jetbrains.annotations.Nullable; - -/** - * The <code>CArchQuickView</code> holds the tile palette. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class CArchQuickView extends JPanel { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final JLabel archObjNameLabel = new JLabel("Name:"); - - private final JLabel archArchNameLabel = new JLabel("Arch:"); - - private final JLabel archTypeLabel = new JLabel("Type:"); - - private final JLabel archTileLabel = new JLabel("Tile:"); - - private final JLabel archObjNameText = new JLabel(); - - private final JLabel archArchNameText = new JLabel(); - - private final JLabel archTypeText = new JLabel(); - - private final JLabel archTileText = new JLabel(); - - public CArchQuickView(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - - final GridBagConstraints gcl = new GridBagConstraints(); - final GridBagConstraints gcr = new GridBagConstraints(); - gcl.fill = GridBagConstraints.HORIZONTAL; - gcr.fill = GridBagConstraints.HORIZONTAL; - gcl.weightx = 0.0; - gcr.weightx = 1.0; - gcl.anchor = GridBagConstraints.WEST; - gcr.anchor = GridBagConstraints.WEST; - gcl.gridwidth = 1; - gcr.gridwidth = GridBagConstraints.REMAINDER; - - add(archObjNameLabel, gcl); - add(archObjNameText, gcr); - - add(archArchNameLabel, gcl); - add(archArchNameText, gcr); - - add(archTypeLabel, gcl); - add(archTypeText, gcr); - - add(archTileLabel, gcl); - add(archTileText, gcr); - } - - /** - * Show quick info for an object. - * - * @param gameObject the object to show; this may be any part of a multi-part - * object, or <code>null</code> to clear the attributes - */ - void showArchPanelQuickObject(@Nullable final GameObject gameObject) { - if (gameObject == null) { - if (mainControl.getMainView().isPickmapActive()) { - archObjNameText.setText(" -random pick- "); - archObjNameText.setForeground(Color.BLUE); - } else { - archObjNameText.setText(null); - } - archArchNameText.setText(null); - archTypeText.setText(null); - archTileText.setText(null); - } else { - final GameObject headObject = gameObject.getHead(); - String objName = headObject.getObjName(); - if (objName == null || objName.length() == 0) { - final Archetype<GameObject> archetype = headObject.getArchetype(); - if (archetype == null || archetype == headObject) { - objName = null; - } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { - } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { - } else { - objName = null; - } - } - if (objName == null) { - objName = " -none- "; - archObjNameText.setForeground(Color.RED); - } else { - archObjNameText.setForeground(Color.BLACK); - } - archObjNameText.setText(objName); - - archArchNameText.setText(headObject.getArchetypeName()); - - final CFArchType archType = mainControl.getTypeList().getType(headObject); - archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); - - if (headObject.isMulti()) { - archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); - } else { - archTileText.setText("single"); - } - - // notify ReplaceDialog - if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { - ReplaceDialog.getInstance().updateArchSelection(headObject, false); - } - } - } - - void refresh() { - mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); - repaint(); - } - -} // class CArchQuickView Copied: trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java (from rev 1288, trunk/daimonin/src/daieditor/CArchQuickView.java) =================================================================== --- trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java (rev 0) +++ trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java 2006-12-26 22:38:51 UTC (rev 1290) @@ -0,0 +1,153 @@ +/* + * Daimonin 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 daieditor; + +import daieditor.gameobject.GameObject; +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import net.sf.gridarta.gameobject.Archetype; +import org.jetbrains.annotations.Nullable; + +/** + * The ObjectChoiceDisplay shows quick information about the chose object from the Object Chooser. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class ObjectChoiceDisplay extends JPanel { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final JLabel archObjNameLabel = new JLabel("Name:"); + + private final JLabel archArchNameLabel = new JLabel("Arch:"); + + private final JLabel archTypeLabel = new JLabel("Type:"); + + private final JLabel archTileLabel = new JLabel("Tile:"); + + private final JLabel archObjNameText = new JLabel(); + + private final JLabel archArchNameText = new JLabel(); + + private final JLabel archTypeText = new JLabel(); + + private final JLabel archTileText = new JLabel(); + + public ObjectChoiceDisplay(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + + final GridBagConstraints gcl = new GridBagConstraints(); + final GridBagConstraints gcr = new GridBagConstraints(); + gcl.fill = GridBagConstraints.HORIZONTAL; + gcr.fill = GridBagConstraints.HORIZONTAL; + gcl.weightx = 0.0; + gcr.weightx = 1.0; + gcl.anchor = GridBagConstraints.WEST; + gcr.anchor = GridBagConstraints.WEST; + gcl.gridwidth = 1; + gcr.gridwidth = GridBagConstraints.REMAINDER; + + add(archObjNameLabel, gcl); + add(archObjNameText, gcr); + + add(archArchNameLabel, gcl); + add(archArchNameText, gcr); + + add(archTypeLabel, gcl); + add(archTypeText, gcr); + + add(archTileLabel, gcl); + add(archTileText, gcr); + } + + /** + * Show quick info for an object. + * + * @param gameObject the object to show; this may be any part of a multi-part + * object, or <code>null</code> to clear the attributes + */ + void showArchPanelQuickObject(@Nullable final GameObject gameObject) { + if (gameObject == null) { + if (mainControl.getMainView().isPickmapActive()) { + archObjNameText.setText(" -random pick- "); + archObjNameText.setForeground(Color.BLUE); + } else { + archObjNameText.setText(null); + } + archArchNameText.setText(null); + archTypeText.setText(null); + archTileText.setText(null); + } else { + final GameObject headObject = gameObject.getHead(); + String objName = headObject.getObjName(); + if (objName == null || objName.length() == 0) { + final Archetype<GameObject> archetype = headObject.getArchetype(); + if (archetype == null || archetype == headObject) { + objName = null; + } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { + } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { + } else { + objName = null; + } + } + if (objName == null) { + objName = " -none- "; + archObjNameText.setForeground(Color.RED); + } else { + archObjNameText.setForeground(Color.BLACK); + } + archObjNameText.setText(objName); + + archArchNameText.setText(headObject.getArchetypeName()); + + final CFArchType archType = mainControl.getTypeList().getType(headObject); + archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); + + if (headObject.isMulti()) { + archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); + } else { + archTileText.setText("single"); + } + + // notify ReplaceDialog + if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { + ReplaceDialog.getInstance().updateArchSelection(headObject, false); + } + } + } + + void refresh() { + mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); + repaint(); + } + +} // class ObjectChoiceDisplay Property changes on: trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 22:41:04
|
Revision: 1291 http://svn.sourceforge.net/gridarta/?rev=1291&view=rev Author: christianhujer Date: 2006-12-26 14:41:00 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Moved ObjectChoiceDisplay to gui package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanel.java trunk/daimonin/src/daieditor/CArchPanel.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java Modified: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-26 22:38:51 UTC (rev 1290) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-26 22:41:00 UTC (rev 1291) @@ -26,6 +26,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.gui.ObjectChoiceDisplay; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; Deleted: trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java =================================================================== --- trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java 2006-12-26 22:38:51 UTC (rev 1290) +++ trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java 2006-12-26 22:41:00 UTC (rev 1291) @@ -1,148 +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 java.awt.Color; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import net.sf.gridarta.gameobject.Archetype; -import org.jetbrains.annotations.Nullable; - -/** - * The ObjectChoiceDisplay shows quick information about the chose object from the Object Chooser. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class ObjectChoiceDisplay extends JPanel { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final JLabel archObjNameLabel = new JLabel("Name:"); - - private final JLabel archArchNameLabel = new JLabel("Arch:"); - - private final JLabel archTypeLabel = new JLabel("Type:"); - - private final JLabel archTileLabel = new JLabel("Tile:"); - - private final JLabel archObjNameText = new JLabel(); - - private final JLabel archArchNameText = new JLabel(); - - private final JLabel archTypeText = new JLabel(); - - private final JLabel archTileText = new JLabel(); - - public ObjectChoiceDisplay(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - - final GridBagConstraints gcl = new GridBagConstraints(); - final GridBagConstraints gcr = new GridBagConstraints(); - gcl.fill = GridBagConstraints.HORIZONTAL; - gcr.fill = GridBagConstraints.HORIZONTAL; - gcl.weightx = 0.0; - gcr.weightx = 1.0; - gcl.anchor = GridBagConstraints.WEST; - gcr.anchor = GridBagConstraints.WEST; - gcl.gridwidth = 1; - gcr.gridwidth = GridBagConstraints.REMAINDER; - - add(archObjNameLabel, gcl); - add(archObjNameText, gcr); - - add(archArchNameLabel, gcl); - add(archArchNameText, gcr); - - add(archTypeLabel, gcl); - add(archTypeText, gcr); - - add(archTileLabel, gcl); - add(archTileText, gcr); - } - - /** - * Show quick info for an object. - * - * @param gameObject the object to show; this may be any part of a multi-part - * object, or <code>null</code> to clear the attributes - */ - void showArchPanelQuickObject(@Nullable final GameObject gameObject) { - if (gameObject == null) { - archObjNameText.setText(null); - archArchNameText.setText(null); - archTypeText.setText(null); - archTileText.setText(null); - } else { - final GameObject headObject = gameObject.getHead(); - String objName = headObject.getObjName(); - if (objName == null || objName.length() == 0) { - final Archetype<GameObject> archetype = headObject.getArchetype(); - if (archetype == null || archetype == headObject) { - objName = null; - } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { - } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { - } else { - objName = null; - } - } - if (objName == null) { - objName = " -none- "; - archObjNameText.setForeground(Color.RED); - } else { - archObjNameText.setForeground(Color.BLACK); - } - archObjNameText.setText(objName); - - archArchNameText.setText(headObject.getArchetypeName()); - - final CFArchType archType = mainControl.getTypeList().getType(headObject); - archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); - - if (headObject.isMulti()) { - archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); - } else { - archTileText.setText("single"); - } - - // notify ReplaceDialog - if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { - ReplaceDialog.getInstance().updateArchSelection(headObject, false); - } - } - } - - void refresh() { - mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); - repaint(); - } - -} // class ObjectChoiceDisplay Copied: trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java (from rev 1290, trunk/crossfire/src/cfeditor/ObjectChoiceDisplay.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2006-12-26 22:41:00 UTC (rev 1291) @@ -0,0 +1,151 @@ +/* + * 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.gui; + +import cfeditor.gameobject.GameObject; +import cfeditor.CMainControl; +import cfeditor.CFArchType; +import cfeditor.ReplaceDialog; +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import net.sf.gridarta.gameobject.Archetype; +import org.jetbrains.annotations.Nullable; + +/** + * The ObjectChoiceDisplay shows quick information about the chose object from the Object Chooser. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class ObjectChoiceDisplay extends JPanel { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final JLabel archObjNameLabel = new JLabel("Name:"); + + private final JLabel archArchNameLabel = new JLabel("Arch:"); + + private final JLabel archTypeLabel = new JLabel("Type:"); + + private final JLabel archTileLabel = new JLabel("Tile:"); + + private final JLabel archObjNameText = new JLabel(); + + private final JLabel archArchNameText = new JLabel(); + + private final JLabel archTypeText = new JLabel(); + + private final JLabel archTileText = new JLabel(); + + public ObjectChoiceDisplay(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + + final GridBagConstraints gcl = new GridBagConstraints(); + final GridBagConstraints gcr = new GridBagConstraints(); + gcl.fill = GridBagConstraints.HORIZONTAL; + gcr.fill = GridBagConstraints.HORIZONTAL; + gcl.weightx = 0.0; + gcr.weightx = 1.0; + gcl.anchor = GridBagConstraints.WEST; + gcr.anchor = GridBagConstraints.WEST; + gcl.gridwidth = 1; + gcr.gridwidth = GridBagConstraints.REMAINDER; + + add(archObjNameLabel, gcl); + add(archObjNameText, gcr); + + add(archArchNameLabel, gcl); + add(archArchNameText, gcr); + + add(archTypeLabel, gcl); + add(archTypeText, gcr); + + add(archTileLabel, gcl); + add(archTileText, gcr); + } + + /** + * Show quick info for an object. + * + * @param gameObject the object to show; this may be any part of a multi-part + * object, or <code>null</code> to clear the attributes + */ + public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { + if (gameObject == null) { + archObjNameText.setText(null); + archArchNameText.setText(null); + archTypeText.setText(null); + archTileText.setText(null); + } else { + final GameObject headObject = gameObject.getHead(); + String objName = headObject.getObjName(); + if (objName == null || objName.length() == 0) { + final Archetype<GameObject> archetype = headObject.getArchetype(); + if (archetype == null || archetype == headObject) { + objName = null; + } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { + } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { + } else { + objName = null; + } + } + if (objName == null) { + objName = " -none- "; + archObjNameText.setForeground(Color.RED); + } else { + archObjNameText.setForeground(Color.BLACK); + } + archObjNameText.setText(objName); + + archArchNameText.setText(headObject.getArchetypeName()); + + final CFArchType archType = mainControl.getTypeList().getType(headObject); + archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); + + if (headObject.isMulti()) { + archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); + } else { + archTileText.setText("single"); + } + + // notify ReplaceDialog + if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { + ReplaceDialog.getInstance().updateArchSelection(headObject, false); + } + } + } + + public void refresh() { + mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); + repaint(); + } + +} // class ObjectChoiceDisplay Property changes on: trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-26 22:38:51 UTC (rev 1290) +++ trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-26 22:41:00 UTC (rev 1291) @@ -27,6 +27,7 @@ import daieditor.gameobject.GameObject; import daieditor.gui.map.tools.ToolSelectorPane; +import daieditor.gui.ObjectChoiceDisplay; import java.awt.BorderLayout; import javax.swing.BorderFactory; import javax.swing.JPanel; Deleted: trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java =================================================================== --- trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java 2006-12-26 22:38:51 UTC (rev 1290) +++ trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java 2006-12-26 22:41:00 UTC (rev 1291) @@ -1,153 +0,0 @@ -/* - * Daimonin 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 daieditor; - -import daieditor.gameobject.GameObject; -import java.awt.Color; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import net.sf.gridarta.gameobject.Archetype; -import org.jetbrains.annotations.Nullable; - -/** - * The ObjectChoiceDisplay shows quick information about the chose object from the Object Chooser. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class ObjectChoiceDisplay extends JPanel { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final JLabel archObjNameLabel = new JLabel("Name:"); - - private final JLabel archArchNameLabel = new JLabel("Arch:"); - - private final JLabel archTypeLabel = new JLabel("Type:"); - - private final JLabel archTileLabel = new JLabel("Tile:"); - - private final JLabel archObjNameText = new JLabel(); - - private final JLabel archArchNameText = new JLabel(); - - private final JLabel archTypeText = new JLabel(); - - private final JLabel archTileText = new JLabel(); - - public ObjectChoiceDisplay(final CMainControl mainControl) { - this.mainControl = mainControl; - setLayout(new GridBagLayout()); - - final GridBagConstraints gcl = new GridBagConstraints(); - final GridBagConstraints gcr = new GridBagConstraints(); - gcl.fill = GridBagConstraints.HORIZONTAL; - gcr.fill = GridBagConstraints.HORIZONTAL; - gcl.weightx = 0.0; - gcr.weightx = 1.0; - gcl.anchor = GridBagConstraints.WEST; - gcr.anchor = GridBagConstraints.WEST; - gcl.gridwidth = 1; - gcr.gridwidth = GridBagConstraints.REMAINDER; - - add(archObjNameLabel, gcl); - add(archObjNameText, gcr); - - add(archArchNameLabel, gcl); - add(archArchNameText, gcr); - - add(archTypeLabel, gcl); - add(archTypeText, gcr); - - add(archTileLabel, gcl); - add(archTileText, gcr); - } - - /** - * Show quick info for an object. - * - * @param gameObject the object to show; this may be any part of a multi-part - * object, or <code>null</code> to clear the attributes - */ - void showArchPanelQuickObject(@Nullable final GameObject gameObject) { - if (gameObject == null) { - if (mainControl.getMainView().isPickmapActive()) { - archObjNameText.setText(" -random pick- "); - archObjNameText.setForeground(Color.BLUE); - } else { - archObjNameText.setText(null); - } - archArchNameText.setText(null); - archTypeText.setText(null); - archTileText.setText(null); - } else { - final GameObject headObject = gameObject.getHead(); - String objName = headObject.getObjName(); - if (objName == null || objName.length() == 0) { - final Archetype<GameObject> archetype = headObject.getArchetype(); - if (archetype == null || archetype == headObject) { - objName = null; - } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { - } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { - } else { - objName = null; - } - } - if (objName == null) { - objName = " -none- "; - archObjNameText.setForeground(Color.RED); - } else { - archObjNameText.setForeground(Color.BLACK); - } - archObjNameText.setText(objName); - - archArchNameText.setText(headObject.getArchetypeName()); - - final CFArchType archType = mainControl.getTypeList().getType(headObject); - archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); - - if (headObject.isMulti()) { - archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); - } else { - archTileText.setText("single"); - } - - // notify ReplaceDialog - if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { - ReplaceDialog.getInstance().updateArchSelection(headObject, false); - } - } - } - - void refresh() { - mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); - repaint(); - } - -} // class ObjectChoiceDisplay Copied: trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java (from rev 1290, trunk/daimonin/src/daieditor/ObjectChoiceDisplay.java) =================================================================== --- trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2006-12-26 22:41:00 UTC (rev 1291) @@ -0,0 +1,156 @@ +/* + * Daimonin 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 daieditor.gui; + +import daieditor.gameobject.GameObject; +import daieditor.CMainControl; +import daieditor.CFArchType; +import daieditor.ReplaceDialog; +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import net.sf.gridarta.gameobject.Archetype; +import org.jetbrains.annotations.Nullable; + +/** + * The ObjectChoiceDisplay shows quick information about the chose object from the Object Chooser. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class ObjectChoiceDisplay extends JPanel { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final JLabel archObjNameLabel = new JLabel("Name:"); + + private final JLabel archArchNameLabel = new JLabel("Arch:"); + + private final JLabel archTypeLabel = new JLabel("Type:"); + + private final JLabel archTileLabel = new JLabel("Tile:"); + + private final JLabel archObjNameText = new JLabel(); + + private final JLabel archArchNameText = new JLabel(); + + private final JLabel archTypeText = new JLabel(); + + private final JLabel archTileText = new JLabel(); + + public ObjectChoiceDisplay(final CMainControl mainControl) { + this.mainControl = mainControl; + setLayout(new GridBagLayout()); + + final GridBagConstraints gcl = new GridBagConstraints(); + final GridBagConstraints gcr = new GridBagConstraints(); + gcl.fill = GridBagConstraints.HORIZONTAL; + gcr.fill = GridBagConstraints.HORIZONTAL; + gcl.weightx = 0.0; + gcr.weightx = 1.0; + gcl.anchor = GridBagConstraints.WEST; + gcr.anchor = GridBagConstraints.WEST; + gcl.gridwidth = 1; + gcr.gridwidth = GridBagConstraints.REMAINDER; + + add(archObjNameLabel, gcl); + add(archObjNameText, gcr); + + add(archArchNameLabel, gcl); + add(archArchNameText, gcr); + + add(archTypeLabel, gcl); + add(archTypeText, gcr); + + add(archTileLabel, gcl); + add(archTileText, gcr); + } + + /** + * Show quick info for an object. + * + * @param gameObject the object to show; this may be any part of a multi-part + * object, or <code>null</code> to clear the attributes + */ + public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { + if (gameObject == null) { + if (mainControl.getMainView().isPickmapActive()) { + archObjNameText.setText(" -random pick- "); + archObjNameText.setForeground(Color.BLUE); + } else { + archObjNameText.setText(null); + } + archArchNameText.setText(null); + archTypeText.setText(null); + archTileText.setText(null); + } else { + final GameObject headObject = gameObject.getHead(); + String objName = headObject.getObjName(); + if (objName == null || objName.length() == 0) { + final Archetype<GameObject> archetype = headObject.getArchetype(); + if (archetype == null || archetype == headObject) { + objName = null; + } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { + } else if ((objName = archetype.getArchetypeName()) != null && objName.length() != 0) { + } else { + objName = null; + } + } + if (objName == null) { + objName = " -none- "; + archObjNameText.setForeground(Color.RED); + } else { + archObjNameText.setForeground(Color.BLACK); + } + archObjNameText.setText(objName); + + archArchNameText.setText(headObject.getArchetypeName()); + + final CFArchType archType = mainControl.getTypeList().getType(headObject); + archTypeText.setText(archType.getTypeName() + " (" + archType.getTypeNr() + ')'); + + if (headObject.isMulti()) { + archTileText.setText("<html><span style=\"color:green;\"> multi</span> (" + headObject.getMultiRefCount() + " parts) (" + headObject.getSizeX() + ',' + headObject.getSizeY() + ")</html>"); + } else { + archTileText.setText("single"); + } + + // notify ReplaceDialog + if (ReplaceDialog.isBuilt() && ReplaceDialog.getInstance().isShowing()) { + ReplaceDialog.getInstance().updateArchSelection(headObject, false); + } + } + } + + public void refresh() { + mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); + repaint(); + } + +} // class ObjectChoiceDisplay Property changes on: trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 23:21:29
|
Revision: 1293 http://svn.sourceforge.net/gridarta/?rev=1293&view=rev Author: christianhujer Date: 2006-12-26 15:21:29 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CArchPanel to gui.InsertionObjectChooser. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CMainView.java trunk/daimonin/src/daieditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CMainView.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CArchPanel.java trunk/daimonin/src/daieditor/CArchPanel.java Deleted: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-26 23:15:35 UTC (rev 1292) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -1,238 +0,0 @@ -/* - * 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; - -import cfeditor.gameobject.GameObject; -import cfeditor.gui.ObjectChoiceDisplay; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Toolkit; -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.gridarta.gui.GSplitPane; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * The <code>CArchPanel</code> holds the tile palette. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author Andreas Kirschbaum - */ -public final class CArchPanel extends JPanel { - - private static final String ARCHPANEL_LOCATION_KEY = "MainWindowArchPanel.dividerLocation"; - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final transient CMainControl mainControl; - - /** - * Name of the selected archetype. - * @serial include - */ - private GameObject selectedArch = null; - - /** Panel holding both archlist and pickmaps. */ - private final JTabbedPane archAndPickPane = new JTabbedPane(SwingConstants.TOP); - - /** Our split pane. */ - private final GSplitPane splitPane; - - /** The Tab panel with arch lists. */ - private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); - - /** The data/view of selected objects in tab panel. */ - private final ObjectChoiceDisplay archQuickPanel; - - /** The active panel. */ - private CArchPanelPan selectedPanel; - - /** - * Build Panel. - * @param mainControl CMainControl - */ - public CArchPanel(final CMainControl mainControl) { - super(new BorderLayout()); - this.mainControl = mainControl; - - tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); - archQuickPanel = new ObjectChoiceDisplay(mainControl); - - // archAndPickPane is the panel containing both archpanel and pickmaps - archAndPickPane.addTab("Arch List", tabDesktop); - archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); - // this listener informs the mainview which panel is active: archlist or pickmaps? - CPickmapPanel.getInstance().addArchNPickChangeListener(archAndPickPane); - - // calculate default value in case there is no settings file - final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - final int divLocation = Integer.parseInt(settings.getProperty(ARCHPANEL_LOCATION_KEY, String.valueOf((int) (0.77 * 0.9 * screen.getHeight())))); - - splitPane = new GSplitPane(JSplitPane.VERTICAL_SPLIT, archAndPickPane, archQuickPanel); - splitPane.setDividerLocation(divLocation); - add(splitPane, BorderLayout.CENTER); - } - - /** Move the pickmap panel in front of the default-archpanel. */ - public void movePickmapPanelToFront() { - archAndPickPane.setSelectedIndex(1); - } - - /** - * Get the currently selected archetype. - * - * @return the selected archetype, or <code>null</code> if none is selected - */ - @Nullable public GameObject getArchPanelSelection() { - return selectedPanel != null ? selectedPanel.getArchListObject() : null; - } - - /** - * Show the given game object's attributes in the quick panel. - * - * @param gameObject the game object to show, or <code>null</code> to clear - * the attributes - */ - public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { - archQuickPanel.showArchPanelQuickObject(gameObject); - } - - /** - * Add a new archetype. Create the panel and/or folder if necessary. - * - * @param panelName the panel name to add the archetype to - * - * @param folderName the folder name to add the archetype to - * - * @param arch the archetype to add - */ - public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { - final CArchPanelPan panel = findOrCreatePanel(panelName); - panel.addArchetype(folderName, arch); - } - - /** - * Sets the enabled state of the tab pane for Archetypes. - * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. - */ - public void setTabPaneEnabled(final boolean tabPaneEnabled) { - tabDesktop.setEnabled(tabPaneEnabled); - if (tabPaneEnabled && selectedPanel != null) { - selectedPanel.showArchList(); - } - } - - /** - * Return a panel by name. If this panel does not exist, create a new one. - * - * @param panelName the panel name - * - * @return the panel - */ - @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { - for (int i = 0; i < tabDesktop.getTabCount(); i++) { - if (panelName.equals(tabDesktop.getTitleAt(i))) { - return (CArchPanelPan) tabDesktop.getComponentAt(i); - } - } - - final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); - - // insert new panel in alphabetical order - int i; - for (i = 0; i < tabDesktop.getTabCount() && panelName.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { - ; - } - tabDesktop.insertTab(panelName, null, newPanel, null, i); - - return newPanel; - } - - /** - * After the build process is completed and the panels have - * been fully constructed, we must correct the 'selectedPanel' - * setting and make sure the arch list is properly drawn. - */ - public void finishBuildProcess() { - for (int i = 0; i < tabDesktop.getTabCount(); i++) { - ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); - } - - selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); - if (selectedPanel != null) { - selectedPanel.showArchList(); - } - - // we must set the list of the selected list depend on combo selection - tabDesktop.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); - setSelectedArch(null); - selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); - if (selectedPanel != null) { - selectedPanel.showArchList(); - } - } - }); - } - - public void appExitNotify() { - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - settings.setProperty(ARCHPANEL_LOCATION_KEY, String.valueOf(splitPane.getDividerLocation())); - } - - /** - * Get name of selected Arch. - * @return Name of selected arch in arch panel - */ - @Nullable public String getSelectedArch() { - return selectedArch == null ? null : selectedArch.getArchetypeName(); - } - - /** - * Set selected Arch. - * @param selectedArch name of selected arch in arch panel - */ - public void setSelectedArch(@Nullable final GameObject selectedArch) { - this.selectedArch = selectedArch; - } - - public void refresh() { - archQuickPanel.refresh(); - repaint(); - } - -} // class CArchPanel Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-26 23:15:35 UTC (rev 1292) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -26,6 +26,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.gui.InsertionObjectChooser; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; @@ -78,7 +79,7 @@ private final JComboBox comboBox; - private final CArchPanel archPanel; + private final InsertionObjectChooser archPanel; /** * Comparator used to sort entries shown in {@link #archList}. @@ -97,7 +98,7 @@ private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); /* Build Panel */ - CArchPanelPan(final CArchPanel controlPanel, final CMainControl mainControl) { + public CArchPanelPan(final InsertionObjectChooser controlPanel, final CMainControl mainControl) { super(new BorderLayout()); this.mainControl = mainControl; archPanel = controlPanel; Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:15:35 UTC (rev 1292) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -26,6 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.StatusBar; +import cfeditor.gui.InsertionObjectChooser; import cfeditor.gui.selectedsquare.SelectedSquareControl; import cfeditor.map.MapControl; import cfeditor.menu.AggregateMenuLocation; @@ -123,7 +124,7 @@ private StatusBar statusBar; /** The panel that contains the palette view. */ - private CArchPanel archPanel; + private InsertionObjectChooser archPanel; /** The desktop that holds all level views. */ private JDesktopPane mapDesktop; @@ -220,7 +221,7 @@ getContentPane().add(statusBar, BorderLayout.SOUTH); // Build the placeholder for tile palette - archPanel = new CArchPanel(mainControl); + archPanel = new InsertionObjectChooser(mainControl); selectedSquareControl = new SelectedSquareControl(mainControl, this); mapDesktop = new JDesktopPane(); Copied: trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java (from rev 1291, trunk/crossfire/src/cfeditor/CArchPanel.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -0,0 +1,242 @@ +/* + * 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; + +import cfeditor.CArchPanelPan; +import cfeditor.CMainControl; +import cfeditor.CPickmapPanel; +import cfeditor.CSettings; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.GSplitPane; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The <code>InsertionObjectChooser</code> holds the tile palette. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author Andreas Kirschbaum + */ +public final class InsertionObjectChooser extends JPanel { + + private static final String ARCHPANEL_LOCATION_KEY = "MainWindowArchPanel.dividerLocation"; + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final transient CMainControl mainControl; + + /** + * Name of the selected archetype. + * @serial include + */ + private GameObject selectedArch = null; + + /** Panel holding both archlist and pickmaps. */ + private final JTabbedPane archAndPickPane = new JTabbedPane(SwingConstants.TOP); + + /** Our split pane. */ + private final GSplitPane splitPane; + + /** The Tab panel with arch lists. */ + private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); + + /** The data/view of selected objects in tab panel. */ + private final ObjectChoiceDisplay archQuickPanel; + + /** The active panel. */ + private CArchPanelPan selectedPanel; + + /** + * Build Panel. + * @param mainControl CMainControl + */ + public InsertionObjectChooser(final CMainControl mainControl) { + super(new BorderLayout()); + this.mainControl = mainControl; + + tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); + archQuickPanel = new ObjectChoiceDisplay(mainControl); + + // archAndPickPane is the panel containing both archpanel and pickmaps + archAndPickPane.addTab("Arch List", tabDesktop); + archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); + // this listener informs the mainview which panel is active: archlist or pickmaps? + CPickmapPanel.getInstance().addArchNPickChangeListener(archAndPickPane); + + // calculate default value in case there is no settings file + final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + + final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); + final int divLocation = Integer.parseInt(settings.getProperty(ARCHPANEL_LOCATION_KEY, String.valueOf((int) (0.77 * 0.9 * screen.getHeight())))); + + splitPane = new GSplitPane(JSplitPane.VERTICAL_SPLIT, archAndPickPane, archQuickPanel); + splitPane.setDividerLocation(divLocation); + add(splitPane, BorderLayout.CENTER); + } + + /** Move the pickmap panel in front of the default-archpanel. */ + public void movePickmapPanelToFront() { + archAndPickPane.setSelectedIndex(1); + } + + /** + * Get the currently selected archetype. + * + * @return the selected archetype, or <code>null</code> if none is selected + */ + @Nullable public GameObject getArchPanelSelection() { + return selectedPanel != null ? selectedPanel.getArchListObject() : null; + } + + /** + * Show the given game object's attributes in the quick panel. + * + * @param gameObject the game object to show, or <code>null</code> to clear + * the attributes + */ + public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { + archQuickPanel.showArchPanelQuickObject(gameObject); + } + + /** + * Add a new archetype. Create the panel and/or folder if necessary. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + final CArchPanelPan panel = findOrCreatePanel(panelName); + panel.addArchetype(folderName, arch); + } + + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + */ + public void setTabPaneEnabled(final boolean tabPaneEnabled) { + tabDesktop.setEnabled(tabPaneEnabled); + if (tabPaneEnabled && selectedPanel != null) { + selectedPanel.showArchList(); + } + } + + /** + * Return a panel by name. If this panel does not exist, create a new one. + * + * @param panelName the panel name + * + * @return the panel + */ + @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + if (panelName.equals(tabDesktop.getTitleAt(i))) { + return (CArchPanelPan) tabDesktop.getComponentAt(i); + } + } + + final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); + + // insert new panel in alphabetical order + int i; + for (i = 0; i < tabDesktop.getTabCount() && panelName.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { + ; + } + tabDesktop.insertTab(panelName, null, newPanel, null, i); + + return newPanel; + } + + /** + * After the build process is completed and the panels have + * been fully constructed, we must correct the 'selectedPanel' + * setting and make sure the arch list is properly drawn. + */ + public void finishBuildProcess() { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); + } + + selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); + if (selectedPanel != null) { + selectedPanel.showArchList(); + } + + // we must set the list of the selected list depend on combo selection + tabDesktop.addChangeListener(new ChangeListener() { + public void stateChanged(final ChangeEvent e) { + final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); + setSelectedArch(null); + selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); + if (selectedPanel != null) { + selectedPanel.showArchList(); + } + } + }); + } + + public void appExitNotify() { + final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); + settings.setProperty(ARCHPANEL_LOCATION_KEY, String.valueOf(splitPane.getDividerLocation())); + } + + /** + * Get name of selected Arch. + * @return Name of selected arch in arch panel + */ + @Nullable public String getSelectedArch() { + return selectedArch == null ? null : selectedArch.getArchetypeName(); + } + + /** + * Set selected Arch. + * @param selectedArch name of selected arch in arch panel + */ + public void setSelectedArch(@Nullable final GameObject selectedArch) { + this.selectedArch = selectedArch; + } + + public void refresh() { + archQuickPanel.refresh(); + repaint(); + } + +} // class InsertionObjectChooser Property changes on: trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Deleted: trunk/daimonin/src/daieditor/CArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-26 23:15:35 UTC (rev 1292) +++ trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -1,236 +0,0 @@ -/* - * Daimonin 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 daieditor; - -import daieditor.gameobject.GameObject; -import daieditor.gui.map.tools.ToolPalette; -import daieditor.gui.ObjectChoiceDisplay; -import java.awt.BorderLayout; -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.gridarta.gui.GSplitPane; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * The <code>CArchPanel</code> holds the tile palette. - * @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> - * @author Andreas Kirschbaum - */ -public final class CArchPanel extends JPanel { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final transient CMainControl mainControl; - - /** ToolSelector of this subview. */ - private final ToolPalette toolPalette = new ToolPalette(); - - /** - * Name of the selected archetype. - * @serial include - */ - private GameObject selectedArch = null; - - /** Panel holding both archlist and pickmaps. */ - private final JTabbedPane archAndPickPane = new JTabbedPane(SwingConstants.TOP); - - /** The Tab panel with arch lists. */ - private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); - - /** The data/view of selected objects in tab panel. */ - private final ObjectChoiceDisplay archQuickPanel; - - /** The active panel. */ - private CArchPanelPan selectedPanel; - - /** - * Build Panel. - * @param mainControl CMainControl - */ - public CArchPanel(final CMainControl mainControl) { - super(new BorderLayout()); - this.mainControl = mainControl; - - tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); - archQuickPanel = new ObjectChoiceDisplay(mainControl); - - // archAndPickPane is the panel containing both archpanel and pickmaps - archAndPickPane.addTab("Arch List", tabDesktop); - archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); - // this listener informs the mainview which panel is active: archlist or pickmaps? - CPickmapPanel.getInstance().addArchNPickChangeListener(archAndPickPane); - - // calculate default value in case there is no settings file - - - // TODO: introduce a tool registry - add(new GSplitPane(JSplitPane.VERTICAL_SPLIT, toolPalette, archAndPickPane), BorderLayout.CENTER); - add(archQuickPanel, BorderLayout.SOUTH); - } - - /** Move the pickmap panel in front of the default-archpanel. */ - public void movePickmapPanelToFront() { - archAndPickPane.setSelectedIndex(1); - } - - /** - * Get the currently selected archetype. - * - * @return the selected archetype, or <code>null</code> if none is selected - */ - @Nullable public GameObject getArchPanelSelection() { - return selectedPanel != null ? selectedPanel.getArchListObject() : null; - } - - /** - * Show the given game object's attributes in the quick panel. - * - * @param gameObject the game object to show, or <code>null</code> to clear - * the attributes - */ - public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { - archQuickPanel.showArchPanelQuickObject(gameObject); - } - - /** - * Add a new archetype. Create the panel and/or folder if necessary. - * - * @param panelName the panel name to add the archetype to - * - * @param folderName the folder name to add the archetype to - * - * @param arch the archetype to add - */ - public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { - final CArchPanelPan panel = findOrCreatePanel(panelName); - panel.addArchetype(folderName, arch); - } - - /** - * Sets the enabled state of the tab pane for Archetypes. - * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. - */ - public void setTabPaneEnabled(final boolean tabPaneEnabled) { - tabDesktop.setEnabled(tabPaneEnabled); - if (tabPaneEnabled && selectedPanel != null) { - selectedPanel.showArchList(); - } - } - - /** - * Return a panel by name. If this panel does not exist, create a new one. - * - * @param panelName the panel name - * - * @return the panel - */ - @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { - for (int i = 0; i < tabDesktop.getTabCount(); i++) { - if (panelName.equals(tabDesktop.getTitleAt(i))) { - return (CArchPanelPan) tabDesktop.getComponentAt(i); - } - } - - final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); - - // insert new panel in alphabetical order - int i; - for (i = 0; i < tabDesktop.getTabCount() && panelName.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { - ; - } - tabDesktop.insertTab(panelName, null, newPanel, null, i); - - return newPanel; - } - - /** - * After the build process is completed and the panels have - * been fully constructed, we must correct the 'selectedPanel' - * setting and make sure the arch list is properly drawn. - */ - public void finishBuildProcess() { - for (int i = 0; i < tabDesktop.getTabCount(); i++) { - ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); - } - - selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); - if (selectedPanel != null) { - selectedPanel.showArchList(); - } - - // we must set the list of the selected list depend on combo selection - tabDesktop.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); - setSelectedArch(null); - selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); - if (selectedPanel != null) { - selectedPanel.showArchList(); - } - } - }); - } - - /** - * Get name of selected Arch. - * @return Name of selected arch in arch panel - */ - @Nullable public String getSelectedArch() { - return selectedArch == null ? null : selectedArch.getArchetypeName(); - } - - /** - * Set selected Arch. - * @param selectedArch name of selected arch in arch panel - */ - public void setSelectedArch(@Nullable final GameObject selectedArch) { - this.selectedArch = selectedArch; - } - - public void refresh() { - archQuickPanel.refresh(); - repaint(); - } - - /** - * Returns the tool selector pane. - * @return The tool selector pane. - */ - public ToolPalette getToolSelectorPane() { - return toolPalette; - } - -} // class CArchPanel Modified: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-26 23:15:35 UTC (rev 1292) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -26,6 +26,7 @@ package daieditor; import daieditor.gameobject.GameObject; +import daieditor.gui.InsertionObjectChooser; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; @@ -90,7 +91,7 @@ // This looks unused, but don't remove it. It will be used in future. private final JPopupMenu menu = createListPopupMenu(); - private final CArchPanel archPanel; + private final InsertionObjectChooser archPanel; /** * Comparator used to sort entries shown in {@link #archList}. @@ -109,7 +110,7 @@ private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); /* Build Panel */ - CArchPanelPan(final CArchPanel controlPanel, final CMainControl mainControl) { + public CArchPanelPan(final InsertionObjectChooser controlPanel, final CMainControl mainControl) { super(new BorderLayout()); this.mainControl = mainControl; archPanel = controlPanel; Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 23:15:35 UTC (rev 1292) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -27,6 +27,7 @@ import daieditor.gameobject.GameObject; import daieditor.gui.AboutDialog; import daieditor.gui.StatusBar; +import daieditor.gui.InsertionObjectChooser; import daieditor.gui.selectedsquare.SelectedSquareControl; import daieditor.map.MapControl; import daieditor.map.validation.ErrorCollector; @@ -125,7 +126,7 @@ private StatusBar statusBar; /** The panel that contains the palette view. */ - public CArchPanel archPanel; + public InsertionObjectChooser archPanel; /** The desktop that holds all level views. */ private JDesktopPane mapDesktop; @@ -220,7 +221,7 @@ CPickmapPanel.getInstance().addPickmapSelectionListener(pickmapPanel); statusBar = new StatusBar(mainControl); - archPanel = new CArchPanel(mainControl); + archPanel = new InsertionObjectChooser(mainControl); selectedSquareControl = new SelectedSquareControl(mainControl, this); mapDesktop = new JDesktopPane(); mapArchPanel = new CMapArchPanel(mainControl, this); Copied: trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java (from rev 1292, trunk/daimonin/src/daieditor/CArchPanel.java) =================================================================== --- trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2006-12-26 23:21:29 UTC (rev 1293) @@ -0,0 +1,239 @@ +/* + * Daimonin 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 daieditor.gui; + +import daieditor.CArchPanelPan; +import daieditor.CMainControl; +import daieditor.CPickmapPanel; +import daieditor.IGUIConstants; +import daieditor.gameobject.GameObject; +import daieditor.gui.map.tools.ToolPalette; +import java.awt.BorderLayout; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.GSplitPane; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The <code>InsertionObjectChooser</code> holds the tile palette. + * @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> + * @author Andreas Kirschbaum + */ +public final class InsertionObjectChooser extends JPanel { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final transient CMainControl mainControl; + + /** ToolSelector of this subview. */ + private final ToolPalette toolPalette = new ToolPalette(); + + /** + * Name of the selected archetype. + * @serial include + */ + private GameObject selectedArch = null; + + /** Panel holding both archlist and pickmaps. */ + private final JTabbedPane archAndPickPane = new JTabbedPane(SwingConstants.TOP); + + /** The Tab panel with arch lists. */ + private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); + + /** The data/view of selected objects in tab panel. */ + private final ObjectChoiceDisplay archQuickPanel; + + /** The active panel. */ + private CArchPanelPan selectedPanel; + + /** + * Build Panel. + * @param mainControl CMainControl + */ + public InsertionObjectChooser(final CMainControl mainControl) { + super(new BorderLayout()); + this.mainControl = mainControl; + + tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); + archQuickPanel = new ObjectChoiceDisplay(mainControl); + + // archAndPickPane is the panel containing both archpanel and pickmaps + archAndPickPane.addTab("Arch List", tabDesktop); + archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); + // this listener informs the mainview which panel is active: archlist or pickmaps? + CPickmapPanel.getInstance().addArchNPickChangeListener(archAndPickPane); + + // calculate default value in case there is no settings file + + + // TODO: introduce a tool registry + add(new GSplitPane(JSplitPane.VERTICAL_SPLIT, toolPalette, archAndPickPane), BorderLayout.CENTER); + add(archQuickPanel, BorderLayout.SOUTH); + } + + /** Move the pickmap panel in front of the default-archpanel. */ + public void movePickmapPanelToFront() { + archAndPickPane.setSelectedIndex(1); + } + + /** + * Get the currently selected archetype. + * + * @return the selected archetype, or <code>null</code> if none is selected + */ + @Nullable public GameObject getArchPanelSelection() { + return selectedPanel != null ? selectedPanel.getArchListObject() : null; + } + + /** + * Show the given game object's attributes in the quick panel. + * + * @param gameObject the game object to show, or <code>null</code> to clear + * the attributes + */ + public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { + archQuickPanel.showArchPanelQuickObject(gameObject); + } + + /** + * Add a new archetype. Create the panel and/or folder if necessary. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + final CArchPanelPan panel = findOrCreatePanel(panelName); + panel.addArchetype(folderName, arch); + } + + /** + * Sets the enabled state of the tab pane for Archetypes. + * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. + */ + public void setTabPaneEnabled(final boolean tabPaneEnabled) { + tabDesktop.setEnabled(tabPaneEnabled); + if (tabPaneEnabled && selectedPanel != null) { + selectedPanel.showArchList(); + } + } + + /** + * Return a panel by name. If this panel does not exist, create a new one. + * + * @param panelName the panel name + * + * @return the panel + */ + @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + if (panelName.equals(tabDesktop.getTitleAt(i))) { + return (CArchPanelPan) tabDesktop.getComponentAt(i); + } + } + + final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); + + // insert new panel in alphabetical order + int i; + for (i = 0; i < tabDesktop.getTabCount() && panelName.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { + ; + } + tabDesktop.insertTab(panelName, null, newPanel, null, i); + + return newPanel; + } + + /** + * After the build process is completed and the panels have + * been fully constructed, we must correct the 'selectedPanel' + * setting and make sure the arch list is properly drawn. + */ + public void finishBuildProcess() { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); + } + + selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); + if (selectedPanel != null) { + selectedPanel.showArchList(); + } + + // we must set the list of the selected list depend on combo selection + tabDesktop.addChangeListener(new ChangeListener() { + public void stateChanged(final ChangeEvent e) { + final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); + setSelectedArch(null); + selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); + if (selectedPanel != null) { + selectedPanel.showArchList(); + } + } + }); + } + + /** + * Get name of selected Arch. + * @return Name of selected arch in arch panel + */ + @Nullable public String getSelectedArch() { + return selectedArch == null ? null : selectedArch.getArchetypeName(); + } + + /** + * Set selected Arch. + * @param selectedArch name of selected arch in arch panel + */ + public void setSelectedArch(@Nullable final GameObject selectedArch) { + this.selectedArch = selectedArch; + } + + public void refresh() { + archQuickPanel.refresh(); + repaint(); + } + + /** + * Returns the tool selector pane. + * @return The tool selector pane. + */ + public ToolPalette getToolSelectorPane() { + return toolPalette; + } + +} // class InsertionObjectChooser Property changes on: trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 23:31:02
|
Revision: 1294 http://svn.sourceforge.net/gridarta/?rev=1294&view=rev Author: christianhujer Date: 2006-12-26 15:31:00 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CArchPanelPan to gui.ArchetypeChooser. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CArchPanelPan.java Deleted: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-26 23:21:29 UTC (rev 1293) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-26 23:31:00 UTC (rev 1294) @@ -1,254 +0,0 @@ -/* - * 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; - -import cfeditor.gameobject.GameObject; -import cfeditor.gui.InsertionObjectChooser; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.TreeSet; -import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JViewport; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -/** - * Panel for Archetypes. - * @author unknown - * @author Andreas Kirschbaum - */ -public final class CArchPanelPan extends JPanel { - - private static final Logger log = Logger.getLogger(CArchPanelPan.class); - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - /** - * List of archetypes for each folder. The folders correspond to the - * entries in {@link #comboBox}. - * @note The first entry is always <code>null</code>. - */ - private final ArrayList<ArrayList<GameObject>> folders = new ArrayList<ArrayList<GameObject>>(); - - /** - * The list of currently shown archetypes; it is updated from {@link - * #folders} each time a new folder is selected. - */ - private final JList archList; - - private final DefaultListModel model; - - private final JComboBox comboBox; - - private final InsertionObjectChooser archPanel; - - /** - * Comparator used to sort entries shown in {@link #archList}. - */ - private static final Comparator<GameObject> archComparator = new Comparator<GameObject>() - { - public int compare(final GameObject o1, final GameObject o2) { - return o1.getArchetypeName().compareToIgnoreCase(o2.getArchetypeName()); - } - }; - - /** - * Temporary variable used to collect and sort the archeteypes to be - * inserted into {@link #archList}. - */ - private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); - - /* Build Panel */ - public CArchPanelPan(final InsertionObjectChooser controlPanel, final CMainControl mainControl) { - super(new BorderLayout()); - this.mainControl = mainControl; - archPanel = controlPanel; - - comboBox = new JComboBox(); - - model = new DefaultListModel(); - archList = new JList(model); - archList.setCellRenderer(new MyCellRenderer()); - archList.setBackground(IGUIConstants.BG_COLOR); - archList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - final JScrollPane scrollPane = new JScrollPane(archList); - add(scrollPane, BorderLayout.CENTER); - add(comboBox, BorderLayout.NORTH); - scrollPane.setAutoscrolls(true); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - - comboBox.setAutoscrolls(true); - } - - public void finishBuildProcess() { - comboBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - showArchList(); - } - }); - - archList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - updateSelectedArchListObject(); - } - }); - } - - /** - * Get the GameObject currently selected in the list. - * @return GameObject or <code>null</code> if no selection - */ - public GameObject getArchListObject() { - return (GameObject) archList.getSelectedValue(); - } - - /** - * Show the selected archetype. - */ - private void updateSelectedArchListObject() { - final GameObject archetype = (GameObject) archList.getSelectedValue(); - mainControl.setStatusText(archetype != null ? archetype.getArchetypeName() : ""); - archPanel.setSelectedArch(archetype); - mainControl.showArchPanelQuickObject(archetype); - } - - /** - * Add an archetype to this panel. - * - * @param folderName the folder to add it to - * - * @param arch the archetype to add - */ - public void addArchetype(@NotNull final String folderName, @NotNull final GameObject arch) { - final ArrayList<GameObject> folder = findOrCreateFolder(folderName); - folder.add(arch); - } - - /** - * Return a folder by name. If this folder does not exist, create a new one. - * - * @param folderName the folder name - * - * @return the folder - */ - @NotNull private ArrayList<GameObject> findOrCreateFolder(@NotNull final String folderName) { - assert folders.size() == comboBox.getItemCount(); - for (int i = 1; i < folders.size(); i++) { - if (folderName.equals(comboBox.getItemAt(i))) { - return folders.get(i); - } - } - - if (folders.size() <= 0) { - comboBox.addItem("show all"); - folders.add(null); // first entry is always empty - } - - // insert new folder in alphabetical order - int i; - for (i = 1; i < folders.size(); i++) { - if (folderName.compareToIgnoreCase((String) comboBox.getItemAt(i)) <= 0) { - break; - } - } - - final ArrayList<GameObject> folder = new ArrayList<GameObject>(); - comboBox.insertItemAt(folderName, i); - folders.add(i, folder); - - return folder; - } - - /** - * Update {@link #archList} to contain the currently selected folder. - */ - public void showArchList() { - final int index = comboBox.getSelectedIndex(); - - sortedArchetypes.clear(); - if (index == 0) { - for (int i = 1; i < folders.size(); i++) { - sortedArchetypes.addAll(folders.get(i)); - } - } else if (index > 0) { - final ArrayList<GameObject> archList = folders.get(index); - if (archList != null) { - sortedArchetypes.addAll(archList); - } - } - - archList.setVisible(false); - model.removeAllElements(); - for (final GameObject arch : sortedArchetypes) { - model.addElement(arch); - } - archList.setVisible(true); - } - - /** Cell Renderer for rendering cells in the ArchPanelPan. */ - 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); - - final GameObject archetype = (GameObject) value; - setText(archetype.getArchetypeName()); - - if (archetype.getFaceFlag()) { - setIcon(CMainControl.getNofaceTileIcon()); - } else if (archetype.getFaceNr() == -1) { - setIcon(CMainControl.getUnknownTileIcon()); - } else { - setIcon(mainControl.getFace(archetype.getFaceNr())); - } - - return this; - } - - } // class MyCellRenderer - -} // class CArchPanelPan Copied: trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java (from rev 1293, trunk/crossfire/src/cfeditor/CArchPanelPan.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2006-12-26 23:31:00 UTC (rev 1294) @@ -0,0 +1,256 @@ +/* + * 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; + +import cfeditor.gameobject.GameObject; +import cfeditor.gui.InsertionObjectChooser; +import cfeditor.CMainControl; +import cfeditor.IGUIConstants; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.TreeSet; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.JComboBox; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JViewport; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +/** + * Panel for Archetypes. + * @author unknown + * @author Andreas Kirschbaum + */ +public final class ArchetypeChooser extends JPanel { + + private static final Logger log = Logger.getLogger(ArchetypeChooser.class); + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + /** + * List of archetypes for each folder. The folders correspond to the + * entries in {@link #comboBox}. + * @note The first entry is always <code>null</code>. + */ + private final ArrayList<ArrayList<GameObject>> folders = new ArrayList<ArrayList<GameObject>>(); + + /** + * The list of currently shown archetypes; it is updated from {@link + * #folders} each time a new folder is selected. + */ + private final JList archList; + + private final DefaultListModel model; + + private final JComboBox comboBox; + + private final InsertionObjectChooser archPanel; + + /** + * Comparator used to sort entries shown in {@link #archList}. + */ + private static final Comparator<GameObject> archComparator = new Comparator<GameObject>() + { + public int compare(final GameObject o1, final GameObject o2) { + return o1.getArchetypeName().compareToIgnoreCase(o2.getArchetypeName()); + } + }; + + /** + * Temporary variable used to collect and sort the archeteypes to be + * inserted into {@link #archList}. + */ + private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); + + /* Build Panel */ + public ArchetypeChooser(final InsertionObjectChooser controlPanel, final CMainControl mainControl) { + super(new BorderLayout()); + this.mainControl = mainControl; + archPanel = controlPanel; + + comboBox = new JComboBox(); + + model = new DefaultListModel(); + archList = new JList(model); + archList.setCellRenderer(new MyCellRenderer()); + archList.setBackground(IGUIConstants.BG_COLOR); + archList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final JScrollPane scrollPane = new JScrollPane(archList); + add(scrollPane, BorderLayout.CENTER); + add(comboBox, BorderLayout.NORTH); + scrollPane.setAutoscrolls(true); + scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + + comboBox.setAutoscrolls(true); + } + + public void finishBuildProcess() { + comboBox.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + showArchList(); + } + }); + + archList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(final ListSelectionEvent e) { + updateSelectedArchListObject(); + } + }); + } + + /** + * Get the GameObject currently selected in the list. + * @return GameObject or <code>null</code> if no selection + */ + public GameObject getArchListObject() { + return (GameObject) archList.getSelectedValue(); + } + + /** + * Show the selected archetype. + */ + private void updateSelectedArchListObject() { + final GameObject archetype = (GameObject) archList.getSelectedValue(); + mainControl.setStatusText(archetype != null ? archetype.getArchetypeName() : ""); + archPanel.setSelectedArch(archetype); + mainControl.showArchPanelQuickObject(archetype); + } + + /** + * Add an archetype to this panel. + * + * @param folderName the folder to add it to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String folderName, @NotNull final GameObject arch) { + final ArrayList<GameObject> folder = findOrCreateFolder(folderName); + folder.add(arch); + } + + /** + * Return a folder by name. If this folder does not exist, create a new one. + * + * @param folderName the folder name + * + * @return the folder + */ + @NotNull private ArrayList<GameObject> findOrCreateFolder(@NotNull final String folderName) { + assert folders.size() == comboBox.getItemCount(); + for (int i = 1; i < folders.size(); i++) { + if (folderName.equals(comboBox.getItemAt(i))) { + return folders.get(i); + } + } + + if (folders.size() <= 0) { + comboBox.addItem("show all"); + folders.add(null); // first entry is always empty + } + + // insert new folder in alphabetical order + int i; + for (i = 1; i < folders.size(); i++) { + if (folderName.compareToIgnoreCase((String) comboBox.getItemAt(i)) <= 0) { + break; + } + } + + final ArrayList<GameObject> folder = new ArrayList<GameObject>(); + comboBox.insertItemAt(folderName, i); + folders.add(i, folder); + + return folder; + } + + /** + * Update {@link #archList} to contain the currently selected folder. + */ + public void showArchList() { + final int index = comboBox.getSelectedIndex(); + + sortedArchetypes.clear(); + if (index == 0) { + for (int i = 1; i < folders.size(); i++) { + sortedArchetypes.addAll(folders.get(i)); + } + } else if (index > 0) { + final ArrayList<GameObject> archList = folders.get(index); + if (archList != null) { + sortedArchetypes.addAll(archList); + } + } + + archList.setVisible(false); + model.removeAllElements(); + for (final GameObject arch : sortedArchetypes) { + model.addElement(arch); + } + archList.setVisible(true); + } + + /** Cell Renderer for rendering cells in the ArchPanelPan. */ + 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); + + final GameObject archetype = (GameObject) value; + setText(archetype.getArchetypeName()); + + if (archetype.getFaceFlag()) { + setIcon(CMainControl.getNofaceTileIcon()); + } else if (archetype.getFaceNr() == -1) { + setIcon(CMainControl.getUnknownTileIcon()); + } else { + setIcon(mainControl.getFace(archetype.getFaceNr())); + } + + return this; + } + + } // class MyCellRenderer + +} // class ArchetypeChooser Property changes on: trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:21:29 UTC (rev 1293) +++ trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:31:00 UTC (rev 1294) @@ -25,7 +25,7 @@ package cfeditor.gui; -import cfeditor.CArchPanelPan; +import cfeditor.gui.ArchetypeChooser; import cfeditor.CMainControl; import cfeditor.CPickmapPanel; import cfeditor.CSettings; @@ -80,7 +80,7 @@ private final ObjectChoiceDisplay archQuickPanel; /** The active panel. */ - private CArchPanelPan selectedPanel; + private ArchetypeChooser selectedPanel; /** * Build Panel. @@ -144,7 +144,7 @@ * @param arch the archetype to add */ public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { - final CArchPanelPan panel = findOrCreatePanel(panelName); + final ArchetypeChooser panel = findOrCreatePanel(panelName); panel.addArchetype(folderName, arch); } @@ -166,14 +166,14 @@ * * @return the panel */ - @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { + @NotNull private ArchetypeChooser findOrCreatePanel(@NotNull final String panelName) { for (int i = 0; i < tabDesktop.getTabCount(); i++) { if (panelName.equals(tabDesktop.getTitleAt(i))) { - return (CArchPanelPan) tabDesktop.getComponentAt(i); + return (ArchetypeChooser) tabDesktop.getComponentAt(i); } } - final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); + final ArchetypeChooser newPanel = new ArchetypeChooser(this, mainControl); // insert new panel in alphabetical order int i; @@ -192,10 +192,10 @@ */ public void finishBuildProcess() { for (int i = 0; i < tabDesktop.getTabCount(); i++) { - ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); + ((ArchetypeChooser) tabDesktop.getComponentAt(i)).finishBuildProcess(); } - selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); + selectedPanel = (ArchetypeChooser) tabDesktop.getSelectedComponent(); if (selectedPanel != null) { selectedPanel.showArchList(); } @@ -205,7 +205,7 @@ public void stateChanged(final ChangeEvent e) { final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); setSelectedArch(null); - selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); + selectedPanel = (ArchetypeChooser) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); if (selectedPanel != null) { selectedPanel.showArchList(); } Deleted: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-26 23:21:29 UTC (rev 1293) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-26 23:31:00 UTC (rev 1294) @@ -1,296 +0,0 @@ -/* - * Daimonin 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 daieditor; - -import daieditor.gameobject.GameObject; -import daieditor.gui.InsertionObjectChooser; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.TreeSet; -import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.ImageIcon; -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JViewport; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -/** - * Panel for Archetypes. - * @author unknown - * @author Andreas Kirschbaum - */ -public final class CArchPanelPan extends JPanel { - - private static final Logger log = Logger.getLogger(CArchPanelPan.class); - - /** 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; - - /** - * List of archetypes for each folder. The folders correspond to the - * entries in {@link #comboBox}. - * @note The first entry is always <code>null</code>. - */ - private final ArrayList<ArrayList<GameObject>> folders = new ArrayList<ArrayList<GameObject>>(); - - /** - * The list of currently shown archetypes; it is updated from {@link - * #folders} each time a new folder is selected. - */ - private final JList archList; - - private final DefaultListModel model; - - private final JComboBox comboBox; - - /** The popup menu for the arch lists to bring up the editor. */ - // This looks unused, but don't remove it. It will be used in future. - private final JPopupMenu menu = createListPopupMenu(); - - private final InsertionObjectChooser archPanel; - - /** - * Comparator used to sort entries shown in {@link #archList}. - */ - private static final Comparator<GameObject> archComparator = new Comparator<GameObject>() - { - public int compare(final GameObject o1, final GameObject o2) { - return o1.getArchetypeName().compareToIgnoreCase(o2.getArchetypeName()); - } - }; - - /** - * Temporary variable used to collect and sort the archeteypes to be - * inserted into {@link #archList}. - */ - private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); - - /* Build Panel */ - public CArchPanelPan(final InsertionObjectChooser controlPanel, final CMainControl mainControl) { - super(new BorderLayout()); - this.mainControl = mainControl; - archPanel = controlPanel; - - comboBox = new JComboBox(); - - model = new DefaultListModel(); - archList = new JList(model); - archList.setCellRenderer(new MyCellRenderer()); - archList.setBackground(IGUIConstants.BG_COLOR); - archList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - final JScrollPane scrollPane = new JScrollPane(archList); - add(scrollPane, BorderLayout.CENTER); - add(comboBox, BorderLayout.NORTH); - scrollPane.setAutoscrolls(true); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - - comboBox.setAutoscrolls(true); - } - - public void finishBuildProcess() { - // listening for mouse-click events in the ArchPanel list - archList.addMouseListener(new MouseAdapter() { - @Override public void mousePressed(final MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON3) { - //this will display the future arch editor. - //Because editing default arches is not yet possible, this line is commented in production. - //menu.show((Component) e.getSource(), e.getX(), e.getY()); - } - } - }); - - comboBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - showArchList(); - } - }); - - archList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - updateSelectedArchListObject(); - } - }); - - //archList.setComponentPopupMenu(menu); - } - - private JPopupMenu createListPopupMenu() { - final JPopupMenu menu = new JPopupMenu(); - menu.add(ACTION_FACTORY.createAction(false, "editPopup", this)); - return menu; - } - - /** - * Action method for the popup menu to edit a default arch. - */ - public void editPopup() { - final GameObject arch = getArchListObject(); - CAttribDialog.showAttribDialog(mainControl.getTypeList(), arch, mainControl); - } - - /** - * Get the GameObject currently selected in the list. - * @return GameObject or <code>null</code> if no selection - */ - public GameObject getArchListObject() { - return (GameObject) archList.getSelectedValue(); - } - - /** - * Show the selected archetype. - */ - private void updateSelectedArchListObject() { - final GameObject archetype = (GameObject) archList.getSelectedValue(); - mainControl.setStatusText(archetype != null ? archetype.getArchetypeName() : ""); - archPanel.setSelectedArch(archetype); - mainControl.showArchPanelQuickObject(archetype); - } - - /** - * Add an archetype to this panel. - * - * @param folderName the folder to add it to - * - * @param arch the archetype to add - */ - public void addArchetype(@NotNull final String folderName, @NotNull final GameObject arch) { - final ArrayList<GameObject> folder = findOrCreateFolder(folderName); - folder.add(arch); - } - - /** - * Return a folder by name. If this folder does not exist, create a new one. - * - * @param folderName the folder name - * - * @return the folder - */ - @NotNull private ArrayList<GameObject> findOrCreateFolder(@NotNull final String folderName) { - assert folders.size() == comboBox.getItemCount(); - for (int i = 1; i < folders.size(); i++) { - if (folderName.equals(comboBox.getItemAt(i))) { - return folders.get(i); - } - } - - if (folders.size() <= 0) { - comboBox.addItem("show all"); - folders.add(null); // first entry is always empty - } - - // insert new folder in alphabetical order - int i; - for (i = 1; i < folders.size(); i++) { - if (folderName.compareToIgnoreCase((String) comboBox.getItemAt(i)) <= 0) { - break; - } - } - - final ArrayList<GameObject> folder = new ArrayList<GameObject>(); - comboBox.insertItemAt(folderName, i); - folders.add(i, folder); - - return folder; - } - - /** - * Update {@link #archList} to contain the currently selected folder. - */ - public void showArchList() { - final int index = comboBox.getSelectedIndex(); - - sortedArchetypes.clear(); - if (index == 0) { - for (int i = 1; i < folders.size(); i++) { - sortedArchetypes.addAll(folders.get(i)); - } - } else if (index > 0) { - final ArrayList<GameObject> archList = folders.get(index); - if (archList != null) { - sortedArchetypes.addAll(archList); - } - } - - archList.setVisible(false); - model.removeAllElements(); - for (final GameObject arch : sortedArchetypes) { - model.addElement(arch); - } - archList.setVisible(true); - } - - /** Cell Renderer for rendering cells in the ArchPanelPan. */ - 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); - - final GameObject archetype = (GameObject) value; - setText(archetype.getArchetypeName()); - - if (archetype.hasFaceObject()) { - setIcon(CMainControl.getNofaceTileIcon()); - } else { - final ImageIcon icon = mainControl.getArchetypeSet().getFace(archetype.getFaceRealName()); - if (icon == null) { - //setIcon(mainControl.nofaceTileIcon); - } else { - setIcon(icon); - } - } - - return this; - } - - } // class MyCellRenderer - -} // class CArchPanelPan Copied: trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java (from rev 1293, trunk/daimonin/src/daieditor/CArchPanelPan.java) =================================================================== --- trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2006-12-26 23:31:00 UTC (rev 1294) @@ -0,0 +1,299 @@ +/* + * Daimonin 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 daieditor.gui; + +import daieditor.gameobject.GameObject; +import daieditor.gui.InsertionObjectChooser; +import daieditor.CMainControl; +import daieditor.IGUIConstants; +import daieditor.CAttribDialog; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.TreeSet; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.ImageIcon; +import javax.swing.JComboBox; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JViewport; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +/** + * Panel for Archetypes. + * @author unknown + * @author Andreas Kirschbaum + */ +public final class ArchetypeChooser extends JPanel { + + private static final Logger log = Logger.getLogger(ArchetypeChooser.class); + + /** 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; + + /** + * List of archetypes for each folder. The folders correspond to the + * entries in {@link #comboBox}. + * @note The first entry is always <code>null</code>. + */ + private final ArrayList<ArrayList<GameObject>> folders = new ArrayList<ArrayList<GameObject>>(); + + /** + * The list of currently shown archetypes; it is updated from {@link + * #folders} each time a new folder is selected. + */ + private final JList archList; + + private final DefaultListModel model; + + private final JComboBox comboBox; + + /** The popup menu for the arch lists to bring up the editor. */ + // This looks unused, but don't remove it. It will be used in future. + private final JPopupMenu menu = createListPopupMenu(); + + private final InsertionObjectChooser archPanel; + + /** + * Comparator used to sort entries shown in {@link #archList}. + */ + private static final Comparator<GameObject> archComparator = new Comparator<GameObject>() + { + public int compare(final GameObject o1, final GameObject o2) { + return o1.getArchetypeName().compareToIgnoreCase(o2.getArchetypeName()); + } + }; + + /** + * Temporary variable used to collect and sort the archeteypes to be + * inserted into {@link #archList}. + */ + private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); + + /* Build Panel */ + public ArchetypeChooser(final InsertionObjectChooser controlPanel, final CMainControl mainControl) { + super(new BorderLayout()); + this.mainControl = mainControl; + archPanel = controlPanel; + + comboBox = new JComboBox(); + + model = new DefaultListModel(); + archList = new JList(model); + archList.setCellRenderer(new MyCellRenderer()); + archList.setBackground(IGUIConstants.BG_COLOR); + archList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final JScrollPane scrollPane = new JScrollPane(archList); + add(scrollPane, BorderLayout.CENTER); + add(comboBox, BorderLayout.NORTH); + scrollPane.setAutoscrolls(true); + scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + + comboBox.setAutoscrolls(true); + } + + public void finishBuildProcess() { + // listening for mouse-click events in the ArchPanel list + archList.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(final MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3) { + //this will display the future arch editor. + //Because editing default arches is not yet possible, this line is commented in production. + //menu.show((Component) e.getSource(), e.getX(), e.getY()); + } + } + }); + + comboBox.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + showArchList(); + } + }); + + archList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(final ListSelectionEvent e) { + updateSelectedArchListObject(); + } + }); + + //archList.setComponentPopupMenu(menu); + } + + private JPopupMenu createListPopupMenu() { + final JPopupMenu menu = new JPopupMenu(); + menu.add(ACTION_FACTORY.createAction(false, "editPopup", this)); + return menu; + } + + /** + * Action method for the popup menu to edit a default arch. + */ + public void editPopup() { + final GameObject arch = getArchListObject(); + CAttribDialog.showAttribDialog(mainControl.getTypeList(), arch, mainControl); + } + + /** + * Get the GameObject currently selected in the list. + * @return GameObject or <code>null</code> if no selection + */ + public GameObject getArchListObject() { + return (GameObject) archList.getSelectedValue(); + } + + /** + * Show the selected archetype. + */ + private void updateSelectedArchListObject() { + final GameObject archetype = (GameObject) archList.getSelectedValue(); + mainControl.setStatusText(archetype != null ? archetype.getArchetypeName() : ""); + archPanel.setSelectedArch(archetype); + mainControl.showArchPanelQuickObject(archetype); + } + + /** + * Add an archetype to this panel. + * + * @param folderName the folder to add it to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String folderName, @NotNull final GameObject arch) { + final ArrayList<GameObject> folder = findOrCreateFolder(folderName); + folder.add(arch); + } + + /** + * Return a folder by name. If this folder does not exist, create a new one. + * + * @param folderName the folder name + * + * @return the folder + */ + @NotNull private ArrayList<GameObject> findOrCreateFolder(@NotNull final String folderName) { + assert folders.size() == comboBox.getItemCount(); + for (int i = 1; i < folders.size(); i++) { + if (folderName.equals(comboBox.getItemAt(i))) { + return folders.get(i); + } + } + + if (folders.size() <= 0) { + comboBox.addItem("show all"); + folders.add(null); // first entry is always empty + } + + // insert new folder in alphabetical order + int i; + for (i = 1; i < folders.size(); i++) { + if (folderName.compareToIgnoreCase((String) comboBox.getItemAt(i)) <= 0) { + break; + } + } + + final ArrayList<GameObject> folder = new ArrayList<GameObject>(); + comboBox.insertItemAt(folderName, i); + folders.add(i, folder); + + return folder; + } + + /** + * Update {@link #archList} to contain the currently selected folder. + */ + public void showArchList() { + final int index = comboBox.getSelectedIndex(); + + sortedArchetypes.clear(); + if (index == 0) { + for (int i = 1; i < folders.size(); i++) { + sortedArchetypes.addAll(folders.get(i)); + } + } else if (index > 0) { + final ArrayList<GameObject> archList = folders.get(index); + if (archList != null) { + sortedArchetypes.addAll(archList); + } + } + + archList.setVisible(false); + model.removeAllElements(); + for (final GameObject arch : sortedArchetypes) { + model.addElement(arch); + } + archList.setVisible(true); + } + + /** Cell Renderer for rendering cells in the ArchPanelPan. */ + 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); + + final GameObject archetype = (GameObject) value; + setText(archetype.getArchetypeName()); + + if (archetype.hasFaceObject()) { + setIcon(CMainControl.getNofaceTileIcon()); + } else { + final ImageIcon icon = mainControl.getArchetypeSet().getFace(archetype.getFaceRealName()); + if (icon == null) { + //setIcon(mainControl.nofaceTileIcon); + } else { + setIcon(icon); + } + } + + return this; + } + + } // class MyCellRenderer + +} // class ArchetypeChooser Property changes on: trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2006-12-26 23:21:29 UTC (rev 1293) +++ trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2006-12-26 23:31:00 UTC (rev 1294) @@ -25,7 +25,7 @@ package daieditor.gui; -import daieditor.CArchPanelPan; +import daieditor.gui.ArchetypeChooser; import daieditor.CMainControl; import daieditor.CPickmapPanel; import daieditor.IGUIConstants; @@ -77,7 +77,7 @@ private final ObjectChoiceDisplay archQuickPanel; /** The active panel. */ - private CArchPanelPan selectedPanel; + private ArchetypeChooser selectedPanel; /** * Build Panel. @@ -138,7 +138,7 @@ * @param arch the archetype to add */ public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { - final CArchPanelPan panel = findOrCreatePanel(panelName); + final ArchetypeChooser panel = findOrCreatePanel(panelName); panel.addArchetype(folderName, arch); } @@ -160,14 +160,14 @@ * * @return the panel */ - @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { + @NotNull private ArchetypeChooser findOrCreatePanel(@NotNull final String panelName) { for (int i = 0; i < tabDesktop.getTabCount(); i++) { if (panelName.equals(tabDesktop.getTitleAt(i))) { - return (CArchPanelPan) tabDesktop.getComponentAt(i); + return (ArchetypeChooser) tabDesktop.getComponentAt(i); } } - final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); + final ArchetypeChooser newPanel = new ArchetypeChooser(this, mainControl); // insert new panel in alphabetical order int i; @@ -186,10 +186,10 @@ */ public void finishBuildProcess() { for (int i = 0; i < tabDesktop.getTabCount(); i++) { - ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); + ((ArchetypeChooser) tabDesktop.getComponentAt(i)).finishBuildProcess(); } - selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); + selectedPanel = (ArchetypeChooser) tabDesktop.getSelectedComponent(); if (selectedPanel != null) { selectedPanel.showArchList(); } @@ -199,7 +199,7 @@ public void stateChanged(final ChangeEvent e) { final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); setSelectedArch(null); - selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); + selectedPanel = (ArchetypeChooser) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); if (selectedPanel != null) { selectedPanel.showArchList(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 23:36:53
|
Revision: 1295 http://svn.sourceforge.net/gridarta/?rev=1295&view=rev Author: christianhujer Date: 2006-12-26 15:36:52 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Optimized imports. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java trunk/crossfire/src/cfeditor/io/CMapReader.java trunk/crossfire/src/cfeditor/io/CMapWriter.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/IGUIConstants.java trunk/daimonin/src/daieditor/MultiPositionData.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java trunk/daimonin/src/test/daieditor/io/PathManagerTest.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -25,8 +25,8 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.gui.InsertionObjectChooser; import cfeditor.gui.StatusBar; -import cfeditor.gui.InsertionObjectChooser; import cfeditor.gui.selectedsquare.SelectedSquareControl; import cfeditor.map.MapControl; import cfeditor.menu.AggregateMenuLocation; Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -26,7 +26,6 @@ import java.awt.Color; import java.awt.Insets; -import java.io.File; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; Modified: trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -25,10 +25,9 @@ package cfeditor.gui; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.InsertionObjectChooser; import cfeditor.CMainControl; import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; Modified: trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -25,7 +25,6 @@ package cfeditor.gui; -import cfeditor.gui.ArchetypeChooser; import cfeditor.CMainControl; import cfeditor.CPickmapPanel; import cfeditor.CSettings; Modified: trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -24,10 +24,10 @@ package cfeditor.gui; -import cfeditor.gameobject.GameObject; +import cfeditor.CFArchType; import cfeditor.CMainControl; -import cfeditor.CFArchType; import cfeditor.ReplaceDialog; +import cfeditor.gameobject.GameObject; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; Modified: trunk/crossfire/src/cfeditor/io/CMapReader.java =================================================================== --- trunk/crossfire/src/cfeditor/io/CMapReader.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/io/CMapReader.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -29,11 +29,9 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.List; import net.sf.gridarta.io.AbstractMapReader; import net.sf.gridarta.io.MapReader; import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** Modified: trunk/crossfire/src/cfeditor/io/CMapWriter.java =================================================================== --- trunk/crossfire/src/cfeditor/io/CMapWriter.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/crossfire/src/cfeditor/io/CMapWriter.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -32,7 +32,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; -import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Map; Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -26,8 +26,8 @@ import daieditor.gameobject.GameObject; import daieditor.gui.AboutDialog; +import daieditor.gui.InsertionObjectChooser; import daieditor.gui.StatusBar; -import daieditor.gui.InsertionObjectChooser; import daieditor.gui.selectedsquare.SelectedSquareControl; import daieditor.map.MapControl; import daieditor.map.validation.ErrorCollector; Modified: trunk/daimonin/src/daieditor/IGUIConstants.java =================================================================== --- trunk/daimonin/src/daieditor/IGUIConstants.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/IGUIConstants.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -25,7 +25,6 @@ import java.awt.Color; import java.awt.Insets; -import java.io.File; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; Modified: trunk/daimonin/src/daieditor/MultiPositionData.java =================================================================== --- trunk/daimonin/src/daieditor/MultiPositionData.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/MultiPositionData.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -27,7 +27,6 @@ import java.awt.Dimension; import java.awt.Point; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -31,9 +31,9 @@ import daieditor.CPickmapPanel; import daieditor.IGUIConstants; import daieditor.gameobject.anim.AnimationObjects; +import daieditor.gameobject.face.ArchFaceProvider; import daieditor.gameobject.face.DuplicateFaceException; import daieditor.gameobject.face.FaceObjects; -import daieditor.gameobject.face.ArchFaceProvider; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; Modified: trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -25,11 +25,10 @@ package daieditor.gui; -import daieditor.gameobject.GameObject; -import daieditor.gui.InsertionObjectChooser; +import daieditor.CAttribDialog; import daieditor.CMainControl; import daieditor.IGUIConstants; -import daieditor.CAttribDialog; +import daieditor.gameobject.GameObject; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; Modified: trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -25,7 +25,6 @@ package daieditor.gui; -import daieditor.gui.ArchetypeChooser; import daieditor.CMainControl; import daieditor.CPickmapPanel; import daieditor.IGUIConstants; Modified: trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -24,10 +24,10 @@ package daieditor.gui; -import daieditor.gameobject.GameObject; +import daieditor.CFArchType; import daieditor.CMainControl; -import daieditor.CFArchType; import daieditor.ReplaceDialog; +import daieditor.gameobject.GameObject; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; Modified: trunk/daimonin/src/test/daieditor/io/PathManagerTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/io/PathManagerTest.java 2006-12-26 23:31:00 UTC (rev 1294) +++ trunk/daimonin/src/test/daieditor/io/PathManagerTest.java 2006-12-26 23:36:52 UTC (rev 1295) @@ -1,8 +1,8 @@ package test.daieditor.io; import daieditor.io.PathManager; +import org.junit.Assert; import org.junit.Test; -import org.junit.Assert; /** * Test for {@link PathManager}. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-26 23:40:47
|
Revision: 1296 http://svn.sourceforge.net/gridarta/?rev=1296&view=rev Author: christianhujer Date: 2006-12-26 15:40:48 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CPickmapPanel to gui.PickmapChooser. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CNewMapDialog.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/CNewMapDialog.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java trunk/daimonin/src/daieditor/map/MapControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/PickmapChooser.java trunk/daimonin/src/daieditor/gui/PickmapChooser.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/daimonin/src/daieditor/CPickmapPanel.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -30,6 +30,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.face.FaceObjects; +import cfeditor.gui.PickmapChooser; import cfeditor.gui.map.MapCursorControl; import cfeditor.gui.map.MapPropertiesDialog; import cfeditor.gui.prefs.GUIPrefs; @@ -232,7 +233,7 @@ readGlobalSettings(); // initialize pickmap panel (needed early during the loading process) - new CPickmapPanel(); + new PickmapChooser(); // initialize the script-editor pad ScriptEditControl.init(strMapDir, this); @@ -770,13 +771,13 @@ /** Invoked when the user wants to close the active pickmap. */ public void closePickmap() { - if (!CPickmapPanel.getInstance().isLoadComplete()) { + if (!PickmapChooser.getInstance().isLoadComplete()) { ACTION_FACTORY.showMessageDialog(mainView, "closePickmapNotLoaded"); } else { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "closePickmapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "closePickmapNoPickmaps"); } else { @@ -837,7 +838,7 @@ if (level.isPickmap()) { // special case: close a pickmap - CPickmapPanel.getInstance().closePickmap(level); + PickmapChooser.getInstance().closePickmap(level); level.levelCloseNotify(); } else { // Notify the level about the closing @@ -858,13 +859,13 @@ /** Open active pickmap as normal map for extensive editing. */ public void openPickmapMap() { - if (!CPickmapPanel.getInstance().isLoadComplete()) { + if (!PickmapChooser.getInstance().isLoadComplete()) { ACTION_FACTORY.showMessageDialog(mainView, "openPickmapMapNotLoaded"); } else { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "openPickmapMapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "openPickmapNoPickmaps"); } else { @@ -1038,7 +1039,7 @@ * @note The current implementation always returns <code>true</code>. * @todo Check whether <code>return false;</code> ever happens, and if not, change method return type to <code>void</code>. */ - boolean collectTempList(final List<GameObject> objects, final File file) { + public boolean collectTempList(final List<GameObject> objects, final File file) { final List<GameObject> tailList = new ArrayList<GameObject>(); // first: attach our map sucker to a default arch we have loaded @@ -1089,11 +1090,11 @@ /** Save current active pickmap. */ public void savePickmap() { - if (CPickmapPanel.getInstance().isLoadComplete()) { + if (PickmapChooser.getInstance().isLoadComplete()) { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "savePickmapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "savePickmapNoPickmaps"); } else { @@ -1569,13 +1570,13 @@ /** Invoked when user wants to revert the current pickmap to previously saved state. */ public void revertPickmap() { - if (!CPickmapPanel.getInstance().isLoadComplete()) { + if (!PickmapChooser.getInstance().isLoadComplete()) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapNotLoaded"); } else { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapNoPickmaps"); } else { @@ -1587,8 +1588,8 @@ } closeLevel(activePickmap, true); // close the old map - CPickmapPanel.getInstance().openPickmap(mfile); // open the new map - CPickmapPanel.getInstance().setActivePickmap(mfile.getName()); + PickmapChooser.getInstance().openPickmap(mfile); // open the new map + PickmapChooser.getInstance().setActivePickmap(mfile.getName()); // Update the main view so the new map instantly pops up. mainView.update(mainView.getGraphics()); Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -26,6 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.InsertionObjectChooser; +import cfeditor.gui.PickmapChooser; import cfeditor.gui.StatusBar; import cfeditor.gui.selectedsquare.SelectedSquareControl; import cfeditor.map.MapControl; @@ -215,7 +216,7 @@ // initialize pickmap panel pickmapPanel = new JTabbedPane(SwingConstants.TOP); pickmapPanel.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); - CPickmapPanel.getInstance().addPickmapSelectionListener(pickmapPanel); + PickmapChooser.getInstance().addPickmapSelectionListener(pickmapPanel); statusBar = new StatusBar(mainControl); getContentPane().add(statusBar, BorderLayout.SOUTH); @@ -331,9 +332,9 @@ */ public GameObject getArchPanelHighlight() { - if ((isPickmapActive() || archPanel.getArchPanelSelection() == null) && CPickmapPanel.getInstance().isLoadComplete() && CPickmapPanel.getInstance().getCurrentPickmap() != null) { + if ((isPickmapActive() || archPanel.getArchPanelSelection() == null) && PickmapChooser.getInstance().isLoadComplete() && PickmapChooser.getInstance().getCurrentPickmap() != null) { // get the active pickmap - final MapControl pmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl pmap = PickmapChooser.getInstance().getCurrentPickmap(); if (pmap != null && pmap.getMapViewFrame().isHighlight()) { // now try to get the topmost object Modified: trunk/crossfire/src/cfeditor/CNewMapDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -25,6 +25,7 @@ package cfeditor; import cfeditor.gameobject.ArchetypeSet; +import cfeditor.gui.PickmapChooser; import cfeditor.map.MapArchObject; import java.awt.Component; import java.awt.FlowLayout; @@ -256,7 +257,7 @@ if (mapType == MapType.GAMEMAP) { mainControl.newLevel(null, maparch, true, null); } else if (mapType == MapType.PICKMAP) { - return CPickmapPanel.getInstance().addNewPickmap(parent, maparch); + return PickmapChooser.getInstance().addNewPickmap(parent, maparch); } return true; Deleted: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -1,387 +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.io.CMapReader; -import cfeditor.map.MapArchObject; -import cfeditor.map.MapControl; -import java.awt.Component; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import javax.swing.JTabbedPane; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; - -/** - * The <code>CPickmapPanel</code> manages the pickmap panel - * and most pickmap-related code in general. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CPickmapPanel { - - private static final Logger log = Logger.getLogger(CPickmapPanel.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** Singleton instance of this class. */ - private static CPickmapPanel instance; - - private final CMainControl mainControl; // main control reference - - private boolean loadComplete; // true when all pickmaps have been loaded (at least one) - - private JTabbedPane tabpane = null; // tab pane with pickmaps - - /** All open pickmaps (the map controllers get stored in the vector). */ - private final Map<String, MapControl> pickmaps = new HashMap<String, MapControl>(); - - /** The current active pickmap ontop. */ - private MapControl currentPickMap; - - /** - * Create a CPickmapPanel. - */ - public CPickmapPanel() { - mainControl = CMainControl.getInstance(); - instance = this; - loadComplete = false; - currentPickMap = null; - } - - /** - * Return the singleton instance of this class. - * @return the singleton instance of this class - */ - public static CPickmapPanel getInstance() { - return instance; - } - - /** - * Return whether loading of pickmaps is complete and at least one pickmap is available. - * @return <code>true</code> if loading of pickmaps is complete and at least one pickmap is available, otherwise <code>false</code> - * @todo check whether this method returns <code>true</code> or <code>false</code> if the loading process is complete but no pickmaps are availbale. - */ - public boolean isLoadComplete() { - return loadComplete; - } - - /** - * Return the currently active pickmap. - * If there is no currently active pickmap, this method returns <code>null</code>. - * @return the currently active pickmap or <code>null</code> if there is no pickmap - */ - public MapControl getCurrentPickmap() { - return currentPickMap; - } - - /** - * Load all pickmaps and build the pickmap-panel. - */ - public void loadPickmaps() { - // the main-panel for pickmaps: - tabpane = mainControl.getMainView().getPickmapPanel(); - - final File pickmapDir = new File(IGUIConstants.PICKMAP_DIR); - if (!pickmapDir.exists() || !pickmapDir.isDirectory()) { - log.warn("No pickmaps directory found."); - return; - } - - final File[] flist = pickmapDir.listFiles(); // list of files - Arrays.sort(flist); - for (final File aFlist : flist) { - // open the pickmaps - if (aFlist.isFile()) { - openPickmap(aFlist); - } - } - mainControl.refreshMenusAndToolbars(); - - // did we get something? - if (!pickmaps.isEmpty()) { - loadComplete = true; - } - - updateActivePickmap(); // make sure we know which one is on top - } - - /** - * Open and load a pickmap from the given file. - * @param mapFile the map file - * @return true when pickmap was opened successfully - */ - public boolean openPickmap(final File mapFile) { - // open the pickmaps - final CMapViewBasic bmapview; - final MapArchObject maparch; - - try { - final CMapReader decoder = new CMapReader(mapFile); - final List<GameObject> objects = decoder.decodeMapFile(); // parse mapfile - maparch = decoder.getMapArch(); // get map arch - - if (objects == null) { - // The map is totally empty - bmapview = newPickmap(null, maparch, mapFile); // init the map - } else { - // go to ArchetypeParser and add the default arch list information to them - if (!mainControl.collectTempList(objects, mapFile)) { // get face names, face id, etc. - return false; - } - mainControl.getArchetypeParser().sortTempList(objects); // sort the list (put multiparts at the end) - bmapview = newPickmap(objects, maparch, mapFile); // init the map - } - - // looks like it worked, so we add a panel and display this pickmap - if (bmapview != null) { - int i; - for (i = 0; i < tabpane.getTabCount() && mapFile.getName().compareToIgnoreCase(tabpane.getTitleAt(i)) < 0; i++) { - ; - } - tabpane.insertTab(mapFile.getName(), null, bmapview, null, i); - return true; - } - } catch (final IOException e) { - // loading failed - could be a system file in that directory, - // or something else. Doesn't deserve more attention than a printout. - if (!mapFile.getName().startsWith(".")) { - log.warn("Couldn't load pickmap", e); - } - } - return false; - } - - /** - * Create a new pickmap and display it. - * @param parent the parent component to be used for error messages - * @param maparch MapArchObject containing map name and -size - * @return <code>true</code> if the pickmap was added, <code>false</code> - * if an error has occurred - */ - public boolean addNewPickmap(final Component parent, final MapArchObject maparch) { - - final File mapFile = new File(IGUIConstants.PICKMAP_DIR, maparch.getFileName()); - if (mapFile.exists()) { - ACTION_FACTORY.showMessageDialog(parent, "pickmapExists", mapFile); - return false; - } - if (!mapFile.getParentFile().exists()) { - mapFile.getParentFile().mkdirs(); - } - - final CMapViewBasic bmapview = newPickmap(null, maparch, mapFile); - if (bmapview != null) { - // insert new pickmap in the alphabetic order - int i; - for (i = 0; i < tabpane.getTabCount() && mapFile.getName().compareToIgnoreCase(tabpane.getTitleAt(i)) < 0; i++) { - ; - } - tabpane.insertTab(mapFile.getName(), null, bmapview, null, i); - setActivePickmap(mapFile.getName()); - loadComplete = true; - return true; - } - return false; - } - - /** - * Add a new pickmap. - * @param objects list of objects or <code>null</code> for empty - * @param maparch the maparch of the pickmap - * @param mapFile The map file that's stored in the MapControl. - * @return basic mapview - */ - private CMapViewBasic newPickmap(final List<GameObject> objects, final MapArchObject maparch, final File mapFile) { - final MapControl mapControl = new MapControl(mainControl, objects, maparch, true, null); - mapControl.getMapViewFrame().setAutoscrolls(true); - mapControl.setMapFile(mapFile); - - // add pickmap to hashtable - pickmaps.put(mapFile.getName(), mapControl); - - currentPickMap = mapControl; - mapControl.getMapModel().resetLevelChangedFlag(); - - return mapControl.getMapViewFrame().getBasicView(); - } - - /** - * Close a pickmap: Remove it from the panel and the data vector. - * @param mapControl MapControl of the pickmap to remove - * @return true when closing successful - */ - public boolean closePickmap(final MapControl mapControl) { - boolean mapClosed = false; - - final Iterator<String> keyit = pickmaps.keySet().iterator(); - while (!mapClosed && keyit.hasNext()) { - final String tmpKey = keyit.next(); - final MapControl tmpMap = pickmaps.get(tmpKey); - if (tmpMap == mapControl) { - pickmaps.remove(tmpKey); - tabpane.remove(tmpMap.getMapViewFrame().getBasicView()); - mapClosed = true; - } - } - - if (mapClosed) { - updateActivePickmap(); - } - - return mapClosed; - } - - /** - * Set pickmap with given name to be the active one (ontop). - * @param name map name (which is also the tab title) - */ - public void setActivePickmap(final String name) { - final MapControl tmpMap = pickmaps.get(name); - if (tmpMap != null) { - tabpane.setSelectedComponent(tmpMap.getMapViewFrame().getBasicView()); - } - } - - /** Update info which pickmap is currently on top. */ - private void updateActivePickmap() { - - if (tabpane == null) { - return; // for safety, shouldn't happen - } - - if (pickmaps.isEmpty()) { - currentPickMap = null; - return; - } - - final String newName = tabpane.getTitleAt(tabpane.getSelectedIndex()); - - final MapControl tmp = pickmaps.get(newName); - boolean foundMap = false; - if (tmp != null && tmp.getMapFileName().endsWith("/"+newName)) { - // this is the new active pickmap - currentPickMap = tmp; // <- new pickmap - foundMap = true; - if (log.isDebugEnabled()) { - log.debug("new pickmap: " + newName); - } - } - - if (!foundMap && mainControl.getMainView().isPickmapActive() && loadComplete) { - // error: the new selected pickmap couldn't be found - log.error("Bad Error in CPickmapPanel.updateActivePickmap: Selected pickmap couldn't be found!"); - } - } - - /** - * Add the PickmapSelectionListener to the pickmap tabbed panel. - * @param pickpane the panel with pickmaps - * @todo this method's name is a Bad Thing - */ - public void addPickmapSelectionListener(final JTabbedPane pickpane) { - pickpane.addChangeListener(new PickmapSelectionListener(pickpane)); - } - - /** - * Add the ArchNPickChangeListener to the panel containing both - * archlist and pickmaps. - * @param pane the left-side panel - * @todo this method's name is a Bad Thing - */ - public void addArchNPickChangeListener(final JTabbedPane pane) { - pane.addChangeListener(new ArchNPickChangeListener(mainControl.getMainView(), pane)); - } - - // ------------------------ nested and inner classes ------------------------ - - /** Listener class to keep track of the currently active pickmap. */ - private final class PickmapSelectionListener implements ChangeListener { - - private final String activePickmap; // file-name of active pickmap - - private PickmapSelectionListener(final JTabbedPane pane) { - tabpane = pane; - activePickmap = null; - } - - public void stateChanged(final ChangeEvent e) { - if (activePickmap == null || activePickmap.length() <= 0 || !tabpane.getTitleAt(tabpane.getSelectedIndex()).equals(activePickmap)) { - // new pickmap is active - updateActivePickmap(); - } - } - - } // class PickmapSelectionListener - - /** - * In the left-side panel, archlist and pickmaps are exclusive - * (only the one being displayed is active). - * This listener gets to know which of them is active and - * keeps the main view informed whenever the state changes. - */ - private static final class ArchNPickChangeListener implements ChangeListener { - - private final CMainView mainView; // main view - - private final JTabbedPane tabpane; // parent pane for archlist & pickmaps - - private int selectedIndex; // current state of selection - - /** - * Create an ArchNPickChangeListener. - * @param mainView the main view - * @param pane the JTabbedPane containing both archlist and pickmaps - */ - private ArchNPickChangeListener(final CMainView mainView, final JTabbedPane pane) { - this.mainView = mainView; - tabpane = pane; - selectedIndex = tabpane.getSelectedIndex(); - } - - public void stateChanged(final ChangeEvent e) { - if (tabpane.getSelectedIndex() != selectedIndex) { - // the state has changed, user has switched panels - if (tabpane.getSelectedIndex() == 0) { - mainView.setPickmapActive(false); - } else { - mainView.setPickmapActive(true); - } - - selectedIndex = tabpane.getSelectedIndex(); // save new state - } - } - - } // class ArchNPickChangeListener - -} // class CPickmapPanel Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -27,10 +27,10 @@ import cfeditor.CFTreasureListTree; import cfeditor.CMainControl; -import cfeditor.CPickmapPanel; import cfeditor.IGUIConstants; import cfeditor.gameobject.face.FaceObject; import cfeditor.gameobject.face.FaceObjects; +import cfeditor.gui.PickmapChooser; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.DataOutputStream; @@ -165,7 +165,7 @@ } // load pickmaps - CPickmapPanel.getInstance().loadPickmaps(); + PickmapChooser.getInstance().loadPickmaps(); // load the treasurelists data CFTreasureListTree.init(); Modified: trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -26,7 +26,6 @@ package cfeditor.gui; import cfeditor.CMainControl; -import cfeditor.CPickmapPanel; import cfeditor.CSettings; import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; @@ -96,7 +95,7 @@ archAndPickPane.addTab("Arch List", tabDesktop); archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); // this listener informs the mainview which panel is active: archlist or pickmaps? - CPickmapPanel.getInstance().addArchNPickChangeListener(archAndPickPane); + PickmapChooser.getInstance().addArchNPickChangeListener(archAndPickPane); // calculate default value in case there is no settings file final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Copied: trunk/crossfire/src/cfeditor/gui/PickmapChooser.java (from rev 1288, trunk/crossfire/src/cfeditor/CPickmapPanel.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/PickmapChooser.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/PickmapChooser.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -0,0 +1,391 @@ +/* + * 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.gui; + +import cfeditor.CMainControl; +import cfeditor.CMainView; +import cfeditor.CMapViewBasic; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; +import cfeditor.io.CMapReader; +import cfeditor.map.MapArchObject; +import cfeditor.map.MapControl; +import java.awt.Component; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.swing.JTabbedPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; + +/** + * The <code>PickmapChooser</code> manages the pickmap panel + * and most pickmap-related code in general. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class PickmapChooser { + + private static final Logger log = Logger.getLogger(PickmapChooser.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + /** Singleton instance of this class. */ + private static PickmapChooser instance; + + private final CMainControl mainControl; // main control reference + + private boolean loadComplete; // true when all pickmaps have been loaded (at least one) + + private JTabbedPane tabpane = null; // tab pane with pickmaps + + /** All open pickmaps (the map controllers get stored in the vector). */ + private final Map<String, MapControl> pickmaps = new HashMap<String, MapControl>(); + + /** The current active pickmap ontop. */ + private MapControl currentPickMap; + + /** + * Create a PickmapChooser. + */ + public PickmapChooser() { + mainControl = CMainControl.getInstance(); + instance = this; + loadComplete = false; + currentPickMap = null; + } + + /** + * Return the singleton instance of this class. + * @return the singleton instance of this class + */ + public static PickmapChooser getInstance() { + return instance; + } + + /** + * Return whether loading of pickmaps is complete and at least one pickmap is available. + * @return <code>true</code> if loading of pickmaps is complete and at least one pickmap is available, otherwise <code>false</code> + * @todo check whether this method returns <code>true</code> or <code>false</code> if the loading process is complete but no pickmaps are availbale. + */ + public boolean isLoadComplete() { + return loadComplete; + } + + /** + * Return the currently active pickmap. + * If there is no currently active pickmap, this method returns <code>null</code>. + * @return the currently active pickmap or <code>null</code> if there is no pickmap + */ + public MapControl getCurrentPickmap() { + return currentPickMap; + } + + /** + * Load all pickmaps and build the pickmap-panel. + */ + public void loadPickmaps() { + // the main-panel for pickmaps: + tabpane = mainControl.getMainView().getPickmapPanel(); + + final File pickmapDir = new File(IGUIConstants.PICKMAP_DIR); + if (!pickmapDir.exists() || !pickmapDir.isDirectory()) { + log.warn("No pickmaps directory found."); + return; + } + + final File[] flist = pickmapDir.listFiles(); // list of files + Arrays.sort(flist); + for (final File aFlist : flist) { + // open the pickmaps + if (aFlist.isFile()) { + openPickmap(aFlist); + } + } + mainControl.refreshMenusAndToolbars(); + + // did we get something? + if (!pickmaps.isEmpty()) { + loadComplete = true; + } + + updateActivePickmap(); // make sure we know which one is on top + } + + /** + * Open and load a pickmap from the given file. + * @param mapFile the map file + * @return true when pickmap was opened successfully + */ + public boolean openPickmap(final File mapFile) { + // open the pickmaps + final CMapViewBasic bmapview; + final MapArchObject maparch; + + try { + final CMapReader decoder = new CMapReader(mapFile); + final List<GameObject> objects = decoder.decodeMapFile(); // parse mapfile + maparch = decoder.getMapArch(); // get map arch + + if (objects == null) { + // The map is totally empty + bmapview = newPickmap(null, maparch, mapFile); // init the map + } else { + // go to ArchetypeParser and add the default arch list information to them + if (!mainControl.collectTempList(objects, mapFile)) { // get face names, face id, etc. + return false; + } + mainControl.getArchetypeParser().sortTempList(objects); // sort the list (put multiparts at the end) + bmapview = newPickmap(objects, maparch, mapFile); // init the map + } + + // looks like it worked, so we add a panel and display this pickmap + if (bmapview != null) { + int i; + for (i = 0; i < tabpane.getTabCount() && mapFile.getName().compareToIgnoreCase(tabpane.getTitleAt(i)) < 0; i++) { + ; + } + tabpane.insertTab(mapFile.getName(), null, bmapview, null, i); + return true; + } + } catch (final IOException e) { + // loading failed - could be a system file in that directory, + // or something else. Doesn't deserve more attention than a printout. + if (!mapFile.getName().startsWith(".")) { + log.warn("Couldn't load pickmap", e); + } + } + return false; + } + + /** + * Create a new pickmap and display it. + * @param parent the parent component to be used for error messages + * @param maparch MapArchObject containing map name and -size + * @return <code>true</code> if the pickmap was added, <code>false</code> + * if an error has occurred + */ + public boolean addNewPickmap(final Component parent, final MapArchObject maparch) { + + final File mapFile = new File(IGUIConstants.PICKMAP_DIR, maparch.getFileName()); + if (mapFile.exists()) { + ACTION_FACTORY.showMessageDialog(parent, "pickmapExists", mapFile); + return false; + } + if (!mapFile.getParentFile().exists()) { + mapFile.getParentFile().mkdirs(); + } + + final CMapViewBasic bmapview = newPickmap(null, maparch, mapFile); + if (bmapview != null) { + // insert new pickmap in the alphabetic order + int i; + for (i = 0; i < tabpane.getTabCount() && mapFile.getName().compareToIgnoreCase(tabpane.getTitleAt(i)) < 0; i++) { + ; + } + tabpane.insertTab(mapFile.getName(), null, bmapview, null, i); + setActivePickmap(mapFile.getName()); + loadComplete = true; + return true; + } + return false; + } + + /** + * Add a new pickmap. + * @param objects list of objects or <code>null</code> for empty + * @param maparch the maparch of the pickmap + * @param mapFile The map file that's stored in the MapControl. + * @return basic mapview + */ + private CMapViewBasic newPickmap(final List<GameObject> objects, final MapArchObject maparch, final File mapFile) { + final MapControl mapControl = new MapControl(mainControl, objects, maparch, true, null); + mapControl.getMapViewFrame().setAutoscrolls(true); + mapControl.setMapFile(mapFile); + + // add pickmap to hashtable + pickmaps.put(mapFile.getName(), mapControl); + + currentPickMap = mapControl; + mapControl.getMapModel().resetLevelChangedFlag(); + + return mapControl.getMapViewFrame().getBasicView(); + } + + /** + * Close a pickmap: Remove it from the panel and the data vector. + * @param mapControl MapControl of the pickmap to remove + * @return true when closing successful + */ + public boolean closePickmap(final MapControl mapControl) { + boolean mapClosed = false; + + final Iterator<String> keyit = pickmaps.keySet().iterator(); + while (!mapClosed && keyit.hasNext()) { + final String tmpKey = keyit.next(); + final MapControl tmpMap = pickmaps.get(tmpKey); + if (tmpMap == mapControl) { + pickmaps.remove(tmpKey); + tabpane.remove(tmpMap.getMapViewFrame().getBasicView()); + mapClosed = true; + } + } + + if (mapClosed) { + updateActivePickmap(); + } + + return mapClosed; + } + + /** + * Set pickmap with given name to be the active one (ontop). + * @param name map name (which is also the tab title) + */ + public void setActivePickmap(final String name) { + final MapControl tmpMap = pickmaps.get(name); + if (tmpMap != null) { + tabpane.setSelectedComponent(tmpMap.getMapViewFrame().getBasicView()); + } + } + + /** Update info which pickmap is currently on top. */ + private void updateActivePickmap() { + + if (tabpane == null) { + return; // for safety, shouldn't happen + } + + if (pickmaps.isEmpty()) { + currentPickMap = null; + return; + } + + final String newName = tabpane.getTitleAt(tabpane.getSelectedIndex()); + + final MapControl tmp = pickmaps.get(newName); + boolean foundMap = false; + if (tmp != null && tmp.getMapFileName().endsWith("/"+newName)) { + // this is the new active pickmap + currentPickMap = tmp; // <- new pickmap + foundMap = true; + if (log.isDebugEnabled()) { + log.debug("new pickmap: " + newName); + } + } + + if (!foundMap && mainControl.getMainView().isPickmapActive() && loadComplete) { + // error: the new selected pickmap couldn't be found + log.error("Bad Error in PickmapChooser.updateActivePickmap: Selected pickmap couldn't be found!"); + } + } + + /** + * Add the PickmapSelectionListener to the pickmap tabbed panel. + * @param pickpane the panel with pickmaps + * @todo this method's name is a Bad Thing + */ + public void addPickmapSelectionListener(final JTabbedPane pickpane) { + pickpane.addChangeListener(new PickmapSelectionListener(pickpane)); + } + + /** + * Add the ArchNPickChangeListener to the panel containing both + * archlist and pickmaps. + * @param pane the left-side panel + * @todo this method's name is a Bad Thing + */ + public void addArchNPickChangeListener(final JTabbedPane pane) { + pane.addChangeListener(new ArchNPickChangeListener(mainControl.getMainView(), pane)); + } + + // ------------------------ nested and inner classes ------------------------ + + /** Listener class to keep track of the currently active pickmap. */ + private final class PickmapSelectionListener implements ChangeListener { + + private final String activePickmap; // file-name of active pickmap + + private PickmapSelectionListener(final JTabbedPane pane) { + tabpane = pane; + activePickmap = null; + } + + public void stateChanged(final ChangeEvent e) { + if (activePickmap == null || activePickmap.length() <= 0 || !tabpane.getTitleAt(tabpane.getSelectedIndex()).equals(activePickmap)) { + // new pickmap is active + updateActivePickmap(); + } + } + + } // class PickmapSelectionListener + + /** + * In the left-side panel, archlist and pickmaps are exclusive + * (only the one being displayed is active). + * This listener gets to know which of them is active and + * keeps the main view informed whenever the state changes. + */ + private static final class ArchNPickChangeListener implements ChangeListener { + + private final CMainView mainView; // main view + + private final JTabbedPane tabpane; // parent pane for archlist & pickmaps + + private int selectedIndex; // current state of selection + + /** + * Create an ArchNPickChangeListener. + * @param mainView the main view + * @param pane the JTabbedPane containing both archlist and pickmaps + */ + private ArchNPickChangeListener(final CMainView mainView, final JTabbedPane pane) { + this.mainView = mainView; + tabpane = pane; + selectedIndex = tabpane.getSelectedIndex(); + } + + public void stateChanged(final ChangeEvent e) { + if (tabpane.getSelectedIndex() != selectedIndex) { + // the state has changed, user has switched panels + if (tabpane.getSelectedIndex() == 0) { + mainView.setPickmapActive(false); + } else { + mainView.setPickmapActive(true); + } + + selectedIndex = tabpane.getSelectedIndex(); // save new state + } + } + + } // class ArchNPickChangeListener + +} // class PickmapChooser Property changes on: trunk/crossfire/src/cfeditor/gui/PickmapChooser.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -36,6 +36,7 @@ import daieditor.gameobject.match.MutableOrGameObjectMatcher; import daieditor.gameobject.match.ViewGameObjectMatcherManager; import daieditor.gui.MapFileFilter; +import daieditor.gui.PickmapChooser; import daieditor.gui.map.MapCursorControl; import daieditor.gui.map.MapPreviewAccessory; import daieditor.gui.map.MapPropertiesDialog; @@ -405,7 +406,7 @@ readGlobalSettings(); // initialize pickmap panel (needed early during the loading process) - new CPickmapPanel(); + new PickmapChooser(); // initialize & load MultiPositionData.init(); @@ -942,13 +943,13 @@ /** Invoked when the user wants to close the active pickmap. */ public void closePickmap() { - if (!CPickmapPanel.getInstance().isLoadComplete()) { + if (!PickmapChooser.getInstance().isLoadComplete()) { ACTION_FACTORY.showMessageDialog(mainView, "closePickmapNotLoaded"); } else { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "closePickmapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "closePickmapNoPickmaps"); } else { @@ -1009,7 +1010,7 @@ if (level.isPickmap()) { // special case: close a pickmap - CPickmapPanel.getInstance().closePickmap(level); + PickmapChooser.getInstance().closePickmap(level); level.levelCloseNotify(); } else { // Notify the level about the closing @@ -1033,13 +1034,13 @@ /** Open active pickmap as normal map for extensive editing. */ public void openPickmapMap() { - if (!CPickmapPanel.getInstance().isLoadComplete()) { + if (!PickmapChooser.getInstance().isLoadComplete()) { ACTION_FACTORY.showMessageDialog(mainView, "openPickmapMapNotLoaded"); } else { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "openPickmapMapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "openPickmapNoPickmaps"); } else { @@ -1311,11 +1312,11 @@ /** Save current active pickmap. */ public void savePickmap() { - if (CPickmapPanel.getInstance().isLoadComplete()) { + if (PickmapChooser.getInstance().isLoadComplete()) { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "savePickmapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "savePickmapNoPickmaps"); } else { @@ -1758,13 +1759,13 @@ /** Invoked when user wants to revert the current pickmap to previously saved state. */ public void revertPickmap() { - if (!CPickmapPanel.getInstance().isLoadComplete()) { + if (!PickmapChooser.getInstance().isLoadComplete()) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapNotLoaded"); } else { if (!mainView.isPickmapActive()) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapHidden"); } else { - final MapControl activePickmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl activePickmap = PickmapChooser.getInstance().getCurrentPickmap(); if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapNoPickmaps"); } else { @@ -1775,11 +1776,11 @@ return; } - final int tabIndex = CPickmapPanel.getInstance().getPickmapTabIndex(activePickmap); + final int tabIndex = PickmapChooser.getInstance().getPickmapTabIndex(activePickmap); if (tabIndex >= 0) { closeLevel(activePickmap, true); // close the old map - CPickmapPanel.getInstance().openPickmap(mfile, tabIndex); // open the new map - CPickmapPanel.getInstance().setActivePickmap(tabIndex); + PickmapChooser.getInstance().openPickmap(mfile, tabIndex); // open the new map + PickmapChooser.getInstance().setActivePickmap(tabIndex); // Update the main view so the new map instantly pops up. mainView.update(mainView.getGraphics()); @@ -2329,7 +2330,7 @@ if (arch != null) { title.append("with arch ").append(arch.getArchetypeName()); } else { - pmap = CPickmapPanel.getInstance().getCurrentPickmap(); + pmap = PickmapChooser.getInstance().getCurrentPickmap(); if (pmap != null) { title.append("with pickmap ").append(pmap.getMapArch().getMapName()); } else { // ok ,we have a problem here: arch == null, pmap == null... Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -27,6 +27,7 @@ import daieditor.gameobject.GameObject; import daieditor.gui.AboutDialog; import daieditor.gui.InsertionObjectChooser; +import daieditor.gui.PickmapChooser; import daieditor.gui.StatusBar; import daieditor.gui.selectedsquare.SelectedSquareControl; import daieditor.map.MapControl; @@ -218,7 +219,7 @@ pickmapPanel = new JTabbedPane(SwingConstants.TOP); pickmapPanel.setComponentPopupMenu(ACTION_FACTORY.createPopupMenu(true, "pickmaps")); pickmapPanel.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); - CPickmapPanel.getInstance().addPickmapSelectionListener(pickmapPanel); + PickmapChooser.getInstance().addPickmapSelectionListener(pickmapPanel); statusBar = new StatusBar(mainControl); archPanel = new InsertionObjectChooser(mainControl); @@ -286,9 +287,9 @@ */ @Nullable public GameObject getArchPanelHighlight() { - if ((pickmapActive || archPanel.getArchPanelSelection() == null) && CPickmapPanel.getInstance().isLoadComplete() && CPickmapPanel.getInstance().getCurrentPickmap() != null) { + if ((pickmapActive || archPanel.getArchPanelSelection() == null) && PickmapChooser.getInstance().isLoadComplete() && PickmapChooser.getInstance().getCurrentPickmap() != null) { // get the active pickmap - final MapControl pmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl pmap = PickmapChooser.getInstance().getCurrentPickmap(); if (pmap != null && pmap.getMapViewFrame().isHighlight()) { // now try to get the topmost object @@ -321,9 +322,9 @@ */ @Nullable public List<GameObject> getArchPanelSelection() { - if ((pickmapActive || archPanel.getArchPanelSelection() == null) && CPickmapPanel.getInstance().isLoadComplete()) { + if ((pickmapActive || archPanel.getArchPanelSelection() == null) && PickmapChooser.getInstance().isLoadComplete()) { // get the active pickmap - final MapControl pmap = CPickmapPanel.getInstance().getCurrentPickmap(); + final MapControl pmap = PickmapChooser.getInstance().getCurrentPickmap(); if (pmap != null) { return CopyBuffer.getMapArchList(pmap, 100); } Modified: trunk/daimonin/src/daieditor/CNewMapDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CNewMapDialog.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/daimonin/src/daieditor/CNewMapDialog.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -27,6 +27,7 @@ import static daieditor.CMainControl.PREFS_USERNAME; import static daieditor.CMainControl.PREFS_USERNAME_DEFAULT; +import daieditor.gui.PickmapChooser; import daieditor.map.MapArchObject; import java.awt.Component; import java.awt.FlowLayout; @@ -297,7 +298,7 @@ if (mapType == MapType.GAMEMAP) { mainControl.newLevel(null, maparch, true); } else if (mapType == MapType.PICKMAP) { - return CPickmapPanel.getInstance().addNewPickmap(parent, maparch); + return PickmapChooser.getInstance().addNewPickmap(parent, maparch); } return true; Deleted: trunk/daimonin/src/daieditor/CPickmapPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CPickmapPanel.java 2006-12-26 23:36:52 UTC (rev 1295) +++ trunk/daimonin/src/daieditor/CPickmapPanel.java 2006-12-26 23:40:48 UTC (rev 1296) @@ -1,420 +0,0 @@ -/* - * Daimonin 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 daieditor; - -import daieditor.gameobject.GameObject; -import daieditor.io.CMapReader; -import daieditor.map.MapArchObject; -import daieditor.map.MapControl; -import java.awt.Component; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import javax.swing.JTabbedPane; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; - -/** - * The <code>CPickmapPanel</code> manages the pickmap panel - * and most pickmap-related code in general. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CPickmapPanel { - - private static final Logger log = Logger.getLogger(CPickmapPanel.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** Singleton instance of this class. */ - private static CPickmapPanel instance; - - private final CMainControl mainControl; // main control reference - - private boolean loadComplete; // true when all pickmaps have been loaded (at least one) - - private JTabbedPane tabpane = null; // tab pane with pickmaps - - /** All open pickmaps (the map controllers get stored in the vector). */ - private final List<MapControl> pickmaps = new ArrayList<MapControl>(); - - /** The current active pickmap ontop. */ - private MapControl currentPickMap; - - /** - * Create a CPickmapPanel. - */ - public CPickmapPanel() { - mainControl = CMainControl.getInstance(); - instance = this; - loadComplete = false; - currentPickMap = null; - } - - /** - * Return the singleton instance of this class. - * @return the singleton instance of this class - */ - public static CPickmapPanel getInstance() { - return instance; - } - - /** - * Return whether loading of pickmaps is complete and at least one pickmap is available. - * @return <code>true</code> if loading of pickmaps is complete and at least one pickmap is available, otherwise <code>false</code> - */ - public boolean isLoadComplete() { - return loadComplete; - } - - /** - * Return the currently active pickmap (is on top). - * @return the currently active pickmap or <code>null</code> if there is no pickmap - */ - public MapControl getCurrentPickmap() { - return currentPickMap; - } - - /** - * Load all pickmaps and build the pickmap-panel. - */ - public void loadPickmaps() { - // the main-panel for pickmaps: - tabpane = mainControl.getMainView().getPickmapPanel(); - - final File pickmapDir = new File(CMainControl.getInstance().getArchDefaultFolder(), IGUIConstants.PICKMAP_DIR); - if (!pickmapDir.exists() || !pickmapDir.isDirectory()) { - log.warn("No pickmaps directory found."); - return; - } - - final File[] flist = pickmapDir.listFiles(); // list of files - Arrays.sort(flist); - for (final File aFlist : flist) { - // open the pickmaps - if (aFlist.isFile()) { - openPickmap(aFlist); - } - } - mainControl.refreshMenusAndToolbars(); - - // did we get something? - if (!pickmaps.isEmpty()) { - loadComplete = true; - - mainControl.getMainView().movePickmapPanelToFront(); - } - - updateActivePickmap(); // make sure we know which one is on top - } - - public boolean openPickmap(final File mapFile) { - return openPickmap(mapFile, -1); - } - - /** - * Open and load a pickmap from the given file. - * @param mapFile the map file - * @param index the tab index where this pickmap should be inserted - * @return true when pickmap was opened successfully - */ - public boolean openPickmap(final File mapFile, final int index) { - // open the pickmaps - - try { - // FIXME: This is somewhat dangerous regarding multithreading - final CMapReader decoder = new CMapReader(mapFile); - try { - final List<GameObject> objects = decoder.decodeMapFile(); - final MapArchObject maparch = decoder.getMapArch(); - final CMapViewBasic bmapview; - - // go to ArchetypeParser and add the default arch list information to them - bmapview = newPickmap(objects, maparch, mapFile, index); // init the map - - // looks like it worked, so we add a panel and display this pickmap - if (bmapview != null) { - if (index < 0 || index >= tabpane.getTabCount()) { - tabpane.addTab(mapFile.getName(), bmapview); - } else { - tabpane.insertTab(mapFile.getName(), null, bmapview, null, index); - } - bmapview.getMapControl().setPickmap(true); - return true; - } - } finally { - decoder.close(); - } - } catch (final IOException e) { - log.warn("Couldn't load pickmap", e); - } - return false; - } - - /** - * Create a new pickmap and display it. - * @param parent the parent component to be used for error messages - * @param maparch MapArchObject containing map name and -size - * @return <code>true</code> if the pickmap was added, <code>false</code> - * if an error has occurred - */ - public boolean addNewPickmap(final Component parent, final MapArchObject maparch) { - - final File mapFile = new File(new File(CMainControl.getInstance().getArchDefaultFolder(), IGUIConstants.PICKMAP_DIR), maparch.getFileName()); - if (mapFile.exists()) { - ACTION_FACTORY.showMessageDialog(parent, "pickmapExists", mapFile); - return false; - } - if (!mapFile.getParentFile().exists()) { - mapFile.getParentFile().mkdirs(); - } - - final CMapViewBasic bmapview = newPickmap(null, maparch, mapFile, -1); - if (bmapview != null) { - bmapview.getLevel().save(); - tabpane.addTab(mapFile.getName(), bmapview); - setActivePickmap(tabpane.getTabCount() - 1); - loadComplete = true; - return true; - } - return false; - } - - /** - * Add a new pickmap. - * @param objects list of objects or <code>null</code> for empty - * @param maparch the maparch of the pickmap - * @param mapFile File to load the pickmap from. - * @param index tab index to insert, -1 means add to the end - * @return basic mapview - */ - private CMapViewBasic newPickmap(final List<GameObject> objects, final MapArchObject maparch, final File mapFile, final int index) { - final MapControl mapControl = new MapControl(mainControl, objects, maparch, true, true); - mapControl.getMapViewFrame().setAutoscrolls(true); - mapControl.setMapFile(mapFile); - - // add pickmap to vector - if (index < 0 || index >= pickmaps.size()) { - pickmaps.add(mapControl); - } else { - pickmaps.add(index, mapControl); - } - currentPickMap = mapControl; - return mapControl.getMapViewFrame().getBasicView(); - } - - /** - * Close a pickmap: Remove it from the panel and the data vector. - * @param mapControl MapControl of the pickmap to remove - * @return true when closing successful - */ - public boolean closePickmap(final MapControl mapControl) { - boolean mapClosed = false; - for (int i = 0; !mapClosed && i < pickmaps.size(); i++) { - final MapControl tmpMap = pickmaps.get(i); - if (tmpMap == mapControl) { - pickmaps.remove(i); - tabpane.remove(i); - mapClosed = true; - ... [truncated message content] |
From: <chr...@us...> - 2006-12-26 23:55:07
|
Revision: 1297 http://svn.sourceforge.net/gridarta/?rev=1297&view=rev Author: christianhujer Date: 2006-12-26 15:55:03 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CMapArchPanel to gui.GameObjectAttributesPanel. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/GameObject.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesPanel.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/daimonin/src/daieditor/CMapArchPanel.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:40:48 UTC (rev 1296) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-26 23:55:03 UTC (rev 1297) @@ -25,6 +25,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.gui.GameObjectAttributesPanel; import cfeditor.gui.InsertionObjectChooser; import cfeditor.gui.PickmapChooser; import cfeditor.gui.StatusBar; @@ -146,7 +147,7 @@ private SelectedSquareControl selectedSquareControl; /** Attributes panel (bottom). */ - private CMapArchPanel mapArchPanel; + private GameObjectAttributesPanel mapArchPanel; /** Panel with pickmaps. */ private JTabbedPane pickmapPanel; @@ -235,7 +236,7 @@ getContentPane().add(splitRightPane, BorderLayout.CENTER); - mapArchPanel = new CMapArchPanel(mainControl, this); + mapArchPanel = new GameObjectAttributesPanel(mainControl, this); splitDownPane = new GSplitPane(JSplitPane.VERTICAL_SPLIT, splitRightPane, mapArchPanel); splitDownPane.setDividerLocation(divLocationDown); @@ -250,7 +251,7 @@ getContentPane().add(splitPane, BorderLayout.CENTER); } else { // the map tile list is merged into the bottom panel - mapArchPanel = new CMapArchPanel(mainControl, this); + mapArchPanel = new GameObjectAttributesPanel(mainControl, this); splitRightPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, selectedSquareControl.getMapTileListView()); splitRightPane.setDividerLocation(divLocationRight); @@ -783,7 +784,7 @@ mainControl.showMessage("About " + IGUIConstants.APP_NAME, " Version " + IGUIConstants.VERSION + "\n (c) 2001 Michael Toennies\n" + " Andreas Vogl\n"); } - public CMapArchPanel getMapArchPanel() { + public GameObjectAttributesPanel getMapArchPanel() { return mapArchPanel; } Deleted: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-26 23:40:48 UTC (rev 1296) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-26 23:55:03 UTC (rev 1297) @@ -1,905 +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.ArchetypeSet; -import cfeditor.gameobject.GameObject; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.Toolkit; -import javax.swing.Action; -import javax.swing.BoxLayout; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JTextPane; -import javax.swing.JViewport; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.border.EtchedBorder; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import net.sf.gridarta.gui.GSplitPane; -import net.sf.gridarta.gui.connectionview.ConnectionControl; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.swing.ActionMethod; - -/** - * <code>CMapArchPanel</code> implements the panel that holds information about - * the currently selected GameObject on the map. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CMapArchPanel extends JPanel { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - // constants for the 'task' parameter in editScriptWanted() - public static final int SCRIPT_OPEN = 0; - - public static final int SCRIPT_EDIT_PATH = 1; - - public static final int SCRIPT_REMOVE = 2; - - // MAN! This is one of these java shitholes - // without overruling getScrollableTracksViewportWidth(), - // is JTextPanel not scrolling horizontal - // i searched hours for the reason... the net is full of broken examples - private final JTextPane archEdit = new JTextPane() { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** {@inheritDoc} */ - @Override public boolean getScrollableTracksViewportWidth() { - return getSize().width < getParent().getSize().width; - } - - /** {@inheritDoc} */ - @Override public void setSize(final Dimension d) { - if (d.width < getParent().getSize().width) { - d.width = getParent().getSize().width; - } - super.setSize(d); - } - }; - - private static final String MAPARCHPANEL_LOCATION_KEY = "MainWindowMapArchPanel.dividerLocation"; - - /** Controller of this subview. */ - private final CMainControl mainControl; - - private final CMainView mainView; - - private final GSplitPane splitPane; - - private final JTabbedPane panelDesktop; - - private final Document document; - - /** Panel with name/face etc. */ - private final JPanel archPanel; - - /** Panel with message text. */ - private JPanel textPanel; - - private final JPanel animationPanel; - - /** Arch text field. */ - private final JTextArea archTextArea = new JTextArea(4, 25); - - /** Arch name field. */ - private final JTextField archNameField = new JTextField(14); - - /** Arch face field. */ - private final JTextField archFaceField = new JTextField(14); - - private final JLabel archMapPos = new JLabel(); - - private final JLabel archFaceText = new JLabel(); - - private final JLabel archTypeText = new JLabel(); - - private final JLabel archAnimText = new JLabel(); - - private final JPanel mapArchPanel = new JPanel(); - - private final Action aSubmitChange = ACTION_FACTORY.createAction(false, "mapArchApply", this); - - private final Action aInvChange = ACTION_FACTORY.createAction(false, "mapArchAddInv", this); - - private final Action aAttrWin = ACTION_FACTORY.createAction(false, "mapArchAttrib", this); - - private final Action aNew = ACTION_FACTORY.createAction(false, "scriptAddNew", this); - - private final Action aPath = ACTION_FACTORY.createAction(false, "scriptEditData", this); - - private final Action aModify = ACTION_FACTORY.createAction(false, "scriptEdit", this); - - private final Action aRemove = ACTION_FACTORY.createAction(false, "scriptRemove", this); - - private JList eventList; - - private GameObject selectedObject; - - /* Build Panel */ - CMapArchPanel(final CMainControl mainControl, final CMainView view) { - this.mainControl = mainControl; - mainView = view; - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - setLayout(new BorderLayout()); - - final ConnectionControl connectionControl = new ConnectionControl(mainControl); - - // scrollPane2 contains the document for archtext editing - final JScrollPane scrollPane2 = new JScrollPane(archEdit); - scrollPane2.setBackground(archEdit.getBackground()); - scrollPane2.getViewport().add(archEdit); - add(scrollPane2, BorderLayout.EAST); - scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - scrollPane2.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - - panelDesktop = new JTabbedPane(SwingConstants.TOP); - mapArchPanel.setLayout(new BorderLayout()); - splitPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, scrollPane2); - - final JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(0, 1)); - - mapArchPanel.add(buttonPanel, BorderLayout.WEST); - - // our buttons - buttonPanel.add(new JButton(aSubmitChange)); - buttonPanel.add(new JButton(aInvChange)); - buttonPanel.add(new JButton(aAttrWin)); - - mapArchPanel.add(panelDesktop, BorderLayout.CENTER); - - // setup our plain archPanel - we need to add later field to it - // depending on the arch typ selected - archPanel = new JPanel(); - final GridBagLayout gridbag = new GridBagLayout(); - final GridBagConstraints gbc = new GridBagConstraints(); - archPanel.setLayout(gridbag); - gbc.fill = GridBagConstraints.BOTH; - gbc.anchor = GridBagConstraints.NORTHWEST; - - animationPanel = new JPanel(); - - setupArchPanel(); - setupTextPanel(); - setupAnimationPanel(); - - panelDesktop.add(archPanel, "Arch"); - panelDesktop.add(textPanel, "Msg Text"); - - panelDesktop.add(createScriptPanel(), "Scripts"); - - panelDesktop.add(animationPanel, "Animation"); - panelDesktop.add(connectionControl.getView(), "Connection"); - - // calculate default value in case there is no settings file - final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - - splitPane.setDividerLocation(Integer.parseInt(settings.getProperty(MAPARCHPANEL_LOCATION_KEY, String.valueOf((int) (0.49 * screen.getWidth()))))); - add(splitPane, BorderLayout.CENTER); - - updateFont(true); - - document = archEdit.getDocument(); - } - - /** - * Action method for applying the changes made in the arch panel. - */ - @ActionMethod public void mapArchApply() { - applyArchPanelChanges(mainView.getMapTileSelection()); - } - - /** - * Action method for displaying the attributes of the currently selected object. - */ - @ActionMethod public void mapArchAttrib() { - mainControl.openAttrDialog(mainView.getMapTileSelection()); - } - - /** - * Action method for adding an object to the inventory of the currently selected object. - */ - @ActionMethod public void mapArchAddInv() { - final GameObject arch = mainControl.getArchPanelHighlight(); - if (arch == null) { // nothing selected? - return; - } - - // no single tile? - if(arch.isMulti()) { - return; - } - - GameObject inv = mainView.getMapTileSelection(); - if (inv == null) { - return; - } - - // if this is a multi-tail, we put the new arch into the head's inv. - inv = inv.getHead(); - - final GameObject invnew; - if (arch.isArchetype()) { - // create a new copy of a default arch - invnew = arch.createArch(); - } else { - // create clone from a pickmap - invnew = arch.createClone(inv.getMapX(), inv.getMapY()); - } - - mainControl.getArchetypeParser().postParseGameObject(invnew, 0); - inv.addLast(invnew); - mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified - } - - public void updateMapTileList() { - mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified - } - - /** - * When the "apply"-button on the ArchPanel (at the bottom of the window) - * is pressed, this function updates the active arch object. - * @param activeArch the currently selected arch - */ - public void applyArchPanelChanges(final GameObject activeArch) { - boolean needRedraw = false; // do we need a map-redraw? true/false - - if (activeArch == null) { - return; - } - - // If the active gameObject is part of a multi, the mutli-head's stats - // are taken instead: - final GameObject gameObject = activeArch.getHead(); - - final GameObject archetype = gameObject.getArchetype(); - if (archetype == null) { // hm, this should NOT happen - return; - } - - final String oldArchText = gameObject.getObjectText(); - final String oldMsg = gameObject.getMsgText(); - - // We update all panels: name, face, msg and archText (more to come...) - // the obj name: - if (isNonwhitespaceText(archNameField.getText())) { // there is something in - // if this equal the default name... - if (archetype.getObjName() != null) { - if (archNameField.getText().compareTo(archetype.getObjName()) == 0) { - gameObject.setObjName(null); // yes, we don't need it in map - } else { - gameObject.setObjName(archNameField.getText()); // overrule in map gameObject - } - } else if (archNameField.getText().compareTo(gameObject.getArchetypeName()) == 0) { - gameObject.setObjName(null); - } else { // def is null, something is in panel, so we set it - gameObject.setObjName(archNameField.getText()); // overrule in map gameObject - } - } else { - gameObject.setObjName(null); // nothing in, nothing in map gameObject - // hm, there is no way yet to overrule a default gameObject name with "nothing" - // like <name > ore <name "">..?? - } - - // set face - if (isNonwhitespaceText(archFaceField.getText())) { // there is something in - // check if we need a map redraw - if (archetype.getFaceName() != null) { - final String facename; - if (gameObject.getFaceName() != null) { - facename = gameObject.getFaceName(); - } else { - facename = archetype.getFaceName(); - } - - if (archFaceField.getText() != null && archFaceField.getText().compareTo(facename) != 0) { - needRedraw = true; - } - } - - if (archetype.getFaceName() != null) { - if (archFaceField.getText().compareTo(archetype.getFaceName()) == 0) { - gameObject.setFaceName(null); // yes, we don't need it in map - } else { - gameObject.setFaceName(archFaceField.getText()); // overrule in map arch - } - } else { - gameObject.setFaceName(archFaceField.getText()); // overrule in map arch - } - } else { - if (gameObject.getFaceName() != null) { - needRedraw = true; // reset to default arch - needs redraw - } - - gameObject.setFaceName(null); // nothing in, nothing in map arch - // also, no overrule... - } - - if (gameObject.getFaceName() != null) { - // we have a non-default face - final int index = ArchetypeSet.getFaceIndex(gameObject.getFaceName()); - gameObject.setFaceNr(index); - } else { - // we have the default face - final int index = ArchetypeSet.getFaceIndex(archetype.getFaceName()); - gameObject.setFaceNr(index); - } - - // the msg TEXT!! ("msg ... endmsg") - // if there is an entry in the archTextArea (msg window), this - // overrules the default text (if any) - if (isNonwhitespaceText(archTextArea.getText())) { // there is something in the msg win - if (archetype.getMsgText() != null) { - // trim text from message window - String newMsgText = archTextArea.getText(); - if (newMsgText != null) { - newMsgText = newMsgText.trim(); - } else { - newMsgText = ""; - } - if (newMsgText.equals(archetype.getMsgText().trim())) { - gameObject.deleteMsgText(); // yes, we don't need it in map - } else { - gameObject.resetMsgText(); - gameObject.addMsgText(newMsgText); - } - } else { - gameObject.resetMsgText(); - gameObject.addMsgText(archTextArea.getText()); - } - } else { // there is nothing in the msg win - gameObject.deleteMsgText(); // always delete this... - if (archetype.getMsgText() != null) { - gameObject.addMsgText(""); // but here we must overrule default with msg/endmsg (empty msg) - } - } - - // read from archEdit (bottom right textwin) only the attributes - // that differ from the default gameObject. These get stored into - // the arche's archText (and finally in the map). - gameObject.setObjectText(archetype.diffArchText(archEdit.getText(), false)); - - // we look for 'type' in the ArchText. In future maybe type should get - // a seperate textfield - if (gameObject.getAttributeString("type", false).length() > 0) { - gameObject.setArchTypNr(gameObject.getAttributeInt("type", false)); // specified type - } - - // Recalculate the editType value. It shall stay 100% accurate ;) - gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); - - // if the archtext changed, set the map changed flag - if ((oldArchText != null && !oldArchText.equals(gameObject.getObjectText())) || - (oldArchText == null && gameObject.getObjectText() != null) || - (oldMsg != null && !oldMsg.equals(gameObject.getMsgText())) || - (oldMsg == null && gameObject.getMsgText() != null)) { - mainControl.getCurrentMap().setLevelChangedFlag(); - } - - // there we go!!!!! - // now here will be the special panels added! - refresh(); - - updateMapTileList(); - - // if needed (due to face changes), we also redraw the map - if (needRedraw) { - mainControl.getCurrentMap().repaint(); - } - } - - // simple "white space test, to eliminate ' ' - // perhaps we should include here a real white space test - private static boolean isNonwhitespaceText(final String text) { - return text.replaceAll("\\s+", "").length() > 0; - } - - /** Set up the animation panel. */ - private void setupAnimationPanel() { - final GridBagLayout gridbag = new GridBagLayout(); - final GridBagConstraints gbc = new GridBagConstraints(); - - animationPanel.setLayout(gridbag); - gbc.fill = GridBagConstraints.BOTH; - gbc.weightx = 1.0; - gbc.weighty = 0; - gbc.anchor = GridBagConstraints.NORTHWEST; - gbc.insets = new Insets(3, 3, 0, 0); - - archAnimText.setText("Animation: "); - gbc.gridx = 0; - gbc.gridy = 0; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gridbag.setConstraints(archAnimText, gbc); - animationPanel.add(archAnimText); - - } - - /** Set up the arch panel entry of the lower window. */ - private void setupArchPanel() { - final GridBagLayout gridbag = new GridBagLayout(); - final GridBagConstraints gbc = new GridBagConstraints(); - - archPanel.setLayout(gridbag); - gbc.fill = GridBagConstraints.BOTH; - gbc.weightx = 1.0; - gbc.weighty = 0; - gbc.anchor = GridBagConstraints.NORTHWEST; - gbc.insets = new Insets(4, 4, 0, 0); - - archNameField.setText(""); - archNameField.setForeground(Color.blue); - gbc.gridx = 0; - gbc.gridy = 0; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gridbag.setConstraints(archNameField, gbc); - archPanel.add(archNameField); - - archFaceField.setText(""); - archFaceField.setForeground(Color.blue); - gbc.gridx = 0; - gbc.gridy = 1; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gridbag.setConstraints(archFaceField, gbc); - archPanel.add(archFaceField); - - archFaceText.setText(""); - gbc.gridx = 0; - gbc.gridy = 2; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gridbag.setConstraints(archFaceText, gbc); - archPanel.add(archFaceText); - - archTypeText.setText(""); - gbc.gridx = 0; - gbc.gridy = 3; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gridbag.setConstraints(archTypeText, gbc); - archPanel.add(archTypeText); - - archMapPos.setText(""); - gbc.gridx = 0; - gbc.gridy = 4; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gridbag.setConstraints(archMapPos, gbc); - archPanel.add(archMapPos); - } - - /** Set up the text panel entry of the lower window. */ - private void setupTextPanel() { - textPanel = new JPanel(); // new panel - - archTextArea.setText(""); - archTextArea.setForeground(Color.blue); - - // create ScrollPane for text scrolling - final JScrollPane sta = new JScrollPane(archTextArea); - sta.setBorder(new EtchedBorder()); - sta.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - sta.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - - //textPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); - textPanel.add(sta); - } - - /** - * Set up the script panel tab. - * @return Newly created script panel. - */ - private JPanel createScriptPanel() { - eventList = new JList(); - - // create ScrollPane for jlist scrolling - final JScrollPane ssa = new JScrollPane(eventList); - ssa.setBorder(new EtchedBorder()); - ssa.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - ssa.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - ssa.setPreferredSize(new Dimension(80, 40)); - - // create buttons - final JPanel grid = new JPanel(new GridLayout(2, 2)); - grid.add(new JButton(aNew)); - grid.add(new JButton(aPath)); - grid.add(new JButton(aModify)); - grid.add(new JButton(aRemove)); - - // disable all the buttons in the beginning - aNew.setEnabled(false); - aModify.setEnabled(false); - aPath.setEnabled(false); - aRemove.setEnabled(false); - - final JPanel scriptPanel = new JPanel(); // new panel - scriptPanel.setLayout(new BoxLayout(scriptPanel, BoxLayout.X_AXIS)); - scriptPanel.add(ssa); - scriptPanel.add(grid); - scriptPanel.setPreferredSize(new Dimension(100, 40)); - return scriptPanel; - } - - /** Action method for creating a new Script. */ - @ActionMethod public void scriptAddNew() { - addNewScriptWanted(); - } - - /** Action method for editing the data of an existing Script. */ - @ActionMethod public void scriptEditData() { - editScriptWanted(SCRIPT_EDIT_PATH); - } - - /** Action method for editing an existing Script. */ - @ActionMethod public void scriptEdit() { - editScriptWanted(SCRIPT_OPEN); - } - - /** Action method for removing an existing script. */ - @ActionMethod public void scriptRemove() { - editScriptWanted(SCRIPT_REMOVE); - } - - void appExitNotify() { - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - settings.setProperty(MAPARCHPANEL_LOCATION_KEY, String.valueOf(splitPane.getDividerLocation())); - } - - void refresh() { - setMapArchPanelObject(mainView.getMapTileSelection()); - repaint(); - } - - /** - * Update the map arch panel to display the custom font. - * @param refresh if true, the window is redrawn after setting the fonts - */ - public void updateFont(final boolean refresh) { - archMapPos.setForeground(Color.black); - archTypeText.setForeground(Color.black); - archFaceText.setForeground(Color.black); - - // document needs to be set! - - // refresh if desired - if (refresh) { - refresh(); - } - } - - /** - * If an arch is selected, the MapArchPanels (bottom right windows) get - * updated. - * @return the selected arch - */ - public GameObject getMapArchPanelObject() { - return selectedObject; - } - - /** - * If an arch is selected, the MapArchPanels (bottom right windows) get - * updated. - * @param activeGameObject the selected arch - */ - void setMapArchPanelObject(final GameObject activeGameObject) { - selectedObject = activeGameObject; - // reset panel - archNameField.setText(""); - archFaceText.setText("Image:"); - archTypeText.setText("Type:"); - archTextArea.setText(""); - archMapPos.setText("Status: "); - - // reset list - archEdit.setEnabled(false); - archEdit.setText(""); - if (activeGameObject == null) { - // an empty space has been selected - reset panel to empty state - if (eventList != null && eventList.getModel() != null && eventList.getModel().getSize() > 0) { - eventList.setModel(new DefaultListModel()); // clear script event list - } - - if (aNew != null && aRemove != null) { - aNew.setEnabled(false); - aModify.setEnabled(false); - aPath.setEnabled(false); - aRemove.setEnabled(false); - } - panelDesktop.setForegroundAt(0, Color.black); - panelDesktop.setForegroundAt(1, Color.black); - panelDesktop.setForegroundAt(2, Color.black); - panelDesktop.setForegroundAt(3, Color.black); - - aInvChange.setEnabled(false); - aAttrWin.setEnabled(false); - aSubmitChange.setEnabled(false); - return; - } - - // If the active gameObject is part of a multi, the mutli-head's stats - // are displayed (Only the head can store information!). - final GameObject gameObject = activeGameObject.getHead(); - - panelDesktop.setForegroundAt(0, Color.blue); - aInvChange.setEnabled(true); - aAttrWin.setEnabled(true); - aSubmitChange.setEnabled(true); - - final GameObject archetype = gameObject.getArchetype(); - - // no text, we try to set the default text - final boolean hasMessage; - if (gameObject.getMsgText() == null && archetype != null) { - archTextArea.setForeground(Color.black); - if (archetype.getMsgText() == null) { - archTextArea.setText(""); - hasMessage = false; - } else { - archTextArea.setText(archetype.getMsgText()); - hasMessage = true; - } - } else { - archTextArea.setForeground(Color.blue); - archTextArea.setText(gameObject.getMsgText()); - hasMessage = true; - } - archTextArea.setCaretPosition(0); - if (hasMessage) { - panelDesktop.setForegroundAt(1, Color.blue); - } - // end msg text - - // SET FACE - if (gameObject.getFaceFlag()) { - archFaceField.setText(""); - } else if (gameObject.getFaceName() != null) { // custom face - archFaceField.setForeground(Color.blue); - archFaceField.setText(gameObject.getFaceName()); - } else if (gameObject.getArchetypeName() != null) { - archFaceField.setForeground(Color.black); - archFaceField.setText(archetype.getFaceName()); - } // end face - if (gameObject.getAnimName() != null || archetype != null && archetype.getAnimName() != null) { - panelDesktop.setForegroundAt(3, Color.blue); - } - - // *** OBJECT NAME *** - if (gameObject.getObjName() == null && archetype != null) { - archNameField.setForeground(Color.black); - if (archetype.getObjName() == null) { - // gameObject name - if (gameObject.getArchetypeName() != null) { - archNameField.setText(gameObject.getArchetypeName()); - } else { - archNameField.setText(""); - } - } else { - // default name - archNameField.setText(archetype.getObjName()); - } - } else { - // object name ("special") - archNameField.setForeground(Color.blue); - archNameField.setText(gameObject.getObjName()); - } // end ObjName - - // set hint for "specials": scripts/inventory/message - final StringBuilder specialText = new StringBuilder(); - specialText.append("Status: in node ").append(gameObject.getMapX()).append(", ").append(gameObject.getMapY()).append(' '); - if (gameObject.isScripted()) { - panelDesktop.setForegroundAt(2, Color.blue); - specialText.append("(script)"); - } - if (hasMessage) { - specialText.append("(msg)"); - } - final int invObjects = gameObject.countInvObjects(); - if (invObjects > 0) { - specialText.append(" (inv: ").append(invObjects).append(')'); - } - if (gameObject.isInContainer()) { - final GameObject cont = (GameObject) gameObject.getContainer(); - if (cont.getArchetypeName() != null) { - specialText.append(" (env: ").append(cont.getArchetypeName()).append(')'); - } else { - specialText.append(" (env: ><)"); - } - } - - archMapPos.setText(specialText.toString()); - - final StringBuilder typeText = new StringBuilder(); - if (archetype != null) { - typeText.append("Type: ").append(mainControl.getTypeList().getArchTypeName(gameObject.getArchTypNr())).append(" (").append(gameObject.getArchTypNr()).append(") [").append(gameObject.getArchetypeName()).append(']'); - } else { - typeText.append("Type: <unknown>"); - } - - // check for multi tile - if (gameObject.isMulti()) { - // multi: print size - typeText.append(" [").append(gameObject.getSizeX()).append('x').append(gameObject.getSizeY()).append(']'); - } else { - // single - typeText.append(" [single]"); - } - - archTypeText.setText(typeText.toString()); - - final StringBuilder faceText = new StringBuilder(); - if (gameObject.getFaceFlag()) { - faceText.append("Image: >no face<"); - } else { - final String faceName = gameObject.getFaceName(); - if (faceName != null) { - faceText.append("Image: ").append(faceName); - } else if (archetype == null) { - faceText.append("Image: >no face<"); - } else { - final String archFaceName = archetype.getFaceName(); - if (archFaceName != null) { - faceText.append("Image: ").append(archFaceName); - } else { - faceText.append("Image: >no face<"); - } - } - } - archFaceText.setText(faceText.toString()); - - String animName = gameObject.getAnimName(); - if (animName == null && archetype != null) { - animName = archetype.getAnimName(); - } - final StringBuilder animText = new StringBuilder("Animation: "); - if (animName != null) { - animText.append(animName); - if (!mainControl.getAnimationObjects().containsKey(animName)) { - panelDesktop.setForegroundAt(3, Color.red); - animText.append(" (** unknown animation **)"); - } - } - archAnimText.setText(animText.toString()); - - // drawing the gameObject's attributes in the text field (archEdit) at the bottom right - archEdit.setEnabled(true); - final Style currentAttributes = archEdit.getStyle(StyleContext.DEFAULT_STYLE); - try { - // Color.blue: the "special" attributes, differ from the default archetype - StyleConstants.setForeground(currentAttributes, Color.blue); - if (gameObject.getObjectText() != null) { - document.insertString(document.getLength(), gameObject.getObjectText(), currentAttributes); - } - - // document.insertString(document.getLength(), "ID#"+gameObject+ " inv#: "+gameObject.countInvObjects()+"\n", currentAttributes); - - // Color.black: the attributes from the default archetype - // that don't exist among the "special" ones - StyleConstants.setForeground(currentAttributes, Color.black); - if (gameObject.getObjectText() != null && archetype != null) { - document.insertString(document.getLength(), gameObject.diffArchText(archetype.getObjectText(), true), currentAttributes); - } - } catch (final BadLocationException e) { - // TODO - } - archEdit.setCaretPosition(0); - - // ------ script panel ------ - if (gameObject.isScripted()) { - eventList.removeAll(); // clear event list - gameObject.addEventsToJList(eventList); // update JList to display all events - - aModify.setEnabled(true); - aPath.setEnabled(true); - aRemove.setEnabled(true); - } else if (eventList.getModel() != null && eventList.getModel().getSize() > 0) { - eventList.setModel(new DefaultListModel()); // clear event list - - aModify.setEnabled(false); - aPath.setEnabled(false); - aRemove.setEnabled(false); - } - aNew.setEnabled(true); - } - - /** - * This method is invoked when the user pressed the "edit - * script"/"path"/"remove" button from the script panel. If there is a - * valid selection in the event list, the appropriate action for this - * script is triggered. - * @param task Script type to edit (?). - */ - public void editScriptWanted(final int task) { - GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected gameObject - if (gameObject == null) { - return; - } - - gameObject = gameObject.getHead(); - - // check for a valid selection in the event list - if (eventList.getModel() != null && eventList.getModel().getSize() > 0 && eventList.getSelectedIndex() >= 0) { - // there - String eventType = (String) eventList.getSelectedValue(); - if (eventType != null && eventType.length() > 0) { - eventType = eventType.trim(); - gameObject.modifyEventScript(eventType, task, eventList, this); - } - } - } - - /** This method is invoked when the user pressed the "new script" button. */ - public void addNewScriptWanted() { - GameObject arch = mainControl.getMainView().getMapTileSelection(); // get selected arch - if (arch != null) { - arch = arch.getHead(); - arch.addEventScript(eventList, this); - } - } - - /** - * Set enable/disable states for the four buttons in the script panel. - * @param newButton Enabled state for the "new" button. - * @param modifyButton Enabled state for the "modify" button. - * @param pathButton Enabled state for the "path" button. - * @param removeButton Enabled state for the "remove" button. - */ - public void setScriptPanelButtonState(final boolean newButton, final boolean modifyButton, final boolean pathButton, final boolean removeButton) { - aNew.setEnabled(newButton); - aModify.setEnabled(modifyButton); - aPath.setEnabled(pathButton); - aRemove.setEnabled(removeButton); - } - -} // class CMapArchPanel Modified: trunk/crossfire/src/cfeditor/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/ScriptArchData.java 2006-12-26 23:40:48 UTC (rev 1296) +++ trunk/crossfire/src/cfeditor/ScriptArchData.java 2006-12-26 23:55:03 UTC (rev 1297) @@ -25,6 +25,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.gui.GameObjectAttributesPanel; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Insets; @@ -284,13 +285,13 @@ if (index >= 0) { final ScriptedEvent event = eventList.get(index); // now decide what to do: - if (task == CMapArchPanel.SCRIPT_OPEN) { + if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { event.openScript(); - } else if (task == CMapArchPanel.SCRIPT_EDIT_PATH) { + } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { // show popup to edit file path and plugin name event.editScriptPath(); eventList.set(index, event); // save changes - } else if (task == CMapArchPanel.SCRIPT_REMOVE) { + } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + eventType + "\" event which is\n" + "linked to the script: '" + event.getFilePath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { // remove this event from the GameObject Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-12-26 23:40:48 UTC (rev 1296) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-12-26 23:55:03 UTC (rev 1297) @@ -27,9 +27,9 @@ import cfeditor.AutojoinList; import cfeditor.CFArchType; import cfeditor.CFArchTypeList; -import cfeditor.CMapArchPanel; import cfeditor.IGUIConstants; import cfeditor.ScriptArchData; +import cfeditor.gui.GameObjectAttributesPanel; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -757,7 +757,7 @@ * @param mapanel the MapArchPanel * @xxx this method knows things it should never know, it is evil! */ - public void modifyEventScript(final String eventType, final int task, final JList eventList, final CMapArchPanel mapanel) { + public void modifyEventScript(final String eventType, final int task, final JList eventList, final GameObjectAttributesPanel mapanel) { if (script != null) { script.modifyEventScript(eventType, task, eventList); @@ -775,7 +775,7 @@ * the events * @param mapanel the MapArchPanel */ - public void addEventScript(final JList eventList, final CMapArchPanel mapanel) { + public void addEventScript(final JList eventList, final GameObjectAttributesPanel mapanel) { if (script == null) { script = new ScriptArchData(); } Copied: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java (from rev 1296, trunk/crossfire/src/cfeditor/CMapArchPanel.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2006-12-26 23:55:03 UTC (rev 1297) @@ -0,0 +1,909 @@ +/* + * 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.gui; + +import cfeditor.CMainControl; +import cfeditor.CMainView; +import cfeditor.CSettings; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.ArchetypeSet; +import cfeditor.gameobject.GameObject; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.Toolkit; +import javax.swing.Action; +import javax.swing.BoxLayout; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.JViewport; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingConstants; +import javax.swing.border.EtchedBorder; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyleContext; +import net.sf.gridarta.gui.GSplitPane; +import net.sf.gridarta.gui.connectionview.ConnectionControl; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.swing.ActionMethod; + +/** + * <code>GameObjectAttributesPanel</code> implements the panel that holds information about + * the currently selected GameObject on the map. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class GameObjectAttributesPanel extends JPanel { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + // constants for the 'task' parameter in editScriptWanted() + public static final int SCRIPT_OPEN = 0; + + public static final int SCRIPT_EDIT_PATH = 1; + + public static final int SCRIPT_REMOVE = 2; + + // MAN! This is one of these java shitholes + // without overruling getScrollableTracksViewportWidth(), + // is JTextPanel not scrolling horizontal + // i searched hours for the reason... the net is full of broken examples + private final JTextPane archEdit = new JTextPane() { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** {@inheritDoc} */ + @Override public boolean getScrollableTracksViewportWidth() { + return getSize().width < getParent().getSize().width; + } + + /** {@inheritDoc} */ + @Override public void setSize(final Dimension d) { + if (d.width < getParent().getSize().width) { + d.width = getParent().getSize().width; + } + super.setSize(d); + } + }; + + private static final String MAPARCHPANEL_LOCATION_KEY = "MainWindowMapArchPanel.dividerLocation"; + + /** Controller of this subview. */ + private final CMainControl mainControl; + + private final CMainView mainView; + + private final GSplitPane splitPane; + + private final JTabbedPane panelDesktop; + + private final Document document; + + /** Panel with name/face etc. */ + private final JPanel archPanel; + + /** Panel with message text. */ + private JPanel textPanel; + + private final JPanel animationPanel; + + /** Arch text field. */ + private final JTextArea archTextArea = new JTextArea(4, 25); + + /** Arch name field. */ + private final JTextField archNameField = new JTextField(14); + + /** Arch face field. */ + private final JTextField archFaceField = new JTextField(14); + + private final JLabel archMapPos = new JLabel(); + + private final JLabel archFaceText = new JLabel(); + + private final JLabel archTypeText = new JLabel(); + + private final JLabel archAnimText = new JLabel(); + + private final JPanel mapArchPanel = new JPanel(); + + private final Action aSubmitChange = ACTION_FACTORY.createAction(false, "mapArchApply", this); + + private final Action aInvChange = ACTION_FACTORY.createAction(false, "mapArchAddInv", this); + + private final Action aAttrWin = ACTION_FACTORY.createAction(false, "mapArchAttrib", this); + + private final Action aNew = ACTION_FACTORY.createAction(false, "scriptAddNew", this); + + private final Action aPath = ACTION_FACTORY.createAction(false, "scriptEditData", this); + + private final Action aModify = ACTION_FACTORY.createAction(false, "scriptEdit", this); + + private final Action aRemove = ACTION_FACTORY.createAction(false, "scriptRemove", this); + + private JList eventList; + + private GameObject selectedObject; + + /* Build Panel */ + public GameObjectAttributesPanel(final CMainControl mainControl, final CMainView view) { + this.mainControl = mainControl; + mainView = view; + final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); + setLayout(new BorderLayout()); + + final ConnectionControl connectionControl = new ConnectionControl(mainControl); + + // scrollPane2 contains the document for archtext editing + final JScrollPane scrollPane2 = new JScrollPane(archEdit); + scrollPane2.setBackground(archEdit.getBackground()); + scrollPane2.getViewport().add(archEdit); + add(scrollPane2, BorderLayout.EAST); + scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane2.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + + panelDesktop = new JTabbedPane(SwingConstants.TOP); + mapArchPanel.setLayout(new BorderLayout()); + splitPane = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapArchPanel, scrollPane2); + + final JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(0, 1)); + + mapArchPanel.add(buttonPanel, BorderLayout.WEST); + + // our buttons + buttonPanel.add(new JButton(aSubmitChange)); + buttonPanel.add(new JButton(aInvChange)); + buttonPanel.add(new JButton(aAttrWin)); + + mapArchPanel.add(panelDesktop, BorderLayout.CENTER); + + // setup our plain archPanel - we need to add later field to it + // depending on the arch typ selected + archPanel = new JPanel(); + final GridBagLayout gridbag = new GridBagLayout(); + final GridBagConstraints gbc = new GridBagConstraints(); + archPanel.setLayout(gridbag); + gbc.fill = GridBagConstraints.BOTH; + gbc.anchor = GridBagConstraints.NORTHWEST; + + animationPanel = new JPanel(); + + setupArchPanel(); + setupTextPanel(); + setupAnimationPanel(); + + panelDesktop.add(archPanel, "Arch"); + panelDesktop.add(textPanel, "Msg Text"); + + panelDesktop.add(createScriptPanel(), "Scripts"); + + panelDesktop.add(animationPanel, "Animation"); + panelDesktop.add(connectionControl.getView(), "Connection"); + + // calculate default value in case there is no settings file + final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + + splitPane.setDividerLocation(Integer.parseInt(settings.getProperty(MAPARCHPANEL_LOCATION_KEY, String.valueOf((int) (0.49 * screen.getWidth()))))); + add(splitPane, BorderLayout.CENTER); + + updateFont(true); + + document = archEdit.getDocument(); + } + + /** + * Action method for applying the changes made in the arch panel. + */ + @ActionMethod public void mapArchApply() { + applyArchPanelChanges(mainView.getMapTileSelection()); + } + + /** + * Action method for displaying the attributes of the currently selected object. + */ + @ActionMethod public void mapArchAttrib() { + mainControl.openAttrDialog(mainView.getMapTileSelection()); + } + + /** + * Action method for adding an object to the inventory of the currently selected object. + */ + @ActionMethod public void mapArchAddInv() { + final GameObject arch = mainControl.getArchPanelHighlight(); + if (arch == null) { // nothing selected? + return; + } + + // no single tile? + if(arch.isMulti()) { + return; + } + + GameObject inv = mainView.getMapTileSelection(); + if (inv == null) { + return; + } + + // if this is a multi-tail, we put the new arch into the head's inv. + inv = inv.getHead(); + + final GameObject invnew; + if (arch.isArchetype()) { + // create a new copy of a default arch + invnew = arch.createArch(); + } else { + // create clone from a pickmap + invnew = arch.createClone(inv.getMapX(), inv.getMapY()); + } + + mainControl.getArchetypeParser().postParseGameObject(invnew, 0); + inv.addLast(invnew); + mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified + } + + public void updateMapTileList() { + mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified + } + + /** + * When the "apply"-button on the ArchPanel (at the bottom of the window) + * is pressed, this function updates the active arch object. + * @param activeArch the currently selected arch + */ + public void applyArchPanelChanges(final GameObject activeArch) { + boolean needRedraw = false; // do we need a map-redraw? true/false + + if (activeArch == null) { + return; + } + + // If the active gameObject is part of a multi, the mutli-head's stats + // are taken instead: + final GameObject gameObject = activeArch.getHead(); + + final GameObject archetype = gameObject.getArchetype(); + if (archetype == null) { // hm, this should NOT happen + return; + } + + final String oldArchText = gameObject.getObjectText(); + final String oldMsg = gameObject.getMsgText(); + + // We update all panels: name, face, msg and archText (more to come...) + // the obj name: + if (isNonwhitespaceText(archNameField.getText())) { // there is something in + // if this equal the default name... + if (archetype.getObjName() != null) { + if (archNameField.getText().compareTo(archetype.getObjName()) == 0) { + gameObject.setObjName(null); // yes, we don't need it in map + } else { + gameObject.setObjName(archNameField.getText()); // overrule in map gameObject + } + } else if (archNameField.getText().compareTo(gameObject.getArchetypeName()) == 0) { + gameObject.setObjName(null); + } else { // def is null, something is in panel, so we set it + gameObject.setObjName(archNameField.getText()); // overrule in map gameObject + } + } else { + gameObject.setObjName(null); // nothing in, nothing in map gameObject + // hm, there is no way yet to overrule a default gameObject name with "nothing" + // like <name > ore <name "">..?? + } + + // set face + if (isNonwhitespaceText(archFaceField.getText())) { // there is something in + // check if we need a map redraw + if (archetype.getFaceName() != null) { + final String facename; + if (gameObject.getFaceName() != null) { + facename = gameObject.getFaceName(); + } else { + facename = archetype.getFaceName(); + } + + if (archFaceField.getText() != null && archFaceField.getText().compareTo(facename) != 0) { + needRedraw = true; + } + } + + if (archetype.getFaceName() != null) { + if (archFaceField.getText().compareTo(archetype.getFaceName()) == 0) { + gameObject.setFaceName(null); // yes, we don't need it in map + } else { + gameObject.setFaceName(archFaceField.getText()); // overrule in map arch + } + } else { + gameObject.setFaceName(archFaceField.getText()); // overrule in map arch + } + } else { + if (gameObject.getFaceName() != null) { + needRedraw = true; // reset to default arch - needs redraw + } + + gameObject.setFaceName(null); // nothing in, nothing in map arch + // also, no overrule... + } + + if (gameObject.getFaceName() != null) { + // we have a non-default face + final int index = ArchetypeSet.getFaceIndex(gameObject.getFaceName()); + gameObject.setFaceNr(index); + } else { + // we have the default face + final int index = ArchetypeSet.getFaceIndex(archetype.getFaceName()); + gameObject.setFaceNr(index); + } + + // the msg TEXT!! ("msg ... endmsg") + // if there is an entry in the archTextArea (msg window), this + // overrules the default text (if any) + if (isNonwhitespaceText(archTextArea.getText())) { // there is something in the msg win + if (archetype.getMsgText() != null) { + // trim text from message window + String newMsgText = archTextArea.getText(); + if (newMsgText != null) { + newMsgText = newMsgText.trim(); + } else { + newMsgText = ""; + } + if (newMsgText.equals(archetype.getMsgText().trim())) { + gameObject.deleteMsgText(); // yes, we don't need it in map + } else { + gameObject.resetMsgText(); + gameObject.addMsgText(newMsgText); + } + } else { + gameObject.resetMsgText(); + gameObject.addMsgText(archTextArea.getText()); + } + } else { // there is nothing in the msg win + gameObject.deleteMsgText(); // always delete this... + if (archetype.getMsgText() != null) { + gameObject.addMsgText(""); // but here we must overrule default with msg/endmsg (empty msg) + } + } + + // read from archEdit (bottom right textwin) only the attributes + // that differ from the default gameObject. These get stored into + // the arche's archText (and finally in the map). + gameObject.setObjectText(archetype.diffArchText(archEdit.getText(), false)); + + // we look for 'type' in the ArchText. In future maybe type should get + // a seperate textfield + if (gameObject.getAttributeString("type", false).length() > 0) { + gameObject.setArchTypNr(gameObject.getAttributeInt("type", false)); // specified type + } + + // Recalculate the editType value. It shall stay 100% accurate ;) + gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); + + // if the archtext changed, set the map changed flag + if ((oldArchText != null && !oldArchText.equals(gameObject.getObjectText())) || + (oldArchText == null && gameObject.getObjectText() != null) || + (oldMsg != null && !oldMsg.equals(gameObject.getMsgText())) || + (oldMsg == null && gameObject.getMsgText() != null)) { + mainControl.getCurrentMap().setLevelChangedFlag(); + } + + // there we go!!!!! + // now here will be the special panels added! + refresh(); + + updateMapTileList(); + + // if needed (due to face changes), we also redraw the map + if (needRedraw) { + mainControl.getCurrentMap().repaint(); + } + } + + // simple "white space test, to eliminate ' ' + // perhaps we should include here a real white space test + private static boolean isNonwhitespaceText(final String text) { + return text.replaceAll("\\s+", "").length() > 0; + } + + /** Set up the animation panel. */ + private void setupAnimationPanel() { + final GridBagLayout gridbag = new GridBagLayout(); + final GridBagConstraints gbc = new GridBagConstraints(); + + animationPanel.setLayout(gridbag); + gbc.fill = GridBagConstraints.BOTH; + gbc.weightx = 1.0; + gbc.weighty = 0; + gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.insets = new Insets(3, 3, 0, 0); + + archAnimText.setText("Animation: "); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.gridwidth = 1; + gbc.gridheight = 1; + gridbag.setConstraints(archAnimText, gbc); + animationPanel.add(archAnimText); + + } + + /** Set up the arch panel entry of the lower window. */ + private void setupArchPanel() { + final GridBagLayout gridbag = new GridBagLayout(); + final GridBagConstraints gbc = new GridBagConstraints(); + + archPanel.setLayout(gridbag); + gbc.fill = Grid... [truncated message content] |
From: <chr...@us...> - 2006-12-27 00:00:10
|
Revision: 1298 http://svn.sourceforge.net/gridarta/?rev=1298&view=rev Author: christianhujer Date: 2006-12-26 16:00:10 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CAttribDialog to GameObjectAttributesDialog. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribBitmask.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CAttribBitmask.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java Added Paths: ----------- trunk/crossfire/src/cfeditor/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/GameObjectAttributesDialog.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/daimonin/src/daieditor/CAttribDialog.java Modified: trunk/crossfire/src/cfeditor/CAttribBitmask.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribBitmask.java 2006-12-26 23:55:03 UTC (rev 1297) +++ trunk/crossfire/src/cfeditor/CAttribBitmask.java 2006-12-27 00:00:10 UTC (rev 1298) @@ -135,7 +135,7 @@ * @param guiAttr Bitmask attribute to update * @return Integer with new value or <code>null</code> if the user cancelled the dialog */ - @Nullable public Integer showBitmaskDialog(final Component parentComponent, final CAttribDialog.BitmaskAttrib guiAttr) { + @Nullable public Integer showBitmaskDialog(final Component parentComponent, final GameObjectAttributesDialog.BitmaskAttrib guiAttr) { final String title = "Choose " + guiAttr.ref.getNameNew().substring(0, 1).toUpperCase() + guiAttr.ref.getNameNew().substring(1); final JPanel gridPanel = new JPanel(new GridLayout(0, 2, 3, 3)); final JCheckBox[] checkbox = new JCheckBox[number]; Deleted: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-26 23:55:03 UTC (rev 1297) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-27 00:00:10 UTC (rev 1298) @@ -1,1775 +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.ArchetypeSet; -import cfeditor.gameobject.GameObject; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.ComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFormattedTextField; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JTextPane; -import javax.swing.JViewport; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.WindowConstants; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultFormatterFactory; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.NumberFormatter; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import net.sf.gridarta.gameobject.ArchAttribType; -import net.sf.gridarta.gameobject.Archetype; -import net.sf.gridarta.gameobject.NamedObject; -import net.sf.gridarta.gameobject.NamedObjects; -import net.sf.gridarta.help.Help; -import net.sf.gridarta.map.MapModel; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * CAttribDialog poses the GUI for Crossfire object attributes. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @fixme I suck - */ -public final class CAttribDialog extends JOptionPane implements FocusListener { - - private static final Logger log = Logger.getLogger(CAttribDialog.class); - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - // store width of input-textfields, then JChooseBoxes are set to this width too - public static final int TEXTFIELD_COLUMNS = 18; // number of columns for textfields - - private final CMainControl mainControl; // reference to the main control - - private final CFArchTypeList archTypeList; // reference to the list of CF type-data - - private List<DialogAttrib<?>> dialogAttribs = new ArrayList<DialogAttrib<?>>(); - - private JComboBox typesel; // selection box for type - - private JLabel imagePanel; // panel for object's face (png) - - /** The game object being modified. */ - @NotNull private final GameObject gameObject; - - private final Archetype<GameObject> archetype; - - private CFArchType type; // reference to the type data - - // this differs from the GameObject if the type is undefined - private int listNr; // the position of this type in the type list - - /** The CardLayout for toggling between edit and summary. */ - private final CardLayout cardLayout = new CardLayout(); - - /** The Action for switching to the summary. */ - private Action summaryAction = ACTION_FACTORY.createAction(false, "attribSummary", this); - - /** The Action for switching to the edit. */ - private Action editAction = ACTION_FACTORY.createAction(false, "attribEdit", this); - - /** The Button for toggling the summary. */ - private JButton summaryEditButton; - - /** The Button for cancel. */ - private JButton cancelButton; - - /** The Button for ok. */ - private JButton okButton; - - /** Central tabbed pane (the place where all the attribute tabs are). */ - private JTabbedPane tabbedPane; - - /** Central pane, this is the parent component of above tabbed pane. */ - private final JPanel centerPane; - - /** Text pane where the summary is displayed. */ - private final JTextPane summaryTP; - - /** The gameObject objects that already are shown, to avoid opening a dialog twice. */ - private static final Map<GameObject, JDialog> dialogs = new HashMap<GameObject, JDialog>(); - - /** - * Wrapper method for the constructor. - * This method only creates a CAttribDialog if there's no dialog for the same gameObject already. - * @param archTypeList the list of CF type-data - * @param gameObject the GameObject to be displayed by this dialog - * @param mainControl main control - */ - public static void showAttribDialog(final CFArchTypeList archTypeList, final GameObject gameObject, final CMainControl mainControl) { - synchronized (dialogs) { - if (dialogs.containsKey(gameObject)) { - dialogs.get(gameObject).toFront(); - } else { - final CAttribDialog pane = new CAttribDialog(archTypeList, gameObject, mainControl); - final JDialog dialog = pane.createDialog(mainControl.getMainView(), ACTION_FACTORY.getString("attribTitle")); - dialog.getRootPane().setDefaultButton(pane.okButton); - dialog.setResizable(true); - dialog.setModal(false); - dialog.setVisible(true); - dialogs.put(pane.gameObject, dialog); - } - } - } - - /** - * Constructor, creates the GUI layout. - * @param archTypeList the list of CF type-data - * @param gameObject the GameObject to be displayed by this dialog - * @param mainControl main control - */ - private CAttribDialog(final CFArchTypeList archTypeList, @NotNull final GameObject gameObject, final CMainControl mainControl) { - listNr = 0; - - this.mainControl = mainControl; // reference to the main control - this.archTypeList = archTypeList; // reference to the typelist - - // reference to the GameObject - this.gameObject = gameObject.getHead(); - archetype = this.gameObject.getArchetype(); - - type = archTypeList.getType(gameObject); - listNr = archTypeList.getArchTypeIndex(type); - - // first split top-left and -right - final JComponent leftPane = buildHeader(); - final JScrollPane rightPane = buildInv(); - - //Create a split pane with the two scroll panes in it. - final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane); - - // Now split horizontally - //JScrollPane centerPane = buildAttr(); - centerPane = new JPanel(cardLayout); - centerPane.add("edit", buildAttr()); - summaryTP = new JTextPane(); - summaryTP.setEditable(false); - summaryTP.setBorder(BorderFactory.createEmptyBorder(3, 15, 0, 0)); - centerPane.add("summary", new JScrollPane(summaryTP)); - final Dimension size = centerPane.getPreferredSize(); - size.height = 256; - centerPane.setMinimumSize(size); - centerPane.setPreferredSize(size); - - final JPanel contentPanel = new JPanel(new GridBagLayout()); - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.weightx = 1.0; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridwidth = GridBagConstraints.REMAINDER; - gbc.weighty = 0.0; - contentPanel.add(splitPane, gbc); - gbc.weighty = 1.0; - contentPanel.add(centerPane, gbc); - - setOptions(buildOptions()); - - setMessage(contentPanel); - } - - /** {@inheritDoc} */ - @Override public void setValue(final Object newValue) { - super.setValue(newValue); - if (newValue != UNINITIALIZED_VALUE) { - dialogs.remove(gameObject).dispose(); - } - } - - /** - * Construct the Combo box of the available archetypes. - * @return a <code>JComponent</code> with the combo box in it - */ - private JComponent buildTypesBox() { - final String[] namelist = new String[archTypeList.getLength()]; // list of typenames - - // read all type names - int i = 0; - for (final CFArchType tmp : archTypeList) { - namelist[i++] = " " + tmp.getTypeName(); - } - - // the active type appears selected in the box - final int selection = listNr; // position of selected type in the list - - typesel = new JComboBox(namelist); // set "content" - typesel.setSelectedIndex(selection); // set active selection - - //typesel.setKeySelectionManager(new StringKeyManager(typesel)); - - typesel.setName("Types"); - - // the listener: - typesel.addItemListener(new TypesBoxAL(this, gameObject)); - return typesel; - } - - /** - * Construct the Combo box of the available spells. - * @param attr spell attribute - * @return the completed <code>JComboBox</code> - */ - private JComboBox buildSpellBox(final CFArchAttrib attr) { - - // first parse the spell-number value from gameObject - int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - - if (spnum < 0 || spnum >= CFArchTypeList.getSpells().getSpellNumbers().length - 1) { - spnum = 0; // undefined spellnumbers be zero - } - - // do we have "none" spell? - int active; - if (spnum == 0 && (gameObject.getAttributeString(attr.getNameOld()).length() == 0 || attr.getDataType() == ArchAttribType.ZSPELL)) { - active = 0; - } else { - // now look up the spell-number in the array of spells - active = 0; - for (int i = 0; i < CFArchTypeList.getSpells().getSpellNumbers().length; i++) { - if (CFArchTypeList.getSpells().getSpellNumbers()[i] == spnum) { - active = i; // set selection - i = CFArchTypeList.getSpells().getSpellNumbers().length + 10; // end loop - } - } - } - - final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpells().getSpellNames()); // set "content" - spellsel.setSelectedIndex(active); // set active selection - spellsel.setMaximumRowCount(10); - spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); - - spellsel.setName(attr.getNameNew()); - - return spellsel; - } - - /** - * Construct the Combo box for arrays of "list data" (this is used for ArchAttribType.LIST). - * @param attr list attribute - * @param listData List with list items and corresponding values, that means the types are altering: String,Integer - * @return the completed <code>JComboBox</code> - */ - private JComboBox buildArrayBox(final CFArchAttrib attr, final List<?> listData) { - // build the array of list-items - final String[] array = new String[(int) (listData.size() / 2.0)]; - boolean hasSelection = false; - int active = gameObject.getAttributeInt(attr.getNameOld()); - - for (int i = 0; i < array.length; i++) { - array[i] = (String) listData.get(i * 2 + 1); // put string to array - if (!hasSelection && (Integer) listData.get(i * 2) == active) { - hasSelection = true; // the selection is valid - active = i; // set selection to this index in the array - } - } - // if there is no valid pre-selection, show first element of list - if (!hasSelection) { - active = 0; - } - - final JComboBox arraysel = new JComboBox(array); // set "content" - arraysel.setSelectedIndex(active); // set active selection - arraysel.setMaximumRowCount(10); - arraysel.setKeySelectionManager(new StringKeyManager(arraysel)); - - arraysel.setName(attr.getNameNew()); - - return arraysel; - } - - /** - * Construct the upper left part of the attribute dialog, - * containing name, type, archetype name and face. - * @return a <code>JScrollPane</code> with the upper left part of the dialog window - */ - private JComponent buildHeader() { - final JPanel header = new JPanel(new GridBagLayout()); // the final thing, in a panel - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.BOTH; - gbc.insets = new Insets(2, 2, 2, 2); - gbc.gridx = 1; - gbc.gridy = 1; - gbc.weightx = 0.0; - gbc.weighty = 3.0; - gbc.gridheight = 3; - imagePanel = new JLabel(mainControl.getArchetypeSet().getFace(gameObject.getFaceNr())); - imagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); - header.add(imagePanel, gbc); - gbc.gridheight = 1; - gbc.weighty = 1.0; - gbc.fill = GridBagConstraints.HORIZONTAL; - - gbc.weightx = 0.0; - gbc.gridx = 2; - gbc.gridy = 1; - header.add(new JLabel("Name: ", SwingConstants.TRAILING), gbc); // create label - gbc.gridy++; - header.add(new JLabel("Type: ", SwingConstants.TRAILING), gbc); - gbc.gridy++; - header.add(new JLabel("Archetype: ", SwingConstants.TRAILING), gbc); // create label - - gbc.gridx = 3; - gbc.gridy = 1; - gbc.weightx = 1.0; - final JTextField nameTF;if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { - nameTF = new JTextField(gameObject.getObjName(), 16); - } else if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { - nameTF = new JTextField(archetype.getObjName(), 16); - } else { - nameTF = new JTextField(archetype.getArchetypeName(), 16); - } - nameTF.setEditable(false); - header.add(nameTF, gbc); - gbc.gridy++; - header.add(buildTypesBox(), gbc); // build type-selection box - gbc.gridy++; - final JTextField archetypeTF=new JTextField(archetype.getArchetypeName(), 16); - archetypeTF.setEditable(false); - header.add(archetypeTF, gbc); - - return header; - } - - /** - * Construct the upper right part of the attribute dialog, - * containing the object's inventory. - * @return a <code>JScrollPane</code> with the upper right part of the dialog window - */ - private static JScrollPane buildInv() { - final JPanel inv = new JPanel(); // the final thing, in a panel - inv.add(new JLabel("Inventory:")); // create label - - final JScrollPane scrollPane = new JScrollPane(inv); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - scrollPane.setSize(80, 70); - - return scrollPane; - } - - /** - * Construct the central part of the attribute dialog, containing the - * object's gameObject attributes. - * @return When this method is called the first time: a <code>JScrollPane</code> - * with the central part of the dialog window. - * All further calls rebuild the existing tabbedpane and return null. - */ - @Nullable private JComponent buildAttr() { - boolean initialCall = false; - - if (tabbedPane == null) { - tabbedPane = new JTabbedPane(); - initialCall = true; - } - - for (int i = 0; i < type.getSectionNum(); i++) { - final Component panel1 = makeAttribPanel(i); - if (panel1 != null) { - tabbedPane.addTab(getSectionName(i), null, panel1); - } - } - - // set selected tab - tabbedPane.setSelectedIndex(0); - - if (initialCall) { - return tabbedPane; - } else { - return null; - } - } - - /** - * This method creates an attribute panel for one section of attributes. If - * the section is empty, null is returned. - * @param secId the identifier of the section - * @return a <code>Component</code> containing the attribute panel - * (currently always a JScrollPane) - * @todo I'm still 263 lines long, please make me shorter. - */ - @Nullable private Component makeAttribPanel(final int secId) { - int number = 0; // number of attributes in this section - boolean hasBitmask = false; // true if this section contains a bitmask attribute - - // first we check how many attribs this section has - for (int i = 0; type.getAttr().length > i; i++) { - if (type.getAttr()[i].getSecId() == secId) { - // count number of attributes - if (type.getAttr()[i].getDataType() != ArchAttribType.FIXED) { - number++; - } - // check for bitmask attributes - if (!hasBitmask && type.getAttr()[i].getDataType() == ArchAttribType.BITMASK) { - hasBitmask = true; - } - } - } - if (number == 0) { - return null; - } - - // All attribute-"lines" go into this panel: - final JPanel panel = new JPanel(new GridBagLayout()); - final Insets gbcInsets = new Insets(2, 2, 2, 2); - - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = gbcInsets; - final Object helpGbc = gbc.clone(); - gbc.fill = GridBagConstraints.HORIZONTAL; - final Object labelGbc = gbc.clone(); - gbc.weightx = 1.0; - gbc.gridwidth = GridBagConstraints.REMAINDER; - final Object compGbc = gbc.clone(); - gbc.anchor = GridBagConstraints.WEST; - final Object rowGbc = gbc.clone(); - gbc.fill = GridBagConstraints.BOTH; - gbc.weighty = 1.0; - boolean isText = false; - final Object glueGbc = gbc.clone(); - - final CFArchAttrib[] attribs = type.getAttr(); - // now add the entrys, line by line - for (int i = 0; attribs.length > i; i++) { - final CFArchAttrib attrib = attribs[i]; - final ArchAttribType dType = attrib.getDataType(); // data type of the attribute - if (attrib.getSecId() == secId && dType != ArchAttribType.FIXED) { - final String nameOld = attrib.getNameOld(); - final JButton helpButton = new JButton("?"); - helpButton.setMargin(new Insets(0, 5, 0, 5)); - panel.add(helpButton, helpGbc); - helpButton.addFocusListener(this); - - JComponent cLabel = null; - JComponent cComp = null; - JComponent cRow = null; - JComponent cGlue = null; - - // now create the attribute-GUI-instance - final DialogAttrib<?> newAttr; - - switch (dType) { - case TEXT: { - isText = true; // text section (need special embedding without additional scrollbars) - newAttr = new DialogAttrib<JTextArea>(attrib); - String text = ""; - if (nameOld.equalsIgnoreCase("msg")) { - if (archetype.getMsgText() != null && archetype.getMsgText().length() > 0 && (gameObject.getMsgText() == null || gameObject.getMsgText().trim().length() == 0)) { - text = archetype.getMsgText(); - } else { - text = gameObject.getMsgText(); - } - } - final JTextArea input = new JTextArea(text, 10, 20); - input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); - final JScrollPane scrollPane = new JScrollPane(input); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - ((DialogAttrib<JTextArea>) newAttr).input = input; - cGlue = scrollPane; - } - break; - case BOOL: - case BOOL_SPEC: { - newAttr = new DialogAttrib<JCheckBox>(attrib); - final JCheckBox input; - switch (dType) { - case BOOL: - // normal bool - input = new JCheckBox(attrib.getNameNew(), gameObject.getAttributeInt(nameOld) == 1); - break; - case BOOL_SPEC: { - // parse values for customized bool - final String trueVal = attrib.getMisc()[0]; - if (trueVal.equals("0")) { - final String attrString = gameObject.getAttributeString(nameOld); - input = new JCheckBox(attrib.getNameNew(), attrString.length() == 0 || attrString.equals("0")); - } else { - input = new JCheckBox(attrib.getNameNew(), gameObject.getAttributeString(nameOld).equals(trueVal)); - } - } - break; - default: - assert false; - input = null; - break; - } - ((DialogAttrib<JCheckBox>) newAttr).input = input; - cRow = input; - } - break; - case INT: - case LONG: - case FLOAT: { - cLabel = new JLabel(attrib.getNameNew() + ": "); - cLabel.setForeground(dType == ArchAttribType.FLOAT ? IGUIConstants.FLOAT_COLOR : IGUIConstants.INT_COLOR); - newAttr = new DialogAttrib<JFormattedTextField>(attrib); - final int fieldLength = attrib.getInputLength() == 0 ? TEXTFIELD_COLUMNS : attrib.getInputLength(); - final NumberFormat format; - switch (dType) { - case INT: - case LONG: - format = NumberFormat.getIntegerInstance(); - break; - case FLOAT: - format = NumberFormat.getInstance(); - format.setMaximumFractionDigits(10); - break; - default: - assert false; - format = null; - break; - } - format.setGroupingUsed(false); - final NumberFormatter formatter = new NumberFormatter(format); - final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); - // parse value from gameObject - final Number value; - switch (dType) { - case INT: - value = gameObject.getAttributeInt(nameOld); - break; - case LONG: - value = gameObject.getAttributeLong(nameOld); - break; - case FLOAT: - value = gameObject.getAttributeDouble(nameOld); - break; - default: - value = null; - assert false; - break; - } - final JFormattedTextField input = new JFormattedTextField(factory, value); - input.setColumns(fieldLength); - cComp = input; - ((DialogAttrib<JFormattedTextField>) newAttr).input = input; - } - break; - case STRING: - case FACENAME: - case ANIMNAME: { - final String dtxt; - if (nameOld.equalsIgnoreCase("name")) { - if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { - dtxt = gameObject.getObjName(); - } else if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { - dtxt = archetype.getObjName(); - } else { - dtxt = archetype.getArchetypeName(); - } - } else if (nameOld.equalsIgnoreCase("face")) { - if (gameObject.getFaceName() != null && gameObject.getFaceName().length() > 0) { - dtxt = gameObject.getFaceName(); - } else { - dtxt = archetype.getFaceName(); - } - } else { - dtxt = gameObject.getAttributeString(nameOld); - } - final JTextField input = new JTextField(dtxt, TEXTFIELD_COLUMNS); - switch (dType) { - case STRING: - cLabel = new JLabel(attrib.getNameNew() + ": "); - newAttr = new DialogAttrib<JTextField>(attrib); - break; - case FACENAME: - case ANIMNAME: - newAttr = new DialogAttrib<JTextField>(attrib); - switch (dType) { - case FACENAME: - cLabel = new JButton(new TreeChooseAction(attrib.getNameNew() + ": ", input, mainControl.getFaceObjects())); - break; - case ANIMNAME: - cLabel = new JButton(new TreeChooseAction(attrib.getNameNew() + ": ", input, mainControl.getAnimationObjects())); - break; - default: - assert false; - cLabel = null; - break; - } - break; - default: - assert false; - newAttr = null; - break; - } - cComp = input; - ((DialogAttrib<JTextField>) newAttr).input = input; - } - break; - case SPELL: - case ZSPELL: - case LIST: { - cLabel = new JLabel(attrib.getNameNew() + ": "); - cLabel.setForeground(IGUIConstants.INT_COLOR); - newAttr = new DialogAttrib<JComboBox>(attrib); - // create ComboBox with parsed selection - final JComboBox input; - switch (dType) { - case SPELL: - case ZSPELL: - input = buildSpellBox(attrib); - break; - case LIST: - if (attrib.getMisc() != null && archTypeList.getListTable().containsKey(attrib.getMisc()[0])) { - // build the list from vector data - input = buildArrayBox(attrib, archTypeList.getListTable().get(attrib.getMisc()[0])); - } else { - // error: list data is missing or corrupt - cComp = new JLabel("Error: Undefined List"); - input = null; - } - break; - default: - assert false; - input = null; - break; - } - if (input != null) { - cComp = input; - } - ((DialogAttrib<JComboBox>) newAttr).input = input; - } - break; - case DBLLIST: { - final JPanel compo = new JPanel(new BorderLayout()); - cLabel = new JLabel(attrib.getNameNew() + ": "); - cLabel.setForeground(IGUIConstants.INT_COLOR); - newAttr = new DialogAttrib<JComboBox[]>(attrib); - // create ComboBox with parsed selection - final JComboBox[] inputs = new JComboBox[2]; - if (attrib.getMisc() != null && archTypeList.getListTable().containsKey(attrib.getMisc()[0]) && archTypeList.getListTable().containsKey(attrib.getMisc()[1])) { - // Hack to set preselected if available - final int active = gameObject.getAttributeInt(nameOld); - final int[] activepart = {active & 0x0F, active & 0xF0}; - // build the lists from vector data - for (int j = 0; j < 2; j++) { - final List<?> listData = archTypeList.getListTable().get(attrib.getMisc()[j]); - inputs[j] = buildArrayBox(attrib, listData); - for (int k = 0; (double) k < listData.size() / 2.0; k++) { - if ((Integer) listData.get(k << 1) == activepart[j]) { - inputs[j].setSelectedIndex(k); // set active selection - break; - } - } - } - compo.add(inputs[0], BorderLayout.NORTH); - compo.add(inputs[1], BorderLayout.SOUTH); - cComp = compo; - } else { - // error: list data is missing or corrupt - cComp = new JLabel("Error: Undefined List"); - } - ((DialogAttrib<JComboBox[]>) newAttr).input = inputs; - } - break; - case BITMASK: { - newAttr = new BitmaskAttrib(attrib); - if (attrib.getMisc() != null && archTypeList.getBitmaskTable().containsKey(attrib.getMisc()[0])) { - // fetch the bitmask data, then build the attribute panel - final CAttribBitmask bitmask = archTypeList.getBitmaskTable().get(attrib.getMisc()[0]); - ((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).bitmask = bitmask; - cLabel = new JButton(new MaskChangeAL(attrib.getNameNew() + ":", (BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr)); - final JTextArea input = new JTextArea(); - input.setBackground(getBackground()); - input.setEditable(false); - input.setBorder(BorderFactory.createLineBorder(Color.gray)); - input.setText(bitmask.getText(((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).getValue())); - cComp = input; - ((DialogAttrib<JTextComponent>) newAttr).input = input; - ((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).setValue(gameObject.getAttributeInt(nameOld)); - } else { - cRow = new JLabel("Error: Undefined Bitmask"); - } - } - break; - case TREASURE: { - newAttr = new DialogAttrib<JTextField>(attrib); - // textfield (no direct input, text is set by the treasurelist dialog) - String treasureName = gameObject.getAttributeString(nameOld); - if (treasureName.trim().length() == 0 || treasureName.trim().equalsIgnoreCase("none")) { - treasureName = CFTreasureListTree.NONE_SYM; - } - final JTextField input = new JTextField(" " + treasureName, TEXTFIELD_COLUMNS); - input.setEditable(false); - cLabel = new JButton(new ViewTreasurelistAL((DialogAttrib<JTextField>) newAttr, this)); - cComp = input; - ((DialogAttrib<JTextField>) newAttr).input = input; - } - break; - default: - newAttr = null; - assert false; - break; - } // switch (dType) - - assert newAttr != null; - dialogAttribs.add(newAttr); - helpButton.addActionListener(new HelpActionListener(newAttr.ref)); - if (cLabel != null) { - panel.add(cLabel, labelGbc); - cLabel.addFocusListener(this); - } - if (cComp != null) { - panel.add(cComp, compGbc); - cComp.addFocusListener(this); - } - if (cRow != null) { - panel.add(cRow, rowGbc); - cRow.addFocusListener(this); - } - if (cGlue != null) { - panel.add(cGlue, glueGbc); - cGlue.addFocusListener(this); - } - } - } - - if (!isText) { - // if the component does not already have glue, put glue inside to align its contents to the top. - panel.add(Box.createGlue(), glueGbc); - } - final JScrollPane panelReturn = new JScrollPane(panel); - panelReturn.getVerticalScrollBar().setUnitIncrement(8); - return panelReturn; - } - - /** - * Looks up the section name from the ID. - * @param secId ID of the section - * @return name of that section - */ - private String getSectionName(final int secId) { - for (int i = 0; type.getAttr().length > i; i++) { - if (type.getAttr()[i].getSecId() == secId) { - // we've got the string, now capitalize the first letter - String s = type.getAttr()[i].getSecName(); - if (s.length() > 1) { - s = s.substring(0, 1).toUpperCase() + s.substring(1); - } - return s; - } - } - - return "???"; - } - - /** - * Construct the dialog options: help, default, okay, apply, cancel. - * @return Object[] with dialog options - */ - private Object[] buildOptions() { - return new Object[] { - new JButton(ACTION_FACTORY.createAction(false, "attribHelp", this)), - summaryEditButton = new JButton(summaryAction), - Box.createHorizontalStrut(32), - okButton = new JButton(ACTION_FACTORY.createAction(false, "attribOk", this)), - new JButton(ACTION_FACTORY.createAction(false, "attribApply", this)), - cancelButton = new JButton(ACTION_FACTORY.createAction(false, "attribCancel", this)), - }; - } - - /** - * Action method for help. - */ - public void attribHelp() { - new Help(mainControl.getMainView(), type.createHtmlDocu()).setVisible(true); - } - - /** - * Action method for ok. - */ - public void attribOk() { - if (applySettings()) { - setValue(okButton); - } - } - - /** - * Action method for apply. - */ - public void attribApply() { - applySettings(); - } - - /** - * Action method for cancel. - */ - public void attribCancel() { - setValue(cancelButton); - } - - /** - * Spawns a popup-message to display the help text of an attribute. - * @param title name of attribute - * @param msg message text - */ - private void popupHelp(final String title, final String msg) { - showMessageDialog(this, msg, "Help: " + title, PLAIN_MESSAGE); - } - - /** - * Action method for summary. Switches the cardlayout to the summary list - * of all nonzero attributes. - */ - public void attribSummary() { - // interface is displayed, switch to summary - final Document doc = summaryTP.getDocument(); - - try { - // clear document - if (doc.getLength() > 0) { - doc.remove(0, doc.getLength()); - } - - final Style docStyle = summaryTP.getStyle(StyleContext.DEFAULT_STYLE); - StyleConstants.setForeground(docStyle, Color.black); - - // now loop through all attributes and write out nonzero ones - for (final DialogAttrib attr : dialogAttribs) { - switch (attr.ref.getDataType()) { - case BOOL: - case BOOL_SPEC: { - final boolean value = ((DialogAttrib<JCheckBox>) attr).input.isSelected(); // true/false - if (value) { - doc.insertString(doc.getLength(), "<" + attr.ref.getNameNew() + ">\n", docStyle); - } - } - break; - case INT: - case LONG: - case FLOAT: { - final String value = ((DialogAttrib<JFormattedTextField>) attr).input.getText(); // the attrib value - if (value != null && value.length() > 0 && !value.equals("0")) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case STRING: - case FACENAME: - case ANIMNAME: { - final String value = ((DialogAttrib<JTextField>) attr).input.getText(); // the attrib value - if (value != null && value.length() > 0) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case SPELL: - case ZSPELL: - case LIST: { - final String value = ((DialogAttrib<JComboBox>) attr).input.getSelectedItem().toString().trim(); // the attrib value - if (value != null && value.length() > 0 && !value.startsWith("<")) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case DBLLIST: { - final String value1 = ((DialogAttrib<JComboBox[]>) attr).input[0].getSelectedItem().toString().trim(); - final String value2 = ((DialogAttrib<JComboBox[]>) attr).input[1].getSelectedItem().toString().trim(); - String out = null; - if (value1 != null && value1.length() > 0 && !value1.startsWith("<")) { - out = value1; - } - if (value2 != null && value2.length() > 0 && !value2.startsWith("<")) { - if (out == null) { - out = value2; - } else { - out += " / " + value2; - } - } - if (out != null) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + out + "\n", docStyle); - } - } - break; - case BITMASK: { - final String value = ((BitmaskAttrib) attr).input.getText().trim(); - if (value != null && value.length() > 0 && !value.startsWith("<")) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case TREASURE: { - final String value = ((DialogAttrib<JTextField>) attr).input.getText().trim(); // the attrib value - if (value != null && value.length() > 0 && !value.equals(CFTreasureListTree.NONE_SYM)) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case TEXT: - /* Nothing to do. */ - break; - default: - assert false : "Unknown type: " + attr.ref.getDataType(); - break; - } - } - } catch (final BadLocationException e) { - log.error("toggleSummary: Bad Location in Document!", e); - } - - summaryTP.setCaretPosition(0); // this prevents the document from scrolling down - summaryEditButton.setAction(editAction); - cardLayout.show(centerPane, "summary"); - } - - /** - * Turns the summary off. - * Switches to the input-interface for all attributes and the summary list of all nonzero attributes. - */ - public void attribEdit() { - summaryEditButton.setAction(summaryAction); - cardLayout.show(centerPane, "edit"); - } - - /** - * This method is called when the "apply"-button has been - * pressed. All the settings from the dialog get - * written into the GameObject. - * @return true if the settings were applied, false if error occurred - */ - private boolean applySettings() { - final MapModel mapModel = mainControl.getCurrentMap().getMapModel(); - mapModel.beginTransaction("Change object attributes"); - try { - return applySettings2(); - } finally { - mapModel.endTransaction(); - } - } - - /** - * This method is called when the "apply"-button has been - * pressed. All the settings from the dialog get - * written into the GameObject. - * @return true if the settings were applied, false if error occurred - */ - private boolean applySettings2() { - final String oldArchText = gameObject.getObjectText(); // the old ArchText - final String oldMsg = gameObject.getMsgText(); // old gameObject msg - final CFArchType typeStruct = archTypeList.getTypeOfArch(gameObject); // the type structure for this gameObject - - String newArchText = ""; - String newName = null; - String newFace = null; - String newMsg = null; - for (final DialogAttrib attr : dialogAttribs) { - final ArchAttribType dType = attr.ref.getDataType(); - - switch (dType) { - case BOOL: { - // a boolean attribute (flag) - if (((DialogAttrib<JCheckBox>) attr).input.isSelected() != (archetype.getAttributeInt(attr.ref.getNameOld()) == 1)) { - newArchText = newArchText + attr.ref.getNameOld() + " " + (((DialogAttrib<JCheckBox>) attr).input.isSelected() ? 1 : 0) + "\n"; - } - } - break; - case BOOL_SPEC: { - // a boolean attribute with customized true/false values - final String valString; // value-string to apply - if (((DialogAttrib<JCheckBox>) attr).input.isSelected()) { - valString = attr.ref.getMisc()[0]; // true string - } else { - valString = attr.ref.getMisc()[1]; // false string - } - // now see if we need to write it into the archtext or not - if ((valString.equals("0") && !(archetype.getAttributeString(attr.ref.getNameOld()).length() == 0)) || (!valString.equals("0") && !archetype.getAttributeString(attr.ref.getNameOld()).equals(valString))) { - newArchText = newArchText + attr.ref.getNameOld() + " " + valString + "\n"; - } - } - break; - case INT: - case LONG: - case FLOAT: { - // an int attribute - if (dType == ArchAttribType.INT && ((DialogAttrib<JFormattedTextField>) attr).input.getText().trim().length() == 0) { - if (archetype.getAttributeInt(attr.ref.getNameOld()) != 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } - } else if (dType == ArchAttribType.LONG && ((DialogAttrib<JFormattedTextField>) attr).input.getText().trim().length() == 0) { - if (archetype.getAttributeLong(attr.ref.getNameOld()) != 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } - } else if (dType == ArchAttribType.FLOAT && ((DialogAttrib<JFormattedTextField>) attr).input.getText().trim().length() == 0) { - if (archetype.getAttributeString(attr.ref.getNameOld()).length() > 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0.0\n"; - } - } else { - try { - switch (dType) { - case INT: { - final int value = ((Number) ((DialogAttrib<JFormattedTextField>) attr).input.getValue()).intValue(); - if (archetype.getAttributeInt(attr.ref.getNameOld()) != value) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - case LONG: { - final long value = ((Number) ((DialogAttrib<JFormattedTextField>) attr).input.getValue()).longValue(); - if (archetype.getAttributeLong(attr.ref.getNameOld()) != value) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - case FLOAT: { - final double value = ((Number) ((DialogAttrib<JFormattedTextField>) attr).input.getValue()).doubleValue(); - final String defValueStr = archetype.getAttributeString(attr.ref.getNameOld()).trim(); - final double defValue; - if (defValueStr.length() > 0) { - defValue = Double.parseDouble(defValueStr); - } else { - defValue = 0; - } - // The following floating point equality comparison is okay and known not to cause problems. - //noinspection FloatingPointEquality - if (value != defValue) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - default: - assert false; - break; - } - } catch (final NumberFormatException e) { - // parsing failed: wrong entry!! - showMessageDialog(this, "Attribute '" + attr.ref.getNameNew() + "' must be a number!", "Input Error", ERROR_MESSAGE); - return false; - } - } - } - break; - case STRING: - case FACENAME: - case ANIMNAME: { - // a String attribute - final String inline = ((DialogAttrib<JTextField>) attr).input.getText().trim(); - - if (inline != null) { - if (attr.ref.getNameOld().equalsIgnoreCase("name")) { - // special case #1: "name"-textfield - if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { - if (!inline.equals(archetype.getObjName())) { - newName = inline; - } else { - newName = ""; - } - } else if (!inline.equals(archetype.getArchetypeName())) { - newName = inline; - } else { - newName = ""; - } - } else if (attr.ref.getNameOld().equalsIgnoreCase("face")) { - // special case #2: "face"-textfield - if (archetype.getFaceName() != null && archetype.getFaceName().length() > 0 && !inline.equals(archetype.getFaceName())) { - newFace = inline; - } else { - newFace = ""; - } - } else { - if (!inline.equals(archetype.getAttributeString(attr.ref.getNameOld()))) { - newArchText = newArchText + attr.ref.getNameOld() + " " + inline + "\n"; - } - } - } - } - break; - case TEXT: { - // a String attribute - if (attr.ref.getNameOld().equalsIgnoreCase("msg") && ((DialogAttrib<JTextArea>) attr).input.getText().trim().length() > 0) { - newMsg = ((DialogAttrib<JTextArea>) attr).input.getText().trim(); - } - } - break; - case SPELL: - case ZSPELL: - case LIST: { - // get attribute value that should go into the gameObject - final int attrVal; // attribute value - switch (dType) { - case SPELL: - case ZSPELL: - attrVal = CFArchTypeList.getSpells().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; - break; - case LIST: - // get selected index of ComboBox - final int attrValTmp = ((JComboBox) attr.input).getSelectedIndex(); - // fetch value according to this list entry: - attrVal = (Integer) (archTypeList.getListTable().get(attr.ref.getMisc()[0])).get(2 * attrValTmp); - break; - default: - assert false; - attrVal = 0; - break; - } - - if (attrVal == -1 || (attrVal == 0 && dType != ArchAttribType.SPELL && dType != ArchAttribType.ZSPELL)) { - if (archetype.getAttributeInt(attr.ref.getNameOld()) != 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } - } else if (attrVal == 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } else if (archetype.getAttributeInt(attr.ref.getNameOld()) != attrVal) { - newArchText = newArchText + attr.ref.getNameOld() + " " + attrVal + "\n"; - } - } - break; - case DBLLIST: { - final int val1 = (Integer) archTypeList.getListTable().get(attr.ref.getMisc()[0]).get(2 * ((JComboBox[]) attr.input)[0].getSelectedIndex()); - final int val2 = (Integer) archTypeList.getListTable().get(attr.ref.getMisc()[1]).get(2 * ((JComboBox[]) attr.input)[1].getSelectedIndex()); - final int combinedVal = val1 + val2; - - if (archetype.getAttributeInt(attr.ref.getNameOld()) != combinedVal) { - newArchText = newArchText + attr.ref.getNameOld() + " " + combinedVal + "\n"; - } - } - break; - case BITMASK: { - // a bitmask attribute (similar to integer, but easier because no parsing needed) - final int value = ((BitmaskAttrib) attr).getValue(); // get bitmask value - - if (archetype.getAttributeInt(attr.ref.getNameOld()) != value) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - case TREASURE: { - // a treasurelist attribute - final String inline = ((JTextComponent) attr.input).getText().trim(); // input string - - if (inline != null) { - final boolean isNone = inline.equals(CFTreasureListTree.NONE_SYM) || inline.length() == 0; - - if (!isNone && !CFTreasureListTree.containsTreasureList(inline) && !inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld()))) { - // The user has specified a WRONG treasurelist name, and it does not come - // from the default gameObject. -> Error and out. - showMessageDialog(this, "In attribute '" + attr.ref.getNameNew() + "':\n" + "'" + inline + "' is not a known treasurelist name!", "Input Error", ERROR_MESSAGE); - return false; - } - - if (!inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld())) && !(isNone && archetype.getAttributeString(attr.ref.getNameOld()).length() == 0)) { - if (isNone) { - newArchText = newArchText + attr.ref.getNameOld() + " none\n"; - } else { - newArchText = newArchText + attr.ref.getNameOld() + " " + inline + "\n"; - } - } - } - } - break; - } - } - - // Also write all the 'fixed' attributes into the archtext - for (int i = 0; type.getAttr().length > i; i++) { - if (type.getAttr()[i].getDataType() == ArchAttribType.FIXED) { - final String defaultValue = archetype.getAttributeString(type.getAttr()[i].getNameOld()); - if (defaultValue.length() == 0 || (gameObject.getArchTypNr() != archetype.getArchTypNr() && !defaultValue.equalsIgnoreCase(type.getAttr()[i].getNameNew()))) { - // usually, fixed attributes are only applied when *not* defined in the archetype. - // the reason behind this is: if the default gameObject violates our fixed attribute, - // we assume the default gameObject is "right" and we are "wrong". The typedefs aren't that trustworthy. - // BUT - if the gameObject has a changed type, the archetype has lost it's credibility. - // So, in this special case, the fixed attribute applies always. - newArchText = newArchText + type.getAttr()[i].getNameOld() + " " + type.getAttr()[i].getNameNew() + "\n"; - } - } - } - - // before we modify the archtext, we look for errors and save them. - // later the user must confirm whether to keep or dump those errors - final String errors = gameObject.getSyntaxErrors(typeStruct); - - // --- parsing succeeded, now we write it into the gameObject/map --- - gameObject.setObjectText(newArchText); - //gameObject.setArchTypNr(); - if (newName != null) { - if (newName.length() == 0) { - gameObject.setObjName(null); - } else { - gameObject.setObjName(newName); - } - } - - if (newFace != null) { - boolean faceChanged = false; // check if face changed - ... [truncated message content] |
From: <chr...@us...> - 2006-12-27 00:07:51
|
Revision: 1299 http://svn.sourceforge.net/gridarta/?rev=1299&view=rev Author: christianhujer Date: 2006-12-26 16:07:52 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Moved GameObjectAttributesDialog to gui package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribBitmask.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CAttribBitmask.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/GameObjectAttributesDialog.java Modified: trunk/crossfire/src/cfeditor/CAttribBitmask.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribBitmask.java 2006-12-27 00:00:10 UTC (rev 1298) +++ trunk/crossfire/src/cfeditor/CAttribBitmask.java 2006-12-27 00:07:52 UTC (rev 1299) @@ -24,6 +24,7 @@ package cfeditor; +import cfeditor.gui.GameObjectAttributesDialog; import java.awt.Component; import java.awt.GridLayout; import javax.swing.JCheckBox; Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-27 00:00:10 UTC (rev 1298) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-27 00:07:52 UTC (rev 1299) @@ -26,6 +26,7 @@ import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; +import cfeditor.gui.GameObjectAttributesDialog; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-27 00:00:10 UTC (rev 1298) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-27 00:07:52 UTC (rev 1299) @@ -30,6 +30,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.face.FaceObjects; +import cfeditor.gui.GameObjectAttributesDialog; import cfeditor.gui.PickmapChooser; import cfeditor.gui.map.MapCursorControl; import cfeditor.gui.map.MapPropertiesDialog; Deleted: trunk/crossfire/src/cfeditor/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/GameObjectAttributesDialog.java 2006-12-27 00:00:10 UTC (rev 1298) +++ trunk/crossfire/src/cfeditor/GameObjectAttributesDialog.java 2006-12-27 00:07:52 UTC (rev 1299) @@ -1,1775 +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.ArchetypeSet; -import cfeditor.gameobject.GameObject; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.ComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFormattedTextField; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JTextPane; -import javax.swing.JViewport; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.WindowConstants; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultFormatterFactory; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.NumberFormatter; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import net.sf.gridarta.gameobject.ArchAttribType; -import net.sf.gridarta.gameobject.Archetype; -import net.sf.gridarta.gameobject.NamedObject; -import net.sf.gridarta.gameobject.NamedObjects; -import net.sf.gridarta.help.Help; -import net.sf.gridarta.map.MapModel; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * GameObjectAttributesDialog poses the GUI for Crossfire object attributes. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @fixme I suck - */ -public final class GameObjectAttributesDialog extends JOptionPane implements FocusListener { - - private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - // store width of input-textfields, then JChooseBoxes are set to this width too - public static final int TEXTFIELD_COLUMNS = 18; // number of columns for textfields - - private final CMainControl mainControl; // reference to the main control - - private final CFArchTypeList archTypeList; // reference to the list of CF type-data - - private List<DialogAttrib<?>> dialogAttribs = new ArrayList<DialogAttrib<?>>(); - - private JComboBox typesel; // selection box for type - - private JLabel imagePanel; // panel for object's face (png) - - /** The game object being modified. */ - @NotNull private final GameObject gameObject; - - private final Archetype<GameObject> archetype; - - private CFArchType type; // reference to the type data - - // this differs from the GameObject if the type is undefined - private int listNr; // the position of this type in the type list - - /** The CardLayout for toggling between edit and summary. */ - private final CardLayout cardLayout = new CardLayout(); - - /** The Action for switching to the summary. */ - private Action summaryAction = ACTION_FACTORY.createAction(false, "attribSummary", this); - - /** The Action for switching to the edit. */ - private Action editAction = ACTION_FACTORY.createAction(false, "attribEdit", this); - - /** The Button for toggling the summary. */ - private JButton summaryEditButton; - - /** The Button for cancel. */ - private JButton cancelButton; - - /** The Button for ok. */ - private JButton okButton; - - /** Central tabbed pane (the place where all the attribute tabs are). */ - private JTabbedPane tabbedPane; - - /** Central pane, this is the parent component of above tabbed pane. */ - private final JPanel centerPane; - - /** Text pane where the summary is displayed. */ - private final JTextPane summaryTP; - - /** The gameObject objects that already are shown, to avoid opening a dialog twice. */ - private static final Map<GameObject, JDialog> dialogs = new HashMap<GameObject, JDialog>(); - - /** - * Wrapper method for the constructor. - * This method only creates a GameObjectAttributesDialog if there's no dialog for the same gameObject already. - * @param archTypeList the list of CF type-data - * @param gameObject the GameObject to be displayed by this dialog - * @param mainControl main control - */ - public static void showAttribDialog(final CFArchTypeList archTypeList, final GameObject gameObject, final CMainControl mainControl) { - synchronized (dialogs) { - if (dialogs.containsKey(gameObject)) { - dialogs.get(gameObject).toFront(); - } else { - final GameObjectAttributesDialog pane = new GameObjectAttributesDialog(archTypeList, gameObject, mainControl); - final JDialog dialog = pane.createDialog(mainControl.getMainView(), ACTION_FACTORY.getString("attribTitle")); - dialog.getRootPane().setDefaultButton(pane.okButton); - dialog.setResizable(true); - dialog.setModal(false); - dialog.setVisible(true); - dialogs.put(pane.gameObject, dialog); - } - } - } - - /** - * Constructor, creates the GUI layout. - * @param archTypeList the list of CF type-data - * @param gameObject the GameObject to be displayed by this dialog - * @param mainControl main control - */ - private GameObjectAttributesDialog(final CFArchTypeList archTypeList, @NotNull final GameObject gameObject, final CMainControl mainControl) { - listNr = 0; - - this.mainControl = mainControl; // reference to the main control - this.archTypeList = archTypeList; // reference to the typelist - - // reference to the GameObject - this.gameObject = gameObject.getHead(); - archetype = this.gameObject.getArchetype(); - - type = archTypeList.getType(gameObject); - listNr = archTypeList.getArchTypeIndex(type); - - // first split top-left and -right - final JComponent leftPane = buildHeader(); - final JScrollPane rightPane = buildInv(); - - //Create a split pane with the two scroll panes in it. - final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane); - - // Now split horizontally - //JScrollPane centerPane = buildAttr(); - centerPane = new JPanel(cardLayout); - centerPane.add("edit", buildAttr()); - summaryTP = new JTextPane(); - summaryTP.setEditable(false); - summaryTP.setBorder(BorderFactory.createEmptyBorder(3, 15, 0, 0)); - centerPane.add("summary", new JScrollPane(summaryTP)); - final Dimension size = centerPane.getPreferredSize(); - size.height = 256; - centerPane.setMinimumSize(size); - centerPane.setPreferredSize(size); - - final JPanel contentPanel = new JPanel(new GridBagLayout()); - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.weightx = 1.0; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridwidth = GridBagConstraints.REMAINDER; - gbc.weighty = 0.0; - contentPanel.add(splitPane, gbc); - gbc.weighty = 1.0; - contentPanel.add(centerPane, gbc); - - setOptions(buildOptions()); - - setMessage(contentPanel); - } - - /** {@inheritDoc} */ - @Override public void setValue(final Object newValue) { - super.setValue(newValue); - if (newValue != UNINITIALIZED_VALUE) { - dialogs.remove(gameObject).dispose(); - } - } - - /** - * Construct the Combo box of the available archetypes. - * @return a <code>JComponent</code> with the combo box in it - */ - private JComponent buildTypesBox() { - final String[] namelist = new String[archTypeList.getLength()]; // list of typenames - - // read all type names - int i = 0; - for (final CFArchType tmp : archTypeList) { - namelist[i++] = " " + tmp.getTypeName(); - } - - // the active type appears selected in the box - final int selection = listNr; // position of selected type in the list - - typesel = new JComboBox(namelist); // set "content" - typesel.setSelectedIndex(selection); // set active selection - - //typesel.setKeySelectionManager(new StringKeyManager(typesel)); - - typesel.setName("Types"); - - // the listener: - typesel.addItemListener(new TypesBoxAL(this, gameObject)); - return typesel; - } - - /** - * Construct the Combo box of the available spells. - * @param attr spell attribute - * @return the completed <code>JComboBox</code> - */ - private JComboBox buildSpellBox(final CFArchAttrib attr) { - - // first parse the spell-number value from gameObject - int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - - if (spnum < 0 || spnum >= CFArchTypeList.getSpells().getSpellNumbers().length - 1) { - spnum = 0; // undefined spellnumbers be zero - } - - // do we have "none" spell? - int active; - if (spnum == 0 && (gameObject.getAttributeString(attr.getNameOld()).length() == 0 || attr.getDataType() == ArchAttribType.ZSPELL)) { - active = 0; - } else { - // now look up the spell-number in the array of spells - active = 0; - for (int i = 0; i < CFArchTypeList.getSpells().getSpellNumbers().length; i++) { - if (CFArchTypeList.getSpells().getSpellNumbers()[i] == spnum) { - active = i; // set selection - i = CFArchTypeList.getSpells().getSpellNumbers().length + 10; // end loop - } - } - } - - final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpells().getSpellNames()); // set "content" - spellsel.setSelectedIndex(active); // set active selection - spellsel.setMaximumRowCount(10); - spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); - - spellsel.setName(attr.getNameNew()); - - return spellsel; - } - - /** - * Construct the Combo box for arrays of "list data" (this is used for ArchAttribType.LIST). - * @param attr list attribute - * @param listData List with list items and corresponding values, that means the types are altering: String,Integer - * @return the completed <code>JComboBox</code> - */ - private JComboBox buildArrayBox(final CFArchAttrib attr, final List<?> listData) { - // build the array of list-items - final String[] array = new String[(int) (listData.size() / 2.0)]; - boolean hasSelection = false; - int active = gameObject.getAttributeInt(attr.getNameOld()); - - for (int i = 0; i < array.length; i++) { - array[i] = (String) listData.get(i * 2 + 1); // put string to array - if (!hasSelection && (Integer) listData.get(i * 2) == active) { - hasSelection = true; // the selection is valid - active = i; // set selection to this index in the array - } - } - // if there is no valid pre-selection, show first element of list - if (!hasSelection) { - active = 0; - } - - final JComboBox arraysel = new JComboBox(array); // set "content" - arraysel.setSelectedIndex(active); // set active selection - arraysel.setMaximumRowCount(10); - arraysel.setKeySelectionManager(new StringKeyManager(arraysel)); - - arraysel.setName(attr.getNameNew()); - - return arraysel; - } - - /** - * Construct the upper left part of the attribute dialog, - * containing name, type, archetype name and face. - * @return a <code>JScrollPane</code> with the upper left part of the dialog window - */ - private JComponent buildHeader() { - final JPanel header = new JPanel(new GridBagLayout()); // the final thing, in a panel - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.BOTH; - gbc.insets = new Insets(2, 2, 2, 2); - gbc.gridx = 1; - gbc.gridy = 1; - gbc.weightx = 0.0; - gbc.weighty = 3.0; - gbc.gridheight = 3; - imagePanel = new JLabel(mainControl.getArchetypeSet().getFace(gameObject.getFaceNr())); - imagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); - header.add(imagePanel, gbc); - gbc.gridheight = 1; - gbc.weighty = 1.0; - gbc.fill = GridBagConstraints.HORIZONTAL; - - gbc.weightx = 0.0; - gbc.gridx = 2; - gbc.gridy = 1; - header.add(new JLabel("Name: ", SwingConstants.TRAILING), gbc); // create label - gbc.gridy++; - header.add(new JLabel("Type: ", SwingConstants.TRAILING), gbc); - gbc.gridy++; - header.add(new JLabel("Archetype: ", SwingConstants.TRAILING), gbc); // create label - - gbc.gridx = 3; - gbc.gridy = 1; - gbc.weightx = 1.0; - final JTextField nameTF;if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { - nameTF = new JTextField(gameObject.getObjName(), 16); - } else if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { - nameTF = new JTextField(archetype.getObjName(), 16); - } else { - nameTF = new JTextField(archetype.getArchetypeName(), 16); - } - nameTF.setEditable(false); - header.add(nameTF, gbc); - gbc.gridy++; - header.add(buildTypesBox(), gbc); // build type-selection box - gbc.gridy++; - final JTextField archetypeTF=new JTextField(archetype.getArchetypeName(), 16); - archetypeTF.setEditable(false); - header.add(archetypeTF, gbc); - - return header; - } - - /** - * Construct the upper right part of the attribute dialog, - * containing the object's inventory. - * @return a <code>JScrollPane</code> with the upper right part of the dialog window - */ - private static JScrollPane buildInv() { - final JPanel inv = new JPanel(); // the final thing, in a panel - inv.add(new JLabel("Inventory:")); // create label - - final JScrollPane scrollPane = new JScrollPane(inv); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - scrollPane.setSize(80, 70); - - return scrollPane; - } - - /** - * Construct the central part of the attribute dialog, containing the - * object's gameObject attributes. - * @return When this method is called the first time: a <code>JScrollPane</code> - * with the central part of the dialog window. - * All further calls rebuild the existing tabbedpane and return null. - */ - @Nullable private JComponent buildAttr() { - boolean initialCall = false; - - if (tabbedPane == null) { - tabbedPane = new JTabbedPane(); - initialCall = true; - } - - for (int i = 0; i < type.getSectionNum(); i++) { - final Component panel1 = makeAttribPanel(i); - if (panel1 != null) { - tabbedPane.addTab(getSectionName(i), null, panel1); - } - } - - // set selected tab - tabbedPane.setSelectedIndex(0); - - if (initialCall) { - return tabbedPane; - } else { - return null; - } - } - - /** - * This method creates an attribute panel for one section of attributes. If - * the section is empty, null is returned. - * @param secId the identifier of the section - * @return a <code>Component</code> containing the attribute panel - * (currently always a JScrollPane) - * @todo I'm still 263 lines long, please make me shorter. - */ - @Nullable private Component makeAttribPanel(final int secId) { - int number = 0; // number of attributes in this section - boolean hasBitmask = false; // true if this section contains a bitmask attribute - - // first we check how many attribs this section has - for (int i = 0; type.getAttr().length > i; i++) { - if (type.getAttr()[i].getSecId() == secId) { - // count number of attributes - if (type.getAttr()[i].getDataType() != ArchAttribType.FIXED) { - number++; - } - // check for bitmask attributes - if (!hasBitmask && type.getAttr()[i].getDataType() == ArchAttribType.BITMASK) { - hasBitmask = true; - } - } - } - if (number == 0) { - return null; - } - - // All attribute-"lines" go into this panel: - final JPanel panel = new JPanel(new GridBagLayout()); - final Insets gbcInsets = new Insets(2, 2, 2, 2); - - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = gbcInsets; - final Object helpGbc = gbc.clone(); - gbc.fill = GridBagConstraints.HORIZONTAL; - final Object labelGbc = gbc.clone(); - gbc.weightx = 1.0; - gbc.gridwidth = GridBagConstraints.REMAINDER; - final Object compGbc = gbc.clone(); - gbc.anchor = GridBagConstraints.WEST; - final Object rowGbc = gbc.clone(); - gbc.fill = GridBagConstraints.BOTH; - gbc.weighty = 1.0; - boolean isText = false; - final Object glueGbc = gbc.clone(); - - final CFArchAttrib[] attribs = type.getAttr(); - // now add the entrys, line by line - for (int i = 0; attribs.length > i; i++) { - final CFArchAttrib attrib = attribs[i]; - final ArchAttribType dType = attrib.getDataType(); // data type of the attribute - if (attrib.getSecId() == secId && dType != ArchAttribType.FIXED) { - final String nameOld = attrib.getNameOld(); - final JButton helpButton = new JButton("?"); - helpButton.setMargin(new Insets(0, 5, 0, 5)); - panel.add(helpButton, helpGbc); - helpButton.addFocusListener(this); - - JComponent cLabel = null; - JComponent cComp = null; - JComponent cRow = null; - JComponent cGlue = null; - - // now create the attribute-GUI-instance - final DialogAttrib<?> newAttr; - - switch (dType) { - case TEXT: { - isText = true; // text section (need special embedding without additional scrollbars) - newAttr = new DialogAttrib<JTextArea>(attrib); - String text = ""; - if (nameOld.equalsIgnoreCase("msg")) { - if (archetype.getMsgText() != null && archetype.getMsgText().length() > 0 && (gameObject.getMsgText() == null || gameObject.getMsgText().trim().length() == 0)) { - text = archetype.getMsgText(); - } else { - text = gameObject.getMsgText(); - } - } - final JTextArea input = new JTextArea(text, 10, 20); - input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); - final JScrollPane scrollPane = new JScrollPane(input); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - ((DialogAttrib<JTextArea>) newAttr).input = input; - cGlue = scrollPane; - } - break; - case BOOL: - case BOOL_SPEC: { - newAttr = new DialogAttrib<JCheckBox>(attrib); - final JCheckBox input; - switch (dType) { - case BOOL: - // normal bool - input = new JCheckBox(attrib.getNameNew(), gameObject.getAttributeInt(nameOld) == 1); - break; - case BOOL_SPEC: { - // parse values for customized bool - final String trueVal = attrib.getMisc()[0]; - if (trueVal.equals("0")) { - final String attrString = gameObject.getAttributeString(nameOld); - input = new JCheckBox(attrib.getNameNew(), attrString.length() == 0 || attrString.equals("0")); - } else { - input = new JCheckBox(attrib.getNameNew(), gameObject.getAttributeString(nameOld).equals(trueVal)); - } - } - break; - default: - assert false; - input = null; - break; - } - ((DialogAttrib<JCheckBox>) newAttr).input = input; - cRow = input; - } - break; - case INT: - case LONG: - case FLOAT: { - cLabel = new JLabel(attrib.getNameNew() + ": "); - cLabel.setForeground(dType == ArchAttribType.FLOAT ? IGUIConstants.FLOAT_COLOR : IGUIConstants.INT_COLOR); - newAttr = new DialogAttrib<JFormattedTextField>(attrib); - final int fieldLength = attrib.getInputLength() == 0 ? TEXTFIELD_COLUMNS : attrib.getInputLength(); - final NumberFormat format; - switch (dType) { - case INT: - case LONG: - format = NumberFormat.getIntegerInstance(); - break; - case FLOAT: - format = NumberFormat.getInstance(); - format.setMaximumFractionDigits(10); - break; - default: - assert false; - format = null; - break; - } - format.setGroupingUsed(false); - final NumberFormatter formatter = new NumberFormatter(format); - final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); - // parse value from gameObject - final Number value; - switch (dType) { - case INT: - value = gameObject.getAttributeInt(nameOld); - break; - case LONG: - value = gameObject.getAttributeLong(nameOld); - break; - case FLOAT: - value = gameObject.getAttributeDouble(nameOld); - break; - default: - value = null; - assert false; - break; - } - final JFormattedTextField input = new JFormattedTextField(factory, value); - input.setColumns(fieldLength); - cComp = input; - ((DialogAttrib<JFormattedTextField>) newAttr).input = input; - } - break; - case STRING: - case FACENAME: - case ANIMNAME: { - final String dtxt; - if (nameOld.equalsIgnoreCase("name")) { - if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { - dtxt = gameObject.getObjName(); - } else if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { - dtxt = archetype.getObjName(); - } else { - dtxt = archetype.getArchetypeName(); - } - } else if (nameOld.equalsIgnoreCase("face")) { - if (gameObject.getFaceName() != null && gameObject.getFaceName().length() > 0) { - dtxt = gameObject.getFaceName(); - } else { - dtxt = archetype.getFaceName(); - } - } else { - dtxt = gameObject.getAttributeString(nameOld); - } - final JTextField input = new JTextField(dtxt, TEXTFIELD_COLUMNS); - switch (dType) { - case STRING: - cLabel = new JLabel(attrib.getNameNew() + ": "); - newAttr = new DialogAttrib<JTextField>(attrib); - break; - case FACENAME: - case ANIMNAME: - newAttr = new DialogAttrib<JTextField>(attrib); - switch (dType) { - case FACENAME: - cLabel = new JButton(new TreeChooseAction(attrib.getNameNew() + ": ", input, mainControl.getFaceObjects())); - break; - case ANIMNAME: - cLabel = new JButton(new TreeChooseAction(attrib.getNameNew() + ": ", input, mainControl.getAnimationObjects())); - break; - default: - assert false; - cLabel = null; - break; - } - break; - default: - assert false; - newAttr = null; - break; - } - cComp = input; - ((DialogAttrib<JTextField>) newAttr).input = input; - } - break; - case SPELL: - case ZSPELL: - case LIST: { - cLabel = new JLabel(attrib.getNameNew() + ": "); - cLabel.setForeground(IGUIConstants.INT_COLOR); - newAttr = new DialogAttrib<JComboBox>(attrib); - // create ComboBox with parsed selection - final JComboBox input; - switch (dType) { - case SPELL: - case ZSPELL: - input = buildSpellBox(attrib); - break; - case LIST: - if (attrib.getMisc() != null && archTypeList.getListTable().containsKey(attrib.getMisc()[0])) { - // build the list from vector data - input = buildArrayBox(attrib, archTypeList.getListTable().get(attrib.getMisc()[0])); - } else { - // error: list data is missing or corrupt - cComp = new JLabel("Error: Undefined List"); - input = null; - } - break; - default: - assert false; - input = null; - break; - } - if (input != null) { - cComp = input; - } - ((DialogAttrib<JComboBox>) newAttr).input = input; - } - break; - case DBLLIST: { - final JPanel compo = new JPanel(new BorderLayout()); - cLabel = new JLabel(attrib.getNameNew() + ": "); - cLabel.setForeground(IGUIConstants.INT_COLOR); - newAttr = new DialogAttrib<JComboBox[]>(attrib); - // create ComboBox with parsed selection - final JComboBox[] inputs = new JComboBox[2]; - if (attrib.getMisc() != null && archTypeList.getListTable().containsKey(attrib.getMisc()[0]) && archTypeList.getListTable().containsKey(attrib.getMisc()[1])) { - // Hack to set preselected if available - final int active = gameObject.getAttributeInt(nameOld); - final int[] activepart = {active & 0x0F, active & 0xF0}; - // build the lists from vector data - for (int j = 0; j < 2; j++) { - final List<?> listData = archTypeList.getListTable().get(attrib.getMisc()[j]); - inputs[j] = buildArrayBox(attrib, listData); - for (int k = 0; (double) k < listData.size() / 2.0; k++) { - if ((Integer) listData.get(k << 1) == activepart[j]) { - inputs[j].setSelectedIndex(k); // set active selection - break; - } - } - } - compo.add(inputs[0], BorderLayout.NORTH); - compo.add(inputs[1], BorderLayout.SOUTH); - cComp = compo; - } else { - // error: list data is missing or corrupt - cComp = new JLabel("Error: Undefined List"); - } - ((DialogAttrib<JComboBox[]>) newAttr).input = inputs; - } - break; - case BITMASK: { - newAttr = new BitmaskAttrib(attrib); - if (attrib.getMisc() != null && archTypeList.getBitmaskTable().containsKey(attrib.getMisc()[0])) { - // fetch the bitmask data, then build the attribute panel - final CAttribBitmask bitmask = archTypeList.getBitmaskTable().get(attrib.getMisc()[0]); - ((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).bitmask = bitmask; - cLabel = new JButton(new MaskChangeAL(attrib.getNameNew() + ":", (BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr)); - final JTextArea input = new JTextArea(); - input.setBackground(getBackground()); - input.setEditable(false); - input.setBorder(BorderFactory.createLineBorder(Color.gray)); - input.setText(bitmask.getText(((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).getValue())); - cComp = input; - ((DialogAttrib<JTextComponent>) newAttr).input = input; - ((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).setValue(gameObject.getAttributeInt(nameOld)); - } else { - cRow = new JLabel("Error: Undefined Bitmask"); - } - } - break; - case TREASURE: { - newAttr = new DialogAttrib<JTextField>(attrib); - // textfield (no direct input, text is set by the treasurelist dialog) - String treasureName = gameObject.getAttributeString(nameOld); - if (treasureName.trim().length() == 0 || treasureName.trim().equalsIgnoreCase("none")) { - treasureName = CFTreasureListTree.NONE_SYM; - } - final JTextField input = new JTextField(" " + treasureName, TEXTFIELD_COLUMNS); - input.setEditable(false); - cLabel = new JButton(new ViewTreasurelistAL((DialogAttrib<JTextField>) newAttr, this)); - cComp = input; - ((DialogAttrib<JTextField>) newAttr).input = input; - } - break; - default: - newAttr = null; - assert false; - break; - } // switch (dType) - - assert newAttr != null; - dialogAttribs.add(newAttr); - helpButton.addActionListener(new HelpActionListener(newAttr.ref)); - if (cLabel != null) { - panel.add(cLabel, labelGbc); - cLabel.addFocusListener(this); - } - if (cComp != null) { - panel.add(cComp, compGbc); - cComp.addFocusListener(this); - } - if (cRow != null) { - panel.add(cRow, rowGbc); - cRow.addFocusListener(this); - } - if (cGlue != null) { - panel.add(cGlue, glueGbc); - cGlue.addFocusListener(this); - } - } - } - - if (!isText) { - // if the component does not already have glue, put glue inside to align its contents to the top. - panel.add(Box.createGlue(), glueGbc); - } - final JScrollPane panelReturn = new JScrollPane(panel); - panelReturn.getVerticalScrollBar().setUnitIncrement(8); - return panelReturn; - } - - /** - * Looks up the section name from the ID. - * @param secId ID of the section - * @return name of that section - */ - private String getSectionName(final int secId) { - for (int i = 0; type.getAttr().length > i; i++) { - if (type.getAttr()[i].getSecId() == secId) { - // we've got the string, now capitalize the first letter - String s = type.getAttr()[i].getSecName(); - if (s.length() > 1) { - s = s.substring(0, 1).toUpperCase() + s.substring(1); - } - return s; - } - } - - return "???"; - } - - /** - * Construct the dialog options: help, default, okay, apply, cancel. - * @return Object[] with dialog options - */ - private Object[] buildOptions() { - return new Object[] { - new JButton(ACTION_FACTORY.createAction(false, "attribHelp", this)), - summaryEditButton = new JButton(summaryAction), - Box.createHorizontalStrut(32), - okButton = new JButton(ACTION_FACTORY.createAction(false, "attribOk", this)), - new JButton(ACTION_FACTORY.createAction(false, "attribApply", this)), - cancelButton = new JButton(ACTION_FACTORY.createAction(false, "attribCancel", this)), - }; - } - - /** - * Action method for help. - */ - public void attribHelp() { - new Help(mainControl.getMainView(), type.createHtmlDocu()).setVisible(true); - } - - /** - * Action method for ok. - */ - public void attribOk() { - if (applySettings()) { - setValue(okButton); - } - } - - /** - * Action method for apply. - */ - public void attribApply() { - applySettings(); - } - - /** - * Action method for cancel. - */ - public void attribCancel() { - setValue(cancelButton); - } - - /** - * Spawns a popup-message to display the help text of an attribute. - * @param title name of attribute - * @param msg message text - */ - private void popupHelp(final String title, final String msg) { - showMessageDialog(this, msg, "Help: " + title, PLAIN_MESSAGE); - } - - /** - * Action method for summary. Switches the cardlayout to the summary list - * of all nonzero attributes. - */ - public void attribSummary() { - // interface is displayed, switch to summary - final Document doc = summaryTP.getDocument(); - - try { - // clear document - if (doc.getLength() > 0) { - doc.remove(0, doc.getLength()); - } - - final Style docStyle = summaryTP.getStyle(StyleContext.DEFAULT_STYLE); - StyleConstants.setForeground(docStyle, Color.black); - - // now loop through all attributes and write out nonzero ones - for (final DialogAttrib attr : dialogAttribs) { - switch (attr.ref.getDataType()) { - case BOOL: - case BOOL_SPEC: { - final boolean value = ((DialogAttrib<JCheckBox>) attr).input.isSelected(); // true/false - if (value) { - doc.insertString(doc.getLength(), "<" + attr.ref.getNameNew() + ">\n", docStyle); - } - } - break; - case INT: - case LONG: - case FLOAT: { - final String value = ((DialogAttrib<JFormattedTextField>) attr).input.getText(); // the attrib value - if (value != null && value.length() > 0 && !value.equals("0")) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case STRING: - case FACENAME: - case ANIMNAME: { - final String value = ((DialogAttrib<JTextField>) attr).input.getText(); // the attrib value - if (value != null && value.length() > 0) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case SPELL: - case ZSPELL: - case LIST: { - final String value = ((DialogAttrib<JComboBox>) attr).input.getSelectedItem().toString().trim(); // the attrib value - if (value != null && value.length() > 0 && !value.startsWith("<")) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case DBLLIST: { - final String value1 = ((DialogAttrib<JComboBox[]>) attr).input[0].getSelectedItem().toString().trim(); - final String value2 = ((DialogAttrib<JComboBox[]>) attr).input[1].getSelectedItem().toString().trim(); - String out = null; - if (value1 != null && value1.length() > 0 && !value1.startsWith("<")) { - out = value1; - } - if (value2 != null && value2.length() > 0 && !value2.startsWith("<")) { - if (out == null) { - out = value2; - } else { - out += " / " + value2; - } - } - if (out != null) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + out + "\n", docStyle); - } - } - break; - case BITMASK: { - final String value = ((BitmaskAttrib) attr).input.getText().trim(); - if (value != null && value.length() > 0 && !value.startsWith("<")) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case TREASURE: { - final String value = ((DialogAttrib<JTextField>) attr).input.getText().trim(); // the attrib value - if (value != null && value.length() > 0 && !value.equals(CFTreasureListTree.NONE_SYM)) { - doc.insertString(doc.getLength(), attr.ref.getNameNew() + " = " + value + "\n", docStyle); - } - } - break; - case TEXT: - /* Nothing to do. */ - break; - default: - assert false : "Unknown type: " + attr.ref.getDataType(); - break; - } - } - } catch (final BadLocationException e) { - log.error("toggleSummary: Bad Location in Document!", e); - } - - summaryTP.setCaretPosition(0); // this prevents the document from scrolling down - summaryEditButton.setAction(editAction); - cardLayout.show(centerPane, "summary"); - } - - /** - * Turns the summary off. - * Switches to the input-interface for all attributes and the summary list of all nonzero attributes. - */ - public void attribEdit() { - summaryEditButton.setAction(summaryAction); - cardLayout.show(centerPane, "edit"); - } - - /** - * This method is called when the "apply"-button has been - * pressed. All the settings from the dialog get - * written into the GameObject. - * @return true if the settings were applied, false if error occurred - */ - private boolean applySettings() { - final MapModel mapModel = mainControl.getCurrentMap().getMapModel(); - mapModel.beginTransaction("Change object attributes"); - try { - return applySettings2(); - } finally { - mapModel.endTransaction(); - } - } - - /** - * This method is called when the "apply"-button has been - * pressed. All the settings from the dialog get - * written into the GameObject. - * @return true if the settings were applied, false if error occurred - */ - private boolean applySettings2() { - final String oldArchText = gameObject.getObjectText(); // the old ArchText - final String oldMsg = gameObject.getMsgText(); // old gameObject msg - final CFArchType typeStruct = archTypeList.getTypeOfArch(gameObject); // the type structure for this gameObject - - String newArchText = ""; - String newName = null; - String newFace = null; - String newMsg = null; - for (final DialogAttrib attr : dialogAttribs) { - final ArchAttribType dType = attr.ref.getDataType(); - - switch (dType) { - case BOOL: { - // a boolean attribute (flag) - if (((DialogAttrib<JCheckBox>) attr).input.isSelected() != (archetype.getAttributeInt(attr.ref.getNameOld()) == 1)) { - newArchText = newArchText + attr.ref.getNameOld() + " " + (((DialogAttrib<JCheckBox>) attr).input.isSelected() ? 1 : 0) + "\n"; - } - } - break; - case BOOL_SPEC: { - // a boolean attribute with customized true/false values - final String valString; // value-string to apply - if (((DialogAttrib<JCheckBox>) attr).input.isSelected()) { - valString = attr.ref.getMisc()[0]; // true string - } else { - valString = attr.ref.getMisc()[1]; // false string - } - // now see if we need to write it into the archtext or not - if ((valString.equals("0") && !(archetype.getAttributeString(attr.ref.getNameOld()).length() == 0)) || (!valString.equals("0") && !archetype.getAttributeString(attr.ref.getNameOld()).equals(valString))) { - newArchText = newArchText + attr.ref.getNameOld() + " " + valString + "\n"; - } - } - break; - case INT: - case LONG: - case FLOAT: { - // an int attribute - if (dType == ArchAttribType.INT && ((DialogAttrib<JFormattedTextField>) attr).input.getText().trim().length() == 0) { - if (archetype.getAttributeInt(attr.ref.getNameOld()) != 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } - } else if (dType == ArchAttribType.LONG && ((DialogAttrib<JFormattedTextField>) attr).input.getText().trim().length() == 0) { - if (archetype.getAttributeLong(attr.ref.getNameOld()) != 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } - } else if (dType == ArchAttribType.FLOAT && ((DialogAttrib<JFormattedTextField>) attr).input.getText().trim().length() == 0) { - if (archetype.getAttributeString(attr.ref.getNameOld()).length() > 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0.0\n"; - } - } else { - try { - switch (dType) { - case INT: { - final int value = ((Number) ((DialogAttrib<JFormattedTextField>) attr).input.getValue()).intValue(); - if (archetype.getAttributeInt(attr.ref.getNameOld()) != value) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - case LONG: { - final long value = ((Number) ((DialogAttrib<JFormattedTextField>) attr).input.getValue()).longValue(); - if (archetype.getAttributeLong(attr.ref.getNameOld()) != value) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - case FLOAT: { - final double value = ((Number) ((DialogAttrib<JFormattedTextField>) attr).input.getValue()).doubleValue(); - final String defValueStr = archetype.getAttributeString(attr.ref.getNameOld()).trim(); - final double defValue; - if (defValueStr.length() > 0) { - defValue = Double.parseDouble(defValueStr); - } else { - defValue = 0; - } - // The following floating point equality comparison is okay and known not to cause problems. - //noinspection FloatingPointEquality - if (value != defValue) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - default: - assert false; - break; - } - } catch (final NumberFormatException e) { - // parsing failed: wrong entry!! - showMessageDialog(this, "Attribute '" + attr.ref.getNameNew() + "' must be a number!", "Input Error", ERROR_MESSAGE); - return false; - } - } - } - break; - case STRING: - case FACENAME: - case ANIMNAME: { - // a String attribute - final String inline = ((DialogAttrib<JTextField>) attr).input.getText().trim(); - - if (inline != null) { - if (attr.ref.getNameOld().equalsIgnoreCase("name")) { - // special case #1: "name"-textfield - if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { - if (!inline.equals(archetype.getObjName())) { - newName = inline; - } else { - newName = ""; - } - } else if (!inline.equals(archetype.getArchetypeName())) { - newName = inline; - } else { - newName = ""; - } - } else if (attr.ref.getNameOld().equalsIgnoreCase("face")) { - // special case #2: "face"-textfield - if (archetype.getFaceName() != null && archetype.getFaceName().length() > 0 && !inline.equals(archetype.getFaceName())) { - newFace = inline; - } else { - newFace = ""; - } - } else { - if (!inline.equals(archetype.getAttributeString(attr.ref.getNameOld()))) { - newArchText = newArchText + attr.ref.getNameOld() + " " + inline + "\n"; - } - } - } - } - break; - case TEXT: { - // a String attribute - if (attr.ref.getNameOld().equalsIgnoreCase("msg") && ((DialogAttrib<JTextArea>) attr).input.getText().trim().length() > 0) { - newMsg = ((DialogAttrib<JTextArea>) attr).input.getText().trim(); - } - } - break; - case SPELL: - case ZSPELL: - case LIST: { - // get attribute value that should go into the gameObject - final int attrVal; // attribute value - switch (dType) { - case SPELL: - case ZSPELL: - attrVal = CFArchTypeList.getSpells().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; - break; - case LIST: - // get selected index of ComboBox - final int attrValTmp = ((JComboBox) attr.input).getSelectedIndex(); - // fetch value according to this list entry: - attrVal = (Integer) (archTypeList.getListTable().get(attr.ref.getMisc()[0])).get(2 * attrValTmp); - break; - default: - assert false; - attrVal = 0; - break; - } - - if (attrVal == -1 || (attrVal == 0 && dType != ArchAttribType.SPELL && dType != ArchAttribType.ZSPELL)) { - if (archetype.getAttributeInt(attr.ref.getNameOld()) != 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } - } else if (attrVal == 0) { - newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } else if (archetype.getAttributeInt(attr.ref.getNameOld()) != attrVal) { - newArchText = newArchText + attr.ref.getNameOld() + " " + attrVal + "\n"; - } - } - break; - case DBLLIST: { - final int val1 = (Integer) archTypeList.getListTable().get(attr.ref.getMisc()[0]).get(2 * ((JComboBox[]) attr.input)[0].getSelectedIndex()); - final int val2 = (Integer) archTypeList.getListTable().get(attr.ref.getMisc()[1]).get(2 * ((JComboBox[]) attr.input)[1].getSelectedIndex()); - final int combinedVal = val1 + val2; - - if (archetype.getAttributeInt(attr.ref.getNameOld()) != combinedVal) { - newArchText = newArchText + attr.ref.getNameOld() + " " + combinedVal + "\n"; - } - } - break; - case BITMASK: { - // a bitmask attribute (similar to integer, but easier because no parsing needed) - final int value = ((BitmaskAttrib) attr).getValue(); // get bitmask value - - if (archetype.getAttributeInt(attr.ref.getNameOld()) != value) { - newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; - } - } - break; - case TREASURE: { - // a treasurelist attribute - final String inline = ((JTextComponent) attr.input).getText().trim(); // input string - - if (inline != null) { - final boolean isNone = inline.equals(CFTreasureListTree.NONE_SYM) || inline.length() == 0; - - if (!isNone && !CFTreasureListTree.containsTreasureList(inline) && !inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld()))) { - // The user has specified a WRONG treasurelist name, and it does not come - // from the default gameObject. -> Error and out. - showMessageDialog(this, "In attribute '" + attr.ref.getNameNew() + "':\n" + "'" + inline + "' is not a known treasurelist name!", "Input Error", ERROR_MESSAGE); - return false; - } - - if (!inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld())) && !(isNone && archetype.getAttributeString(attr.ref.getNameOld()).length() == 0)) { - if (isNone) { - newArchText = newArchText + attr.ref.getNameOld() + " none\n"; - } else { - newArchText = newArchText + attr.ref.getNameOld() + " " + inline + "\n"; - } - } - } - } - break; - } - } - - // Also write all the 'fixed' attributes into the archtext - for (int i = 0; type.getAttr().length > i; i++) { - if (type.getAttr()[i].getDataType() == ArchAttribType.FIXED) { - final String defaultValue = archetype.getAttributeString(type.getAttr()[i].getNameOld()); - if (defaultValue.length() == 0 || (gameObject.getArchTypNr() != archetype.getArchTypNr() && !defaultValue.equalsIgnoreCase(type.getAttr()[i].getNameNew()))) { - // usually, fixed attributes are only applied when *not* defined in the archetype. - // the reason behind this is: if the default gameObject violates our fixed attribute, - // we assume the default gameObject is "right" and we are "wrong". The typedefs aren't that trustworthy. - // BUT - if the gameObject has a changed type, the archetype has lost it's credibility. - // So, in this special case, the fixed attribute applies always. - newArchText = newArchText + type.getAttr()[i].getNameOld() + " " + type.getAttr()[i].getNameNew() + "\n"; - } - } - } - - // before we modify... [truncated message content] |
From: <chr...@us...> - 2006-12-27 00:16:06
|
Revision: 1300 http://svn.sourceforge.net/gridarta/?rev=1300&view=rev Author: christianhujer Date: 2006-12-26 16:16:06 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Renamed CNewMapDialog to gui.NewMapDialog. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/NewMapDialog.java trunk/daimonin/src/daieditor/gui/NewMapDialog.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CNewMapDialog.java trunk/daimonin/src/daieditor/CNewMapDialog.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-27 00:07:52 UTC (rev 1299) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-27 00:16:06 UTC (rev 1300) @@ -31,6 +31,7 @@ import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.face.FaceObjects; import cfeditor.gui.GameObjectAttributesDialog; +import cfeditor.gui.NewMapDialog; import cfeditor.gui.PickmapChooser; import cfeditor.gui.map.MapCursorControl; import cfeditor.gui.map.MapPropertiesDialog; @@ -695,12 +696,12 @@ * @param filename desired filename for the new map, null if not specified */ public void newLevelWanted(final String filename) { - CNewMapDialog.showNewMapDialog(this, mainView, filename, MapType.GAMEMAP); + NewMapDialog.showNewMapDialog(this, mainView, filename, MapType.GAMEMAP); } /** Invoked when user wants to open a new pickmap. */ public void addNewPickmap() { - CNewMapDialog.showNewMapDialog(this, mainView, null, MapType.PICKMAP); + NewMapDialog.showNewMapDialog(this, mainView, null, MapType.PICKMAP); } /** Deleted: trunk/crossfire/src/cfeditor/CNewMapDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-12-27 00:07:52 UTC (rev 1299) +++ trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-12-27 00:16:06 UTC (rev 1300) @@ -1,285 +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.ArchetypeSet; -import cfeditor.gui.PickmapChooser; -import cfeditor.map.MapArchObject; -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.Calendar; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFormattedTextField; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import net.sf.gridarta.Size2D; -import net.sf.gridarta.map.MapType; -import net.sf.japi.swing.ActionFactory; - -/** - * Dialog used to ask the user the properties for the new level. Contains a - * tabbed pane for creating a level either based on a template or from a - * scratch. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CNewMapDialog extends JOptionPane { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** The key value used to store the last used level width to INI file. */ - private static final String DEFAULT_LEVEL_WIDTH_KEY = "NewLevelDialog.mapWidth"; - - /** The key value used to store the last used level height to INI file. */ - private static final String DEFAULT_LEVEL_HEIGHT_KEY = "NewLevelDialog.mapHeight"; - - /** The controller of this new level dialog view. */ - private final CMainControl mainControl; - - /** Type of map to create: pickmap or normal map. */ - private final MapType mapType; - - /** Desired filename for new map, null if not specified. */ - private final String filename; - - /** - * Textfield for the name of the map. - * This is only used for {@link MapType#GAMEMAP} to determine the title of the new map. - * The filename of the new map is unset and will be specified when the user saves the map for the first time. - */ - private final JTextField mapNameField = new JTextField(16); - - /** - * Textfield for the width of the new map. - */ - private final JFormattedTextField mapWidthField = new JFormattedTextField(); - - /** - * Textfield for the height of the new map. - */ - private final JFormattedTextField mapHeightField = new JFormattedTextField(); - - /** JButton for ok. */ - private final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "mapOkay", this)); - - /** JButton for cancel. */ - private final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "mapCancel", this)); - - /** - * Constructs a new level dialog. Builds the dialog UI. - * @param mainControl the controller of this dialog. - * @param filename desired filename for new map, null if not specified - * @param mapType type of map to create - */ - private CNewMapDialog(final CMainControl mainControl, final String filename, final MapType mapType) { - okButton.setDefaultCapable(true); - setOptions(new Object[]{okButton, cancelButton}); - - this.mainControl = mainControl; - this.mapType = mapType; - this.filename = filename; - setMessage(createPanel()); - } - - private JPanel createPanel() { - final JPanel newLevelFromScratchPanel = new JPanel(); - newLevelFromScratchPanel.setLayout(new BoxLayout(newLevelFromScratchPanel, BoxLayout.Y_AXIS)); - - newLevelFromScratchPanel.setBorder(IGUIConstants.DIALOG_BORDER); - - // map name panel - final JPanel mapNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - mapNamePanel.add(new JLabel(ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newMapPickmapName" : "newMapMapName"))); - mapNamePanel.add(mapNameField); - newLevelFromScratchPanel.add(mapNamePanel); - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - - final JPanel mapSizePanel = new JPanel(new GridBagLayout()); - final GridBagConstraints gbcLabel = new GridBagConstraints(); - final GridBagConstraints gbcField = new GridBagConstraints(); - gbcLabel.insets = new Insets(2, 2, 2, 2); - gbcField.insets = new Insets(2, 2, 2, 2); - gbcLabel.anchor = GridBagConstraints.EAST; - gbcField.gridwidth = GridBagConstraints.REMAINDER; - mapSizePanel.setBorder(new CompoundBorder(new TitledBorder(new EtchedBorder(), ACTION_FACTORY.getString("newMapParameters")), IGUIConstants.DIALOG_BORDER)); - mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapWidth")), gbcLabel); - if (mapType == MapType.PICKMAP) { - mapWidthField.setValue(IGUIConstants.DEF_PICKMAP_WIDTH); - } else { - assert mapType == MapType.GAMEMAP; - mapWidthField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_WIDTH_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); - } - mapWidthField.setColumns(3); - mapSizePanel.add(mapWidthField, gbcField); - mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapHeight")), gbcLabel); - if (mapType == MapType.PICKMAP) { - mapHeightField.setValue(IGUIConstants.DEF_PICKMAP_HEIGHT); - } else { - assert mapType == MapType.GAMEMAP; - mapHeightField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_HEIGHT_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); - } - mapHeightField.setColumns(3); - mapSizePanel.add(mapHeightField, gbcField); - newLevelFromScratchPanel.add(mapSizePanel); - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - - return newLevelFromScratchPanel; - } - - /** Action method for okay. */ - public void mapOkay() { - if (createNewLevel(this)) { - setValue(okButton); - } - } - - /** Action method for cancel. */ - public void mapCancel() { - setValue(cancelButton); - } - - /** - * Checks the given values and creates a new level. - * @param parent the parent component to be used for error messages - * @return True if the level was created, false if the parameters were wrong. - */ - private boolean createNewLevel(final Component parent) { - - // Create a new level from scratch - final MapArchObject maparch = new MapArchObject(); - - // Get and validate the width - final int width; - final int height; - try { - width = (Integer) mapWidthField.getValue(); - } catch (final IllegalArgumentException e) { - ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); - mapWidthField.requestFocus(); - return false; - } - if (width < 1) { - ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); - mapWidthField.requestFocus(); - return false; - } - - // Get and validate the height - try { - height = (Integer) mapHeightField.getValue(); - } catch (final IllegalArgumentException e) { - ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); - mapHeightField.requestFocus(); - return false; - } - if (height < 1) { - ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); - mapHeightField.requestFocus(); - return false; - } - - maparch.setMapSize(new Size2D(width, height)); - - // the mapmaker must enter a name -- both for maps and pickmaps - final String mapName = mapNameField.getText(); - if (mapName == null || mapName.length() <= 0) { - ACTION_FACTORY.showMessageDialog(this, mapType == MapType.PICKMAP ? "newPickmapNoName" : "newMapNoName"); - mapNameField.requestFocus(); - return false; - } - - // arches must be loaded to create a new map - if (mainControl.getArchetypeSet().getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { - ACTION_FACTORY.showMessageDialog(this, "openFileWantedNotReady"); - return false; - } - - if (mapType == MapType.GAMEMAP) { - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - settings.setProperty(DEFAULT_LEVEL_WIDTH_KEY, String.valueOf(width)); - settings.setProperty(DEFAULT_LEVEL_HEIGHT_KEY, String.valueOf(height)); - } - - // set map name and file name - if (mapType == MapType.GAMEMAP) { - maparch.setMapName(mapName); - maparch.setFileName(filename != null ? filename : IGUIConstants.DEF_MAPFNAME); - } else if (mapType == MapType.PICKMAP) { - maparch.setMapName("pickmap"); - maparch.setFileName(mapName); - } - - // default map text: - final Calendar today = Calendar.getInstance(); // get current date - maparch.addText("Creator: CF Java Map Editor\n"); - maparch.addText("Date: " + (today.get(Calendar.MONTH) + 1) + "/" + today.get(Calendar.DAY_OF_MONTH) + "/" + today.get(Calendar.YEAR)); - - if (mapType == MapType.GAMEMAP) { - mainControl.newLevel(null, maparch, true, null); - } else if (mapType == MapType.PICKMAP) { - return PickmapChooser.getInstance().addNewPickmap(parent, maparch); - } - - return true; - } - - /** - * Show a dialog for creating a new map. - * @param mainControl the controller of this dialog. - * @param parentComponent the parent component of this dialog - * @param filename desired filename for new map, null if not specified - * @param mapType type of map to create - */ - public static void showNewMapDialog(final CMainControl mainControl, final Component parentComponent, final String filename, final MapType mapType) { - final CNewMapDialog pane = new CNewMapDialog(mainControl, filename, mapType); - final JDialog dialog = pane.createDialog(parentComponent, ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newPickmap.title" : "newMap.title")); - dialog.getRootPane().setDefaultButton(pane.okButton); - dialog.setModal(false); - - dialog.setVisible(true); - pane.mapNameField.selectAll(); - pane.mapWidthField.selectAll(); - pane.mapHeightField.selectAll(); - } - -} // class CNewMapDialog Copied: trunk/crossfire/src/cfeditor/gui/NewMapDialog.java (from rev 1299, trunk/crossfire/src/cfeditor/CNewMapDialog.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/NewMapDialog.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/NewMapDialog.java 2006-12-27 00:16:06 UTC (rev 1300) @@ -0,0 +1,287 @@ +/* + * 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.gui; + +import cfeditor.CMainControl; +import cfeditor.CSettings; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.ArchetypeSet; +import cfeditor.map.MapArchObject; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.util.Calendar; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.MapType; +import net.sf.japi.swing.ActionFactory; + +/** + * Dialog used to ask the user the properties for the new level. Contains a + * tabbed pane for creating a level either based on a template or from a + * scratch. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class NewMapDialog extends JOptionPane { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + /** The key value used to store the last used level width to INI file. */ + private static final String DEFAULT_LEVEL_WIDTH_KEY = "NewLevelDialog.mapWidth"; + + /** The key value used to store the last used level height to INI file. */ + private static final String DEFAULT_LEVEL_HEIGHT_KEY = "NewLevelDialog.mapHeight"; + + /** The controller of this new level dialog view. */ + private final CMainControl mainControl; + + /** Type of map to create: pickmap or normal map. */ + private final MapType mapType; + + /** Desired filename for new map, null if not specified. */ + private final String filename; + + /** + * Textfield for the name of the map. + * This is only used for {@link MapType#GAMEMAP} to determine the title of the new map. + * The filename of the new map is unset and will be specified when the user saves the map for the first time. + */ + private final JTextField mapNameField = new JTextField(16); + + /** + * Textfield for the width of the new map. + */ + private final JFormattedTextField mapWidthField = new JFormattedTextField(); + + /** + * Textfield for the height of the new map. + */ + private final JFormattedTextField mapHeightField = new JFormattedTextField(); + + /** JButton for ok. */ + private final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "mapOkay", this)); + + /** JButton for cancel. */ + private final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "mapCancel", this)); + + /** + * Constructs a new level dialog. Builds the dialog UI. + * @param mainControl the controller of this dialog. + * @param filename desired filename for new map, null if not specified + * @param mapType type of map to create + */ + private NewMapDialog(final CMainControl mainControl, final String filename, final MapType mapType) { + okButton.setDefaultCapable(true); + setOptions(new Object[]{okButton, cancelButton}); + + this.mainControl = mainControl; + this.mapType = mapType; + this.filename = filename; + setMessage(createPanel()); + } + + private JPanel createPanel() { + final JPanel newLevelFromScratchPanel = new JPanel(); + newLevelFromScratchPanel.setLayout(new BoxLayout(newLevelFromScratchPanel, BoxLayout.Y_AXIS)); + + newLevelFromScratchPanel.setBorder(IGUIConstants.DIALOG_BORDER); + + // map name panel + final JPanel mapNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + mapNamePanel.add(new JLabel(ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newMapPickmapName" : "newMapMapName"))); + mapNamePanel.add(mapNameField); + newLevelFromScratchPanel.add(mapNamePanel); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + + final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + + final JPanel mapSizePanel = new JPanel(new GridBagLayout()); + final GridBagConstraints gbcLabel = new GridBagConstraints(); + final GridBagConstraints gbcField = new GridBagConstraints(); + gbcLabel.insets = new Insets(2, 2, 2, 2); + gbcField.insets = new Insets(2, 2, 2, 2); + gbcLabel.anchor = GridBagConstraints.EAST; + gbcField.gridwidth = GridBagConstraints.REMAINDER; + mapSizePanel.setBorder(new CompoundBorder(new TitledBorder(new EtchedBorder(), ACTION_FACTORY.getString("newMapParameters")), IGUIConstants.DIALOG_BORDER)); + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapWidth")), gbcLabel); + if (mapType == MapType.PICKMAP) { + mapWidthField.setValue(IGUIConstants.DEF_PICKMAP_WIDTH); + } else { + assert mapType == MapType.GAMEMAP; + mapWidthField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_WIDTH_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); + } + mapWidthField.setColumns(3); + mapSizePanel.add(mapWidthField, gbcField); + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapHeight")), gbcLabel); + if (mapType == MapType.PICKMAP) { + mapHeightField.setValue(IGUIConstants.DEF_PICKMAP_HEIGHT); + } else { + assert mapType == MapType.GAMEMAP; + mapHeightField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_HEIGHT_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); + } + mapHeightField.setColumns(3); + mapSizePanel.add(mapHeightField, gbcField); + newLevelFromScratchPanel.add(mapSizePanel); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + + return newLevelFromScratchPanel; + } + + /** Action method for okay. */ + public void mapOkay() { + if (createNewLevel(this)) { + setValue(okButton); + } + } + + /** Action method for cancel. */ + public void mapCancel() { + setValue(cancelButton); + } + + /** + * Checks the given values and creates a new level. + * @param parent the parent component to be used for error messages + * @return True if the level was created, false if the parameters were wrong. + */ + private boolean createNewLevel(final Component parent) { + + // Create a new level from scratch + final MapArchObject maparch = new MapArchObject(); + + // Get and validate the width + final int width; + final int height; + try { + width = (Integer) mapWidthField.getValue(); + } catch (final IllegalArgumentException e) { + ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); + mapWidthField.requestFocus(); + return false; + } + if (width < 1) { + ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); + mapWidthField.requestFocus(); + return false; + } + + // Get and validate the height + try { + height = (Integer) mapHeightField.getValue(); + } catch (final IllegalArgumentException e) { + ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); + mapHeightField.requestFocus(); + return false; + } + if (height < 1) { + ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); + mapHeightField.requestFocus(); + return false; + } + + maparch.setMapSize(new Size2D(width, height)); + + // the mapmaker must enter a name -- both for maps and pickmaps + final String mapName = mapNameField.getText(); + if (mapName == null || mapName.length() <= 0) { + ACTION_FACTORY.showMessageDialog(this, mapType == MapType.PICKMAP ? "newPickmapNoName" : "newMapNoName"); + mapNameField.requestFocus(); + return false; + } + + // arches must be loaded to create a new map + if (mainControl.getArchetypeSet().getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { + ACTION_FACTORY.showMessageDialog(this, "openFileWantedNotReady"); + return false; + } + + if (mapType == MapType.GAMEMAP) { + final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); + settings.setProperty(DEFAULT_LEVEL_WIDTH_KEY, String.valueOf(width)); + settings.setProperty(DEFAULT_LEVEL_HEIGHT_KEY, String.valueOf(height)); + } + + // set map name and file name + if (mapType == MapType.GAMEMAP) { + maparch.setMapName(mapName); + maparch.setFileName(filename != null ? filename : IGUIConstants.DEF_MAPFNAME); + } else if (mapType == MapType.PICKMAP) { + maparch.setMapName("pickmap"); + maparch.setFileName(mapName); + } + + // default map text: + final Calendar today = Calendar.getInstance(); // get current date + maparch.addText("Creator: CF Java Map Editor\n"); + maparch.addText("Date: " + (today.get(Calendar.MONTH) + 1) + "/" + today.get(Calendar.DAY_OF_MONTH) + "/" + today.get(Calendar.YEAR)); + + if (mapType == MapType.GAMEMAP) { + mainControl.newLevel(null, maparch, true, null); + } else if (mapType == MapType.PICKMAP) { + return PickmapChooser.getInstance().addNewPickmap(parent, maparch); + } + + return true; + } + + /** + * Show a dialog for creating a new map. + * @param mainControl the controller of this dialog. + * @param parentComponent the parent component of this dialog + * @param filename desired filename for new map, null if not specified + * @param mapType type of map to create + */ + public static void showNewMapDialog(final CMainControl mainControl, final Component parentComponent, final String filename, final MapType mapType) { + final NewMapDialog pane = new NewMapDialog(mainControl, filename, mapType); + final JDialog dialog = pane.createDialog(parentComponent, ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newPickmap.title" : "newMap.title")); + dialog.getRootPane().setDefaultButton(pane.okButton); + dialog.setModal(false); + + dialog.setVisible(true); + pane.mapNameField.selectAll(); + pane.mapWidthField.selectAll(); + pane.mapHeightField.selectAll(); + } + +} // class NewMapDialog Property changes on: trunk/crossfire/src/cfeditor/gui/NewMapDialog.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-27 00:07:52 UTC (rev 1299) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-27 00:16:06 UTC (rev 1300) @@ -37,6 +37,7 @@ import daieditor.gameobject.match.ViewGameObjectMatcherManager; import daieditor.gui.GameObjectAttributesDialog; import daieditor.gui.MapFileFilter; +import daieditor.gui.NewMapDialog; import daieditor.gui.PickmapChooser; import daieditor.gui.map.MapCursorControl; import daieditor.gui.map.MapPreviewAccessory; @@ -864,12 +865,12 @@ * @param filename desired filename for the new map, null if not specified */ public void newLevelWanted(final String filename) { - CNewMapDialog.showNewMapDialog(this, mainView, filename, MapType.GAMEMAP); + NewMapDialog.showNewMapDialog(this, mainView, filename, MapType.GAMEMAP); } /** Invoked when user wants to open a new pickmap. */ public void addNewPickmap() { - CNewMapDialog.showNewMapDialog(this, mainView, null, MapType.PICKMAP); + NewMapDialog.showNewMapDialog(this, mainView, null, MapType.PICKMAP); } /** Deleted: trunk/daimonin/src/daieditor/CNewMapDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CNewMapDialog.java 2006-12-27 00:07:52 UTC (rev 1299) +++ trunk/daimonin/src/daieditor/CNewMapDialog.java 2006-12-27 00:16:06 UTC (rev 1300) @@ -1,349 +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 static daieditor.CMainControl.PREFS_USERNAME; -import static daieditor.CMainControl.PREFS_USERNAME_DEFAULT; -import daieditor.gui.PickmapChooser; -import daieditor.map.MapArchObject; -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.prefs.Preferences; -import static java.util.prefs.Preferences.userNodeForPackage; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JDialog; -import javax.swing.JFormattedTextField; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import net.sf.gridarta.Size2D; -import net.sf.gridarta.map.MapType; -import net.sf.japi.swing.ActionFactory; - -/** - * Dialog used to ask the user the properties for the new level. Contains a - * tabbed pane for creating a level either based on a template or from a - * scratch. - * @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> - */ -public final class CNewMapDialog extends JOptionPane { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** - * Whether to use the default map size. - * @val true override default map size - * @val false use default map size - * @default true - */ - private boolean mapSizeDefault = true; - - /** Preferences. */ - private static final Preferences prefs = userNodeForPackage(CMainControl.class); - - /** The key used to store the last used level width in preferences. */ - private static final String DEFAULT_LEVEL_WIDTH_KEY = "NewLevelDialog.mapWidth"; - - /** The key used to store the last used level height in preferences. */ - private static final String DEFAULT_LEVEL_HEIGHT_KEY = "NewLevelDialog.mapHeight"; - - /** The key used to store the last used difficulty in preferences. */ - private static final String DEFAULT_DIFFICULTY_KEY = "NewLevelDialog.difficulty"; - - /** The controller of this new level dialog view. */ - private final CMainControl mainControl; - - /** Type of map to create: pickmap or normal map. */ - private final MapType mapType; - - /** Desired filename for new map, null if not specified. */ - private final String filename; - - /** - * Textfield for the name of the map. - * This is only used for {@link MapType#GAMEMAP} to determine the title of the new map. - * The filename of the new map is unset and will be specified when the user saves the map for the first time. - */ - private final JTextField mapNameField = new JTextField(16); - - /** - * Checkbox to set whether the default width / height should be overridden. - */ - private final JCheckBox mapSizeDefaultCheckbox = new JCheckBox(ACTION_FACTORY.createToggle(false, "mapSizeDefault", this)); - - /** - * Textfield for the width of the new map. - */ - private final JFormattedTextField mapWidthField = new JFormattedTextField(); - - /** - * Textfield for the height of the new map. - */ - private final JFormattedTextField mapHeightField = new JFormattedTextField(); - - /** - * Textfield for the difficulty of the new map. - */ - private final JFormattedTextField mapDifficultyField = new JFormattedTextField(); - - /** JButton for ok. */ - private final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "mapOkay", this)); - - /** JButton for cancel. */ - private final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "mapCancel", this)); - - /** - * Constructs a new level dialog. Builds the dialog UI. - * @param mainControl the controller of this dialog. - * @param filename desired filename for new map, null if not specified - * @param mapType type of map to create - */ - private CNewMapDialog(final CMainControl mainControl, final String filename, final MapType mapType) { - okButton.setDefaultCapable(true); - setOptions(new Object[]{okButton, cancelButton}); - - this.mainControl = mainControl; - this.mapType = mapType; - this.filename = filename; - setMessage(createPanel()); - } - - private JPanel createPanel() { - final JPanel newLevelFromScratchPanel = new JPanel(); - newLevelFromScratchPanel.setLayout(new BoxLayout(newLevelFromScratchPanel, BoxLayout.Y_AXIS)); - - newLevelFromScratchPanel.setBorder(IGUIConstants.DIALOG_BORDER); - - // map name panel - final JPanel mapNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - mapNamePanel.add(new JLabel(ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newMapPickmapName" : "newMapMapName"))); - mapNamePanel.add(mapNameField); - newLevelFromScratchPanel.add(mapNamePanel); - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - - if (mapType != MapType.PICKMAP) { - newLevelFromScratchPanel.add(mapSizeDefaultCheckbox); - } - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - - final JPanel mapSizePanel = new JPanel(new GridBagLayout()); - final GridBagConstraints gbcLabel = new GridBagConstraints(); - final GridBagConstraints gbcField = new GridBagConstraints(); - gbcLabel.insets = new Insets(2, 2, 2, 2); - gbcField.insets = new Insets(2, 2, 2, 2); - gbcLabel.anchor = GridBagConstraints.EAST; - gbcField.gridwidth = GridBagConstraints.REMAINDER; - mapSizePanel.setBorder(new CompoundBorder(new TitledBorder(new EtchedBorder(), ACTION_FACTORY.getString("newMapParameters")), IGUIConstants.DIALOG_BORDER)); - mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapWidth")), gbcLabel); - if (mapType == MapType.PICKMAP) { - mapWidthField.setValue(IGUIConstants.DEF_PICKMAP_WIDTH); - } else { - assert mapType == MapType.GAMEMAP; - mapWidthField.setValue(prefs.getInt(DEFAULT_LEVEL_WIDTH_KEY, IGUIConstants.DEF_MAPSIZE)); - } - mapWidthField.setColumns(3); - mapSizePanel.add(mapWidthField, gbcField); - mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapHeight")), gbcLabel); - if (mapType == MapType.PICKMAP) { - mapHeightField.setValue(IGUIConstants.DEF_PICKMAP_HEIGHT); - } else { - assert mapType == MapType.GAMEMAP; - mapHeightField.setValue(prefs.getInt(DEFAULT_LEVEL_HEIGHT_KEY, IGUIConstants.DEF_MAPSIZE)); - } - mapHeightField.setColumns(3); - mapSizePanel.add(mapHeightField, gbcField); - if (mapType == MapType.GAMEMAP) { - mapDifficultyField.setValue(prefs.getInt(DEFAULT_DIFFICULTY_KEY, IGUIConstants.DEF_MAPDIFFICULTY)); - mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapDifficulty")), gbcLabel); - mapDifficultyField.setColumns(3); - mapSizePanel.add(mapDifficultyField, gbcField); - } - newLevelFromScratchPanel.add(mapSizePanel); - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - - return newLevelFromScratchPanel; - } - - /** Action method for okay. */ - public void mapOkay() { - if (createNewLevel(this)) { - setValue(okButton); - } - } - - /** Action method for cancel. */ - public void mapCancel() { - setValue(cancelButton); - } - - /** - * Checks the given values and creates a new level. - * @param parent the parent component to be used for error messages - * @return True if the level was created, false if the parameters were wrong. - */ - private boolean createNewLevel(final Component parent) { - - // Create a new level from scratch - final MapArchObject maparch = new MapArchObject(); - - // Get and validate the width - final int width; - final int height; - if (mapType == MapType.PICKMAP || !mapSizeDefault) { - try { - width = (Integer) mapWidthField.getValue(); - } catch (final IllegalArgumentException e) { - ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); - mapWidthField.requestFocus(); - return false; - } - if (width < 1) { - ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); - mapWidthField.requestFocus(); - return false; - } - - // Get and validate the height - try { - height = (Integer) mapHeightField.getValue(); - } catch (final IllegalArgumentException e) { - ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); - mapHeightField.requestFocus(); - return false; - } - if (height < 1) { - ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); - mapHeightField.requestFocus(); - return false; - } - } else { - width = IGUIConstants.DEF_MAPSIZE; - height = IGUIConstants.DEF_MAPSIZE; - } - - maparch.setMapSize(new Size2D(width, height)); - - // the mapmaker must enter a name -- both for maps and pickmaps - final String mapName = mapNameField.getText(); - if (mapName == null || mapName.length() <= 0) { - ACTION_FACTORY.showMessageDialog(this, mapType == MapType.PICKMAP ? "newPickmapNoName" : "newMapNoName"); - mapNameField.requestFocus(); - return false; - } - - if (mapType == MapType.GAMEMAP) { - prefs.putInt(DEFAULT_LEVEL_WIDTH_KEY, width); - prefs.putInt(DEFAULT_LEVEL_HEIGHT_KEY, height); - } - - // set map name, file name and difficulty - if (mapType == MapType.GAMEMAP) { - maparch.setMapName(mapName); - maparch.setFileName(filename != null ? filename : IGUIConstants.DEF_MAPFNAME); - try { - maparch.setDifficulty((Integer) mapDifficultyField.getValue()); - } catch (final IllegalArgumentException e) { - ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDifficultyNotANumber" : "newMapDifficultyOutOfRange"); - mapDifficultyField.requestFocus(); - return false; - } - } else if (mapType == MapType.PICKMAP) { - maparch.setMapName("pickmap"); - maparch.setFileName(mapName); - } - - // default map text: - maparch.addText("Creator: " + prefs.get(PREFS_USERNAME, PREFS_USERNAME_DEFAULT) + '\n'); - maparch.addText(String.format("Date: %tF", System.currentTimeMillis())); - - if (mapType == MapType.GAMEMAP) { - mainControl.newLevel(null, maparch, true); - } else if (mapType == MapType.PICKMAP) { - return PickmapChooser.getInstance().addNewPickmap(parent, maparch); - } - - return true; - } - - /** - * Show a dialog for creating a new map. - * @param mainControl the controller of this dialog. - * @param parentComponent the parent component of this dialog - * @param filename desired filename for new map, null if not specified - * @param mapType type of map to create - */ - public static void showNewMapDialog(final CMainControl mainControl, final Component parentComponent, final String filename, final MapType mapType) { - final CNewMapDialog pane = new CNewMapDialog(mainControl, filename, mapType); - final JDialog dialog = pane.createDialog(parentComponent, ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newPickmap.title" : "newMap.title")); - dialog.getRootPane().setDefaultButton(pane.okButton); - dialog.setModal(false); - - if (mapType != MapType.PICKMAP) { - pane.setMapSizeDefault(true); - } - - dialog.setVisible(true); - pane.mapNameField.selectAll(); - pane.mapWidthField.selectAll(); - pane.mapHeightField.selectAll(); - } - - /** - * Set whether to override the default map size. - * @return mapSizeDefault <code>true</code> if the user wants to specify her own map size, otherwise <code>false</code> - */ - public boolean isMapSizeDefault() { - return mapSizeDefault; - } - - /** - * Set whether to override the default map size. - * @param mapSizeDefault <code>true</code> if the user wants to specify her own map size, otherwise <code>false</code> - */ - public void setMapSizeDefault(final boolean mapSizeDefault) { - mapSizeDefaultCheckbox.setSelected(mapSizeDefault); - this.mapSizeDefault = mapSizeDefault; - mapWidthField.setEnabled(!mapSizeDefault); - mapHeightField.setEnabled(!mapSizeDefault); - } - -} // class CNewMapDialog Copied: trunk/daimonin/src/daieditor/gui/NewMapDialog.java (from rev 1299, trunk/daimonin/src/daieditor/CNewMapDialog.java) =================================================================== --- trunk/daimonin/src/daieditor/gui/NewMapDialog.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/NewMapDialog.java 2006-12-27 00:16:06 UTC (rev 1300) @@ -0,0 +1,350 @@ +/* + * 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.gui; + +import daieditor.CMainControl; +import static daieditor.CMainControl.PREFS_USERNAME; +import static daieditor.CMainControl.PREFS_USERNAME_DEFAULT; +import daieditor.IGUIConstants; +import daieditor.map.MapArchObject; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.util.prefs.Preferences; +import static java.util.prefs.Preferences.userNodeForPackage; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.MapType; +import net.sf.japi.swing.ActionFactory; + +/** + * Dialog used to ask the user the properties for the new level. Contains a + * tabbed pane for creating a level either based on a template or from a + * scratch. + * @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> + */ +public final class NewMapDialog extends JOptionPane { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + /** + * Whether to use the default map size. + * @val true override default map size + * @val false use default map size + * @default true + */ + private boolean mapSizeDefault = true; + + /** Preferences. */ + private static final Preferences prefs = userNodeForPackage(CMainControl.class); + + /** The key used to store the last used level width in preferences. */ + private static final String DEFAULT_LEVEL_WIDTH_KEY = "NewLevelDialog.mapWidth"; + + /** The key used to store the last used level height in preferences. */ + private static final String DEFAULT_LEVEL_HEIGHT_KEY = "NewLevelDialog.mapHeight"; + + /** The key used to store the last used difficulty in preferences. */ + private static final String DEFAULT_DIFFICULTY_KEY = "NewLevelDialog.difficulty"; + + /** The controller of this new level dialog view. */ + private final CMainControl mainControl; + + /** Type of map to create: pickmap or normal map. */ + private final MapType mapType; + + /** Desired filename for new map, null if not specified. */ + private final String filename; + + /** + * Textfield for the name of the map. + * This is only used for {@link MapType#GAMEMAP} to determine the title of the new map. + * The filename of the new map is unset and will be specified when the user saves the map for the first time. + */ + private final JTextField mapNameField = new JTextField(16); + + /** + * Checkbox to set whether the default width / height should be overridden. + */ + private final JCheckBox mapSizeDefaultCheckbox = new JCheckBox(ACTION_FACTORY.createToggle(false, "mapSizeDefault", this)); + + /** + * Textfield for the width of the new map. + */ + private final JFormattedTextField mapWidthField = new JFormattedTextField(); + + /** + * Textfield for the height of the new map. + */ + private final JFormattedTextField mapHeightField = new JFormattedTextField(); + + /** + * Textfield for the difficulty of the new map. + */ + private final JFormattedTextField mapDifficultyField = new JFormattedTextField(); + + /** JButton for ok. */ + private final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "mapOkay", this)); + + /** JButton for cancel. */ + private final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "mapCancel", this)); + + /** + * Constructs a new level dialog. Builds the dialog UI. + * @param mainControl the controller of this dialog. + * @param filename desired filename for new map, null if not specified + * @param mapType type of map to create + */ + private NewMapDialog(final CMainControl mainControl, final String filename, final MapType mapType) { + okButton.setDefaultCapable(true); + setOptions(new Object[]{okButton, cancelButton}); + + this.mainControl = mainControl; + this.mapType = mapType; + this.filename = filename; + setMessage(createPanel()); + } + + private JPanel createPanel() { + final JPanel newLevelFromScratchPanel = new JPanel(); + newLevelFromScratchPanel.setLayout(new BoxLayout(newLevelFromScratchPanel, BoxLayout.Y_AXIS)); + + newLevelFromScratchPanel.setBorder(IGUIConstants.DIALOG_BORDER); + + // map name panel + final JPanel mapNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + mapNamePanel.add(new JLabel(ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newMapPickmapName" : "newMapMapName"))); + mapNamePanel.add(mapNameField); + newLevelFromScratchPanel.add(mapNamePanel); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + + if (mapType != MapType.PICKMAP) { + newLevelFromScratchPanel.add(mapSizeDefaultCheckbox); + } + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + + final JPanel mapSizePanel = new JPanel(new GridBagLayout()); + final GridBagConstraints gbcLabel = new GridBagConstraints(); + final GridBagConstraints gbcField = new GridBagConstraints(); + gbcLabel.insets = new Insets(2, 2, 2, 2); + gbcField.insets = new Insets(2, 2, 2, 2); + gbcLabel.anchor = GridBagConstraints.EAST; + gbcField.gridwidth = GridBagConstraints.REMAINDER; + mapSizePanel.setBorder(new CompoundBorder(new TitledBorder(new EtchedBorder(), ACTION_FACTORY.getString("newMapParameters")), IGUIConstants.DIALOG_BORDER)); + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapWidth")), gbcLabel); + if (mapType == MapType.PICKMAP) { + mapWidthField.setValue(IGUIConstants.DEF_PICKMAP_WIDTH); + } else { + assert mapType == MapType.GAMEMAP; + mapWidthField.setValue(prefs.getInt(DEFAULT_LEVEL_WIDTH_KEY, IGUIConstants.DEF_MAPSIZE)); + } + mapWidthField.setColumns(3); + mapSizePanel.add(mapWidthField, gbcField); + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapHeight")), gbcLabel); + if (mapType == MapType.PICKMAP) { + mapHeightField.setValue(IGUIConstants.DEF_PICKMAP_HEIGHT); + } else { + assert mapType == MapType.GAMEMAP; + mapHeightField.setValue(prefs.getInt(DEFAULT_LEVEL_HEIGHT_KEY, IGUIConstants.DEF_MAPSIZE)); + } + mapHeightField.setColumns(3); + mapSizePanel.add(mapHeightField, gbcField); + if (mapType == MapType.GAMEMAP) { + mapDifficultyField.setValue(prefs.getInt(DEFAULT_DIFFICULTY_KEY, IGUIConstants.DEF_MAPDIFFICULTY)); + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapDifficulty")), gbcLabel); + mapDifficultyField.setColumns(3); + mapSizePanel.add(mapDifficultyField, gbcField); + } + newLevelFromScratchPanel.add(mapSizePanel); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + + return newLevelFromScratchPanel; + } + + /** Action method for okay. */ + public void mapOkay() { + if (createNewLevel(this)) { + setValue(okButton); + } + } + + /** Action method for cancel. */ + public void mapCancel() { + setValue(cancelButton); + } + + /** + * Checks the given values and creates a new level. + * @param parent the parent component to be used for error messages + * @return True if the level was created, false if the parameters were wrong. + */ + private boolean createNewLevel(final Component parent) { + + // Create a new level from scratch + final MapArchObject maparch = new MapArchObject(); + + // Get and validate the width + final int width; + final int height; + if (mapType == MapType.PICKMAP || !mapSizeDefault) { + try { + width = (Integer) mapWidthField.getValue(); + } catch (final IllegalArgumentException e) { + ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); + mapWidthField.requestFocus(); + return false; + } + if (width < 1) { + ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); + mapWidthField.requestFocus(); + return false; + } + + // Get and validate the height + try { + height = (Integer) mapHeightField.getValue(); + } catch (final IllegalArgumentException e) { + ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"); + mapHeightField.requestFocus(); + return false; + } + if (height < 1) { + ACTION_FACTORY.showMessageDialog(this, "newMapDimensionOutOfRange"); + mapHeightField.requestFocus(); + return false; + } + } else { + width = IGUIConstants.DEF_MAPSIZE; + height = IGUIConstants.DEF_MAPSIZE; + } + + maparch.setMapSize(new Size2D(width, height)); + + // the mapmaker must enter a name -- both for maps and pickmaps + final String mapName = mapNameField.getText(); + if (mapName == null || mapName.length() <= 0) { + ACTION_FACTORY.showMessageDialog(this, mapType == MapType.PICKMAP ? "newPickmapNoName" : "newMapNoName"); + mapNameField.requestFocus(); + return false; + } + + if (mapType == MapType.GAMEMAP) { + prefs.putInt(DEFAULT_LEVEL_WIDTH_KEY, width); + prefs.putInt(DEFAULT_LEVEL_HEIGHT_KEY, height); + } + + // set map name, file name and difficulty + if (mapType == MapType.GAMEMAP) { + maparch.setMapName(mapName); + maparch.setFileName(filename != null ? filename : IGUIConstants.DEF_MAPFNAME); + try { + maparch.setDifficulty((Integer) mapDifficultyField.getValue()); + } catch (final IllegalArgumentException e) { + ACTION_FACTORY.showMessageDialog(this, e instanceof NumberFormatException ? "newMapDifficultyNotANumber" : "newMapDifficultyOutOfRange"); + mapDifficultyField.requestFocus(); + return false; + } + } else if (mapType == MapType.PICKMAP) { + maparch.setMapName("pickmap"); + maparch.setFileName(mapName); + } + + // default map text: + maparch.addText("Creator: " + prefs.get(PREFS_USERNAME, PREFS_USERNAME_DEFAULT) + '\n'); + maparch.addText(String.format("Date: %tF", System.currentTimeMillis())); + + if (mapType == MapType.GAMEMAP) { + mainControl.newLevel(null, maparch, true); + } else if (mapType == MapType.PICKMAP) { + return PickmapChooser.getInstance().addNewPickmap(parent, maparch); + } + + return true; + } + + /** + * Show a dialog for creating a new map. + * @param mainControl the controller of this dialog. + * @param parentComponent the parent component of this dialog + * @param filename desired filename for new map, null if not specified + * @param mapType type of map to create + */ + public static void showNewMapDialog(final CMainControl mainControl, final Component parentComponent, final String filename, final MapType mapType) { + final NewMapDialog pane = new NewMapDialog(mainControl, filename, mapType); + final JDialog dialog = pane.createDialog(parentComponent, ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newPickmap.title" : "newMap.title")); + dialog.getRootPane().setDefaultButton(pane.okButton); + dialog.setModal(false); + + if (mapType != MapType.PICKMAP) { + pane.setMapSizeDefault(true); + } + + dialog.setVisible(true); + pane.mapNameField.selectAll(); + pane.mapWidthField.selectAll(); + pane.mapHeightField.selectAll(); + } + + /** + * Set whether to override the default map size. + * @return mapSizeDefault <code>true</code> if the user wants to specify her own map size, otherwise <code>false</code> + */ + public boolean isMapSizeDefault() { + return mapSizeDefault; + } + + /** + * Set whether to override the default map size. + * @param mapSizeDefault <code>true</code> if the user wants to specify her own map size, otherwise <code>false</code> + */ + public void setMapSizeDefault(final boolean mapSizeDefault) { + mapSizeDefaultCheckbox.setSelected(mapSizeDefault); + this.mapSizeDefault = mapSizeDefault; + mapWidthField.setEnabled(!mapSizeDefault); + mapHeightField.setEnabled(!mapSizeDefault); + } + +} // class NewMapDialog Property changes on: trunk/daimonin/src/daieditor/gui/NewMapDialog.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-27 00:55:12
|
Revision: 1301 http://svn.sourceforge.net/gridarta/?rev=1301&view=rev Author: christianhujer Date: 2006-12-26 16:55:12 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Update to transaction system, improvement of transaction system documentation. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java trunk/src/app/net/sf/gridarta/map/MapModel.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-27 00:16:06 UTC (rev 1300) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-27 00:55:12 UTC (rev 1301) @@ -1333,9 +1333,7 @@ } else if (!currentMap.isPointValid(exitPos)) { ACTION_FACTORY.showMessageDialog(mainView, "enterExitOutside"); } else { - currentMap.getMapModel().beginTransaction("Enter Exit"); currentMap.getMapViewFrame().setCursorPosition(exitPos); - currentMap.getMapModel().endTransaction(); } } else { // path points to a different map @@ -1374,9 +1372,7 @@ exitPos.x = currentMap.getMapModel().getMapArchObject().getEnterX(); exitPos.y = currentMap.getMapModel().getMapArchObject().getEnterY(); } - currentMap.getMapModel().beginTransaction("Enter Exit"); currentMap.getMapViewFrame().setCursorPosition(exitPos); - currentMap.getMapModel().endTransaction(); // Update the main view so the new map instantly pops up. mainView.update(mainView.getGraphics()); Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2006-12-27 00:16:06 UTC (rev 1300) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2006-12-27 00:55:12 UTC (rev 1301) @@ -15,7 +15,10 @@ /** * Abstract implementation of {@link MapModel} that covers the similarities between crossfire and daimonin. + * The transaction system is not implemented in a way that supports overriding its method for change. + * Therefore all methods belonging to the transaction system are final. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @see MapModel class MapModel for a documentation of the transaction system. */ public abstract class AbstractMapModel<G extends GameObject<G>, A extends MapArchObject> implements MapModel<G, A> { @@ -39,12 +42,26 @@ /** The registered event listeners. */ private EventListenerList listenerList = new EventListenerList(); - /** The transaction depth. */ + /** + * The transaction depth. + * A value of 0 means there's no transaction going on. + * A value > 0 means there's a transaction going on and denotes the nesting level. + * @invariant transactionDepth >= 0 + */ private int transactionDepth; - /** The name of the current transaction. */ + /** + * The name of the current transaction. + * @invariant transactionDepth > 0 || transactionName == null + */ @Nullable private String transactionName; + /** + * The thread that performs the current transaction. + * @invariant transactionDepth > 0 || transactionThread == null + */ + @Nullable private Thread transactionThread; + /** The ArrayList with changed squares. */ private final List<MapSquare<G>> changedSquares = new ArrayList<MapSquare<G>>(); @@ -229,40 +246,72 @@ } /** {@inheritDoc} */ - public void beginTransaction(@NotNull final String name) { - if (transactionDepth++ == 0) { + public final void beginTransaction(@NotNull final String name) { + if (transactionDepth == 0) { transactionName = name; + transactionThread = Thread.currentThread(); + // TODO: create backup and prepare undo entry + } else { + // == is okay for threads. + //noinspection ObjectEquality + if (transactionThread != Thread.currentThread()) { + throw new IllegalStateException("A transaction must only be used by one thread."); + } } + transactionDepth++; } /** {@inheritDoc} */ - public void endTransaction() { + public final void endTransaction() { + endTransaction(false); + } + + /** {@inheritDoc} */ + public final void endTransaction(final boolean fireEvent) { + if (transactionDepth <= 0) { + throw new IllegalStateException("Tried to end a transaction but no transaction was open."); + } transactionDepth--; assert transactionDepth >= 0; - if (transactionDepth == 0 && !changedSquares.isEmpty()) { + if (transactionDepth == 0) { + commitTransaction(); + } else if (fireEvent && transactionDepth == 1 && !changedSquares.isEmpty()) { fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); - changedSquares.clear(); } } /** {@inheritDoc} */ - public void endAllTransactions() { + public final void endAllTransactions() { if (transactionDepth > 0) { - transactionDepth = 0; - if (!changedSquares.isEmpty()) { - fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); - changedSquares.clear(); - } + commitTransaction(); } } + /** + * Performs ending a transaction. + * Resets all transaction states and fires an event. + */ + private void commitTransaction() { + transactionDepth = 0; + transactionThread = null; + if (!changedSquares.isEmpty()) { + fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); + changedSquares.clear(); + } + } + /** {@inheritDoc} */ - public int getTransactionDepth() { + public final int getTransactionDepth() { return transactionDepth; } /** {@inheritDoc} */ - @Nullable public String getTransactionName() { + public final boolean isAnyTransactionActive() { + return transactionDepth > 0; + } + + /** {@inheritDoc} */ + @Nullable public final String getTransactionName() { return transactionName; } Modified: trunk/src/app/net/sf/gridarta/map/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-12-27 00:16:06 UTC (rev 1300) +++ trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-12-27 00:55:12 UTC (rev 1301) @@ -14,6 +14,10 @@ * The purpose of the transaction system in MapModel is to allow several subsequent changes to the model to be collected as a single big change before the registered listeners (usually the user interface) gets notified. * This prevents the user interface from performing hundrets of updates when a single one would be enough. * The transaction system will also be used for implementing undo / redo. + * <h3>Concurrency</h3> + * It's not purpose of the transaction system to provide concurrent transactions for concurrent threads. + * A MapModel will protect itself against concurrent modification. + * <h3>Performance</h3> * <p /> * The transaction system is efficient-safe. * The following operations are very cheap: @@ -24,10 +28,20 @@ * </ul> * Whether beginning the outermost transaction will be a cheap operation is not yet decided. * <p /> + * Transactions are recorded. + * <p /> * It is not (yet?) the purpose of the transaction system to provide real transactions (ACID). * Queries to the MapModel during an ongoing transaction will reflect the intermediate state. * And there is no rollback yet, but this is planned for future as it's required for undo anyway. + * <h3>Future</h3> + * The following features are not yet implemented but planned. + * <h4>Undo System</h4> + * The transaction system will serve as a base for an undo / redo system. + * Beginning the outermost transaction stores a new undo record in the undo buffer. + * An undo record consists of the transaction's name plus the current map state. * @author <a href="mailto:ch...@ri...">Christian HUjer</a> + * @invariant !isAnyTransactionActive() || getTransactionDepth() > 0 + * @invariant isCutoffSafe(getMapSize()) */ public interface MapModel<G extends GameObject<G>, A extends MapArchObject> extends Iterable<MapSquare<G>>, Serializable { @@ -55,7 +69,7 @@ * If any bounds are smaller than before, the map gets cut on the right and bottom side. * Accordingly, new space is attached to right and bottom. * @param newSize new map size - * @see {@link #isCutoffSafe(net.sf.gridarta.Size2D)} for checking whether map contents would get cut off. + * @see {@link #isCutoffSafe(Size2D)} for checking whether map contents would get cut off. */ void resizeMap(@NotNull Size2D newSize); @@ -103,9 +117,13 @@ * <p /> * Beginning a nested transaction is a cheap operation. * @param name Name of the transaction. + * @see #beginTransaction(String) * @see #endTransaction() + * @see #endTransaction(boolean) + * @see #endAllTransactions() * @see #getTransactionDepth() - * @see #endAllTransactions() + * @see #getTransactionName() + * @see #isAnyTransactionActive() */ void beginTransaction(@NotNull String name); @@ -115,20 +133,56 @@ * <p /> * Ending a nested operation is a cheap operation. * Ending a transaction without changes also is a cheap operation. + * <p /> + * If the last transaction is ended, the changes are committed. + * <p /> + * Same as {@link #endTransaction(boolean) endTransaction(false)}. * @see #beginTransaction(String) + * @see #endTransaction() + * @see #endTransaction(boolean) + * @see #endAllTransactions() * @see #getTransactionDepth() - * @see #endAllTransactions() + * @see #getTransactionName() + * @see #isAnyTransactionActive() */ void endTransaction(); /** + * End a transaction. + * Invoking this method will reduce the transaction depth by only 1. + * <p /> + * Ending a nested operation is a cheap operation. + * Ending a transaction without changes also is a cheap operation. + * <p /> + * If the last transaction is ended, the changes are committed. + * <p /> + * An example where setting <var>fireEvent</var> to <code>true</code> is useful even though the outermost transaction is not ended is when during painting the UI should be updated though painting is not finnished. + * @param fireEvent <code>true</code> if an event should be fired even in case this doesn't end the outermost transaction. + * @note If the outermost transaction is ended, <var>fireEvent</var> is ignored and the event is always fired. + * @note An event is never fired when there were no changes, no matter whether the outermost transaction is ended or <var>fireEvent</var> is set to <code>true</code>. + * @note If the event is fired, the internal change list is not cleared. + * @see #beginTransaction(String) + * @see #endTransaction() + * @see #endTransaction(boolean) + * @see #endAllTransactions() + * @see #getTransactionDepth() + * @see #getTransactionName() + * @see #isAnyTransactionActive() + */ + void endTransaction(boolean fireEvent); + + /** * Ends all transaction. * Invoking this method will reduce set the transaction depth to 0. * You shouldn't invoke this method regularly. * It is meant as a fallback in high level methods / exception handlers to prevent errors from causing unclosed transactions. * @see #beginTransaction(String) * @see #endTransaction() + * @see #endTransaction(boolean) + * @see #endAllTransactions() * @see #getTransactionDepth() + * @see #getTransactionName() + * @see #isAnyTransactionActive() */ void endAllTransactions(); @@ -138,7 +192,11 @@ * @return transaction depth * @see #beginTransaction(String) * @see #endTransaction() + * @see #endTransaction(boolean) * @see #endAllTransactions() + * @see #getTransactionDepth() + * @see #getTransactionName() + * @see #isAnyTransactionActive() */ int getTransactionDepth(); @@ -149,10 +207,31 @@ * If not called inside a transaction and there hasn't been a transaction so far, <code>null</code> is returned. * @return The current transaction's name. * @note Unstable: This part of this interface's contract is unstable. Details like nullability and exceptions are subject of change. + * @see #beginTransaction(String) + * @see #endTransaction() + * @see #endTransaction(boolean) + * @see #endAllTransactions() + * @see #getTransactionDepth() + * @see #getTransactionName() + * @see #isAnyTransactionActive() */ @Nullable String getTransactionName(); /** + * Returns whether a transaction is currently active. + * This method will return <code>true</code> if and only if {@link #getTransactionDepth()} returns a value greater than zero. + * @return <code>true</code> if there's a transaction going on, otherwise <code>false</code>. + * @see #beginTransaction(String) + * @see #endTransaction() + * @see #endTransaction(boolean) + * @see #endAllTransactions() + * @see #getTransactionDepth() + * @see #getTransactionName() + * @see #isAnyTransactionActive() + */ + boolean isAnyTransactionActive(); + + /** * Get the square at a specified location. * @param pos location to get square at * @return square at <var>p</var> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |