Crossfire JXClient, Trunk
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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.util;
24 
25 import java.awt.Dimension;
26 import java.awt.DisplayMode;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
36 public class Resolution {
37 
41  private final int width;
42 
46  private final int height;
47 
53  public Resolution(final int width, final int height) {
54  this.width = width;
55  this.height = height;
56  }
57 
66  @Nullable
67  public static Resolution parse(@NotNull final String str) {
68  final String[] tmp = str.split("x", -1);
69  if (tmp.length != 2) {
70  return null;
71  }
72  final int width;
73  final int height;
74  try {
75  width = Integer.parseInt(tmp[0]);
76  height = Integer.parseInt(tmp[1]);
77  } catch (final NumberFormatException ignored) {
78  return null;
79  }
80 
81  return new Resolution(width, height);
82  }
83 
88  public int getWidth() {
89  return width;
90  }
91 
96  public int getHeight() {
97  return height;
98  }
99 
106  public boolean equalsDisplayMode(@NotNull final DisplayMode displayMode) {
107  return width == displayMode.getWidth() && height == displayMode.getHeight();
108  }
109 
110  @Override
111  public boolean equals(@Nullable final Object obj) {
112  if (obj == null) {
113  return false;
114  }
115  if (obj.getClass() != Resolution.class) {
116  return false;
117  }
118  final Resolution resolution = (Resolution)obj;
119  return resolution.width == width && resolution.height == height;
120  }
121 
122  @Override
123  public int hashCode() {
124  return width^(height<<16)^(height>>16);
125  }
126 
127  @NotNull
128  @Override
129  public String toString() {
130  return width+"x"+height;
131  }
132 
137  @NotNull
138  public Dimension asDimension() {
139  return new Dimension(width, height);
140  }
141 
142 }
com.realtime.crossfire.jxclient.util.Resolution.hashCode
int hashCode()
Definition: Resolution.java:123
com.realtime.crossfire.jxclient.util.Resolution.getWidth
int getWidth()
Definition: Resolution.java:88
com.realtime.crossfire.jxclient.util.Resolution.equalsDisplayMode
boolean equalsDisplayMode(@NotNull final DisplayMode displayMode)
Definition: Resolution.java:106
com.realtime.crossfire.jxclient.util.Resolution.width
final int width
Definition: Resolution.java:41
com.realtime.crossfire.jxclient.util.Resolution.equals
boolean equals(@Nullable final Object obj)
Definition: Resolution.java:111
com.realtime.crossfire.jxclient.util.Resolution.height
final int height
Definition: Resolution.java:46
com.realtime.crossfire.jxclient.util.Resolution.asDimension
Dimension asDimension()
Definition: Resolution.java:138
com.realtime.crossfire.jxclient.util.Resolution.parse
static Resolution parse(@NotNull final String str)
Definition: Resolution.java:67
com.realtime.crossfire.jxclient.util.Resolution
Definition: Resolution.java:36
com.realtime.crossfire.jxclient.util.Resolution.Resolution
Resolution(final int width, final int height)
Definition: Resolution.java:53
com.realtime.crossfire.jxclient.util.Resolution.toString
String toString()
Definition: Resolution.java:129
com.realtime.crossfire.jxclient.util.Resolution.getHeight
int getHeight()
Definition: Resolution.java:96