16 package net.squiz.matrix.assetmap;
18 import net.squiz.matrix.matrixtree.*;
19 import net.squiz.matrix.debug.*;
20 import net.squiz.matrix.core.*;
21 import net.squiz.matrix.ui.*;
23 import javax.swing.tree.*;
24 import java.awt.event.*;
25 import javax.swing.event.*;
27 import java.io.IOException;
38 private JMenuBar menuBar;
39 private MatrixTree tree;
40 private JToolBar toolBar;
42 public static final Color BG_COLOUR =
new Color(0xF5F5F5);
43 public static final int ICON_GAP = 1;
52 setLayout(
new BorderLayout());
54 JPanel leftPanel =
new JPanel(
new FlowLayout(FlowLayout.LEADING));
55 JPanel rightPanel =
new JPanel(
new FlowLayout(FlowLayout.TRAILING));
57 rightPanel.add(createRefreshAssetsButton());
58 rightPanel.add(createRestoreRootButton());
59 rightPanel.add(createCollapseAllButton());
60 rightPanel.add(createPaintStatusesButton());
62 if (includeCreateButton) {
63 leftPanel.add(createAddMenuButton());
64 add(leftPanel, BorderLayout.WEST);
67 add(rightPanel, BorderLayout.EAST);
69 leftPanel.setBackground(BG_COLOUR);
70 rightPanel.setBackground(BG_COLOUR);
71 setBackground(BG_COLOUR);
74 public Dimension getPreferredSize() {
75 return new Dimension(300, 25);
78 public Dimension getMinimumSize() {
79 return new Dimension(300, 25);
82 public Dimension getMaximumSize() {
83 return new Dimension(300, 25);
99 private JButton createButton(
101 ActionListener listener,
102 String toolTipText) {
104 Icon icon = GUIUtilities.getAssetMapIcon(iconName +
"_off.png");
105 Icon pressedIcon = GUIUtilities.getAssetMapIcon(iconName +
"_on.png");
107 JButton button =
new JButton(icon);
108 button.setBackground(BG_COLOUR);
109 button.setBorderPainted(
false);
111 button.setPreferredSize(
new Dimension(icon.getIconWidth(), icon.getIconHeight()));
113 button.setPressedIcon(pressedIcon);
114 button.addActionListener(listener);
115 button.setToolTipText(toolTipText);
126 private JButton createRefreshAssetsButton() {
128 ActionListener refreshListener =
new ActionListener() {
129 public void actionPerformed(ActionEvent e) {
130 AssetRefreshWorker worker =
new AssetRefreshWorker(
true);
134 JButton refreshButton
135 = createButton(
"refresh", refreshListener, Matrix.translate(
"asset_map_tooltip_refresh_all"));
137 return refreshButton;
145 private JButton createRestoreRootButton() {
147 ActionListener restoreListener =
new ActionListener() {
148 public void actionPerformed(ActionEvent e) {
149 String newRoot = Matrix.getProperty(
"parameter.rootlineage");
151 if ((newRoot.length() > 0) && (tree.getModel().getRoot() == AssetManager.getRootFolderNode())) {
153 String[] info = newRoot.split(
"~");
154 String[] assetIds = info[0].split(
"\\|");
155 String[] sort_orders = info[1].split(
"\\|");
156 tree.collapsePath(tree.getPathToRoot((MatrixTreeNode)tree.getModel().getRoot()));
157 tree.loadChildAssets(assetIds, sort_orders,
false,
true);
159 tree.setRootVisible(
false);
160 ((DefaultTreeModel) tree.getModel()).setRoot(AssetManager.getRootFolderNode());
164 JButton restoreButton
165 = createButton(
"teleport", restoreListener, Matrix.translate(
"asset_map_tooltip_restore_root"));
167 return restoreButton;
176 private JButton createCollapseAllButton() {
178 ActionListener collapseListener =
new ActionListener() {
179 public void actionPerformed(ActionEvent e) {
180 ((DefaultTreeModel) tree.getModel()).reload();
184 JButton collapseButton
185 = createButton(
"collapse", collapseListener, Matrix.translate(
"asset_map_tooltip_collapse_all"));
187 return collapseButton;
197 private JButton createPaintStatusesButton() {
199 ActionListener statusListener =
new ActionListener() {
200 public void actionPerformed(ActionEvent evt) {
201 ((MatrixTreeCellRenderer) tree.getCellRenderer()).flipSelection();
205 JButton paintStatusButton
206 = createButton(
"status", statusListener, Matrix.translate(
"asset_map_tooltip_toggle_status"));
208 return paintStatusButton;
215 private ButtonMenu createAddMenuButton() {
217 Icon icon = GUIUtilities.getAssetMapIcon(
"add_off.png");
218 Icon pressedIcon = GUIUtilities.getAssetMapIcon(
"add_on.png");
220 final ButtonMenu button =
new ButtonMenu(icon, pressedIcon);
224 ActionListener bListener =
new ActionListener() {
225 private JPopupMenu addMenu;
227 public void actionPerformed(ActionEvent evt) {
228 if (addMenu == null) {
229 ActionListener listener = MatrixMenus.getMatrixTreeAddMenuListener(tree);
230 addMenu = MatrixMenus.getPopupAddMenu(listener);
231 button.setPopupMenu(addMenu);
236 button.addActionListener(bListener);
237 button.setPressedIcon(pressedIcon);
238 button.setBackground(BG_COLOUR);
239 button.setBorderPainted(
false);
241 button.setPreferredSize(
new Dimension(icon.getIconWidth(), icon.getIconHeight()));
242 button.setToolTipText(Matrix.translate(
"asset_map_tooltip_add_asset"));