View Javadoc

1   package com.atlassian.selenium.visualcomparison.utils;
2   
3   import com.atlassian.selenium.visualcomparison.VisualComparableClient;
4   
5   public class ScreenResolution implements Comparable<ScreenResolution>
6   {
7       private int width;
8       private int height;
9   
10      public ScreenResolution(int width, int height)
11      {
12          this.width = width;
13          this.height = height;
14      }
15  
16      public int compareTo(ScreenResolution other)
17      {
18          if (this.width < other.width)
19          {
20              return -1;
21          }
22          if (this.width > other.width)
23          {
24              return 1;
25          }
26          if (this.height < other.height)
27          {
28              return -1;
29          }
30          if (this.height > other.height)
31          {
32              return 1;
33          }
34          return 0;
35      }
36  
37      public ScreenResolution(String value)
38      {
39          String[] parts = value.split("x");
40          if (parts.length != 2)
41          {
42              throw new RuntimeException(value + " is not a valid screen resolution");
43          }
44          width = Integer.parseInt(parts[0]);
45          height = Integer.parseInt(parts[1]);
46      }
47  
48      public String toString()
49      {
50          return width + "x" + height;
51      }
52  
53      public void resize(VisualComparableClient client, boolean refresh)
54      {
55          client.evaluate("window.resizeTo(" + width + ", " + height + ");");
56          if (refresh)
57          {
58              client.refreshAndWait();
59          }
60      }
61  }