foul-magics/Mage.Client/src/main/java/mage/client/util/SettingsManager.java
vraskulin 076840df53 Big refactoring
I used Intellij IDEA to automatically refactor code to achive 3 goals.
1) get rid of anonymouse classes, and replace the with lamba to get more readeable and clean code (like in TableWaitingDialog).
2) make effectively final  variables actually final to avoid inadvertent changes on it in further releases and keep objects as immutable, as possible.
3)  Get rid of unused imports (most of the changes) in whole project classes.
2017-01-09 19:16:53 +03:00

72 lines
1.8 KiB
Java

package mage.client.util;
import java.awt.Point;
import java.awt.Rectangle;
import org.mage.card.arcane.CardPanel;
/**
* Contains dynamic settings for client.
*
* @author nantuko
*/
public class SettingsManager {
private static final SettingsManager fInstance = new SettingsManager();
public static SettingsManager getInstance() {
return fInstance;
}
public int getScreenWidth() {
return screenWidth;
}
public void setScreenWidth(int screenWidth) {
this.screenWidth = screenWidth;
}
public int getScreenHeight() {
return screenHeight;
}
public void setScreenHeight(int screenHeight) {
this.screenHeight = screenHeight;
}
public void setScreenWidthAndHeight(int screenWidth, int screenHeight) {
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
}
public Rectangle getCardSize() {
return cardSize;
}
/**
* Get centered component position. Depends on screen width and height.
*
* @param dialogWidth
* @param dialogHeight
* @return
*/
public Point getComponentPosition(int dialogWidth, int dialogHeight) {
if (dialogWidth == 0) {
throw new IllegalArgumentException("dialogWidth can't be 0");
}
if (dialogHeight == 0) {
throw new IllegalArgumentException("dialogHeight can't be 0");
}
int width = Math.max(screenWidth, dialogWidth);
int height = Math.max(screenHeight, dialogHeight);
int x = ((width - dialogWidth) / 2);
int y = ((height - dialogHeight) / 2);
return new Point(x, y);
}
private int screenWidth;
private int screenHeight;
private final Rectangle cardSize = CardPanel.CARD_SIZE_FULL;
}