1 | |
package org.jtheque.films.view.impl.frames; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.error.JThequeError; |
20 | |
import org.jtheque.core.managers.log.IJThequeLogger; |
21 | |
import org.jtheque.core.managers.log.Logger; |
22 | |
import org.jtheque.core.managers.view.impl.components.model.SimpleListModel; |
23 | |
import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView; |
24 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
25 | |
import org.jtheque.films.controllers.able.ISitesController; |
26 | |
import org.jtheque.films.utils.Constants.Site; |
27 | |
import org.jtheque.films.utils.FileUtils; |
28 | |
import org.jtheque.films.view.able.ISitesView; |
29 | |
import org.jtheque.films.view.impl.actions.CloseViewAction; |
30 | |
import org.jtheque.utils.ui.GridBagUtils; |
31 | |
|
32 | |
import javax.annotation.PostConstruct; |
33 | |
import javax.annotation.Resource; |
34 | |
import javax.swing.DefaultListModel; |
35 | |
import javax.swing.JList; |
36 | |
import javax.swing.JTextPane; |
37 | |
import javax.swing.ListSelectionModel; |
38 | |
import javax.swing.text.html.HTMLEditorKit; |
39 | |
import java.awt.Container; |
40 | |
import java.awt.Dimension; |
41 | |
import java.awt.Frame; |
42 | |
import java.io.IOException; |
43 | |
import java.util.Collection; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public final class SitesView extends SwingDialogView implements ISitesView { |
51 | |
private static final long serialVersionUID = -600407247345067765L; |
52 | |
|
53 | |
private JList listSites; |
54 | |
private DefaultListModel sitesModel; |
55 | |
private JTextPane textSites; |
56 | |
|
57 | |
@Logger |
58 | |
private IJThequeLogger logger; |
59 | |
|
60 | |
@Resource |
61 | |
private ISitesController sitesController; |
62 | |
|
63 | |
private static final int MINIMUM_WIDTH = 200; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public SitesView(Frame parent) { |
71 | 0 | super(parent); |
72 | 0 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@PostConstruct |
78 | |
private void build() { |
79 | 0 | setTitleKey("sites.view.title"); |
80 | 0 | setContentPane(buildContentPane()); |
81 | 0 | setMinimumSize(new Dimension(MINIMUM_WIDTH, getMinimumSize().height)); |
82 | 0 | pack(); |
83 | |
|
84 | 0 | setLocationRelativeTo(getOwner()); |
85 | 0 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
private Container buildContentPane() { |
93 | 0 | PanelBuilder builder = new PanelBuilder(); |
94 | |
|
95 | 0 | sitesModel = new SimpleListModel<Site>(Site.values()); |
96 | |
|
97 | 0 | listSites = new JList(sitesModel); |
98 | 0 | listSites.setSelectedIndex(0); |
99 | 0 | listSites.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
100 | |
|
101 | 0 | listSites.getSelectionModel().addListSelectionListener(sitesController); |
102 | |
|
103 | 0 | builder.addScrolled(listSites, builder.gbcSet(0, 0)); |
104 | |
|
105 | 0 | textSites = new JTextPane(); |
106 | 0 | textSites.setContentType("text/html"); |
107 | 0 | textSites.setEditable(false); |
108 | 0 | textSites.setEditorKit(new HTMLEditorKit()); |
109 | |
|
110 | |
try { |
111 | 0 | textSites.setPage(FileUtils.getLocalisedPage(((Site) sitesModel.getElementAt(0)).value())); |
112 | 0 | } catch (IOException e) { |
113 | 0 | logger.error(e); |
114 | 0 | textSites.setText(""); |
115 | 0 | } |
116 | |
|
117 | 0 | builder.addScrolled(textSites, builder.gbcSet(1, 0)); |
118 | |
|
119 | 0 | builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, 2, 1), new CloseViewAction("generic.view.actions.cancel", this)); |
120 | |
|
121 | 0 | return builder.getPanel(); |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
public JTextPane getSitesTextComponent() { |
126 | 0 | return textSites; |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public String getSelectedSite() { |
131 | 0 | return ((Site) sitesModel.get(listSites.getSelectedIndex())).value(); |
132 | |
} |
133 | |
|
134 | |
@Override |
135 | |
protected void validate(Collection<JThequeError> errors) { |
136 | 0 | } |
137 | |
} |