[Schmitzm-commits] r2348 - in trunk/schmitzm-core/src/main/java/de/schmitzm: io swing
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Jun 13 15:55:17 CEST 2013
Author: mojays
Date: 2013-06-13 15:55:17 +0200 (Thu, 13 Jun 2013)
New Revision: 2348
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConsoleProgressBar.java
trunk/schmitzm-core/src/main/java/de/schmitzm/io/FileProcessor.java
trunk/schmitzm-core/src/main/java/de/schmitzm/io/ProgressUpdater.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarUpdater.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/StatusDialog.java
Log:
ProgressUpdater: new method showStatusMessage(.) to pipe status messages; DUMMY ProgressUpdater
ApplicationFrame: new method getStatusMess() to return the current status bar message
StatusDialog: new method getMessageLabel()
FileProcessor: JavaDoc updated
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConsoleProgressBar.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConsoleProgressBar.java 2013-06-10 23:38:43 UTC (rev 2347)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConsoleProgressBar.java 2013-06-13 13:55:17 UTC (rev 2348)
@@ -88,4 +88,13 @@
System.out.println();
}
+ /**
+ * Pipes the given message to {@link System#out System.out.print(.)}. Should not
+ * be called during progress bar is in progress.
+ */
+ @Override
+ public void showStatusMessage(String mess) {
+ System.out.print(mess);
+ }
+
}
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/FileProcessor.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/FileProcessor.java 2013-06-10 23:38:43 UTC (rev 2347)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/FileProcessor.java 2013-06-13 13:55:17 UTC (rev 2348)
@@ -100,6 +100,8 @@
/**
* Calls {@link #processFile(File)} for all files defined by
* the given files specification which may include wildcards.
+ * @param cancelOnError indicates whether the process is canceled in case of error (if {@code false}
+ * the failing files are ignored and the process continues with the remaining files)
* @param filesSpec defines the files to process (if {@code null} or empty
* array is given, the initial specification {@link #getFilesSpecifiation()}
* is used)
@@ -113,6 +115,8 @@
/**
* Calls {@link #processFile(File)} for all files defined by
* the given files specification which may include wildcards.
+ * @param cancelOnError indicates whether the process is canceled in case of error (if {@code false}
+ * the failing files are ignored and the process continues with the remaining files)
* @param filesSpec defines the files to process (if {@code null} or empty
* array is given, the initial specification {@link #getFilesSpecifiation()}
* is used)
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/ProgressUpdater.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/ProgressUpdater.java 2013-06-10 23:38:43 UTC (rev 2347)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/ProgressUpdater.java 2013-06-13 13:55:17 UTC (rev 2348)
@@ -39,8 +39,22 @@
*
*/
public interface ProgressUpdater {
-
/**
+ * {@link ProgressUpdater} which does nothing. Can be used if {@code null}
+ * is given as {@link ProgressUpdater} in process method.
+ */
+ public static final ProgressUpdater DUMMY = new AbstractProgressUpdater() {
+ @Override
+ public void updateProgress(double perc) {}
+
+ @Override
+ public void showStatusMessage(String mess) {}
+
+ @Override
+ public double getProgressPerc() { return 0; }
+ };
+
+ /**
* Returns the maximum value which represents 100%.
* @throws UnsupportedOperationException if {@link #initProgress(int, int)} was not yet called
*/
@@ -103,4 +117,9 @@
* during process.
*/
public void dispose();
+
+ /**
+ * Shows a status message-
+ */
+ public void showStatusMessage(String mess);
}
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java 2013-06-10 23:38:43 UTC (rev 2347)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java 2013-06-13 13:55:17 UTC (rev 2348)
@@ -34,7 +34,7 @@
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
*
*/
-public abstract class ApplicationFrame extends JFrame {
+public abstract class ApplicationFrame extends JFrame implements Disposable {
/** Holds the main content pane. */
protected Container contentPane;
/** Holds a panel, which can contain several tool bars.
@@ -46,7 +46,9 @@
/** Holds the status bar on the bottom of the frame.
* @see BorderLayout#SOUTH */
protected JComponent statusBar;
-
+ /** Holds the current status message */
+ protected String statusMess = "";
+
/**
* Creates a new frame.
*/
@@ -161,6 +163,7 @@
* @param statusMess a message
*/
public void setStatusMess(String statusMess) {
+ this.statusMess = statusMess;
if ( statusBar instanceof JLabel ) {
if ( StringUtils.isBlank(statusMess) )
statusMess = " "; // avoid that JLabel collapse on empty string!
@@ -174,6 +177,13 @@
}
/**
+ * Returns the current message of the status bar.
+ */
+ public String getStatusMess() {
+ return statusMess;
+ }
+
+ /**
* Sets the cursor of the main frame to {@link Cursor#WAIT_CURSOR}, to lock the frame.
*/
public void setWaitCursor() {
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarUpdater.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarUpdater.java 2013-06-10 23:38:43 UTC (rev 2347)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarUpdater.java 2013-06-13 13:55:17 UTC (rev 2348)
@@ -30,7 +30,10 @@
package de.schmitzm.swing;
import javax.swing.JProgressBar;
+import javax.swing.SwingUtilities;
+import org.apache.commons.lang.StringUtils;
+
import de.schmitzm.io.AbstractProgressUpdater;
import de.schmitzm.io.ProgressUpdater;
@@ -46,6 +49,9 @@
/** Holds the {@link JProgressBar} to be updated. */
protected JProgressBar progressBar = null;
+ /** Indicates whether the status message must be renewed on next {@link #showStatusMessage(String)}
+ * call. */
+ protected boolean renewStatusMess = true;
/**
* Creates a new updater.
@@ -121,4 +127,26 @@
return calculatePercentage(value);
}
+ /**
+ * If progress bar is a {@link ProgressBarWithText} the message is
+ * shown in {@link ProgressBarWithText}. Otherwise the method does nothing.
+ */
+ @Override
+ public void showStatusMessage(final String mess) {
+ if ( progressBar instanceof ProgressBarWithText ) {
+ SwingUtilities.invokeLater( new Runnable() {
+ @Override
+ public void run() {
+ ProgressBarWithText progressBarWithText = (ProgressBarWithText)progressBar;
+ if ( renewStatusMess )
+ progressBarWithText.setText(mess);
+ else
+ progressBarWithText.setText(progressBarWithText.getText() + mess);
+ }
+ });
+ }
+ // renew status mess (on next call) when message ends with carriage return
+ renewStatusMess = mess != null && mess.endsWith("\n");
+ }
+
}
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/StatusDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/StatusDialog.java 2013-06-10 23:38:43 UTC (rev 2347)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/StatusDialog.java 2013-06-13 13:55:17 UTC (rev 2348)
@@ -239,5 +239,12 @@
setDialogOption( CANCEL_OPTION );
getProgressBar().setValue(0);
}
+
+ /**
+ * Returns the {@link JLabel} which shows the message.
+ */
+ public JLabel getMessageLabel() {
+ return messageLabel;
+ }
}
More information about the Schmitzm-commits
mailing list