[cc-commits] [CC SVN] r14597 - in ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice: program ui/wikimedia

webmaster at creativecommons.org webmaster at creativecommons.org
Sat Jul 24 08:21:28 EDT 2010


Author: akila87
Date: 2010-07-24 12:21:28 +0000 (Sat, 24 Jul 2010)
New Revision: 14597

Modified:
   ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/program/WikimediaConnection.java
   ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchClickListener.java
   ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchThread.java
   ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/WikimediaDialog.java
Log:
*Search wikimedia images by license

Modified: ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/program/WikimediaConnection.java
===================================================================
--- ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/program/WikimediaConnection.java	2010-07-24 11:10:14 UTC (rev 14596)
+++ ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/program/WikimediaConnection.java	2010-07-24 12:21:28 UTC (rev 14597)
@@ -29,7 +29,7 @@
     protected WikimediaConnection() {
     }
 
-    public ArrayList<Image> searchPhotos(String[] tags, int currentPage) {
+    public ArrayList<Image> searchPhotos(String[] tags, String[] licenses) {
 
         imgList.removeAll(imgList);
         String tagLine = "";
@@ -38,7 +38,7 @@
         }
         tagLine = tagLine.replaceFirst("\\+", "");
         String title, imgUrl, imgUrlMainPage, imgUrlThumb, licenseNumber = " ", licenseURL = " ",
-                    licenseCode = "license info not available";
+                licenseCode = "license info not available";
         int width, height;
         try {
 
@@ -63,21 +63,21 @@
                     imgUrl = imageInfo.getAttributes().getNamedItem("url").getNodeValue();
                     imgUrlMainPage = imageInfo.getAttributes().getNamedItem("descriptionurl").getNodeValue();
                     width = Integer.parseInt(imageInfo.getAttributes().getNamedItem("width").getNodeValue());
-                    height = Integer.parseInt(imageInfo.getAttributes().getNamedItem("height").getNodeValue());                    
+                    height = Integer.parseInt(imageInfo.getAttributes().getNamedItem("height").getNodeValue());
                     imgUrlThumb = imgUrl.replace("/commons/", "/commons/thumb/").concat("/120px-"
                             + title.replaceAll("\\s", "_"));
                     if (title.contains(".svg")) {
                         imgUrlThumb = imgUrlThumb.concat(".png");
                         imgUrl = imgUrlThumb.replace("/120px-", "/400px-");
-                        height=400*height/width;
-                        width=400;
+                        height = 400 * height / width;
+                        width = 400;
                     } else if (width < 120 || height < 120) {
                         imgUrlThumb = imgUrl;
                     }
 
                     Image img = new Image(title, null, null, imgUrlThumb, null,
                             null, imgUrlMainPage, null, title, null);
-                    
+
                     NodeList listOfLicenses = page.getLastChild().getChildNodes();
                     for (int l = 0; l < listOfLicenses.getLength(); l++) {
                         String license = listOfLicenses.item(l).getAttributes().
@@ -100,35 +100,35 @@
                                             + licenseCode.toLowerCase().replace("cc-", "").replaceAll("\\-\\d\\.\\d", "/" + licenseNumber);
                                 }
                                 img.setLicenseURL(licenseURL);
-                                licenseCode = licenseCode.replace("-", " ").replaceAll("\\d\\.\\d", "");
+                                licenseCode = licenseCode.replaceAll("-\\d\\.\\d", "").replace("-", " ");
                                 img.setLicenseCode(licenseCode);
                             } else if (license.equalsIgnoreCase("CC-Zero")) {
                                 licenseCode = "CC0";
                                 licenseURL = "http://creativecommons.org/publicdomain/zero/1.0/";
                                 licenseNumber = "1.0";
                             }
-        
-                        } else if (license.startsWith("GFDL")&&(l==listOfLicenses.getLength()-1||licenseURL.equals(" "))) {
+
+                        } else if (license.startsWith("GFDL") && (l == listOfLicenses.getLength() - 1 || licenseURL.equals(" "))) {
                             licenseCode = "GFDL";
                             licenseURL = "http://www.gnu.org/licenses/fdl.html";
                             licenseNumber = " ";
-                        } else if (license.startsWith("LGPL")&&(l==listOfLicenses.getLength()-1||licenseURL.equals(" "))) {
+                        } else if (license.startsWith("LGPL") && (l == listOfLicenses.getLength() - 1 || licenseURL.equals(" "))) {
                             licenseCode = "LGPL";
                             licenseURL = "http://creativecommons.org/licenses/LGPL/2.1/";//http://www.gnu.org/licenses/lgpl.html
                             licenseNumber = " ";
-                        } else if (license.startsWith("GPL")&&(l==listOfLicenses.getLength()-1||licenseURL.equals(" "))) {
+                        } else if (license.startsWith("GPL") && (l == listOfLicenses.getLength() - 1 || licenseURL.equals(" "))) {
                             licenseCode = "GPL";
                             licenseURL = "http://creativecommons.org/licenses/GPL/2.0/";//http://www.gnu.org/licenses/gpl.html
                             licenseNumber = " ";
-                        } else if (license.startsWith("Copyrighted free use")&&(l==listOfLicenses.getLength()-1||licenseURL.equals(" "))) {
+                        } else if (license.startsWith("Copyrighted free use") && (l == listOfLicenses.getLength() - 1 || licenseURL.equals(" "))) {
                             licenseCode = "Copyrighted free use";
                             licenseURL = "-";
                             licenseNumber = " ";
-                        } else if (license.startsWith("FAL")&&(l==listOfLicenses.getLength()-1||licenseURL.equals(" "))) {
+                        } else if (license.startsWith("FAL") && (l == listOfLicenses.getLength() - 1 || licenseURL.equals(" "))) {
                             licenseCode = "Free Art License";
                             licenseURL = "http://artlibre.org/licence/lal/en";
                             licenseNumber = " ";
-                        }  
+                        }
                     }
                     img.setLicenseURL(licenseURL);
                     img.setLicenseCode(licenseCode);
