mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Refactored out screen centering code to utilities class.
This commit is contained in:
@@ -1,70 +1,35 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import arcane.ui.util.ManaSymbols;
|
||||
import arcane.util.MultiplexOutputStream;
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.error.ExceptionHandler;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.ListChooser;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.CardSizeType;
|
||||
import forge.properties.ForgePreferences.StackOffsetType;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.MENU;
|
||||
import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.OPTIONS;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.UIManager.LookAndFeelInfo;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UIManager.LookAndFeelInfo;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import arcane.ui.util.ManaSymbols;
|
||||
import arcane.util.MultiplexOutputStream;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.error.ExceptionHandler;
|
||||
import forge.gui.ListChooser;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.properties.ForgePreferences.CardSizeType;
|
||||
import forge.properties.ForgePreferences.StackOffsetType;
|
||||
import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.MENU;
|
||||
import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.OPTIONS;
|
||||
/*CHOPPIC*/
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/*CHOPPIC*/
|
||||
|
||||
@@ -226,13 +191,8 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
|
||||
addListeners();
|
||||
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
Rectangle bounds = getBounds();
|
||||
bounds.width = 550;
|
||||
bounds.height = 553;
|
||||
bounds.x = (screen.width - bounds.width) / 2;
|
||||
bounds.y = (screen.height - bounds.height) / 2;
|
||||
setBounds(bounds);
|
||||
this.setSize(550, 553);
|
||||
GuiUtils.centerFrame(this);
|
||||
|
||||
setTitle(ForgeProps.getLocalized(LANG.PROGRAM_NAME));
|
||||
setupMenu();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package forge;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.quest.QuestFrame;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -60,6 +60,8 @@ public class Gui_QuestOptions extends JFrame {
|
||||
setup();
|
||||
setupRadioButtonText();
|
||||
|
||||
this.setSize(420,570);
|
||||
GuiUtils.centerFrame(this);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@@ -67,10 +69,6 @@ public class Gui_QuestOptions extends JFrame {
|
||||
//make the text look correct on the screen
|
||||
jTextArea1.setBackground(getBackground());
|
||||
|
||||
//center window on the screen
|
||||
Dimension screen = this.getToolkit().getScreenSize();
|
||||
setBounds(screen.width / 4, 50, //position
|
||||
420, 570); //size
|
||||
|
||||
//if user closes this window, go back to "New Game" screen
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
|
||||
@@ -4,10 +4,7 @@ import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -41,6 +38,7 @@ public class GuiUtils {
|
||||
public static void addExpandingHorizontalSpace(JPanel panel) {
|
||||
panel.add(Box.createHorizontalGlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Vertical Glue to panel
|
||||
*/
|
||||
@@ -65,25 +63,41 @@ public class GuiUtils {
|
||||
/**
|
||||
* Sets the font size of a component
|
||||
*/
|
||||
public static void setFontSize(Component component, int newSize){
|
||||
public static void setFontSize(Component component, int newSize) {
|
||||
Font oldFont = component.getFont();
|
||||
component.setFont(oldFont.deriveFont((float )newSize));
|
||||
component.setFont(oldFont.deriveFont((float) newSize));
|
||||
}
|
||||
|
||||
public static ImageIcon getIconFromFile(String iconName) {
|
||||
File base = ForgeProps.getFile(NewConstants.IMAGE_ICON);
|
||||
File file = new File(base, iconName);
|
||||
if (file.exists())
|
||||
File base = ForgeProps.getFile(NewConstants.IMAGE_ICON);
|
||||
File file = new File(base, iconName);
|
||||
if (file.exists()) {
|
||||
return new ImageIcon(file.toString());
|
||||
else
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageIcon getResizedIcon(ImageIcon icon, int width, int height){
|
||||
public static ImageIcon getResizedIcon(ImageIcon icon, int width, int height) {
|
||||
return new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
|
||||
}
|
||||
|
||||
public static ImageIcon getEmptyIcon(int width, int height){
|
||||
public static ImageIcon getEmptyIcon(int width, int height) {
|
||||
return new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB));
|
||||
}
|
||||
|
||||
/**
|
||||
* Centers a frame on the screen based on its current size
|
||||
* @param frame a fully laid-out frame
|
||||
*/
|
||||
public static void centerFrame(Frame frame) {
|
||||
Dimension screen = frame.getToolkit().getScreenSize();
|
||||
Rectangle bounds = frame.getBounds();
|
||||
bounds.width = frame.getWidth();
|
||||
bounds.height = frame.getHeight();
|
||||
bounds.x = (screen.width - bounds.width) / 2;
|
||||
bounds.y = (screen.height - bounds.height) / 2;
|
||||
frame.setBounds(bounds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.quest;
|
||||
import forge.AllZone;
|
||||
import forge.Gui_NewGame;
|
||||
import forge.QuestData;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.quest.bazaar.QuestBazaarPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -53,8 +54,12 @@ public class QuestFrame extends JFrame {
|
||||
this.pack();
|
||||
this.setVisible(true);
|
||||
|
||||
GuiUtils.centerFrame(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showPane(String paneName){
|
||||
subPanelMap.get(paneName).refreshState();
|
||||
questLayout.show(visiblePanel, paneName);
|
||||
|
||||
Reference in New Issue
Block a user