Skip to content

Commit

Permalink
Merge pull request #34 from danstooamerican/bluej5-update
Browse files Browse the repository at this point in the history
Bluej5 update
  • Loading branch information
danstooamerican authored Oct 25, 2021
2 parents 388f28f + b060377 commit bf8ed0c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Package Files #
*.jar
!bluejext2.jar
*.war
*.ear

Expand Down
Binary file added libs/bluejext2.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>klasseneditor</groupId>
<artifactId>klasseneditor</artifactId>
<version>0.0.1</version>
<version>2.0.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -49,7 +49,7 @@
<artifactId>bluejext</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\libs\bluejext.jar</systemPath>
<systemPath>${basedir}\libs\bluejext2.jar</systemPath>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
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}.
*/
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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()) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public CodeRepository() {
}

private void initialize(String elementName, String sourceCode) {
if (sourceCode.isEmpty()) {
return;
}

try {
JavaProjectBuilder builder = new JavaProjectBuilder();

Expand Down

0 comments on commit bf8ed0c

Please sign in to comment.