16 package net.squiz.matrix.ui;
18 import net.squiz.matrix.core.*;
19 import net.squiz.matrix.debug.*;
20 import net.squiz.matrix.assetmap.*;
21 import net.squiz.matrix.matrixtree.*;
24 import javax.swing.tree.*;
27 import javax.swing.event.*;
28 import java.awt.event.*;
37 private static JMenu addMenu;
38 private static ImageLoader loader =
new ImageLoader();
39 public static final String DEFAULT_ASSET_ICON =
"default_asset.png";
114 JMenu menu =
new JMenu();
116 AssetType type = asset.getType();
117 Iterator screens = type.getScreens();
119 while (screens.hasNext()) {
120 AssetTypeScreen screen = (AssetTypeScreen) screens.next();
121 JMenuItem item =
new JMenuItem(screen.getScreenName());
122 item.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
123 item.addActionListener(listener);
124 item.setActionCommand(screen.getCodeName());
138 ActionListener screenListener =
new ActionListener() {
139 public void actionPerformed(ActionEvent evt) {
141 String command = evt.getActionCommand();
143 String assetPath = MatrixToolkit.rawUrlEncode(node.
getAssetPath(),
true);
144 String linkPath = MatrixToolkit.rawUrlEncode(node.
getLinkPath(),
true);
145 String assetid = MatrixToolkit.rawUrlEncode(asset.getId(),
true);
147 String screenUrl = getScreenUrl(
154 AssetMap.getURL(screenUrl);
155 }
catch (MalformedURLException mue) {
156 Object[] transArgs = {
159 String message = Matrix.translate(
"asset_map_error_screen_url", transArgs);
160 GUIUtilities.error(message, Matrix.translate(
"asset_map_dialog_title_error"));
165 return screenListener;
174 private static String getScreenUrl(
180 Matrix.getProperty(
"parameter.url.baseurl") +
181 Matrix.getProperty(
"parameter.backendsuffix") +
182 "/?SQ_BACKEND_PAGE=main&backend_section=" +
183 "am&am_section=edit_asset&assetid=" + assetid +
184 "&sq_asset_path=" + assetPath +
"&sq_link_path=" +
185 linkPath +
"&asset_ei_screen=" + screenName;
200 JPopupMenu menu =
new JPopupMenu();
202 ActionListener useMeListener =
new ActionListener() {
203 public void actionPerformed(ActionEvent evt) {
205 String[] info =
new String[] {
210 asset.getType().toString(),
212 netscape.javascript.JSObject window = netscape.javascript.JSObject.getWindow(AssetMap.getApplet());
213 window.call(
"asset_finder_done", info);
214 MatrixTreeBus.stopAssetFinderMode();
218 JMenuItem item =
new JMenuItem(Matrix.translate(
"asset_map_menu_useme"));
219 item.addActionListener(useMeListener);
220 item.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
237 ActionListener addMenuListener =
new ActionListener() {
238 public void actionPerformed(ActionEvent evt) {
239 if (evt.getSource() instanceof JMenuItem) {
240 JMenuItem item = (JMenuItem) evt.getSource();
242 tree.initiateAddMode(
249 return addMenuListener;
262 JPopupMenu popupAddMenu =
getAddMenu(listener).getPopupMenu();
263 popupAddMenu.addPopupMenuListener(loader);
280 addMenu =
new JMenu(Matrix.translate(
"asset_map_menu_add_new"));
281 addMenu.addMenuListener(loader);
282 Iterator it = AssetManager.getAssetTypes();
284 while (it.hasNext()) {
285 AssetType type = (AssetType) it.next();
289 if (!(type.isCreatable()))
296 String[] paths = type.getMenuPath();
297 MenuElement parentMenu = addMenu;
299 if (paths.length > 0) {
301 boolean found =
false;
303 MenuElement[] elements = null;
305 for (
int i = 0; i < paths.length; i++) {
311 elements = parentMenu.getSubElements();
313 if (elements.length > 0 && elements[0] instanceof JPopupMenu)
314 elements = elements[0].getSubElements();
316 for (
int j = 0; j < elements.length; j++) {
317 Component component = (Component) elements[j];
318 if (component instanceof JMenu) {
319 if (component.getAccessibleContext().getAccessibleName().equals(path)) {
321 parentMenu = (JMenu) component;
330 JMenu newMenu =
new JMenu(path);
331 newMenu.getAccessibleContext().setAccessibleName(path);
332 newMenu.addMenuListener(loader);
337 getMenuIndex(path, parentMenu, newMenu.getClass()),
345 if (i == paths.length - 1) {
346 addMenuItem(newMenu, type, listener);
351 addMenuItem(parentMenu, type, listener);
357 addMenuItem(addMenu, type, listener);
370 private static int getMenuIndex(String name, MenuElement parentMenu, Class cls){
372 MenuElement[] components = parentMenu.getSubElements();
373 for (i = 0; i < components.length; i++) {
378 if (components[i] instanceof JPopupMenu)
379 return getMenuIndex(name, components[i], cls);
381 Component nextMenu = (Component) components[i];
382 String otherName =
"";
384 if (nextMenu.getClass().equals(JMenuItem.class)) {
385 String typeCode = nextMenu.getAccessibleContext().getAccessibleName();
386 otherName = AssetManager.getAssetType(typeCode).getName();
388 otherName = nextMenu.getAccessibleContext().getAccessibleName();
391 if (cls.equals(JMenuItem.class) && nextMenu.getClass().equals(JMenu.class))
393 if (name.compareToIgnoreCase(otherName) < 0)
405 private static void addMenuItem(MenuElement parentMenu, AssetType type, ActionListener listener) {
406 JMenuItem newItem =
new JMenuItem(type.getName());
408 newItem.getAccessibleContext().setAccessibleName(type.getTypeCode());
410 int index = getMenuIndex(type.getName(),
414 addNewItem(parentMenu, newItem, index, listener);
423 private static void addNewItem(
427 ActionListener listener) {
428 item.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
429 if (parent instanceof JPopupMenu)
430 ((JPopupMenu) parent).add(item, index);
432 ((JMenu) parent).add(item, index);
433 item.addActionListener(listener);
442 JMenuItem item = (JMenuItem) evt.getSource();
443 return item.getAccessibleContext().getAccessibleName();
451 static class ImageLoader
implements MenuListener, PopupMenuListener {
457 private void loadImages(MenuElement menu) {
458 final MenuElement[] elements = menu.getSubElements();
459 for (
int i = 0; i < elements.length; i++) {
460 if (!(elements[i] instanceof JMenu)) {
461 String typeCode = ((Component) elements[i])
462 .getAccessibleContext().getAccessibleName();
463 final AssetType type = AssetManager.getAssetType(typeCode);
468 if (elements[i] instanceof JPopupMenu) {
469 loadImages(elements[i]);
471 final JMenuItem nextItem = (JMenuItem) elements[i];
474 if (!type.isIconLoaded()) {
475 nextItem.setIcon(GUIUtilities.getAssetMapIcon(DEFAULT_ASSET_ICON));
476 MatrixSwingWorker worker =
new MatrixSwingWorker() {
477 public Object construct() {
478 Icon icon = type.getIcon();
479 nextItem.setIcon(icon);
485 nextItem.setIcon(type.getIcon());
496 public void menuSelected(MenuEvent evt) {
497 JMenu menu = (JMenu) evt.getSource();
505 public void popupMenuWillBecomeVisible(PopupMenuEvent evt) {
506 JPopupMenu menu = (JPopupMenu) evt.getSource();
510 public void menuCanceled(MenuEvent evt) {}
511 public void menuDeselected(MenuEvent evt) {}
512 public void popupMenuCanceled(PopupMenuEvent evt) {}
513 public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {}