GWT-AI Integration - java

I am developing a demo application with using GwtAI (Gwt Applet Integration). I have included all the GwtAI-client.jar,GwtAI-core.jar.I am referring to the http://code.google.com/p/gwtai/wiki/GettingStarted Following is the code.
FileUploadingApplet.class
#ImplementingClass(com.nextenders.appletImpl.FileUploadingAppletImpl.class)
#Height("60")
#Width("350")
#Archive("GwtAI-Client.jar,FileUploadingAppletImpl.jar")
#Codebase("applet")
public interface FileUploadingApplet extends Applet{
public void increment();
public void decrement();
public Object getCurrentValue();
}
FileUploadingAppletImpl.class
public class FileUploadingAppletImpl extends JApplet implements FileUploadingApplet {
JTextField m_fileNameTF = new JTextField(15);
String controlTransactionId = "";
JFileChooser m_fileChooser = new JFileChooser();
JPanel content = new JPanel();
FileWriter fstream = null;
long fileLength = 0l;
#Override
public void init() {
JPanel panelMain = new JPanel();
m_fileNameTF = new JTextField(20);
m_fileNameTF.setHorizontalAlignment(JTextField.CENTER);
m_fileNameTF.setText("0");
m_fileNameTF.setEditable(false);
panelMain.add(new JLabel("Current count : "));
panelMain.add(m_fileNameTF);
panelMain.setBorder(BorderFactory.createTitledBorder("CounterApplet"));
panelMain.setBackground(Color.WHITE);
getContentPane().add(panelMain);
}
public void increment() {
int currentCount = Integer.parseInt(m_fileNameTF.getText());
currentCount++;
m_fileNameTF.setText(currentCount + "");
}
public void decrement() {
int currentCount = Integer.parseInt(m_fileNameTF.getText());
currentCount--;
m_fileNameTF.setText(currentCount + "");
}
public Object getCurrentValue() {
return m_fileNameTF.getText();
}
}
NTFileUpload.java
private void createPanel(){
PopupPanel panel = new PopupPanel();
panel.setPopupPosition(500, 500);
panel.setHeight("600px");
panel.setHeight("900px");
final FileUploadingApplet fileUploadApplet = (FileUploadingApplet) GWT.create(FileUploadingApplet.class);
VerticalPanel panelMain = new VerticalPanel();
Button buttonInc = new Button("Increment");
buttonInc.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
fileUploadApplet.increment();
}
});
Widget widgetApplet = AppletJSUtil.createAppletWidget(fileUploadApplet);
panelMain.add(widgetApplet);
panelMain.add(buttonInc);
panel.add(panelMain);
panel.show();
}
I have followed the package structure as per the link. But I am getting following Exception.
java.lang.IncompatibleClassChangeError: Found interface com.google.gwt.core.ext.typeinfo.JClassType, but class was expected
at com.google.gwt.gwtai.applet.generator.AppletProxyGenerator.generate(AppletProxyGenerator.java:71)
at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:257)
at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:96)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:254)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:173)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:288)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$400(AbstractCompiler.java:139)
at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:588)
at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:97)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:52)
at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:569)
at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:284)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
at com.google.gwt.dev.Compiler.run(Compiler.java:232)
at com.google.gwt.dev.Compiler.run(Compiler.java:198)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
at com.google.gwt.dev.Compiler.main(Compiler.java:177)
Thanks in advance.

you need to build the dependencies that you're using (jar/war) with the same GWT SDK version that you are using for compilation of your project i.e. if 2.4 then use 2.4 to jar the dependencies and then compile your project. This error is due to the mismatch in the SDK versions being used.

There have been breaking changes in the GWT code generator feature, between version 1.7 and 2.0. So make sure you have the current version of GwtAI, if you work with a GWT version 2.0 or higher. If you work with a GWT version before 2.0 go to the GwtAI download page, select All downloads and click Search, you should see GwtAI 0.2 files. Those
should work with older GWT versions.

Related

PlantUML graph generation in java Illegal acces error

