compat -> ui.compat
authorNiki Roo <niki@nikiroo.be>
Wed, 6 May 2020 15:33:12 +0000 (17:33 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 6 May 2020 15:33:12 +0000 (17:33 +0200)
src/be/nikiroo/utils/resources/Bundle.java
src/be/nikiroo/utils/ui/ListModel.java
src/be/nikiroo/utils/ui/UIUtils.java
src/be/nikiroo/utils/ui/compat/DefaultListModel6.java [moved from src/be/nikiroo/utils/compat/DefaultListModel6.java with 94% similarity]
src/be/nikiroo/utils/ui/compat/JList6.java [moved from src/be/nikiroo/utils/compat/JList6.java with 98% similarity]
src/be/nikiroo/utils/ui/compat/ListCellRenderer6.java [moved from src/be/nikiroo/utils/compat/ListCellRenderer6.java with 98% similarity]
src/be/nikiroo/utils/ui/compat/ListModel6.java [moved from src/be/nikiroo/utils/compat/ListModel6.java with 93% similarity]

index c757e2b1d705dc005b52ac425f7a9a89a14deabd..84efceafabfacac5d1edf887dc49f3542bd76725 100644 (file)
@@ -133,8 +133,8 @@ public class Bundle<E extends Enum<E>> {
         * @param def
         *            the default value when it is not present in the config file
         * 
-        * @return the associated value, or NULL if not found (not present in the
-        *         resource file)
+        * @return the associated value, or <tt>def</tt> if not found (not present
+        *         in the resource file)
         */
        public String getString(E id, String def) {
                return getString(id, def, -1);
@@ -154,8 +154,9 @@ public class Bundle<E extends Enum<E>> {
         *            the item number to get for an array of values, or -1 for
         *            non-arrays
         * 
-        * @return the associated value, or NULL if not found (not present in the
-        *         resource file)
+        * @return the associated value, <tt>def</tt> if not found (not present in
+        *         the resource file) or NULL if the item is specified (not -1) and
+        *         does not exist
         */
        public String getString(E id, String def, int item) {
                String rep = getString(id.name(), null);
@@ -163,7 +164,7 @@ public class Bundle<E extends Enum<E>> {
                        rep = getMetaDef(id.name());
                }
 
-               if (rep == null || rep.isEmpty()) {
+               if (rep.isEmpty()) {
                        return def;
                }
 
@@ -273,8 +274,9 @@ public class Bundle<E extends Enum<E>> {
         *            the item number to get for an array of values, or -1 for
         *            non-arrays
         * 
-        * @return the associated value, or NULL if not found (not present in the
-        *         resource file)
+        * @return the associated value, <tt>def</tt> if not found (not present in
+        *         the resource file), NULL if the item is specified (not -1) but
+        *         does not exist and NULL if bad key
         */
        public String getStringX(E id, String suffix, String def, int item) {
                String key = id.name()
@@ -932,7 +934,7 @@ public class Bundle<E extends Enum<E>> {
        }
 
        /**
-        * The default {@link MetaInfo.def} value for the given enumeration name.
+        * The default {@link Meta#def()} value for the given enumeration name.
         * 
         * @param id
         *            the enumeration name (the "id")
@@ -1209,22 +1211,18 @@ public class Bundle<E extends Enum<E>> {
         */
        protected void resetMap(ResourceBundle bundle) {
                this.map.clear();
-               for (Field field : type.getDeclaredFields()) {
-                       try {
-                               Meta meta = field.getAnnotation(Meta.class);
-                               if (meta != null) {
-                                       E id = Enum.valueOf(type, field.getName());
-
-                                       String value;
-                                       if (bundle != null) {
-                                               value = bundle.getString(id.name());
-                                       } else {
-                                               value = null;
+               if (bundle != null) {
+                       for (Field field : type.getDeclaredFields()) {
+                               try {
+                                       Meta meta = field.getAnnotation(Meta.class);
+                                       if (meta != null) {
+                                               E id = Enum.valueOf(type, field.getName());
+                                               String value = bundle.getString(id.name());
+                                               this.map.put(id.name(),
+                                                               value == null ? null : value.trim());
                                        }
-
-                                       this.map.put(id.name(), value == null ? null : value.trim());
+                               } catch (MissingResourceException e) {
                                }
-                       } catch (MissingResourceException e) {
                        }
                }
        }
index 12f6aa6217b0d66cda7a0fafe45997935284e6c6..d76c5dc2c169a595e6a90b48d41b110bac7d6a46 100644 (file)
@@ -14,9 +14,9 @@ import javax.swing.JPopupMenu;
 import javax.swing.ListCellRenderer;
 import javax.swing.SwingWorker;
 
-import be.nikiroo.utils.compat.DefaultListModel6;
-import be.nikiroo.utils.compat.JList6;
-import be.nikiroo.utils.compat.ListCellRenderer6;
+import be.nikiroo.utils.ui.compat.DefaultListModel6;
+import be.nikiroo.utils.ui.compat.JList6;
+import be.nikiroo.utils.ui.compat.ListCellRenderer6;
 
 /**
  * A {@link javax.swing.ListModel} that can maintain 2 lists; one with the
index 5861d00fc3a6e3a254230c8bd5d43a17d26299db..7d78d1e8c38669b118dab12828da99c351091b8c 100644 (file)
@@ -20,24 +20,45 @@ import javax.swing.UnsupportedLookAndFeelException;
  */
 public class UIUtils {
        /**
-        * Set a fake "native look &amp; feel" for the application if possible
+        * Set a fake "native Look &amp; Feel" for the application if possible
         * (check for the one currently in use, then try GTK).
         * <p>
         * <b>Must</b> be called prior to any GUI work.
+        * 
+        * @return TRUE if it succeeded
         */
-       static public void setLookAndFeel() {
+       static public boolean setLookAndFeel() {
                // native look & feel
+               String noLF = "javax.swing.plaf.metal.MetalLookAndFeel";
+               String lf = UIManager.getSystemLookAndFeelClassName();
+               if (lf.equals(noLF))
+                       lf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
+               
+               return setLookAndFeel(lf);
+       }
+
+       /**
+        * Switch to the given Look &amp; Feel for the application if possible
+        * (check for the one currently in use, then try GTK).
+        * <p>
+        * <b>Must</b> be called prior to any GUI work.
+        * 
+        * @param laf
+        *            the Look &amp; Feel to use
+        * 
+        * @return TRUE if it succeeded
+        */
+       static public boolean setLookAndFeel(String laf) {
                try {
-                       String noLF = "javax.swing.plaf.metal.MetalLookAndFeel";
-                       String lf = UIManager.getSystemLookAndFeelClassName();
-                       if (lf.equals(noLF))
-                               lf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
-                       UIManager.setLookAndFeel(lf);
+                       UIManager.setLookAndFeel(laf);
+                       return true;
                } catch (InstantiationException e) {
                } catch (ClassNotFoundException e) {
                } catch (UnsupportedLookAndFeelException e) {
                } catch (IllegalAccessException e) {
                }
+
+               return false;
        }
 
        /**
similarity index 94%
rename from src/be/nikiroo/utils/compat/DefaultListModel6.java
rename to src/be/nikiroo/utils/ui/compat/DefaultListModel6.java
index 114ac42eac73fd02ab7a9cbd8381ce5e00c00e5a..3f7552f879c7b42d32638a526ca5555a9f233a78 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.utils.compat;
+package be.nikiroo.utils.ui.compat;
 
 import javax.swing.DefaultListModel;
 import javax.swing.JList;
similarity index 98%
rename from src/be/nikiroo/utils/compat/JList6.java
rename to src/be/nikiroo/utils/ui/compat/JList6.java
index ca44165067d0676ad62861c3005dc5452fb19469..a504abb0db7519ddd63ab45b105f7dd6496093e7 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.utils.compat;
+package be.nikiroo.utils.ui.compat;
 
 import javax.swing.JList;
 import javax.swing.ListCellRenderer;
similarity index 98%
rename from src/be/nikiroo/utils/compat/ListCellRenderer6.java
rename to src/be/nikiroo/utils/ui/compat/ListCellRenderer6.java
index d00484982599dd6cd4e074743b1b6a3693ee3685..bc76e8002910fabe0022d0ff50525abe142c1853 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.utils.compat;
+package be.nikiroo.utils.ui.compat;
 
 import java.awt.Component;
 
similarity index 93%
rename from src/be/nikiroo/utils/compat/ListModel6.java
rename to src/be/nikiroo/utils/ui/compat/ListModel6.java
index a1f8c60766a29a2e54913359f3d56308ae392d8a..938da143759dbb8fbac1998fdea67170f01c925d 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.utils.compat;
+package be.nikiroo.utils.ui.compat;
 
 import javax.swing.JList;