diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 53db01905..8548c9d00 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,9 +5,7 @@ name: Java CI with Gradle on: push: - branches: [ master ] pull_request: - branches: [ master ] jobs: build: @@ -24,3 +22,17 @@ jobs: run: chmod +x gradlew - name: Build with Gradle run: ./gradlew build -x test + + checkstyle: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: gradlew executable + run: chmod +x gradlew + - name: Run checkstyle + run: ./gradlew check diff --git a/build.gradle b/build.gradle index d97583d68..4b4dbf38b 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ version '2.0.0' apply plugin: 'java' apply plugin: 'application' +apply plugin: 'checkstyle' mainClassName = 'edu.rpi.legup.Legup' sourceCompatibility = 1.8 diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..7ce5010e2 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/legup-update/src/main/java/edu/rpi/legupupdate/Update.java b/legup-update/src/main/java/edu/rpi/legupupdate/Update.java index e9ba837f5..578c4f002 100644 --- a/legup-update/src/main/java/edu/rpi/legupupdate/Update.java +++ b/legup-update/src/main/java/edu/rpi/legupupdate/Update.java @@ -46,7 +46,8 @@ public class Update { try { version = reader.readLine(); reader.close(); - } catch (IOException e) { + } + catch (IOException e) { logger.severe("An error occurred while attempting to read the version\n" + e.getMessage()); } VERSION = version; @@ -75,18 +76,22 @@ public boolean checkUpdate() { InputStreamReader reader = new InputStreamReader(in)) { releaseData = new JsonParser().parse(reader).getAsJsonObject(); JsonElement tagElement = releaseData.get("tag_name"); - if (tagElement == null) + if (tagElement == null) { return false; + } updateVersion = tagElement.getAsString(); logger.info("Current version: " + VERSION); logger.info("Latest version: " + updateVersion); if (NetUtil.versionCompare(VERSION, updateVersion) < 0) { logger.info("Update available"); return true; - } else + } + else { logger.info("No update available"); + } } - } catch (IOException e) { + } + catch (IOException e) { logger.severe("Failed to check for update\n" + e.getMessage()); } return false; @@ -94,12 +99,14 @@ public boolean checkUpdate() { private String getAssetUrl(String assetName) { JsonArray array = releaseData.get("assets").getAsJsonArray(); - if (array == null) + if (array == null) { return null; + } for (int i = 0; i < array.size(); ++i) { JsonObject asset = array.get(i).getAsJsonObject(); - if (asset.get("name").getAsString().equals(assetName)) + if (asset.get("name").getAsString().equals(assetName)) { return asset.get("browser_download_url").getAsString(); + } } return null; } @@ -111,15 +118,18 @@ private void getLibs(String urlStr, HashMap set) throws IOExcept BufferedReader reader = new BufferedReader(isr)) { String line; while ((line = reader.readLine()) != null) { - if (!line.contains(LIBRARY_LINE_ID)) + if (!line.contains(LIBRARY_LINE_ID)) { continue; + } Matcher m = LIB_PATTERN.matcher(line); - if (!m.find()) + if (!m.find()) { continue; + } line = m.group(); String[] split = line.split(":"); - if (split.length != 3) + if (split.length != 3) { throw new IOException("Invalid library list in remote repository"); + } String groupId = split[0].replaceAll("\\.", "/"); String artifactId = split[1]; String version = split[2]; @@ -146,8 +156,9 @@ private void downloadFile(String urlStr, File destination) throws IOException { } public boolean update() { - if (releaseData == null) + if (releaseData == null) { return false; + } if (guessDevEnvironment()) { logger.warning("Legup appears to be running in a development environment so automatic updating has been disabled"); // return false; @@ -159,8 +170,9 @@ public boolean update() { progress.setDescription("Starting update"); } String jarUrl = getAssetUrl(updateStream.assetName); - if (jarUrl == null) + if (jarUrl == null) { return false; + } try { HashMap libs = getLibs(); if (!downloadDir.exists() && !downloadDir.mkdirs()) { @@ -184,13 +196,14 @@ public boolean update() { downloadFile(lib.getValue(), new File(libDir, lib.getKey())); current++; } - if(progress != null) { + if (progress != null) { progress.setCurrentDownload(current); progress.setDescription("Download complete!"); } logger.info("Download complete"); return true; - } catch (IOException e) { + } + catch (IOException e) { logger.severe("Failed to update Legup\n" + e.getMessage()); return false; } @@ -203,11 +216,14 @@ private void unzipFile(File file) throws IOException { ZipEntry entry = entries.nextElement(); File entryDestination = new File(downloadDir, entry.getName()); if (entry.isDirectory()) { - if (!entryDestination.exists() && !entryDestination.mkdirs()) + if (!entryDestination.exists() && !entryDestination.mkdirs()) { throw new IOException("Failed to unzip file: " + file.getCanonicalPath()); - } else { - if (!entryDestination.getParentFile().exists() && !entryDestination.getParentFile().mkdirs()) + } + } + else { + if (!entryDestination.getParentFile().exists() && !entryDestination.getParentFile().mkdirs()) { throw new IOException("Failed to unzip file: " + file.getCanonicalPath()); + } try (InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination)) { IOUtils.copy(in, out); diff --git a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml index 231c2cfed..0bf6a8c76 100644 --- a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml +++ b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml @@ -1,10 +1,11 @@
-
- - - - - -
+
+ + + + + +
diff --git a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.6.0.20150526-2032.xml b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.6.0.20150526-2032.xml index e33758c3a..63d411340 100644 --- a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.6.0.20150526-2032.xml +++ b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.6.0.20150526-2032.xml @@ -1,43 +1,43 @@ - - - %date [%thread] %-5level %logger{35} - %msg%n - - - OFF - - + + + %date [%thread] %-5level %logger{35} - %msg%n + + + OFF + + - - ${org.eclipse.m2e.log.dir}/0.log - - ${org.eclipse.m2e.log.dir}/%i.log - 1 - 10 - - - 100MB - - - %date [%thread] %-5level %logger{35} - %msg%n - - + + ${org.eclipse.m2e.log.dir}/0.log + + ${org.eclipse.m2e.log.dir}/%i.log + 1 + 10 + + + 100MB + + + %date [%thread] %-5level %logger{35} - %msg%n + + - - - WARN - - + + + WARN + + - - - - - - - - - + + - + + + + + + + + diff --git a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml index a033ea971..c00d6ca9e 100644 --- a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml +++ b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -1,11 +1,11 @@
-
- - -
-
- - -
+
+ + +
+
+ + +
diff --git a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml index 851c296e6..d2ff1eed0 100644 --- a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml +++ b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml @@ -1,15 +1,15 @@
-
- - - - - - - - - - -
+
+ + + + + + + + + + +
diff --git a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml index 3f804cad8..5e61d80ea 100644 --- a/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml +++ b/src/main/java/edu/rpi/legup/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -1,4 +1,5 @@ - + \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/Legup.java b/src/main/java/edu/rpi/legup/Legup.java index 3298e429a..5e69bc8f1 100644 --- a/src/main/java/edu/rpi/legup/Legup.java +++ b/src/main/java/edu/rpi/legup/Legup.java @@ -21,13 +21,14 @@ public class Legup { static { String logPath = ""; - try { - logPath = Paths.get(Legup.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toFile().getParent(); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - System.exit(0); - } + try { + logPath = Paths.get(Legup.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toFile().getParent(); + } + catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + System.exit(0); + } logPath += logPath.endsWith(File.separator) ? "" : File.separator; LoggerContext context = (LoggerContext) LogManager.getContext(false); Configuration config = context.getConfiguration(); @@ -66,7 +67,8 @@ private static void setConfig() { Config config = null; try { config = new Config(); - } catch (InvalidConfigException e) { + } + catch (InvalidConfigException e) { System.exit(1); } GameBoardFacade.getInstance().setConfig(config); diff --git a/src/main/java/edu/rpi/legup/ai/Solver.java b/src/main/java/edu/rpi/legup/ai/Solver.java index ca44142bb..68b934bfb 100644 --- a/src/main/java/edu/rpi/legup/ai/Solver.java +++ b/src/main/java/edu/rpi/legup/ai/Solver.java @@ -1,5 +1,4 @@ package edu.rpi.legup.ai; -public class Solver -{ +public class Solver { } diff --git a/src/main/java/edu/rpi/legup/app/Config.java b/src/main/java/edu/rpi/legup/app/Config.java index b03b01cb9..eeb6f1824 100644 --- a/src/main/java/edu/rpi/legup/app/Config.java +++ b/src/main/java/edu/rpi/legup/app/Config.java @@ -42,12 +42,13 @@ public List getPuzzleNames() { return new ArrayList<>(puzzles.keySet()); } - public List getFileCreationEnabledPuzzles() - { + public List getFileCreationEnabledPuzzles() { LinkedList puzzles = new LinkedList(); - for (String puzzle : this.puzzles.keySet()) - if (!this.fileCreationDisabledStatuses.get(puzzle)) + for (String puzzle : this.puzzles.keySet()) { + if (!this.fileCreationDisabledStatuses.get(puzzle)) { puzzles.add(puzzle); + } + } return puzzles; } @@ -90,12 +91,13 @@ private void loadConfig(InputStream stream) throws InvalidConfigException { String name = puzzle.getAttribute("name"); String className = puzzle.getAttribute("qualifiedClassName"); boolean status = Boolean.parseBoolean(puzzle.getAttribute("fileCreationDisabled").toLowerCase()); - Logger.debug("Class Name: "+className); + Logger.debug("Class Name: " + className); this.puzzles.put(name, className); this.fileCreationDisabledStatuses.put(name, Boolean.valueOf(status)); } - } catch (ParserConfigurationException | SAXException | IOException e) { + } + catch (ParserConfigurationException | SAXException | IOException e) { throw new InvalidConfigException(e.getMessage()); } } diff --git a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java index 240ccc090..d19943bcb 100644 --- a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java +++ b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java @@ -77,7 +77,7 @@ public synchronized static GameBoardFacade getInstance() { } public void initializeUI() { - EventQueue.invokeLater(() ->{ + EventQueue.invokeLater(() -> { legupUI = new LegupUI(); puzzleSolver = legupUI.getProofEditor(); puzzleEditor = legupUI.getPuzzleEditor(); @@ -105,9 +105,9 @@ public void setConfig(Config config) { /** * Loads an empty puzzle * - * @param game name of the puzzle - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param game name of the puzzle + * @param rows the number of rows on the board + * @param columns the number of columns on the board */ public void loadPuzzle(String game, int rows, int columns) throws RuntimeException { String qualifiedClassName = config.getPuzzleClassForName(game); @@ -131,13 +131,11 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti // puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); setPuzzleEditor(puzzle); } - catch (IllegalArgumentException exception) - { + catch (IllegalArgumentException exception) { throw new IllegalArgumentException(exception.getMessage()); } - catch(ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) - { + catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException | InstantiationException e) { LOGGER.error(e); throw new RuntimeException("Puzzle creation error"); } @@ -153,7 +151,8 @@ public void loadPuzzle(String fileName) throws InvalidFileFormatException { loadPuzzle(new FileInputStream(fileName)); curFileName = fileName; setWindowTitle(puzzle.getName(), fileName); - } catch (IOException e) { + } + catch (IOException e) { LOGGER.error("Invalid file " + fileName, e); throw new InvalidFileFormatException("Could not find file"); } @@ -170,7 +169,8 @@ public void loadPuzzle(InputStream inputStream) throws InvalidFileFormatExceptio DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); - } catch (IOException | SAXException | ParserConfigurationException e) { + } + catch (IOException | SAXException | ParserConfigurationException e) { LOGGER.error("Invalid file", e); throw new InvalidFileFormatException("Could not find file"); } @@ -198,12 +198,14 @@ public void loadPuzzle(InputStream inputStream) throws InvalidFileFormatExceptio puzzle.initializeView(); puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); setPuzzle(puzzle); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) { + } + catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException | InstantiationException e) { LOGGER.error(e); throw new InvalidFileFormatException("Puzzle creation error"); } - } else { + } + else { LOGGER.error("Invalid file"); throw new InvalidFileFormatException("Invalid file: must be a Legup file"); } diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index 92469f4ab..06275927d 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -79,7 +79,7 @@ public String getUserPref(String key) { /** * Gets the user preference by the string key, value pair * - * @param key key name of the preference + * @param key key name of the preference * @param value value of the preference */ public void setUserPref(String key, String value) { @@ -88,12 +88,16 @@ public void setUserPref(String key, String value) { } public boolean getUserPrefAsBool(String key) { - if(preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(true))) { + if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(true))) { return true; - } else if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(false))) { - return false; - } else { - throw new RuntimeException("Cannot get user preference - " + key); + } + else { + if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(false))) { + return false; + } + else { + throw new RuntimeException("Cannot get user preference - " + key); + } } } } diff --git a/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java b/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java index e1a769610..a03a77a03 100644 --- a/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java +++ b/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java @@ -67,25 +67,31 @@ public void keyPressed(KeyEvent e) { String update = ""; if (rule.getRuleType() == RuleType.CASE) { // handleCaseRule((CaseRule)rule); - } else if (rule.getRuleType() == RuleType.CONTRADICTION) { - TreeViewSelection selection = treeView.getSelection(); - - ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); - if (validate.canExecute()) { - getInstance().getHistory().pushChange(validate); - validate.execute(); - } else { - update = validate.getError(); + } + else { + if (rule.getRuleType() == RuleType.CONTRADICTION) { + TreeViewSelection selection = treeView.getSelection(); + + ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); + if (validate.canExecute()) { + getInstance().getHistory().pushChange(validate); + validate.execute(); + } + else { + update = validate.getError(); + } } - } else { - TreeViewSelection selection = treeView.getSelection(); - - ICommand validate = new ValidateBasicRuleCommand(selection, (BasicRule) rule); - if (validate.canExecute()) { - getInstance().getHistory().pushChange(validate); - validate.execute(); - } else { - update = validate.getError(); + else { + TreeViewSelection selection = treeView.getSelection(); + + ICommand validate = new ValidateBasicRuleCommand(selection, (BasicRule) rule); + if (validate.canExecute()) { + getInstance().getHistory().pushChange(validate); + validate.execute(); + } + else { + update = validate.getError(); + } } } GameBoardFacade.getInstance().getLegupUI().getTreePanel().updateError(update); diff --git a/src/main/java/edu/rpi/legup/controller/Controller.java b/src/main/java/edu/rpi/legup/controller/Controller.java index e52b9133f..5eef8cc17 100644 --- a/src/main/java/edu/rpi/legup/controller/Controller.java +++ b/src/main/java/edu/rpi/legup/controller/Controller.java @@ -119,10 +119,11 @@ public void mouseMoved(MouseEvent e) { public void mouseWheelMoved(MouseWheelEvent e) { // System.out.println(e.getWheelRotation()); if (e.isControlDown()) { - if (e.getWheelRotation() != 0){ + if (e.getWheelRotation() != 0) { viewer.zoom(e.getWheelRotation() * 2, e.getPoint()); } - } else { + } + else { if (e.getWheelRotation() != 0) { viewer.zoom(e.getWheelRotation(), e.getPoint()); } diff --git a/src/main/java/edu/rpi/legup/controller/ElementController.java b/src/main/java/edu/rpi/legup/controller/ElementController.java index 80f80db3e..7128857a6 100644 --- a/src/main/java/edu/rpi/legup/controller/ElementController.java +++ b/src/main/java/edu/rpi/legup/controller/ElementController.java @@ -84,16 +84,19 @@ public void mouseReleased(MouseEvent e) { autoCaseRuleCommand.execute(); getInstance().getHistory().pushChange(autoCaseRuleCommand); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(autoCaseRuleCommand.getError()); } - } else { + } + else { ICommand edit = new EditDataCommand(elementView, selection, e); if (edit.canExecute()) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(edit.getError()); } } @@ -110,7 +113,7 @@ public void mouseEntered(MouseEvent e) { boardView.setFocusable(true); boardView.requestFocusInWindow(); TreeElement treeElement = boardView.getTreeElement(); - DynamicView dynamicView = getInstance().getLegupUI().getDynamicBoardView(); + DynamicView dynamicView = getInstance().getLegupUI().getDynamicBoardView(); BoardView boardView = getInstance().getLegupUI().getBoardView(); Board board = boardView.getBoard(); ElementView elementView = boardView.getElement(e.getPoint()); @@ -118,7 +121,7 @@ public void mouseEntered(MouseEvent e) { String error = null; if (elementView != null) { selection.newHover(elementView); - if(LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { + if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { PuzzleElement element = elementView.getPuzzleElement(); if (treeElement.getType() == TreeElementType.TRANSITION && board.getModifiedData().contains(element)) { TreeTransition transition = (TreeTransition) treeElement; @@ -128,7 +131,8 @@ public void mouseEntered(MouseEvent e) { } if (error != null) { dynamicView.updateError(error); - } else { + } + else { dynamicView.resetStatus(); } } @@ -144,7 +148,7 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { boardView.setFocusable(false); - DynamicView dynamicView = getInstance().getLegupUI().getDynamicBoardView(); + DynamicView dynamicView = getInstance().getLegupUI().getDynamicBoardView(); BoardView boardView = getInstance().getLegupUI().getBoardView(); ElementView element = boardView.getElement(e.getPoint()); if (element != null) { @@ -174,13 +178,13 @@ public void mouseMoved(MouseEvent e) { BoardView boardView = getInstance().getLegupUI().getBoardView(); Board board = boardView.getBoard(); TreeElement treeElement = boardView.getTreeElement(); - DynamicView dynamicView = getInstance().getLegupUI().getDynamicBoardView(); + DynamicView dynamicView = getInstance().getLegupUI().getDynamicBoardView(); ElementView elementView = boardView.getElement(e.getPoint()); ElementSelection selection = boardView.getSelection(); String error = null; if (elementView != null && elementView != selection.getHover()) { selection.newHover(elementView); - if(LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { + if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { PuzzleElement element = elementView.getPuzzleElement(); if (treeElement.getType() == TreeElementType.TRANSITION && board.getModifiedData().contains(element)) { TreeTransition transition = (TreeTransition) treeElement; @@ -190,7 +194,8 @@ public void mouseMoved(MouseEvent e) { } if (error != null) { dynamicView.updateError(error); - } else { + } + else { dynamicView.resetStatus(); } } @@ -225,10 +230,12 @@ public void actionPerformed(ActionEvent e) { puzzleElement.setData(value); - if (puzzleElement.equalsData(prevBord.getPuzzleElement(puzzleElement))) + if (puzzleElement.equalsData(prevBord.getPuzzleElement(puzzleElement))) { puzzleElement.setModified(false); - else + } + else { puzzleElement.setModified(true); + } transitionView.getTreeElement().propagateChange(puzzleElement); diff --git a/src/main/java/edu/rpi/legup/controller/RuleController.java b/src/main/java/edu/rpi/legup/controller/RuleController.java index 12fef9b77..6abe39d84 100644 --- a/src/main/java/edu/rpi/legup/controller/RuleController.java +++ b/src/main/java/edu/rpi/legup/controller/RuleController.java @@ -51,46 +51,58 @@ public void buttonPressed(Rule rule) { if (caseRuleCommand.canExecute()) { caseRuleCommand.execute(); getInstance().getHistory().pushChange(caseRuleCommand); - } else { + } + else { updateErrorString = caseRuleCommand.getError(); } - } else { + } + else { if (LegupPreferences.getInstance().getUserPref(LegupPreferences.AUTO_GENERATE_CASES).equalsIgnoreCase(Boolean.toString(true))) { CaseBoard caseBoard = caseRule.getCaseBoard(element.getBoard()); if (caseBoard != null && caseBoard.getCount() > 0) { puzzle.notifyBoardListeners(listener -> listener.onCaseBoardAdded(caseBoard)); - } else { + } + else { updateErrorString = "This board cannot be applied with this case rule."; } - } else { + } + else { updateErrorString = "Auto generated case rules are turned off in preferences."; } } - } else { + } + else { ICommand caseRuleCommand = new ValidateCaseRuleCommand(selection, caseRule); if (caseRuleCommand.canExecute()) { caseRuleCommand.execute(); getInstance().getHistory().pushChange(caseRuleCommand); - } else { + } + else { updateErrorString = caseRuleCommand.getError(); } } - } else if (rule.getRuleType() == RuleType.CONTRADICTION) { - ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); - if (validate.canExecute()) { - getInstance().getHistory().pushChange(validate); - validate.execute(); - } else { - updateErrorString = validate.getError(); + } + else { + if (rule.getRuleType() == RuleType.CONTRADICTION) { + ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); + if (validate.canExecute()) { + getInstance().getHistory().pushChange(validate); + validate.execute(); + } + else { + updateErrorString = validate.getError(); + } } - } else { - boolean def = LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES); - ICommand validate = def ? new ApplyDefaultBasicRuleCommand(selection, (BasicRule) rule) : new ValidateBasicRuleCommand(selection, (BasicRule) rule); - if (validate.canExecute()) { - getInstance().getHistory().pushChange(validate); - validate.execute(); - } else { - updateErrorString = validate.getError(); + else { + boolean def = LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES); + ICommand validate = def ? new ApplyDefaultBasicRuleCommand(selection, (BasicRule) rule) : new ValidateBasicRuleCommand(selection, (BasicRule) rule); + if (validate.canExecute()) { + getInstance().getHistory().pushChange(validate); + validate.execute(); + } + else { + updateErrorString = validate.getError(); + } } } GameBoardFacade.getInstance().getLegupUI().getTreePanel().updateError(updateErrorString); diff --git a/src/main/java/edu/rpi/legup/controller/TreeController.java b/src/main/java/edu/rpi/legup/controller/TreeController.java index 55306798b..b954edd79 100644 --- a/src/main/java/edu/rpi/legup/controller/TreeController.java +++ b/src/main/java/edu/rpi/legup/controller/TreeController.java @@ -57,12 +57,16 @@ public void mouseReleased(MouseEvent e) { if (treeElementView != null) { if (e.isShiftDown()) { selection.addToSelection(treeElementView); - } else if (e.isControlDown()) { - if(!(selection.getSelectedViews().size() == 1 && treeElementView == selection.getFirstSelection())) { - selection.toggleSelection(treeElementView); + } + else { + if (e.isControlDown()) { + if (!(selection.getSelectedViews().size() == 1 && treeElementView == selection.getFirstSelection())) { + selection.toggleSelection(treeElementView); + } + } + else { + selection.newSelection(treeElementView); } - } else { - selection.newSelection(treeElementView); } puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); @@ -135,10 +139,13 @@ public void mouseMoved(MouseEvent e) { puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); selection.newHover(treeElementView); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); - } else if (treeElementView == null && selection.getHover() != null) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement())); - selection.clearHover(); - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); + } + else { + if (treeElementView == null && selection.getHover() != null) { + puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement())); + selection.clearHover(); + puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); + } } } } diff --git a/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java b/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java index 2f4733a55..0aa6f416d 100644 --- a/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java +++ b/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java @@ -41,12 +41,14 @@ public void executeCommand() { for (TreeElementView view : selectedViews) { TreeElement treeElement = view.getTreeElement(); TreeElement child = addChild.get(treeElement); - if(child == null) { + if (child == null) { child = tree.addTreeElement(treeElement); - } else { + } + else { if (treeElement.getType() == TreeElementType.NODE) { - child = tree.addTreeElement((TreeNode)treeElement, (TreeTransition)child); - } else { + child = tree.addTreeElement((TreeNode) treeElement, (TreeTransition) child); + } + else { child = tree.addTreeElement((TreeTransition) treeElement, (TreeNode) child); } } @@ -74,7 +76,8 @@ public String getErrorString() { List selectedViews = selection.getSelectedViews(); if (selectedViews.isEmpty()) { return CommandError.NO_SELECTED_VIEWS.toString(); - } else { + } + else { for (TreeElementView view : selectedViews) { TreeElement element = view.getTreeElement(); if (element.getType() == TreeElementType.TRANSITION) { @@ -82,11 +85,12 @@ public String getErrorString() { if (transition.getChildNode() != null) { return CommandError.ADD_WITH_CHILD.toString(); } - } else { - TreeNode node = (TreeNode)element; - if(!node.getChildren().isEmpty()) { + } + else { + TreeNode node = (TreeNode) element; + if (!node.getChildren().isEmpty()) { TreeTransition transition = node.getChildren().get(0); - if(transition.getParents().size() > 1) { + if (transition.getParents().size() > 1) { return CommandError.ADD_TO_MERGE.toString(); } } diff --git a/src/main/java/edu/rpi/legup/history/ApplyDefaultBasicRuleCommand.java b/src/main/java/edu/rpi/legup/history/ApplyDefaultBasicRuleCommand.java index a212ec602..23f2fa066 100644 --- a/src/main/java/edu/rpi/legup/history/ApplyDefaultBasicRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ApplyDefaultBasicRuleCommand.java @@ -21,7 +21,7 @@ public class ApplyDefaultBasicRuleCommand extends PuzzleCommand { * ApplyDefaultBasicRuleCommand Constructor creates a command for applying the default of a basic rule * * @param selection selection of tree element views - * @param rule basic rule for the command + * @param rule basic rule for the command */ public ApplyDefaultBasicRuleCommand(TreeViewSelection selection, BasicRule rule) { this.selection = selection.copy(); @@ -40,17 +40,22 @@ public String getErrorString() { List selectedViews = selection.getSelectedViews(); if (selectedViews.isEmpty()) { return CommandError.DEFAULT_APPLICATION + " - " + CommandError.NO_SELECTED_VIEWS.toString(); - } else { + } + else { for (TreeElementView view : selectedViews) { TreeElement element = view.getTreeElement(); if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; if (!node.getChildren().isEmpty()) { return CommandError.DEFAULT_APPLICATION + " - " + CommandError.NO_CHILDREN.toString(); - } else if (rule.getDefaultBoard(node) == null) { - return CommandError.DEFAULT_APPLICATION + " - " + "This selection contains a tree element that this rule cannot be applied to."; } - } else { + else { + if (rule.getDefaultBoard(node) == null) { + return CommandError.DEFAULT_APPLICATION + " - " + "This selection contains a tree element that this rule cannot be applied to."; + } + } + } + else { return CommandError.DEFAULT_APPLICATION + " - " + CommandError.SELECTION_CONTAINS_TRANSITION.toString(); } } @@ -77,7 +82,8 @@ public void executeCommand() { transition = (TreeTransition) tree.addTreeElement(node); childNode = (TreeNode) tree.addTreeElement(transition); addMap.put(node, transition); - } else { + } + else { tree.addTreeElement(node, transition); childNode = transition.getChildNode(); } diff --git a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java index c61875b74..ae5f62f22 100644 --- a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java @@ -64,7 +64,8 @@ public void executeCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(transition)); newSelection.addToSelection(treeView.getElementView(childNode)); } - } else { + } + else { for (final TreeTransition transition : caseTrans) { tree.addTreeElement(node, transition); TreeNode childNode = transition.getChildNode(); diff --git a/src/main/java/edu/rpi/legup/history/CommandError.java b/src/main/java/edu/rpi/legup/history/CommandError.java index a60ed8153..90c9db526 100644 --- a/src/main/java/edu/rpi/legup/history/CommandError.java +++ b/src/main/java/edu/rpi/legup/history/CommandError.java @@ -18,6 +18,7 @@ public enum CommandError { DEFAULT_APPLICATION("[Apply Default Rule Application]"); private String value; + CommandError(String value) { this.value = value; } diff --git a/src/main/java/edu/rpi/legup/history/CommandState.java b/src/main/java/edu/rpi/legup/history/CommandState.java index 24ce231b0..b7c2ff938 100644 --- a/src/main/java/edu/rpi/legup/history/CommandState.java +++ b/src/main/java/edu/rpi/legup/history/CommandState.java @@ -4,6 +4,7 @@ public enum CommandState { CREATED("Created"), EXECUTED("Executed"), UNDOED("Undoed"), REDOED("Redoed"); private String value; + CommandState(String value) { this.value = value; } diff --git a/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java b/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java index 4d78564de..80cad9b24 100644 --- a/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java +++ b/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java @@ -35,7 +35,8 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; newSelectedView = nodeView.getParentView(); - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; newSelectedView = transitionView.getParentViews().get(0); } @@ -88,7 +89,8 @@ public void undoCommand() { node.getParent().setChildNode(node); puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(node)); - } else { + } + else { TreeTransition transition = (TreeTransition) element; transition.getParents().forEach(node -> node.addChild(transition)); transition.getParents().get(0).getChildren().forEach(TreeTransition::reverify); diff --git a/src/main/java/edu/rpi/legup/history/EditDataCommand.java b/src/main/java/edu/rpi/legup/history/EditDataCommand.java index f4c582220..328cc050d 100644 --- a/src/main/java/edu/rpi/legup/history/EditDataCommand.java +++ b/src/main/java/edu/rpi/legup/history/EditDataCommand.java @@ -69,7 +69,8 @@ public void executeCommand() { puzzleElement = board.getPuzzleElement(selectedPuzzleElement); savePuzzleElement = puzzleElement.copy(); - } else { + } + else { transition = (TreeTransition) treeElement; puzzleElement = board.getPuzzleElement(selectedPuzzleElement); savePuzzleElement = puzzleElement.copy(); @@ -81,7 +82,8 @@ public void executeCommand() { if (prevBoard.getPuzzleElement(selectedPuzzleElement).equalsData(puzzleElement)) { board.removeModifiedData(puzzleElement); - } else { + } + else { board.addModifiedData(puzzleElement); } transition.propagateChange(puzzleElement); @@ -110,20 +112,23 @@ public String getErrorString() { Board board = selectedView.getTreeElement().getBoard(); PuzzleElement selectedPuzzleElement = elementView.getPuzzleElement(); if (selectedView.getType() == TreeElementType.NODE) { - + TreeNodeView nodeView = (TreeNodeView) selectedView; if (!nodeView.getChildrenViews().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); - } else { + } + else { if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); } } - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) selectedView; if (!transitionView.getTreeElement().getBoard().isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); - } else { + } + else { if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); } @@ -157,7 +162,8 @@ public void undoCommand() { if (prevBoard.getPuzzleElement(selectedPuzzleElement).equalsData(puzzleElement)) { board.removeModifiedData(puzzleElement); - } else { + } + else { board.addModifiedData(puzzleElement); } transition.propagateChange(puzzleElement); diff --git a/src/main/java/edu/rpi/legup/history/History.java b/src/main/java/edu/rpi/legup/history/History.java index 0bf9edbf6..77e3fae94 100644 --- a/src/main/java/edu/rpi/legup/history/History.java +++ b/src/main/java/edu/rpi/legup/history/History.java @@ -53,7 +53,7 @@ public void pushChange(ICommand command) { public void undo() { synchronized (lock) { if (curIndex > -1) { - ICommand command = history.get(curIndex--); + ICommand command = history.get(curIndex--); command.undo(); LOGGER.info("Undoed " + command.getClass().getSimpleName()); GameBoardFacade.getInstance().notifyHistoryListeners(l -> l.onUndo(curIndex < 0, curIndex == history.size() - 1)); @@ -67,7 +67,7 @@ public void undo() { public void redo() { synchronized (lock) { if (curIndex < history.size() - 1) { - ICommand command = history.get(++curIndex); + ICommand command = history.get(++curIndex); command.redo(); LOGGER.info("Redoed " + command.getClass().getSimpleName()); GameBoardFacade.getInstance().notifyHistoryListeners(l -> l.onRedo(curIndex < 0, curIndex == history.size() - 1)); diff --git a/src/main/java/edu/rpi/legup/history/MergeCommand.java b/src/main/java/edu/rpi/legup/history/MergeCommand.java index e6ddf6dfb..2091ecf0a 100644 --- a/src/main/java/edu/rpi/legup/history/MergeCommand.java +++ b/src/main/java/edu/rpi/legup/history/MergeCommand.java @@ -55,7 +55,8 @@ public void executeCommand() { transition.setRule(new MergeRule()); transition.setChildNode(mergedNode); mergedNode.setParent(transition); - } else { + } + else { mergedNode = transition.getChildNode(); } @@ -111,7 +112,8 @@ public String getErrorString() { return CommandError.NO_CHILDREN.toString(); } nodeList.add(nodeView.getTreeElement()); - } else { + } + else { return CommandError.SELECTION_CONTAINS_TRANSITION.toString(); } } @@ -127,12 +129,12 @@ public String getErrorString() { return "Unable to merge tree elements."; } Set leafNodes = tree.getLeafTreeElements(lca); - if(leafNodes.size() != mergingNodes.size()) { + if (leafNodes.size() != mergingNodes.size()) { // return "Unable to merge tree elements."; } - for(TreeNode node : mergingNodes) { - if(!leafNodes.contains(node)) { + for (TreeNode node : mergingNodes) { + if (!leafNodes.contains(node)) { // return "Unable to merge tree elements."; } } diff --git a/src/main/java/edu/rpi/legup/history/PuzzleCommand.java b/src/main/java/edu/rpi/legup/history/PuzzleCommand.java index 360cab6f3..0c96b16f5 100644 --- a/src/main/java/edu/rpi/legup/history/PuzzleCommand.java +++ b/src/main/java/edu/rpi/legup/history/PuzzleCommand.java @@ -48,7 +48,8 @@ public final boolean canExecute() { public final String getError() { if (isCached) { return cachedError; - } else { + } + else { return getErrorString(); } } @@ -78,7 +79,8 @@ public void redoCommand() { if (state == CommandState.UNDOED) { executeCommand(); state = CommandState.REDOED; - } else { + } + else { throw new InvalidCommandStateTransition(this, state, CommandState.REDOED); } } @@ -91,7 +93,8 @@ public final void undo() { if (state == CommandState.EXECUTED || state == CommandState.REDOED) { undoCommand(); state = CommandState.UNDOED; - } else { + } + else { throw new InvalidCommandStateTransition(this, state, CommandState.UNDOED); } } @@ -103,7 +106,8 @@ public final void redo() { if (state == CommandState.UNDOED) { redoCommand(); state = CommandState.REDOED; - } else { + } + else { throw new InvalidCommandStateTransition(this, state, CommandState.REDOED); } } diff --git a/src/main/java/edu/rpi/legup/history/ValidateBasicRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateBasicRuleCommand.java index 55c3421db..29d8a6193 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateBasicRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateBasicRuleCommand.java @@ -22,7 +22,7 @@ public class ValidateBasicRuleCommand extends PuzzleCommand { * ValidateBasicRuleCommand Constructor creates a command for verifying a basic rule * * @param selection selection of tree elements - * @param rule basic rule + * @param rule basic rule */ public ValidateBasicRuleCommand(TreeViewSelection selection, BasicRule rule) { this.selection = selection.copy(); @@ -48,7 +48,8 @@ public void executeCommand() { if (element.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) selectedView; transitionView = nodeView.getChildrenViews().get(0); - } else { + } + else { transitionView = (TreeTransitionView) selectedView; } TreeTransition transition = transitionView.getTreeElement(); @@ -62,7 +63,8 @@ public void executeCommand() { if (childNode == null) { childNode = (TreeNode) tree.addTreeElement(transition); addNode.put(transition, childNode); - } else { + } + else { tree.addTreeElement(transition, childNode); } @@ -76,7 +78,8 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; finalTreeElement = transitionView.getChildView().getTreeElement(); } @@ -103,7 +106,8 @@ public String getErrorString() { if (nodeView.getChildrenViews().size() != 1) { return CommandError.ONE_CHILD.toString(); } - } else { + } + else { TreeTransitionView transView = (TreeTransitionView) view; if (transView.getParentViews().size() > 1) { return CommandError.CONTAINS_MERGE.toString(); @@ -127,7 +131,8 @@ public void undoCommand() { if (element.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) selectedView; transitionView = nodeView.getChildrenViews().get(0); - } else { + } + else { transitionView = (TreeTransitionView) selectedView; } TreeTransition transition = transitionView.getTreeElement(); diff --git a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java index 38672a555..923b17dda 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java @@ -57,7 +57,8 @@ public void executeCommand() { if (childNode == null) { childNode = (TreeNode) tree.addTreeElement(transition); addNode.put(transition, childNode); - } else { + } + else { childNode = (TreeNode) tree.addTreeElement(transition, childNode); } @@ -73,7 +74,8 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; finalTreeElement = transitionView.getChildView().getTreeElement(); } @@ -97,7 +99,8 @@ public String getErrorString() { for (TreeElementView view : selectedViews) { if (view.getType() == TreeElementType.NODE) { return CommandError.SELECTION_CONTAINS_NODE.toString(); - } else { + } + else { TreeTransitionView transView = (TreeTransitionView) view; if (transView.getParentViews().size() > 1) { return CommandError.CONTAINS_MERGE.toString(); diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java index 7033bbc3f..c5e2de258 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java @@ -48,7 +48,8 @@ public void executeCommand() { if (treeElement.getType() == TreeElementType.TRANSITION) { TreeTransition transition = (TreeTransition) treeElement; treeNode = transition.getParents().get(0); - } else { + } + else { treeNode = (TreeNode) treeElement; } @@ -66,7 +67,8 @@ public void executeCommand() { transition = tree.addNewTransition(treeNode); transition.setRule(newRule); tree.addTreeElement(transition); - } else { + } + else { tree.addTreeElement(treeNode, transition); } @@ -81,7 +83,8 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; finalTreeElement = transitionView.getChildView().getTreeElement(); } @@ -127,7 +130,8 @@ public void undoCommand() { if (element.getType() == TreeElementType.TRANSITION) { TreeTransition transition = (TreeTransition) element; node = transition.getParents().get(0); - } else { + } + else { node = (TreeNode) element; } node.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(n))); diff --git a/src/main/java/edu/rpi/legup/log4j2.properties b/src/main/java/edu/rpi/legup/log4j2.properties index 4a2ab408f..4f2556c2d 100644 --- a/src/main/java/edu/rpi/legup/log4j2.properties +++ b/src/main/java/edu/rpi/legup/log4j2.properties @@ -1,13 +1,11 @@ # Logging level # Root logger option log4j.rootLogger=DEBUG, stdout, file - # Redirect log messages to console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n - # Redirect log messages to a log file, support file rolling. log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=Legup.log diff --git a/src/main/java/edu/rpi/legup/model/Puzzle.java b/src/main/java/edu/rpi/legup/model/Puzzle.java index a94f84b37..cce4bb7e9 100644 --- a/src/main/java/edu/rpi/legup/model/Puzzle.java +++ b/src/main/java/edu/rpi/legup/model/Puzzle.java @@ -111,7 +111,8 @@ private void registerRules() { default: break; } - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) { System.out.println(" Failed "); e.getTargetException().printStackTrace(); } @@ -123,7 +124,8 @@ private void registerRules() { // InstantiationException | IllegalAccessException | InvocationTargetException e) { // LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e); // } - }catch(Exception e){ + } + catch (Exception e) { LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e); } } @@ -144,9 +146,9 @@ private void registerRules() { /** * Checks if the given height and width are valid board dimensions for the given puzzle * - * @param rows the number of rows on the board - * @param columns the number of columns on the board - * @return true if the given dimensions are valid for the given puzzle, false otherwise + * @param rows the number of rows on the board + * @param columns the number of columns on the board + * @return true if the given dimensions are valid for the given puzzle, false otherwise */ public abstract boolean isValidDimensions(int rows, int columns); @@ -159,14 +161,16 @@ public boolean isPuzzleComplete() { boolean isComplete = tree.isValid(); if (isComplete) { for (TreeElement leaf : tree.getLeafTreeElements()) { - if(leaf.getType() == TreeElementType.NODE) { - TreeNode node = (TreeNode)leaf; + if (leaf.getType() == TreeElementType.NODE) { + TreeNode node = (TreeNode) leaf; if (!node.isRoot()) { isComplete &= node.getParent().isContradictoryBranch() || isBoardComplete(node.getBoard()); - } else { + } + else { isComplete &= isBoardComplete(node.getBoard()); } - } else { + } + else { isComplete = false; } } @@ -200,7 +204,8 @@ public boolean isPuzzleComplete() { public void importPuzzle(String fileName) throws InvalidFileFormatException { try { importPuzzle(new FileInputStream(fileName)); - } catch (IOException e) { + } + catch (IOException e) { LOGGER.error("Importing puzzle error", e); throw new InvalidFileFormatException("Could not find file"); } @@ -220,7 +225,8 @@ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatExcept DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); - } catch (IOException | SAXException | ParserConfigurationException e) { + } + catch (IOException | SAXException | ParserConfigurationException e) { LOGGER.error("Importing puzzle error", e); throw new InvalidFileFormatException("Could not find file"); } @@ -232,7 +238,8 @@ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatExcept throw new InvalidFileFormatException("Puzzle importer null"); } importer.initializePuzzle(node); - } else { + } + else { LOGGER.error("Invalid file"); throw new InvalidFileFormatException("Invalid file: must be a Legup file"); } @@ -273,9 +280,11 @@ public String getName() { public List getBasicRules() { return basicRules; } + public List getPlaceableElements() { return placeableElements; } + public List getNonPlaceableElements() { return nonPlaceableElements; } @@ -298,12 +307,15 @@ public void setBasicRules(List basicRules) { public void addBasicRule(BasicRule rule) { basicRules.add(rule); } + public void addPlaceableElement(PlaceableElement element) { placeableElements.add(element); } + public void addNonPlaceableElement(NonPlaceableElement element) { nonPlaceableElements.add(element); } + /** * Remove a basic rule from this Puzzle * diff --git a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java index 1d596b7d6..f09c1dc91 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java @@ -65,9 +65,11 @@ public void exportPuzzle(String fileName) throws ExportFileException { StreamResult result = new StreamResult(new File(fileName)); transformer.transform(source, result); - } catch (ParserConfigurationException | TransformerException e) { + } + catch (ParserConfigurationException | TransformerException e) { throw new ExportFileException("Puzzle Exporter: parser configuration exception"); - } catch (Exception e) { + } + catch (Exception e) { throw e; //throw new ExportFileException(e.getMessage()); } diff --git a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java index da15a62d4..b72beac68 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java @@ -32,15 +32,17 @@ public PuzzleImporter(Puzzle puzzle) { /** * Initializes an empty puzzle * - * @param rows number of rows on the puzzle - * @param columns number of columns on the puzzle + * @param rows number of rows on the puzzle + * @param columns number of columns on the puzzle * @throws RuntimeException */ public void initializePuzzle(int rows, int columns) throws RuntimeException { - if (this.puzzle.isValidDimensions(rows, columns)) + if (this.puzzle.isValidDimensions(rows, columns)) { initializeBoard(rows, columns); - else + } + else { throw new IllegalArgumentException("Invalid dimensions provided"); + } } /** @@ -64,18 +66,22 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { } initializeBoard(n); initBoard = true; - } else if (n.getNodeName().equalsIgnoreCase("proof")) { - if (initProof) { - throw new InvalidFileFormatException("Puzzle creation error: duplicate proof puzzleElement found"); - } - if (!initBoard) { - throw new InvalidFileFormatException("Puzzle creation error: could not find board puzzleElement"); + } + else { + if (n.getNodeName().equalsIgnoreCase("proof")) { + if (initProof) { + throw new InvalidFileFormatException("Puzzle creation error: duplicate proof puzzleElement found"); + } + if (!initBoard) { + throw new InvalidFileFormatException("Puzzle creation error: could not find board puzzleElement"); + } + initializeProof(n); + initProof = true; } - initializeProof(n); - initProof = true; - } else { - if (!n.getNodeName().equalsIgnoreCase("#text")) { - throw new InvalidFileFormatException("Puzzle creation error: unknown node found in file"); + else { + if (!n.getNodeName().equalsIgnoreCase("#text")) { + throw new InvalidFileFormatException("Puzzle creation error: unknown node found in file"); + } } } } @@ -86,7 +92,8 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { if (!initProof) { createDefaultTree(); } - } else { + } + else { throw new InvalidFileFormatException("Invalid file format; does not contain \"puzzle\" node"); } } @@ -94,8 +101,8 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { /** * Creates the board for building * - * @param rows number of rows on the puzzle - * @param columns number of columns on the puzzle + * @param rows number of rows on the puzzle + * @param columns number of columns on the puzzle * @throws RuntimeException */ public abstract void initializeBoard(int rows, int columns); @@ -128,14 +135,16 @@ public void initializeProof(Node node) throws InvalidFileFormatException { } createTree(n); initTree = true; - } else { + } + else { throw new InvalidFileFormatException("Proof Tree construction error: unknown puzzleElement found"); } } if (!initTree) { createDefaultTree(); } - } else { + } + else { throw new InvalidFileFormatException("Invalid file format; does not contain \"proof\" node"); } } @@ -209,7 +218,8 @@ protected void createTree(Node node) throws InvalidFileFormatException { transition.addParent(treeNode); treeNode.addChild(transition); continue; - } else { + } + else { throw new InvalidFileFormatException("Proof Tree construction error: duplicate transition ID found"); } @@ -290,7 +300,8 @@ protected void validateTreeStructure(HashMap nodes, HashMap nodes, HashMap mergingNodes = transition.getParents(); List mergingBoards = new ArrayList<>(); mergingNodes.forEach(n -> mergingBoards.add(n.getBoard())); TreeNode lca = Tree.getLowestCommonAncestor(mergingNodes); - if(lca == null) { + if (lca == null) { throw new InvalidFileFormatException("Proof Tree construction error: unable to find merge node"); } Board lcaBoard = lca.getBoard(); @@ -333,10 +344,11 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen transition.setBoard(mergedBoard); TreeNode childNode = transition.getChildNode(); - if(childNode != null) { + if (childNode != null) { childNode.setBoard(mergedBoard.copy()); } - } else { + } + else { NodeList cellList = transElement.getChildNodes(); for (int i = 0; i < cellList.getLength(); i++) { Node node = cellList.item(i); @@ -347,7 +359,8 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen board.setPuzzleElement(cell.getIndex(), cell); board.addModifiedData(cell); transition.propagateChange(cell); - } else { + } + else { if (!node.getNodeName().equalsIgnoreCase("#text")) { throw new InvalidFileFormatException("Proof Tree construction error: unknown node in transition"); } diff --git a/src/main/java/edu/rpi/legup/model/elements/Element.java b/src/main/java/edu/rpi/legup/model/elements/Element.java index 0fdabe383..b78c1fcfc 100644 --- a/src/main/java/edu/rpi/legup/model/elements/Element.java +++ b/src/main/java/edu/rpi/legup/model/elements/Element.java @@ -32,12 +32,12 @@ private void loadImage() { this.image = new ImageIcon(ClassLoader.getSystemResource(imageName)); //Resize images to be 100px wide Image image = this.image.getImage(); - if(this.image.getIconWidth() < 120) return; + if (this.image.getIconWidth() < 120) return; int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); - if(height==0){ + if (height == 0) { System.out.println("height is 0 error"); - System.out.println("height: "+this.image.getIconHeight()); - System.out.println("width: "+this.image.getIconWidth()); + System.out.println("height: " + this.image.getIconHeight()); + System.out.println("width: " + this.image.getIconWidth()); return; } BufferedImage bimage = new BufferedImage(100, height, BufferedImage.TYPE_INT_RGB); @@ -46,6 +46,7 @@ private void loadImage() { this.image = new ImageIcon(bimage); } } + public String getElementName() { return elementName; } @@ -70,8 +71,7 @@ public ElementType getElementType() { return elementType; } - public String getInvalidUseOfRuleMessage() - { + public String getInvalidUseOfRuleMessage() { return this.INVALID_USE_MESSAGE; } } diff --git a/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java b/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java index b22bdbf5e..2d018ddbb 100644 --- a/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java +++ b/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java @@ -1,6 +1,6 @@ package edu.rpi.legup.model.elements; -public abstract class PlaceableElement extends Element{ +public abstract class PlaceableElement extends Element { public PlaceableElement(String elementID, String elementName, String description, String imageName) { super(elementID, elementName, description, imageName); this.elementType = ElementType.PLACEABLE; diff --git a/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java index 5051af826..799825025 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java @@ -6,61 +6,50 @@ import java.util.HashSet; import java.util.Set; -public class CaseBoard extends Board -{ +public class CaseBoard extends Board { protected Board baseBoard; protected CaseRule caseRule; protected Set pickablePuzzleElements; - public CaseBoard(Board baseBoard, CaseRule caseRule) - { + public CaseBoard(Board baseBoard, CaseRule caseRule) { this.baseBoard = baseBoard; this.caseRule = caseRule; this.pickablePuzzleElements = new HashSet<>(); } - public void addPickableElement(PuzzleElement puzzleElement) - { + public void addPickableElement(PuzzleElement puzzleElement) { pickablePuzzleElements.add(puzzleElement); } - public void removePickableElement(PuzzleElement puzzleElement) - { + public void removePickableElement(PuzzleElement puzzleElement) { pickablePuzzleElements.remove(puzzleElement); } - public boolean isPickable(PuzzleElement puzzleElement, MouseEvent e) - { + public boolean isPickable(PuzzleElement puzzleElement, MouseEvent e) { return pickablePuzzleElements.contains(baseBoard.getPuzzleElement(puzzleElement)); } - public Board getBaseBoard() - { + public Board getBaseBoard() { return baseBoard; } - public void setBaseBoard(Board baseBoard) - { + public void setBaseBoard(Board baseBoard) { this.baseBoard = baseBoard; } - public CaseRule getCaseRule() - { + public CaseRule getCaseRule() { return caseRule; } - public void setCaseRule(CaseRule caseRule) - { + public void setCaseRule(CaseRule caseRule) { this.caseRule = caseRule; } - public int getCount() - { + public int getCount() { return pickablePuzzleElements.size(); } - public CaseBoard copy() - { + public CaseBoard copy() { return null; } } diff --git a/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java b/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java index 7cfd461b8..99e9bf65a 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java @@ -20,8 +20,8 @@ public abstract class ElementFactory { /** * Creates a xml document {@link PuzzleElement} from a cell for exporting. * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public abstract Element exportCell(Document document, PuzzleElement puzzleElement); diff --git a/src/main/java/edu/rpi/legup/model/rules/BasicRule.java b/src/main/java/edu/rpi/legup/model/rules/BasicRule.java index ae30acdf9..e71007d6b 100644 --- a/src/main/java/edu/rpi/legup/model/rules/BasicRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/BasicRule.java @@ -32,11 +32,15 @@ public String checkRule(TreeTransition transition) { if (!finalBoard.isModified()) { return "State must be modified"; - } else if (transition.getParents().size() != 1 || - transition.getParents().get(0).getChildren().size() != 1) { - return "State must have only 1 parent and 1 child"; - } else { - return checkRuleRaw(transition); + } + else { + if (transition.getParents().size() != 1 || + transition.getParents().get(0).getChildren().size() != 1) { + return "State must have only 1 parent and 1 child"; + } + else { + return checkRuleRaw(transition); + } } } @@ -74,11 +78,15 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement String checkStr; if (!puzzleElement.isModified()) { checkStr = "PuzzleElement must be modified"; - } else if (transition.getParents().size() != 1 || - transition.getParents().get(0).getChildren().size() != 1) { - checkStr = "State must have only 1 parent and 1 child"; - } else { - checkStr = checkRuleRawAt(transition, puzzleElement); + } + else { + if (transition.getParents().size() != 1 || + transition.getParents().get(0).getChildren().size() != 1) { + checkStr = "State must have only 1 parent and 1 child"; + } + else { + checkStr = checkRuleRawAt(transition, puzzleElement); + } } puzzleElement.setValid(checkStr == null); return checkStr; diff --git a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java index cf07975db..d9c7e73e5 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -69,8 +69,11 @@ public String checkRule(TreeTransition transition) { for (TreeTransition childTrans : parentNodes.get(0).getChildren()) { if (childTrans.getRule() == null || !childTrans.getRule().getClass().equals(this.getClass())) { return "All children nodes must be justified with the same case rule."; - } else if (childTrans.getBoard().getModifiedData().isEmpty()) { - return "You must modify the board in each case node"; + } + else { + if (childTrans.getBoard().getModifiedData().isEmpty()) { + return "You must modify the board in each case node"; + } } } diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java index c29ad030b..0d3a79a98 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -91,15 +91,14 @@ public String checkContradiction(Board board) { return this.NO_CONTRADICTION_MESSAGE; } - public String getNoContradictionMessage() - { + public String getNoContradictionMessage() { return this.NO_CONTRADICTION_MESSAGE; } /** * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, * otherwise error message diff --git a/src/main/java/edu/rpi/legup/model/rules/MergeRule.java b/src/main/java/edu/rpi/legup/model/rules/MergeRule.java index 16454643a..9ae18648e 100644 --- a/src/main/java/edu/rpi/legup/model/rules/MergeRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/MergeRule.java @@ -19,7 +19,7 @@ public class MergeRule extends Rule { * MergeRule Constructor merges to board states together */ public MergeRule() { - super("MERGE","Merge Rule", + super("MERGE", "Merge Rule", "Merge any number of nodes into one", "edu/rpi/legup/images/Legup/MergeRule.png"); this.ruleType = MERGE; diff --git a/src/main/java/edu/rpi/legup/model/rules/Rule.java b/src/main/java/edu/rpi/legup/model/rules/Rule.java index 172b20bd3..51075bf5c 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -87,12 +87,12 @@ private void loadImage() { this.image = new ImageIcon(ClassLoader.getSystemResource(imageName)); //Resize images to be 100px wide Image image = this.image.getImage(); - if(this.image.getIconWidth() < 120) return; + if (this.image.getIconWidth() < 120) return; int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); - if(height==0){ + if (height == 0) { System.out.println("height is 0 error"); - System.out.println("height: "+this.image.getIconHeight()); - System.out.println("width: "+this.image.getIconWidth()); + System.out.println("height: " + this.image.getIconHeight()); + System.out.println("width: " + this.image.getIconWidth()); return; } BufferedImage bimage = new BufferedImage(100, height, BufferedImage.TYPE_INT_RGB); @@ -156,8 +156,7 @@ public RuleType getRuleType() { return ruleType; } - public String getInvalidUseOfRuleMessage() - { + public String getInvalidUseOfRuleMessage() { return this.INVALID_USE_MESSAGE; } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/model/tree/Tree.java b/src/main/java/edu/rpi/legup/model/tree/Tree.java index f27701947..cc222b809 100644 --- a/src/main/java/edu/rpi/legup/model/tree/Tree.java +++ b/src/main/java/edu/rpi/legup/model/tree/Tree.java @@ -45,7 +45,8 @@ public TreeElement addTreeElement(TreeElement element) { if (element.getType() == TreeElementType.NODE) { TreeNode treeNode = (TreeNode) element; return addTreeElement(treeNode, new TreeTransition(treeNode, treeNode.getBoard().copy())); - } else { + } + else { TreeTransition transition = (TreeTransition) element; Board copyBoard = transition.board.copy(); copyBoard.setModifiable(false); @@ -69,7 +70,8 @@ public void removeTreeElement(TreeElement element) { if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; node.getParent().setChildNode(null); - } else { + } + else { TreeTransition transition = (TreeTransition) element; transition.getParents().forEach(n -> n.removeChild(transition)); transition.getParents().get(0).getChildren().forEach(TreeTransition::reverify); @@ -111,24 +113,27 @@ public Set getLeafTreeElements(TreeNode node) { /** * Recursively gets a Set of TreeNodes that are leaf nodes * - * @param leafs Set of TreeNodes that are leaf nodes - * @param element current TreeNode being evaluated + * @param leafs Set of TreeNodes that are leaf nodes + * @param element current TreeNode being evaluated */ private void getLeafTreeElements(Set leafs, TreeElement element) { - if(element.getType() == TreeElementType.NODE) { - TreeNode node = (TreeNode)element; + if (element.getType() == TreeElementType.NODE) { + TreeNode node = (TreeNode) element; List childTrans = node.getChildren(); - if(childTrans.isEmpty()) { + if (childTrans.isEmpty()) { leafs.add(node); - } else { + } + else { childTrans.forEach(t -> getLeafTreeElements(leafs, t)); } - } else { - TreeTransition transition = (TreeTransition)element; + } + else { + TreeTransition transition = (TreeTransition) element; TreeNode childNode = transition.getChildNode(); - if(childNode == null) { + if (childNode == null) { leafs.add(transition); - } else { + } + else { getLeafTreeElements(leafs, childNode); } } @@ -146,24 +151,28 @@ private void getLeafTreeElements(Set leafs, TreeElement element) { public static TreeNode getLowestCommonAncestor(List nodes) { if (nodes.isEmpty()) { return null; - } else if (nodes.size() == 1) { - return nodes.get(0); - } else { - List> ancestors = new ArrayList<>(); - for (TreeNode node : nodes) { - ancestors.add(node.getAncestors()); + } + else { + if (nodes.size() == 1) { + return nodes.get(0); } + else { + List> ancestors = new ArrayList<>(); + for (TreeNode node : nodes) { + ancestors.add(node.getAncestors()); + } - List first = ancestors.get(0); + List first = ancestors.get(0); - for (TreeNode node : first) { - boolean isCommon = true; - for (List nList : ancestors) { - isCommon &= nList.contains(node); - } + for (TreeNode node : first) { + boolean isCommon = true; + for (List nList : ancestors) { + isCommon &= nList.contains(node); + } - if (isCommon) { - return node; + if (isCommon) { + return node; + } } } } diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java index 80c9c7766..dc4e2a587 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java @@ -104,7 +104,8 @@ public List getDescendants() { it.add(transition); } } - } else { + } + else { TreeTransition trans = (TreeTransition) next; TreeNode childNode = trans.getChildNode(); if (childNode != null && !descendants.contains(childNode)) { @@ -142,7 +143,8 @@ public DisjointSets findMergingBranches() { if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; nodes.addAll(node.getChildren()); - } else { + } + else { TreeTransition childTran = (TreeTransition) element; if (childTran.getChildNode() != null) { nodes.add(childTran.getChildNode()); @@ -184,14 +186,14 @@ public static TreeTransition findMergingPoint(Set branche mergeSet.createSet(element); if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; - node.getDescendants().forEach((TreeElement e) -> - { + node.getDescendants().forEach((TreeElement e) -> { if (!mergeSet.contains(e)) { mergeSet.createSet(e); } mergeSet.union(element, e); }); - } else { + } + else { TreeTransition transition = (TreeTransition) element; TreeNode childNode = transition.getChildNode(); if (childNode != null) { @@ -226,7 +228,8 @@ public static TreeTransition findMergingPoint(Set branche if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; next.addAll(node.getChildren()); - } else { + } + else { TreeTransition tran = (TreeTransition) element; next.add(tran.getChildNode()); } diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java index 1112e4ba0..e1d042626 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java @@ -48,7 +48,7 @@ public TreeTransition(TreeNode parent, Board board) { */ @SuppressWarnings("unchecked") public void propagateChange(PuzzleElement element) { - if(isJustified() && rule.getRuleType() == RuleType.MERGE) { + if (isJustified() && rule.getRuleType() == RuleType.MERGE) { TreeNode lca = Tree.getLowestCommonAncestor(parents); Board lcaBoard = lca.getBoard(); List boards = new ArrayList<>(); @@ -62,16 +62,19 @@ public void propagateChange(PuzzleElement element) { if (isSame) { boolean changed = false; PuzzleElement mergedData = board.getPuzzleElement(element); - if(lcaElement.equalsData(element) && !mergedData.equalsData(element)) { + if (lcaElement.equalsData(element) && !mergedData.equalsData(element)) { mergedData.setData(element.getData()); board.removeModifiedData(element); board.notifyChange(element); changed = true; - } else if (!lcaElement.equalsData(element)){ - mergedData.setData(element.getData()); - board.addModifiedData(mergedData); - board.notifyChange(element); - changed = true; + } + else { + if (!lcaElement.equalsData(element)) { + mergedData.setData(element.getData()); + board.addModifiedData(mergedData); + board.notifyChange(element); + changed = true; + } } if (changed && childNode != null) { childNode.getBoard().notifyChange(element.copy()); @@ -82,13 +85,16 @@ public void propagateChange(PuzzleElement element) { } } } - } else if (childNode != null) { - board.notifyChange(element); - childNode.getBoard().notifyChange(element.copy()); - for (TreeTransition child : childNode.getChildren()) { - PuzzleElement copy = element.copy(); - copy.setModifiable(false); - child.propagateChange(copy); + } + else { + if (childNode != null) { + board.notifyChange(element); + childNode.getBoard().notifyChange(element.copy()); + for (TreeTransition child : childNode.getChildren()) { + PuzzleElement copy = element.copy(); + copy.setModifiable(false); + child.propagateChange(copy); + } } } reverify(); @@ -101,7 +107,7 @@ public void propagateChange(PuzzleElement element) { */ @SuppressWarnings("unchecked") public void propagateAddition(PuzzleElement element) { - if(isJustified() && rule.getRuleType() == RuleType.MERGE) { + if (isJustified() && rule.getRuleType() == RuleType.MERGE) { TreeNode lca = Tree.getLowestCommonAncestor(parents); Board lcaBoard = lca.getBoard(); List boards = new ArrayList<>(); @@ -115,16 +121,19 @@ public void propagateAddition(PuzzleElement element) { if (isSame) { boolean changed = false; PuzzleElement mergedData = board.getPuzzleElement(element); - if(lcaElement.equalsData(element) && !mergedData.equalsData(element)) { + if (lcaElement.equalsData(element) && !mergedData.equalsData(element)) { mergedData.setData(element.getData()); board.removeModifiedData(element); board.notifyDeletion(element); changed = true; - } else if (!lcaElement.equalsData(element)){ - mergedData.setData(element.getData()); - board.addModifiedData(mergedData); - board.notifyAddition(element); - changed = true; + } + else { + if (!lcaElement.equalsData(element)) { + mergedData.setData(element.getData()); + board.addModifiedData(mergedData); + board.notifyAddition(element); + changed = true; + } } if (changed && childNode != null) { childNode.getBoard().notifyAddition(element.copy()); @@ -133,11 +142,14 @@ public void propagateAddition(PuzzleElement element) { } } } - } else if (childNode != null) { - board.notifyAddition(element); - childNode.getBoard().notifyAddition(element.copy()); - for (TreeTransition child : childNode.getChildren()) { - child.propagateAddition(element.copy()); + } + else { + if (childNode != null) { + board.notifyAddition(element); + childNode.getBoard().notifyAddition(element.copy()); + for (TreeTransition child : childNode.getChildren()) { + child.propagateAddition(element.copy()); + } } } reverify(); @@ -150,7 +162,7 @@ public void propagateAddition(PuzzleElement element) { */ @SuppressWarnings("unchecked") public void propagateDeletion(PuzzleElement element) { - if(isJustified() && rule.getRuleType() == RuleType.MERGE) { + if (isJustified() && rule.getRuleType() == RuleType.MERGE) { TreeNode lca = Tree.getLowestCommonAncestor(parents); Board lcaBoard = lca.getBoard(); List boards = new ArrayList<>(); @@ -164,16 +176,19 @@ public void propagateDeletion(PuzzleElement element) { if (isSame) { boolean changed = false; PuzzleElement mergedData = board.getPuzzleElement(element); - if(lcaElement.equalsData(element) && !mergedData.equalsData(element)) { + if (lcaElement.equalsData(element) && !mergedData.equalsData(element)) { mergedData.setData(element.getData()); board.removeModifiedData(element); board.notifyDeletion(element); changed = true; - } else if (!lcaElement.equalsData(element)){ - mergedData.setData(element.getData()); - board.addModifiedData(mergedData); - board.notifyAddition(element); - changed = true; + } + else { + if (!lcaElement.equalsData(element)) { + mergedData.setData(element.getData()); + board.addModifiedData(mergedData); + board.notifyAddition(element); + changed = true; + } } if (changed && childNode != null) { childNode.getBoard().notifyDeletion(element.copy()); @@ -182,11 +197,14 @@ public void propagateDeletion(PuzzleElement element) { } } } - } else if (childNode != null) { - board.notifyDeletion(element); - childNode.getBoard().notifyDeletion(element.copy()); - for (TreeTransition child : childNode.getChildren()) { - child.propagateDeletion(element.copy()); + } + else { + if (childNode != null) { + board.notifyDeletion(element); + childNode.getBoard().notifyDeletion(element.copy()); + for (TreeTransition child : childNode.getChildren()) { + child.propagateDeletion(element.copy()); + } } } reverify(); @@ -202,10 +220,14 @@ public void propagateDeletion(PuzzleElement element) { public boolean isContradictoryBranch() { if (isJustified() && isCorrect() && rule.getRuleType() == RuleType.CONTRADICTION) { return true; - } else if (childNode == null) { - return false; - } else { - return childNode.isContradictoryBranch() && isJustified() && isCorrect(); + } + else { + if (childNode == null) { + return false; + } + else { + return childNode.isContradictoryBranch() && isJustified() && isCorrect(); + } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java b/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java index abcfbc3a9..22a980251 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java @@ -37,7 +37,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Battleship, false otherwise + * @return true if the given dimensions are valid for Battleship, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java index c72aa9ac6..e086d4bbc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java @@ -44,8 +44,8 @@ public BattleshipBoard(int size) { /** * Gets the east {@link BattleshipClue} * - * @return List of BattleShipClue objects on the east - * side of the board + * @return List of BattleShipClue objects on the east + * side of the board */ public List getEast() { return east; @@ -73,7 +73,7 @@ public BattleshipBoard copy() { copy.setCell(x, y, getCell(x, y).copy()); } } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } copy.east = this.east; @@ -83,10 +83,10 @@ public BattleshipBoard copy() { /** * Get a list of all orthogonally adjacent cells. - * - * @param cell The cell to get adjacent cells from. - * @return List of adjacent cells in clockwise order: - * { up, right, down, left } + * + * @param cell The cell to get adjacent cells from. + * @return List of adjacent cells in clockwise order: + * { up, right, down, left } */ public List getAdjOrthogonals(BattleshipCell cell) { List adj = new ArrayList<>(); @@ -105,9 +105,9 @@ public List getAdjOrthogonals(BattleshipCell cell) { /** * Get a list of all diagonally adjacent cells. * - * @param cell The cell to get diagonally adjacent cells from. - * @return List of diagonally adjacent cells in clockwise order: - * { upRight, downRight, downLeft, upLeft } + * @param cell The cell to get diagonally adjacent cells from. + * @return List of diagonally adjacent cells in clockwise order: + * { upRight, downRight, downLeft, upLeft } */ public List getAdjDiagonals(BattleshipCell cell) { List dia = new ArrayList<>(); @@ -127,7 +127,7 @@ public List getAdjDiagonals(BattleshipCell cell) { * Get a list of cells in a row. * * @param y The y-coordinate of the row. - * @return List of cells in the row in increasing x-coordinate order. + * @return List of cells in the row in increasing x-coordinate order. */ public List getRow(int y) { List row = new ArrayList<>(); @@ -141,7 +141,7 @@ public List getRow(int y) { * Get a list of cells in a column. * * @param x The x-coordinate of the column. - * @return List of cells in the column in increasing y-coordinate order. + * @return List of cells in the column in increasing y-coordinate order. */ public List getColumn(int x) { List column = new ArrayList<>(); diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java index c37fc4184..0a7f7ec4e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java @@ -12,18 +12,24 @@ public void changeCell(MouseEvent e, PuzzleElement data) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } else { + } + else { if (cell.getData() == BattleshipType.SHIP_MIDDLE) { cell.setData(BattleshipType.UNKNOWN); - } else { + } + else { cell.setData(BattleshipType.getType(cell.getData().value + 1)); } } - } else if (e.getButton() == MouseEvent.BUTTON3) { - if (cell.getData() == BattleshipType.UNKNOWN) { - cell.setData(BattleshipType.SHIP_MIDDLE); - } else { - cell.setData(BattleshipType.getType(cell.getData().value - 1)); + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + if (cell.getData() == BattleshipType.UNKNOWN) { + cell.setData(BattleshipType.SHIP_MIDDLE); + } + else { + cell.setData(BattleshipType.getType(cell.getData().value - 1)); + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java index 7caaad50b..bc244856b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java @@ -41,12 +41,15 @@ public PuzzleElement importCell(Node node, Board board) throws I BattleshipCell cell = new BattleshipCell(BattleshipType.getType(value), new Point(x, y)); cell.setIndex(y * height + x); return cell; - } else { + } + else { throw new InvalidFileFormatException("BattleShip Factory: unknown puzzleElement puzzleElement"); } - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("BattleShip Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("BattleShip Factory: could not find attribute(s)"); } } @@ -54,8 +57,8 @@ public PuzzleElement importCell(Node node, Board board) throws I /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java index dcc9d6443..e63f915e1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java @@ -16,8 +16,8 @@ public BattleshipImporter(Battleship battleShip) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -52,13 +52,16 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int size = Integer.valueOf(boardElement.getAttribute( "size")); battleShipBoard = new BattleshipBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() - && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute( - "width")); - int height = Integer.valueOf(boardElement.getAttribute( - "height")); - battleShipBoard = new BattleshipBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute( + "width")); + int height = Integer.valueOf(boardElement.getAttribute( + "height")); + battleShipBoard = new BattleshipBoard(width, height); + } } if (battleShipBoard == null) { @@ -168,7 +171,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } puzzle.setCurrentBoard(battleShipBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("BattleShip Importer: " + "unknown value where integer expected"); } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java index 46e0304b1..71dd4ce02 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java @@ -27,8 +27,8 @@ public static BattleshipType getType(int value) { /** * Checks if the type is a ship. * - * @param type the {@link BattleshipType} to check - * @return true if the type is a ship, false otherwise + * @param type the {@link BattleshipType} to check + * @return true if the type is a ship, false otherwise */ public static boolean isShip(BattleshipType type) { return type == SHIP_UNKNOWN || type == SHIP_TOP || type == SHIP_RIGHT diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java index 46360c43f..49bee101a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java @@ -28,9 +28,9 @@ public AdjacentShipsContradictionRule() { * * @param board board to check contradiction * @param puzzleElement equivalent {@link PuzzleElement} - * @return null if the transition contains a - * contradiction at the specified {@link PuzzleElement}, - * otherwise return a no contradiction message. + * @return null if the transition contains a + * contradiction at the specified {@link PuzzleElement}, + * otherwise return a no contradiction message. */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -38,8 +38,9 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { BattleshipCell cell = (BattleshipCell) bsBoard.getPuzzleElement(puzzleElement); // rule only applies to battleship cells - if (!BattleshipType.isShip(cell.getType())) + if (!BattleshipType.isShip(cell.getType())) { return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; + } // check orthogonally adjacent cells List orthoAdjCells @@ -57,8 +58,9 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { || (right != null && BattleshipType.isShip(right.getData())); // ships cannot be both vertical and horizontal - if (isVertical && isHorizontal) + if (isVertical && isHorizontal) { return null; + } // check diagonally adjacent cells List diagAdjCells @@ -70,14 +72,18 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { BattleshipCell upLeft = diagAdjCells.get(3); // diagonally adjacent cells must be water - if (upRight != null && BattleshipType.isShip(upRight.getData())) + if (upRight != null && BattleshipType.isShip(upRight.getData())) { return null; - if (downRight != null && BattleshipType.isShip(downRight.getData())) + } + if (downRight != null && BattleshipType.isShip(downRight.getData())) { return null; - if (downLeft != null && BattleshipType.isShip(downLeft.getData())) + } + if (downLeft != null && BattleshipType.isShip(downLeft.getData())) { return null; - if (upLeft != null && BattleshipType.isShip(upLeft.getData())) + } + if (upLeft != null && BattleshipType.isShip(upLeft.getData())) { return null; + } return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java index cf6df4064..ca10ab266 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java @@ -39,7 +39,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Fillapix, false otherwise + * @return true if the given dimensions are valid for Fillapix, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java index bb66eea2d..24615db5c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java @@ -34,7 +34,7 @@ public FillapixBoard copy() { copy.setCell(x, y, getCell(x, y).copy()); } } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } return copy; diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java index 29595970c..62d14630d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java @@ -12,13 +12,20 @@ public void changeCell(MouseEvent e, PuzzleElement puzzleElement) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } else { + } + else { if (cell.getType() == FillapixCellType.UNKNOWN) { cell.setType(FillapixCellType.BLACK); - } else if (cell.getType() == FillapixCellType.BLACK) { - cell.setType(FillapixCellType.WHITE); - } else if (cell.getType() == FillapixCellType.WHITE) { - cell.setType(FillapixCellType.UNKNOWN); + } + else { + if (cell.getType() == FillapixCellType.BLACK) { + cell.setType(FillapixCellType.WHITE); + } + else { + if (cell.getType() == FillapixCellType.WHITE) { + cell.setType(FillapixCellType.UNKNOWN); + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java index 51c7bc728..65061bf2e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java @@ -44,9 +44,11 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE FillapixCell cell = new FillapixCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Fillapix Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("Fillapix Factory: could not find attribute(s)"); } } @@ -54,8 +56,8 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java index 0be80324a..819e56fe7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java @@ -16,8 +16,8 @@ public FillapixImporter(Fillapix fillapix) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -48,10 +48,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); fillapixBoard = new FillapixBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - fillapixBoard = new FillapixBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + fillapixBoard = new FillapixBoard(width, height); + } } if (fillapixBoard == null) { @@ -80,7 +83,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(fillapixBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Fillapix Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java index d2f96e3d2..58efa2ab1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java @@ -30,7 +30,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForcedBlack(parentBoard, cell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black"; } } @@ -61,7 +62,8 @@ public Board getDefaultBoard(TreeNode node) { } if (fillapixBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return fillapixBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java index 307ee974e..0874f0177 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java @@ -30,7 +30,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForcedWhite(parentBoard, cell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be white"; } } @@ -61,7 +62,8 @@ public Board getDefaultBoard(TreeNode node) { } if (fillapixBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return fillapixBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java index 951dd5c3e..fc52a6fff 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java @@ -41,7 +41,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for HeyAwake, false otherwise + * @return true if the given dimensions are valid for HeyAwake, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java index c8b07a823..2f15213ec 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java @@ -48,7 +48,7 @@ public HeyawakeBoard copy() { } copy.regions.put(region.get(0).getRegionIndex(), newCpy); } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } return copy; diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java index 4f821b25c..2b1d329f0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java @@ -46,9 +46,11 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE cell.setIndex(y * height + x); heyawakeBoard.getRegions(); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Heyawake Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("Heyawake Factory: could not find attribute(s)"); } } @@ -56,8 +58,8 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java index 018246175..2ec326ee0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java @@ -17,8 +17,8 @@ public HeyawakeImporter(Heyawake heyawake) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -49,10 +49,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); heyawakeBoard = new HeyawakeBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - heyawakeBoard = new HeyawakeBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + heyawakeBoard = new HeyawakeBoard(width, height); + } } if (heyawakeBoard == null) { @@ -83,7 +86,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(heyawakeBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Heyawake Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java index c60ca2d88..00506df0f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java @@ -31,7 +31,8 @@ public HeyawakeView(HeyawakeBoard board) { int regionIndex = cell.getRegionIndex(); if (regionsBoundaries.get(regionIndex) == null) { regionsBoundaries.put(regionIndex, new Area(elementView.getBounds())); - } else { + } + else { regionsBoundaries.get(regionIndex).add(new Area(elementView.getBounds())); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java index 7ed87dc25..0e7552dd2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java @@ -11,7 +11,7 @@ public class BlackOrWhiteCaseRule extends CaseRule { public BlackOrWhiteCaseRule() { - super("HEYA-CASE-0001", + super("HEYA-CASE-0001", "Black or White", "", "edu/rpi/legup/images/heyawake/cases/BlackOrWhite.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathBasicRule.java index 9c656498c..8b214a648 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathBasicRule.java @@ -1,8 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; public class BlackPathBasicRule { - public BlackPathBasicRule() - { + public BlackPathBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckBasicRule.java index 65d4919f0..4267c4076 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class BottleNeckBasicRule -{ - public BottleNeckBasicRule() - { +public class BottleNeckBasicRule { + public BottleNeckBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackBasicRule.java index 35ffcdb14..b738a20b0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackBasicRule.java @@ -9,7 +9,7 @@ public class FillRoomBlackBasicRule extends BasicRule { public FillRoomBlackBasicRule() { - super("HEYA-BASC-0003", + super("HEYA-BASC-0003", "Fill Room Black", "", "edu/rpi/legup/images/heyawake/rules/FillRoomBlack.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteBasicRule.java index c4b8def02..cbfb3ad06 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteBasicRule.java @@ -9,7 +9,7 @@ public class FillRoomWhiteBasicRule extends BasicRule { public FillRoomWhiteBasicRule() { - super("HEYA-BASC-0004", + super("HEYA-BASC-0004", "Fill Room White", "", "edu/rpi/legup/images/heyawake/rules/FillRoomWhite.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowBasicRule.java index 201cd8816..2acb0624f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class OneRowBasicRule -{ - public OneRowBasicRule() - { +public class OneRowBasicRule { + public OneRowBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineBasicRule.java index 5620ac457..58e1f31b7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class PreventWhiteLineBasicRule -{ - public PreventWhiteLineBasicRule() - { +public class PreventWhiteLineBasicRule { + public PreventWhiteLineBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java index 10b34282d..0e0beaeb2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java @@ -7,7 +7,7 @@ public class RoomTooEmptyContradictionRule extends ContradictionRule { public RoomTooEmptyContradictionRule() { - super("HEYA-CONT-0002", + super("HEYA-CONT-0002", "Room too Empty", "", "edu/rpi/legup/images/heyawake/contradictions/RoomTooEmpty.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java index a21d82063..1de746cb2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java @@ -7,7 +7,7 @@ public class RoomTooFullContradictionRule extends ContradictionRule { public RoomTooFullContradictionRule() { - super("HEYA-CONT-0003", + super("HEYA-CONT-0003", "Room too Full", "", "edu/rpi/legup/images/heyawake/contradictions/RoomTooFull.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeBasicRule.java index 54328de8b..9560b411a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class ThreeByThreeBasicRule -{ - public ThreeByThreeBasicRule() - { +public class ThreeByThreeBasicRule { + public ThreeByThreeBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerBasicRule.java index 096273bc1..2746d3cce 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class TwoInCornerBasicRule -{ - public TwoInCornerBasicRule() - { +public class TwoInCornerBasicRule { + public TwoInCornerBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java index 2608725aa..a287d9c78 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java @@ -7,7 +7,7 @@ public class WhiteAreaContradictionRule extends ContradictionRule { public WhiteAreaContradictionRule() { - super("HEYA-CONT-0004", + super("HEYA-CONT-0004", "White Area", "", "edu/rpi/legup/images/heyawake/contradictions/WhiteArea.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackBasicRule.java index e8fbdd0a9..2b99baab5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackBasicRule.java @@ -9,7 +9,7 @@ public class WhiteAroundBlackBasicRule extends BasicRule { public WhiteAroundBlackBasicRule() { - super("HEYA-BASC-0009", + super("HEYA-BASC-0009", "White Around Black", "", "edu/rpi/legup/images/heyawake/rules/WhiteAroundBlack.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeBasicRule.java index 0a4a5fe1f..1232f79e3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class WhiteEscapeBasicRule -{ - public WhiteEscapeBasicRule() - { +public class WhiteEscapeBasicRule { + public WhiteEscapeBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java index 9cc36bd6d..835bce98c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java @@ -7,7 +7,7 @@ public class WhiteLineContradictionRule extends ContradictionRule { public WhiteLineContradictionRule() { - super("HEYA-CONT-0005", + super("HEYA-CONT-0005", "White Line", "", "edu/rpi/legup/images/heyawake/contradictions/WhiteLine.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagCaseRule.java index 8e553e623..d44491a6e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagCaseRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class ZigZagCaseRule -{ - public ZigZagCaseRule() - { +public class ZigZagCaseRule { + public ZigZagCaseRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteBasicRule.java index 7628116f4..235a9029d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteBasicRule.java @@ -1,9 +1,7 @@ package edu.rpi.legup.puzzle.heyawake.rules; -public class ZigZagWhiteBasicRule -{ - public ZigZagWhiteBasicRule() - { +public class ZigZagWhiteBasicRule { + public ZigZagWhiteBasicRule() { throw new RuntimeException("This rule has not been implemented"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java index 0053335e2..22eee239f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java @@ -44,7 +44,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Light Up, false otherwise + * @return true if the given dimensions are valid for Light Up, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented @@ -64,7 +64,7 @@ public boolean isBoardComplete(Board board) { for (ContradictionRule rule : contradictionRules) { if (rule.checkContradiction(lightUpBoard) == null) { - System.out.println(rule.getRuleName()); + System.out.println(rule.getRuleName()); return false; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java index 0568d872f..3ac982e40 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java @@ -137,7 +137,7 @@ public LightUpBoard copy() { copy.setCell(x, y, getCell(x, y).copy()); } } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } copy.fillWithLight(); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java index 226676e6c..9c94b24f7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java @@ -12,22 +12,34 @@ public void changeCell(MouseEvent e, PuzzleElement data) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } else { + } + else { if (cell.getData() == -2) { data.setData(-4); - } else if (cell.getData() == -4) { - data.setData(-3); - } else { - data.setData(-2); + } + else { + if (cell.getData() == -4) { + data.setData(-3); + } + else { + data.setData(-2); + } } } - } else if (e.getButton() == MouseEvent.BUTTON3) { - if (cell.getData() == -4) { - data.setData(-2); - } else if (cell.getData() == -2) { - data.setData(-3); - } else { - data.setData(-4); + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + if (cell.getData() == -4) { + data.setData(-2); + } + else { + if (cell.getData() == -2) { + data.setData(-3); + } + else { + data.setData(-4); + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java index 05aa66023..5cb8353df 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java @@ -44,9 +44,11 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx LightUpCell cell = new LightUpCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("lightup Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("lightup Factory: could not find attribute(s)"); } } @@ -54,8 +56,8 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java index a57f22706..7f35d46a6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java @@ -42,29 +42,41 @@ public void drawElement(Graphics2D graphics2D) { int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText); - } else if (type == LightUpCellType.BLACK) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(BLACK_COLOR); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - } else if (type == LightUpCellType.EMPTY) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(cell.isLite() ? LITE : WHITE_COLOR); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.setColor(BLACK_COLOR); - graphics2D.fillRect(location.x + size.width * 7 / 16, location.y + size.height * 7 / 16, size.width / 8, size.height / 8); - graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == LightUpCellType.UNKNOWN) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(cell.isLite() ? LITE : Color.LIGHT_GRAY); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == LightUpCellType.BULB) { - graphics2D.setColor(Color.LIGHT_GRAY); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.drawImage(LightUpView.lightImage, location.x, location.y, size.width, size.height, LITE, null); - graphics2D.setColor(BLACK_COLOR); - graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == LightUpCellType.BLACK) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(BLACK_COLOR); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + } + else { + if (type == LightUpCellType.EMPTY) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(cell.isLite() ? LITE : WHITE_COLOR); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.setColor(BLACK_COLOR); + graphics2D.fillRect(location.x + size.width * 7 / 16, location.y + size.height * 7 / 16, size.width / 8, size.height / 8); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == LightUpCellType.UNKNOWN) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(cell.isLite() ? LITE : Color.LIGHT_GRAY); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == LightUpCellType.BULB) { + graphics2D.setColor(Color.LIGHT_GRAY); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.drawImage(LightUpView.lightImage, location.x, location.y, size.width, size.height, LITE, null); + graphics2D.setColor(BLACK_COLOR); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + } + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java index aa8c8458c..7a8bca84f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java @@ -16,8 +16,8 @@ public LightUpImporter(LightUp lightUp) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -48,10 +48,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); lightUpBoard = new LightUpBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - lightUpBoard = new LightUpBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + lightUpBoard = new LightUpBoard(width, height); + } } if (lightUpBoard == null) { @@ -82,7 +85,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(lightUpBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("lightup Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java index f4c762124..9896653fc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java @@ -7,6 +7,8 @@ import edu.rpi.legup.ui.boardview.DataSelectionView; import edu.rpi.legup.ui.boardview.GridBoardView; import edu.rpi.legup.ui.boardview.SelectionItemView; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.imageio.ImageIO; import javax.swing.*; @@ -14,13 +16,15 @@ import java.io.IOException; public class LightUpView extends GridBoardView { + private final static Logger LOGGER = LogManager.getLogger(LightUpView.class.getName()); static Image lightImage; static { try { lightImage = ImageIO.read(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/lightup/light.png")); - } catch (IOException e) { - + } + catch (IOException e) { + LOGGER.error("Failed to open TreeTent images"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java index 1a7c219fc..2804e6eab 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java @@ -12,7 +12,7 @@ public class BulbsInPathContradictionRule extends ContradictionRule { public BulbsInPathContradictionRule() { - super("LTUP-CONT-0001","Bulbs In Path", + super("LTUP-CONT-0001", "Bulbs In Path", "A bulb cannot be placed in another bulb's path.", "edu/rpi/legup/images/lightup/contradictions/BulbsInPath.png"); } @@ -38,32 +38,44 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.BULB) { - return null; + } + else { + if (c.getType() == LightUpCellType.BULB) { + return null; + } } } for (int i = location.x - 1; i >= 0; i--) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.BULB) { - return null; + } + else { + if (c.getType() == LightUpCellType.BULB) { + return null; + } } } for (int i = location.y + 1; i < lightUpBoard.getHeight(); i++) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.BULB) { - return null; + } + else { + if (c.getType() == LightUpCellType.BULB) { + return null; + } } } for (int i = location.y - 1; i >= 0; i--) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.BULB) { - return null; + } + else { + if (c.getType() == LightUpCellType.BULB) { + return null; + } } } return super.getNoContradictionMessage(); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java index e5f0f31fd..011bf1c0a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java @@ -42,36 +42,48 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { - hor_count += 1; + } + else { + if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { + hor_count += 1; + } } } for (int i = location.x - 1; i >= 0; i--) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { - hor_count += 1; + } + else { + if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { + hor_count += 1; + } } } for (int i = location.y + 1; i < lightUpBoard.getHeight(); i++) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { - ver_count += 1; + } + else { + if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { + ver_count += 1; + } } } for (int i = location.y - 1; i >= 0; i--) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { - ver_count += 1; + } + else { + if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { + ver_count += 1; + } } } System.out.printf("%d, %d, %d, %d\n", location.x, location.y, hor_count, ver_count); - if(hor_count == 0 && ver_count == 0) { + if (hor_count == 0 && ver_count == 0) { return null; } return super.getNoContradictionMessage(); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java index 7db548962..68d69165a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java @@ -56,7 +56,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java index 59c725092..6c11d5140 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java @@ -75,7 +75,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } if (createsContra) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty"; } } @@ -99,13 +100,15 @@ public Board getDefaultBoard(TreeNode node) { LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell); modCell.setData(LightUpCellType.EMPTY.value); lightUpBoard.addModifiedData(modCell); - } else { + } + else { cell.setData(temp); } } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java index 04b06fd86..9a5911b04 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java @@ -92,7 +92,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java index 2d9a0e2e0..e6e642106 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java @@ -96,7 +96,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java index 482ed594b..2830a497a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java @@ -46,7 +46,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell can be lit by another cell"; } } @@ -62,36 +63,48 @@ private boolean isForcedBulb(LightUpBoard board, Point loc) { LightUpCell c = board.getCell(i, loc.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { - return true; + } + else { + if (c.getType() == LightUpCellType.EMPTY && + !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { + return true; + } } } for (int i = loc.x - 1; i >= 0; i--) { LightUpCell c = board.getCell(i, loc.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { - return true; + } + else { + if (c.getType() == LightUpCellType.EMPTY && + !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { + return true; + } } } for (int i = loc.y + 1; i < board.getHeight(); i++) { LightUpCell c = board.getCell(loc.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { - return true; + } + else { + if (c.getType() == LightUpCellType.EMPTY && + !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { + return true; + } } } for (int i = loc.y - 1; i >= 0; i--) { LightUpCell c = board.getCell(loc.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } else if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { - return true; + } + else { + if (c.getType() == LightUpCellType.EMPTY && + !c.isLite() && cannotLite.checkContradictionAt(board, c) == null) { + return true; + } } } return false; @@ -122,7 +135,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java index 75d7b4201..0bef37c82 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java @@ -58,32 +58,44 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } else if (checkCell.getType() == LightUpCellType.BULB) { - numNeeded--; + } + else { + if (checkCell.getType() == LightUpCellType.BULB) { + numNeeded--; + } } } checkCell = lightUpBoard.getCell(loc.x, loc.y + 1); if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } else if (checkCell.getType() == LightUpCellType.BULB) { - numNeeded--; + } + else { + if (checkCell.getType() == LightUpCellType.BULB) { + numNeeded--; + } } } checkCell = lightUpBoard.getCell(loc.x - 1, loc.y); if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } else if (checkCell.getType() == LightUpCellType.BULB) { - numNeeded--; + } + else { + if (checkCell.getType() == LightUpCellType.BULB) { + numNeeded--; + } } } checkCell = lightUpBoard.getCell(loc.x, loc.y - 1); if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } else if (checkCell.getType() == LightUpCellType.BULB) { - numNeeded--; + } + else { + if (checkCell.getType() == LightUpCellType.BULB) { + numNeeded--; + } } } @@ -236,7 +248,8 @@ private List getPossibleSpots(TreeTransition transition) { int size = modCells.size(); if (size == 0 || size > 4) { return null; - } else { + } + else { Iterator it = modCells.iterator(); List spots = getAdjacentCells(board, (LightUpCell) it.next()); diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java b/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java index 8ff001d71..827be37ff 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java @@ -71,7 +71,8 @@ public void executeCommand() { board = (MasyuBoard) transition.getBoard(); getInstance().getPuzzleModule().setCurrentBoard(board); oldData = newData.copy(); - } else { + } + else { transitionView = (TreeTransitionView) selectedView; transition = transitionView.getTreeElement(); } @@ -100,7 +101,8 @@ public void executeCommand() { board.getModifiedData().remove(dup_line); board.getLines().remove(dup_line); // puzzle.notifyBoardListeners((IBoardListener listener) -> listener.onTreeElementChanged(editBoard)); - } else { + } + else { System.out.println("adding"); board.getModifiedData().add(newData); board.getLines().add((MasyuLine) newData); @@ -121,8 +123,11 @@ public String getErrorString() { Board board = selectedView.getTreeElement().getBoard(); if (!board.isModifiable()) { return "Board is not modifiable"; - } else if (!board.getPuzzleElement(elementView.getPuzzleElement()).isModifiable()) { - return "Data is not modifiable"; + } + else { + if (!board.getPuzzleElement(elementView.getPuzzleElement()).isModifiable()) { + return "Data is not modifiable"; + } } return null; } @@ -160,7 +165,8 @@ public void undoCommand() { if (prevBoard.getPuzzleElement(elementView.getPuzzleElement()).equalsData(newData)) { board.removeModifiedData(newData); - } else { + } + else { board.addModifiedData(newData); } transition.propagateChange(newData); diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java b/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java index 2134f1f90..b339630e9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java @@ -42,7 +42,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Masyu, false otherwise + * @return true if the given dimensions are valid for Masyu, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java index 1d65bb67a..96183bcfe 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java @@ -36,7 +36,8 @@ public void setLines(List lines) { public void notifyChange(PuzzleElement puzzleElement) { if (puzzleElement instanceof MasyuLine) { lines.add((MasyuLine) puzzleElement); - } else { + } + else { super.notifyChange(puzzleElement); } } @@ -52,7 +53,7 @@ public MasyuBoard copy() { for (MasyuLine line : lines) { copy.lines.add(line.copy()); } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } return copy; diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java index 687950d12..eb26ce514 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java @@ -44,9 +44,11 @@ public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatExce MasyuCell cell = new MasyuCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Masyu Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("Masyu Factory: could not find attribute(s)"); } } @@ -54,8 +56,8 @@ public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatExce /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java index 554b8d898..72c5e634a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java @@ -55,16 +55,19 @@ public void mouseDragged(MouseEvent e) { MasyuLine newLine = new MasyuLine(mousePressedCell.getPuzzleElement(), mouseDraggedCell.getPuzzleElement()); puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine)); } - } else if (mouseDraggedCell != elementView) { - Point p1 = mouseDraggedCell.getPuzzleElement().getLocation(); - Point p2 = elementView.getPuzzleElement().getLocation(); + } + else { + if (mouseDraggedCell != elementView) { + Point p1 = mouseDraggedCell.getPuzzleElement().getLocation(); + Point p2 = elementView.getPuzzleElement().getLocation(); - if (Math.abs(p1.x - p2.x) == 1 ^ Math.abs(p1.y - p2.y) == 1) { - masyuLine.add(elementView); - MasyuLine newLine = new MasyuLine(mouseDraggedCell.getPuzzleElement(), elementView.getPuzzleElement()); - puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine)); + if (Math.abs(p1.x - p2.x) == 1 ^ Math.abs(p1.y - p2.y) == 1) { + masyuLine.add(elementView); + MasyuLine newLine = new MasyuLine(mouseDraggedCell.getPuzzleElement(), elementView.getPuzzleElement()); + puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine)); + } + mouseDraggedCell = elementView; } - mouseDraggedCell = elementView; } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java index 6a13d7155..b2f1f8902 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java @@ -24,25 +24,31 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.fillRect(location.x, location.y, size.width, size.height); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == MasyuType.BLACK) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(Color.LIGHT_GRAY); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.setColor(Color.BLACK); - graphics2D.fillOval(location.x + 5, location.y + 5, 20, 20); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == MasyuType.WHITE) { - graphics2D.setStroke(new BasicStroke(2)); - graphics2D.setColor(Color.LIGHT_GRAY); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.setColor(Color.WHITE); - graphics2D.fillOval(location.x + 5, location.y + 5, 20, 20); - graphics2D.setColor(Color.BLACK); - graphics2D.drawOval(location.x + 6, location.y + 6, 18, 18); - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == MasyuType.BLACK) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(Color.LIGHT_GRAY); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.setColor(Color.BLACK); + graphics2D.fillOval(location.x + 5, location.y + 5, 20, 20); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == MasyuType.WHITE) { + graphics2D.setStroke(new BasicStroke(2)); + graphics2D.setColor(Color.LIGHT_GRAY); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.setColor(Color.WHITE); + graphics2D.fillOval(location.x + 5, location.y + 5, 20, 20); + graphics2D.setColor(Color.BLACK); + graphics2D.drawOval(location.x + 6, location.y + 6, 18, 18); + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java index 0f96d59df..b17338d21 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java @@ -16,8 +16,8 @@ public MasyuImporter(Masyu masyu) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -48,10 +48,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); masyuBoard = new MasyuBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - masyuBoard = new MasyuBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + masyuBoard = new MasyuBoard(width, height); + } } if (masyuBoard == null) { @@ -82,7 +85,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(masyuBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Masyu Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackBasicRule.java index 85e136210..fece691cb 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackBasicRule.java @@ -9,7 +9,7 @@ public class BlockedBlackBasicRule extends BasicRule { public BlockedBlackBasicRule() { - super("MASY-BASC-0002","Blocked Black", + super("MASY-BASC-0002", "Blocked Black", "", "edu/rpi/legup/images/masyu/RuleBlockedBlack.gif"); } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java index 84522d8ac..19da790aa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java @@ -7,7 +7,7 @@ public class NoOptionsContradictionRule extends ContradictionRule { public NoOptionsContradictionRule() { - super("MASY-CONT-0003","No Options", + super("MASY-CONT-0003", "No Options", "", "edu/rpi/legup/images/masyu/ContradictionNoOptions.png"); } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java index 765a13f25..e45fde0a1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java @@ -11,7 +11,7 @@ public class WhiteSplitCaseRule extends CaseRule { public WhiteSplitCaseRule() { - super("MASY-CASE-0003","White Split", + super("MASY-CASE-0003", "White Split", "", "edu/rpi/legup/images/masyu/CaseWhiteSplit.png"); } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java index fbd0d3d88..fc29e9f55 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java @@ -43,7 +43,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Nurikabe, false otherwise + * @return true if the given dimensions are valid for Nurikabe, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java index 09a9bd686..cf0b21757 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java @@ -41,7 +41,7 @@ public NurikabeBoard copy() { copy.setCell(x, y, getCell(x, y).copy()); } } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } return copy; diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java index 7667c2c45..14d8efe41 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java @@ -6,7 +6,7 @@ public class NurikabeCell extends GridCell { -/** + /** * NurikabeCell Constructor - creates a NurikabeCell from the specified value and location * * @param value value of the NurikabeCell diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java index bd0f1c715..47113325b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java @@ -44,9 +44,11 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE NurikabeCell cell = new NurikabeCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("nurikabe Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("nurikabe Factory: could not find attribute(s)"); } } @@ -54,8 +56,8 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java index 1460bc6d3..c115498a8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java @@ -13,22 +13,34 @@ public void changeCell(MouseEvent e, PuzzleElement data) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } else { + } + else { if (cell.getData() == -2) { data.setData(0); - } else if (cell.getData() == 0) { - data.setData(-1); - } else { - data.setData(-2); + } + else { + if (cell.getData() == 0) { + data.setData(-1); + } + else { + data.setData(-2); + } } } - } else if (e.getButton() == MouseEvent.BUTTON3) { - if (cell.getData() == -2) { - data.setData(-1); - } else if (cell.getData() == 0) { - data.setData(-2); - } else { - data.setData(0); + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + if (cell.getData() == -2) { + data.setData(-1); + } + else { + if (cell.getData() == 0) { + data.setData(-2); + } + else { + data.setData(0); + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java index 09f976dc9..f122a7a5b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java @@ -42,22 +42,31 @@ public void drawElement(Graphics2D graphics2D) { int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText); - } else if (type == NurikabeType.BLACK) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(Color.BLACK); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - } else if (type == NurikabeType.WHITE) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(Color.WHITE); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == NurikabeType.UNKNOWN) { - graphics2D.setStroke(new BasicStroke(1)); - graphics2D.setColor(Color.LIGHT_GRAY); - graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == NurikabeType.BLACK) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(Color.BLACK); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + } + else { + if (type == NurikabeType.WHITE) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(Color.WHITE); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == NurikabeType.UNKNOWN) { + graphics2D.setStroke(new BasicStroke(1)); + graphics2D.setColor(Color.LIGHT_GRAY); + graphics2D.fillRect(location.x, location.y, size.width, size.height); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java index f9dfb98f5..4f408ea42 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java @@ -16,8 +16,8 @@ public NurikabeImporter(Nurikabe nurikabe) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -48,10 +48,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); nurikabeBoard = new NurikabeBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - nurikabeBoard = new NurikabeBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + nurikabeBoard = new NurikabeBoard(width, height); + } } if (nurikabeBoard == null) { @@ -82,7 +85,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(nurikabeBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("nurikabe Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java index 17e970af3..f8125ad43 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java @@ -59,19 +59,25 @@ public static DisjointSets getNurikabeRegions(NurikabeBoard board) downCell.getType() == NurikabeType.WHITE)) { regions.union(cell, downCell); } - } else if (cell.getType() == NurikabeType.BLACK) { - if (rightCell != null && rightCell.getType() == NurikabeType.BLACK) { - regions.union(cell, rightCell); - } - if (downCell != null && downCell.getType() == NurikabeType.BLACK) { - regions.union(cell, downCell); - } - } else if (cell.getType() == NurikabeType.UNKNOWN) { - if (rightCell != null && rightCell.getType() == NurikabeType.UNKNOWN) { - regions.union(cell, rightCell); - } - if (downCell != null && downCell.getType() == NurikabeType.UNKNOWN) { - regions.union(cell, downCell); + } + else { + if (cell.getType() == NurikabeType.BLACK) { + if (rightCell != null && rightCell.getType() == NurikabeType.BLACK) { + regions.union(cell, rightCell); + } + if (downCell != null && downCell.getType() == NurikabeType.BLACK) { + regions.union(cell, downCell); + } + } + else { + if (cell.getType() == NurikabeType.UNKNOWN) { + if (rightCell != null && rightCell.getType() == NurikabeType.UNKNOWN) { + regions.union(cell, rightCell); + } + if (downCell != null && downCell.getType() == NurikabeType.UNKNOWN) { + regions.union(cell, downCell); + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java index 91a30051a..9df8ac70b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java @@ -46,7 +46,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (contraRule.checkContradiction(modified) == null) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This is not the only way for black to escape!"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellBasicRule.java index 0cb016a92..7b4deb4ae 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellBasicRule.java @@ -40,17 +40,19 @@ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleE NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); NurikabeBoard modified = origBoardState.copy(); - for (int i = 0; i < modified.getWidth(); i++) - for (int j = 0; j < modified.getHeight(); j++) - { + for (int i = 0; i < modified.getWidth(); i++) { + for (int j = 0; j < modified.getHeight(); j++) { NurikabeCell currentCell = modified.getCell(i, j); - if (currentCell.getType() == NurikabeType.WHITE) + if (currentCell.getType() == NurikabeType.WHITE) { currentCell.setData(NurikabeType.UNKNOWN.toValue()); + } } + } NurikabeCell modifiedCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); modifiedCell.setData(NurikabeType.WHITE.toValue()); - if (contraRule.checkContradiction(modified) == null) + if (contraRule.checkContradiction(modified) == null) { return null; + } return super.getInvalidUseOfRuleMessage() + ": This is not the only way for black to escape!"; } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackBasicRule.java index c7ec93e22..d24c56293 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackBasicRule.java @@ -37,61 +37,62 @@ public CornerBlackBasicRule() { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { NurikabeBoard board = (NurikabeBoard) transition.getBoard(); NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); - if (cell.getType() != NurikabeType.BLACK) + if (cell.getType() != NurikabeType.BLACK) { return "Only black cells are allowed for this rule!"; + } ContradictionRule tooFewContra = new TooFewSpacesContradictionRule(); Point cellLocation = cell.getLocation(); // 1. Find the coordinates of the white space (should be a corner of cell) - for (int i = -1; i < 2; i += 2) - for (int j = -1; j < 2; j += 2) - { + for (int i = -1; i < 2; i += 2) { + for (int j = -1; j < 2; j += 2) { // If the corner does not exist, skip the corner - if (!(cellLocation.x + i >= 0 && cellLocation.x + i < board.getWidth() && cellLocation.y + j >= 0 && cellLocation.x + i < board.getHeight())) + if (!(cellLocation.x + i >= 0 && cellLocation.x + i < board.getWidth() && cellLocation.y + j >= 0 && cellLocation.x + i < board.getHeight())) { continue; + } NurikabeCell corner = board.getCell(cellLocation.x + i, cellLocation.y + j); NurikabeType cornerType = corner.getType(); - if (cornerType == NurikabeType.WHITE || cornerType == NurikabeType.NUMBER) - { + if (cornerType == NurikabeType.WHITE || cornerType == NurikabeType.NUMBER) { Point cornerLocation = corner.getLocation(); // 2. Check if the intersecting adjacent spaces of the white space and the black corner are empty - if (board.getCell(cornerLocation.x, cellLocation.y).getType() == NurikabeType.UNKNOWN && board.getCell(cellLocation.x, cornerLocation.y).getType() == NurikabeType.UNKNOWN) - { + if (board.getCell(cornerLocation.x, cellLocation.y).getType() == NurikabeType.UNKNOWN && board.getCell(cellLocation.x, cornerLocation.y).getType() == NurikabeType.UNKNOWN) { // System.out.println("Went inside if statement"); NurikabeBoard modified = board.copy(); modified.getCell(cornerLocation.x, cellLocation.y).setData(NurikabeType.BLACK.toValue()); modified.getCell(cellLocation.x, cornerLocation.y).setData(NurikabeType.BLACK.toValue()); boolean containsContradiction = tooFewContra.checkContradiction(modified) == null; - if (containsContradiction) - { + if (containsContradiction) { // 3. Check if the connected region is 1 under what is needed Set region = ConnectedRegions.getRegionAroundPoint(cornerLocation, NurikabeType.BLACK.toValue(), modified.getIntArray(), modified.getWidth(), modified.getHeight()); int regionNumber = 0; // System.out.println("Region set size: " + region.size()); - for (Point p : region) - { + for (Point p : region) { NurikabeCell pCell = modified.getCell(p.x, p.y); - if (pCell.getType() == NurikabeType.NUMBER) - { - if (regionNumber == 0) + if (pCell.getType() == NurikabeType.NUMBER) { + if (regionNumber == 0) { regionNumber = pCell.getData(); - else + } + else { return "There is a MultipleNumbers Contradiction on the board."; + } } } // If the region size is 0, there is a possibility that there was only 1 cell in the white // region, and that white cell was a NurikabeType.NUMBER cell - if (regionNumber == 0 && corner.getType() == NurikabeType.NUMBER && corner.getData() == 2) + if (regionNumber == 0 && corner.getType() == NurikabeType.NUMBER && corner.getData() == 2) { return null; + } // If the region size is not 0, make sure the regionNumber and the region size match (need // to add 1 to account for the cell that was surrounded - if (regionNumber != 0 && region.size() + 1 == regionNumber) + if (regionNumber != 0 && region.size() + 1 == regionNumber) { return null; + } } } } } + } return "This is not a valid use of the corner black rule!"; } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java index 5c2abf53a..c7331330b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java @@ -29,9 +29,9 @@ public IsolateBlackContradictionRule() { * * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement - * @return null if the transition contains a - * contradiction at the specified {@link PuzzleElement}, - * otherwise return a no contradiction message. + * @return null if the transition contains a + * contradiction at the specified {@link PuzzleElement}, + * otherwise return a no contradiction message. */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -48,7 +48,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { if (c.getType() == NurikabeType.BLACK) { if (oneRegion) { return null; - } else { + } + else { oneRegion = true; break; } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java index 2713d55cc..0149f0f50 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java @@ -49,13 +49,14 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } for (NurikabeCell c : whiteRegion) { // System.out.println(c.getLocation().x + "\t" + c.getLocation().y); - NurikabeCell top = nurikabeBoard.getCell(c.getLocation().x, c.getLocation().y+1); - NurikabeCell left = nurikabeBoard.getCell(c.getLocation().x-1, c.getLocation().y); - NurikabeCell right = nurikabeBoard.getCell(c.getLocation().x+1, c.getLocation().y); - NurikabeCell bottom = nurikabeBoard.getCell(c.getLocation().x, c.getLocation().y-1); + NurikabeCell top = nurikabeBoard.getCell(c.getLocation().x, c.getLocation().y + 1); + NurikabeCell left = nurikabeBoard.getCell(c.getLocation().x - 1, c.getLocation().y); + NurikabeCell right = nurikabeBoard.getCell(c.getLocation().x + 1, c.getLocation().y); + NurikabeCell bottom = nurikabeBoard.getCell(c.getLocation().x, c.getLocation().y - 1); - if (isEmptyCell(top) || isEmptyCell(left) || isEmptyCell(right) || isEmptyCell(bottom)) + if (isEmptyCell(top) || isEmptyCell(left) || isEmptyCell(right) || isEmptyCell(bottom)) { return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_SURROUNDED_BY_BLACK_MESSAGE; + } } return null; } @@ -63,13 +64,13 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { /** * Checks whether a give NurikabeCell is empty. * - * @param cell NurikabeCell to check if empty - * @return false if the NurikabeCell is not empty or null, true otherwise + * @param cell NurikabeCell to check if empty + * @return false if the NurikabeCell is not empty or null, true otherwise */ - private boolean isEmptyCell(NurikabeCell cell) - { - if (cell == null) + private boolean isEmptyCell(NurikabeCell cell) { + if (cell == null) { return false; + } NurikabeType cellType = cell.getType(); return cellType != NurikabeType.BLACK && cellType != NurikabeType.WHITE; } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareBasicRule.java index 25c16d362..0233e48ef 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareBasicRule.java @@ -47,7 +47,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (contraRule.checkContradiction(modified) == null) { return null; - } else { + } + else { return "Does not contain a contradiction at this index"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionBasicRule.java index e6abd0416..0a925911d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionBasicRule.java @@ -13,7 +13,7 @@ public class SurroundRegionBasicRule extends BasicRule { public SurroundRegionBasicRule() { - super("NURI-BASC-0007","Surround Region", + super("NURI-BASC-0007", "Surround Region", "Surround Region", "edu/rpi/legup/images/nurikabe/rules/SurroundBlack.png"); } @@ -46,7 +46,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (contraRule.checkContradiction(modified) == null) { return null; - } else { + } + else { return "Does not follow from this rule at this index"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java index e8a23b1e9..3ce185b6c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java @@ -45,7 +45,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Short Truth Table, false otherwise + * @return true if the given dimensions are valid for Short Truth Table, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java index 941f45c44..d084cd2ff 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java @@ -25,19 +25,20 @@ public ShortTruthTableBoard(int width, int height, ShortTruthTableStatement[] st } - public Set getCellsWithSymbol(char symbol){ + public Set getCellsWithSymbol(char symbol) { Set cells = new HashSet(); for (int x = 0; x < this.dimension.width; x++) { for (int y = 0; y < this.dimension.height; y++) { ShortTruthTableCell cell = (ShortTruthTableCell) getCell(x, y); - if(cell.getSymbol() == symbol) + if (cell.getSymbol() == symbol) { cells.add(cell); + } } } return cells; } - public ShortTruthTableCell getCellFromElement(PuzzleElement element){ + public ShortTruthTableCell getCellFromElement(PuzzleElement element) { return (ShortTruthTableCell) getPuzzleElement(element); } @@ -47,20 +48,22 @@ public ShortTruthTableBoard copy() { //Copy the statements ShortTruthTableStatement[] statementsCopy = new ShortTruthTableStatement[this.statements.length]; - for(int i = 0; i copyStatementList(List statements){ + public static List copyStatementList(List statements) { List copy = new ArrayList(); - for(int i = 0; i copyStatementList(List{ +public class ShortTruthTableCell extends GridCell { //The symbol on the cell - private final char symbol; + private final char symbol; - //This is a reference to the statement that contains this cell - private ShortTruthTableStatement statement; + //This is a reference to the statement that contains this cell + private ShortTruthTableStatement statement; - //Constructors + //Constructors - public ShortTruthTableCell(char symbol, ShortTruthTableCellType cellType, Point location){ - super(cellType, location); - this.symbol = symbol; - } + public ShortTruthTableCell(char symbol, ShortTruthTableCellType cellType, Point location) { + super(cellType, location); + this.symbol = symbol; + } /** @@ -27,8 +27,8 @@ public ShortTruthTableCell(char symbol, ShortTruthTableCellType cellType, Point * * @param location the location of this cell on the board */ - public ShortTruthTableCell(Point location){ - this(' ', ShortTruthTableCellType.NOT_IN_PLAY, location); + public ShortTruthTableCell(Point location) { + this(' ', ShortTruthTableCellType.NOT_IN_PLAY, location); } @@ -42,8 +42,8 @@ public ShortTruthTableCellType getType() { return data; } - public char getSymbol(){ - return symbol; + public char getSymbol() { + return symbol; } /** @@ -51,31 +51,34 @@ public char getSymbol(){ * * @return true if cell is a variable; false otherwise */ - public boolean isVariable(){ return Character.isLetter(symbol); } + public boolean isVariable() { + return Character.isLetter(symbol); + } - public int getX(){ + public int getX() { return (int) location.getX(); } - public int getY(){ + + public int getY() { return (int) location.getY(); } - public boolean isAssigned(){ - return getType()==ShortTruthTableCellType.TRUE || getType()==ShortTruthTableCellType.FALSE; + public boolean isAssigned() { + return getType() == ShortTruthTableCellType.TRUE || getType() == ShortTruthTableCellType.FALSE; } //Setters - void setStatementReference(ShortTruthTableStatement statement){ + void setStatementReference(ShortTruthTableStatement statement) { this.statement = statement; } - public void setType(ShortTruthTableCellType type){ + public void setType(ShortTruthTableCellType type) { data = type; } - public void setGiven(ShortTruthTableCellType type){ + public void setGiven(ShortTruthTableCellType type) { setType(type); setModifiable(false); setGiven(true); @@ -83,36 +86,36 @@ public void setGiven(ShortTruthTableCellType type){ //Modifiers - public void cycleTypeForward(){ - switch(data){ - case UNKNOWN: data = ShortTruthTableCellType.TRUE; break; - case TRUE: data = ShortTruthTableCellType.FALSE; break; - case FALSE: data = ShortTruthTableCellType.UNKNOWN; break; - default: break; + public void cycleTypeForward() { + switch (data) { + case UNKNOWN: + data = ShortTruthTableCellType.TRUE; + break; + case TRUE: + data = ShortTruthTableCellType.FALSE; + break; + case FALSE: + data = ShortTruthTableCellType.UNKNOWN; + break; + default: + break; } } - public void cycleTypeBackward(){ + public void cycleTypeBackward() { cycleTypeForward(); cycleTypeForward(); } - - //TO STRING @Override - public String toString(){ + public String toString() { return String.format("STTCell: %c %2d %-11s %s", symbol, index, data, location.toString()); } - - - - - //Copy function @Override @@ -125,5 +128,4 @@ public ShortTruthTableCell copy() { } - } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java index a706bc052..4c41b5858 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java @@ -36,14 +36,16 @@ public ShortTruthTableCell importCell(Node node, Board board) throws InvalidFile String cellType = attributeList.getNamedItem("type").getNodeValue(); //modify the appropriet cell - ShortTruthTableCell cell = (ShortTruthTableCell) sttBoard.getCell(charIndex, rowIndex*2); + ShortTruthTableCell cell = (ShortTruthTableCell) sttBoard.getCell(charIndex, rowIndex * 2); cell.setData(ShortTruthTableCellType.valueOf(cellType)); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("nurikabe Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("nurikabe Factory: could not find attribute(s)"); } @@ -52,8 +54,8 @@ public ShortTruthTableCell importCell(Node node, Board board) throws InvalidFile /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { @@ -61,7 +63,7 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle ShortTruthTableCell cell = (ShortTruthTableCell) puzzleElement; org.w3c.dom.Element cellElement = document.createElement("cell"); - cellElement.setAttribute("row_index", String.valueOf(cell.getY()/2)); + cellElement.setAttribute("row_index", String.valueOf(cell.getY() / 2)); cellElement.setAttribute("char_index", String.valueOf(cell.getX())); cellElement.setAttribute("type", String.valueOf(cell.getType())); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java index 96f8b673c..4e9b7b715 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java @@ -3,9 +3,9 @@ import java.util.Map; import java.util.HashMap; -public enum ShortTruthTableCellType{ +public enum ShortTruthTableCellType { - FALSE(0), TRUE(1), UNKNOWN(-1), NOT_IN_PLAY(-2), PARENTHESIS(-3); + FALSE(0), TRUE(1), UNKNOWN(-1), NOT_IN_PLAY(-2), PARENTHESIS(-3); public int value; private static Map map = new HashMap<>(); @@ -27,10 +27,10 @@ public static ShortTruthTableCellType valueOf(int cellType) { /** * Gets the char value of a cell, Used for debugging */ - public static char toChar(ShortTruthTableCellType type){ - if(type == TRUE) return 'T'; - if(type == FALSE) return 'F'; - if(type == UNKNOWN) return '?'; + public static char toChar(ShortTruthTableCellType type) { + if (type == TRUE) return 'T'; + if (type == FALSE) return 'F'; + if (type == UNKNOWN) return '?'; return ' '; } @@ -40,21 +40,24 @@ public static char toChar(ShortTruthTableCellType type){ * * @return */ - public boolean isTrueOrFalse(){ - return value==0 || value==1; + public boolean isTrueOrFalse() { + return value == 0 || value == 1; } - public ShortTruthTableCellType getNegation(){ - switch(value){ - case 1: return ShortTruthTableCellType.FALSE; - case 0: return ShortTruthTableCellType.TRUE; - default: throw new RuntimeException("Trying to negate a cell not assigned to true or false"); + public ShortTruthTableCellType getNegation() { + switch (value) { + case 1: + return ShortTruthTableCellType.FALSE; + case 0: + return ShortTruthTableCellType.TRUE; + default: + throw new RuntimeException("Trying to negate a cell not assigned to true or false"); } } - public static ShortTruthTableCellType getDefaultType(char c){ - if( c == '(' || c == ')' ) return PARENTHESIS; + public static ShortTruthTableCellType getDefaultType(char c) { + if (c == '(' || c == ')') return PARENTHESIS; return UNKNOWN; } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java index 77d320d99..a870f38cd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java @@ -18,11 +18,15 @@ public void changeCell(MouseEvent e, PuzzleElement data) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } else { + } + else { cell.cycleTypeForward(); } - } else if (e.getButton() == MouseEvent.BUTTON3) { - cell.cycleTypeBackward(); + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + cell.cycleTypeBackward(); + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java index 7b0cd1b06..b3a04a690 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java @@ -38,14 +38,20 @@ public void drawElement(Graphics2D graphics2D) { ShortTruthTableCellType type = cell.getData(); //do not draw the cell if it is not in play - if(type == ShortTruthTableCellType.NOT_IN_PLAY) return; + if (type == ShortTruthTableCellType.NOT_IN_PLAY) return; //fill in background color of the cell graphics2D.setStroke(new BasicStroke(1)); - switch (type){ - case TRUE: graphics2D.setColor(TRUE_COLOR); break; - case FALSE: graphics2D.setColor(FALSE_COLOR); break; - default: graphics2D.setColor(UNKNOWN_COLOR); break; + switch (type) { + case TRUE: + graphics2D.setColor(TRUE_COLOR); + break; + case FALSE: + graphics2D.setColor(FALSE_COLOR); + break; + default: + graphics2D.setColor(UNKNOWN_COLOR); + break; } graphics2D.fillRect(location.x, location.y, size.width, size.height); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java index 60460614c..bcb744789 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java @@ -19,7 +19,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { org.w3c.dom.Element dataElement = newDocument.createElement("data"); ShortTruthTableStatement[] statements = board.getStatements(); - for (int i = 0; i getCells(String statement, int y){ + private List getCells(String statement, int y) { List cells = new ArrayList(); //go through each char in the statment and make a cell for it - for(int i = 0; i getCells(String statement, int y){ * Parses the statementData into all the cells (with symbols) and statements for the * puzzle. All cells are set to UNKNWON, it their value is given, it will be set later * in the import process. - * + *

* Both allCells and statements act as returns, They should be passed as empty arrays * * @param statementData The data to be imported - * @param allCells returns all the cells as a jagged 2d array - * @param statements returns all the statements + * @param allCells returns all the cells as a jagged 2d array + * @param statements returns all the statements * @return the length, in chars, of the longest statement */ private int parseAllStatmentsAndCells(final NodeList statementData, - List> allCells, - List statements) throws InvalidFileFormatException{ + List> allCells, + List statements) throws InvalidFileFormatException { int maxStatementLength = 0; @@ -68,14 +68,14 @@ private int parseAllStatmentsAndCells(final NodeList statementData, String statementRep = attributeList.getNamedItem("representation").getNodeValue(); //parser time (on statementRep) //if (!validGrammar(statementRep)) throw some error - if(!validGrammar(statementRep)){ + if (!validGrammar(statementRep)) { JOptionPane.showMessageDialog(null, "ERROR: Invalid file syntax"); throw new InvalidFileFormatException("shorttruthtable importer: invalid sentence syntax"); } int rowIndex = Integer.valueOf(attributeList.getNamedItem("row_index").getNodeValue()); //get the cells for the statement - List rowOfCells = getCells(statementRep, rowIndex*2); + List rowOfCells = getCells(statementRep, rowIndex * 2); allCells.add(rowOfCells); statements.add(new ShortTruthTableStatement(statementRep, rowOfCells)); @@ -91,10 +91,10 @@ private int parseAllStatmentsAndCells(final NodeList statementData, private boolean validGrammar(String sentence) { int open = 0; int close = 0; - char[] valid_characters = new char[] {'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'}; - for(int i = 0; i < sentence.length(); i++) { + char[] valid_characters = new char[]{'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'}; + for (int i = 0; i < sentence.length(); i++) { char s = sentence.charAt(i); - if(s == '(' || s == ')'){ + if (s == '(' || s == ')') { switch (s) { case ')': close++; @@ -105,24 +105,24 @@ private boolean validGrammar(String sentence) { } continue; } - if(!Character.isLetter(s)) { + if (!Character.isLetter(s)) { boolean valid = false; - for(char c: valid_characters) { - if(c == s) { + for (char c : valid_characters) { + if (c == s) { valid = true; break; } } - if(!valid) { + if (!valid) { System.out.println("Invalid character"); System.out.println(s); return false; } - if(i != sentence.length() - 1) { - char next = sentence.charAt(i+1); - if(next != '!' && next != '~') { - for(char c: valid_characters) { - if(c == next) { + if (i != sentence.length() - 1) { + char next = sentence.charAt(i + 1); + if (next != '!' && next != '~') { + for (char c : valid_characters) { + if (c == next) { System.out.println("Invalid next character"); System.out.println(s); System.out.println(next); @@ -131,26 +131,27 @@ private boolean validGrammar(String sentence) { } } } - } else { - if(i != sentence.length() - 1) { - if(Character.isLetter(sentence.charAt(i+1))) { + } + else { + if (i != sentence.length() - 1) { + if (Character.isLetter(sentence.charAt(i + 1))) { System.out.println("Invalid next character"); System.out.println(s); - System.out.println(sentence.charAt(i+1)); + System.out.println(sentence.charAt(i + 1)); return false; - } + } } } } return open == close; - } + } private ShortTruthTableBoard generateBoard(List> allCells, List statements, - int width){ + int width) { //calculate the height for the board - int height = statements.size()*2-1; + int height = statements.size() * 2 - 1; //instantiate the board with the correct width and height ShortTruthTableBoard sttBoard = new ShortTruthTableBoard(width, height, @@ -161,16 +162,17 @@ private ShortTruthTableBoard generateBoard(List> allCe for (int x = 0; x < width; x++) { //get the statement index for this row of the table - int statementIndex = y/2; + int statementIndex = y / 2; //get the cell at this location; or create a not_in_play one if necessary ShortTruthTableCell cell = null; //for a cell to exist at (x, y), it must be a valid row and within the statment length - if(y%2==0 && x < statements.get(statementIndex).getLength()) { + if (y % 2 == 0 && x < statements.get(statementIndex).getLength()) { cell = allCells.get(statementIndex).get(x); - System.out.println("Importer: check cell statement ref: "+cell.getStatementReference()); - }else{ + System.out.println("Importer: check cell statement ref: " + cell.getStatementReference()); + } + else { //if it is not a valid cell space, add a NOT_IN_PLAY cell cell = new ShortTruthTableCell(' ', ShortTruthTableCellType.NOT_IN_PLAY, new Point(x, y)); cell.setModifiable(false); @@ -190,20 +192,21 @@ private ShortTruthTableBoard generateBoard(List> allCe private void setGivenCells(ShortTruthTableBoard sttBoard, Element dataElement, NodeList cellData, - List statements) throws InvalidFileFormatException{ + List statements) throws InvalidFileFormatException { //if it is normal, set all predicats to true and the conclusion to false - if(dataElement.getAttribute("normal").equalsIgnoreCase("true")){ + if (dataElement.getAttribute("normal").equalsIgnoreCase("true")) { //set all predicates to true (all but the last one) - for(int i = 0; i{ - - //the cell that this statement holds - private final ShortTruthTableCell cell; - - //child nodes of the tree - private final ShortTruthTableStatement parentStatement; - private final ShortTruthTableStatement leftStatement; - private final ShortTruthTableStatement rightStatement; - - //the representation string for this statement - private final String stringRep; - private final List cells; - - - - //constructor for root statement, sets parent to null - public ShortTruthTableStatement(String statement, List cells){ - this(statement, null, cells); - } - - //recursive constructor; constructs child statement nodes if necessary - private ShortTruthTableStatement(String statement, ShortTruthTableStatement parent, List cells){ - - this.parentStatement = parent; - - //set the string rep to the statement (include parens incase this is a sub statement) - this.stringRep = statement; - this.cells = new ArrayList(cells); - - //remove the parens for parsing the statement - statement = removeParens(statement); - removeParens(cells); - - //get the index of the char that this statement represents - int index = parse(statement); - - //construct the cell for this node in the tree - cell = cells.get(index); - //give the cell a reference back to this statement - cell.setStatementReference(this); - - //get the strings on either side of this char in the string rep - String left = statement.substring(0, index); - String right = statement.substring(index+1); - - List leftCells = new ArrayList(cells.subList(0, index)); - List rightCells = new ArrayList(cells.subList(index+1, cells.size())); - - //cunstruct substatements if necessary - if(left.length() > 0) - leftStatement = new ShortTruthTableStatement(left, this, leftCells); - else - leftStatement = null; - - if(right.length() > 0) { - rightStatement = new ShortTruthTableStatement(right, this, rightCells); - }else - rightStatement = null; - - } - - - - //parsing for the constructor - static String removeParens(String statement){ - - if(statement.charAt(0) != '(') - return statement; - - //if the statement does start with a paren, check that it matches with the last paren - int openParenCount = 1; - int i = 1; - while(i < statement.length()-1){ - char c = statement.charAt(i); - if(c == '(') openParenCount++; - else if(c == ')') openParenCount--; - - //if the first paren has been closed and it is not the end of the string, - //then there is no whole statement parens to remove - if(openParenCount == 0 && i!=statement.length()-1) - return statement; - - i++; - } - //if the while loop made it through the entire statement, there are parens around the whole thing - return statement.substring(1, statement.length()-1); - - } - - int parse(String statement){ - - - //Split by and, or, CONDITIONAL, or biconditional - //keep track of the parens, it must be equal to zero to split - int openParenCount = 0; - //index for stepping through the string - int i = 0; - //step through each char in the statement - while(i < statement.length()){ - //get the char - char c = statement.charAt(i); - //keep track of the open parens - if(c == '(') openParenCount++; - else if(c == ')') openParenCount--; - //if the char is an operator, and there are no open parens, split the statement here - else if(openParenCount==0 && ShortTruthTableOperation.isOperation(c) && c!=ShortTruthTableOperation.NOT) - return i; - //increment the index - i++; - } - - //if it made it through the while loop: - //this is an atomic statement or a negation - //either way, the important char is the first character in the string - return 0; - - } - - static void removeParens(List cells){ - - if(cells.get(0).getSymbol() != '(') - return; - - //if the statement does start with a paren, check that it matches with the last paren - int openParenCount = 1; - int i = 1; - while(i < cells.size()-1){ - char c = cells.get(i).getSymbol(); - if(c == '(') openParenCount++; - else if(c == ')') openParenCount--; - - //if the first paren has been closed and it is not the end of the string, - //then there is no whole statement parens to remove - if(openParenCount == 0 && i!=cells.size()-1) - return; - - i++; - } - - //if the while loop made it through the entire statement, there are parens around the whole thing - cells.remove(cells.size()-1); - cells.remove(0); - - } - - - - - //Getters - - - public ShortTruthTableCell getCell() { return cell; } - - public ShortTruthTableStatement getLeftStatement(){ return leftStatement; } - public ShortTruthTableStatement getRightStatement(){ return rightStatement; } - public ShortTruthTableStatement getParentStatement(){ return parentStatement; } - - @Override - public String toString(){ - if(this.parentStatement == null) - return "SST_Statement: "+stringRep+" parent: null"; - return "SST_Statement: "+stringRep+" parent: "+parentStatement.stringRep; - } - - public String getStringRep(){ - return this.stringRep; - } - - /** - * Returns the length of the statement in cells. This includes all cells used for parenthesis - * - * @return the number of cells contained in this statement - */ - public int getLength(){ - return stringRep.length(); - } - - - public ShortTruthTableCell getCell(int i){ - return cells.get(i); - } - +public class ShortTruthTableStatement extends PuzzleElement { + //the cell that this statement holds + private final ShortTruthTableCell cell; - //Getters (recursive) + //child nodes of the tree + private final ShortTruthTableStatement parentStatement; + private final ShortTruthTableStatement leftStatement; + private final ShortTruthTableStatement rightStatement; - //returns all cells in this statement with the symbol 'symbol'; runs recursively on both sides of the tree - public Set getCellsWithSymbol(char symbol){ - Set set = new HashSet(getLength()); - if(cell.getSymbol() == symbol) set.add(cell); - if(leftStatement != null) set.addAll(leftStatement.getCellsWithSymbol(symbol)); - if(rightStatement != null) set.addAll(rightStatement.getCellsWithSymbol(symbol)); - return set; - } + //the representation string for this statement + private final String stringRep; + private final List cells; + + + //constructor for root statement, sets parent to null + public ShortTruthTableStatement(String statement, List cells) { + this(statement, null, cells); + } + + //recursive constructor; constructs child statement nodes if necessary + private ShortTruthTableStatement(String statement, ShortTruthTableStatement parent, List cells) { + + this.parentStatement = parent; + + //set the string rep to the statement (include parens incase this is a sub statement) + this.stringRep = statement; + this.cells = new ArrayList(cells); + + //remove the parens for parsing the statement + statement = removeParens(statement); + removeParens(cells); + + //get the index of the char that this statement represents + int index = parse(statement); + + //construct the cell for this node in the tree + cell = cells.get(index); + //give the cell a reference back to this statement + cell.setStatementReference(this); + + //get the strings on either side of this char in the string rep + String left = statement.substring(0, index); + String right = statement.substring(index + 1); + + List leftCells = new ArrayList(cells.subList(0, index)); + List rightCells = new ArrayList(cells.subList(index + 1, cells.size())); + + //cunstruct substatements if necessary + if (left.length() > 0) { + leftStatement = new ShortTruthTableStatement(left, this, leftCells); + } + else { + leftStatement = null; + } + + if (right.length() > 0) { + rightStatement = new ShortTruthTableStatement(right, this, rightCells); + } + else { + rightStatement = null; + } + + } + + + //parsing for the constructor + static String removeParens(String statement) { + + if (statement.charAt(0) != '(') { + return statement; + } + + //if the statement does start with a paren, check that it matches with the last paren + int openParenCount = 1; + int i = 1; + while (i < statement.length() - 1) { + char c = statement.charAt(i); + if (c == '(') { + openParenCount++; + } + else { + if (c == ')') openParenCount--; + } + + //if the first paren has been closed and it is not the end of the string, + //then there is no whole statement parens to remove + if (openParenCount == 0 && i != statement.length() - 1) { + return statement; + } + + i++; + } + //if the while loop made it through the entire statement, there are parens around the whole thing + return statement.substring(1, statement.length() - 1); + + } + + int parse(String statement) { + + + //Split by and, or, CONDITIONAL, or biconditional + //keep track of the parens, it must be equal to zero to split + int openParenCount = 0; + //index for stepping through the string + int i = 0; + //step through each char in the statement + while (i < statement.length()) { + //get the char + char c = statement.charAt(i); + //keep track of the open parens + if (c == '(') { + openParenCount++; + } + else { + if (c == ')') { + openParenCount--; + } + //if the char is an operator, and there are no open parens, split the statement here + else { + if (openParenCount == 0 && ShortTruthTableOperation.isOperation(c) && c != ShortTruthTableOperation.NOT) { + return i; + } + } + } + //increment the index + i++; + } + + //if it made it through the while loop: + //this is an atomic statement or a negation + //either way, the important char is the first character in the string + return 0; + + } + + static void removeParens(List cells) { + + if (cells.get(0).getSymbol() != '(') { + return; + } + + //if the statement does start with a paren, check that it matches with the last paren + int openParenCount = 1; + int i = 1; + while (i < cells.size() - 1) { + char c = cells.get(i).getSymbol(); + if (c == '(') { + openParenCount++; + } + else { + if (c == ')') openParenCount--; + } + + //if the first paren has been closed and it is not the end of the string, + //then there is no whole statement parens to remove + if (openParenCount == 0 && i != cells.size() - 1) { + return; + } + + i++; + } + + //if the while loop made it through the entire statement, there are parens around the whole thing + cells.remove(cells.size() - 1); + cells.remove(0); + + } + + + //Getters + + + public ShortTruthTableCell getCell() { + return cell; + } + + public ShortTruthTableStatement getLeftStatement() { + return leftStatement; + } + + public ShortTruthTableStatement getRightStatement() { + return rightStatement; + } + + public ShortTruthTableStatement getParentStatement() { + return parentStatement; + } + + @Override + public String toString() { + if (this.parentStatement == null) { + return "SST_Statement: " + stringRep + " parent: null"; + } + return "SST_Statement: " + stringRep + " parent: " + parentStatement.stringRep; + } + + public String getStringRep() { + return this.stringRep; + } + + /** + * Returns the length of the statement in cells. This includes all cells used for parenthesis + * + * @return the number of cells contained in this statement + */ + public int getLength() { + return stringRep.length(); + } + + + public ShortTruthTableCell getCell(int i) { + return cells.get(i); + } + + + //Getters (recursive) + + //returns all cells in this statement with the symbol 'symbol'; runs recursively on both sides of the tree + public Set getCellsWithSymbol(char symbol) { + Set set = new HashSet(getLength()); + if (cell.getSymbol() == symbol) set.add(cell); + if (leftStatement != null) set.addAll(leftStatement.getCellsWithSymbol(symbol)); + if (rightStatement != null) set.addAll(rightStatement.getCellsWithSymbol(symbol)); + return set; + } // public Set getAllCells(){ // Set set = new HashSet(getLength()); @@ -215,60 +245,62 @@ public Set getCellsWithSymbol(char symbol){ // return set; // } - /** - * Returns an array of three elements where [0] is the left - * statement type, [1] is this statement type, and [2] is the - * right statement type. null means either the statement doesn't - * exist or is is an unknown value. - * - * @return the assigned values to this statement and its substatements - */ - public ShortTruthTableCellType[] getCellTypePattern(){ - //get this type and the right type, they will always be used - ShortTruthTableCellType type = this.cell.getType(); - System.out.println("Right statement: " + rightStatement.getCell()); - ShortTruthTableCellType rightType = this.rightStatement.getCell().getType(); - System.out.println("Right type: " + rightType); - //if this is a not statement, there is no left side - if(cell.getSymbol() == ShortTruthTableOperation.NOT) - return new ShortTruthTableCellType[]{null, type, rightType}; - //if it is any other operation, get the left side too and return it - ShortTruthTableCellType leftType = this.leftStatement.getCell().getType(); - return new ShortTruthTableCellType[]{leftType, type, rightType}; - } - - //Setters - - private void setCellLocations(int rowIndex, int offset){ - //set the location of this cell - int xLoc = offset; - if(leftStatement != null) - xLoc += leftStatement.getLength(); - cell.setLocation(new Point(xLoc, rowIndex)); - //recurse on both sides of the tree - if(leftStatement != null) - leftStatement.setCellLocations(rowIndex, offset); - if(rightStatement != null) - rightStatement.setCellLocations(rowIndex, xLoc+1); - } - - public void setCellLocations(int rowIndex){ - setCellLocations(rowIndex, 0); - } - - - - - - public ShortTruthTableStatement copy(){ - //copy all the cells - List cellsCopy = new ArrayList(); - for(ShortTruthTableCell c : cells) - cellsCopy.add(c.copy()); - //make a copy of the statement with all of the copied cells - ShortTruthTableStatement statementCopy = new ShortTruthTableStatement(stringRep, cellsCopy); - //return the new statement - return statementCopy; - } + /** + * Returns an array of three elements where [0] is the left + * statement type, [1] is this statement type, and [2] is the + * right statement type. null means either the statement doesn't + * exist or is is an unknown value. + * + * @return the assigned values to this statement and its substatements + */ + public ShortTruthTableCellType[] getCellTypePattern() { + //get this type and the right type, they will always be used + ShortTruthTableCellType type = this.cell.getType(); + System.out.println("Right statement: " + rightStatement.getCell()); + ShortTruthTableCellType rightType = this.rightStatement.getCell().getType(); + System.out.println("Right type: " + rightType); + //if this is a not statement, there is no left side + if (cell.getSymbol() == ShortTruthTableOperation.NOT) { + return new ShortTruthTableCellType[]{null, type, rightType}; + } + //if it is any other operation, get the left side too and return it + ShortTruthTableCellType leftType = this.leftStatement.getCell().getType(); + return new ShortTruthTableCellType[]{leftType, type, rightType}; + } + + //Setters + + private void setCellLocations(int rowIndex, int offset) { + //set the location of this cell + int xLoc = offset; + if (leftStatement != null) { + xLoc += leftStatement.getLength(); + } + cell.setLocation(new Point(xLoc, rowIndex)); + //recurse on both sides of the tree + if (leftStatement != null) { + leftStatement.setCellLocations(rowIndex, offset); + } + if (rightStatement != null) { + rightStatement.setCellLocations(rowIndex, xLoc + 1); + } + } + + public void setCellLocations(int rowIndex) { + setCellLocations(rowIndex, 0); + } + + + public ShortTruthTableStatement copy() { + //copy all the cells + List cellsCopy = new ArrayList(); + for (ShortTruthTableCell c : cells) { + cellsCopy.add(c.copy()); + } + //make a copy of the statement with all of the copied cells + ShortTruthTableStatement statementCopy = new ShortTruthTableStatement(stringRep, cellsCopy); + //return the new statement + return statementCopy; + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRuleAtomic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRuleAtomic.java index 809251023..df90efadf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRuleAtomic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRuleAtomic.java @@ -2,9 +2,9 @@ import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAtomic; -public class BasicRuleAtomic extends BasicRule_Generic{ - - public BasicRuleAtomic(){ +public class BasicRuleAtomic extends BasicRule_Generic { + + public BasicRuleAtomic() { super("STTT-BASC-0001", "Atomic Rule", "All identical atoms have the same T/F value", "Atomic", @@ -12,5 +12,5 @@ public BasicRuleAtomic(){ false ); } - + } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java index 822a22292..4a0fac4b2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java @@ -15,42 +15,42 @@ public abstract class BasicRule_Generic extends BasicRule { final ContradictionRule CORRESPONDING_CONTRADICTION_RULE; final boolean ELIMINATION_RULE; - public BasicRule_Generic(String ruleID, String ruleName, String description, String imageName, ContradictionRule contraRule, boolean eliminationRule){ - super(ruleID, ruleName, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/"+imageName+".png"); + public BasicRule_Generic(String ruleID, String ruleName, String description, String imageName, ContradictionRule contraRule, boolean eliminationRule) { + super(ruleID, ruleName, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/" + imageName + ".png"); this.CORRESPONDING_CONTRADICTION_RULE = contraRule; this.ELIMINATION_RULE = eliminationRule; } - public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) - { + public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) { // Check that the puzzle element is not unknown ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); ShortTruthTableCell cell = (ShortTruthTableCell) board.getPuzzleElement(element); - if (!cell.isAssigned()) + if (!cell.isAssigned()) { return super.getInvalidUseOfRuleMessage() + ": Only assigned cells are allowed for basic rules"; + } - if (this.ELIMINATION_RULE) - { + if (this.ELIMINATION_RULE) { // Strategy: If this is an elimination rule, simply check if there is a contradiction at the specified statement // This gets the operator of the parent statement, which is what we need for checking the contradiction PuzzleElement checkElement = cell.getStatementReference().getParentStatement().getCell(); String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(board, checkElement); - if (contradictionMessage != null) - { - if (contradictionMessage.startsWith(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) + if (contradictionMessage != null) { + if (contradictionMessage.startsWith(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) { return null; - else + } + else { return super.getInvalidUseOfRuleMessage() + ": " + contradictionMessage; + } } - else + else { return super.getInvalidUseOfRuleMessage(); + } } - else - { + else { // Strategy: Negate the modified cell and check if there is a contradiction. If there is one, then the // original statement must be true. If there isn't one, then the original statement must be false. @@ -58,8 +58,9 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) ((ShortTruthTableCell) modifiedBoard.getPuzzleElement(element)).setType(cell.getType().getNegation()); String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(modifiedBoard, element); - if (contradictionMessage == null) // A contradiction exists in the modified statement; this is good! + if (contradictionMessage == null) { // A contradiction exists in the modified statement; this is good! return null; + } return super.getInvalidUseOfRuleMessage() + ": " + contradictionMessage; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/BasicRule_GenericElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/BasicRule_GenericElimination.java index 53e6e90a0..bd2470fed 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/BasicRule_GenericElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/BasicRule_GenericElimination.java @@ -7,9 +7,9 @@ public abstract class BasicRule_GenericElimination extends BasicRule_Generic { public BasicRule_GenericElimination(String ruleID, String ruleName, ContradictionRule contradictionRule) { - super(ruleID,ruleName+" Elimination", - ruleName+" statements must have a valid pattern", - "elimination/"+ruleName, + super(ruleID, ruleName + " Elimination", + ruleName + " statements must have a valid pattern", + "elimination/" + ruleName, contradictionRule, true ); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/BasicRule_GenericIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/BasicRule_GenericIntroduction.java index bdd4033cc..dccb25385 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/BasicRule_GenericIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/BasicRule_GenericIntroduction.java @@ -7,9 +7,9 @@ public abstract class BasicRule_GenericIntroduction extends BasicRule_Generic { protected BasicRule_GenericIntroduction(String ruleID, String ruleName, ContradictionRule contradictionRule) { - super(ruleID,ruleName+" Introduction", - ruleName+" statements must have a valid pattern", - "introduction/"+ruleName, + super(ruleID, ruleName + " Introduction", + ruleName + " statements must have a valid pattern", + "introduction/" + ruleName, contradictionRule, false ); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java index 9e97a5ddb..0fa1e2214 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java @@ -65,8 +65,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { } @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) - { + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return null; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java index 2a375109f..047ea5d33 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java @@ -19,11 +19,10 @@ public abstract class CaseRule_Generic extends CaseRule { public CaseRule_Generic(String ruleID, String ruleName, String title, String description) { - super(ruleID, title, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/case/"+ruleName+".png"); + super(ruleID, title, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/case/" + ruleName + ".png"); } - /** * Checks whether the transition logically follows from the parent node using this rule * @@ -31,26 +30,29 @@ public CaseRule_Generic(String ruleID, String ruleName, String title, String des * @return null if the child node logically follow from the parent node, otherwise error message */ @Override - public String checkRuleRaw(TreeTransition transition) - { + public String checkRuleRaw(TreeTransition transition) { List childTransitions = transition.getParents().get(0).getChildren(); - if (childTransitions.size() != 2) + if (childTransitions.size() != 2) { return "This case rule must have 2 children."; + } TreeTransition case1 = childTransitions.get(0); TreeTransition case2 = childTransitions.get(1); - if (case1.getBoard().getModifiedData().size() != 1 || case2.getBoard().getModifiedData().size() != 1) + if (case1.getBoard().getModifiedData().size() != 1 || case2.getBoard().getModifiedData().size() != 1) { return "This case rule must have 1 modified cell for each case."; + } ShortTruthTableCell mod1 = (ShortTruthTableCell) case1.getBoard().getModifiedData().iterator().next(); ShortTruthTableCell mod2 = (ShortTruthTableCell) case2.getBoard().getModifiedData().iterator().next(); - if (!mod1.getLocation().equals(mod2.getLocation())) + if (!mod1.getLocation().equals(mod2.getLocation())) { return "This case rule must modify the same cell for each case."; + } boolean firstPossibility = mod1.getType() == ShortTruthTableCellType.TRUE && mod2.getType() == ShortTruthTableCellType.FALSE; boolean secondPossibility = mod1.getType() == ShortTruthTableCellType.FALSE && mod2.getType() == ShortTruthTableCellType.TRUE; - if (!firstPossibility && !secondPossibility) + if (!firstPossibility && !secondPossibility) { return "This case rule must an empty true or false cell."; + } return null; } @@ -65,8 +67,7 @@ public String checkRuleRaw(TreeTransition transition) * otherwise error message */ @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) - { + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java index 68185860d..375a60292 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java @@ -19,8 +19,8 @@ public CaseRule_GenericStatement(String ruleID, char operation, String title, ShortTruthTableCellType[][] trueCases, ShortTruthTableCellType[][] falseCases) { super(ruleID, ShortTruthTableOperation.getRuleName(operation), - title+" case", - "A known "+title.toUpperCase()+" statement can have multiple forms"); + title + " case", + "A known " + title.toUpperCase() + " statement can have multiple forms"); this.operation = operation; @@ -48,22 +48,24 @@ public CaseBoard getCaseBoard(Board board) { //add all elements that can be selected for the case rule statement for (PuzzleElement element : sttBoard.getPuzzleElements()) { - System.out.println("GetCaseBoard Testing: "+element); + System.out.println("GetCaseBoard Testing: " + element); //get the cell object ShortTruthTableCell cell = sttBoard.getCellFromElement(element); //the cell must match the symbol - if(cell.getSymbol() != this.operation) continue; + if (cell.getSymbol() != this.operation) continue; System.out.println(" Selectable... checking logic"); //the statement must be assigned with unassigned sub-statements - if(!cell.getType().isTrueOrFalse()) continue; + if (!cell.getType().isTrueOrFalse()) continue; System.out.println(" Operation is known"); - if(cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; + if (cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; System.out.println(" right side is unknown"); - if(this.operation != ShortTruthTableOperation.NOT && - cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; + if (this.operation != ShortTruthTableOperation.NOT && + cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) { + continue; + } System.out.println(" left side is unknown"); System.out.println(" Valid choice"); @@ -90,21 +92,22 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { ShortTruthTableCell cell = sttBoard.getCellFromElement(puzzleElement); //if the statement is set to true - if(cell.getType() == ShortTruthTableCellType.TRUE) + if (cell.getType() == ShortTruthTableCellType.TRUE) { return getCasesFromCell(sttBoard, puzzleElement, trueCases); + } //if the statement is set to false return getCasesFromCell(sttBoard, puzzleElement, falseCases); } - private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities){ + private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities) { //store all possible boards ArrayList cases = new ArrayList<>(); //go through all the possibilities - for(int i = 0; i getCasesFromCell(ShortTruthTableBoard board, PuzzleElem //modify its children //avoid error if it is a NOT statement - if(possibilities[i][0] != null){ + if (possibilities[i][0] != null) { ShortTruthTableCell leftCell = statement.getLeftStatement().getCell(); leftCell.setData(possibilities[i][0]); b.addModifiedData(leftCell); } //always modify the right side of the statement - if(possibilities[i][1] != null) { + if (possibilities[i][1] != null) { ShortTruthTableCell rightCell = statement.getRightStatement().getCell(); rightCell.setData(possibilities[i][1]); b.addModifiedData(rightCell); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java index 083051caa..aa0da52c3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java @@ -3,18 +3,18 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -public class ContradictionRuleAnd extends ContradictionRule_GenericStatement{ +public class ContradictionRuleAnd extends ContradictionRule_GenericStatement { - public ContradictionRuleAnd(){ + public ContradictionRuleAnd() { super("STTT-CONT-0001", "Contradicting And", "An AND statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/And.png", ShortTruthTableOperation.AND, - new ShortTruthTableCellType[][] { - {n, T, F}, - {F, T, n}, - // {F, T, F}, - {T, F, T}, + new ShortTruthTableCellType[][]{ + {n, T, F}, + {F, T, n}, + // {F, T, F}, + {T, F, T}, } ); } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java index aec8effd0..2d1efb945 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java @@ -14,10 +14,10 @@ import java.util.Iterator; -public class ContradictionRuleAtomic extends ContradictionRule{ +public class ContradictionRuleAtomic extends ContradictionRule { - public ContradictionRuleAtomic(){ + public ContradictionRuleAtomic() { super("STTT-CONT-0002", "Contradicting Variable", "A single variable can not be both True and False", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Atomic.png"); @@ -33,13 +33,13 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen //get the cell that contradicts another cell in the board ShortTruthTableCell cell = (ShortTruthTableCell) board.getPuzzleElement(puzzleElement); - if(!cell.isVariable()){ + if (!cell.isVariable()) { System.out.println(" Not Var"); return "Can not check for contradiction on a non-variable element"; } ShortTruthTableCellType cellType = cell.getType(); - if(!cellType.isTrueOrFalse()){ + if (!cellType.isTrueOrFalse()) { return "Can only check for a contradiction against a cell that is assigned a value of True or False"; } @@ -48,16 +48,17 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen //check if there are any contradictions Iterator itr = varCells.iterator(); - while(itr.hasNext()){ + while (itr.hasNext()) { ShortTruthTableCell checkCell = itr.next(); ShortTruthTableCellType checkCellType = checkCell.getType(); //if there is an assigned contradiction, return null - if(checkCellType.isTrueOrFalse() && checkCellType!=cellType) + if (checkCellType.isTrueOrFalse() && checkCellType != cellType) { return null; + } } //if it made it through the while loop, thene there is no contradiction - return "There is no contradiction for the variable "+cell.getSymbol(); + return "There is no contradiction for the variable " + cell.getSymbol(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java index b74888dbb..b6b159b26 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java @@ -3,14 +3,14 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -public class ContradictionRuleBiconditional extends ContradictionRule_GenericStatement{ +public class ContradictionRuleBiconditional extends ContradictionRule_GenericStatement { - public ContradictionRuleBiconditional(){ + public ContradictionRuleBiconditional() { super("STTT-CONT-0002", "Contradicting Biconditional", "A Biconditional statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Biconditional.png", ShortTruthTableOperation.BICONDITIONAL, - new ShortTruthTableCellType[][] { + new ShortTruthTableCellType[][]{ {T, T, F}, {F, T, T}, {T, F, T}, diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java index 96a15282b..caa65afa4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java @@ -3,14 +3,14 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -public class ContradictionRuleConditional extends ContradictionRule_GenericStatement{ +public class ContradictionRuleConditional extends ContradictionRule_GenericStatement { - public ContradictionRuleConditional(){ + public ContradictionRuleConditional() { super("STTT-CONT-0004", "Contradicting Conditional", "A Conditional statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Conditional.png", ShortTruthTableOperation.CONDITIONAL, - new ShortTruthTableCellType[][] { + new ShortTruthTableCellType[][]{ {n, F, T}, {F, F, n}, {T, T, F} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java index e81e95218..4be059a06 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java @@ -3,14 +3,14 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -public class ContradictionRuleNot extends ContradictionRule_GenericStatement{ +public class ContradictionRuleNot extends ContradictionRule_GenericStatement { - public ContradictionRuleNot(){ + public ContradictionRuleNot() { super("STTT-CONT-0005", "Contradicting Negation", "A negation and its following statement can not have the same truth value", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Not.png", ShortTruthTableOperation.NOT, - new ShortTruthTableCellType[][] { + new ShortTruthTableCellType[][]{ {n, T, T}, {n, F, F} } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java index 6c903f76f..46fee2a44 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java @@ -3,17 +3,17 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -public class ContradictionRuleOr extends ContradictionRule_GenericStatement{ +public class ContradictionRuleOr extends ContradictionRule_GenericStatement { - public ContradictionRuleOr(){ + public ContradictionRuleOr() { super("STTT-CONT-0006", "Contradicting Or", "An OR statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Or.png", ShortTruthTableOperation.OR, - new ShortTruthTableCellType[][] { - {n, F, T}, - {T, F, n}, - {F, T, F} + new ShortTruthTableCellType[][]{ + {n, F, T}, + {T, F, n}, + {F, T, F} } ); } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java index b6f1630bb..4554e5100 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java @@ -11,7 +11,7 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; -public abstract class ContradictionRule_GenericStatement extends ContradictionRule{ +public abstract class ContradictionRule_GenericStatement extends ContradictionRule { private final char operationSymbol; @@ -25,7 +25,7 @@ public abstract class ContradictionRule_GenericStatement extends ContradictionRu private final String NOT_TRUE_FALSE_ERROR_MESSAGE = "Can only check for a contradiction on a cell that is assigned a value of True or False"; public ContradictionRule_GenericStatement(String ruleID, String ruleName, String description, String imageName, - char operationSymbol, ShortTruthTableCellType[][] contradictionPatterns){ + char operationSymbol, ShortTruthTableCellType[][] contradictionPatterns) { super(ruleID, ruleName, description, imageName); this.operationSymbol = operationSymbol; this.contradictionPatterns = contradictionPatterns; @@ -41,34 +41,38 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement operatorPuzz ShortTruthTableCell cell = board.getCellFromElement(operatorPuzzleElement); ShortTruthTableStatement statement = cell.getStatementReference(); - if(cell.getSymbol() != this.operationSymbol) + if (cell.getSymbol() != this.operationSymbol) { return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; + } // check that the initial statement is assigned ShortTruthTableCellType cellType = cell.getType(); - if(!cellType.isTrueOrFalse()) + if (!cellType.isTrueOrFalse()) { return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_TRUE_FALSE_ERROR_MESSAGE; + } // get the pattern for this sub-statement ShortTruthTableCellType[] testPattern = statement.getCellTypePattern(); // if the board pattern matches any contradiction pattern, it is a valid contradiction - for(ShortTruthTableCellType[] pattern : contradictionPatterns){ + for (ShortTruthTableCellType[] pattern : contradictionPatterns) { boolean matches = true; - for(int i = 0; i < 3; i++){ + for (int i = 0; i < 3; i++) { // ull means that part does not affect the statement - if(pattern[i] == null) + if (pattern[i] == null) { continue; + } //if it is not null, it must match the test pattern - if(pattern[i] != testPattern[i]){ + if (pattern[i] != testPattern[i]) { matches = false; break; } } // if testPattern matches one of the valid contradiction patterns, the contradiction is correct - if (matches) + if (matches) { return null; + } } return super.getNoContradictionMessage(); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java index d45d82c54..e80cd3d77 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java @@ -97,20 +97,23 @@ public String getErrorString() { Board board = selectedView.getTreeElement().getBoard(); SkyscrapersClue selectedPuzzleElement = clueView.getPuzzleElement(); if (selectedView.getType() == TreeElementType.NODE) { - + TreeNodeView nodeView = (TreeNodeView) selectedView; if (!nodeView.getChildrenViews().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); - } else { + } + else { if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); } } - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) selectedView; if (!transitionView.getTreeElement().getBoard().isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); - } else { + } + else { if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java index b04fb5123..a4853993d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java @@ -26,7 +26,7 @@ public Skyscrapers() { */ @Override public void initializeView() { - SkyscrapersBoard board = (SkyscrapersBoard) currentBoard; + SkyscrapersBoard board = (SkyscrapersBoard) currentBoard; boardView = new SkyscrapersView((SkyscrapersBoard) currentBoard); } @@ -47,7 +47,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Skyscrapers, false otherwise + * @return true if the given dimensions are valid for Skyscrapers, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented @@ -62,11 +62,11 @@ public boolean isValidDimensions(int rows, int columns) { */ @Override public boolean isBoardComplete(Board board) { - SkyscrapersBoard SkyscraperBoard = (SkyscrapersBoard) board; + SkyscrapersBoard SkyscraperBoard = (SkyscrapersBoard) board; for (ContradictionRule rule : contradictionRules) { if (rule.checkContradiction(SkyscraperBoard) == null) { - System.out.println(rule.getRuleName()); + System.out.println(rule.getRuleName()); return false; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index b4de925e3..0e8786874 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -56,7 +56,7 @@ public ArrayList getRowClues() { //EAST CLUE public ArrayList getColClues() { //SOUTH CLUE return colClues; } - + public ArrayList getRow() { //WEST CLUE return row; } @@ -76,8 +76,8 @@ public PuzzleElement getPuzzleElement(PuzzleElement element) { case -2: return element; case -1: - SkyscrapersLine line = (SkyscrapersLine) element; - SkyscrapersLine thisLine = null; + SkyscrapersLine line = (SkyscrapersLine) element; + SkyscrapersLine thisLine = null; for (SkyscrapersLine l : lines) { if (line.compare(l)) { thisLine = l; @@ -97,7 +97,7 @@ public PuzzleElement getPuzzleElement(PuzzleElement element) { */ @Override public void notifyAddition(PuzzleElement puzzleElement) { - if(puzzleElement instanceof SkyscrapersLine) { + if (puzzleElement instanceof SkyscrapersLine) { lines.add((SkyscrapersLine) puzzleElement); } } @@ -109,9 +109,9 @@ public void notifyAddition(PuzzleElement puzzleElement) { */ @Override public void notifyDeletion(PuzzleElement puzzleElement) { - if(puzzleElement instanceof SkyscrapersLine) { - for(SkyscrapersLine line : lines) { - if(line.compare((SkyscrapersLine)puzzleElement)) { + if (puzzleElement instanceof SkyscrapersLine) { + for (SkyscrapersLine line : lines) { + if (line.compare((SkyscrapersLine) puzzleElement)) { lines.remove(line); break; } @@ -167,14 +167,15 @@ public List getRowCol(int index, SkyscrapersType type, boolean List list = new ArrayList<>(); if (isRow) { for (int i = 0; i < dimension.height; i++) { - SkyscrapersCell cell = getCell(i, index); + SkyscrapersCell cell = getCell(i, index); if (cell.getType() == type) { list.add(cell); } } - } else { + } + else { for (int i = 0; i < dimension.width; i++) { - SkyscrapersCell cell = getCell(index, i); + SkyscrapersCell cell = getCell(index, i); if (cell.getType() == type) { list.add(cell); } @@ -191,7 +192,7 @@ public List getRowCol(int index, SkyscrapersType type, boolean */ @Override public boolean equalsBoard(Board board) { - SkyscrapersBoard treeTentBoard = (SkyscrapersBoard) board; + SkyscrapersBoard treeTentBoard = (SkyscrapersBoard) board; for (SkyscrapersLine l1 : lines) { boolean hasLine = false; for (SkyscrapersLine l2 : treeTentBoard.lines) { @@ -208,18 +209,18 @@ public boolean equalsBoard(Board board) { @Override public SkyscrapersBoard copy() { - SkyscrapersBoard copy = new SkyscrapersBoard(dimension.width, dimension.height); + SkyscrapersBoard copy = new SkyscrapersBoard(dimension.width, dimension.height); for (int x = 0; x < this.dimension.width; x++) { for (int y = 0; y < this.dimension.height; y++) { copy.setCell(x, y, getCell(x, y).copy()); } } for (SkyscrapersLine line : lines) { - SkyscrapersLine lineCpy = line.copy(); + SkyscrapersLine lineCpy = line.copy(); lineCpy.setModifiable(false); copy.getLines().add(lineCpy); } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } copy.rowClues = rowClues; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java index 1a0a5e956..74d753666 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java @@ -5,7 +5,7 @@ import java.awt.*; public class SkyscrapersCell extends GridCell { - private int max; + private int max; public SkyscrapersCell(int valueInt, Point location, int size) { super(valueInt, location); @@ -20,14 +20,14 @@ public SkyscrapersType getType() { return SkyscrapersType.Number; } } - + public int getMax() { return max; } @Override public SkyscrapersCell copy() { - SkyscrapersCell copy = new SkyscrapersCell(data, (Point) location.clone(), max); + SkyscrapersCell copy = new SkyscrapersCell(data, (Point) location.clone(), max); copy.setIndex(index); copy.setModifiable(isModifiable); copy.setGiven(isGiven); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java index 0cf634fde..4e66708bd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java @@ -22,7 +22,7 @@ public class SkyscrapersCellFactory extends ElementFactory { @Override public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { try { - SkyscrapersBoard treeTentBoard = (SkyscrapersBoard) board; + SkyscrapersBoard treeTentBoard = (SkyscrapersBoard) board; int width = treeTentBoard.getWidth(); int height = treeTentBoard.getHeight(); NamedNodeMap attributeList = node.getAttributes(); @@ -41,24 +41,30 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat SkyscrapersCell cell = new SkyscrapersCell(value, new Point(x, y), width); cell.setIndex(y * height + x); return cell; - } else if (node.getNodeName().equalsIgnoreCase("line")) { - int x1 = Integer.valueOf(attributeList.getNamedItem("x1").getNodeValue()); - int y1 = Integer.valueOf(attributeList.getNamedItem("y1").getNodeValue()); - int x2 = Integer.valueOf(attributeList.getNamedItem("x2").getNodeValue()); - int y2 = Integer.valueOf(attributeList.getNamedItem("y2").getNodeValue()); - if (x1 >= width || y1 >= height || x2 >= width || y2 >= height) { - throw new InvalidFileFormatException("TreeTent Factory: line location out of bounds"); - } + } + else { + if (node.getNodeName().equalsIgnoreCase("line")) { + int x1 = Integer.valueOf(attributeList.getNamedItem("x1").getNodeValue()); + int y1 = Integer.valueOf(attributeList.getNamedItem("y1").getNodeValue()); + int x2 = Integer.valueOf(attributeList.getNamedItem("x2").getNodeValue()); + int y2 = Integer.valueOf(attributeList.getNamedItem("y2").getNodeValue()); + if (x1 >= width || y1 >= height || x2 >= width || y2 >= height) { + throw new InvalidFileFormatException("TreeTent Factory: line location out of bounds"); + } - SkyscrapersCell c1 = treeTentBoard.getCell(x1, y1); - SkyscrapersCell c2 = treeTentBoard.getCell(x2, y2); - return new SkyscrapersLine(c1, c2); - } else { - throw new InvalidFileFormatException("TreeTent Factory: unknown puzzleElement puzzleElement"); + SkyscrapersCell c1 = treeTentBoard.getCell(x1, y1); + SkyscrapersCell c2 = treeTentBoard.getCell(x2, y2); + return new SkyscrapersLine(c1, c2); + } + else { + throw new InvalidFileFormatException("TreeTent Factory: unknown puzzleElement puzzleElement"); + } } - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("TreeTent Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("TreeTent Factory: could not find attribute(s)"); } } @@ -66,8 +72,8 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { @@ -82,7 +88,8 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle cellElement.setAttribute("y", String.valueOf(loc.y)); return cellElement; - } else { + } + else { org.w3c.dom.Element lineElement = document.createElement("line"); SkyscrapersLine line = (SkyscrapersLine) puzzleElement; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java index 22799ed05..549789c01 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java @@ -22,6 +22,7 @@ public SkyscrapersClueView(SkyscrapersClue clue) { public SkyscrapersClue getPuzzleElement() { return (SkyscrapersClue) super.getPuzzleElement(); } + @Override public void draw(Graphics2D graphics2D) { drawElement(graphics2D); @@ -46,7 +47,7 @@ public void drawElement(Graphics2D graphics2D) { value = String.valueOf(clue.getData()); break; case CLUE_WEST: - value = String.valueOf(clue.getData()); + value = String.valueOf(clue.getData()); //value = SkyscrapersClue.colNumToString(clue.getData() + 1); break; default: diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java index 1a5664f94..fa771beca 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java @@ -56,10 +56,12 @@ public void mouseReleased(MouseEvent e) { autoCaseRuleCommand.execute(); getInstance().getHistory().pushChange(autoCaseRuleCommand); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(autoCaseRuleCommand.getError()); } - } else { + } + else { if (dragStart == lastCellPressed) { if (dragStart.getPuzzleElement().getIndex() >= 0) { ICommand edit = new EditDataCommand(lastCellPressed, selection, e); @@ -67,16 +69,19 @@ public void mouseReleased(MouseEvent e) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(edit.getError()); } - } else { + } + else { ClueCommand edit = new ClueCommand(selection, (SkyscrapersClueView) dragStart); if (edit.canExecute()) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(edit.getError()); } } @@ -100,18 +105,23 @@ public void mouseReleased(MouseEvent e) { @Override public void changeCell(MouseEvent e, PuzzleElement element) { - SkyscrapersCell cell = (SkyscrapersCell) element; + SkyscrapersCell cell = (SkyscrapersCell) element; if (e.getButton() == MouseEvent.BUTTON1) { - if (cell.getData() < cell.getMax()) { - cell.setData(cell.getData()+1); - } else { + if (cell.getData() < cell.getMax()) { + cell.setData(cell.getData() + 1); + } + else { cell.setData(0); } - } else if (e.getButton() == MouseEvent.BUTTON3) { - if (cell.getData() > 0) { - cell.setData(cell.getData()-1); - } else { - cell.setData(cell.getMax()); + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + if (cell.getData() > 0) { + cell.setData(cell.getData() - 1); + } + else { + cell.setData(cell.getMax()); + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java index 727d9957e..8df3a18a8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java @@ -5,10 +5,11 @@ import java.awt.*; public class SkyscrapersElementView extends GridElementView { - private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16); + private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16); private static final Color FONT_COLOR = new Color(0x212121); private static final Color BORDER_COLOR = new Color(0x424242); private static final Color BACKGROUND_COLOR = new Color(0xEEEEEE); + public SkyscrapersElementView(SkyscrapersCell cell) { super(cell); } @@ -37,8 +38,8 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); }*/ - - graphics2D.setStroke(new BasicStroke(1)); + + graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(BACKGROUND_COLOR); graphics2D.fillRect(location.x, location.y, size.width, size.height); graphics2D.setColor(BORDER_COLOR); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java index 80bf05b61..96a41378f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -12,7 +12,7 @@ public SkyscrapersExporter(Skyscrapers treeTent) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - SkyscrapersBoard board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); + SkyscrapersBoard board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); @@ -20,7 +20,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { org.w3c.dom.Element cellsElement = newDocument.createElement("cells"); for (PuzzleElement puzzleElement : board.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; if (cell.getData() != 0) { org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java index 0f009a440..68979881a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java @@ -16,8 +16,8 @@ public SkyscrapersImporter(Skyscrapers treeTent) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -48,10 +48,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); treeTentBoard = new SkyscrapersBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - treeTentBoard = new SkyscrapersBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + treeTentBoard = new SkyscrapersBoard(width, height); + } } if (treeTentBoard == null) { @@ -62,7 +65,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = treeTentBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - SkyscrapersCell cell = (SkyscrapersCell) puzzle.getFactory().importCell(elementDataList.item(i), treeTentBoard); + SkyscrapersCell cell = (SkyscrapersCell) puzzle.getFactory().importCell(elementDataList.item(i), treeTentBoard); Point loc = cell.getLocation(); if (cell.getData() != 0) { cell.setModifiable(false); @@ -74,7 +77,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (treeTentBoard.getCell(x, y) == null) { - SkyscrapersCell cell = new SkyscrapersCell(0, new Point(x, y), width); + SkyscrapersCell cell = new SkyscrapersCell(0, new Point(x, y), width); cell.setIndex(y * height + x); cell.setModifiable(true); treeTentBoard.setCell(x, y, cell); @@ -147,7 +150,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } puzzle.setCurrentBoard(treeTentBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("TreeTent Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java index a66c6d7b2..2f0f30afd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java @@ -16,7 +16,7 @@ public SkyscrapersLineView(SkyscrapersLine line) { @Override public void draw(Graphics2D graphics2D) { - SkyscrapersLine line = (SkyscrapersLine) puzzleElement; + SkyscrapersLine line = (SkyscrapersLine) puzzleElement; Point p1 = line.getC1().getLocation(); Point p2 = line.getC2().getLocation(); int x1 = (p1.x + 1) * size.width + size.width / 2; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java index 98d3545d2..e165686bb 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java @@ -6,6 +6,8 @@ import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.imageio.ImageIO; import java.awt.*; @@ -13,6 +15,7 @@ import java.util.ArrayList; public class SkyscrapersView extends GridBoardView { + private final static Logger LOGGER = LogManager.getLogger(SkyscrapersView.class.getName()); static Image TREE, GRASS, TENT; static { @@ -20,8 +23,9 @@ public class SkyscrapersView extends GridBoardView { TREE = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/tree.png")); GRASS = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/grass.png")); TENT = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/tent.png")); - } catch (IOException e) { - + } + catch (IOException e) { + LOGGER.error("Failed to open TreeTent images"); } } @@ -43,7 +47,7 @@ public SkyscrapersView(SkyscrapersBoard board) { this.westClues = new ArrayList<>(); for (PuzzleElement puzzleElement : board.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; Point loc = cell.getLocation(); SkyscrapersElementView elementView = new SkyscrapersElementView(cell); elementView.setIndex(cell.getIndex()); @@ -53,14 +57,14 @@ public SkyscrapersView(SkyscrapersBoard board) { } for (SkyscrapersLine line : board.getLines()) { - SkyscrapersLineView lineView = new SkyscrapersLineView(line); + SkyscrapersLineView lineView = new SkyscrapersLineView(line); lineView.setSize(elementSize); lineViews.add(lineView); } for (int i = 0; i < gridSize.height; i++) { - //SkyscrapersClueView row = new SkyscrapersClueView(new SkyscrapersClue(i, i, SkyscrapersType.CLUE_WEST)); - SkyscrapersClueView row = new SkyscrapersClueView(board.getRow().get(i)); + //SkyscrapersClueView row = new SkyscrapersClueView(new SkyscrapersClue(i, i, SkyscrapersType.CLUE_WEST)); + SkyscrapersClueView row = new SkyscrapersClueView(board.getRow().get(i)); row.setLocation(new Point(0, (i + 1) * elementSize.height)); row.setSize(elementSize); @@ -73,8 +77,8 @@ public SkyscrapersView(SkyscrapersBoard board) { } for (int i = 0; i < gridSize.width; i++) { - //SkyscrapersClueView col = new SkyscrapersClueView(new SkyscrapersClue(i, i, SkyscrapersType.CLUE_NORTH)); - SkyscrapersClueView col = new SkyscrapersClueView(board.getCol().get(i)); + //SkyscrapersClueView col = new SkyscrapersClueView(new SkyscrapersClue(i, i, SkyscrapersType.CLUE_NORTH)); + SkyscrapersClueView col = new SkyscrapersClueView(board.getCol().get(i)); col.setLocation(new Point((i + 1) * elementSize.width, 0)); col.setSize(elementSize); @@ -164,13 +168,14 @@ public void onTreeElementChanged(TreeElement treeElement) { SkyscrapersBoard treeTentBoard; if (board instanceof CaseBoard) { treeTentBoard = (SkyscrapersBoard) ((CaseBoard) board).getBaseBoard(); - } else { + } + else { treeTentBoard = (SkyscrapersBoard) board; } lineViews.clear(); for (SkyscrapersLine line : treeTentBoard.getLines()) { - SkyscrapersLineView lineView = new SkyscrapersLineView(line); + SkyscrapersLineView lineView = new SkyscrapersLineView(line); lineView.setSize(elementSize); lineViews.add(lineView); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/TODO.md b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/TODO.md index dc21403ef..76c86b32f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/TODO.md +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/TODO.md @@ -1,10 +1,11 @@ ## TODO + - Implement board class (`SkyscrapersBoard.java`) - Implement clues class (`SkyscrapersClue.java`) - Implement cell generation (`SkyscrapersCellFactory.java`) - Implement puzzle exporter (`SkyscrapersExporter.java`) - Add way to interact with puzzle (`SkyscrapersCellController.java`) - Add vision (`SkyscrapersVision.java`, `SkyscrapersVisionView.java`) -- Puzzle GUI (`SkyscrapersView.java`, `SkyscrapersElementView.java`, `SkyscrapersClueView.java`) +- Puzzle GUI (`SkyscrapersView.java`, `SkyscrapersElementView.java`, `SkyscrapersClueView.java`) - Determine if puzzle is solved - Add rules (see Sudoku and the powerpoint) diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java index 34fbaa1dc..a7df882ff 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java @@ -29,32 +29,32 @@ public DuplicateNumberContradictionRule() { */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - + Set candidates = new HashSet(); - + //check row for (int i = 0; i < skyscrapersboard.getWidth(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (i != loc.x && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { - System.out.print(c.getData()); - System.out.println(cell.getData()); + System.out.print(c.getData()); + System.out.println(cell.getData()); return null; } } - + // check column for (int i = 0; i < skyscrapersboard.getHeight(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (i != loc.y && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { - System.out.print(c.getData()); - System.out.println(cell.getData()); + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (i != loc.y && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { + System.out.print(c.getData()); + System.out.println(cell.getData()); return null; } } - + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java index a2ecaf527..9a9c0bf8e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java @@ -29,94 +29,94 @@ public ExceedingVisibilityContradictionRule() { */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - + Set candidates = new HashSet(); - + //check row - int west = skyscrapersboard.getRow().get(loc.y).getData(); - int east = skyscrapersboard.getRowClues().get(loc.y).getData(); - int north = skyscrapersboard.getCol().get(loc.x).getData(); - int south = skyscrapersboard.getColClues().get(loc.x).getData(); - int max = 0; - int count = 0; - boolean complete = true; - for (int i = 0; i < skyscrapersboard.getWidth(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + int west = skyscrapersboard.getRow().get(loc.y).getData(); + int east = skyscrapersboard.getRowClues().get(loc.y).getData(); + int north = skyscrapersboard.getCol().get(loc.x).getData(); + int south = skyscrapersboard.getColClues().get(loc.x).getData(); + int max = 0; + int count = 0; + boolean complete = true; + for (int i = 0; i < skyscrapersboard.getWidth(); i++) { + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); max = c.getData(); count++; } if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + complete = false; } } - if (count > west && complete == true) { - return null; - } - - max = 0; - count = 0; - complete = true; - for (int i = skyscrapersboard.getWidth() - 1; i >= 0; i--) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + if (count > west && complete == true) { + return null; + } + + max = 0; + count = 0; + complete = true; + for (int i = skyscrapersboard.getWidth() - 1; i >= 0; i--) { + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); max = c.getData(); count = count + 1; } if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + complete = false; } } - if (count > east && complete == true) { - return null; - } - + if (count > east && complete == true) { + return null; + } + // check column - max = 0; - count = 0; - complete = true; + max = 0; + count = 0; + complete = true; for (int i = 0; i < skyscrapersboard.getHeight(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); - max = c.getData(); + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (c.getType() == SkyscrapersType.Number && c.getData() > max) { + //System.out.print(c.getData()); + //System.out.println(cell.getData()); + max = c.getData(); count = count + 1; } - if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + if (c.getType() == SkyscrapersType.UNKNOWN) { + complete = false; } } if (count > north && complete == true) { - return null; - } - + return null; + } + max = 0; - count = 0; - complete = true; + count = 0; + complete = true; for (int i = skyscrapersboard.getHeight() - 1; i >= 0; i--) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); - max = c.getData(); + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (c.getType() == SkyscrapersType.Number && c.getData() > max) { + //System.out.print(c.getData()); + //System.out.println(cell.getData()); + max = c.getData(); count = count + 1; } - if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + if (c.getType() == SkyscrapersType.UNKNOWN) { + complete = false; } } if (count > south && complete == true) { - return null; - } - + return null; + } + //System.out.print("Does not contain a contradiction at this index"); return super.getNoContradictionMessage(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java index a3cac5bdd..85b6fe62d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java @@ -17,7 +17,7 @@ public class FixedMaxBasicRule extends BasicRule { public FixedMaxBasicRule() { - super("SKYS-BASC-0001","Fixed Max", + super("SKYS-BASC-0001", "Fixed Max", "If the sum of two opposing edges is n+1, the maximum number appears at a position k spaces away from the edge, where k is the number at that edge.", "edu/rpi/legup/images/skyscrapers/FixedMax.png"); } @@ -33,9 +33,9 @@ public FixedMaxBasicRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; @@ -52,23 +52,23 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem System.out.println(north); System.out.println(south); if (north + south != max + 1 && west + east != max + 1) { - System.out.println("111"); - return super.getInvalidUseOfRuleMessage() + ": Opposing clues must add up to max"; + System.out.println("111"); + return super.getInvalidUseOfRuleMessage() + ": Opposing clues must add up to max"; } - + if (finalCell.getData() != initialBoard.getWidth()) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max"; } - + if (north + south == max + 1 && loc.y + 1 == north) { - return null; + return null; } if (west + east == max + 1 && loc.x + 1 == west) { - return null; + return null; } - + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; - + } private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { @@ -76,7 +76,7 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { emptyCase.getPuzzleElement(cell).setData(0); DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); + System.out.println("no contradiction ln"); return true; } return false; @@ -90,12 +90,12 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { */ @Override public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); - SkyscrapersCell cell = (SkyscrapersCell) element; + System.out.println("123"); + SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); lightUpBoard.addModifiedData(cell); @@ -103,7 +103,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java index d134fd8bf..ef0968710 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java @@ -29,94 +29,94 @@ public InsufficientVisibilityContradictionRule() { */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - + Set candidates = new HashSet(); - + //check row - int west = skyscrapersboard.getRow().get(loc.y).getData(); - int east = skyscrapersboard.getRowClues().get(loc.y).getData(); - int north = skyscrapersboard.getCol().get(loc.x).getData(); - int south = skyscrapersboard.getColClues().get(loc.x).getData(); - int max = 0; - int count = 0; - boolean complete = true; - for (int i = 0; i < skyscrapersboard.getWidth(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + int west = skyscrapersboard.getRow().get(loc.y).getData(); + int east = skyscrapersboard.getRowClues().get(loc.y).getData(); + int north = skyscrapersboard.getCol().get(loc.x).getData(); + int south = skyscrapersboard.getColClues().get(loc.x).getData(); + int max = 0; + int count = 0; + boolean complete = true; + for (int i = 0; i < skyscrapersboard.getWidth(); i++) { + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); max = c.getData(); count++; } if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + complete = false; } } - if (count < west && complete == true) { - return null; - } - - max = 0; - count = 0; - complete = true; - for (int i = skyscrapersboard.getWidth() - 1; i >= 0; i--) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + if (count < west && complete == true) { + return null; + } + + max = 0; + count = 0; + complete = true; + for (int i = skyscrapersboard.getWidth() - 1; i >= 0; i--) { + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); max = c.getData(); count = count + 1; } if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + complete = false; } } - if (count < east && complete == true) { - return null; - } - + if (count < east && complete == true) { + return null; + } + // check column - max = 0; - count = 0; - complete = true; + max = 0; + count = 0; + complete = true; for (int i = 0; i < skyscrapersboard.getHeight(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); - max = c.getData(); + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (c.getType() == SkyscrapersType.Number && c.getData() > max) { + //System.out.print(c.getData()); + //System.out.println(cell.getData()); + max = c.getData(); count = count + 1; } - if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + if (c.getType() == SkyscrapersType.UNKNOWN) { + complete = false; } } if (count < north && complete == true) { - return null; - } - + return null; + } + max = 0; - count = 0; - complete = true; + count = 0; + complete = true; for (int i = skyscrapersboard.getHeight() - 1; i >= 0; i--) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (c.getType() == SkyscrapersType.Number && c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); - max = c.getData(); + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (c.getType() == SkyscrapersType.Number && c.getData() > max) { + //System.out.print(c.getData()); + //System.out.println(cell.getData()); + max = c.getData(); count = count + 1; } - if (c.getType() == SkyscrapersType.UNKNOWN) { - complete = false; + if (c.getType() == SkyscrapersType.UNKNOWN) { + complete = false; } } if (count < south && complete == true) { - return null; - } - + return null; + } + //System.out.print("Does not contain a contradiction at this index"); return super.getNoContradictionMessage(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java index dc37cbe12..524c36319 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java @@ -33,9 +33,9 @@ public LastCellBasicRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; @@ -44,51 +44,51 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard emptyCase = initialBoard.copy(); emptyCase.getPuzzleElement(finalCell).setData(0); Point loc = finalCell.getLocation(); - + Set candidates = new HashSet(); for (int i = 1; i <= initialBoard.getWidth(); i++) { - candidates.add(i); + candidates.add(i); } - + //check row for (int i = 0; i < initialBoard.getWidth(); i++) { - SkyscrapersCell c = initialBoard.getCell(i, loc.y); + SkyscrapersCell c = initialBoard.getCell(i, loc.y); if (i != loc.x && c.getType() == SkyscrapersType.Number) { - candidates.remove(c.getData()); - //System.out.print(c.getData()); - //System.out.println(finalCell.getData()); + candidates.remove(c.getData()); + //System.out.print(c.getData()); + //System.out.println(finalCell.getData()); } } if (candidates.size() == 1) { - Iterator it = candidates.iterator(); - if (it.next() == finalCell.getData()) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; + Iterator it = candidates.iterator(); + if (it.next() == finalCell.getData()) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; } - + candidates.clear(); for (int i = 1; i <= initialBoard.getWidth(); i++) { - candidates.add(i); + candidates.add(i); } - + // check column for (int i = 0; i < initialBoard.getHeight(); i++) { - SkyscrapersCell c = initialBoard.getCell(loc.x, i); - if (i != loc.y && c.getType() == SkyscrapersType.Number) { - candidates.remove(c.getData()); - //System.out.print(c.getData()); - //System.out.println(finalCell.getData()); + SkyscrapersCell c = initialBoard.getCell(loc.x, i); + if (i != loc.y && c.getType() == SkyscrapersType.Number) { + candidates.remove(c.getData()); + //System.out.print(c.getData()); + //System.out.println(finalCell.getData()); } } if (candidates.size() == 1) { - Iterator it = candidates.iterator(); - if (it.next() == finalCell.getData()) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; + Iterator it = candidates.iterator(); + if (it.next() == finalCell.getData()) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; } - + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; } @@ -97,7 +97,7 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { emptyCase.getPuzzleElement(cell).setData(0); DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); + System.out.println("no contradiction ln"); return true; } return false; @@ -111,12 +111,12 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { */ @Override public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); - SkyscrapersCell cell = (SkyscrapersCell) element; + System.out.println("123"); + SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); lightUpBoard.addModifiedData(cell); @@ -124,7 +124,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java index fa9fb31a0..a4f36cd04 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java @@ -33,9 +33,9 @@ public LastNumberBasicRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; @@ -44,41 +44,41 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard emptyCase = initialBoard.copy(); emptyCase.getPuzzleElement(finalCell).setData(0); Point loc = finalCell.getLocation(); - + Set candidates = new HashSet(); for (int i = 1; i <= initialBoard.getWidth(); i++) { - candidates.add(i); + candidates.add(i); } - + //check row for (int i = 0; i < initialBoard.getWidth(); i++) { - SkyscrapersCell c = initialBoard.getCell(i, loc.y); + SkyscrapersCell c = initialBoard.getCell(i, loc.y); if (i != loc.x && c.getType() == SkyscrapersType.Number) { - candidates.remove(c.getData()); - //System.out.print(c.getData()); - //System.out.println(finalCell.getData()); + candidates.remove(c.getData()); + //System.out.print(c.getData()); + //System.out.println(finalCell.getData()); } } - + // check column for (int i = 0; i < initialBoard.getHeight(); i++) { - SkyscrapersCell c = initialBoard.getCell(loc.x, i); - if (i != loc.y && c.getType() == SkyscrapersType.Number) { - candidates.remove(c.getData()); - //System.out.print(c.getData()); - //System.out.println(finalCell.getData()); + SkyscrapersCell c = initialBoard.getCell(loc.x, i); + if (i != loc.y && c.getType() == SkyscrapersType.Number) { + candidates.remove(c.getData()); + //System.out.print(c.getData()); + //System.out.println(finalCell.getData()); } } - + DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); if (candidates.size() == 1 && duplicate.checkContradictionAt(emptyCase, finalCell) != null) { - Iterator it = candidates.iterator(); - if (it.next() == finalCell.getData()) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; + Iterator it = candidates.iterator(); + if (it.next() == finalCell.getData()) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; } - + return super.getInvalidUseOfRuleMessage() + ":This cell is not forced."; } @@ -87,7 +87,7 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { emptyCase.getPuzzleElement(cell).setData(0); DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); + System.out.println("no contradiction ln"); return true; } return false; @@ -101,12 +101,12 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { */ @Override public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); - SkyscrapersCell cell = (SkyscrapersCell) element; + System.out.println("123"); + SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); lightUpBoard.addModifiedData(cell); @@ -114,7 +114,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java index 9344173b1..d5c58220e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java @@ -33,9 +33,9 @@ public NEdgeBasicRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; @@ -45,22 +45,22 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem emptyCase.getPuzzleElement(finalCell).setData(0); Point loc = finalCell.getLocation(); int max = initialBoard.getHeight(); - + if (initialBoard.getRow().get(loc.y).getData() == max && finalCell.getData() == loc.x + 1) { - return null; + return null; } if (initialBoard.getRowClues().get(loc.y).getData() == max && finalCell.getData() == max - loc.x) { - return null; + return null; } if (initialBoard.getCol().get(loc.x).getData() == max && finalCell.getData() == loc.y + 1) { - return null; + return null; } if (initialBoard.getColClues().get(loc.x).getData() == max && finalCell.getData() == max - loc.y) { - return null; + return null; } - + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; - + } private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { @@ -68,7 +68,7 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { emptyCase.getPuzzleElement(cell).setData(0); DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); + System.out.println("no contradiction ln"); return true; } return false; @@ -82,12 +82,12 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { */ @Override public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); - SkyscrapersCell cell = (SkyscrapersCell) element; + System.out.println("123"); + SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); lightUpBoard.addModifiedData(cell); @@ -95,7 +95,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java index 559817ae1..f883d7cee 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java @@ -33,9 +33,9 @@ public OneEdgeBasicRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; @@ -44,30 +44,37 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard emptyCase = initialBoard.copy(); emptyCase.getPuzzleElement(finalCell).setData(0); Point loc = finalCell.getLocation(); - + if (loc.x != 0 && loc.x != initialBoard.getWidth() - 1 && loc.y != 0 && loc.y != initialBoard.getHeight() - 1) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be on the edge"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be on the edge"; } - + if (finalCell.getData() != initialBoard.getWidth()) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max"; } - + if (loc.x == 0 && initialBoard.getRow().get(loc.y).getData() == 1) { - return null; - } - else if (loc.x == initialBoard.getWidth() - 1 && initialBoard.getRowClues().get(loc.y).getData() == 1) { - return null; - } - else if (loc.y == 0 && initialBoard.getCol().get(loc.x).getData() == 1) { - return null; + return null; } - else if (loc.y == initialBoard.getHeight() - 1 && initialBoard.getColClues().get(loc.x).getData() == 1) { - return null; - } else { - return "This cell is not forced."; + else { + if (loc.x == initialBoard.getWidth() - 1 && initialBoard.getRowClues().get(loc.y).getData() == 1) { + return null; + } + else { + if (loc.y == 0 && initialBoard.getCol().get(loc.x).getData() == 1) { + return null; + } + else { + if (loc.y == initialBoard.getHeight() - 1 && initialBoard.getColClues().get(loc.x).getData() == 1) { + return null; + } + else { + return "This cell is not forced."; + } + } + } } - + } private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { @@ -75,7 +82,7 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { emptyCase.getPuzzleElement(cell).setData(0); DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); + System.out.println("no contradiction ln"); return true; } return false; @@ -89,12 +96,12 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { */ @Override public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); - SkyscrapersCell cell = (SkyscrapersCell) element; + System.out.println("123"); + SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); lightUpBoard.addModifiedData(cell); @@ -102,7 +109,8 @@ public Board getDefaultBoard(TreeNode node) { } if (lightUpBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return lightUpBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java index d1ae8a8cd..eb106ec05 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java @@ -24,7 +24,7 @@ public PossibleContentsCaseRule() { @Override public CaseBoard getCaseBoard(Board board) { - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) board.copy(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) board.copy(); lightUpBoard.setModifiable(false); CaseBoard caseBoard = new CaseBoard(lightUpBoard, this); for (PuzzleElement data : lightUpBoard.getPuzzleElements()) { @@ -45,32 +45,32 @@ public CaseBoard getCaseBoard(Board board) { @Override public ArrayList getCases(Board board, PuzzleElement puzzleElement) { ArrayList cases = new ArrayList<>(); - + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - + Set candidates = new HashSet(); for (int i = 1; i <= skyscrapersboard.getWidth(); i++) { - candidates.add(i); + candidates.add(i); } - + for (int i = 0; i < skyscrapersboard.getWidth(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (c.getType() == SkyscrapersType.Number) { candidates.remove(c.getData()); } } for (int i = 0; i < skyscrapersboard.getHeight(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (c.getType() == SkyscrapersType.Number) { + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (c.getType() == SkyscrapersType.Number) { candidates.remove(c.getData()); } } - + Iterator it = candidates.iterator(); while (it.hasNext()) { - Board case1 = board.copy(); + Board case1 = board.copy(); PuzzleElement data = case1.getPuzzleElement(puzzleElement); data.setData(it.next()); case1.addModifiedData(data); @@ -90,28 +90,28 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { List childTransitions = transition.getParents().get(0).getChildren(); if (childTransitions.size() == 0) { - //System.out.println("0"); + //System.out.println("0"); return "This case rule must have at least one child."; } - - + + //TreeTransition case1 = childTransitions.get(0); //TreeTransition case2 = childTransitions.get(1); TreeTransition case1 = childTransitions.get(0); SkyscrapersCell mod1 = (SkyscrapersCell) case1.getBoard().getModifiedData().iterator().next(); for (int i = 0; i < childTransitions.size(); i++) { - TreeTransition case2 = childTransitions.get(i); - if (case2.getBoard().getModifiedData().size() != 1) { - //System.out.println("1"); + TreeTransition case2 = childTransitions.get(i); + if (case2.getBoard().getModifiedData().size() != 1) { + //System.out.println("1"); return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case."; } - SkyscrapersCell mod2 = (SkyscrapersCell) case2.getBoard().getModifiedData().iterator().next(); + SkyscrapersCell mod2 = (SkyscrapersCell) case2.getBoard().getModifiedData().iterator().next(); if (!mod1.getLocation().equals(mod2.getLocation())) { - //System.out.println("2"); + //System.out.println("2"); return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case."; } if (!(mod2.getType() == SkyscrapersType.Number)) { - //System.out.println("3"); + //System.out.println("3"); return super.getInvalidUseOfRuleMessage() + ": This case rule must assign a number."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md index d2c6e4bd1..9ff730666 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md @@ -1,16 +1,16 @@ ## TODO - 1. Basic Rules: - - Last Cell - - Last Number - - 1-Edge - - N-Edge - - Fixed Max - 2. Contradiction Rules: - - Duplicate Number - - Unresolved Cell - - Exceeding Visibility - - Insufficient Visibility - 3. Case Rules: - - Possible Contents - - Possible Places +1. Basic Rules: + - Last Cell + - Last Number + - 1-Edge + - N-Edge + - Fixed Max +2. Contradiction Rules: + - Duplicate Number + - Unresolved Cell + - Exceeding Visibility + - Insufficient Visibility +3. Case Rules: + - Possible Contents + - Possible Places diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java index f667fc0e7..98ed7e96d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java @@ -29,35 +29,35 @@ public UnresolvedCellContradictionRule() { */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - + Set candidates = new HashSet(); - + //check row for (int i = 0; i < skyscrapersboard.getWidth(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); + SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (i != loc.x && cell.getType() == SkyscrapersType.UNKNOWN && c.getType() == SkyscrapersType.Number) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); candidates.add(c.getData()); } } - + // check column for (int i = 0; i < skyscrapersboard.getHeight(); i++) { - SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (i != loc.y && cell.getType() == SkyscrapersType.UNKNOWN && c.getType() == SkyscrapersType.Number) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); + if (i != loc.y && cell.getType() == SkyscrapersType.UNKNOWN && c.getType() == SkyscrapersType.Number) { + //System.out.print(c.getData()); + //System.out.println(cell.getData()); candidates.add(c.getData()); } } - + if (candidates.size() == skyscrapersboard.getWidth()) { - System.out.print("violation"); - return null; + System.out.print("violation"); + return null; } //System.out.print("Does not contain a contradiction at this index"); return super.getNoContradictionMessage(); diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java index 228af0b37..8af2aca2e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java @@ -37,16 +37,20 @@ public boolean isPickable(PuzzleElement puzzleElement, MouseEvent e) { return true; } } - } else if (e.isControlDown()) { - for (int c : pickableCols) { - if (c == sudokuCell.getLocation().x) { - return true; + } + else { + if (e.isControlDown()) { + for (int c : pickableCols) { + if (c == sudokuCell.getLocation().x) { + return true; + } } } - } else { - for (int r : pickableRegions) { - if (r == sudokuCell.getGroupIndex()) { - return true; + else { + for (int r : pickableRegions) { + if (r == sudokuCell.getGroupIndex()) { + return true; + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java index f94d2290a..ac082e427 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java @@ -52,23 +52,26 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Sudoku, false otherwise + * @return true if the given dimensions are valid for Sudoku, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // The number of rows and columns must be greater than 1 - if (rows <= 1 || columns <= 1) + if (rows <= 1 || columns <= 1) { return false; + } // The number of rows and columns must be equal - if (rows != columns) + if (rows != columns) { return false; + } // For Sudoku, the number of rows and columns must be a perfect square // Note: we don't need to check the columns since by this point, we have verified that the number of rows // equals the number of columns double sqrtRows = Math.sqrt(rows); - if (sqrtRows - Math.floor(sqrtRows) != 0) + if (sqrtRows - Math.floor(sqrtRows) != 0) { return false; + } return true; } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java index 2ef51cd24..ed3048c88 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java @@ -166,7 +166,7 @@ public SudokuBoard copy() { copy.setCell(x, y, getCell(x, y).copy()); } } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } return copy; diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java index e3d177c34..6e13d70dc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java @@ -33,7 +33,7 @@ public SudokuCell(int value, Point location, int groupIndex, int size) { public int getGroupIndex() { return groupIndex; } - + public int getMax() { return max; } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java index 8c84a1e2e..18b6cd0a8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java @@ -22,18 +22,24 @@ public void changeCell(MouseEvent e, PuzzleElement data) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } else { + } + else { if (cell.getData() < cell.getMax()) { - data.setData(cell.getData()+1); - } else { + data.setData(cell.getData() + 1); + } + else { data.setData(0); } } - } else if (e.getButton() == MouseEvent.BUTTON3) { - if (cell.getData() > 0) { - data.setData(cell.getData()-1); - } else { - data.setData(cell.getMax()); + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + if (cell.getData() > 0) { + data.setData(cell.getData() - 1); + } + else { + data.setData(cell.getMax()); + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java index 669f9a2e8..e9bafa43a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java @@ -44,9 +44,11 @@ public SudokuCell importCell(Node node, Board board) throws InvalidFileFormatExc SudokuCell cell = new SudokuCell(value, new Point(x, y), groupIndex, size); cell.setIndex(y * size + x); return cell; - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Sudoku Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("Sudoku Factory: could not find attribute(s)"); } } @@ -54,8 +56,8 @@ public SudokuCell importCell(Node node, Board board) throws InvalidFileFormatExc /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java index bc114c3c5..46d7e4ec7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java @@ -52,7 +52,8 @@ public void drawElement(Graphics2D graphics2D) { int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(value, xText, yText); - } else { + } + else { boolean annotate = LegupPreferences.getInstance().getUserPref(LegupPreferences.SHOW_ANNOTATIONS).equalsIgnoreCase(Boolean.toString(true)); if (annotate) { graphics2D.setColor(FONT_COLOR); diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java index f94f516ba..dcce56946 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java @@ -16,8 +16,8 @@ public SudokuImporter(Sudoku sudoku) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -70,7 +70,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Sudoku Importer: invalid board dimensions"); } sudokuBoard = new SudokuBoard(size); - } else { + } + else { throw new InvalidFileFormatException("Sudoku Importer: invalid board dimensions"); } @@ -106,7 +107,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { // } puzzle.setCurrentBoard(sudokuBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("Sudoku Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java index e0e099038..bb25c3e21 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java @@ -79,15 +79,18 @@ public void drawBoard(Graphics2D graphics2D) { for (int i = 0; i < gridSize.height; i++) { for (int k = 0; k < gridSize.width; k++) { ElementView element = elementViews.get(i * gridSize.height + k); - if (!element.isHover()) + if (!element.isHover()) { element.draw(graphics2D); - else + } + else { hover = element; + } } } - if (hover != null) + if (hover != null) { hover.draw(graphics2D); + } } public void drawCaseBoard(Graphics2D graphics2D) { @@ -102,10 +105,12 @@ public void drawCaseBoard(Graphics2D graphics2D) { for (int i = 0; i < gridSize.height; i++) { for (int k = 0; k < gridSize.width; k++) { ElementView element = elementViews.get(i * gridSize.height + k); - if (!element.isHover()) + if (!element.isHover()) { element.draw(graphics2D); - else + } + else { hover = element; + } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java index 2e65fac90..658a7386c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java @@ -69,8 +69,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem for (int x = 0; x < groupDim; x++) { if (possible[y][x] && !isForced) { isForced = true; - } else if (possible[y][x]) { - return super.getInvalidUseOfRuleMessage() + ": Not forced"; + } + else { + if (possible[y][x]) { + return super.getInvalidUseOfRuleMessage() + ": Not forced"; + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java index 2a6ed32e9..95ae503cd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java @@ -55,8 +55,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } if (numbers.size() > 1) { return super.getInvalidUseOfRuleMessage() + ": The number at the index is not forced"; - } else if (numbers.size() == 1 && numbers.iterator().next() != finalBoard.getPuzzleElement(puzzleElement).getData()) { - return super.getInvalidUseOfRuleMessage() + ": The number at the index is forced but not correct"; + } + else { + if (numbers.size() == 1 && numbers.iterator().next() != finalBoard.getPuzzleElement(puzzleElement).getData()) { + return super.getInvalidUseOfRuleMessage() + ": The number at the index is forced but not correct"; + } } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java index 7a726270e..27d6b58b7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java @@ -89,10 +89,14 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement, int v Set group; if (groupType == GroupType.REGION) { group = sudokuBoard.getRegion(cell.getGroupIndex()); - } else if (groupType == GroupType.ROW) { - group = sudokuBoard.getRow(cell.getLocation().y); - } else { - group = sudokuBoard.getCol(cell.getLocation().x); + } + else { + if (groupType == GroupType.ROW) { + group = sudokuBoard.getRow(cell.getLocation().y); + } + else { + group = sudokuBoard.getCol(cell.getLocation().x); + } } for (SudokuCell c : group) { diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java b/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java index 5722774ef..7ada10a07 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java @@ -52,7 +52,8 @@ public void executeCommand() { if (transition == null) { transition = tree.addNewTransition(treeNode); addTran.put(treeNode, transition); - } else { + } + else { treeNode.addChild(transition); } @@ -61,7 +62,8 @@ public void executeCommand() { newSelection.addToSelection(treeView.getElementView(finalTran)); board = (TreeTentBoard) finalTran.getBoard(); - } else { + } + else { finalTran = (TreeTransition) treeElement; newSelection.addToSelection(treeView.getElementView(treeElement)); } @@ -103,7 +105,8 @@ public String getErrorString() { if (!node.getChildren().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } - } else { + } + else { if (!board.isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } @@ -119,7 +122,8 @@ public String getErrorString() { tempList.add(cell); } } - } else { + } + else { int row = clue.getType() == TreeTentType.CLUE_WEST ? clue.getClueIndex() : clue.getClueIndex() - 1; for (int i = 0; i < board.getWidth(); i++) { TreeTentCell cell = board.getCell(i, row); @@ -159,7 +163,8 @@ public void undoCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(finalTran)); board = (TreeTentBoard) finalTran.getBoard(); - } else { + } + else { finalTran = (TreeTransition) treeElement; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java b/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java index ea03fc6f5..d2f8575f1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java @@ -49,7 +49,8 @@ public void executeCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(transition)); board = (TreeTentBoard) transition.getBoard(); - } else { + } + else { transition = (TreeTransition) treeElement; } @@ -72,7 +73,8 @@ public void executeCommand() { board.getLines().add(line); notifyLine = line; transition.propagateAddition(notifyLine); - } else { + } + else { board.removeModifiedData(dupLine); board.getLines().remove(dupLine); notifyLine = dupLine; @@ -112,7 +114,8 @@ public String getErrorString() { if (!node.getChildren().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } - } else { + } + else { if (!board.isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } @@ -156,7 +159,8 @@ public void undoCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition)); board = (TreeTentBoard) transition.getBoard(); - } else { + } + else { transition = (TreeTransition) treeElement; } @@ -178,7 +182,8 @@ public void undoCommand() { board.addModifiedData(line); board.getLines().add(line); notifyLine = line; - } else { + } + else { board.removeModifiedData(dupLine); board.getLines().remove(dupLine); notifyLine = dupLine; @@ -204,18 +209,25 @@ private TreeTentElementView getViewInDirection(ElementView endDrag) { //up xIndex = startLoc.x / size.width; yIndex = (startLoc.y / size.height) - 1; - } else if (radians >= -Math.PI / 4 && radians < Math.PI / 4) { - //right - xIndex = (startLoc.x / size.width) + 1; - yIndex = startLoc.y / size.height; - } else if (radians >= -3 * Math.PI / 4 && radians < -Math.PI / 4) { - //down - xIndex = startLoc.x / size.width; - yIndex = (startLoc.y / size.height) + 1; - } else { - //left - xIndex = (startLoc.x / size.width) - 1; - yIndex = startLoc.y / size.height; + } + else { + if (radians >= -Math.PI / 4 && radians < Math.PI / 4) { + //right + xIndex = (startLoc.x / size.width) + 1; + yIndex = startLoc.y / size.height; + } + else { + if (radians >= -3 * Math.PI / 4 && radians < -Math.PI / 4) { + //down + xIndex = startLoc.x / size.width; + yIndex = (startLoc.y / size.height) + 1; + } + else { + //left + xIndex = (startLoc.x / size.width) - 1; + yIndex = startLoc.y / size.height; + } + } } return (TreeTentElementView) boardView.getElement(xIndex - 1, yIndex - 1); } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java index cf5fd5fdf..0dbd1e6ed 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java @@ -42,7 +42,7 @@ public Board generatePuzzle(int difficulty) { * * @param rows the number of rows * @param columns the number of columns - * @return true if the given dimensions are valid for Tree Tent, false otherwise + * @return true if the given dimensions are valid for Tree Tent, false otherwise */ public boolean isValidDimensions(int rows, int columns) { // This is a placeholder, this method needs to be implemented diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java index 73bc9293b..467b36827 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java @@ -79,7 +79,7 @@ public PuzzleElement getPuzzleElement(PuzzleElement element) { */ @Override public void notifyAddition(PuzzleElement puzzleElement) { - if(puzzleElement instanceof TreeTentLine) { + if (puzzleElement instanceof TreeTentLine) { lines.add((TreeTentLine) puzzleElement); } } @@ -91,9 +91,9 @@ public void notifyAddition(PuzzleElement puzzleElement) { */ @Override public void notifyDeletion(PuzzleElement puzzleElement) { - if(puzzleElement instanceof TreeTentLine) { - for(TreeTentLine line : lines) { - if(line.compare((TreeTentLine)puzzleElement)) { + if (puzzleElement instanceof TreeTentLine) { + for (TreeTentLine line : lines) { + if (line.compare((TreeTentLine) puzzleElement)) { lines.remove(line); break; } @@ -104,10 +104,10 @@ public void notifyDeletion(PuzzleElement puzzleElement) { /** * Get a list of all orthogonally adjacent cells. * - * @param cell The cell to get adjacent cells from. - * @param type The cell types to get. - * @return List of adjacent cells in the form { up, right, down, left }. - * If an adjacent cell is null, it will not be added to the list. + * @param cell The cell to get adjacent cells from. + * @param type The cell types to get. + * @return List of adjacent cells in the form { up, right, down, left }. + * If an adjacent cell is null, it will not be added to the list. */ public List getAdjacent(TreeTentCell cell, TreeTentType type) { List adj = new ArrayList<>(); @@ -162,7 +162,8 @@ public List getRowCol(int index, TreeTentType type, boolean isRow) list.add(cell); } } - } else { + } + else { for (int i = 0; i < dimension.width; i++) { TreeTentCell cell = getCell(index, i); if (cell.getType() == type) { @@ -209,7 +210,7 @@ public TreeTentBoard copy() { lineCpy.setModifiable(false); copy.getLines().add(lineCpy); } - for(PuzzleElement e : modifiedData) { + for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } copy.rowClues = rowClues; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java index ba9dca86b..9543c89dc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java @@ -41,24 +41,30 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat TreeTentCell cell = new TreeTentCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } else if (node.getNodeName().equalsIgnoreCase("line")) { - int x1 = Integer.valueOf(attributeList.getNamedItem("x1").getNodeValue()); - int y1 = Integer.valueOf(attributeList.getNamedItem("y1").getNodeValue()); - int x2 = Integer.valueOf(attributeList.getNamedItem("x2").getNodeValue()); - int y2 = Integer.valueOf(attributeList.getNamedItem("y2").getNodeValue()); - if (x1 >= width || y1 >= height || x2 >= width || y2 >= height) { - throw new InvalidFileFormatException("TreeTent Factory: line location out of bounds"); - } + } + else { + if (node.getNodeName().equalsIgnoreCase("line")) { + int x1 = Integer.valueOf(attributeList.getNamedItem("x1").getNodeValue()); + int y1 = Integer.valueOf(attributeList.getNamedItem("y1").getNodeValue()); + int x2 = Integer.valueOf(attributeList.getNamedItem("x2").getNodeValue()); + int y2 = Integer.valueOf(attributeList.getNamedItem("y2").getNodeValue()); + if (x1 >= width || y1 >= height || x2 >= width || y2 >= height) { + throw new InvalidFileFormatException("TreeTent Factory: line location out of bounds"); + } - TreeTentCell c1 = treeTentBoard.getCell(x1, y1); - TreeTentCell c2 = treeTentBoard.getCell(x2, y2); - return new TreeTentLine(c1, c2); - } else { - throw new InvalidFileFormatException("TreeTent Factory: unknown puzzleElement puzzleElement"); + TreeTentCell c1 = treeTentBoard.getCell(x1, y1); + TreeTentCell c2 = treeTentBoard.getCell(x2, y2); + return new TreeTentLine(c1, c2); + } + else { + throw new InvalidFileFormatException("TreeTent Factory: unknown puzzleElement puzzleElement"); + } } - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("TreeTent Factory: unknown value where integer expected"); - } catch (NullPointerException e) { + } + catch (NullPointerException e) { throw new InvalidFileFormatException("TreeTent Factory: could not find attribute(s)"); } } @@ -66,8 +72,8 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document - * @param puzzleElement PuzzleElement cell + * @param document xml document + * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { @@ -82,7 +88,8 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle cellElement.setAttribute("y", String.valueOf(loc.y)); return cellElement; - } else { + } + else { org.w3c.dom.Element lineElement = document.createElement("line"); TreeTentLine line = (TreeTentLine) puzzleElement; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java index 1440ced35..603e118b7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java @@ -56,10 +56,12 @@ public void mouseReleased(MouseEvent e) { autoCaseRuleCommand.execute(); getInstance().getHistory().pushChange(autoCaseRuleCommand); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(autoCaseRuleCommand.getError()); } - } else { + } + else { if (dragStart == lastCellPressed) { if (dragStart.getPuzzleElement().getIndex() >= 0) { ICommand edit = new EditDataCommand(lastCellPressed, selection, e); @@ -67,27 +69,34 @@ public void mouseReleased(MouseEvent e) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(edit.getError()); } - } else { + } + else { ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart); if (edit.canExecute()) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } else { + } + else { treePanel.updateError(edit.getError()); } } - } else if (lastCellPressed != null) { - if (dragStart instanceof TreeTentElementView) { - ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed); - if (editLine.canExecute()) { - editLine.execute(); - getInstance().getHistory().pushChange(editLine); - } else { - treePanel.updateError(editLine.getError()); + } + else { + if (lastCellPressed != null) { + if (dragStart instanceof TreeTentElementView) { + ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed); + if (editLine.canExecute()) { + editLine.execute(); + getInstance().getHistory().pushChange(editLine); + } + else { + treePanel.updateError(editLine.getError()); + } } } } @@ -104,18 +113,29 @@ public void changeCell(MouseEvent e, PuzzleElement element) { if (e.getButton() == MouseEvent.BUTTON1) { if (cell.getData() == 0) { element.setData(2); - } else if (cell.getData() == 2) { - element.setData(3); - } else { - element.setData(0); } - } else if (e.getButton() == MouseEvent.BUTTON3) { - if (cell.getData() == 0) { - element.setData(3); - } else if (cell.getData() == 2) { - element.setData(0); - } else { - element.setData(2); + else { + if (cell.getData() == 2) { + element.setData(3); + } + else { + element.setData(0); + } + } + } + else { + if (e.getButton() == MouseEvent.BUTTON3) { + if (cell.getData() == 0) { + element.setData(3); + } + else { + if (cell.getData() == 2) { + element.setData(0); + } + else { + element.setData(2); + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java index 91d2c29b1..ee1c1549e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java @@ -21,18 +21,27 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.fill(new Rectangle2D.Double(location.x + 0.5f, location.y + 0.5f, size.width - 1, size.height - 1)); graphics2D.setColor(Color.BLACK); graphics2D.draw(new Rectangle2D.Double(location.x + 0.5f, location.y + 0.5f, size.width - 1, size.height - 1)); - } else if (type == TreeTentType.TREE) { - graphics2D.drawImage(TreeTentView.TREE, location.x, location.y, size.width, size.height, null, null); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == TreeTentType.GRASS) { - graphics2D.drawImage(TreeTentView.GRASS, location.x, location.y, size.width, size.height, null, null); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); - } else if (type == TreeTentType.TENT) { - graphics2D.drawImage(TreeTentView.TENT, location.x, location.y, size.width, size.height, null, null); - graphics2D.setColor(Color.BLACK); - graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == TreeTentType.TREE) { + graphics2D.drawImage(TreeTentView.TREE, location.x, location.y, size.width, size.height, null, null); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == TreeTentType.GRASS) { + graphics2D.drawImage(TreeTentView.GRASS, location.x, location.y, size.width, size.height, null, null); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + else { + if (type == TreeTentType.TENT) { + graphics2D.drawImage(TreeTentView.TENT, location.x, location.y, size.width, size.height, null, null); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + } + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java index 68b8fdf70..0096fb448 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java @@ -16,8 +16,8 @@ public TreeTentImporter(TreeTent treeTent) { /** * Creates an empty board for building * - * @param rows the number of rows on the board - * @param columns the number of columns on the board + * @param rows the number of rows on the board + * @param columns the number of columns on the board * @throws RuntimeException */ @Override @@ -48,10 +48,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); treeTentBoard = new TreeTentBoard(size); - } else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); - treeTentBoard = new TreeTentBoard(width, height); + } + else { + if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); + treeTentBoard = new TreeTentBoard(width, height); + } } if (treeTentBoard == null) { @@ -145,7 +148,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } puzzle.setCurrentBoard(treeTentBoard); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) { throw new InvalidFileFormatException("TreeTent Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java index 5a2127fc7..293fbfeef 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java @@ -6,6 +6,8 @@ import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.imageio.ImageIO; import java.awt.*; @@ -13,6 +15,8 @@ import java.util.ArrayList; public class TreeTentView extends GridBoardView { + private final static Logger LOGGER = LogManager.getLogger(TreeTentView.class.getName()); + static Image TREE, GRASS, TENT; static { @@ -20,8 +24,9 @@ public class TreeTentView extends GridBoardView { TREE = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/tree.png")); GRASS = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/grass.png")); TENT = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/tent.png")); - } catch (IOException e) { - + } + catch (IOException e) { + LOGGER.error("Failed to open TreeTent images"); } } @@ -162,7 +167,8 @@ public void onTreeElementChanged(TreeElement treeElement) { TreeTentBoard treeTentBoard; if (board instanceof CaseBoard) { treeTentBoard = (TreeTentBoard) ((CaseBoard) board).getBaseBoard(); - } else { + } + else { treeTentBoard = (TreeTentBoard) board; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java index acf85c74b..07c1e9ead 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java @@ -43,7 +43,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced(finalBoard, finalCell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty."; } } @@ -71,7 +72,8 @@ public Board getDefaultBoard(TreeNode node) { } if (treeTentBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return treeTentBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java index edf4a657c..0d052a956 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java @@ -52,13 +52,14 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { List group; int tentsLeft; TreeTentClue clue = ((TreeTentClue) puzzleElement); - int clueIndex = clue.getClueIndex()-1; - TreeTentBoard tBoard = (TreeTentBoard)board; - if(clue.getType() == TreeTentType.CLUE_SOUTH) { + int clueIndex = clue.getClueIndex() - 1; + TreeTentBoard tBoard = (TreeTentBoard) board; + if (clue.getType() == TreeTentType.CLUE_SOUTH) { group = tBoard.getRowCol(clueIndex, TreeTentType.UNKNOWN, false); tentsLeft = tBoard.getRowClues().get(clueIndex).getData() - tBoard.getRowCol(clueIndex, TreeTentType.TENT, false).size(); cases = genCombinations(tBoard, group, tentsLeft, clueIndex, false); - } else { + } + else { group = tBoard.getRowCol(clueIndex, TreeTentType.UNKNOWN, true); tentsLeft = tBoard.getRowClues().get(clueIndex).getData() - tBoard.getRowCol(clueIndex, TreeTentType.TENT, true).size(); cases = genCombinations(tBoard, group, tentsLeft, clueIndex, true); @@ -67,69 +68,64 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { //generate every combination (nCr) //call goodBoard for each generated combination //alternitive would be to implement collision avoidance while generating instead of after - if(cases.size() > 0) {return cases;} + if (cases.size() > 0) { + return cases; + } return null; } - private ArrayList genCombinations(TreeTentBoard iBoard, List tiles, int target, Integer index, boolean isRow) - { + private ArrayList genCombinations(TreeTentBoard iBoard, List tiles, int target, Integer index, boolean isRow) { return genCombRecursive(iBoard, tiles, tiles, target, 0, new ArrayList(), index, isRow); } - private ArrayList genCombRecursive(TreeTentBoard iBoard, List original, List tiles, int target, int current, List selected, Integer index, boolean isRow) - { + private ArrayList genCombRecursive(TreeTentBoard iBoard, List original, List tiles, int target, int current, List selected, Integer index, boolean isRow) { ArrayList b = new ArrayList<>(); - if(target == current) - { + if (target == current) { TreeTentBoard temp = iBoard.copy(); - for(TreeTentCell c : original) - { - if(selected.contains(c)) - { + for (TreeTentCell c : original) { + if (selected.contains(c)) { PuzzleElement change = temp.getPuzzleElement(c); change.setData(TreeTentType.TENT.value); temp.addModifiedData(change); } - else - { + else { PuzzleElement change = temp.getPuzzleElement(c); change.setData(TreeTentType.GRASS.value); temp.addModifiedData(change); } - + + } + if (goodBoard(temp, index, isRow)) { + b.add(temp); } - if(goodBoard(temp, index, isRow)) {b.add(temp);} return b; } - for(int i = 0; i < tiles.size(); ++i) - { - List sub = tiles.subList(i+1, tiles.size()); + for (int i = 0; i < tiles.size(); ++i) { + List sub = tiles.subList(i + 1, tiles.size()); List next = new ArrayList(selected); next.add(tiles.get(i)); - b.addAll(genCombRecursive(iBoard, original, sub, target, current+1, next, index, isRow)); + b.addAll(genCombRecursive(iBoard, original, sub, target, current + 1, next, index, isRow)); } return b; } //Effectively runs TouchingTents check on all the added tents to make sure that the proposed board is valid. //Could check more or less in the future depending on how "smart" this case rule should be. - private boolean goodBoard(TreeTentBoard board, Integer index, boolean isRow) - { + private boolean goodBoard(TreeTentBoard board, Integer index, boolean isRow) { List tents; - if(isRow) - { + if (isRow) { tents = board.getRowCol(index, TreeTentType.TENT, true); } - else - { + else { tents = board.getRowCol(index, TreeTentType.TENT, false); } - for(TreeTentCell t : tents) - { + for (TreeTentCell t : tents) { List adj = board.getAdjacent(t, TreeTentType.TENT); List diag = board.getDiagonals(t, TreeTentType.TENT); - if(adj.size() > 0 || diag.size() > 0) {return false;} + if (adj.size() > 0 || diag.size() > 0) { + return false; + } } return true; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java index 967e75791..745a14c5e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java @@ -45,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced(initialBoard, initCell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be grass."; } } @@ -77,7 +78,8 @@ public Board getDefaultBoard(TreeNode node) { } if (treeTentBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return treeTentBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java index d797a388f..0937b5edc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java @@ -45,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced(initialBoard, initCell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } @@ -79,7 +80,8 @@ public Board getDefaultBoard(TreeNode node) { } if (treeTentBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return treeTentBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java index 836129e17..cd782a7e7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java @@ -45,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced(finalBoard, finalCell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } @@ -55,19 +56,19 @@ private boolean isForced(TreeTentBoard board, TreeTentCell cell) { for (TreeTentCell c : adjTrees) { List unkAroundTree = board.getAdjacent(c, TreeTentType.UNKNOWN); List tntAroundTree = board.getAdjacent(c, TreeTentType.TENT); - if(unkAroundTree.size() == 0) - { - if(tntAroundTree.size() == 1) - { + if (unkAroundTree.size() == 0) { + if (tntAroundTree.size() == 1) { return true; } - else - { - for(TreeTentCell t : tntAroundTree) - { - if(t == cell) {continue;} + else { + for (TreeTentCell t : tntAroundTree) { + if (t == cell) { + continue; + } List treesAroundTents = board.getAdjacent(t, TreeTentType.TREE); - if(treesAroundTents.size() == 1) {return false;} + if (treesAroundTents.size() == 1) { + return false; + } } return true; } @@ -94,7 +95,8 @@ public Board getDefaultBoard(TreeNode node) { } if (treeTentBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return treeTentBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java index 92b567531..f2290b9fd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java @@ -24,8 +24,10 @@ public CaseBoard getCaseBoard(Board board) { TreeTentBoard treeTentBoard = (TreeTentBoard) board.copy(); treeTentBoard.setModifiable(false); CaseBoard caseBoard = new CaseBoard(treeTentBoard, this); - for(PuzzleElement element : treeTentBoard.getPuzzleElements()) { - if(((TreeTentCell) element).getType() == TreeTentType.TENT) {caseBoard.addPickableElement(element);} + for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { + if (((TreeTentCell) element).getType() == TreeTentType.TENT) { + caseBoard.addPickableElement(element); + } } return caseBoard; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java index a27966da0..b612c2292 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java @@ -38,28 +38,26 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int adjUnknown = treeTentBoard.getAdjacent(cell, TreeTentType.UNKNOWN).size(); if (adjTent == 0 && adjUnknown == 0) { return null; - } else { - if(adjTent != 0) - { + } + else { + if (adjTent != 0) { List lines = treeTentBoard.getLines(); List adjTents = treeTentBoard.getAdjacent(cell, TreeTentType.TENT); - for(TreeTentLine l : lines) - { + for (TreeTentLine l : lines) { Iterator i = adjTents.iterator(); - while(i.hasNext()) - { + while (i.hasNext()) { TreeTentCell t = i.next(); - if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) - { + if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } - if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) - { + if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } } } - if(adjTents.size() == 0) {return null;} + if (adjTents.size() == 0) { + return null; + } } return super.getNoContradictionMessage(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java index 335017c98..67f023dd7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java @@ -36,18 +36,14 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } List adjTrees = treeTentBoard.getAdjacent(cell, TreeTentType.TREE); List lines = treeTentBoard.getLines(); - for(TreeTentLine l : lines) - { + for (TreeTentLine l : lines) { Iterator i = adjTrees.iterator(); - while(i.hasNext()) - { + while (i.hasNext()) { TreeTentCell t = i.next(); - if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) - { + if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } - if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) - { + if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } } @@ -55,7 +51,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int adjTree = adjTrees.size(); if (adjTree == 0) { return null; - } else { + } + else { return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java index 73afd0b85..806724038 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java @@ -44,7 +44,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced(initialBoard, initCell)) { return null; - } else { + } + else { return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } @@ -73,7 +74,8 @@ public Board getDefaultBoard(TreeNode node) { } if (treeTentBoard.getModifiedData().isEmpty()) { return null; - } else { + } + else { return treeTentBoard; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java index e50ca4f88..0f1c7d607 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java @@ -9,6 +9,7 @@ import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.TreeTentType; + import java.util.ArrayList; import java.util.List; @@ -35,66 +36,79 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (!(puzzleElement instanceof TreeTentLine)) { return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; } - TreeTentBoard board = (TreeTentBoard)transition.getBoard(); - TreeTentLine line = (TreeTentLine)board.getPuzzleElement(puzzleElement); - TreeTentCell tree,tent; + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + TreeTentLine line = (TreeTentLine) board.getPuzzleElement(puzzleElement); + TreeTentCell tree, tent; if (line.getC1().getType() == TreeTentType.TREE && line.getC2().getType() == TreeTentType.TENT) { tree = line.getC1(); tent = line.getC2(); - } else if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { - tree = line.getC2(); - tent = line.getC1(); - } else { - return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; + } + else { + if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { + tree = line.getC2(); + tent = line.getC1(); + } + else { + return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; + } } int forced = isForced(board, tree, tent, line); - if(forced == 1) - { + if (forced == 1) { return null; } - else if (forced == -1) - { - return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; - } - else if (forced == -2) - { - return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; - } - else - { - return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; + else { + if (forced == -1) { + return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; + } + else { + if (forced == -2) { + return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; + } + else { + return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; + } + } } } - private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) - { + private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { List adjTents = board.getAdjacent(tree, TreeTentType.TENT); adjTents.remove(tent); List lines = board.getLines(); lines.remove(line); - for(TreeTentLine l : lines) - { + for (TreeTentLine l : lines) { ArrayList toRemove = new ArrayList<>(); - if(l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) {return -2;} - for(TreeTentCell c : adjTents) - { - if(l.getC1().getLocation().equals(c.getLocation())) - { - if(l.getC2().getLocation().equals(tree.getLocation())) {return -1;} - toRemove.add(c); - - } - else if(l.getC2().getLocation().equals(c.getLocation())) - { - if(l.getC1().getLocation().equals(tree.getLocation())) {return -1;} - toRemove.add(c); - } + if (l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) { + return -2; + } + for (TreeTentCell c : adjTents) { + if (l.getC1().getLocation().equals(c.getLocation())) { + if (l.getC2().getLocation().equals(tree.getLocation())) { + return -1; + } + toRemove.add(c); + + } + else { + if (l.getC2().getLocation().equals(c.getLocation())) { + if (l.getC1().getLocation().equals(tree.getLocation())) { + return -1; + } + toRemove.add(c); + } + } + } + for (TreeTentCell c : toRemove) { + adjTents.remove(c); } - for(TreeTentCell c : toRemove) {adjTents.remove(c);} toRemove.clear(); } - if(adjTents.size() == 0) {return 1;} - else {return 0;} + if (adjTents.size() == 0) { + return 1; + } + else { + return 0; + } } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java index 9f4efd419..92b951feb 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java @@ -39,7 +39,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { if (rowTents + rowUnknowns < treeTentBoard.getRowClues().get(loc.y).getData() || colTents + colUnknowns < treeTentBoard.getColClues().get(loc.x).getData()) { return null; - } else { + } + else { return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java index 0b9743934..8bc908d0c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java @@ -37,7 +37,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { if (rowTents > treeTentBoard.getRowClues().get(loc.y).getData() || colTents > treeTentBoard.getColClues().get(loc.x).getData()) { return null; - } else { + } + else { return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java index 1760e3490..a07153a31 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java @@ -21,9 +21,9 @@ public TouchingTentsContradictionRule() { * * @param board board to check contradiction * @param puzzleElement equivalent {@link PuzzleElement} - * @return null if the transition contains a - * contradiction at the specified puzzleElement, - * otherwise error message. + * @return null if the transition contains a + * contradiction at the specified puzzleElement, + * otherwise error message. */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -36,7 +36,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int diagTree = treeTentBoard.getDiagonals(cell, TreeTentType.TENT).size(); if (adjTree > 0 || diagTree > 0) { return null; - } else { + } + else { return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java index 6492d60e6..2d8690c58 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.ArrayList; + import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.BasicRule; @@ -33,66 +34,79 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (!(puzzleElement instanceof TreeTentLine)) { return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; } - TreeTentBoard board = (TreeTentBoard)transition.getBoard(); - TreeTentLine line = (TreeTentLine)board.getPuzzleElement(puzzleElement); - TreeTentCell tree,tent; + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + TreeTentLine line = (TreeTentLine) board.getPuzzleElement(puzzleElement); + TreeTentCell tree, tent; if (line.getC1().getType() == TreeTentType.TREE && line.getC2().getType() == TreeTentType.TENT) { tree = line.getC1(); tent = line.getC2(); - } else if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { - tree = line.getC2(); - tent = line.getC1(); - } else { - return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; + } + else { + if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { + tree = line.getC2(); + tent = line.getC1(); + } + else { + return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; + } } int forced = isForced(board, tree, tent, line); - if(forced == 1) - { + if (forced == 1) { return null; } - else if (forced == -1) - { - return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; - } - else if (forced == -2) - { - return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; - } - else - { - return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; + else { + if (forced == -1) { + return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; + } + else { + if (forced == -2) { + return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; + } + else { + return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; + } + } } } - private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) - { + private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { List adjTrees = board.getAdjacent(tent, TreeTentType.TREE); adjTrees.remove(tree); List lines = board.getLines(); lines.remove(line); - for(TreeTentLine l : lines) - { + for (TreeTentLine l : lines) { ArrayList toRemove = new ArrayList<>(); - if(l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) {return -2;} - for(TreeTentCell c : adjTrees) - { - if(l.getC1().getLocation().equals(c.getLocation())) - { - if(l.getC2().getLocation().equals(tent.getLocation())) {return -1;} - toRemove.add(c); - - } - else if(l.getC2().getLocation().equals(c.getLocation())) - { - if(l.getC1().getLocation().equals(tent.getLocation())) {return -1;} - toRemove.add(c); - } + if (l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) { + return -2; + } + for (TreeTentCell c : adjTrees) { + if (l.getC1().getLocation().equals(c.getLocation())) { + if (l.getC2().getLocation().equals(tent.getLocation())) { + return -1; + } + toRemove.add(c); + + } + else { + if (l.getC2().getLocation().equals(c.getLocation())) { + if (l.getC1().getLocation().equals(tent.getLocation())) { + return -1; + } + toRemove.add(c); + } + } + } + for (TreeTentCell c : toRemove) { + adjTrees.remove(c); } - for(TreeTentCell c : toRemove) {adjTrees.remove(c);} toRemove.clear(); } - if(adjTrees.size() == 0) {return 1;} - else {return 0;} + if (adjTrees.size() == 0) { + return 1; + } + else { + return 0; + } } /** diff --git a/src/main/java/edu/rpi/legup/save/ExportFileException.java b/src/main/java/edu/rpi/legup/save/ExportFileException.java index c6960c1f6..46ebac9e0 100644 --- a/src/main/java/edu/rpi/legup/save/ExportFileException.java +++ b/src/main/java/edu/rpi/legup/save/ExportFileException.java @@ -1,10 +1,8 @@ package edu.rpi.legup.save; -public class ExportFileException extends Exception -{ +public class ExportFileException extends Exception { - public ExportFileException(String message) - { + public ExportFileException(String message) { super("Export File Exception: " + message); } diff --git a/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java b/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java index aa80ad0c3..94c229411 100644 --- a/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java +++ b/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java @@ -1,10 +1,8 @@ package edu.rpi.legup.save; -public class InvalidFileFormatException extends Exception -{ +public class InvalidFileFormatException extends Exception { - public InvalidFileFormatException(String message) - { + public InvalidFileFormatException(String message) { super("InvalidFileFormatException: " + message); } diff --git a/src/main/java/edu/rpi/legup/save/SavableBoard.java b/src/main/java/edu/rpi/legup/save/SavableBoard.java index 59d59495c..a7799a15a 100644 --- a/src/main/java/edu/rpi/legup/save/SavableBoard.java +++ b/src/main/java/edu/rpi/legup/save/SavableBoard.java @@ -8,15 +8,13 @@ import java.io.FileInputStream; import java.io.InputStream; -public class SavableBoard -{ +public class SavableBoard { private static final String LEGUP_HEADER = "edu.rpi.legup.Legup"; private String filePath; private InputStream inputStream; - public SavableBoard(String filePath) throws Exception - { + public SavableBoard(String filePath) throws Exception { this.filePath = filePath; this.inputStream = new FileInputStream(filePath); diff --git a/src/main/java/edu/rpi/legup/save/SavableProof.java b/src/main/java/edu/rpi/legup/save/SavableProof.java index 34a397c6e..101e56125 100644 --- a/src/main/java/edu/rpi/legup/save/SavableProof.java +++ b/src/main/java/edu/rpi/legup/save/SavableProof.java @@ -1,6 +1,5 @@ package edu.rpi.legup.save; -public class SavableProof -{ +public class SavableProof { } diff --git a/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java b/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java index 9f6d242fc..7141a4f1a 100644 --- a/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java +++ b/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java @@ -77,23 +77,22 @@ public void initPuzzles() { public void actionPerformed(ActionEvent e) { if (e.getSource() == ok) { String game = (String) gameBox.getSelectedItem(); - try - { + try { this.homePanel.openEditorWithNewPuzzle(game, Integer.valueOf(this.rows.getText()), Integer.valueOf(this.columns.getText())); setVisible(false); } - catch (IllegalArgumentException exception) - { + catch (IllegalArgumentException exception) { // Don't do anything. This is here to prevent the dialog from closing if the dimensions are invalid. } } - else if (e.getSource() == cancel) { - setVisible(false); + else { + if (e.getSource() == cancel) { + setVisible(false); + } } } - private boolean isValidDimensions() - { + private boolean isValidDimensions() { // Needs to be implemented return false; } diff --git a/src/main/java/edu/rpi/legup/ui/DynamicView.java b/src/main/java/edu/rpi/legup/ui/DynamicView.java index 40641c851..97928ea76 100644 --- a/src/main/java/edu/rpi/legup/ui/DynamicView.java +++ b/src/main/java/edu/rpi/legup/ui/DynamicView.java @@ -88,7 +88,7 @@ public void mouseWheelMoved(MouseWheelEvent e) { scrollView.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { - zoomSlider.setValue(scrollView.getZoom() ); + zoomSlider.setValue(scrollView.getZoom()); zoomLabel.setText(zoomSlider.getValue() + "%"); } }); @@ -121,7 +121,8 @@ public void componentResized(ComponentEvent e) { zoomWrapper.setLayout(new BorderLayout()); zoomWrapper.add(status, WEST); zoomWrapper.add(zoomer, EAST); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } return zoomWrapper; @@ -155,13 +156,12 @@ public void resetStatus() { status.setText(""); } - public void reset() - { + public void reset() { // System.out.println("get into the reset"); Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); Board board1 = GameBoardFacade.getInstance().getBoard(); board1.setModifiable(true); - Dimension bi = new Dimension(1200,900); + Dimension bi = new Dimension(1200, 900); this.getScrollView().zoomFit(); // System.out.println("get into the reset"+UIhight+" "+this.getHeight()+" "+this.getWidth()); // this.getScrollView().zoomTo(UIhight); diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 48ccea450..f1773c82f 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -20,39 +20,44 @@ public HomePanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { initButtons(); } - public JMenuBar getMenuBar() - { + public JMenuBar getMenuBar() { this.menuBar = new JMenuBar(); JMenu settings = new JMenu("Settings"); menuBar.add(settings); JMenuItem preferences = new JMenuItem("Preferences"); - preferences.addActionListener(a -> { System.out.println("Preferences clicked"); }); + preferences.addActionListener(a -> { + System.out.println("Preferences clicked"); + }); settings.add(preferences); JMenuItem about = new JMenuItem("About"); - about.addActionListener(a -> { System.out.println("About clicked"); }); + about.addActionListener(a -> { + System.out.println("About clicked"); + }); settings.add(about); JMenuItem help = new JMenuItem("Help"); - about.addActionListener(a -> { System.out.println("Help clicked"); }); + about.addActionListener(a -> { + System.out.println("Help clicked"); + }); settings.add(help); JMenuItem contribute = new JMenuItem("Contribute to Legup"); - contribute.addActionListener(a -> { System.out.println("Contribute to Legup clicked"); }); + contribute.addActionListener(a -> { + System.out.println("Contribute to Legup clicked"); + }); settings.add(contribute); return this.menuBar; } @Override - public void makeVisible() - { + public void makeVisible() { render(); frame.setJMenuBar(this.getMenuBar()); } - private static ImageIcon resizeButtonIcon(ImageIcon icon, int width, int height) - { + private static ImageIcon resizeButtonIcon(ImageIcon icon, int width, int height) { Image image = icon.getImage(); Image resizedImage = image.getScaledInstance(width, height, Image.SCALE_SMOOTH); return new ImageIcon(resizedImage); @@ -61,8 +66,7 @@ private static ImageIcon resizeButtonIcon(ImageIcon icon, int width, int height) private void initButtons() { this.buttons = new JButton[4]; - this.buttons[0] = new JButton("Open Proof") - { + this.buttons[0] = new JButton("Open Proof") { { setSize(buttonSize, buttonSize); setMaximumSize(getSize()); @@ -75,8 +79,7 @@ private void initButtons() { this.buttons[0].setVerticalTextPosition(AbstractButton.BOTTOM); this.buttons[0].addActionListener(l -> this.legupUI.displayPanel(1)); - this.buttons[1] = new JButton("New Puzzle") - { + this.buttons[1] = new JButton("New Puzzle") { { setSize(buttonSize, buttonSize); setMaximumSize(getSize()); @@ -88,8 +91,7 @@ private void initButtons() { this.buttons[1].setVerticalTextPosition(AbstractButton.BOTTOM); this.buttons[1].addActionListener(l -> this.openNewPuzzleDialog()); - this.buttons[2] = new JButton("Edit Puzzle") - { + this.buttons[2] = new JButton("Edit Puzzle") { { setSize(buttonSize, buttonSize); setMaximumSize(getSize()); @@ -101,8 +103,7 @@ private void initButtons() { this.buttons[2].setVerticalTextPosition(AbstractButton.BOTTOM); this.buttons[2].addActionListener(l -> this.legupUI.displayPanel(2)); // PLACEHOLDER - for (int i = 0; i < this.buttons.length - 1; i++) // -1 to avoid the batch grader button - { + for (int i = 0; i < this.buttons.length - 1; i++) { // -1 to avoid the batch grader button //this.buttons[i].setPreferredSize(new Dimension(100, 100)); this.buttons[i].setBounds(200, 200, 700, 700); } @@ -112,10 +113,9 @@ private void initButtons() { this.buttons[3].setVerticalTextPosition(AbstractButton.BOTTOM); } - private void initText() - { + private void initText() { this.text = new JLabel[3]; - + JLabel welcome = new JLabel("Welcome to Legup"); welcome.setFont(new Font("Roboto", Font.BOLD, 23)); welcome.setAlignmentX(Component.CENTER_ALIGNMENT); @@ -127,14 +127,13 @@ private void initText() JLabel credits = new JLabel("A project by Dr. Bram van Heuveln"); credits.setFont(new Font("Roboto", Font.PLAIN, 12)); credits.setAlignmentX(Component.CENTER_ALIGNMENT); - + this.text[0] = welcome; this.text[1] = version; this.text[2] = credits; } - private void render() - { + private void render() { this.removeAll(); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); @@ -154,8 +153,9 @@ private void render() batchGraderButton.setAlignmentX(Component.LEFT_ALIGNMENT); this.add(Box.createRigidArea(new Dimension(0, 5))); - for (int i = 0; i < this.text.length; i++) + for (int i = 0; i < this.text.length; i++) { this.add(this.text[i]); + } this.add(buttons); this.add(batchGraderButton); this.add(Box.createRigidArea(new Dimension(0, 5))); @@ -168,13 +168,11 @@ private void openNewPuzzleDialog() { public void openEditorWithNewPuzzle(String game, int width, int height) throws IllegalArgumentException { // Set game type on the puzzle editor - try - { + try { this.legupUI.displayPanel(2); this.legupUI.getPuzzleEditor().loadPuzzleFromHome(game, width, height); } - catch (IllegalArgumentException exception) - { + catch (IllegalArgumentException exception) { this.legupUI.displayPanel(0); JOptionPane.showMessageDialog(null, "The dimensions you entered are invalid. Please double check \n" + diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 6a32e0001..dc1454e5a 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -32,8 +32,12 @@ public class LegupUI extends JFrame implements WindowListener { */ public static String getOS() { String os = System.getProperty("os.name").toLowerCase(); - if(os.contains("mac")) os = "mac"; - else os = "win"; + if (os.contains("mac")) { + os = "mac"; + } + else { + os = "win"; + } return os; } @@ -46,7 +50,8 @@ public LegupUI() { try { UIManager.setLookAndFeel(new LegupLookAndFeel()); - } catch (UnsupportedLookAndFeelException e) { + } + catch (UnsupportedLookAndFeelException e) { System.err.println("Not supported ui look and feel"); } @@ -107,6 +112,7 @@ protected void displayPanel(int option) { public ProofEditorPanel getProofEditor() { return (ProofEditorPanel) panels[1]; } + public PuzzleEditorPanel getPuzzleEditor() { return (PuzzleEditorPanel) panels[2]; } @@ -146,10 +152,12 @@ public void windowClosing(WindowEvent e) { if (GameBoardFacade.getInstance().getHistory().getIndex() > -1) { if (noquit("Exiting LEGUP?")) { this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - } else { + } + else { this.setDefaultCloseOperation(EXIT_ON_CLOSE); } - } else { + } + else { this.setDefaultCloseOperation(EXIT_ON_CLOSE); } } diff --git a/src/main/java/edu/rpi/legup/ui/PickGameDialog.java b/src/main/java/edu/rpi/legup/ui/PickGameDialog.java index aaac26641..2d978d9c9 100644 --- a/src/main/java/edu/rpi/legup/ui/PickGameDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PickGameDialog.java @@ -75,7 +75,8 @@ public PickGameDialog(JFrame parent, boolean pickBothAtOnce) { if (pickBoth) { gameLabel.setBounds(10, 10, 70, 25); gameBox.setBounds(80, 10, 190, 25); - } else { + } + else { gameLabel.setBounds(10, 30, 70, 25); gameBox.setBounds(80, 30, 190, 25); } @@ -118,8 +119,9 @@ public void initPuzzles() { games = new String[o.length]; - for (int x = 0; x < o.length; ++x) + for (int x = 0; x < o.length; ++x) { games[x] = (String) o[x]; + } puzzles = new String[games.length][]; puzzleBox = new JTextField(); @@ -127,8 +129,9 @@ public void initPuzzles() { // o = GameBoardFacade.getInstance().getConfig().getBoardsForPuzzle(games[x]).toArray(); puzzles[x] = new String[o.length]; - for (int y = 0; y < o.length; ++y) + for (int y = 0; y < o.length; ++y) { puzzles[x][y] = (String) o[y]; + } } gameBox = new JComboBox(games); @@ -145,20 +148,32 @@ public String getGame() { public void actionPerformed(ActionEvent e) { if (e.getSource() == gameBox) { int index = gameBox.getSelectedIndex(); - } else if (e.getSource() == ok) { - okPressed = true; - setVisible(false); - } else if (e.getSource() == cancel) { - okPressed = false; - setVisible(false); - } else if (e.getSource() == puzzleButton) { - File f = new File("puzzlefiles" + File.separator + gameBox.getSelectedItem().toString().toLowerCase() + File.separator); - if (f.exists() && f.isDirectory()) - puzzleChooser = new JFileChooser(f); - else - puzzleChooser = new JFileChooser(); - if (puzzleChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) - puzzleBox.setText(puzzleChooser.getSelectedFile().getAbsolutePath()); + } + else { + if (e.getSource() == ok) { + okPressed = true; + setVisible(false); + } + else { + if (e.getSource() == cancel) { + okPressed = false; + setVisible(false); + } + else { + if (e.getSource() == puzzleButton) { + File f = new File("puzzlefiles" + File.separator + gameBox.getSelectedItem().toString().toLowerCase() + File.separator); + if (f.exists() && f.isDirectory()) { + puzzleChooser = new JFileChooser(f); + } + else { + puzzleChooser = new JFileChooser(); + } + if (puzzleChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + puzzleBox.setText(puzzleChooser.getSelectedFile().getAbsolutePath()); + } + } + } + } } } } diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 78d6cf72d..2bae648b2 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -31,7 +31,8 @@ public class PreferencesDialog extends JDialog { static { try { folderIcon = ImageIO.read(PreferencesDialog.class.getResource("/edu/rpi/legup/imgs/folder.png")); - } catch (IOException e) { + } + catch (IOException e) { LOGGER.log(Level.SEVERE, "Unable to locate icons"); } } @@ -42,7 +43,7 @@ public PreferencesDialog(Frame frame) { setTitle("Preferences"); JPanel mainPanel = new JPanel(); - mainPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); mainPanel.setLayout(new BorderLayout()); mainPanel.add(createGeneralTab()); @@ -257,10 +258,16 @@ public void keyPressed(KeyEvent e) { String combo = ""; if (e.isControlDown()) { combo += "Ctrl + "; - } else if (e.isShiftDown()) { - combo += "Shift + "; - } else if (e.isAltDown()) { - combo += "Alt + "; + } + else { + if (e.isShiftDown()) { + combo += "Shift + "; + } + else { + if (e.isAltDown()) { + combo += "Alt + "; + } + } } if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT) { return; diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 932962f8e..a24ea7309 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -107,7 +107,7 @@ public void makeVisible() { } public JMenuBar getMenuBar() { - if(mBar != null) return mBar; + if (mBar != null) return mBar; mBar = new JMenuBar(); file = new JMenu("File"); @@ -130,26 +130,42 @@ public JMenuBar getMenuBar() { add = new JMenuItem("Add"); add.addActionListener(a -> treePanel.add()); - if(os.equals("mac")) add.setAccelerator(KeyStroke.getKeyStroke('A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else add.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + add.setAccelerator(KeyStroke.getKeyStroke('A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + add.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)); + } proof.add(add); delete = new JMenuItem("Delete"); delete.addActionListener(a -> treePanel.delete()); - if(os.equals("mac")) delete.setAccelerator(KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else delete.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + delete.setAccelerator(KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + delete.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK)); + } proof.add(delete); merge = new JMenuItem("Merge"); merge.addActionListener(a -> treePanel.merge()); - if(os.equals("mac")) merge.setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else merge.setAccelerator(KeyStroke.getKeyStroke('M', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + merge.setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + merge.setAccelerator(KeyStroke.getKeyStroke('M', InputEvent.CTRL_DOWN_MASK)); + } proof.add(merge); collapse = new JMenuItem("Collapse"); collapse.addActionListener(a -> treePanel.collapse()); - if(os.equals("mac")) collapse.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else collapse.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + collapse.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + collapse.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_DOWN_MASK)); + } collapse.setEnabled(false); proof.add(collapse); @@ -184,8 +200,12 @@ public JMenuBar getMenuBar() { mBar.add(file); file.add(newPuzzle); newPuzzle.addActionListener((ActionEvent) -> promptPuzzle()); - if(os.equals("mac")) newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); + } // file.add(genPuzzle); //// genPuzzle.addActionListener((ActionEvent) -> @@ -211,14 +231,22 @@ public JMenuBar getMenuBar() { } } }); - if(os.equals("mac")) resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', InputEvent.CTRL_DOWN_MASK)); + } file.addSeparator(); file.add(saveProof); saveProof.addActionListener((ActionEvent) -> saveProof()); - if(os.equals("mac")) saveProof.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else saveProof.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + saveProof.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + saveProof.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK)); + } file.add(preferences); preferences.addActionListener(a -> { @@ -228,26 +256,34 @@ public JMenuBar getMenuBar() { file.add(exit); exit.addActionListener((ActionEvent) -> this.legupUI.displayPanel(0)); - if(os.equals("mac")) exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK)); + } mBar.add(edit); edit.add(undo); undo.addActionListener((ActionEvent) -> - { - GameBoardFacade.getInstance().getHistory().undo(); - }); - if(os.equals("mac")) undo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else undo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK)); + GameBoardFacade.getInstance().getHistory().undo()); + if (os.equals("mac")) { + undo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + undo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK)); + } edit.add(redo); redo.addActionListener((ActionEvent) -> - { - GameBoardFacade.getInstance().getHistory().redo(); - }); - if(os.equals("mac")) redo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK)); - else redo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); + GameBoardFacade.getInstance().getHistory().redo()); + if (os.equals("mac")) { + redo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK)); + } + else { + redo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); + } mBar.add(proof); @@ -260,7 +296,8 @@ public JMenuBar getMenuBar() { helpLegup.addActionListener(l -> { try { java.awt.Desktop.getDesktop().browse(URI.create("https://github.com/jpoegs/Legup2.0")); - } catch (IOException e) { + } + catch (IOException e) { LOGGER.error("Can't open web page"); } }); @@ -273,8 +310,7 @@ public JMenuBar getMenuBar() { public void promptPuzzle() { GameBoardFacade facade = GameBoardFacade.getInstance(); if (facade.getBoard() != null) { - if (noquit("Opening a new puzzle?")) // !noquit or noquit? - { + if (noquit("Opening a new puzzle?")) { // !noquit or noquit? return; } } @@ -291,7 +327,7 @@ public void promptPuzzle() { String fileName = null; File puzzleFile = folderBrowser.getSelectedFile(); if (folderBrowser.getCurrentDirectory() != null && folderBrowser.getSelectedFile().getName() != null) { - fileName = puzzleFile.getAbsolutePath()+ File.separator; + fileName = puzzleFile.getAbsolutePath() + File.separator; puzzleFile = new File(fileName); } @@ -300,12 +336,15 @@ public void promptPuzzle() { GameBoardFacade.getInstance().loadPuzzle(fileName); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } catch (InvalidFileFormatException e) { + } + catch (InvalidFileFormatException e) { LOGGER.error(e.getMessage()); - if (e.getMessage().contains("Proof Tree construction error: could not find rule by ID")) // TO DO: make error message not hardcoded + if (e.getMessage().contains("Proof Tree construction error: could not find rule by ID")) { // TO DO: make error message not hardcoded JOptionPane.showMessageDialog(null, "This file runs on an outdated version of Legup\nand is not compatible with the current version.", "Error", JOptionPane.ERROR_MESSAGE); - else + } + else { JOptionPane.showMessageDialog(null, "File does not exist or it cannot be read", "Error", JOptionPane.ERROR_MESSAGE); + } } } } @@ -324,7 +363,8 @@ private void saveProof() { String curFileName = GameBoardFacade.getInstance().getCurFileName(); if (curFileName == null) { fileDialog.setDirectory(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); - } else { + } + else { File curFile = new File(curFileName); fileDialog.setDirectory(curFile.getParent()); } @@ -342,7 +382,8 @@ private void saveProof() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } catch (ExportFileException e) { + } + catch (ExportFileException e) { e.printStackTrace(); } } @@ -495,7 +536,8 @@ private void checkProof() { submission.submit(); }*/ JOptionPane.showMessageDialog(null, "Congratulations! Your proof is correct."); - } else { + } + else { String message = "\nThe game board is not solved."; JOptionPane.showMessageDialog(null, message, "Invalid proof.", JOptionPane.ERROR_MESSAGE); } @@ -582,7 +624,8 @@ private void checkProofAll() { String path = folderEntry.getName(); traverseDir(folderEntry, writer, path); } - }catch (IOException ex){ + } + catch (IOException ex) { LOGGER.error(ex.getMessage()); } JOptionPane.showMessageDialog(null, "Batch grading complete."); @@ -597,16 +640,16 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws GameBoardFacade facade = GameBoardFacade.getInstance(); // Folder is empty - if(Objects.requireNonNull(folder.listFiles()).length == 0) { + if (Objects.requireNonNull(folder.listFiles()).length == 0) { writer.append(path).append(",Empty folder,,Ungradeable\n"); return; } // Travese directory, recurse if sub-directory found // If ungradeable, do not leave a score (0, 1) - for(final File f : Objects.requireNonNull(folder.listFiles())) { + for (final File f : Objects.requireNonNull(folder.listFiles())) { // Recurse - if(f.isDirectory()) { + if (f.isDirectory()) { traverseDir(f, writer, path + "/" + f.getName()); continue; } @@ -619,7 +662,7 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws String fName = f.getName(); String fPath = f.getAbsolutePath(); File puzzleFile = new File(fPath); - if(puzzleFile.exists()) { + if (puzzleFile.exists()) { // Try to load file. If invalid, note in csv try { // Load puzzle, run checker @@ -632,14 +675,18 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws // Write data writer.append(fName).append(","); writer.append(puzzle.getName()).append(","); - if (puzzle.isPuzzleComplete()) + if (puzzle.isPuzzleComplete()) { writer.append("1,Solved\n"); - else + } + else { writer.append("0,Unsolved\n"); - } catch (InvalidFileFormatException e) { + } + } + catch (InvalidFileFormatException e) { writer.append(fName).append(",Invalid,,Ungradeable\n"); } - } else { + } + else { LOGGER.debug("Failed to run sim"); } } @@ -702,7 +749,8 @@ public void onRedo(boolean isBottom, boolean isTop) { String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } else { + } + else { String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); @@ -725,7 +773,8 @@ public void onUndo(boolean isBottom, boolean isTop) { File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); if (isBottom) { frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } else { + } + else { frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); } } @@ -747,7 +796,8 @@ private void submit() { Submission submission = new Submission(board); submission.submit(); } - } else { + } + else { JOptionPane.showConfirmDialog(null, "Your proof is incorrect! Are you sure you wish to submit?", "Proof Submission", JOptionPane.YES_NO_OPTION); Submission submit = new Submission(board); } diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index 92dd83df9..1692dc943 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -74,7 +74,7 @@ protected void setupContent() { elementBox.add(boardPanel); this.add(elementBox); - splitPanel.setDividerLocation(splitPanel.getMaximumDividerLocation()+100); + splitPanel.setDividerLocation(splitPanel.getMaximumDividerLocation() + 100); this.splitPanel = splitPanel; revalidate(); } @@ -91,16 +91,22 @@ public void setMenuBar() { // file>new JMenuItem newPuzzle = new JMenuItem("New"); newPuzzle.addActionListener((ActionEvent) -> promptPuzzle()); - if(os.equals("mac")) newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); + if (os.equals("mac")) { + newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } + else { + newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); + } // file>save JMenuItem savePuzzle = new JMenuItem("Save"); JMenuItem exit = new JMenuItem("Exit"); exit.addActionListener((ActionEvent) -> this.legupUI.displayPanel(0)); - if (os.equals("mac")) + if (os.equals("mac")) { exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - else + } + else { exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK)); + } menus[0].add(newPuzzle); menus[0].add(savePuzzle); menus[0].add(exit); @@ -182,24 +188,24 @@ private void setupToolBar() { this.add(toolBar, BorderLayout.NORTH); } + public void loadPuzzleFromHome(String game, int rows, int columns) throws IllegalArgumentException { GameBoardFacade facade = GameBoardFacade.getInstance(); try { facade.loadPuzzle(game, rows, columns); } - catch (IllegalArgumentException exception) - { + catch (IllegalArgumentException exception) { throw new IllegalArgumentException(exception.getMessage()); } - catch (RuntimeException e){ + catch (RuntimeException e) { LOGGER.error(e.getMessage()); } } + public void promptPuzzle() { GameBoardFacade facade = GameBoardFacade.getInstance(); if (facade.getBoard() != null) { - if (noQuit("Opening a new puzzle to edit?")) // !noquit or noquit? - { + if (noQuit("Opening a new puzzle to edit?")) { // !noquit or noquit? return; } } @@ -219,11 +225,13 @@ public void promptPuzzle() { GameBoardFacade.getInstance().loadPuzzle(fileName); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } catch (InvalidFileFormatException e) { + } + catch (InvalidFileFormatException e) { LOGGER.error(e.getMessage()); } } } + public boolean noQuit(String instr) { int n = JOptionPane.showConfirmDialog(null, instr, "Confirm", JOptionPane.YES_NO_CANCEL_OPTION); return n != JOptionPane.YES_OPTION; @@ -252,6 +260,7 @@ public void onClearHistory() { public JButton[] getToolBarButtons() { return toolBarButtons; } + public void setToolBarButtons(JButton[] toolBarButtons) { this.toolBarButtons = toolBarButtons; } diff --git a/src/main/java/edu/rpi/legup/ui/ScrollView.java b/src/main/java/edu/rpi/legup/ui/ScrollView.java index 807d95e06..bc638ee7e 100644 --- a/src/main/java/edu/rpi/legup/ui/ScrollView.java +++ b/src/main/java/edu/rpi/legup/ui/ScrollView.java @@ -15,7 +15,7 @@ public class ScrollView extends JScrollPane { private static final double minScale = 0.25; private static final double maxScale = 4.0; - private static final double[] levels = { 0.25, 1.0 / 3.0, 0.50, 2.0 / 3.0, 1.0, 2.0, 3.0, 4.0 }; + private static final double[] levels = {0.25, 1.0 / 3.0, 0.50, 2.0 / 3.0, 1.0, 2.0, 3.0, 4.0}; private Dimension viewSize; private Dimension zoomSize; @@ -153,7 +153,8 @@ public void zoom(int n, Point point) { updateSize(); updatePosition(point, mag); // zoom out - } else { + } + else { mag = 1 / mag; // check zoom bounds if (scale * mag < minScale) { @@ -193,7 +194,8 @@ public void zoomTo(double newScale) { updateSize(); updatePosition(p, mag); // zoom out - } else { + } + else { updatePosition(p, mag); updateSize(); } @@ -312,11 +314,11 @@ protected void draw(Graphics2D graphics2D) { * @param mag The magnitude for scroll up * positive is scroll up, negative is scroll down, * recommend to use getWheelRotation() as the mag - * */ - public void scroll(int mag){ + */ + public void scroll(int mag) { Point point = super.viewport.getViewPosition(); // the point changing speed changes with the scale - point.y += mag*getZoom()/20; + point.y += mag * getZoom() / 20; viewport.setViewPosition(point); updateSize(); revalidate(); diff --git a/src/main/java/edu/rpi/legup/ui/WrapLayout.java b/src/main/java/edu/rpi/legup/ui/WrapLayout.java index a8058daa9..79771d2a4 100644 --- a/src/main/java/edu/rpi/legup/ui/WrapLayout.java +++ b/src/main/java/edu/rpi/legup/ui/WrapLayout.java @@ -91,8 +91,9 @@ private Dimension layoutSize(Container target, boolean preferred) { int targetWidth = target.getSize().width; - if (targetWidth == 0) + if (targetWidth == 0) { targetWidth = Integer.MAX_VALUE; + } int hgap = getHgap(); int vgap = getVgap(); @@ -154,12 +155,12 @@ private Dimension layoutSize(Container target, boolean preferred) { } /** - * A new row has been completed. Use the dimensions of this row - * to update the preferred dimension for the container. + * A new row has been completed. Use the dimensions of this row + * to update the preferred dimension for the container. * - * @param dim update the width and height when appropriate - * @param rowWidth the width of the row to add - * @param rowHeight the height of the row to add + * @param dim update the width and height when appropriate + * @param rowWidth the width of the row to add + * @param rowHeight the height of the row to add */ private void addRow(Dimension dim, int rowWidth, int rowHeight) { dim.width = Math.max(dim.width, rowWidth); diff --git a/src/main/java/edu/rpi/legup/ui/ZoomWidget.java b/src/main/java/edu/rpi/legup/ui/ZoomWidget.java index dded8ce23..c183df86c 100644 --- a/src/main/java/edu/rpi/legup/ui/ZoomWidget.java +++ b/src/main/java/edu/rpi/legup/ui/ZoomWidget.java @@ -36,24 +36,24 @@ public ZoomWidget(ScrollView parent) { /** * */ - private class PopupSlider extends JPopupMenu implements ChangeListener { - private static final long serialVersionUID = 8225019381200459814L; + private class PopupSlider extends JPopupMenu implements ChangeListener { + private static final long serialVersionUID = 8225019381200459814L; - private JSlider slider; + private JSlider slider; - public PopupSlider() { - slider = new JSlider(SwingConstants.VERTICAL, 0, 400, 200); - slider.setMajorTickSpacing(25); - slider.setPaintTicks(true); + public PopupSlider() { + slider = new JSlider(SwingConstants.VERTICAL, 0, 400, 200); + slider.setMajorTickSpacing(25); + slider.setPaintTicks(true); - add(slider); - slider.addChangeListener(this); - } + add(slider); + slider.addChangeListener(this); + } - public void stateChanged(ChangeEvent e) { - if (slider.getValueIsAdjusting()) { - parent.zoomTo((double) slider.getValue() / 100.0); - } + public void stateChanged(ChangeEvent e) { + if (slider.getValueIsAdjusting()) { + parent.zoomTo((double) slider.getValue() / 100.0); } } + } } diff --git a/src/main/java/edu/rpi/legup/ui/ZoomablePane.java b/src/main/java/edu/rpi/legup/ui/ZoomablePane.java index 6392bb98c..86cfd866f 100644 --- a/src/main/java/edu/rpi/legup/ui/ZoomablePane.java +++ b/src/main/java/edu/rpi/legup/ui/ZoomablePane.java @@ -5,8 +5,7 @@ import java.awt.Graphics2D; import java.awt.AWTEvent; -public class ZoomablePane extends JLayeredPane -{ +public class ZoomablePane extends JLayeredPane { private ScrollView viewer; /** @@ -14,8 +13,7 @@ public class ZoomablePane extends JLayeredPane * * @param viewer dynamic dynamicView */ - public ZoomablePane(ScrollView viewer) - { + public ZoomablePane(ScrollView viewer) { this.viewer = viewer; } @@ -24,9 +22,8 @@ public ZoomablePane(ScrollView viewer) * * @param graphics graphics object used to paint the JComponent */ - public void paint(Graphics graphics) - { - Graphics2D graphics2D = (Graphics2D)graphics; + public void paint(Graphics graphics) { + Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.scale(viewer.getScale(), viewer.getScale()); viewer.draw(graphics2D); } @@ -36,8 +33,7 @@ public void paint(Graphics graphics) * * @param e AWTEvent to process */ - protected void processEvent(AWTEvent e) - { + protected void processEvent(AWTEvent e) { viewer.dispatchEvent(e); super.processEvent(e); } diff --git a/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java b/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java index 92fbb3455..77e6449e4 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java @@ -20,7 +20,6 @@ public abstract class BoardView extends ScrollView implements IBoardListener { protected ElementSelection selection; - /** * BoardView Constructor creates a view for the board object using the controller handle the ui events * @@ -114,7 +113,8 @@ public void setBoard(Board board) { if (board instanceof CaseBoard) { setCasePickable(); - } else { + } + else { for (ElementView elementView : elementViews) { elementView.setPuzzleElement(board.getPuzzleElement(elementView.getPuzzleElement())); elementView.setShowCasePicker(false); diff --git a/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java b/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java index 8e6f2cb18..d8f88f979 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java @@ -26,7 +26,8 @@ public void toggleSelection(ElementView elementView) { if (selection.contains(elementView)) { selection.remove(elementView); elementView.setSelected(false); - } else { + } + else { selection.add(elementView); elementView.setSelected(true); } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java index b1463fc4d..84804e1a0 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java @@ -122,224 +122,224 @@ public void initialize() { protected void initClassDefaults(UIDefaults table) { super.initClassDefaults(table); - table.put ("ButtonUI", MaterialButtonUI.class.getCanonicalName()); - table.put ("TextFieldUI", MaterialTextFieldUI.class.getCanonicalName()); - table.put ("PasswordFieldUI", MaterialPasswordFieldUI.class.getCanonicalName()); - table.put ("TableUI", MaterialTableUI.class.getCanonicalName()); - table.put ("TableHeaderUI", MaterialTableHeaderUI.class.getCanonicalName()); - table.put ("TreeUI", MaterialTreeUI.class.getCanonicalName()); - table.put ("SpinnerUI", MaterialSpinnerUI.class.getCanonicalName()); - table.put ("PanelUI", MaterialPanelUI.class.getCanonicalName()); - table.put ("LabelUI", MaterialLabelUI.class.getCanonicalName()); - table.put ("MenuItemUI", MaterialMenuItemUI.class.getCanonicalName()); + table.put("ButtonUI", MaterialButtonUI.class.getCanonicalName()); + table.put("TextFieldUI", MaterialTextFieldUI.class.getCanonicalName()); + table.put("PasswordFieldUI", MaterialPasswordFieldUI.class.getCanonicalName()); + table.put("TableUI", MaterialTableUI.class.getCanonicalName()); + table.put("TableHeaderUI", MaterialTableHeaderUI.class.getCanonicalName()); + table.put("TreeUI", MaterialTreeUI.class.getCanonicalName()); + table.put("SpinnerUI", MaterialSpinnerUI.class.getCanonicalName()); + table.put("PanelUI", MaterialPanelUI.class.getCanonicalName()); + table.put("LabelUI", MaterialLabelUI.class.getCanonicalName()); + table.put("MenuItemUI", MaterialMenuItemUI.class.getCanonicalName()); // table.put ("MenuBarUI", .class.getCanonicalName()); - table.put ("MenuUI", MaterialMenuUI.class.getCanonicalName()); - table.put ("CheckBoxUI", MaterialCheckBoxUI.class.getCanonicalName()); - table.put ("RadioButtonUI", MaterialRadioButtonUI.class.getCanonicalName()); - table.put ("TabbedPaneUI", MaterialTabbedPaneUI.class.getCanonicalName()); - table.put ("ToggleButtonUI", MaterialToggleButtonUI.class.getCanonicalName()); - table.put ("ScrollBarUI", MaterialScrollBarUI.class.getCanonicalName()); - table.put ("ComboBoxUI", MaterialComboBoxUI.class.getCanonicalName()); - table.put ("PopupMenuUI", MaterialPopupMenuUI.class.getCanonicalName()); - table.put ("ToolBarUI", MaterialToolBarUI.class.getCanonicalName()); - table.put ("SliderUI", MaterialSliderUI.class.getCanonicalName()); - table.put ("ProgressBarUI", MaterialProgressBarUI.class.getCanonicalName()); - table.put ("RadioButtonMenuItemUI", MaterialRadioButtonMenuItemUI.class.getCanonicalName()); - table.put ("CheckBoxMenuItemUI", MaterialCheckBoxMenuItemUI.class.getCanonicalName()); - table.put ("TextPaneUI", MaterialTextPaneUI.class.getCanonicalName()); - table.put ("EditorPaneUI", MaterialEditorPaneUI.class.getCanonicalName()); - table.put ("SeparatorUI", MaterialSeparatorUI.class.getCanonicalName()); - table.put ("FileChooserUI", MaterialFileChooserUI.class.getCanonicalName()); - table.put ("ToolTipUI", MaterialToolTipUI.class.getCanonicalName()); - table.put ("SplitPaneUI", MaterialSplitPaneUI.class.getCanonicalName()); + table.put("MenuUI", MaterialMenuUI.class.getCanonicalName()); + table.put("CheckBoxUI", MaterialCheckBoxUI.class.getCanonicalName()); + table.put("RadioButtonUI", MaterialRadioButtonUI.class.getCanonicalName()); + table.put("TabbedPaneUI", MaterialTabbedPaneUI.class.getCanonicalName()); + table.put("ToggleButtonUI", MaterialToggleButtonUI.class.getCanonicalName()); + table.put("ScrollBarUI", MaterialScrollBarUI.class.getCanonicalName()); + table.put("ComboBoxUI", MaterialComboBoxUI.class.getCanonicalName()); + table.put("PopupMenuUI", MaterialPopupMenuUI.class.getCanonicalName()); + table.put("ToolBarUI", MaterialToolBarUI.class.getCanonicalName()); + table.put("SliderUI", MaterialSliderUI.class.getCanonicalName()); + table.put("ProgressBarUI", MaterialProgressBarUI.class.getCanonicalName()); + table.put("RadioButtonMenuItemUI", MaterialRadioButtonMenuItemUI.class.getCanonicalName()); + table.put("CheckBoxMenuItemUI", MaterialCheckBoxMenuItemUI.class.getCanonicalName()); + table.put("TextPaneUI", MaterialTextPaneUI.class.getCanonicalName()); + table.put("EditorPaneUI", MaterialEditorPaneUI.class.getCanonicalName()); + table.put("SeparatorUI", MaterialSeparatorUI.class.getCanonicalName()); + table.put("FileChooserUI", MaterialFileChooserUI.class.getCanonicalName()); + table.put("ToolTipUI", MaterialToolTipUI.class.getCanonicalName()); + table.put("SplitPaneUI", MaterialSplitPaneUI.class.getCanonicalName()); // table.put ("ColorChooserUI", ); } @Override - protected void initComponentDefaults (UIDefaults table) { + protected void initComponentDefaults(UIDefaults table) { super.initComponentDefaults(table); - table.put ("Button.highlight", MaterialColors.GRAY_300); - table.put ("Button.opaque", false); - table.put ("Button.border", BorderFactory.createEmptyBorder (7, 17, 7, 17)); - table.put ("Button.background", MaterialColors.GRAY_200); - table.put ("Button.foreground", Color.BLACK); - table.put ("Button.font", MaterialFonts.MEDIUM); - - table.put ("CheckBox.font", MaterialFonts.REGULAR); - table.put ("CheckBox.background", Color.WHITE); - table.put ("CheckBox.foreground", Color.BLACK); - table.put ("CheckBox.icon", new ImageIcon (MaterialImages.UNCHECKED_BOX)); - table.put ("CheckBox.selectedIcon", new ImageIcon (MaterialImages.PAINTED_CHECKED_BOX)); - - table.put ("ComboBox.font", MaterialFonts.REGULAR); - table.put ("ComboBox.background", Color.WHITE); - table.put ("ComboBox.foreground", Color.BLACK); - table.put ("ComboBox.border", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (0, 5, 0, 0))); - table.put ("ComboBox.buttonBackground", MaterialColors.GRAY_300); - table.put ("ComboBox.selectionBackground", Color.WHITE); - table.put ("ComboBox.selectionForeground", Color.BLACK); - table.put ("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); - - table.put ("Label.font", MaterialFonts.REGULAR); - table.put ("Label.background", Color.WHITE); - table.put ("Label.foreground", Color.BLACK); - table.put ("Label.border", BorderFactory.createEmptyBorder ()); - - table.put ("Menu.font", MaterialFonts.BOLD); - table.put ("Menu.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); - table.put ("Menu.background", Color.WHITE); - table.put ("Menu.foreground", Color.BLACK); - table.put ("Menu.opaque", true); - table.put ("Menu.selectionBackground", MaterialColors.GRAY_200); - table.put ("Menu.selectionForeground", Color.BLACK); - table.put ("Menu.disabledForeground", new Color (0, 0, 0, 100)); - table.put ("Menu.menuPopupOffsetY", 3); - - table.put ("MenuBar.font", MaterialFonts.BOLD); - table.put ("MenuBar.background", Color.WHITE); - table.put ("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); - table.put ("MenuBar.foreground", Color.BLACK); - - table.put ("MenuItem.disabledForeground", new Color (0, 0, 0, 100)); - table.put ("MenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put ("MenuItem.selectionForeground", Color.BLACK); - table.put ("MenuItem.font", MaterialFonts.MEDIUM); - table.put ("MenuItem.background", Color.WHITE); - table.put ("MenuItem.foreground", Color.BLACK); - table.put ("MenuItem.border", BorderFactory.createEmptyBorder (5, 0, 5, 0)); - - table.put ("OptionPane.background", Color.WHITE); - table.put ("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); - table.put ("OptionPane.font", MaterialFonts.REGULAR); - - table.put ("Panel.font", MaterialFonts.REGULAR); - table.put ("Panel.background", Color.WHITE); - table.put ("Panel.border", BorderFactory.createEmptyBorder ()); - - table.put ("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("PopupMenu.background", Color.WHITE); - table.put ("PopupMenu.foreground", Color.BLACK); - - table.put ("RadioButton.font", MaterialFonts.REGULAR); - table.put ("RadioButton.background", Color.WHITE); - table.put ("RadioButton.foreground", Color.BLACK); - table.put ("RadioButton.icon", new ImageIcon (MaterialImages.RADIO_BUTTON_OFF)); - table.put ("RadioButton.selectedIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_ON)); - - table.put ("Spinner.font", MaterialFonts.REGULAR); - table.put ("Spinner.background", Color.WHITE); - table.put ("Spinner.foreground", Color.BLACK); - table.put ("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); - table.put ("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder ()); - - table.put ("ScrollBar.font", MaterialFonts.REGULAR); - table.put ("ScrollBar.track", MaterialColors.GRAY_200); - table.put ("ScrollBar.thumb", MaterialColors.GRAY_300); - table.put ("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); - table.put ("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); - table.put ("ScrollBar.thumbShadow", MaterialColors.GRAY_300); - table.put ("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); - table.put ("ScrollBar.arrowButtonBorder", BorderFactory.createEmptyBorder ()); - - table.put ("ScrollPane.background", Color.WHITE); - table.put ("ScrollPane.border", BorderFactory.createEmptyBorder ()); - table.put ("ScrollPane.font", MaterialFonts.REGULAR); - - table.put ("Slider.font", MaterialFonts.REGULAR); - table.put ("Slider.background", Color.WHITE); - table.put ("Slider.foreground", MaterialColors.GRAY_700); - table.put ("Slider.trackColor", Color.BLACK); + table.put("Button.highlight", MaterialColors.GRAY_300); + table.put("Button.opaque", false); + table.put("Button.border", BorderFactory.createEmptyBorder(7, 17, 7, 17)); + table.put("Button.background", MaterialColors.GRAY_200); + table.put("Button.foreground", Color.BLACK); + table.put("Button.font", MaterialFonts.MEDIUM); + + table.put("CheckBox.font", MaterialFonts.REGULAR); + table.put("CheckBox.background", Color.WHITE); + table.put("CheckBox.foreground", Color.BLACK); + table.put("CheckBox.icon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); + table.put("CheckBox.selectedIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); + + table.put("ComboBox.font", MaterialFonts.REGULAR); + table.put("ComboBox.background", Color.WHITE); + table.put("ComboBox.foreground", Color.BLACK); + table.put("ComboBox.border", BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(0, 5, 0, 0))); + table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); + table.put("ComboBox.selectionBackground", Color.WHITE); + table.put("ComboBox.selectionForeground", Color.BLACK); + table.put("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); + + table.put("Label.font", MaterialFonts.REGULAR); + table.put("Label.background", Color.WHITE); + table.put("Label.foreground", Color.BLACK); + table.put("Label.border", BorderFactory.createEmptyBorder()); + + table.put("Menu.font", MaterialFonts.BOLD); + table.put("Menu.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); + table.put("Menu.background", Color.WHITE); + table.put("Menu.foreground", Color.BLACK); + table.put("Menu.opaque", true); + table.put("Menu.selectionBackground", MaterialColors.GRAY_200); + table.put("Menu.selectionForeground", Color.BLACK); + table.put("Menu.disabledForeground", new Color(0, 0, 0, 100)); + table.put("Menu.menuPopupOffsetY", 3); + + table.put("MenuBar.font", MaterialFonts.BOLD); + table.put("MenuBar.background", Color.WHITE); + table.put("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); + table.put("MenuBar.foreground", Color.BLACK); + + table.put("MenuItem.disabledForeground", new Color(0, 0, 0, 100)); + table.put("MenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("MenuItem.selectionForeground", Color.BLACK); + table.put("MenuItem.font", MaterialFonts.MEDIUM); + table.put("MenuItem.background", Color.WHITE); + table.put("MenuItem.foreground", Color.BLACK); + table.put("MenuItem.border", BorderFactory.createEmptyBorder(5, 0, 5, 0)); + + table.put("OptionPane.background", Color.WHITE); + table.put("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); + table.put("OptionPane.font", MaterialFonts.REGULAR); + + table.put("Panel.font", MaterialFonts.REGULAR); + table.put("Panel.background", Color.WHITE); + table.put("Panel.border", BorderFactory.createEmptyBorder()); + + table.put("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("PopupMenu.background", Color.WHITE); + table.put("PopupMenu.foreground", Color.BLACK); + + table.put("RadioButton.font", MaterialFonts.REGULAR); + table.put("RadioButton.background", Color.WHITE); + table.put("RadioButton.foreground", Color.BLACK); + table.put("RadioButton.icon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); + table.put("RadioButton.selectedIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); + + table.put("Spinner.font", MaterialFonts.REGULAR); + table.put("Spinner.background", Color.WHITE); + table.put("Spinner.foreground", Color.BLACK); + table.put("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); + table.put("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder()); + + table.put("ScrollBar.font", MaterialFonts.REGULAR); + table.put("ScrollBar.track", MaterialColors.GRAY_200); + table.put("ScrollBar.thumb", MaterialColors.GRAY_300); + table.put("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); + table.put("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); + table.put("ScrollBar.thumbShadow", MaterialColors.GRAY_300); + table.put("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); + table.put("ScrollBar.arrowButtonBorder", BorderFactory.createEmptyBorder()); + + table.put("ScrollPane.background", Color.WHITE); + table.put("ScrollPane.border", BorderFactory.createEmptyBorder()); + table.put("ScrollPane.font", MaterialFonts.REGULAR); + + table.put("Slider.font", MaterialFonts.REGULAR); + table.put("Slider.background", Color.WHITE); + table.put("Slider.foreground", MaterialColors.GRAY_700); + table.put("Slider.trackColor", Color.BLACK); // table.put ("Slider.border", BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (5, 5, 5, 5))); - table.put ("SplitPane.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("SplitPane.background", Color.WHITE); - table.put ("SplitPane.dividerSize", 10); - table.put ("SplitPaneDivider.border", MaterialBorders.LIGHT_SHADOW_BORDER); - - table.put ("TabbedPane.font", MaterialFonts.REGULAR); - table.put ("TabbedPane.background", Color.WHITE); - table.put ("TabbedPane.foreground", Color.BLACK); - table.put ("TabbedPane.border", BorderFactory.createEmptyBorder ()); - table.put ("TabbedPane.shadow", null); - table.put ("TabbedPane.darkShadow", null); - table.put ("TabbedPane.highlight", MaterialColors.GRAY_200); - table.put ("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); - - table.put ("Table.selectionBackground", MaterialColors.GRAY_100); - table.put ("Table.selectionForeground", Color.BLACK); - table.put ("Table.background", Color.WHITE); - table.put ("Table.font", MaterialFonts.REGULAR); - table.put ("Table.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("Table.gridColor", MaterialColors.GRAY_200); - table.put ("TableHeader.background", MaterialColors.GRAY_200); - table.put ("TableHeader.font", MaterialFonts.BOLD); - table.put ("TableHeader.cellBorder", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (5, 5, 5, 5))); - - table.put ("TextArea.background", MaterialColors.GRAY_200); - table.put ("TextArea.border", BorderFactory.createEmptyBorder ()); - table.put ("TextArea.foreground", Color.BLACK); - - table.put ("ToggleButton.border", BorderFactory.createEmptyBorder ()); - table.put ("ToggleButton.font", MaterialFonts.REGULAR); - table.put ("ToggleButton.background", Color.WHITE); - table.put ("ToggleButton.foreground", Color.BLACK); - table.put ("ToggleButton.icon", new ImageIcon (MaterialImages.TOGGLE_BUTTON_OFF)); - table.put ("ToggleButton.selectedIcon", new ImageIcon (MaterialImages.TOGGLE_BUTTON_ON)); - - table.put ("ToolBar.font", MaterialFonts.REGULAR); - table.put ("ToolBar.background", Color.WHITE); - table.put ("ToolBar.foreground", Color.BLACK); - table.put ("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); - table.put ("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); - table.put ("ToolBar.floatingBackground", MaterialColors.GRAY_200); - - table.put ("Tree.font", MaterialFonts.REGULAR); - table.put ("Tree.selectionForeground", Color.BLACK); - table.put ("Tree.foreground", Color.BLACK); - table.put ("Tree.selectionBackground", MaterialColors.GRAY_200); - table.put ("Tree.background", Color.WHITE); - table.put ("Tree.closedIcon", new ImageIcon (MaterialImages.RIGHT_ARROW)); - table.put ("Tree.openIcon", new ImageIcon (MaterialImages.DOWN_ARROW)); - table.put ("Tree.selectionBorderColor", null); - - table.put ("RadioButtonMenuItem.foreground", Color.BLACK); - table.put ("RadioButtonMenuItem.selectionForeground", Color.BLACK); + table.put("SplitPane.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("SplitPane.background", Color.WHITE); + table.put("SplitPane.dividerSize", 10); + table.put("SplitPaneDivider.border", MaterialBorders.LIGHT_SHADOW_BORDER); + + table.put("TabbedPane.font", MaterialFonts.REGULAR); + table.put("TabbedPane.background", Color.WHITE); + table.put("TabbedPane.foreground", Color.BLACK); + table.put("TabbedPane.border", BorderFactory.createEmptyBorder()); + table.put("TabbedPane.shadow", null); + table.put("TabbedPane.darkShadow", null); + table.put("TabbedPane.highlight", MaterialColors.GRAY_200); + table.put("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); + + table.put("Table.selectionBackground", MaterialColors.GRAY_100); + table.put("Table.selectionForeground", Color.BLACK); + table.put("Table.background", Color.WHITE); + table.put("Table.font", MaterialFonts.REGULAR); + table.put("Table.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("Table.gridColor", MaterialColors.GRAY_200); + table.put("TableHeader.background", MaterialColors.GRAY_200); + table.put("TableHeader.font", MaterialFonts.BOLD); + table.put("TableHeader.cellBorder", BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(5, 5, 5, 5))); + + table.put("TextArea.background", MaterialColors.GRAY_200); + table.put("TextArea.border", BorderFactory.createEmptyBorder()); + table.put("TextArea.foreground", Color.BLACK); + + table.put("ToggleButton.border", BorderFactory.createEmptyBorder()); + table.put("ToggleButton.font", MaterialFonts.REGULAR); + table.put("ToggleButton.background", Color.WHITE); + table.put("ToggleButton.foreground", Color.BLACK); + table.put("ToggleButton.icon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_OFF)); + table.put("ToggleButton.selectedIcon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_ON)); + + table.put("ToolBar.font", MaterialFonts.REGULAR); + table.put("ToolBar.background", Color.WHITE); + table.put("ToolBar.foreground", Color.BLACK); + table.put("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); + table.put("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); + table.put("ToolBar.floatingBackground", MaterialColors.GRAY_200); + + table.put("Tree.font", MaterialFonts.REGULAR); + table.put("Tree.selectionForeground", Color.BLACK); + table.put("Tree.foreground", Color.BLACK); + table.put("Tree.selectionBackground", MaterialColors.GRAY_200); + table.put("Tree.background", Color.WHITE); + table.put("Tree.closedIcon", new ImageIcon(MaterialImages.RIGHT_ARROW)); + table.put("Tree.openIcon", new ImageIcon(MaterialImages.DOWN_ARROW)); + table.put("Tree.selectionBorderColor", null); + + table.put("RadioButtonMenuItem.foreground", Color.BLACK); + table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); //If it changes the background of the menuitem it must change this too, irrespective of its setting - table.put ("RadioButtonMenuItem.background", UIManager.getColor ("MenuItem.background")); - table.put ("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put ("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); - table.put ("RadioButtonMenuItem.checkIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_OFF)); - table.put ("RadioButtonMenuItem.selectedCheckIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_ON)); + table.put("RadioButtonMenuItem.background", UIManager.getColor("MenuItem.background")); + table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); + table.put("RadioButtonMenuItem.checkIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); + table.put("RadioButtonMenuItem.selectedCheckIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); //If it changes the background of the menuitem it must change this too, irrespective of its setting - table.put ("CheckBoxMenuItem.background", UIManager.getColor ("MenuItem.background")); - table.put ("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put ("CheckBoxMenuItem.foreground", Color.BLACK); - table.put ("CheckBoxMenuItem.selectionForeground", Color.BLACK); - table.put ("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); - table.put ("CheckBoxMenuItem.checkIcon", new ImageIcon (MaterialImages.UNCHECKED_BOX)); - table.put ("CheckBoxMenuItem.selectedCheckIcon", new ImageIcon (MaterialImages.PAINTED_CHECKED_BOX)); - - table.put ("TextPane.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("TextPane.background", MaterialColors.GRAY_50); - table.put ("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put ("TextPane.inactiveForeground", MaterialColors.GRAY_500); - table.put ("TextPane.font", MaterialFonts.REGULAR); - - table.put ("EditorPane.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("EditorPane.background", MaterialColors.GRAY_50); - table.put ("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put ("EditorPane.inactiveForeground", MaterialColors.GRAY_500); - table.put ("EditorPane.font", MaterialFonts.REGULAR); - - table.put ("Separator.background", MaterialColors.GRAY_300); - table.put ("Separator.foreground", MaterialColors.GRAY_300); + table.put("CheckBoxMenuItem.background", UIManager.getColor("MenuItem.background")); + table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("CheckBoxMenuItem.foreground", Color.BLACK); + table.put("CheckBoxMenuItem.selectionForeground", Color.BLACK); + table.put("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); + table.put("CheckBoxMenuItem.checkIcon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); + table.put("CheckBoxMenuItem.selectedCheckIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); + + table.put("TextPane.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("TextPane.background", MaterialColors.GRAY_50); + table.put("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); + table.put("TextPane.inactiveForeground", MaterialColors.GRAY_500); + table.put("TextPane.font", MaterialFonts.REGULAR); + + table.put("EditorPane.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("EditorPane.background", MaterialColors.GRAY_50); + table.put("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); + table.put("EditorPane.inactiveForeground", MaterialColors.GRAY_500); + table.put("EditorPane.font", MaterialFonts.REGULAR); + + table.put("Separator.background", MaterialColors.GRAY_300); + table.put("Separator.foreground", MaterialColors.GRAY_300); table.put("ToolTip.background", MaterialColors.GRAY_500); table.put("ToolTip.foreground", MaterialColors.GRAY_50); - table.put("ToolTip.border", BorderFactory.createEmptyBorder(5,5,5,5)); + table.put("ToolTip.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("ColorChooser.background", MaterialColors.WHITE); table.put("ColorChooser.foreground", MaterialColors.BLACK); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java index 21e5b2622..fe82238ab 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java @@ -5,13 +5,14 @@ public class MaterialUIMovement { - private MaterialUIMovement () {} + private MaterialUIMovement() { + } - public static void add (JComponent c, Color fadeTo, int steps, int interval) { - new MaterialUITimer (c, fadeTo, steps, interval); - } + public static void add(JComponent c, Color fadeTo, int steps, int interval) { + new MaterialUITimer(c, fadeTo, steps, interval); + } - public static void add (JComponent c, Color fadeTo) { - add (c, fadeTo, 5, 1000 / 30); - } + public static void add(JComponent c, Color fadeTo) { + add(c, fadeTo, 5, 1000 / 30); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java index 747f50fcd..b5b3bbd76 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java @@ -10,104 +10,104 @@ public class MaterialUITimer implements MouseListener, ActionListener { - private Color from, to; - private boolean forward; - private int alpha, steps; - private int[] forwardDeltas, backwardDeltas; - - private JComponent component; - private Timer timer; - - protected MaterialUITimer (JComponent component, Color to, int steps, int interval) { - this.from = component.getBackground (); - this.to = to; - - this.forwardDeltas = new int[4]; - this.backwardDeltas = new int[4]; - - forwardDeltas[0] = (from.getRed () - to.getRed ()) / steps; - forwardDeltas[1] = (from.getGreen () - to.getGreen ()) / steps; - forwardDeltas[2] = (from.getBlue () - to.getBlue ()) / steps; - forwardDeltas[3] = (from.getAlpha () - to.getAlpha ()) / steps; - - backwardDeltas[0] = (to.getRed () - from.getRed ()) / steps; - backwardDeltas[1] = (to.getGreen () - from.getGreen ()) / steps; - backwardDeltas[2] = (to.getBlue () - from.getBlue ()) / steps; - backwardDeltas[3] = (to.getAlpha () - from.getAlpha ()) / steps; - - this.steps = steps; - - this.component = component; - this.component.addMouseListener (this); - timer = new Timer (interval, this); - } - - private Color nextColor () { - int rValue = from.getRed () - alpha * forwardDeltas[0]; - int gValue = from.getGreen () - alpha * forwardDeltas[1]; - int bValue = from.getBlue () - alpha * forwardDeltas[2]; - int aValue = from.getAlpha () - alpha * forwardDeltas[3]; - - return new Color (rValue, gValue, bValue, aValue); - } - - private Color previousColor () { - int rValue = to.getRed () - (steps - alpha) * backwardDeltas[0]; - int gValue = to.getGreen () - (steps - alpha) * backwardDeltas[1]; - int bValue = to.getBlue () - (steps - alpha) * backwardDeltas[2]; - int aValue = to.getAlpha () - (steps - alpha) * backwardDeltas[3]; - - return new Color (rValue, gValue, bValue, aValue); - } - - @Override - public void mousePressed (MouseEvent me) { - alpha = steps - 1; - forward = false; - timer.start (); - - alpha = 0; - forward = true; - timer.start (); - } - - @Override - public void mouseReleased (MouseEvent me) { - - } - - @Override - public void mouseClicked (MouseEvent me) { - - } - - @Override - public void mouseExited (MouseEvent me) { - alpha = steps - 1; - forward = false; - timer.start (); - } - - @Override - public void mouseEntered (MouseEvent me) { - alpha = 0; - forward = true; - timer.start (); - } - - @Override - public void actionPerformed (ActionEvent ae) { - if (forward) { - component.setBackground (nextColor ()); - ++alpha; - } - else { - component.setBackground (previousColor ()); - --alpha; - } - - if (alpha == steps + 1 || alpha == -1) { - timer.stop (); - } - } + private Color from, to; + private boolean forward; + private int alpha, steps; + private int[] forwardDeltas, backwardDeltas; + + private JComponent component; + private Timer timer; + + protected MaterialUITimer(JComponent component, Color to, int steps, int interval) { + this.from = component.getBackground(); + this.to = to; + + this.forwardDeltas = new int[4]; + this.backwardDeltas = new int[4]; + + forwardDeltas[0] = (from.getRed() - to.getRed()) / steps; + forwardDeltas[1] = (from.getGreen() - to.getGreen()) / steps; + forwardDeltas[2] = (from.getBlue() - to.getBlue()) / steps; + forwardDeltas[3] = (from.getAlpha() - to.getAlpha()) / steps; + + backwardDeltas[0] = (to.getRed() - from.getRed()) / steps; + backwardDeltas[1] = (to.getGreen() - from.getGreen()) / steps; + backwardDeltas[2] = (to.getBlue() - from.getBlue()) / steps; + backwardDeltas[3] = (to.getAlpha() - from.getAlpha()) / steps; + + this.steps = steps; + + this.component = component; + this.component.addMouseListener(this); + timer = new Timer(interval, this); + } + + private Color nextColor() { + int rValue = from.getRed() - alpha * forwardDeltas[0]; + int gValue = from.getGreen() - alpha * forwardDeltas[1]; + int bValue = from.getBlue() - alpha * forwardDeltas[2]; + int aValue = from.getAlpha() - alpha * forwardDeltas[3]; + + return new Color(rValue, gValue, bValue, aValue); + } + + private Color previousColor() { + int rValue = to.getRed() - (steps - alpha) * backwardDeltas[0]; + int gValue = to.getGreen() - (steps - alpha) * backwardDeltas[1]; + int bValue = to.getBlue() - (steps - alpha) * backwardDeltas[2]; + int aValue = to.getAlpha() - (steps - alpha) * backwardDeltas[3]; + + return new Color(rValue, gValue, bValue, aValue); + } + + @Override + public void mousePressed(MouseEvent me) { + alpha = steps - 1; + forward = false; + timer.start(); + + alpha = 0; + forward = true; + timer.start(); + } + + @Override + public void mouseReleased(MouseEvent me) { + + } + + @Override + public void mouseClicked(MouseEvent me) { + + } + + @Override + public void mouseExited(MouseEvent me) { + alpha = steps - 1; + forward = false; + timer.start(); + } + + @Override + public void mouseEntered(MouseEvent me) { + alpha = 0; + forward = true; + timer.start(); + } + + @Override + public void actionPerformed(ActionEvent ae) { + if (forward) { + component.setBackground(nextColor()); + ++alpha; + } + else { + component.setBackground(previousColor()); + --alpha; + } + + if (alpha == steps + 1 || alpha == -1) { + timer.stop(); + } + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java index d412b831c..fe23536d3 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java @@ -13,33 +13,33 @@ public class MaterialButtonUI extends BasicButtonUI { - public static ComponentUI createUI (final JComponent c) { - return new MaterialButtonUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - AbstractButton button = (AbstractButton) c; - MaterialUIMovement.add(c, MaterialColors.GRAY_300); - button.setOpaque (UIManager.getBoolean ("Button.opaque")); - button.setBorder (UIManager.getBorder ("Button.border")); - button.setBackground (UIManager.getColor ("Button.background")); - button.setForeground (UIManager.getColor ("Button.foreground")); - button.setFont (UIManager.getFont ("Button.font")); - } - - @Override - public void paint (Graphics g, JComponent c) { - AbstractButton b = (AbstractButton) c; - g = MaterialDrawingUtils.getAliasedGraphics (g); - paintBackground (g, b); - super.paint (g, c); - } - - private void paintBackground (Graphics g, JComponent c) { - g.setColor (c.getBackground ()); - g.fillRoundRect (0, 0, c.getWidth (), c.getHeight (), 7, 7); - } + public static ComponentUI createUI(final JComponent c) { + return new MaterialButtonUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + AbstractButton button = (AbstractButton) c; + MaterialUIMovement.add(c, MaterialColors.GRAY_300); + button.setOpaque(UIManager.getBoolean("Button.opaque")); + button.setBorder(UIManager.getBorder("Button.border")); + button.setBackground(UIManager.getColor("Button.background")); + button.setForeground(UIManager.getColor("Button.foreground")); + button.setFont(UIManager.getFont("Button.font")); + } + + @Override + public void paint(Graphics g, JComponent c) { + AbstractButton b = (AbstractButton) c; + g = MaterialDrawingUtils.getAliasedGraphics(g); + paintBackground(g, b); + super.paint(g, c); + } + + private void paintBackground(Graphics g, JComponent c) { + g.setColor(c.getBackground()); + g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7); + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java index 47b2b326f..e5068a8ed 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java @@ -17,27 +17,27 @@ public class MaterialCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialCheckBoxMenuItemUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } - - @Override - protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { - JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c; - if (checkBoxMenuItem.isSelected ()) { - super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), checkBoxMenuItem, UIManager.getIcon ("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); - return; - } - super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), checkBoxMenuItem, UIManager.getIcon ("CheckBoxMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialCheckBoxMenuItemUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } + + @Override + protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { + JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c; + if (checkBoxMenuItem.isSelected()) { + super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), checkBoxMenuItem, UIManager.getIcon("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); + return; + } + super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), checkBoxMenuItem, UIManager.getIcon("CheckBoxMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java index da98b3752..a85e9079e 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java @@ -12,24 +12,24 @@ //TODO cambio colore icone combo box public class MaterialCheckBoxUI extends BasicCheckBoxUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialCheckBoxUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialCheckBoxUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JCheckBox checkBox = (JCheckBox) c; - checkBox.setFont (UIManager.getFont ("CheckBox.font")); - checkBox.setBackground (UIManager.getColor ("CheckBox.background")); - checkBox.setForeground (UIManager.getColor ("CheckBox.foreground")); - checkBox.setIcon (UIManager.getIcon ("CheckBox.icon")); - checkBox.setSelectedIcon (UIManager.getIcon ("CheckBox.selectedIcon")); - } + JCheckBox checkBox = (JCheckBox) c; + checkBox.setFont(UIManager.getFont("CheckBox.font")); + checkBox.setBackground(UIManager.getColor("CheckBox.background")); + checkBox.setForeground(UIManager.getColor("CheckBox.foreground")); + checkBox.setIcon(UIManager.getIcon("CheckBox.icon")); + checkBox.setSelectedIcon(UIManager.getIcon("CheckBox.selectedIcon")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java index dc43af125..d6df89d44 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java @@ -9,16 +9,16 @@ public class MaterialComboBoxRenderer extends BasicComboBoxRenderer { - @Override - public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - JComponent component = (JComponent) super.getListCellRendererComponent (list, value, index, isSelected, cellHasFocus); + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + JComponent component = (JComponent) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - component.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5)); - component.setForeground (UIManager.getColor ("ComboBox.foreground")); - component.setBackground (isSelected || cellHasFocus ? - UIManager.getColor ("ComboBox.selectedInDropDownBackground") : - UIManager.getColor ("ComboBox.background")); + component.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + component.setForeground(UIManager.getColor("ComboBox.foreground")); + component.setBackground(isSelected || cellHasFocus ? + UIManager.getColor("ComboBox.selectedInDropDownBackground") : + UIManager.getColor("ComboBox.background")); - return component; - } + return component; + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java index 9c2162c37..6b7c042f4 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java @@ -16,42 +16,42 @@ public class MaterialComboBoxUI extends BasicComboBoxUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialComboBoxUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JComboBox comboBox = (JComboBox) c; - comboBox.setFont (UIManager.getFont ("ComboBox.font")); - comboBox.setBackground (UIManager.getColor ("ComboBox.background")); - comboBox.setForeground (UIManager.getColor ("ComboBox.foreground")); - comboBox.setBorder (UIManager.getBorder ("ComboBox.border")); - comboBox.setLightWeightPopupEnabled (true); - comboBox.setRenderer (new MaterialComboBoxRenderer ()); - } - - @Override - protected JButton createArrowButton () { - Icon icon = UIManager.getIcon ("ComboBox.buttonIcon"); - JButton button; - if (icon != null) { - button = new JButton (icon); - } - else { - button = new BasicArrowButton (SwingConstants.SOUTH); - } - button.setOpaque (true); - button.setBackground (UIManager.getColor ("ComboBox.buttonBackground")); - button.setBorder (BorderFactory.createEmptyBorder ()); - - return button; - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialComboBoxUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JComboBox comboBox = (JComboBox) c; + comboBox.setFont(UIManager.getFont("ComboBox.font")); + comboBox.setBackground(UIManager.getColor("ComboBox.background")); + comboBox.setForeground(UIManager.getColor("ComboBox.foreground")); + comboBox.setBorder(UIManager.getBorder("ComboBox.border")); + comboBox.setLightWeightPopupEnabled(true); + comboBox.setRenderer(new MaterialComboBoxRenderer()); + } + + @Override + protected JButton createArrowButton() { + Icon icon = UIManager.getIcon("ComboBox.buttonIcon"); + JButton button; + if (icon != null) { + button = new JButton(icon); + } + else { + button = new BasicArrowButton(SwingConstants.SOUTH); + } + button.setOpaque(true); + button.setBackground(UIManager.getColor("ComboBox.buttonBackground")); + button.setBorder(BorderFactory.createEmptyBorder()); + + return button; + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java index 06bb3c9bd..92d6770e0 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java @@ -10,12 +10,12 @@ public class MaterialEditorPaneUI extends BasicEditorPaneUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialEditorPaneUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialEditorPaneUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); - } + @Override + public void installUI(JComponent c) { + super.installUI(c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java index cea1ba82b..9a4ffc9d4 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java @@ -12,48 +12,48 @@ public class MaterialFileChooserUI extends MetalFileChooserUI { - public MaterialFileChooserUI (JFileChooser fileChooser) { - super (fileChooser); - } - - public static ComponentUI createUI (JComponent c) { - return new MaterialFileChooserUI ((JFileChooser) c); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - JFileChooser fileChooser = (JFileChooser) c; - MaterialFileChooserUI ui = (MaterialFileChooserUI) fileChooser.getUI (); - - ui.uninstallIcons (fileChooser); - ui.uninstallComponents (fileChooser); - ui.clearIconCache (); - - ui.computerIcon = new ImageIcon (MaterialImages.COMPUTER); - ui.directoryIcon = new ImageIcon (MaterialImages.FOLDER); - ui.fileIcon = new ImageIcon (MaterialImages.FILE); - ui.floppyDriveIcon = new ImageIcon (MaterialImages.FLOPPY_DRIVE); - ui.hardDriveIcon = new ImageIcon (MaterialImages.HARD_DRIVE); - - ui.homeFolderIcon = new ImageIcon (MaterialImages.HOME); - ui.listViewIcon = new ImageIcon (MaterialImages.LIST); - ui.detailsViewIcon = new ImageIcon (MaterialImages.DETAILS); - ui.newFolderIcon = new ImageIcon (MaterialImages.NEW_FOLDER); - ui.upFolderIcon = new ImageIcon (MaterialImages.BACK_ARROW); - - ui.openButtonText = "OPEN"; - ui.cancelButtonText = "CANCEL"; - ui.helpButtonText = "HELP"; - ui.saveButtonText = "SAVE"; - ui.directoryOpenButtonText = "OPEN"; - ui.updateButtonText = "UPDATE"; - - ui.installComponents (fileChooser); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public MaterialFileChooserUI(JFileChooser fileChooser) { + super(fileChooser); + } + + public static ComponentUI createUI(JComponent c) { + return new MaterialFileChooserUI((JFileChooser) c); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + JFileChooser fileChooser = (JFileChooser) c; + MaterialFileChooserUI ui = (MaterialFileChooserUI) fileChooser.getUI(); + + ui.uninstallIcons(fileChooser); + ui.uninstallComponents(fileChooser); + ui.clearIconCache(); + + ui.computerIcon = new ImageIcon(MaterialImages.COMPUTER); + ui.directoryIcon = new ImageIcon(MaterialImages.FOLDER); + ui.fileIcon = new ImageIcon(MaterialImages.FILE); + ui.floppyDriveIcon = new ImageIcon(MaterialImages.FLOPPY_DRIVE); + ui.hardDriveIcon = new ImageIcon(MaterialImages.HARD_DRIVE); + + ui.homeFolderIcon = new ImageIcon(MaterialImages.HOME); + ui.listViewIcon = new ImageIcon(MaterialImages.LIST); + ui.detailsViewIcon = new ImageIcon(MaterialImages.DETAILS); + ui.newFolderIcon = new ImageIcon(MaterialImages.NEW_FOLDER); + ui.upFolderIcon = new ImageIcon(MaterialImages.BACK_ARROW); + + ui.openButtonText = "OPEN"; + ui.cancelButtonText = "CANCEL"; + ui.helpButtonText = "HELP"; + ui.saveButtonText = "SAVE"; + ui.directoryOpenButtonText = "OPEN"; + ui.updateButtonText = "UPDATE"; + + ui.installComponents(fileChooser); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java index ea98b1fd5..e06509a82 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java @@ -11,24 +11,24 @@ public class MaterialLabelUI extends BasicLabelUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialLabelUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialLabelUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JLabel label = (JLabel) c; - label.setOpaque (true); - label.setFont (UIManager.getFont ("Label.font")); - label.setBackground (UIManager.getColor ("Label.background")); - label.setForeground (UIManager.getColor ("Label.foreground")); - label.setBorder (UIManager.getBorder ("Label.border")); - } + JLabel label = (JLabel) c; + label.setOpaque(true); + label.setFont(UIManager.getFont("Label.font")); + label.setBackground(UIManager.getColor("Label.background")); + label.setForeground(UIManager.getColor("Label.foreground")); + label.setBorder(UIManager.getBorder("Label.border")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java index 28fb6dfae..8d5625559 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java @@ -11,23 +11,23 @@ public class MaterialMenuBarUI extends BasicMenuBarUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialMenuBarUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialMenuBarUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JMenuBar menuBar = (JMenuBar) c; - menuBar.setFont (UIManager.getFont ("MenuBar.font")); - menuBar.setBackground (UIManager.getColor ("MenuBar.background")); - menuBar.setBorder (UIManager.getBorder ("MenuBar.border")); - menuBar.setForeground (UIManager.getColor ("MenuBar.foreground")); - } + JMenuBar menuBar = (JMenuBar) c; + menuBar.setFont(UIManager.getFont("MenuBar.font")); + menuBar.setBackground(UIManager.getColor("MenuBar.background")); + menuBar.setBorder(UIManager.getBorder("MenuBar.border")); + menuBar.setForeground(UIManager.getColor("MenuBar.foreground")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java index a91c150e2..d7a23d1a3 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java @@ -12,25 +12,25 @@ public class MaterialMenuItemUI extends BasicMenuItemUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialMenuItemUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialMenuItemUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JMenuItem menuItem = (JMenuItem) c; - menuItem.setFont (UIManager.getFont ("MenuItem.font")); - menuItem.setBackground (UIManager.getColor ("MenuItem.background")); - menuItem.setForeground (UIManager.getColor ("MenuItem.foreground")); - menuItem.setHorizontalAlignment (SwingConstants.LEFT); - menuItem.setVerticalAlignment (SwingConstants.CENTER); - menuItem.setBorder (UIManager.getBorder ("MenuItem.border")); - } + JMenuItem menuItem = (JMenuItem) c; + menuItem.setFont(UIManager.getFont("MenuItem.font")); + menuItem.setBackground(UIManager.getColor("MenuItem.background")); + menuItem.setForeground(UIManager.getColor("MenuItem.foreground")); + menuItem.setHorizontalAlignment(SwingConstants.LEFT); + menuItem.setVerticalAlignment(SwingConstants.CENTER); + menuItem.setBorder(UIManager.getBorder("MenuItem.border")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java index 23cebd31e..7461cbea0 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java @@ -11,24 +11,24 @@ public class MaterialMenuUI extends BasicMenuUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialMenuUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialMenuUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JMenu menu = (JMenu) c; - menu.setFont (UIManager.getFont ("Menu.font")); - menu.setBorder (UIManager.getBorder ("Menu.border")); - menu.setBackground (UIManager.getColor ("Menu.background")); - menu.setForeground (UIManager.getColor ("Menu.foreground")); - menu.setOpaque (UIManager.getBoolean ("Menu.opaque")); - } + JMenu menu = (JMenu) c; + menu.setFont(UIManager.getFont("Menu.font")); + menu.setBorder(UIManager.getBorder("Menu.border")); + menu.setBackground(UIManager.getColor("Menu.background")); + menu.setForeground(UIManager.getColor("Menu.foreground")); + menu.setOpaque(UIManager.getBoolean("Menu.opaque")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java index 87cb28aa6..cf786be3f 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java @@ -11,23 +11,23 @@ public class MaterialPanelUI extends BasicPanelUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialPanelUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialPanelUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JPanel panel = (JPanel) c; - panel.setOpaque (true); - panel.setFont (UIManager.getFont ("Panel.font")); - panel.setBackground (UIManager.getColor ("Panel.background")); - panel.setBorder (UIManager.getBorder ("Panel.border")); - } + JPanel panel = (JPanel) c; + panel.setOpaque(true); + panel.setFont(UIManager.getFont("Panel.font")); + panel.setBackground(UIManager.getColor("Panel.background")); + panel.setBorder(UIManager.getBorder("Panel.border")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java index 7183e6720..61aa84fc7 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java @@ -29,167 +29,167 @@ public class MaterialPasswordFieldUI extends BasicPasswordFieldUI implements FocusListener, PropertyChangeListener { - private Color focusedBackground; - private Color unfocusedBackground; - private Color focusedSelectionBackground; - private Color unfocusedSelectionBackground; - - public static ComponentUI createUI (JComponent c) { - return new MaterialPasswordFieldUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JPasswordField passwordField = (JPasswordField) c; - passwordField.setOpaque (false); - passwordField.setBorder (BorderFactory.createEmptyBorder (5, 2, 10, 0)); - passwordField.setBackground (MaterialColors.LIGHT_BLUE_400); - - this.focusedBackground = passwordField.getBackground (); - this.unfocusedBackground = MaterialColors.GRAY_200; - - this.focusedSelectionBackground = MaterialColors.bleach (focusedBackground, 0.3f); - this.unfocusedSelectionBackground = unfocusedBackground; - } - - @Override - protected void installListeners () { - getComponent ().addFocusListener (this); - getComponent ().addPropertyChangeListener (this); - } - - @Override - protected void installKeyboardActions () { - super.installKeyboardActions (); - - Action selectAll = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().selectAll (); - } - }; - - Action delete = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - if (getComponent ().getSelectedText () == null) { - int pos = getComponent ().getCaretPosition () - 1; - - if (pos >= 0) { - getComponent ().select (pos, pos + 1); - getComponent ().replaceSelection (""); - } - } - else { - getComponent ().replaceSelection (""); - } - } - }; - - Action left = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().setCaretPosition (Math.max (0, getComponent ().getCaretPosition () - 1)); - } - }; - - Action right = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().setCaretPosition (Math.min (getComponent ().getText ().length (), getComponent ().getCaretPosition () + 1)); - } - }; - - // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_A, Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask ()), "selectAll"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_BACK_SPACE, 0), "delete"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_LEFT, 0), "left"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_RIGHT, 0), "right"); - - getComponent ().getActionMap ().put ("selectAll", selectAll); - getComponent ().getActionMap ().put ("delete", delete); - getComponent ().getActionMap ().put ("left", left); - getComponent ().getActionMap ().put ("right", right); - } - - @Override - public void paintSafely (Graphics g) { - JPasswordField c = (JPasswordField) getComponent (); - g = MaterialDrawingUtils.getAliasedGraphics (g); - - if (getComponent ().hasFocus ()) { - c.setBackground (focusedBackground); - c.setSelectionColor (focusedSelectionBackground); - } - else { - c.setBackground (unfocusedBackground); - c.setSelectionColor (unfocusedSelectionBackground); - } - - int x = getComponent ().getInsets ().left; - int y = getComponent ().getInsets ().top; - int w = getComponent ().getWidth () - getComponent ().getInsets ().left - getComponent ().getInsets ().right; - - g.setColor (c.getBackground ()); - g.fillRect (x, c.getHeight () - y, w, 2); - - super.paintSafely (g); - } - - @Override - public void paintBackground (Graphics g) { - super.paintBackground (MaterialDrawingUtils.getAliasedGraphics (g)); - } - - @Override - public void focusGained (FocusEvent e) { - e.getComponent ().setBackground (focusedBackground); - } - - @Override - public void focusLost (FocusEvent e) { - e.getComponent ().setBackground (unfocusedBackground); - } - - @Override - public void propertyChange (PropertyChangeEvent pce) { - if (pce.getPropertyName ().equals ("background")) { - Color newColor = (Color) pce.getNewValue (); - - if (!newColor.equals (focusedBackground) && !newColor.equals (unfocusedBackground)) { - this.focusedBackground = (Color) pce.getNewValue (); - this.focusedSelectionBackground = MaterialColors.bleach (this.focusedBackground, 0.3f); - } - } - } - - @Override - public View create (Element elem) { - return new MaterialPasswordView (elem); - } - - private static class MaterialPasswordView extends PasswordView { - - private MaterialPasswordView (Element elem) { - super (elem); - } - - // depreciated in Java 9 and above - replace method with float drawEchoCharacter(Graphics2D g, float x, float y, char c) - @Override - protected int drawEchoCharacter (Graphics g, int x, int y, char c) { - Graphics2D g2 = (Graphics2D) g.create (); - g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - FontMetrics fm = g2.getFontMetrics (); - int r = fm.charWidth (c) - 2; - - g2.setPaint (Color.BLACK); - g2.fillOval (x + 1, y + 5 - fm.getAscent (), r, r); - g2.dispose (); - - return x + fm.charWidth (c); - } - } + private Color focusedBackground; + private Color unfocusedBackground; + private Color focusedSelectionBackground; + private Color unfocusedSelectionBackground; + + public static ComponentUI createUI(JComponent c) { + return new MaterialPasswordFieldUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JPasswordField passwordField = (JPasswordField) c; + passwordField.setOpaque(false); + passwordField.setBorder(BorderFactory.createEmptyBorder(5, 2, 10, 0)); + passwordField.setBackground(MaterialColors.LIGHT_BLUE_400); + + this.focusedBackground = passwordField.getBackground(); + this.unfocusedBackground = MaterialColors.GRAY_200; + + this.focusedSelectionBackground = MaterialColors.bleach(focusedBackground, 0.3f); + this.unfocusedSelectionBackground = unfocusedBackground; + } + + @Override + protected void installListeners() { + getComponent().addFocusListener(this); + getComponent().addPropertyChangeListener(this); + } + + @Override + protected void installKeyboardActions() { + super.installKeyboardActions(); + + Action selectAll = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().selectAll(); + } + }; + + Action delete = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (getComponent().getSelectedText() == null) { + int pos = getComponent().getCaretPosition() - 1; + + if (pos >= 0) { + getComponent().select(pos, pos + 1); + getComponent().replaceSelection(""); + } + } + else { + getComponent().replaceSelection(""); + } + } + }; + + Action left = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().setCaretPosition(Math.max(0, getComponent().getCaretPosition() - 1)); + } + }; + + Action right = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().setCaretPosition(Math.min(getComponent().getText().length(), getComponent().getCaretPosition() + 1)); + } + }; + + // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "selectAll"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "left"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "right"); + + getComponent().getActionMap().put("selectAll", selectAll); + getComponent().getActionMap().put("delete", delete); + getComponent().getActionMap().put("left", left); + getComponent().getActionMap().put("right", right); + } + + @Override + public void paintSafely(Graphics g) { + JPasswordField c = (JPasswordField) getComponent(); + g = MaterialDrawingUtils.getAliasedGraphics(g); + + if (getComponent().hasFocus()) { + c.setBackground(focusedBackground); + c.setSelectionColor(focusedSelectionBackground); + } + else { + c.setBackground(unfocusedBackground); + c.setSelectionColor(unfocusedSelectionBackground); + } + + int x = getComponent().getInsets().left; + int y = getComponent().getInsets().top; + int w = getComponent().getWidth() - getComponent().getInsets().left - getComponent().getInsets().right; + + g.setColor(c.getBackground()); + g.fillRect(x, c.getHeight() - y, w, 2); + + super.paintSafely(g); + } + + @Override + public void paintBackground(Graphics g) { + super.paintBackground(MaterialDrawingUtils.getAliasedGraphics(g)); + } + + @Override + public void focusGained(FocusEvent e) { + e.getComponent().setBackground(focusedBackground); + } + + @Override + public void focusLost(FocusEvent e) { + e.getComponent().setBackground(unfocusedBackground); + } + + @Override + public void propertyChange(PropertyChangeEvent pce) { + if (pce.getPropertyName().equals("background")) { + Color newColor = (Color) pce.getNewValue(); + + if (!newColor.equals(focusedBackground) && !newColor.equals(unfocusedBackground)) { + this.focusedBackground = (Color) pce.getNewValue(); + this.focusedSelectionBackground = MaterialColors.bleach(this.focusedBackground, 0.3f); + } + } + } + + @Override + public View create(Element elem) { + return new MaterialPasswordView(elem); + } + + private static class MaterialPasswordView extends PasswordView { + + private MaterialPasswordView(Element elem) { + super(elem); + } + + // depreciated in Java 9 and above - replace method with float drawEchoCharacter(Graphics2D g, float x, float y, char c) + @Override + protected int drawEchoCharacter(Graphics g, int x, int y, char c) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + FontMetrics fm = g2.getFontMetrics(); + int r = fm.charWidth(c) - 2; + + g2.setPaint(Color.BLACK); + g2.fillOval(x + 1, y + 5 - fm.getAscent(), r, r); + g2.dispose(); + + return x + fm.charWidth(c); + } + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java index cc594cf7b..3fdb79961 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java @@ -11,22 +11,22 @@ public class MaterialPopupMenuUI extends BasicPopupMenuUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialPopupMenuUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialPopupMenuUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JPopupMenu popupMenu = (JPopupMenu) c; - popupMenu.setBorder (UIManager.getBorder ("PopupMenu.border")); - popupMenu.setBackground (UIManager.getColor ("PopupMenu.background")); - popupMenu.setForeground (UIManager.getColor ("PopupMenu.foreground")); - } + JPopupMenu popupMenu = (JPopupMenu) c; + popupMenu.setBorder(UIManager.getBorder("PopupMenu.border")); + popupMenu.setBackground(UIManager.getColor("PopupMenu.background")); + popupMenu.setForeground(UIManager.getColor("PopupMenu.foreground")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java index 26a85fae6..111b7ef92 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java @@ -16,23 +16,23 @@ public class MaterialProgressBarUI extends BasicProgressBarUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialProgressBarUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JProgressBar progressBar = (JProgressBar) c; - progressBar.setBorder (MaterialBorders.LIGHT_LINE_BORDER); - progressBar.setBackground (MaterialColors.GRAY_200); - progressBar.setForeground (MaterialColors.LIGHT_BLUE_400); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialProgressBarUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JProgressBar progressBar = (JProgressBar) c; + progressBar.setBorder(MaterialBorders.LIGHT_LINE_BORDER); + progressBar.setBackground(MaterialColors.GRAY_200); + progressBar.setForeground(MaterialColors.LIGHT_BLUE_400); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java index a8296f99a..d08e52f05 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java @@ -17,30 +17,30 @@ public class MaterialRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialRadioButtonMenuItemUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; - //j.setBackground(MaterialColors.WHITE); - j.setBorder (UIManager.getBorder ("MenuItem.border")); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } - - @Override - protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { - JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; - if (j.isSelected ()) { - super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), c, UIManager.getIcon ("RadioButtonMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); - return; - } - super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), c, UIManager.getIcon ("RadioButtonMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialRadioButtonMenuItemUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; + //j.setBackground(MaterialColors.WHITE); + j.setBorder(UIManager.getBorder("MenuItem.border")); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } + + @Override + protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { + JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; + if (j.isSelected()) { + super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), c, UIManager.getIcon("RadioButtonMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); + return; + } + super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), c, UIManager.getIcon("RadioButtonMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java index 59ed46074..047270369 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java @@ -15,24 +15,24 @@ //TODO cambio colore del radio button. public class MaterialRadioButtonUI extends BasicRadioButtonUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialRadioButtonUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialRadioButtonUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JRadioButton radioButton = (JRadioButton) c; - radioButton.setFont (UIManager.getFont ("RadioButton.font")); - radioButton.setBackground (UIManager.getColor ("RadioButton.background")); - radioButton.setForeground (UIManager.getColor ("RadioButton.foreground")); - radioButton.setIcon (UIManager.getIcon ("RadioButton.icon")); - radioButton.setSelectedIcon (UIManager.getIcon ("RadioButton.selectedIcon")); - } + JRadioButton radioButton = (JRadioButton) c; + radioButton.setFont(UIManager.getFont("RadioButton.font")); + radioButton.setBackground(UIManager.getColor("RadioButton.background")); + radioButton.setForeground(UIManager.getColor("RadioButton.foreground")); + radioButton.setIcon(UIManager.getIcon("RadioButton.icon")); + radioButton.setSelectedIcon(UIManager.getIcon("RadioButton.selectedIcon")); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java index 819966e6e..f91149d75 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java @@ -17,47 +17,47 @@ public class MaterialScrollBarUI extends BasicScrollBarUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialScrollBarUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JScrollBar scrollBar = (JScrollBar) c; - scrollBar.setFont (UIManager.getFont ("ScrollBar.font")); - trackColor = UIManager.getColor ("ScrollBar.track"); - thumbColor = UIManager.getColor ("ScrollBar.thumb"); - thumbDarkShadowColor = UIManager.getColor ("ScrollBar.thumbDarkShadow"); - thumbHighlightColor = UIManager.getColor ("ScrollBar.thumbHighlight"); - thumbLightShadowColor = UIManager.getColor ("ScrollBar.thumbShadow"); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } - - @Override - protected JButton createDecreaseButton (int orientation) { - JButton button = new BasicArrowButton (orientation); - - button.setOpaque (true); - button.setBackground (UIManager.getColor ("ScrollBar.arrowButtonBackground")); - button.setBorder (UIManager.getBorder ("ScrollBar.arrowButtonBorder")); - - return button; - } - - @Override - protected JButton createIncreaseButton (int orientation) { - JButton button = new BasicArrowButton (orientation); - - button.setOpaque (true); - button.setBackground (UIManager.getColor ("ScrollBar.arrowButtonBackground")); - button.setBorder (UIManager.getBorder ("ScrollBar.arrowButtonBorder")); - - return button; - } + public static ComponentUI createUI(JComponent c) { + return new MaterialScrollBarUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JScrollBar scrollBar = (JScrollBar) c; + scrollBar.setFont(UIManager.getFont("ScrollBar.font")); + trackColor = UIManager.getColor("ScrollBar.track"); + thumbColor = UIManager.getColor("ScrollBar.thumb"); + thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow"); + thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight"); + thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow"); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } + + @Override + protected JButton createDecreaseButton(int orientation) { + JButton button = new BasicArrowButton(orientation); + + button.setOpaque(true); + button.setBackground(UIManager.getColor("ScrollBar.arrowButtonBackground")); + button.setBorder(UIManager.getBorder("ScrollBar.arrowButtonBorder")); + + return button; + } + + @Override + protected JButton createIncreaseButton(int orientation) { + JButton button = new BasicArrowButton(orientation); + + button.setOpaque(true); + button.setBackground(UIManager.getColor("ScrollBar.arrowButtonBackground")); + button.setBorder(UIManager.getBorder("ScrollBar.arrowButtonBorder")); + + return button; + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java index a9fe9ee2c..05cd5b60e 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java @@ -9,17 +9,17 @@ public class MaterialSeparatorUI extends BasicSeparatorUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialSeparatorUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialSeparatorUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); - } + @Override + public void installUI(JComponent c) { + super.installUI(c); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java index 6c0427cd5..ab9d75484 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java @@ -14,115 +14,115 @@ //TODO cambio grafica slider public class MaterialSliderUI extends BasicSliderUI { - private static final int NORMAL_THUMB_RADIUS = 6; - private static final int DRAG_THUMB_RADIUS = 10; - private static final Dimension THUMB_SIZE = new Dimension (DRAG_THUMB_RADIUS * 2, DRAG_THUMB_RADIUS * 2); - - public MaterialSliderUI (JSlider slider) { - super (slider); - } - - public static ComponentUI createUI (JComponent c) { - return new MaterialSliderUI ((JSlider) c); - } - - private static void drawCircle (Graphics g, int x, int y, int radius) { - g.fillOval (x - radius, y - radius, radius * 2, radius * 2); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JSlider slider = (JSlider) c; - slider.setFont (UIManager.getFont ("Slider.font")); - slider.setBackground (UIManager.getColor ("Slider.background")); - slider.setForeground (UIManager.getColor ("Slider.foreground")); - slider.setBorder (UIManager.getBorder ("Slider.border")); - } - - @Override - public Dimension getThumbSize () { - return THUMB_SIZE; - } - - @Override - public void paintThumb (Graphics g) { - g = MaterialDrawingUtils.getAliasedGraphics (g); - - int cx = thumbRect.x + thumbRect.width / 2; - int cy = thumbRect.y + thumbRect.height / 2; - - if (isDragging ()) { - g.setColor (MaterialColors.bleach (slider.getForeground (), 0.5f)); - drawCircle (g, cx, cy, DRAG_THUMB_RADIUS); - } - - g.setColor (slider.getForeground ()); - drawCircle (g, cx, cy, NORMAL_THUMB_RADIUS); - - // need to redraw loaded part of progress line - Line loaded = getTrack (true); - g.drawLine (loaded.x1, loaded.y1, loaded.x2, loaded.y2); - } - - @Override - public void paintTrack (Graphics g) { - g = MaterialDrawingUtils.getAliasedGraphics (g); - - g.setColor (UIManager.getColor ("Slider.trackColor")); - Line unloaded = getTrack (false); - g.drawLine (unloaded.x1, unloaded.y1, unloaded.x2, unloaded.y2); - - g.setColor (slider.getForeground ()); - Line loaded = getTrack (true); - g.drawLine (loaded.x1, loaded.y1, loaded.x2, loaded.y2); - } - - private Line getTrack (boolean loaded) { - if (slider.getOrientation () == JSlider.HORIZONTAL) { - Line left = new Line (trackRect.x, thumbRect.y + thumbRect.height / 2, thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2); - Line right = new Line (thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2, trackRect.x + trackRect.width, thumbRect.y + thumbRect.height / 2); - - if (loaded) { - return slider.getInverted () ? right : left; - } - else { - return slider.getInverted () ? left : right; - } - } - else { - Line top = new Line (thumbRect.x + thumbRect.width / 2, trackRect.y, thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2); - Line bottom = new Line (thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2, thumbRect.x + thumbRect.width / 2, trackRect.y + trackRect.height); - - if (loaded) { - return slider.getInverted () ? top : bottom; - } - else { - return slider.getInverted () ? bottom : top; - } - } - } - - @Override - public void paintFocus (Graphics g) { - - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } - - private static class Line { - - int x1, y1, x2, y2; - - Line (int x1, int y1, int x2, int y2) { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - } + private static final int NORMAL_THUMB_RADIUS = 6; + private static final int DRAG_THUMB_RADIUS = 10; + private static final Dimension THUMB_SIZE = new Dimension(DRAG_THUMB_RADIUS * 2, DRAG_THUMB_RADIUS * 2); + + public MaterialSliderUI(JSlider slider) { + super(slider); + } + + public static ComponentUI createUI(JComponent c) { + return new MaterialSliderUI((JSlider) c); + } + + private static void drawCircle(Graphics g, int x, int y, int radius) { + g.fillOval(x - radius, y - radius, radius * 2, radius * 2); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JSlider slider = (JSlider) c; + slider.setFont(UIManager.getFont("Slider.font")); + slider.setBackground(UIManager.getColor("Slider.background")); + slider.setForeground(UIManager.getColor("Slider.foreground")); + slider.setBorder(UIManager.getBorder("Slider.border")); + } + + @Override + public Dimension getThumbSize() { + return THUMB_SIZE; + } + + @Override + public void paintThumb(Graphics g) { + g = MaterialDrawingUtils.getAliasedGraphics(g); + + int cx = thumbRect.x + thumbRect.width / 2; + int cy = thumbRect.y + thumbRect.height / 2; + + if (isDragging()) { + g.setColor(MaterialColors.bleach(slider.getForeground(), 0.5f)); + drawCircle(g, cx, cy, DRAG_THUMB_RADIUS); + } + + g.setColor(slider.getForeground()); + drawCircle(g, cx, cy, NORMAL_THUMB_RADIUS); + + // need to redraw loaded part of progress line + Line loaded = getTrack(true); + g.drawLine(loaded.x1, loaded.y1, loaded.x2, loaded.y2); + } + + @Override + public void paintTrack(Graphics g) { + g = MaterialDrawingUtils.getAliasedGraphics(g); + + g.setColor(UIManager.getColor("Slider.trackColor")); + Line unloaded = getTrack(false); + g.drawLine(unloaded.x1, unloaded.y1, unloaded.x2, unloaded.y2); + + g.setColor(slider.getForeground()); + Line loaded = getTrack(true); + g.drawLine(loaded.x1, loaded.y1, loaded.x2, loaded.y2); + } + + private Line getTrack(boolean loaded) { + if (slider.getOrientation() == JSlider.HORIZONTAL) { + Line left = new Line(trackRect.x, thumbRect.y + thumbRect.height / 2, thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2); + Line right = new Line(thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2, trackRect.x + trackRect.width, thumbRect.y + thumbRect.height / 2); + + if (loaded) { + return slider.getInverted() ? right : left; + } + else { + return slider.getInverted() ? left : right; + } + } + else { + Line top = new Line(thumbRect.x + thumbRect.width / 2, trackRect.y, thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2); + Line bottom = new Line(thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2, thumbRect.x + thumbRect.width / 2, trackRect.y + trackRect.height); + + if (loaded) { + return slider.getInverted() ? top : bottom; + } + else { + return slider.getInverted() ? bottom : top; + } + } + } + + @Override + public void paintFocus(Graphics g) { + + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } + + private static class Line { + + int x1, y1, x2, y2; + + Line(int x1, int y1, int x2, int y2) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java index da590cd7e..5b6a7e175 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java @@ -16,69 +16,69 @@ public class MaterialSpinnerUI extends BasicSpinnerUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialSpinnerUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialSpinnerUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JSpinner spinner = (JSpinner) c; - spinner.setOpaque (false); - spinner.setFont (UIManager.getFont ("Spinner.font")); - spinner.setBackground (UIManager.getColor ("Spinner.background")); - spinner.setForeground (UIManager.getColor ("Spinner.foreground")); - spinner.setBorder (UIManager.getBorder ("Spinner.border")); - } + JSpinner spinner = (JSpinner) c; + spinner.setOpaque(false); + spinner.setFont(UIManager.getFont("Spinner.font")); + spinner.setBackground(UIManager.getColor("Spinner.background")); + spinner.setForeground(UIManager.getColor("Spinner.foreground")); + spinner.setBorder(UIManager.getBorder("Spinner.border")); + } - @Override - protected JComponent createEditor () { - JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) super.createEditor (); - editor.getTextField ().setUI (new MaterialTextFieldUI (false)); + @Override + protected JComponent createEditor() { + JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) super.createEditor(); + editor.getTextField().setUI(new MaterialTextFieldUI(false)); - return editor; - } + return editor; + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } - @Override - protected Component createNextButton () { - Icon icon = UIManager.getIcon ("Spinner.nextButtonIcon"); - JButton button; - if (icon != null) { - button = new JButton (icon); - } - else { - button = new BasicArrowButton (SwingConstants.NORTH); - } - button.setOpaque (true); - button.setBackground (UIManager.getColor ("Spinner.arrowButtonBackground")); - button.setBorder (UIManager.getBorder ("Spinner.arrowButtonBorder")); - installNextButtonListeners (button); + @Override + protected Component createNextButton() { + Icon icon = UIManager.getIcon("Spinner.nextButtonIcon"); + JButton button; + if (icon != null) { + button = new JButton(icon); + } + else { + button = new BasicArrowButton(SwingConstants.NORTH); + } + button.setOpaque(true); + button.setBackground(UIManager.getColor("Spinner.arrowButtonBackground")); + button.setBorder(UIManager.getBorder("Spinner.arrowButtonBorder")); + installNextButtonListeners(button); - return button; - } + return button; + } - @Override - protected Component createPreviousButton () { - Icon icon = UIManager.getIcon ("Spinner.previousButtonIcon"); - JButton button; - if (icon != null) { - button = new JButton (icon); - } - else { - button = new BasicArrowButton (SwingConstants.SOUTH); - } + @Override + protected Component createPreviousButton() { + Icon icon = UIManager.getIcon("Spinner.previousButtonIcon"); + JButton button; + if (icon != null) { + button = new JButton(icon); + } + else { + button = new BasicArrowButton(SwingConstants.SOUTH); + } - button.setOpaque (true); - button.setBackground (UIManager.getColor ("Spinner.arrowButtonBackground")); - button.setBorder (UIManager.getBorder ("Spinner.arrowButtonBorder")); - installPreviousButtonListeners (button); + button.setOpaque(true); + button.setBackground(UIManager.getColor("Spinner.arrowButtonBackground")); + button.setBorder(UIManager.getBorder("Spinner.arrowButtonBorder")); + installPreviousButtonListeners(button); - return button; - } + return button; + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java index 92cb3c95d..90bd79b5e 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java @@ -5,11 +5,11 @@ public class MaterialSplitPaneUI extends BasicSplitPaneUI { @Override - public void installUI (JComponent c) { - super.installUI (c); + public void installUI(JComponent c) { + super.installUI(c); JSplitPane splitPane = (JSplitPane) c; - splitPane.setOpaque (false); + splitPane.setOpaque(false); splitPane.setBorder(UIManager.getBorder("SplitPane.border")); splitPane.setBackground(UIManager.getColor("SplitPane.background")); splitPane.setDividerSize(UIManager.getInt("SplitPane.dividerSize")); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java index 216c72d99..0441cca35 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java @@ -12,51 +12,51 @@ public class MaterialTabbedPaneUI extends BasicTabbedPaneUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialTabbedPaneUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JTabbedPane tabbedPane = (JTabbedPane) c; - tabbedPane.setOpaque (false); - tabbedPane.setFont (UIManager.getFont ("TabbedPane.font")); - tabbedPane.setBackground (UIManager.getColor ("TabbedPane.background")); - tabbedPane.setForeground (UIManager.getColor ("TabbedPane.foreground")); - tabbedPane.setBorder (UIManager.getBorder ("TabbedPane.border")); - - darkShadow = UIManager.getColor ("TabbedPane.darkShadow"); - shadow = UIManager.getColor ("TabbedPane.shadow"); - lightHighlight = UIManager.getColor ("TabbedPane.highlight"); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } - - @Override - protected void paintTabBackground (Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { - g.setColor (isSelected ? lightHighlight : tabPane.getBackground ()); - g.fillRect (x, y, w, h); - } - - @Override - protected void paintTabBorder (Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { - g.setColor (UIManager.getColor ("TabbedPane.borderHighlightColor")); - g.drawRect (x, y, w, h); - } - - @Override - protected void paintFocusIndicator (Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) { - // do nothing - } - - @Override - protected void paintTab (Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { - // for some reason tabs aren't painted properly by paint() - super.paintTab (MaterialDrawingUtils.getAliasedGraphics (g), tabPlacement, rects, tabIndex, iconRect, textRect); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialTabbedPaneUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JTabbedPane tabbedPane = (JTabbedPane) c; + tabbedPane.setOpaque(false); + tabbedPane.setFont(UIManager.getFont("TabbedPane.font")); + tabbedPane.setBackground(UIManager.getColor("TabbedPane.background")); + tabbedPane.setForeground(UIManager.getColor("TabbedPane.foreground")); + tabbedPane.setBorder(UIManager.getBorder("TabbedPane.border")); + + darkShadow = UIManager.getColor("TabbedPane.darkShadow"); + shadow = UIManager.getColor("TabbedPane.shadow"); + lightHighlight = UIManager.getColor("TabbedPane.highlight"); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } + + @Override + protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { + g.setColor(isSelected ? lightHighlight : tabPane.getBackground()); + g.fillRect(x, y, w, h); + } + + @Override + protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { + g.setColor(UIManager.getColor("TabbedPane.borderHighlightColor")); + g.drawRect(x, y, w, h); + } + + @Override + protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) { + // do nothing + } + + @Override + protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { + // for some reason tabs aren't painted properly by paint() + super.paintTab(MaterialDrawingUtils.getAliasedGraphics(g), tabPlacement, rects, tabIndex, iconRect, textRect); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java index b2e28cf89..329102fbe 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java @@ -7,22 +7,22 @@ public class MaterialTableCellEditor extends DefaultCellEditor { - public MaterialTableCellEditor () { - super (init ()); - } + public MaterialTableCellEditor() { + super(init()); + } - private static JTextField init () { - JTextField textField = new JTextField (); - textField.setUI (new MaterialTextFieldUI (false)); + private static JTextField init() { + JTextField textField = new JTextField(); + textField.setUI(new MaterialTextFieldUI(false)); - return textField; - } + return textField; + } - @Override - public Component getTableCellEditorComponent (JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) { - JTextField textField = (JTextField) super.getTableCellEditorComponent (table, value, isSelected, rowIndex, vColIndex); - textField.setText (value.toString ()); + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) { + JTextField textField = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, rowIndex, vColIndex); + textField.setText(value.toString()); - return textField; - } + return textField; + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java index 43ac2aef3..86c76e005 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java @@ -9,16 +9,16 @@ public class MaterialTableCellRenderer extends DefaultTableCellRenderer { - @Override - public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JComponent component = (JComponent) super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column); + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JComponent component = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - // hides yellow selection highlight - component.setBorder (BorderFactory.createEmptyBorder ()); + // hides yellow selection highlight + component.setBorder(BorderFactory.createEmptyBorder()); - this.setHorizontalAlignment (SwingConstants.CENTER); - this.setVerticalAlignment (SwingConstants.CENTER); + this.setHorizontalAlignment(SwingConstants.CENTER); + this.setVerticalAlignment(SwingConstants.CENTER); - return component; - } + return component; + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java index f5d38ced4..2cdfb0fa9 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java @@ -9,16 +9,16 @@ public class MaterialTableHeaderCellRenderer extends DefaultTableCellRenderer { - @Override - public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JComponent component = (JComponent) super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column); - component.setBorder (UIManager.getBorder ("TableHeader.cellBorder")); - component.setFont (UIManager.getFont ("TableHeader.font")); - component.setBackground (UIManager.getColor ("TableHeader.background")); + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JComponent component = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + component.setBorder(UIManager.getBorder("TableHeader.cellBorder")); + component.setFont(UIManager.getFont("TableHeader.font")); + component.setBackground(UIManager.getColor("TableHeader.background")); - this.setHorizontalAlignment (SwingConstants.CENTER); - this.setVerticalAlignment (SwingConstants.CENTER); + this.setHorizontalAlignment(SwingConstants.CENTER); + this.setVerticalAlignment(SwingConstants.CENTER); - return component; - } + return component; + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java index cb6f80a9f..82144615b 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java @@ -10,20 +10,20 @@ public class MaterialTableHeaderUI extends BasicTableHeaderUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialTableHeaderUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialTableHeaderUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); + @Override + public void installUI(JComponent c) { + super.installUI(c); - JTableHeader header = (JTableHeader) c; - header.setDefaultRenderer (new MaterialTableHeaderCellRenderer ()); - } + JTableHeader header = (JTableHeader) c; + header.setDefaultRenderer(new MaterialTableHeaderCellRenderer()); + } - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java index de34f98e5..dc0b82a34 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java @@ -11,38 +11,38 @@ public class MaterialTableUI extends BasicTableUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialTableUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JTable table = (JTable) c; - table.setOpaque (false); - table.setSelectionForeground (UIManager.getColor ("Table.selectionForeground")); - table.setBackground (UIManager.getColor ("Table.background")); - table.setFont (UIManager.getFont ("Table.font")); - table.setBorder (UIManager.getBorder ("Table.border")); - table.setGridColor (UIManager.getColor ("Table.gridColor")); - table.setSelectionBackground (UIManager.getColor ("Table.selectionBackground")); - - table.getTableHeader ().setResizingAllowed (true); - int rowHeight = UIManager.getInt ("Table.rowHeight"); - if (rowHeight > 0) { - table.setRowHeight (rowHeight); - } - else { - table.setRowHeight (table.getRowHeight () + 25); - } - - table.setDefaultRenderer (Object.class, new MaterialTableCellRenderer ()); - table.setDefaultEditor (Object.class, new MaterialTableCellEditor ()); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialTableUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JTable table = (JTable) c; + table.setOpaque(false); + table.setSelectionForeground(UIManager.getColor("Table.selectionForeground")); + table.setBackground(UIManager.getColor("Table.background")); + table.setFont(UIManager.getFont("Table.font")); + table.setBorder(UIManager.getBorder("Table.border")); + table.setGridColor(UIManager.getColor("Table.gridColor")); + table.setSelectionBackground(UIManager.getColor("Table.selectionBackground")); + + table.getTableHeader().setResizingAllowed(true); + int rowHeight = UIManager.getInt("Table.rowHeight"); + if (rowHeight > 0) { + table.setRowHeight(rowHeight); + } + else { + table.setRowHeight(table.getRowHeight() + 25); + } + + table.setDefaultRenderer(Object.class, new MaterialTableCellRenderer()); + table.setDefaultEditor(Object.class, new MaterialTableCellEditor()); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java index 79d06415c..019c4b047 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java @@ -25,171 +25,171 @@ public class MaterialTextFieldUI extends BasicTextFieldUI implements FocusListener, PropertyChangeListener { - private Color focusedBackground; - private Color unfocusedBackground; - private Color focusedSelectionBackground; - private Color unfocusedSelectionBackground; - private boolean drawLine; - - public MaterialTextFieldUI () { - this (true); - } - - public MaterialTextFieldUI (boolean drawLine) { - super (); - this.drawLine = drawLine; - } - - public static ComponentUI createUI (JComponent c) { - return new MaterialTextFieldUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JTextField textField = (JTextField) c; - textField.setOpaque (false); - textField.setBorder (drawLine ? - BorderFactory.createEmptyBorder (5, 2, 10, 0) : - BorderFactory.createEmptyBorder (2, 2, 2, 2)); - - textField.setBackground (MaterialColors.LIGHT_BLUE_400); - textField.setFont (MaterialFonts.REGULAR); - - this.focusedBackground = textField.getBackground (); - this.unfocusedBackground = MaterialColors.GRAY_200; - - this.focusedSelectionBackground = MaterialColors.bleach (focusedBackground, 0.3f); - this.unfocusedSelectionBackground = unfocusedBackground; - } - - @Override - protected void installListeners () { - super.installListeners (); - getComponent ().addFocusListener (this); - getComponent ().addPropertyChangeListener (this); - } - - @Override - protected void installKeyboardActions () { - super.installKeyboardActions (); - - Action selectAll = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().selectAll (); - } - }; - - Action delete = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - if (getComponent ().getSelectedText () == null) { - int pos = getComponent ().getCaretPosition () - 1; - - if (pos >= 0) { - getComponent ().select (pos, pos + 1); - getComponent ().replaceSelection (""); - } - } - else { - getComponent ().replaceSelection (""); - } - } - }; - - Action left = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().setCaretPosition (Math.max (0, getComponent ().getCaretPosition () - 1)); - } - }; - - Action right = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().setCaretPosition (Math.min (getComponent ().getText ().length (), getComponent ().getCaretPosition () + 1)); - } - }; - - Action enter = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - ((JTextField) getComponent ()).postActionEvent (); - } - }; - - // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_A, Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask ()), "selectAll"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_BACK_SPACE, 0), "delete"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_LEFT, 0), "left"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_RIGHT, 0), "right"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_ENTER, 0), "enter"); - - getComponent ().getActionMap ().put ("selectAll", selectAll); - getComponent ().getActionMap ().put ("delete", delete); - getComponent ().getActionMap ().put ("left", left); - getComponent ().getActionMap ().put ("right", right); - getComponent ().getActionMap ().put ("enter", enter); - } - - @Override - public void paintSafely (Graphics g) { - JTextField c = (JTextField) getComponent (); - g = MaterialDrawingUtils.getAliasedGraphics (g); - - Color lineColor; - - if (getComponent ().hasFocus ()) { - lineColor = focusedBackground; - c.setSelectionColor (focusedSelectionBackground); - } - else { - lineColor = unfocusedBackground; - c.setSelectionColor (unfocusedSelectionBackground); - } - - g.setColor (lineColor); - getComponent ().setBackground (lineColor); - - if (drawLine) { - int x = getComponent ().getInsets ().left; - int y = getComponent ().getInsets ().top; - int w = getComponent ().getWidth () - getComponent ().getInsets ().left - getComponent ().getInsets ().right; - - g.fillRect (x, c.getHeight () - y, w, 2); - } - - super.paintSafely (g); - } - - @Override - public void paintBackground (final Graphics g) { - super.paintBackground (MaterialDrawingUtils.getAliasedGraphics (g)); - } - - @Override - public void focusGained (FocusEvent e) { - e.getComponent ().setBackground (focusedBackground); - } - - @Override - public void focusLost (FocusEvent e) { - e.getComponent ().setBackground (unfocusedBackground); - } - - @Override - public void propertyChange (PropertyChangeEvent pce) { - super.propertyChange (pce); - - if (pce.getPropertyName ().equals ("background")) { - Color newColor = (Color) pce.getNewValue (); - - if (!newColor.equals (focusedBackground) && !newColor.equals (unfocusedBackground)) { - this.focusedBackground = (Color) pce.getNewValue (); - this.focusedSelectionBackground = MaterialColors.bleach (this.focusedBackground, 0.3f); - } - } - } + private Color focusedBackground; + private Color unfocusedBackground; + private Color focusedSelectionBackground; + private Color unfocusedSelectionBackground; + private boolean drawLine; + + public MaterialTextFieldUI() { + this(true); + } + + public MaterialTextFieldUI(boolean drawLine) { + super(); + this.drawLine = drawLine; + } + + public static ComponentUI createUI(JComponent c) { + return new MaterialTextFieldUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JTextField textField = (JTextField) c; + textField.setOpaque(false); + textField.setBorder(drawLine ? + BorderFactory.createEmptyBorder(5, 2, 10, 0) : + BorderFactory.createEmptyBorder(2, 2, 2, 2)); + + textField.setBackground(MaterialColors.LIGHT_BLUE_400); + textField.setFont(MaterialFonts.REGULAR); + + this.focusedBackground = textField.getBackground(); + this.unfocusedBackground = MaterialColors.GRAY_200; + + this.focusedSelectionBackground = MaterialColors.bleach(focusedBackground, 0.3f); + this.unfocusedSelectionBackground = unfocusedBackground; + } + + @Override + protected void installListeners() { + super.installListeners(); + getComponent().addFocusListener(this); + getComponent().addPropertyChangeListener(this); + } + + @Override + protected void installKeyboardActions() { + super.installKeyboardActions(); + + Action selectAll = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().selectAll(); + } + }; + + Action delete = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (getComponent().getSelectedText() == null) { + int pos = getComponent().getCaretPosition() - 1; + + if (pos >= 0) { + getComponent().select(pos, pos + 1); + getComponent().replaceSelection(""); + } + } + else { + getComponent().replaceSelection(""); + } + } + }; + + Action left = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().setCaretPosition(Math.max(0, getComponent().getCaretPosition() - 1)); + } + }; + + Action right = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().setCaretPosition(Math.min(getComponent().getText().length(), getComponent().getCaretPosition() + 1)); + } + }; + + Action enter = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + ((JTextField) getComponent()).postActionEvent(); + } + }; + + // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "selectAll"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "left"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "right"); + getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); + + getComponent().getActionMap().put("selectAll", selectAll); + getComponent().getActionMap().put("delete", delete); + getComponent().getActionMap().put("left", left); + getComponent().getActionMap().put("right", right); + getComponent().getActionMap().put("enter", enter); + } + + @Override + public void paintSafely(Graphics g) { + JTextField c = (JTextField) getComponent(); + g = MaterialDrawingUtils.getAliasedGraphics(g); + + Color lineColor; + + if (getComponent().hasFocus()) { + lineColor = focusedBackground; + c.setSelectionColor(focusedSelectionBackground); + } + else { + lineColor = unfocusedBackground; + c.setSelectionColor(unfocusedSelectionBackground); + } + + g.setColor(lineColor); + getComponent().setBackground(lineColor); + + if (drawLine) { + int x = getComponent().getInsets().left; + int y = getComponent().getInsets().top; + int w = getComponent().getWidth() - getComponent().getInsets().left - getComponent().getInsets().right; + + g.fillRect(x, c.getHeight() - y, w, 2); + } + + super.paintSafely(g); + } + + @Override + public void paintBackground(final Graphics g) { + super.paintBackground(MaterialDrawingUtils.getAliasedGraphics(g)); + } + + @Override + public void focusGained(FocusEvent e) { + e.getComponent().setBackground(focusedBackground); + } + + @Override + public void focusLost(FocusEvent e) { + e.getComponent().setBackground(unfocusedBackground); + } + + @Override + public void propertyChange(PropertyChangeEvent pce) { + super.propertyChange(pce); + + if (pce.getPropertyName().equals("background")) { + Color newColor = (Color) pce.getNewValue(); + + if (!newColor.equals(focusedBackground) && !newColor.equals(unfocusedBackground)) { + this.focusedBackground = (Color) pce.getNewValue(); + this.focusedSelectionBackground = MaterialColors.bleach(this.focusedBackground, 0.3f); + } + } + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java index 40f061a9b..2adea67b2 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java @@ -10,12 +10,12 @@ public class MaterialTextPaneUI extends BasicTextPaneUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialTextPaneUI (); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialTextPaneUI(); + } - @Override - public void installUI (JComponent c) { - super.installUI (c); - } + @Override + public void installUI(JComponent c) { + super.installUI(c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java index 3dd7f5592..928b2e688 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java @@ -11,28 +11,28 @@ public class MaterialToggleButtonUI extends BasicToggleButtonUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialToggleButtonUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JToggleButton toggleButton = (JToggleButton) c; - toggleButton.setBorder (UIManager.getBorder ("ToggleButton.border")); - toggleButton.setFont (UIManager.getFont ("ToggleButton.font")); - toggleButton.setBackground (UIManager.getColor ("ToggleButton.background")); - toggleButton.setForeground (UIManager.getColor ("ToggleButton.foreground")); - - if (toggleButton.getIcon () == null && toggleButton.getSelectedIcon () == null) { - toggleButton.setIcon (UIManager.getIcon ("ToggleButton.icon")); - toggleButton.setSelectedIcon (UIManager.getIcon ("ToggleButton.selectedIcon")); - } - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialToggleButtonUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JToggleButton toggleButton = (JToggleButton) c; + toggleButton.setBorder(UIManager.getBorder("ToggleButton.border")); + toggleButton.setFont(UIManager.getFont("ToggleButton.font")); + toggleButton.setBackground(UIManager.getColor("ToggleButton.background")); + toggleButton.setForeground(UIManager.getColor("ToggleButton.foreground")); + + if (toggleButton.getIcon() == null && toggleButton.getSelectedIcon() == null) { + toggleButton.setIcon(UIManager.getIcon("ToggleButton.icon")); + toggleButton.setSelectedIcon(UIManager.getIcon("ToggleButton.selectedIcon")); + } + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java index 354c4f7ed..d95d52455 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java @@ -11,28 +11,28 @@ public class MaterialToolBarUI extends BasicToolBarUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialToolBarUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - JToolBar toolBar = (JToolBar) c; - - toolBar.setFont (UIManager.getFont ("ToolBar.font")); - toolBar.setBackground (UIManager.getColor ("ToolBar.background")); - toolBar.setForeground (UIManager.getColor ("ToolBar.foreground")); - toolBar.setBorder (UIManager.getBorder ("ToolBar.border")); - - this.dockingBorderColor = null; - this.floatingBorderColor = null; - this.dockingColor = UIManager.getColor ("ToolBar.dockingBackground"); - this.floatingColor = UIManager.getColor ("ToolBar.floatingBackground"); - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialToolBarUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + JToolBar toolBar = (JToolBar) c; + + toolBar.setFont(UIManager.getFont("ToolBar.font")); + toolBar.setBackground(UIManager.getColor("ToolBar.background")); + toolBar.setForeground(UIManager.getColor("ToolBar.foreground")); + toolBar.setBorder(UIManager.getBorder("ToolBar.border")); + + this.dockingBorderColor = null; + this.floatingBorderColor = null; + this.dockingColor = UIManager.getColor("ToolBar.dockingBackground"); + this.floatingColor = UIManager.getColor("ToolBar.floatingBackground"); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java index 7b1da941c..adbd78925 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java @@ -9,7 +9,7 @@ public class MaterialToolTipUI extends BasicToolTipUI { - public static ComponentUI createUI(JComponent c){ + public static ComponentUI createUI(JComponent c) { return new MaterialToolTipUI(); } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java index c157e9e4f..6ac2230f4 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java @@ -11,39 +11,40 @@ public class MaterialTreeCellEditor extends DefaultTreeCellEditor { - private JTextField textField; - - public MaterialTreeCellEditor (JTree tree, DefaultTreeCellRenderer renderer) { - super (tree, renderer); - init (); - } - - public MaterialTreeCellEditor (JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { - super (tree, renderer, editor); - init (); - } - - private void init () { - textField = new JTextField (); - textField.setUI (new MaterialTextFieldUI ()); - - textField.addKeyListener (new KeyAdapter () { - @Override - public void keyTyped (KeyEvent e) { - if (e.getKeyChar () == KeyEvent.VK_ENTER) - stopCellEditing (); - } - }); - } - - @Override - public Component getTreeCellEditorComponent (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { - textField.setText (value.toString ()); - return textField; - } - - @Override - public Object getCellEditorValue () { - return textField.getText (); - } + private JTextField textField; + + public MaterialTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) { + super(tree, renderer); + init(); + } + + public MaterialTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { + super(tree, renderer, editor); + init(); + } + + private void init() { + textField = new JTextField(); + textField.setUI(new MaterialTextFieldUI()); + + textField.addKeyListener(new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + stopCellEditing(); + } + } + }); + } + + @Override + public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { + textField.setText(value.toString()); + return textField; + } + + @Override + public Object getCellEditorValue() { + return textField.getText(); + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java index 0e2f55325..f9ddcbf45 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java @@ -9,28 +9,28 @@ public class MaterialTreeCellRenderer extends DefaultTreeCellRenderer { - public MaterialTreeCellRenderer () { - setTextSelectionColor (UIManager.getColor ("Tree.selectionForeground")); - setTextNonSelectionColor (UIManager.getColor ("Tree.foreground")); + public MaterialTreeCellRenderer() { + setTextSelectionColor(UIManager.getColor("Tree.selectionForeground")); + setTextNonSelectionColor(UIManager.getColor("Tree.foreground")); - setBackgroundSelectionColor (UIManager.getColor ("Tree.selectionBackground")); - setBackgroundNonSelectionColor (UIManager.getColor ("Tree.background")); + setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground")); + setBackgroundNonSelectionColor(UIManager.getColor("Tree.background")); - setBorderSelectionColor (UIManager.getColor ("Tree.selectionBorderColor")); + setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor")); - setClosedIcon (UIManager.getIcon ("Tree.closedIcon")); - setOpenIcon (UIManager.getIcon ("Tree.openIcon")); - setLeafIcon (null); + setClosedIcon(UIManager.getIcon("Tree.closedIcon")); + setOpenIcon(UIManager.getIcon("Tree.openIcon")); + setLeafIcon(null); - setFont (UIManager.getFont ("Tree.font")); - } + setFont(UIManager.getFont("Tree.font")); + } - @Override - public Component getTreeCellRendererComponent (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - JComponent component = (JComponent) super.getTreeCellRendererComponent (tree, value, isSelected, expanded, leaf, row, hasFocus); - component.setBorder (BorderFactory.createEmptyBorder (5, 2, 5, 2)); + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { + JComponent component = (JComponent) super.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, hasFocus); + component.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2)); - return component; - } + return component; + } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java index 4354eb20d..b1b9839bd 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java @@ -13,33 +13,33 @@ public class MaterialTreeUI extends BasicTreeUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialTreeUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - JTree tree = (JTree) c; - - DefaultTreeCellRenderer renderer = new MaterialTreeCellRenderer (); - TreeCellEditor editor = new MaterialTreeCellEditor (tree, renderer); - - tree.setCellRenderer (renderer); - tree.setCellEditor (editor); - - tree.setFont (UIManager.getFont ("Tree.font")); - tree.setRowHeight (0); - tree.setInvokesStopCellEditing (true); - - MaterialTreeUI ui = (MaterialTreeUI) tree.getUI (); - ui.setLeftChildIndent (10); - ui.setRightChildIndent (10); - } - - @Override - public void paint (Graphics g, JComponent c) { - g = MaterialDrawingUtils.getAliasedGraphics (g); - super.paint (g, c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialTreeUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + JTree tree = (JTree) c; + + DefaultTreeCellRenderer renderer = new MaterialTreeCellRenderer(); + TreeCellEditor editor = new MaterialTreeCellEditor(tree, renderer); + + tree.setCellRenderer(renderer); + tree.setCellEditor(editor); + + tree.setFont(UIManager.getFont("Tree.font")); + tree.setRowHeight(0); + tree.setInvokesStopCellEditing(true); + + MaterialTreeUI ui = (MaterialTreeUI) tree.getUI(); + ui.setLeftChildIndent(10); + ui.setRightChildIndent(10); + } + + @Override + public void paint(Graphics g, JComponent c) { + g = MaterialDrawingUtils.getAliasedGraphics(g); + super.paint(g, c); + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java index 153d72652..0d3a2a5d6 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java @@ -30,7 +30,7 @@ public class DropShadowBorder extends AbstractBorder implements Border { private static final Map> CACHE - = new HashMap> (); + = new HashMap>(); private Color lineColor; private int lineWidth; private int shadowSize; @@ -41,21 +41,21 @@ public class DropShadowBorder extends AbstractBorder implements Border { private boolean showBottomShadow; private boolean showRightShadow; - public DropShadowBorder () { - this (UIManager.getColor ("Control"), 1, 5); + public DropShadowBorder() { + this(UIManager.getColor("Control"), 1, 5); } - public DropShadowBorder (Color lineColor, int lineWidth, int shadowSize) { - this (lineColor, lineWidth, shadowSize, .5f, 12, false, false, true, true); + public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize) { + this(lineColor, lineWidth, shadowSize, .5f, 12, false, false, true, true); } - public DropShadowBorder (Color lineColor, int lineWidth, boolean showLeftShadow) { - this (lineColor, lineWidth, 5, .5f, 12, false, showLeftShadow, true, true); + public DropShadowBorder(Color lineColor, int lineWidth, boolean showLeftShadow) { + this(lineColor, lineWidth, 5, .5f, 12, false, showLeftShadow, true, true); } - public DropShadowBorder (Color lineColor, int lineWidth, int shadowSize, - float shadowOpacity, int cornerSize, boolean showTopShadow, - boolean showLeftShadow, boolean showBottomShadow, boolean showRightShadow) { + public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize, + float shadowOpacity, int cornerSize, boolean showTopShadow, + boolean showLeftShadow, boolean showBottomShadow, boolean showRightShadow) { this.lineColor = lineColor; this.lineWidth = lineWidth; this.shadowSize = shadowSize; @@ -70,12 +70,12 @@ public DropShadowBorder (Color lineColor, int lineWidth, int shadowSize, /** * @inheritDoc */ - public void paintBorder (Component c, Graphics graphics, int x, int y, int width, int height) { + public void paintBorder(Component c, Graphics graphics, int x, int y, int width, int height) { /* * 1) Get images for this border * 2) Paint the images for each side of the border that should be painted */ - Map images = getImages (null); + Map images = getImages(null); //compute the edges of the components -- not including the border //Insets borderInsets = getBorderInsets (c); @@ -84,7 +84,7 @@ public void paintBorder (Component c, Graphics graphics, int x, int y, int width // int topEdge = y + borderInsets.top - lineWidth; // int bottomEdge = y + height - borderInsets.bottom; Graphics2D g2 = (Graphics2D) graphics; - g2.setColor (lineColor); + g2.setColor(lineColor); //The location and size of the shadows depends on which shadows are being //drawn. For instance, if the left & bottom shadows are being drawn, then @@ -95,100 +95,116 @@ public void paintBorder (Component c, Graphics graphics, int x, int y, int width Point topLeftShadowPoint = null; if (showLeftShadow || showTopShadow) { - topLeftShadowPoint = new Point (); + topLeftShadowPoint = new Point(); if (showLeftShadow && !showTopShadow) { - topLeftShadowPoint.setLocation (x, y + shadowSize); + topLeftShadowPoint.setLocation(x, y + shadowSize); } - else if (showLeftShadow && showTopShadow) { - topLeftShadowPoint.setLocation (x, y); - } - else if (!showLeftShadow && showTopShadow) { - topLeftShadowPoint.setLocation (x + shadowSize, y); + else { + if (showLeftShadow && showTopShadow) { + topLeftShadowPoint.setLocation(x, y); + } + else { + if (!showLeftShadow && showTopShadow) { + topLeftShadowPoint.setLocation(x + shadowSize, y); + } + } } } Point bottomLeftShadowPoint = null; if (showLeftShadow || showBottomShadow) { - bottomLeftShadowPoint = new Point (); + bottomLeftShadowPoint = new Point(); if (showLeftShadow && !showBottomShadow) { - bottomLeftShadowPoint.setLocation (x, y + height - shadowSize - shadowSize); - } - else if (showLeftShadow && showBottomShadow) { - bottomLeftShadowPoint.setLocation (x, y + height - shadowSize); + bottomLeftShadowPoint.setLocation(x, y + height - shadowSize - shadowSize); } - else if (!showLeftShadow && showBottomShadow) { - bottomLeftShadowPoint.setLocation (x + shadowSize, y + height - shadowSize); + else { + if (showLeftShadow && showBottomShadow) { + bottomLeftShadowPoint.setLocation(x, y + height - shadowSize); + } + else { + if (!showLeftShadow && showBottomShadow) { + bottomLeftShadowPoint.setLocation(x + shadowSize, y + height - shadowSize); + } + } } } Point bottomRightShadowPoint = null; if (showRightShadow || showBottomShadow) { - bottomRightShadowPoint = new Point (); + bottomRightShadowPoint = new Point(); if (showRightShadow && !showBottomShadow) { - bottomRightShadowPoint.setLocation (x + width - shadowSize, y + height - shadowSize - shadowSize); + bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize - shadowSize); } - else if (showRightShadow && showBottomShadow) { - bottomRightShadowPoint.setLocation (x + width - shadowSize, y + height - shadowSize); - } - else if (!showRightShadow && showBottomShadow) { - bottomRightShadowPoint.setLocation (x + width - shadowSize - shadowSize, y + height - shadowSize); + else { + if (showRightShadow && showBottomShadow) { + bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize); + } + else { + if (!showRightShadow && showBottomShadow) { + bottomRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y + height - shadowSize); + } + } } } Point topRightShadowPoint = null; if (showRightShadow || showTopShadow) { - topRightShadowPoint = new Point (); + topRightShadowPoint = new Point(); if (showRightShadow && !showTopShadow) { - topRightShadowPoint.setLocation (x + width - shadowSize, y + shadowSize); - } - else if (showRightShadow && showTopShadow) { - topRightShadowPoint.setLocation (x + width - shadowSize, y); + topRightShadowPoint.setLocation(x + width - shadowSize, y + shadowSize); } - else if (!showRightShadow && showTopShadow) { - topRightShadowPoint.setLocation (x + width - shadowSize - shadowSize, y); + else { + if (showRightShadow && showTopShadow) { + topRightShadowPoint.setLocation(x + width - shadowSize, y); + } + else { + if (!showRightShadow && showTopShadow) { + topRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y); + } + } } } if (showLeftShadow) { - Rectangle leftShadowRect = new Rectangle (x, (int) (topLeftShadowPoint.getY () + shadowSize), shadowSize, (int) (bottomLeftShadowPoint.getY () - topLeftShadowPoint.getY () - shadowSize)); - g2.drawImage (images.get (Position.LEFT).getScaledInstance (leftShadowRect.width, leftShadowRect.height, Image.SCALE_FAST), leftShadowRect.x, leftShadowRect.y, null); + Rectangle leftShadowRect = new Rectangle(x, (int) (topLeftShadowPoint.getY() + shadowSize), shadowSize, (int) (bottomLeftShadowPoint.getY() - topLeftShadowPoint.getY() - shadowSize)); + g2.drawImage(images.get(Position.LEFT).getScaledInstance(leftShadowRect.width, leftShadowRect.height, Image.SCALE_FAST), leftShadowRect.x, leftShadowRect.y, null); } if (showBottomShadow) { - Rectangle bottomShadowRect = new Rectangle ((int) (bottomLeftShadowPoint.getX () + shadowSize), y + height - shadowSize, (int) (bottomRightShadowPoint.getX () - bottomLeftShadowPoint.getX () - shadowSize), shadowSize); - g2.drawImage (images.get (Position.BOTTOM).getScaledInstance (bottomShadowRect.width, bottomShadowRect.height, Image.SCALE_FAST), bottomShadowRect.x, bottomShadowRect.y, null); + Rectangle bottomShadowRect = new Rectangle((int) (bottomLeftShadowPoint.getX() + shadowSize), y + height - shadowSize, (int) (bottomRightShadowPoint.getX() - bottomLeftShadowPoint.getX() - shadowSize), shadowSize); + g2.drawImage(images.get(Position.BOTTOM).getScaledInstance(bottomShadowRect.width, bottomShadowRect.height, Image.SCALE_FAST), bottomShadowRect.x, bottomShadowRect.y, null); } if (showRightShadow) { - Rectangle rightShadowRect = new Rectangle (x + width - shadowSize, (int) (topRightShadowPoint.getY () + shadowSize), shadowSize, (int) (bottomRightShadowPoint.getY () - topRightShadowPoint.getY () - shadowSize)); - g2.drawImage (images.get (Position.RIGHT).getScaledInstance (rightShadowRect.width, rightShadowRect.height, Image.SCALE_FAST), rightShadowRect.x, rightShadowRect.y, null); + Rectangle rightShadowRect = new Rectangle(x + width - shadowSize, (int) (topRightShadowPoint.getY() + shadowSize), shadowSize, (int) (bottomRightShadowPoint.getY() - topRightShadowPoint.getY() - shadowSize)); + g2.drawImage(images.get(Position.RIGHT).getScaledInstance(rightShadowRect.width, rightShadowRect.height, Image.SCALE_FAST), rightShadowRect.x, rightShadowRect.y, null); } if (showTopShadow) { - Rectangle topShadowRect = new Rectangle ((int) topLeftShadowPoint.getX () + shadowSize, y, (int) (topRightShadowPoint.getX () - topLeftShadowPoint.getX () - shadowSize), shadowSize); - g2.drawImage (images.get (Position.TOP).getScaledInstance (topShadowRect.width, topShadowRect.height, Image.SCALE_FAST), topShadowRect.x, topShadowRect.y, null); + Rectangle topShadowRect = new Rectangle((int) topLeftShadowPoint.getX() + shadowSize, y, (int) (topRightShadowPoint.getX() - topLeftShadowPoint.getX() - shadowSize), shadowSize); + g2.drawImage(images.get(Position.TOP).getScaledInstance(topShadowRect.width, topShadowRect.height, Image.SCALE_FAST), topShadowRect.x, topShadowRect.y, null); } if (showLeftShadow || showTopShadow) { - g2.drawImage (images.get (Position.TOP_LEFT), null, (int) topLeftShadowPoint.getX (), (int) topLeftShadowPoint.getY ()); + g2.drawImage(images.get(Position.TOP_LEFT), null, (int) topLeftShadowPoint.getX(), (int) topLeftShadowPoint.getY()); } if (showLeftShadow || showBottomShadow) { - g2.drawImage (images.get (Position.BOTTOM_LEFT), null, (int) bottomLeftShadowPoint.getX (), (int) bottomLeftShadowPoint.getY ()); + g2.drawImage(images.get(Position.BOTTOM_LEFT), null, (int) bottomLeftShadowPoint.getX(), (int) bottomLeftShadowPoint.getY()); } if (showRightShadow || showBottomShadow) { - g2.drawImage (images.get (Position.BOTTOM_RIGHT), null, (int) bottomRightShadowPoint.getX (), (int) bottomRightShadowPoint.getY ()); + g2.drawImage(images.get(Position.BOTTOM_RIGHT), null, (int) bottomRightShadowPoint.getX(), (int) bottomRightShadowPoint.getY()); } if (showRightShadow || showTopShadow) { - g2.drawImage (images.get (Position.TOP_RIGHT), null, (int) topRightShadowPoint.getX (), (int) topRightShadowPoint.getY ()); + g2.drawImage(images.get(Position.TOP_RIGHT), null, (int) topRightShadowPoint.getX(), (int) topRightShadowPoint.getY()); } } - private Map getImages (Graphics2D g2) { + private Map getImages(Graphics2D g2) { //first, check to see if an image for this size has already been rendered //if so, use the cache. Else, draw and save - Map images = CACHE.get (shadowSize); + Map images = CACHE.get(shadowSize); if (images == null) { - images = new HashMap (); + images = new HashMap(); /* * Do draw a drop shadows, I have to: @@ -205,69 +221,69 @@ private Map getImages (Graphics2D g2) { * drawing the Border */ int rectWidth = cornerSize + 1; - RoundRectangle2D rect = new RoundRectangle2D.Double (0, 0, rectWidth, rectWidth, cornerSize, cornerSize); + RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, rectWidth, rectWidth, cornerSize, cornerSize); int imageWidth = rectWidth + shadowSize * 2; - BufferedImage image = new BufferedImage (imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); - Graphics2D buffer = (Graphics2D) image.getGraphics (); - buffer.setRenderingHint (RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - buffer.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - buffer.setRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - buffer.setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - buffer.setColor (new Color (0.0f, 0.0f, 0.0f, shadowOpacity)); - buffer.translate (shadowSize, shadowSize); - buffer.fill (rect); + BufferedImage image = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); + Graphics2D buffer = (Graphics2D) image.getGraphics(); + buffer.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + buffer.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + buffer.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + buffer.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + buffer.setColor(new Color(0.0f, 0.0f, 0.0f, shadowOpacity)); + buffer.translate(shadowSize, shadowSize); + buffer.fill(rect); float blurry = 1.0f / (float) (shadowSize * shadowSize);//1.0f / (float)(shadowSize * shadowSize); float[] blurKernel = new float[shadowSize * shadowSize]; for (int i = 0; i < blurKernel.length; i++) { blurKernel[i] = blurry; } - ConvolveOp blur = new ConvolveOp (new Kernel (shadowSize, shadowSize, blurKernel)); - BufferedImage targetImage = new BufferedImage (imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); - ((Graphics2D) targetImage.getGraphics ()).drawImage (image, blur, -(shadowSize / 2), -(shadowSize / 2)); + ConvolveOp blur = new ConvolveOp(new Kernel(shadowSize, shadowSize, blurKernel)); + BufferedImage targetImage = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); + ((Graphics2D) targetImage.getGraphics()).drawImage(image, blur, -(shadowSize / 2), -(shadowSize / 2)); int x = 1; int y = 1; int w = shadowSize; int h = shadowSize; - images.put (Position.TOP_LEFT, targetImage.getSubimage (x, y, w, h)); + images.put(Position.TOP_LEFT, targetImage.getSubimage(x, y, w, h)); x = 1; y = h; w = shadowSize; h = 1; - images.put (Position.LEFT, targetImage.getSubimage (x, y, w, h)); + images.put(Position.LEFT, targetImage.getSubimage(x, y, w, h)); x = 1; y = rectWidth; w = shadowSize; h = shadowSize; - images.put (Position.BOTTOM_LEFT, targetImage.getSubimage (x, y, w, h)); + images.put(Position.BOTTOM_LEFT, targetImage.getSubimage(x, y, w, h)); x = cornerSize + 1; y = rectWidth; w = 1; h = shadowSize; - images.put (Position.BOTTOM, targetImage.getSubimage (x, y, w, h)); + images.put(Position.BOTTOM, targetImage.getSubimage(x, y, w, h)); x = rectWidth; y = x; w = shadowSize; h = shadowSize; - images.put (Position.BOTTOM_RIGHT, targetImage.getSubimage (x, y, w, h)); + images.put(Position.BOTTOM_RIGHT, targetImage.getSubimage(x, y, w, h)); x = rectWidth; y = cornerSize + 1; w = shadowSize; h = 1; - images.put (Position.RIGHT, targetImage.getSubimage (x, y, w, h)); + images.put(Position.RIGHT, targetImage.getSubimage(x, y, w, h)); x = rectWidth; y = 1; w = shadowSize; h = shadowSize; - images.put (Position.TOP_RIGHT, targetImage.getSubimage (x, y, w, h)); + images.put(Position.TOP_RIGHT, targetImage.getSubimage(x, y, w, h)); x = shadowSize; y = 1; w = 1; h = shadowSize; - images.put (Position.TOP, targetImage.getSubimage (x, y, w, h)); + images.put(Position.TOP, targetImage.getSubimage(x, y, w, h)); - buffer.dispose (); - image.flush (); + buffer.dispose(); + image.flush(); } return images; } @@ -275,55 +291,55 @@ private Map getImages (Graphics2D g2) { /** * @inheritDoc */ - public Insets getBorderInsets (Component c) { + public Insets getBorderInsets(Component c) { int top = 4 + (showTopShadow ? lineWidth + shadowSize : lineWidth); int left = 4 + (showLeftShadow ? lineWidth + shadowSize : lineWidth); int bottom = 4 + (showBottomShadow ? lineWidth + shadowSize : lineWidth); int right = 4 + (showRightShadow ? lineWidth + shadowSize : lineWidth); - return new Insets (top, left, bottom, right); + return new Insets(top, left, bottom, right); } /** * @inheritDoc */ - public boolean isBorderOpaque () { + public boolean isBorderOpaque() { return true; } - public boolean isShowTopShadow () { + public boolean isShowTopShadow() { return showTopShadow; } - public boolean isShowLeftShadow () { + public boolean isShowLeftShadow() { return showLeftShadow; } - public boolean isShowRightShadow () { + public boolean isShowRightShadow() { return showRightShadow; } - public boolean isShowBottomShadow () { + public boolean isShowBottomShadow() { return showBottomShadow; } - public int getLineWidth () { + public int getLineWidth() { return lineWidth; } - public Color getLineColor () { + public Color getLineColor() { return lineColor; } - public int getShadowSize () { + public int getShadowSize() { return shadowSize; } - public float getShadowOpacity () { + public float getShadowOpacity() { return shadowOpacity; } - public int getCornerSize () { + public int getCornerSize() { return cornerSize; } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java index 728e192fe..c78d20e34 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java @@ -6,11 +6,12 @@ public class MaterialBorders { - public static final Border LIGHT_LINE_BORDER = BorderFactory.createLineBorder (MaterialColors.GRAY_200, 1); - public static final Border THICK_LINE_BORDER = BorderFactory.createLineBorder (MaterialColors.GRAY_200, 2); + public static final Border LIGHT_LINE_BORDER = BorderFactory.createLineBorder(MaterialColors.GRAY_200, 1); + public static final Border THICK_LINE_BORDER = BorderFactory.createLineBorder(MaterialColors.GRAY_200, 2); - public static final Border LIGHT_SHADOW_BORDER = new DropShadowBorder (Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); - public static final Border DEFAULT_SHADOW_BORDER = new DropShadowBorder (Color.BLACK, 5, 5, 0.3f, 12, true, true, true, true); + public static final Border LIGHT_SHADOW_BORDER = new DropShadowBorder(Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); + public static final Border DEFAULT_SHADOW_BORDER = new DropShadowBorder(Color.BLACK, 5, 5, 0.3f, 12, true, true, true, true); - private MaterialBorders () {} + private MaterialBorders() { + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java index afeccf46d..30229b936 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java @@ -3,270 +3,271 @@ import java.awt.*; public class MaterialColors { - public static final Color RED_50 = new Color (255, 235, 238); - public static final Color RED_100 = new Color (255, 205, 210); - public static final Color RED_200 = new Color (239, 154, 154); - public static final Color RED_300 = new Color (229, 115, 115); - public static final Color RED_400 = new Color (239, 83, 80); - public static final Color RED_500 = new Color (244, 67, 54); - public static final Color RED_600 = new Color (229, 57, 53); - public static final Color RED_700 = new Color (211, 47, 47); - public static final Color RED_800 = new Color (198, 40, 40); - public static final Color RED_900 = new Color (183, 28, 28); - public static final Color RED_A100 = new Color (255, 138, 128); - public static final Color RED_A200 = new Color (255, 82, 82); - public static final Color RED_A400 = new Color (255, 23, 68); - public static final Color RED_A700 = new Color (213, 0, 0); - public static final Color PINK_50 = new Color (252, 228, 236); - public static final Color PINK_100 = new Color (248, 187, 208); - public static final Color PINK_200 = new Color (244, 143, 177); - public static final Color PINK_300 = new Color (240, 98, 146); - public static final Color PINK_400 = new Color (236, 64, 122); - public static final Color PINK_500 = new Color (233, 30, 99); - public static final Color PINK_600 = new Color (216, 27, 96); - public static final Color PINK_700 = new Color (194, 24, 91); - public static final Color PINK_800 = new Color (173, 20, 87); - public static final Color PINK_900 = new Color (136, 14, 79); - public static final Color PINK_A100 = new Color (255, 128, 171); - public static final Color PINK_A200 = new Color (255, 64, 129); - public static final Color PINK_A400 = new Color (245, 0, 87); - public static final Color PINK_A700 = new Color (197, 17, 98); - public static final Color PURPLE_50 = new Color (243, 229, 245); - public static final Color PURPLE_100 = new Color (225, 190, 231); - public static final Color PURPLE_200 = new Color (206, 147, 216); - public static final Color PURPLE_300 = new Color (186, 104, 200); - public static final Color PURPLE_400 = new Color (171, 71, 188); - public static final Color PURPLE_500 = new Color (156, 39, 176); - public static final Color PURPLE_600 = new Color (142, 36, 170); - public static final Color PURPLE_700 = new Color (123, 31, 162); - public static final Color PURPLE_800 = new Color (106, 27, 154); - public static final Color PURPLE_900 = new Color (74, 20, 140); - public static final Color PURPLE_A100 = new Color (234, 128, 252); - public static final Color PURPLE_A200 = new Color (224, 64, 251); - public static final Color PURPLE_A400 = new Color (213, 0, 249); - public static final Color PURPLE_A700 = new Color (170, 0, 255); - public static final Color DEEP_PURPLE_50 = new Color (237, 231, 246); - public static final Color DEEP_PURPLE_100 = new Color (209, 196, 233); - public static final Color DEEP_PURPLE_200 = new Color (179, 157, 219); - public static final Color DEEP_PURPLE_300 = new Color (149, 117, 205); - public static final Color DEEP_PURPLE_400 = new Color (126, 87, 194); - public static final Color DEEP_PURPLE_500 = new Color (103, 58, 183); - public static final Color DEEP_PURPLE_600 = new Color (94, 53, 177); - public static final Color DEEP_PURPLE_700 = new Color (81, 45, 168); - public static final Color DEEP_PURPLE_800 = new Color (69, 39, 160); - public static final Color DEEP_PURPLE_900 = new Color (49, 27, 146); - public static final Color DEEP_PURPLE_A100 = new Color (179, 136, 255); - public static final Color DEEP_PURPLE_A200 = new Color (124, 77, 255); - public static final Color DEEP_PURPLE_A400 = new Color (101, 31, 255); - public static final Color DEEP_PURPLE_A700 = new Color (98, 0, 234); - public static final Color INDIGO_50 = new Color (232, 234, 246); - public static final Color INDIGO_100 = new Color (197, 202, 233); - public static final Color INDIGO_200 = new Color (159, 168, 218); - public static final Color INDIGO_300 = new Color (121, 134, 203); - public static final Color INDIGO_400 = new Color (92, 107, 192); - public static final Color INDIGO_500 = new Color (63, 81, 181); - public static final Color INDIGO_600 = new Color (57, 73, 171); - public static final Color INDIGO_700 = new Color (48, 63, 159); - public static final Color INDIGO_800 = new Color (40, 53, 147); - public static final Color INDIGO_900 = new Color (26, 35, 126); - public static final Color INDIGO_A100 = new Color (140, 158, 255); - public static final Color INDIGO_A200 = new Color (83, 109, 254); - public static final Color INDIGO_A400 = new Color (61, 90, 254); - public static final Color INDIGO_A700 = new Color (48, 79, 254); - public static final Color BLUE_50 = new Color (227, 242, 253); - public static final Color BLUE_100 = new Color (187, 222, 251); - public static final Color BLUE_200 = new Color (144, 202, 249); - public static final Color BLUE_300 = new Color (100, 181, 246); - public static final Color BLUE_400 = new Color (66, 165, 245); - public static final Color BLUE_500 = new Color (33, 150, 243); - public static final Color BLUE_600 = new Color (30, 136, 229); - public static final Color BLUE_700 = new Color (25, 118, 210); - public static final Color BLUE_800 = new Color (21, 101, 192); - public static final Color BLUE_900 = new Color (13, 71, 161); - public static final Color BLUE_A100 = new Color (130, 177, 255); - public static final Color BLUE_A200 = new Color (68, 138, 255); - public static final Color BLUE_A400 = new Color (41, 121, 255); - public static final Color BLUE_A700 = new Color (41, 98, 255); - public static final Color LIGHT_BLUE_50 = new Color (225, 245, 254); - public static final Color LIGHT_BLUE_100 = new Color (179, 229, 252); - public static final Color LIGHT_BLUE_200 = new Color (129, 212, 250); - public static final Color LIGHT_BLUE_300 = new Color (79, 195, 247); - public static final Color LIGHT_BLUE_400 = new Color (41, 182, 246); - public static final Color LIGHT_BLUE_500 = new Color (3, 169, 244); - public static final Color LIGHT_BLUE_600 = new Color (3, 155, 229); - public static final Color LIGHT_BLUE_700 = new Color (2, 136, 209); - public static final Color LIGHT_BLUE_800 = new Color (2, 119, 189); - public static final Color LIGHT_BLUE_900 = new Color (1, 87, 155); - public static final Color LIGHT_BLUE_A100 = new Color (128, 216, 255); - public static final Color LIGHT_BLUE_A200 = new Color (64, 196, 255); - public static final Color LIGHT_BLUE_A400 = new Color (0, 176, 255); - public static final Color LIGHT_BLUE_A700 = new Color (0, 145, 234); - public static final Color CYAN_50 = new Color (224, 247, 250); - public static final Color CYAN_100 = new Color (178, 235, 242); - public static final Color CYAN_200 = new Color (128, 222, 234); - public static final Color CYAN_300 = new Color (77, 208, 225); - public static final Color CYAN_400 = new Color (38, 198, 218); - public static final Color CYAN_500 = new Color (0, 188, 212); - public static final Color CYAN_600 = new Color (0, 172, 193); - public static final Color CYAN_700 = new Color (0, 151, 167); - public static final Color CYAN_800 = new Color (0, 131, 143); - public static final Color CYAN_900 = new Color (0, 96, 100); - public static final Color CYAN_A100 = new Color (132, 255, 255); - public static final Color CYAN_A200 = new Color (24, 255, 255); - public static final Color CYAN_A400 = new Color (0, 229, 255); - public static final Color CYAN_A700 = new Color (0, 184, 212); - public static final Color TEAL_50 = new Color (224, 242, 241); - public static final Color TEAL_100 = new Color (178, 223, 219); - public static final Color TEAL_200 = new Color (128, 203, 196); - public static final Color TEAL_300 = new Color (77, 182, 172); - public static final Color TEAL_400 = new Color (38, 166, 154); - public static final Color TEAL_500 = new Color (0, 150, 136); - public static final Color TEAL_600 = new Color (0, 137, 123); - public static final Color TEAL_700 = new Color (0, 121, 107); - public static final Color TEAL_800 = new Color (0, 105, 92); - public static final Color TEAL_900 = new Color (0, 77, 64); - public static final Color TEAL_A100 = new Color (167, 255, 235); - public static final Color TEAL_A200 = new Color (100, 255, 218); - public static final Color TEAL_A400 = new Color (29, 233, 182); - public static final Color TEAL_A700 = new Color (0, 191, 165); - public static final Color GREEN_50 = new Color (232, 245, 233); - public static final Color GREEN_100 = new Color (200, 230, 201); - public static final Color GREEN_200 = new Color (165, 214, 167); - public static final Color GREEN_300 = new Color (129, 199, 132); - public static final Color GREEN_400 = new Color (102, 187, 106); - public static final Color GREEN_500 = new Color (76, 175, 80); - public static final Color GREEN_600 = new Color (67, 160, 71); - public static final Color GREEN_700 = new Color (56, 142, 60); - public static final Color GREEN_800 = new Color (46, 125, 50); - public static final Color GREEN_900 = new Color (27, 94, 32); - public static final Color GREEN_A100 = new Color (185, 246, 202); - public static final Color GREEN_A200 = new Color (105, 240, 174); - public static final Color GREEN_A400 = new Color (0, 230, 118); - public static final Color GREEN_A700 = new Color (0, 200, 83); - public static final Color LIGHT_GREEN_50 = new Color (241, 248, 233); - public static final Color LIGHT_GREEN_100 = new Color (220, 237, 200); - public static final Color LIGHT_GREEN_200 = new Color (197, 225, 165); - public static final Color LIGHT_GREEN_300 = new Color (174, 213, 129); - public static final Color LIGHT_GREEN_400 = new Color (156, 204, 101); - public static final Color LIGHT_GREEN_500 = new Color (139, 195, 74); - public static final Color LIGHT_GREEN_600 = new Color (124, 179, 66); - public static final Color LIGHT_GREEN_700 = new Color (104, 159, 56); - public static final Color LIGHT_GREEN_800 = new Color (85, 139, 47); - public static final Color LIGHT_GREEN_900 = new Color (51, 105, 30); - public static final Color LIGHT_GREEN_A100 = new Color (204, 255, 144); - public static final Color LIGHT_GREEN_A200 = new Color (178, 255, 89); - public static final Color LIGHT_GREEN_A400 = new Color (118, 255, 3); - public static final Color LIGHT_GREEN_A700 = new Color (100, 221, 23); - public static final Color LIME_50 = new Color (249, 251, 231); - public static final Color LIME_100 = new Color (240, 244, 195); - public static final Color LIME_200 = new Color (230, 238, 156); - public static final Color LIME_300 = new Color (220, 231, 117); - public static final Color LIME_400 = new Color (212, 225, 87); - public static final Color LIME_500 = new Color (205, 220, 57); - public static final Color LIME_600 = new Color (192, 202, 51); - public static final Color LIME_700 = new Color (175, 180, 43); - public static final Color LIME_800 = new Color (158, 157, 36); - public static final Color LIME_900 = new Color (130, 119, 23); - public static final Color LIME_A100 = new Color (244, 255, 129); - public static final Color LIME_A200 = new Color (238, 255, 65); - public static final Color LIME_A400 = new Color (198, 255, 0); - public static final Color LIME_A700 = new Color (174, 234, 0); - public static final Color YELLOW_50 = new Color (255, 253, 231); - public static final Color YELLOW_100 = new Color (255, 249, 196); - public static final Color YELLOW_200 = new Color (255, 245, 157); - public static final Color YELLOW_300 = new Color (255, 241, 118); - public static final Color YELLOW_400 = new Color (255, 238, 88); - public static final Color YELLOW_500 = new Color (255, 235, 59); - public static final Color YELLOW_600 = new Color (253, 216, 53); - public static final Color YELLOW_700 = new Color (251, 192, 45); - public static final Color YELLOW_800 = new Color (249, 168, 37); - public static final Color YELLOW_900 = new Color (245, 127, 23); - public static final Color YELLOW_A100 = new Color (255, 255, 141); - public static final Color YELLOW_A200 = new Color (255, 255, 0); - public static final Color YELLOW_A400 = new Color (255, 234, 0); - public static final Color YELLOW_A700 = new Color (255, 214, 0); - public static final Color AMBER_50 = new Color (255, 248, 225); - public static final Color AMBER_100 = new Color (255, 236, 179); - public static final Color AMBER_200 = new Color (255, 224, 130); - public static final Color AMBER_300 = new Color (255, 213, 79); - public static final Color AMBER_400 = new Color (255, 202, 40); - public static final Color AMBER_500 = new Color (255, 193, 7); - public static final Color AMBER_600 = new Color (255, 179, 0); - public static final Color AMBER_700 = new Color (255, 160, 0); - public static final Color AMBER_800 = new Color (255, 143, 0); - public static final Color AMBER_900 = new Color (255, 111, 0); - public static final Color AMBER_A100 = new Color (255, 229, 127); - public static final Color AMBER_A200 = new Color (255, 215, 64); - public static final Color AMBER_A400 = new Color (255, 196, 0); - public static final Color AMBER_A700 = new Color (255, 171, 0); - public static final Color ORANGE_50 = new Color (255, 243, 224); - public static final Color ORANGE_100 = new Color (255, 224, 178); - public static final Color ORANGE_200 = new Color (255, 204, 128); - public static final Color ORANGE_300 = new Color (255, 183, 77); - public static final Color ORANGE_400 = new Color (255, 167, 38); - public static final Color ORANGE_500 = new Color (255, 152, 0); - public static final Color ORANGE_600 = new Color (251, 140, 0); - public static final Color ORANGE_700 = new Color (245, 124, 0); - public static final Color ORANGE_800 = new Color (239, 108, 0); - public static final Color ORANGE_900 = new Color (230, 81, 0); - public static final Color ORANGE_A100 = new Color (255, 209, 128); - public static final Color ORANGE_A200 = new Color (255, 171, 64); - public static final Color ORANGE_A400 = new Color (255, 145, 0); - public static final Color ORANGE_A700 = new Color (255, 109, 0); - public static final Color DEEP_ORANGE_50 = new Color (251, 233, 231); - public static final Color DEEP_ORANGE_100 = new Color (255, 204, 188); - public static final Color DEEP_ORANGE_200 = new Color (255, 171, 145); - public static final Color DEEP_ORANGE_300 = new Color (255, 138, 101); - public static final Color DEEP_ORANGE_400 = new Color (255, 112, 67); - public static final Color DEEP_ORANGE_500 = new Color (255, 87, 34); - public static final Color DEEP_ORANGE_600 = new Color (244, 81, 30); - public static final Color DEEP_ORANGE_700 = new Color (230, 74, 25); - public static final Color DEEP_ORANGE_800 = new Color (216, 67, 21); - public static final Color DEEP_ORANGE_900 = new Color (191, 54, 12); - public static final Color DEEP_ORANGE_A100 = new Color (255, 158, 128); - public static final Color DEEP_ORANGE_A200 = new Color (255, 110, 64); - public static final Color DEEP_ORANGE_A400 = new Color (255, 61, 0); - public static final Color DEEP_ORANGE_A700 = new Color (221, 44, 0); - public static final Color BROWN_50 = new Color (239, 235, 233); - public static final Color BROWN_100 = new Color (215, 204, 200); - public static final Color BROWN_200 = new Color (188, 170, 164); - public static final Color BROWN_300 = new Color (161, 136, 127); - public static final Color BROWN_400 = new Color (141, 110, 99); - public static final Color BROWN_500 = new Color (121, 85, 72); - public static final Color BROWN_600 = new Color (109, 76, 65); - public static final Color BROWN_700 = new Color (93, 64, 55); - public static final Color BROWN_800 = new Color (78, 52, 46); - public static final Color BROWN_900 = new Color (62, 39, 35); - public static final Color GRAY_50 = new Color (250, 250, 250); - public static final Color GRAY_100 = new Color (245, 245, 245); - public static final Color GRAY_200 = new Color (238, 238, 238); - public static final Color GRAY_300 = new Color (224, 224, 224); - public static final Color GRAY_400 = new Color (189, 189, 189); - public static final Color GRAY_500 = new Color (158, 158, 158); - public static final Color GRAY_600 = new Color (117, 117, 117); - public static final Color GRAY_700 = new Color (97, 97, 97); - public static final Color GRAY_800 = new Color (66, 66, 66); - public static final Color GRAY_900 = new Color (33, 33, 33); - public static final Color BLUE_GRAY_50 = new Color (236, 239, 241); - public static final Color BLUE_GRAY_100 = new Color (207, 216, 220); - public static final Color BLUE_GRAY_200 = new Color (176, 190, 197); - public static final Color BLUE_GRAY_300 = new Color (144, 164, 174); - public static final Color BLUE_GRAY_400 = new Color (120, 144, 156); - public static final Color BLUE_GRAY_500 = new Color (96, 125, 139); - public static final Color BLUE_GRAY_600 = new Color (84, 110, 122); - public static final Color BLUE_GRAY_700 = new Color (69, 90, 100); - public static final Color BLUE_GRAY_800 = new Color (55, 71, 79); - public static final Color BLUE_GRAY_900 = new Color (38, 50, 56); - public static final Color BLACK = new Color (0, 0, 0); - public static final Color WHITE = new Color (255, 255, 255); - public static final Color TRANSPARENT = new Color(0,0,0,255); + public static final Color RED_50 = new Color(255, 235, 238); + public static final Color RED_100 = new Color(255, 205, 210); + public static final Color RED_200 = new Color(239, 154, 154); + public static final Color RED_300 = new Color(229, 115, 115); + public static final Color RED_400 = new Color(239, 83, 80); + public static final Color RED_500 = new Color(244, 67, 54); + public static final Color RED_600 = new Color(229, 57, 53); + public static final Color RED_700 = new Color(211, 47, 47); + public static final Color RED_800 = new Color(198, 40, 40); + public static final Color RED_900 = new Color(183, 28, 28); + public static final Color RED_A100 = new Color(255, 138, 128); + public static final Color RED_A200 = new Color(255, 82, 82); + public static final Color RED_A400 = new Color(255, 23, 68); + public static final Color RED_A700 = new Color(213, 0, 0); + public static final Color PINK_50 = new Color(252, 228, 236); + public static final Color PINK_100 = new Color(248, 187, 208); + public static final Color PINK_200 = new Color(244, 143, 177); + public static final Color PINK_300 = new Color(240, 98, 146); + public static final Color PINK_400 = new Color(236, 64, 122); + public static final Color PINK_500 = new Color(233, 30, 99); + public static final Color PINK_600 = new Color(216, 27, 96); + public static final Color PINK_700 = new Color(194, 24, 91); + public static final Color PINK_800 = new Color(173, 20, 87); + public static final Color PINK_900 = new Color(136, 14, 79); + public static final Color PINK_A100 = new Color(255, 128, 171); + public static final Color PINK_A200 = new Color(255, 64, 129); + public static final Color PINK_A400 = new Color(245, 0, 87); + public static final Color PINK_A700 = new Color(197, 17, 98); + public static final Color PURPLE_50 = new Color(243, 229, 245); + public static final Color PURPLE_100 = new Color(225, 190, 231); + public static final Color PURPLE_200 = new Color(206, 147, 216); + public static final Color PURPLE_300 = new Color(186, 104, 200); + public static final Color PURPLE_400 = new Color(171, 71, 188); + public static final Color PURPLE_500 = new Color(156, 39, 176); + public static final Color PURPLE_600 = new Color(142, 36, 170); + public static final Color PURPLE_700 = new Color(123, 31, 162); + public static final Color PURPLE_800 = new Color(106, 27, 154); + public static final Color PURPLE_900 = new Color(74, 20, 140); + public static final Color PURPLE_A100 = new Color(234, 128, 252); + public static final Color PURPLE_A200 = new Color(224, 64, 251); + public static final Color PURPLE_A400 = new Color(213, 0, 249); + public static final Color PURPLE_A700 = new Color(170, 0, 255); + public static final Color DEEP_PURPLE_50 = new Color(237, 231, 246); + public static final Color DEEP_PURPLE_100 = new Color(209, 196, 233); + public static final Color DEEP_PURPLE_200 = new Color(179, 157, 219); + public static final Color DEEP_PURPLE_300 = new Color(149, 117, 205); + public static final Color DEEP_PURPLE_400 = new Color(126, 87, 194); + public static final Color DEEP_PURPLE_500 = new Color(103, 58, 183); + public static final Color DEEP_PURPLE_600 = new Color(94, 53, 177); + public static final Color DEEP_PURPLE_700 = new Color(81, 45, 168); + public static final Color DEEP_PURPLE_800 = new Color(69, 39, 160); + public static final Color DEEP_PURPLE_900 = new Color(49, 27, 146); + public static final Color DEEP_PURPLE_A100 = new Color(179, 136, 255); + public static final Color DEEP_PURPLE_A200 = new Color(124, 77, 255); + public static final Color DEEP_PURPLE_A400 = new Color(101, 31, 255); + public static final Color DEEP_PURPLE_A700 = new Color(98, 0, 234); + public static final Color INDIGO_50 = new Color(232, 234, 246); + public static final Color INDIGO_100 = new Color(197, 202, 233); + public static final Color INDIGO_200 = new Color(159, 168, 218); + public static final Color INDIGO_300 = new Color(121, 134, 203); + public static final Color INDIGO_400 = new Color(92, 107, 192); + public static final Color INDIGO_500 = new Color(63, 81, 181); + public static final Color INDIGO_600 = new Color(57, 73, 171); + public static final Color INDIGO_700 = new Color(48, 63, 159); + public static final Color INDIGO_800 = new Color(40, 53, 147); + public static final Color INDIGO_900 = new Color(26, 35, 126); + public static final Color INDIGO_A100 = new Color(140, 158, 255); + public static final Color INDIGO_A200 = new Color(83, 109, 254); + public static final Color INDIGO_A400 = new Color(61, 90, 254); + public static final Color INDIGO_A700 = new Color(48, 79, 254); + public static final Color BLUE_50 = new Color(227, 242, 253); + public static final Color BLUE_100 = new Color(187, 222, 251); + public static final Color BLUE_200 = new Color(144, 202, 249); + public static final Color BLUE_300 = new Color(100, 181, 246); + public static final Color BLUE_400 = new Color(66, 165, 245); + public static final Color BLUE_500 = new Color(33, 150, 243); + public static final Color BLUE_600 = new Color(30, 136, 229); + public static final Color BLUE_700 = new Color(25, 118, 210); + public static final Color BLUE_800 = new Color(21, 101, 192); + public static final Color BLUE_900 = new Color(13, 71, 161); + public static final Color BLUE_A100 = new Color(130, 177, 255); + public static final Color BLUE_A200 = new Color(68, 138, 255); + public static final Color BLUE_A400 = new Color(41, 121, 255); + public static final Color BLUE_A700 = new Color(41, 98, 255); + public static final Color LIGHT_BLUE_50 = new Color(225, 245, 254); + public static final Color LIGHT_BLUE_100 = new Color(179, 229, 252); + public static final Color LIGHT_BLUE_200 = new Color(129, 212, 250); + public static final Color LIGHT_BLUE_300 = new Color(79, 195, 247); + public static final Color LIGHT_BLUE_400 = new Color(41, 182, 246); + public static final Color LIGHT_BLUE_500 = new Color(3, 169, 244); + public static final Color LIGHT_BLUE_600 = new Color(3, 155, 229); + public static final Color LIGHT_BLUE_700 = new Color(2, 136, 209); + public static final Color LIGHT_BLUE_800 = new Color(2, 119, 189); + public static final Color LIGHT_BLUE_900 = new Color(1, 87, 155); + public static final Color LIGHT_BLUE_A100 = new Color(128, 216, 255); + public static final Color LIGHT_BLUE_A200 = new Color(64, 196, 255); + public static final Color LIGHT_BLUE_A400 = new Color(0, 176, 255); + public static final Color LIGHT_BLUE_A700 = new Color(0, 145, 234); + public static final Color CYAN_50 = new Color(224, 247, 250); + public static final Color CYAN_100 = new Color(178, 235, 242); + public static final Color CYAN_200 = new Color(128, 222, 234); + public static final Color CYAN_300 = new Color(77, 208, 225); + public static final Color CYAN_400 = new Color(38, 198, 218); + public static final Color CYAN_500 = new Color(0, 188, 212); + public static final Color CYAN_600 = new Color(0, 172, 193); + public static final Color CYAN_700 = new Color(0, 151, 167); + public static final Color CYAN_800 = new Color(0, 131, 143); + public static final Color CYAN_900 = new Color(0, 96, 100); + public static final Color CYAN_A100 = new Color(132, 255, 255); + public static final Color CYAN_A200 = new Color(24, 255, 255); + public static final Color CYAN_A400 = new Color(0, 229, 255); + public static final Color CYAN_A700 = new Color(0, 184, 212); + public static final Color TEAL_50 = new Color(224, 242, 241); + public static final Color TEAL_100 = new Color(178, 223, 219); + public static final Color TEAL_200 = new Color(128, 203, 196); + public static final Color TEAL_300 = new Color(77, 182, 172); + public static final Color TEAL_400 = new Color(38, 166, 154); + public static final Color TEAL_500 = new Color(0, 150, 136); + public static final Color TEAL_600 = new Color(0, 137, 123); + public static final Color TEAL_700 = new Color(0, 121, 107); + public static final Color TEAL_800 = new Color(0, 105, 92); + public static final Color TEAL_900 = new Color(0, 77, 64); + public static final Color TEAL_A100 = new Color(167, 255, 235); + public static final Color TEAL_A200 = new Color(100, 255, 218); + public static final Color TEAL_A400 = new Color(29, 233, 182); + public static final Color TEAL_A700 = new Color(0, 191, 165); + public static final Color GREEN_50 = new Color(232, 245, 233); + public static final Color GREEN_100 = new Color(200, 230, 201); + public static final Color GREEN_200 = new Color(165, 214, 167); + public static final Color GREEN_300 = new Color(129, 199, 132); + public static final Color GREEN_400 = new Color(102, 187, 106); + public static final Color GREEN_500 = new Color(76, 175, 80); + public static final Color GREEN_600 = new Color(67, 160, 71); + public static final Color GREEN_700 = new Color(56, 142, 60); + public static final Color GREEN_800 = new Color(46, 125, 50); + public static final Color GREEN_900 = new Color(27, 94, 32); + public static final Color GREEN_A100 = new Color(185, 246, 202); + public static final Color GREEN_A200 = new Color(105, 240, 174); + public static final Color GREEN_A400 = new Color(0, 230, 118); + public static final Color GREEN_A700 = new Color(0, 200, 83); + public static final Color LIGHT_GREEN_50 = new Color(241, 248, 233); + public static final Color LIGHT_GREEN_100 = new Color(220, 237, 200); + public static final Color LIGHT_GREEN_200 = new Color(197, 225, 165); + public static final Color LIGHT_GREEN_300 = new Color(174, 213, 129); + public static final Color LIGHT_GREEN_400 = new Color(156, 204, 101); + public static final Color LIGHT_GREEN_500 = new Color(139, 195, 74); + public static final Color LIGHT_GREEN_600 = new Color(124, 179, 66); + public static final Color LIGHT_GREEN_700 = new Color(104, 159, 56); + public static final Color LIGHT_GREEN_800 = new Color(85, 139, 47); + public static final Color LIGHT_GREEN_900 = new Color(51, 105, 30); + public static final Color LIGHT_GREEN_A100 = new Color(204, 255, 144); + public static final Color LIGHT_GREEN_A200 = new Color(178, 255, 89); + public static final Color LIGHT_GREEN_A400 = new Color(118, 255, 3); + public static final Color LIGHT_GREEN_A700 = new Color(100, 221, 23); + public static final Color LIME_50 = new Color(249, 251, 231); + public static final Color LIME_100 = new Color(240, 244, 195); + public static final Color LIME_200 = new Color(230, 238, 156); + public static final Color LIME_300 = new Color(220, 231, 117); + public static final Color LIME_400 = new Color(212, 225, 87); + public static final Color LIME_500 = new Color(205, 220, 57); + public static final Color LIME_600 = new Color(192, 202, 51); + public static final Color LIME_700 = new Color(175, 180, 43); + public static final Color LIME_800 = new Color(158, 157, 36); + public static final Color LIME_900 = new Color(130, 119, 23); + public static final Color LIME_A100 = new Color(244, 255, 129); + public static final Color LIME_A200 = new Color(238, 255, 65); + public static final Color LIME_A400 = new Color(198, 255, 0); + public static final Color LIME_A700 = new Color(174, 234, 0); + public static final Color YELLOW_50 = new Color(255, 253, 231); + public static final Color YELLOW_100 = new Color(255, 249, 196); + public static final Color YELLOW_200 = new Color(255, 245, 157); + public static final Color YELLOW_300 = new Color(255, 241, 118); + public static final Color YELLOW_400 = new Color(255, 238, 88); + public static final Color YELLOW_500 = new Color(255, 235, 59); + public static final Color YELLOW_600 = new Color(253, 216, 53); + public static final Color YELLOW_700 = new Color(251, 192, 45); + public static final Color YELLOW_800 = new Color(249, 168, 37); + public static final Color YELLOW_900 = new Color(245, 127, 23); + public static final Color YELLOW_A100 = new Color(255, 255, 141); + public static final Color YELLOW_A200 = new Color(255, 255, 0); + public static final Color YELLOW_A400 = new Color(255, 234, 0); + public static final Color YELLOW_A700 = new Color(255, 214, 0); + public static final Color AMBER_50 = new Color(255, 248, 225); + public static final Color AMBER_100 = new Color(255, 236, 179); + public static final Color AMBER_200 = new Color(255, 224, 130); + public static final Color AMBER_300 = new Color(255, 213, 79); + public static final Color AMBER_400 = new Color(255, 202, 40); + public static final Color AMBER_500 = new Color(255, 193, 7); + public static final Color AMBER_600 = new Color(255, 179, 0); + public static final Color AMBER_700 = new Color(255, 160, 0); + public static final Color AMBER_800 = new Color(255, 143, 0); + public static final Color AMBER_900 = new Color(255, 111, 0); + public static final Color AMBER_A100 = new Color(255, 229, 127); + public static final Color AMBER_A200 = new Color(255, 215, 64); + public static final Color AMBER_A400 = new Color(255, 196, 0); + public static final Color AMBER_A700 = new Color(255, 171, 0); + public static final Color ORANGE_50 = new Color(255, 243, 224); + public static final Color ORANGE_100 = new Color(255, 224, 178); + public static final Color ORANGE_200 = new Color(255, 204, 128); + public static final Color ORANGE_300 = new Color(255, 183, 77); + public static final Color ORANGE_400 = new Color(255, 167, 38); + public static final Color ORANGE_500 = new Color(255, 152, 0); + public static final Color ORANGE_600 = new Color(251, 140, 0); + public static final Color ORANGE_700 = new Color(245, 124, 0); + public static final Color ORANGE_800 = new Color(239, 108, 0); + public static final Color ORANGE_900 = new Color(230, 81, 0); + public static final Color ORANGE_A100 = new Color(255, 209, 128); + public static final Color ORANGE_A200 = new Color(255, 171, 64); + public static final Color ORANGE_A400 = new Color(255, 145, 0); + public static final Color ORANGE_A700 = new Color(255, 109, 0); + public static final Color DEEP_ORANGE_50 = new Color(251, 233, 231); + public static final Color DEEP_ORANGE_100 = new Color(255, 204, 188); + public static final Color DEEP_ORANGE_200 = new Color(255, 171, 145); + public static final Color DEEP_ORANGE_300 = new Color(255, 138, 101); + public static final Color DEEP_ORANGE_400 = new Color(255, 112, 67); + public static final Color DEEP_ORANGE_500 = new Color(255, 87, 34); + public static final Color DEEP_ORANGE_600 = new Color(244, 81, 30); + public static final Color DEEP_ORANGE_700 = new Color(230, 74, 25); + public static final Color DEEP_ORANGE_800 = new Color(216, 67, 21); + public static final Color DEEP_ORANGE_900 = new Color(191, 54, 12); + public static final Color DEEP_ORANGE_A100 = new Color(255, 158, 128); + public static final Color DEEP_ORANGE_A200 = new Color(255, 110, 64); + public static final Color DEEP_ORANGE_A400 = new Color(255, 61, 0); + public static final Color DEEP_ORANGE_A700 = new Color(221, 44, 0); + public static final Color BROWN_50 = new Color(239, 235, 233); + public static final Color BROWN_100 = new Color(215, 204, 200); + public static final Color BROWN_200 = new Color(188, 170, 164); + public static final Color BROWN_300 = new Color(161, 136, 127); + public static final Color BROWN_400 = new Color(141, 110, 99); + public static final Color BROWN_500 = new Color(121, 85, 72); + public static final Color BROWN_600 = new Color(109, 76, 65); + public static final Color BROWN_700 = new Color(93, 64, 55); + public static final Color BROWN_800 = new Color(78, 52, 46); + public static final Color BROWN_900 = new Color(62, 39, 35); + public static final Color GRAY_50 = new Color(250, 250, 250); + public static final Color GRAY_100 = new Color(245, 245, 245); + public static final Color GRAY_200 = new Color(238, 238, 238); + public static final Color GRAY_300 = new Color(224, 224, 224); + public static final Color GRAY_400 = new Color(189, 189, 189); + public static final Color GRAY_500 = new Color(158, 158, 158); + public static final Color GRAY_600 = new Color(117, 117, 117); + public static final Color GRAY_700 = new Color(97, 97, 97); + public static final Color GRAY_800 = new Color(66, 66, 66); + public static final Color GRAY_900 = new Color(33, 33, 33); + public static final Color BLUE_GRAY_50 = new Color(236, 239, 241); + public static final Color BLUE_GRAY_100 = new Color(207, 216, 220); + public static final Color BLUE_GRAY_200 = new Color(176, 190, 197); + public static final Color BLUE_GRAY_300 = new Color(144, 164, 174); + public static final Color BLUE_GRAY_400 = new Color(120, 144, 156); + public static final Color BLUE_GRAY_500 = new Color(96, 125, 139); + public static final Color BLUE_GRAY_600 = new Color(84, 110, 122); + public static final Color BLUE_GRAY_700 = new Color(69, 90, 100); + public static final Color BLUE_GRAY_800 = new Color(55, 71, 79); + public static final Color BLUE_GRAY_900 = new Color(38, 50, 56); + public static final Color BLACK = new Color(0, 0, 0); + public static final Color WHITE = new Color(255, 255, 255); + public static final Color TRANSPARENT = new Color(0, 0, 0, 255); - private MaterialColors () {} + private MaterialColors() { + } - public static Color bleach (Color color, float amount) { - int red = (int) ((color.getRed () * (1 - amount) / 255 + amount) * 255); - int green = (int) ((color.getGreen () * (1 - amount) / 255 + amount) * 255); - int blue = (int) ((color.getBlue () * (1 - amount) / 255 + amount) * 255); - return new Color (red, green, blue); + public static Color bleach(Color color, float amount) { + int red = (int) ((color.getRed() * (1 - amount) / 255 + amount) * 255); + int green = (int) ((color.getGreen() * (1 - amount) / 255 + amount) * 255); + int blue = (int) ((color.getBlue() * (1 - amount) / 255 + amount) * 255); + return new Color(red, green, blue); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java index a538abd02..fbc330faf 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java @@ -9,24 +9,25 @@ public class MaterialDrawingUtils { static { - System.setProperty ("awt.useSystemAAFontSettings", "on"); - System.setProperty ("swing.aatext", "true"); - System.setProperty ("sun.java2d.xrender", "true"); + System.setProperty("awt.useSystemAAFontSettings", "on"); + System.setProperty("swing.aatext", "true"); + System.setProperty("sun.java2d.xrender", "true"); } - public static Graphics getAliasedGraphics (Graphics g) { - Map hints = (Map) Toolkit.getDefaultToolkit ().getDesktopProperty ("awt.font.desktophints"); + public static Graphics getAliasedGraphics(Graphics g) { + Map hints = (Map) Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"); if (hints != null) { - hints.put (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - Graphics2D g2d = (Graphics2D) g; - g2d.addRenderingHints (hints); + Graphics2D g2d = (Graphics2D) g; + g2d.addRenderingHints(hints); - //g2d.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); - return g2d; - } else { - // Desktop hints not supported on this platform - return g; + //g2d.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); + return g2d; + } + else { + // Desktop hints not supported on this platform + return g; } } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java index 4538e79dc..9bbc4e884 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java @@ -12,31 +12,31 @@ public class MaterialFonts { private static final Map fontSettings = new HashMap<>(); - public static final Font BLACK = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Black.ttf"); - public static final Font BLACK_ITALIC = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-BlackItalic.ttf"); - public static final Font BOLD = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Bold.ttf"); - public static final Font BOLD_ITALIC = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-BoldItalic.ttf"); - public static final Font ITALIC = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Italic.ttf"); - public static final Font LIGHT = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Light.ttf"); - public static final Font LIGHT_ITALIC = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-LightItalic.ttf"); - public static final Font MEDIUM = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Medium.ttf"); - public static final Font MEDIUM_ITALIC = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-MediumItalic.ttf"); - public static final Font REGULAR = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Regular.ttf"); - public static final Font THIN = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-Thin.ttf"); - public static final Font THIN_ITALIC = loadFont ("/edu/rpi/legup/fonts/Roboto/Roboto-ThinItalic.ttf"); - - private static Font loadFont (String fontPath) { - if (fontSettings.isEmpty ()) { - fontSettings.put (TextAttribute.SIZE, 14f); - fontSettings.put (TextAttribute.KERNING, TextAttribute.KERNING_ON); + public static final Font BLACK = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Black.ttf"); + public static final Font BLACK_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-BlackItalic.ttf"); + public static final Font BOLD = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Bold.ttf"); + public static final Font BOLD_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-BoldItalic.ttf"); + public static final Font ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Italic.ttf"); + public static final Font LIGHT = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Light.ttf"); + public static final Font LIGHT_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-LightItalic.ttf"); + public static final Font MEDIUM = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Medium.ttf"); + public static final Font MEDIUM_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-MediumItalic.ttf"); + public static final Font REGULAR = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Regular.ttf"); + public static final Font THIN = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Thin.ttf"); + public static final Font THIN_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-ThinItalic.ttf"); + + private static Font loadFont(String fontPath) { + if (fontSettings.isEmpty()) { + fontSettings.put(TextAttribute.SIZE, 14f); + fontSettings.put(TextAttribute.KERNING, TextAttribute.KERNING_ON); } - try (InputStream inputStream = MaterialFonts.class.getResourceAsStream (fontPath)) { - return Font.createFont (Font.TRUETYPE_FONT, inputStream).deriveFont (fontSettings); + try (InputStream inputStream = MaterialFonts.class.getResourceAsStream(fontPath)) { + return Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(fontSettings); } catch (IOException | FontFormatException e) { - e.printStackTrace (); - throw new RuntimeException ("Font " + fontPath + " wasn't loaded"); + e.printStackTrace(); + throw new RuntimeException("Font " + fontPath + " wasn't loaded"); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java index a6e49d4f2..dabf2139d 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java @@ -1,4 +1,5 @@ package edu.rpi.legup.ui.lookandfeel.materialdesign; + import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; @@ -6,36 +7,37 @@ public class MaterialImages { - public static final BufferedImage RIGHT_ARROW = loadImg ("/edu/rpi/legup/imgs/right_arrow.png"); - public static final BufferedImage DOWN_ARROW = loadImg ("/edu/rpi/legup/imgs/down_arrow.png"); - public static final BufferedImage UP_ARROW = loadImg ("/edu/rpi/legup/imgs/up_arrow.png"); - public static final BufferedImage PAINTED_CHECKED_BOX = loadImg ("/edu/rpi/legup/imgs/painted_checked_box.png"); - public static final BufferedImage OUTLINED_CHECKED_BOX = loadImg ("/edu/rpi/legup/imgs/outlined_checked_box.png"); - public static final BufferedImage UNCHECKED_BOX = loadImg ("/edu/rpi/legup/imgs/unchecked_box.png"); - public static final BufferedImage RADIO_BUTTON_ON = loadImg ("/edu/rpi/legup/imgs/radio_button_on.png"); - public static final BufferedImage RADIO_BUTTON_OFF = loadImg ("/edu/rpi/legup/imgs/radio_button_off.png"); - public static final BufferedImage TOGGLE_BUTTON_ON = loadImg ("/edu/rpi/legup/imgs/toggle_on.png"); - public static final BufferedImage TOGGLE_BUTTON_OFF = loadImg ("/edu/rpi/legup/imgs/toggle_off.png"); - public static final BufferedImage BACK_ARROW = loadImg ("/edu/rpi/legup/imgs/back_arrow.png"); - public static final BufferedImage COMPUTER = loadImg ("/edu/rpi/legup/imgs/computer.png"); - public static final BufferedImage FILE = loadImg ("/edu/rpi/legup/imgs/file.png"); - public static final BufferedImage FLOPPY_DRIVE = loadImg ("/edu/rpi/legup/imgs/floppy_drive.png"); - public static final BufferedImage FOLDER = loadImg ("/edu/rpi/legup/imgs/folder.png"); - public static final BufferedImage HARD_DRIVE = loadImg ("/edu/rpi/legup/imgs/hard_drive.png"); - public static final BufferedImage HOME = loadImg ("/edu/rpi/legup/imgs/home.png"); - public static final BufferedImage LIST = loadImg ("/edu/rpi/legup/imgs/list.png"); - public static final BufferedImage NEW_FOLDER = loadImg ("/edu/rpi/legup/imgs/new_folder.png"); - public static final BufferedImage DETAILS = loadImg ("/edu/rpi/legup/imgs/details.png"); + public static final BufferedImage RIGHT_ARROW = loadImg("/edu/rpi/legup/imgs/right_arrow.png"); + public static final BufferedImage DOWN_ARROW = loadImg("/edu/rpi/legup/imgs/down_arrow.png"); + public static final BufferedImage UP_ARROW = loadImg("/edu/rpi/legup/imgs/up_arrow.png"); + public static final BufferedImage PAINTED_CHECKED_BOX = loadImg("/edu/rpi/legup/imgs/painted_checked_box.png"); + public static final BufferedImage OUTLINED_CHECKED_BOX = loadImg("/edu/rpi/legup/imgs/outlined_checked_box.png"); + public static final BufferedImage UNCHECKED_BOX = loadImg("/edu/rpi/legup/imgs/unchecked_box.png"); + public static final BufferedImage RADIO_BUTTON_ON = loadImg("/edu/rpi/legup/imgs/radio_button_on.png"); + public static final BufferedImage RADIO_BUTTON_OFF = loadImg("/edu/rpi/legup/imgs/radio_button_off.png"); + public static final BufferedImage TOGGLE_BUTTON_ON = loadImg("/edu/rpi/legup/imgs/toggle_on.png"); + public static final BufferedImage TOGGLE_BUTTON_OFF = loadImg("/edu/rpi/legup/imgs/toggle_off.png"); + public static final BufferedImage BACK_ARROW = loadImg("/edu/rpi/legup/imgs/back_arrow.png"); + public static final BufferedImage COMPUTER = loadImg("/edu/rpi/legup/imgs/computer.png"); + public static final BufferedImage FILE = loadImg("/edu/rpi/legup/imgs/file.png"); + public static final BufferedImage FLOPPY_DRIVE = loadImg("/edu/rpi/legup/imgs/floppy_drive.png"); + public static final BufferedImage FOLDER = loadImg("/edu/rpi/legup/imgs/folder.png"); + public static final BufferedImage HARD_DRIVE = loadImg("/edu/rpi/legup/imgs/hard_drive.png"); + public static final BufferedImage HOME = loadImg("/edu/rpi/legup/imgs/home.png"); + public static final BufferedImage LIST = loadImg("/edu/rpi/legup/imgs/list.png"); + public static final BufferedImage NEW_FOLDER = loadImg("/edu/rpi/legup/imgs/new_folder.png"); + public static final BufferedImage DETAILS = loadImg("/edu/rpi/legup/imgs/details.png"); - private MaterialImages () {} + private MaterialImages() { + } - private static BufferedImage loadImg (String imgPath) { - try (InputStream inputStream = MaterialImages.class.getResourceAsStream (imgPath)) { - return ImageIO.read (inputStream); + private static BufferedImage loadImg(String imgPath) { + try (InputStream inputStream = MaterialImages.class.getResourceAsStream(imgPath)) { + return ImageIO.read(inputStream); } catch (IOException e) { - e.printStackTrace (); - throw new RuntimeException ("Image " + imgPath + " wasn't loaded"); + e.printStackTrace(); + throw new RuntimeException("Image " + imgPath + " wasn't loaded"); } } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java index dc5848d8f..dd60f8dc3 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java @@ -36,9 +36,10 @@ public class RuleFrame extends JPanel { public RuleFrame(RuleController controller) { - MaterialTabbedPaneUI tabOverride = new MaterialTabbedPaneUI(){ + MaterialTabbedPaneUI tabOverride = new MaterialTabbedPaneUI() { //this prevents the tabs from moving around when you select them - @Override protected boolean shouldRotateTabRuns(int i){ + @Override + protected boolean shouldRotateTabRuns(int i) { return false; } }; diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java index f60ffe300..2fce4d2d1 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java @@ -70,7 +70,8 @@ public void draw(Graphics2D graphics2D) { graphics2D.setColor(NODE_COLOR_CONTRADICTION); graphics2D.drawLine(location.x - RADIUS, location.y - RADIUS, location.x + RADIUS, location.y + RADIUS); graphics2D.drawLine(location.x + RADIUS, location.y - RADIUS, location.x - RADIUS, location.y + RADIUS); - } else { + } + else { isContradictoryState = false; graphics2D.setStroke(MAIN_STROKE); boolean isContraBranch = getTreeElement().isContradictoryBranch(); @@ -85,22 +86,26 @@ public void draw(Graphics2D graphics2D) { graphics2D.setStroke(SELECTION_STROKE); graphics2D.setColor(OUTLINE_SELECTION_COLOR); graphics2D.drawOval(location.x - RADIUS - 4, location.y - RADIUS - 4, DIAMETER + 8, DIAMETER + 8); - } else if (isHover) { - graphics2D.setColor(HOVER_COLOR); - graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); - - graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); - - graphics2D.setStroke(SELECTION_STROKE); - graphics2D.setColor(OUTLINE_HOVER_COLOR); - graphics2D.drawOval(location.x - RADIUS - 4, location.y - RADIUS - 4, DIAMETER + 8, DIAMETER + 8); - } else { - graphics2D.setColor(isContraBranch ? NODE_COLOR_CONTRADICTION : NODE_COLOR_DEFAULT); - graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); - - graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + } + else { + if (isHover) { + graphics2D.setColor(HOVER_COLOR); + graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + + graphics2D.setColor(OUTLINE_COLOR); + graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + + graphics2D.setStroke(SELECTION_STROKE); + graphics2D.setColor(OUTLINE_HOVER_COLOR); + graphics2D.drawOval(location.x - RADIUS - 4, location.y - RADIUS - 4, DIAMETER + 8, DIAMETER + 8); + } + else { + graphics2D.setColor(isContraBranch ? NODE_COLOR_CONTRADICTION : NODE_COLOR_DEFAULT); + graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + + graphics2D.setColor(OUTLINE_COLOR); + graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + } } } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java index 306cffec8..b1f44dc54 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java @@ -105,7 +105,8 @@ public void add() { if (add.canExecute()) { add.execute(); GameBoardFacade.getInstance().getHistory().pushChange(add); - } else { + } + else { updateError(add.getError()); } } @@ -117,7 +118,8 @@ public void delete() { if (del.canExecute()) { del.execute(); GameBoardFacade.getInstance().getHistory().pushChange(del); - } else { + } + else { updateError(del.getError()); } } @@ -129,7 +131,8 @@ public void merge() { if (merge.canExecute()) { merge.execute(); GameBoardFacade.getInstance().getHistory().pushChange(merge); - } else { + } + else { updateError(merge.getError()); } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java index 3f1f59ba5..0e80499e6 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java @@ -100,25 +100,29 @@ public void draw(Graphics2D graphics2D) { graphics2D.setStroke(SELECTION_STROKE); graphics2D.setColor(OUTLINE_SELECTION_COLOR); graphics2D.drawPolygon(selection_triangle); - } else if (isHover) { - graphics2D.setColor(HOVER_COLOR); - graphics2D.fillPolygon(arrowhead); - - graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawPolygon(arrowhead); - - Polygon selection_triangle = createTransitionTriangle(RADIUS + 10); - selection_triangle.translate(7, 0); - - graphics2D.setStroke(SELECTION_STROKE); - graphics2D.setColor(OUTLINE_HOVER_COLOR); - graphics2D.drawPolygon(selection_triangle); - } else { - graphics2D.setColor(getTreeElement().isJustified() ? getTreeElement().isCorrect() ? CORRECT_COLOR : INCORRECT_COLOR : DEFAULT_COLOR); - graphics2D.fillPolygon(arrowhead); - - graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawPolygon(arrowhead); + } + else { + if (isHover) { + graphics2D.setColor(HOVER_COLOR); + graphics2D.fillPolygon(arrowhead); + + graphics2D.setColor(OUTLINE_COLOR); + graphics2D.drawPolygon(arrowhead); + + Polygon selection_triangle = createTransitionTriangle(RADIUS + 10); + selection_triangle.translate(7, 0); + + graphics2D.setStroke(SELECTION_STROKE); + graphics2D.setColor(OUTLINE_HOVER_COLOR); + graphics2D.drawPolygon(selection_triangle); + } + else { + graphics2D.setColor(getTreeElement().isJustified() ? getTreeElement().isCorrect() ? CORRECT_COLOR : INCORRECT_COLOR : DEFAULT_COLOR); + graphics2D.fillPolygon(arrowhead); + + graphics2D.setColor(OUTLINE_COLOR); + graphics2D.drawPolygon(arrowhead); + } } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java index 79367216a..6e06ef68e 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java @@ -103,23 +103,28 @@ public TreeElementView getTreeElementView(Point point) { private TreeElementView getTreeElementView(Point point, TreeElementView elementView) { if (elementView == null) { return null; - } else if (elementView.contains(point) && elementView.isVisible()) { - if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { - return null; + } + else { + if (elementView.contains(point) && elementView.isVisible()) { + if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { + return null; + } + return elementView; } - return elementView; - } else { - if (elementView.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) elementView; - for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { - TreeElementView view = getTreeElementView(point, transitionView); - if (view != null) { - return view; + else { + if (elementView.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) elementView; + for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { + TreeElementView view = getTreeElementView(point, transitionView); + if (view != null) { + return view; + } } } - } else { - TreeTransitionView transitionView = (TreeTransitionView) elementView; - return getTreeElementView(point, transitionView.getChildView()); + else { + TreeTransitionView transitionView = (TreeTransitionView) elementView; + return getTreeElementView(point, transitionView.getChildView()); + } } } return null; @@ -248,7 +253,8 @@ public void removeTreeElement(TreeElementView view) { if (view.getType() == NODE) { TreeNodeView nodeView = (TreeNodeView) view; nodeView.getParentView().setChildView(null); - } else { + } + else { TreeTransitionView transitionView = (TreeTransitionView) view; transitionView.getParentViews().forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); } @@ -288,7 +294,8 @@ public void resetView() { public void onTreeElementAdded(TreeElement treeElement) { if (treeElement.getType() == NODE) { addTreeNode((TreeNode) treeElement); - } else { + } + else { addTreeTransition((TreeTransition) treeElement); } repaint(); @@ -307,7 +314,8 @@ public void onTreeElementRemoved(TreeElement element) { nodeView.getParentView().setChildView(null); removeTreeNode(node); - } else { + } + else { TreeTransition trans = (TreeTransition) element; TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); @@ -426,7 +434,8 @@ private void addTreeTransition(TreeTransition trans) { public void drawTree(Graphics2D graphics2D) { if (tree == null) { LOGGER.error("Unable to draw tree."); - } else { + } + else { if (rootNodeView == null) { rootNodeView = new TreeNodeView(tree.getRootNode()); @@ -455,7 +464,7 @@ public void createViews(TreeNodeView nodeView) { TreeNode node = nodeView.getTreeElement(); for (TreeTransition trans : node.getChildren()) { TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - if(transView != null) { + if (transView != null) { nodeView.addChildrenView(transView); transView.addParentView(nodeView); break; @@ -515,29 +524,32 @@ public void calculateViewLocations(TreeNodeView nodeView, int depth) { if (childNodeView != null) { calculateViewLocations(childNodeView, depth + 1); } - } else if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { - int yAvg = 0; - for (int i = 0; i < parentsViews.size(); i++) { - TreeNodeView parentNodeView = parentsViews.get(i); - depth = Math.max(depth, parentNodeView.getDepth()); - yAvg += parentNodeView.getY(); - - Point lineStartPoint = childView.getLineStartPoint(i); - lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = parentNodeView.getY(); - } - yAvg /= parentsViews.size(); - childView.setEndY(yAvg); + } + else { + if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { + int yAvg = 0; + for (int i = 0; i < parentsViews.size(); i++) { + TreeNodeView parentNodeView = parentsViews.get(i); + depth = Math.max(depth, parentNodeView.getDepth()); + yAvg += parentNodeView.getY(); + + Point lineStartPoint = childView.getLineStartPoint(i); + lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = parentNodeView.getY(); + } + yAvg /= parentsViews.size(); + childView.setEndY(yAvg); - childView.setDepth(depth); + childView.setDepth(depth); - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - dimension.width = Math.max(dimension.width, childView.getEndX()); + dimension.width = Math.max(dimension.width, childView.getEndX()); - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } } } break; @@ -577,57 +589,65 @@ public void calcSpan(TreeElementView view) { TreeNode node = nodeView.getTreeElement(); if (nodeView.getChildrenViews().size() == 0) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else if (nodeView.getChildrenViews().size() == 1) { - TreeTransitionView childView = nodeView.getChildrenViews().get(0); - calcSpan(childView); - if (childView.getParentViews().size() > 1) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else { - nodeView.setSpan(childView.getSpan()); - } - } else { - DisjointSets branches = node.findMergingBranches(); - List children = node.getChildren(); - - if (node == children.get(0).getParents().get(0)) { - reorderBranches(node, branches); - ArrayList newChildrenViews = new ArrayList<>(); - for (TreeTransition trans : node.getChildren()) { - newChildrenViews.add((TreeTransitionView) viewMap.get(trans)); + } + else { + if (nodeView.getChildrenViews().size() == 1) { + TreeTransitionView childView = nodeView.getChildrenViews().get(0); + calcSpan(childView); + if (childView.getParentViews().size() > 1) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + nodeView.setSpan(childView.getSpan()); } - nodeView.setChildrenViews(newChildrenViews); } + else { + DisjointSets branches = node.findMergingBranches(); + List children = node.getChildren(); + + if (node == children.get(0).getParents().get(0)) { + reorderBranches(node, branches); + ArrayList newChildrenViews = new ArrayList<>(); + for (TreeTransition trans : node.getChildren()) { + newChildrenViews.add((TreeTransitionView) viewMap.get(trans)); + } + nodeView.setChildrenViews(newChildrenViews); + } - List> mergingSets = branches.getAllSets(); - - double span = 0.0; - for (Set mergeSet : mergingSets) { - if (mergeSet.size() > 1) { - TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); - double subSpan = 0.0; - for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); - subCalcSpan(branchView, mergePointView); - subSpan += branchView.getSpan(); + List> mergingSets = branches.getAllSets(); + + double span = 0.0; + for (Set mergeSet : mergingSets) { + if (mergeSet.size() > 1) { + TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); + TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + double subSpan = 0.0; + for (TreeTransition branch : mergeSet) { + TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + subCalcSpan(branchView, mergePointView); + subSpan += branchView.getSpan(); + } + calcSpan(mergePointView); + span += Math.max(mergePointView.getSpan(), subSpan); + } + else { + TreeTransition trans = mergeSet.iterator().next(); + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + calcSpan(transView); + span += transView.getSpan(); } - calcSpan(mergePointView); - span += Math.max(mergePointView.getSpan(), subSpan); - } else { - TreeTransition trans = mergeSet.iterator().next(); - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - calcSpan(transView); - span += transView.getSpan(); } + nodeView.setSpan(span); } - nodeView.setSpan(span); } - } else { + } + else { TreeTransitionView transView = (TreeTransitionView) view; TreeNodeView nodeView = transView.getChildView(); if (nodeView == null) { transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else { + } + else { calcSpan(nodeView); transView.setSpan(nodeView.getSpan()); } @@ -652,57 +672,66 @@ private void subCalcSpan(TreeElementView view, TreeElementView stop) { TreeNode node = nodeView.getTreeElement(); if (nodeView.getChildrenViews().size() == 0) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else if (nodeView.getChildrenViews().size() == 1) { - TreeTransitionView childView = nodeView.getChildrenViews().get(0); - if (childView == stop) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else { - subCalcSpan(childView, stop); - if (childView.getParentViews().size() > 1) { + } + else { + if (nodeView.getChildrenViews().size() == 1) { + TreeTransitionView childView = nodeView.getChildrenViews().get(0); + if (childView == stop) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else { - nodeView.setSpan(childView.getSpan()); + } + else { + subCalcSpan(childView, stop); + if (childView.getParentViews().size() > 1) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + nodeView.setSpan(childView.getSpan()); + } } } - } else { - DisjointSets branches = node.findMergingBranches(); - List children = node.getChildren(); + else { + DisjointSets branches = node.findMergingBranches(); + List children = node.getChildren(); - if (node == children.get(0).getParents().get(0)) { - reorderBranches(node, branches); - } + if (node == children.get(0).getParents().get(0)) { + reorderBranches(node, branches); + } - List> mergingSets = branches.getAllSets(); - - double span = 0.0; - for (Set mergeSet : mergingSets) { - if (mergeSet.size() > 1) { - TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); - double subSpan = 0.0; - for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); - subCalcSpan(branchView, mergePointView); - subSpan += branchView.getSpan(); + List> mergingSets = branches.getAllSets(); + + double span = 0.0; + for (Set mergeSet : mergingSets) { + if (mergeSet.size() > 1) { + TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); + TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + double subSpan = 0.0; + for (TreeTransition branch : mergeSet) { + TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + subCalcSpan(branchView, mergePointView); + subSpan += branchView.getSpan(); + } + subCalcSpan(mergePointView, stop); + span += Math.max(mergePointView.getSpan(), subSpan); + } + else { + TreeTransition trans = mergeSet.iterator().next(); + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + subCalcSpan(transView, stop); + span += transView.getSpan(); } - subCalcSpan(mergePointView, stop); - span += Math.max(mergePointView.getSpan(), subSpan); - } else { - TreeTransition trans = mergeSet.iterator().next(); - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - subCalcSpan(transView, stop); - span += transView.getSpan(); } - } - nodeView.setSpan(span); + nodeView.setSpan(span); + } } - } else { + } + else { TreeTransitionView transView = (TreeTransitionView) view; TreeNodeView nodeView = transView.getChildView(); if (nodeView == null || nodeView == stop) { transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } else { + } + else { calcSpan(nodeView); transView.setSpan(nodeView.getSpan()); } @@ -724,8 +753,7 @@ private void reorderBranches(TreeNode node, DisjointSets branche for (Set set : mergingSets) { List mergeBranch = new ArrayList<>(); newOrder.add(mergeBranch); - children.forEach(t -> - { + children.forEach(t -> { if (set.contains(t)) { mergeBranch.add(t); } @@ -734,8 +762,7 @@ private void reorderBranches(TreeNode node, DisjointSets branche children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); } - newOrder.sort((List b1, List b2) -> - { + newOrder.sort((List b1, List b2) -> { int low1 = -1; int low2 = -1; for (TreeTransition t1 : b1) { diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java index 575d19f19..042eb8880 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java @@ -66,7 +66,8 @@ public void toggleSelection(TreeElementView treeElementView) { if (selectedViews.contains(treeElementView)) { selectedViews.remove(treeElementView); treeElementView.setSelected(false); - } else { + } + else { selectedViews.add(treeElementView); treeElementView.setSelected(true); } diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java index a7fe8bf7c..037782225 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java @@ -8,6 +8,7 @@ public class ElementButton extends JButton { private Element element; + ElementButton(Element e) { super(e.getImageIcon()); this.element = e; diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java index ebb0e9ca4..abfe39d85 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java @@ -68,6 +68,11 @@ public JTabbedPane getTabbedPane() { return tabbedPane; } - public NonPlaceableElementPanel getNonPlaceableElementPanel() { return nonPlaceableElementPanel; } - public PlaceableElementPanel getPlaceableElementPanel() { return placeableElementPanel; } + public NonPlaceableElementPanel getNonPlaceableElementPanel() { + return nonPlaceableElementPanel; + } + + public PlaceableElementPanel getPlaceableElementPanel() { + return placeableElementPanel; + } } diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java index 4c2bebd54..96719bc33 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java @@ -22,6 +22,7 @@ public ElementPanel(ElementFrame eFrame) { this.elements = new ArrayList<>(); setLayout(new WrapLayout()); } + public void setElements(List elements) { this.elements = elements; clearButtons(); diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java index 6704d1aa2..3dba14c42 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java @@ -2,7 +2,7 @@ import javax.swing.*; -public class NonPlaceableElementPanel extends ElementPanel{ +public class NonPlaceableElementPanel extends ElementPanel { public NonPlaceableElementPanel(ElementFrame elementFrame) { super(elementFrame); this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Basic Rules.gif")); diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java index 2021d43cc..8ef7e2d49 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java @@ -2,7 +2,7 @@ import javax.swing.*; -public class PlaceableElementPanel extends ElementPanel{ +public class PlaceableElementPanel extends ElementPanel { public PlaceableElementPanel(ElementFrame elementFrame) { super(elementFrame); this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Basic Rules.gif")); diff --git a/src/main/java/edu/rpi/legup/user/UsageStatistics.java b/src/main/java/edu/rpi/legup/user/UsageStatistics.java index 3c0651a27..192db593f 100644 --- a/src/main/java/edu/rpi/legup/user/UsageStatistics.java +++ b/src/main/java/edu/rpi/legup/user/UsageStatistics.java @@ -45,11 +45,13 @@ public boolean sendErrorReport() { try { // System.err.println(new String(instream.readAllBytes())); - } finally { + } + finally { instream.close(); } } - } catch (IOException e) { + } + catch (IOException e) { return false; } return false; diff --git a/src/main/java/edu/rpi/legup/utility/DisjointSets.java b/src/main/java/edu/rpi/legup/utility/DisjointSets.java index 18832be52..1e2270318 100644 --- a/src/main/java/edu/rpi/legup/utility/DisjointSets.java +++ b/src/main/java/edu/rpi/legup/utility/DisjointSets.java @@ -26,7 +26,8 @@ public DisjointSets() { public boolean createSet(T u) { if (u == null || parents.containsKey(u)) { return false; - } else { + } + else { parents.put(u, u); depths.put(u, 0); Set newSet = new HashSet<>(); @@ -45,8 +46,11 @@ public boolean createSet(T u) { public T find(T p) { if (p == null || parents.get(p) == null) { return null; - } else if (p != parents.get(p)) { - parents.put(p, find(parents.get(p))); + } + else { + if (p != parents.get(p)) { + parents.put(p, find(parents.get(p))); + } } return parents.get(p); } @@ -63,12 +67,14 @@ public boolean union(T p, T q) { T qid = find(q); if (pid == null || qid == null || pid == qid) { return false; - } else { + } + else { if (depths.get(pid) > depths.get(qid)) { parents.put(qid, pid); sets.get(pid).addAll(sets.get(qid)); sets.remove(qid); - } else { + } + else { parents.put(pid, qid); sets.get(qid).addAll(sets.get(pid)); sets.remove(pid); @@ -121,7 +127,8 @@ public Set getSet(T p) { T pid = find(p); if (pid != null) { return new HashSet<>(sets.get(pid)); - } else { + } + else { return null; } } diff --git a/src/main/java/edu/rpi/legup/utility/LegupUtils.java b/src/main/java/edu/rpi/legup/utility/LegupUtils.java index f5beb4798..8c09cfd1e 100644 --- a/src/main/java/edu/rpi/legup/utility/LegupUtils.java +++ b/src/main/java/edu/rpi/legup/utility/LegupUtils.java @@ -69,8 +69,11 @@ private static List findClasses(File directory, String packageName) throw if (file.isDirectory()) { assert !file.getName().contains("."); classes.addAll(findClasses(file, packageName + "." + file.getName())); - } else if (file.getName().endsWith(".class")) { - classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6))); + } + else { + if (file.getName().endsWith(".class")) { + classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6))); + } } } return classes; diff --git a/src/test/java/legup/MockGameBoardFacade.java b/src/test/java/legup/MockGameBoardFacade.java index 2d57cc5d9..7840b61b7 100644 --- a/src/test/java/legup/MockGameBoardFacade.java +++ b/src/test/java/legup/MockGameBoardFacade.java @@ -5,18 +5,14 @@ import edu.rpi.legup.app.InvalidConfigException; import edu.rpi.legup.model.Puzzle; -public class MockGameBoardFacade extends GameBoardFacade -{ - protected MockGameBoardFacade() - { +public class MockGameBoardFacade extends GameBoardFacade { + protected MockGameBoardFacade() { super(); Config config = null; - try - { + try { config = new Config(); } - catch(InvalidConfigException e) - { + catch (InvalidConfigException e) { System.exit(1); } setConfig(config); @@ -27,30 +23,25 @@ protected MockGameBoardFacade() * * @return single instance of GameBoardFacade */ - public synchronized static GameBoardFacade getInstance() - { - if(instance == null) - { + public synchronized static GameBoardFacade getInstance() { + if (instance == null) { instance = new MockGameBoardFacade(); } return instance; } @Override - public void initializeUI() - { + public void initializeUI() { } @Override - public void setPuzzle(Puzzle puzzle) - { + public void setPuzzle(Puzzle puzzle) { this.puzzle = puzzle; } @Override - public void setWindowTitle(String puzzleName, String fileName) - { + public void setWindowTitle(String puzzleName, String fileName) { } } diff --git a/src/test/java/legup/TestUtilities.java b/src/test/java/legup/TestUtilities.java index 423798b9b..9f203b223 100644 --- a/src/test/java/legup/TestUtilities.java +++ b/src/test/java/legup/TestUtilities.java @@ -7,10 +7,8 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.save.InvalidFileFormatException; -public final class TestUtilities -{ - public static void importTestBoard(String fileName, Puzzle puzzle) throws InvalidFileFormatException - { +public final class TestUtilities { + public static void importTestBoard(String fileName, Puzzle puzzle) throws InvalidFileFormatException { puzzle.importPuzzle(ClassLoader.getSystemResourceAsStream(fileName)); Tree tree = puzzle.getTree(); TreeNode rootNode = tree.getRootNode(); diff --git a/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java b/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java index 7239cf7ba..c9e65e9c1 100644 --- a/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java +++ b/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java @@ -16,23 +16,20 @@ import java.awt.*; -public class AdjacentShipsContradictionRuleTest -{ +public class AdjacentShipsContradictionRuleTest { private static final AdjacentShipsContradictionRule RULE = new AdjacentShipsContradictionRule(); private static Battleship battleship; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); battleship = new Battleship(); } @Test - public void OrthogonalAdjacentTest() throws InvalidFileFormatException - { + public void OrthogonalAdjacentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/battleship/rules" + "/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards", battleship); @@ -40,31 +37,29 @@ public void OrthogonalAdjacentTest() throws InvalidFileFormatException TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - BattleshipBoard board = (BattleshipBoard)transition.getBoard(); + BattleshipBoard board = (BattleshipBoard) transition.getBoard(); Assert.assertNotNull(RULE.checkContradiction( board)); } @Test - public void InvalidOrthogonalAdjacentTest() throws InvalidFileFormatException - { + public void InvalidOrthogonalAdjacentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/AdjacentShipsContradictionRule" + - "/InvalidOrthogonalAdjacentBoards", battleship); + "/AdjacentShipsContradictionRule" + + "/InvalidOrthogonalAdjacentBoards", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - BattleshipBoard board = (BattleshipBoard)transition.getBoard(); + BattleshipBoard board = (BattleshipBoard) transition.getBoard(); Assert.assertNull(RULE.checkContradiction( board)); } @Test - public void DiagonalAdjacentTest() throws InvalidFileFormatException - { + public void DiagonalAdjacentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/battleship/rules" + "/AdjacentShipsContradictionRule" + "/DiagonalAdjacentBoards", battleship); @@ -72,7 +67,7 @@ public void DiagonalAdjacentTest() throws InvalidFileFormatException TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - BattleshipBoard board = (BattleshipBoard)transition.getBoard(); + BattleshipBoard board = (BattleshipBoard) transition.getBoard(); Assert.assertNull(RULE.checkContradiction( board)); diff --git a/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java index 3a7d51c88..3b1748abb 100644 --- a/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java @@ -14,23 +14,20 @@ import org.junit.BeforeClass; import org.junit.Test; -public class BulbsInPathContradictionRuleTest -{ +public class BulbsInPathContradictionRuleTest { private static final BulbsInPathContradictionRule RULE = new BulbsInPathContradictionRule(); private static LightUp lightUp; private static PuzzleImporter importer; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); lightUp = new LightUp(); importer = lightUp.getImporter(); } @Test - public void BulbsInPathContradictionRule_LightInHorizontalPath() throws InvalidFileFormatException - { + public void BulbsInPathContradictionRule_LightInHorizontalPath() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -38,15 +35,14 @@ public void BulbsInPathContradictionRule_LightInHorizontalPath() throws InvalidF LightUpBoard board = (LightUpBoard) transition.getBoard(); Assert.assertNull(RULE.checkContradiction(board)); - Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0,0))); - Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2,0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); - Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0,1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); } @Test - public void BulbsInPathContradictionRule_LightInVerticalPath() throws InvalidFileFormatException - { + public void BulbsInPathContradictionRule_LightInVerticalPath() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -54,9 +50,9 @@ public void BulbsInPathContradictionRule_LightInVerticalPath() throws InvalidFil LightUpBoard board = (LightUpBoard) transition.getBoard(); Assert.assertNull(RULE.checkContradiction(board)); - Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0,0))); - Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0,2))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); - Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1,1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); } } diff --git a/src/test/java/puzzles/lightup/rules/BulbsOutsideDiagonalBasicRuleTest.java b/src/test/java/puzzles/lightup/rules/BulbsOutsideDiagonalBasicRuleTest.java index c72426d29..1f0e0b5e1 100644 --- a/src/test/java/puzzles/lightup/rules/BulbsOutsideDiagonalBasicRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/BulbsOutsideDiagonalBasicRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class BulbsOutsideDiagonalBasicRuleTest -{ +public class BulbsOutsideDiagonalBasicRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java index 8362e54e9..260a62c9c 100644 --- a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class CannotLightACellContradictionRuleTest -{ +public class CannotLightACellContradictionRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/EmptyCellinLightBasicRuleTest.java b/src/test/java/puzzles/lightup/rules/EmptyCellinLightBasicRuleTest.java index 3bb4f035e..5cea77d8f 100644 --- a/src/test/java/puzzles/lightup/rules/EmptyCellinLightBasicRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/EmptyCellinLightBasicRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class EmptyCellinLightBasicRuleTest -{ +public class EmptyCellinLightBasicRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/EmptyCornersBasicRuleTest.java b/src/test/java/puzzles/lightup/rules/EmptyCornersBasicRuleTest.java index 9a87cf532..cbec500f6 100644 --- a/src/test/java/puzzles/lightup/rules/EmptyCornersBasicRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/EmptyCornersBasicRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class EmptyCornersBasicRuleTest -{ +public class EmptyCornersBasicRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/FinishWithBulbsBasicRuleTest.java b/src/test/java/puzzles/lightup/rules/FinishWithBulbsBasicRuleTest.java index 0351dedb2..2f27b4d14 100644 --- a/src/test/java/puzzles/lightup/rules/FinishWithBulbsBasicRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/FinishWithBulbsBasicRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class FinishWithBulbsBasicRuleTest -{ +public class FinishWithBulbsBasicRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/FinishWithEmptyBasicRuleTest.java b/src/test/java/puzzles/lightup/rules/FinishWithEmptyBasicRuleTest.java index 4533ac6d1..833c64eb9 100644 --- a/src/test/java/puzzles/lightup/rules/FinishWithEmptyBasicRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/FinishWithEmptyBasicRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class FinishWithEmptyBasicRuleTest -{ +public class FinishWithEmptyBasicRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java b/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java index 73b74f698..8125f32dc 100644 --- a/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class LightOrEmptyCaseRuleTest -{ +public class LightOrEmptyCaseRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/MustLightBasicRuleTest.java b/src/test/java/puzzles/lightup/rules/MustLightBasicRuleTest.java index 531d7e474..db983aa11 100644 --- a/src/test/java/puzzles/lightup/rules/MustLightBasicRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/MustLightBasicRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class MustLightBasicRuleTest -{ +public class MustLightBasicRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java b/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java index ae44f6fb9..60e28fefd 100644 --- a/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class SatisfyNumberCaseRuleTest -{ +public class SatisfyNumberCaseRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java index 5a5c777b5..b3ff026ed 100644 --- a/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class TooFewBulbsContradictionRuleTest -{ +public class TooFewBulbsContradictionRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java index f58360fba..ac4c49520 100644 --- a/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java @@ -4,19 +4,16 @@ import org.junit.Test; import edu.rpi.legup.puzzle.lightup.LightUp; -public class TooManyBulbsContradictionRuleTest -{ +public class TooManyBulbsContradictionRuleTest { private static LightUp lightUp; @BeforeClass - public static void setUp() - { + public static void setUp() { lightUp = new LightUp(); } @Test - public void simpleCaseTest() - { + public void simpleCaseTest() { } } diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsBasicRuleTest.java index aed76abb9..ae40ba6cb 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsBasicRuleTest.java @@ -1,6 +1,7 @@ package puzzles.nurikabe.rules; //import javafx.scene.layout.Pane; + import legup.MockGameBoardFacade; import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; @@ -18,22 +19,19 @@ import java.awt.*; -public class BlackBetweenRegionsBasicRuleTest -{ +public class BlackBetweenRegionsBasicRuleTest { private static final BlackBetweenRegionsBasicRule RULE = new BlackBetweenRegionsBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions1Test() throws InvalidFileFormatException - { + public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions1Test() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsBasicRule/DiagonalBlackBetweenRegions1", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -51,12 +49,13 @@ public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions1Test() thro Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -64,8 +63,7 @@ public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions1Test() thro } @Test - public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions2Test() throws InvalidFileFormatException - { + public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions2Test() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsBasicRule/DiagonalBlackBetweenRegions2", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -83,12 +81,13 @@ public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions2Test() thro Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -96,8 +95,7 @@ public void BlackBetweenRegionsBasicRule_DiagonalBlackBetweenRegions2Test() thro } @Test - public void BlackBetweenRegionsBasicRule_HorizontalBlackBetweenRegionsTest() throws InvalidFileFormatException - { + public void BlackBetweenRegionsBasicRule_HorizontalBlackBetweenRegionsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsBasicRule/HorizontalBlackBetweenRegions", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -112,12 +110,13 @@ public void BlackBetweenRegionsBasicRule_HorizontalBlackBetweenRegionsTest() thr Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -125,8 +124,7 @@ public void BlackBetweenRegionsBasicRule_HorizontalBlackBetweenRegionsTest() thr } @Test - public void BlackBetweenRegionsBasicRule_VerticalBlackBetweenRegionsTest() throws InvalidFileFormatException - { + public void BlackBetweenRegionsBasicRule_VerticalBlackBetweenRegionsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsBasicRule/VerticalBlackBetweenRegions", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -141,12 +139,13 @@ public void BlackBetweenRegionsBasicRule_VerticalBlackBetweenRegionsTest() throw Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckBasicRuleTest.java index 44262373d..f630d02b5 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckBasicRuleTest.java @@ -16,22 +16,19 @@ import java.awt.*; -public class BlackBottleNeckBasicRuleTest -{ +public class BlackBottleNeckBasicRuleTest { private static final BlackBottleNeckBasicRule RULE = new BlackBottleNeckBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void BlackBottleNeckBasicRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void BlackBottleNeckBasicRule_TwoSurroundBlackTest() throws InvalidFileFormatException { // TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckBasicRule/SimpleBlackBottleNeck", nurikabe); // TreeNode rootNode = nurikabe.getTree().getRootNode(); // TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java index 6660f14df..d270204ac 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java @@ -14,37 +14,35 @@ import java.awt.*; -public class BlackOrWhiteCaseRuleTest -{ +public class BlackOrWhiteCaseRuleTest { private static final TooFewSpacesContradictionRule RULE = new TooFewSpacesContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); - NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); Point location = new Point(1, 1); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(location)) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java index 89a227489..7c0a00dd5 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java @@ -15,41 +15,39 @@ import java.awt.*; -public class BlackSquareContradictionRuleTest -{ +public class BlackSquareContradictionRuleTest { private static final BlackSquareContradictionRule RULE = new BlackSquareContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/SimpleBlackSquare", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); NurikabeCell cell1 = board.getCell(1, 1); NurikabeCell cell2 = board.getCell(1, 2); NurikabeCell cell3 = board.getCell(2, 1); NurikabeCell cell4 = board.getCell(2, 2); - Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/CornerBlackBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/CornerBlackBasicRuleTest.java index 6cbf73bc8..b0b198e2c 100644 --- a/src/test/java/puzzles/nurikabe/rules/CornerBlackBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/CornerBlackBasicRuleTest.java @@ -14,22 +14,19 @@ import java.awt.*; -public class CornerBlackBasicRuleTest -{ +public class CornerBlackBasicRuleTest { private static final CornerBlackBasicRule RULE = new CornerBlackBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void CornerBlackContradictionRule_SimpleCornerBlackTest() throws InvalidFileFormatException - { + public void CornerBlackContradictionRule_SimpleCornerBlackTest() throws InvalidFileFormatException { // TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe); // TreeNode rootNode = nurikabe.getTree().getRootNode(); // TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/nurikabe/rules/FillinBlackBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/FillinBlackBasicRuleTest.java index 0e1112a8f..46bd73bce 100644 --- a/src/test/java/puzzles/nurikabe/rules/FillinBlackBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/FillinBlackBasicRuleTest.java @@ -16,41 +16,39 @@ import java.awt.*; -public class FillinBlackBasicRuleTest -{ +public class FillinBlackBasicRuleTest { private static final FillinBlackBasicRule RULE = new FillinBlackBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void FillinBlackBasicRule_UnknownSurroundBlackTest() throws InvalidFileFormatException - { + public void FillinBlackBasicRule_UnknownSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/FillinBlackBasicRule/UnknownSurroundBlack", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = board.getCell(1,1); + NurikabeCell cell = board.getCell(1, 1); cell.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); Point location = new Point(1, 1); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(location)) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/FillinWhiteBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/FillinWhiteBasicRuleTest.java index 44e457670..7e6e92950 100644 --- a/src/test/java/puzzles/nurikabe/rules/FillinWhiteBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/FillinWhiteBasicRuleTest.java @@ -16,21 +16,18 @@ import java.awt.*; -public class FillinWhiteBasicRuleTest -{ +public class FillinWhiteBasicRuleTest { private static final FillinWhiteBasicRule RULE = new FillinWhiteBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void FillinWhiteBasicRule_UnknownSurroundWhiteTest() throws InvalidFileFormatException - { + public void FillinWhiteBasicRule_UnknownSurroundWhiteTest() throws InvalidFileFormatException { // TestUtilities.importTestBoard("puzzles/nurikabe/rules/FillinWhiteBasicRule/UnknownSurroundWhite", nurikabe); // TreeNode rootNode = nurikabe.getTree().getRootNode(); // TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java index b8aa8b6c5..11a5e8f7d 100644 --- a/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java @@ -14,22 +14,19 @@ import java.awt.*; -public class IsolateBlackContradictionRuleTest -{ +public class IsolateBlackContradictionRuleTest { private static final IsolateBlackContradictionRule RULE = new IsolateBlackContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void IsolateBlackContradictionRule_SimpleIsolateBlackTest() throws InvalidFileFormatException - { + public void IsolateBlackContradictionRule_SimpleIsolateBlackTest() throws InvalidFileFormatException { // TestUtilities.importTestBoard("puzzles/nurikabe/rules/IsolateBlackContradictionRule/SimpleIsolateBlack", nurikabe); // TreeNode rootNode = nurikabe.getTree().getRootNode(); // TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java index 4caa5499f..5d855ce40 100644 --- a/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java @@ -14,36 +14,34 @@ import java.awt.*; -public class MultipleNumbersContradictionRuleTest -{ +public class MultipleNumbersContradictionRuleTest { private static final MultipleNumbersContradictionRule RULE = new MultipleNumbersContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void MultipleNumbersContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void MultipleNumbersContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/MultipleNumbersContradictionRule/MultipleNumbers", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); - NurikabeBoard board = (NurikabeBoard)transition.getBoard(); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(new Point(0, 0)) || point.equals(new Point(2, 0))) { + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(new Point(0, 0)) || point.equals(new Point(2, 0))) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/NoNumbersContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/NoNumbersContradictionRuleTest.java index 25b61827b..2f13b7ccb 100644 --- a/src/test/java/puzzles/nurikabe/rules/NoNumbersContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/NoNumbersContradictionRuleTest.java @@ -14,37 +14,35 @@ import java.awt.*; -public class NoNumbersContradictionRuleTest -{ +public class NoNumbersContradictionRuleTest { private static final NoNumberContradictionRule RULE = new NoNumberContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberSurroundBlack", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); - NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); Point location = new Point(1, 1); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(location)) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/PreventBlackSquareBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/PreventBlackSquareBasicRuleTest.java index edca3b18e..b14dc4c43 100644 --- a/src/test/java/puzzles/nurikabe/rules/PreventBlackSquareBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/PreventBlackSquareBasicRuleTest.java @@ -16,40 +16,38 @@ import java.awt.*; -public class PreventBlackSquareBasicRuleTest -{ +public class PreventBlackSquareBasicRuleTest { private static final PreventBlackSquareBasicRule RULE = new PreventBlackSquareBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void PreventBlackSquareBasicRule_BottomLeftWhiteBlackSquareTest() throws InvalidFileFormatException - { + public void PreventBlackSquareBasicRule_BottomLeftWhiteBlackSquareTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/PreventBlackSquareBasicRule/BottomLeftWhiteBlackSquare", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = board.getCell(0,1); + NurikabeCell cell = board.getCell(0, 1); cell.setData(NurikabeType.WHITE.toValue()); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -57,26 +55,26 @@ public void PreventBlackSquareBasicRule_BottomLeftWhiteBlackSquareTest() throws } @Test - public void PreventBlackSquareBasicRule_BottomRightWhiteBlackSquareTest() throws InvalidFileFormatException - { + public void PreventBlackSquareBasicRule_BottomRightWhiteBlackSquareTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/PreventBlackSquareBasicRule/BottomRightWhiteBlackSquare", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = board.getCell(1,1); + NurikabeCell cell = board.getCell(1, 1); cell.setData(NurikabeType.WHITE.toValue()); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -84,26 +82,26 @@ public void PreventBlackSquareBasicRule_BottomRightWhiteBlackSquareTest() throws } @Test - public void PreventBlackSquareBasicRule_TopLeftWhiteBlackSquareTest() throws InvalidFileFormatException - { + public void PreventBlackSquareBasicRule_TopLeftWhiteBlackSquareTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/PreventBlackSquareBasicRule/TopLeftWhiteBlackSquare", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = board.getCell(0,0); + NurikabeCell cell = board.getCell(0, 0); cell.setData(NurikabeType.WHITE.toValue()); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -111,26 +109,26 @@ public void PreventBlackSquareBasicRule_TopLeftWhiteBlackSquareTest() throws Inv } @Test - public void PreventBlackSquareBasicRule_TopRightWhiteBlackSquareTest() throws InvalidFileFormatException - { + public void PreventBlackSquareBasicRule_TopRightWhiteBlackSquareTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/PreventBlackSquareBasicRule/TopRightWhiteBlackSquare", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = board.getCell(1,0); + NurikabeCell cell = board.getCell(1, 0); cell.setData(NurikabeType.WHITE.toValue()); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/SurroundRegionBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/SurroundRegionBasicRuleTest.java index 218ff5049..c1ffe679a 100644 --- a/src/test/java/puzzles/nurikabe/rules/SurroundRegionBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/SurroundRegionBasicRuleTest.java @@ -16,50 +16,48 @@ import java.awt.*; -public class SurroundRegionBasicRuleTest -{ +public class SurroundRegionBasicRuleTest { private static final SurroundRegionBasicRule RULE = new SurroundRegionBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void SurroundRegionBasicRule_SurroundRegionBlackTest() throws InvalidFileFormatException - { + public void SurroundRegionBasicRule_SurroundRegionBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/SurroundRegionBasicRule/SurroundRegionBlack", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell1 = board.getCell(1,0); + NurikabeCell cell1 = board.getCell(1, 0); cell1.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell1); - NurikabeCell cell2 = board.getCell(0,1); + NurikabeCell cell2 = board.getCell(0, 1); cell2.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell2); - NurikabeCell cell3 = board.getCell(2,1); + NurikabeCell cell3 = board.getCell(2, 1); cell3.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell3); - NurikabeCell cell4 = board.getCell(1,2); + NurikabeCell cell4 = board.getCell(1, 2); cell4.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell4); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -67,29 +65,29 @@ public void SurroundRegionBasicRule_SurroundRegionBlackTest() throws InvalidFile } @Test - public void SurroundRegionBasicRule_SurroundRegionBlackInCornerTest() throws InvalidFileFormatException - { + public void SurroundRegionBasicRule_SurroundRegionBlackInCornerTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/SurroundRegionBasicRule/SurroundRegionBlackInCorner", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell1 = board.getCell(1,0); + NurikabeCell cell1 = board.getCell(1, 0); cell1.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell1); - NurikabeCell cell2 = board.getCell(0,1); + NurikabeCell cell2 = board.getCell(0, 1); cell2.setData(NurikabeType.BLACK.toValue()); board.addModifiedData(cell2); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/TooFewSpacesContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/TooFewSpacesContradictionRuleTest.java index c46e9457c..b97daa6b5 100644 --- a/src/test/java/puzzles/nurikabe/rules/TooFewSpacesContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/TooFewSpacesContradictionRuleTest.java @@ -14,36 +14,34 @@ import java.awt.*; -public class TooFewSpacesContradictionRuleTest -{ +public class TooFewSpacesContradictionRuleTest { private static final TooFewSpacesContradictionRule RULE = new TooFewSpacesContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); - NurikabeBoard board = (NurikabeBoard)transition.getBoard(); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(new Point(1, 1))) { + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(new Point(1, 1))) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java index ba2e35b35..2783b1565 100644 --- a/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java @@ -14,22 +14,19 @@ import java.awt.*; -public class TooManySpacesContradictionRuleTest -{ +public class TooManySpacesContradictionRuleTest { private static final TooManySpacesContradictionRule RULE = new TooManySpacesContradictionRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void TooManySpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException - { + public void TooManySpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { // TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooManySpacesContradictionRule/TwoSurroundWhite", nurikabe); // TreeNode rootNode = nurikabe.getTree().getRootNode(); // TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/nurikabe/rules/WhiteBottleNeckBasicRuleTest.java b/src/test/java/puzzles/nurikabe/rules/WhiteBottleNeckBasicRuleTest.java index f4d6b17c5..8b17115da 100644 --- a/src/test/java/puzzles/nurikabe/rules/WhiteBottleNeckBasicRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/WhiteBottleNeckBasicRuleTest.java @@ -16,22 +16,19 @@ import java.awt.*; -public class WhiteBottleNeckBasicRuleTest -{ +public class WhiteBottleNeckBasicRuleTest { private static final WhiteBottleNeckBasicRule RULE = new WhiteBottleNeckBasicRule(); private static Nurikabe nurikabe; @BeforeClass - public static void setUp() - { + public static void setUp() { MockGameBoardFacade.getInstance(); nurikabe = new Nurikabe(); } @Test - public void WhiteBottleNeckBasicRule_SimpleWhiteBottleNeckTest() throws InvalidFileFormatException - { + public void WhiteBottleNeckBasicRule_SimpleWhiteBottleNeckTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/WhiteBottleNeckBasicRule/SimpleWhiteBottleNeck", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -44,12 +41,13 @@ public void WhiteBottleNeckBasicRule_SimpleWhiteBottleNeckTest() throws InvalidF Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } else { + } + else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -57,8 +55,7 @@ public void WhiteBottleNeckBasicRule_SimpleWhiteBottleNeckTest() throws InvalidF } @Test - public void WhiteBottleNeckBasicRule_NurikabeBoard1Test() throws InvalidFileFormatException - { + public void WhiteBottleNeckBasicRule_NurikabeBoard1Test() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/WhiteBottleNeckBasicRule/NurikabeBoard1", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -71,8 +68,8 @@ public void WhiteBottleNeckBasicRule_NurikabeBoard1Test() throws InvalidFileForm Assert.assertNotNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/java/puzzles/shorttruthtable/ShortTruthTableImporterTest.java b/src/test/java/puzzles/shorttruthtable/ShortTruthTableImporterTest.java index e44a1de6d..66df727ac 100644 --- a/src/test/java/puzzles/shorttruthtable/ShortTruthTableImporterTest.java +++ b/src/test/java/puzzles/shorttruthtable/ShortTruthTableImporterTest.java @@ -10,6 +10,4 @@ // } - - //} \ No newline at end of file diff --git a/src/test/java/puzzles/shorttruthtable/rules/BasicRuleAtomicTest.java b/src/test/java/puzzles/shorttruthtable/rules/BasicRuleAtomicTest.java index e0556341f..c06af20e9 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/BasicRuleAtomicTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/BasicRuleAtomicTest.java @@ -1,7 +1,6 @@ package puzzles.shorttruthtable.rules; -class BasicRuleAtomicTest{ - +class BasicRuleAtomicTest { } \ No newline at end of file