/izpack-src/branches/branch-3-5/src/lib/com/izforge/izpack/panels/InstallPanel.java

https://github.com/jponge/izpack-full-svn-history-copy · Java · 256 lines · 152 code · 30 blank · 74 comment · 2 complexity · 774b9077c8e576017e796176d97f638d MD5 · raw file

  1. /*
  2. * $Id$
  3. * IzPack
  4. * Copyright (C) 2001-2004 Julien Ponge
  5. *
  6. * File : InstallPanel.java
  7. * Description : A panel to launch the installation process.
  8. * Author's email : julien@izforge.com
  9. * Author's Website : http://www.izforge.com
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. */
  25. package com.izforge.izpack.panels;
  26. import java.awt.Dimension;
  27. import java.awt.GridBagConstraints;
  28. import java.awt.GridBagLayout;
  29. import javax.swing.JLabel;
  30. import javax.swing.JOptionPane;
  31. import javax.swing.JProgressBar;
  32. import javax.swing.JSeparator;
  33. import com.izforge.izpack.installer.InstallData;
  34. import com.izforge.izpack.installer.InstallerFrame;
  35. import com.izforge.izpack.installer.IzPanel;
  36. import com.izforge.izpack.util.AbstractUIProgressHandler;
  37. /**
  38. * The install panel class. Launches the actual installation job.
  39. *
  40. * @author Julien Ponge
  41. */
  42. public class InstallPanel extends IzPanel implements AbstractUIProgressHandler
  43. {
  44. /** The layout. */
  45. private GridBagLayout layout;
  46. /** The layout constraints. */
  47. private GridBagConstraints gbConstraints;
  48. /** The tip label. */
  49. protected JLabel tipLabel;
  50. /** The operation label . */
  51. protected JLabel packOpLabel;
  52. /** The operation label . */
  53. protected JLabel overallOpLabel;
  54. /** The pack progress bar. */
  55. protected JProgressBar packProgressBar;
  56. /** The progress bar. */
  57. protected JProgressBar overallProgressBar;
  58. /** True if the installation has been done. */
  59. private volatile boolean validated = false;
  60. /** How many packs we are going to install. */
  61. private int noOfPacks = 0;
  62. /**
  63. * The constructor.
  64. *
  65. * @param parent The parent window.
  66. * @param idata The installation data.
  67. */
  68. public InstallPanel(InstallerFrame parent, InstallData idata)
  69. {
  70. super(parent, idata);
  71. // We initialize our layout
  72. layout = new GridBagLayout();
  73. gbConstraints = new GridBagConstraints();
  74. setLayout(layout);
  75. int row = 1;
  76. this.tipLabel =
  77. new JLabel(
  78. parent.langpack.getString("InstallPanel.tip"),
  79. parent.icons.getImageIcon("information"),
  80. JLabel.TRAILING);
  81. parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0);
  82. gbConstraints.fill = GridBagConstraints.NONE;
  83. gbConstraints.anchor = GridBagConstraints.NORTHWEST;
  84. layout.addLayoutComponent(this.tipLabel, gbConstraints);
  85. add(this.tipLabel);
  86. this.packOpLabel = new JLabel(" ", JLabel.TRAILING);
  87. parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0);
  88. gbConstraints.anchor = GridBagConstraints.SOUTHWEST;
  89. layout.addLayoutComponent(this.packOpLabel, gbConstraints);
  90. add(this.packOpLabel);
  91. this.packProgressBar = new JProgressBar();
  92. this.packProgressBar.setStringPainted(true);
  93. this.packProgressBar.setString(
  94. parent.langpack.getString("InstallPanel.begin"));
  95. this.packProgressBar.setValue(0);
  96. parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0);
  97. gbConstraints.anchor = GridBagConstraints.NORTH;
  98. gbConstraints.fill = GridBagConstraints.HORIZONTAL;
  99. layout.addLayoutComponent(this.packProgressBar, gbConstraints);
  100. add(this.packProgressBar);
  101. // make sure there is some space between the progress bars
  102. JSeparator sep = new JSeparator();
  103. Dimension dim = new Dimension(0, 10);
  104. sep.setPreferredSize(dim);
  105. sep.setMinimumSize(dim);
  106. sep.setMaximumSize(dim);
  107. parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0);
  108. layout.addLayoutComponent(sep, gbConstraints);
  109. add(sep);
  110. this.overallOpLabel =
  111. new JLabel(
  112. parent.langpack.getString("InstallPanel.progress"),
  113. parent.icons.getImageIcon("information"),
  114. JLabel.TRAILING);
  115. parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0);
  116. gbConstraints.anchor = GridBagConstraints.NORTHWEST;
  117. gbConstraints.fill = GridBagConstraints.NONE;
  118. layout.addLayoutComponent(this.overallOpLabel, gbConstraints);
  119. add(this.overallOpLabel);
  120. this.overallProgressBar = new JProgressBar();
  121. this.overallProgressBar.setStringPainted(true);
  122. this.overallProgressBar.setString("");
  123. this.overallProgressBar.setValue(0);
  124. parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0);
  125. gbConstraints.anchor = GridBagConstraints.NORTH;
  126. gbConstraints.fill = GridBagConstraints.HORIZONTAL;
  127. layout.addLayoutComponent(this.overallProgressBar, gbConstraints);
  128. add(this.overallProgressBar);
  129. }
  130. /**
  131. * Indicates wether the panel has been validated or not.
  132. *
  133. * @return The validation state.
  134. */
  135. public boolean isValidated()
  136. {
  137. return this.validated;
  138. }
  139. /** The unpacker starts. */
  140. public void startAction(String name, int noOfJobs)
  141. {
  142. parent.blockGUI();
  143. // figure out how many packs there are to install
  144. this.noOfPacks = noOfJobs;
  145. this.overallProgressBar.setMinimum(0);
  146. this.overallProgressBar.setMaximum(this.noOfPacks);
  147. this.overallProgressBar.setString(
  148. "0 / " + Integer.toString(this.noOfPacks));
  149. }
  150. /**
  151. * An error was encountered.
  152. *
  153. * @param error The error text.
  154. */
  155. public void errorUnpack(String error)
  156. {
  157. this.packOpLabel.setText(error);
  158. idata.installSuccess = false;
  159. JOptionPane.showMessageDialog(
  160. this,
  161. error.toString(),
  162. parent.langpack.getString("installer.error"),
  163. JOptionPane.ERROR_MESSAGE);
  164. }
  165. /** The unpacker stops. */
  166. public void stopAction()
  167. {
  168. parent.releaseGUI();
  169. parent.lockPrevButton();
  170. this.overallProgressBar.setValue(this.overallProgressBar.getValue() + 1);
  171. this.packProgressBar.setString(
  172. parent.langpack.getString("InstallPanel.finished"));
  173. this.packProgressBar.setEnabled(false);
  174. String no_of_packs = Integer.toString(this.noOfPacks);
  175. this.overallProgressBar.setString(no_of_packs + " / " + no_of_packs);
  176. this.overallProgressBar.setEnabled(false);
  177. this.packOpLabel.setText(" ");
  178. this.packOpLabel.setEnabled(false);
  179. idata.installSuccess = true;
  180. idata.canClose = true;
  181. this.validated = true;
  182. if (idata.panels.indexOf(this) != (idata.panels.size() - 1))
  183. parent.unlockNextButton();
  184. }
  185. /**
  186. * Normal progress indicator.
  187. *
  188. * @param val The progression value.
  189. * @param msg The progression message.
  190. */
  191. public void progress(int val, String msg)
  192. {
  193. this.packProgressBar.setValue(val + 1);
  194. packOpLabel.setText(msg);
  195. }
  196. /**
  197. * Pack changing.
  198. *
  199. * @param packName The pack name.
  200. * @param stepno The number of the pack.
  201. * @param max The new maximum progress.
  202. */
  203. public void nextStep(String packName, int stepno, int max)
  204. {
  205. this.packProgressBar.setValue(0);
  206. this.packProgressBar.setMinimum(0);
  207. this.packProgressBar.setMaximum(max);
  208. this.packProgressBar.setString(packName);
  209. this.overallProgressBar.setValue(stepno - 1);
  210. this.overallProgressBar.setString(
  211. Integer.toString(stepno) + " / " + Integer.toString(this.noOfPacks));
  212. }
  213. /** Called when the panel becomes active. */
  214. public void panelActivate()
  215. {
  216. // We clip the panel
  217. Dimension dim = parent.getPanelsContainerSize();
  218. dim.width = dim.width - (dim.width / 4);
  219. dim.height = 150;
  220. setMinimumSize(dim);
  221. setMaximumSize(dim);
  222. setPreferredSize(dim);
  223. parent.lockNextButton();
  224. parent.install(this);
  225. }
  226. }