[brailleblaster] [brailleblaster.newdesign] push by RandomCh...@xxxxxxxxx - Image Describer loads and outputs descriptions. on 2013-07-31 19:49 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Wed, 31 Jul 2013 19:50:02 +0000

Revision: fb050255b913
Branch:   default
Author:   cmyers@xxxxxxxxxxxxxxxxx
Date:     Wed Jul 31 13:56:26 2013
Log:      Image Describer loads and outputs descriptions.
http://code.google.com/p/brailleblaster/source/detail?r=fb050255b913&repo=newdesign

Modified:
 /src/main/org/brailleblaster/imagedescriber/ImageDescriber.java
 /src/main/org/brailleblaster/imagedescriber/ImageDescriberDialog.java

=======================================
--- /src/main/org/brailleblaster/imagedescriber/ImageDescriber.java Wed Jul 31 12:02:01 2013 +++ /src/main/org/brailleblaster/imagedescriber/ImageDescriber.java Wed Jul 31 13:56:26 2013
@@ -114,7 +114,7 @@
                curImgElement = imgElmList.get(curElementIndex);

                // Return current <img> element.
-               return imgElmList.get(curElementIndex);
+               return curImgElement;

        } // NextImageElement()

@@ -135,7 +135,7 @@
                curImgElement = imgElmList.get(curElementIndex);

                // Return current <img> element.
-               return imgElmList.get(curElementIndex);
+               return curImgElement;

        } // PrevImageElement()

@@ -256,24 +256,70 @@
        } // getCurrentElementIndex()

///////////////////////////////////////////////////////////////////////////
-       // Sets the current element's <img> attributes.
+       // Sets the current element's <img> attributes. Pass null to atts you
+       // don't want modified.
public void setCurElmImgAttributes(String tagID, String tagSRC, String tagALT)
        {
                // Set attribute values.
-               curImgElement.getAttribute("id").setValue(tagID);
-               curImgElement.getAttribute("src").setValue(tagSRC);
-               curImgElement.getAttribute("alt").setValue(tagALT);
+               if(tagID != null)
+                       curImgElement.getAttribute("id").setValue(tagID);
+               if(tagSRC != null)
+                       curImgElement.getAttribute("src").setValue(tagSRC);
+               if(tagALT != null)
+                       curImgElement.getAttribute("alt").setValue(tagALT);


        } // setCurElmImgAttributes()