@@ -136,10 +136,15 @@
                     img.setSelectedImageURL(imgUrl);
                     img.setSelectedImageWidth(width);
                     img.setSelectedImageHeight(height);
-                    System.out.println(imgUrlMainPage);
-                    System.out.println(licenseCode);
-                    System.out.println(licenseNumber);
-                    imgList.add(img);
+                    for (int i = 0; i < licenses.length; i++) {
+                        if (img.getLicenseCode().equals(licenses[i])) {
+                            imgList.add(img);
+                            System.out.println(imgUrlMainPage);
+                            System.out.println(licenseCode);
+                            System.out.println(licenseNumber);
+                            break;
+                        }
+                    }
                 }//end of if clause
             }//end of for loop with s var
 

Modified: ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchClickListener.java
===================================================================
--- ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchClickListener.java	2010-07-24 11:10:14 UTC (rev 14596)
+++ ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchClickListener.java	2010-07-24 12:21:28 UTC (rev 14597)
@@ -25,6 +25,10 @@
     }
     
     public void actionPerformed(ActionEvent a) {
+
+        if (!wikimediaDialog.IsInputValid()) {
+            return;
+        }
         SearchThread th = new SearchThread(wikimediaDialog,a.ActionCommand);
         th.start();
         

Modified: ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchThread.java
===================================================================
--- ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchThread.java	2010-07-24 11:10:14 UTC (rev 14596)
+++ ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/SearchThread.java	2010-07-24 12:21:28 UTC (rev 14597)
@@ -36,8 +36,8 @@
         ArrayList<Image> imgList = null;
         if (buttonName.equalsIgnoreCase(WikimediaDialog.BTN_SEARCH)) {
             wikimediaDialog.setCurrentPage(1);
-            WikimediaConnection.instance.searchPhotos(
-                    wikimediaDialog.GetTags(), wikimediaDialog.getCurrentPage());
+            String[] licenses = wikimediaDialog.getLicense();
+            WikimediaConnection.instance.searchPhotos(wikimediaDialog.GetTags(),licenses);
             imgList = new ArrayList<Image>();
             int currentPage = wikimediaDialog.getCurrentPage();
             int noOfImg = WikimediaDialog.SHOWRESULTSPERCOLUMN * WikimediaDialog.SHOWRESULTSPERROW;

Modified: ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/WikimediaDialog.java
===================================================================
--- ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/WikimediaDialog.java	2010-07-24 11:10:14 UTC (rev 14596)
+++ ccooo/branches/akila-gsoc-2010/src/org/creativecommons/openoffice/ui/wikimedia/WikimediaDialog.java	2010-07-24 12:21:28 UTC (rev 14597)
@@ -10,6 +10,7 @@
 import com.sun.star.awt.SystemPointer;
 import java.awt.Rectangle;
 import com.sun.star.awt.XButton;
+import com.sun.star.awt.XCheckBox;
 import com.sun.star.awt.XPointer;
 import com.sun.star.awt.XControl;
 import com.sun.star.awt.XControlContainer;
@@ -58,6 +59,12 @@
     private Image loadingImage = null;
     public static final String LBL_TAGS = "lblTags";
     public static final String TXT_TAGS = "txtTags";
+    public static final String CHK_COMMERCIALNAME = "chkCommercial";
+    public static final String CHK_COMMERCIALLABEL = "Search for works I can use for commercial purposes";
+    public static final String CHK_UPDATENAME = "chkUpdate";
+    public static final String CHK_UPDATELABEL = "Search for works I can modify, adapt, or build upon";
+    public static final String CHK_SHAREALKENAME = "chkShareAlike";
+    public static final String CHK_SHAREALKELABEL = "Include content which requires me to Share-Alike";
     //public static final String LBL_LICENSE = "lblLicense";
     //public static final String LISTBOX_LICENSE = "cmbLicense";    
     public static final String BTN_SEARCH = "btnSearch";
@@ -71,7 +78,7 @@
     public static final int SHOWRESULTSPERROW = 4;
     public static final int SHOWRESULTSPERCOLUMN = 4;
     public static final int POSITIONWIDTHHEIGHT = 45;//50
-    public static final int LOCATIONIMAGESY = 40;//100
+    public static final int LOCATIONIMAGESY = 80;//100
 
     /**
      * Creates a new instance of ChooserDialog
@@ -121,6 +128,28 @@
                     "com.sun.star.awt.UnoControlEditModel");
             createAWTControl(txtTags, TXT_TAGS, "", new Rectangle(30, 10, 150, 12));
 
+            Object chkCommercial = msfLicenseSelector.createInstance(
+                    "com.sun.star.awt.UnoControlCheckBoxModel");
+            XPropertySet xpsCHKProperties = createAWTControl(chkCommercial, CHK_COMMERCIALNAME, CHK_COMMERCIALLABEL,
+                    new Rectangle(10, 32, 150, 12));
+
+            xpsCHKProperties.setPropertyValue("TriState", Boolean.FALSE);
+            xpsCHKProperties.setPropertyValue("State", new Short((short) 1));
+
+            Object chkUpdate = msfLicenseSelector.createInstance(
+                    "com.sun.star.awt.UnoControlCheckBoxModel");
+            xpsCHKProperties = createAWTControl(chkUpdate, CHK_UPDATENAME, CHK_UPDATELABEL,
+                    new Rectangle(10, 49, 150, 12));
+            xpsCHKProperties.setPropertyValue("TriState", Boolean.FALSE);
+            xpsCHKProperties.setPropertyValue("State", new Short((short) 1));
+
+            Object chkShareAlike = msfLicenseSelector.createInstance(
+                    "com.sun.star.awt.UnoControlCheckBoxModel");
+            xpsCHKProperties = createAWTControl(chkShareAlike, CHK_SHAREALKENAME, CHK_SHAREALKELABEL,
+                    new Rectangle(10, 66, 150, 12)); //(50, 66, 150, 12));
+            xpsCHKProperties.setPropertyValue("TriState", Boolean.FALSE);
+            xpsCHKProperties.setPropertyValue("State", new Short((short) 0));
+
             Object searchButton = msfLicenseSelector.createInstance(
                     "com.sun.star.awt.UnoControlButtonModel");
             XPropertySet xPSetFinishButton = createAWTControl(searchButton,
@@ -665,6 +694,67 @@
         setMousePointer(SystemPointer.ARROW);
     }
 
+    public String[] getLicense() {
+
+        boolean commercial = getCheckBoxStatus(CHK_COMMERCIALNAME);
+        boolean update = getCheckBoxStatus(CHK_UPDATENAME);
+        boolean shareAlike = getCheckBoxStatus(CHK_SHAREALKENAME);
+
+        if (commercial && update && shareAlike) {
+            return new String[]{"CC BY", "PD", "CC BY SA", "GFDL", "CC0"};//"4,5"
+        } else if (commercial && update) {
+            return new String[]{"CC BY", "PD", "CC0"};//"4"
+        } else if (update && shareAlike) {
+            return new String[]{"CC BY", "PD", "CC BY SA", "CC BY NC SA", "CC BY NC", "GFDL", "CC0"};//"1,2,4,5"
+        } else if (commercial) {
+            return new String[]{"CC BY", "PD", "CC BY SA", "CC BY ND", "GFDL", "CC0"};//"4,5,6"
+        } else if (update) {
+            return new String[]{"CC BY", "PD", "CC BY NC", "CC0"};//"2,4"
+        }
+        //default atribution license
+        return new String[]{"CC BY", "PD", "CC0"};//"4";
+    }
+
+    public boolean getCheckBoxStatus(String ctrlName) {
+
+        Object oLicense = xControlCont.getControl(ctrlName);
+        XCheckBox checkBox = (XCheckBox) UnoRuntime.queryInterface(XCheckBox.class, oLicense);
+
+        Object value = checkBox.getState();
+        if (value != null) {
+
+            short chkStatus = new Short(value.toString());
+            if (chkStatus == 1) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean IsInputValid() {
+
+        if (this.GetTags().length == 0) {
+            return false;
+        }
+
+        boolean commercial = getCheckBoxStatus(CHK_COMMERCIALNAME);
+        boolean update = getCheckBoxStatus(CHK_UPDATENAME);
+        boolean shareAlike = getCheckBoxStatus(CHK_SHAREALKENAME);
+
+        if (!commercial && !update && !shareAlike) {
+            return false;
+        }
+
+        if (commercial && !update && shareAlike) {
+            return false;
+        }
+
+        if (!commercial && !update && shareAlike) {
+            return false;
+        }
+
+        return true;
+    }
     public void setLoadable(boolean val) {
 
         this.isLoadable = val;




More information about the cc-commits mailing list