| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.comic; |
| 17 | |
| 18 | /** |
| 19 | * A sheet containig 1 or 2 images, depending on the size of the images: if an image is wider than |
| 20 | * high, a sheet can contain only 1 image.<p> |
| 21 | * |
| 22 | * Sheets are used to render a the ComicView in two page mode. ComicImages are referred to by their |
| 23 | * index in the ComicViews internal ComicView[]. |
| 24 | * |
| 25 | * @author Thomas Aglassinger |
| 26 | */ |
| 27 | public class ComicSheet |
| 28 | { |
| 29 | /** |
| 30 | * Value to indicat that no image is assigned. |
| 31 | */ |
| 32 | public static final int NO_IMAGE = -1; |
| 33 | private int leftImageIndex; |
| 34 | private int page; |
| 35 | private int rightImage; |
| 36 | |
| 37 | /** |
| 38 | * Create a sheet holding a single image. Use <code>setRightImageIndex()</code> to add an |
| 39 | * image. |
| 40 | * |
| 41 | * @see #setRightImageIndex(int) |
| 42 | * @param newPage page number of the left ComicImage |
| 43 | * @param newLeftImageIndex index of the ComicImage that describes this page |
| 44 | */ |
| 45 | public ComicSheet(int newPage, int newLeftImageIndex) { |
| 46 | this(newPage, newLeftImageIndex, NO_IMAGE); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Create a sheet holding a single image. Use <code>setRightImageIndex()</code> to add an |
| 51 | * image. |
| 52 | * |
| 53 | * @param newPage page number of the left ComicImage |
| 54 | * @param newLeftImageIndex index of the ComicImage that describes this page |
| 55 | * @param newRightImageIndex Description of the parameter |
| 56 | */ |
| 57 | public ComicSheet(int newPage, int newLeftImageIndex, int newRightImageIndex) { |
| 58 | assert newPage >= 0; |
| 59 | assert newLeftImageIndex >= 0; |
| 60 | assert (newRightImageIndex == NO_IMAGE) || (newRightImageIndex == newLeftImageIndex + 1) |
| 61 | : "newRightImageIndex must be NO_IMAGE or " + (newLeftImageIndex + 1) + " but is " + newRightImageIndex; |
| 62 | page = newPage; |
| 63 | leftImageIndex = newLeftImageIndex; |
| 64 | rightImage = newRightImageIndex; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void setRightImageIndex(int newRightImageIndex) { |
| 69 | assert !hasRightImage(); |
| 70 | assert newRightImageIndex == (leftImageIndex + 1) |
| 71 | : "left=" + leftImageIndex + ", newRight=" + newRightImageIndex; |
| 72 | rightImage = newRightImageIndex; |
| 73 | } |
| 74 | |
| 75 | public int getLeftImageIndex() { |
| 76 | return leftImageIndex; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get the page to which the left image refers to. |
| 81 | */ |
| 82 | public int getPage() { |
| 83 | return page; |
| 84 | } |
| 85 | |
| 86 | public int getRightImageIndex() { |
| 87 | assert hasRightImage(); |
| 88 | return getRightImageIndexOrNoImage(); |
| 89 | } |
| 90 | |
| 91 | public int getRightImageIndexOrNoImage() { |
| 92 | return rightImage; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Does the sheet have a second image? |
| 97 | */ |
| 98 | public boolean hasRightImage() { |
| 99 | return rightImage != NO_IMAGE; |
| 100 | } |
| 101 | |
| 102 | public String toString() { |
| 103 | String result = "ComicSheet[page=" + getPage() + ", left=" + getLeftImageIndex(); |
| 104 | |
| 105 | if (hasRightImage()) { |
| 106 | result += ", right=" + getRightImageIndex(); |
| 107 | } |
| 108 | result += "]"; |
| 109 | return result; |
| 110 | } |
| 111 | } |