[Schmitzm-commits] r2359 - in trunk/schmitzm-core/src/main/java/de/schmitzm/swing: . dnd plaf

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Jul 18 12:30:11 CEST 2013


Author: mojays
Date: 2013-07-18 12:30:11 +0200 (Thu, 18 Jul 2013)
New Revision: 2359

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicListUI.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/GUIBuilder.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/JList.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ListMaintainancePanel.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/dnd/ListingDropTargetListener.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicTextAreaUI.java
Log:
schmitz-JList: replaced by AdaptableBackgroundBasicListUI
GUIBuilder: methods to change UI constants to adapt background and foreground colors

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/GUIBuilder.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/GUIBuilder.java	2013-07-17 21:57:52 UTC (rev 2358)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/GUIBuilder.java	2013-07-18 10:30:11 UTC (rev 2359)
@@ -43,9 +43,12 @@
 import javax.swing.JTextField;
 import javax.swing.JToggleButton;
 import javax.swing.JToolBar;
+import javax.swing.UIManager;
 
 import org.apache.commons.lang.StringUtils;
 
+import de.schmitzm.swing.plaf.AdaptableBackgroundBasicListUI;
+import de.schmitzm.swing.plaf.AdaptableBackgroundBasicTextAreaUI;
 import de.schmitzm.temp.BaseTypeUtil;
 
 /**
@@ -73,7 +76,75 @@
   /** Color for section labels in the frames. */
   public final Color COLOR_SECTION_LABEL = new Color(0,51,153); // dark blue
 
