-
- 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));
- 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 unavilable";
- break;
-
- default:
- err += "An error occured when contacting the library";
- break;
- }
-
- error(err, "Library error", null);
- }
- }
- });
-
- setVisible(true);
- }
-
- private void addSourcePanes() {
- // Sources -> i18n
- GuiReaderGroup bookPane = new GuiReaderGroup(reader, "Sources", color);
-
- List<MetaData> sources = new ArrayList<MetaData>();
- for (String source : reader.getLibrary().getSources()) {
- MetaData mSource = new MetaData();
- mSource.setLuid(null);
- mSource.setTitle(source);
- mSource.setSource(source);
- sources.add(mSource);
- }
-
- bookPane.refreshBooks(sources, 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(), true);
- refreshBooks();
- }
- });