Difference between revisions of "Dragtop"

From BITPlan Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
|title=Drag and Drop target desktop application with plugable functionality
 
|title=Drag and Drop target desktop application with plugable functionality
 
|url=https://github.com/BITPlan/com.bitplan.dragtop
 
|url=https://github.com/BITPlan/com.bitplan.dragtop
|version=0.0.1
+
|version=0.0.2
|date=2018/12/03
+
|date=2019-03-21
 
}}
 
}}
 
= Installation =
 
= Installation =
Line 69: Line 69:
 
@// Rythm template
 
@// Rythm template
 
@// you can try Rythm out at http://fiddle.rythmengine.com
 
@// you can try Rythm out at http://fiddle.rythmengine.com
 +
@// this template will work in the dragtop environment only
 
@// Created by Wolfgang Fahl, BITPlan GmbH,  2018-12-06
 
@// Created by Wolfgang Fahl, BITPlan GmbH,  2018-12-06
 
@import com.bitplan.dragtop.DropTarget
 
@import com.bitplan.dragtop.DropTarget
 
@import com.bitplan.dragtop.DragItem
 
@import com.bitplan.dragtop.DragItem
 
@import org.apache.tinkerpop.gremlin.structure.Graph
 
@import org.apache.tinkerpop.gremlin.structure.Graph
 +
@import org.apache.tinkerpop.gremlin.structure.Vertex
 
@import com.bitplan.simplegraph.powerpoint.PowerPointSystem
 
@import com.bitplan.simplegraph.powerpoint.PowerPointSystem
 
@import com.bitplan.simplegraph.powerpoint.SlideNode
 
@import com.bitplan.simplegraph.powerpoint.SlideNode
Line 97: Line 99:
 
   return sw.toString();
 
   return sw.toString();
 
}
 
}
 +
@// show errors
 
@def showError(Throwable error) {
 
@def showError(Throwable error) {
 
<h3 style="color:red">Error @(error.getClass().getName()): @(error.getMessage())</h3>
 
<h3 style="color:red">Error @(error.getClass().getName()): @(error.getMessage())</h3>
Line 102: Line 105:
 
@getStackTrace(error)
 
@getStackTrace(error)
 
</pre>
 
</pre>
 +
}
 +
@// get the property with the given name or ? if the property is not set
 +
@def String getProperty(SimpleStepNode n, String pname) {
 +
  Object property=n.property(pname);
 +
  String value="?";
 +
  if (property!=null)
 +
    value=property.toString();
 +
  return value;
 
}
 
}
 
<!DOCTYPE html>
 
<!DOCTYPE html>
Line 135: Line 146:
 
       @for (SimpleStepNode slideNode:slides) {
 
       @for (SimpleStepNode slideNode:slides) {
 
         @{
 
         @{
           Object titleProperty=slideNode.property("title");
+
           String title=getProperty(slideNode,"title");
           String title="?";
+
           String name=getProperty(slideNode,"name");
 
           SlideNode slide=null;
 
           SlideNode slide=null;
 
           File slideFile=null;
 
           File slideFile=null;
          if (titleProperty!=null)
 
            title=titleProperty.toString();
 
 
           if (slideNode instanceof SlideNode) {
 
           if (slideNode instanceof SlideNode) {
 
             try {
 
             try {
Line 151: Line 160:
 
           }
 
           }
 
         }
 
         }
   <li>@(title)
+
   <li>@(title) / @(name)
 
         @if (error) {
 
         @if (error) {
 
     @showError(error)
 
     @showError(error)
Line 159: Line 168:
 
           }
 
           }
 
         }
 
         }
         <pre>@(slideNode.property("text"))</pre>
+
         <pre>@(getProperty(slideNode,"text"))</pre>
 
   </li>
 
   </li>
 
       }
 
       }
Line 168: Line 177:
 
</body>
 
</body>
 
</html>
 
</html>
 
 
</source>
 
</source>
  

Latest revision as of 09:39, 8 July 2019

OsProject
id  com.bitplan.dragtop
state  
owner  BITPlan
title  Drag and Drop target desktop application with plugable functionality
url  https://github.com/BITPlan/com.bitplan.dragtop
version  0.0.2
description  
date  2019-03-21
since  
until  

Installation

git clone https://github.com/BITPlan/com.bitplan.dragtop
mvn clean install -D createAssembly=true

or use the rebuild script which skips Tests and gpg signature

dragtop script

This is a convenience script to start your dragtop. You might want to adapt the base directory setting to your environment

#!/bin/bash
# WF 2019-02-17
#
# start dragtop
#
# uncomment to debug
# set -x

