1 | //////////////////////////////////////////////////////////////////////// |
---|
2 | // |
---|
3 | // This file ProgressFrame.java is part of SURFEX. |
---|
4 | // |
---|
5 | //////////////////////////////////////////////////////////////////////// |
---|
6 | |
---|
7 | //////////////////////////////////////////////////////////////////////// |
---|
8 | // |
---|
9 | // SURFEX version 0.90.00 |
---|
10 | // ================= |
---|
11 | // |
---|
12 | // Saarland University at Saarbruecken, Germany |
---|
13 | // Department of Mathematics and Computer Science |
---|
14 | // |
---|
15 | // SURFEX on the web: www.surfex.AlgebraicSurface.net |
---|
16 | // |
---|
17 | // Authors: Oliver Labs (2001-2008), Stephan Holzer (2004-2005) |
---|
18 | // |
---|
19 | // Copyright (C) 2001-2008 |
---|
20 | // |
---|
21 | // |
---|
22 | // *NOTICE* |
---|
23 | // ======== |
---|
24 | // |
---|
25 | // This program is free software; you can redistribute it and/or modify it |
---|
26 | // under the terms of the GNU General Public License as published by the |
---|
27 | // Free Software Foundation ( version 3 or later of the License ). |
---|
28 | // |
---|
29 | // See LICENCE.TXT for details. |
---|
30 | // |
---|
31 | ///////////////////////////////////////////////////////////////////////// |
---|
32 | |
---|
33 | import java.awt.*; |
---|
34 | import java.awt.event.*; |
---|
35 | import javax.swing.*; |
---|
36 | |
---|
37 | public class ProgressFrame extends JPanel |
---|
38 | implements ActionListener { |
---|
39 | public final static int ONE_SECOND = 1000; |
---|
40 | |
---|
41 | private JProgressBar progressBar; |
---|
42 | private Timer timer; |
---|
43 | private JButton startButton; |
---|
44 | // private LongTask task; |
---|
45 | private JTextArea taskOutput; |
---|
46 | private String newline = "\n"; |
---|
47 | |
---|
48 | public boolean processCanceled=false; |
---|
49 | |
---|
50 | JButton playMovieButton=new JButton("play Movie"); |
---|
51 | |
---|
52 | JButton cancelButton=new JButton("cancel"); |
---|
53 | |
---|
54 | JButton closeButton=new JButton("close"); |
---|
55 | |
---|
56 | JLabel previewLabel=new JLabel(new ImageIcon("prevstart.jpg")); |
---|
57 | |
---|
58 | public ProgressFrame(int LengthOfTask) { |
---|
59 | super(new BorderLayout()); |
---|
60 | //task = new LongTask(); |
---|
61 | |
---|
62 | |
---|
63 | ImageIcon i=new ImageIcon(); |
---|
64 | |
---|
65 | progressBar = new JProgressBar(0, LengthOfTask); |
---|
66 | progressBar.setValue(0); |
---|
67 | progressBar.setStringPainted(true); |
---|
68 | |
---|
69 | taskOutput = new JTextArea(5, 20); |
---|
70 | taskOutput.setMargin(new Insets(5,5,5,5)); |
---|
71 | taskOutput.setEditable(false); |
---|
72 | taskOutput.setCursor(null); //inherit the panel's cursor |
---|
73 | //see bug 4851758 |
---|
74 | |
---|
75 | //Create and set up the content pane. |
---|
76 | JPanel pane=new JPanel(new BorderLayout()); |
---|
77 | JPanel progressPanel = new JPanel(new BorderLayout()); |
---|
78 | progressPanel.add(progressBar,BorderLayout.NORTH); |
---|
79 | progressPanel.add(new JScrollPane(taskOutput),BorderLayout.CENTER); |
---|
80 | // progressPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); |
---|
81 | |
---|
82 | pane.add(progressPanel,BorderLayout.NORTH); |
---|
83 | JPanel previewPanel =new JPanel(new BorderLayout()); |
---|
84 | previewPanel.add(new JLabel("last frame:"),BorderLayout.WEST); |
---|
85 | //previewLabel.setSize(100,100); |
---|
86 | previewPanel.add(new JScrollPane(previewLabel),BorderLayout.CENTER); |
---|
87 | pane.add(previewPanel,BorderLayout.CENTER); |
---|
88 | // System.out.println("dsfkgreg--------------"); |
---|
89 | JPanel controlPanel=new JPanel(new GridLayout(1,3)); |
---|
90 | |
---|
91 | playMovieButton.setEnabled(false); |
---|
92 | controlPanel.add(playMovieButton); |
---|
93 | cancelButton.addActionListener(new ActionListener(){ |
---|
94 | public void actionPerformed(ActionEvent ae){ |
---|
95 | processCanceled=true; |
---|
96 | } |
---|
97 | |
---|
98 | }); |
---|
99 | controlPanel.add(cancelButton); |
---|
100 | // controlPanel.add(closeButton); |
---|
101 | pane.add(controlPanel,BorderLayout.SOUTH); |
---|
102 | // newContentPane.setOpaque(true); //content panes must be opaque |
---|
103 | //frame.setContentPane(pane); |
---|
104 | |
---|
105 | |
---|
106 | //JPanel panel = new JPanel(); |
---|
107 | //panel.add(progressBar); |
---|
108 | |
---|
109 | add(pane, BorderLayout.CENTER); |
---|
110 | //add(new JScrollPane(taskOutput), BorderLayout.CENTER); |
---|
111 | setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); |
---|
112 | |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * Called when the user presses the start button. |
---|
118 | */ |
---|
119 | public void actionPerformed(ActionEvent evt) { |
---|
120 | startButton.setEnabled(false); |
---|
121 | setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
---|
122 | // task.go(); |
---|
123 | timer.start(); |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | public void refresh(int progress, String Message){ |
---|
129 | progressBar.setValue(progress); |
---|
130 | // System.out.println("---"); |
---|
131 | String s = Message; |
---|
132 | if (s != null) { |
---|
133 | taskOutput.append(s + newline); |
---|
134 | taskOutput.setCaretPosition( |
---|
135 | taskOutput.getDocument().getLength()); |
---|
136 | } |
---|
137 | |
---|
138 | } |
---|
139 | |
---|
140 | public void refresh(int progress, String Message, String prevFileLoc){ |
---|
141 | refresh(progress, Message); |
---|
142 | // previewLabel.setText(prevFileLoc); |
---|
143 | previewLabel.setIcon(new ImageIcon(prevFileLoc)); |
---|
144 | // System.out.println("preview update"); |
---|
145 | } |
---|
146 | |
---|
147 | } |
---|
148 | |
---|