import java.awt.BorderLayout;
import java.awt.Component;
-import java.awt.Window;
-import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
+import javax.swing.JToolBar;
import javax.swing.SwingWorker;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
-import be.nikiroo.fanfix_swing.Actions;
import be.nikiroo.fanfix_swing.gui.book.BookInfo;
import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
-import be.nikiroo.fanfix_swing.gui.utils.WaitingDialogMeta;
import be.nikiroo.fanfix_swing.gui.viewer.ViewerImages;
import be.nikiroo.fanfix_swing.gui.viewer.ViewerNonImages;
-import be.nikiroo.utils.ui.WaitingDialog;
public class TouchFrame extends JFrame {
private JPanel root;
+ private List<JComponent> active;
private JPanel wait;
private BooksPanel books;
public TouchFrame() {
+ active = new ArrayList<JComponent>();
+
root = new JPanel(new BorderLayout());
wait = new JPanel();
wait.add(new JLabel("Waiting..."));
- books = new BooksPanel(false, true);
+ books = new BooksPanel(false, true) {
+ @Override
+ protected BooksPanelActions initActions() {
+ return new BooksPanelActions(books, getInformer()) {
+ @Override
+ public boolean openBook() {
+ BookInfo book = getInformer().getUniqueSelected();
+ if (book != null) {
+ showWait(); // TODO: some details
+ open(book);
+ return true;
+ }
+
+ return false;
+ }
+ };
+ }
+ };
books.setTooltip(false);
books.loadData(null, null, null);
// We hijack the popup to generate an action on long-press.
public void show(Component invoker, int x, int y) {
final BookInfo book = books.getInformer().getUniqueSelected();
if (book != null && book.getMeta() != null) {
- final BasicLibrary lib = Instance.getInstance()
- .getLibrary();
-
showWait(); // TODO: some details
-
- new SwingWorker<File, Void>() {
- private Story story;
-
- @Override
- protected File doInBackground() throws Exception {
- story = lib.getStory(book.getMeta().getLuid(),
- null);
- return null;
- }
-
- @Override
- protected void done() {
- try {
- get();
- Actions.openInternal(story);
- } catch (Exception e) {
- // TODO: i18n
- UiHelper.error(TouchFrame.this,
- e.getLocalizedMessage(),
- "Cannot open the story", e);
- }
-
- // Integrate it with showViewer or something
- if (story.getMeta().isImageDocument()) {
- ViewerImages viewer = new ViewerImages(story);
- viewer.setVisible(true);
- } else {
- ViewerNonImages viewer = new ViewerNonImages(
- Instance.getInstance().getLibrary(),
- story);
- viewer.setVisible(true);
- }
-
- }
- }.execute();
+ open(book);
}
}
});
showBooks();
setSize(355, 465);
}
+
+ private void open(final BookInfo book) {
+ new SwingWorker<Story, Void>() {
+ @Override
+ protected Story doInBackground() throws Exception {
+ BasicLibrary lib = Instance.getInstance().getLibrary();
+ return lib.getStory(book.getMeta().getLuid(), null);
+ }
+
+ @Override
+ protected void done() {
+ try {
+ open(get());
+ } catch (Exception e) {
+ // TODO: i18n
+ UiHelper.error(TouchFrame.this,
+ e.getLocalizedMessage(),
+ "Cannot open the story", e);
+ }
+ }
+ }.execute();
+ }
+
+ private void open(Story story) {
+ // Integrate it with showViewer or something
+ if (story.getMeta().isImageDocument()) {
+ ViewerImages viewer = new ViewerImages(story) {
+ @Override
+ protected JToolBar createToolBar() {
+ JToolBar toolbar = super.createToolBar();
+ active.add(toolbar);
+ TouchFrame.this.add(toolbar, BorderLayout.NORTH);
+ return null;
+ }
+
+ @Override
+ protected void initGui() {
+ super.initGui();
+ removeShows();
+ active.add(scroll);
+ root.add(scroll);
+ }
+ };
+
+ revalidate();
+ repaint();
+
+ //TODO: dispose viewer when changed
+ } else {
+ ViewerNonImages viewer = new ViewerNonImages(
+ Instance.getInstance().getLibrary(),
+ story);
+ viewer.setVisible(true);
+ }
+ }
private void removeShows() {
- root.remove(wait);
- root.remove(books);
+ for (JComponent comp : active) {
+ this.remove(comp);
+ root.remove(comp);
+ }
+ active.clear();
}
private void showBooks() {
removeShows();
+ active.add(books);
root.add(books);
revalidate();
+ repaint();
}
private void showWait() {
removeShows();
+ active.add(wait);
root.add(wait);
revalidate();
+ repaint();
}
}
private NavBar navbar;
private JLabel area;
- private JScrollPane scroll;
+ protected JScrollPane scroll;
@SuppressWarnings("rawtypes") // JComboBox<?> not compatible java 1.6
private DefaultComboBoxModel zoomBoxModel;
});
UiHelper.setFrameIcon(this, images.isEmpty() ? null : images.get(0));
+ setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
- private void initGui() {
+ protected void initGui() {
this.setLayout(new BorderLayout());
- this.add(createToolBar(), BorderLayout.NORTH);
-
+
+ JToolBar toolbar = createToolBar();
+ if (toolbar != null) {
+ this.add(toolbar, BorderLayout.NORTH);
+ }
+
area = new JLabel();
area.setHorizontalAlignment(JLabel.CENTER);
area.setOpaque(false);
@SuppressWarnings({ "unchecked", "rawtypes" }) // JComboBox<?> not
// compatible java 1.6
- private JToolBar createToolBar() {
+ protected JToolBar createToolBar() {
JToolBar toolBar = new JToolBar();
// Page navigation
}
}
});
- this.addComponentListener(new ComponentAdapter() {
+ scroll.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
display(index, rotation, false);