1 4 package uk.ac.roe.antigen.dialogs; 5 6 import java.awt.BorderLayout ; 7 import java.awt.Color ; 8 import java.awt.Dimension ; 9 import java.awt.Font ; 10 import java.awt.GridLayout ; 11 import java.awt.HeadlessException ; 12 import java.awt.Toolkit ; 13 import java.awt.event.WindowAdapter ; 14 import java.awt.event.WindowEvent ; 15 import java.util.logging.Logger ; 16 17 import javax.swing.ImageIcon ; 18 import javax.swing.JFrame ; 19 import javax.swing.JLabel ; 20 import javax.swing.JPanel ; 21 import javax.swing.SwingConstants ; 22 import javax.swing.UIManager ; 23 import javax.swing.WindowConstants ; 24 import javax.swing.border.LineBorder ; 25 26 import uk.ac.roe.antigen.utils.Config; 27 28 29 30 31 36 public abstract class AntigenFrame extends JFrame { 37 40 static final Logger logger = Logger.getLogger(AntigenFrame.class.getName()); 41 42 45 public AntigenFrame() throws HeadlessException { 46 super(); 47 initGUI(); 48 } 49 50 51 52 protected JPanel titlebar; 53 protected JLabel jLabel2; 54 protected JLabel bannerBottom; 55 protected JPanel titles; 56 protected JLabel logoLeft; 57 protected JLabel jLabel1; 58 protected JPanel workPanel; 59 protected JLabel logoRight; 60 protected JLabel bannerTop; 61 protected JPanel southPanel; 62 63 69 protected Dimension getDialogLocation() { 70 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); 72 Dimension dlgInputDim = this.getSize(); 73 int dlgInputX = (int) ((screenDim.getWidth() - dlgInputDim.getWidth()) / 2); 74 int dlgInputY = (int) ((screenDim.getHeight() - dlgInputDim.getHeight()) / 2)-200; 75 return new Dimension (dlgInputX, dlgInputY); 76 } 77 78 protected void initGUI() { 79 try { 80 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 81 } catch(Exception e) { 82 logger.warning("There was an exception setting the look and feel, so you're stuck with what you got."+e.getMessage()); 83 } 84 setSize(Integer.parseInt(Config.getProperty("antigen.builddialog.xsize","600")),Integer.parseInt(Config.getProperty("antigen.builddialog.ysize","450"))); 85 { 86 titlebar = new JPanel (); 87 BorderLayout jPanel1Layout = new BorderLayout (); 88 titlebar.setOpaque(false); 89 90 titlebar.setLayout(jPanel1Layout); 91 this.getContentPane().add(titlebar, BorderLayout.NORTH); 92 { 93 logoRight = new JLabel (); 94 titlebar.add(logoRight, BorderLayout.EAST); 95 } 96 { 97 logoLeft = new JLabel (); 98 titlebar.add(logoLeft, BorderLayout.WEST); 99 100 } 101 { 102 titles = new JPanel (); 103 GridLayout jPanel2Layout = new GridLayout (2, 1); 104 titles.setOpaque(false); 105 106 jPanel2Layout.setRows(2); 107 titles.setLayout(jPanel2Layout); 108 titlebar.add(titles, BorderLayout.CENTER); 109 { 110 jLabel1 = new JLabel (); 111 jLabel1.setText("antIgen"); 112 jLabel1.setFont(new java.awt.Font ("Eurostile", 1, 36)); 113 jLabel1.setHorizontalAlignment(SwingConstants.CENTER); 114 titles.add(jLabel1); 115 jLabel1.setForeground(new java.awt.Color (0, 0, 255)); 116 } 117 { 118 jLabel2 = new JLabel (); 119 jLabel2.setText("Ant-based Installer"); 120 jLabel2.setFont(new java.awt.Font ("Eurostile", 1, 24)); 121 jLabel2.setHorizontalAlignment(SwingConstants.CENTER); 122 titles.add(jLabel2); 123 jLabel2.setForeground(new java.awt.Color (0, 0, 255)); 124 } 125 } 126 { 127 bannerTop = new JLabel (); 128 titlebar.add(bannerTop, BorderLayout.NORTH); 129 } 130 } 131 { 132 workPanel = new JPanel (); 133 this.getContentPane().add(workPanel, BorderLayout.CENTER); 134 BorderLayout workPanelLayout = new BorderLayout (); 135 workPanel.setLayout(workPanelLayout); 136 137 } 138 { 139 southPanel = new JPanel (); 140 BorderLayout buttonsLayout = new BorderLayout (); 141 southPanel.setLayout(buttonsLayout); 142 this.getContentPane().add(southPanel, BorderLayout.SOUTH); 143 southPanel.setBorder(new LineBorder (new java.awt.Color (0, 0, 255), 144 1, false)); 145 southPanel.setOpaque(false); 146 { 147 bannerBottom = new JLabel (); 148 bannerBottom.setHorizontalAlignment(SwingConstants.CENTER); 149 southPanel.add(bannerBottom, BorderLayout.CENTER); 150 } 151 152 } 153 jLabel1.setText(Config.getProperty("antigen.title1.text","")); 155 jLabel1.setForeground(new Color (Integer.parseInt(Config.getProperty("antigen.title1.colour","0000ff"),16))); 156 jLabel1.setFont(new Font (Config.getProperty("antigen.title1.font","Eurostile"), 157 Integer.parseInt(Config.getProperty("antigen.title1.style","1")), 158 Integer.parseInt(Config.getProperty("antigen.title1.size","36")))); 159 jLabel1.setFocusable(false); 160 161 162 163 jLabel2.setText(Config.getProperty("antigen.title2.text","")); 164 jLabel2.setForeground(new Color (Integer.parseInt(Config.getProperty("antigen.title2.colour","0000ff"),16))); 165 jLabel2.setFont(new Font (Config.getProperty("antigen.title2.font","Eurostile"), 166 Integer.parseInt(Config.getProperty("antigen.title2.style","1")), 167 Integer.parseInt(Config.getProperty("antigen.title2.size","24")))); 168 jLabel2.setFocusable(false); 169 170 171 172 this.setTitle(Config.getProperty("antigen.windowtitle.text","antigen")); 173 174 String banner1 = Config.getProperty("antigen.banner.bottom" ); 175 logger.fine("Bottom banner: "+banner1+"|"); 176 if (banner1!=null) { 177 bannerBottom.setIcon(new ImageIcon (getClass().getClassLoader() 178 .getResource(banner1))); 179 } 180 181 182 String banner2 = Config.getProperty("antigen.banner.top" ); 183 logger.fine("Top banner: "+banner2+"|"); 184 if (banner2!=null) { 185 bannerTop.setIcon(new ImageIcon (getClass().getClassLoader() 186 .getResource(banner2))); 187 } 188 189 String leftIcon = Config.getProperty("antigen.logo.left" ); 190 logger.fine("Left icon: "+leftIcon+"|"); 191 if (leftIcon!=null) { 192 logoLeft.setIcon(new ImageIcon (getClass().getClassLoader() 193 .getResource(leftIcon))); 194 } 195 196 String rightIcon = Config.getProperty("antigen.logo.right"); 197 logger.fine("Right icon: "+rightIcon+"|"); 198 if (rightIcon!=null) { 199 logoRight.setIcon(new ImageIcon (getClass().getClassLoader() 200 .getResource(rightIcon))); 201 } 202 203 String title1Icon = Config.getProperty("antigen.logo.title1"); 204 logger.fine("Title1 icon: "+title1Icon+"|"); 205 if (title1Icon!=null) { 206 jLabel1.setIcon(new ImageIcon (getClass().getClassLoader() 207 .getResource(title1Icon))); 208 } 209 String title2Icon = Config.getProperty("antigen.logo.title2"); 210 logger.fine("Title2 icon: "+title2Icon+"|"); 211 if (title2Icon!=null) { 212 jLabel2.setIcon(new ImageIcon (getClass().getClassLoader() 213 .getResource(title2Icon))); 214 } 215 216 217 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 218 219 Color back = new Color (Integer.parseInt(Config.getProperty("antigen.background.colour","000000"),16)); 220 logger.fine("Background colour: "+back); 221 this.getContentPane().setBackground(back); 222 223 this.addWindowListener(new WindowAdapter () { 224 public void windowClosed(WindowEvent e) { 225 } 227 }); 228 229 this.setLocation(getDialogLocation().width, getDialogLocation().height); 230 } 231 public abstract void shutDown(); 232 233 } 234 | Popular Tags |