001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.gui;
012:
013: import java.awt.Color;
014: import java.awt.Dimension;
015: import java.awt.Font;
016: import java.awt.event.ComponentAdapter;
017: import java.awt.event.ComponentEvent;
018: import java.awt.event.ComponentListener;
019:
020: import javax.swing.*;
021: import javax.swing.border.BevelBorder;
022:
023: class MainStatusLine extends JPanel {
024: private JLabel text;
025: private JPanel progressPanel;
026: private JProgressBar progressBar;
027: private int max = 0;
028: //private JButton abortButton;
029: private boolean phantomBoxAdded = false;
030:
031: MainStatusLine(String p_initialText, Font p_font) {
032: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
033:
034: setBorder(new BevelBorder(BevelBorder.LOWERED));
035: setBackground(Color.gray);
036: setFont(p_font);
037: setOpaque(false);
038:
039: text = new JLabel(p_initialText);
040:
041: text.setIcon(IconFactory.keyLogo(35, 20));
042:
043: add(Box.createHorizontalGlue());
044: add(text);
045: add(Box.createHorizontalGlue());
046:
047: createProgressPanel();
048: progressPanel.setVisible(false);
049: add(progressPanel);
050:
051: setVisible(true);
052: }
053:
054: private void createProgressPanel() {
055: Dimension s;
056:
057: progressPanel = new JPanel();
058: progressPanel.setLayout(new BoxLayout(progressPanel,
059: BoxLayout.X_AXIS));
060:
061: progressBar = new JProgressBar(0, max);
062: progressBar.setValue(0);
063: progressBar.setStringPainted(true);
064:
065: s = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
066: progressBar.setMaximumSize(s);
067:
068: progressBar.setEnabled(true);
069: progressPanel.add(progressBar);
070:
071: // s = new Dimension ( 5, 5 );
072: // progressPanel.add ( Box.createRigidArea ( s ) );
073:
074: s = new Dimension(100, Short.MAX_VALUE);
075: progressPanel.setMaximumSize(s);
076: }
077:
078: /**
079: * The following methods should only be called from the event
080: * dispatching thread
081: */
082:
083: /**
084: * Make the status line display a standard message
085: */
086: public void reset() {
087: setProgressPanelVisible(false);
088: setStatusText("Integrated Deductive Software Design: Ready");
089: }
090:
091: /**
092: * Set the range of values the progress bar can display (see
093: * <code>setMaximum</code> of <code>ProgressBar</code>)
094: */
095: public void setProgressBarMaximum(int value) {
096: progressBar.setMaximum(value);
097: }
098:
099: /**
100: * Set the value the progress bar currently displays
101: */
102: public void setProgress(int value) {
103: progressBar.setValue(value);
104: }
105:
106: /**
107: * Set the visibility of the progress bar and the abort button
108: */
109: public void setProgressPanelVisible(boolean p_visible) {
110: progressPanel.setVisible(p_visible);
111:
112: if (p_visible) {
113: setProgress(0);
114:
115: // To avoid later resizing of the status line, add an
116: // invisible element with the same height as the abort button
117: if (!phantomBoxAdded) {
118: phantomBoxAdded = true;
119: ComponentListener phantomAdder = new ComponentAdapter() {
120: public void componentResized(ComponentEvent e) {
121: progressPanel.removeComponentListener(this );
122: Dimension s = progressPanel.getSize();
123: s = new Dimension(0, (int) s.getHeight());
124: add(Box.createRigidArea(s));
125: }
126: };
127: progressPanel.addComponentListener(phantomAdder);
128: }
129: }
130: }
131:
132: /**
133: * Make the status line display the given string, don't modify
134: * anything else
135: */
136: public void setStatusText(String s) {
137: text.setText(s);
138: }
139: }
|