private void open(Story story) {
final JComponent[] comps = new JComponent[3];
- // Integrate it with showViewer or something
+ final JFrame viewer;
if (story.getMeta().isImageDocument()) {
- final ViewerImages viewer = new ViewerImages(story) {
+ viewer = new ViewerImages(story) {
+ private static final long serialVersionUID = 1L;
+
@Override
protected JToolBar createToolbar() {
// we need it to be created to steal its content
comps[2] = zoombox;
}
};
+ } else {
+ viewer = new ViewerNonImages(Instance.getInstance().getLibrary(),
+ story) {
+ private static final long serialVersionUID = 1L;
- removeShows();
-
- JComponent scroll = comps[0];
+ @Override
+ protected JToolBar createToolbar() {
+ // we need it to be created to steal its content
+ super.createToolbar();
+ return null;
+ }
- JPanel navbar = new JPanel();
- navbar.add(comps[1]);
+ @Override
+ protected JPanel createDescPane() {
+ return null;
+ }
- JPanel zoombox = new JPanel();
- JButton exit = new JButton(IconGenerator.get(Icon.back, Size.x32));
- exit.addActionListener(new ActionListener() {
@Override
- public void actionPerformed(ActionEvent e) {
- removeShows();
- viewer.dispose();
- showBooks();
+ protected void initGui() {
+ super.initGui();
+ title.setFont(title.getFont()
+ .deriveFont(title.getFont().getSize() * 0.75f));
+ comps[0] = scroll;
+ comps[1] = navbar;
+ comps[2] = title;
}
- });
- zoombox.add(exit);
- zoombox.add(Box.createRigidArea(new Dimension(10, 10)));
- zoombox.add(comps[2]);
+ };
+ }
- active.add(scroll);
- active.add(navbar);
- active.add(zoombox);
+ removeShows();
- TouchFrame.this.add(navbar, BorderLayout.NORTH);
- TouchFrame.this.add(zoombox, BorderLayout.SOUTH);
- root.add(scroll);
+ JComponent scroll = comps[0];
- revalidate();
- repaint();
- } else {
- ViewerNonImages viewer = new ViewerNonImages(
- Instance.getInstance().getLibrary(), story);
- viewer.setVisible(true);
- }
+ JPanel navbar = new JPanel();
+ navbar.add(comps[1]);
+
+ JButton exit = new JButton(IconGenerator.get(Icon.back, Size.x32));
+ exit.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ removeShows();
+ viewer.dispose();
+ showBooks();
+ }
+ });
+
+ JPanel zoombox = new JPanel();
+ zoombox.add(exit);
+ zoombox.add(Box.createRigidArea(new Dimension(10, 10)));
+ zoombox.add(comps[2]);
+
+ active.add(scroll);
+ active.add(navbar);
+ active.add(zoombox);
+
+ TouchFrame.this.add(navbar, BorderLayout.NORTH);
+ TouchFrame.this.add(zoombox, BorderLayout.SOUTH);
+ root.add(scroll);
+
+ revalidate();
+ repaint();
}
private void removeShows() {
public class ViewerNonImages extends JFrame {
private static final long serialVersionUID = 1L;
+ private BasicLibrary lib;
private Story story;
private ViewerTextOutput html;
- private NavBar navbar;
- private JLabel title;
- private JScrollPane scroll;
+ /** The navigation bar. */
+ protected NavBar navbar;
+ /** The story title */
+ protected JLabel title;
+ /** The main element of this viewer: the scrolled text. */
+ protected JScrollPane scroll;
+
private JEditorPane area;
private JPanel descPane;
*
*/
public ViewerNonImages(BasicLibrary lib, Story story) {
+ this.lib = lib;
this.story = story;
this.setTitle(Instance.getInstance().getTransGui().getString(
StringIdGui.TITLE_STORY, story.getMeta().getLuid(),
worker = new DelayWorker(100);
worker.start();
- initGui(lib);
+ initGui();
setChapter(0);
UiHelper.setFrameIcon(this, lib, story.getMeta());
}
/**
- * Initialise the base panel.
- *
- * @param lib
- * the {@link BasicLibrary} to use to retrieve the cover image in
- * the description panel
+ * Initialise the GUI (after this call, all the graphical elements are in
+ * place).
*/
- private void initGui(BasicLibrary lib) {
+ protected void initGui() {
this.setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
title = new JLabel();
title.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
title.setToolTipText(story.getMeta().getTitle());
- JToolBar toolbarTitle = createToolBar();
- toolbarTitle.add(title);
+ JToolBar toolbarTitle = createToolbar();
+ if (toolbarTitle != null) {
+ toolbarTitle.add(title);
+ }
area = new JEditorPane("text/html", "");
area.setEditable(false);
scroll = UIUtils.scroll(area, false);
- JLabel descLabel = new JLabel("Description");
- descLabel.setFont(new Font(Font.SERIF, Font.BOLD,
- (int) Math.round(descLabel.getFont().getSize() * 1.5)));
- descLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- descLabel.setHorizontalAlignment(JLabel.CENTER);
- descLabel.setOpaque(true);
- Color bg = descLabel.getBackground();
- descLabel.setBackground(descLabel.getForeground());
- descLabel.setForeground(bg);
-
- descPane = new JPanel(new BorderLayout());
- PropertiesPanel desc = new PropertiesPanel(lib, story.getMeta(), false);
- desc.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
- descPane.add(desc, BorderLayout.CENTER);
- descPane.add(descLabel, BorderLayout.SOUTH);
+ descPane = createDescPane();
area.setSize(scroll.getViewport().getSize());
area.setPreferredSize(this.getSize()); // make it as big as possible
area.requestFocus();
- this.add(toolbarTitle);
- this.add(descPane);
+ if (toolbarTitle != null)
+ this.add(toolbarTitle);
+ if (descPane != null)
+ this.add(descPane);
this.add(scroll);
listen();
});
}
- private JToolBar createToolBar() {
+ /**
+ * Create the main toolbar used for this viewer.
+ *
+ * @return the toolbar, can be NULL
+ */
+ protected JToolBar createToolbar() {
JToolBar toolbar = new JToolBar();
navbar = new NavBar(0, story.getChapters().size());
navbar.setIcons( //
return toolbar;
}
+ /**
+ * Create the story description panel used for this viewer.
+ *
+ * @return the panel, can be NULL
+ */
+ protected JPanel createDescPane() {
+ JLabel descLabel = new JLabel("Description");
+ descLabel.setFont(new Font(Font.SERIF, Font.BOLD,
+ (int) Math.round(descLabel.getFont().getSize() * 1.5)));
+ descLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ descLabel.setHorizontalAlignment(JLabel.CENTER);
+ descLabel.setOpaque(true);
+ Color bg = descLabel.getBackground();
+ descLabel.setBackground(descLabel.getForeground());
+ descLabel.setForeground(bg);
+
+ JPanel descPane = new JPanel(new BorderLayout());
+ PropertiesPanel desc = new PropertiesPanel(lib, story.getMeta(), false);
+ desc.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
+ descPane.add(desc, BorderLayout.CENTER);
+ descPane.add(descLabel, BorderLayout.SOUTH);
+
+ return descPane;
+ }
+
/**
* Set the current chapter, 0-based.
* <p>
protected void done() {
try {
String text = get();
- if (chapter <= 0) {
- descPane.setVisible(true);
- } else {
- descPane.setVisible(false);
+ if (descPane != null) {
+ if (chapter <= 0) {
+ descPane.setVisible(true);
+ } else {
+ descPane.setVisible(false);
+ }
}
area.setText(text);