Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EditorDockable |
|
| 3.3333333333333335;3.333 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy.gui.dock; | |
11 | ||
12 | import java.awt.BorderLayout; | |
13 | ||
14 | import javax.swing.Icon; | |
15 | ||
16 | import bibliothek.gui.dock.common.DefaultMultipleCDockable; | |
17 | import bibliothek.gui.dock.common.MultipleCDockableFactory; | |
18 | ||
19 | import org.openpermis.editor.policy.view.View; | |
20 | ||
21 | /** | |
22 | * Dockable implementation for editor views. | |
23 | * <p>An editor view is a view that is displayed in the main working area. | |
24 | * Editor views display a specific part of a model that is editable.</p> | |
25 | * <p>The difference between an {@code EditorDockable} and a {@link ToolDockable} | |
26 | * is that while a tool dockable is unique there may be several {@code EditorDockable}s | |
27 | * that display different parts of a policy.</p> | |
28 | * @see ToolDockable | |
29 | * @since 0.1.0 | |
30 | */ | |
31 | public class EditorDockable | |
32 | extends DefaultMultipleCDockable | |
33 | implements ViewDockable | |
34 | { | |
35 | ||
36 | //---- State | |
37 | ||
38 | /** | |
39 | * The view rendered by this dockable. | |
40 | * @since 0.1.0 | |
41 | */ | |
42 | private final View view; | |
43 | ||
44 | //---- Constructors | |
45 | ||
46 | /** | |
47 | * Creates a new editor dockable. | |
48 | * @param factory the factory this dockable is attached to. | |
49 | * @param view the view displayed by this editor. | |
50 | * @since 0.1.0 | |
51 | */ | |
52 | public EditorDockable (MultipleCDockableFactory<?, ?> factory, View view) { | |
53 | 0 | super(factory); |
54 | 0 | this.view = view; |
55 | 0 | setTitleText(view == null ? "" : view.getTitle()); |
56 | 0 | final Icon icon = view != null ? view.getIcon() : null; |
57 | 0 | if (icon != null) { |
58 | 0 | setTitleIcon(icon); |
59 | } | |
60 | 0 | setCloseable(true); |
61 | 0 | setExternalizable(false); |
62 | 0 | setMinimizable(false); |
63 | 0 | getContentPane().setLayout(new BorderLayout()); |
64 | 0 | if (view != null && view.getContentPane() != null) { |
65 | 0 | getContentPane().add(view.getContentPane(), BorderLayout.CENTER); |
66 | } | |
67 | 0 | } |
68 | ||
69 | //---- ViewDockable | |
70 | ||
71 | /** | |
72 | * @since 0.1.0 | |
73 | */ | |
74 | public View getView () { | |
75 | 0 | return this.view; |
76 | } | |
77 | ||
78 | /** | |
79 | * @since 0.1.0 | |
80 | */ | |
81 | public void updateTitle () { | |
82 | 0 | setTitleText(this.view == null ? "" : this.view.getTitle()); |
83 | 0 | setTitleIcon(this.view == null ? null : this.view.getIcon()); |
84 | 0 | } |
85 | ||
86 | } |