1 package ch.odi.justblog.gui.swing;
2
3 import java.awt.BorderLayout;
4 import java.awt.Container;
5 import java.awt.Dimension;
6 import java.awt.HeadlessException;
7
8 import javax.swing.JFrame;
9
10 import ch.odi.justblog.api.Blog;
11 import ch.odi.justblog.command.ISession;
12 import ch.odi.justblog.command.SimpleSession;
13 import ch.odi.justblog.gui.swing.control.Controller;
14
15 /***
16 * This is the application's main window.
17 *
18 * @author oglueck
19 */
20 public class MainWindow extends JFrame {
21 private ISession session = new SimpleSession();
22 private UrlBar bar;
23 private Editor editor;
24 private ButtonBar buttons;
25 private Controller controller;
26 private Blog blog;
27
28 /***
29 * @param title
30 * @throws java.awt.HeadlessException
31 */
32 public MainWindow(String title, Controller controller) throws HeadlessException {
33 super(title);
34 this.controller = controller;
35 controller.setView(this);
36 init();
37 }
38
39 public void canEditEntry(boolean enabled) {
40 editor.setEnabled(enabled);
41 buttons.setEnabled(enabled);
42 }
43
44 public String getEntryText() {
45 return editor.getHtml();
46 }
47
48 public void clearEntry() {
49 editor.setHtml("");
50 }
51
52 /***
53 * Returns the session associated with this window.
54 * @return
55 */
56 public ISession getSession() {
57 return session;
58 }
59
60 private void init() {
61 placeComponents();
62 }
63
64 /***
65 * Initial setup of all components in this frame.
66 */
67 private void placeComponents() {
68 Container cp = this.getContentPane();
69 cp.setLayout(new BorderLayout());
70 bar = new UrlBar(controller);
71 cp.add(bar, BorderLayout.NORTH);
72 editor = new Editor();
73 editor.setMinimumSize(new Dimension(200, 200));
74 cp.add(editor, BorderLayout.CENTER);
75 buttons = new ButtonBar(controller);
76 cp.add(buttons, BorderLayout.SOUTH);
77 bar.setDefaultButton(this.getRootPane());
78 }
79 }