From: <aki...@us...> - 2006-09-23 06:28:41
|
Revision: 360 http://svn.sourceforge.net/gridarta/?rev=360&view=rev Author: akirschbaum Date: 2006-09-22 23:28:35 -0700 (Fri, 22 Sep 2006) Log Message: ----------- Remove useless return value from ArchObjectParser.sortTempList(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-23 06:19:51 UTC (rev 359) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-23 06:28:35 UTC (rev 360) @@ -996,8 +996,8 @@ return null; } - final List<ArchObject> sortedObjects = ArchObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) - control = newLevel(sortedObjects, maparch, show, initial); // init the map + ArchObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) + control = newLevel(objects, maparch, show, initial); // init the map if (show) { // finally, show the map and refresh toolbars Modified: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-09-23 06:19:51 UTC (rev 359) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-09-23 06:28:35 UTC (rev 360) @@ -147,8 +147,8 @@ if (!mainControl.collectTempList(objects, mapFile)) { // get face names, face id, etc. return false; } - final List<ArchObject> sortedObjects = ArchObjectParser.sortTempList(objects); // sort the list (put multiparts at the end) - bmapview = newPickmap(sortedObjects, maparch, mapFile); // init the map + ArchObjectParser.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 Modified: trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java 2006-09-23 06:19:51 UTC (rev 359) +++ trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java 2006-09-23 06:28:35 UTC (rev 360) @@ -594,10 +594,8 @@ * Note: This method assumes that all pieces of one multipart are * listed in a row. (Which is okay as long as the loader puts it that way.) * @param objects list of arches - * @return the sorting might eventually change the starting - * arch. Therefore, the new start arch is returned. */ - public static List<ArchObject> sortTempList(final List<ArchObject> objects) { + public static void sortTempList(final List<ArchObject> objects) { final Comparator<ArchObject> sorter = new Comparator<ArchObject>() { public int compare(final ArchObject o1, final ArchObject o2) { final boolean b1 = o1.isMulti(); @@ -606,7 +604,6 @@ } }; Collections.sort(objects, sorter); - return objects; } } // class ArchObjectParser This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-09-24 15:51:17
|
Revision: 393 http://svn.sourceforge.net/gridarta/?rev=393&view=rev Author: akirschbaum Date: 2006-09-24 08:51:12 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Remove unused variables. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMapArchPanel.java Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-24 15:42:45 UTC (rev 392) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-24 15:51:12 UTC (rev 393) @@ -359,7 +359,6 @@ * @param listNode node of the treasureone list */ private void recalculateChances(final TreasureTreeNode listNode) { - final int cnum = listNode.getSiblingCount() - 1; // number of child-objects in the treasureone list int sumChances = 0; // sum of chances // calculate the sum of all chances Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-09-24 15:42:45 UTC (rev 392) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-09-24 15:51:12 UTC (rev 393) @@ -146,8 +146,6 @@ private final JButton submitMultiChange; - private JButton jumpChange; - private final JButton invChange; private final JButton attrWin; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-09-25 08:42:18
|
Revision: 423 http://svn.sourceforge.net/gridarta/?rev=423&view=rev Author: akirschbaum Date: 2006-09-25 01:41:50 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Use generics where possible. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchType.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainToolbar.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CScriptController.java trunk/crossfire/src/cfeditor/CScriptModel.java trunk/crossfire/src/cfeditor/CScriptView.java trunk/crossfire/src/cfeditor/FaceObject.java trunk/crossfire/src/cfeditor/JFontChooser.java trunk/crossfire/src/cfeditor/JarResources.java trunk/crossfire/src/cfeditor/PluginParameter.java trunk/crossfire/src/cfeditor/PluginParameterFactory.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gui/ArchComboBox.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/BasicMenuEntry.java trunk/crossfire/src/cfeditor/menu/MenuManager.java trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2006-09-25 08:41:50 UTC (rev 423) @@ -120,13 +120,13 @@ */ public boolean load(final Element root, final CFArchTypeList tlist) { // this vector is used to store a temporare linked list of attributes - final Vector attrList = new Vector(); + final Vector<CFArchAttrib> attrList = new Vector<CFArchAttrib>(); // for internal section handling: - final Vector secNames = new Vector(); // list of section names - final Hashtable ignoreTable = new Hashtable(); // ignore list + final Vector<String> secNames = new Vector<String>(); // list of section names + final Hashtable<String, String> ignoreTable = new Hashtable<String, String>(); // ignore list - List children; // list of children elements + List<Element> children; // list of children elements Element elem; // xml element Attribute a1; @@ -154,7 +154,7 @@ children = required.getChildren(XML_ATTRIBUTE); final List<String> tmp = new ArrayList<String>(); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); a1 = elem.getAttribute(CFArchAttrib.XML_KEY_ARCH); final Attribute a2 = elem.getAttribute(XML_VALUE); if (a1 == null || a2 == null) { @@ -182,7 +182,7 @@ // load all attributes in the ignore section children = signore.getChildren(XML_ATTRIBUTE); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); a1 = elem.getAttribute(CFArchAttrib.XML_KEY_ARCH); if (a1 == null) { log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); @@ -194,15 +194,15 @@ // load attributes from ignore lists children = signore.getChildren("ignore_list"); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); a1 = elem.getAttribute("name"); if (a1 == null) { log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { // just copy everything from ignorelist to this ignore section - final Vector ignlist = (Vector) (tlist.getIgnoreListTable().get(a1.getValue().trim())); + final Vector<String> ignlist = tlist.getIgnoreListTable().get(a1.getValue().trim()); for (int k = 0; k < ignlist.size(); k++) { - ignoreTable.put((String) (ignlist.elementAt(k)), ""); + ignoreTable.put(ignlist.elementAt(k), ""); } } else { log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); @@ -237,7 +237,7 @@ boolean inSection; String section = "?"; for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); // attribute directly in type element if (elem.getName().equalsIgnoreCase(XML_ATTRIBUTE)) { parseAttribute(elem, secNames, false, null, attrList, tlist); @@ -258,9 +258,9 @@ } // parse all attributes in the section - final List schildren = elem.getChildren(); + final List<Element> schildren = elem.getChildren(); for (int k = 0; schildren != null && k < schildren.size(); k++) { - elem = (Element) schildren.get(k); + elem = schildren.get(k); if (elem.getName().equalsIgnoreCase(XML_ATTRIBUTE)) { // got an attribute element possibly in a section parseAttribute(elem, secNames, inSection, section, attrList, tlist); @@ -359,7 +359,7 @@ // put the list of the (non-default) CFArchAttribs into an array: for (int i = 0; numDef < j && i < attrList.size(); numDef++, i++) { - attr[numDef] = (CFArchAttrib) (attrList.elementAt(i)); + attr[numDef] = attrList.elementAt(i); } return true; // archtype was parsed correctly @@ -376,7 +376,7 @@ * @param attrList linked list of attributes * @param tlist arch type list */ - private void parseAttribute(final Element elem, final Vector secNames, final boolean inSection, final String section, final Vector attrList, final CFArchTypeList tlist) { + private void parseAttribute(final Element elem, final Vector<String> secNames, final boolean inSection, final String section, final Vector<CFArchAttrib> attrList, final CFArchTypeList tlist) { // create new instance final CFArchAttrib attrib = new CFArchAttrib(); @@ -384,7 +384,7 @@ if (attrib.load(elem, tlist, typeName)) { // add this attribute to the list: if (attrList.size() > 0) { - ((CFArchAttrib) (attrList.get(attrList.size() - 1))).setNext(attrib); + attrList.get(attrList.size() - 1).setNext(attrib); } attrList.add(attrib); Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-09-25 08:41:50 UTC (rev 423) @@ -64,11 +64,11 @@ private int[] spellNum; // array of spell numbers - private Map bitmaskTable; // table with CAttrBitmask objects (value) sorted by name (key) + private Map<String, CAttribBitmask> bitmaskTable; // table with CAttribBitmask objects (value) sorted by name (key) - private Map listTable; // table with Vector objects for lists (value) sorted by name (key) + private Map<String, Vector> listTable; // table with Vector objects for lists (value) sorted by name (key) - private Map ignoreListTable; // table with Vector objects for ignore_lists (value) sorted by name (key) + private Map<String, Vector<String>> ignoreListTable; // table with Vector objects for ignore_lists (value) sorted by name (key) private int length = 0; // Number of types in the list @@ -81,9 +81,9 @@ final boolean headLoaded = false; // true when the default type (=head) is loaded // initialize the arrays of "special-data" - bitmaskTable = new HashMap(); - listTable = new HashMap(); - ignoreListTable = new HashMap(); + bitmaskTable = new HashMap<String, CAttribBitmask>(); + listTable = new HashMap<String, Vector>(); + ignoreListTable = new HashMap<String, Vector<String>>(); loadSpellsFromXML(); // load spells from file @@ -105,11 +105,11 @@ if (root == null || !root.getName().equalsIgnoreCase("types")) { log.warn("File '" + IGUIConstants.TYPEDEF_FILE + "' lacks root element 'types'."); } else { - List children; + List<Element> children; // parse all bitmask elements children = root.getChildren("bitmask"); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); if (elem.getAttribute("name") == null) { log.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load bitmask element without 'name'."); } else { @@ -120,7 +120,7 @@ // parse all list elements children = root.getChildren("list"); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); if (elem.getAttribute("name") == null) { log.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); } else { @@ -150,17 +150,17 @@ // parse ignore lists children = root.getChildren("ignore_list"); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); if (elem.getAttribute("name") == null) { log.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); } else { final String lname = elem.getAttribute("name").getValue().trim(); - final List children2 = elem.getChildren(CFArchType.XML_ATTRIBUTE); + final List<Element> children2 = elem.getChildren(CFArchType.XML_ATTRIBUTE); if (children2 != null && children2.size() > 0) { // load all attribute entries - final Vector content = new Vector(); + final Vector<String> content = new Vector<String>(); for (int k = 0; k < children2.size(); k++) { - elem = (Element) children2.get(k); + elem = children2.get(k); if ((a = elem.getAttribute(CFArchAttrib.XML_KEY_ARCH)) != null) { content.addElement(a.getValue().trim()); } else { @@ -176,7 +176,7 @@ // parse all type elements children = root.getChildren("type"); for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); + elem = children.get(i); if (elem.getAttribute("name") == null || elem.getAttribute("number") == null) { log.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': found type element without 'name' or 'number'."); } else { @@ -265,15 +265,15 @@ return spellNum; } - public Map getBitmaskTable() { + public Map<String, CAttribBitmask> getBitmaskTable() { return bitmaskTable; } - public Map getListTable() { + public Map<String, Vector> getListTable() { return listTable; } - public Map getIgnoreListTable() { + public Map<String, Vector<String>> getIgnoreListTable() { return ignoreListTable; } @@ -396,14 +396,14 @@ * @return number of successfully collected spells */ private int importSpells(final File spellfile) { - Vector list = null; // growable array of spellnames+numbers + Vector<String> list = null; // growable array of spellnames+numbers String tmp; // tmp String for spell names final FileWriter fileWriter; // file writer for "spells.def" final BufferedWriter bufferedWriter; // buffered writer if (spellfile.getName().equalsIgnoreCase("spellist.h")) { - list = new Vector(); + list = new Vector<String>(); FileReader fileReader = null; BufferedReader bufferedReader = null; @@ -426,7 +426,7 @@ name = name.trim(); // now insert this string lexographically into the vector for (i = 0; i < list.size(); i++) { - tmp = (String) list.elementAt(i); + tmp = list.elementAt(i); tmp = tmp.substring(tmp.indexOf(" ") + 1); if (name.compareTo(tmp) < 0) { Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-25 08:41:50 UTC (rev 423) @@ -79,16 +79,16 @@ private static final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Treasurelists:"); // hashtable containing references to all treasurelists (tree nodes) - private static Hashtable treasureTable = null; + private static Hashtable<String, TreasureTreeNode> treasureTable = null; // hashtable temporarily containing names of special treasurelists (like gods' lists) // as keys and folder-nodes where to put these treasurelists as values - private Hashtable specialTreasureLists = null; + private Hashtable<String, TreasureTreeNode> specialTreasureLists = null; // all syntax-errors encountered during datafile-parsing get written in this log private StringBuffer errorLog = null; - private Vector needSecondLink; + private Vector<TreasureTreeNode> needSecondLink; private boolean processSecondLinking; @@ -134,7 +134,7 @@ // font CMainControl.getInstance().setPlainFont(this); - needSecondLink = new Vector(); + needSecondLink = new Vector<TreasureTreeNode>(); processSecondLinking = false; // set special cell renderer @@ -160,7 +160,7 @@ * TODO: It would be nice to read this information from a simple datafile. */ public synchronized void initSpecialTreasureLists() { - specialTreasureLists = new Hashtable(); + specialTreasureLists = new Hashtable<String, TreasureTreeNode>(); final TreasureTreeNode godFolder = new TreasureTreeNode("God Intervention", TreasureObj.FOLDER); root.add(godFolder); @@ -240,9 +240,9 @@ * has been parsed. False when there is no data and tree remains empty. */ private boolean parseTreasures() { - final Vector tmpList = new Vector(); // tmp. container for all treasurelists - final Vector needLink = new Vector(); // all sub-treasurelist nodes that need linking - treasureTable = new Hashtable(); // hashtable for all treasureTreeNodes + final Vector<TreasureTreeNode> tmpList = new Vector<TreasureTreeNode>(); // tmp. container for all treasurelists + final Vector<TreasureTreeNode> needLink = new Vector<TreasureTreeNode>(); // all sub-treasurelist nodes that need linking + treasureTable = new Hashtable<String, TreasureTreeNode>(); // hashtable for all treasureTreeNodes // first step: parsing datafile, adding all treasurelists to the tmpList vector try { @@ -285,14 +285,14 @@ // Loop through all treasureone lists and calculate the real ratio // of chances (Summed up to be 100%). Also attach lists to tree model. for (int i = 0; i < tmpList.size(); i++) { - final TreasureTreeNode realNode = (TreasureTreeNode) tmpList.elementAt(i); + final TreasureTreeNode realNode = tmpList.elementAt(i); if (realNode.getTreasureObj().getType() == TreasureObj.TREASUREONE_LIST) { recalculateChances(realNode); } // check for special treasurelists, which are put in subfolders if (specialTreasureLists.containsKey(realNode.getTreasureObj().getName())) { - ((TreasureTreeNode) (specialTreasureLists.get(realNode.getTreasureObj().getName()))).add(realNode); + specialTreasureLists.get(realNode.getTreasureObj().getName()).add(realNode); } else { root.add(realNode); // normal treasurelist - attach to root node } @@ -301,10 +301,10 @@ // link the sub-lists first time for (int i = 0; i < needLink.size(); i++) { // 'node' is a sub-treasurelist which needs to be linked to it's content - final TreasureTreeNode node = (TreasureTreeNode) needLink.elementAt(i); + final TreasureTreeNode node = needLink.elementAt(i); // 'realNode' is the real instance of that treasurelist - final TreasureTreeNode realNode = (TreasureTreeNode) treasureTable.get(node.getTreasureObj().getName()); + final TreasureTreeNode realNode = treasureTable.get(node.getTreasureObj().getName()); if (realNode != null) { // set accurate type of treausrelist (one/multi) @@ -321,10 +321,10 @@ final int x = needSecondLink.size(); for (int i = 0; i < x; i++) { // 'node' is a sub-treasurelist which needs to be linked to it's content - final TreasureTreeNode node = (TreasureTreeNode) needSecondLink.elementAt(i); + final TreasureTreeNode node = needSecondLink.elementAt(i); // 'realNode' is the real instance of that treasurelist - final TreasureTreeNode realNode = (TreasureTreeNode) treasureTable.get(node.getTreasureObj().getName()); + final TreasureTreeNode realNode = treasureTable.get(node.getTreasureObj().getName()); if (realNode != null) { // set accurate type of treausrelist (one/multi) @@ -386,12 +386,12 @@ * is bubblesort because the expected number of objects is low (~300). * @param v Vector to be sorted */ - private void sortVector(final Vector v) { + private void sortVector(final Vector<TreasureTreeNode> v) { for (int j = 0; j < v.size() + 1; j++) { for (int i = 0; i < v.size() - 1; i++) { - if (((TreasureTreeNode) v.elementAt(i)).getTreasureObj().getName().compareToIgnoreCase( - ((TreasureTreeNode) v.elementAt(i + 1)).getTreasureObj().getName()) > 0) { - final Object node = v.elementAt(i); + if (v.elementAt(i).getTreasureObj().getName().compareToIgnoreCase( + v.elementAt(i + 1).getTreasureObj().getName()) > 0) { + final TreasureTreeNode node = v.elementAt(i); v.setElementAt(v.elementAt(i + 1), i); v.setElementAt(node, i + 1); } @@ -404,7 +404,7 @@ * @param parentNode parent treenode * @param needLink vector containing all sub-treasurelist nodes which need linking */ - private void readInsideList(final TreasureTreeNode parentNode, final BufferedReader reader, final Vector needLink) throws IOException { + private void readInsideList(final TreasureTreeNode parentNode, final BufferedReader reader, final Vector<TreasureTreeNode> needLink) throws IOException { String line; // read line of file TreasureTreeNode node = null; // tmp. treenode @@ -574,7 +574,7 @@ // set the position of the scrollbar final DefaultMutableTreeNode[] nnode = new DefaultMutableTreeNode[2]; nnode[0] = root; - nnode[1] = (DefaultMutableTreeNode) treasureTable.get(listName); + nnode[1] = treasureTable.get(listName); final TreePath tpath = new TreePath(nnode); expandPath(tpath); // expand pre-selected treasurelist setSelectionPath(tpath); // select it too Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-25 08:41:50 UTC (rev 423) @@ -145,7 +145,7 @@ private final ArchetypeSet archList; // the one and only arch list /** All open maps. */ - private final Vector levels = new Vector(1, 2); + private final Vector<MapControl> levels = new Vector<MapControl>(1, 2); /** The current top map we are working with */ private MapControl currentMap; @@ -367,8 +367,8 @@ */ void selectEditType(final int newType) { // calculate the new type for all opened maps: - for (Enumeration enu = levels.elements(); enu.hasMoreElements();) { - final MapControl level = (MapControl) enu.nextElement(); + for (Enumeration<MapControl> enu = levels.elements(); enu.hasMoreElements();) { + final MapControl level = enu.nextElement(); level.addEditType(newType); // calculate new type } @@ -666,8 +666,8 @@ // update the look and feel for all open map views if (levels.size() > 0) { - for (final Enumeration enu = levels.elements(); enu.hasMoreElements();) { - final MapControl level = (MapControl) enu.nextElement(); + for (final Enumeration<MapControl> enu = levels.elements(); enu.hasMoreElements();) { + final MapControl level = enu.nextElement(); level.getMapView().updateLookAndFeel(); if (log.isDebugEnabled()) { log.debug("map " + level.getMapName()); @@ -847,8 +847,8 @@ if (levels.size() > 0) { // get next open map we can find and set it to currentMap - for (final Enumeration enu = levels.elements(); enu.hasMoreElements();) { - currentMap = (MapControl) enu.nextElement(); + for (final Enumeration<MapControl> enu = levels.elements(); enu.hasMoreElements();) { + currentMap = enu.nextElement(); } } } @@ -1301,8 +1301,8 @@ /** Invoked when user wants to exit from the program. */ void exitWanted() { if (levels.size() > 0) { - for (final Enumeration enu = levels.elements(); enu.hasMoreElements();) { - final MapControl level = (MapControl) enu.nextElement(); + for (final Enumeration<MapControl> enu = levels.elements(); enu.hasMoreElements();) { + final MapControl level = enu.nextElement(); closeLevel(level, false); } } @@ -1827,7 +1827,7 @@ } public MapControl[] getOpenedMaps() { - return (MapControl[]) levels.toArray(new MapControl[levels.size()]); + return levels.toArray(new MapControl[levels.size()]); } public MapControl getCurrentMap() { Modified: trunk/crossfire/src/cfeditor/CMainToolbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-09-25 08:41:50 UTC (rev 423) @@ -143,7 +143,7 @@ setMargin(new Insets(IGUIConstants.DIALOG_INSETS, 0, IGUIConstants.DIALOG_INSETS, IGUIConstants.DIALOG_INSETS)); - final Vector buttons = new Vector(10, 2); + final Vector<JButton> buttons = new Vector<JButton>(10, 2); m_new = new CFancyButton( checkLabel("New"), "New Map", @@ -265,14 +265,14 @@ // If icons and labels are visible make buttons square shaped if (m_eIconAndLabelVisibility == SHOW_ICONS_AND_LABELS) { int maxWidth = 16; - for (Enumeration enu = buttons.elements(); + for (Enumeration<JButton> enu = buttons.elements(); enu.hasMoreElements();) { - final JButton button = (JButton) enu.nextElement(); + final JButton button = enu.nextElement(); maxWidth = Math.max(maxWidth, button.getWidth()); } - for (final Enumeration enu = buttons.elements(); enu.hasMoreElements();) { - final JButton button = (JButton) enu.nextElement(); + for (final Enumeration<JButton> enu = buttons.elements(); enu.hasMoreElements();) { + final JButton button = enu.nextElement(); final Dimension size = new Dimension(maxWidth, maxWidth); button.setSize(size); button.setMinimumSize(size); Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-09-25 08:41:50 UTC (rev 423) @@ -716,7 +716,7 @@ grfx.fillRect(0, 0, getWidth(), getHeight()); // ---------- draw rectangular map -------------- // this vector contains all heads of multi-tiles with oversized images - final Vector oversizedMultiHeads = new Vector(); + final Vector<GameObject> oversizedMultiHeads = new Vector<GameObject>(); final CFilterControl filter = mainControl.getFilterControl(); for (int y = 0; y < mapSize.getHeight(); y++) { for (int x = 0; x < mapSize.getWidth(); x++) { @@ -771,7 +771,7 @@ } // at the end, we have to draw the oversized multipart images on top of the rest for (int i = 0; i < oversizedMultiHeads.size(); i++) { - final GameObject node = (GameObject) (oversizedMultiHeads.elementAt(i)); + final GameObject node = oversizedMultiHeads.elementAt(i); archlist.getFace(node.getFaceNr()).paintIcon(this, grfx, node.getMapX() * 32 + bOffset, node.getMapY() * 32 + bOffset); } Modified: trunk/crossfire/src/cfeditor/CScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptController.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CScriptController.java 2006-09-25 08:41:50 UTC (rev 423) @@ -46,11 +46,11 @@ private static final Logger log = Logger.getLogger(CScriptController.class); - private final LinkedHashMap scripts = new LinkedHashMap(); + private final LinkedHashMap<String, CScriptModel> scripts = new LinkedHashMap<String, CScriptModel>(); private final CScriptView view; - private final HashSet listeners = new HashSet(); + private final HashSet<ChangeListener> listeners = new HashSet<ChangeListener>(); private final CMainControl mainControl; @@ -66,7 +66,7 @@ } public String[] listScript() { - return (String[]) (scripts.keySet().toArray(new String[]{})); + return scripts.keySet().toArray(new String[]{}); } public void addScript(final CScriptModel script) { @@ -175,8 +175,8 @@ public void exportXML(final OutputStream destination) { final Element root = new Element("scripts"); final Document d = new Document(root); - for (Iterator i = scripts.values().iterator(); i.hasNext();) { - final CScriptModel sm = (CScriptModel) i.next(); + for (Iterator<CScriptModel> i = scripts.values().iterator(); i.hasNext();) { + final CScriptModel sm = i.next(); root.addContent(sm.toXML()); } final XMLOutputter out = new XMLOutputter(); @@ -262,7 +262,7 @@ } public void runScript(final String name) { - final CScriptModel model = (CScriptModel) scripts.get(name); + final CScriptModel model = scripts.get(name); runScript(model); } @@ -282,10 +282,10 @@ } @Nullable public CScriptModel getScript(int index) { - final Iterator i = scripts.values().iterator(); + final Iterator<CScriptModel> i = scripts.values().iterator(); CScriptModel m = null; while (i.hasNext() && index-- >= 0) { - m = (CScriptModel) i.next(); + m = i.next(); } if (index >= 0) { return null; @@ -295,7 +295,7 @@ } public CScriptModel getScript(final String name) { - return (CScriptModel) scripts.get(name); + return scripts.get(name); } public int getScriptCount() { @@ -312,7 +312,7 @@ private void notifyListeners() { final ChangeEvent e = new ChangeEvent(this); - for (Iterator i = listeners.iterator(); i.hasNext(); ((ChangeListener) i.next()).stateChanged(e)) { + for (Iterator<ChangeListener> i = listeners.iterator(); i.hasNext(); i.next().stateChanged(e)) { ; } } Modified: trunk/crossfire/src/cfeditor/CScriptModel.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptModel.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CScriptModel.java 2006-09-25 08:41:50 UTC (rev 423) @@ -49,7 +49,7 @@ private int scriptType; - private final HashSet listeners = new HashSet(); + private final HashSet<ChangeListener> listeners = new HashSet<ChangeListener>(); private final CScriptController ctrl; @@ -234,14 +234,14 @@ } public String[] getParameters() { - final ArrayList l = new ArrayList(); - for (Iterator it = params.iterator(); it.hasNext();) { - final PluginParameter p = (PluginParameter) it.next(); + final ArrayList<String> l = new ArrayList<String>(); + for (Iterator<PluginParameter> it = params.iterator(); it.hasNext();) { + final PluginParameter p = it.next(); if (!l.contains(p.getName())) { l.add(p.getName()); } } - return (String[]) l.toArray(new String[]{}); + return l.toArray(new String[]{}); } private int locateParam(final String name) { @@ -285,7 +285,7 @@ /** Tell all listeners plugged on this CScriptModel its content has changed. */ private void notifyListeners() { final ChangeEvent e = new ChangeEvent(this); - for (Iterator i = listeners.iterator(); i.hasNext(); ((ChangeListener) i.next()).stateChanged(e)) { + for (Iterator<ChangeListener> i = listeners.iterator(); i.hasNext(); i.next().stateChanged(e)) { ; } } @@ -392,9 +392,9 @@ if (mode == null) { scriptType = PLUGIN_SCRIPT; } else { - final List modes = mode.getChildren(); - for (Iterator i = modes.iterator(); i.hasNext();) { - final Element m = (Element) i.next(); + final List<Element> modes = mode.getChildren(); + for (Iterator<Element> i = modes.iterator(); i.hasNext();) { + final Element m = i.next(); final boolean b = Boolean.valueOf(m.getTextTrim()).booleanValue(); final String name = m.getName(); if ("autoboot".equalsIgnoreCase(name) && b) { @@ -406,10 +406,10 @@ } } } - final List params = node.getChildren("parameter"); + final List<Element> params = node.getChildren("parameter"); if (params != null && !params.isEmpty()) { for (int j = 0; j < params.size(); j++) { - final Element parameter = (Element) params.get(j); + final Element parameter = params.get(j); final PluginParameter p = PluginParameterFactory.createParameter(parameter); addParameter(p); } @@ -444,7 +444,7 @@ } root.addContent(modes); - for (Iterator i = params.iterator(); i.hasNext(); root.addContent(((PluginParameter) i.next()).toXML())) { + for (Iterator<PluginParameter> i = params.iterator(); i.hasNext(); root.addContent(i.next().toXML())) { ; } return root; Modified: trunk/crossfire/src/cfeditor/CScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptView.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/CScriptView.java 2006-09-25 08:41:50 UTC (rev 423) @@ -112,7 +112,7 @@ menu.setToolTipText("Manage and use beanshell plugins"); } final String[] scripts = ctrl.listScript(); - final ArrayList visibleScripts = new ArrayList(); + final ArrayList<JMenuItem> visibleScripts = new ArrayList<JMenuItem>(); for (int i = 0; i < scripts.length; i++) { if (!ctrl.getScript(scripts[i]).isBash()) { continue; @@ -125,7 +125,7 @@ menu.add(item); visibleScripts.add(item); } - entryScript = (JMenuItem[]) visibleScripts.toArray(new JMenuItem[0]); + entryScript = visibleScripts.toArray(new JMenuItem[0]); if (entryScript.length == 0) { final JMenuItem def = new JMenuItem("no scripts available"); def.setEnabled(false); Modified: trunk/crossfire/src/cfeditor/FaceObject.java =================================================================== --- trunk/crossfire/src/cfeditor/FaceObject.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/FaceObject.java 2006-09-25 08:41:50 UTC (rev 423) @@ -88,7 +88,7 @@ log.debug("Getting soft reference to " + name); } if (face != null) { - final ImageIcon icon = (ImageIcon) ((Reference) face).get(); + final ImageIcon icon = ((Reference<ImageIcon>) face).get(); if (icon != null) { return icon; } @@ -124,7 +124,7 @@ public void setFace(final ImageIcon im) { if (isLazyLoading) { - face = new SoftReference(im); + face = new SoftReference<ImageIcon>(im); } else { face = im; } Modified: trunk/crossfire/src/cfeditor/JFontChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/JFontChooser.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/JFontChooser.java 2006-09-25 08:41:50 UTC (rev 423) @@ -244,7 +244,7 @@ } protected void updateFont() { - final Map fontAttrs = new HashMap(); + final Map<TextAttribute, Object> fontAttrs = new HashMap<TextAttribute, Object>(); fontAttrs.put(TextAttribute.FAMILY, (String) familyCombo.getSelectedItem()); fontAttrs.put(TextAttribute.SIZE, new Float((String) sizeCombo.getSelectedItem())); Modified: trunk/crossfire/src/cfeditor/JarResources.java =================================================================== --- trunk/crossfire/src/cfeditor/JarResources.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/JarResources.java 2006-09-25 08:41:50 UTC (rev 423) @@ -55,9 +55,9 @@ private static final Logger log = Logger.getLogger(JarResources.class); // jar resource mapping tables - private final Hashtable htSizes = new Hashtable(); + private final Hashtable<String, Integer> htSizes = new Hashtable<String, Integer>(); - private final Hashtable htJarContents = new Hashtable(); + private final Hashtable<String, byte[]> htJarContents = new Hashtable<String, byte[]>(); // a jar file private String jarFileName; @@ -97,7 +97,7 @@ * @return array of bytes */ public byte[] getResource(final String name) { - return (byte[]) htJarContents.get(name); + return htJarContents.get(name); } /** initializes internal hash tables with Jar file resources. */ @@ -105,9 +105,9 @@ try { // extracts just sizes only. final ZipFile zf = new ZipFile(jarFileName); - final Enumeration e = zf.entries(); + final Enumeration<? extends ZipEntry> e = zf.entries(); while (e.hasMoreElements()) { - final ZipEntry ze = (ZipEntry) e.nextElement(); + final ZipEntry ze = e.nextElement(); if (log.isDebugEnabled()) { log.debug(dumpZipEntry(ze)); } @@ -131,7 +131,7 @@ int size = (int) ze.getSize(); // -1 means unknown size. if (size == -1) { - size = ((Integer) htSizes.get(ze.getName())).intValue(); + size = htSizes.get(ze.getName()).intValue(); } final byte[] b = new byte[(int) size]; int rb = 0; Modified: trunk/crossfire/src/cfeditor/PluginParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/PluginParameter.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/PluginParameter.java 2006-09-25 08:41:50 UTC (rev 423) @@ -29,7 +29,7 @@ private String name; - private final HashSet listeners = new HashSet(); + private final HashSet<ChangeListener> listeners = new HashSet<ChangeListener>(); protected String parameterType; @@ -104,7 +104,7 @@ protected void fireDataChanged() { final ChangeEvent e = new ChangeEvent(this); - for (Iterator i = listeners.iterator(); i.hasNext(); ((ChangeListener) i.next()).stateChanged(e)) { + for (Iterator<ChangeListener> i = listeners.iterator(); i.hasNext(); i.next().stateChanged(e)) { ; } } Modified: trunk/crossfire/src/cfeditor/PluginParameterFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/PluginParameterFactory.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/PluginParameterFactory.java 2006-09-25 08:41:50 UTC (rev 423) @@ -29,10 +29,10 @@ private static final Logger log = Logger.getLogger(PluginParameterFactory.class); - private static final LinkedHashMap parameterTypes; + private static final LinkedHashMap<String, Class<? extends PluginParameter>> parameterTypes; static { - parameterTypes = new LinkedHashMap(); + parameterTypes = new LinkedHashMap<String, Class<? extends PluginParameter>>(); parameterTypes.put(StringParameter.getParameterType(), StringParameter.class); parameterTypes.put(IntegerParameter.getParameterType(), IntegerParameter.class); parameterTypes.put(DoubleParameter.getParameterType(), DoubleParameter.class); @@ -55,7 +55,7 @@ type = "java.lang.String"; } - final Class c = (Class) parameterTypes.get(type); + final Class<? extends PluginParameter> c = parameterTypes.get(type); if (c == null) { return null; } @@ -65,7 +65,7 @@ log.debug("trying to instance a class of type " + c.getName()); } - final PluginParameter p = (PluginParameter) c.newInstance(); + final PluginParameter p = c.newInstance(); return p; } catch (final Exception e) { e.printStackTrace(); @@ -78,13 +78,13 @@ type = "java.lang.String"; } - final Class c = (Class) parameterTypes.get(type); + final Class<? extends PluginParameter> c = parameterTypes.get(type); if (c == null) { return null; } try { - final PluginParameter p = (PluginParameter) c.newInstance(); + final PluginParameter p = c.newInstance(); p.fromXML(parameterNode); return p; } catch (Exception e) { @@ -98,6 +98,6 @@ } public static String[] getTypes() { - return (String[]) parameterTypes.keySet().toArray(new String[parameterTypes.size()]); + return parameterTypes.keySet().toArray(new String[parameterTypes.size()]); } } Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-09-25 08:41:50 UTC (rev 423) @@ -170,7 +170,7 @@ private AutojoinList join; // if nonzero, pointing to the list of autojoining archetypes - private final HashMap cachedAttribute = new HashMap(); + private final HashMap<String, String> cachedAttribute = new HashMap<String, String>(); /** Create an GameObject. */ public GameObject() { @@ -610,7 +610,7 @@ } if (inv == Collections.EMPTY_LIST) { - inv = new LinkedList(); + inv = new LinkedList<GameObject>(); } inv.add(arch); @@ -1480,7 +1480,7 @@ } private String getCachedAttributeValue(final String name) { - return (String) cachedAttribute.get(name); + return cachedAttribute.get(name); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gui/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-09-25 08:41:50 UTC (rev 423) @@ -303,7 +303,7 @@ private String currentFilter = ""; - private ArrayList subFilters = new ArrayList(); + private ArrayList<GameObject[]> subFilters = new ArrayList<GameObject[]>(); private static final long serialVersionUID = 1L; @@ -312,9 +312,9 @@ for (int i = 0; i < mainControl.getArchCount(); i++) { archList[i] = mainControl.getArch(i); } - Arrays.sort(archList, new Comparator() { - public int compare(final Object o1, final Object o2) { - return ((GameObject) o1).getArchetypeName().toLowerCase().compareTo(((GameObject) o2).getArchetypeName().toLowerCase()); + Arrays.sort(archList, new Comparator<GameObject>() { + public int compare(final GameObject o1, final GameObject o2) { + return o1.getArchetypeName().toLowerCase().compareTo(o2.getArchetypeName().toLowerCase()); } }); subFilters.add(archList); @@ -366,7 +366,7 @@ } private GameObject getNearsetMatch(final String name) { - int pos = Arrays.binarySearch(archList, name, new Comparator() { + int pos = Arrays.binarySearch(archList, name, new Comparator<Object>() { public int compare(final Object o1, final Object o2) { final String s1; final String s2; Modified: trunk/crossfire/src/cfeditor/gui/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2006-09-25 08:41:50 UTC (rev 423) @@ -73,13 +73,13 @@ private String uuid = null; - private final Hashtable paramNameEditors = new Hashtable(); + private final Hashtable<PluginParameter, ParameterNameEditor> paramNameEditors = new Hashtable<PluginParameter, ParameterNameEditor>(); - private final Hashtable paramDescriptionEditors = new Hashtable(); + private final Hashtable<PluginParameter, ParameterDescriptionEditor> paramDescriptionEditors = new Hashtable<PluginParameter, ParameterDescriptionEditor>(); - private final Hashtable paramTypeEditors = new Hashtable(); + private final Hashtable<PluginParameter, ParameterTypeEditor> paramTypeEditors = new Hashtable<PluginParameter, ParameterTypeEditor>(); - private final Hashtable paramViews = new Hashtable(); + private final Hashtable<PluginParameter, PluginParameterView> paramViews = new Hashtable<PluginParameter, PluginParameterView>(); private int selectedRow = -1; @@ -318,7 +318,7 @@ log.debug("Doing " + param); } - ParameterNameEditor o = (ParameterNameEditor) paramNameEditors.get(param); + ParameterNameEditor o = paramNameEditors.get(param); if (o != null) { return o; } @@ -330,7 +330,7 @@ } private ParameterDescriptionEditor getParameterDescriptionEditor(final PluginParameter param) { - ParameterDescriptionEditor o = (ParameterDescriptionEditor) paramDescriptionEditors.get(param); + ParameterDescriptionEditor o = paramDescriptionEditors.get(param); if (o != null) { return o; } @@ -342,7 +342,7 @@ } private ParameterTypeEditor getParameterTypeEditor(final PluginParameter param) { - ParameterTypeEditor o = (ParameterTypeEditor) paramTypeEditors.get(param); + ParameterTypeEditor o = paramTypeEditors.get(param); if (o != null) { return o; } @@ -354,7 +354,7 @@ } private PluginParameterView getParameterView(final PluginParameter param) { - PluginParameterView o = (PluginParameterView) paramViews.get(param); + PluginParameterView o = paramViews.get(param); if (o != null) { return o; } Modified: trunk/crossfire/src/cfeditor/gui/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2006-09-25 08:41:50 UTC (rev 423) @@ -51,7 +51,7 @@ private final CScriptController ctrl; - private final HashMap components = new HashMap(); + private final HashMap<CScriptModel, ScriptEditor> components = new HashMap<CScriptModel, ScriptEditor>(); private static final long serialVersionUID = 1L; @@ -158,7 +158,7 @@ return; } - ScriptEditor c = (ScriptEditor) components.get(model); + ScriptEditor c = components.get(model); if (c == null) { c = new ScriptEditor(model); components.put(model, c); @@ -168,7 +168,7 @@ } private void removeScript(final CScriptModel model) { - final ScriptEditor c = (ScriptEditor) components.get(model); + final ScriptEditor c = components.get(model); if (c != null) { components.remove(model); scriptPanel.remove(c); Modified: trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/menu/AggregateMenuLocation.java 2006-09-25 08:41:50 UTC (rev 423) @@ -77,7 +77,7 @@ * List of handled submenus as AggregateMenuLocation.WrappedMenuLocation * objects. */ - private final LinkedHashMap subMenus; + private final LinkedHashMap<String, WrappedMenuLocation> subMenus; private String name; @@ -85,7 +85,7 @@ public AggregateMenuLocation(final String name) { super(name); - subMenus = new LinkedHashMap(); + subMenus = new LinkedHashMap<String, WrappedMenuLocation>(); } public void addMenuLocation(final MenuLocation location) { @@ -108,7 +108,7 @@ * AggregateMenuLocation name as parent. It is a relative path. */ @Nullable public MenuLocation getMenuLocation(final String location) { - final WrappedMenuLocation wml = (WrappedMenuLocation) subMenus.get(location); + final WrappedMenuLocation wml = subMenus.get(location); if (wml != null) { return wml.getLocation(); } else { @@ -121,8 +121,8 @@ return true; } - for (Iterator i = subMenus.values().iterator(); i.hasNext();) { - if (((MenuLocation) i.next()).contains(entry)) { + for (Iterator<WrappedMenuLocation> i = subMenus.values().iterator(); i.hasNext();) { + if (i.next().contains(entry)) { return true; } } @@ -140,8 +140,8 @@ } this.menuManager = menuManager; if (!subMenus.isEmpty()) { - for (Iterator i = subMenus.values().iterator(); i.hasNext();) { - menuManager.addMenuLocation((MenuLocation) i.next()); + for (Iterator<WrappedMenuLocation> i = subMenus.values().iterator(); i.hasNext();) { + menuManager.addMenuLocation(i.next()); } } } Modified: trunk/crossfire/src/cfeditor/menu/BasicMenuEntry.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/BasicMenuEntry.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/menu/BasicMenuEntry.java 2006-09-25 08:41:50 UTC (rev 423) @@ -35,11 +35,11 @@ private char mnemonic; - private final ArrayList listeners = new ArrayList(); + private final ArrayList<ActionListener> listeners = new ArrayList<ActionListener>(); - private final ArrayList refs = new ArrayList(); + private final ArrayList<WeakReference<JComponent>> refs = new ArrayList<WeakReference<JComponent>>(); - private final ReferenceQueue componentQueue = new ReferenceQueue(); + private final ReferenceQueue<JComponent> componentQueue = new ReferenceQueue<JComponent>(); private String name; @@ -88,10 +88,10 @@ return action; } - private void referenceItem(final Object item) { + private void referenceItem(final JComponent item) { log.debug("referenceMenuItem()"); synchronized (refs) { - refs.add(new WeakReference(item, componentQueue)); + refs.add(new WeakReference<JComponent>(item, componentQueue)); } } @@ -118,9 +118,9 @@ public void actionPerformed(final ActionEvent e) { synchronized (listeners) { - for (Iterator i = listeners.iterator(); i.hasNext();) { + for (Iterator<ActionListener> i = listeners.iterator(); i.hasNext();) { log.debug("One more actionPerformed Listerner"); - ((ActionListener) i.next()).actionPerformed(e); + i.next().actionPerformed(e); } } log.debug("Acton performed done"); @@ -136,9 +136,9 @@ update(); cleanUpQueue(componentQueue); synchronized (refs) { - for (Iterator i = refs.iterator(); i.hasNext();) { - final WeakReference wf = (WeakReference) i.next(); - final JComponent item = (JComponent) wf.get(); + for (Iterator<WeakReference<JComponent>> i = refs.iterator(); i.hasNext();) { + final WeakReference<JComponent> wf = i.next(); + final JComponent item = wf.get(); if (log.isDebugEnabled()) { log.debug("Updating item: " + item); } Modified: trunk/crossfire/src/cfeditor/menu/MenuManager.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/MenuManager.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/menu/MenuManager.java 2006-09-25 08:41:50 UTC (rev 423) @@ -17,9 +17,9 @@ private final Logger log = Logger.getLogger(MenuManager.class); - private final HashMap locations = new HashMap(); + private final HashMap<String, MenuLocation> locations = new HashMap<String, MenuLocation>(); - private final HashMap listeners = new HashMap(); + private final HashMap<String, Set<MenuListener>> listeners = new HashMap<String, Set<MenuListener>>(); private static final MenuManager theManager = new MenuManager(); @@ -34,7 +34,7 @@ * @param entry the MenuEntry to add to the location */ public void addMenuEntry(final String location, final MenuEntry entry) { /** lock-end */ - final MenuLocation loc = (MenuLocation) locations.get(location); + final MenuLocation loc = locations.get(location); if (loc == null) { log.warn("Location " + location + " was not found to add a menu entry"); } else { @@ -46,11 +46,11 @@ * i wrote this code without thinking *** - Iterator i = locations.keySet().iterator(); + Iterator<String> i = locations.keySet().iterator(); for (; i.hasNext(); ) { Object o = i.next(); if (location.equals(o)) { - ((MenuLocation)locations.get(o)).addMenuEntry(entry); + locations.get(o).addMenuEntry(entry); return; } } @@ -65,9 +65,9 @@ */ public void removeMenuEntry(final MenuEntry entry) { log.debug("Removing all instance of a menu entry"); - final Iterator i = locations.values().iterator(); + final Iterator<MenuLocation> i = locations.values().iterator(); for (; i.hasNext();) { - ((MenuLocation) i.next()).removeMenuEntry(entry); + i.next().removeMenuEntry(entry); } } @@ -81,7 +81,7 @@ log.debug("removing MenuEntry " + entry + " from " + location); } - final MenuLocation loc = (MenuLocation) locations.get(location); + final MenuLocation loc = locations.get(location); if (loc == null) { log.warn("Location " + location + " was not found to remove a menu entry"); } else { @@ -119,17 +119,17 @@ log.debug("GetMenuLocation called for " + location); } } - return (MenuLocation) locations.get(location); + return locations.get(location); } - private Set getListeners(final String location) { + private Set<MenuListener> getListeners(final String location) { if (log.isDebugEnabled()) { log.debug("returning Listeners for " + location); } - Set listeners = (Set) this.listeners.get(location); + Set<MenuListener> listeners = this.listeners.get(location); if (listeners == null) { - listeners = new HashSet(); + listeners = new HashSet<MenuListener>(); this.listeners.put(location, listeners); } return listeners; @@ -151,7 +151,7 @@ log.warn("Adding a Listener to an inexistent Location: " + location); } - final Set listeners = getListeners(location); + final Set<MenuListener> listeners = getListeners(location); listeners.add(listener); } @@ -164,8 +164,8 @@ log.debug("Removing listener " + listener + " from all locations"); } - for (Iterator i = listeners.values().iterator(); i.hasNext();) { - final Set s = (Set) i.next(); + for (Iterator<Set<MenuListener>> i = listeners.values().iterator(); i.hasNext();) { + final Set<MenuListener> s = i.next(); s.remove(listener); } } @@ -183,12 +183,12 @@ log.debug("fireMenuEntryChange(" + location + ", " + entry + ", " + type); } - final MenuLocation loc = (MenuLocation) locations.get(location); + final MenuLocation loc = locations.get(location); if (loc != null) { - final Set s = getListeners(location); + final Set<MenuListener> s = getListeners(location); final MenuChangeEvent e = new MenuChangeEvent(loc, entry, type); - for (Iterator i = s.iterator(); i.hasNext();) { - ((MenuListener) (i.next())).menuChanged(e); + for (Iterator<MenuListener> i = s.iterator(); i.hasNext();) { + i.next().menuChanged(e); } } else { log.warn("Tried to notify a change to unknown location " + location); @@ -207,9 +207,9 @@ log.debug("fireMenuEntryChange(" + entry + ", " + type); } - final HashSet l = new HashSet(); - for (Iterator i = locations.values().iterator(); i.hasNext();) { - final MenuLocation ml = ((MenuLocation) i.next()); + final HashSet<MenuListener> l = new HashSet<MenuListener>(); + for (Iterator<MenuLocation> i = locations.values().iterator(); i.hasNext();) { + final MenuLocation ml = i.next(); if (!ml.contains(entry)) { continue; } @@ -221,8 +221,8 @@ * ensure each listener is notified only once. */ final MenuChangeEvent e = new MenuChangeEvent(null, entry, type); - for (Iterator i = l.iterator(); i.hasNext();) { - ((MenuListener) i.next()).menuChanged(e); + for (Iterator<MenuListener> i = l.iterator(); i.hasNext();) { + i.next().menuChanged(e); } } Modified: trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java =================================================================== --- trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java 2006-09-24 23:04:34 UTC (rev 422) +++ trunk/crossfire/src/cfeditor/menu/SimpleMenuLocation.java 2006-09-25 08:41:50 UTC (rev 423) @@ -18,7 +18,7 @@ */ public class SimpleMenuLocation implements MenuLocation { - private final LinkedHashSet entries; + private final LinkedHashSet<MenuEntry> entries; private final String name; @@ -28,7 +28,7 @@ */ public SimpleMenuLocation(final String name) { super(); - entries = new LinkedHashSet(); + entries = new LinkedHashSet<MenuEntry>(); this.name = name; } @@ -57,9 +57,9 @@ } /** @see MenuLocation#getMenuEntries() */ - public Set getMenuEntries() { + public Set<MenuEntry> getMenuEntries() { synchronized (entries) { - return (Set) entries.clone(); + return (Set<MenuEntry>) entries.clone(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-09-30 10:39:23
|
Revision: 434 http://svn.sourceforge.net/gridarta/?rev=434&view=rev Author: akirschbaum Date: 2006-09-30 03:39:11 -0700 (Sat, 30 Sep 2006) Log Message: ----------- Unify GameObject instantiation. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-09-29 22:23:07 UTC (rev 433) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-09-30 10:39:11 UTC (rev 434) @@ -278,7 +278,7 @@ final GameObject invnew; if (arch.isArchetype()) { // create a new copy of a default arch - invnew = mainControl.getArchObjectStack().newArchObjectInstance(arch.getArchetypeName()); + invnew = arch.createArch(); } else { // create clone from a pickmap invnew = arch.createClone(inv.getMapX(), inv.getMapY()); Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-09-29 22:23:07 UTC (rev 433) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-09-30 10:39:11 UTC (rev 434) @@ -362,19 +362,14 @@ } else { newHead = arch.createClone(pos.x, pos.y); for (GameObject tmp = arch.getArchetype().getMultiNext(); tmp != null; tmp = tmp.getMultiNext()) { - final GameObject newTail = mainControl.getArchObjectStack().newArchObjectInstance(tmp.getArchetypeName()); + final Point mapPos = new Point(pos.x + tmp.getMultiX(), pos.y + tmp.getMultiY()); - final Point mapPos = new Point(pos.x + newTail.getMultiX(), pos.y + newTail.getMultiY()); - if (!mapControl.isPointValid(mapPos)) { // outside map return; } - newTail.setMultiX(tmp.getMultiX()); - newTail.setMultiY(tmp.getMultiY()); - newTail.setMapX(mapPos.x); - newTail.setMapY(mapPos.y); + final GameObject newTail = tmp.createClone(mapPos.x, mapPos.y); newHead.addTailPart(newTail); } Modified: trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-09-29 22:23:07 UTC (rev 433) +++ trunk/crossfire/src/cfeditor/gameobject/ArchObjectParser.java 2006-09-30 10:39:11 UTC (rev 434) @@ -567,9 +567,8 @@ // do insertion for all non-head parts of the multi for (GameObject oldPart = defarch.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { - final GameObject newarch = mainControl.getArchObjectStack().newArchObjectInstance(oldPart.getArchetypeName()); + final GameObject newarch = oldPart.createArch(); - assert newarch != null; arch.addTailPart(newarch); objects.add(newarch); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-09-29 22:23:07 UTC (rev 433) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-09-30 10:39:11 UTC (rev 434) @@ -175,38 +175,13 @@ * @return default GameObject for <var>archname</var> or <code>null</code> * if no such GameObject exists * - * @see #newArchObjectInstance(String) for a similar method that instantiates. + * @see GameObject#createArch() for a similar method that instantiates. */ @Nullable public GameObject getArch(final String archname) { return arches.get(archname); } /** - * Create a GameObject for the specified archetype name. - * - * @param archname the archetype name - * - * @return GameObject instantiated from the specified archetype - */ - @Nullable public GameObject newArchObjectInstance(final String archname) { - final GameObject template = getArch(archname); - if (template == null) { - return null; - } - - final GameObject arch = new GameObject(); - arch.setArchetypeName(template.getArchetypeName()); - if (!template.getFaceFlag()) { - arch.setFaceNr(template.getFaceNr()); - } - - arch.setArchetypeName(template.getArchetypeName()); - arch.setMultiX(template.getMultiX()); - arch.setMultiY(template.getMultiY()); - return arch; - } - - /** * Adds an GameObject to the stack. * Only invoke this method if the GameObject is an Archetype. * Do not invoke this method on map arches. Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-09-29 22:23:07 UTC (rev 433) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-09-30 10:39:11 UTC (rev 434) @@ -1447,6 +1447,26 @@ } } + /** + * Create a new GameObject from this Archetype. + * If this GameObject is not an Archetype, this method recursively forwards to its Archetype. + * @return new GameObject + */ + public GameObject createArch() { + if (!isArchetype()) { + return archetype.createArch(); + } + final GameObject arch = new GameObject(); + arch.setArchetypeName(archetypeName); + arch.setArchetype(this); + if (!getFaceFlag()) { + arch.setFaceNr(getFaceNr()); + } + arch.setMultiX(multiX); + arch.setMultiY(multiY); + return arch; + } + private void setCachedAttributeValue(final String name, final String value) { cachedAttribute.put(name, value); } Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-29 22:23:07 UTC (rev 433) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-30 10:39:11 UTC (rev 434) @@ -488,7 +488,7 @@ GameObject newHead = null; for (GameObject oldPart = newarch; oldPart != null; oldPart = oldPart.getMultiNext()) { - final GameObject newPart = mainControl.getArchObjectStack().newArchObjectInstance(oldPart.getArchetypeName()); + final GameObject newPart = oldPart.createArch(); if (oldPart == newarch) { newHead = newPart; } else { @@ -602,7 +602,7 @@ archname = newarch.getArchetypeName(); } // create a new copy of a default arch - invnew = mainControl.getArchObjectStack().newArchObjectInstance(archname); + invnew = getDefaultArch(archname).createArch(); } else { // create clone from a pickmap if (!newarch.isMulti()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-10-02 17:46:59
|
Revision: 454 http://svn.sourceforge.net/gridarta/?rev=454&view=rev Author: akirschbaum Date: 2006-10-02 10:46:54 -0700 (Mon, 02 Oct 2006) Log Message: ----------- Rename variable and function names. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-02 17:34:02 UTC (rev 453) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-02 17:46:54 UTC (rev 454) @@ -579,7 +579,7 @@ /** Serial Version UID. */ private static final long serialVersionUID = 1L; - private final MapModel _model; + private final MapModel mapModel; // 32x32 Image and Icon for temprary storing tiles before drawing private Image tmpImage; @@ -604,8 +604,8 @@ private final AffineTransform renderTransform; /** Constructor */ - CFlatLevelRenderer(final MapModel model, final boolean pickmap) { - _model = model; + CFlatLevelRenderer(final MapModel mapModel, final boolean pickmap) { + this.mapModel = mapModel; af = new AttributeFilter(); af.addAttribute("no_pass", "1"); @@ -721,7 +721,7 @@ for (int y = 0; y < mapSize.getHeight(); y++) { for (int x = 0; x < mapSize.getWidth(); x++) { filter.newSquare(); - if (!_model.containsArchObject(x, y)) { + if (!mapModel.containsArchObject(x, y)) { // empty square if (isPickmap) { grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); @@ -729,7 +729,7 @@ mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); } } else { - final Iterator it = _model.getArchObjects(x, y); + final Iterator it = mapModel.getArchObjects(x, y); while (it.hasNext()) { final GameObject node = (GameObject) it.next(); filter.objectInSquare(node); @@ -824,7 +824,7 @@ final CFilterControl filter = mainControl.getFilterControl(); filter.newSquare(); // first, draw the object's faces: - if (!_model.containsArchObject(x, y)) { + if (!mapModel.containsArchObject(x, y)) { // draw the empty-tile icon (direcly to the mapview) if (isPickmap) { grfx.setColor(IGUIConstants.BG_COLOR); @@ -835,7 +835,7 @@ } else { tmpGrfx.fillRect(0, 0, 32, 32); // loop through all arches on that square and draw em - final Iterator it = _model.getArchObjects(x, y); + final Iterator it = mapModel.getArchObjects(x, y); while (it.hasNext()) { final GameObject node = (GameObject) it.next(); @@ -876,7 +876,7 @@ } // We have been drawing to the tmp. buffer, now convert it to // an ImageIcon and paint it into the mapview: - if (_model.containsArchObject(x, y)) { + if (mapModel.containsArchObject(x, y)) { tmpIcon.setImage(tmpImage); tmpIcon.paintIcon(this, grfx, x * 32, y * 32); } Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-10-02 17:34:02 UTC (rev 453) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-10-02 17:46:54 UTC (rev 454) @@ -99,7 +99,7 @@ * @param mapControl MapControl of the active map where we copy from */ public void clear(final MapControl mapControl) { - CopyNCut(mapControl, DO_CLEAR); + copyNCut(mapControl, DO_CLEAR); } /** @@ -107,7 +107,7 @@ * @param mapControl MapControl of the active map where we copy from */ public void cut(final MapControl mapControl) { - CopyNCut(mapControl, DO_CUT); + copyNCut(mapControl, DO_CUT); } /** @@ -115,7 +115,7 @@ * @param mapControl MapControl of the active map where we copy from */ public void copy(final MapControl mapControl) { - CopyNCut(mapControl, DO_COPY); + copyNCut(mapControl, DO_COPY); } /** @@ -124,7 +124,7 @@ * @param mapControl MapControl of the active map where we copy from * @param mode defines if we have a cut, copy or paste action */ - private void CopyNCut(final MapControl mapControl, final int mode) { + private void copyNCut(final MapControl mapControl, final int mode) { final Point startp = mapControl.getMapView().getHighlightStart(); // start of highlighted rect final Point offset = mapControl.getMapView().getHighlightOffset(); // offset of rect from startp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-10-03 17:12:20
|
Revision: 471 http://svn.sourceforge.net/gridarta/?rev=471&view=rev Author: akirschbaum Date: 2006-10-03 10:11:54 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Unify MapSquare implementation. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CMapFileDecode.java trunk/crossfire/src/cfeditor/CMapFileEncode.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/map/MapModel.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java trunk/crossfire/src/cfeditor/map/MapSquare.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/GameObjectIterator.java trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteGameMapObject.java trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteMapGame.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-10-03 17:11:54 UTC (rev 471) @@ -27,6 +27,7 @@ import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; import cfeditor.map.MapModel; +import java.awt.Point; import java.io.FileNotFoundException; import java.io.IOException; import net.sf.gridarta.io.CFileReader; @@ -310,9 +311,8 @@ * @return arch which is part of this joinlist, null if no such arch exists */ @Nullable private GameObject findArchOfJoinlist(final MapModel map, final int x, final int y) { - GameObject tmpArch = map.getTopArchObject(x, y); // we look through the arches at the given location (top to bottom): - for (; tmpArch != null; tmpArch = tmpArch.getPrev()) { + for (final GameObject tmpArch : map.getMapSquare(new Point(x, y)).reverse()) { if (stack.getArchetype(tmpArch.getArchetypeName()).getJoinList() == this) { return tmpArch; // we found an arch } Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-10-03 17:11:54 UTC (rev 471) @@ -274,11 +274,11 @@ } void moveTileUp(final GameObject arch, final boolean refresh) { - currentMap.getMapModel().moveTileUp(arch, refresh); + arch.moveUp(); // XXX: ignores refresh } void moveTileDown(final GameObject arch, final boolean refresh) { - currentMap.getMapModel().moveTileDown(arch, refresh); + arch.moveDown(); // XXX: ignores refresh } /** collect CF arches */ Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-10-03 17:11:54 UTC (rev 471) @@ -307,7 +307,7 @@ // now try to get the topmost object GameObject arch = null; if (pmap.isPointValid(pmap.getMapView().getHighlightStart())) { - arch = pmap.getMapModel().getBottomArchObject(pmap.getMapView().getHighlightStart()); + arch = pmap.getMapModel().getMapSquare(pmap.getMapView().getHighlightStart()).getFirst(); } if (arch != null) { // so here we return the arch from the pickmap Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-10-03 17:11:54 UTC (rev 471) @@ -284,7 +284,7 @@ invnew = arch.createClone(inv.getMapX(), inv.getMapY()); } - inv.addInvObj(invnew); + inv.addLast(invnew); mainControl.getArchObjectParser().postParseMapArch(invnew, 0); mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), inv.getMyID()); mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified Modified: trunk/crossfire/src/cfeditor/CMapFileDecode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-10-03 17:11:54 UTC (rev 471) @@ -165,7 +165,7 @@ // ok, we have setup our arch, now check for inventory if (container != null) { - container.addInvObj(arch); + container.addLast(arch); } } } Modified: trunk/crossfire/src/cfeditor/CMapFileEncode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileEncode.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMapFileEncode.java 2006-10-03 17:11:54 UTC (rev 471) @@ -85,9 +85,7 @@ 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++) { - final Iterator it = mapModel.getArchObjects(pos); - while (it.hasNext()) { - final GameObject node = (GameObject) it.next(); + for (final GameObject node : mapModel.getMapSquare(pos)) { // only non multi suckers if (!node.isMulti()) { if (!writeMapArch(node, false)) { @@ -101,9 +99,7 @@ // 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++) { - final Iterator it = mapModel.getArchObjects(pos); - while (it.hasNext()) { - final GameObject node = (GameObject) it.next(); + for (final GameObject node : mapModel.getMapSquare(pos)) { // search only for heads! if (node.isMulti() && node.isHead()) { // only the heads get stored in the mapfile Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-10-03 17:11:54 UTC (rev 471) @@ -314,33 +314,29 @@ postSelect = -1; listCounter = 0; currentSquare = map.getMapModel().getMouseRightPos(); - GameObject node = map.getMapModel().getMouseRightPosObject(); - // Jump to the end of the list - for (; node != null && node.getNext() != null; node = node.getNext()) { - ; - } + if (currentSquare != null) { + // Now go through the list backwards and put all arches + // on the panel in this order + for (final GameObject node : map.getMapModel().getMapSquare(currentSquare).reverse()) { + // add the node + if (node.getMyID() == archid) { + postSelect = listCounter; + } + final String num = Integer.toString(node.getMyID()); + String liststring = listDef.substring(0, 10 - num.length()) + num; + liststring += listDef; + listCounter++; + model.addElement(liststring); - // Now go through the list backwards and put all arches - // on the panel in this order - for (; node != null; node = node.getPrev()) { - // add the node - if (node.getMyID() == archid) { - postSelect = listCounter; - } - final String num = Integer.toString(node.getMyID()); - String liststring = listDef.substring(0, 10 - num.length()) + num; - liststring += listDef; - listCounter++; - model.addElement(liststring); + // 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 + } - // 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 + addInvObjects(node, archid, 1); // browse the inventory of the map object } - - addInvObjects(node, archid, 1); // browse the inventory of the map object } if (postSelect != -1) { Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-10-03 17:11:54 UTC (rev 471) @@ -729,9 +729,7 @@ mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); } } else { - final Iterator it = mapModel.getArchObjects(x, y); - while (it.hasNext()) { - final GameObject node = (GameObject) it.next(); + for (final GameObject node : mapModel.getMapSquare(new Point(x, y))) { filter.objectInSquare(node); if (!filter.canShow(node)) { continue; @@ -835,10 +833,7 @@ } else { tmpGrfx.fillRect(0, 0, 32, 32); // loop through all arches on that square and draw em - final Iterator it = mapModel.getArchObjects(x, y); - while (it.hasNext()) { - final GameObject node = (GameObject) it.next(); - + for (final GameObject node : mapModel.getMapSquare(new Point(x, y))) { filter.objectInSquare(node); if (!filter.canShow(node)) { continue; @@ -1242,23 +1237,20 @@ } else { // delete the topmost arch (matching the view settings) // on that square and redraw the map - GameObject tmpArch = mapControl.getBottomArchObject(temp); - if (tmpArch != null) { - // go to the topmost arch (end of the list) - for (; tmpArch.getNext() != null; tmpArch = tmpArch.getNext()) { - ; - } + GameObject tmpArch = null; + final Iterator<GameObject> it = mapControl.getMapModel().getMapSquare(temp).reverse().iterator(); + while (it.hasNext()) { + tmpArch = it.next(); // now search backwards for matching view settings - for (; tmpArch != null && mainControl.getTileEdit() != 0 && - !mainControl.isTileEdit(tmpArch.getEditType()); tmpArch = tmpArch.getPrev()) { - ; + if (mainControl.getTileEdit() == 0 || mainControl.isTileEdit(tmpArch.getEditType())) { + break; } - if (tmpArch != null) { - needRedraw = calcArchRedraw(tmpArch); // get redraw info - mapControl.deleteMapArch(tmpArch.getMyID(), temp, false, MapModel.JOIN_ENABLE); - } } + if (tmpArch != null) { + needRedraw = calcArchRedraw(tmpArch); // get redraw info + mapControl.deleteMapArch(tmpArch.getMyID(), temp, false, MapModel.JOIN_ENABLE); + } needMpanelUpdate[1] = true; // when dragging is done, update map panel } @@ -1367,23 +1359,18 @@ // delete the topmost arch (matching the view settings) on that square // and redraw the map - GameObject tmpArch = mapControl.getBottomArchObject(mapLoc); - if (tmpArch != null) { - // go to the topmost arch (end of the list) - for (; tmpArch.getNext() != null; tmpArch = tmpArch.getNext()) { - ; + GameObject tmpArch = null; + final Iterator<GameObject> it = mapControl.getMapModel().getMapSquare(mapLoc).reverse().iterator(); + while (it.hasNext()) { + tmpArch = it.next(); + if (mainControl.getTileEdit() == 0 || mainControl.isTileEdit(tmpArch.getEditType())) { + break; } + } + if (tmpArch != null) { + needRedraw = calcArchRedraw(tmpArch); // get redraw info + mapControl.deleteMapArch(tmpArch.getMyID(), mapLoc, false, MapModel.JOIN_ENABLE); - // now search backwards for matching view settings - for (; tmpArch != null && mainControl.getTileEdit() != 0 && - !mainControl.isTileEdit(tmpArch.getEditType()); tmpArch = tmpArch.getPrev()) { - ; - } - if (tmpArch != null) { - needRedraw = calcArchRedraw(tmpArch); // get redraw info - mapControl.deleteMapArch(tmpArch.getMyID(), mapLoc, false, MapModel.JOIN_ENABLE); - } - // update mapArch panel mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), -1); } @@ -1426,9 +1413,7 @@ boolean insertAllowed = true; // are we allowed to insert this? if (!allowMany) { // check if there is already an arch of that kind - final Iterator it = mapControl.getArchObjects(pos); - while (it.hasNext()) { - final GameObject t = (GameObject) it.next(); + for (final GameObject t : mapControl.getMapModel().getMapSquare(pos)) { if (t.getArchetypeName().equals(newarch.getArchetypeName()) && t.getArchTypNr() == newarch.getArchTypNr()) { insertAllowed = false; // there's a match - don't insert a second one Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-10-03 17:11:54 UTC (rev 471) @@ -30,7 +30,9 @@ import cfeditor.map.MapControl; import cfeditor.map.MapModel; import java.awt.Point; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import net.sf.gridarta.Size2D; import org.apache.log4j.Logger; @@ -150,7 +152,6 @@ } // recycle and resize buffer - mapData.freeMapArchObject(); // free old map (/buffer) object bufWidth = Math.abs(offset.x) + 1; // new width bufHeight = Math.abs(offset.y) + 1; // new height mapArch.setMapSize(new Size2D(bufWidth, bufHeight)); @@ -162,10 +163,11 @@ // cycle through all tile coordinates which are highlighted: final Point pos = new Point(); + final List<GameObject> archesToDelete = new ArrayList<GameObject>(); for (pos.x = startp.x; pos.x - startp.x <= offset.x; pos.x++) { for (pos.y = startp.y; pos.y - startp.y <= offset.y; pos.y++) { // do the copying for one tile position: - final Iterator<GameObject> it = mapControl.getArchObjectsDeleteMapArch(pos, false, MapModel.JOIN_DISABLE); + final Iterator<GameObject> it = mapControl.getMapModel().getMapSquare(pos).iterator(); while (it.hasNext()) { final GameObject arch = it.next(); @@ -173,7 +175,7 @@ // (for multiparts, only the heads get copied into the buffer) // arches that don't match the view settings are ignored! if ((mode == DO_CUT || mode == DO_COPY) && - arch.isHead() && arch.getContainer() == null && + arch.isHead() && !arch.isInContainer() && (mainControl.getTileEdit() == 0 || mainControl.isTileEdit(arch.getEditType()))) { // copy this arch final GameObject clone = arch.createClone(Math.abs(pos.x - startp.x), Math.abs(pos.y - startp.y)); @@ -190,13 +192,17 @@ // For CUT we don't delete multi tails of multis which are left or // above the head (we would miss to copy them otherwise). if (mode == DO_CLEAR || (arch.getMultiX() >= 0 && arch.getMultiY() >= 0)) { - it.remove(); + archesToDelete.add(arch); } } } } } + for (final GameObject arch : archesToDelete) { + arch.remove(); + } + // finally redraw the map if (mode != DO_COPY) { mainControl.refreshCurrentMap(); @@ -223,9 +229,7 @@ if (mapControl.isPointValid(pos)) { sourcePos.x = pos.x - startp.x; sourcePos.y = pos.y - startp.y; - final Iterator<GameObject> it = buffCtrl.getArchObjects(sourcePos); - while (it.hasNext()) { - final GameObject arch = it.next(); + for (final GameObject arch : buffCtrl.getMapModel().getMapSquare(sourcePos)) { if (!arch.isMulti()) { // read arch from buffer and stick in on the map final GameObject clone = arch.createClone(pos.x, pos.y); @@ -243,9 +247,7 @@ if (mapControl.isPointValid(pos)) { sourcePos.x = pos.x - startp.x; sourcePos.y = pos.y - startp.y; - final Iterator<GameObject> it = buffCtrl.getArchObjects(sourcePos); - while (it.hasNext()) { - final GameObject arch = it.next(); + for (final GameObject arch : buffCtrl.getMapModel().getMapSquare(sourcePos)) { if (arch.isMulti()) { addArchToMap(mapControl, arch, pos, -1, false); } Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-10-03 17:11:54 UTC (rev 471) @@ -33,6 +33,7 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.ArrayList; import java.util.Iterator; import javax.swing.BorderFactory; import javax.swing.Box; @@ -321,35 +322,54 @@ // cycle through all tile coordinates between startpoint and offset: final Point pos = new Point(); int replaceCount = 0; + final ArrayList<GameObject> objectsToReplace = new ArrayList<GameObject>(); for (pos.x = startp.x; pos.x - startp.x <= offset.x; pos.x++) { for (pos.y = startp.y; pos.y - startp.y <= offset.y; pos.y++) { - final Iterator<GameObject> it = mapControl.getArchObjectsDeleteMapArch(pos, false, false); - while (it.hasNext()) { - final GameObject node = it.next(); + // find objects to replace + objectsToReplace.clear(); + for (final GameObject node : mapControl.getMapModel().getMapSquare(pos)) { if (node.isHead() && ((matchCriteria == MATCH_ARCH_NAME && node.getArchetypeName() != null && node.getArchetypeName().equalsIgnoreCase(matchString)) || (matchCriteria == MATCH_OBJ_NAME && node.getBestName().equalsIgnoreCase(matchString)))) { - // first, delete the old arch - final GameObject prevArch = node.getPrev(); - it.remove(); + objectsToReplace.add(node); + } + } - if (replaceArch != null && !deleteOnly) { - // insert replacement object - if (replaceArch.isMulti()) { - // multi's cannot be inserted properly, so we just put them ontop - replaceArch = replaceArch.getHead(); - mapControl.addArchToMap(replaceArch.getArchetypeName(), pos, 0, false); + // actually replace the objects + for (final GameObject objectToDelete : objectsToReplace) { + final Iterator<GameObject> it = mapControl.getMapModel().getMapSquare(pos).iterator(); + GameObject prevArch = null; + GameObject node = null; + while (it.hasNext()) { + node = it.next(); - // TODO: if from pickmap it could have special attributes -> copy them - } else { - mapControl.insertArchToMap(replaceArch, null, prevArch, pos, false); - } + if (node == objectToDelete) { + break; } - replaceCount++; + + prevArch = node; } + assert node != null; + + // first, delete the old arch + node.remove(); + + if (replaceArch != null && !deleteOnly) { + // insert replacement object + if (replaceArch.isMulti()) { + // multi's cannot be inserted properly, so we just put them ontop + replaceArch = replaceArch.getHead(); + mapControl.addArchToMap(replaceArch.getArchetypeName(), pos, 0, false); + + // TODO: if from pickmap it could have special attributes -> copy them + } else { + mapControl.insertArchToMap(replaceArch, null, prevArch, pos, false); + } + } + replaceCount++; } } } Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-10-03 17:11:54 UTC (rev 471) @@ -31,6 +31,7 @@ import cfeditor.IGUIConstants; import cfeditor.MultiArchData; import cfeditor.ScriptArchData; +import cfeditor.map.MapSquare; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -49,7 +50,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public class GameObject implements Cloneable, net.sf.gridarta.gameobject.GameObject, Iterable<GameObject> { +public class GameObject extends GameObjectContainer implements Cloneable, net.sf.gridarta.gameobject.GameObject, Iterable<GameObject> { private static final Logger log = Logger.getLogger(GameObject.class); @@ -147,9 +148,13 @@ /** * Container of this GameObject. - * The Crossfire implementation only knows <code>null</code> (map or unlinked) or being an inventory item. + * There are two possibilities for the container: + * <ul> + * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> + * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> + * </ul> */ - @Nullable private GameObject container = null; + private GameObjectContainer container; /** * All inventory objects. Set to {@link Collections#EMPTY_LIST} @@ -440,23 +445,82 @@ } /** {@inheritDoc} */ - @Nullable public GameObject getContainer() { + @NotNull public GameObjectContainer getContainer() { return container; } /** {@inheritDoc} */ @NotNull public GameObject getTopContainer() { - GameObject tmpArch; + return isInContainer() ? ((GameObject) container).getTopContainer() : this; + } - for (tmpArch = this; tmpArch.getContainer() != null; - tmpArch = tmpArch.getContainer()) { - ; - } + /** + * Sets container of this GameObject. + * There are two possibilities for the container: + * <ul> + * <li>Another GameObject, which means this object is in the inventory of that GameObject.</li> + * <li>A MapSquare, which means that this GameObject is top level on that MapSquare.</li> + * </ul> + * @param container container of this GameObject. + */ + public void setContainer(final GameObjectContainer container) { + this.container = container; + } - return tmpArch; + /** + * Check whether this GameObject is in a Container (in Daimonin sense, + * which means being in a MapSquare isn't, but being in an GameObject is). + * @return <code>true</code> if this GameObject has a Container and the + * Container is an GameObject, otherwise (no Container or Container is not + * an GameObject) false + */ + public boolean isInContainer() { + return container != null && container instanceof GameObject; } + /** {@inheritDoc} */ + @Override public MapSquare getMapSquare() { + return container != null ? container.getMapSquare() : null; + } + + /** Move this GameObject top. */ + public void moveTop() { + container.moveTop(this); + } + + /** Move this GameObject up. */ + public void moveUp() { + container.moveUp(this); + } + + /** Move this GameObject down. */ + public void moveDown() { + container.moveDown(this); + } + + /** Move this GameObject bottom. */ + public void moveBottom() { + container.moveBottom(this); + } + /** + * Remove this GameObject from its container. Do nothing if the object is + * not inside a container. + * This method also takes perfectly well care of multihead arches. + */ + public void remove() { + final GameObject head = getHead(); + for (GameObject tail = head.getMultiNext(); tail != null; tail = tail.getMultiNext()) { + if (tail.container != null) { + tail.container.remove(tail); + } + } + if (head.container != null) { + head.container.remove(head); + } + } + + /** * Set the String of an arch attribute in the objectText. * @param attributeName search for "attributeName <string>" * @param value value to set @@ -572,59 +636,21 @@ } /** - * The given <code>GameObject</code> 'arch' is placed as inventory - * into 'this' <code>GameObject</code>. (Keep in mind that 'arch' - * has to be a free (unlinked) instance of <code>GameObject</code>.) - * @param arch the <code>GameObject</code> to be placed in the inventory + * Insert an GameObject before this GameObject. + * @param node GameObject to append */ - public void addInvObj(final GameObject arch) { - // arch must not be already in a container - if (arch.container != null) { - throw new IllegalArgumentException(); - } - - if (inv == Collections.EMPTY_LIST) { - inv = new LinkedList<GameObject>(); - } - - inv.add(arch); - arch.container = this; - - arch.setMapX(getMapX()); - arch.setMapY(getMapY()); + public void insertBefore(final GameObject node) { + getContainer().insertBefore(node, this); } - /** Remove 'this' arch from the inventory-list and delete all it's pointers */ - public void removeInvObj() { - // object's inventory must have already been deleted - if (inv != Collections.EMPTY_LIST) { - throw new IllegalArgumentException(); - } - - // object must be in a container - if (container == null) { - throw new IllegalArgumentException(); - } - - // remove this object from its parent container - if (!container.inv.remove(this)) { - throw new AssertionError(); - } - - if (container.inv.size() == 0) { - container.inv = Collections.EMPTY_LIST; - } + /** + * Insert an GameObject after this GameObject. + * @param node GameObject to append + */ + public void insertAfter(final GameObject node) { + getContainer().insertAfter(this, node); } - /** Remove all inventory objects. */ - public void clearInventory() { - while (inv.size() > 0) { - final GameObject inv = this.inv.get(0); - inv.clearInventory(); - inv.removeInvObj(); - } - } - /** {@inheritDoc} */ public int countInvObjects() { int count = 0; @@ -821,38 +847,24 @@ return mapy; } - /** - * Set Next link. - * @param arch Arch to point next to - */ - public void setNext(final GameObject arch) { - next = arch; + /** {@inheritDoc} */ + @Override public void addLast(final GameObject arch) { + super.addLast(arch); + // force type change when a MONSTER is put in a spawn point + if (typeList.getTypeOfArch(this) != null && typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(arch).getTypeNr() == 80) { + arch.archType = 83; // change to SPAWN_POINT_MOB + } } - /** - * Set Prev link. - * @param arch Arch to point prev to - */ - public void setPrev(final GameObject arch) { - prev = arch; + /** {@inheritDoc} */ + @Override public void addFirst(final GameObject arch) { + super.addFirst(arch); + // force type change when a MONSTER is put in a spawn point + if (typeList.getTypeOfArch(this).getTypeNr() == 81 && typeList.getTypeOfArch(arch).getTypeNr() == 80) { + arch.archType = 83; // change to SPAWN_POINT_MOB + } } - /** - * Get Next link. - * @return next link - */ - public GameObject getNext() { - return next; - } - - /** - * Get Prev link. - * @return prev link - */ - public GameObject getPrev() { - return prev; - } - /* Set the default face. Number is index of face list */ public void setFaceNr(final int nr) { facenr = nr; @@ -1203,20 +1215,12 @@ // If 'this' arch is a container, we have to create clones // of the whole inventory (recursively) and link them in: for (final GameObject invItem : inv) { - clone.addInvObj(invItem.createClone(posx, posy)); + clone.addLast(invItem.createClone(posx, posy)); } return clone; } - /** - * @return true if 'this' arch is a container (has something - * inside), otherwise false - */ - public boolean isContainer() { - return inv.size() > 0; - } - /** @return true if 'this' arch is part of a multisquare object */ public boolean isMulti() { return multi != null; @@ -1458,9 +1462,4 @@ return cachedAttribute.get(name); } - /** {@inheritDoc} */ - public Iterator<GameObject> iterator() { - return inv.iterator(); - } - } // class GameObject Added: trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java 2006-10-03 17:11:54 UTC (rev 471) @@ -0,0 +1,427 @@ +/* + * Daimonin Java Editor. + * Copyright (C) 2005 Christian Hujer + * + * 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.gameobject; + +import cfeditor.map.MapSquare; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Base class for classes that contain GameObjects as children in the sense of containment. + * The interface serves 2 main purposes: + * <ul> + * <li>{@link GameObject} extends this class for containing other GameObjects, like inventory contents e.g. of a bag or attached events.</li> + * <li>{@link MapSquare} extends this class to list the tiles on a MapSquare.</li> + * </ul> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @todo: In case of MapSquares, this class is most likely bogus regarding multipart objects. This needs to be fixed. + */ +@SuppressWarnings({"ClassReferencesSubclass"}) +public abstract class GameObjectContainer implements Iterable<GameObject>, Serializable { + + /** Serial Version. */ + private static final long serialVersionUID = 1L; + + /** + * The contents of this container. + * @note the order of this container is bottom to top. + */ + @NotNull private List<GameObject> contents; + + /** Iterable implementation for recursice traversal. */ + @NotNull private transient Iterable<GameObject> recursive; + + /** Iterable implementation for reverse traversal. */ + @NotNull private transient Iterable<GameObject> reverse; + + /** Create a new GameObjectContainer. */ + protected GameObjectContainer() { + initData(); + } + + /** + * Initialize the fields. + * This is needed because there are two ways of object construction, + * <ul> + * <li>regular object construction via constructor invocation and</li> + * <li>cloning of objects via {@link #clone()}.</li> + * </ul> + */ + private void initData() { + contents = new ArrayList<GameObject>(); + recursive = new Iterable<GameObject>() { + /** {@inheritDoc} */ + public Iterator<GameObject> iterator() { + return new RecursiveGameObjectIterator(GameObjectContainer.this); + } + }; + reverse = new Iterable<GameObject>() { + /** {@inheritDoc} */ + public Iterator<GameObject> iterator() { + return new ReverseIterator<GameObject>(contents); + } + }; // Iterable<GameObject> reverse + } + + /** + * {@inheritDoc} + * The Iterator returned does not recurse, it only contains objects on the first level. + * The Iterator returned is transparent, that means modifying the iterator's collection actually modifies the underlying GameObjectContainer. + */ + @NotNull public final Iterator<GameObject> iterator() { + // Do not return contents.iterator() directly because otherwise the remove() operation will not properly unlink the removed GameObject from its container. + return new Iterator<GameObject>() { + + /** The basic iterator. */ + private Iterator<GameObject> delegate = contents.iterator(); + private GameObject current; + + /** {@inheritDoc} */ + public boolean hasNext() { + return delegate.hasNext(); + } + + /** {@inheritDoc} */ + public GameObject next() { + return current = delegate.next(); + } + + /** {@inheritDoc} */ + public void remove() { + // keep this in sync with GameObjectContainer#remove(GameObject) + // we can't simply invoke GameObjectContainer#remove(current) because that would result in a ConcurrentModificationException. + delegate.remove(); + current.setContainer(null); + squareChanged(); + } + }; + } + + /** + * Return an object that is the reverse representation. + * Invoke this method if you want to iterate over the contained GameObjects in reverse order. + * @return reverse representation + */ + @NotNull public final Iterable<GameObject> reverse() { + return reverse; + } + + /** + * Return an object that is a recursive representation. + * Invoke this method if you want to iterate over the contained GameObjects recursively. + * @return recursive representation + */ + @NotNull public final Iterable<GameObject> recursive() { + return recursive; + } + + /** + * Check whether this square is empty. + * @return <code>true</code> if this square is empty, otherwise <code>false</code> + */ + public boolean isEmpty() { + return contents.isEmpty(); + } + + /** + * Return the first GameObject contained in this container. + * @return first GameObject contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> + */ + @Nullable public final GameObject getFirst() { + return contents.isEmpty() ? null : contents.get(0); + } + + /** + * Return the last GameObject contained in this container. + * You should not invoke this method to iterate over GameObjects, such invocation is regarded deprecated. + * @return last GameObject contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> + */ + @Nullable public final GameObject getLast() { + return contents.isEmpty() ? null : contents.get(contents.size() - 1); + } + + /** + * Remove a GameObject from this container. + * @param gameObject GameObject to remove + * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container + */ + final void remove(@NotNull final GameObject gameObject) { + // keep this in sync with iterator() + if (!contents.remove(gameObject)) { + throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); + } + gameObject.setContainer(null); + squareChanged(); + } + + /** Remove all GameObjects from this container. */ + public final void removeAll() { + if (contents.size() <= 0) { + return; + } + + for (final GameObject gameObject : contents) { + gameObject.setContainer(null); + } + contents.clear(); + squareChanged(); + } + + /** + * Move an item to top. + * @param gameObject item to move to top + * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container + */ + public final void moveTop(@NotNull final GameObject gameObject) { + final int oldIndex = contents.indexOf(gameObject); + if (oldIndex != contents.size() - 1) { + if (!contents.remove(gameObject)) { + throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); + } + contents.add(gameObject); + squareChanged(); + } + } + + /** + * Move an item up. + * @param gameObject item to move up + * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container + */ + public final void moveUp(@NotNull final GameObject gameObject) { + final int oldIndex = contents.indexOf(gameObject); + if (oldIndex < contents.size() - 1) { + if (!contents.remove(gameObject)) { + throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); + } + contents.add(oldIndex + 1, gameObject); + squareChanged(); + } + } + + /** + * Move an item down. + * @param gameObject item to move down + * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container + */ + public final void moveDown(@NotNull final GameObject gameObject) { + final int oldIndex = contents.indexOf(gameObject); + if (oldIndex > 0) { + if (!contents.remove(gameObject)) { + throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); + } + contents.add(oldIndex - 1, gameObject); + squareChanged(); + } + } + + /** + * Move an item to bottom. + * @param gameObject item to move to bottom + * @throws IllegalArgumentException if <var>gameObject</var> isn't in this container + */ + public final void moveBottom(@NotNull final GameObject gameObject) { + final int oldIndex = contents.indexOf(gameObject); + if (oldIndex != 0) { + if (!contents.remove(gameObject)) { + throw new IllegalArgumentException(gameObject + " wasn't inside container " + this); + } + contents.add(0, gameObject); + squareChanged(); + } + } + + /** + * Get the X coordinate on the map. + * @return X coordinate on map + */ + public abstract int getMapX(); + + /** + * Get the Y coordinate on the map. + * @return Y coordinate on map + */ + public abstract int getMapY(); + + /** + * Add the given GameObject at the end of this Container. + * @param gameObject the free yet unlinked <code>GameObject</code> to be placed in the inventory + * @throws IllegalArgumentException if <var>gameObject</var> already is inside another container + */ + public void addLast(@NotNull final GameObject gameObject) { + if (gameObject.isInContainer()) { + throw new IllegalArgumentException("Can't add " + gameObject + " to " + this + " because it's already inside " + gameObject.getContainer()); + } + contents.add(gameObject); + gameObject.setContainer(this); + squareChanged(); + } + + /** + * Add the given GameObject at the end of this Container. + * @param gameObject the free yet unlinked <code>GameObject</code> to be placed in the inventory + * @throws IllegalArgumentException if <var>gameObject</var> already is inside another container + */ + public void addFirst(@NotNull final GameObject gameObject) { + if (gameObject.isInContainer()) { + throw new IllegalArgumentException("Can't add " + gameObject + " to " + this + " because it's already inside " + gameObject.getContainer()); + } + contents.add(0, gameObject); + gameObject.setContainer(this); + squareChanged(); + } + + /** + * Add a GameObject after another. + * @param previousGameObject previous anchor + * @param newGameObject GameObject to insert + * @throws IllegalArgumentException if <var>newGameObject</var> already is inside another container or <var>previousGameObject</var> isn't inside this container + */ + public void insertAfter(@NotNull final GameObject previousGameObject, @NotNull final GameObject newGameObject) { + if (newGameObject.isInContainer()) { + throw new IllegalArgumentException("Can't add " + newGameObject + " to " + this + " because it's already inside " + newGameObject.getContainer()); + } + final int insertIndex = contents.indexOf(previousGameObject); + if (insertIndex == -1) { + throw new IllegalArgumentException("Can't insert " + newGameObject + " after " + previousGameObject + " because that isn't inside " + this); + } + contents.add(insertIndex, newGameObject); + newGameObject.setContainer(this); + squareChanged(); + } + + /** + * Add a GameObject before another. + * @param newGameObject GameObject to insert + * @param nextGameObject nextGameObject anchor + * @throws IllegalArgumentException if <var>newGameObject</var> already is inside another container or <var>prev</var> isn't inside this container + */ + public void insertBefore(@NotNull final GameObject newGameObject, @NotNull final GameObject nextGameObject) { + if (newGameObject.isInContainer()) { + throw new IllegalArgumentException("Can't add " + newGameObject + " to " + this + " because it's already inside " + newGameObject.getContainer()); + } + final int insertIndex = contents.indexOf(nextGameObject); + if (insertIndex == -1) { + throw new IllegalArgumentException("Can't insert " + newGameObject + " before " + nextGameObject + " because that isn't inside " + this); + } + contents.add(insertIndex + 1, newGameObject); + newGameObject.setContainer(this); + squareChanged(); + } + + /** + * Replace an GameObject with another one. + * @param oldGameObject old GameObject to be replaced + * @param newGameObject new GameObject that replaces oldGameObject + * @throws IllegalArgumentException if <var>oldGameObject</var> isn't in this container + */ + public void replace(@NotNull final GameObject oldGameObject, @NotNull final GameObject newGameObject) { + final int insertIndex = contents.indexOf(oldGameObject); + if (insertIndex == -1) { + throw new IllegalArgumentException(oldGameObject + " wasn't inside container " + this); + } + contents.remove(oldGameObject); + oldGameObject.setContainer(null); + contents.add(insertIndex, newGameObject); + newGameObject.setContainer(this); + squareChanged(); + } + + /** + * Get the MapSquare of this GameObjectContainer. + * @return MapSquare of this GameObjectContainer or <code>null</code> if this GameObjectContainer is not (yet?) connected to a map (a {@link MapSquare} would return itself) + */ + @Nullable public abstract MapSquare getMapSquare(); + + /** + * Tell the model that this MapSquare has changed. + * This method must be invoked by all other methods that change something. + */ + protected final void squareChanged() { + final MapSquare square = getMapSquare(); + if (square != null) { + square.getModel().squareChanged(square); + } + } + + /** {@inheritDoc} */ + @NotNull @Override protected GameObjectContainer clone() throws CloneNotSupportedException { + try { + final GameObjectContainer clone = (GameObjectContainer) super.clone(); + clone.initData(); + return clone; + } catch (final CloneNotSupportedException e) { + assert false; + throw new AssertionError(); + } + } + + /** {@inheritDoc} */ + // writeObject() is not required because this class doesn't require special handling during serialization. + private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { + stream.defaultReadObject(); + // initialize transients + initData(); + } + + /** + * An iterator for iterating over a list in reverse order. + * @todo move this class to JAPI + */ + private static class ReverseIterator<T> implements Iterator<T> { + + /** The iterator used for delegation. */ + @NotNull private final ListIterator<T> delegate; + + /** + * Create a reverse iterator. + * @param list to iterate over in reverse order + */ + public ReverseIterator(final List<T> list) { + delegate = list.listIterator(list.size()); + } + + /** {@inheritDoc} */ + public boolean hasNext() { + return delegate.hasPrevious(); + } + + /** {@inheritDoc} */ + @NotNull public T next() { + return delegate.previous(); + } + + /** {@inheritDoc} */ + public void remove() { + delegate.remove(); + } + + } // class ReverseIterator + +} // interface GameObjectContainer Property changes on: trunk/crossfire/src/cfeditor/gameobject/GameObjectContainer.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Deleted: trunk/crossfire/src/cfeditor/gameobject/GameObjectIterator.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObjectIterator.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/gameobject/GameObjectIterator.java 2006-10-03 17:11:54 UTC (rev 471) @@ -1,99 +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 cfeditor.gameobject; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * Iterator for ArchObjects. - * This class is only meant for usage during the transition from manually linked lists to encapslued Collections lists in arch handling. - * This Iterator is believed to be safe against concurrent modification. - * Therefore it is not fail-fast, it does not throw ConcurrentModificationException. - * The next link is future-fetched, which means that the invocation of {@link #next()} already prepares the next invocation of {@link #hasNext()} or {@link #next()}. - * This allows to safely perform manipulations on the current object, especially deletion, without loosing traversal. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class GameObjectIterator implements Iterator<GameObject> { - -// /** Current GameObject, used for {@link #remove()}. */ -// private GameObject current; - - /** Traversal direction. */ - private final boolean forward; - - /** GameObject for first iteration step. */ - private GameObject next; - - /** - * Creates a new instance of GameObjectIterator (forward iteration). - * @param first first GameObject to start forward iteration on - */ - public GameObjectIterator(final GameObject first) { - this(first, true); - } - - /** - * Creates a new instance of GameObjectIterator. - * @param first first GameObject to start iteration on - * @param forward <code>true</code> for forward iteration, <code>false</code> for backward iteration - */ - GameObjectIterator(final GameObject first, final boolean forward) { - next = first; - this.forward = forward; - } - - /** {@inheritDoc} */ - public boolean hasNext() { - return next != null; - } - - /** {@inheritDoc} */ - public GameObject next() { - try { - return next; - } finally { - try { - next = forward ? next.getNext() : next.getPrev(); - } catch (final NullPointerException e) { - //noinspection ThrowFromFinallyBlock - throw new NoSuchElementException(); - } - } - } - - /** - * {@inheritDoc} - * @todo eventually, multitile-removal should go here. - */ - public void remove() { - throw new UnsupportedOperationException(); -// GameObject prev = current.getPrevArch(); -// GameObject next = current.getNextArch(); -// if (next != null) { next.setPrevArch(prev); } -// if (prev != null) { prev.setPrevArch(next); } - } - -} // class GameObjectIterator Deleted: trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteGameMapObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteGameMapObject.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteGameMapObject.java 2006-10-03 17:11:54 UTC (rev 471) @@ -1,46 +0,0 @@ -/* $Id: GameObjectIteratorDeleteGameMapObject.java,v 1.1 2006/04/06 17:16:03 akirschbaum Exp $ */ - -package cfeditor.gameobject; - -import cfeditor.map.MapModel; -import java.util.Iterator; - -/** - * The class GameObjectIterator implements an {@link GameObjectIterator} that - * implements the {@link Iterator#remove()} operation via {@link - * MapModel#deleteArchMapObject(GameObject)}. - * @author Andreas Kirschbaum - */ -public class GameObjectIteratorDeleteGameMapObject extends GameObjectIterator { - - private final MapModel model; - - public GameObjectIteratorDeleteGameMapObject(final MapModel model, final GameObject archObject) { - super(archObject); - - if (model == null) { - throw new IllegalArgumentException(); - } - - this.model = model; - } - - /** {@inheritDoc} */ - public GameObject next() { - currArchObject = super.next(); - return currArchObject; - } - - /** {@inheritDoc} */ - @Override public void remove() { - if (currArchObject == null) { - throw new IllegalStateException(); - } - - model.deleteArchMapObject(currArchObject); - currArchObject = null; - } - - private GameObject currArchObject = null; - -} // class GameObjectIteratorDeleteGameMapObject Deleted: trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteMapGame.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteMapGame.java 2006-10-03 16:45:57 UTC (rev 470) +++ trunk/crossfire/src/cfeditor/gameobject/GameObjectIteratorDeleteMapGame.java 2006-10-03 17:11:54 UTC (rev 471) @@ -1,69 +0,0 @@ -/* $Id: GameObjectIteratorDeleteMapGame.java,v 1.1 2006/04/06 17:16:03 akirschbaum Exp $ */ - -package cfeditor.gameobject; - -import cfeditor.map.MapModel; -import java.awt.Point; -import java.util.Iterator; - -/** - * The class GameObjectIterator implements an {@link GameObjectIterator} that - * implements the {@link Iterator#remove()} operation via {@link - * MapModel#deleteMapArch(int, int, int, boolean, boolean)}. - * @author Andreas Kirschbaum - */ -public class GameObjectIteratorDeleteMapGame extends GameObjectIterator { - - private final MapModel mapModel; - - private final Point pos; - - private final boolean refreshMap; - - private final boolean join; - - public GameObjectIteratorDeleteMapGame(final MapModel mapModel, final GameObject archObject, final Point pos, final boolean refreshMap, final boolean join) { - super(archObject); - - if (mapModel == null) { - throw new IllegalArgumentException(); - } - - this.mapModel = mapModel; - this.pos = pos; - this.refreshMap = refreshMap; - this.join = join; - } - - /** - * @param mapModel - * @param archObject - * @param x - * @param y - * @param refreshMap - * @param join - * @deprecated use {@link #ArchObjectIteratorDeleteMapArch(MapModel,GameObject, Point, boolean, boolean)} instead - */ - @Deprecated public GameObjectIteratorDeleteMapGame(final MapModel mapModel, final GameObject archObject, final int x, final int y, final boolean refreshMap, final boolean join) { - this(mapModel, archObject, new Point(x, y), refreshMap, join); - } - - /** {@inheritDoc} */ - public GameObject next() { - currArchObject = super.next(); - return currArchObject; - } - - /** {@inheritDoc} */ - @Override public void remove() { - if (currArchObject == null) { - throw new IllegalStateException(); - } - - mapModel.deleteMapArch(currArchObject.getMyID(), pos, refreshMap, join); - currArchObject = null; - } - - private GameObject currArchObject = null; - -} // class GameObjectIteratorDeleteMapGame Added: trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/RecursiveGameObjectIterator.java 2006-10-03 17:11:54 UTC (rev 471) @@ -0,0 +1,58 @@ +package cfeditor.gameobject; + +import java.util.EmptyStackException; +import java.util.Iterator; +import java.util.Stack; + +/** + * Iterator for recursively iterating over ArchObjectContainers. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +class RecursiveGameObjectIterator implements Iterator<GameObject> { + + /** The Iterator stack. */ + private Stack<Iterator<GameObject>> iteratorStack = new Stack... [truncated message content] |
From: <chr...@us...> - 2006-10-23 19:48:12
|
Revision: 571 http://svn.sourceforge.net/gridarta/?rev=571&view=rev Author: christianhujer Date: 2006-10-23 12:47:59 -0700 (Mon, 23 Oct 2006) Log Message: ----------- Moved FaceObject to a package of its own (for unification). Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/face/ trunk/crossfire/src/cfeditor/gameobject/face/FaceObject.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/FaceObject.java Deleted: trunk/crossfire/src/cfeditor/FaceObject.java =================================================================== --- trunk/crossfire/src/cfeditor/FaceObject.java 2006-10-22 13:16:29 UTC (rev 570) +++ trunk/crossfire/src/cfeditor/FaceObject.java 2006-10-23 19:47:59 UTC (rev 571) @@ -1,161 +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 com.sixlegs.image.png.PngImage; -import java.awt.Toolkit; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import javax.swing.ImageIcon; -import net.sf.gridarta.io.IOUtils; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.Nullable; - -/** - * The <code>FaceObject</code> - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class FaceObject { - - private static final Logger log = Logger.getLogger(FaceObject.class); - - //private ImageIcon face; - private Object face; - - private String name = new String(""); // name of face - - private String path; - - private int index; - - private int dataSize; - - private long dataStartIndex; - - private String ressourceName; - - private String ressourceDirectory; - - private boolean isLazyLoading = false; - - public FaceObject() { - face = null; - index = -1; - } - - /** FaceObject with informations on how to localize ressource (lazy loading) */ - public FaceObject(final String directory, final String ressource, final long position, final int size) { - ressourceDirectory = directory; - ressourceName = ressource; - dataStartIndex = position; - dataSize = size; - isLazyLoading = true; - } - - public ImageIcon getFace() { - if (isLazyLoading) { - return loadFace(); - } else { - return (ImageIcon) face; - } - } - - @Nullable private synchronized ImageIcon loadFace() { - if (log.isDebugEnabled()) { - log.debug("Getting soft reference to " + name); - } - if (face != null) { - final ImageIcon icon = ((Reference<ImageIcon>) face).get(); - if (icon != null) { - return icon; - } - } - try { - if (log.isDebugEnabled()) { - log.debug("Lazy loading " + name); - } - final InputStream fi = IOUtils.createStream(ressourceDirectory, ressourceName); - try { - if (dataStartIndex > 0) { - fi.skip(dataStartIndex); // FIXME: result of skip is ignored. - } - final byte[] data = new byte[dataSize]; - fi.read(data); // FIXME: result of read is ignored. - final PngImage png = new PngImage(new ByteArrayInputStream(data)); // read png data from bytestream - png.setFlushAfterNextProduction(true); - final ImageIcon im = new ImageIcon(Toolkit.getDefaultToolkit().createImage(png)); - setFace(im); - return im; - } finally { - fi.close(); - } - } catch (final Exception e) { - log.warn("Problem lazy loading face " + name, e); - return null; - } - } - - /* - public void setFace(final Image im) { - face = new ImageIcon(); - face.setImage(im); - im = null; - } - */ - - public void setFace(final ImageIcon im) { - if (isLazyLoading) { - face = new SoftReference<ImageIcon>(im); - } else { - face = im; - } - } - - public String getPath() { - return path; - } - - public void setPath(final String text) { - path = text; - } - - public String getName() { - return name; - } - - public void setName(final String text) { - name = new String(text); - } - - public int getIndex() { - return index; - } - - public void setIndex(final int i) { - index = i; - } -} Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-22 13:16:29 UTC (rev 570) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-10-23 19:47:59 UTC (rev 571) @@ -31,7 +31,7 @@ import cfeditor.CMainStatusbar; import cfeditor.CPickmapPanel; import cfeditor.CSettings; -import cfeditor.FaceObject; +import cfeditor.gameobject.face.FaceObject; import cfeditor.IGUIConstants; import java.awt.Color; import java.awt.GridLayout; Copied: trunk/crossfire/src/cfeditor/gameobject/face/FaceObject.java (from rev 570, trunk/crossfire/src/cfeditor/FaceObject.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/face/FaceObject.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/face/FaceObject.java 2006-10-23 19:47:59 UTC (rev 571) @@ -0,0 +1,161 @@ +/* + * 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.gameobject.face; + +import com.sixlegs.image.png.PngImage; +import java.awt.Toolkit; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +import javax.swing.ImageIcon; +import net.sf.gridarta.io.IOUtils; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.Nullable; + +/** + * The <code>FaceObject</code> + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class FaceObject { + + private static final Logger log = Logger.getLogger(FaceObject.class); + + //private ImageIcon face; + private Object face; + + private String name = new String(""); // name of face + + private String path; + + private int index; + + private int dataSize; + + private long dataStartIndex; + + private String ressourceName; + + private String ressourceDirectory; + + private boolean isLazyLoading = false; + + public FaceObject() { + face = null; + index = -1; + } + + /** FaceObject with informations on how to localize ressource (lazy loading) */ + public FaceObject(final String directory, final String ressource, final long position, final int size) { + ressourceDirectory = directory; + ressourceName = ressource; + dataStartIndex = position; + dataSize = size; + isLazyLoading = true; + } + + public ImageIcon getFace() { + if (isLazyLoading) { + return loadFace(); + } else { + return (ImageIcon) face; + } + } + + @Nullable private synchronized ImageIcon loadFace() { + if (log.isDebugEnabled()) { + log.debug("Getting soft reference to " + name); + } + if (face != null) { + final ImageIcon icon = ((Reference<ImageIcon>) face).get(); + if (icon != null) { + return icon; + } + } + try { + if (log.isDebugEnabled()) { + log.debug("Lazy loading " + name); + } + final InputStream fi = IOUtils.createStream(ressourceDirectory, ressourceName); + try { + if (dataStartIndex > 0) { + fi.skip(dataStartIndex); // FIXME: result of skip is ignored. + } + final byte[] data = new byte[dataSize]; + fi.read(data); // FIXME: result of read is ignored. + final PngImage png = new PngImage(new ByteArrayInputStream(data)); // read png data from bytestream + png.setFlushAfterNextProduction(true); + final ImageIcon im = new ImageIcon(Toolkit.getDefaultToolkit().createImage(png)); + setFace(im); + return im; + } finally { + fi.close(); + } + } catch (final Exception e) { + log.warn("Problem lazy loading face " + name, e); + return null; + } + } + + /* + public void setFace(final Image im) { + face = new ImageIcon(); + face.setImage(im); + im = null; + } + */ + + public void setFace(final ImageIcon im) { + if (isLazyLoading) { + face = new SoftReference<ImageIcon>(im); + } else { + face = im; + } + } + + public String getPath() { + return path; + } + + public void setPath(final String text) { + path = text; + } + + public String getName() { + return name; + } + + public void setName(final String text) { + name = new String(text); + } + + public int getIndex() { + return index; + } + + public void setIndex(final int i) { + index = i; + } +} Property changes on: trunk/crossfire/src/cfeditor/gameobject/face/FaceObject.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-11-10 22:45:52
|
Revision: 631 http://svn.sourceforge.net/gridarta/?rev=631&view=rev Author: christianhujer Date: 2006-11-10 14:45:40 -0800 (Fri, 10 Nov 2006) Log Message: ----------- Removed empty application exit notifications. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/MapViewIFrame.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/map/MapModel.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-08 22:57:20 UTC (rev 630) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-10 22:45:40 UTC (rev 631) @@ -1570,7 +1570,6 @@ if (currentMap != null) { mainView.setMapTileList(null, -1); - currentMap.appExitNotify(); } // save settings Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-08 22:57:20 UTC (rev 630) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-10 22:45:40 UTC (rev 631) @@ -237,10 +237,6 @@ this.modelChanged(); } - /** Notifies that the application is about to exit. */ - void appExitNotify() { - } - /** Notifies that this level view is about to be closed. */ void closeNotify() { mapControl.viewCloseNotify(this); Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-11-08 22:57:20 UTC (rev 630) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-11-10 22:45:40 UTC (rev 631) @@ -158,10 +158,6 @@ view.setGridVisibility(fVisible); } - public void appExitNotify() { - view.appExitNotify(); - } - public void closeNotify() { view.closeNotify(); } Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-11-08 22:57:20 UTC (rev 630) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-11-10 22:45:40 UTC (rev 631) @@ -106,12 +106,6 @@ } /** - * Notify that the application is about to exit. - */ - public void appExitNotify() { - } - - /** * Notify that the level is about to be closed. */ public void levelCloseNotify() { Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-11-08 22:57:20 UTC (rev 630) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-11-10 22:45:40 UTC (rev 631) @@ -111,12 +111,6 @@ mapView = new MapViewIFrame(mainControl, this, initial); } - /** Notifies that the application is about to exit. */ - public void appExitNotify() { - mapView.appExitNotify(); // drop the view - mapModel.appExitNotify(); // and then the model - } - /** * Return flag that indicates whether this is a pickmap or not. * @return flag that indicates whether this is a pickmap or not Modified: trunk/crossfire/src/cfeditor/map/MapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapModel.java 2006-11-08 22:57:20 UTC (rev 630) +++ trunk/crossfire/src/cfeditor/map/MapModel.java 2006-11-10 22:45:40 UTC (rev 631) @@ -34,8 +34,6 @@ @Nullable GameObject getExit(); - void appExitNotify(); - String getMapText(); void setNewMapText(String str); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-12 00:15:35
|
Revision: 657 http://svn.sourceforge.net/gridarta/?rev=657&view=rev Author: christianhujer Date: 2006-11-11 16:15:19 -0800 (Sat, 11 Nov 2006) Log Message: ----------- Added missing final keywords at catch parameters. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/PluginParameterFactory.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gui/ScriptManager.java trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-11-12 00:15:19 UTC (rev 657) @@ -167,12 +167,12 @@ } finally { stream.close(); } - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { if (log.isInfoEnabled()) { log.info("Autojoin definitions file '" + filename + "' not found."); } return false; - } catch (IOException e) { + } catch (final IOException e) { log.warn("Read error in file '" + filename + "'."); return false; } Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-11-12 00:15:19 UTC (rev 657) @@ -200,9 +200,9 @@ } finally { fread.close(); } - } catch (JDOMException e) { + } catch (final JDOMException e) { log.error("Parsing error in '" + IGUIConstants.TYPEDEF_FILE, e); - } catch (IOException e) { + } catch (final IOException e) { log.error("Cannot read file '" + IGUIConstants.TYPEDEF_FILE + "'!", e); } @@ -231,7 +231,7 @@ num = elem.getAttribute("value").getIntValue(); list.addElement(new Integer(num)); list.addElement(" " + elem.getAttribute("name").getValue().trim()); - } catch (DataConversionException e) { + } catch (final DataConversionException e) { log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name").getValue() + ": value '" + elem.getAttribute("value").getValue() + "' is not an integer."); } } @@ -336,7 +336,7 @@ spellNum[i] = spellElem.getAttribute("id").getIntValue(); spellName[i] = spellElem.getAttribute("name").getValue().trim(); i++; - } catch (DataConversionException de) { + } catch (final DataConversionException de) { log.error("in '" + IGUIConstants.SPELL_FILE + "': spell id '" + spellElem.getAttribute("id").getValue() + "' is not an integer."); } } @@ -356,9 +356,9 @@ } finally { reader.close(); } - } catch (JDOMException e) { + } catch (final JDOMException e) { log.error("Parsing error in '" + IGUIConstants.SPELL_FILE + "'", e); - } catch (IOException e) { + } catch (final IOException e) { log.error("Cannot read file '" + IGUIConstants.SPELL_FILE + "'!"); } } @@ -452,16 +452,16 @@ list.insertElementAt((counter + " " + name), list.size()); } } - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { log.error("File '" + spellfile.getAbsolutePath() + "' not found!"); - } catch (EOFException e) { + } catch (final EOFException e) { // end of file/spell struct reached try { fileReader.close(); bufferedReader.close(); - } catch (IOException ioe) { + } catch (final IOException ioe) { } - } catch (IOException e) { + } catch (final IOException e) { log.error("Cannot read file '" + spellfile.getAbsolutePath() + "'!"); } } @@ -515,7 +515,7 @@ bufferedWriter.close(); fileWriter.close(); return list.size(); - } catch (IOException e) { + } catch (final IOException e) { log.error("Cannot write file '" + dfile.getAbsolutePath() + "'!"); } } Modified: trunk/crossfire/src/cfeditor/PluginParameterFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/PluginParameterFactory.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/PluginParameterFactory.java 2006-11-12 00:15:19 UTC (rev 657) @@ -87,7 +87,7 @@ final PluginParameter p = c.newInstance(); p.fromXML(parameterNode); return p; - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); return null; } Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-11-12 00:15:19 UTC (rev 657) @@ -512,7 +512,7 @@ if (line.length() > 0 && (test == null || c == '\n')) { result = result.concat(line + "\n"); } - } catch (StringIndexOutOfBoundsException e) { + } catch (final StringIndexOutOfBoundsException e) { } } @@ -867,7 +867,7 @@ // close streams sstream.close(); sread.close(); - } catch (IOException e) { + } catch (final IOException e) { log.error("in getSyntaxErrors: Cannot close StringReader", e); } Modified: trunk/crossfire/src/cfeditor/gui/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2006-11-12 00:15:19 UTC (rev 657) @@ -80,7 +80,7 @@ @Nullable public Object getElementAt(final int index) { try { return ctrl.getScript(index); - } catch (Exception e) { + } catch (final Exception e) { return null; } } Modified: trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/parameter/BooleanParameter.java 2006-11-12 00:15:19 UTC (rev 657) @@ -62,7 +62,7 @@ try { final Boolean iVal = Boolean.valueOf(val); setValue(iVal); - } catch (Exception ex) { + } catch (final Exception ex) { setValue(new Boolean(false)); } ; Modified: trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/parameter/DoubleParameter.java 2006-11-12 00:15:19 UTC (rev 657) @@ -62,18 +62,18 @@ try { final Double iVal = new Double(Double.parseDouble(val)); setValue(iVal); - } catch (Exception ex) { + } catch (final Exception ex) { setValue(new Double(0)); } ; final DoubleConfig o = new DoubleConfig(); try { o.setMin(Double.parseDouble(e.getChildTextTrim("minimum"))); - } catch (Exception ex) { + } catch (final Exception ex) { } try { o.setMax(Double.parseDouble(e.getChildTextTrim("maximum"))); - } catch (Exception ex) { + } catch (final Exception ex) { } setConfig(o); } Modified: trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/parameter/DoubleParameterView.java 2006-11-12 00:15:19 UTC (rev 657) @@ -98,13 +98,13 @@ value = new TooltipSpinner(mdl); try { value.setValue(param.getValue()); - } catch (Exception e) { + } catch (final Exception e) { } value.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent e) { try { parameter.setValue((Double) ((SpinnerNumberModel) value.getModel()).getNumber()); - } catch (Exception ex) { + } catch (final Exception ex) { ex.printStackTrace(); } } @@ -140,7 +140,7 @@ ((SpinnerNumberModel) value.getModel()).setMinimum(new Double(parameter.getMin())); ((SpinnerNumberModel) value.getModel()).setMaximum(new Double(parameter.getMax())); updateTooltip(); - } catch (Exception ex) { + } catch (final Exception ex) { JOptionPane.showMessageDialog(null, "Could not change Double configuration"); } } Modified: trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/parameter/IntegerParameter.java 2006-11-12 00:15:19 UTC (rev 657) @@ -60,17 +60,17 @@ try { final Integer iVal = new Integer(Integer.parseInt(val)); setValue(iVal); - } catch (Exception ex) { + } catch (final Exception ex) { setValue(new Integer(0)); } final IntegerConfig o = new IntegerConfig(); try { o.setMin(Integer.parseInt(e.getChildTextTrim("minimum"))); - } catch (Exception ex) { + } catch (final Exception ex) { } try { o.setMax(Integer.parseInt(e.getChildTextTrim("maximum"))); - } catch (Exception ex) { + } catch (final Exception ex) { } setConfig(o); } Modified: trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java 2006-11-12 00:10:18 UTC (rev 656) +++ trunk/crossfire/src/cfeditor/parameter/IntegerParameterView.java 2006-11-12 00:15:19 UTC (rev 657) @@ -95,13 +95,13 @@ value = new TooltipSpinner(mdl); try { value.setValue(param.getValue()); - } catch (Exception e) { + } catch (final Exception e) { } value.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent e) { try { parameter.setValue((Integer) ((SpinnerNumberModel) value.getModel()).getNumber()); - } catch (Exception ex) { + } catch (final Exception ex) { ex.printStackTrace(); } } @@ -136,7 +136,7 @@ ((SpinnerNumberModel) value.getModel()).setMinimum(new Integer(parameter.getMin())); ((SpinnerNumberModel) value.getModel()).setMaximum(new Integer(parameter.getMax())); updateTooltip(); - } catch (Exception ex) { + } catch (final Exception ex) { JOptionPane.showMessageDialog(null, "Could not change integer configuration"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-21 21:34:13
|
Revision: 680 http://svn.sourceforge.net/gridarta/?rev=680&view=rev Author: christianhujer Date: 2006-11-21 13:34:13 -0800 (Tue, 21 Nov 2006) Log Message: ----------- Replaced manControl.getArchetype(gameObject.getArchetypeName()) with gameObject.getArchetype() Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-11-21 21:27:45 UTC (rev 679) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-11-21 21:34:13 UTC (rev 680) @@ -665,11 +665,11 @@ final boolean hasMessage; if (gameObject.getMsgText() == null && gameObject.getArchetypeName() != null) { archTextArea.setForeground(Color.black); - if (mainControl.getArchetype(gameObject.getArchetypeName()).getMsgText() == null) { + if (gameObject.getArchetype().getMsgText() == null) { archTextArea.setText(""); hasMessage = false; } else { - archTextArea.setText(mainControl.getArchetype(gameObject.getArchetypeName()).getMsgText()); + archTextArea.setText(gameObject.getArchetype().getMsgText()); hasMessage = true; } } else { @@ -688,13 +688,13 @@ archFaceField.setText(gameObject.getFaceName()); } else if (gameObject.getArchetypeName() != null) { archFaceField.setForeground(Color.black); - archFaceField.setText(mainControl.getArchetype(gameObject.getArchetypeName()).getFaceName()); + archFaceField.setText(gameObject.getArchetype().getFaceName()); } // end face // *** OBJECT NAME *** if (gameObject.getObjName() == null && gameObject.getArchetypeName() != null) { archNameField.setForeground(Color.black); - if (mainControl.getArchetype(gameObject.getArchetypeName()).getObjName() == null) { + if (gameObject.getArchetype().getObjName() == null) { // arch name if (gameObject.getArchetypeName() != null) { archNameField.setText(gameObject.getArchetypeName()); @@ -703,7 +703,7 @@ } } else { // default name - archNameField.setText(mainControl.getArchetype(gameObject.getArchetypeName()).getObjName()); + archNameField.setText(gameObject.getArchetype().getObjName()); } } else { // object name ("special") Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-11-21 21:27:45 UTC (rev 679) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-11-21 21:34:13 UTC (rev 680) @@ -438,7 +438,7 @@ } else { final String defname; if (gameObject.getArchetypeName() != null) { - defname = mainControl.getArchetype(gameObject.getArchetypeName()).getObjName(); + defname = gameObject.getArchetype().getObjName(); } else { defname = null; } Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-21 21:27:45 UTC (rev 679) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-21 21:34:13 UTC (rev 680) @@ -361,65 +361,65 @@ /** * Determine which map-squares need to be redrawn after inserting/deleting * the given GameObject. - * @param arch the arch that is inserted or deleted + * @param gameObject the gameObject that is inserted or deleted * @return a <code>Point</code> array containing the coords of the tiles * which need to be redrawn */ - @Nullable Point[] calcArchRedraw(GameObject arch) { - if (arch == null) { // safety check + @Nullable Point[] calcArchRedraw(GameObject gameObject) { + if (gameObject == null) { // safety check return null; } final Point[] redraw; // return value (coords needing redraw) - if (mainControl.getAutojoin() && mainControl.getArchetype(arch.getArchetypeName()).getJoinList() != null) { - // this arch does autojoining: + if (mainControl.getAutojoin() && gameObject.getArchetype().getJoinList() != null) { + // this gameObject does autojoining: // first look how many we need int num = 1; - if (mapControl.isPointValid(arch.getMapX() + 1, arch.getMapY())) { + if (mapControl.isPointValid(gameObject.getMapX() + 1, gameObject.getMapY())) { num++; } - if (mapControl.isPointValid(arch.getMapX(), arch.getMapY() + 1)) { + if (mapControl.isPointValid(gameObject.getMapX(), gameObject.getMapY() + 1)) { num++; } - if (mapControl.isPointValid(arch.getMapX() - 1, arch.getMapY())) { + if (mapControl.isPointValid(gameObject.getMapX() - 1, gameObject.getMapY())) { num++; } - if (mapControl.isPointValid(arch.getMapX(), arch.getMapY() - 1)) { + if (mapControl.isPointValid(gameObject.getMapX(), gameObject.getMapY() - 1)) { num++; } // now get the coordinates redraw = new Point[num]; // create instance of needed size - redraw[--num] = new Point(arch.getMapX(), arch.getMapY()); // center square - if (mapControl.isPointValid(arch.getMapX() + 1, arch.getMapY())) { - redraw[--num] = new Point(arch.getMapX() + 1, arch.getMapY()); + redraw[--num] = new Point(gameObject.getMapX(), gameObject.getMapY()); // center square + if (mapControl.isPointValid(gameObject.getMapX() + 1, gameObject.getMapY())) { + redraw[--num] = new Point(gameObject.getMapX() + 1, gameObject.getMapY()); } - if (mapControl.isPointValid(arch.getMapX(), arch.getMapY() + 1)) { - redraw[--num] = new Point(arch.getMapX(), arch.getMapY() + 1); + if (mapControl.isPointValid(gameObject.getMapX(), gameObject.getMapY() + 1)) { + redraw[--num] = new Point(gameObject.getMapX(), gameObject.getMapY() + 1); } - if (mapControl.isPointValid(arch.getMapX() - 1, arch.getMapY())) { - redraw[--num] = new Point(arch.getMapX() - 1, arch.getMapY()); + if (mapControl.isPointValid(gameObject.getMapX() - 1, gameObject.getMapY())) { + redraw[--num] = new Point(gameObject.getMapX() - 1, gameObject.getMapY()); } - if (mapControl.isPointValid(arch.getMapX(), arch.getMapY() - 1)) { - redraw[--num] = new Point(arch.getMapX(), arch.getMapY() - 1); + if (mapControl.isPointValid(gameObject.getMapX(), gameObject.getMapY() - 1)) { + redraw[--num] = new Point(gameObject.getMapX(), gameObject.getMapY() - 1); } assert num == 0; - } else if (arch.isMulti()) { - arch = arch.getHead(); // make sure we got the head + } else if (gameObject.isMulti()) { + gameObject = gameObject.getHead(); // make sure we got the head - int num = arch.getMultiRefCount(); // get number of parts + int num = gameObject.getMultiRefCount(); // get number of parts redraw = new Point[num]; // create instance of needed size - for (GameObject tmp = arch; num > 0 && tmp != null; + for (GameObject tmp = gameObject; num > 0 && tmp != null; num--, tmp = tmp.getMultiNext()) { redraw[num - 1] = new Point(tmp.getMapX(), tmp.getMapY()); } assert num == 0; } else { - // just an ordinary single-square arch + // just an ordinary single-square gameObject redraw = new Point[1]; - redraw[0] = new Point(arch.getMapX(), arch.getMapY()); + redraw[0] = new Point(gameObject.getMapX(), gameObject.getMapY()); } return redraw; Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2006-11-21 21:27:45 UTC (rev 679) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2006-11-21 21:34:13 UTC (rev 680) @@ -413,7 +413,7 @@ final String text = gameObject.getObjectText(); final int len = text.length(); // TODO can't this be replaced by archetype = gameObject.getArchetype() ? - final GameObject archetype = mainControl.getArchetype(gameObject.getArchetypeName()); + final GameObject archetype = gameObject.getArchetype(); gameObject.resetObjectText(); for (int i = 0, s = 0; i < len; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-26 10:48:34
|
Revision: 686 http://svn.sourceforge.net/gridarta/?rev=686&view=rev Author: akirschbaum Date: 2006-11-26 02:48:33 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Unify ReplaceDialog initialization. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/ReplaceDialog.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-11-26 10:42:23 UTC (rev 685) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-11-26 10:48:33 UTC (rev 686) @@ -197,8 +197,6 @@ menu = new CMainMenu(mainControl); setJMenuBar(menu); - ReplaceDialog.init(mainControl); // initialize replace dialog - // initialize pickmap panel pickmapPanel = new JTabbedPane(JTabbedPane.TOP); pickmapPanel.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 10:42:23 UTC (rev 685) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 10:48:33 UTC (rev 686) @@ -102,18 +102,15 @@ replaceArch = null; } - public static void init(final CMainControl mainControl) { - if (instance == null) { - instance = new ReplaceDialog(mainControl); - } - } - /** @return true when this frame has been fully built */ public static boolean isBuilt() { return instance != null && instance.isBuilt; } public static ReplaceDialog getInstance() { + if (instance == null) { + instance = new ReplaceDialog(CMainControl.getInstance()); + } return instance; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-26 16:06:36
|
Revision: 702 http://svn.sourceforge.net/gridarta/?rev=702&view=rev Author: akirschbaum Date: 2006-11-26 08:06:35 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Unify variable/method names. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainMenu.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapControl.java Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-11-26 16:06:35 UTC (rev 702) @@ -112,8 +112,8 @@ // In JDK 1.4 it is required to transfer focus back to mapview after // every click in the panel, otherwise the menu-shortcuts stop working if (mainControl.getCurrentMap() != null && - mainControl.getCurrentMap().getMapView() != null) { - mainControl.getCurrentMap().getMapView().requestFocus(); // focus to mapview + mainControl.getCurrentMap().getMapViewFrame() != null) { + mainControl.getCurrentMap().getMapViewFrame().requestFocus(); // focus to mapview } } }); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-26 16:06:35 UTC (rev 702) @@ -378,7 +378,7 @@ } void setMapAndArchPosition(final int archid, final Point pos) { - currentMap.getMapView().setMapAndArchPosition(archid, pos); + currentMap.getMapViewFrame().setMapAndArchPosition(archid, pos); } /** @@ -583,7 +583,7 @@ if (levels.size() > 0) { for (final Enumeration<MapControl> enu = levels.elements(); enu.hasMoreElements();) { final MapControl level = enu.nextElement(); - level.getMapView().updateLookAndFeel(); + level.getMapViewFrame().updateLookAndFeel(); if (log.isDebugEnabled()) { log.debug("map " + level.getMapName()); } @@ -602,12 +602,12 @@ return false; } - return currentMap.getMapView().isGridVisible(); + return currentMap.getMapViewFrame().isGridVisible(); } public void setGridVisibility(final boolean fVisible) { if (currentMap != null) { - currentMap.getMapView().setGridVisibility(fVisible); + currentMap.getMapViewFrame().setGridVisibility(fVisible); } } @@ -658,8 +658,8 @@ final MapControl map = new MapControl(this, objects, maparch, false, initial); if (show) { - mainView.addLevelView(map.getMapView()); // one view... - map.getMapView().setAutoscrolls(true); + mainView.addLevelView(map.getMapViewFrame()); // one view... + map.getMapViewFrame().setAutoscrolls(true); levels.addElement(map); setCurrentLevel(map); refreshMenusAndToolbars(); @@ -675,7 +675,7 @@ if (currentMap != null) { closeLevel(currentMap, false); if (currentMap != null) { - mainView.setCurrentLevelView(currentMap.getMapView()); + mainView.setCurrentLevelView(currentMap.getMapViewFrame()); } } } @@ -685,7 +685,7 @@ for (; levels.size() > 0;) { closeLevel(currentMap, false); if (currentMap != null) { - mainView.setCurrentLevelView(currentMap.getMapView()); + mainView.setCurrentLevelView(currentMap.getMapViewFrame()); } } } @@ -751,7 +751,7 @@ // Notify the level about the closing mainView.setMapTileList(null, -1); level.levelCloseNotify(); - mainView.removeLevelView(level.getMapView()); + mainView.removeLevelView(level.getMapViewFrame()); levels.removeElement(level); currentMap = null; @@ -1118,7 +1118,7 @@ if (!filename.endsWith(".png")) { filename += ".png"; } - mc.getMapView().printFullImage(filename); + mc.getMapViewFrame().printFullImage(filename); } } catch (final IOException e) { showMessage("Couln't create Image", "The image could not be created because the" + @@ -1154,7 +1154,7 @@ if (!filename.endsWith(".png")) { filename += ".png"; } - mapc.getMapView().printFullImage(filename); + mapc.getMapViewFrame().printFullImage(filename); if (log.isInfoEnabled()) { log.info("Created image \"" + filename + "\" of map " + mapc.getMapFileName() + "."); } @@ -1253,7 +1253,7 @@ if (exitPos.x == 0 && exitPos.y == 0) { showMessage("Destination Invalid", "This exit points nowhere."); } else if (currentMap.isPointValid(exitPos)) { - currentMap.getMapView().setHotspot(exitPos.x, exitPos.y); + currentMap.getMapViewFrame().setHotspot(exitPos.x, exitPos.y); } else { showMessage("Destination Invalid", "The destination of this exit is outside the map."); } @@ -1294,7 +1294,7 @@ exitPos.x = currentMap.getMapModel().getMapArchObject().getEnterX(); exitPos.y = currentMap.getMapModel().getMapArchObject().getEnterY(); } - currentMap.getMapView().setHotspot(exitPos.x, exitPos.y); // set hotspot + currentMap.getMapViewFrame().setHotspot(exitPos.x, exitPos.y); // set hotspot // Update the main view so the new map instantly pops up. mainView.update(mainView.getGraphics()); @@ -1337,8 +1337,8 @@ openFile(newfile); // open the new map // set viewport view on the new map - final JViewport newViewPort = currentMap.getMapView().getViewPort(); - final JViewport oldViewPort = oldmap.getMapView().getViewPort(); + final JViewport newViewPort = currentMap.getMapViewFrame().getViewPort(); + final JViewport oldViewPort = oldmap.getMapViewFrame().getViewPort(); final Rectangle scrollto; // new vieport rect if (direction == IGUIConstants.SOUTH) { @@ -1452,7 +1452,7 @@ /** "Clear" was selected from the Edit menu. */ public void clearWanted() { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } @@ -1461,7 +1461,7 @@ /** "Cut" was selected from the Edit menu. */ public void cutWanted() { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } @@ -1470,7 +1470,7 @@ /** "Copy" was selected from the Edit menu. */ public void copyWanted() { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } @@ -1479,7 +1479,7 @@ /** "Paste" was selected from the Edit menu. */ public void pasteWanted() { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } @@ -1491,7 +1491,7 @@ * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" */ public void fillWanted(final boolean fillBelow) { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } @@ -1513,7 +1513,7 @@ * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" */ private void fillRandomWanted(final boolean fillBelow) { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } @@ -1541,7 +1541,7 @@ /** "Replace" was selected from the Edit menu. */ public void replace() { - if (currentMap == null || currentMap.getMapView() == null) { + if (currentMap == null || currentMap.getMapViewFrame() == null) { return; // this should never be possible, but I just wanna make sure... } Modified: trunk/crossfire/src/cfeditor/CMainMenu.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainMenu.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/CMainMenu.java 2006-11-26 16:06:35 UTC (rev 702) @@ -1314,7 +1314,7 @@ m_showTiles.setEnabled(foundATile); m_showTiles.setChecked(mainControl.getCurrentMap().isTileShow()); // Cut/Copy only when there is a highlighted tile selection - if (mainControl.getCurrentMap().getMapView().isHighlight()) { + if (mainControl.getCurrentMap().getMapViewFrame().isHighlight()) { m_clear.setEnabled(true); m_cut.setEnabled(true); m_copy.setEnabled(true); Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-11-26 16:06:35 UTC (rev 702) @@ -301,11 +301,11 @@ // get the active pickmap final MapControl pmap = CPickmapPanel.getInstance().getCurrentPickmap(); - if (pmap != null && pmap.getMapView().isHighlight()) { + if (pmap != null && pmap.getMapViewFrame().isHighlight()) { // now try to get the topmost object GameObject arch = null; - if (pmap.isPointValid(pmap.getMapView().getHighlightStart())) { - arch = (GameObject) pmap.getMapModel().getMapSquare(pmap.getMapView().getHighlightStart()).getFirst(); + if (pmap.isPointValid(pmap.getMapViewFrame().getHighlightStart())) { + arch = (GameObject) pmap.getMapModel().getMapSquare(pmap.getMapViewFrame().getHighlightStart()).getFirst(); } if (arch != null) { // so here we return the arch from the pickmap Modified: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-11-26 16:06:35 UTC (rev 702) @@ -209,7 +209,7 @@ */ @Nullable private CMapViewBasic newPickmap(final List<GameObject> objects, final MapArchObject maparch, final File mapFile) { final MapControl map = new MapControl(mainControl, objects, maparch, true, null); - map.getMapView().setAutoscrolls(true); + map.getMapViewFrame().setAutoscrolls(true); map.setMapFile(mapFile); // add pickmap to hashtable @@ -218,7 +218,7 @@ currentPickMap = map; map.getMapModel().resetLevelChangedFlag(); - return map.getMapView().getBasicView(); + return map.getMapViewFrame().getBasicView(); } /** @@ -235,7 +235,7 @@ final MapControl tmpMap = pickmaps.get(tmpKey); if (tmpMap == mapControl) { pickmaps.remove(tmpKey); - tabpane.remove(tmpMap.getMapView().getBasicView()); + tabpane.remove(tmpMap.getMapViewFrame().getBasicView()); mapClosed = true; } } @@ -254,7 +254,7 @@ public void setActivePickmap(final String name) { final MapControl tmpMap = pickmaps.get(name); if (tmpMap != null) { - tabpane.setSelectedComponent(tmpMap.getMapView().getBasicView()); + tabpane.setSelectedComponent(tmpMap.getMapViewFrame().getBasicView()); } } Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-11-26 16:06:35 UTC (rev 702) @@ -139,10 +139,10 @@ * @param mode defines if we have a cut, copy or paste action */ private void copyNCut(final MapControl mapControl, final Mode mode) { - final Point startp = mapControl.getMapView().getHighlightStart(); // start of highlighted rect - final Point offset = mapControl.getMapView().getHighlightOffset(); // offset of rect from startp + final Point startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect + final Point offset = mapControl.getMapViewFrame().getHighlightOffset(); // offset of rect from startp - if (!mapControl.getMapView().isHighlight()) { // should actually never happen + if (!mapControl.getMapViewFrame().isHighlight()) { // should actually never happen return; } @@ -228,9 +228,9 @@ * @param mapControl MapControl of the active map we paste on */ public void paste(final MapControl mapControl) { - final Point startp = mapControl.getMapView().getHighlightStart(); // start of highlighted rect + final Point startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect - if (!mapControl.getMapView().isHighlight()) { // should actually never happen + if (!mapControl.getMapViewFrame().isHighlight()) { // should actually never happen return; } @@ -286,11 +286,11 @@ * @todo the fill density is ignored for floodfill */ public void fill(final MapControl mapControl, final boolean fillBelow, final int density) { - final Point startp = mapControl.getMapView().getHighlightStart(); // start of highlighted rect - final Point offset = mapControl.getMapView().getHighlightOffset(); // offset of rect from startp + final Point startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect + final Point offset = mapControl.getMapViewFrame().getHighlightOffset(); // offset of rect from startp final Point pos = new Point(); - if (!mapControl.getMapView().isHighlight()) { // should actually never happen + if (!mapControl.getMapViewFrame().isHighlight()) { // should actually never happen return; } Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 16:06:35 UTC (rev 702) @@ -138,7 +138,7 @@ line1.add(labelon); line1.add(Box.createVerticalStrut(3)); replaceEntireBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceOnMap"), ACTION_FACTORY.getString("replaceOnSelection")}); - if (mapControl.getMapView().isHighlight()) { + if (mapControl.getMapViewFrame().isHighlight()) { replaceEntireBox.setSelectedIndex(1); } else { replaceEntireBox.setSelectedIndex(0); @@ -223,7 +223,7 @@ colonLabel.setText(":"); } - if (mapControl.getMapView().isHighlight()) { + if (mapControl.getMapViewFrame().isHighlight()) { replaceEntireBox.setSelectedIndex(1); // selected squares } else { replaceEntireBox.setSelectedIndex(0); // entire map @@ -289,8 +289,8 @@ final Size2D mapSize = mapControl.getMapSize(); offset = new Point(mapSize.getWidth() - 1, mapSize.getHeight() - 1); } else { - startp = mapControl.getMapView().getHighlightStart(); // start of highlighted rect - offset = mapControl.getMapView().getHighlightOffset(); // offset of rect from startp + startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect + offset = mapControl.getMapViewFrame().getHighlightOffset(); // offset of rect from startp } // convert negative 'offset' into positive by flipping 'startp' @@ -400,7 +400,7 @@ if (mapControl == null || mapControl.isClosing()) { setVisible(false); ACTION_FACTORY.showMessageDialog(this, "replaceMapGone", mapControl.getMapFileName()); - } else if (!entireMap && !mapControl.getMapView().isHighlight()) { + } else if (!entireMap && !mapControl.getMapViewFrame().isHighlight()) { // user selected "replace highlighted" but nothing is highlighted ACTION_FACTORY.showMessageDialog(this, "replaceMapNoSelection", mapControl.getMapFileName()); } else { Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-11-26 16:06:35 UTC (rev 702) @@ -79,7 +79,7 @@ * @return the position to show */ @Nullable public Point getMouseRightPos() { - final Point pos = mapControl.getMapView().getMapMouseRightPos(); + final Point pos = mapControl.getMapViewFrame().getMapMouseRightPos(); if (pos.x == -1 || pos.y == -1 || !isPointValid(pos)) { return null; @@ -121,8 +121,8 @@ // change status and update title bar levelChanged = false; - if (mapControl.getMapView() != null) { - mapControl.getMapView().changedFlagNotify(); + if (mapControl.getMapViewFrame() != null) { + mapControl.getMapViewFrame().changedFlagNotify(); } } @@ -136,8 +136,8 @@ // change status and update title bar levelChanged = true; - if (mapControl.getMapView() != null) { - mapControl.getMapView().changedFlagNotify(); + if (mapControl.getMapViewFrame() != null) { + mapControl.getMapViewFrame().changedFlagNotify(); } // enable menu file->revert to revert the map @@ -587,7 +587,7 @@ * @return GameObject exit-arch if existent, otherwise null */ @Nullable public GameObject getExit() { - final Point hspot = mapControl.getMapView().getHighlightStart(); // selected spot + final Point hspot = mapControl.getMapViewFrame().getHighlightStart(); // selected spot if (!isPointValid(hspot)) { return null; // out of map @@ -622,12 +622,12 @@ super.resizeMap(newSize); // an important last point: if there is a highlighted area in a region // that got cut off - unhilight it! - final int mposx = mapControl.getMapView().getHighlightStart().x; - final int mposy = mapControl.getMapView().getHighlightStart().y; + final int mposx = mapControl.getMapViewFrame().getHighlightStart().x; + final int mposy = mapControl.getMapViewFrame().getHighlightStart().y; if (!isPointValid(mposx, mposy) || - !isPointValid(mposx + mapControl.getMapView().getHighlightOffset().x, - mposy + mapControl.getMapView().getHighlightOffset().y)) { - mapControl.getMapView().unHighlight(); + !isPointValid(mposx + mapControl.getMapViewFrame().getHighlightOffset().x, + mposy + mapControl.getMapViewFrame().getHighlightOffset().y)) { + mapControl.getMapViewFrame().unHighlight(); } setLevelChangedFlag(); // the map changed for sure! Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-11-26 16:01:04 UTC (rev 701) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-11-26 16:06:35 UTC (rev 702) @@ -57,7 +57,7 @@ /** * Main view of this map. */ - private final MapViewIFrame mapView; + private final MapViewIFrame mapViewFrame; private File mapFile; @@ -108,7 +108,7 @@ // we create model (= data) mapModel = new DefaultMapModel(mainControl, this, objects, maparch); // and create a view (= window) - mapView = new MapViewIFrame(mainControl, this, initial); + mapViewFrame = new MapViewIFrame(mainControl, this, initial); } /** {@inheritDoc} */ @@ -307,14 +307,14 @@ * Repaints the view. */ public void repaint() { - mapView.modelChanged(); + mapViewFrame.modelChanged(); } /** * Notifies the view that data has changed in the model. */ void notifyViews() { - mapView.refreshDataFromModel(); + mapViewFrame.refreshDataFromModel(); } /** @@ -330,7 +330,7 @@ * @return the current view position */ public Point getViewPosition() { - return mapView.getViewPosition(); + return mapViewFrame.getViewPosition(); } /** @@ -437,7 +437,7 @@ } public void setMapFileName(final String fname) { - mapView.setTitle("Map [" + fname + "]"); + mapViewFrame.setTitle("Map [" + fname + "]"); mapModel.setFileName(fname); } @@ -465,7 +465,7 @@ assert mapFile != null; mainControl.encodeMapFile(mapFile, mapModel); mapModel.resetLevelChangedFlag(); - mapView.changedFlagNotify(); + mapViewFrame.changedFlagNotify(); } /** @@ -476,7 +476,7 @@ CMainStatusbar.getInstance().setText("Saving the map to a file..."); mainControl.encodeMapFile(file, mapModel); mapModel.resetLevelChangedFlag(); - mapView.changedFlagNotify(); + mapViewFrame.changedFlagNotify(); } public void setMapFile(final File file) { @@ -487,8 +487,8 @@ return mapModel; } - public MapViewIFrame getMapView() { - return mapView; + public MapViewIFrame getMapViewFrame() { + return mapViewFrame; } public MapArchObject getMapArch() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-26 17:10:09
|
Revision: 707 http://svn.sourceforge.net/gridarta/?rev=707&view=rev Author: akirschbaum Date: 2006-11-26 09:10:04 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Unify method names. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchQuickView.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/gui/ArchComboBox.java Modified: trunk/crossfire/src/cfeditor/CArchQuickView.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-11-26 17:10:04 UTC (rev 707) @@ -153,7 +153,7 @@ } void refresh() { - mainControl.showArchPanelQuickObject(mainControl.getArchPanelSelection()); + mainControl.showArchPanelQuickObject(mainControl.getArchPanelHighlight()); repaint(); } Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-26 17:10:04 UTC (rev 707) @@ -485,9 +485,9 @@ } } - // ask arch panel which arch is selectd - public GameObject getArchPanelSelection() { - return mainView.getArchPanelSelection(); + // ask arch panel which arch is highlighted + public GameObject getArchPanelHighlight() { + return mainView.getArchPanelHighlight(); } // setup quick view window Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-11-26 17:10:04 UTC (rev 707) @@ -293,7 +293,7 @@ * IMPORTANT: The returned GameObject is not a clone. A copy * must be generated before inserting such an arch to the map. */ - public GameObject getArchPanelSelection() { + public GameObject getArchPanelHighlight() { if ((isPickmapActive() || archPanel.getArchPanelSelection() == null) && CPickmapPanel.getInstance().isLoadComplete() && Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-11-26 17:10:04 UTC (rev 707) @@ -257,7 +257,7 @@ invChange.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { - final GameObject arch = mainControl.getArchPanelSelection(); + final GameObject arch = mainControl.getArchPanelHighlight(); if (arch == null) { // nothing selected? return; } Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-11-26 17:10:04 UTC (rev 707) @@ -186,14 +186,14 @@ ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0 && e.isShiftDown())) { // --- right mouse button: insert arch --- - if (currentSquare != null && mainControl.getArchPanelSelection() != null) { + if (currentSquare != null && mainControl.getArchPanelHighlight() != null) { final int listIndex = getListIndex(e); if (listIndex >= list.getModel().getSize()) { - mainControl.insertArchToMap(mainControl.getArchPanelSelection(), mainControl.getPanelArch(), null, currentSquare, MapModel.JOIN_ENABLE); + mainControl.insertArchToMap(mainControl.getArchPanelHighlight(), mainControl.getPanelArch(), null, currentSquare, MapModel.JOIN_ENABLE); } else { final String entry = model.getElementAt(listIndex).toString(); final int num = Integer.parseInt(entry.substring(0, 10)); - mainControl.insertArchToMap(mainControl.getArchPanelSelection(), mainControl.getPanelArch(), mainControl.getMapArch(num, currentSquare), currentSquare, MapModel.JOIN_ENABLE); + mainControl.insertArchToMap(mainControl.getArchPanelHighlight(), mainControl.getPanelArch(), mainControl.getMapArch(num, currentSquare), currentSquare, MapModel.JOIN_ENABLE); } // refresh Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-26 17:10:04 UTC (rev 707) @@ -1240,7 +1240,7 @@ needRedraw = insertSelArchToMap(mapLoc, true); // get name of inserted arch (this is display in status bar while dragging) - @Nullable final GameObject insArch = mainControl.getArchPanelSelection(); + @Nullable final GameObject insArch = mainControl.getArchPanelHighlight(); if (insArch != null) { if (insArch.getObjName() != null && insArch.getObjName().length() > 0) { insertArchName = insArch.getObjName(); @@ -1345,7 +1345,7 @@ // this is the arch that would get inserted from pickmap, but it also could // be a default arch (when pickmap has no selection) - GameObject newarch = mainControl.getArchPanelSelection(); + GameObject newarch = mainControl.getArchPanelHighlight(); if (!mainControl.getMainView().isPickmapActive() || mapControl.isPickmap() || (newarch != null && newarch.isArchetype())) { Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-11-26 17:10:04 UTC (rev 707) @@ -294,7 +294,7 @@ return; // should actually never happen } - if (mainControl.getArchPanelSelection() == null) { // no selected arch to fill with + if (mainControl.getArchPanelHighlight() == null) { // no selected arch to fill with return; } @@ -302,7 +302,7 @@ final GameObject arch; if (offset.x == 0 && offset.y == 0 && !mapControl.containsArchObject(startp)) { - arch = mainControl.getArchPanelSelection(); + arch = mainControl.getArchPanelHighlight(); if (arch != null) { floodfill(mapControl, startp.x, startp.y, arch); } @@ -319,7 +319,7 @@ } // get the arch to fill with - arch = mainControl.getArchPanelSelection(); + arch = mainControl.getArchPanelHighlight(); // cycle through all tile coordinates which are highlighted: for (pos.x = startp.x; pos.x - startp.x <= offset.x; pos.x++) { Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 17:10:04 UTC (rev 707) @@ -124,7 +124,7 @@ * @param mapControl MapControl of the active map where the action was invoked */ public void display(final MapControl mapControl) { - replaceArch = mainControl.getArchPanelSelection(); // selected arch + replaceArch = mainControl.getArchPanelHighlight(); // highlighted arch if (!isBuilt) { this.mapControl = mapControl; @@ -372,7 +372,7 @@ switch (selectedIndex) { case 0: // replace with arch - replaceArch = mainControl.getArchPanelSelection(); // selected arch + replaceArch = mainControl.getArchPanelHighlight(); // selected arch updateArchSelection(replaceArch, true); break; Modified: trunk/crossfire/src/cfeditor/gui/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-11-26 16:22:58 UTC (rev 706) +++ trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2006-11-26 17:10:04 UTC (rev 707) @@ -141,7 +141,7 @@ fromSelect.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { try { - final GameObject ao = archComboBoxModel.getNearsetMatch(mainControl.getArchPanelSelection().getArchetypeName()); + final GameObject ao = archComboBoxModel.getNearsetMatch(mainControl.getArchPanelHighlight().getArchetypeName()); setSelectedItem(ao); setItem(ao); } catch (final Exception ex) {//null pointer exception This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-26 20:06:01
|
Revision: 723 http://svn.sourceforge.net/gridarta/?rev=723&view=rev Author: akirschbaum Date: 2006-11-26 12:06:01 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Unify checking for duplicate archetypes when adding game objects to maps. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/map/MapModel.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-26 20:06:01 UTC (rev 723) @@ -509,8 +509,8 @@ return JFontChooser.msgToHtml(msg, null); } - boolean addArchToMap(final String archname, final Point pos, final int intern, final boolean join) { - return currentMap.addArchToMap(archname, pos, intern, join); + boolean addArchToMap(final String archname, final Point pos, final boolean allowDouble, final boolean join) { + return currentMap.addArchToMap(archname, pos, allowDouble, join); } boolean insertArchToMap(final GameObject newarch, final String archname, final GameObject next, final Point pos, final boolean join) { Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-11-26 20:06:01 UTC (rev 723) @@ -113,9 +113,6 @@ private final boolean[] needMpanelUpdate; // indicates that the mapArchPanel needs - // to be updated when mousebutton is released - private int drawInternCount; - // interface for the mapview frame private final MapView frame; @@ -139,7 +136,6 @@ needMpanelUpdate[0] = false; needMpanelUpdate[1] = false; needMpanelUpdate[2] = false; - drawInternCount = 0; mapMousePos.x = -1; mapMousePos.y = -1; mapMouseRightPos.x = -1; @@ -1350,7 +1346,7 @@ if (!mainControl.getMainView().isPickmapActive() || mapControl.isPickmap() || (newarch != null && newarch.isArchetype())) { // insert default arch from archlist: - if (!mapControl.addArchToMap(mainControl.getPanelArch(), pos, allowMany ? -1 : drawInternCount, MapModel.JOIN_ENABLE)) { + if (!mapControl.addArchToMap(mainControl.getPanelArch(), pos, allowMany, MapModel.JOIN_ENABLE)) { // mainControl.getMainView().mapPanel.setMapArchList(null); // Toolkit.getDefaultToolkit().beep(); } else { @@ -1385,7 +1381,7 @@ // insert multi tile from pickmap: newarch = newarch.getHead(); // first insert default arch from archlist - if (!mapControl.addArchToMap(newarch.getArchetypeName(), pos, allowMany ? -1 : drawInternCount, MapModel.JOIN_DISABLE)) { + if (!mapControl.addArchToMap(newarch.getArchetypeName(), pos, allowMany, MapModel.JOIN_DISABLE)) { // do nothing } else { // insertion successful, now get redraw info @@ -1451,7 +1447,7 @@ } // first insert default arch from archlist - if (!allSpacesFree || !mapControl.addArchToMap(newarch.getArchetypeName(), pos, -1, MapModel.JOIN_DISABLE)) { + if (!allSpacesFree || !mapControl.addArchToMap(newarch.getArchetypeName(), pos, true, MapModel.JOIN_DISABLE)) { // do nothing } else { // insertion successful, now get redraw info Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-11-26 20:06:01 UTC (rev 723) @@ -264,7 +264,7 @@ sourcePos.y = pos.y - startp.y; for (final GameObject gameObject : copyMapCtrl.getMapModel().getMapSquare(sourcePos)) { if (gameObject.isMulti()) { - addArchToMap(mapControl, gameObject, pos, -1, false); + addArchToMap(mapControl, gameObject, pos, true, false); } } } @@ -328,7 +328,7 @@ continue; } // Insert the new arch into the map - addArchToMap(mapControl, arch, pos, 0, fillBelow); + addArchToMap(mapControl, arch, pos, false, fillBelow); } } } @@ -349,7 +349,7 @@ * @param arch GameObject to fill with */ private void floodfill(final MapControl mapControl, final int startX, final int startY, final GameObject arch) { - addArchToMap(mapControl, arch, new Point(startX, startY), 0, false); + addArchToMap(mapControl, arch, new Point(startX, startY), false, false); // now go recursive into all four directions if (mapControl.isPointValid(startX - 1, startY) && !mapControl.containsArchObject(startX - 1, startY)) { @@ -370,10 +370,10 @@ * Add an archetype to the destination map. Inserts a new object instance * for default archetypes, and a clone for non-default archetypes. */ - private void addArchToMap(final MapControl mapControl, final GameObject gameObject, final Point pos, final int intern, final boolean fillBelow) { + private void addArchToMap(final MapControl mapControl, final GameObject gameObject, final Point pos, final boolean allowDouble, final boolean fillBelow) { final GameObject newHead; if (gameObject.isArchetype()) { - mapControl.addArchToMap(gameObject.getArchetypeName(), pos, intern, false, fillBelow); + mapControl.addArchToMap(gameObject.getArchetypeName(), pos, allowDouble, false, fillBelow); } else { newHead = gameObject.createClone(pos.x, pos.y); for (GameObject tmp = gameObject.getArchetype().getMultiNext(); tmp != null; tmp = tmp.getMultiNext()) { Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-11-26 20:06:01 UTC (rev 723) @@ -344,7 +344,7 @@ if (replaceArch.isMulti()) { // multi's cannot be inserted properly, so we just put them ontop replaceArch = replaceArch.getHead(); - mapControl.addArchToMap(replaceArch.getArchetypeName(), pos, 0, false); + mapControl.addArchToMap(replaceArch.getArchetypeName(), pos, false, false); // TODO: if from pickmap it could have special attributes -> copy them } else { Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-11-26 20:06:01 UTC (rev 723) @@ -208,28 +208,19 @@ return isPointValid(pos) && !mapGrid[pos.x][pos.y].isEmpty(); } - /** - * Check if a given archetype fits within map bounds. Multi tiles can't be - * set if going out of borders. - * @param archName the archetype to check - * @param xx the x-coordinate to place archName - * @param yy the y-coordinate to place archName - * @param intern ??? - */ - private boolean testArchToMap(final String archName, final int xx, final int yy, final int intern) { + /** {@inheritDoc} */ + public boolean isMultiArchFittingToMap(final String archName, final Point pos, final boolean allowDouble) { for (GameObject part = getArchetype(archName); part != null; part = part.getMultiNext()) { - final int mapx = xx + part.getMultiX(); - final int mapy = yy + part.getMultiY(); + final int mapx = pos.x + part.getMultiX(); + final int mapy = pos.y + part.getMultiY(); if (!isPointValid(mapx, mapy)) { // outside map return false; } - if (intern != -1) { // we use this different - only one object + if (!allowDouble) { final String temp = part.getArchetypeName(); - // run through map parts and test for intern counter - // if == intern, this is painted from this action for (final GameObject node : getMapSquare(new Point(mapx, mapy))) { if (node.getArchetypeName().equals(temp)) { return false; @@ -241,8 +232,8 @@ return true; } - @Deprecated public boolean addArchToMap(final String archName, final int xx, final int yy, final int intern, final boolean join, final boolean insertBelow) { - return addArchToMap(archName, new Point(xx, yy), intern, join, insertBelow); + @Deprecated public boolean addArchToMap(final String archName, final int xx, final int yy, final boolean allowDouble, final boolean join, final boolean insertBelow) { + return addArchToMap(archName, new Point(xx, yy), allowDouble, join, insertBelow); } /** @@ -250,7 +241,7 @@ * allows only to choose from the default arches (->archName). * @param archName Name of a default arch on the ArchetypeSet * @param pos insert-location on this map - * @param intern if NOT '-1': only one arch of the same kind can be + * @param allowDouble if set, only one arch of the same kind can be * inserted per square * @param join if set to JOIN_ENABLE auto-joining is supported; autojoining * is only done if enabled in the main control @@ -258,14 +249,14 @@ * inserted below * @return true if insertion successful, false if not */ - public boolean addArchToMap(String archName, final Point pos, final int intern, final boolean join, final boolean insertBelow) { + public boolean addArchToMap(String archName, final Point pos, final boolean allowDouble, final boolean join, final boolean insertBelow) { GameObject newarch; // our new suckers (copys, not ref ptrs) if (archName == null || !isPointValid(pos)) { // invalid parameter return false; } - if (!testArchToMap(archName, pos.x, pos.y, intern)) { + if (!isMultiArchFittingToMap(archName, pos, allowDouble)) { // does not fit on map return false; } @@ -354,7 +345,7 @@ archName = newarch.getArchetypeName(); } // insert a new instance of the default arch (number 'archName') - if (!mapControl.addArchToMap(archName, pos, -1, join)) { + if (!mapControl.addArchToMap(archName, pos, true, join)) { return false; } } else { Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-11-26 20:06:01 UTC (rev 723) @@ -199,26 +199,26 @@ return levelClosing; } - public boolean addArchToMap(final String archname, final Point pos, final int intern, final boolean join, final boolean insertBelow) { - return mapModel.addArchToMap(archname, pos, intern, join, insertBelow); + public boolean addArchToMap(final String archname, final Point pos, final boolean allowDouble, final boolean join, final boolean insertBelow) { + return mapModel.addArchToMap(archname, pos, allowDouble, join, insertBelow); } /** wrapper method for addArchToMap, always inserting new arches on top */ - public boolean addArchToMap(final String archname, final Point pos, final int intern, final boolean join) { - return addArchToMap(archname, pos, intern, join, false); + public boolean addArchToMap(final String archname, final Point pos, final boolean allowDouble, final boolean join) { + return addArchToMap(archname, pos, allowDouble, join, false); } /** wrapper method for addArchToMap, always inserting new arches on top. * @param archname * @param xx * @param yy - * @param intern + * @param allowDouble * @param join * @return <code>true</code> if insertion is successful, <code>false</code> if not * @deprecated use {@link #addArchToMap(String, Point, int, boolean, boolean)} instead */ - @Deprecated public boolean addArchToMap(final String archname, final int xx, final int yy, final int intern, final boolean join) { - return addArchToMap(archname, new Point(xx, yy), intern, join, false); + @Deprecated public boolean addArchToMap(final String archname, final int xx, final int yy, final boolean allowDouble, final boolean join) { + return addArchToMap(archname, new Point(xx, yy), allowDouble, join, false); } public boolean insertArchToMap(final GameObject newarch, final String archname, final GameObject next, final Point pos, final boolean join) { Modified: trunk/crossfire/src/cfeditor/map/MapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapModel.java 2006-11-26 19:53:35 UTC (rev 722) +++ trunk/crossfire/src/cfeditor/map/MapModel.java 2006-11-26 20:06:01 UTC (rev 723) @@ -18,9 +18,21 @@ @Nullable Point getMouseRightPos(); - @Deprecated boolean addArchToMap(String archname, int xx, int yy, int intern, boolean join, boolean insertBelow); - boolean addArchToMap(String archname, Point pos, int intern, boolean join, boolean insertBelow); + /** + * Checks whether an GameObject (multi-arch) would still fit on this map. + * @param archname name of arch to check + * @param pos position of multitile head + * @param allowDouble whether overlapping multitile arches should be allowed (check is done using the arch name) + * @return whether the multi-arch would still fit on this map + * @retval <code>true</code> if the multi-tile arch would still fit on this map + * @retval <code>false</code> otherwise + * @todo discuss whether this method really belongs to the interface of MapModel as it is only used by MapModel implementations and heavily depends on how arches, especially multi-tile arches are implemented. + */ + boolean isMultiArchFittingToMap(String archname, Point pos, boolean allowDouble); + @Deprecated boolean addArchToMap(String archname, int xx, int yy, boolean allowDouble, boolean join, boolean insertBelow); + boolean addArchToMap(String archname, Point pos, boolean allowDouble, boolean join, boolean insertBelow); + @Deprecated boolean insertArchToMap(GameObject newarch, String archname, GameObject next, int mapx, int mapy, boolean join); boolean insertArchToMap(GameObject newarch, String archname, GameObject next, Point pos, boolean join); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-27 22:33:46
|
Revision: 737 http://svn.sourceforge.net/gridarta/?rev=737&view=rev Author: akirschbaum Date: 2006-11-27 14:33:43 -0800 (Mon, 27 Nov 2006) Log Message: ----------- Unify GUI related code in CAttribDialog. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribBitmask.java trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/crossfire/src/cfeditor/messages_sv.properties Modified: trunk/crossfire/src/cfeditor/CAttribBitmask.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribBitmask.java 2006-11-27 22:26:52 UTC (rev 736) +++ trunk/crossfire/src/cfeditor/CAttribBitmask.java 2006-11-27 22:33:43 UTC (rev 737) @@ -24,24 +24,20 @@ package cfeditor; -import java.awt.Color; -import java.awt.FlowLayout; +import java.awt.Component; import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.List; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JDialog; +import static javax.swing.JOptionPane.OK_CANCEL_OPTION; +import static javax.swing.JOptionPane.OK_OPTION; +import static javax.swing.JOptionPane.PLAIN_MESSAGE; +import static javax.swing.JOptionPane.showConfirmDialog; import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.WindowConstants; import org.apache.log4j.Logger; import org.jdom.Attribute; import org.jdom.DataConversionException; import org.jdom.Element; +import org.jetbrains.annotations.Nullable; /** * This class manages bitmask values which appear in Crossfire arch attributes. @@ -55,7 +51,7 @@ /** * Maximum number of characters in a line before linebreak (see {@link - * #getText(int, JTextArea)}). + * #getText(int)}). */ private static final int MAX_CHARS_PER_LINE = 35; // 50 @@ -165,15 +161,11 @@ } /** - * Display the appropriate text for a given bitmask value. - * The text is put into a non-editable textarea. + * Generate the text to be displayed for a given bitmask value. * @param value bitmask value - * @param textf if non-null, this textarea is used for drawing, - * if null, a new textarea is created and returned - * @return <code>JTextArea</code> with all entries belonging to the bitmask - * and proper dimensions + * @return <code>String</code> with all entries belonging to the bitmask */ - public JTextArea getText(final int value, JTextArea textf) { + public String getText(final int value) { String text = " "; // text string to return int rows = 1; // rows of textarea int columns = 1; // columns of textarea (actually not needed) @@ -213,138 +205,34 @@ } } - // create JTextArea (setting columns results in textarea being too wide) - if (textf == null) { - textf = new JTextArea(text + " ", rows, 18); - - // set colors, border and stuff - textf.setForeground(Color.black); - textf.setBackground(CMainControl.getInstance().getMainView().getBackground()); - textf.setEditable(false); - textf.setBorder(BorderFactory.createLineBorder(Color.gray)); - } else { - // textarea already exists, so change it - textf.setText(text + " "); - textf.setRows(rows); - textf.setColumns(18); - } - - return textf; + return text; } /** * Open a popup frame to select bitmask-entries via chooseboxes. + * @param parentComponent the parent component of this dialog + * @param guiAttr Bitmask attribute to update + * @return Integer with new value or <code>null</code> if the user cancelled the dialog */ - public void popupFrame(final CAttribDialog attrDialog, final CAttribDialog.BitmaskAttrib guiAttr) { + @Nullable public Integer showBitmaskDialog(final Component parentComponent, final CAttribDialog.BitmaskAttrib guiAttr) { final String title = "Choose " + guiAttr.ref.getNameNew().substring(0, 1).toUpperCase() + guiAttr.ref.getNameNew().substring(1); - final JDialog frame = new JDialog(attrDialog, title, true); - frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - - // panels - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - final JPanel gridPanel = new JPanel(new GridLayout(1, 2)); - final JPanel leftList = new JPanel(); // left column of checkboxes - leftList.setLayout(new BoxLayout(leftList, BoxLayout.Y_AXIS)); - final JPanel rightList = new JPanel(); // right column of checkboxes - rightList.setLayout(new BoxLayout(rightList, BoxLayout.Y_AXIS)); - final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - - // create checkboxes + final JPanel gridPanel = new JPanel(new GridLayout(0, 2, 3, 3)); final JCheckBox[] checkbox = new JCheckBox[number]; for (int i = 0; i < number; i++) { - checkbox[i] = new JCheckBox(" " + bitName[i + 1]); + checkbox[i] = new JCheckBox(bitName[i + 1]); checkbox[i].setSelected(isActive(i + 1, guiAttr.getValue())); - if (i % 2 == 0) { - leftList.add(checkbox[i]); - } else { - rightList.add(checkbox[i]); - } + gridPanel.add(checkbox[i]); } - gridPanel.add(leftList); - gridPanel.add(rightList); - gridPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - mainPanel.add(gridPanel); - - // buttons - final JButton okButton = new JButton("Ok"); - final JButton cancelButton = new JButton("Cancel"); - buttonPanel.add(okButton); - buttonPanel.add(cancelButton); - mainPanel.add(buttonPanel); - - // attach action listener to the buttons - final PopupFrameAL listener = new PopupFrameAL(frame, guiAttr, this, checkbox, attrDialog); - okButton.addActionListener(listener); - cancelButton.addActionListener(listener); - - // hurl all this litter into the frame, pack and show it - frame.getContentPane().add(mainPanel); - frame.pack(); - frame.setLocationRelativeTo(attrDialog); - frame.setVisible(true); - } - - /** - * Subclass: Action-listener for the buttons in the popup frame - * where changes to the bitmask can be selected. - */ - private class PopupFrameAL implements ActionListener { - - private final CAttribBitmask bitmask; // reference to this CAttribBitmask instance - - private JDialog frame; // reference to the popup dialog frame - - private final CAttribDialog.BitmaskAttrib guiAttr; // gui attribute instance - - private final JCheckBox[] checkbox; // array of checkboxes on the frame - - private final CAttribDialog attrDialog; // instance of attribute dialog (parent frame) - - /** - * Contructor - * @param newFrame thepopup dialog frame - * @param newGuiAttr gui attribute instance - * @param newMask this CAttribBitmask instance - * @param boxarray array of checkboxes in the popup frame - * @param newAttrD attribute dialog frame - */ - private PopupFrameAL(final JDialog newFrame, final CAttribDialog.BitmaskAttrib newGuiAttr, - final CAttribBitmask newMask, final JCheckBox[] boxarray, final CAttribDialog newAttrD) { - frame = newFrame; - guiAttr = newGuiAttr; - bitmask = newMask; - checkbox = boxarray; - attrDialog = newAttrD; - } - - /** - * a button was pressed - * @param event the occured <code>ActionEvent</code> (button pressed) - */ - public void actionPerformed(final ActionEvent event) { - if (event.getSource() instanceof JButton) { - // check if the okay button was pressed - if (((JButton) event.getSource()).getText().equalsIgnoreCase("Ok")) { - // calculate the new bitmask value: - int newValue = 0; - for (int i = 0; i < bitmask.number; i++) { - if (checkbox[i].isSelected()) { - newValue |= (int) (Math.pow(2.0, (double) i)); - } - } - - // update the text component in the CAttribDialog with the new values - bitmask.getText(newValue, guiAttr.text); - attrDialog.update(attrDialog.getGraphics()); - guiAttr.setValue(newValue); + if (showConfirmDialog(parentComponent, gridPanel, title, OK_CANCEL_OPTION, PLAIN_MESSAGE) == OK_OPTION) { + int newValue = 0; + for (int i = 0; i < number; i++) { + if (checkbox[i].isSelected()) { + newValue |= 1 << i; } - - // nuke the dialog frame - frame.dispose(); - frame = null; } + return newValue; } + return null; } } // class CAttribBitmask Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-11-27 22:26:52 UTC (rev 736) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-11-27 22:33:43 UTC (rev 737) @@ -28,20 +28,32 @@ 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.awt.event.WindowListener; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Vector; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; @@ -49,7 +61,10 @@ 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; @@ -61,14 +76,19 @@ 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.Archetype; import net.sf.gridarta.help.Help; +import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -76,44 +96,25 @@ * CAttribDialog poses the GUI for Crossfire object attributes. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class CAttribDialog extends JDialog { +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; - private static int width = 395; + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - private static int height = 505; - - private static int buttonBarHeight = 40; - - private static int inventoryWidth = 100; - - private static final int dividerSize = 3; - // store width of input-textfields, then JChooseBoxes are set to this width too - private static int textFieldWidth = 0; + public static final int TEXTFIELD_COLUMNS = 18; // number of columns for textfields - private static final int textFieldColumns = 18; // number of columns for textfields - - // pixel height of all JChooseBoxes - private static int chooseBoxHeight = 25; - - // the center pane of the dialog can either show the attribute - // input-interface or the summary of nonzero attributes - // the 'displaySummary' flag indicates what is shown: true->summary, false->interface - private boolean displaySummary = false; - private final CMainControl mainControl; // reference to the main control private final CFArchTypeList typelist; // reference to the list of CF type-data - private DialogAttrib attrHead; // head of the list of attribute-GUI components + private List<DialogAttrib<?>> dialogAttribs = new ArrayList<DialogAttrib<?>>(); - private DialogAttrib attrTail; // head of the list of attribute-GUI components - private JComboBox typesel; // selection box for type private JTextField nameTF; // textfield for gameObject name @@ -131,62 +132,77 @@ // this differs from the GameObject if the type is undefined private int listNr; // the position of this type in the type list - // buttons: - private JButton helpButton; + /** The CardLayout for toggling between edit and summary. */ + private final CardLayout cardLayout = new CardLayout(); - private JButton summaryButton; + /** The Action for switching to the summary. */ + private Action summaryAction = ACTION_FACTORY.createAction(false, "attribSummary", this); - private JButton okButton; + /** 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; + private JButton applyButton; /** 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 JScrollPane centerPane; + 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>(); + /** - * Constructor: Creates the GUI layout and - * draws the dialog window. - * @param atList the list of CF type-data - * @param gameObject the GameObject to be displayed by this dialog - * @param mainControl main control + * Wrapper method for the constructor. + * This method only creates a CAttribDialog if there's no dialog for the same gameObject already. + * @param atList the list of CF type-data + * @param gameObject the GameObject to be displayed by this dialog + * @param mainControl main control */ - CAttribDialog(final CFArchTypeList atList, final GameObject gameObject, final CMainControl mainControl) { - super(mainControl.getMainView(), "CF Attribute Dialog", false); - - // when close-box is selected, execute the 'closeDialog' method and nothing else - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override public void windowClosing(final WindowEvent event) { - closeDialog(); + public static void showAttribDialog(final CFArchTypeList atList, final GameObject gameObject, final CMainControl mainControl) { + synchronized (dialogs) { + if (dialogs.containsKey(gameObject)) { + dialogs.get(gameObject).toFront(); + } else { + final CAttribDialog pane = new CAttribDialog(atList, 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); } - }); + } + } - attrHead = null; + /** + * Constructor, creates the GUI layout. + * @param atList the list of CF type-data + * @param gameObject the GameObject to be displayed by this dialog + * @param mainControl main control + */ + private CAttribDialog(final CFArchTypeList atList, final GameObject gameObject, final CMainControl mainControl) { listNr = 0; this.mainControl = mainControl; // reference to the main control typelist = atList; // reference to the typelist - CAttribDialog.setDefaultBounds(); // set width/height etc - // reference to the GameObject this.gameObject = gameObject.getHead(); archetype = this.gameObject.getArchetype(); - /* set frame icon - if (gameObject.getFaceNr() >= 0) { - setIconImage(mainControl.getArchObjectStack().getFace(gameObject.getFaceNr()).getImage()); - } - */ // check if the type of the object is present in the definitions CFArchType tmp = typelist.getHead().getNext(); //typeNr = 0; // for invalid types, we take "type 0" @@ -243,78 +259,54 @@ //type = typelist.getType(typeNr); // first split top-left and -right - final JScrollPane leftPane = buildHeader(); + 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); - splitPane.setOneTouchExpandable(false); - splitPane.setDividerLocation(width - inventoryWidth - 2 * dividerSize); - splitPane.setDividerSize(dividerSize + 1); - //Provide minimum sizes for the two components in the split pane - leftPane.setMinimumSize(new Dimension(width - inventoryWidth - 2 * dividerSize, 120)); - rightPane.setMinimumSize(new Dimension(inventoryWidth, 120)); - // Now split horizontally //JScrollPane centerPane = buildAttr(); - centerPane = buildAttr(); - - //Create a split pane with the two scroll panes in it. - final JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane, centerPane); - splitPane2.setOneTouchExpandable(false); - splitPane2.setDividerLocation(126); - splitPane2.setDividerSize(dividerSize); - - // split horizontally again - final JScrollPane paneButtons = buildButtons(); - final JSplitPane splitPane3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane2, paneButtons); - splitPane3.setOneTouchExpandable(false); - //splitPane3.setDividerLocation(height-buttonBarHeight-34); - splitPane3.setDividerLocation((int) (this.getHeight() - paneButtons.getMinimumSize().height - dividerSize)); - splitPane3.setDividerSize(dividerSize); - splitPane3.setResizeWeight(1); - - getContentPane().add(splitPane3); - - // initialize the summary TextPane + centerPane = new JPanel(cardLayout); + centerPane.add("edit", buildAttr()); summaryTP = new JTextPane(); - summaryTP.setForeground(Color.black); - summaryTP.setBackground(CMainControl.getInstance().getMainView().getBackground()); 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); - this.setResizable(true); - // now draw the whole thing: - setBounds(this.mainControl.getMainView().getX() + (this.mainControl.getMainView().getWidth() - width) / 2, - this.mainControl.getMainView().getY() + (this.mainControl.getMainView().getHeight() - height) / 2 - 20, - width, height); - setVisible(true); + 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); } - /** - * This method sets the default bounds for the dialog frame - * in proportion to the size of the currently used font. - * Not the perfect approach, but it's impossible to have swing do it - * right automatically. Having the user define it would be a - * lot more difficult, and probably not very convenient. - */ - public static void setDefaultBounds() { - width = 395; - height = 505 + 30; - buttonBarHeight = 40; - inventoryWidth = 95; - chooseBoxHeight = 23; + /** {@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. - * @param boxWidth width of the JChooseBox in pixels - * @return a <code>JPanel</code> with the combo box in it + * @return a <code>JComponent</code> with the combo box in it */ - private JPanel buildTypesBox(final int boxWidth) { - final JPanel lineLayout = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // layout for this line - final String []namelist = new String[typelist.getLength()]; // list of typenames + private JComponent buildTypesBox() { + final String[] namelist = new String[typelist.getLength()]; // list of typenames // read all type names CFArchType tmp = typelist.getHead().getNext(); @@ -323,24 +315,18 @@ } // the active type appears selected in the box - final int selection = listNr; + final int selection = listNr; // position of selected type in the list - lineLayout.add(new JLabel("Type: ")); // create label - typesel = new JComboBox(namelist); // set "content" - typesel.setPreferredSize(new Dimension(boxWidth, chooseBoxHeight)); typesel.setSelectedIndex(selection); // set active selection //typesel.setKeySelectionManager(new StringKeyManager(typesel)); - typesel.setBackground(Color.white); // white background typesel.setName("Types"); // the listener: typesel.addItemListener(new TypesBoxAL(this, gameObject)); - - lineLayout.add(typesel); - return lineLayout; + return typesel; } /** @@ -373,12 +359,10 @@ } final JComboBox spellsel = new JComboBox(typelist.getSpellName()); // set "content" - spellsel.setPreferredSize(new Dimension((textFieldWidth == 0 ? 197 : textFieldWidth), chooseBoxHeight)); spellsel.setSelectedIndex(active); // set active selection spellsel.setMaximumRowCount(10); spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); - spellsel.setBackground(Color.white); // white background spellsel.setName(attr.getNameNew()); return spellsel; @@ -409,60 +393,50 @@ } final JComboBox arraysel = new JComboBox(array); // set "content" - arraysel.setPreferredSize(new Dimension(textFieldWidth == 0 ? 197 : textFieldWidth, chooseBoxHeight)); arraysel.setSelectedIndex(active); // set active selection arraysel.setMaximumRowCount(10); arraysel.setKeySelectionManager(new StringKeyManager(arraysel)); - arraysel.setBackground(Color.white); // white background arraysel.setName(attr.getNameNew()); return arraysel; } /** - * Construct the Panel for bitmask values (this is used for ArchAttribType.BITMASK) - * @param attr spell-attribute - * @param guiAttr the gui-instance of the bitmask attribute - * @param bitmask the bitmask data for this attribute - * @param mainPanel the panel to put everything in - */ - private void buildBitmask(final CFArchAttrib attr, final BitmaskAttrib guiAttr, final CAttribBitmask bitmask, final JPanel mainPanel) { - // initialize bitmask value - guiAttr.setValue(gameObject.getAttributeInt(attr.getNameOld())); - guiAttr.bitmask = bitmask; - - // add button - final JButton button = new JButton(attr.getNameNew() + ":"); - button.setAlignmentX(JButton.CENTER_ALIGNMENT); - button.setMargin(new Insets(0, 3, 0, 3)); - button.addActionListener(new MaskChangeAL(guiAttr, this)); - mainPanel.add(button); - - // add the text field - guiAttr.text = bitmask.getText(guiAttr.getValue(), null); - mainPanel.add(guiAttr.text); - } - - /** * 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 JScrollPane buildHeader() { - final JPanel header = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // the final thing, in a panel - - final JPanel layout1 = new JPanel(new BorderLayout()); // face, name & type - + 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; - layout1.add(imagePanel, BorderLayout.WEST); + 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 - final JPanel layout2 = new JPanel(new GridLayout(2, 1)); - final JPanel layout3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - layout3.add(new JLabel("Name: ")); // create label + gbc.gridx = 3; + gbc.gridy = 1; + gbc.weightx = 1.0; if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { nameTF = new JTextField(gameObject.getObjName(), 16); } else if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { @@ -471,36 +445,15 @@ nameTF = new JTextField(archetype.getArchetypeName(), 16); } nameTF.setEditable(false); - layout3.add(nameTF); - - layout2.add(layout3); // name field - layout2.add(buildTypesBox(nameTF.getPreferredSize().width)); // build type-selection box - layout2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 4)); - - //layout1.add(imagePanel, BorderLayout.WEST); - layout1.add(layout2, BorderLayout.EAST); - - header.add(layout1); - - final JPanel layout4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - layout4.add(new JLabel("Archetype: ")); // create label + header.add(nameTF, gbc); + gbc.gridy++; + header.add(buildTypesBox(), gbc); // build type-selection box + gbc.gridy++; archetypeTF = new JTextField(archetype.getArchetypeName(), 16); archetypeTF.setEditable(false); - layout4.add(archetypeTF); + header.add(archetypeTF, gbc); - final JPanel layout5 = new JPanel(); - layout5.add(layout4); - header.add(layout5); - header.setPreferredSize(new Dimension(width - inventoryWidth - 2 * dividerSize, 70)); - - // finally put the result into a (non-scrollable) - // scrollpane to get the size right - final JScrollPane scrollPane = new JScrollPane(header); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); - - return scrollPane; + return header; } /** @@ -508,7 +461,7 @@ * containing the object's inventory. * @return a <code>JScrollPane</code> with the upper right part of the dialog window */ - private JScrollPane buildInv() { + private static JScrollPane buildInv() { final JPanel inv = new JPanel(); // the final thing, in a panel inv.add(new JLabel("Inventory:")); // create label @@ -528,7 +481,7 @@ * with the central part of the dialog window. * All further calls rebuild the existing tabbedpane and return null. */ - @Nullable private JScrollPane buildAttr() { + @Nullable private JComponent buildAttr() { boolean initialCall = false; if (tabbedPane == null) { @@ -547,18 +500,10 @@ tabbedPane.setSelectedIndex(0); if (initialCall) { - // if this is the first time call: - // create a scrollpane and put the tabbedpane inside - final JScrollPane scrollPane = new JScrollPane(tabbedPane); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); - scrollPane.setSize(width, height - 70 - buttonBarHeight); - - return scrollPane; + return tabbedPane; + } else { + return null; } - - return null; } /** @@ -569,9 +514,7 @@ */ @Nullable private Component makeAttribPanel(final int secId) { int number = 0; // number of attributes in this section - boolean isText = false; // true if this section contains a textfield boolean hasBitmask = false; // true if this section contains a bitmask attribute - Component fullPanel = null; // return object: the full attrib. panel // first we check how many attribs this section has for (int i = 0; type.getAttr().length > i; i++) { @@ -591,77 +534,75 @@ } // All attribute-"lines" go into this panel: - // We choose the boxlayout only for tabs with bitmasks, because we - // need it there. For all other cases, the gridlayout is better. - final JPanel panel = new JPanel(); - if (hasBitmask) { - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - } else { - panel.setLayout(new GridLayout(number, 1)); - } + 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; type.getAttr().length > i; i++) { - final ArchAttribType dType = type.getAttr()[i].getDataType(); // data type of the attribute - if (type.getAttr()[i].getSecId() == secId && dType != ArchAttribType.FIXED) { - JPanel panel2 = null; // tmp. Panel for the layout + 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; + final DialogAttrib<?> newAttr; switch (dType) { case TEXT: { - // special case: we've got a text section isText = true; // text section (need special embedding without additional scrollbars) - newAttr = new TextAttrib(); - newAttr.ref = type.getAttr()[i]; - final JTextArea input; - - // note that the textarea is initialized with rows/columns: 1, 1 - // this is pretty weird, but seems the only way to achieve desired behaviour - if (type.getAttr()[i].getNameOld().equalsIgnoreCase("msg")) { - if (archetype.getMsgText() != null && archetype.getMsgText().length() > 0 - && (gameObject.getMsgText() == null || gameObject.getMsgText().trim().length() == 0)) { - input = new JTextArea(archetype.getMsgText(), 1, 1); + newAttr = new DialogAttrib<JTextArea>(type.getAttr()[i]); + 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 { - input = new JTextArea(gameObject.getMsgText(), 1, 1); + text = gameObject.getMsgText(); } - } else { - input = new JTextArea(1, 1); } - + final JTextArea input = new JTextArea(text, 10, 20); input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); - - newAttr.helpButton = new JButton("?"); - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - final JScrollPane scrollPane = new JScrollPane(input); scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - - //Create a split pane with the two scroll panes in it. - final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, newAttr.helpButton); - splitPane.setDividerSize(0); - splitPane.setResizeWeight(1); - splitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - - ((TextAttrib) newAttr).input = input; - - fullPanel = splitPane; // return the splitpane + 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: { - // create an attribute line for BOOL - panel2 = new JPanel(new BorderLayout()); // need this layout for consistent resize-behaviour - final JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - newAttr = new BoolAttrib(); + newAttr = new DialogAttrib<JCheckBox>(type.getAttr()[i]); final JCheckBox input; switch (dType) { case BOOL: // normal bool - input = new JCheckBox(" " + type.getAttr()[i].getNameNew(), (gameObject.getAttributeInt(type.getAttr()[i].getNameOld()) == 1)); + input = new JCheckBox(type.getAttr()[i].getNameNew(), (gameObject.getAttributeInt(type.getAttr()[i].getNameOld()) == 1)); break; case BOOL_SPEC: { // parse values for customized bool @@ -669,9 +610,9 @@ if (trueVal.equals("0")) { final String attrString = gameObject.getAttributeString(type.getAttr()[i].getNameOld()); - input = new JCheckBox(" " + type.getAttr()[i].getNameNew(), (attrString.length() == 0 || attrString.equals("0"))); + input = new JCheckBox(type.getAttr()[i].getNameNew(), (attrString.length() == 0 || attrString.equals("0"))); } else { - input = new JCheckBox(" " + type.getAttr()[i].getNameNew(), (gameObject.getAttributeString(type.getAttr()[i].getNameOld()).equals(trueVal))); + input = new JCheckBox(type.getAttr()[i].getNameNew(), (gameObject.getAttributeString(type.getAttr()[i].getNameOld()).equals(trueVal))); } } break; @@ -680,90 +621,54 @@ input = null; break; } - - newAttr.helpButton = new JButton("?"); - newAttr.ref = type.getAttr()[i]; - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - - panel3.add(Box.createRigidArea(new Dimension(3, 20))); - panel3.add(newAttr.helpButton); - // create the offset from help-button and checkbox: - panel3.add(Box.createHorizontalStrut((int) (width / 3.3))); - panel3.add(input); // add checkbox - panel2.add(panel3, BorderLayout.WEST); - - ((BoolAttrib) newAttr).input = input; + ((DialogAttrib<JCheckBox>) newAttr).input = input; + cRow = input; } break; - case INT: { - // create an attribute line for INT - panel2 = new JPanel(new BorderLayout()); - final JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - final JLabel label = new JLabel(type.getAttr()[i].getNameNew() + ": "); - label.setForeground(IGUIConstants.INT_COLOR); - panel3.add(label); // add label - - newAttr = new IntAttrib(); - newAttr.ref = type.getAttr()[i]; - final JTextField input; - - // parse value from gameObject - final int fieldLength = (type.getAttr()[i].getInputLength() == 0 ? textFieldColumns : type.getAttr()[i].getInputLength()); - final int attrval = gameObject.getAttributeInt(type.getAttr()[i].getNameOld()); - if (attrval != 0) { - input = new JTextField(String.valueOf(attrval), fieldLength); - } else { - input = new JTextField("", fieldLength); - } - panel3.add(input); // add textfield - - // store width of textfield - if (textFieldWidth == 0 && type.getAttr()[i].getInputLength() == 0) { - textFieldWidth = input.getPreferredSize().width; - } - - newAttr.helpButton = new JButton("?"); - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - panel4.add(Box.createRigidArea(new Dimension(3, 20))); - panel4.add(newAttr.helpButton); - - panel3.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - panel2.add(panel3, BorderLayout.EAST); - panel2.add(panel4, BorderLayout.WEST); - ((IntAttrib) newAttr).input = input; - } - break; - case STRING: + case INT: case FLOAT: { - // create an attribute line for STRING - panel2 = new JPanel(new BorderLayout()); - final JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - final JLabel label = new JLabel(type.getAttr()[i].getNameNew() + ": "); - + cLabel = new JLabel(type.getAttr()[i].getNameNew() + ": "); + cLabel.setForeground(dType == ArchAttribType.FLOAT ? IGUIConstants.FLOAT_COLOR : IGUIConstants.INT_COLOR); + newAttr = new DialogAttrib<JFormattedTextField>(type.getAttr()[i]); + final int fieldLength = type.getAttr()[i].getInputLength() == 0 ? TEXTFIELD_COLUMNS : type.getAttr()[i].getInputLength(); + final NumberFormat format; switch (dType) { - case STRING: - newAttr = new StringAttrib(); - label.setForeground(Color.black); + case INT: + format = NumberFormat.getIntegerInstance(); break; case FLOAT: - newAttr = new FloatAttrib(); - label.setForeground(IGUIConstants.FLOAT_COLOR); + format = NumberFormat.getInstance(); + format.setMaximumFractionDigits(10); break; default: assert false; - newAttr = null; + format = null; break; } - - panel3.add(label); // add label - newAttr.ref = type.getAttr()[i]; - final JTextField input; - - // parse String from gameObject + 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, true); + break; + case FLOAT: + value = gameObject.getAttributeDouble(nameOld, true); + 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: { final String dtxt; if (type.getAttr()[i].getNameOld().equalsIgnoreCase("name")) { if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { @@ -782,53 +687,27 @@ } else { dtxt = gameObject.getAttributeString(type.getAttr()[i].getNameOld()); } - - input = new JTextField(dtxt, textFieldColumns); - panel3.add(input); // add textfield - - // store width of textfield - if (textFieldWidth == 0) { - textFieldWidth = input.getPreferredSize().width; - } - - newAttr.helpButton = new JButton("?"); - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - - panel4.add(Box.createRigidArea(new Dimension(3, 20))); - panel4.add(newAttr.helpButton); - - panel3.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - panel2.add(panel3, BorderLayout.EAST); - panel2.add(panel4, BorderLayout.WEST); - + final JTextField input = new JTextField(dtxt, TEXTFIELD_COLUMNS); switch (dType) { case STRING: - ((StringAttrib) newAttr).input = input; + cLabel = new JLabel(type.getAttr()[i].getNameNew() + ": "); + newAttr = new DialogAttrib<JTextField>(type.getAttr()[i]); break; - case FLOAT: - ((FloatAttrib) newAttr).input = input; - break; default: assert false; + newAttr = null; break; } + cComp = input; + ((DialogAttrib<JTextField>) newAttr).input = input; } break; case SPELL: case ZSPELL: case LIST: { - // create an attribute line for a combo box entry - panel2 = new JPanel(new BorderLayout()); - final JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - final JLabel label = new JLabel(type.getAttr()[i].getNameNew() + ": "); - label.setForeground(IGUIConstants.INT_COLOR); - panel3.add(label); // add label - - newAttr = new ListAttrib(); - newAttr.ref = type.getAttr()[i]; - + cLabel = new JLabel(type.getAttr()[i].getNameNew() + ": "); + cLabel.setForeground(IGUIConstants.INT_COLOR); + newAttr = new DialogAttrib<JComboBox>(type.getAttr()[i]); // create ComboBox with parsed selection final JComboBox input; switch (dType) { @@ -842,97 +721,53 @@ input = buildArrayBox(type.getAttr()[i], (Vector) (typelist.getListTable().get((String) (type.getAttr()[i].getMisc()[0])))); } else { // error: list data is missing or corrupt - panel3.add(new JLabel("Error: Undefined List")); - panel3.add(Box.createHorizontalStrut(50)); - input = null; // XXX: is later added to panel3 + cComp = new JLabel("Error: Undefined List"); + input = null; } break; default: - input = null; // XXX: is later added to panel3 + assert false; + input = null; break; } - - panel3.add(input); // add spellbox - - newAttr.helpButton = new JButton("?"); - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - panel4.add(Box.createRigidArea(new Dimension(3, 20))); - panel4.add(newAttr.helpButton); - - panel3.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - panel2.add(panel3, BorderLayout.EAST); - panel2.add(panel4, BorderLayout.WEST); - ((ListAttrib) newAttr).input = input; + if (input != null) { + cComp = input; + } + ((DialogAttrib<JComboBox>) newAttr).input = input; } break; case BITMASK: { - // create an attribute entry for a bitmask - panel2 = new JPanel(new BorderLayout()); - final JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - newAttr = new BitmaskAttrib(); - newAttr.ref = type.getAttr()[i]; - - // create bitmask-entry in the gui - //JButton input = null; + newAttr = new BitmaskAttrib(type.getAttr()[i]); if (type.getAttr()[i].getMisc() != null && typelist.getBitmaskTable().containsKey((String) (type.getAttr()[i].getMisc()[0]))) { // fetch the bitmask data, then build the attribute panel final CAttribBitmask bitmask = (CAttribBitmask) (typelist.getBitmaskTable().get((String) (type.getAttr()[i].getMisc()[0]))); - buildBitmask(type.getAttr()[i], (BitmaskAttrib) newAttr, bitmask, panel3); + ((BitmaskAttrib) (DialogAttrib<JTextComponent>) newAttr).bitmask = bitmask; + cLabel = new JButton(new MaskChangeAL(type.getAttr()[i].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, true)); } else { - // error: bitmask data is missing or corrupt - panel3.add(new JLabel("Error: Undefined Bitmask")); - panel3.add(Box.createHorizontalStrut(50)); + cRow = new JLabel("Error: Undefined Bitmask"); } - - newAttr.helpButton = new JButton("?"); - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - newAttr.helpButton.setAlignmentY(JButton.CENTER_ALIGNMENT); - panel4.add(Box.createRigidArea(new Dimension(3, 20))); - panel4.add(newAttr.helpButton); - - panel3.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - panel2.add(panel3, BorderLayout.EAST); - panel2.add(panel4, BorderLayout.WEST); - //((BitmaskAttrib)newAttr).input = input; } break; case TREASURE: { - // create an attribute entry for a treasurelist - panel2 = new JPanel(new BorderLayout()); - final JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - // button to view treasurelist tree - final JButton viewTTree = new JButton("treasurelist:"); - viewTTree.setMargin(new Insets(0, 3, 0, 3)); - - newAttr = new StringAttrib(); - newAttr.ref = type.getAttr()[i]; - + newAttr = new DialogAttrib<JTextField>(type.getAttr()[i]); // textfield (no direct input, text is set by the treasurelist dialog) String treasureName = gameObject.getAttributeString(type.getAttr()[i].getNameOld()); if (treasureName.trim().length() == 0 || treasureName.trim().equalsIgnoreCase("none")) { treasureName = CFTreasureListTree.NONE_SYM; } - final JTextField input = new JTextField(" " + treasureName, textFieldColumns); + final JTextField input = new JTextField(" " + treasureName, TEXTFIELD_COLUMNS); input.setEditable(false); - viewTTree.addActionListener(new ViewTreasurelistAL((StringAttrib) newAttr, this)); - - panel3.add(viewTTree); // add button - panel3.add(input); // add textfield - newAttr.helpButton = new JButton("?"); - newAttr.helpButton.setMargin(new Insets(0, 3, 0, 3)); - - panel4.add(Box.createRigidArea(new Dimension(3, 20))); - panel4.add(newAttr.helpButton); - - panel3.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - panel2.add(panel3, BorderLayout.EAST); - panel2.add(panel4, BorderLayout.WEST); - - ((StringAttrib) newAttr).input = input; + cLabel = new JButton(new ViewTreasurelistAL((DialogAttrib<JTextField>) newAttr, this)); + cComp = input; + ((DialogAttrib<JTextField>) newAttr).input = input; } break; default: @@ -942,41 +777,34 @@ } // switch (dType) assert newAttr != null; - if (newAttr.helpButton != null) { - // help button: popup Info Window when clicked - newAttr.helpButton.addActionListener(new HelpAL(newAttr.ref)); + dialogAttribs.add(newAttr); + helpButton.addActionListener(new HelpActionListener(newAttr.ref)); + if (cLabel != null) { + panel.add(cLabel, labelGbc); + cLabel.addFocusListener(this); } - - // now attach the new attribute into the list - if (attrHead == null) { - attrHead = attrTail = newAttr; - } else { - attrTail.next = newAttr; - attrTail = attrTail.next; + if (cComp != null) { + panel.add(cComp, compGbc); + cComp.addFocusListener(this); } - - if (!isText) { - panel2.setSize(new Dimension(width - 70, 20)); - panel.add(panel2); + if (cRow != null) { + panel.add(cRow, rowGbc); + cRow.addFocusListener(this); } + if (cGlue != null) { + panel.add(cGlue, glueGbc); + cGlue.addFocusListener(this); + } } } if (!isText) { - // for non-text panels: put everything into a scrollpane - final JScrollPane scrollPane = new JScrollPane(panel); - final JScrollPane scrollPane2 = new JScrollPane(scrollPane); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); - scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); // don't show the border - - scrollPane2.setPreferredSize(new Dimension(20, 20)); - scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - fullPanel = scrollPane2; // return this scrollpane + // if the component does not already have glue, put glue inside to align its contents to the top. + panel.add(Box.createGlue(), glueGbc); } - - return fullPanel; // return the full panel + final JScrollPane panelReturn = new JScrollPane(panel); + panelReturn.getVerticalScrollBar().setUnitIncrement(8); + return panelReturn; } /** @@ -1000,81 +828,52 @@ } /** - * Construct the lower part of the attribute dialog, - * containing the buttons (help, default, okay, apply, cancel). - * @return a <code>JScrollPane</code> with the lower part of the attribute dialog + * Construct the dialog options: help, default, okay, apply, cancel. + * @return Object[] with dialog options */ - private JScrollPane buildButtons() { - final JPanel totalBar = new JPanel(new BorderLayout()); // all buttons - final JPanel rightBar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // right side - final JPanel leftBar = new JPanel(new FlowLayout(FlowLayout.LEFT)); // left side + 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", th... [truncated message content] |
From: <aki...@us...> - 2006-11-28 20:30:11
|
Revision: 738 http://svn.sourceforge.net/gridarta/?rev=738&view=rev Author: akirschbaum Date: 2006-11-28 12:30:09 -0800 (Tue, 28 Nov 2006) Log Message: ----------- Unify GUI related code in CNewMapDialog. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CNewMapDialog.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/crossfire/src/cfeditor/messages_sv.properties Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-27 22:33:43 UTC (rev 737) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-28 20:30:09 UTC (rev 738) @@ -622,14 +622,14 @@ */ public void newLevelWanted(final String filename) { CMainStatusbar.getInstance().setText(" Creating new map..."); - new CNewMapDialog(this, mainView, filename, CNewMapDialog.TYPE_CFMAP); + CNewMapDialog.showNewMapDialog(this, mainView, filename, CNewMapDialog.TYPE_CFMAP); CMainStatusbar.getInstance().setText(""); } /** Invoked when user wants to open a new pickmap */ public void newPickmapWanted() { CMainStatusbar.getInstance().setText(" Creating new pickmap..."); - new CNewMapDialog(this, mainView, null, CNewMapDialog.TYPE_PICKMAP); + CNewMapDialog.showNewMapDialog(this, mainView, null, CNewMapDialog.TYPE_PICKMAP); CMainStatusbar.getInstance().setText(""); } Modified: trunk/crossfire/src/cfeditor/CNewMapDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-11-27 22:33:43 UTC (rev 737) +++ trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-11-28 20:30:09 UTC (rev 738) @@ -26,25 +26,26 @@ import cfeditor.gameobject.ArchetypeSet; import cfeditor.map.MapArchObject; -import java.awt.BorderLayout; -import java.awt.Dimension; +import java.awt.Component; import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Calendar; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; 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.EmptyBorder; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import net.sf.gridarta.Size2D; +import net.sf.japi.swing.ActionFactory; /** * Dialog used to ask the user the properties for the new level. Contains a @@ -53,11 +54,14 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class CNewMapDialog extends CDialogBase { +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"); + /** Map types. */ public static final int TYPE_CFMAP = 0; @@ -76,128 +80,127 @@ /** type of map to create: pickmap or normal map? */ private final int mapType; - // Dialog UI Components - private final JTextField mapNameField; + /** + * 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); - private final JTextField fileNameField; + /** + * Textfield for the filename of the map. + * This is only used for {@link MapType#PICKMAP} to determine the filename of the new pickmap. + * The title of the pickmap will be set to "pickmap" always. + */ + private final JTextField fileNameField = new JTextField(16); - private final JTextField mapWidthField; + /** + * Textfield for the width of the new map. + */ + private final JFormattedTextField mapWidthField = new JFormattedTextField(); - private final JTextField mapHeightField; + /** + * 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 parentFrame the parent frame of this dialog. * @param filename desired filename for new map, null if not specified + * @param mapType type of map to create */ - CNewMapDialog(final CMainControl mainControl, final Frame parentFrame, final String filename, final int mapType) { - super(parentFrame, mapType == TYPE_PICKMAP ? "Create New Pickap" : "Create New Map"); + private CNewMapDialog(final CMainControl mainControl, final String filename, final int mapType) { + okButton.setDefaultCapable(true); + setOptions(new Object[]{okButton, cancelButton}); this.mainControl = mainControl; this.mapType = mapType; - getContentPane().setLayout(new BorderLayout()); + setMessage(createPanel(filename)); + } + private JPanel createPanel(final String filename) { final JPanel newLevelFromScratchPanel = new JPanel(); newLevelFromScratchPanel.setLayout(new BoxLayout(newLevelFromScratchPanel, BoxLayout.Y_AXIS)); - newLevelFromScratchPanel.setBorder(new EmptyBorder( - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS)); + newLevelFromScratchPanel.setBorder(IGUIConstants.DIALOG_BORDER); // file name panel final JPanel fileNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); if (mapType == TYPE_PICKMAP) { - fileNamePanel.add(new JLabel("Pickmap Name:")); + fileNamePanel.add(new JLabel("Pickmap Name:")); // TODO cher: i18n/l10n } else { - fileNamePanel.add(new JLabel("File Name:")); + fileNamePanel.add(new JLabel("File Name:")); // TODO cher: i18n/l10n } if (filename != null && filename.length() > 0) { - fileNameField = new JTextField(filename, 16); - } else { - fileNameField = new JTextField(16); + fileNameField.setText(filename); } fileNamePanel.add(fileNameField); - newLevelFromScratchPanel.add(fileNamePanel); - newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + if (mapType == TYPE_PICKMAP) { + newLevelFromScratchPanel.add(fileNamePanel); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); + } if (mapType == TYPE_CFMAP) { // map name panel final JPanel mapNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - mapNamePanel.add(new JLabel("Map Name:")); - mapNameField = new JTextField(16); + mapNamePanel.add(new JLabel("Map Name:")); // TODO cher: i18n/l10n mapNamePanel.add(mapNameField); newLevelFromScratchPanel.add(mapNamePanel); newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - } else { - mapNameField = null; } final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); + newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - final JPanel mapSizePanel = new JPanel(new GridLayout(2, 2)); + 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(), mapType == TYPE_PICKMAP ? "Pickmap Size" : "Map Size"), - new EmptyBorder( - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS))); - mapSizePanel.add(new JLabel("Width:")); - mapWidthField = new JTextField(3); + IGUIConstants.DIALOG_BORDER)); // TODO cher: i18n/l10n + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapWidth")), gbcLabel); if (mapType == TYPE_PICKMAP) { - mapWidthField.setText(String.valueOf(IGUIConstants.DEF_PICKMAP_WIDTH)); + mapWidthField.setValue(IGUIConstants.DEF_PICKMAP_WIDTH); } else { - mapWidthField.setText(settings.getProperty(DEFAULT_LEVEL_WIDTH_KEY, "" + IGUIConstants.DEF_MAPSIZE)); + assert mapType == TYPE_CFMAP; + mapWidthField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_WIDTH_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); } - mapSizePanel.add(mapWidthField); - mapSizePanel.add(new JLabel("Height:")); - mapHeightField = new JTextField(3); + mapWidthField.setColumns(3); + mapSizePanel.add(mapWidthField, gbcField); + mapSizePanel.add(new JLabel(ACTION_FACTORY.getString("mapHeight")), gbcLabel); if (mapType == TYPE_PICKMAP) { - mapHeightField.setText(String.valueOf(IGUIConstants.DEF_PICKMAP_HEIGHT)); + mapHeightField.setValue(IGUIConstants.DEF_PICKMAP_HEIGHT); } else { - mapHeightField.setText(settings.getProperty(DEFAULT_LEVEL_HEIGHT_KEY, "" + IGUIConstants.DEF_MAPSIZE)); + assert mapType == TYPE_CFMAP; + mapHeightField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_HEIGHT_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); } - mapSizePanel.add(mapHeightField); + mapHeightField.setColumns(3); + mapSizePanel.add(mapHeightField, gbcField); newLevelFromScratchPanel.add(mapSizePanel); newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); - getContentPane().add(newLevelFromScratchPanel, BorderLayout.CENTER); + return newLevelFromScratchPanel; + } - final JPanel buttonPanel = new JPanel(); - buttonPanel.setBorder(new EmptyBorder(IGUIConstants.SPACE_BETWEEN_BUTTON_AREA_AND_MAIN_DIALOG, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS)); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - buttonPanel.add(Box.createGlue()); + /** Action method for okay. */ + public void mapOkay() { + if (createNewLevel()) { + setValue(okButton); + } + } - final JButton okButton = new JButton("OK"); - okButton.addActionListener( - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - if (createNewLevel()) { - dispose(); - } - } - }); - buttonPanel.add(okButton); - - buttonPanel.add(Box.createRigidArea(new Dimension(IGUIConstants.SPACE_BETWEEN_BUTTONS, 1))); - - final JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener( - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - dispose(); - } - }); - buttonPanel.add(cancelButton); - - getContentPane().add(buttonPanel, BorderLayout.SOUTH); - - pack(); - setVisible(true); + /** Action method for cancel. */ + public void mapCancel() { + setValue(cancelButton); } /** @@ -206,34 +209,47 @@ */ private boolean createNewLevel() { - // Create a new level from scratch + // Create a new level from scratch final MapArchObject maparch = new MapArchObject(); - // Get and validate the level size - final int width, height; - try { - // get size - width = Integer.parseInt(mapWidthField.getText()); - height = Integer.parseInt(mapHeightField.getText()); - } catch (final NumberFormatException illegalNumbers) { - mainControl.showMessage( - "Illegal Value", - "Map dimensions must be numerical integer values!"); - return false; - } - if (width < 1 || height < 1) { - mainControl.showMessage("Illegal Value", "Map dimensions must be in range [1, " + Integer.MAX_VALUE + "]."); - return false; - } + // Get and validate the width + final int width; + final int height; + try { + width = (Integer) mapWidthField.getValue(); + } catch (final IllegalArgumentException e) { + final String key = e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"; + ACTION_FACTORY.showMessageDialog(this, key); + 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) { + final String key = e instanceof NumberFormatException ? "newMapDimensionNotANumber" : "newMapDimensionOutOfRange"; + ACTION_FACTORY.showMessageDialog(this, key); + 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 mapname to create a new map - if (mapType == TYPE_CFMAP && (mapNameField.getText() == null || mapNameField.getText().length() <= 0)) { - mainControl.showMessage("Map Name is Missing", - "You must enter a map name! This name will appear\n" + - "in the game, so it should be a descriptive name.\n" + - "Map names don't need to be unique."); + final String mapName = mapNameField.getText(); + if (mapType == TYPE_CFMAP && (mapName == null || mapName.length() <= 0)) { + ACTION_FACTORY.showMessageDialog(this, "newMapNoName"); + mapNameField.requestFocus(); return false; } @@ -260,7 +276,7 @@ // set map name if (mapType == TYPE_CFMAP) { - maparch.setMapName(mapNameField.getText()); + maparch.setMapName(mapName); } else if (mapType == TYPE_PICKMAP) { maparch.setMapName("pickmap"); } @@ -280,4 +296,27 @@ 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 int mapType) { + final CNewMapDialog pane = new CNewMapDialog(mainControl, filename, mapType); + final JDialog dialog = pane.createDialog(parentComponent, ACTION_FACTORY.getString(mapType == TYPE_PICKMAP ? "newPickmap.title" : "newMap.title")); + dialog.getRootPane().setDefaultButton(pane.okButton); + dialog.setModal(false); + + // TODO: localize + pane.mapNameField.setText("Unnamed Map"); + + dialog.setVisible(true); + pane.mapNameField.selectAll(); + pane.fileNameField.selectAll(); + pane.mapWidthField.selectAll(); + pane.mapHeightField.selectAll(); + } + } // class CNewMapDialog Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-11-27 22:33:43 UTC (rev 737) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-11-28 20:30:09 UTC (rev 738) @@ -25,7 +25,10 @@ package cfeditor; import java.awt.Color; +import java.awt.Insets; import java.io.File; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; /** * Defines common UI constants used in different dialogs and all used icon @@ -104,6 +107,9 @@ */ int DOUBLECLICK_MS = 300; + /** The Border object to be used when creating dialogs. */ + Border DIALOG_BORDER = new EmptyBorder(new Insets(4, 4, 4, 4)); + /** Default file name for new maps. */ String DEF_MAPFNAME = "<new map>"; Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2006-11-27 22:33:43 UTC (rev 737) +++ trunk/crossfire/src/cfeditor/messages.properties 2006-11-28 20:30:09 UTC (rev 738) @@ -3,6 +3,21 @@ fileDialog.filter.python=Python Scripts +# New Map +newMap.title=Create New Map +newPickmap.title=Create New Pickmap +newMapDimensionOutOfRange.title=Illegal Value +newMapDimensionOutOfRange.message=Map dimensions must be greater or equal 1 and less or equal 2147483647 +newMapDimensionNotANumber.title=Illegal Value +newMapDimensionNotANumber.message=Map dimensions must be numerical integer values! +newMapNoName.title=Map Name is missing +newMapNoName.message=You must enter a map name! This name will appear\nin the game, so it should be a descriptive name.\nMap names do not need to be unique. + +mapWidth=Width +mapHeight=Height +mapOkay.text=Ok +mapCancel.text=Cancel + #replace replaceTitle=Replace replaceOn=On Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2006-11-27 22:33:43 UTC (rev 737) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2006-11-28 20:30:09 UTC (rev 738) @@ -1,6 +1,11 @@ # Warning: This file MUST be ISO-8859-1 # See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding +mapWidth=Breite +mapHeight=H\xF6he +mapOkay.text=Ok +mapCancel.text=Abbrechen + #replace replaceTitle=Ersetze replaceOn=In Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2006-11-27 22:33:43 UTC (rev 737) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2006-11-28 20:30:09 UTC (rev 738) @@ -1,6 +1,21 @@ # Warning: This file MUST be ISO-8859-1 # See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding +# New Map +newMap.title=Skapa ny karta +newPickmap.title=Skapa ny plockkarta +newMapDimensionOutOfRange.title=Ogiltigt v\xE4rde +newMapDimensionOutOfRange.message=Kartans dimensioner m\xE5ste st\xF6rre eller lika med 1 och mindre eller lika med 2147483647 +newMapDimensionNotANumber.title=Ogiltigt v\xE4rde +newMapDimensionNotANumber.message=Kartans dimensioner m\xE5ste vara heltalsv\xE4rden. +newMapNoName.title=Kartnamn saknas +newMapNoName.message=Du m\xE5ste ange ett kartnamn! Namnet syns i spelet,\n s\xE5 det b\xF6r vara ett beskrivande namn.\nNamn p\xE5 kartor beh\xF6ver inte vara unika. + +mapWidth=Bredd +mapHeight=H\xF6jd +mapOkay.text=Ok +mapCancel.text=Avbryt + #replace replaceTitle=Ers\xE4tt replaceOn=P\xE5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-29 18:52:27
|
Revision: 744 http://svn.sourceforge.net/gridarta/?rev=744&view=rev Author: akirschbaum Date: 2006-11-29 10:52:27 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Use ActionFactory to create GUI elements in CPickmapPanel. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_sv.properties Modified: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-11-29 18:08:15 UTC (rev 743) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-11-29 18:52:27 UTC (rev 744) @@ -39,6 +39,7 @@ 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; import org.jetbrains.annotations.Nullable; @@ -51,6 +52,9 @@ private static final Logger log = Logger.getLogger(CPickmapPanel.class); + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + /** static instance of this class */ private static CPickmapPanel instance; @@ -178,8 +182,7 @@ final File mapFile = new File(IGUIConstants.PICKMAP_DIR, maparch.getFileName()); if (mapFile.exists()) { - mainControl.showMessage("Cannot Create Pickmap", "A pickmap named '" + mapFile + "' already exists.\n" + - "Either remove the existing one or choose a different name.", JOptionPane.ERROR_MESSAGE); + ACTION_FACTORY.showMessageDialog(tabpane, "pickmapExists", mapFile); return false; } if (!mapFile.getParentFile().exists()) { Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2006-11-29 18:08:15 UTC (rev 743) +++ trunk/crossfire/src/cfeditor/messages.properties 2006-11-29 18:52:27 UTC (rev 744) @@ -1,6 +1,10 @@ # Warning: This file MUST be ISO-8859-1 # See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding +# Dialogs +pickmapExists.title=Cannot Create Pickmap +pickmapExists.message=A pickmap named {0} already exists.\nEither remove the existing one or choose a different name. + # New Map newMap.title=Create New Map newPickmap.title=Create New Pickmap Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2006-11-29 18:08:15 UTC (rev 743) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2006-11-29 18:52:27 UTC (rev 744) @@ -1,6 +1,10 @@ # Warning: This file MUST be ISO-8859-1 # See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding +# Dialogs +pickmapExists.title=Kan inte skapa plockkarta +pickmapExists.message=En plockkarta med namnet {0} finns redan.\nTa antingen bort den tidigare plockkartan eller v\xE4lj ett annat namn. + # New Map newMap.title=Skapa ny karta newPickmap.title=Skapa ny plockkarta This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-11-29 19:28:19
|
Revision: 752 http://svn.sourceforge.net/gridarta/?rev=752&view=rev Author: akirschbaum Date: 2006-11-29 11:28:19 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Use MapType class for map types. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CNewMapDialog.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-29 19:17:52 UTC (rev 751) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-11-29 19:28:19 UTC (rev 752) @@ -58,6 +58,7 @@ import net.sf.gridarta.gameobject.Collectable; import net.sf.gridarta.gameobject.Collector; import net.sf.gridarta.gui.HideFileFilterProxy; +import net.sf.gridarta.map.MapType; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.filter.file.EndingFileFilter; @@ -622,14 +623,14 @@ */ public void newLevelWanted(final String filename) { CMainStatusbar.getInstance().setText(" Creating new map..."); - CNewMapDialog.showNewMapDialog(this, mainView, filename, CNewMapDialog.TYPE_CFMAP); + CNewMapDialog.showNewMapDialog(this, mainView, filename, MapType.GAMEMAP); CMainStatusbar.getInstance().setText(""); } /** Invoked when user wants to open a new pickmap */ public void newPickmapWanted() { CMainStatusbar.getInstance().setText(" Creating new pickmap..."); - CNewMapDialog.showNewMapDialog(this, mainView, null, CNewMapDialog.TYPE_PICKMAP); + CNewMapDialog.showNewMapDialog(this, mainView, null, MapType.PICKMAP); CMainStatusbar.getInstance().setText(""); } Modified: trunk/crossfire/src/cfeditor/CNewMapDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-11-29 19:17:52 UTC (rev 751) +++ trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-11-29 19:28:19 UTC (rev 752) @@ -45,6 +45,7 @@ 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; /** @@ -62,12 +63,6 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - /** Map types. */ - public static final int TYPE_CFMAP = 0; - - /** Map types. */ - public static final int TYPE_PICKMAP = 1; - /** The key value used to store the last used level width to INI file. */ private static final String DEFAULT_LEVEL_WIDTH_KEY = "NewLevelDialog.mapWidth"; @@ -78,7 +73,7 @@ private final CMainControl mainControl; /** type of map to create: pickmap or normal map? */ - private final int mapType; + private final MapType mapType; /** * Textfield for the name of the map. @@ -116,7 +111,7 @@ * @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 int mapType) { + private CNewMapDialog(final CMainControl mainControl, final String filename, final MapType mapType) { okButton.setDefaultCapable(true); setOptions(new Object[]{okButton, cancelButton}); @@ -132,7 +127,7 @@ newLevelFromScratchPanel.setBorder(IGUIConstants.DIALOG_BORDER); // file name panel final JPanel fileNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - if (mapType == TYPE_PICKMAP) { + if (mapType == MapType.PICKMAP) { fileNamePanel.add(new JLabel(ACTION_FACTORY.getString("newMapPickmapName"))); } else { fileNamePanel.add(new JLabel(ACTION_FACTORY.getString("newMapFileName"))); @@ -141,12 +136,12 @@ fileNameField.setText(filename); } fileNamePanel.add(fileNameField); - if (mapType == TYPE_PICKMAP) { + if (mapType == MapType.PICKMAP) { newLevelFromScratchPanel.add(fileNamePanel); newLevelFromScratchPanel.add(Box.createVerticalStrut(5)); } - if (mapType == TYPE_CFMAP) { + if (mapType == MapType.GAMEMAP) { // map name panel final JPanel mapNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); mapNamePanel.add(new JLabel(ACTION_FACTORY.getString("newMapMapName"))); @@ -167,19 +162,19 @@ 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 == TYPE_PICKMAP) { + if (mapType == MapType.PICKMAP) { mapWidthField.setValue(IGUIConstants.DEF_PICKMAP_WIDTH); } else { - assert mapType == TYPE_CFMAP; + 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 == TYPE_PICKMAP) { + if (mapType == MapType.PICKMAP) { mapHeightField.setValue(IGUIConstants.DEF_PICKMAP_HEIGHT); } else { - assert mapType == TYPE_CFMAP; + assert mapType == MapType.GAMEMAP; mapHeightField.setValue(Integer.valueOf(settings.getProperty(DEFAULT_LEVEL_HEIGHT_KEY, String.valueOf(IGUIConstants.DEF_MAPSIZE)))); } mapHeightField.setColumns(3); @@ -247,7 +242,7 @@ maparch.setMapSize(new Size2D(width, height)); final String mapName = mapNameField.getText(); - if (mapType == TYPE_CFMAP && (mapName == null || mapName.length() <= 0)) { + if (mapType == MapType.GAMEMAP && (mapName == null || mapName.length() <= 0)) { ACTION_FACTORY.showMessageDialog(this, "newMapNoName"); mapNameField.requestFocus(); return false; @@ -259,7 +254,7 @@ return false; } - if (mapType == TYPE_CFMAP) { + 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)); @@ -273,9 +268,9 @@ maparch.setFileName(strfileName); // set map name - if (mapType == TYPE_CFMAP) { + if (mapType == MapType.GAMEMAP) { maparch.setMapName(mapName); - } else if (mapType == TYPE_PICKMAP) { + } else if (mapType == MapType.PICKMAP) { maparch.setMapName("pickmap"); } @@ -285,9 +280,9 @@ maparch.addText("Date: " + (today.get(Calendar.MONTH) + 1) + "/" + today.get(Calendar.DAY_OF_MONTH) + "/" + today.get(Calendar.YEAR)); - if (mapType == TYPE_CFMAP) { + if (mapType == MapType.GAMEMAP) { mainControl.newLevel(null, maparch, null); - } else if (mapType == TYPE_PICKMAP) { + } else if (mapType == MapType.PICKMAP) { return CPickmapPanel.getInstance().addNewPickmap(parent, maparch); } @@ -301,9 +296,9 @@ * @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 int mapType) { + 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 == TYPE_PICKMAP ? "newPickmap.title" : "newMap.title")); + final JDialog dialog = pane.createDialog(parentComponent, ACTION_FACTORY.getString(mapType == MapType.PICKMAP ? "newPickmap.title" : "newMap.title")); dialog.getRootPane().setDefaultButton(pane.okButton); dialog.setModal(false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-01 21:49:33
|
Revision: 764 http://svn.sourceforge.net/gridarta/?rev=764&view=rev Author: akirschbaum Date: 2006-12-01 13:49:33 -0800 (Fri, 01 Dec 2006) Log Message: ----------- Extract level renderer class from CMapViewBasic. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapViewBasic.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/map/ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-01 21:30:36 UTC (rev 763) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-01 21:49:33 UTC (rev 764) @@ -24,32 +24,21 @@ package cfeditor; -import cfeditor.filter.AttributeFilter; -import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; import cfeditor.gui.MapView; import cfeditor.map.MapControl; import cfeditor.map.MapModel; -import java.awt.Color; +import cfeditor.gui.map.DefaultLevelRenderer; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionListener; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; -import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Iterator; -import java.util.Vector; import javax.imageio.ImageIO; -import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JScrollPane; import javax.swing.JViewport; @@ -95,7 +84,7 @@ private Size2D mapSize = new Size2D(1, 1); /** The tile palette renderer. */ - private final CLevelRenderer renderer; + private final DefaultLevelRenderer renderer; private boolean changed = false; @@ -145,7 +134,7 @@ if (isPickmap()) { setBackground(IGUIConstants.BG_COLOR); } - renderer = new CFlatLevelRenderer(mapControl.getMapModel(), isPickmap()); + renderer = new DefaultLevelRenderer(this, mainControl, mapControl, isPickmap()); setViewportView((JComponent) renderer); getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); @@ -493,491 +482,17 @@ renderer.freeBackBuffer(); } - /** - * A lavel renderer, mainly used as central point interfac to iso and flat - * renderer - * @author tchize - */ - public interface CLevelRenderer { + public Size2D getMapSize() { + return mapSize; + } - void updateLookAndFeel(); - - BufferedImage getFullImage(); - - void paintTile(int x, int y); - - Point getTileLocationAt(Point point); - - boolean isPickmap(); - - void paintHighlightTile(Graphics grfx, int x, int y); - - void modelChanged(); - - void setHighlightTile(int x, int y); - - boolean resizeBackBuffer(); - - void freeBackBuffer(); + public Point getMapMousePos() { + return mapMousePos; } - /** - * The component that does the actual rendering of tiles in the palette. - * Flat version - */ - public final class CFlatLevelRenderer extends JComponent implements CLevelRenderer { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - private final MapModel mapModel; - - // 32x32 Image and Icon for temprary storing tiles before drawing - private Image tmpImage; - - private Graphics tmpGrfx; - - private ImageIcon tmpIcon; - - private final boolean isPickmap; // true if the map is a pickmap (those have different layout!) - - private int bOffset; // offset to map borders (32 for std. rect. maps, 0 for pickmaps) - - private final AttributeFilter af; - - private final Color[] highLightMask; - - private BufferedImage backBuffer; - - /** Current size of {@link #backBuffer} image. */ - private final Dimension bufferedSize = new Dimension(); - - private final AffineTransform renderTransform; - - /** Constructor */ - CFlatLevelRenderer(final MapModel mapModel, final boolean pickmap) { - this.mapModel = mapModel; - - af = new AttributeFilter(); - af.addAttribute("no_pass", "1"); - isPickmap = pickmap; - // initialize the tmp. graphic buffer - tmpImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); - tmpGrfx = tmpImage.getGraphics(); - if (!pickmap) { - tmpGrfx.setColor(mainControl.getMainView().getBackground()); // background color of window - } else { - tmpGrfx.setColor(IGUIConstants.BG_COLOR); - } - tmpIcon = new ImageIcon(); - - bOffset = !pickmap ? 32 : 0; - renderTransform = new AffineTransform(1f, 0f, 0f, 1f, (float) bOffset, (float) bOffset); - highLightMask = new Color[]{ - new Color(1.0f, 0.0f, 0.0f, 0.33f), - new Color(0.0f, 1.0f, 0.0f, 0.33f), - new Color(0.0f, 1.0f, 1.0f, 0.33f)}; - resizeBackBuffer(); - /*taken from java doc, scroll while dragged*/ - final MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { - @Override public void mouseDragged(final MouseEvent e) { - final Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); - ((JComponent) e.getSource()).scrollRectToVisible(r); - } - }; - this.addMouseMotionListener(doScrollRectToVisible); - } - - /** This method is called when the look and feel has changed */ - public void updateLookAndFeel() { - // update background color of window - if (!isPickmap) { - tmpGrfx.setColor(getBackground()); - } - } - - /** @return wether rendered map is a pickmap */ - public boolean isPickmap() { - return isPickmap; - } - - /** @return an image of the entire mapview */ - public BufferedImage getFullImage() { - final int storeOffset; // tmp. storage to save map offset - - final Size2D mapSize = getMapControl().getMapSize(); - final int mapWidth = 32 * mapSize.getWidth(); - final int mapHeight = 32 * mapSize.getHeight(); - - // first create a storing place for the image - final BufferedImage bufImage = new BufferedImage(mapWidth, mapHeight, BufferedImage.TYPE_INT_ARGB); - final Graphics bufGrfx = bufImage.getGraphics(); - bufGrfx.setColor(Color.white); - bufGrfx.setColor(Color.white); - bufGrfx.fillRect(0, 0, mapWidth, mapHeight); - - // paint the mapview into the image - storeOffset = bOffset; - bOffset = 0; - paintComponent((Graphics2D) bufGrfx, true); - bOffset = storeOffset; - //return bufImage.getScaledInstance(16*getMapControl().getMapWidth(), 16*getMapControl().getMapHeight(), Image.SCALE_SMOOTH); - return bufImage; - } - - @Override public void paintComponent(final Graphics grfx) { - if (isPickmap) { - paintComponent((Graphics2D) grfx, false); - } else { - ((Graphics2D) grfx).drawImage(backBuffer, renderTransform, null); - } - //paintHighLight(grfx); - } - - public void modelChanged() { - if (isPickmap) { - //pickmaps don't have double buffers - //maybe later could have them share one single buffer ? - repaint(); - } else { - log.debug("modelChanged(), we are in a backbuffered behaviour."); - final int storeOffset = bOffset; - bOffset = 0; - paintComponent((Graphics2D) backBuffer.getGraphics(), false); - bOffset = storeOffset; - repaint(); - } - } - - /** - * Paints this component. - * @param grfx The graphics context to paint to. - * @param isSnapshot true when this drawing is for a - * "screenshot"-image, false for normal drawing - */ - public void paintComponent(final Graphics2D grfx, final boolean isSnapshot) { - final ArchetypeSet archlist = mainControl.getArchetypeSet(); - - if (isPickmap) { - // draw greenisch background for pickmaps - grfx.setColor(IGUIConstants.BG_COLOR); - } else { - grfx.setColor(mainControl.getMainView().getBackground()); // background color of window - } - grfx.fillRect(0, 0, getWidth(), getHeight()); - // ---------- draw rectangular map -------------- - // this vector contains all heads of multi-tiles with oversized images - final Vector<GameObject> oversizedMultiHeads = new Vector<GameObject>(); - final CFilterControl filter = mainControl.getFilterControl(); - for (int y = 0; y < mapSize.getHeight(); y++) { - for (int x = 0; x < mapSize.getWidth(); x++) { - filter.newSquare(); - if (!mapModel.containsArchObject(x, y)) { - // empty square - if (isPickmap) { - grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); - } else { - mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); - } - } else { - for (final GameObject node : mapModel.getMapSquare(new Point(x, y))) { - filter.objectInSquare(node); - if (!filter.canShow(node)) { - continue; - } - if (mainControl.isTileEdit(node.getEditType()) || mainControl.getTileEdit() == 0 || isPickmap) { - if (node.getArchetypeName() == null) { - mainControl.getNoarchTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); - } else if (node.getFaceFlag()) { - mainControl.getNofaceTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); - } else { - if (node.getFaceNr() == -1) { - mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); - } else { - // draw object face - final ImageIcon img = archlist.getFace(node.getFaceNr()); - if (!node.isMulti() || (img.getIconWidth() == 32 && img.getIconHeight() == 32)) { - archlist.getFace(node.getFaceNr()).paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); - } else if (node.isHead()) { - oversizedMultiHeads.addElement(node); // store oversized arches for later - } - } - } - } - } - } - for (int i = 0; i < CFilterControl.MAX_HIGHLIGHT; i++) { - if (!filter.highLightedSquare(i)) { - continue; - } - final Color alpha = highLightMask[i]; - final Color c = grfx.getColor(); - grfx.setColor(alpha); - grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); - grfx.setColor(c); - } - } - } - // at the end, we have to draw the oversized multipart images on top of the rest - for (int i = 0; i < oversizedMultiHeads.size(); i++) { - final GameObject node = oversizedMultiHeads.elementAt(i); - archlist.getFace(node.getFaceNr()).paintIcon(this, grfx, node.getMapX() * 32 + bOffset, node.getMapY() * 32 + bOffset); - } - - // grid lines - if (showMapGrid && !isSnapshot) { - for (int x = 0; x <= mapSize.getWidth(); x++) { - grfx.drawLine( - x * 32 + bOffset, - 0 + bOffset, - x * 32 + bOffset, - mapSize.getHeight() * 32 + bOffset); - } - for (int y = 0; y <= mapSize.getHeight(); y++) { - grfx.drawLine( - 0 + bOffset, - y * 32 + bOffset, - mapSize.getWidth() * 32 + bOffset, - y * 32 + bOffset); - } - } - if (highlightOn && mapMouseRightPos.y != -1 && mapMouseRightPos.x != -1 && !isSnapshot) { - // Highlight the selected area - paintHighlightArea(grfx); - } - - - } - - /** - * Paints only one tile of the map. This is an incredible time-saver - * for insert/select/delete tile actions. - * <p/> - * Important: This method currently works only for standard - * (rectangular) view. Iso has overlapping tiles which makes this a lot - * more difficult. :( - * @param x map coordinates for the tile to draw - * @param y map coordinates for the tile to draw - */ - public void paintTile(final int x, final int y) { - final Graphics grfx; - if (isPickmap()) { - grfx = getGraphics(); // graphics context for drawing in the mapview - } else { - grfx = backBuffer.getGraphics(); - } - final ArchetypeSet archlist = mainControl.getArchetypeSet(); // arch stack - - // ---------- draw tile for rectangular view (non-iso) -------------- - final CFilterControl filter = mainControl.getFilterControl(); - filter.newSquare(); - // first, draw the object's faces: - if (!mapModel.containsArchObject(x, y)) { - // draw the empty-tile icon (direcly to the mapview) - if (isPickmap) { - grfx.setColor(IGUIConstants.BG_COLOR); - grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); - } else { - mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32, y * 32); - } - } else { - tmpGrfx.fillRect(0, 0, 32, 32); - // loop through all arches on that square and draw em - for (final GameObject node : mapModel.getMapSquare(new Point(x, y))) { - filter.objectInSquare(node); - if (!filter.canShow(node)) { - continue; - } - if (mainControl.isTileEdit(node.getEditType()) || mainControl.getTileEdit() == 0) { - if (node.getArchetypeName() == null) { - mainControl.getNoarchTileIconX().paintIcon(this, tmpGrfx, 0, 0); - } else if (node.getFaceFlag()) { - mainControl.getNofaceTileIconX().paintIcon(this, tmpGrfx, 0, 0); - } else { - if (node.getFaceNr() == -1) { - mainControl.getUnknownTileIconX().paintIcon(this, tmpGrfx, 0, 0); - } else { - final ImageIcon img = archlist.getFace(node.getFaceNr()); - if (!node.isMulti() || (img.getIconWidth() == 32 && img.getIconHeight() == 32)) { - img.paintIcon(this, tmpGrfx, 0, 0); - } else { - // this is an oversized image, so it must be shifted - img.paintIcon(this, tmpGrfx, -32 * node.getMultiX(), -32 * node.getMultiY()); - } - } - } - } - } - } - for (int i = 0; i < CFilterControl.MAX_HIGHLIGHT; i++) { - if (!filter.highLightedSquare(i)) { - continue; - } - final Color alpha = highLightMask[i]; - final Color c = grfx.getColor(); - tmpGrfx.setColor(alpha); - tmpGrfx.fillRect(0, 0, 32, 32); - tmpGrfx.setColor(c); - } - // We have been drawing to the tmp. buffer, now convert it to - // an ImageIcon and paint it into the mapview: - if (mapModel.containsArchObject(x, y)) { - tmpIcon.setImage(tmpImage); - tmpIcon.paintIcon(this, grfx, x * 32, y * 32); - } - - // if grid is active, draw grid lines (right and bottom) - if (showMapGrid) { - // horizontal: - grfx.drawLine(x * 32, y * 32, x * 32, y * 32 + 32); - // vertical: - grfx.drawLine(x * 32, y * 32, x * 32 + 32, y * 32); - } - - // if tile is highlighted, draw the highlight icon - paintHighlightTile(grfx, x, y); - } - - - public void setHighlightTile(final int x, final int y) { - if (isPickmap()) { - paintHighlightTile(getGraphics(), x, y); - } else { - paintHighlightTile(backBuffer.getGraphics(), x, y); - repaint(); - } - } - - /** - * If the given map-square is highlighted, the highligh-icon is drawn - * on that square. - * @param x map coords of the square - * @param y map coords of the square - * @param grfx graphics context to draw in - */ - public void paintHighlightTile(final Graphics grfx, final int x, final int y) { - // if tile is highlighted, draw the highlight icon: - if (highlightOn && mapMouseRightPos.y != -1 && mapMouseRightPos.x != -1) { - // get rect. coords of highlighted area: top(left) and bot(tomright) corner - final int topx = Math.min(mapMouseRightPos.x, mapMouseRightPos.x + mapMouseRightOff.x); - final int topy = Math.min(mapMouseRightPos.y, mapMouseRightPos.y + mapMouseRightOff.y); - final int botx = Math.max(mapMouseRightPos.x, mapMouseRightPos.x + mapMouseRightOff.x); - final int boty = Math.max(mapMouseRightPos.y, mapMouseRightPos.y + mapMouseRightOff.y); - - // Highlight the selected square - if (x >= topx && x <= botx && y >= topy && y <= boty) { - mainControl.getMapSelIconX().paintIcon(this, grfx, x * 32, y * 32); - } - } - } - - /** - * Painting the highlited (selected) area on the map - * @param grfx graphics context of mapview - */ - public void paintHighlightArea(final Graphics grfx) { - final int signX, signY; // sign = "direction" of the dragging offset - - if (mapMouseRightOff.x > 0) { - signX = 1; - } else if (mapMouseRightOff.x < 0) { - signX = -1; - } else { - signX = 0; - } - - if (mapMouseRightOff.y > 0) { - signY = 1; - } else if (mapMouseRightOff.y < 0) { - signY = -1; - } else { - signY = 0; - } - - // Highlight all tiles that are in the rectangle between drag-start and mouse - for (int posx = mapMouseRightPos.x; Math.abs(posx - mapMouseRightPos.x) - <= Math.abs(mapMouseRightOff.x); posx += signX) { - for (int posy = mapMouseRightPos.y; Math.abs(posy - mapMouseRightPos.y) - <= Math.abs(mapMouseRightOff.y); posy += signY) { - // Draw the Icon: - - // Rectangular view - mainControl.getMapSelIconX().paintIcon(this, grfx, posx * 32 + bOffset, posy * 32 + bOffset); - - if (signY == 0) { - break; - } - } - if (signX == 0) { - break; - } - } - } - - /** - * Returns the map location at the given point or null if no map - * location is at the point. - * @param point The coordinates in the renderer view. - * @return The map location. - */ - - // i'll change it to a fixed point... i want use this for mouse tracking - // and don't want have millions of mallocs here - // this should be reworked more intelligent later - public Point getTileLocationAt(final Point point) { - try { - renderTransform.inverseTransform(point, point); - } catch (final NoninvertibleTransformException e) { - } - mapMousePos.x = -1; - mapMousePos.y = -1; - - final Point mpoint = new Point(); - mpoint.x = mapMousePos.x; - mpoint.y = mapMousePos.y; - if (point.x >= 0 && point.x < mapSize.getWidth() * 32 && point.y >= 0 && point.y < mapSize.getHeight() * 32) { - mapMousePos.x = point.x / 32; - mapMousePos.y = point.y / 32; - } - - mpoint.x = mapMousePos.x; - mpoint.y = mapMousePos.y; - return mpoint; - } - - public boolean resizeBackBuffer() { - if (isPickmap) { - return false; - } - - final Size2D mapSize = getMapControl().getMapSize(); - final Dimension size = new Dimension(mapSize.getWidth() * 32, mapSize.getHeight() * 32); - if (bufferedSize.equals(size)) { - return true; - } - bufferedSize.setSize(size); - - if (log.isDebugEnabled()) { - log.debug("Creating a backbuffer of size " + size.width + "x" + size.height + "."); - } - backBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); - final Graphics g = backBuffer.getGraphics(); - g.setColor(Color.YELLOW); - g.fillRect(0, 0, size.width, size.height); - - return true; - } - - /* (non-Javadoc) - * - * @see cfeditor.CMapViewBasic.CLevelRenderer#freeMapBuffer() - */ - public void freeBackBuffer() { - backBuffer = null; - tmpGrfx = null; - tmpIcon = null; - tmpImage = null; - } + public void setMapMousePos(final int x, final int y) { + mapMousePos.x = x; + mapMousePos.y = y; } /** The mouse listener for the view. */ Added: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-01 21:49:33 UTC (rev 764) @@ -0,0 +1,518 @@ +/* + * 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.map; + +import cfeditor.CFilterControl; +import cfeditor.CMainControl; +import cfeditor.CMapViewBasic; +import cfeditor.IGUIConstants; +import cfeditor.filter.AttributeFilter; +import cfeditor.gameobject.ArchetypeSet; +import cfeditor.gameobject.GameObject; +import cfeditor.map.MapControl; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; +import java.awt.event.MouseMotionListener; +import java.awt.geom.AffineTransform; +import java.awt.geom.NoninvertibleTransformException; +import java.awt.image.BufferedImage; +import java.util.Vector; +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import net.sf.gridarta.Size2D; +import org.apache.log4j.Logger; + +/** + * The component that does the actual rendering of tiles in the palette. + * Flat version + */ +public final class DefaultLevelRenderer extends JComponent implements LevelRenderer { + + private static final Logger log = Logger.getLogger(DefaultLevelRenderer.class); + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + private final MapControl mapControl; + + private final CMapViewBasic mapViewBasic; + + // 32x32 Image and Icon for temprary storing tiles before drawing + private Image tmpImage; + + private Graphics tmpGrfx; + + private ImageIcon tmpIcon; + + private final boolean isPickmap; // true if the map is a pickmap (those have different layout!) + + private int bOffset; // offset to map borders (32 for std. rect. maps, 0 for pickmaps) + + private final CMainControl mainControl; + + private final AttributeFilter af; + + private final Color[] highLightMask; + + private BufferedImage backBuffer; + + /** Current size of {@link #backBuffer} image. */ + private final Dimension bufferedSize = new Dimension(); + + private final AffineTransform renderTransform; + + /** Constructor */ + public DefaultLevelRenderer(final CMapViewBasic mapViewBasic, final CMainControl mainControl, final MapControl mapControl, final boolean pickmap) { + this.mapViewBasic = mapViewBasic; + this.mainControl = mainControl; + this.mapControl = mapControl; + + af = new AttributeFilter(); + af.addAttribute("no_pass", "1"); + isPickmap = pickmap; + // initialize the tmp. graphic buffer + tmpImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); + tmpGrfx = tmpImage.getGraphics(); + if (!pickmap) { + tmpGrfx.setColor(mainControl.getMainView().getBackground()); // background color of window + } else { + tmpGrfx.setColor(IGUIConstants.BG_COLOR); + } + tmpIcon = new ImageIcon(); + + bOffset = !pickmap ? 32 : 0; + renderTransform = new AffineTransform(1f, 0f, 0f, 1f, (float) bOffset, (float) bOffset); + highLightMask = new Color[]{ + new Color(1.0f, 0.0f, 0.0f, 0.33f), + new Color(0.0f, 1.0f, 0.0f, 0.33f), + new Color(0.0f, 1.0f, 1.0f, 0.33f)}; + resizeBackBuffer(); + /*taken from java doc, scroll while dragged*/ + final MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { + @Override public void mouseDragged(final MouseEvent e) { + final Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); + ((JComponent) e.getSource()).scrollRectToVisible(r); + } + }; + this.addMouseMotionListener(doScrollRectToVisible); + } + + /** This method is called when the look and feel has changed */ + public void updateLookAndFeel() { + // update background color of window + if (!isPickmap) { + tmpGrfx.setColor(getBackground()); + } + } + + /** @return wether rendered map is a pickmap */ + public boolean isPickmap() { + return isPickmap; + } + + /** @return an image of the entire mapview */ + public BufferedImage getFullImage() { + final int storeOffset; // tmp. storage to save map offset + + final Size2D mapSize = mapControl.getMapSize(); + final int mapWidth = 32 * mapSize.getWidth(); + final int mapHeight = 32 * mapSize.getHeight(); + + // first create a storing place for the image + final BufferedImage bufImage = new BufferedImage(mapWidth, mapHeight, BufferedImage.TYPE_INT_ARGB); + final Graphics bufGrfx = bufImage.getGraphics(); + bufGrfx.setColor(Color.white); + bufGrfx.setColor(Color.white); + bufGrfx.fillRect(0, 0, mapWidth, mapHeight); + + // paint the mapview into the image + storeOffset = bOffset; + bOffset = 0; + paintComponent((Graphics2D) bufGrfx, true); + bOffset = storeOffset; + //return bufImage.getScaledInstance(16*mapControl.getMapWidth(), 16*mapControl.getMapHeight(), Image.SCALE_SMOOTH); + return bufImage; + } + + @Override public void paintComponent(final Graphics grfx) { + if (isPickmap) { + paintComponent((Graphics2D) grfx, false); + } else { + ((Graphics2D) grfx).drawImage(backBuffer, renderTransform, null); + } + //paintHighLight(grfx); + } + + public void modelChanged() { + if (isPickmap) { + //pickmaps don't have double buffers + //maybe later could have them share one single buffer ? + repaint(); + } else { + log.debug("modelChanged(), we are in a backbuffered behaviour."); + final int storeOffset = bOffset; + bOffset = 0; + paintComponent((Graphics2D) backBuffer.getGraphics(), false); + bOffset = storeOffset; + repaint(); + } + } + + /** + * Paints this component. + * @param grfx The graphics context to paint to. + * @param isSnapshot true when this drawing is for a + * "screenshot"-image, false for normal drawing + */ + public void paintComponent(final Graphics2D grfx, final boolean isSnapshot) { + final ArchetypeSet archlist = mainControl.getArchetypeSet(); + + if (isPickmap) { + // draw greenisch background for pickmaps + grfx.setColor(IGUIConstants.BG_COLOR); + } else { + grfx.setColor(mainControl.getMainView().getBackground()); // background color of window + } + grfx.fillRect(0, 0, getWidth(), getHeight()); + // ---------- draw rectangular map -------------- + // this vector contains all heads of multi-tiles with oversized images + final Vector<GameObject> oversizedMultiHeads = new Vector<GameObject>(); + final CFilterControl filter = mainControl.getFilterControl(); + for (int y = 0; y < mapViewBasic.getMapSize().getHeight(); y++) { + for (int x = 0; x < mapViewBasic.getMapSize().getWidth(); x++) { + filter.newSquare(); + if (!mapControl.getMapModel().containsArchObject(x, y)) { + // empty square + if (isPickmap) { + grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); + } else { + mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); + } + } else { + for (final GameObject node : mapControl.getMapModel().getMapSquare(new Point(x, y))) { + filter.objectInSquare(node); + if (!filter.canShow(node)) { + continue; + } + if (mainControl.isTileEdit(node.getEditType()) || mainControl.getTileEdit() == 0 || isPickmap) { + if (node.getArchetypeName() == null) { + mainControl.getNoarchTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); + } else if (node.getFaceFlag()) { + mainControl.getNofaceTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); + } else { + if (node.getFaceNr() == -1) { + mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); + } else { + // draw object face + final ImageIcon img = archlist.getFace(node.getFaceNr()); + if (!node.isMulti() || (img.getIconWidth() == 32 && img.getIconHeight() == 32)) { + archlist.getFace(node.getFaceNr()).paintIcon(this, grfx, x * 32 + bOffset, y * 32 + bOffset); + } else if (node.isHead()) { + oversizedMultiHeads.addElement(node); // store oversized arches for later + } + } + } + } + } + } + for (int i = 0; i < CFilterControl.MAX_HIGHLIGHT; i++) { + if (!filter.highLightedSquare(i)) { + continue; + } + final Color alpha = highLightMask[i]; + final Color c = grfx.getColor(); + grfx.setColor(alpha); + grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); + grfx.setColor(c); + } + } + } + // at the end, we have to draw the oversized multipart images on top of the rest + for (int i = 0; i < oversizedMultiHeads.size(); i++) { + final GameObject node = oversizedMultiHeads.elementAt(i); + archlist.getFace(node.getFaceNr()).paintIcon(this, grfx, node.getMapX() * 32 + bOffset, node.getMapY() * 32 + bOffset); + } + + // grid lines + if (mapViewBasic.isGridVisible() && !isSnapshot) { + for (int x = 0; x <= mapViewBasic.getMapSize().getWidth(); x++) { + grfx.drawLine( + x * 32 + bOffset, + 0 + bOffset, + x * 32 + bOffset, + mapViewBasic.getMapSize().getHeight() * 32 + bOffset); + } + for (int y = 0; y <= mapViewBasic.getMapSize().getHeight(); y++) { + grfx.drawLine( + 0 + bOffset, + y * 32 + bOffset, + mapViewBasic.getMapSize().getWidth() * 32 + bOffset, + y * 32 + bOffset); + } + } + if (mapViewBasic.isHighlight() && mapViewBasic.getMapMouseRightPos().y != -1 && mapViewBasic.getMapMouseRightPos().x != -1 && !isSnapshot) { + // Highlight the selected area + paintHighlightArea(grfx); + } + + + } + + /** + * Paints only one tile of the map. This is an incredible time-saver + * for insert/select/delete tile actions. + * <p/> + * Important: This method currently works only for standard + * (rectangular) view. Iso has overlapping tiles which makes this a lot + * more difficult. :( + * @param x map coordinates for the tile to draw + * @param y map coordinates for the tile to draw + */ + public void paintTile(final int x, final int y) { + final Graphics grfx; + if (isPickmap()) { + grfx = getGraphics(); // graphics context for drawing in the mapview + } else { + grfx = backBuffer.getGraphics(); + } + final ArchetypeSet archlist = mainControl.getArchetypeSet(); // arch stack + + // ---------- draw tile for rectangular view (non-iso) -------------- + final CFilterControl filter = mainControl.getFilterControl(); + filter.newSquare(); + // first, draw the object's faces: + if (!mapControl.getMapModel().containsArchObject(x, y)) { + // draw the empty-tile icon (direcly to the mapview) + if (isPickmap) { + grfx.setColor(IGUIConstants.BG_COLOR); + grfx.fillRect(x * 32 + bOffset, y * 32 + bOffset, 32, 32); + } else { + mainControl.getUnknownTileIconX().paintIcon(this, grfx, x * 32, y * 32); + } + } else { + tmpGrfx.fillRect(0, 0, 32, 32); + // loop through all arches on that square and draw em + for (final GameObject node : mapControl.getMapModel().getMapSquare(new Point(x, y))) { + filter.objectInSquare(node); + if (!filter.canShow(node)) { + continue; + } + if (mainControl.isTileEdit(node.getEditType()) || mainControl.getTileEdit() == 0) { + if (node.getArchetypeName() == null) { + mainControl.getNoarchTileIconX().paintIcon(this, tmpGrfx, 0, 0); + } else if (node.getFaceFlag()) { + mainControl.getNofaceTileIconX().paintIcon(this, tmpGrfx, 0, 0); + } else { + if (node.getFaceNr() == -1) { + mainControl.getUnknownTileIconX().paintIcon(this, tmpGrfx, 0, 0); + } else { + final ImageIcon img = archlist.getFace(node.getFaceNr()); + if (!node.isMulti() || (img.getIconWidth() == 32 && img.getIconHeight() == 32)) { + img.paintIcon(this, tmpGrfx, 0, 0); + } else { + // this is an oversized image, so it must be shifted + img.paintIcon(this, tmpGrfx, -32 * node.getMultiX(), -32 * node.getMultiY()); + } + } + } + } + } + } + for (int i = 0; i < CFilterControl.MAX_HIGHLIGHT; i++) { + if (!filter.highLightedSquare(i)) { + continue; + } + final Color alpha = highLightMask[i]; + final Color c = grfx.getColor(); + tmpGrfx.setColor(alpha); + tmpGrfx.fillRect(0, 0, 32, 32); + tmpGrfx.setColor(c); + } + // We have been drawing to the tmp. buffer, now convert it to + // an ImageIcon and paint it into the mapview: + if (mapControl.getMapModel().containsArchObject(x, y)) { + tmpIcon.setImage(tmpImage); + tmpIcon.paintIcon(this, grfx, x * 32, y * 32); + } + + // if grid is active, draw grid lines (right and bottom) + if (mapViewBasic.isGridVisible()) { + // horizontal: + grfx.drawLine(x * 32, y * 32, x * 32, y * 32 + 32); + // vertical: + grfx.drawLine(x * 32, y * 32, x * 32 + 32, y * 32); + } + + // if tile is highlighted, draw the highlight icon + paintHighlightTile(grfx, x, y); + } + + + public void setHighlightTile(final int x, final int y) { + if (isPickmap()) { + paintHighlightTile(getGraphics(), x, y); + } else { + paintHighlightTile(backBuffer.getGraphics(), x, y); + repaint(); + } + } + + /** + * If the given map-square is highlighted, the highligh-icon is drawn + * on that square. + * @param x map coords of the square + * @param y map coords of the square + * @param grfx graphics context to draw in + */ + public void paintHighlightTile(final Graphics grfx, final int x, final int y) { + // if tile is highlighted, draw the highlight icon: + if (mapViewBasic.isHighlight() && mapViewBasic.getMapMouseRightPos().y != -1 && mapViewBasic.getMapMouseRightPos().x != -1) { + // get rect. coords of highlighted area: top(left) and bot(tomright) corner + final int topx = Math.min(mapViewBasic.getMapMouseRightPos().x, mapViewBasic.getMapMouseRightPos().x + mapViewBasic.getHighlightOffset().x); + final int topy = Math.min(mapViewBasic.getMapMouseRightPos().y, mapViewBasic.getMapMouseRightPos().y + mapViewBasic.getHighlightOffset().y); + final int botx = Math.max(mapViewBasic.getMapMouseRightPos().x, mapViewBasic.getMapMouseRightPos().x + mapViewBasic.getHighlightOffset().x); + final int boty = Math.max(mapViewBasic.getMapMouseRightPos().y, mapViewBasic.getMapMouseRightPos().y + mapViewBasic.getHighlightOffset().y); + + // Highlight the selected square + if (x >= topx && x <= botx && y >= topy && y <= boty) { + mainControl.getMapSelIconX().paintIcon(this, grfx, x * 32, y * 32); + } + } + } + + /** + * Painting the highlited (selected) area on the map + * @param grfx graphics context of mapview + */ + public void paintHighlightArea(final Graphics grfx) { + final int signX, signY; // sign = "direction" of the dragging offset + + if (mapViewBasic.getHighlightOffset().x > 0) { + signX = 1; + } else if (mapViewBasic.getHighlightOffset().x < 0) { + signX = -1; + } else { + signX = 0; + } + + if (mapViewBasic.getHighlightOffset().y > 0) { + signY = 1; + } else if (mapViewBasic.getHighlightOffset().y < 0) { + signY = -1; + } else { + signY = 0; + } + + // Highlight all tiles that are in the rectangle between drag-start and mouse + for (int posx = mapViewBasic.getMapMouseRightPos().x; Math.abs(posx - mapViewBasic.getMapMouseRightPos().x) + <= Math.abs(mapViewBasic.getHighlightOffset().x); posx += signX) { + for (int posy = mapViewBasic.getMapMouseRightPos().y; Math.abs(posy - mapViewBasic.getMapMouseRightPos().y) + <= Math.abs(mapViewBasic.getHighlightOffset().y); posy += signY) { + // Draw the Icon: + + // Rectangular view + mainControl.getMapSelIconX().paintIcon(this, grfx, posx * 32 + bOffset, posy * 32 + bOffset); + + if (signY == 0) { + break; + } + } + if (signX == 0) { + break; + } + } + } + + /** + * Returns the map location at the given point or null if no map + * location is at the point. + * @param point The coordinates in the renderer view. + * @return The map location. + */ + + // i'll change it to a fixed point... i want use this for mouse tracking + // and don't want have millions of mallocs here + // this should be reworked more intelligent later + public Point getTileLocationAt(final Point point) { + try { + renderTransform.inverseTransform(point, point); + } catch (final NoninvertibleTransformException e) { + } + mapViewBasic.setMapMousePos(-1, -1); + + final Point mpoint = new Point(); + mpoint.x = mapViewBasic.getMapMousePos().x; + mpoint.y = mapViewBasic.getMapMousePos().y; + if (point.x >= 0 && point.x < mapViewBasic.getMapSize().getWidth() * 32 && point.y >= 0 && point.y < mapViewBasic.getMapSize().getHeight() * 32) { + mapViewBasic.setMapMousePos(point.x / 32, point.y / 32); + } + + mpoint.x = mapViewBasic.getMapMousePos().x; + mpoint.y = mapViewBasic.getMapMousePos().y; + return mpoint; + } + + public boolean resizeBackBuffer() { + if (isPickmap) { + return false; + } + + final Size2D mapSize = mapControl.getMapSize(); + final Dimension size = new Dimension(mapSize.getWidth() * 32, mapSize.getHeight() * 32); + if (bufferedSize.equals(size)) { + return true; + } + bufferedSize.setSize(size); + + if (log.isDebugEnabled()) { + log.debug("Creating a backbuffer of size " + size.width + "x" + size.height + "."); + } + backBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); + final Graphics g = backBuffer.getGraphics(); + g.setColor(Color.YELLOW); + g.fillRect(0, 0, size.width, size.height); + + return true; + } + + /* (non-Javadoc) + * + * @see LevelRenderer#freeMapBuffer() + */ + public void freeBackBuffer() { + backBuffer = null; + tmpGrfx = null; + tmpIcon = null; + tmpImage = null; + } + +} Property changes on: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java 2006-12-01 21:49:33 UTC (rev 764) @@ -0,0 +1,53 @@ +/* + * 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 cfeditor.gui.map; + +import java.awt.Graphics; +import java.awt.Point; +import java.awt.image.BufferedImage; + +/** + * A lavel renderer, mainly used as central point interfac to iso and flat + * renderer + * @author tchize + */ +public interface LevelRenderer { + + void updateLookAndFeel(); + + BufferedImage getFullImage(); + + void paintTile(int x, int y); + + Point getTileLocationAt(Point point); + + boolean isPickmap(); + + void paintHighlightTile(Graphics grfx, int x, int y); + + void modelChanged(); + + void setHighlightTile(int x, int y); + + boolean resizeBackBuffer(); + + void freeBackBuffer(); +} Property changes on: trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.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: <aki...@us...> - 2006-12-01 22:28:44
|
Revision: 768 http://svn.sourceforge.net/gridarta/?rev=768&view=rev Author: akirschbaum Date: 2006-12-01 14:28:44 -0800 (Fri, 01 Dec 2006) Log Message: ----------- Rename variables/methods. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainMenu.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/MapViewIFrame.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-01 22:06:28 UTC (rev 767) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-01 22:28:44 UTC (rev 768) @@ -606,9 +606,9 @@ return currentMap.getMapViewFrame().isGridVisible(); } - public void setGridVisibility(final boolean fVisible) { + public void setGridVisible(final boolean gridVisible) { if (currentMap != null) { - currentMap.getMapViewFrame().setGridVisibility(fVisible); + currentMap.getMapViewFrame().setGridVisible(gridVisible); } } Modified: trunk/crossfire/src/cfeditor/CMainMenu.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainMenu.java 2006-12-01 22:06:28 UTC (rev 767) +++ trunk/crossfire/src/cfeditor/CMainMenu.java 2006-12-01 22:28:44 UTC (rev 768) @@ -679,7 +679,7 @@ m_gridToggle.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent event) { - mainControl.setGridVisibility(m_gridToggle.isChecked()); + mainControl.setGridVisible(m_gridToggle.isChecked()); } }); menuManager.addMenuEntry("main.map", m_gridToggle); Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-01 22:06:28 UTC (rev 767) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-01 22:28:44 UTC (rev 768) @@ -88,7 +88,7 @@ private boolean changed = false; - private boolean showMapGrid; + private boolean gridVisible = false; // this is needed to check the diamond tile areas and convert rectangles to diamond private final Point mapMousePos = new Point(); @@ -117,7 +117,6 @@ this.mapControl = mapControl; this.mainControl = mainControl; frame = fi; - showMapGrid = false; highlightOn = false; needMpanelUpdate = new boolean[3]; @@ -177,7 +176,7 @@ * @return true if map grid is visible */ public boolean isGridVisible() { - return showMapGrid; + return gridVisible; } /** Update for a new look and feel (-> view menu) */ @@ -213,8 +212,8 @@ return mapControl; } - public void setGridVisibility(final boolean fVisible) { - showMapGrid = fVisible; + public void setGridVisible(final boolean gridVisible) { + this.gridVisible = gridVisible; this.modelChanged(); } Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-01 22:06:28 UTC (rev 767) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-01 22:28:44 UTC (rev 768) @@ -154,8 +154,8 @@ return mapControl; } - public void setGridVisibility(final boolean fVisible) { - view.setGridVisibility(fVisible); + public void setGridVisible(final boolean gridVisible) { + view.setGridVisible(gridVisible); } public void closeNotify() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-01 22:32:20
|
Revision: 769 http://svn.sourceforge.net/gridarta/?rev=769&view=rev Author: akirschbaum Date: 2006-12-01 14:32:20 -0800 (Fri, 01 Dec 2006) Log Message: ----------- Unify transient modifier. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanel.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-01 22:28:44 UTC (rev 768) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-01 22:32:20 UTC (rev 769) @@ -52,7 +52,7 @@ private static final long serialVersionUID = 1L; /** Controller of this subview. */ - private final CMainControl mainControl; + private final transient CMainControl mainControl; /** The "Import..." button. */ Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-01 22:28:44 UTC (rev 768) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-01 22:32:20 UTC (rev 769) @@ -89,7 +89,7 @@ private int lastClickId = -1; /** The currently selected MapSquare. */ - private Point currentSquare = null; + private transient Point currentSquare = null; /** Build Panel */ CMapTileList(final CMainControl mainControl, final CMainView mainView) { Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-12-01 22:28:44 UTC (rev 768) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-12-01 22:32:20 UTC (rev 769) @@ -57,7 +57,7 @@ * The CMainControl used for various operations. * @deprecated it's not a good idea to require the MapModel implementation to know such a heavy-weight strongly UI-related glue class like {@link CMainControl}. */ - @Deprecated private final CMainControl mainControl; + @Deprecated private final transient CMainControl mainControl; /** * The MapControl that controls this MapModel. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-01 22:56:26
|
Revision: 770 http://svn.sourceforge.net/gridarta/?rev=770&view=rev Author: akirschbaum Date: 2006-12-01 14:56:24 -0800 (Fri, 01 Dec 2006) Log Message: ----------- Replace Vector with List. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CFArchType.java trunk/crossfire/src/cfeditor/CFArchTypeList.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-01 22:32:20 UTC (rev 769) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-01 22:56:24 UTC (rev 770) @@ -51,7 +51,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Vector; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.BorderFactory; @@ -371,18 +370,18 @@ /** * Construct the Combo box for arrays of "list data" (this is used for ArchAttribType.LIST). * @param attr list attribute - * @param listData Vector with list items and corresponding values + * @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 Vector listData) { + private JComboBox buildArrayBox(final CFArchAttrib attr, final List<?> listData) { // build the array of list-items final String []array = new String[(int) (listData.size() / 2.)]; boolean hasSelection = false; int active = gameObject.getAttributeInt(attr.getNameOld()); for (int i = 0; i < array.length; i++) { - array[i] = (String) listData.elementAt(i * 2 + 1); // put string to array - if (!hasSelection && ((Integer) listData.elementAt(i * 2)).intValue() == active) { + array[i] = (String) listData.get(i * 2 + 1); // put string to array + if (!hasSelection && ((Integer) listData.get(i * 2)).intValue() == active) { hasSelection = true; // the selection is valid active = i; // set selection to this index in the array } @@ -718,7 +717,7 @@ case LIST: if (type.getAttr()[i].getMisc() != null && typelist.getListTable().containsKey((String) (type.getAttr()[i].getMisc()[0]))) { // build the list from vector data - input = buildArrayBox(type.getAttr()[i], (Vector) (typelist.getListTable().get((String) (type.getAttr()[i].getMisc()[0])))); + input = buildArrayBox(type.getAttr()[i], typelist.getListTable().get((String) (type.getAttr()[i].getMisc()[0]))); } else { // error: list data is missing or corrupt cComp = new JLabel("Error: Undefined List"); @@ -1120,7 +1119,7 @@ // get selected index of ComboBox final int attrValTmp = ((JComboBox) attr.input).getSelectedIndex(); // fetch value according to this list entry: - attrVal = (Integer) ((Vector) (typelist.getListTable().get(attr.ref.getMisc()[0]))).elementAt(2 * attrValTmp); + attrVal = (Integer) (typelist.getListTable().get(attr.ref.getMisc()[0])).get(2 * attrValTmp); break; default: assert false; Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2006-12-01 22:32:20 UTC (rev 769) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2006-12-01 22:56:24 UTC (rev 770) @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; -import java.util.Vector; import org.apache.log4j.Logger; import org.jdom.Attribute; import org.jdom.Element; @@ -121,10 +120,10 @@ */ public boolean load(final Element root, final CFArchTypeList tlist) { // this vector is used to store a temporare linked list of attributes - final Vector<CFArchAttrib> attrList = new Vector<CFArchAttrib>(); + final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); // for internal section handling: - final Vector<String> secNames = new Vector<String>(); // list of section names + final List<String> secNames = new ArrayList<String>(); // list of section names final Hashtable<String, String> ignoreTable = new Hashtable<String, String>(); // ignore list List<Element> children; // list of children elements @@ -203,9 +202,9 @@ log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { // just copy everything from ignorelist to this ignore section - final Vector<String> ignlist = tlist.getIgnoreListTable().get(a1.getValue().trim()); + final List<String> ignlist = tlist.getIgnoreListTable().get(a1.getValue().trim()); for (int k = 0; k < ignlist.size(); k++) { - ignoreTable.put(ignlist.elementAt(k), ""); + ignoreTable.put(ignlist.get(k), ""); } } else { log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); @@ -318,7 +317,7 @@ !impType.attr[z].getSecName().equalsIgnoreCase("special") && !secNames.contains(impType.attr[z].getSecName())) { sectionNum++; // increment number of valid sections - secNames.addElement(impType.attr[z].getSecName()); + secNames.add(impType.attr[z].getSecName()); } importList[importNum] = impType.attr[z].getClone(); @@ -362,7 +361,7 @@ // put the list of the (non-default) CFArchAttribs into an array: for (int i = 0; numDef < j && i < attrList.size(); numDef++, i++) { - attr[numDef] = attrList.elementAt(i); + attr[numDef] = attrList.get(i); } return true; // archtype was parsed correctly @@ -379,7 +378,7 @@ * @param attrList linked list of attributes * @param tlist arch type list */ - private void parseAttribute(final Element elem, final Vector<String> secNames, final boolean inSection, final String section, final Vector<CFArchAttrib> attrList, final CFArchTypeList tlist) { + private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final CFArchTypeList tlist) { // create new instance final CFArchAttrib attrib = new CFArchAttrib(); Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-01 22:32:20 UTC (rev 769) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-01 22:56:24 UTC (rev 770) @@ -33,10 +33,10 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Vector; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.io.IOUtils; @@ -66,9 +66,9 @@ private Map<String, CAttribBitmask> bitmaskTable; // table with CAttribBitmask objects (value) sorted by name (key) - private Map<String, Vector> listTable; // table with Vector objects for lists (value) sorted by name (key) + private Map<String, List<?>> listTable; // table with List objects for lists (value) sorted by name (key) - private Map<String, Vector<String>> ignoreListTable; // table with Vector objects for ignore_lists (value) sorted by name (key) + private Map<String, List<String>> ignoreListTable; // table with List objects for ignore_lists (value) sorted by name (key) private int length = 0; // Number of types in the list @@ -80,8 +80,8 @@ CFArchType cfType = head; // index of CFArchType list // initialize the arrays of "special-data" bitmaskTable = new HashMap<String, CAttribBitmask>(); - listTable = new HashMap<String, Vector>(); - ignoreListTable = new HashMap<String, Vector<String>>(); + listTable = new HashMap<String, List<?>>(); + ignoreListTable = new HashMap<String, List<String>>(); loadSpellsFromXML(); // load spells from file @@ -122,7 +122,7 @@ if (elem.getAttribute("name") == null) { log.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); } else { - final Vector list = parseListFromElement(elem); + final List<?> list = parseListFromElement(elem); if (list != null && list.size() > 0) { listTable.put(elem.getAttribute("name").getValue(), list); } @@ -156,11 +156,11 @@ final List<Element> children2 = elem.getChildren(CFArchType.XML_ATTRIBUTE); if (children2 != null && children2.size() > 0) { // load all attribute entries - final Vector<String> content = new Vector<String>(); + final List<String> content = new ArrayList<String>(); for (int k = 0; k < children2.size(); k++) { elem = children2.get(k); if ((a = elem.getAttribute(CFArchAttrib.XML_KEY_ARCH)) != null) { - content.addElement(a.getValue().trim()); + content.add(a.getValue().trim()); } else { log.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); } @@ -211,8 +211,8 @@ * Parse a list vector from an xml list element. * @param root element to parse */ - private Vector parseListFromElement(final Element root) { - final Vector list = new Vector(); // list vector + private List<?> parseListFromElement(final Element root) { + final List<Object> list = new ArrayList<Object>(); int num; // number for list element Element elem; @@ -225,8 +225,8 @@ // every list entry adds value (Integer) and name (String) to the vector try { num = elem.getAttribute("value").getIntValue(); - list.addElement(new Integer(num)); - list.addElement(" " + elem.getAttribute("name").getValue().trim()); + list.add(new Integer(num)); + list.add(" " + elem.getAttribute("name").getValue().trim()); } catch (final DataConversionException e) { log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name").getValue() + ": value '" + elem.getAttribute("value").getValue() + "' is not an integer."); } @@ -268,7 +268,7 @@ return bitmaskTable; } - public Map<String, Vector> getListTable() { + public Map<String, List<?>> getListTable() { return listTable; } @@ -276,7 +276,7 @@ * Return the ignore list table which contains all definitions of ignore lists for arch attributes. * @return ignore list table */ - public Map<String, Vector<String>> getIgnoreListTable() { + public Map<String, List<String>> getIgnoreListTable() { return ignoreListTable; } @@ -397,14 +397,14 @@ * @return number of successfully collected spells */ private int importSpells(final File spellfile) { - Vector<String> list = null; // growable array of spellnames+numbers + List<String> list = null; // growable array of spellnames+numbers String tmp; // tmp String for spell names final FileWriter fileWriter; // file writer for "spells.def" final BufferedWriter bufferedWriter; // buffered writer if (spellfile.getName().equalsIgnoreCase("spellist.h")) { - list = new Vector<String>(); + list = new ArrayList<String>(); FileReader fileReader = null; BufferedReader bufferedReader = null; @@ -427,12 +427,12 @@ name = name.trim(); // now insert this string lexographically into the vector for (i = 0; i < list.size(); i++) { - tmp = list.elementAt(i); + tmp = list.get(i); tmp = tmp.substring(tmp.indexOf(" ") + 1); if (name.compareTo(tmp) < 0) { // everything okay, now insert - list.insertElementAt((counter + " " + name), i); + list.add(i, counter + " " + name); i = list.size() + 10; // end for } else if (name.compareTo(tmp) == 0) { // this spell already exist in the list @@ -443,7 +443,7 @@ // if no insertion spot found, add to end of list if (i < list.size() + 10) { - list.insertElementAt((counter + " " + name), list.size()); + list.add(counter + " " + name); } } } catch (final FileNotFoundException e) { @@ -493,7 +493,7 @@ // write spell-entries: for (int i = 0; i < list.size(); i++) { - tmp = String.valueOf(list.elementAt(i)); + tmp = String.valueOf(list.get(i)); final String id = tmp.substring(0, tmp.indexOf(" ")).trim(); final String name = tmp.substring(tmp.indexOf(" ") + 1).trim(); String space = ""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-02 09:41:20
|
Revision: 782 http://svn.sourceforge.net/gridarta/?rev=782&view=rev Author: akirschbaum Date: 2006-12-02 01:41:20 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Implement 'long' attribute type for game object attibutes. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CFArchAttrib.java trunk/crossfire/src/cfeditor/gameobject/ArchAttribType.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-01 23:57:05 UTC (rev 781) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-02 09:41:20 UTC (rev 782) @@ -623,6 +623,7 @@ } break; case INT: + case LONG: case FLOAT: { cLabel = new JLabel(type.getAttr()[i].getNameNew() + ": "); cLabel.setForeground(dType == ArchAttribType.FLOAT ? IGUIConstants.FLOAT_COLOR : IGUIConstants.INT_COLOR); @@ -631,6 +632,7 @@ final NumberFormat format; switch (dType) { case INT: + case LONG: format = NumberFormat.getIntegerInstance(); break; case FLOAT: @@ -651,6 +653,9 @@ case INT: value = gameObject.getAttributeInt(nameOld, true); break; + case LONG: + value = gameObject.getAttributeLong(nameOld, true); + break; case FLOAT: value = gameObject.getAttributeDouble(nameOld, true); break; @@ -912,6 +917,7 @@ } 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")) { @@ -1017,12 +1023,17 @@ } 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"; @@ -1037,6 +1048,13 @@ } } 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(); Modified: trunk/crossfire/src/cfeditor/CFArchAttrib.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchAttrib.java 2006-12-01 23:57:05 UTC (rev 781) +++ trunk/crossfire/src/cfeditor/CFArchAttrib.java 2006-12-02 09:41:20 UTC (rev 782) @@ -150,6 +150,8 @@ misc[1] = a2.getValue().trim(); // string for false } else if (atype.equalsIgnoreCase("int")) { dataType = ArchAttribType.INT; + } else if (atype.equalsIgnoreCase("long")) { + dataType = ArchAttribType.LONG; } else if (atype.equalsIgnoreCase("float")) { dataType = ArchAttribType.FLOAT; } else if (atype.equalsIgnoreCase("string")) { Modified: trunk/crossfire/src/cfeditor/gameobject/ArchAttribType.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchAttribType.java 2006-12-01 23:57:05 UTC (rev 781) +++ trunk/crossfire/src/cfeditor/gameobject/ArchAttribType.java 2006-12-02 09:41:20 UTC (rev 782) @@ -36,6 +36,9 @@ /** Integer -> Textfield. */ INT, + /** Long -> Textfield. */ + LONG, + /** Float -> Textfield. */ FLOAT, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-02 10:50:19
|
Revision: 784 http://svn.sourceforge.net/gridarta/?rev=784&view=rev Author: akirschbaum Date: 2006-12-02 02:50:19 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Rename cfeditor.CMapPropertiesDialog to cfeditor.gui.map.MapPropertiesDialog. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CMapPropertiesDialog.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-02 09:42:45 UTC (rev 783) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-02 10:50:19 UTC (rev 784) @@ -31,6 +31,7 @@ import cfeditor.gameobject.face.FaceObjects; import cfeditor.io.CMapReader; import cfeditor.io.CMapWriter; +import cfeditor.gui.map.MapPropertiesDialog; import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; @@ -1173,7 +1174,7 @@ */ void showMapProperties(final MapControl level) { if (level != null) { - new CMapPropertiesDialog(this, mainView, level); + new MapPropertiesDialog(this, mainView, level); } } @@ -1200,7 +1201,7 @@ * @param strMapTitle map name * @param mapSize size of map */ - void setLevelProperties(final MapControl level, final String archText, final String loreText, final String strMapTitle, final Size2D mapSize) { + public void setLevelProperties(final MapControl level, final String archText, final String loreText, final String strMapTitle, final Size2D mapSize) { if (level != null) { level.setProperties(archText, loreText, strMapTitle, mapSize); refreshMenusAndToolbars(); Deleted: trunk/crossfire/src/cfeditor/CMapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapPropertiesDialog.java 2006-12-02 09:42:45 UTC (rev 783) +++ trunk/crossfire/src/cfeditor/CMapPropertiesDialog.java 2006-12-02 10:50:19 UTC (rev 784) @@ -1,661 +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.map.MapArchObject; -import cfeditor.map.MapControl; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JViewport; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import net.sf.gridarta.Size2D; -import net.sf.gridarta.help.Help; - -/** - * Dialog used to ask the user the properties for the new level. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class CMapPropertiesDialog extends CDialogBase { - - public static final String CENTER_MAP_KEY = "MapProperties.centerMapOnResize"; - - private final CMainControl mainControl; - - private final MapControl m_level; - - // input components, see MapArchObject for expl. of purpose - private final JTextArea m_textArea; // the msg text/arch text - - private final JTextArea m_loreArea; // the lore text - - private final JTextField m_nameField = new JTextField(); // name of arch - - private final JTextField m_regionField = new JTextField(); // map's region - - private final JTextField m_levelWidthField = new JTextField(); // len x - - private final JTextField m_levelHeightField = new JTextField(); // len y - - private final JCheckBox m_unique = new JCheckBox(); // map unique - - private final JCheckBox m_outdoor = new JCheckBox(); // map outdoor - - private final JCheckBox m_fixedReset = new JCheckBox(); // fixed reset - - private final JCheckBox m_nosmooth = new JCheckBox(); // map nosmooth - - private final JTextField m_enterX = new JTextField(); // enter x - - private final JTextField m_enterY = new JTextField(); // enter y - - private final JTextField m_swapTime = new JTextField(); // swap time - - private final JTextField m_resetTimeout = new JTextField(); // reset timeout - - private final JTextField m_difficulty = new JTextField(); // map difficulty - - private final JTextField m_darkness = new JTextField(); // darkness - - private final JTextField[] m_tilePath = new JTextField[IGUIConstants.DIRECTIONS]; // tile paths - - // only for CF: - private final JTextField m_shopitems = new JTextField(); // shopitems - - private final JTextField m_shopgreed = new JTextField(); // shopgreed - - private final JTextField m_shopmax = new JTextField(); // shop maximum price - - private final JTextField m_shopmin = new JTextField(); // shop minimum price - - private final JTextField m_shoprace = new JTextField(); // shop's preferred race - - private final JTextField m_temp = new JTextField(); // temperature - - private final JTextField m_pressure = new JTextField(); // pressure - - private final JTextField m_humid = new JTextField(); // humidity - - private final JTextField m_windspeed = new JTextField(); // wind speed - - private final JTextField m_winddir = new JTextField(); // wind direction - - private final JTextField m_sky = new JTextField(); // sky setting - - // only for ISO: - private final JCheckBox m_no_magic = new JCheckBox(); - - private final JCheckBox m_no_priest = new JCheckBox(); - - private final JCheckBox m_no_summon = new JCheckBox(); - - private final JCheckBox m_no_harm = new JCheckBox(); - - private final JCheckBox m_fixed_login = new JCheckBox(); - - private final JCheckBox m_perm_death = new JCheckBox(); - - private final JCheckBox m_ultra_death = new JCheckBox(); - - private final JCheckBox m_ultimate_death = new JCheckBox(); - - private final JCheckBox m_pvp = new JCheckBox(); - - private static final long serialVersionUID = 1L; - - /** - * Constructs the map-options dialog. - * @param mainControl The controller of this dialog. - * @param parentFrame The parent frame of this dialog. - * @param level The level whose properties are shown/edited. - */ - CMapPropertiesDialog(final CMainControl mainControl, final Frame parentFrame, final MapControl level) { - // set title - super(parentFrame, "" + level.getMapNameWithoutMusic() + " - Map Properties"); - final MapArchObject map = level.getMapModel().getMapArchObject(); // map arch object - - this.mainControl = mainControl; // main control - m_level = level; // map control - - getContentPane().setLayout(new BorderLayout()); - - // main panel (gridbag) - final GridBagLayout gridbag = new GridBagLayout(); - final GridBagConstraints c = new GridBagConstraints(); - final JPanel mainPanel = new JPanel(gridbag); - //mainPanel.setLayout(new CardLayout()); - mainPanel.setBorder(new EmptyBorder( - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS)); - - // 1. map panel: - final JPanel mapPanel = new JPanel(new GridLayout(0, 1)); - mapPanel.setBorder( - new CompoundBorder( - new TitledBorder(new EtchedBorder(), "Map"), - new EmptyBorder( - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS))); - - createPanelLine(mapPanel, m_nameField, 16, m_level.getMapName(), "Name: "); - createPanelLine(mapPanel, m_regionField, 16, map.getMapRegion(), "Region: "); - final Size2D mapSize = m_level.getMapSize(); - createPanelLine(mapPanel, m_levelWidthField, 10, String.valueOf(mapSize.getWidth()), "Width: "); - createPanelLine(mapPanel, m_levelHeightField, 10, String.valueOf(mapSize.getHeight()), "Height: "); - createPanelCBox(mapPanel, m_unique, map.isUnique(), " Unique Map"); - createPanelCBox(mapPanel, m_outdoor, map.isOutdoor(), " Outdoor Map"); - createPanelCBox(mapPanel, m_fixedReset, map.isFixedReset(), " Fixed Reset"); - createPanelCBox(mapPanel, m_nosmooth, map.isNosmooth(), " Nosmooth Map"); - - // set constraints - c.fill = GridBagConstraints.BOTH; - c.weightx = 1.0; - c.weighty = 1.0; - gridbag.setConstraints(mapPanel, c); - mainPanel.add(mapPanel); - - // 2. options panel: - final JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP); - tabPane.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 0)); - - final JPanel optionPanel = new JPanel(new GridLayout(1, 1)); - final JPanel optionPanel2 = new JPanel(); - optionPanel2.setLayout(new BoxLayout(optionPanel2, BoxLayout.Y_AXIS)); - final JScrollPane scrollPane2 = new JScrollPane(optionPanel2); - scrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - scrollPane2.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - - createPanelLine(optionPanel2, m_enterX, 10, String.valueOf(map.getEnterX()), "Enter X: "); - createPanelLine(optionPanel2, m_enterY, 10, String.valueOf(map.getEnterY()), "Enter Y: "); - createPanelLine(optionPanel2, m_difficulty, 10, String.valueOf(map.getDifficulty()), "Difficulty: "); - createPanelLine(optionPanel2, m_darkness, 10, String.valueOf(map.getDarkness()), "Darkness: "); - createPanelLine(optionPanel2, m_swapTime, 10, String.valueOf(map.getSwapTime()), "Swap Time: "); - createPanelLine(optionPanel2, m_resetTimeout, 10, String.valueOf(map.getResetTimeout()), "Reset Timeout: "); - - createPanelLine(optionPanel2, m_shopitems, 10, map.getShopItems(), "Shop Type: "); - createPanelLine(optionPanel2, m_shopgreed, 10, String.valueOf(map.getShopGreed()), "Shop Greed: "); - createPanelLine(optionPanel2, m_shopmax, 10, String.valueOf(map.getShopMax()), "Upper Price Limit: "); - createPanelLine(optionPanel2, m_shopmin, 10, String.valueOf(map.getShopMin()), "Lower Price Limit: "); - createPanelLine(optionPanel2, m_shoprace, 10, map.getShopRace(), "Shop Race: "); - - createPanelLine(optionPanel2, m_temp, 10, String.valueOf(map.getTemp()), "Temperature: "); - createPanelLine(optionPanel2, m_pressure, 10, String.valueOf(map.getPressure()), "Pressure: "); - createPanelLine(optionPanel2, m_humid, 10, String.valueOf(map.getHumid()), "Humidity: "); - createPanelLine(optionPanel2, m_windspeed, 10, String.valueOf(map.getWindspeed()), "Wind Speed: "); - createPanelLine(optionPanel2, m_winddir, 10, String.valueOf(map.getWinddir()), "Wind Direction: "); - createPanelLine(optionPanel2, m_sky, 10, String.valueOf(map.getSky()), "Sky Setting: "); - - optionPanel.add(scrollPane2); - - optionPanel.setPreferredSize(new Dimension(240, 185)); - - // set constraints - c.weightx = 1.0; - c.weighty = 1.0; - c.gridwidth = GridBagConstraints.REMAINDER; //end row - m_loreArea = new JTextArea(); - gridbag.setConstraints(tabPane, c); - - tabPane.addTab("Options", optionPanel); - m_loreArea.setText(m_level.getMapLore()); - m_loreArea.setCaretPosition(0); - m_loreArea.setBorder(BorderFactory.createEmptyBorder(1, 4, 0, 0)); - final JScrollPane lscrollPane = new JScrollPane(m_loreArea); - lscrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - lscrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - lscrollPane.setPreferredSize(new Dimension(20, 20)); - - tabPane.addTab("Lore", lscrollPane); - mainPanel.add(tabPane); - - // 3. map text panel: - final JPanel mapDataPanel = new JPanel(new BorderLayout(1, 1)); - mapDataPanel.setBorder( - new CompoundBorder( - new TitledBorder(new EtchedBorder(), "Map Text"), - new EmptyBorder( - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS))); - - final JPanel labelPanel = new JPanel(new BorderLayout(1, 1)); - m_textArea = new JTextArea(4, 4); - m_textArea.setText(m_level.getMapText()); - m_textArea.setCaretPosition(0); - m_textArea.setBorder(BorderFactory.createEmptyBorder(1, 4, 0, 0)); - final JScrollPane scrollPane = new JScrollPane(m_textArea); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - - labelPanel.add(scrollPane, BorderLayout.CENTER); - mapDataPanel.add(labelPanel); - - // set constraints - c.weightx = 1.0; - c.weighty = 1.0; - c.gridwidth = GridBagConstraints.RELATIVE; - gridbag.setConstraints(mapDataPanel, c); - mainPanel.add(mapDataPanel); - - // 4. map tiling panel: - final JPanel tilePathPanel = new JPanel(new GridLayout(IGUIConstants.DIRECTIONS, 2)); - tilePathPanel.setBorder( - new CompoundBorder( - new TitledBorder(new EtchedBorder(), "Paths for Map-Tiling"), - new EmptyBorder( - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS, - IGUIConstants.DIALOG_INSETS))); - - createPanelLine(tilePathPanel, m_tilePath[0] = new JTextField(), 16, map.getTilePath(0), "North: "); - createPanelLine(tilePathPanel, m_tilePath[1] = new JTextField(), 16, map.getTilePath(1), "East: "); - createPanelLine(tilePathPanel, m_tilePath[2] = new JTextField(), 16, map.getTilePath(2), "South: "); - createPanelLine(tilePathPanel, m_tilePath[3] = new JTextField(), 16, map.getTilePath(3), "West: "); - createPanelLine(tilePathPanel, m_tilePath[4] = new JTextField(), 16, map.getTilePath(4), "Top: "); - createPanelLine(tilePathPanel, m_tilePath[5] = new JTextField(), 16, map.getTilePath(5), "Bottom: "); - - // set constraints - c.weightx = 1.0; - c.weighty = 1.0; - gridbag.setConstraints(tilePathPanel, c); - mainPanel.add(tilePathPanel); - - getContentPane().add(mainPanel, BorderLayout.CENTER); - - // build the button panel - final JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BorderLayout()); - buttonPanel.add(Box.createGlue()); - final JPanel left_buttons = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JPanel right_buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - - // Help button - JButton button = new JButton("Help"); - button.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // open the help window - new Help(mainControl.getMainView(), "tut_mapattr.html").setVisible(true); - } - }); - left_buttons.add(button); - - // OK button - button = new JButton("OK"); - button.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // try to apply changes, then kill window - if (modifyMapProperties()) { - dispose(); - } - } - }); - right_buttons.add(button); - - // Restore Button - button = new JButton("Restore"); - button.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // restore to saved values from maparch - restoreMapProperties(); - } - }); - right_buttons.add(button); - - // Cancel Button - button = new JButton("Cancel"); - button.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // kill window - dispose(); - } - }); - right_buttons.add(button); - - buttonPanel.add(left_buttons, BorderLayout.WEST); - buttonPanel.add(right_buttons, BorderLayout.EAST); - - getContentPane().add(buttonPanel, BorderLayout.SOUTH); - - setBounds(this.mainControl.getMainView().getX() + (this.mainControl.getMainView().getWidth() - 545) / 2, - this.mainControl.getMainView().getY() + (this.mainControl.getMainView().getHeight() - 480) / 2, - 545, 480); - pack(); - setVisible(true); - } - - /** - * create an "attribute"-line (format: <label> <textfield>) and insert it - * into the given parent layout - * @param parent parent panel where line gets inserted - * @param textField textfield - * @param n lenght of textfield - * @param defaultText initial text in textfield - * @param label (attribute-)label - */ - void createPanelLine(final JPanel parent, final JTextField textField, final int n, - final String defaultText, final String label) { - final JPanel lineLayout = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // layout for this line - lineLayout.add(new JLabel(label)); // create label (attr. name) - //textField = new JTextField(n); // create text field - textField.setColumns(n); - textField.setText(defaultText); // insert default text - lineLayout.add(textField); // add textf. to line - parent.add(lineLayout); // add line to parent layout - } - - /** - * create a checkbox-line and insert it into the given parent layout. - * similar to createPanelLine - * @param parent parent panel where checkbox gets inserted - * @param checkBox checkbox - * @param state initial state - * @param label (attribute-)label - */ - void createPanelCBox(final JPanel parent, final JCheckBox checkBox, - final boolean state, final String label) { - final JPanel lineLayout = new JPanel(new FlowLayout(FlowLayout.CENTER)); // layout for this line - //checkBox = new JCheckBox(label); // create checkbox - checkBox.setText(label); - checkBox.setSelected(state); // set to current state - lineLayout.add(checkBox); // add checkbox to line - parent.add(lineLayout); // add line to parent layout - } - - /** - * Checks the given values and modifies the current level. - * @return true if the level properties were edited, false if the - * parameters were wrong. - */ - private boolean modifyMapProperties() { - final MapArchObject map = m_level.getMapModel().getMapArchObject(); // map arch object - boolean modifyTilepaths = false; // true when map tile-paths were modified - - // tmp variables for parsing - final int width, height; - final int t_enter_x, t_enter_y; - final int t_reset_timeout, t_swap_time; - final int t_difficulty, t_darkness; - final int t_temp, t_pressure, t_humid; - final int t_winds, t_windd, t_sky; - final double t_shopgreed; - final int t_shopmax, t_shopmin; - final String t_shopitems, t_shoprace; - final String t_region; - - // first check if the entries are all okay - try { - // try to parse everything - width = parseProperty(m_levelWidthField.getText(), "Width"); - height = parseProperty(m_levelHeightField.getText(), "Height"); - t_enter_x = parseProperty(m_enterX.getText(), "Enter X"); - t_enter_y = parseProperty(m_enterY.getText(), "Enter Y"); - t_swap_time = parseProperty(m_swapTime.getText(), "Swap Time"); - t_reset_timeout = parseProperty(m_resetTimeout.getText(), "Reset Timeout"); - t_difficulty = parseProperty(m_difficulty.getText(), "Difficulty"); - t_darkness = parseProperty(m_darkness.getText(), "Darkness"); - t_region = m_regionField.getText(); - - t_shopitems = m_shopitems.getText(); - t_shoprace = m_shoprace.getText(); - t_shopmax = parseProperty(m_shopmax.getText(), "Shop Maximum"); - t_shopmin = parseProperty(m_shopmin.getText(), "Shop Minimum"); - t_shopgreed = parsePropertyToDouble(m_shopgreed.getText(), "Shop Greed"); - t_temp = parseProperty(m_temp.getText(), "Temperature"); - t_pressure = parseProperty(m_pressure.getText(), "Pressure"); - t_humid = parseProperty(m_humid.getText(), "Humidity"); - t_winds = parseProperty(m_windspeed.getText(), "Wind Speed"); - t_windd = parseProperty(m_winddir.getText(), "Wind Direction"); - t_sky = parseProperty(m_sky.getText(), "Sky Setting"); - - // Now do some sanity checks: - if (width < 1 || height < 1) { - mainControl.showMessage( - "Illegal Value", - "Level dimensions must be greater than zero."); - return false; - } - if (t_darkness > 5) { - mainControl.showMessage( - "Illegal Value", - "Darkness level must be in range 0-5."); - return false; - } - if (m_nameField.getText().length() == 0) { - mainControl.showMessage( - "missing Map Name", - "You must specify a Map Name."); - return false; - } - } catch (final GridderException e) { - mainControl.showMessage("Invalid Entry", e.getMessage()); - return false; - } - - // if the mapsize has been modified, see if we should ask for a confirm - Size2D size = new Size2D(width, height); - if (!m_level.isCutoffSave(size)) { - if (!askConfirmResize(size)) { - // resizing has been cancelled - size = m_level.getMapSize(); - } - } - - // now that all is well, write the new values into the maparch - mainControl.setLevelProperties(m_level, m_textArea.getText(), m_loreArea.getText(), - m_nameField.getText(), size); - - map.setMapRegion(t_region); - map.setEnterX(t_enter_x); - map.setEnterY(t_enter_y); - map.setResetTimeout(t_reset_timeout); - map.setSwapTime(t_swap_time); - map.setDifficulty(t_difficulty); - map.setDarkness(t_darkness); - map.setUnique(m_unique.isSelected()); - map.setOutdoor(m_outdoor.isSelected()); - map.setFixedReset(m_fixedReset.isSelected()); - map.setNosmooth(m_nosmooth.isSelected()); - - map.setShopItems(t_shopitems); - map.setShopRace(t_shoprace); - map.setShopMin(t_shopmin); - map.setShopMax(t_shopmax); - map.setShopGreed(t_shopgreed); - - map.setTemp(t_temp); - map.setPressure(t_pressure); - map.setHumid(t_humid); - map.setWindspeed(t_winds); - map.setWinddir(t_windd); - map.setSky(t_sky); - - // update tilepaths - for (int i = 0; i < IGUIConstants.DIRECTIONS; i++) { - if ((map.getTilePath(i) == null && (m_tilePath[i].getText() == null || m_tilePath[i].getText().length() == 0)) - || (map.getTilePath(i) != null && !map.getTilePath(i).equals(m_tilePath[i].getText()))) { - modifyTilepaths = true; - } - map.setTilePath(i, m_tilePath[i].getText()); - } - - // refresh menus if tilepaths have been modified - if (modifyTilepaths) { - mainControl.refreshMenus(); - } - - // set flag that map has changed - m_level.setLevelChangedFlag(); - - return true; - } - - /** - * This is a simple string-to-int parser that throws CGridder- instead of - * NumberFormatExceptions, with appropriate errormessage. Used in - * modifyMapProperties(). - * @param s string to be parse - * @param label attribute label for errormessage - * @return value of String 's', zero if 's' is empty - * @throws GridderException when parsing fails - */ - private int parseProperty(final String s, final String label) throws GridderException { - final int r; // return value - - if (s.length() == 0) { - return 0; // empty string is interpreted as zero - } - - try { - r = Integer.parseInt(s); // trying to parse - } catch (final NumberFormatException illegalNumbers) { - // 's' is not a number - throw new GridderException(label + ": '" + s + "' is not a numerical integer value."); - } - - // negative values are not allowed - if (r < 0) { - throw new GridderException(label + ": '" + s + "' is negative."); - } - - return r; // everything okay - } - - /** - * This is a simple string-to-double parser that throws CGridder- instead - * of NumberFormatExceptions, with appropriate errormessage. Used in - * modifyMapProperties(). - * @param s string to be parse - * @param label attribute label for errormessage - * @return value of String 's', zero if 's' is empty - * @throws GridderException when parsing fails - */ - private double parsePropertyToDouble(final String s, final String label) throws GridderException { - final double r; // return value - - if (s.length() == 0) { - return 0; // empty string is interpreted as zero - } - - try { - r = Double.parseDouble(s); // trying to parse - } catch (final NumberFormatException illegalNumbers) { - // 's' is not a number - throw new GridderException(label + ": '" + s + "' is not a numerical double value."); - } - - // negative values are not allowed - if (r < 0) { - throw new GridderException(label + ": '" + s + "' is negative."); - } - - return r; // everything okay - } - - /** Reset all map properties to the saved values in the maparch */ - private void restoreMapProperties() { - final MapArchObject map = m_level.getMapModel().getMapArchObject(); // map arch object - - m_level.getMapModel().getMapArchObject().getText(); - m_textArea.setText(m_level.getMapText()); - m_loreArea.setText(m_level.getMapLore()); - m_nameField.setText(m_level.getMapName()); - m_regionField.setText("" + map.getMapRegion()); - final Size2D mapSize = map.getMapSize(); - m_levelWidthField.setText(String.valueOf(mapSize.getWidth())); - m_levelHeightField.setText(String.valueOf(mapSize.getHeight())); - m_enterX.setText("" + map.getEnterX()); - m_enterY.setText("" + map.getEnterY()); - m_swapTime.setText("" + map.getSwapTime()); - m_resetTimeout.setText("" + map.getResetTimeout()); - m_darkness.setText("" + map.getDarkness()); - m_difficulty.setText("" + map.getDifficulty()); - - m_unique.setSelected(map.isUnique()); - m_outdoor.setSelected(map.isOutdoor()); - m_fixedReset.setSelected(map.isFixedReset()); - m_nosmooth.setSelected(map.isNosmooth()); - - m_shopitems.setText("" + map.getShopItems()); - m_shoprace.setText("" + map.getShopRace()); - m_shopmax.setText("" + map.getShopMax()); - m_shopmin.setText("" + map.getShopMin()); - m_shopgreed.setText("" + map.getShopGreed()); - m_temp.setText("" + map.getTemp()); - m_pressure.setText("" + map.getPressure()); - m_humid.setText("" + map.getHumid()); - m_windspeed.setText("" + map.getWindspeed()); - m_winddir.setText("" + map.getWinddir()); - m_sky.setText("" + map.getSky()); - - for (int i = 0; i < 4; i++) { - m_tilePath[i].setText("" + map.getTilePath(i)); - } - } - - /** - * Open a popup and ask user to confirm his map-resizing selection. This - * popup dialog disables all other windows (and threads). - * @return true if user confirmed, false if user cancelled resize - */ - private boolean askConfirmResize(final Size2D size) { - return JOptionPane.showConfirmDialog(this, - "You selected a new map size of " + size.getWidth() + "x" + size.getHeight() + ". If the map was\n" + - "resized in this way, some objects would get cut off and deleted.\n" + - "Are you really sure you want this?", - "Confirm", - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE) - == JOptionPane.YES_OPTION; - } - -} // class CMapPropertiesDialog Added: trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2006-12-02 10:50:19 UTC (rev 784) @@ -0,0 +1,665 @@ +/* + * 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.map; + +import cfeditor.CDialogBase; +import cfeditor.CMainControl; +import cfeditor.GridderException; +import cfeditor.IGUIConstants; +import cfeditor.map.MapArchObject; +import cfeditor.map.MapControl; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JViewport; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import net.sf.gridarta.Size2D; +import net.sf.gridarta.help.Help; + +/** + * Dialog used to ask the user the properties for the new level. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class MapPropertiesDialog extends CDialogBase { + + public static final String CENTER_MAP_KEY = "MapProperties.centerMapOnResize"; + + private final CMainControl mainControl; + + private final MapControl m_level; + + // input components, see MapArchObject for expl. of purpose + private final JTextArea m_textArea; // the msg text/arch text + + private final JTextArea m_loreArea; // the lore text + + private final JTextField m_nameField = new JTextField(); // name of arch + + private final JTextField m_regionField = new JTextField(); // map's region + + private final JTextField m_levelWidthField = new JTextField(); // len x + + private final JTextField m_levelHeightField = new JTextField(); // len y + + private final JCheckBox m_unique = new JCheckBox(); // map unique + + private final JCheckBox m_outdoor = new JCheckBox(); // map outdoor + + private final JCheckBox m_fixedReset = new JCheckBox(); // fixed reset + + private final JCheckBox m_nosmooth = new JCheckBox(); // map nosmooth + + private final JTextField m_enterX = new JTextField(); // enter x + + private final JTextField m_enterY = new JTextField(); // enter y + + private final JTextField m_swapTime = new JTextField(); // swap time + + private final JTextField m_resetTimeout = new JTextField(); // reset timeout + + private final JTextField m_difficulty = new JTextField(); // map difficulty + + private final JTextField m_darkness = new JTextField(); // darkness + + private final JTextField[] m_tilePath = new JTextField[IGUIConstants.DIRECTIONS]; // tile paths + + // only for CF: + private final JTextField m_shopitems = new JTextField(); // shopitems + + private final JTextField m_shopgreed = new JTextField(); // shopgreed + + private final JTextField m_shopmax = new JTextField(); // shop maximum price + + private final JTextField m_shopmin = new JTextField(); // shop minimum price + + private final JTextField m_shoprace = new JTextField(); // shop's preferred race + + private final JTextField m_temp = new JTextField(); // temperature + + private final JTextField m_pressure = new JTextField(); // pressure + + private final JTextField m_humid = new JTextField(); // humidity + + private final JTextField m_windspeed = new JTextField(); // wind speed + + private final JTextField m_winddir = new JTextField(); // wind direction + + private final JTextField m_sky = new JTextField(); // sky setting + + // only for ISO: + private final JCheckBox m_no_magic = new JCheckBox(); + + private final JCheckBox m_no_priest = new JCheckBox(); + + private final JCheckBox m_no_summon = new JCheckBox(); + + private final JCheckBox m_no_harm = new JCheckBox(); + + private final JCheckBox m_fixed_login = new JCheckBox(); + + private final JCheckBox m_perm_death = new JCheckBox(); + + private final JCheckBox m_ultra_death = new JCheckBox(); + + private final JCheckBox m_ultimate_death = new JCheckBox(); + + private final JCheckBox m_pvp = new JCheckBox(); + + private static final long serialVersionUID = 1L; + + /** + * Constructs the map-options dialog. + * @param mainControl The controller of this dialog. + * @param parentFrame The parent frame of this dialog. + * @param level The level whose properties are shown/edited. + */ + public MapPropertiesDialog(final CMainControl mainControl, final Frame parentFrame, final MapControl level) { + // set title + super(parentFrame, "" + level.getMapNameWithoutMusic() + " - Map Properties"); + final MapArchObject map = level.getMapModel().getMapArchObject(); // map arch object + + this.mainControl = mainControl; // main control + m_level = level; // map control + + getContentPane().setLayout(new BorderLayout()); + + // main panel (gridbag) + final GridBagLayout gridbag = new GridBagLayout(); + final GridBagConstraints c = new GridBagConstraints(); + final JPanel mainPanel = new JPanel(gridbag); + //mainPanel.setLayout(new CardLayout()); + mainPanel.setBorder(new EmptyBorder( + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS)); + + // 1. map panel: + final JPanel mapPanel = new JPanel(new GridLayout(0, 1)); + mapPanel.setBorder( + new CompoundBorder( + new TitledBorder(new EtchedBorder(), "Map"), + new EmptyBorder( + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS))); + + createPanelLine(mapPanel, m_nameField, 16, m_level.getMapName(), "Name: "); + createPanelLine(mapPanel, m_regionField, 16, map.getMapRegion(), "Region: "); + final Size2D mapSize = m_level.getMapSize(); + createPanelLine(mapPanel, m_levelWidthField, 10, String.valueOf(mapSize.getWidth()), "Width: "); + createPanelLine(mapPanel, m_levelHeightField, 10, String.valueOf(mapSize.getHeight()), "Height: "); + createPanelCBox(mapPanel, m_unique, map.isUnique(), " Unique Map"); + createPanelCBox(mapPanel, m_outdoor, map.isOutdoor(), " Outdoor Map"); + createPanelCBox(mapPanel, m_fixedReset, map.isFixedReset(), " Fixed Reset"); + createPanelCBox(mapPanel, m_nosmooth, map.isNosmooth(), " Nosmooth Map"); + + // set constraints + c.fill = GridBagConstraints.BOTH; + c.weightx = 1.0; + c.weighty = 1.0; + gridbag.setConstraints(mapPanel, c); + mainPanel.add(mapPanel); + + // 2. options panel: + final JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP); + tabPane.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 0)); + + final JPanel optionPanel = new JPanel(new GridLayout(1, 1)); + final JPanel optionPanel2 = new JPanel(); + optionPanel2.setLayout(new BoxLayout(optionPanel2, BoxLayout.Y_AXIS)); + final JScrollPane scrollPane2 = new JScrollPane(optionPanel2); + scrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane2.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + + createPanelLine(optionPanel2, m_enterX, 10, String.valueOf(map.getEnterX()), "Enter X: "); + createPanelLine(optionPanel2, m_enterY, 10, String.valueOf(map.getEnterY()), "Enter Y: "); + createPanelLine(optionPanel2, m_difficulty, 10, String.valueOf(map.getDifficulty()), "Difficulty: "); + createPanelLine(optionPanel2, m_darkness, 10, String.valueOf(map.getDarkness()), "Darkness: "); + createPanelLine(optionPanel2, m_swapTime, 10, String.valueOf(map.getSwapTime()), "Swap Time: "); + createPanelLine(optionPanel2, m_resetTimeout, 10, String.valueOf(map.getResetTimeout()), "Reset Timeout: "); + + createPanelLine(optionPanel2, m_shopitems, 10, map.getShopItems(), "Shop Type: "); + createPanelLine(optionPanel2, m_shopgreed, 10, String.valueOf(map.getShopGreed()), "Shop Greed: "); + createPanelLine(optionPanel2, m_shopmax, 10, String.valueOf(map.getShopMax()), "Upper Price Limit: "); + createPanelLine(optionPanel2, m_shopmin, 10, String.valueOf(map.getShopMin()), "Lower Price Limit: "); + createPanelLine(optionPanel2, m_shoprace, 10, map.getShopRace(), "Shop Race: "); + + createPanelLine(optionPanel2, m_temp, 10, String.valueOf(map.getTemp()), "Temperature: "); + createPanelLine(optionPanel2, m_pressure, 10, String.valueOf(map.getPressure()), "Pressure: "); + createPanelLine(optionPanel2, m_humid, 10, String.valueOf(map.getHumid()), "Humidity: "); + createPanelLine(optionPanel2, m_windspeed, 10, String.valueOf(map.getWindspeed()), "Wind Speed: "); + createPanelLine(optionPanel2, m_winddir, 10, String.valueOf(map.getWinddir()), "Wind Direction: "); + createPanelLine(optionPanel2, m_sky, 10, String.valueOf(map.getSky()), "Sky Setting: "); + + optionPanel.add(scrollPane2); + + optionPanel.setPreferredSize(new Dimension(240, 185)); + + // set constraints + c.weightx = 1.0; + c.weighty = 1.0; + c.gridwidth = GridBagConstraints.REMAINDER; //end row + m_loreArea = new JTextArea(); + gridbag.setConstraints(tabPane, c); + + tabPane.addTab("Options", optionPanel); + m_loreArea.setText(m_level.getMapLore()); + m_loreArea.setCaretPosition(0); + m_loreArea.setBorder(BorderFactory.createEmptyBorder(1, 4, 0, 0)); + final JScrollPane lscrollPane = new JScrollPane(m_loreArea); + lscrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + lscrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + lscrollPane.setPreferredSize(new Dimension(20, 20)); + + tabPane.addTab("Lore", lscrollPane); + mainPanel.add(tabPane); + + // 3. map text panel: + final JPanel mapDataPanel = new JPanel(new BorderLayout(1, 1)); + mapDataPanel.setBorder( + new CompoundBorder( + new TitledBorder(new EtchedBorder(), "Map Text"), + new EmptyBorder( + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS))); + + final JPanel labelPanel = new JPanel(new BorderLayout(1, 1)); + m_textArea = new JTextArea(4, 4); + m_textArea.setText(m_level.getMapText()); + m_textArea.setCaretPosition(0); + m_textArea.setBorder(BorderFactory.createEmptyBorder(1, 4, 0, 0)); + final JScrollPane scrollPane = new JScrollPane(m_textArea); + scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + labelPanel.add(scrollPane, BorderLayout.CENTER); + mapDataPanel.add(labelPanel); + + // set constraints + c.weightx = 1.0; + c.weighty = 1.0; + c.gridwidth = GridBagConstraints.RELATIVE; + gridbag.setConstraints(mapDataPanel, c); + mainPanel.add(mapDataPanel); + + // 4. map tiling panel: + final JPanel tilePathPanel = new JPanel(new GridLayout(IGUIConstants.DIRECTIONS, 2)); + tilePathPanel.setBorder( + new CompoundBorder( + new TitledBorder(new EtchedBorder(), "Paths for Map-Tiling"), + new EmptyBorder( + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS, + IGUIConstants.DIALOG_INSETS))); + + createPanelLine(tilePathPanel, m_tilePath[0] = new JTextField(), 16, map.getTilePath(0), "North: "); + createPanelLine(tilePathPanel, m_tilePath[1] = new JTextField(), 16, map.getTilePath(1), "East: "); + createPanelLine(tilePathPanel, m_tilePath[2] = new JTextField(), 16, map.getTilePath(2), "South: "); + createPanelLine(tilePathPanel, m_tilePath[3] = new JTextField(), 16, map.getTilePath(3), "West: "); + createPanelLine(tilePathPanel, m_tilePath[4] = new JTextField(), 16, map.getTilePath(4), "Top: "); + createPanelLine(tilePathPanel, m_tilePath[5] = new JTextField(), 16, map.getTilePath(5), "Bottom: "); + + // set constraints + c.weightx = 1.0; + c.weighty = 1.0; + gridbag.setConstraints(tilePathPanel, c); + mainPanel.add(tilePathPanel); + + getContentPane().add(mainPanel, BorderLayout.CENTER); + + // build the button panel + final JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BorderLayout()); + buttonPanel.add(Box.createGlue()); + final JPanel left_buttons = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JPanel right_buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + + // Help button + JButton button = new JButton("Help"); + button.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + // open the help window + new Help(mainControl.getMainView(), "tut_mapattr.html").setVisible(true); + } + }); + left_buttons.add(button); + + // OK button + button = new JButton("OK"); + button.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + // try to apply changes, then kill window + if (modifyMapProperties()) { + dispose(); + } + } + }); + right_buttons.add(button); + + // Restore Button + button = new JButton("Restore"); + button.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + // restore to saved values from maparch + restoreMapProperties(); + } + }); + right_buttons.add(button); + + // Cancel Button + button = new JButton("Cancel"); + button.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + // kill window + dispose(); + } + }); + right_buttons.add(button); + + buttonPanel.add(left_buttons, BorderLayout.WEST); + buttonPanel.add(right_buttons, BorderLayout.EAST); + + getContentPane().add(buttonPanel, BorderLayout.SOUTH); + + setBounds(this.mainControl.getMainView().getX() + (this.mainControl.getMainView().getWidth() - 545) / 2, + this.mainControl.getMainView().getY() + (this.mainControl.getMainView().getHeight() - 480) / 2, + 545, 480); + pack(); + setVisible(true); + } + + /** + * create an "attribute"-line (format: <label> <textfield>) and insert it + * into the given parent layout + * @param parent parent panel where line gets inserted + * @param textField textfield + * @param n lenght of textfield + * @param defaultText initial text in textfield + * @param label (attribute-)label + */ + void createPanelLine(final JPanel parent, final JTextField textField, final int n, + final String defaultText, final String label) { + final JPanel lineLayout = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // layout for this line + lineLayout.add(new JLabel(label)); // create label (attr. name) + //textField = new JTextField(n); // create text field + textField.setColumns(n); + textField.setText(defaultText); // insert default text + lineLayout.add(textField); // add textf. to line + parent.add(lineLayout); // add line to parent layout + } + + /** + * create a checkbox-line and insert it into the given parent layout. + * similar to createPanelLine + * @param parent parent panel where checkbox gets inserted + * @param checkBox checkbox + * @param state initial state + * @param label (attribute-)label + */ + void createPanelCBox(final JPanel parent, final JCheckBox checkBox, + final boolean state, final String label) { + final JPanel lineLayout = new JPanel(new FlowLayout(FlowLayout.CENTER)); // layout for this line + //checkBox = new JCheckBox(label); // create checkbox + checkBox.setText(label); + checkBox.setSelected(state); // set to current state + lineLayout.add(checkBox); // add checkbox to line + parent.add(lineLayout); // add line to parent layout + } + + /** + * Checks the given values and modifies the current level. + * @return true if the level properties were edited, false if the + * parameters were wrong. + */ + private boolean modifyMapProperties() { + final MapArchObject map = m_level.getMapModel().getMapArchObject(); // map arch object + boolean modifyTilepaths = false; // true when map tile-paths were modified + + // tmp variables for parsing + final int width, height; + final int t_enter_x, t_enter_y; + final int t_reset_timeout, t_swap_time; + final int t_difficulty, t_darkness; + final int t_temp, t_pressure, t_humid; + final int t_winds, t_windd, t_sky; + final double t_shopgreed; + final int t_shopmax, t_shopmin; + final String t_shopitems, t_shoprace; + final String t_region; + + // first check if the entries are all okay + try { + // try to parse everything + width = parseProperty(m_levelWidthField.getText(), "Width"); + height = parseProperty(m_levelHeightField.getText(), "Height"); + t_enter_x = parseProperty(m_enterX.getText(), "Enter X"); + t_enter_y = parseProperty(m_enterY.getText(), "Enter Y"); + t_swap_time = parseProperty(m_swapTime.getText(), "Swap Time"); + t_reset_timeout = parseProperty(m_resetTimeout.getText(), "Reset Timeout"); + t_difficulty = parseProperty(m_difficulty.getText(), "Difficulty"); + t_darkness = parseProperty(m_darkness.getText(), "Darkness"); + t_region = m_regionField.getText(); + + t_shopitems = m_shopitems.getText(); + t_shoprace = m_shoprace.getText(); + t_shopmax = parseProperty(m_shopmax.getText(), "Shop Maximum"); + t_shopmin = parseProperty(m_shopmin.getText(), "Shop Minimum"); + t_shopgreed = parsePropertyToDouble(m_shopgreed.getText(), "Shop Greed"); + t_temp = parseProperty(m_temp.getText(), "Temperature"); + t_pressure = parseProperty(m_pressure.getText(), "Pressure"); + t_humid = parseProperty(m_humid.getText(), "Humidity"); + t_winds = parseProperty(m_windspeed.getText(), "Wind Speed"); + t_windd = parseProperty(m_winddir.getText(), "Wind Direction"); + t_sky = parseProperty(m_sky.getText(), "Sky Setting"); + + // Now do some sanity checks: + if (width < 1 || height < 1) { + mainControl.showMessage( + "Illegal Value", + "Level dimensions must be greater than zero."); + return false; + } + if (t_darkness > 5) { + mainControl.showMessage( + "Illegal Value", + "Darkness level must be in range 0-5."); + return false; + } + if (m_nameField.getText().length() == 0) { + mainControl.showMessage( + "missing Map Name", + "You must specify a Map Name."); + return false; + } + } catch (final GridderException e) { + mainControl.showMessage("Invalid Entry", e.getMessage()); + return false; + } + + // if the mapsize has been modified, see if we should ask for a confirm + Size2D size = new Size2D(width, height); + if (!m_level.isCutoffSave(size)) { + if (!askConfirmResize(size)) { + // resizing has been cancelled + size = m_level.getMapSize(); + } + } + + // now that all is well, write the new values into the maparch + mainControl.setLevelProperties(m_level, m_textArea.getText(), m_loreArea.getText(), + m_nameField.getText(), size); + + map.setMapRegion(t_region); + map.setEnterX(t_enter_x); + map.setEnterY(t_enter_y); + map.setResetTimeout(t_reset_timeout); + map.setSwapTime(t_swap_time); + map.setDifficulty(t_difficulty); + map.setDarkness(t_darkness); + map.setUnique(m_unique.isSelected()); + map.setOutdoor(m_outdoor.isSelected()); + map.setFixedReset(m_fixedReset.isSelected()); + map.setNosmooth(m_nosmooth.isSelected()); + + map.setShopItems(t_shopitems); + map.setShopRace(t_shoprace); + map.setShopMin(t_shopmin); + map.setShopMax(t_shopmax); + map.setShopGreed(t_shopgreed); + + map.setTemp(t_temp); + map.setPressure(t_pressure); + map.setHumid(t_humid); + map.setWindspeed(t_winds); + map.setWinddir(t_windd); + map.setSky(t_sky); + + // update tilepaths + for (int i = 0; i < IGUIConstants.DIRECTIONS; i++) { + if ((map.getTilePath(i) == null && (m_tilePath[i].getText() == null || m_tilePath[i].getText().length() == 0)) + || (map.getTilePath(i) != null && !map.getTilePath(i).equals(m_tilePath[i].getText()))) { + modifyTilepaths = true; + } + map.setTilePath(i, m_tilePath[i].getText()); + } + + // refresh menus if tilepaths have been modified + if (modifyTilepaths) { + mainControl.refreshMenus(); + } + + // set flag that map has changed + m_level.setLevelChangedFlag(); + + return true; + } + + /** + * This is a simple string-to-int parser that throws CGridder- instead of + * NumberFormatExceptions, with appropriate errormessage. Used in + * modifyMapProperties(). + * @param s string to be parse + * @param label attribute label for errormessage + * @return value of String 's', zero if 's' is empty + * @throws GridderException when parsing fails + */ + private int parseProperty(final String s, final String label) throws GridderException { + final int r; // return value + + if (s.length() == 0) { + return 0; // empty string is interpreted as zero + } + + try { + r = Integer.parseInt(s); // trying to parse + } catch (final NumberFormatException illegalNumbers) { + // 's' is not a number + throw new GridderException(label + ": '" + s + "' is not a numerical integer value."); + } + + // negative values are not allowed + if (r < 0) { + throw new GridderException(label + ": '" + s + "' is negative."); + } + + return r; // everything okay + } + + /** + * This is a simple string-to-double parser that throws CGridder- instead + * of NumberFormatExceptions, with appropriate errormessage. Used in + * modifyMapProperties(). + * @param s string to be parse + * @param label attribute label for errormessage + * @return value of String 's', zero if 's' is empty + * @throws GridderException when parsing fails + */ + private double parsePropertyToDouble(final String s, final String label) throws GridderException { + final double r; // return value + + if (s.length() == 0) { + return 0; // empty string is interpreted as zero + } + + try { + r = Double.parseDouble(s); // trying to parse + } catch (final NumberFormatException illegalNumbers) { + // 's' is not a number + throw new GridderException(label + ": '" + s + "' is not a numerical double value."); + } + + // negative values are not allowed + if (r < 0) { + throw new GridderException(label + ": '" + s + "' is negative."); + } + + return r; // everything okay + } + + /** Reset all map properties to the saved values in the maparch */ + private void restoreMapProperties() { + final MapArchObject map = m_level.getMapModel().getMapArchObject(); // map arch object + + m_level.getMapModel().getMapArchObject().getText(); + m_textArea.setText(m_level.getMapText()); + m_loreArea.setText(m_level.getMapLore()); + m_nameField.setText(m_level.getMapName()); + m_regionField.setText("" + map.getMapRegion()); + final Size2D mapSize = map.getMapSize(); + m_levelWidthField.setText(String.valueOf(mapSize.getWidth())); + m_levelHeightField.setText(String.valueOf(mapSize.getHeight())); + m_enterX.setText("" + map.getEnterX()); + m_enterY.setText("" + map.getEnterY()); + m_swapTime.setText("" + map.getSwapTime()); + m_resetTimeout.setText("" + map.getResetTimeout()); + m_darkness.setText("" + map.getDarkness()); + m_difficulty.setText("" + map.getDifficulty()); + + m_unique.setSelected(map.isUnique()); + m_outdoor.setSelected(map.isOutdoor()); + m_fixedReset.setSelected(map.isFixedReset()); + m_nosmooth.setSelected(map.isNosmooth()); + + m_shopitems.setText("" + map.getShopItems()); + m_shoprace.setText("" + map.getShopRace()); + m_shopmax.setText("" + map.getShopMax()); + m_shopmin.setText("" + map.getShopMin()); + m_shopgreed.setText("" + map.getShopGreed()); + m_temp.setText("" + map.getTemp()); + m_pressure.setText("" + map.getPressure()); + m_humid.setText("" + map.getHumid()); + m_windspeed.setText("" + map.getWindspeed()); + m_winddir.setText("" + map.getWinddir()); + m_sky.setText("" + map.getSky()); + + for (int i = 0; i < 4; i++) { + m_tilePath[i].setText("" + map.getTilePath(i)); + } + } + + /** + * Open a popup and ask user to confirm his map-resizing selection. This + * popup dialog disables all other windows (and threads). + * @return true if user confirmed, false if user cancelled resize + */ + private boolean askConfirmResize(final Size2D size) { + return JOptionPane.showConfirmDialog(this, + "You selected a new map size of " + size.getWidth() + "x" + size.getHeight() + ". If the map was\n" + + "resized in this way, some objects would get cut off and deleted.\n" + + "Are... [truncated message content] |
From: <aki...@us...> - 2006-12-02 11:42:16
|
Revision: 787 http://svn.sourceforge.net/gridarta/?rev=787&view=rev Author: akirschbaum Date: 2006-12-02 03:42:16 -0800 (Sat, 02 Dec 2006) Log Message: ----------- Make functions to retrieve fixed icons static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapTileList.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-02 11:35:36 UTC (rev 786) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-02 11:42:16 UTC (rev 787) @@ -115,25 +115,25 @@ private AnimationObjects animationObjects; // icons for the map and arch pictures . X= rectangle, normal = iso - private ImageIcon mapSelIcon; + private static ImageIcon mapSelIcon; - private ImageIcon mapGridIcon; + private static ImageIcon mapGridIcon; - private ImageIcon unknownTileIcon; + private static ImageIcon unknownTileIcon; - private ImageIcon nofaceTileIcon; + private static ImageIcon nofaceTileIcon; - private ImageIcon mapSelIconX; + private static ImageIcon mapSelIconX; - private ImageIcon mapGridIconX; + private static ImageIcon mapGridIconX; - private ImageIcon unknownTileIconX; + private static ImageIcon unknownTileIconX; - private ImageIcon nofaceTileIconX; + private static ImageIcon nofaceTileIconX; - private ImageIcon noarchTileIcon; + private static ImageIcon noarchTileIcon; - private ImageIcon noarchTileIconX; + private static ImageIcon noarchTileIconX; private final ArchetypeSet archetypeSet; // the one and only arch list @@ -1630,43 +1630,43 @@ return mapGridIcon; } - public ImageIcon getUnknownTileIcon() { + public static ImageIcon getUnknownTileIcon() { return unknownTileIconX; } - public ImageIcon getUnknownTileIconX() { + public static ImageIcon getUnknownTileIconX() { return unknownTileIconX; } - public ImageIcon getNoarchTileIcon() { + public static ImageIcon getNoarchTileIcon() { return noarchTileIconX; } - public ImageIcon getNoarchTileIconF() { + public static ImageIcon getNoarchTileIconF() { return noarchTileIcon; } - public ImageIcon getNoarchTileIconX() { + public static ImageIcon getNoarchTileIconX() { return noarchTileIconX; } - public ImageIcon getNofaceTileIcon() { + public static ImageIcon getNofaceTileIcon() { return nofaceTileIconX; } - public ImageIcon getNofaceTileIconF() { + public static ImageIcon getNofaceTileIconF() { return nofaceTileIcon; } - public ImageIcon getNofaceTileIconX() { + public static ImageIcon getNofaceTileIconX() { return nofaceTileIconX; } - public ImageIcon getMapSelIconF() { + public static ImageIcon getMapSelIconF() { return mapSelIcon; } - public ImageIcon getMapSelIconX() { + public static ImageIcon getMapSelIconX() { return mapSelIconX; } @@ -1674,7 +1674,7 @@ * Load all system tile icons into temporare variables for more convenient * access. */ - private void loadDefTiles() { + private static void loadDefTiles() { mapGridIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_IGRID_TILE); mapSelIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_ISEL_TILE); unknownTileIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_IUNKNOWN); @@ -1731,7 +1731,7 @@ return scriptControl; } - public ImageIcon getEmptyTileIcon() { + public static ImageIcon getEmptyTileIcon() { return nofaceTileIconX; } Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-02 11:35:36 UTC (rev 786) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-02 11:42:16 UTC (rev 787) @@ -410,7 +410,7 @@ // We must set a disabled Icon (even though we don't want it) // If unset, in JDK 1.4 swing tries to generate a greyed out version // of the lable-icon from the image-producer - causing a runtime error. - setDisabledIcon(mainControl.getUnknownTileIcon()); + setDisabledIcon(CMainControl.getUnknownTileIcon()); // arch == null should not happen, but it *can* happen when the active // window gets changed by user and java is still blitting here @@ -422,11 +422,11 @@ } if (gameObject.getArchetypeName() == null) { - setIcon(mainControl.getNoarchTileIcon()); + setIcon(CMainControl.getNoarchTileIcon()); } else if (gameObject.getFaceFlag()) { - setIcon(mainControl.getNofaceTileIcon()); + setIcon(CMainControl.getNofaceTileIcon()); } else if (gameObject.getFaceNr() == -1) { - setIcon(mainControl.getUnknownTileIcon()); + setIcon(CMainControl.getUnknownTileIcon()); } else { setIcon(mainControl.getFace(gameObject.getFaceNr())); } @@ -450,7 +450,7 @@ } } } else { - setIcon(mainControl.getUnknownTileIcon()); + setIcon(CMainControl.getUnknownTileIcon()); setText("?"); } setBorder(BorderFactory.createEmptyBorder(0, Math.max(0, indent - 1) * 16, 0, 0)); // indentation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |