Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version2.2 #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OrcMathGUI/BookCatalog.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
The Hunchback of Notre Dame,Victor Hugo,1024
Great Expectations,Charles Dickens,987
Jane Eyre,Charlotte Bronte,780
Do Androids Dream of Electric Sheep,Philip K. Dick,756
The Martian,Andy Weir,430
Ready Player One,Ernest Cline,478
The Underground Railroad,Colson Whitehead,610
Binary file removed OrcMathGUI/images/answer1.png
Binary file not shown.
Binary file removed OrcMathGUI/images/question1.png
Binary file not shown.
Binary file added OrcMathGUI/resources/Holiday.ttf
Binary file not shown.
Binary file added OrcMathGUI/resources/Snowinter.ttf
Binary file not shown.
Binary file added OrcMathGUI/resources/falling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added OrcMathGUI/resources/newyork.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added OrcMathGUI/resources/santa.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added OrcMathGUI/resources/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added OrcMathGUI/resources/winterscape.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 61 additions & 3 deletions OrcMathGUI/src/guiPlayer/Book.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package guiPlayer;

import java.awt.Color;
import java.awt.Graphics2D;

import guiTeacher.components.Action;
import guiTeacher.components.Component;
import guiTeacher.interfaces.Clickable;

public class Book extends Component {
public class Book extends Component implements Clickable{

private String title;
private String author;
private int pages;

private Color color;
private boolean selected;
private boolean onShelf;


public Book(String title, String author, int pages) {
super(0, 0, 300, 1*pages);
super(0, 0, 300, 10+pages/12);
this.title = title;
this.author = author;
this.pages = pages;
this.selected = false;
this.color = new Color(100+(int)(100*Math.random()),100+(int)(100*Math.random()),100+(int)(100*Math.random()));
update();
}


Expand All @@ -26,8 +34,58 @@ public String toString(){

@Override
public void update(Graphics2D g) {
g.setColor(new Color(100,200,255));
if(selected){
g.fillOval(1, getHeight()/2-10, 20, 20);

}
else {
g.setColor(Color.white);
g.fillOval(1, getHeight()/2-10, 20, 20);
g.setColor(new Color(100,200,255));
g.drawOval(1, getHeight()/2-10, 20, 20);
}
g.setColor(this.color);
g.fillRect(22, 0, getWidth()-23, getHeight()-1);
g.setColor(Color.black);
g.drawString(title, 26, getHeight()/2-6);
g.drawRect(22, 0, getWidth()-23, getHeight()-1);
}


@Override
public boolean isHovered(int x, int y) {
return x>getX() && x < getX()+getWidth() && y > getY() && y < getY() + getHeight();
}


@Override
public void act() {
selected = !selected;
update();
}



public boolean isOnShelf() {
return onShelf;
}


public void setOnShelf(boolean onShelf) {
this.onShelf = onShelf;
}


@Override
public void setAction(Action a) {
// TODO Auto-generated method stub

}


public boolean isSelected() {
return selected;
}

}
59 changes: 40 additions & 19 deletions OrcMathGUI/src/guiPlayer/CatalogMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ private void menu() {
}
}

public ArrayList<Book> getBooks(){
return catalog;
}

public Book getBook(int index){
return catalog.get(index);
}

private void create() {

boolean running = true;
while(running){
showCatalog();
Expand Down Expand Up @@ -72,10 +80,11 @@ private void add() {
}

private int getIntegerInput() {
String text = in.nextLine();

int value = 0;
boolean valid = false;
while(!valid){
String text = in.nextLine();
try{
value = Integer.parseInt(text);
valid = true;
Expand All @@ -96,11 +105,11 @@ private static String getStringInput(){
}


private void addBook(Book b){
public void addBook(Book b){
catalog.add(b);
}

private void save() {
public void save() {
try{
FileWriter fw=new FileWriter("BookCatalog.csv");
for(Book b: catalog){
Expand Down Expand Up @@ -148,29 +157,41 @@ private void load() {
//use this boolean to control the while loop. The user should have multiple chances to enter a correct filename
boolean opened = false;
while(!opened){
try {

System.out.println("Enter a file to open");
fileName = in.nextLine();
FileReader fileReader = new FileReader(new File(fileName));
String line = "";
//a BufferedReader enables us to read teh file one line at a time
BufferedReader br = new BufferedReader(fileReader);
while ((line = br.readLine()) != null) {
opened = read(new File(fileName));


}
create();

}

String[] param = line.split(",");
//add a new Book for each line in the save file
catalog.add(new Book(param[0],param[1],Integer.parseInt(param[2])));
public boolean read(File f){
try{
FileReader fileReader = new FileReader(f);
String line = "";
//a BufferedReader enables us to read teh file one line at a time
BufferedReader br = new BufferedReader(fileReader);
while ((line = br.readLine()) != null) {

String[] param = line.split(",");
//add a new Book for each line in the save file
catalog.add(new Book(param[0],param[1],Integer.parseInt(param[2])));



}
br.close();
opened = true;
}catch (IOException e) {
System.out.println("The file name you specified does not exist.");
}
br.close();
return true;
}catch(Exception e){
System.out.println("The file name you specified does not exist.");
return false;
}
create();
}

public void removeBook(Book b) {
catalog.remove(b);
}
}
29 changes: 29 additions & 0 deletions OrcMathGUI/src/guiPlayer/CatalogMakerGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package guiPlayer;

import guiTeacher.GUIApplication;

public class CatalogMakerGUI extends GUIApplication {

/**
*
*/
private static final long serialVersionUID = 7548071104587737267L;

public CatalogMakerGUI(int width, int height) {
super(width, height);
setVisible(true);
}

public static void main(String[] args){
CatalogMakerGUI catalog = new CatalogMakerGUI(800, 550);
Thread runner = new Thread(catalog);
runner.start();
}

@Override
public void initScreen() {
CatalogScreen screen = new CatalogScreen(getWidth(), getHeight());
setScreen(screen);
}

}
155 changes: 155 additions & 0 deletions OrcMathGUI/src/guiPlayer/CatalogScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package guiPlayer;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import guiTeacher.components.*;
import guiTeacher.interfaces.FileRequester;
import guiTeacher.interfaces.Visible;
import guiTeacher.userInterfaces.FullFunctionScreen;

public class CatalogScreen extends FullFunctionScreen implements FileRequester{

private TextField[] fields;
private CatalogMaker catalog;
private Button addButton;
private Button saveButton;
private FileOpenButton openButton;
// private TextArea books;

public CatalogScreen(int width, int height) {
super(width, height);
// TODO Auto-generated constructor stub
}

@Override
public void initAllObjects(List<Visible> viewObjects) {
StyledComponent.setButtonOutline(true);
catalog = new CatalogMaker();
fields = new TextField[3];
String[] titles = {"Title","Author","Pages"};
for(int i = 0; i < fields.length; i++){
fields[i] = new TextField(40, 40+60*i, 270, 30, "",titles[i]);
viewObjects.add(fields[i]);
if(i==2){
fields[i].setInputType(TextField.INPUT_TYPE_NUMERIC);
}
}
// books = new TextArea(250,40,200,180,"");
addButton = new Button(40, 300, 100, 30, "Add", new Action() {

@Override
public void act() {
addBook();
}
});
viewObjects.add(addButton);
saveButton = new Button(40, 340, 100, 30, "Save", new Action() {

@Override
public void act() {
catalog.save();
}
});
viewObjects.add(saveButton);
openButton = new FileOpenButton(145, 340, 100, 30, null, this);
viewObjects.add(openButton);
Button deleteButton = new Button(145,300,100,30,"Delete", new Action(){

@Override
public void act() {
deleteSelectedBooks();
}



});
viewObjects.add(deleteButton);
// viewObjects.add(books);
}

public void deleteSelectedBooks() {
//In ArrayList, to delete you must use a standard for loop

for(int i=0; i < catalog.getBooks().size(); i++){
Book b = catalog.getBook(i);
if(b.isSelected()){
//remove from screen
remove(b);
//remove from database
catalog.removeBook(b);
//compensate for deletion
i--;
}
}
arrangeStack();
}

/**
* Iterates through all books on shelf and adjusts y-values so books appear stacked.
*/
private void arrangeStack(){
int y = getHeight();
for(Book c: catalog.getBooks()){
if(c.isOnShelf()){
y-=c.getHeight();
c.setY(y);
}
}

}

public void addBook(){
int pages = 0;
try{
pages = Integer.parseInt(fields[2].getText());
Book newBook = new Book (fields[0].getText(),fields[1].getText(),pages);
catalog.addBook(newBook);
// books.setText(books.getText()+fields[0].getText()+"\n");
for(TextField t: fields){
t.setText("");
t.update();
}
addBookToStack(newBook);
}catch(NumberFormatException n){
fields[2].setText("Enter a valid number of pages");
}
}

/**
* Adds a book that is already in the catalog to the visual shelf
* @param b
*/
private void addBookToStack(Book b){
//x value for all books
int x = 460;
b.setX(x);
//add book to screen
addObject(b);
//mark book as having been added
b.setOnShelf(true);
//adjust y-values of all books
arrangeStack();
}

@Override
public void setFile(File f) {
catalog.read(f);
// books.setText("");
for(Book b: catalog.getBooks()){
// books.setText(books.getText()+b+"\n");
addBookToStack(b);
}

}

@Override
public JFrame getWindow() {
// TODO Auto-generated method stub
return null;
}

}
Loading