Dragtop

From BITPlan Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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