I'm trying to make a simple graph using java but keep getting error
Code:
public class PlantUMLDemoMain {
public static void main(String[] args) throws Exception {
generateFromStringSource(new File("from-string.png"));
generateFromApi(new File("from-api.png"));
}
private static void generateFromApi(File file) throws IOException {
// 1. setup:
SequenceDiagramFactory f = new SequenceDiagramFactory();
SequenceDiagram diagram = f.createEmptyDiagram();
// 2. Build the diagram:
// "Bob -> Alice : hello"
// See net.sourceforge.plantuml.sequencediagram.command.CommandArrow#executeArg
Display bobD = Display.getWithNewlines("Bob");
Participant bobP = diagram.getOrCreateParticipant("Bob", bobD);
Display aliceD = Display.getWithNewlines("Alice");
Participant aliceP = diagram.getOrCreateParticipant("Alice", aliceD);
Display label = Display.getWithNewlines("hello");
ArrowConfiguration config = ArrowConfiguration.withDirectionNormal();
Message msg = new Message(bobP, aliceP, label, config, diagram.getNextMessageNumber());
checkState(null == diagram.addMessage(msg));
// 3. Output the diagram
// See net.sourceforge.plantuml.SourceStringReader#generateImage
diagram.makeDiagramReady();
checkState(1 == diagram.getNbImages());
try (OutputStream os = new FileOutputStream(file)) {
ImageData imageData = diagram.exportDiagram(os, 0, new FileFormatOption(FileFormat.PNG));
System.out.println("generateFromApi: " + diagram.getDescription().getDescription());
}
}
private static void generateFromStringSource(File file) throws IOException {
String source = "#startuml\n";
source += "Bob -> Alice : hello\n";
source += "#enduml\n";
StringBuffer stringBuffer = new StringBuffer();
SourceStringReader reader = new SourceStringReader(source);
// Write the first image to "png"
String desc = reader.generateImage(file);
// Return a null string if no generation
System.out.println("generateFromStringSource: " + desc);
}
}
Error: Exception in thread "main" java.lang.IllegalAccessError: class net.sourceforge.plantuml.png.PngIOMetadata (in unnamed module #0x9597028) cannot access class com.sun.imageio.plugins.png.PNGMetadata (in module java.desktop) because module java.desktop does not export com.sun.imageio.plugins.png to unnamed module #0x9597028
at net.sourceforge.plantuml.png.PngIOMetadata.writeWithMetadata(PngIOMetadata.java:60)
at net.sourceforge.plantuml.png.PngIO.write(PngIO.java:86)
at net.sourceforge.plantuml.png.PngIO.write(PngIO.java:80)
at net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d.writeImageTOBEMOVED(UGraphicG2d.java:219)
at net.sourceforge.plantuml.ugraphic.ImageBuilder.writeImageInternal(ImageBuilder.java:249)
at net.sourceforge.plantuml.ugraphic.ImageBuilder.writeImageTOBEMOVED(ImageBuilder.java:171)
at net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMakerPuma2.createOne(SequenceDiagramFileMakerPuma2.java:234)
at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.exportDiagramInternal(SequenceDiagram.java:222)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:236)
at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:127)
at net.sourceforge.plantuml.SourceStringReader.generateImage(SourceStringReader.java:124)
at net.sourceforge.plantuml.SourceStringReader.generateImage(SourceStringReader.java:111)
at net.sourceforge.plantuml.SourceStringReader.generateImage(SourceStringReader.java:101)
at scr.graphviz.sk.PlantUMLDemoMain.generateFromStringSource(PlantUMLDemoMain.java:66)
at scr.graphviz.sk.PlantUMLDemoMain.main(PlantUMLDemoMain.java:23)
I found someone with similar problem and older version of plantuml worked for him. I have jar file of the older version but I'm not sure how to apply it. I tried inspecting the file and find out versions of libraries used and added maven dependencies for them but it didnt seem to work.
This is similar problem i mentioned https://github.com/plantuml/plantuml/issues/69

java.lang.IllegalAccessError: tried to access method net.sourceforge.tess4j.Tesseract.<init>()V from class Tess4jTest.TestTess

