1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

simple toolbar implementation has been added

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@124 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Nikolay Pultsin 2007-11-13 17:37:53 +00:00
parent ef9eb40af6
commit aa6d9826ee
25 changed files with 123 additions and 28 deletions

BIN
icons/toolbar/addbook.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
icons/toolbar/bookinfo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icons/toolbar/books.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
icons/toolbar/contents.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

BIN
icons/toolbar/find.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
icons/toolbar/findnext.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
icons/toolbar/findprev.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icons/toolbar/help.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
icons/toolbar/history.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
icons/toolbar/home.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
icons/toolbar/leftarrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icons/toolbar/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -0,0 +1,44 @@
package org.fbreader.fbreader;
public enum ActionCode {
// please, don't change these numbers
// add new action id's at end of this enumeration
NONE,// = 0,
SHOW_COLLECTION,// = 1,
SHOW_OPTIONS,// = 2,
UNDO,// = 3,
REDO,// = 4,
SHOW_CONTENTS,// = 5,
SEARCH,// = 6,
FIND_PREVIOUS,// = 7,
FIND_NEXT,// = 8,
LARGE_SCROLL_FORWARD,// = 9,
LARGE_SCROLL_BACKWARD,// = 10,
SMALL_SCROLL_FORWARD,// = 11,
SMALL_SCROLL_BACKWARD,// = 12,
MOUSE_SCROLL_FORWARD,// = 13,
MOUSE_SCROLL_BACKWARD,// = 14,
SCROLL_TO_HOME,// = 15,
SCROLL_TO_START_OF_TEXT,// = 16,
SCROLL_TO_END_OF_TEXT,// = 17,
CANCEL,// = 18,
INCREASE_FONT,// = 19,
DECREASE_FONT,// = 20,
SHOW_HIDE_POSITION_INDICATOR,// = 21,
TOGGLE_FULLSCREEN,// = 22,
FULLSCREEN_ON,// = 23,
ADD_BOOK,// = 24,
SHOW_BOOK_INFO,// = 25,
SHOW_HELP,// = 26,
ROTATE_SCREEN,// = 27,
SHOW_LAST_BOOKS,// = 28,
QUIT,// = 29,
OPEN_PREVIOUS_BOOK,// = 30,
FINGER_TAP_SCROLL_FORWARD,// = 31,
FINGER_TAP_SCROLL_BACKWARD,// = 32,
GOTO_NEXT_TOC_SECTION,// = 33,
GOTO_PREVIOUS_TOC_SECTION,// = 34,
COPY_SELECTED_TEXT_TO_CLIPBOARD,// = 35,
CLEAR_SELECTION,// = 36,
OPEN_SELECTED_TEXT_IN_DICTIONARY,// = 37,
};

View file

