-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfiguratorCategoryEditorUi.java
86 lines (72 loc) · 2.55 KB
/
ConfiguratorCategoryEditorUi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.barattoManager.ui.components;
import com.barattoManager.ui.customComponents.tree.category.CategoryConfButtons;
import com.barattoManager.ui.customComponents.tree.category.CategoryTree;
import com.barattoManager.ui.customComponents.tree.event.RepaintEventHandler;
import com.barattoManager.ui.customComponents.tree.event.RepaintListener;
import javax.swing.*;
import java.awt.*;
/**
* Class used to create a JPanel that represent the category editor view (only configurator)
*/
public class ConfiguratorCategoryEditorUi extends JPanel implements RepaintListener {
/**
*Event Handler for reprint the category tree and buttons
*/
private final RepaintEventHandler repaintEventHandler = new RepaintEventHandler();
/**
* {@link CategoryTree} object
*/
private CategoryTree categoryTree = new CategoryTree();
/**
* {@link CategoryConfButtons} object
*/
private CategoryConfButtons categoryConfButtons = new CategoryConfButtons(categoryTree, repaintEventHandler);
/**
* Main JPanel
*/
private JPanel mainPanel;
/**
* Center JPanel {@code BorderLayout.CENTER}
*/
private JPanel centerPanel;
/**
* Back button to {@link InitialMenuUI}
*/
private JButton backToInitButton;
/**
* {@link ConfiguratorCategoryEditorUi} constructor
* @param dimension Dimension of JPanel
* @param cardLayout {@link CardLayout} object instanced in {@link com.barattoManager.ui.BarattoManagerGui}
* @param panelContainer {@link JPanel} object that contains every cards
*/
public ConfiguratorCategoryEditorUi(Dimension dimension, CardLayout cardLayout, JPanel panelContainer) {
// JPanel conf
setVisible(true);
add(mainPanel);
mainPanel.setPreferredSize(dimension);
// Set up the repainting event
repaintEventHandler.addListener(this);
// add the tree and the buttons
centerPanel.add(categoryTree);
centerPanel.add(categoryConfButtons, BorderLayout.SOUTH);
backToInitButton.addActionListener(e -> cardLayout.show(panelContainer, ComponentsName.CONF_HOME.toString()));
}
/**
* Implementation of the method {@link RepaintListener#repaintCategoryTree()}
*/
@Override
public void repaintCategoryTree() {
// remove components
centerPanel.remove(categoryTree);
centerPanel.remove(categoryConfButtons);
// new instances
categoryTree = new CategoryTree();
categoryConfButtons = new CategoryConfButtons(categoryTree, repaintEventHandler);
// add new component
centerPanel.add(categoryTree);
centerPanel.add(categoryConfButtons, BorderLayout.SOUTH);
// Revalidate & Repaint
centerPanel.revalidate();
centerPanel.repaint();
}
}