summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-04-24 13:48:32 +0200
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-04-24 13:48:32 +0200
commit35fa56d0033b95d99f082442ed55a0d1aee231f8 (patch)
tree838599497975d1e9457e56914f6a0a9a292c8420
parent1bdd410a39e7abec4c1691d721af864f2838c796 (diff)
downloadmobi_reader-35fa56d0033b95d99f082442ed55a0d1aee231f8.tar.gz
mobi_reader-35fa56d0033b95d99f082442ed55a0d1aee231f8.tar.bz2
mobi_reader-35fa56d0033b95d99f082442ed55a0d1aee231f8.tar.xz
mobi_reader-35fa56d0033b95d99f082442ed55a0d1aee231f8.zip
Classes author and book to store data of books. Some changes in gui.
-rw-r--r--MobiReader/src/mobireader/Author.java53
-rw-r--r--MobiReader/src/mobireader/Book.java54
-rw-r--r--MobiReader/src/mobireader/MobiReader.java35
-rw-r--r--MobiReader/src/mobireader/gui/model/GuiModel.java18
-rw-r--r--MobiReader/src/mobireader/gui/ui/AppMain.java334
5 files changed, 463 insertions, 31 deletions
diff --git a/MobiReader/src/mobireader/Author.java b/MobiReader/src/mobireader/Author.java
new file mode 100644
index 0000000..0c78792
--- /dev/null
+++ b/MobiReader/src/mobireader/Author.java
@@ -0,0 +1,53 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mobireader;
+
+import java.util.List;
+import com.google.common.base.Joiner;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author att
+ */
+public class Author {
+ String name;
+ String additionalInfo = "No additional information available";
+ List<String> writtenTitles = new ArrayList<>();
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public Author(String name, String titleOfBook)
+ {
+ writtenTitles.add(titleOfBook);
+ this.name = name;
+ }
+
+ public Author(String name, ArrayList<String> titles)
+ {
+ writtenTitles = titles;
+ this.name = name;
+ }
+
+ public void addAdditionalInfo(String info)
+ {
+ this.additionalInfo = info;
+ }
+
+ public String provideAllInfo()
+ {
+ String separator = "\n";
+ String info = "Name: " + this.name + "\n";
+ info += "Wrote:\n" + Joiner.on(separator).join(this.writtenTitles);
+ info += "\n" + this.additionalInfo;
+ return info;
+ }
+
+
+
+}
diff --git a/MobiReader/src/mobireader/Book.java b/MobiReader/src/mobireader/Book.java
new file mode 100644
index 0000000..fa5a4d6
--- /dev/null
+++ b/MobiReader/src/mobireader/Book.java
@@ -0,0 +1,54 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mobireader;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.joda.time.DateTime;
+
+/**
+ *
+ * @author att
+ */
+public class Book {
+ String title;
+ Author author;
+ DateTime timestamp;
+ public Book(String title, Author author, DateTime timestamp)
+ {
+ this.title = title;
+ this.author = author;
+ this.timestamp = timestamp;
+ }
+ public Book(String title, Author author)
+ {
+ this.title = title;
+ this.author = author;
+ this.timestamp = new DateTime();
+ }
+ public String getTitle()
+ {
+ return this.title;
+ }
+ public Author getAuthor()
+ {
+ return this.author;
+ }
+ public DateTime getTimestamp()
+ {
+ return this.timestamp;
+ }
+ static public List<Book> createSomeExamples()
+ {
+ List<Book> books = new ArrayList<>();
+ books.add(new Book("Hakuna Matata", new Author("Mr. Elephant", "Hakuna Matata")));
+ books.add(new Book("Life of a star", new Author("Elvis Presley","Life of a star")));
+ String[] titles = {"Real physics", "Kartofle"};
+ books.add(new Book("Real physics", new Author("Wise old physicist",
+ new ArrayList<String>(Arrays.asList(titles)))));
+ return books;
+ }
+}
diff --git a/MobiReader/src/mobireader/MobiReader.java b/MobiReader/src/mobireader/MobiReader.java
index e0a8489..3e93470 100644
--- a/MobiReader/src/mobireader/MobiReader.java
+++ b/MobiReader/src/mobireader/MobiReader.java
@@ -1,39 +1,12 @@
package mobireader;
-import javafx.application.Application;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-import javafx.scene.Scene;
-import javafx.scene.control.Button;
-import javafx.scene.layout.StackPane;
-import javafx.stage.Stage;
+import mobireader.gui.ui.AppMain;
-public class MobiReader extends Application {
-
- @Override
- public void start(Stage primaryStage) {
- Button btn = new Button();
- btn.setText("Display help");
- btn.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- System.out.println("Read the docs! Trololo.");
- }
- });
-
- StackPane root = new StackPane();
- root.getChildren().add(btn);
-
- Scene scene = new Scene(root, 300, 250);
-
- primaryStage.setTitle("Hello World!");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
-
+public class MobiReader {
public static void main(String[] args) {
- launch(args);
+ AppMain.main(args);
+
}
}
diff --git a/MobiReader/src/mobireader/gui/model/GuiModel.java b/MobiReader/src/mobireader/gui/model/GuiModel.java
new file mode 100644
index 0000000..aba7616
--- /dev/null
+++ b/MobiReader/src/mobireader/gui/model/GuiModel.java
@@ -0,0 +1,18 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mobireader.gui.model;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+
+/**
+ *
+ * @author att
+ */
+public class GuiModel {
+
+ public ObservableList listViewItems = FXCollections.observableArrayList();
+
+} \ No newline at end of file
diff --git a/MobiReader/src/mobireader/gui/ui/AppMain.java b/MobiReader/src/mobireader/gui/ui/AppMain.java
new file mode 100644
index 0000000..1059de7
--- /dev/null
+++ b/MobiReader/src/mobireader/gui/ui/AppMain.java
@@ -0,0 +1,334 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mobireader.gui.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import javafx.application.Application;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.event.ActionEvent;
+import javafx.event.Event;
+import javafx.event.EventHandler;
+import javafx.geometry.Insets;
+import javafx.geometry.Orientation;
+import javafx.geometry.Pos;
+import javafx.scene.Node;
+import javafx.scene.Scene;
+import javafx.scene.SceneBuilder;
+import javafx.scene.control.Accordion;
+import javafx.scene.control.AccordionBuilder;
+import javafx.scene.control.Button;
+import javafx.scene.control.ButtonBuilder;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.CheckBoxBuilder;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.ChoiceBoxBuilder;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.ContextMenuBuilder;
+import javafx.scene.control.HyperlinkBuilder;
+import javafx.scene.control.Label;
+import javafx.scene.control.LabelBuilder;
+import javafx.scene.control.ListView;
+import javafx.scene.control.ListViewBuilder;
+import javafx.scene.control.MenuBar;
+import javafx.scene.control.MenuBarBuilder;
+import javafx.scene.control.MenuBuilder;
+import javafx.scene.control.MenuButtonBuilder;
+import javafx.scene.control.MenuItemBuilder;
+import javafx.scene.control.PasswordField;
+import javafx.scene.control.PasswordFieldBuilder;
+import javafx.scene.control.ProgressBar;
+import javafx.scene.control.ProgressBarBuilder;
+import javafx.scene.control.ProgressIndicator;
+import javafx.scene.control.ProgressIndicatorBuilder;
+import javafx.scene.control.RadioButton;
+import javafx.scene.control.RadioButtonBuilder;
+import javafx.scene.control.ScrollBar;
+import javafx.scene.control.ScrollBarBuilder;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.control.ScrollPaneBuilder;
+import javafx.scene.control.SelectionMode;
+import javafx.scene.control.Separator;
+import javafx.scene.control.Slider;
+import javafx.scene.control.SliderBuilder;
+import javafx.scene.control.SplitMenuButtonBuilder;
+import javafx.scene.control.SplitPane;
+import javafx.scene.control.SplitPaneBuilder;
+import javafx.scene.control.Tab;
+import javafx.scene.control.TabBuilder;
+import javafx.scene.control.TabPane;
+import javafx.scene.control.TabPaneBuilder;
+import javafx.scene.control.TableColumnBuilder;
+import javafx.scene.control.TableView;
+import javafx.scene.control.TableViewBuilder;
+import javafx.scene.control.TextArea;
+import javafx.scene.control.TextAreaBuilder;
+import javafx.scene.control.TextField;
+import javafx.scene.control.TextFieldBuilder;
+import javafx.scene.control.TitledPane;
+import javafx.scene.control.TitledPaneBuilder;
+import javafx.scene.control.ToggleButton;
+import javafx.scene.control.ToggleButtonBuilder;
+import javafx.scene.control.ToggleGroup;
+import javafx.scene.control.ToolBar;
+import javafx.scene.control.ToolBarBuilder;
+import javafx.scene.control.Tooltip;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeItemBuilder;
+import javafx.scene.control.TreeView;
+import javafx.scene.control.TreeViewBuilder;
+import javafx.scene.control.cell.PropertyValueFactory;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.input.KeyCombination;
+import javafx.scene.input.MouseButton;
+import javafx.scene.input.MouseEvent;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.BorderPaneBuilder;
+import javafx.scene.layout.HBoxBuilder;
+import javafx.scene.layout.StackPaneBuilder;
+import javafx.scene.layout.VBox;
+import javafx.scene.layout.VBoxBuilder;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.CircleBuilder;
+import javafx.scene.shape.RectangleBuilder;
+import javafx.scene.web.HTMLEditor;
+import javafx.scene.web.HTMLEditorBuilder;
+import javafx.scene.web.WebView;
+import javafx.scene.web.WebViewBuilder;
+import javafx.stage.Popup;
+import javafx.stage.PopupBuilder;
+import javafx.stage.Stage;
+import mobireader.Book;
+import mobireader.gui.model.GuiModel;
+
+/**
+ *
+ * @author att
+ */
+public class AppMain extends Application {
+
+ // A reference to the model
+ GuiModel model = new GuiModel();
+
+ Stage stage;
+ CheckBox checkBox;
+ ContextMenu contextMenu;
+ Label htmlLabel;
+ Popup alertPopup;
+ Tab webViewTab;
+ List<Book> myBooks = Book.createSomeExamples();
+
+ public static void main(String[] args) {
+ Application.launch(args);
+ }
+
+ @Override
+ public void start(final Stage primaryStage) {
+ stage = primaryStage;
+ Scene scene = SceneBuilder.create()
+ .width(800)
+ .height(600)
+ .root(
+ BorderPaneBuilder.create()
+ .top(
+ VBoxBuilder.create()
+ .children(
+ createMenus()
+ )
+ .build()
+ )
+ .center(createTabs())
+ .build()
+ )
+ .build();
+
+ stage.setScene(scene);
+ stage.setTitle("Mobi reader");
+ stage.show();
+ }
+
+ MenuBar createMenus() {
+ MenuBar menuBar = MenuBarBuilder.create()
+ .menus(
+ MenuBuilder.create()
+ .text("Edit")
+ .items(
+ MenuItemBuilder.create()
+ .text("Cut")
+ .build(),
+ MenuItemBuilder.create()
+ .text("Copy")
+ .build(),
+ MenuItemBuilder.create()
+ .text("Paste")
+ .build()
+ )
+ .build()
+ )
+ .build();
+
+ return menuBar;
+ }
+
+ TabPane createTabs() {
+ final WebView webView;
+ TabPane tabPane = TabPaneBuilder.create()
+ .tabs(
+ TabBuilder.create()
+ .text("Your books")
+ .content(createAddedBooksView())
+ .closable(false)
+ .build(),
+ TabBuilder.create()
+ .text("Add a book")
+ .content(createScrollMiscDemoNode())
+ .closable(false)
+ .build()
+ )
+ .build();
+
+ return tabPane;
+ }
+
+ TreeItem createBookTreeItem (Book book)
+ {
+ return TreeItemBuilder.create()
+ .value(book.getTitle())
+ .children(
+ TreeItemBuilder.create()
+ .value("Author: " + book.getAuthor().getName())
+ .children(
+ TreeItemBuilder.create()
+ .value(book.getAuthor().provideAllInfo())
+ .build()
+ )
+ .build(),
+ TreeItemBuilder.create()
+ .value("Added: " + book.getTimestamp())
+ .build()
+ )
+ .build();
+ }
+
+ TreeItem createTreeViewOfBooksByAuthor(List<Book> books)
+ {
+ List<TreeItem> bookItems= new ArrayList<>();
+ for (Book book : books)
+ {
+ bookItems.add(createBookTreeItem(book));
+ }
+ return TreeItemBuilder.create()
+ .value("Root")
+ .children(
+ bookItems.get(0),
+ bookItems.get(1),
+ bookItems.get(2)
+ )
+ .build();
+ }
+
+ Node createAddedBooksView() {
+ TreeView treeView = TreeViewBuilder.create()
+ .minWidth(150)
+ .showRoot(false)
+ .editable(false)
+ .root(
+ createTreeViewOfBooksByAuthor(myBooks)
+ )
+ .build();
+
+ ListView listView = ListViewBuilder.create()
+ .items(model.listViewItems)
+ .build();
+
+ SplitPane splitPane = SplitPaneBuilder.create()
+ .items(
+ treeView,
+ listView
+ )
+ .build();
+
+ treeView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
+ treeView.getSelectionModel().selectedItemProperty()
+ .addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue observable, Object oldValue,
+ Object newValue) {
+ TreeItem treeItem = (TreeItem)newValue;
+ if (newValue != null && treeItem.isLeaf()) {
+ model.listViewItems.clear();
+ for (int i = 1; i <= 1; i++) {
+ model.listViewItems.add(treeItem.getValue());
+ }
+ }
+ }
+ });
+
+ return splitPane;
+ }
+
+ Node createScrollMiscDemoNode() {
+ ScrollPane scrollPane = ScrollPaneBuilder.create()
+ .hbarPolicy(ScrollPane.ScrollBarPolicy.NEVER)
+ .vbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED)
+ .onMousePressed(new EventHandler<MouseEvent>() {
+ public void handle(MouseEvent me) {
+ if (me.getButton() == MouseButton.SECONDARY) {
+ contextMenu.show(stage, me.getScreenX(), me.getScreenY());
+ }
+ }
+ })
+ .build();
+ return scrollPane;
+ }
+
+ Popup createAlertPopup(String text) {
+ Button okButton;
+ alertPopup = PopupBuilder.create()
+ .content(
+ StackPaneBuilder.create()
+ .children(
+ RectangleBuilder.create()
+ .width(300)
+ .height(200)
+ .arcWidth(20)
+ .arcHeight(20)
+ .fill(Color.LIGHTBLUE)
+ .stroke(Color.GRAY)
+ .strokeWidth(2)
+ .build(),
+ BorderPaneBuilder.create()
+ .center(
+ htmlLabel = LabelBuilder.create()
+ .text(text)
+ .wrapText(true)
+ .maxWidth(280)
+ .maxHeight(140)
+ .build()
+ )
+ .bottom(
+ okButton = ButtonBuilder.create()
+ .text("OK")
+ .onAction(new EventHandler<ActionEvent>() {
+ @Override public void handle(ActionEvent e) {
+ alertPopup.hide();
+ }
+ })
+ .build()
+ )
+ .build()
+ )
+ .build()
+ )
+ .build();
+
+ BorderPane.setAlignment(okButton, Pos.CENTER);
+ BorderPane.setMargin(okButton, new Insets(10, 0, 10, 0));
+ return alertPopup;
+ }
+}
+