1:
31:
32: package ;
33:
34: import ;
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52: import ;
53:
54:
55:
66: public class ReportProgressDialog extends JDialog
67: {
68: private static class ScreenUpdateRunnable implements Runnable
69: {
70: private int page;
71: private int activity;
72: private int currentRow;
73:
74: private ScreenUpdateRunnable (final int activity,
75: final int currentRow,
76: final int page)
77: {
78: this.activity = activity;
79: this.currentRow = currentRow;
80: this.page = page;
81: }
82:
83: public void run ()
84: {
85:
86: }
87: }
88:
89: private class ReportProgressHandler implements ReportProgressListener
90: {
91: private ReportProgressHandler()
92: {
93: }
94:
95: public void reportProcessingStarted(final ReportProgressEvent event)
96: {
97: postUpdate(event);
98: }
99:
100: public void reportProcessingUpdate(final ReportProgressEvent event)
101: {
102: postUpdate(event);
103: }
104:
105: public void reportProcessingFinished(final ReportProgressEvent event)
106: {
107: postUpdate(event);
108: }
109:
110: private void postUpdate (final ReportProgressEvent event)
111: {
112: final ScreenUpdateRunnable runnable = new ScreenUpdateRunnable
113: (event.getActivity(), event.getRow(), event.getPage());
114: if (SwingUtilities.isEventDispatchThread())
115: {
116: runnable.run();
117: }
118: else
119: {
120: SwingUtilities.invokeLater(runnable);
121: }
122: }
123: }
124:
125: private static class ToFrontHandler extends WindowAdapter
126: {
127: private ToFrontHandler()
128: {
129: }
130:
131:
134: public void windowOpened (final WindowEvent e)
135: {
136: e.getWindow().toFront();
137: }
138: }
139:
140:
143: private JLabel messageCarrier;
144:
147: private JLabel passCountMessage;
148:
151: private JLabel pageCountMessage;
152:
155: private JLabel rowCountMessage;
156:
159: private JProgressBar progressBar;
160:
163: private MessageFormat pageMessageFormatter;
164:
167: private MessageFormat rowsMessageFormatter;
168:
171: private MessageFormat passMessageFormatter;
172:
173:
176: private int lastPage;
177:
180: private int lastPass;
181:
184: private int lastMaxRow;
185:
188: private Integer lastMaxRowInteger;
189:
192: private String layoutText;
193:
196: private String outputText;
197:
198:
199:
202: private ResourceBundle resources;
203:
204:
209: public ReportProgressDialog (final Dialog dialog)
210: {
211: super(dialog);
212: setLocale(dialog.getLocale());
213: initConstructor();
214: }
215:
216:
221: public ReportProgressDialog (final Frame frame)
222: {
223: super(frame);
224: setLocale(frame.getLocale());
225: initConstructor();
226: }
227:
228:
232: public ReportProgressDialog ()
233: {
234: initConstructor();
235: }
236:
237:
240: private void initConstructor ()
241: {
242: resources = ResourceBundle.getBundle
243: (GuiCommonModule.RESOURCE_BASE_NAME, getLocale());
244: initialize();
245: addWindowListener(new ToFrontHandler());
246:
247: setOutputText(resources.getString("progress-dialog.perform-output"));
248: setLayoutText(resources.getString("progress-dialog.prepare-layout"));
249:
250: lastPass = -1;
251: lastMaxRow = -1;
252: lastPage = -1;
253: }
254:
255:
258: private void initialize ()
259: {
260: final JPanel contentPane = new JPanel();
261: contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
262: contentPane.setLayout(new GridBagLayout());
263:
264: pageMessageFormatter = new MessageFormat(resources.getString("progress-dialog.page-label"));
265: rowsMessageFormatter = new MessageFormat(resources.getString("progress-dialog.rows-label"));
266: passMessageFormatter = new MessageFormat(resources.getString("progress-dialog.pass-label"));
267:
268: messageCarrier = new JLabel(" ");
269: passCountMessage = new JLabel(" ");
270: rowCountMessage = new JLabel(" ");
271: pageCountMessage = new JLabel(" ");
272: progressBar = new JProgressBar();
273:
274: GridBagConstraints gbc = new GridBagConstraints();
275: gbc.gridx = 0;
276: gbc.gridy = 0;
277: gbc.gridwidth = 2;
278: gbc.fill = GridBagConstraints.HORIZONTAL;
279: gbc.weightx = 1;
280: gbc.anchor = GridBagConstraints.WEST;
281: gbc.insets = new Insets(3, 1, 5, 1);
282: gbc.ipadx = 200;
283: contentPane.add(messageCarrier, gbc);
284:
285: gbc = new GridBagConstraints();
286: gbc.gridx = 0;
287: gbc.gridy = 1;
288: gbc.gridwidth = 2;
289: gbc.anchor = GridBagConstraints.SOUTHWEST;
290: gbc.insets = new Insets(3, 1, 1, 1);
291: contentPane.add(passCountMessage, gbc);
292:
293: gbc = new GridBagConstraints();
294: gbc.gridx = 0;
295: gbc.gridy = 2;
296: gbc.gridwidth = 2;
297: gbc.anchor = GridBagConstraints.WEST;
298: gbc.fill = GridBagConstraints.HORIZONTAL;
299: gbc.weightx = 1;
300: gbc.insets = new Insets(3, 1, 1, 1);
301: contentPane.add(progressBar, gbc);
302:
303: gbc = new GridBagConstraints();
304: gbc.gridx = 0;
305: gbc.gridy = 3;
306: gbc.gridwidth = 1;
307: gbc.weighty = 1;
308: gbc.anchor = GridBagConstraints.NORTHWEST;
309: gbc.insets = new Insets(3, 1, 1, 1);
310: contentPane.add(pageCountMessage, gbc);
311:
312: gbc = new GridBagConstraints();
313: gbc.gridx = 1;
314: gbc.gridy = 3;
315: gbc.gridwidth = 1;
316: gbc.anchor = GridBagConstraints.NORTHWEST;
317: gbc.insets = new Insets(3, 10, 1, 1);
318: gbc.weightx = 1;
319: gbc.fill = GridBagConstraints.HORIZONTAL;
320: contentPane.add(rowCountMessage, gbc);
321:
322: setContentPane(contentPane);
323: }
324:
325:
330: public String getMessage ()
331: {
332: return messageCarrier.getText();
333: }
334:
335:
340: public void setMessage (final String message)
341: {
342: messageCarrier.setText(message);
343: }
344:
345:
350: protected void updatePageMessage (final int page)
351: {
352: if (lastPage != page)
353: {
354: final Object[] parameters = new Object[]{new Integer(page)};
355: pageCountMessage.setText(pageMessageFormatter.format(parameters));
356: lastPage = page;
357: }
358: }
359:
360:
366: protected void updateRowsMessage (final int rows, final int maxRows)
367: {
368: if (maxRows != lastMaxRow)
369: {
370: lastMaxRowInteger = new Integer(maxRows);
371: lastMaxRow = maxRows;
372: }
373: final Object[] parameters = new Object[]{
374: new Integer(rows),
375: lastMaxRowInteger
376: };
377: rowCountMessage.setText(rowsMessageFormatter.format(parameters));
378: }
379:
380:
388: protected void updatePassMessage (final int pass, final boolean prepare)
389: {
390: if (lastPass != pass)
391: {
392: lastPass = pass;
393: if (pass >= 0)
394: {
395: final Object[] parameters = new Object[]{new Integer(pass)};
396: passCountMessage.setText(passMessageFormatter.format(parameters));
397: }
398: else
399: {
400: final String message;
401: if (prepare)
402: {
403: message = getLayoutText();
404: }
405: else
406: {
407: message = getOutputText();
408: }
409: passCountMessage.setText(message);
410: }
411: }
412: }
413:
414:
419: protected final JLabel getPassCountMessage ()
420: {
421: return passCountMessage;
422: }
423:
424:
429: protected final JLabel getPageCountMessage ()
430: {
431: return pageCountMessage;
432: }
433:
434:
439: protected final JLabel getRowCountMessage ()
440: {
441: return rowCountMessage;
442: }
443:
444:
449: protected final MessageFormat getPageMessageFormatter ()
450: {
451: return pageMessageFormatter;
452: }
453:
454:
459: protected final MessageFormat getRowsMessageFormatter ()
460: {
461: return rowsMessageFormatter;
462: }
463:
464:
469: protected final MessageFormat getPassMessageFormatter ()
470: {
471: return passMessageFormatter;
472: }
473:
474:
480: public String getOutputText ()
481: {
482: return outputText;
483: }
484:
485:
491: public void setOutputText (final String outputText)
492: {
493: if (outputText == null)
494: {
495: throw new NullPointerException("OutputText must not be null.");
496: }
497: this.outputText = outputText;
498: }
499:
500:
506: public String getLayoutText ()
507: {
508: return layoutText;
509: }
510:
511:
517: public void setLayoutText (final String layoutText)
518: {
519: if (layoutText == null)
520: {
521: throw new NullPointerException("LayoutText must not be null.");
522: }
523: this.layoutText = layoutText;
524: }
525:
526: protected boolean isSameMaxRow (final int row)
527: {
528: return lastMaxRow == row;
529: }
530:
531: }