1 18 package com.izforge.izpack.panels; 19 20 import java.awt.BorderLayout ; 21 import java.awt.Color ; 22 import java.awt.Dimension ; 23 import java.awt.Frame ; 24 import java.awt.HeadlessException ; 25 import java.awt.Point ; 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 import java.io.File ; 29 30 import javax.swing.Box ; 31 import javax.swing.BoxLayout ; 32 import javax.swing.JButton ; 33 import javax.swing.JDialog ; 34 import javax.swing.JFileChooser ; 35 import javax.swing.JLabel ; 36 import javax.swing.JOptionPane ; 37 import javax.swing.JPanel ; 38 import javax.swing.JTextField ; 39 40 import com.izforge.izpack.LocaleDatabase; 41 import com.izforge.izpack.gui.ButtonFactory; 42 import com.izforge.izpack.gui.IconsDatabase; 43 import com.izforge.izpack.gui.LabelFactory; 44 import com.izforge.izpack.installer.AutomatedInstallData; 45 import com.izforge.izpack.installer.InstallerFrame; 46 47 48 52 public class NextMediaDialog extends JDialog implements ActionListener { 53 private static final String NEXTMEDIA_MSG_ID = "nextmedia.msg"; 54 private static final String NEXTMEDIA_TITLE_ID = "nextmedia.title"; 55 private static final String BROWSEBTN_ID = "nextmedia.browsebtn"; 56 private static final String OKBTN_ID = "nextmedia.okbtn"; 57 private static final String CANCELBTN_ID = "nextmedia.cancelbtn"; 58 59 60 private static final long serialVersionUID = -2551719029962051020L; 61 62 protected JLabel msg; 63 protected JTextField path; 64 protected JButton browsebtn; 65 protected JButton okbtn; 66 protected JButton cancelbtn; 67 68 protected String nextmedianame; 69 protected String nextmediapath; 70 protected String nextmediainput; 71 protected LocaleDatabase langpack; 72 protected IconsDatabase icons; 73 74 protected Frame owner; 75 78 public NextMediaDialog(InstallerFrame main, String nextmedia) throws HeadlessException { 79 this(null,main,nextmedia); 80 } 81 82 86 public NextMediaDialog(Frame owner,InstallerFrame main, String nextmedia) throws HeadlessException { 87 this(owner,main.langpack,main.icons,nextmedia); 88 } 89 90 public NextMediaDialog(Frame owner, LocaleDatabase languagepack, IconsDatabase icons, String nextmedia) throws HeadlessException { 91 super(owner,languagepack.getString(NEXTMEDIA_TITLE_ID),true); 92 this.owner = owner; 93 this.langpack = languagepack; 94 this.icons = icons; 95 this.nextmediapath = nextmedia; 96 File nextmediafile = new File (this.nextmediapath); 97 this.nextmedianame = nextmediafile.getName(); 98 this.initUI(); 99 } 100 101 public NextMediaDialog(Frame owner, AutomatedInstallData idata, String nextmedia) throws HeadlessException { 102 this(owner,idata.langpack,null,nextmedia); 103 } 104 105 protected void initUI() { 106 if (this.icons != null) { 107 this.msg = LabelFactory.create(this.langpack.getString(NEXTMEDIA_MSG_ID), this.icons.getImageIcon("warning"), JLabel.LEFT); 108 this.browsebtn = ButtonFactory.createButton(this.langpack.getString(BROWSEBTN_ID), this.icons.getImageIcon("open"), new Color (230, 230, 230)); 109 this.okbtn = ButtonFactory.createButton(this.langpack.getString(OKBTN_ID), this.icons.getImageIcon("ok"), new Color (230, 230, 230)); 110 this.cancelbtn = ButtonFactory.createButton(this.langpack.getString(CANCELBTN_ID), this.icons.getImageIcon("cancel"), new Color (230, 230, 230)); 111 } 112 else { 113 this.msg = new JLabel (this.langpack.getString(NEXTMEDIA_MSG_ID),JLabel.LEFT); 114 this.browsebtn = new JButton (this.langpack.getString(BROWSEBTN_ID)); 115 this.okbtn = new JButton (this.langpack.getString(OKBTN_ID)); 116 this.cancelbtn = new JButton (this.langpack.getString(CANCELBTN_ID)); 117 } 118 this.path = new JTextField (this.nextmediapath); 119 this.path.setColumns(40); 120 121 this.browsebtn.addActionListener(this); 122 this.okbtn.addActionListener(this); 123 this.cancelbtn.addActionListener(this); 124 125 JPanel mainpanel = new JPanel (); 126 mainpanel.setLayout(new BoxLayout (mainpanel,BoxLayout.PAGE_AXIS)); 127 mainpanel.add(this.msg); 128 129 JPanel pathpanel = new JPanel (); 130 pathpanel.setLayout(new BoxLayout (pathpanel,BoxLayout.LINE_AXIS)); 131 pathpanel.add(this.path); 132 pathpanel.add(this.browsebtn); 133 pathpanel.add(Box.createHorizontalGlue()); 134 mainpanel.add(pathpanel); 135 136 JPanel okpanel = new JPanel (); 137 okpanel.setLayout(new BoxLayout (okpanel,BoxLayout.LINE_AXIS)); 138 okpanel.add(Box.createHorizontalGlue()); 139 okpanel.add(this.okbtn); 140 okpanel.add(this.cancelbtn); 141 okpanel.add(Box.createHorizontalGlue()); 142 mainpanel.add(okpanel); 143 mainpanel.add(Box.createVerticalGlue()); 144 145 this.getContentPane().setLayout(new BorderLayout ()); 146 this.getContentPane().add(mainpanel,BorderLayout.CENTER); 147 148 this.pack(); 149 if (this.owner != null) { 151 Dimension mysize = this.getSize(); 152 Dimension ownersize = this.owner.getSize(); 153 Point position = this.owner.getLocationOnScreen(); 154 Point centerposition = new Point (); 155 centerposition.setLocation(position.getX()+ 0.5 * ownersize.getWidth(),position.getY() + 0.5 * ownersize.getHeight()); 156 Point myposition = new Point (); 157 myposition.setLocation(centerposition.getX() - 0.5 * mysize.getWidth(), centerposition.getY() - 0.5 * mysize.getHeight()); 158 this.setLocation(myposition); 159 } 160 } 161 162 public String getNextMedia() { 163 return this.nextmediainput; 164 } 165 166 public void actionPerformed(ActionEvent e) { 167 if (e.getSource() == this.browsebtn){ 168 JFileChooser jfc; 169 if (this.path.getText() != null){ 170 jfc = new JFileChooser (this.path.getText()); 171 } 172 else { 173 jfc = new JFileChooser (); 174 } 175 jfc.setFileFilter(new NextMediaFileFilter(this.nextmedianame, this.langpack)); 176 jfc.setDialogTitle(this.langpack.getString("nextmedia.choosertitle")); 177 jfc.setDialogType(JFileChooser.OPEN_DIALOG); 178 jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); 179 if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){ 180 this.nextmediainput = jfc.getSelectedFile().getAbsolutePath(); 181 this.path.setText(this.nextmediainput); 182 } 183 } 184 else if (e.getSource() == this.okbtn) { 185 this.nextmediainput = this.path.getText(); 186 this.setVisible(false); 188 } 189 else if (e.getSource() == this.cancelbtn) { 190 int option = JOptionPane.showConfirmDialog(this, this.langpack.getString("installer.quit.message") , this.langpack.getString("installer.quit.title"), JOptionPane.YES_NO_OPTION); 191 if (option == JOptionPane.YES_OPTION){ 192 System.exit(-1); 194 } 195 } 196 } 197 } | Popular Tags |