I did a Java OCR project with Tesseract in the Mirth.When I run the jar file from the Mirth,I get this error.When I search it,I found that there is a init() method and also it is a protected void in Tesseract.java.I think that maybe it is the reason for that error.
What should I do?Thank you so much for your helps.
package Tess4jTest;
import java.io.File;
import java.io.IOException;
import net.sourceforge.tess4j.*;
public class TestTess {
public static String Tc;
public static String phone;
public static String date;
public static void main(String[] args) {
//System.out.println(returnText("C:\\Users\\Nevzat\\Desktop\\deneme.pdf"));
}
public static String returnText(String fileName){
File imageFile = new File(fileName);
if(imageFile.exists()){
Tesseract instance = new Tesseract();
instance.setDatapath("C:\\imageRAD\\Onam\\tessdata");
String result = null;
try {
result = instance.doOCR(imageFile);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
if(result!=null){
int i=result.indexOf("Numarasn: ");
int j=result.indexOf("Tel No:");
int k=result.indexOf("Bilgllendirme Tarihl:");
Tc = result.substring(i+10, i+21);
phone = result.substring(j+8,j+23);
date = result.substring(k+22,k+32);
//System.out.println(result);
}else{
return "Null Error!";
}
}else{
return "Does not found a file!";
}
return Tc+","+phone+","+date;
}
public static String returnTC() throws IOException{
return Tc;
}
public static String returnPhone() throws IOException{
return phone;
}
public static String returnDate() throws IOException{
return date;
}
}
The error you got occurs when you try to create an object with a private constructor. (<init>() is the name of a constructor with no parameters)
Looking at the tess4j source I found a method with the following documentation:
#deprecated As of Release 2.0, use default constructor instead.
Looking at the source before 2.0 reveals the default constructor was private.
This means your problem is most likely that you are compiling against a version newer than 2.0, but your environment is running one older than 2.0.
Either update your environment or downgrade the library you build against to fix it.
I solved the error and have finished the project.I mention step by step
1.You have to use right jar files for tess4j.
2.Add java project all of in the tess4j-3.2.1.zip except tess4j-3.2.1.jar via Build Path.
3.Add tess4j-1.5.jar from this
4.Add tessdata folder,ghost4j-0.5.1.jar,jna-4.1.jar,tess4j.jar and jar file of your java project.

Running Wicket the first time

I am having issues with the Wicket GAE sample application,
The issues is that some import cannot be resolved:
import org.apache.wicket.page.PersistentPageManager; // This one
import org.apache.wicket.util.io.IObjectStreamFactory; // and this cannot be resolved
#Override
public void init()
{
super.init();
getResourceSettings().setResourcePollFrequency(null);
WicketObjects.setObjectStreamFactory(new IObjectStreamFactory() {
#Override
public ObjectInputStream newObjectInputStream(InputStream in)
throws IOException {
return new ObjectInputStream(in);
}
#Override
public ObjectOutputStream newObjectOutputStream(OutputStream out)
throws IOException {
return new ObjectOutputStream(out);
}
});
setPageManagerProvider(new DefaultPageManagerProvider(this) {
public IPageManager get(IPageManagerContext pageManagerContext)
{
IDataStore dataStore = new HttpSessionDataStore(pageManagerContext, new PageNumberEvictionStrategy(10));
IPageStore pageStore = new DefaultPageStore(getName(), dataStore,
getCacheSize());
return new PersistentPageManager(getName(), pageStore, pageManagerContext);
}
});
// add your configuration here
}
Also, the getCacheSize() method cannot be found, I am using Wicket version, 1.5-SNAPSHOT as used in the demo app, but I tried other later versions too but still cannot be resolved, how can this be fixed?
This classes and methods were introduced only in RC versions (or earlier release versions) and removed from 1.5 release
So, you can download one of the RC packages or migrate to 1.5 version.
To migrate, you should:
Remove code WicketObjects.setObjectStreamFactory.... This will be replaced by defining serializer for pageStore. See this migration section.
Override DefaultPageManagerProvider's get method as follows:
#Override
public IPageManager get(IPageManagerContext context)
{
IDataStore dataStore = new HttpSessionDataStore(context,
new PageNumberEvictionStrategy(10));
IPageStore pageStore = new DefaultPageStore (
new JavaSerializer ( getName() ), dataStore,
getStoreSettings().getInmemoryCacheSize());
return new PageStoreManager(application.getName(), pageStore,
context);
}
For further migrations you should check wicket migration guides.

Pegdown Custom ParserPlugin binding failed

I'm stuck facing problems with pegdown v1.4.2 while trying to implement custom ParserPlugin to a library I'm writing (Maven project, JDK 8):
CustomPlugin:
public class CustomHeadersParserPlugin extends Parser implements BlockPluginParser {
public CustomHeadersParserPlugin() {super(HtmlMdProc.MDP_SETTINGS, HtmlMdProc.PROCESSING_TIME_LIMIT, DefaultParseRunnerProvider);
}
public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis) {
super(options, maxParsingTimeInMillis, DefaultParseRunnerProvider);
}
public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider) {
super(options, maxParsingTimeInMillis, parseRunnerProvider);
}
public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider, PegDownPlugins plugins) {
super(options, maxParsingTimeInMillis, parseRunnerProvider, plugins);
}
//************* CUSTOM RULES ***************
...
Pegdown Usage:
public class HtmlMdProc {
public static final int MDP_SETTINGS = Extensions.HARDWRAPS | Extensions.AUTOLINKS | Extensions.TABLES | Extensions.FENCED_CODE_BLOCKS;
public static final long PROCESSING_TIME_LIMIT = 5000l;
...
public HtmlMdProc markdown() {
PegDownPlugins pdp = PegDownPlugins.builder().withPlugin(CustomHeadersParserPlugin.class).build();
PegDownProcessor mdp = new PegDownProcessor(MDP_SETTINGS, PROCESSING_TIME_LIMIT, pdp);
RootNode rn = mdp.parseMarkdown(text.toCharArray());
String result = new CustomMarkdownToHtmlSerializer().toHtml(rn);
if (result != null)
this.text = result;
else
logger.debug("Could not process markdown in {} seconds", PROCESSING_TIME_LIMIT / 1000);
return this;
}
Test:
#Test
public void testmarkdownWithoutCode() {
String before = "Simple new line\nTest\n\nTest\nVot";
String expected = "<p>Simple new line<br />Test</p><p>Test<br />Vot</p>".replaceAll("\r", "");
HtmlMdProc textProc = new HtmlMdProc(before);
String result = textProc.markdown().text();
assertEquals(expected, result);
}
Testing Exeption:
java.lang.RuntimeException: Error creating extended parser class: null
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.parboiled.transform.AsmUtils.createClassReader(AsmUtils.java:56)
at org.parboiled.transform.ClassNodeInitializer.process(ClassNodeInitializer.java:62)
at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:44)
at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:38)
at org.parboiled.Parboiled.createParser(Parboiled.java:54)
at org.pegdown.plugins.PegDownPlugins$Builder.withPlugin(PegDownPlugins.java:113)
at com.myorg.html.services.HtmlMdProc.markdown(HtmlMdProc.java:317)
at com.myorg.html.services.HtmlMdProcTest.testmarkdownWithoutCode(HtmlMdProcTest.java:262)
Can I somehow bind my CustomHeadersParserPlugin avoiding spooky Reflections?
If not, tell me how to setup maven-bundle-plugin in pom.xml to make it work with pegdown v 1.4.2.
I found Issue with discussion Here, but I'm too novice to deal alone with Maven plugins and Reflections.
The only solution is to wait for This Issue to be closed, until I thing there is no luck with Pegdown and Java 8.

