-
- pane = new JPanel();
- pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
-
- Integer icolor = Instance.getUiConfig().getColor(
- UiConfig.BACKGROUND_COLOR);
- if (icolor != null) {
- color = new Color(icolor);
- setBackground(color);
- pane.setBackground(color);
- }
-
- JScrollPane scroll = new JScrollPane(pane);
- scroll.getVerticalScrollBar().setUnitIncrement(16);
- add(scroll, BorderLayout.CENTER);
-
- String message = reader.getLibrary().getLibraryName();
- if (!message.isEmpty()) {
- JLabel name = new JLabel(message, SwingConstants.CENTER);
- add(name, BorderLayout.NORTH);
- }
-
- pgBar = new ProgressBar();
- add(pgBar, BorderLayout.SOUTH);
-
- pgBar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- invalidate();
- pgBar.setProgress(null);
- validate();
- setEnabled(true);
- }
- });
-
- pgBar.addUpdateListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- invalidate();
- validate();
- repaint();
- }
- });
-
- booksByType = new HashMap<GuiReaderGroup, String>();
- booksByAuthor = new HashMap<GuiReaderGroup, String>();
-
- pane.setVisible(false);
- final Progress pg = new Progress();
- final String typeF = type;
- outOfUi(pg, new Runnable() {
- @Override
- public void run() {
- BasicLibrary lib = GuiReaderFrame.this.reader.getLibrary();
- Status status = lib.getStatus();
-
- if (status == Status.READY) {
- lib.refresh(pg);
- invalidate();
- setJMenuBar(createMenu(true));
- if (typeF == null) {
- addBookPane(true, false);
- } else {
- addBookPane(typeF, true);
- }
- refreshBooks();
- validate();
- pane.setVisible(true);
- } else {
- invalidate();
- setJMenuBar(createMenu(false));
- validate();
-
- String err = lib.getLibraryName() + "\n";
- switch (status) {
- case INVALID:
- err += "Library not valid";
- break;
-
- case UNAUTORIZED:
- err += "You are not allowed to access this library";
- break;
-
- case UNAVAILABLE:
- err += "Library currently unavailable";
- break;
-
- default:
- err += "An error occured when contacting the library";
- break;
- }
-
- error(err, "Library error", null);
- }
- }
- });
-
- setVisible(true);
- }
-
- private void addListPane(String name, List<String> values,
- final boolean type) {
- // Sources -> i18n
- GuiReaderGroup bookPane = new GuiReaderGroup(reader, name, color);
-
- List<MetaData> metas = new ArrayList<MetaData>();
- for (String source : values) {
- MetaData mSource = new MetaData();
- mSource.setLuid(null);
- mSource.setTitle(source);
- mSource.setSource(source);
- metas.add(mSource);
- }
-
- bookPane.refreshBooks(metas, false);
-
- this.invalidate();
- pane.invalidate();
- pane.add(bookPane);
- pane.validate();
- this.validate();
-
- bookPane.setActionListener(new BookActionListener() {
- @Override
- public void select(GuiReaderBook book) {
- selectedBook = book;
- }
-
- @Override
- public void popupRequested(GuiReaderBook book, MouseEvent e) {
- JPopupMenu popup = new JPopupMenu();
- popup.add(createMenuItemOpenBook());
- popup.show(e.getComponent(), e.getX(), e.getY());
- }
-
- @Override
- public void action(final GuiReaderBook book) {
- removeBookPanes();
- addBookPane(book.getMeta().getSource(), type);
- refreshBooks();
- }
- });
- }
-
- /**
- * Add a new {@link GuiReaderGroup} on the frame to display all the
- * sources/types or all the authors, or a listing of all the books sorted
- * either by source or author.
- * <p>
- * A display of all the sources/types or all the authors will show one icon
- * per source/type or author.
- * <p>
- * A listing of all the books sorted by source/type or author will display
- * all the books.
- *
- * @param type
- * TRUE for type/source, FALSE for author
- * @param listMode
- * TRUE to get a listing of all the sources or authors, FALSE to
- * get one icon per source or author
- */
- private void addBookPane(boolean type, boolean listMode) {
- if (type) {
- if (!listMode) {
- addListPane("Sources", reader.getLibrary().getSources(), type);
- } else {
- for (String tt : reader.getLibrary().getSources()) {
- if (tt != null) {
- addBookPane(tt, type);
- }
- }
- }
- } else {
- if (!listMode) {
- addListPane("Authors", reader.getLibrary().getAuthors(), type);
- } else {
- for (String tt : reader.getLibrary().getAuthors()) {
- if (tt != null) {
- addBookPane(tt, type);
- }
- }
- }
- }