00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.util;
00023
00024 import java.awt.Dimension;
00025 import java.awt.DisplayMode;
00026 import org.jetbrains.annotations.NotNull;
00027 import org.jetbrains.annotations.Nullable;
00028
00035 public class Resolution {
00036
00040 private final int width;
00041
00045 private final int height;
00046
00052 public Resolution(final int width, final int height) {
00053 this.width = width;
00054 this.height = height;
00055 }
00056
00065 @Nullable
00066 public static Resolution parse(@NotNull final String str) {
00067 final String[] tmp = str.split("x", -1);
00068 if (tmp.length != 2) {
00069 return null;
00070 }
00071 final int width;
00072 final int height;
00073 try {
00074 width = Integer.parseInt(tmp[0]);
00075 height = Integer.parseInt(tmp[1]);
00076 } catch (final NumberFormatException ignored) {
00077 return null;
00078 }
00079
00080 return new Resolution(width, height);
00081 }
00082
00087 public int getWidth() {
00088 return width;
00089 }
00090
00095 public int getHeight() {
00096 return height;
00097 }
00098
00105 public boolean equalsDisplayMode(@NotNull final DisplayMode displayMode) {
00106 return width == displayMode.getWidth() && height == displayMode.getHeight();
00107 }
00108
00112 @Override
00113 public boolean equals(@Nullable final Object obj) {
00114 if (obj == null) {
00115 return false;
00116 }
00117 if (obj.getClass() != Resolution.class) {
00118 return false;
00119 }
00120 final Resolution resolution = (Resolution)obj;
00121 return resolution.width == width && resolution.height == height;
00122 }
00123
00127 @Override
00128 public int hashCode() {
00129 return width^(height<<16)^(height>>16);
00130 }
00131
00135 @NotNull
00136 @Override
00137 public String toString() {
00138 return width+"x"+height;
00139 }
00140
00145 @NotNull
00146 public Dimension asDimension() {
00147 return new Dimension(width, height);
00148 }
00149
00150 }