+
   /**
+   * Changes the {@link UIManager} L&F properties. Calls
+   * <ul>
+   *   <li>{@link #changeUI_DisabledTextAreaBackgroundToGray()}</li>
+   *   <li>{@link #changeUI_DisabledListBackgroundToGray()}</li>
+   *   <li>{@link #changeUI_DisabledForegroundToBlack()}</li>
+   * </ul>
+   */
+  public void changeUI() {
+    changeUI_DisabledTextAreaBackgroundToGray();
+    changeUI_DisabledListBackgroundToGray();
+    changeUI_DisabledForegroundToBlack();
+  }
+  
+  /**
+   * Changes the {@link UIManager} L&F properties so that the foreground/text
+   * for disabled/inactive fields is black, instead of grey (for better
+   * readability).<br>
+   * This method should be called in {@code main()} method before any GUI
+   * component is created!
+   */
+  public void changeUI_DisabledForegroundToBlack() {
+    // text should be shown in black (better readable!), even
+    // when text component is diabled 
+    UIManager.put("FormattedTextField.inactiveForeground", Color.BLACK);
+    UIManager.put("TextField.inactiveForeground", Color.BLACK);
+    UIManager.put("TextPane.inactiveForeground", Color.BLACK);
+    UIManager.put("TextArea.inactiveForeground", Color.BLACK);
+    UIManager.put("ComboBox.disabledForeground", Color.BLACK);
+    // unfortunately disabled list foreground can not be set
+    // explicitly, so we have to set it for labels in general
+    UIManager.put("Label.disabledForeground", Color.BLACK);
+    UIManager.put("Label.disabledShadow", UIManager.getColor("Label.background"));
+  }
+  
+  /**
+   * Changes the {@link UIManager} L&F properties so that the background for
+   * disabled/inactive text areas is gray (like one-line text fields).<br>
+   * This method should be called in {@code main()} method before any GUI
+   * component is created!
+   */
+  public void changeUI_DisabledTextAreaBackgroundToGray() {
+    // Use alternative implementation for JTextArea, because standard
+    // BasicTextAreaUI does not apply the UI constant "TextPane.inactiveBackground"
+    // as we want it (because of "BugFix" 6420149; see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6420149)
+    UIManager.put("TextAreaUI",AdaptableBackgroundBasicTextAreaUI.class.getName());
+    
+    // multi-line text panels should be grayed in
+    // disabled mode like JTextField
+    UIManager.put("TextArea.inactiveBackground", UIManager.getColor("TextField.inactiveBackground"));
+    UIManager.put("TextPane.inactiveBackground", UIManager.getColor("TextField.inactiveBackground"));
+  }
+  
+  /**
+   * Changes the {@link UIManager} L&F properties so that the background for
+   * disabled/inactive lists is gray (like one-line text fields).<br>
+   * This method should be called in {@code main()} method before any GUI
+   * component is created!
+   */
+  public void changeUI_DisabledListBackgroundToGray() {
+    // Use alternative implementation for JList, because standard
+    // BasicListUI is not grayed in disabled mode
+    UIManager.put("ListUI",AdaptableBackgroundBasicListUI.class.getName());
+    // disabled mode like JTextField
+    UIManager.put("List.inactiveBackground", UIManager.getColor("TextField.inactiveBackground"));
+  }
+  
+  /**
    * Creates a menu item, standardized for the application.
    * 
    * @param title

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/JList.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/JList.java	2013-07-17 21:57:52 UTC (rev 2358)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/JList.java	2013-07-18 10:30:11 UTC (rev 2359)
@@ -35,10 +35,13 @@
 import javax.swing.ListModel;
 import javax.swing.UIManager;
 
+import de.schmitzm.swing.plaf.AdaptableBackgroundBasicListUI;
+
 /**
  * {@link javax.swing.JList} which background is grayed like
  * {@link JTextField} in disabled state.
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ * @deprecated replaced by PLAF component {@link AdaptableBackgroundBasicListUI}
  */
 public class JList<E> extends javax.swing.JList<E> {
   

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ListMaintainancePanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ListMaintainancePanel.java	2013-07-17 21:57:52 UTC (rev 2358)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ListMaintainancePanel.java	2013-07-18 10:30:11 UTC (rev 2359)
@@ -12,6 +12,7 @@
 
 import javax.swing.Action;
 import javax.swing.JButton;
+import javax.swing.JList;
 import javax.swing.JScrollPane;
 import javax.swing.event.ListDataListener;
 import javax.swing.event.ListSelectionEvent;

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/dnd/ListingDropTargetListener.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/dnd/ListingDropTargetListener.java	2013-07-17 21:57:52 UTC (rev 2358)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/dnd/ListingDropTargetListener.java	2013-07-18 10:30:11 UTC (rev 2359)
@@ -36,12 +36,11 @@
 import java.awt.dnd.DropTargetDropEvent;
 import java.awt.dnd.DropTargetListener;
 
+import javax.swing.JList;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.SwingUtilities;
 
-import de.schmitzm.swing.JList;
-
 /**
  * Abstract super class for several list drop targets ({@link JList} or {@link JTable}).
  * 

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicListUI.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicListUI.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicListUI.java	2013-07-18 10:30:11 UTC (rev 2359)
@@ -0,0 +1,104 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing.plaf;
+
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JComponent;
+import javax.swing.JList;
+import javax.swing.UIManager;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicListUI;
+
+import de.schmitzm.swing.GUIBuilder;
+
+/**
+ * Acts like {@link BasicListUI} with the exception that the background of a
+ * non-editable {@link JList} is set as defined in UI constant "List.inactiveBackground"
+ * when enabled/editable state changes (behavior of standard {@link BasicListUI} is
+ * to keep normal background in inactive mode).<br>
+ * <br>
+ * To use this {@link JList} implementation, it has to be installed in {@link UIManager} by<br>
+ * {@code UIManager.put("ListUI",AdaptableBackgroundBasicListUI.class.getName());}<br>
+ * Furthermore the inactive background color has to be specified, e.g. by<br>
+ * {@code UIManager.put("List.inactiveBackground",UIManager.getColor("TextField.inactiveBackground"));}<br>
+ * <br>
+ * You can use {@link GUIBuilder#changeUI_DisabledListBackgroundToGray()} to process both actions.
+ * @author Martin O.J. Schmitz
+ */
+public class AdaptableBackgroundBasicListUI extends BasicListUI implements PropertyChangeListener {
+
+  /**
+   * Constructor method.
+   */
+  public static ComponentUI createUI(JComponent c) {
+      return new AdaptableBackgroundBasicListUI();
+  }
+
+  /**
+   * Installer method.
+   */
+  @Override
+  public void installUI(JComponent c) {
+    super.installUI(c);
+    c.addPropertyChangeListener(this);
+    updateBackground((JList<?>)c, ((JList<?>)c).isEnabled());
+  }
+
+
+  /**
+   * Reacts on editable/enabled change with call of {@link #updateBackground(JList,boolean)}.
+   */
+  @Override
+  public void propertyChange(java.beans.PropertyChangeEvent evt) {
+    if ( !(evt.getSource() instanceof JList) )
+      return;
+    JList<?> list = (JList<?>)evt.getSource();
+    if (evt.getPropertyName().equals("editable") ||
+        evt.getPropertyName().equals("enabled")) {
+      updateBackground(list, (Boolean)evt.getNewValue());
+    }
+  }
+
+  /**
+   * Updates the background according to UI constants "List.background",
+   * and "List.inactiveBackground".
+   */
+  protected void updateBackground(JList<?> c, boolean enabled) {
+//    System.out.println(UIManager.get("List.inactiveBackground"));
+    if ( enabled ) {
+      // normal background in enabled mode
+      c.setBackground( UIManager.getColor("List.background") );
+    } else {
+      // grayed background in disabled mode
+      c.setBackground( UIManager.getColor("List.inactiveBackground") );
+    }
+  }
+}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicTextAreaUI.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicTextAreaUI.java	2013-07-17 21:57:52 UTC (rev 2358)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/plaf/AdaptableBackgroundBasicTextAreaUI.java	2013-07-18 10:30:11 UTC (rev 2359)
@@ -38,6 +38,8 @@
 import javax.swing.plaf.UIResource;
 import javax.swing.plaf.basic.BasicTextAreaUI;
 
+import de.schmitzm.swing.GUIBuilder;
+
 /**
  * Acts like {@link BasicTextAreaUI} with the exception
  * that the "BugFix" 6420149 (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6420149)
@@ -48,6 +50,8 @@
  * To use this {@link JTextArea} implementation, it has to be installed in {@link UIManager} by<br>
  * {@code UIManager.put("TextAreaUI",AdaptableBackgroundBasicTextAreaUI.class.getName());}<br>
  * <br>
+ * You can use {@link GUIBuilder#changeUI_DisabledListBackgroundToGray()} to process this action.
+ * <br> 
  * This class is predominantly copied from Paul Ebermann's
  * solution (https://groups.google.com/forum/#!msg/de.comp.lang.java/jYqUSQarnwg/WXjjyln7DKAJ).
  * @author Martin O.J. Schmitz
@@ -65,6 +69,7 @@
   /**
    * Installer method.
    */
+  @Override
   public void installUI(JComponent c) {
       super.installUI(c);
       updateBackground((JTextArea)c);
@@ -74,6 +79,7 @@
   /**
    * Reacts on editable/enabled change with call of {@link #updateBackground(JTextArea)}.
    */
+  @Override
   protected void propertyChange(java.beans.PropertyChangeEvent evt) {
     super.propertyChange(evt);
     if (evt.getPropertyName().equals("editable") ||



More information about the Schmitzm-commits mailing list