From: <chr...@us...> - 2006-05-25 19:24:38
|
Revision: 13 Author: christianhujer Date: 2006-05-25 12:24:27 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/gridarta/?rev=13&view=rev Log Message: ----------- Minor refactorings. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AnimationObject.java trunk/crossfire/src/cfeditor/CFancyButton.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainToolbar.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/ExitTypes.java trunk/crossfire/src/cfeditor/JarResources.java Modified: trunk/crossfire/src/cfeditor/AnimationObject.java =================================================================== --- trunk/crossfire/src/cfeditor/AnimationObject.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/AnimationObject.java 2006-05-25 19:24:27 UTC (rev 13) @@ -2,6 +2,7 @@ * 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) * @@ -24,7 +25,8 @@ package cfeditor; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Map; /** * The <code>AnimationObject</code> @@ -40,24 +42,19 @@ // The hash tables hold the name and the index for the field // if one can show me, that storing and accessing names AND objects // in the table is faster than in the static arrays, we can change this - private static final Hashtable animHashTable = new Hashtable(); + private final Map<String,Integer> animHashTable = new HashMap<String,Integer>(); private int animObjCount; - private final CMainControl m_control; - - public AnimationObject(CMainControl control) { - m_control = control; + public AnimationObject() { animObjCount = 0; } - public void addAnimObject(String name, String list) { - animObjects[animObjCount] = new AnimObjectNode(); - animObjects[animObjCount].animName = new String(name); - animObjects[animObjCount].animList = new String(list); - nameTable[animObjCount] = new String(name); - animHashTable.put(name, new Integer(animObjCount)); // put it in list + public void addAnimObject(final String name, final String list) { + animObjects[animObjCount] = new AnimObjectNode(name, list); + nameTable[animObjCount] = name; + animHashTable.put(name, animObjCount); // put it in list animObjCount++; } @@ -66,7 +63,7 @@ return nameTable; } - public String getNameString(int i) { + public String getNameString(final int i) { return nameTable[i]; } @@ -74,26 +71,27 @@ return animObjCount; } - public String getAnimObjectList(int i) { + public String getAnimObjectList(final int i) { return animObjects[i].animList; } - public String getAnimObjectName(int i) { + public String getAnimObjectName(final int i) { return animObjects[i].animName; } - public int findAnimObject(String name) { - Integer num = (Integer)animHashTable.get(name); - return num.intValue(); + public int findAnimObject(final String name) { + return animHashTable.get(name); } -} // End of class -class AnimObjectNode { - String animName; - String animList; // A List of "\n" connected strings - public AnimObjectNode () { - animName = null; - animList = null; - } + private static class AnimObjectNode { + private final String animName; + private final String animList; // A List of "\n" connected strings + + AnimObjectNode (final String animName, final String animList) { + this.animList = animList; + this.animName = animName; + } + } // End of class + } // End of class Modified: trunk/crossfire/src/cfeditor/CFancyButton.java =================================================================== --- trunk/crossfire/src/cfeditor/CFancyButton.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/CFancyButton.java 2006-05-25 19:24:27 UTC (rev 13) @@ -26,152 +26,72 @@ import java.awt.Insets; import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.UIManager; -/** - * <code>CFancyButton</code> implements fancy button that has a cool rollover - * effect enabled under Windows l'n'f. +/** A JButton subclass. * * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @deprecated Don't use this anymore. */ public class CFancyButton extends JButton { - private ImageIcon m_normalIcon; - private ImageIcon m_rolloverIcon; - private boolean m_fMouseOver = false; - private boolean m_fWindowsLNF = false; + private ImageIcon normalIcon; + private ImageIcon rolloverIcon; private static final long serialVersionUID = -6830925679283342190L; - static MouseListener mStatic_rolloverListener = new MouseListener() { - public void mouseClicked(MouseEvent event) { - } - - public void mousePressed(MouseEvent event) { - } - - public void mouseReleased(MouseEvent event) { - } - - public void mouseEntered(MouseEvent event) { - CFancyButton button = (CFancyButton)event.getSource(); - button.m_fMouseOver = true; - - if (button.m_rolloverIcon != null) { - button.setIcon(button.m_rolloverIcon); - } - - if (button.m_fWindowsLNF) { - button.setBorderPainted(button.isEnabled()); - } - } - - public void mouseExited(MouseEvent event) { - CFancyButton button = (CFancyButton)event.getSource(); - - button.m_fMouseOver = false; - - if (button.m_normalIcon != null) { - button.setIcon(button.m_normalIcon); - } - - if (button.m_fWindowsLNF) { - button.setBorderPainted(false); - } - } - }; - - public CFancyButton(String strLabel, ActionListener actionListener) { + public CFancyButton(final String strLabel, final ActionListener actionListener) { this(strLabel, null, null, actionListener); } - public CFancyButton( - String strLabel, - String strToolTip, - ActionListener actionListener) { - this(strLabel, strToolTip, null, actionListener); + public CFancyButton(final String label, final String toolTip, final ActionListener actionListener) { + this(label, toolTip, null, actionListener); } - public CFancyButton( - String strLabel, - String strToolTip, - String strIcon, - ActionListener actionListener) { - super(strLabel); - if (strToolTip != null) { - setToolTipText(strToolTip); + public CFancyButton(final String label, final String toolTip, final String icon, final ActionListener actionListener) { + super(label); + if (toolTip != null) { + setToolTipText(toolTip); } - - if (strIcon != null) { - m_rolloverIcon = CGUIUtils.getIcon(strIcon); - setFancyIcon(m_rolloverIcon); + if (icon != null) { + rolloverIcon = CGUIUtils.getIcon(icon); + setFancyIcon(rolloverIcon); } - if (actionListener != null) { addActionListener(actionListener); } else { setEnabled(false); } - - Insets insets = getInsets(); - insets.top = 2; - insets.left = insets.top; - insets.right = insets.top; - insets.bottom = insets.top; - this.setMargin(insets); - - m_fWindowsLNF = UIManager.getLookAndFeel().getID().compareToIgnoreCase("Windows") == 0; - - addMouseListener(mStatic_rolloverListener); - - if (m_fWindowsLNF) { - setBorderPainted(m_fMouseOver); - } + setMargin(new Insets(2, 2, 2, 2)); } /** * Sets the fancy icon (automatically calculates the grayscaled normal icon) * @param icon the icon to be used as the rollover icon. */ - public void setFancyIcon(ImageIcon icon) { - m_rolloverIcon = icon; - - if (m_rolloverIcon != null) { - m_normalIcon = CGUIUtils.getGrayScaled(m_rolloverIcon); + public void setFancyIcon(final ImageIcon icon) { + rolloverIcon = icon; + if (rolloverIcon != null) { + normalIcon = CGUIUtils.getGrayScaled(rolloverIcon); } else { - m_normalIcon = null; + normalIcon = null; } - - super.setIcon(m_normalIcon); + super.setIcon(normalIcon); } /** * Preserve rollover icons over UI changes. */ - public void updateUI() { + @Override public void updateUI() { super.updateUI(); - - m_fWindowsLNF = UIManager.getLookAndFeel().getID().compareToIgnoreCase("Windows") == 0; - - if (m_fWindowsLNF) { - setBorderPainted(m_fMouseOver); - } else { - setBorderPainted(true); - } - - if (m_fMouseOver) { - setIcon(m_rolloverIcon); - } else { - setIcon(m_normalIcon); - } + setBorderPainted(true); + setIcon(normalIcon); } - public void setEnabled(boolean fEnabled) { + @Override public void setEnabled(final boolean fEnabled) { super.setEnabled(fEnabled); - setRolloverIcon(m_rolloverIcon); - setIcon(m_normalIcon); + setRolloverIcon(rolloverIcon); + setIcon(normalIcon); } -} + +} // class CFancyButton Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-05-25 19:24:27 UTC (rev 13) @@ -233,7 +233,7 @@ // our global object parser archObjectParser = new ArchObjectParser(this); - animationObject = new AnimationObject(this); + animationObject = new AnimationObject(); // read in the type & type field definitions archObjectParser.loadTypeNumbers(); Modified: trunk/crossfire/src/cfeditor/CMainToolbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-05-25 19:24:27 UTC (rev 13) @@ -140,8 +140,8 @@ m_control.newLevelWanted(); } }); - m_new.setVerticalTextPosition(CFancyButton.BOTTOM); - m_new.setHorizontalTextPosition(CFancyButton.CENTER); + m_new.setVerticalTextPosition(JButton.BOTTOM); + m_new.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_new); add(m_new); @@ -154,8 +154,8 @@ m_control.openFileWanted(); } }); - m_open.setVerticalTextPosition(CFancyButton.BOTTOM); - m_open.setHorizontalTextPosition(CFancyButton.CENTER); + m_open.setVerticalTextPosition(JButton.BOTTOM); + m_open.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_open); add(m_open); @@ -168,8 +168,8 @@ m_control.saveCurrentLevelWanted(); } }); - m_save.setVerticalTextPosition(CFancyButton.BOTTOM); - m_save.setHorizontalTextPosition(CFancyButton.CENTER); + m_save.setVerticalTextPosition(JButton.BOTTOM); + m_save.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_save); add(m_save); @@ -182,8 +182,8 @@ m_control.saveCurrentLevelAsWanted(); } }); - m_saveAs.setVerticalTextPosition(CFancyButton.BOTTOM); - m_saveAs.setHorizontalTextPosition(CFancyButton.CENTER); + m_saveAs.setVerticalTextPosition(JButton.BOTTOM); + m_saveAs.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_saveAs); add(m_saveAs); @@ -198,8 +198,8 @@ m_control.undoWanted(); } }); - m_undo.setVerticalTextPosition(CFancyButton.BOTTOM); - m_undo.setHorizontalTextPosition(CFancyButton.CENTER); + m_undo.setVerticalTextPosition(JButton.BOTTOM); + m_undo.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_undo); add(m_undo); @@ -212,8 +212,8 @@ m_control.redoWanted(); } }); - m_redo.setVerticalTextPosition(CFancyButton.BOTTOM); - m_redo.setHorizontalTextPosition(CFancyButton.CENTER); + m_redo.setVerticalTextPosition(JButton.BOTTOM); + m_redo.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_redo); add(m_redo); @@ -228,8 +228,8 @@ m_control.previousWindowWanted(); } }); - m_prevWindow.setVerticalTextPosition(CFancyButton.BOTTOM); - m_prevWindow.setHorizontalTextPosition(CFancyButton.CENTER); + m_prevWindow.setVerticalTextPosition(JButton.BOTTOM); + m_prevWindow.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_prevWindow); add(m_prevWindow); @@ -242,8 +242,8 @@ m_control.nextWindowWanted(); } }); - m_nextWindow.setVerticalTextPosition(CFancyButton.BOTTOM); - m_nextWindow.setHorizontalTextPosition(CFancyButton.CENTER); + m_nextWindow.setVerticalTextPosition(JButton.BOTTOM); + m_nextWindow.setHorizontalTextPosition(JButton.CENTER); buttons.addElement(m_nextWindow); add(m_nextWindow); Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-05-25 19:24:27 UTC (rev 13) @@ -38,10 +38,13 @@ import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; +import javax.swing.JButton; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JViewport; +import static javax.swing.JViewport.SIMPLE_SCROLL_MODE; +import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; +import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -87,7 +90,7 @@ m_list.setBackground(Color.lightGray); scrollPane = new JScrollPane(m_list); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + scrollPane.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); add(scrollPane, BorderLayout.CENTER); JPanel dummy = new JPanel(); @@ -95,9 +98,9 @@ dummy.setLayout(new GridLayout(2, 1)); } JScrollPane scrollPane2 = new JScrollPane(dummy); - scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); - scrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane2.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + scrollPane2.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER); + scrollPane2.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); + scrollPane2.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); if (!m_view.isMapTileListBottom()) { add(scrollPane2, BorderLayout.SOUTH); // put up/down buttons south } else { @@ -112,8 +115,8 @@ m_control.moveTileDown(getMapTileSelection(), true); } }); - buttonDown.setVerticalTextPosition(CFancyButton.BOTTOM); - buttonDown.setHorizontalTextPosition(CFancyButton.CENTER); + buttonDown.setVerticalTextPosition(JButton.BOTTOM); + buttonDown.setHorizontalTextPosition(JButton.CENTER); if (!m_view.isMapTileListBottom()) { dummy.add(buttonDown, BorderLayout.EAST); } @@ -125,8 +128,8 @@ m_control.moveTileUp(getMapTileSelection(), true); } }); - buttonUp.setVerticalTextPosition(CFancyButton.BOTTOM); - buttonUp.setHorizontalTextPosition(CFancyButton.CENTER); + buttonUp.setVerticalTextPosition(JButton.BOTTOM); + buttonUp.setHorizontalTextPosition(JButton.CENTER); if (!m_view.isMapTileListBottom()) { dummy.add(buttonUp, BorderLayout.WEST); } else { Modified: trunk/crossfire/src/cfeditor/ExitTypes.java =================================================================== --- trunk/crossfire/src/cfeditor/ExitTypes.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/ExitTypes.java 2006-05-25 19:24:27 UTC (rev 13) @@ -3,19 +3,21 @@ package cfeditor; import java.util.HashSet; +import java.util.Set; -/** +/** Contains a list of all types that are exits. * @author Andreas Kirschbaum + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class ExitTypes -{ +public class ExitTypes { + /** List of exit object types. (Integer values) */ - private static final HashSet _exitTypes = new HashSet(); + private static final Set<Integer> EXIT_TYPES = new HashSet<Integer>(); static { - _exitTypes.add(new Integer(41)); // teleporter - _exitTypes.add(new Integer(66)); // exit - _exitTypes.add(new Integer(94)); // pit - _exitTypes.add(new Integer(95)); // trapdoor + EXIT_TYPES.add(41); // teleporter + EXIT_TYPES.add(66); // exit + EXIT_TYPES.add(94); // pit + EXIT_TYPES.add(95); // trapdoor } // Prevent instantiation. @@ -26,8 +28,10 @@ * Determine whether a given ArchObject is an "exit". */ public static boolean contains(final ArchObject exit) { - if (exit == null) throw new IllegalArgumentException(); + if (exit == null) { + throw new IllegalArgumentException(); + } + return EXIT_TYPES.contains(exit.getArchTypNr()); + } - return _exitTypes.contains(new Integer(exit.getArchTypNr())); - } -} +} // class ExitTypes Modified: trunk/crossfire/src/cfeditor/JarResources.java =================================================================== --- trunk/crossfire/src/cfeditor/JarResources.java 2006-05-25 18:09:23 UTC (rev 12) +++ trunk/crossfire/src/cfeditor/JarResources.java 2006-05-25 19:24:27 UTC (rev 13) @@ -55,9 +55,6 @@ private static final Logger log = Logger.getLogger(JarResources.class); - // external debug flag - private boolean debugOn = false; - // jar resource mapping tables private final Hashtable htSizes = new Hashtable(); private final Hashtable htJarContents = new Hashtable(); @@ -128,7 +125,7 @@ FileInputStream fis = new FileInputStream(jarFileName); BufferedInputStream bis = new BufferedInputStream(fis); ZipInputStream zis = new ZipInputStream(bis); - ZipEntry ze = null; + ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { if (ze.isDirectory()) { continue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |