-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from HenryCullom/puzzle-editor
Puzzle editor now has framework to add element buttons
- Loading branch information
Showing
7 changed files
with
293 additions
and
4 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/edu/rpi/legup/controller/EditorElementController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package edu.rpi.legup.controller; | ||
|
||
import edu.rpi.legup.app.GameBoardFacade; | ||
import edu.rpi.legup.app.LegupPreferences; | ||
import edu.rpi.legup.history.*; | ||
import edu.rpi.legup.model.Puzzle; | ||
import edu.rpi.legup.model.elements.Element; | ||
import edu.rpi.legup.model.gameboard.CaseBoard; | ||
import edu.rpi.legup.model.rules.*; | ||
import edu.rpi.legup.model.tree.TreeElement; | ||
import edu.rpi.legup.model.tree.TreeElementType; | ||
import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton; | ||
import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; | ||
import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; | ||
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; | ||
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; | ||
import edu.rpi.legup.ui.puzzleeditorui.elementsview.ElementButton; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.util.List; | ||
|
||
import static edu.rpi.legup.app.GameBoardFacade.getInstance; | ||
|
||
public class EditorElementController implements ActionListener { | ||
protected Object lastSource; | ||
|
||
public EditorElementController() { | ||
super(); | ||
} | ||
|
||
public void buttonPressed(Element element) { | ||
// TODO: implement what happens when element is pressed | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
lastSource = e.getSource(); | ||
ElementButton button = (ElementButton) lastSource; | ||
buttonPressed(button.getElement()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package edu.rpi.legup.model.elements; | ||
|
||
import edu.rpi.legup.model.rules.RuleType; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
|
||
public abstract class Element { | ||
protected String elementID; | ||
protected String elementName; | ||
protected String description; | ||
|
||
protected String imageName; | ||
protected ImageIcon image; | ||
|
||
protected ElementType elementType; | ||
|
||
private final String INVALID_USE_MESSAGE; | ||
|
||
public Element(String elementID, String elementName, String description, String imageName) { | ||
this.elementID = elementID; | ||
this.elementName = elementName; | ||
this.description = description; | ||
this.imageName = imageName; | ||
this.INVALID_USE_MESSAGE = "Invalid use of the rule " + this.elementName; | ||
loadImage(); | ||
} | ||
|
||
private void loadImage() { | ||
if (imageName != null) { | ||
this.image = new ImageIcon(ClassLoader.getSystemResource(imageName)); | ||
//Resize images to be 100px wide | ||
Image image = this.image.getImage(); | ||
if(this.image.getIconWidth() < 120) return; | ||
int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); | ||
if(height==0){ | ||
System.out.println("height is 0 error"); | ||
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); | ||
Graphics2D g = bimage.createGraphics(); | ||
g.drawImage(image, 0, 0, 100, height, null); | ||
this.image = new ImageIcon(bimage); | ||
} | ||
} | ||
public String getElementName() { | ||
return elementName; | ||
} | ||
|
||
public void setElementName(String elementName) { | ||
this.elementName = elementName; | ||
} | ||
|
||
public String getElementID() { | ||
return elementID; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public ImageIcon getImageIcon() { | ||
return image; | ||
} | ||
|
||
public ElementType getElementType() { | ||
return elementType; | ||
} | ||
|
||
public String getInvalidUseOfRuleMessage() | ||
{ | ||
return this.INVALID_USE_MESSAGE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package edu.rpi.legup.model.elements; | ||
|
||
public enum ElementType { | ||
NURIKABE, TREETENT, LIGHTUP, SKYSCRAPERS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package edu.rpi.legup.ui.puzzleeditorui.elementsview; | ||
|
||
import edu.rpi.legup.model.elements.Element; | ||
import edu.rpi.legup.model.rules.Rule; | ||
|
||
import javax.swing.*; | ||
|
||
public class ElementButton extends JButton { | ||
|
||
private Element element; | ||
ElementButton(Element e) { | ||
super(e.getImageIcon()); | ||
this.element = e; | ||
} | ||
|
||
public Element getElement() { | ||
return element; | ||
} | ||
|
||
public void setElement(Element e) { | ||
this.element = e; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package edu.rpi.legup.ui.puzzleeditorui.elementsview; | ||
|
||
import edu.rpi.legup.controller.EditorElementController; | ||
import edu.rpi.legup.controller.RuleController; | ||
import edu.rpi.legup.ui.proofeditorui.rulesview.BasicRulePanel; | ||
import edu.rpi.legup.ui.proofeditorui.rulesview.CaseRulePanel; | ||
import edu.rpi.legup.ui.proofeditorui.rulesview.ContradictionRulePanel; | ||
import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.TitledBorder; | ||
import java.awt.*; | ||
|
||
public class ElementFrame extends JPanel { | ||
private static final String checkBox = "<font style=\"color:#00CD00\"> \u2714 </font>"; | ||
private static final String xBox = "<font style=\"color:#FF0000\"> \u2718 </font>"; | ||
private static final String htmlHead = "<html>"; | ||
private static final String htmlTail = "</html>"; | ||
|
||
private JTabbedPane tabbedPane; | ||
private JLabel status; | ||
private ButtonGroup buttonGroup; | ||
|
||
private EditorElementController controller; | ||
|
||
public ElementFrame(EditorElementController controller) { | ||
this.controller = controller; | ||
|
||
this.tabbedPane = new JTabbedPane(); | ||
this.status = new JLabel(); | ||
this.buttonGroup = new ButtonGroup(); | ||
|
||
setLayout(new BorderLayout()); | ||
setMinimumSize(new Dimension(250, 256)); | ||
setPreferredSize(new Dimension(330, 256)); | ||
|
||
add(tabbedPane); | ||
add(status, BorderLayout.SOUTH); | ||
|
||
TitledBorder title = BorderFactory.createTitledBorder("Rules"); | ||
title.setTitleJustification(TitledBorder.CENTER); | ||
setBorder(title); | ||
} | ||
|
||
public ButtonGroup getButtonGroup() { | ||
return buttonGroup; | ||
} | ||
|
||
public void resetSize() { | ||
int buttonWidth = ((ElementPanel) tabbedPane.getSelectedComponent()).getElementButtons()[0].getWidth(); | ||
this.setMinimumSize(new Dimension(2 * buttonWidth + 64, this.getHeight())); | ||
} | ||
|
||
public EditorElementController getController() { | ||
return controller; | ||
} | ||
|
||
public JTabbedPane getTabbedPane() { | ||
return tabbedPane; | ||
} | ||
} |
80 changes: 79 additions & 1 deletion
80
src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,82 @@ | ||
package edu.rpi.legup.ui.puzzleeditorui.elementsview; | ||
|
||
public class ElementPanel { | ||
import edu.rpi.legup.model.rules.Rule; | ||
import edu.rpi.legup.ui.WrapLayout; | ||
import edu.rpi.legup.model.elements.Element; | ||
import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton; | ||
|
||
import javax.swing.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class ElementPanel extends JPanel { | ||
protected ImageIcon icon; | ||
protected String name; | ||
protected String toolTip; | ||
protected ElementButton[] elementButtons; | ||
protected ElementFrame elementFrame; | ||
protected List<? extends Element> elements; | ||
|
||
public ElementPanel(ElementFrame eFrame) { | ||
this.elementFrame = eFrame; | ||
this.elements = new ArrayList<>(); | ||
setLayout(new WrapLayout()); | ||
} | ||
public void setRules(List<? extends Element> elements) { | ||
this.elements = elements; | ||
clearButtons(); | ||
|
||
elementButtons = new ElementButton[elements.size()]; | ||
|
||
for (int i = 0; i < elements.size(); i++) { | ||
Element element = elements.get(i); | ||
elementButtons[i] = new ElementButton(element); | ||
elementFrame.getButtonGroup().add(elementButtons[i]); | ||
|
||
elementButtons[i].setToolTipText(element.getElementName() + ": " + element.getDescription()); | ||
elementButtons[i].addActionListener(elementFrame.getController()); | ||
add(elementButtons[i]); | ||
} | ||
revalidate(); | ||
} | ||
|
||
protected void clearButtons() { | ||
if (elementButtons != null) { | ||
removeAll(); | ||
for (int x = 0; x < elementButtons.length; ++x) { | ||
elementButtons[x].removeActionListener(elementFrame.getController()); | ||
} | ||
} | ||
} | ||
|
||
public ElementButton[] getElementButtons() { | ||
return elementButtons; | ||
} | ||
|
||
public ImageIcon getIcon() { | ||
return icon; | ||
} | ||
|
||
public void setIcon(ImageIcon icon) { | ||
this.icon = icon; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getToolTip() { | ||
return toolTip; | ||
} | ||
|
||
public void setToolTip(String toolTip) { | ||
this.toolTip = toolTip; | ||
} | ||
} | ||
|