PageRenderTime 516ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/izpack-src/tags/release-3-1-0a/src/lib/com/izforge/izpack/panels/HTMLInfoPanel.java

https://github.com/jponge/izpack-full-svn-history-copy
Java | 150 lines | 72 code | 21 blank | 57 comment | 2 complexity | 78a2ff86642f6cc75908d59b9f1b3122 MD5 | raw file
  1. /*
  2. * $Id$
  3. * IzPack
  4. * Copyright (C) 2001-2003 Julien Ponge
  5. *
  6. * File : HTMLInfoPanel.java
  7. * Description : A panel to show some HTML information.
  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 com.izforge.izpack.installer.*;
  27. import java.awt.*;
  28. import java.net.*;
  29. import javax.swing.*;
  30. import javax.swing.event.*;
  31. /**
  32. * The HTML info panel.
  33. *
  34. * @author Julien Ponge
  35. * @created October 27, 2002
  36. */
  37. public class HTMLInfoPanel extends IzPanel implements HyperlinkListener
  38. {
  39. /** The layout. */
  40. private GridBagLayout layout;
  41. /** The layout constraints. */
  42. private GridBagConstraints gbConstraints;
  43. /** The info label. */
  44. private JLabel infoLabel;
  45. /** The text area. */
  46. private JEditorPane textArea;
  47. /**
  48. * The constructor.
  49. *
  50. * @param parent The parent.
  51. * @param idata The installation data.
  52. */
  53. public HTMLInfoPanel(InstallerFrame parent, InstallData idata)
  54. {
  55. super(parent, idata);
  56. // We initialize our layout
  57. layout = new GridBagLayout();
  58. gbConstraints = new GridBagConstraints();
  59. setLayout(layout);
  60. // We add the components
  61. infoLabel = new JLabel(parent.langpack.getString("InfoPanel.info"),
  62. parent.icons.getImageIcon("edit"), JLabel.TRAILING);
  63. parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 1.0, 0.0);
  64. gbConstraints.insets = new Insets(5, 5, 5, 5);
  65. gbConstraints.fill = GridBagConstraints.NONE;
  66. gbConstraints.anchor = GridBagConstraints.SOUTHWEST;
  67. layout.addLayoutComponent(infoLabel, gbConstraints);
  68. add(infoLabel);
  69. try
  70. {
  71. textArea = new JEditorPane();
  72. textArea.setEditable(false);
  73. textArea.addHyperlinkListener(this);
  74. JScrollPane scroller = new JScrollPane(textArea);
  75. textArea.setPage(loadInfo());
  76. parent.buildConstraints(gbConstraints, 0, 1, 1, 1, 1.0, 1.0);
  77. gbConstraints.anchor = GridBagConstraints.CENTER;
  78. gbConstraints.fill = GridBagConstraints.BOTH;
  79. layout.addLayoutComponent(scroller, gbConstraints);
  80. add(scroller);
  81. }
  82. catch (Exception err)
  83. {
  84. err.printStackTrace();
  85. }
  86. }
  87. /**
  88. * Loads the info.
  89. *
  90. * @return The info URL.
  91. */
  92. private URL loadInfo()
  93. {
  94. String resNamePrifix = "HTMLInfoPanel.info";
  95. try
  96. {
  97. return ResourceManager.getInstance().getURL(resNamePrifix);
  98. }
  99. catch (Exception ex)
  100. {
  101. ex.printStackTrace();
  102. }
  103. return null;
  104. }
  105. /**
  106. * Indicates wether the panel has been validated or not.
  107. *
  108. * @return Always true.
  109. */
  110. public boolean isValidated()
  111. {
  112. return true;
  113. }
  114. /**
  115. * Hyperlink events handler.
  116. *
  117. * @param e The event.
  118. */
  119. public void hyperlinkUpdate(HyperlinkEvent e)
  120. {
  121. try
  122. {
  123. if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
  124. textArea.setPage(e.getURL());
  125. }
  126. catch (Exception err)
  127. {}
  128. }
  129. }