You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.java 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20. * or visit www.oracle.com if you need additional information or have any
  21. * questions.
  22. *
  23. */
  24. package com.github.dcevm.installer;
  25. import javax.imageio.ImageIO;
  26. import javax.swing.*;
  27. import java.awt.*;
  28. import java.awt.image.BufferedImage;
  29. import java.io.IOException;
  30. /**
  31. * @author Kerstin Breiteneder
  32. * @author Christoph Wimberger
  33. * @author Ivan Dubrov
  34. * @author Przemysław Rumik
  35. */
  36. public class MainWindow extends JFrame {
  37. private final InstallationsTableModel installations;
  38. private JTable table;
  39. public MainWindow() {
  40. super("Dynamic Code Evolution VM Installer");
  41. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42. Installer installer = new Installer(ConfigurationInfo.current());
  43. installations = new InstallationsTableModel();
  44. for (Installation i : installer.listInstallations()) {
  45. installations.add(i);
  46. }
  47. add(getBanner(), BorderLayout.NORTH);
  48. add(getCenterPanel(), BorderLayout.CENTER);
  49. add(getBottomPanel(), BorderLayout.SOUTH);
  50. if (table.getRowCount() > 0) {
  51. table.setRowSelectionInterval(0, 0);
  52. }
  53. pack();
  54. setMinimumSize(getSize());
  55. }
  56. static void showInstallerException(Exception ex, Component parent) {
  57. Throwable e = ex;
  58. String error = e.getMessage();
  59. e = e.getCause();
  60. while (e != null) {
  61. error += "\n" + e.getMessage();
  62. e = e.getCause();
  63. }
  64. ex.printStackTrace();
  65. error += "\nPlease ensure that no other Java applications are running and you have sufficient permissions.";
  66. JOptionPane.showMessageDialog(parent, error, ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  67. }
  68. private JComponent getBanner() {
  69. try {
  70. BufferedImage img = ImageIO.read(getClass().getResource("splash.png"));
  71. JLabel title = new JLabel(new ImageIcon(img));
  72. title.setPreferredSize(new Dimension(img.getWidth() + 10, img.getHeight()));
  73. title.setOpaque(true);
  74. title.setBackground(new Color(238, 238, 255));
  75. return title;
  76. } catch (Exception ignore) {
  77. }
  78. return new JLabel();
  79. }
  80. private JComponent getCenterPanel() {
  81. JPanel center = new JPanel(new BorderLayout());
  82. center.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  83. center.setBackground(Color.WHITE);
  84. JTextArea license = new javax.swing.JTextArea();
  85. license.setLineWrap(true);
  86. license.setWrapStyleWord(true);
  87. license.setEditable(false);
  88. license.setFont(license.getFont().deriveFont(11.0f));
  89. StringBuilder licenseText = new StringBuilder();
  90. licenseText.append("Enhance current Java (JRE/JDK) installations with DCEVM (http://github.com/dcevm/dcevm).");
  91. licenseText.append("\n\nYou can either replace current Java VM or install DCEVM as alternative JVM (run with -XXaltjvm=dcevm command-line option).");
  92. licenseText.append("\nInstallation as alternative JVM is preferred, it gives you more control where you will use DCEVM.\nWhy this is important? Because DCEVM forces your JVM to use only one GC algorithm, and this may cause performance penalty.");
  93. licenseText.append("\n\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 only, as published by the Free Software Foundation.\n\nThis code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details (a copy is included in the LICENSE file that accompanied this code).\n\nYou should have received a copy of the GNU General Public License version 2 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.");
  94. licenseText.append("\n\n\nASM LICENSE TEXT:\nCopyright (c) 2000-2005 INRIA, France Telecom\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
  95. license.setText(licenseText.toString());
  96. JScrollPane licenses = new JScrollPane(license, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  97. licenses.setPreferredSize(new Dimension(150, 150));
  98. center.add(licenses, BorderLayout.NORTH);
  99. center.add(getChooserPanel(), BorderLayout.CENTER);
  100. return center;
  101. }
  102. private JComponent getChooserPanel() {
  103. JPanel p = new JPanel(new BorderLayout());
  104. p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
  105. p.setOpaque(false);
  106. JLabel l = new JLabel("Please choose installation directory:");
  107. l.setVerticalAlignment(JLabel.NORTH);
  108. l.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
  109. p.add(l, BorderLayout.NORTH);
  110. table = new JTable(installations);
  111. table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  112. table.setColumnSelectionAllowed(false);
  113. table.setDefaultRenderer(Object.class, new InstallationTableCellRenderer());
  114. table.getColumnModel().getColumn(0).setHeaderValue("Directory");
  115. table.getColumnModel().getColumn(0).setPreferredWidth(300);
  116. table.getColumnModel().getColumn(1).setHeaderValue("Java Version");
  117. table.getColumnModel().getColumn(3).setPreferredWidth(100);
  118. table.getColumnModel().getColumn(2).setHeaderValue("Type");
  119. table.getColumnModel().getColumn(3).setPreferredWidth(100);
  120. table.getColumnModel().getColumn(3).setHeaderValue("Replaced by DCEVM?");
  121. table.getColumnModel().getColumn(3).setPreferredWidth(200);
  122. table.getColumnModel().getColumn(4).setHeaderValue("Installed altjvm?");
  123. table.getColumnModel().getColumn(4).setPreferredWidth(200);
  124. JScrollPane lists = new JScrollPane(table);
  125. lists.setPreferredSize(new Dimension(900, 200));
  126. p.add(lists, BorderLayout.CENTER);
  127. return p;
  128. }
  129. private JComponent getBottomPanel() {
  130. JPanel left = new JPanel(new FlowLayout());
  131. left.add(new JButton(new AddDirectoryAction(this, installations, ConfigurationInfo.current())));
  132. JPanel right = new JPanel(new FlowLayout());
  133. //right.add(new JButton(new TestAction(table, installer)));
  134. right.add(new JButton(new InstallUninstallAction(InstallUninstallAction.Type.UNINSTALL, table)));
  135. right.add(new JButton(new InstallUninstallAction(InstallUninstallAction.Type.INSTALL, table)));
  136. right.add(new JButton(new InstallUninstallAction(InstallUninstallAction.Type.INSTALL_ALTJVM, table)));
  137. JPanel bottom = new JPanel(new BorderLayout());
  138. bottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  139. bottom.add(left, BorderLayout.WEST);
  140. bottom.add(right, BorderLayout.EAST);
  141. return bottom;
  142. }
  143. }