Why is my Xuggle video converter not working

I hava this piece of code:
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;
public class ImageToVideo implements Runnable {
private static Dimension dimension;
private final IMediaWriter writer;
long startTime;
LoadFrame loadframe;
public ImageToVideo(int framespersecond, LoadFrame loadframe) {
this.loadframe = loadframe;
writer = ToolFactory.makeWriter(Project.getInstance().getFileURLStr() + Project.getInstance().getProjectName() + ".mp4");
dimension = Toolkit.getDefaultToolkit().getScreenSize();
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, dimension.width / 2, dimension.height / 2);
startTime = System.nanoTime();
}
#Override
public void run() {
Project project = Project.getInstance();
for (int index = 0; index <= project.getTimeLineImageCount(); index++) {
loadframe.updateProgress(index/project.getTimeLineImageCount());
ImageIcon imgtoencode = (ImageIcon)project.getNextTimeLineImage();
BufferedImage imgtoencodebuf = (BufferedImage)imgtoencode.getImage();
writer.encodeVideo(0, imgtoencodebuf, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
}
project.setWalkIndexes();
writer.close();
}
}
Wich should be converting a list of images to a video. But when I try to run it I get this error:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.xuggle.ferry.JNIMemoryManager.<init>(JNIMemoryManager.java:861)
at com.xuggle.ferry.JNIMemoryManager.<clinit>(JNIMemoryManager.java:860)
at com.xuggle.mediatool.MediaWriter.<clinit>(MediaWriter.java:119)
at com.xuggle.mediatool.ToolFactory.makeWriter(ToolFactory.java:149)
at Operations.ImageToVideo.<init>(ImageToVideo.java:31)
at GUI.MainScreen.actionPerformed(MainScreen.java:501)
etc. I got the code from an example on internet:http://examples.javacodegeeks.com/desktop-java/xuggler/create-video-from-image-frames-with-xuggler/"
I am really new to Xuggle, I hope someone can help me out here. Thanks
You are missing the sl4j library Xuggle will not work without that
Download library from here --> http://www.slf4j.org/download.html and add the jar's to your project library (class path)

Categories

Resources