1 package cz
.cvut
.promod
.gui
;
3 import cz
.cvut
.promod
.services
.ModelerSession
;
4 import cz
.cvut
.promod
.gui
.projectNavigation
.ProjectNavigation
;
5 import cz
.cvut
.promod
.gui
.support
.utils
.NotationGuiHolder
;
6 import cz
.cvut
.promod
.plugin
.notationSpecificPlugIn
.DockableFrameData
;
8 import com
.jidesoft
.docking
.*;
9 import com
.jidesoft
.swing
.JideTabbedPane
;
10 import com
.jidesoft
.swing
.JideButton
;
11 import com
.jidesoft
.swing
.JideBoxLayout
;
12 import com
.jidesoft
.action
.CommandBar
;
13 import com
.jidesoft
.status
.StatusBar
;
14 import com
.jidesoft
.status
.LabelStatusBarItem
;
15 import com
.jidesoft
.status
.ButtonStatusBarItem
;
16 import com
.jgoodies
.forms
.factories
.Borders
;
19 import java
.util
.List
;
23 * ProMod, master thesis project
24 * User: Petr Zverina, petr.zverina@gmail.com
25 * Date: 16:10:00, 10.10.2009
29 * GUI definition for the Modeler class.
31 public class ModelerView
extends JFrame
{
33 /** Dimension for layout of side buttons. */
34 private final Dimension BOX_VERTICAL_GAP
= new Dimension(0, 5);
35 private final Dimension BOX_HORIZONTAL_GAP
= new Dimension(5, 0);
37 /** NO other DockableFrame is allowed to have this index */
38 private static final int PROJECT_NAVIGATION_INDEX
= 0;
40 /** Each instance of DockableFrame is supposed to have unique index. */
41 public static int dockingFrameCounter
= PROJECT_NAVIGATION_INDEX
+ 1;
43 /** Represents the dockable frame ID counter. */
44 private static int dockableFrameIDcounter
= 1;
46 protected ProjectNavigation projectNavigationDockableFrame
;
48 protected DefaultDockingManager dockingManager
;
50 private JPanel dockableArea
;
52 protected final CardLayout cardLayoutRightSidePane
= new CardLayout();
53 protected final JPanel rightSidePane
= new JPanel(cardLayoutRightSidePane
);
55 private final JPanel leftSideBottomLayerPane
= new JPanel(new BorderLayout());
56 protected final JButton projectNavigatorButton
= ModelerSession
.getComponentFactoryService().createJideButton(
57 ModelerSession
.getCommonResourceBundle().getString("modeler.action.navigation"), null, 1);
59 protected final CardLayout cardLayoutLeftSidePane
= new CardLayout();
60 protected final JPanel leftSidePane
= new JPanel(cardLayoutLeftSidePane
);
62 protected final CardLayout cardLayoutBottomSidePane
= new CardLayout();
63 protected final JPanel bottomSidePane
= new JPanel(cardLayoutBottomSidePane
);
65 protected final CardLayout cardLayoutTopSidePane
= new CardLayout();
66 protected final JPanel topSidePane
= new JPanel(cardLayoutTopSidePane
);
68 protected final CardLayout cardLayoutWorkspacePane
= new CardLayout();
69 protected final JPanel workspacePane
= new JPanel(cardLayoutWorkspacePane
);
71 private Workspace workspace
;
73 protected final StatusBar statusBar
= ModelerSession
.getComponentFactoryService().createStatusBar();
74 protected final LabelStatusBarItem statusUserTitleLabel
= ModelerSession
.getComponentFactoryService().createLabelStatusBarItem();
75 protected final LabelStatusBarItem loggedUserLabel
= ModelerSession
.getComponentFactoryService().createLabelStatusBarItem();
76 protected final ButtonStatusBarItem switchUserButton
= ModelerSession
.getComponentFactoryService().createButtonStatusBarItem();
78 protected final CardLayout cardLayoutToolBar
= new CardLayout();
79 protected final JPanel toolBarPane
= new JPanel(cardLayoutToolBar
);
81 private static final Dimension DEFAULT_SIZE
= new Dimension(1024, 768);
83 private static final Dimension DEFAULT_SIZE_LOW_LEVEL
= new Dimension(300, 500);
85 private static final Dimension DEFAULT_SIZE_CONSOLE
= new Dimension(500, 200);
87 private static final Point DEFAULT_UNDOCKED_FRAME_POSITION
= new Point(-1, -1);
89 private static final String USER_TITLE_LABEL
= ModelerSession
.getCommonResourceBundle().getString("modeler.user.title");
90 private static final String USER_SWITCH_LABEL
= ModelerSession
.getCommonResourceBundle().getString("modeler.user.switch");
92 protected final CardLayout cardLayoutStatusBar
= new CardLayout();
93 protected final JPanel statusBarPane
= new JPanel(cardLayoutStatusBar
);
97 setTitle(ModelerModel
.APPLICATION_NAME
);
99 initializeDockingManager();
105 setDefaultCloseOperation(WindowConstants
.DO_NOTHING_ON_CLOSE
);
106 setPreferredSize(DEFAULT_SIZE
);
107 setSize(DEFAULT_SIZE
);
108 setLocationRelativeTo(null);
112 * Initialize status bar items.
114 private void initStatusBar() {
115 statusUserTitleLabel
.setAlignment(JLabel
.LEFT
);
116 statusUserTitleLabel
.setText(USER_TITLE_LABEL
);
117 statusBar
.add(statusUserTitleLabel
, JideBoxLayout
.FIX
);
119 loggedUserLabel
.setAlignment(JLabel
.LEFT
);
120 loggedUserLabel
.setText(ModelerSession
.getUserService().getUser());
121 statusBar
.add(loggedUserLabel
, JideBoxLayout
.FIX
);
123 switchUserButton
.setText(USER_SWITCH_LABEL
);
124 statusBar
.add(switchUserButton
, JideBoxLayout
.FIX
);
126 statusBar
.add(statusBarPane
, JideBoxLayout
.VARY
);
129 private void initLayout(){
130 workspace
.add(workspacePane
); // add panel with CardLayout on the workspace
132 final JPanel basisPanel
= ModelerSession
.getComponentFactoryService().createPanel();
133 basisPanel
.setLayout(new BorderLayout());
135 basisPanel
.add(dockableArea
, BorderLayout
.CENTER
);
136 basisPanel
.add(rightSidePane
, BorderLayout
.EAST
);
137 basisPanel
.add(leftSideBottomLayerPane
, BorderLayout
.WEST
);
138 basisPanel
.add(topSidePane
, BorderLayout
.NORTH
);
139 basisPanel
.add(bottomSidePane
, BorderLayout
.SOUTH
);
141 add(basisPanel
, BorderLayout
.CENTER
);
142 add(toolBarPane
, BorderLayout
.PAGE_START
);
143 add(statusBar
, BorderLayout
.PAGE_END
);
145 //init high level navigation hide/show button
146 leftSideBottomLayerPane
.add(leftSidePane
, BorderLayout
.CENTER
);
148 final JPanel panelProjectNavigationButton
= new JPanel(new BorderLayout());
149 panelProjectNavigationButton
.setBorder(Borders
.DLU2_BORDER
);
150 panelProjectNavigationButton
.setOpaque(false);
151 panelProjectNavigationButton
.add(projectNavigatorButton
, BorderLayout
.CENTER
);
153 leftSideBottomLayerPane
.add(panelProjectNavigationButton
, BorderLayout
.NORTH
);
155 //ads empty panels to all of card layouts with special key defined by ModelerModel.MODELER_IDENTIFIER
156 initEmptyModelerView();
160 * Initialize buttons panels, workspace and tool bar that are visible if no notation is selected.
162 private void initEmptyModelerView() {
163 rightSidePane
.add(ModelerSession
.getComponentFactoryService().createPanel(), ModelerModel
.MODELER_IDENTIFIER
);
164 leftSidePane
.add(ModelerSession
.getComponentFactoryService().createPanel(), ModelerModel
.MODELER_IDENTIFIER
);
165 bottomSidePane
.add(ModelerSession
.getComponentFactoryService().createPanel(), ModelerModel
.MODELER_IDENTIFIER
);
166 topSidePane
.add(ModelerSession
.getComponentFactoryService().createPanel(), ModelerModel
.MODELER_IDENTIFIER
);
168 workspacePane
.add(ModelerSession
.getComponentFactoryService().createPanel(), ModelerModel
.MODELER_IDENTIFIER
);
170 toolBarPane
.add(ModelerSession
.getToolBarControlService().getCommandBar(ModelerModel
.MODELER_IDENTIFIER
), ModelerModel
.MODELER_IDENTIFIER
);
171 statusBarPane
.add(ModelerSession
.getStatusBarControlService().getStatusBar(ModelerModel
.MODELER_IDENTIFIER
), ModelerModel
.MODELER_IDENTIFIER
);
175 * Initialization project navigation.
177 protected void initProjectNavigation(){
178 projectNavigationDockableFrame
= new ProjectNavigation(PROJECT_NAVIGATION_INDEX
);
179 dockingManager
.addFrame(projectNavigationDockableFrame
);
182 private void initializeDockingManager(){
183 dockableArea
= new JPanel();
185 dockingManager
= new DefaultDockingManager(this, dockableArea
);
187 workspace
= dockingManager
.getWorkspace();
189 dockingManager
.setSideDockAllowed(false);
191 dockingManager
.setInitSplitPriority(DockingManager
.SPLIT_EAST_WEST_SOUTH_NORTH
);
193 dockingManager
.setTabbedPaneCustomizer(new
194 DockingManager
.TabbedPaneCustomizer(){
195 public void customize( JideTabbedPane tabbedPane
){
196 tabbedPane
.setHideOneTab(true);
202 * Adds a new main windows to the workplace card layout.
204 * @param key is a key for the card layout
205 * @param component is the component to be displayed
207 protected void addMainWindowPane( final String key
, final Component component
){
208 workspacePane
.add(key
, component
);
212 * Adds a new tool bar to the tool bar card layout.
214 * @param notationIdentifier is a key for the card layout
215 * @param commandBar is the component to be displayed
217 protected void addToolBarPane(final String notationIdentifier
, final CommandBar commandBar
){
218 toolBarPane
.add(commandBar
, notationIdentifier
);
222 * Adds a new status bar.
224 * @param notationIdentifier is a key for the card layout
225 * @param statusBar is the notation specific status bar
227 protected void addStatusBar(final String notationIdentifier
, final StatusBar statusBar
){
228 statusBarPane
.add(statusBar
, notationIdentifier
);
232 * Adds a new side panel onto the specified base layer using CardLayout.
234 * @param key to be used by the CardLayout.
235 * @param baseLayer is base layer onto that should be the new panel added.
236 * @param buttonList is list of buttons to be shown on the new layer.
237 * @param isVertical true = vertical (for low level navigation), false = horizontal (consoles).
239 protected void addSidePane( final String key
,
240 final JPanel baseLayer
,
241 final List
<JideButton
> buttonList
,
242 final boolean isVertical
){
243 final JPanel panel
= new JPanel();
244 panel
.setBorder(Borders
.DLU2_BORDER
);
246 final Dimension dimension
;
248 panel
.setLayout(new BoxLayout(panel
, BoxLayout
.Y_AXIS
));
249 dimension
= BOX_VERTICAL_GAP
;
251 panel
.setLayout(new BoxLayout(panel
, BoxLayout
.X_AXIS
));
252 dimension
= BOX_HORIZONTAL_GAP
;
255 for( JideButton but
: buttonList
){
257 panel
.add(Box
.createRigidArea(dimension
));
260 baseLayer
.add(panel
, key
);
264 * Creates the dockable frame.
266 * @param component is the component to be added on the dockable frame.
267 * @param position is the position specification.
268 * @param title is the dockable frame id
269 * @param isMaximizable true if the frame is supposed to be maximizable
270 * @param initialState is the initial state of the frame
271 * @return the instance of required dockable frame
273 protected DockableFrame
createDockableFrame(final JComponent component
,
274 final NotationGuiHolder
.Position position
,
276 final boolean isMaximizable
,
277 final DockableFrameData
.InitialState initialState
){
279 final DockableFrame dockableFrame
= new DockableFrame(String
.valueOf(dockableFrameIDcounter
++));
280 dockableFrame
.setTitle(title
);
282 dockableFrame
.setShowContextMenu(false);
284 if(DockableFrameData
.InitialState
.FLOATED
.equals(initialState
)){
285 dockableFrame
.getContext().setInitMode(DockContext
.STATE_FLOATING
);
287 dockableFrame
.getContext().setInitMode(DockContext
.STATE_FRAMEDOCKED
);
290 dockableFrame
.getContext().setInitIndex(dockingFrameCounter
++);
291 dockableFrame
.setAutohidable(false);
292 dockableFrame
.setDockable(true);
293 dockableFrame
.setSideDockAllowed(false);
294 dockableFrame
.setRearrangable(false);
295 dockableFrame
.setTabDockAllowed(false);
297 // make this dockable frame maximizable or not
298 int availableButtons
= DockableFrame
.BUTTON_FLOATING
| DockableFrame
.BUTTON_CLOSE
;
300 availableButtons
|= DockableFrame
.BUTTON_MAXIMIZE
;
302 dockableFrame
.setAvailableButtons(availableButtons
);
306 dockableFrame
.getContext().setInitSide(DockContext
.DOCK_SIDE_EAST
);
307 dockableFrame
.setUndockedBounds(new Rectangle(DEFAULT_UNDOCKED_FRAME_POSITION
, DEFAULT_SIZE_LOW_LEVEL
));
308 dockableFrame
.setPreferredSize(DEFAULT_SIZE_LOW_LEVEL
);
311 dockableFrame
.getContext().setInitSide(DockContext
.DOCK_SIDE_WEST
);
312 dockableFrame
.setUndockedBounds(new Rectangle(DEFAULT_UNDOCKED_FRAME_POSITION
, DEFAULT_SIZE_LOW_LEVEL
));
313 dockableFrame
.setPreferredSize(DEFAULT_SIZE_LOW_LEVEL
);
316 dockableFrame
.getContext().setInitSide(DockContext
.DOCK_SIDE_SOUTH
);
317 dockableFrame
.setUndockedBounds(new Rectangle(DEFAULT_UNDOCKED_FRAME_POSITION
, DEFAULT_SIZE_CONSOLE
));
318 dockableFrame
.setPreferredSize(DEFAULT_SIZE_CONSOLE
);
321 dockableFrame
.getContext().setInitSide(DockContext
.DOCK_SIDE_NORTH
);
322 dockableFrame
.setUndockedBounds(new Rectangle(DEFAULT_UNDOCKED_FRAME_POSITION
, DEFAULT_SIZE_CONSOLE
));
323 dockableFrame
.setPreferredSize(DEFAULT_SIZE_CONSOLE
);
326 dockableFrame
.getContext().setInitSide(DockContext
.DOCK_SIDE_WEST
);
329 dockableFrame
.add(component
);
331 return dockableFrame
;