[Schmitzm-commits] r1773 - trunk/schmitzm-core/src/main/java/de/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Nov 8 21:20:46 CET 2011


Author: mojays
Date: 2011-11-08 21:20:44 +0100 (Tue, 08 Nov 2011)
New Revision: 1773

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarWithText.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
new ProgressBarWithText


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java	2011-11-08 17:20:52 UTC (rev 1772)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java	2011-11-08 20:20:44 UTC (rev 1773)
@@ -11,10 +11,13 @@
 import javax.swing.BorderFactory;
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
+import javax.swing.JComponent;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuBar;
+import javax.swing.text.JTextComponent;
 
+import de.schmitzm.lang.LangUtil;
 import de.schmitzm.swing.menu.ToolBarsPanel;
 
 /**
@@ -30,16 +33,16 @@
  */
 public abstract class ApplicationFrame extends JFrame {
   /** Holds the main content pane. */
-  protected Container contentPane = null;
+  protected Container contentPane;
   /** Holds a panel, which can contain several tool bars.
    *  @see BorderLayout#NORTH */
-  protected ToolBarsPanel toolBarsPanel = null;
+  protected ToolBarsPanel toolBarsPanel;
   /** Global action listener, calling {@link #performAction(ActionEvent)}
    *  which can be used for the frame actions. */
   protected ActionListener menuActionListener;
   /** Holds the status bar on the bottom of the frame.
    *  @see BorderLayout#SOUTH */
-  protected JLabel statusBar = null;
+  protected JComponent statusBar;
 
   /**
    * Creates a new frame.
@@ -63,20 +66,18 @@
    */
   protected ApplicationFrame(String title, boolean pack, boolean initActions) {
     super(title);
-    contentPane = getContentPane();
+    createComponents();
     contentPane.setLayout(new BorderLayout());
 
     setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
 
+    
     JPanel statusContainer = new JPanel(new BorderLayout());
     statusContainer.setBorder(BorderFactory.createLoweredBevelBorder());
-    this.statusBar = new JLabel(" ");
-    this.statusBar.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
     statusContainer.add(statusBar, BorderLayout.CENTER);
     contentPane.add(statusContainer, BorderLayout.SOUTH);
     
-    this.toolBarsPanel = new ToolBarsPanel();
     contentPane.add(toolBarsPanel, BorderLayout.NORTH);
 
     this.setJMenuBar( new JMenuBar() );
@@ -94,6 +95,18 @@
     if( pack )
       pack();
   }
+
+  /**
+   * Creates the GUI components ({@link #contentPane}, {@link #statusBar} and
+   * {@link #toolBarsPanel}). Sub-classes can override this method to replace
+   * one or another by another instance.
+   */
+  protected void createComponents() {
+    this.statusBar = new JLabel(" ");
+    statusBar.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
+    this.toolBarsPanel = new ToolBarsPanel();
+    this.contentPane = getContentPane();
+  }
   
   /**
    * Checks for window closing to call {@link #dispose()} instead of simply terminate the application.
@@ -138,7 +151,14 @@
    * @param statusMess a message
    */
   public void setStatusMess(String statusMess) {
-      this.statusBar.setText(statusMess);
+    if ( statusBar instanceof JLabel )
+      ((JLabel)statusBar).setText(statusMess);
+    else if ( statusBar instanceof ProgressBarWithText )
+      ((ProgressBarWithText)statusBar).setText(statusMess);
+    else if ( statusBar instanceof JTextComponent )
+      ((JTextComponent)statusBar).setText(statusMess);
+    else
+      throw new UnsupportedOperationException("status bar component not yet supported: "+LangUtil.getSimpleClassName(statusBar));
   }
 
   /**

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarWithText.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarWithText.java	2011-11-08 17:20:52 UTC (rev 1772)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProgressBarWithText.java	2011-11-08 20:20:44 UTC (rev 1773)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz
+ ******************************************************************************/
+
+package de.schmitzm.swing;
+
+import java.awt.Graphics;
+
+import javax.swing.BoundedRangeModel;
+import javax.swing.JLabel;
+import javax.swing.JProgressBar;
+
+/**
+ * Extends the {@link JProgressBar} with a static text
+ * label which is drawn over the bar. 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ *
+ */
+public class ProgressBarWithText extends JProgressBar {
+  protected JLabel label = new JLabel("");
+  
+  /**
+   * Creates a new progress bar. 
+   */
+  public ProgressBarWithText() {
+    super();
+  }
+
+  /**
+   * Creates a new progress bar. 
+   */
+  public ProgressBarWithText(BoundedRangeModel newModel) {
+    super(newModel);
+  }
+
+  /**
+   * Creates a new progress bar. 
+   */
+  public ProgressBarWithText(int orient, int min, int max) {
+    super(orient, min, max);
+  }
+
+  /**
+   * Creates a new progress bar. 
+   */
+  public ProgressBarWithText(int min, int max) {
+    super(min, max);
+  }
+
+  /**
+   * Creates a new progress bar. 
+   */
+  public ProgressBarWithText(int orient) {
+    super(orient);
+  }
+
+  /**
+   * Returns the text shown on top of the bar.
+   */
+  public String getText() {
+    return label.getText();
+  }
+  
+  /**
+   * Returns the text shown on top of the bar.
+   */
+  public void setText(String text) {
+    label.setText(text);
+    repaint();
+  }
+  
+  /**
+   * Returns the label used to show the (static) text. This method can
+   * be used to configure the style (color, font) of the text.
+   * @see #setText(String)
+   */
+  public JLabel getTextLabel() {
+    return label;
+  }
+
+  /**
+   * In addition to paint the progress bar the {@link #labelText}
+   * is painted in the current foreground color.
+   */
+  @Override
+  public void paintComponent(Graphics g) {
+    super.paintComponent(g);
+    g.setXORMode(getBackground());
+    g = g.create();
+    g.translate(5, 0);
+    label.setSize(getSize());
+    label.paint(g);
+  }
+}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2011-11-08 17:20:52 UTC (rev 1772)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2011-11-08 20:20:44 UTC (rev 1773)
@@ -130,7 +130,8 @@
 public class SwingUtil {
 	private static final Logger LOGGER = Logger.getLogger(SwingUtil.class
 			.getClass().getName());
-	private static final JLabel DUMMY_LABEL = new JLabel("dummy");
+	/** A dummy label for default color and font */
+	public static final JLabel DUMMY_LABEL = new JLabel("dummy");
 
 	/**
 	 * {@link ResourceProvider}, der die Lokalisation fuer GUI-Komponenten des
@@ -166,7 +167,7 @@
 	public static final Font DEFAULT_FONT = new Font(Font.DIALOG, Font.PLAIN,
 			12);
 
-	// ****************************************************************************
+    // ****************************************************************************
 	// Diese Icons sind auf Basis der Icons von Gimp erstellt
 	// Eine Sammlung aller Gimp-Icons liegt im svn: gimp-tool-cursors.xcf
 	// ****************************************************************************



More information about the Schmitzm-commits mailing list