Crossfire JXClient, Trunk  R20561
Resolution.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient 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 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient 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 JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.util;
23 
24 import java.awt.Dimension;
25 import java.awt.DisplayMode;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
35 public class Resolution {
36 
40  private final int width;
41 
45  private final int height;
46 
52  public Resolution(final int width, final int height) {
53  this.width = width;
54  this.height = height;
55  }
56 
65  @Nullable
66  public static Resolution parse(@NotNull final String str) {
67  final String[] tmp = str.split("x", -1);
68  if (tmp.length != 2) {
69  return null;
70  }
71  final int width;
72  final int height;
73  try {
74  width = Integer.parseInt(tmp[0]);
75  height = Integer.parseInt(tmp[1]);
76  } catch (final NumberFormatException ignored) {
77  return null;
78  }
79 
80  return new Resolution(width, height);
81  }
82 
87  public int getWidth() {
88  return width;
89  }
90 
95  public int getHeight() {
96  return height;
97  }
98 
105  public boolean equalsDisplayMode(@NotNull final DisplayMode displayMode) {
106  return width == displayMode.getWidth() && height == displayMode.getHeight();
107  }
108 
112  @Override
113  public boolean equals(@Nullable final Object obj) {
114  if (obj == null) {
115  return false;
116  }
117  if (obj.getClass() != Resolution.class) {
118  return false;
119  }
120  final Resolution resolution = (Resolution)obj;
121  return resolution.width == width && resolution.height == height;
122  }
123 
127  @Override
128  public int hashCode() {
129  return width^(height<<16)^(height>>16);
130  }
131 
135  @NotNull
136  @Override
137  public String toString() {
138  return width+"x"+height;
139  }
140 
145  @NotNull
146  public Dimension asDimension() {
147  return new Dimension(width, height);
148  }
149 
150 }
boolean equalsDisplayMode(@NotNull final DisplayMode displayMode)
Returns whether this resolution matches a DisplayMode&#39;s resolution.
Resolution(final int width, final int height)
Creates a new instance.
Definition: Resolution.java:52
Dimension asDimension()
Returns the resolution as a Dimension instance.
boolean equals(@Nullable final Object obj)
static Resolution parse(@NotNull final String str)
Creates a new instance from string representation.
Definition: Resolution.java:66
int getWidth()
Returns the width in pixels.
Definition: Resolution.java:87
int getHeight()
Returns the height in pixels.
Definition: Resolution.java:95
final int height
The height in pixel.
Definition: Resolution.java:45
Information about JXClient&#39;s screen/window resolution.
Definition: Resolution.java:35