base=$HOME/source/java
case $(uname -a) in
  Darwin*)
    base=$HOME/Documents/workspace
  ;;
esac

pdir=$base/com.bitplan.dragtop
if [ ! -d $pdir ]
then
  echo "dragtop project missing - will get it"
  cd $base
	git clone https://github.com/BITPlan/com.bitplan.dragtop
fi

cd $pdir
git pull
jar=$pdir/release/com.bitplan.dragtop.jar
if [ ! -f $jar ]
then
  echo "dragtop jar missing - will create"
  mvn install
fi
java -jar $jar $*

Using the dragtop

Powerpoint extraction example

You you need one ore more Powerpoint files in pptx format e.g. http://people.apache.org/~sctemme/ApconEU2008/Performance_Out.pptx

First start the dragtop. Dragtop2019-03-21.png

Then drag & drop your powerpoint files. DragTopStep2 2019-03-21.png

Then drag & drop a "tool" which can be a jar that follows the dragtop plugin guidelines or simply a fitting rythm template. Dowload https://raw.githubusercontent.com/BITPlan/com.bitplan.dragtop/master/src/test/rythm/pptExtractor.rythm and drag&drop it.

DragTopStep3 2019-03-21.png As a result your browser should open and show you an "exported" version of your Powerpoint presentation with all images and text "extracted". You'll find the images in your /tmp directory.

pptExtractor.rythm

@// Rythm template
@// you can try Rythm out at http://fiddle.rythmengine.com
@// this template will work in the dragtop environment only
@// Created by Wolfgang Fahl, BITPlan GmbH,  2018-12-06
@import com.bitplan.dragtop.DropTarget
@import com.bitplan.dragtop.DragItem
@import org.apache.tinkerpop.gremlin.structure.Graph
@import org.apache.tinkerpop.gremlin.structure.Vertex
@import com.bitplan.simplegraph.powerpoint.PowerPointSystem
@import com.bitplan.simplegraph.powerpoint.SlideNode
@import com.bitplan.simplegraph.core.SimpleStepNode
@import java.util.stream.Collectors
@args() {
  DropTarget dropTarget,
  Graph graph;
}
@{
  PowerPointSystem pps=null;
  Throwable error=null;
  try {
    pps=new PowerPointSystem();
    pps.connect();
  } catch (Throwable th) {
    error=th;
  }
}
@// error handling - get a stack trace
@def String getStackTrace (Throwable t) {
  StringWriter sw = new StringWriter();
  t.printStackTrace(new PrintWriter(sw));
  return sw.toString();
}
@// show errors
@def showError(Throwable error) {
<h3 style="color:red">Error @(error.getClass().getName()): @(error.getMessage())</h3>
<pre>
@getStackTrace(error)
</pre>
}
@// get the property with the given name or ? if the property is not set
@def String getProperty(SimpleStepNode n, String pname) {
  Object property=n.property(pname);
  String value="?";
  if (property!=null)
    value=property.toString();
  return value;
}
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8"/>
</head>
<body>
@if (error) {
  @showError(error)
} else {
  @for(DragItem dragItem:dropTarget.getDragItems()) {
    @{
      Object item=dragItem.getItem();
      int index=0;
      File file=null;
      SimpleStepNode slideShowNode=null;
      List<SimpleStepNode> slides=null;
      if (item instanceof File) {
        file=(File) item;
        if (file.getName().contains(".ppt")) {
          slideShowNode = (SimpleStepNode) pps.moveTo(file.getPath());
          slides = slideShowNode.out("slides")
          .collect(Collectors.toCollection(ArrayList::new));
        } else {
          file=null;
        }
      }
    }
    @if (file) {
<h3>@(file.getName())</h3>
<ol>
       @for (SimpleStepNode slideNode:slides) {
         @{
           String title=getProperty(slideNode,"title");
           String name=getProperty(slideNode,"name");
           SlideNode slide=null;
           File slideFile=null;
           if (slideNode instanceof SlideNode) {
             try {
               slide=(SlideNode) slideNode;
               slideFile=new File("/tmp/"+file.getName()+""+index++);
               slide.outputSlideAsImage(slideFile,1.0,false);
             } catch (Throwable th) {
               error=th;
             }
           }
         }
  <li>@(title) / @(name)
         @if (error) {
    @showError(error)
        } else {
          @if (slideFile) {
  <img src='file://@(slideFile.getAbsolutePath())'/>
          }
        }
        <pre>@(getProperty(slideNode,"text"))</pre>
  </li>
      }
</ol>
    }
  }
}
</body>
</html>

WhatLinksHere