@ -2,16 +2,45 @@ package org.fbreader.fbreader;
import org.zlibrary.core.application.ZLApplication;
import org.zlibrary.core.application.ZLKeyBindings;
import org.zlibrary.core.resources.ZLResourceKey;
import org.zlibrary.text.view.ZLTextView;
public class FBReader extends ZLApplication {
public FBReader(String fileName) {
super("Sample");
addToolbarButton(ActionCode.SHOW_COLLECTION, "books");
addToolbarButton(ActionCode.SHOW_LAST_BOOKS, "history");
addToolbarButton(ActionCode.ADD_BOOK, "addbook");
getToolbar().addSeparator();
addToolbarButton(ActionCode.SCROLL_TO_HOME, "home");
addToolbarButton(ActionCode.UNDO, "leftarrow");
addToolbarButton(ActionCode.REDO, "rightarrow");
getToolbar().addSeparator();
addToolbarButton(ActionCode.SHOW_CONTENTS, "contents");
getToolbar().addSeparator();
addToolbarButton(ActionCode.SEARCH, "find");
addToolbarButton(ActionCode.FIND_NEXT, "findnext");
addToolbarButton(ActionCode.FIND_PREVIOUS, "findprev");
getToolbar().addSeparator();
addToolbarButton(ActionCode.SHOW_BOOK_INFO, "bookinfo");
addToolbarButton(ActionCode.SHOW_OPTIONS, "settings");
getToolbar().addSeparator();
addToolbarButton(ActionCode.ROTATE_SCREEN, "rotatescreen");
//if (ShowHelpIconOption.value()) {
getToolbar().addSeparator();
addToolbarButton(ActionCode.SHOW_HELP, "help");
//}
ZLTextView view = new ZLTextView(this, getContext());
view.setModel(fileName);
setView(view);
}
private final void addToolbarButton(ActionCode code, String name) {
getToolbar().addButton(code.ordinal(), new ZLResourceKey(name));
}
public ZLKeyBindings keyBindings() {
return null;
}

View file

@ -74,7 +74,10 @@ public abstract class ZLApplication extends ZLApplicationBase {
}
public Toolbar getToolbar() {
return this.myToolbar;
if (myToolbar == null) {
myToolbar = new Toolbar();
}
return myToolbar;
}
public Menubar getMenubar() {

View file

@ -14,26 +14,26 @@ public class ButtonItem extends Item {
myTooltip = tooltip;
}
public Type type() {
public Type getType() {
return Type.BUTTON;
}
public int actionId() {
public int getActionId() {
return myActionId;
}
public String iconName() {
public String getIconName() {
return myIconName;
}
public String tooltip() {
public String getTooltip() {
if (!myTooltip.hasValue()) {
return "";
}
return myTooltip.value();
}
public ButtonGroup buttonGroup() {
public ButtonGroup getButtonGroup() {
return myButtonGroup;
}

View file

@ -1,11 +1,13 @@
package org.zlibrary.core.application.toolbar;
abstract public class Item {
public enum Type {
BUTTON,
OPTION_ENTRY,
SEPARATOR
}
public Item() {}
public abstract Type type();
boolean isButton() {
return type() == Type.BUTTON;
}
public abstract Type getType();
}

View file

@ -6,7 +6,7 @@ public class OptionEntryItem extends Item {
//public OptionEntryItem(ZLOptionEntry entry) {
//myOptionEntry = entry;
//}
public Type type() {
public Type getType() {
return Type.OPTION_ENTRY;
}

View file

@ -1,7 +1,7 @@
package org.zlibrary.core.application.toolbar;
public class SeparatorItem extends Item {
public Type type() {
public Type getType() {
return Type.SEPARATOR;
}
}

View file

@ -2,20 +2,26 @@ package org.zlibrary.core.application.toolbar;
import java.util.Collections;
import java.util.List;
import java.util.LinkedList;
import org.zlibrary.core.resources.ZLResource;
import org.zlibrary.core.resources.ZLResourceKey;
public class Toolbar {
private List<Item> myItems;
private ZLResource myResource;
private List<Item> myItems;
private ZLResource myResource;
public Toolbar() {
myItems = new LinkedList<Item>();
myResource = ZLResource.resource("toolbar");
}
public void addButton(int actionId, ZLResourceKey key) {
addButton(actionId, key, null);
}
public void addButton(int actionId, ZLResourceKey key, ButtonGroup group) {
ButtonItem button = new ButtonItem(actionId, key.Name, myResource.getResource(key));
ButtonItem button = new ButtonItem(actionId, key.Name, null/*myResource.getResource(key)*/);
myItems.add(button);
button.setButtonGroup(group);
}

View file

@ -1,7 +0,0 @@
package org.zlibrary.core.application.toolbar;
public enum Type {
BUTTON,
OPTION_ENTRY,
SEPARATOR
}

View file

@ -1,9 +1,7 @@
package org.zlibrary.core.resources;
public class ZLResourceKey {
public String Name;
public ZLResourceKey() {}
public final String Name;
public ZLResourceKey(String name) {
Name = name;

View file

@ -1,5 +1,7 @@
package org.zlibrary.ui.swing.application;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.zlibrary.core.application.ZLApplication;
@ -16,14 +18,20 @@ public class ZLSwingApplicationWindow extends ZLApplicationWindow {
super(application);
myFrame = new JFrame();
myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myToolbar = new JToolBar();
myToolbar.setFloatable(false);
myFrame.getRootPane().setLayout(new BorderLayout());
myFrame.getRootPane().add(myToolbar, BorderLayout.NORTH);
}
public void run() {
myFrame.setSize(300, 300);
myFrame.setSize(800, 600);
myToolbar.setVisible(true);
myFrame.setVisible(true);
}
public void init() {
super.init();
}
public void initMenu() {
@ -35,12 +43,23 @@ public class ZLSwingApplicationWindow extends ZLApplicationWindow {
protected ZLViewWidget createViewWidget() {
ZLSwingViewWidget viewWidget = new ZLSwingViewWidget(ZLSwingViewWidget.Angle.DEGREES0);
myFrame.add(viewWidget.getPanel());
myFrame.getRootPane().add(viewWidget.getPanel(), BorderLayout.CENTER);
return viewWidget;
}
public void addToolbarItem(Item item) {
// TODO: implement
if (item.getType() == Item.Type.BUTTON) {
ButtonItem buttonItem = (ButtonItem)item;
String iconFileName = "icons/toolbar/" + buttonItem.getIconName() + ".png";
Action action = new AbstractAction("tooltip text", new ImageIcon(iconFileName)) {
public void actionPerformed(ActionEvent event) {
}
};
myToolbar.add(action);
} else {
myToolbar.addSeparator();
}
}
public void setToolbarItemState(Item item, boolean visible, boolean enabled) {
@ -52,4 +71,5 @@ public class ZLSwingApplicationWindow extends ZLApplicationWindow {
}
private JFrame myFrame;
private JToolBar myToolbar;
}