1 /* 2 * $Id$ 3 * 4 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Oracle designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Oracle in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24 * or visit www.oracle.com if you need additional information or have any 25 * questions. 26 */ 27 package com.sun.javatest.tool.jthelp; 28 29 import com.sun.javatest.tool.UIFactory; 30 31 import javax.swing.*; 32 import java.awt.*; 33 import java.beans.PropertyChangeEvent; 34 import java.beans.PropertyChangeListener; 35 36 public class JTHelpProgressBar extends Component implements PropertyChangeListener { 37 38 private JProgressBar progressBar; 39 private SwingWorker task; 40 private JDialog frame; 41 private JPanel сontentPane; 42 private UIFactory uif; 43 44 45 public JTHelpProgressBar(SwingWorker progressTask) { 46 uif = new UIFactory(this, null); 47 48 task = progressTask; 49 сontentPane = new JPanel(new BorderLayout()); 50 JLabel waitText = uif.createLabel("help.wait"); 51 progressBar = uif.createProgressBar("help.progress", JProgressBar.HORIZONTAL); 52 53 progressBar.setMinimum(0); 54 progressBar.setMaximum(100); 55 progressBar.setValue(0); 56 progressBar.setStringPainted(true); 57 58 JPanel panel = new JPanel(); 59 panel.add(waitText); 60 panel.add(progressBar); 61 62 сontentPane.add(panel, BorderLayout.PAGE_START); 63 } 64 65 public void propertyChange(PropertyChangeEvent evt) { 66 if ("progress".equals(evt.getPropertyName())) { 67 final int progress = (Integer) evt.getNewValue(); 68 SwingUtilities.invokeLater(new Runnable() { 69 public void run() { 70 progressBar.setValue(progress); 71 } 72 }); 73 } 74 if (SwingWorker.StateValue.DONE == evt.getNewValue()) { 75 SwingUtilities.invokeLater(new Runnable() { 76 public void run() { 77 frame.dispose(); 78 } 79 }); 80 } 81 } 82 83 84 public void createAndShowGUI() { 85 86 frame = new JDialog(); 87 frame.setModal(true); 88 frame.setUndecorated(true); 89 frame.getRootPane().setBorder(BorderFactory.createLineBorder(uif.getI18NColor("help.progress")) ); 90 91 сontentPane.setOpaque(true); 92 frame.setContentPane(сontentPane); 93 frame.pack(); 94 95 final Toolkit toolkit = Toolkit.getDefaultToolkit(); 96 final Dimension screenSize = toolkit.getScreenSize(); 97 final int x = (screenSize.width - frame.getWidth()) / 2; 98 final int y = (screenSize.height - frame.getHeight()) / 2; 99 frame.setLocation(x, y); 100 101 task.addPropertyChangeListener(JTHelpProgressBar.this); 102 task.execute(); 103 104 frame.setVisible(true); 105 106 } 107 108 }