From 808ef0cc89522dde0ac253fb858a23c36f5f429b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 18 Aug 2017 13:53:31 +0200 Subject: [PATCH] Added text area handle --- .../pmd/lang/LanguageRegistry.java | 10 +-- .../fxdesigner/DesignerController.java | 56 +++---------- .../util/fxdesigner/fxdesigner/designer.fxml | 82 ++++++++++--------- 3 files changed, 57 insertions(+), 91 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java index 593cf65aed..6c6a9e3575 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java @@ -26,11 +26,9 @@ public final class LanguageRegistry { private LanguageRegistry() { List languagesList = new ArrayList<>(); ServiceLoader languageLoader = ServiceLoader.load(Language.class); - Iterator iterator = languageLoader.iterator(); - while (iterator.hasNext()) { + for (Language aLanguageLoader : languageLoader) { try { - Language language = iterator.next(); - languagesList.add(language); + languagesList.add(aLanguageLoader); } catch (UnsupportedClassVersionError e) { // Some languages require java8 and are therefore only available // if java8 or later is used as runtime. @@ -120,9 +118,7 @@ public final class LanguageRegistry { public static List findAllVersions() { List versions = new ArrayList<>(); for (Language language : getLanguages()) { - for (LanguageVersion languageVersion : language.getVersions()) { - versions.add(languageVersion); - } + versions.addAll(language.getVersions()); } return versions; } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/fxdesigner/DesignerController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/fxdesigner/DesignerController.java index e73ad82caf..f9b554dac9 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/fxdesigner/DesignerController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/fxdesigner/DesignerController.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.util.fxdesigner.fxdesigner; import java.io.StringReader; import java.net.URL; +import java.util.HashMap; import java.util.Map; import java.util.ResourceBundle; @@ -22,19 +23,23 @@ import javafx.fxml.Initializable; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; import javafx.scene.control.RadioMenuItem; +import javafx.scene.control.TextArea; import javafx.scene.control.ToggleGroup; /** * @author Clément Fournier */ -class DesignerController implements Initializable { +public class DesignerController implements Initializable { + + @FXML + public TextArea codeEditorArea; @FXML private Menu languageMenu; private LanguageVersion selectedLanguageVersion; - private Map languageRadioMenuMap; + private Map languageRadioMenuMap = new HashMap<>(); @Override @@ -47,13 +52,11 @@ class DesignerController implements Initializable { private void initializeLanguageVersionMenu() { LanguageVersion[] supported = DesignerUtil.getSupportedLanguageVersions(); ObservableList items = languageMenu.getItems(); - assert items.size() == 0; - - System.out.println(supported); ToggleGroup group = new ToggleGroup(); for (LanguageVersion version : supported) { RadioMenuItem item = new RadioMenuItem(version.getShortName()); + item.setToggleGroup(group); items.add(item); languageRadioMenuMap.put(version, item); } @@ -68,52 +71,15 @@ class DesignerController implements Initializable { private Node getCompilationUnit() { LanguageVersionHandler languageVersionHandler = getLanguageVersionHandler(); - return getCompilationUnit(languageVersionHandler); + return getCompilationUnit(languageVersionHandler, codeEditorArea.getText()); } - - private Node getCompilationUnit(LanguageVersionHandler languageVersionHandler) { - return null; //getCompilationUnit(languageVersionHandler, codeEditorPane.getText()); - } - - - private LanguageVersion getLanguageVersion() { - return DesignerUtil.getSupportedLanguageVersions()[selectedLanguageVersionIndex()]; - } - - - private void setLanguageVersion(LanguageVersion languageVersion) { - if (languageVersion != null) { - LanguageVersion[] versions = DesignerUtil.getSupportedLanguageVersions(); - for (int i = 0; i < versions.length; i++) { - LanguageVersion version = versions[i]; - if (languageVersion.equals(version)) { - // languageVersionMenuItems[i].setSelected(true); - break; - } - } - } - } - - - private int selectedLanguageVersionIndex() { - /* for (int i = 0; i < languageVersionMenuItems.length; i++) { - if (languageVersionMenuItems[i].isSelected()) { - return i; - } - } - */ - throw new RuntimeException("Initial default language version not specified"); - } - - LanguageVersionHandler getLanguageVersionHandler() { - LanguageVersion languageVersion = getLanguageVersion(); - return languageVersion.getLanguageVersionHandler(); + return selectedLanguageVersion.getLanguageVersionHandler(); } - static Node getCompilationUnit(LanguageVersionHandler languageVersionHandler, String code) { + private static Node getCompilationUnit(LanguageVersionHandler languageVersionHandler, String code) { Parser parser = languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()); Node node = parser.parse(null, new StringReader(code)); languageVersionHandler.getSymbolFacade().start(node); diff --git a/pmd-ui/src/main/resources/net/sourceforge/pmd/util/fxdesigner/fxdesigner/designer.fxml b/pmd-ui/src/main/resources/net/sourceforge/pmd/util/fxdesigner/fxdesigner/designer.fxml index 0ad714dea1..6afd54d6ae 100644 --- a/pmd-ui/src/main/resources/net/sourceforge/pmd/util/fxdesigner/fxdesigner/designer.fxml +++ b/pmd-ui/src/main/resources/net/sourceforge/pmd/util/fxdesigner/fxdesigner/designer.fxml @@ -1,45 +1,49 @@ - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - -
- - - - -