[Picross-commit] SF.net SVN: picross: [49] trunk/src/picross
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-17 09:38:05
|
Revision: 49 http://picross.svn.sourceforge.net/picross/?rev=49&view=rev Author: yvan_norsa Date: 2008-04-17 02:38:09 -0700 (Thu, 17 Apr 2008) Log Message: ----------- exception when an image is missing Modified Paths: -------------- trunk/src/picross/Picross.java trunk/src/picross/app/MainMenuAppUI.java trunk/src/picross/applet/MainMenuAppletUI.java trunk/src/picross/grid/Box.java trunk/src/picross/menus/GameMenuMediator.java trunk/src/picross/menus/GameMenuUI.java trunk/src/picross/menus/MainMenuUI.java trunk/src/picross/menus/MenuUI.java trunk/src/picross/tests/PicrossTest.java Added Paths: ----------- trunk/src/picross/MissingImageException.java Added: trunk/src/picross/MissingImageException.java =================================================================== --- trunk/src/picross/MissingImageException.java (rev 0) +++ trunk/src/picross/MissingImageException.java 2008-04-17 09:38:09 UTC (rev 49) @@ -0,0 +1,58 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross; + +/** + * Exception thrown when an image file is not found. + * + * @author Y. Norsa + */ +public class MissingImageException extends RuntimeException { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 7805399363197308654L; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param cause parent exception + */ + MissingImageException(Throwable cause) { + super(cause); + } +} + Property changes on: trunk/src/picross/MissingImageException.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/Picross.java 2008-04-17 09:38:09 UTC (rev 49) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -97,12 +97,14 @@ * * @param path path of the image * @return the image - * @throws FileNotFoundException if the file can't be found + * @throws MissingImageException if the image file can't be found */ - private static ImageIcon loadImage(String path) - throws FileNotFoundException { - - return new ImageIcon(Picross.getFile(path)); + private static ImageIcon loadImage(String path) { + try { + return new ImageIcon(Picross.getFile(path)); + } catch (FileNotFoundException fileEx) { + throw new MissingImageException(fileEx); + } } /** @@ -112,10 +114,10 @@ * @return the image * @throws IllegalArgumentException if <code>name</code> * is <code>null</code> or empty - * @throws FileNotFoundException if the file can't be found + * @throws MissingImageException if the image file can't be found */ public static ImageIcon getImage(String name) - throws IllegalArgumentException, FileNotFoundException { + throws IllegalArgumentException { if (name == null || name.equals("")) { throw new IllegalArgumentException("name can't be null or empty"); @@ -131,10 +133,10 @@ * @return the image * @throws IllegalArgumentException if <code>name</code> * is <code>null</code> or empty - * @throws FileNotFoundException if the file can't be found + * @throws MissingImageException if the image file can't be found */ public static ImageIcon getLocalizedImage(String name) - throws IllegalArgumentException, FileNotFoundException { + throws IllegalArgumentException { if (name == null || name.equals("")) { throw new IllegalArgumentException("name can't be null or empty"); Modified: trunk/src/picross/app/MainMenuAppUI.java =================================================================== --- trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 09:38:09 UTC (rev 49) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -77,11 +77,9 @@ * Constructor. * * @param controller controller for the buttons - * @throws FileNotFoundException if a button image can't be found + * @throws MissingImageException if a button image can't be found */ - public MainMenuAppUI(ActionListener controller) - throws FileNotFoundException { - + public MainMenuAppUI(ActionListener controller) { super(controller); this.addButton(MainMenuAppUI.EXIT_BUTTON_IMAGE, Modified: trunk/src/picross/applet/MainMenuAppletUI.java =================================================================== --- trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-17 09:38:09 UTC (rev 49) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -64,11 +64,9 @@ * Constructor. * * @param controller controller for the buttons - * @throws FileNotFoundException if a button image can't be found + * @throws MissingImageException if a button image can't be found */ - public MainMenuAppletUI(ActionListener controller) - throws FileNotFoundException { - + public MainMenuAppletUI(ActionListener controller) { super(controller); this.setBackground(Color.WHITE); Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/grid/Box.java 2008-04-17 09:38:09 UTC (rev 49) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -35,14 +35,13 @@ import java.awt.Rectangle; -import java.io.FileNotFoundException; - import java.util.HashMap; import java.util.Map; import java.util.Random; import javax.swing.ImageIcon; +import picross.MissingImageException; import picross.Picross; //import org.apache.log4j.Logger; @@ -128,8 +127,8 @@ Box.images.put(state, img); } - } catch (FileNotFoundException fileEx) { - throw new ExceptionInInitializerError(fileEx); + } catch (MissingImageException imageEx) { + throw new ExceptionInInitializerError(imageEx); } } Modified: trunk/src/picross/menus/GameMenuMediator.java =================================================================== --- trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 09:38:09 UTC (rev 49) @@ -48,6 +48,7 @@ public class GameMenuMediator extends Mediateur { /*** Field ***/ + /** View of the menu. */ private GameMenuUI view; /*** Constructor ***/ @@ -59,11 +60,7 @@ GameMenuController controller = new GameMenuController(); controller.addSimpleListener(this); - try { - this.view = new GameMenuUI(controller); - } catch (FileNotFoundException fileEx) { - throw new PicrossException(fileEx); - } + this.view = new GameMenuUI(controller); } /*** Method overloaded from the Mediateur class ***/ Modified: trunk/src/picross/menus/GameMenuUI.java =================================================================== --- trunk/src/picross/menus/GameMenuUI.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/menus/GameMenuUI.java 2008-04-17 09:38:09 UTC (rev 49) @@ -54,8 +54,11 @@ /** * Constructor. + * + * @param listener listener for the button + * @throws MissingImageException if a button image can't be found */ - GameMenuUI(ActionListener listener) throws FileNotFoundException { + GameMenuUI(ActionListener listener) { this.addButton("button-random.png", PicrossController.RANDOM_GAME_CMD, listener, 150, 225); } Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/menus/MainMenuUI.java 2008-04-17 09:38:09 UTC (rev 49) @@ -68,9 +68,9 @@ * Constructor. * * @param controller controller for the buttons - * @throws FileNotFoundException if a button image can't be found + * @throws MissingImageException if a button image can't be found */ - public MainMenuUI(ActionListener controller) throws FileNotFoundException { + public MainMenuUI(ActionListener controller) { super(); this.addButton(MainMenuUI.PLAY_BUTTON_IMAGE, Modified: trunk/src/picross/menus/MenuUI.java =================================================================== --- trunk/src/picross/menus/MenuUI.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/menus/MenuUI.java 2008-04-17 09:38:09 UTC (rev 49) @@ -45,6 +45,9 @@ import javax.swing.JButton; import javax.swing.JPanel; +import org.apache.log4j.Logger; + +import picross.MissingImageException; import picross.Picross; /** @@ -53,11 +56,22 @@ * @author Y. Norsa */ abstract class MenuUI extends JPanel { - /*** Constant ***/ + /*** Constants ***/ /** Background image. */ private static final String BACKGROUND_IMAGE = "background.png"; + /** Default width to be used if the background file can't be found. */ + private static final int DEFAULT_WIDTH = 450; + + /** Default height to be used if the background file can't be found. */ + private static final int DEFAULT_HEIGHT = 375; + + /*** Static field ***/ + + /** This class' logger. */ + private static Logger log = Logger.getLogger(MenuUI.class); + /*** Field ***/ /** Background image. */ @@ -65,16 +79,18 @@ /*** Constructor ***/ - /** - * Constructor. - * - * @throws FileNotFoundException if the background image can't be found - */ - MenuUI() throws FileNotFoundException { - ImageIcon icon = Picross.getImage(MenuUI.BACKGROUND_IMAGE); - this.setPreferredSize(new Dimension(icon.getIconWidth(), - icon.getIconHeight())); - this.image = icon.getImage(); + /** Constructor. */ + MenuUI() { + try { + ImageIcon icon = Picross.getImage(MenuUI.BACKGROUND_IMAGE); + this.setPreferredSize(new Dimension(icon.getIconWidth(), + icon.getIconHeight())); + this.image = icon.getImage(); + } catch (MissingImageException imageEx) { + MenuUI.log.info(imageEx.getMessage()); + this.setPreferredSize(new Dimension(MenuUI.DEFAULT_WIDTH, + MenuUI.DEFAULT_HEIGHT)); + } this.setLayout(null); } @@ -98,12 +114,10 @@ * @param controller listener for the button * @param x x position for the button * @param y y position for the button - * @throws FileNotFoundException if a button image can't be found + * @throws MissingImageException if a button image can't be found */ protected void addButton(String image, String command, - ActionListener controller, int x, int y) - throws FileNotFoundException { - + ActionListener controller, int x, int y) { ImageIcon buttonIcon = Picross.getLocalizedImage(image); JButton button = new JButton(buttonIcon); button.setActionCommand(command); Modified: trunk/src/picross/tests/PicrossTest.java =================================================================== --- trunk/src/picross/tests/PicrossTest.java 2008-04-17 09:11:28 UTC (rev 48) +++ trunk/src/picross/tests/PicrossTest.java 2008-04-17 09:38:09 UTC (rev 49) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -42,6 +42,7 @@ import org.junit.Assert; import org.junit.Test; +import picross.MissingImageException; import picross.Picross; /** @@ -74,10 +75,10 @@ /** * Tests the method getImage(). * - * @throws FileNotFoundException if a file loading fails. + * @throws MissingImageException if a file loading fails. */ @Test - public void testGetImage() throws FileNotFoundException { + public void testGetImage() { try { Picross.getImage(null); Assert.fail("name = null"); @@ -91,7 +92,7 @@ try { Picross.getImage("fakeFile"); Assert.fail("Fake file"); - } catch (FileNotFoundException fileEx) { } + } catch (MissingImageException imageEx) { } ImageIcon icon = Picross.getImage("empty.png"); PicrossTest.testIcon(icon, 25, 25); @@ -100,10 +101,10 @@ /** * Tests the method getLocalizedImage(). * - * @throws FileNotFoundException if a file loading fails. + * @throws MissingImageException if a file loading fails. */ @Test - public void getLocalizedImage() throws FileNotFoundException { + public void getLocalizedImage() { try { Picross.getLocalizedImage(null); Assert.fail("name = null"); @@ -117,7 +118,7 @@ try { Picross.getImage("fakeFile"); Assert.fail("Fake file"); - } catch (FileNotFoundException fileEx) { } + } catch (MissingImageException imageEx) { } ImageIcon icon = Picross.getLocalizedImage("button-play.png"); PicrossTest.testIcon(icon, 150, 50); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |