View Javadoc
1   package org.woehlke.computer.kurzweil.commons.model;
2   
3   import lombok.*;
4   import lombok.extern.log4j.Log4j2;
5   
6   import javax.swing.*;
7   import java.awt.*;
8   import java.io.Serializable;
9   
10  @Log4j2
11  @Getter
12  @ToString
13  @AllArgsConstructor
14  @EqualsAndHashCode
15  public class Bounds implements Serializable {
16  
17      private final int myStartX;
18      private final int myStartY;
19      private final int myWidth;
20      private final int myHeight;
21  
22      public Bounds(double height, double width, Dimension screenSize){
23          double startX = (screenSize.getWidth() - width) / 2d;
24          double startY = (screenSize.getHeight() - height) / 2d;
25          myStartX = Double.valueOf(startX).intValue();
26          myStartY = Double.valueOf(startY).intValue();
27          myWidth = Double.valueOf(width).intValue();
28          myHeight = Double.valueOf(height).intValue();
29      }
30  
31      public static Bounds getFrameBounds(JRootPane rootPane){
32          double width = rootPane.getWidth();
33          double height = rootPane.getHeight();
34          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
35          return new Bounds(height,width,screenSize);
36      }
37  
38      public static Bounds getCanvas(JRootPane rootPane){
39          double width = rootPane.getWidth();
40          double height = rootPane.getHeight();
41          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
42          return new Bounds(height,width,screenSize);
43      }
44  }