1 package be
.nikiroo
.fanfix_swing
.gui
;
3 import java
.awt
.event
.ActionEvent
;
4 import java
.awt
.event
.ActionListener
;
5 import java
.awt
.event
.KeyEvent
;
7 import javax
.swing
.JComponent
;
8 import javax
.swing
.JFrame
;
9 import javax
.swing
.JLabel
;
10 import javax
.swing
.JMenu
;
11 import javax
.swing
.JMenuBar
;
12 import javax
.swing
.JMenuItem
;
13 import javax
.swing
.JSplitPane
;
15 import be
.nikiroo
.fanfix_swing
.Actions
;
16 import be
.nikiroo
.utils
.Version
;
18 public class MainFrame
extends JFrame
{
19 private BooksPanel books
;
20 private DetailsPanel details
;
21 private BrowserPanel browser
;
23 public MainFrame(boolean sidePanel
, boolean detailsPanel
) {
24 super("Fanfix " + Version
.getCurrentVersion());
26 setJMenuBar(createMenuBar());
31 browser
= new BrowserPanel();
32 books
= new BooksPanel(true);
34 JComponent other
= null;
35 boolean orientationH
= true;
36 if (sidePanel
&& !detailsPanel
) {
38 } else if (sidePanel
&& detailsPanel
) {
39 JComponent side
= browser
;
40 details
= new DetailsPanel();
41 other
= split(side
, details
, false, 0.5, 1);
42 } else if (!sidePanel
&& !detailsPanel
) {
44 other
= new JLabel("<< Go back");
45 } else if (!sidePanel
&& detailsPanel
) {
46 JComponent goBack
= new JLabel("<< Go back");
47 details
= new DetailsPanel();
48 other
= split(goBack
, details
, false, 0.5, 1);
51 browser
.addActionListener(new ActionListener() {
53 public void actionPerformed(ActionEvent e
) {
54 books
.load(browser
.getSelectedSources(),
55 browser
.getSelectedAuthors(),
56 browser
.getSelectedTags());
57 details
.setBook(browser
.getHighlight());
60 books
.addActionListener(new ActionListener() {
62 public void actionPerformed(ActionEvent e
) {
63 if (BooksPanel
.INVALIDATE_CACHE
.equals(e
.getActionCommand())) {
69 JSplitPane split
= split(other
, books
, orientationH
, 0.5, 0);
74 private JSplitPane
split(JComponent leftTop
, JComponent rightBottom
,
75 boolean horizontal
, double ratio
, double weight
) {
76 JSplitPane split
= new JSplitPane(
77 horizontal ? JSplitPane
.HORIZONTAL_SPLIT
78 : JSplitPane
.VERTICAL_SPLIT
,
79 leftTop
, rightBottom
);
80 split
.setOneTouchExpandable(true);
81 split
.setResizeWeight(weight
);
82 split
.setContinuousLayout(true);
83 split
.setDividerLocation(ratio
);
88 private JMenuBar
createMenuBar() {
89 JMenuBar bar
= new JMenuBar();
91 JMenu file
= new JMenu("File");
92 file
.setMnemonic(KeyEvent
.VK_F
);
94 JMenuItem item1
= new JMenuItem("Download", KeyEvent
.VK_D
);
95 item1
.addActionListener(new ActionListener() {
97 public void actionPerformed(ActionEvent e
) {
98 Actions
.imprt(MainFrame
.this, true, new Runnable() {
101 browser
.reloadData();
102 books
.load(browser
.getSelectedSources(),
103 browser
.getSelectedAuthors(),
104 browser
.getSelectedTags());
105 details
.setBook(browser
.getHighlight());
111 JMenuItem item2
= new JMenuItem("Import file", KeyEvent
.VK_I
);
112 item2
.addActionListener(new ActionListener() {
114 public void actionPerformed(ActionEvent e
) {
115 Actions
.imprt(MainFrame
.this, false, new Runnable() {
118 browser
.reloadData();
119 books
.load(browser
.getSelectedSources(),
120 browser
.getSelectedAuthors(),
121 browser
.getSelectedTags());
122 details
.setBook(browser
.getHighlight());
131 JMenu edit
= new JMenu("Edit");
132 edit
.setMnemonic(KeyEvent
.VK_E
);
134 JMenu view
= new JMenu("View");
135 view
.setMnemonic(KeyEvent
.VK_V
);
137 JMenuItem listMode
= new JMenuItem("List mode", KeyEvent
.VK_L
);
138 listMode
.addActionListener(new ActionListener() {
140 public void actionPerformed(ActionEvent e
) {
141 books
.setListMode(!books
.isListMode());