forked from External/mage
Some more changes to GUI to better support high screen resolutions.
This commit is contained in:
parent
1c2faaadde
commit
7ef0a0a7f0
31 changed files with 745 additions and 518 deletions
|
|
@ -5,10 +5,13 @@
|
|||
*/
|
||||
package mage.client.util.gui.countryBox;
|
||||
|
||||
import java.net.URL;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.ImageIcon;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.ImageHelper;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -17,33 +20,44 @@ import org.apache.log4j.Logger;
|
|||
*/
|
||||
public class CountryUtil {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(CountryUtil.class);
|
||||
private static final Map<String, ImageIcon> flagIconCache = new HashMap<>();
|
||||
private static final Map<String, String> countryMap = new HashMap<>();
|
||||
private static final Logger LOGGER = Logger.getLogger(CountryUtil.class);
|
||||
private static final Map<String, ImageIcon> FLAG_ICON_CACHE = new HashMap<>();
|
||||
private static final Map<String, String> COUNTRY_MAP = new HashMap<>();
|
||||
|
||||
public static ImageIcon getCountryFlagIcon(String countryCode) {
|
||||
ImageIcon flagIcon = flagIconCache.get(countryCode);
|
||||
ImageIcon flagIcon = FLAG_ICON_CACHE.get(countryCode);
|
||||
if (flagIcon == null) {
|
||||
URL url = CountryUtil.class.getResource("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png"));
|
||||
if (url != null) {
|
||||
flagIcon = new javax.swing.ImageIcon(url);
|
||||
// URL url = CountryUtil.class.getResource("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png"));
|
||||
Image flagImage = ImageHelper.getImageFromResources("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png"));
|
||||
if (flagImage != null) {
|
||||
if (GUISizeHelper.flagHeight > 11) {
|
||||
int width = Math.round(GUISizeHelper.flagHeight * flagImage.getWidth(null) / flagImage.getHeight(null));
|
||||
BufferedImage resized = ImageHelper.scale((BufferedImage) flagImage, BufferedImage.TYPE_4BYTE_ABGR, width, GUISizeHelper.flagHeight);
|
||||
flagIcon = new ImageIcon(resized);
|
||||
} else {
|
||||
flagIcon = new ImageIcon(flagImage);
|
||||
}
|
||||
}
|
||||
if (flagIcon == null || flagIcon.getImage() == null) {
|
||||
logger.warn("Country flag resource not found: " + countryCode);
|
||||
flagIconCache.put(countryCode, flagIcon);
|
||||
LOGGER.warn("Country flag resource not found: " + countryCode);
|
||||
FLAG_ICON_CACHE.put(countryCode, flagIcon);
|
||||
} else {
|
||||
flagIconCache.put(countryCode, flagIcon);
|
||||
FLAG_ICON_CACHE.put(countryCode, flagIcon);
|
||||
}
|
||||
}
|
||||
return flagIcon;
|
||||
}
|
||||
|
||||
public static void changeGUISize() {
|
||||
FLAG_ICON_CACHE.clear();
|
||||
}
|
||||
|
||||
public static String getCountryName(String countryCode) {
|
||||
if (countryMap.isEmpty()) {
|
||||
if (COUNTRY_MAP.isEmpty()) {
|
||||
for (int i = 0; i <= CountryComboBox.countryList.length - 1; i++) {
|
||||
countryMap.put(CountryComboBox.countryList[i][1], CountryComboBox.countryList[i][0]);
|
||||
COUNTRY_MAP.put(CountryComboBox.countryList[i][1], CountryComboBox.countryList[i][0]);
|
||||
}
|
||||
}
|
||||
return countryMap.get(countryCode);
|
||||
return COUNTRY_MAP.get(countryCode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue