GUI - dev-cuttlefish/cuttlefish GitHub Wiki
The root of the graphical interface of Cuttlefish is the Cuttlefish class from the ch.ethz.sg.cuttlefish.gui2 package.
The class extends JFrame and has 3 main components:
- Cuttlefish menu - this is the menu located on the top of the window. It holds all menus such as Open, Layout, View, and Help. The implementation of each package is located in the ch.ethz.sg.cuttlefish.gui2.menus package.
- Cuttlefish toolbars - Cuttlefish has four toolbars: Mouse, Zoom, Explore, and Simulation. The Mouse and Zoom toolbars are always enabled as they are relevant for all networks. The Explore toolbar is enabled only when the loaded network is a Database network, and the simulation toolbar is active only when the opened network implements the ISimulation interface, used for network simulations.
- Network panel - this is where the network is visualized.
The network panel visualizes the networks loaded with Cuttlefish. It contains two components: (1) JUNG's visualization viewer, and (2) a status bar at the bottom of the panel. The actual rendering of the network is performed by JUNG's visualization viewer. The Network panel provides an interface for communication with the visualization viewer. Below are several important methods for manipulating the rendered network:
- getNetwork() - this returns a BrowsableNetwork object, which is the data representation of the visualized network
- setNetwork(BrowsableNetwork network) - this method is used to change the network
- onNetworkChange() - this method should be called when the network is changed, e.g., when an edge is added to the network
- setLayout(String nameOfLayout) - change the layout
- getLayout() - this returns the layout object, which can be used to access information about the node's position
- centerGraph() - this method places the network in the center of the network panel
Cuttlefish has 4 menus: Open, Layout, View, and Help. Each menu in the menu bar extends the abstract class called AbstractMenu. The AbstractMenu class has references to the NetworkPanel and the Toolbars of Cuttlefish. This allows direct access to the visualized network or the toolbars of Cuttlefish. For instance, when the user clicks on a new layout from the Layout menu, the Layout menu can instruct the Network Panel to change the layout to the one chosen by the user.
Toolbars are convenient to include icons for manipulation of the network. Since toolbars need access to the Network panel, they all implement the AbstractToolbar abstract class, which has a reference to the Network panel.
Cuttlefish leverages the Observer design pattern to achieve consistency at the graphical interface. We declare two interfaces:
- Subject, with an addObserver(Observer o) and a removeObserver(Observer o) methods
- Object, with an update(Subject s) method.