///////////////////////////////////////////////////////////////////////////
-       // Sets <prodnote> attributes for current <img> element's parent.
- public void setCurElmProdAttributes(String tagID, String tagIMGREF, String tagRENDER)
+       // Returns the text/description in the current <imggroup>'s prodnote.
+       // Returns null if it couldn't find the <prodnote> or if it didn't have
+       // text.
+       public String getCurProdText()
+       {
+               // String for <prodnote> text.
+               String prodText = null;
+
+               // Get parent of <img> element.
+               nu.xom.Node parNode = curImgElement.getParent();
+
+               ///////////////////////////
+
+               // Find <prodnote>.
+               Element ch = null;
+               for(int curC = 0; curC < parNode.getChildCount(); curC++) {
+                       ch = (Element)parNode.getChild(curC);
+                       if( ch.getLocalName().compareTo("prodnote") == 0 ) {
+
+                               // If no children, add one.
+                               if(ch.getChildCount() == 0)
+                                       ch.appendChild( new nu.xom.Text("ADD 
DESCRIPTION!") );
+
+                               // Get text.
+                               prodText = ch.getChild(0).getValue();
+
+                               // Found it. Break.
+                               break;
+
+                       } // if( ch.getLocalName()...
+
+               } // for(int curC = 0...
+
+               // Return <prodnote> text.
+               return prodText;
+
+       } // getCurProdText()
+
+ /////////////////////////////////////////////////////////////////////////// + // Sets <prodnote> text and attributes. Uses parent of current <img> element
+       // to get to <prodnote>. Pass null to args you don't want modified.
+ public void setCurElmProd(String text, String tagID, String tagIMGREF, String tagRENDER)
        {
                // Get parent of <img> element.
                nu.xom.Node parNode = curImgElement.getParent();

+               ///////////////////////////
+
                // Find <prodnote>.
                Element ch = null;
                for(int curC = 0; curC < parNode.getChildCount(); curC++) {
@@ -287,10 +333,31 @@

                } // for(int curC = 0...

+               /////////////////////////
+
+               // Set text value.
+               if(text != null)
+               {
+                       // If no children, add one. Else, replace the one 
already there.
+                       if(ch.getChildCount() == 0)
+                               ch.appendChild( new nu.xom.Text(text) );
+                       else {
+                               nu.xom.Node oldNode = ch.getChild(0);
+                               nu.xom.Node newNode = new nu.xom.Text(text);
+                               ch.replaceChild(oldNode, newNode);
+                       }
+
+               } // if(text != null)
+
+               ///////////////////////////
+
                // Set attributes.
-               ch.getAttribute("id").setValue(tagID);
-               ch.getAttribute("imgref").setValue(tagIMGREF);
-               ch.getAttribute("render").setValue(tagRENDER);
+               if(tagID != null)
+                       ch.getAttribute("id").setValue(tagID);
+               if(tagIMGREF != null)
+                       ch.getAttribute("imgref").setValue(tagIMGREF);
+               if(tagRENDER != null)
+                       ch.getAttribute("render").setValue(tagRENDER);

        } // setCurElmProdAttributes

=======================================
--- /src/main/org/brailleblaster/imagedescriber/ImageDescriberDialog.java Wed Jul 31 12:02:01 2013 +++ /src/main/org/brailleblaster/imagedescriber/ImageDescriberDialog.java Wed Jul 31 13:56:26 2013
@@ -42,6 +42,9 @@
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;

///////////////////////////////////////////////////////////////////////////////////////////
 // Simple dialog that displays images in a document, and allows one
@@ -58,13 +61,14 @@
        Button nextBtn;
        Button prevBtn;
        Label mainImage;
+       Text imgDescTextBox;

        // The image describer.
        ImageDescriber imgDesc;

        // Main image.
        int imageOffsetX = 0;
-       int imageOffsetY = 100;
+       int imageOffsetY = 150;
        int clientWidth = -1;
        int clientHeight = -1;

@@ -140,21 +144,24 @@
                mainImage = new Label(configShell, SWT.NONE);
mainImage.setBounds(imageOffsetX, imageOffsetY, clientWidth - imageOffsetX, (clientHeight - imageOffsetY)); mainImage.setImage( createScaledImage(imgDesc.getCurElementImage(), clientWidth, clientHeight) );
-
-               // Create next button.
-               nextBtn = new Button(configShell, SWT.PUSH);
-               nextBtn.setText("Next");
-               nextBtn.setBounds(0,  0, 100, 100);
-               nextBtn.addSelectionListener(new SelectionAdapter() {
-                       public void widgetSelected(SelectionEvent e) {
+
+               // Create image description text box.
+ imgDescTextBox = new Text(configShell, SWT.BORDER | SWT.MULTI | SWT.WRAP);
+               imgDescTextBox.setBounds(250, 8, clientWidth - 250, 200);
+               imgDescTextBox.addModifyListener(new ModifyListener() {
+                       public void modifyText(ModifyEvent arg0) {

-                               // Change main image to next element image.
-                               imgDesc.nextImageElement();
- mainImage.setImage( createScaledImage(imgDesc.getCurElementImage(), clientWidth, clientHeight - imageOffsetY) );
+                               // Set image's description.
+                               imgDesc.setCurElmProd(imgDescTextBox.getText(), 
null, null, null);

-                       } // widgetSelected()
+                       } // modifyText()

-               }); // nextBtn.addSelectionListener...
+               }); // addModifyListener(new ModiftyListener() {
+
+
+               // Get prodnote text/image description.
+               imgDescTextBox.setText( imgDesc.getCurProdText() );
+

                // Create previous button.
                prevBtn = new Button(configShell, SWT.PUSH);
@@ -163,12 +170,35 @@
                prevBtn.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {

+                               // Change main image to previous element image.
+                               imgDesc.prevImageElement();
+ mainImage.setImage( createScaledImage(imgDesc.getCurElementImage(), clientWidth, clientHeight - imageOffsetY) );

+                               // Get prodnote text/image description.
+                               imgDescTextBox.setText( 
imgDesc.getCurProdText() );

                        } // widgetSelected()

                }); // prevBtn.addSelectionListener...

+               // Create next button.
+               nextBtn = new Button(configShell, SWT.PUSH);
+               nextBtn.setText("Next");
+               nextBtn.setBounds(0,  0, 100, 100);
+               nextBtn.addSelectionListener(new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+
+                               // Change main image to next element image.
+                               imgDesc.nextImageElement();
+ mainImage.setImage( createScaledImage(imgDesc.getCurElementImage(), clientWidth, clientHeight - imageOffsetY) );
+
+                               // Get prodnote text/image description.
+                               imgDescTextBox.setText( 
imgDesc.getCurProdText() );
+
+                       } // widgetSelected()
+
+               }); // nextBtn.addSelectionListener...
+
        } // public void createUIelements()

///////////////////////////////////////////////////////////////////////////////////////////

Other related posts:

  • » [brailleblaster] [brailleblaster.newdesign] push by RandomCh...@xxxxxxxxx - Image Describer loads and outputs descriptions. on 2013-07-31 19:49 GMT - brailleblaster