001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/ http://izpack.codehaus.org/
005: *
006: * Copyright 2007 Dennis Reil
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
009: * in compliance with the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software distributed under the License
014: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
015: * or implied. See the License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package com.izforge.izpack.panels;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Color;
022: import java.awt.Dimension;
023: import java.awt.Frame;
024: import java.awt.HeadlessException;
025: import java.awt.Point;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028: import java.io.File;
029:
030: import javax.swing.Box;
031: import javax.swing.BoxLayout;
032: import javax.swing.JButton;
033: import javax.swing.JDialog;
034: import javax.swing.JFileChooser;
035: import javax.swing.JLabel;
036: import javax.swing.JOptionPane;
037: import javax.swing.JPanel;
038: import javax.swing.JTextField;
039:
040: import com.izforge.izpack.LocaleDatabase;
041: import com.izforge.izpack.gui.ButtonFactory;
042: import com.izforge.izpack.gui.IconsDatabase;
043: import com.izforge.izpack.gui.LabelFactory;
044: import com.izforge.izpack.installer.AutomatedInstallData;
045: import com.izforge.izpack.installer.InstallerFrame;
046:
047: /**
048: * Dialog for choosing the next volume.
049: * @author Dennis Reil, <Dennis.Reil@reddot.de>
050: */
051: public class NextMediaDialog extends JDialog implements ActionListener {
052: private static final String NEXTMEDIA_MSG_ID = "nextmedia.msg";
053: private static final String NEXTMEDIA_TITLE_ID = "nextmedia.title";
054: private static final String BROWSEBTN_ID = "nextmedia.browsebtn";
055: private static final String OKBTN_ID = "nextmedia.okbtn";
056: private static final String CANCELBTN_ID = "nextmedia.cancelbtn";
057:
058: private static final long serialVersionUID = -2551719029962051020L;
059:
060: protected JLabel msg;
061: protected JTextField path;
062: protected JButton browsebtn;
063: protected JButton okbtn;
064: protected JButton cancelbtn;
065:
066: protected String nextmedianame;
067: protected String nextmediapath;
068: protected String nextmediainput;
069: protected LocaleDatabase langpack;
070: protected IconsDatabase icons;
071:
072: protected Frame owner;
073:
074: /**
075: * @throws HeadlessException
076: */
077: public NextMediaDialog(InstallerFrame main, String nextmedia)
078: throws HeadlessException {
079: this (null, main, nextmedia);
080: }
081:
082: /**
083: * @param owner
084: * @throws HeadlessException
085: */
086: public NextMediaDialog(Frame owner, InstallerFrame main,
087: String nextmedia) throws HeadlessException {
088: this (owner, main.langpack, main.icons, nextmedia);
089: }
090:
091: public NextMediaDialog(Frame owner, LocaleDatabase languagepack,
092: IconsDatabase icons, String nextmedia)
093: throws HeadlessException {
094: super (owner, languagepack.getString(NEXTMEDIA_TITLE_ID), true);
095: this .owner = owner;
096: this .langpack = languagepack;
097: this .icons = icons;
098: this .nextmediapath = nextmedia;
099: File nextmediafile = new File(this .nextmediapath);
100: this .nextmedianame = nextmediafile.getName();
101: this .initUI();
102: }
103:
104: public NextMediaDialog(Frame owner, AutomatedInstallData idata,
105: String nextmedia) throws HeadlessException {
106: this (owner, idata.langpack, null, nextmedia);
107: }
108:
109: protected void initUI() {
110: if (this .icons != null) {
111: this .msg = LabelFactory.create(this .langpack
112: .getString(NEXTMEDIA_MSG_ID), this .icons
113: .getImageIcon("warning"), JLabel.LEFT);
114: this .browsebtn = ButtonFactory.createButton(this .langpack
115: .getString(BROWSEBTN_ID), this .icons
116: .getImageIcon("open"), new Color(230, 230, 230));
117: this .okbtn = ButtonFactory.createButton(this .langpack
118: .getString(OKBTN_ID),
119: this .icons.getImageIcon("ok"), new Color(230, 230,
120: 230));
121: this .cancelbtn = ButtonFactory.createButton(this .langpack
122: .getString(CANCELBTN_ID), this .icons
123: .getImageIcon("cancel"), new Color(230, 230, 230));
124: } else {
125: this .msg = new JLabel(this .langpack
126: .getString(NEXTMEDIA_MSG_ID), JLabel.LEFT);
127: this .browsebtn = new JButton(this .langpack
128: .getString(BROWSEBTN_ID));
129: this .okbtn = new JButton(this .langpack.getString(OKBTN_ID));
130: this .cancelbtn = new JButton(this .langpack
131: .getString(CANCELBTN_ID));
132: }
133: this .path = new JTextField(this .nextmediapath);
134: this .path.setColumns(40);
135:
136: this .browsebtn.addActionListener(this );
137: this .okbtn.addActionListener(this );
138: this .cancelbtn.addActionListener(this );
139:
140: JPanel mainpanel = new JPanel();
141: mainpanel.setLayout(new BoxLayout(mainpanel,
142: BoxLayout.PAGE_AXIS));
143: mainpanel.add(this .msg);
144:
145: JPanel pathpanel = new JPanel();
146: pathpanel.setLayout(new BoxLayout(pathpanel,
147: BoxLayout.LINE_AXIS));
148: pathpanel.add(this .path);
149: pathpanel.add(this .browsebtn);
150: pathpanel.add(Box.createHorizontalGlue());
151: mainpanel.add(pathpanel);
152:
153: JPanel okpanel = new JPanel();
154: okpanel.setLayout(new BoxLayout(okpanel, BoxLayout.LINE_AXIS));
155: okpanel.add(Box.createHorizontalGlue());
156: okpanel.add(this .okbtn);
157: okpanel.add(this .cancelbtn);
158: okpanel.add(Box.createHorizontalGlue());
159: mainpanel.add(okpanel);
160: mainpanel.add(Box.createVerticalGlue());
161:
162: this .getContentPane().setLayout(new BorderLayout());
163: this .getContentPane().add(mainpanel, BorderLayout.CENTER);
164:
165: this .pack();
166: // set location
167: if (this .owner != null) {
168: Dimension mysize = this .getSize();
169: Dimension ownersize = this .owner.getSize();
170: Point position = this .owner.getLocationOnScreen();
171: Point centerposition = new Point();
172: centerposition.setLocation(position.getX() + 0.5
173: * ownersize.getWidth(), position.getY() + 0.5
174: * ownersize.getHeight());
175: Point myposition = new Point();
176: myposition.setLocation(centerposition.getX() - 0.5
177: * mysize.getWidth(), centerposition.getY() - 0.5
178: * mysize.getHeight());
179: this .setLocation(myposition);
180: }
181: }
182:
183: public String getNextMedia() {
184: return this .nextmediainput;
185: }
186:
187: public void actionPerformed(ActionEvent e) {
188: if (e.getSource() == this .browsebtn) {
189: JFileChooser jfc;
190: if (this .path.getText() != null) {
191: jfc = new JFileChooser(this .path.getText());
192: } else {
193: jfc = new JFileChooser();
194: }
195: jfc.setFileFilter(new NextMediaFileFilter(
196: this .nextmedianame, this .langpack));
197: jfc.setDialogTitle(this .langpack
198: .getString("nextmedia.choosertitle"));
199: jfc.setDialogType(JFileChooser.OPEN_DIALOG);
200: jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
201: if (jfc.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
202: this .nextmediainput = jfc.getSelectedFile()
203: .getAbsolutePath();
204: this .path.setText(this .nextmediainput);
205: }
206: } else if (e.getSource() == this .okbtn) {
207: this .nextmediainput = this .path.getText();
208: // close this dialog
209: this .setVisible(false);
210: } else if (e.getSource() == this .cancelbtn) {
211: int option = JOptionPane.showConfirmDialog(this ,
212: this .langpack.getString("installer.quit.message"),
213: this .langpack.getString("installer.quit.title"),
214: JOptionPane.YES_NO_OPTION);
215: if (option == JOptionPane.YES_OPTION) {
216: // exit
217: System.exit(-1);
218: }
219: }
220: }
221: }
|