将处理项目移植到Eclipse中 [英] Moving Processing project into Eclipse

查看:154
本文介绍了将处理项目移植到Eclipse中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在处理一个Processing项目,现在想把它移植到Eclipse中。我已经用Eclipse环境安装了Proclipse。

I've been working on a Processing project for a while, and now want to move it into Eclipse. I've installed Proclipse with my Eclipse environment.

我有很多扩展名为.pde的文件。但是Proclipse文件全部以.java结尾。并且所有pde文件都有很多依赖问题。如何转换我的项目?

I've a lot of files with the extension of ".pde". However the Proclipse files all ends with ".java". And there's a lot of dependency issues with all the pde files. How should I convert my project?

===============

===============

谢谢大家!似乎没有一个按钮的解决方案,我按照乔治的答案类似的方式重构了所有的代码。加上将所有文件扩展名从.pde更改为.java。

Thanks everyone! There doesn't seem to be a one-button solution, I refactored all the code following an approach similar to George's answer. Plus changing all the file extensions from ".pde" to ".java".

推荐答案

何塞的建议是相当不错的。 快照已经使创建处理项目变得容易。

Jose's advice is pretty good. Proclipsing already makes creating a Processing project easy.

在eclipse中运行的最简单(但不是最简单的方法)将采取以下步骤:

The easiest (but not cleanest way to get your Processing code running in eclipse would be taking these steps:


  1. 将代码从主标签复制到Proclipsing生成的类中,扩展PApplet(删除默认/现有的空设置()和draw()函数),但仍然在类'scope({})

  2. 使用粘贴的代码(setup / draw / keyPressed / keyReleased / mousePressed / etc)来处理函数public(例如 public void setup(){// etc。 而不是 void setup(){// etc。

  3. 将其余的代码粘贴到其他选项卡进入由Proclipsing生成的相同的java类

  4. 在浮点型值附加一个'f'(显式浮点标志)(例如 3.0 成为 3.0f

  5. 如果您正在使用图书馆Proclipsing应该有助于:右键单击项目,然后转到Proclipsing项目属性如果您设置了正确的路径到处理文件夹(例如Documents / Processing),额外的库将会在那里,所以你只需要勾选/启用它们。否则,您将需要手动复制每个库的.jar文件并粘贴到项目的lib文件夹中,然后右键单击eclipse中的.jar文件,然后选择构建路径>添加到构建路径
  1. Copy the code from the main tab onto the Proclipsing generated class which extends PApplet(removing the default/existing empty setup() and draw() functions) but still within class' scope ({})
  2. Make Processing functions from the pasted code(setup/draw/keyPressed/keyReleased/mousePressed/etc.) public (e.g. public void setup(){//etc. instead of void setup(){//etc.)
  3. Paste the rest of the code from other tabs into the same java class generated by Proclipsing
  4. Append an 'f'(explicit float flag) to float type values(e.g. 3.0 becomes 3.0f)
  5. If you're using libraries Proclipsing should help with that: right click the project and go to the Proclipsing project properties. If you've setup the correct path to Processing's folder(e.g. Documents/Processing), the extra libraries will be there so you just need to tick/enable them. Otherwise you will need to manually copy the .jar file of each library and paste into your project's lib folder, then right click the .jar files in eclipse and select Build Path > Add to Build Path

更新
这里使用Processing的导出应用程序功能稍微简单一些。
我将使用来自示例>主题>模拟>植根的Daniel Shiffman的Boids示例来解释此工作流程,因为它有多个选项卡和类。

Update Here is a slightly simpler approach using Processing's Export Application feature. I will explain this workflow using the Daniel Shiffman's Boids example from Examples > Topics > Simulate > Flocking since it has multiple tabs and classes.


  1. 导出应用程序。这将生成一个包含Flocking.java的源文件夹的应用程序文件夹(正如我上面提到的,Processing实际上将所有标签捆绑到一个.java类中)

  2. 创建一个新的Proclipsing项目

  3. 将处理生成的类代码粘贴到语句之后的Proclipsing生成的类中(一个包是一个文件夹可以容纳多个类,所以使用它来保持文件夹的整理/组织良好的基于​​什么类)

  4. 更新底部的静态main方法来使用完全限定的类名(所以以名称为前缀的类名称)

  1. Export the application. This will generate an application folder including a source folder with Flocking.java (as I mentioned above, Processing actually bundles all your tabs into a single .java class)
  2. Create a new Proclipsing project
  3. Paste the code from the Processing generated class into the Proclipsing generated class after the package statement.(a package is a folder can hold multiple classes, so use this to keep things tidy/nicely organized in folders based on what the classes do)
  4. Update the static main method at the bottom to use the fully qualified class name (so the class name prefixed by the package name)

此时希望大部分错误都应该已经消失了。现在尝试运行代码作为Java应用程序。

At this point hopefully most of the errors should have disappeared. Try to run your code as a Java Application now.

问题是在这一点上,您有一个庞大的类仍然很难维护,这可能是您的原因在日食中排名第一。现在将是重构(重组你的代码)的时候,幸运的是eclipse有一些很棒的工具。
如果你看到重复的代码,这是一个很好的候选人的功能。您可以尝试选择该代码,右键单击,然后选择 Refactor>提取方法。重复代码中更改的值可以作为参数/参数提取。

The problem is at this point you have one massive class which is still hard to maintain, probably the reason you're moving to eclipse in the 1st place. Now would be the time to refactor(restructure your code) and luckily eclipse has some great tools for that. If you see repetitive code, that's a great candidate for a function. You can try selecting that code , right clicking then choosing Refactor > Extract Method. The values that change in the repeated code can be extracted as arguments/parameters.

内部类应该移动到新的.java文件,如果您在这些类中使用处理特定的功能,您有多个选项:

Inner classes should move to new .java files and if you use Processing specific functionalities in those classes you've got multiple options:


  1. 将PApplet作为参数传递给这些类(就像Jose在Eclipse中的处理文章链接所示)

  2. 使用PApplet的静态方法 PApplet.map()而不是 map()

  3. 实施PConstants

  4. 传递渲染器( PGraphics ),如果课程只处理在处理中绘制

  1. Passing the PApplet as an argument to those classes (like the Jose's Processing in Eclipse article link suggests)
  2. Using PApplet's static methods(e.g. PApplet.map() instead of map())
  3. Implementing PConstants in a class
  4. Passing the renderer(PGraphics) if a class only deals with drawing in Processing

最重要的是,你应该熟悉一下Java(从头开始编写一个HelloWorld程序)在处理的内部类),特别是一些OOP概念(组合,继承和可能的几个基本设计模式(如Visitor或MVC)在未来。当然,如果你刚刚开始使用这些概念:)

Most importantly though you should familiarize yourself a little bit with Java (compiling a HelloWorld program from scratch which will shine a light on Processing's inner classes) and especially some OOP concepts(composition, inheritance and perhaps a few basic design patterns (such as Visitor or MVC) in the future. This of course, if you're new to these concepts :)

更新这里的href =http://lifesine.eu/so/p5_to_eclipse.mp4 =nofollow>视频。前两分钟说明了基本过程,其余包括上述一些重构概念。

Update the simplified updated instructions for Proclipsing are now available as a video here. The first two minutes illustrate the basic process and the rest covers some of the refactoring concepts mentioned above.

这篇关于将处理项目移植到Eclipse中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