diff --git a/.gitignore b/.gitignore index 31dcba4..fa8f9d7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Package Files # *.jar +!bluejext2.jar *.war *.ear diff --git a/libs/bluejext2.jar b/libs/bluejext2.jar new file mode 100644 index 0000000..29826a7 Binary files /dev/null and b/libs/bluejext2.jar differ diff --git a/pom.xml b/pom.xml index e698c34..2030ddb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ klasseneditor klasseneditor - 0.0.1 + 2.0.0 UTF-8 @@ -49,7 +49,7 @@ bluejext system 1.0 - ${basedir}\libs\bluejext.jar + ${basedir}\libs\bluejext2.jar diff --git a/src/main/java/class_diagram_editor/bluej_adapters/BlueJExtension.java b/src/main/java/class_diagram_editor/bluej_adapters/BlueJExtension.java index da93400..59f32fe 100644 --- a/src/main/java/class_diagram_editor/bluej_adapters/BlueJExtension.java +++ b/src/main/java/class_diagram_editor/bluej_adapters/BlueJExtension.java @@ -1,7 +1,7 @@ package class_diagram_editor.bluej_adapters; -import bluej.extensions.BlueJ; -import bluej.extensions.Extension; +import bluej.extensions2.BlueJ; +import bluej.extensions2.Extension; import class_diagram_editor.ClassEditorApplication; import class_diagram_editor.bluej_adapters.menu.BlueJMenuGenerator; import class_diagram_editor.bluej_adapters.source_control.PrintCodeSourceControl; @@ -16,7 +16,7 @@ public class BlueJExtension extends Extension { private static final String NAME = "Klasseneditor"; - private static final String VERSION = "0.0.1"; + private static final String VERSION = "2.0.0"; /** * Main method for starting the application directly @@ -55,7 +55,7 @@ public String getName() { } /** - * @return the version of the extension. TODO: update version on release + * @return the version of the extension. */ public String getVersion() { return VERSION; diff --git a/src/main/java/class_diagram_editor/bluej_adapters/menu/BlueJMenuGenerator.java b/src/main/java/class_diagram_editor/bluej_adapters/menu/BlueJMenuGenerator.java index 62ced61..1bcd926 100644 --- a/src/main/java/class_diagram_editor/bluej_adapters/menu/BlueJMenuGenerator.java +++ b/src/main/java/class_diagram_editor/bluej_adapters/menu/BlueJMenuGenerator.java @@ -1,16 +1,12 @@ package class_diagram_editor.bluej_adapters.menu; -import bluej.extensions.BPackage; -import bluej.extensions.BProject; -import bluej.extensions.MenuGenerator; -import bluej.extensions.ProjectNotOpenException; +import bluej.extensions2.BPackage; +import bluej.extensions2.BProject; +import bluej.extensions2.MenuGenerator; +import bluej.extensions2.ProjectNotOpenException; import class_diagram_editor.ClassEditorApplication; import class_diagram_editor.bluej_adapters.source_control.SourceControl; -import class_diagram_editor.bluej_adapters.source_control.SourceCodeControl; - -import javax.swing.AbstractAction; -import javax.swing.JMenuItem; -import java.awt.event.ActionEvent; +import javafx.scene.control.MenuItem; /** * Adds extra JMenu entries which belong to the {@link class_diagram_editor.bluej_adapters.BlueJExtension extension}. @@ -18,30 +14,22 @@ public class BlueJMenuGenerator extends MenuGenerator { @Override - public JMenuItem getToolsMenuItem(BPackage bp) { + public MenuItem getToolsMenuItem(BPackage bp) { try { BProject project = bp.getProject(); - return new JMenuItem(new OpenClassEditorAction(project.getName(), new SourceControl(project))); - } catch (ProjectNotOpenException e) { - return null; - } - } + MenuItem menuItem = new MenuItem("Klasseneditor öffnen"); - private static class OpenClassEditorAction extends AbstractAction { - private final SourceCodeControl sourceCodeControl; - private final String projectTitle; + final String projectName = project.getName(); + final SourceControl sourceControl = new SourceControl(project); - public OpenClassEditorAction(String projectTitle, SourceCodeControl sourceCodeControl) { - this.sourceCodeControl = sourceCodeControl; - this.projectTitle = projectTitle; + menuItem.setOnAction(event -> { + new ClassEditorApplication(projectName, sourceControl).run(); + }); - putValue(AbstractAction.NAME, "Klasseneditor öffnen"); - } - - @Override - public void actionPerformed(ActionEvent e) { - new ClassEditorApplication(projectTitle, sourceCodeControl).run(); + return menuItem; + } catch (ProjectNotOpenException e) { + return null; } } } diff --git a/src/main/java/class_diagram_editor/bluej_adapters/source_control/SourceControl.java b/src/main/java/class_diagram_editor/bluej_adapters/source_control/SourceControl.java index 06a8e0e..3b37f09 100644 --- a/src/main/java/class_diagram_editor/bluej_adapters/source_control/SourceControl.java +++ b/src/main/java/class_diagram_editor/bluej_adapters/source_control/SourceControl.java @@ -1,14 +1,9 @@ package class_diagram_editor.bluej_adapters.source_control; -import bluej.extensions.BClass; -import bluej.extensions.BPackage; -import bluej.extensions.BProject; -import bluej.extensions.ClassNotFoundException; -import bluej.extensions.MissingJavaFileException; -import bluej.extensions.PackageNotFoundException; -import bluej.extensions.ProjectNotOpenException; -import bluej.extensions.editor.Editor; -import bluej.extensions.editor.TextLocation; +import bluej.extensions2.*; +import bluej.extensions2.ClassNotFoundException; +import bluej.extensions2.editor.JavaEditor; +import bluej.extensions2.editor.TextLocation; import class_diagram_editor.code_generation.ClassDiagramGenerator; import class_diagram_editor.code_generation.CodeElement; import class_diagram_editor.code_generation.JavaCodeGenerator; @@ -17,7 +12,6 @@ import java.io.File; import java.io.IOException; -import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; @@ -60,7 +54,7 @@ public void generateCode(ClassDiagram classDiagram, GenerationType generationTyp while (iterator.hasNext()) { CodeElement codeElement = iterator.next(); - Editor editor = createFile(bpackage, codeElement); + JavaEditor editor = createFile(bpackage, codeElement); if (editor != null) { generateElement(editor, codeElement); @@ -81,7 +75,7 @@ public ClassDiagram generateDiagram() { BPackage bpackage = project.getPackages()[0]; for (BClass bClass : bpackage.getClasses()) { - final Editor editor = bClass.getEditor(); + final JavaEditor editor = bClass.getJavaEditor(); final String elementContent = editor.getText(START_LOCATION, getEndLocation(editor)); @@ -122,8 +116,8 @@ private void createBackup(File directory) { } } - private Editor createFile(BPackage bPackage, CodeElement codeElement) { - Editor editor = null; + private JavaEditor createFile(BPackage bPackage, CodeElement codeElement) { + JavaEditor editor = null; try { File javaFile = new File(bPackage.getDir(), codeElement.getLastGeneratedName() + JAVA_FILE_EXTENSION); @@ -134,10 +128,10 @@ private Editor createFile(BPackage bPackage, CodeElement codeElement) { } if (javaFile.exists() && !elementRenamed) { - editor = bPackage.getBClass(codeElement.getName()).getEditor(); + editor = bPackage.getBClass(codeElement.getName()).getJavaEditor(); } else { if (javaFile.createNewFile() || javaFile.exists()) { - editor = bPackage.newClass(codeElement.getName()).getEditor(); + editor = bPackage.newClass(codeElement.getName()).getJavaEditor(); } } } catch (ProjectNotOpenException | PackageNotFoundException | MissingJavaFileException @@ -149,7 +143,7 @@ private Editor createFile(BPackage bPackage, CodeElement codeElement) { } private File renameOldClassWithNew(BPackage bPackage, File javaFile, CodeElement codeElement) - throws ProjectNotOpenException, PackageNotFoundException, ClassNotFoundException, IOException { + throws ProjectNotOpenException, PackageNotFoundException, IOException, ClassNotFoundException { File newJavaFile = new File(bPackage.getDir(), codeElement.getName() + JAVA_FILE_EXTENSION); if (javaFile.exists()) { @@ -170,7 +164,7 @@ private File renameOldClassWithNew(BPackage bPackage, File javaFile, CodeElement return newJavaFile; } - private void generateElement(Editor editor, CodeElement codeElement) { + private void generateElement(JavaEditor editor, CodeElement codeElement) { editor.setReadOnly(true); final TextLocation endLocation = getEndLocation(editor); @@ -187,7 +181,7 @@ private void generateElement(Editor editor, CodeElement codeElement) { editor.setReadOnly(false); } - private TextLocation getEndLocation(Editor editor) { + private TextLocation getEndLocation(JavaEditor editor) { // line index is zero indexed int lastLine = editor.getLineCount() - 1; int lastColumn = editor.getLineLength(lastLine); diff --git a/src/main/java/class_diagram_editor/code_generation/CodeRepository.java b/src/main/java/class_diagram_editor/code_generation/CodeRepository.java index 9268a88..759335a 100644 --- a/src/main/java/class_diagram_editor/code_generation/CodeRepository.java +++ b/src/main/java/class_diagram_editor/code_generation/CodeRepository.java @@ -45,6 +45,10 @@ public CodeRepository() { } private void initialize(String elementName, String sourceCode) { + if (sourceCode.isEmpty()) { + return; + } + try { JavaProjectBuilder builder = new JavaProjectBuilder();