1. /*
  2. * Copyright 2002-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.splash;
  18. import java.awt.BorderLayout;
  19. import java.awt.Color;
  20. import java.awt.Dimension;
  21. import java.awt.Font;
  22. import java.awt.Toolkit;
  23. import java.awt.event.ActionEvent;
  24. import java.awt.event.ActionListener;
  25. import javax.swing.BorderFactory;
  26. import javax.swing.ImageIcon;
  27. import javax.swing.JLabel;
  28. import javax.swing.JPanel;
  29. import javax.swing.JProgressBar;
  30. import javax.swing.JWindow;
  31. import org.apache.tools.ant.BuildEvent;
  32. import org.apache.tools.ant.BuildListener;
  33. class SplashScreen extends JWindow implements ActionListener, BuildListener {
  34. private JLabel text;
  35. private JProgressBar pb;
  36. private int total;
  37. private final int min = 0;
  38. private final int max = 200;
  39. public SplashScreen(String msg) {
  40. init(null);
  41. setText(msg);
  42. }
  43. public SplashScreen(ImageIcon img) {
  44. init(img);
  45. }
  46. protected void init(ImageIcon img) {
  47. JPanel pan = (JPanel) getContentPane();
  48. JLabel piccy;
  49. if (img == null) {
  50. piccy = new JLabel();
  51. } else {
  52. piccy = new JLabel(img);
  53. }
  54. piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1));
  55. text = new JLabel("Building....", JLabel.CENTER);
  56. text.setFont(new Font("Sans-Serif", Font.BOLD, 12));
  57. text.setBorder(BorderFactory.createEtchedBorder());
  58. pb = new JProgressBar(min, max);
  59. pb.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
  60. JPanel pan2 = new JPanel();
  61. pan2.setLayout(new BorderLayout());
  62. pan2.add(text, BorderLayout.NORTH);
  63. pan2.add(pb, BorderLayout.SOUTH);
  64. pan.setLayout(new BorderLayout());
  65. pan.add(piccy, BorderLayout.CENTER);
  66. pan.add(pan2, BorderLayout.SOUTH);
  67. pan.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
  68. pack();
  69. Dimension size = getSize();
  70. Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
  71. int x = (scr.width - size.width) / 2;
  72. int y = (scr.height - size.height) / 2;
  73. setBounds(x, y, size.width, size.height);
  74. }
  75. public void setText(String txt) {
  76. text.setText(txt);
  77. }
  78. public void actionPerformed(ActionEvent a) {
  79. if (total < max) {
  80. total++;
  81. } else {
  82. total = min;
  83. }
  84. pb.setValue(total);
  85. }
  86. public void buildStarted(BuildEvent event) {
  87. actionPerformed(null);
  88. }
  89. public void buildFinished(BuildEvent event) {
  90. pb.setValue(max);
  91. setVisible(false);
  92. dispose();
  93. }
  94. public void targetStarted(BuildEvent event) {
  95. actionPerformed(null);
  96. }
  97. public void targetFinished(BuildEvent event) {
  98. actionPerformed(null);
  99. }
  100. public void taskStarted(BuildEvent event) {
  101. actionPerformed(null);
  102. }
  103. public void taskFinished(BuildEvent event) {
  104. actionPerformed(null);
  105. }
  106. public void messageLogged(BuildEvent event) {
  107. actionPerformed(null);
  108. }
  109. }