View Javadoc
1   /*
2    * Copyright (c) 2000, 2002, 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  
25  package sun.jvm.hotspot.ui;
26  
27  import java.awt.*;
28  import javax.swing.*;
29  
30  /** A panel containing a progress bar and a label */
31  
32  public class ProgressBarPanel extends JPanel {
33    private JLabel text;
34    private JProgressBar bar;
35    private static final int MAX = 10000;
36  
37    public static final int VERTICAL   = 0;
38    public static final int HORIZONTAL = 1;
39  
40    public ProgressBarPanel() {
41      this(VERTICAL);
42    }
43  
44    /** LayoutType is either VERTICAL or HORIZONTAL */
45    public ProgressBarPanel(int layoutType) {
46      super();
47      if (layoutType == VERTICAL) {
48        setLayout(new BorderLayout());
49        text = new JLabel();
50        add(text, BorderLayout.NORTH);
51        bar = new JProgressBar(JProgressBar.HORIZONTAL, 0, MAX);
52        JPanel panel = new JPanel();
53        panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
54        panel.add(bar);
55        add(panel, BorderLayout.CENTER);
56      } else {
57        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
58        text = new JLabel();
59        add(text);
60        bar = new JProgressBar(JProgressBar.HORIZONTAL, 0, MAX);
61        add(bar);
62      }
63    }
64  
65    public ProgressBarPanel(String text) {
66      this();
67      setText(text);
68    }
69  
70    public ProgressBarPanel(int layoutType, String text) {
71      this(layoutType);
72      setText(text);
73    }
74  
75    public void setText(String text) {
76      this.text.setText(text);
77    }
78  
79    public void setValue(double val) {
80      int realVal = (int) (val * MAX);
81      bar.setValue(realVal);
82    }
83  
84    public void setIndeterminate(boolean value) {
85      bar.setIndeterminate(value);
86    }
87  }