Fixed bug where 0 byte pictures were treated incorrectly.
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / metadata / Dimension.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.meviz.htmlindexer.metadata;
11
12 import java.io.Serializable;
13
14 /**
15  * Corresponds to single image dimensions.
16  */
17
18 public class Dimension implements Serializable, Comparable<Dimension> {
19
20         private static final long serialVersionUID = -1039288266937331829L;
21
22         public int width;
23         public int height;
24
25         public Dimension() {
26                 width = 0;
27                 height = 0;
28         }
29
30         public Dimension(final Dimension origial) {
31                 width = origial.width;
32                 height = origial.height;
33         }
34
35         public Dimension(final int width, final int height) {
36                 this.width = width;
37                 this.height = height;
38         }
39
40         @Override
41         public int compareTo(final Dimension anotherDimension) {
42                 if (width < anotherDimension.width)
43                         return -1;
44                 if (width > anotherDimension.width)
45                         return 1;
46
47                 if (height < anotherDimension.height)
48                         return -1;
49                 if (height > anotherDimension.height)
50                         return 1;
51
52                 return 0;
53         }
54
55         public boolean equals(final Dimension anotherDimension) {
56                 if (compareTo(anotherDimension) == 0)
57                         return true;
58                 return false;
59         }
60
61         public int getArea() {
62                 return width * height;
63         }
64
65         public java.awt.Dimension getAwtDimension() {
66                 return new java.awt.Dimension(width, height);
67         }
68
69         public Dimension getScaled(final double multiplicationFactor) {
70                 final Dimension result = new Dimension();
71
72                 result.width = (int) ((width) * multiplicationFactor);
73                 result.height = (int) ((height) * multiplicationFactor);
74
75                 return result;
76         }
77
78         @Override
79         public String toString() {
80                 return "Dimension [width=" + width + ", height=" + height + "]";
81         }
82
83 }