21 package net.squiz.matrix.matrixtree;
23 import net.squiz.cuetree.*;
24 import net.squiz.matrix.core.*;
25 import net.squiz.matrix.ui.*;
26 import net.squiz.matrix.assetmap.*;
27 import net.squiz.matrix.debug.*;
29 import javax.swing.tree.*;
30 import javax.swing.event.*;
33 import java.io.IOException;
38 import java.awt.event.*;
39 import java.awt.image.*;
40 import java.awt.geom.*;
41 import java.awt.dnd.*;
42 import java.awt.datatransfer.*;
52 implements CueGestureListener, TreeWillExpandListener, Draggable, Autoscroll {
58 private SelectionTool selTool;
60 private String lastTypeCodeCreated = null;
62 private BufferedImage dblBuffer = null;
63 private DragSource dragSource = null;
65 private boolean hasExpandNextNode =
false;
66 private boolean hasExpandPrevNode =
false;
67 private static final int AUTOSCROLL_MARGIN = 12;
69 public static final Color ASSET_FINDER_BG_COLOR =
new Color(0xE9D4F4);
73 private String multipleMoveType = null;
74 private JTree tree =
this;
83 addCueGestureListener(
this);
93 selTool =
new SelectionTool(
this);
100 addCueGestureListener(
this);
101 addTreeWillExpandListener(
this);
103 addMouseListener(selTool);
104 addMouseListener(menuHandler);
105 addMouseListener(dcHandler);
106 addMouseMotionListener(selTool);
108 setUI(
new MatrixTreeUI());
110 dragSource = DragSource.getDefaultDragSource();
111 DragGestureRecognizer dgr =
112 dragSource.createDefaultDragGestureRecognizer(
114 DnDConstants.ACTION_COPY_OR_MOVE,
118 dgr.setSourceActions(dgr.getSourceActions() & ~InputEvent.BUTTON3_MASK);
119 DropTarget dropTarget =
new DropTarget(
this, dropHandler);
123 MouseMotionListener mmListener =
new MouseMotionAdapter() {
124 public void mouseDragged(MouseEvent evt) {
125 Rectangle r =
new Rectangle(evt.getX(), evt.getY(), 6, 6);
126 scrollRectToVisible(r);
129 setAutoscrolls(
true);
130 addMouseMotionListener(mmListener);
131 ToolTipManager.sharedInstance().registerComponent(
this);
141 int row = getRowForLocation(pt.x, pt.y);
142 Rectangle bounds = getBounds();
144 if (pt.y + bounds.y <= AUTOSCROLL_MARGIN) {
147 if (row < getRowCount() - 1) ++row;
149 scrollRowToVisible(row);
157 Rectangle outer = getBounds();
158 Rectangle inner = getParent().getBounds();
160 return new Insets(inner.y - outer.y + AUTOSCROLL_MARGIN,
161 inner.x - outer.x + AUTOSCROLL_MARGIN,
162 outer.height - inner.height - inner.y + outer.y + AUTOSCROLL_MARGIN,
163 outer.width - inner.width - inner.x + outer.x + AUTOSCROLL_MARGIN);
221 TreePath[] paths = getSelectionPaths();
225 for (
int i = 0; i < paths.length; i++)
237 TreePath path = getSelectionPath();
249 TreePath[] paths = getSelectionPaths();
250 return (paths != null && paths.length > 1);
259 return (getSelectionPath() == null);
268 Object[] nodes = ((DefaultTreeModel) getModel()).
getPathToRoot(node);
271 return new TreePath(nodes);
280 return (TreePath[]) paths.toArray(
new TreePath[paths.size()]);
289 setBackground(ASSET_FINDER_BG_COLOR);
291 removeMouseListener(selTool);
292 removeMouseMotionListener(selTool);
301 setBackground(Color.WHITE);
303 addMouseListener(selTool);
304 addMouseMotionListener(selTool);
318 if (MatrixDialog.hasDialog(SelectionDialog.class)) {
319 SelectionDialog selectionDialog
320 = (SelectionDialog) MatrixDialog.getDialog(SelectionDialog.class);
321 selectionDialog.setNodes(nodes);
330 TreePath path = evt.getPath();
334 if (treeNode.
getAsset().isAccessible()) {
346 if (parent == child.getParent()) {
359 if (parent == node) {
371 if (parent.getChildCount() != 0) {
386 if (parent.getChildCount() != 0) {
404 boolean found =
false;
409 if (loc != 0 || parent.getChildCount() == 0) {
410 removeChildNodes(parent);
411 AssetManager.refreshAsset(parent,
"", loc, -1);
413 childCount = parent.getChildCount();
414 if (childCount > 0) {
415 for (Enumeration children = parent.children(); children.hasMoreElements();) {
416 MatrixTreeNode nextNode = (MatrixTreeNode) children.nextElement();
417 if (nextNode.getAsset().getId().equals(assetid)) {
419 }
else if (incChildren) {
421 nextNode = findAssetUnderParent(nextNode, assetid,
true);
422 if (nextNode != null) {
431 if (childCount >= AssetManager.getLimit()) {
433 loc += AssetManager.getLimit();
438 }
catch (IOException ex) { }
452 public void loadChildAssets(
final String[] assetids,
final String[] sort_orders,
final boolean selectAll,
final boolean teleport) {
453 MatrixStatusBar.setStatus(Matrix.translate(
"asset_map_status_bar_requesting"));
454 Runnable runner =
new Runnable() {
459 tree.setRootVisible(
false);
460 if (((DefaultTreeModel) tree.getModel()).getRoot() != AssetManager.getRootFolderNode()) {
461 ((DefaultTreeModel) tree.getModel()).setRoot(AssetManager.getRootFolderNode());
465 int numAssets = assetids.length;
468 boolean found =
false;
469 TreePath path = null;
473 tree.clearSelection();
478 TreePath[] paths =
new TreePath[numAssets+1];
481 while (level < numAssets) {
485 totalKids = asset.getTotalKidsLoaded();
486 sort_order = Integer.parseInt(sort_orders[level]);
488 if (!sort_orders[level].equals(
"-1")) {
489 int modifier = (int)(sort_order/AssetManager.getLimit());
491 if (parent.getChildCount() == 0 || (AssetManager.getLimit()*modifier != totalKids)) {
492 for (
int i=(AssetManager.getLimit()*modifier); i > 0; i--) {
493 if (parent.
getAsset().getNumKids() >= AssetManager.getLimit()*modifier) {
499 if (parent.
getAsset().getNumKids() >= AssetManager.getLimit()*modifier) {
501 removeChildNodes(parent);
502 AssetManager.refreshAsset(parent,
"", AssetManager.getLimit()*modifier, -1);
503 loadedNodes += parent.getChildCount();
507 if (parent.getChildCount() > 0) {
508 loc += (sort_order%AssetManager.getLimit());
510 if (loc >= parent.getChildCount()) {
511 loc = parent.getChildCount()-1;
512 }
else if (loc < 0) {
518 if (foundChild.
getAsset().getId().equals(assetids[level])) {
523 for (
int i = 0; i < parent.getChildCount(); i++) {
525 if (foundChild.
getAsset().getId().equals(assetids[level])) {
534 parent = findAssetUnderParent(parent, assetids[level],
false);
535 if (parent != null) {
551 tree.addSelectionPaths(paths);
553 tree.addSelectionPath(path);
560 scrollPathToVisible(path);
566 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_requesting"), 1000);
567 Object[] transArgs = {
570 String message = Matrix.translate(
"asset_map_error_locate_asset", transArgs);
571 GUIUtilities.error(message, Matrix.translate(
"asset_map_dialog_title_error"));
575 }
catch (Exception ioe) {
576 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_requesting"), 1000);
577 Object[] transArgs = {
580 String message = Matrix.translate(
"asset_map_error_loading_children", transArgs);
581 GUIUtilities.error(message, Matrix.translate(
"asset_map_dialog_title_error"));
586 if (loadedNodes == 1) {
587 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_loaded_child"), 3000);
589 Object[] transArgs = {
590 new Integer(loadedNodes)
592 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_loaded_children", transArgs), 3000);
596 SwingUtilities.invokeLater(runner);
623 if (node.getChildCount() > 0 && direction.equals(
"") && start < 0) {
624 removeExpandPreviousNode(node);
625 removeExpandNextNode(node);
628 if (node.getChildCount() == 0) {
629 node.
getAsset().propagateChildren(node);
633 insertLoadingNode(node);
634 MatrixStatusBar.setStatus(Matrix.translate(
"asset_map_status_bar_requesting"));
635 Runnable runner =
new Runnable() {
639 if (asset.getId().equals(
"1")) {
640 AssetManager.refreshAsset(node,
"");
641 removeLoadingNode(node);
643 removeChildNodes(node);
644 AssetManager.refreshAsset(node, direction, start, limit);
648 if (!isExpanded(path)) {
653 if (node.getChildCount() == 1) {
654 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_loaded_child"), 1000);
656 Object[] transArgs = {
657 new Integer(node.getChildCount())
659 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_loaded_children", transArgs), 1000);
662 }
catch (IOException ioe) {
663 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_requesting"), 1000);
664 Object[] transArgs = {
667 String message = Matrix.translate(
"asset_map_error_loading_children", transArgs);
668 GUIUtilities.error(message, Matrix.translate(
"asset_map_dialog_title_error"));
673 SwingUtilities.invokeLater(runner);
677 public void treeWillCollapse(TreeExpansionEvent evt) {}
678 public void moveGestureRecognized(CueEvent evt) {}
679 public void addGestureRecognized(CueEvent evt) {}
680 public void multipleMoveGestureRecognized(CueEvent evt) {}
681 public void multipleAddGestureRecognized(CueEvent evt) {}
682 public void multipleAddGestureCompleted(CueEvent evt) {}
691 TreePath[] sourcePaths = evt.getSourcePaths();
694 for (
int i = 0; i < sourcePaths.length; i++) {
695 sourceNodes[i] = (
MatrixTreeNode) sourcePaths[i].getLastPathComponent();
701 if (sourceNodes.length > 1) {
703 while (numSorted > 0) {
705 for (
int i = 0; i < sourceNodes.length; i++) {
706 if (i+1 < sourceNodes.length) {
711 int firstSortOrder = firstTreeNode.getSortOrder();
712 int nextSortOrder = nextTreeNode.getSortOrder();
715 if (nextSortOrder < firstSortOrder) {
716 sourceNodes[i] = nextTreeNode;
717 sourceNodes[i+1] = firstTreeNode;
725 JPopupMenu newLinkMenu = getNewLinkMenu(
728 evt.getIndex(), evt.getPrevIndex());
729 newLinkMenu.show(
this, evt.getX(), evt.getY());
739 String typeCode = (String) evt.getSourcePath().getLastPathComponent();
740 JPopupMenu newAssetMenu = getNewAssetMenu(
745 newAssetMenu.show(
this, evt.getX(), evt.getY());
756 if (multipleMoveType != null) {
757 TreePath[] sourcePaths = evt.getSourcePaths();
759 for (
int i = 0; i < sourcePaths.length; i++) {
760 sourceNodes[i] = (
MatrixTreeNode) sourcePaths[i].getLastPathComponent();
764 fireCreateLink(multipleMoveType, sourceNodes, parent, evt.getIndex(), evt.getPrevIndex());
765 multipleMoveType = null;
779 setRootVisible(
true);
780 ((DefaultTreeModel) getModel()).setRoot(node);
797 Object[] listeners = listenerList.getListenerList();
802 for (
int i = listeners.length - 2; i >= 0; i -= 2) {
805 String[] parentIds = getCueModeParentIds();
806 setCueModeParentIds(null);
808 evt =
new NewLinkEvent(
this, type, sources, parent, index, prevIndex, parentIds);
810 requestForNewLink(evt);
838 Object[] listeners = listenerList.getListenerList();
843 for (
int i = listeners.length - 2; i >= 0; i -= 2) {
849 requestForNewAsset(evt);
853 lastTypeCodeCreated = typeCode;
863 Object[] listeners = listenerList.getListenerList();
868 for (
int i = listeners.length - 2; i >= 0; i -= 2) {
874 nodeDoubleClicked(evt);
885 Graphics2D g2 = (Graphics2D) g;
887 if (dblBuffer == null) {
888 initDoubleBufferImage();
890 g2.drawImage(dblBuffer, null, 0, 0);
891 super.paintComponent(g);
893 if (dropHandler == null)
896 if (selTool.isDragging())
897 selTool.paintSelectionTool(g2);
898 else if (dropHandler.isDropping())
910 return (paths.length == 1) ? getGhostedNode(paths[0]) : getGhostedNode(paths);
975 throw new IllegalArgumentException(
"paths is null");
976 Image ghostedImage = (paths.length == 1)
977 ? getGhostedNode(paths[0])
978 : getGhostedNode(paths);
989 if (getModel().getRoot() == node)
994 if (!treeNode.
getAsset().isAccessible())
1005 for (
int i = 0; i < nodes.length; i++) {
1012 private int currentFontSize = 10;
1013 private int previousFontSize = 0;
1014 private int initialFontSize = 10;
1015 private Font nodeFont;
1017 public Font getFontInUse() {
1018 if (currentFontSize != previousFontSize) {
1020 nodeFont =
new Font(
"nodeFont", Font.PLAIN, currentFontSize);
1022 previousFontSize = currentFontSize;
1027 private void setFontSize(
int size) {
1028 if (size > 7 && size < 18) {
1029 currentFontSize = size;
1033 private java.util.List getExpandedChildren(TreeNode parent) {
1034 java.util.List paths =
new ArrayList();
1035 int count = parent.getChildCount();
1036 for (
int i = 0; i < count; i++) {
1037 MatrixTreeNode node = (MatrixTreeNode)parent.getChildAt(i);
1039 if (isExpanded(path)) {
1041 paths.addAll(getExpandedChildren(node));
1047 private int[] getRowsForPaths(java.util.List paths) {
1048 int rows[] =
new int[paths.size()];
1049 for (
int i = 0; i < paths.size(); i++) {
1050 int row = getRowForPath((TreePath)paths.get(i));
1056 private void expandRows(
int rows[]) {
1057 for (
int i=0; i< rows.length; i++) {
1062 private void expandPaths(java.util.List paths,
boolean scrollPathToVisible) {
1063 for (
int i=0; i< paths.size(); i++) {
1064 expandPath((TreePath)paths.get(i));
1065 if (scrollPathToVisible) {
1066 scrollPathToVisible((TreePath)paths.get(i));
1075 Action deleteAction =
new AbstractAction() {
1076 public void actionPerformed(ActionEvent evt) {
1078 if (nodes == null) {
1081 DeleteDialog deleteDialog = DeleteDialog.getDeleteDialog(nodes, getLocationOnScreen(), getSize());
1082 deleteDialog.show();
1086 Action searchAction =
new AbstractAction() {
1087 public void actionPerformed(ActionEvent evt) {
1088 Point topLeft =
new Point(getLocationOnScreen());
1089 SearchDialog searchDialog = SearchDialog.getSearchDialog(topLeft, getSize());
1090 searchDialog.show();
1094 Action increaseFontAction =
new AbstractAction() {
1095 public void actionPerformed(ActionEvent evt) {
1096 setFontSize(currentFontSize+1);
1097 java.util.List expandedChildren = getExpandedChildren((TreeNode)getModel().getRoot());
1098 ((DefaultTreeModel) getModel()).reload();
1099 expandPaths(expandedChildren,
false);
1104 Action decreaseFontAction =
new AbstractAction() {
1105 public void actionPerformed(ActionEvent evt) {
1106 setFontSize(currentFontSize-1);
1107 java.util.List expandedChildren = getExpandedChildren((TreeNode)getModel().getRoot());
1108 ((DefaultTreeModel) getModel()).reload();
1109 expandPaths(expandedChildren,
false);
1113 Action normalFontAction =
new AbstractAction() {
1114 public void actionPerformed(ActionEvent evt) {
1115 setFontSize(initialFontSize);
1116 java.util.List expandedChildren = getExpandedChildren((TreeNode)getModel().getRoot());
1117 ((DefaultTreeModel) getModel()).reload();
1118 expandPaths(expandedChildren,
false);
1123 getInputMap().put(KeyStroke.getKeyStroke(
"DELETE"),
"delete");
1124 getActionMap().put(
"delete", deleteAction);
1125 getInputMap().put(KeyStroke.getKeyStroke(
"shift ctrl J"),
"search");
1126 getActionMap().put(
"search", searchAction);
1127 getInputMap().put(KeyStroke.getKeyStroke(
"shift ctrl EQUALS"),
"increase_font_size");
1128 getActionMap().put(
"increase_font_size", increaseFontAction);
1129 getInputMap().put(KeyStroke.getKeyStroke(
"shift ctrl ADD"),
"increase_font_size");
1130 getActionMap().put(
"increase_font_size", increaseFontAction);
1131 getInputMap().put(KeyStroke.getKeyStroke(
"shift ctrl MINUS"),
"decrease_font_size");
1132 getActionMap().put(
"decrease_font_size", decreaseFontAction);
1133 getInputMap().put(KeyStroke.getKeyStroke(
"shift ctrl SUBTRACT"),
"decrease_font_size");
1134 getActionMap().put(
"decrease_font_size", decreaseFontAction);
1135 getInputMap().put(KeyStroke.getKeyStroke(
"shift ctrl BACK_SPACE"),
"normal_font_size");
1136 getActionMap().put(
"normal_font_size", normalFontAction);
1140 public void removeKeyStroke(String key) {
1141 getInputMap().put(KeyStroke.getKeyStroke(key),
"none");
1154 private void insertLoadingNode(MatrixTreeNode parentNode) {
1155 int insertIndex = 0;
1156 if (parentNode.getChildCount() > 0) {
1157 insertIndex = parentNode.getChildCount()-1;
1159 ((DefaultTreeModel) getModel()).insertNodeInto(
new LoadingNode(), parentNode, insertIndex);
1166 private void removeLoadingNode(MatrixTreeNode parent) {
1169 int[] childIndex =
new int[1];
1170 Object[] removedArray =
new Object[1];
1172 LoadingNode loadingNode = null;
1173 for (Enumeration children = parent.children(); children.hasMoreElements();) {
1174 MatrixTreeNode nextNode = (MatrixTreeNode) children.nextElement();
1175 if (nextNode instanceof LoadingNode) {
1176 loadingNode = (LoadingNode) nextNode;
1180 if (loadingNode != null) {
1181 childIndex[0] = parent.getIndex(loadingNode);
1182 parent.remove(childIndex[0]);
1184 removedArray[0] = loadingNode;
1185 ((DefaultTreeModel) getModel()).nodesWereRemoved(parent, childIndex, removedArray);
1195 private void removeChildNodes(MatrixTreeNode parent) {
1196 Object[] removedArray =
new Object[parent.getChildCount()];
1199 for (Enumeration children = parent.children(); children.hasMoreElements();) {
1200 MatrixTreeNode nextNode = (MatrixTreeNode) children.nextElement();
1201 if (nextNode != null) {
1202 removeChildNodes(nextNode);
1203 removedArray[i] = nextNode;
1209 for (
int j = i; j > 0; j--) {
1210 MatrixTreeModelBus.removeNodeFromParent((MatrixTreeNode)removedArray[j-1]);
1212 MatrixTreeModelBus.nodeChanged(parent);
1224 if (parentNode.
getAsset().getTotalKidsLoaded() > 0) {
1228 if ((AssetManager.getLimit() <= (parentNode.getChildCount()-modifier)) && (parentNode.
getAsset().getNumKids() == -1 || (parentNode.
getAsset().getNumKids() > (parentNode.
getAsset().getTotalKidsLoaded()+AssetManager.getLimit())))) {
1250 if ((parentNode.
getAsset().getTotalKidsLoaded() > 0)) {
1274 private void addMenuItem(JMenuItem item, JPopupMenu menu, ActionListener l) {
1275 item.addActionListener(l);
1276 item.setFont(getFontInUse());
1287 private JPopupMenu getNewLinkMenu(
1288 final MatrixTreeNode[] sources,
1289 final MatrixTreeNode parent,
1291 final int prevIndex) {
1293 JPopupMenu newLinkMenu =
new JPopupMenu();
1295 final JMenuItem moveMenuItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_move_here"));
1296 final JMenuItem newLinkMenuItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_link_here"));
1297 final JMenuItem cloneMenuItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_clone_here"));
1298 final JMenuItem cancelMenuItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_cancel"));
1300 ActionListener listener =
new ActionListener() {
1301 public void actionPerformed(ActionEvent evt) {
1302 String type = NewLinkEvent.LINK_TYPE_MOVE;
1303 if (evt.getSource().equals(moveMenuItem)) {
1304 type = NewLinkEvent.LINK_TYPE_MOVE;
1305 }
else if (evt.getSource().equals(newLinkMenuItem)) {
1306 type = NewLinkEvent.LINK_TYPE_NEW_LINK;
1307 }
else if (evt.getSource().equals(cloneMenuItem)) {
1308 type = NewLinkEvent.LINK_TYPE_CLONE;
1309 }
else if (evt.getSource().equals(cancelMenuItem)) {
1316 addMenuItem(moveMenuItem, newLinkMenu, listener);
1317 addMenuItem(newLinkMenuItem, newLinkMenu, listener);
1318 addMenuItem(cloneMenuItem, newLinkMenu, listener);
1319 newLinkMenu.addSeparator();
1320 addMenuItem(cancelMenuItem, newLinkMenu, listener);
1332 private JPopupMenu getNewAssetMenu(
1333 final String typeCode,
1334 final MatrixTreeNode parent,
1336 JPopupMenu createMenu =
new JPopupMenu();
1338 final JMenuItem createItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_create_here"));
1339 final JMenuItem cancelItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_cancel"));
1341 ActionListener listener =
new ActionListener() {
1342 public void actionPerformed(ActionEvent evt) {
1343 if (evt.getSource().equals(createItem)) {
1348 addMenuItem(createItem, createMenu, listener);
1349 addMenuItem(cancelItem, createMenu, listener);
1357 private void initDoubleBufferImage() {
1359 int h = getHeight();
1360 dblBuffer = (BufferedImage) createImage(w, h);
1361 Graphics2D gc = dblBuffer.createGraphics();
1362 gc.setColor(getBackground());
1363 gc.fillRect(0, 0, w, h);
1376 private TreePath[] selPaths = null;
1378 public void mouseReleased(MouseEvent evt) {
1379 selPaths = getSelectionPaths();
1382 public void mousePressed(MouseEvent evt) {
1384 TreePath[] paths = getSelectionPaths();
1385 if (paths != null) {
1387 TreePath[] newPaths =
new TreePath[paths.length+1];
1388 for (
int i=0; i < paths.length; i++) {
1389 Object node = paths[i].getLastPathComponent();
1391 newPaths[c++] = paths[i];
1394 setSelectionPaths(newPaths);
1398 public void mouseClicked(MouseEvent evt) {
1399 if (evt.getClickCount() == 1) {
1400 final TreePath treePath = getPathForLocation(evt.getX(), evt.getY());
1401 if (treePath == null)
1405 ((ExpandingNode)node).switchName(evt.getX(),tree.getPathBounds(treePath).getX());
1406 ((DefaultTreeModel) getModel()).nodeChanged(node);
1408 if (selPaths != null) {
1409 setSelectionPaths(selPaths);
1416 if (evt.getClickCount() != 2)
1419 final TreePath treePath = getPathForLocation(evt.getX(), evt.getY());
1420 if (treePath == null)
1423 if (getToggleClickCount() != 2) {
1424 final Point point = evt.getPoint();
1427 if (!node.
getAsset().childrenLoaded()) {
1428 AssetRefreshWorker worker =
new AssetRefreshWorker(node,
true);
1438 int start = ((ExpandingNextNode)node).getStartLoc(evt.getX(),tree.getPathBounds(treePath).getX());
1445 int start = ((ExpandingPreviousNode)node).getStartLoc(evt.getX(),tree.getPathBounds(treePath).getX());
1466 private ActionListener addMenuListener;
1473 addMenuListener = MatrixMenus.getMatrixTreeAddMenuListener(
MatrixTree.this);
1482 if (!GUIUtilities.isRightMouseButton(evt))
1489 JPopupMenu menu = null;
1493 if (getPathForLocation(evt.getX(), evt.getY()) == null) {
1496 TreePath[] selectedPaths
1498 setSelectionPaths(selectedPaths);
1500 menu = (selectedPaths.length == 1)
1505 menu.show(
MatrixTree.this, evt.getX(), evt.getY());
1515 return MatrixMenus.getPopupAddMenu(addMenuListener);
1525 TreePath path = getPathForLocation(x, y);
1526 TreePath[] selPaths = getSelectionPaths();
1531 path = getClosestPathForLocation(x, y);
1532 }
else if (selPaths != null) {
1535 if (selPaths.length > 1) {
1536 boolean found =
false;
1537 for (
int i = 0; i < selPaths.length; i++) {
1538 if (selPaths[i].getLastPathComponent()
1539 == path.getLastPathComponent()) {
1552 TreePath[] paths =
new TreePath[] { path };
1563 JPopupMenu menu = null;
1568 if (!node.
getAsset().isAccessible())
1573 menu = MatrixMenus.getUseMeMenu(node);
1578 menu = MatrixMenus.getPopupScreenMenu(node);
1579 menu.addSeparator();
1584 if (items != null) {
1585 for (
int i = 0; i < items.length; i++) {
1586 items[i].setFont(getFontInUse());
1594 ActionListener explicitAddListener =
new ActionListener() {
1595 public void actionPerformed(ActionEvent evt) {
1597 MatrixMenus.getTypeCodeFromEvent(evt),
1604 JMenu addMenu = MatrixMenus.getAddMenu(explicitAddListener);
1605 addMenu.setText(Matrix.translate(
"asset_map_menu_new_child"));
1606 addMenu.setFont(getFontInUse());
1620 JPopupMenu menu =
new JPopupMenu();
1621 final JMenuItem moveItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_move"));
1622 final JMenuItem newLinkItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_link"));
1623 final JMenuItem cloneItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_clone"));
1625 ActionListener multiplelistener =
new ActionListener() {
1626 public void actionPerformed(ActionEvent evt) {
1627 if (evt.getSource() == moveItem)
1629 else if (evt.getSource() == newLinkItem)
1631 else if (evt.getSource() == cloneItem)
1633 startCueMode(getSelectionPaths());
1637 moveItem.addActionListener(multiplelistener);
1638 newLinkItem.addActionListener(multiplelistener);
1639 cloneItem.addActionListener(multiplelistener);
1642 moveItem.setFont(getFontInUse());
1643 newLinkItem.setFont(getFontInUse());
1644 cloneItem.setFont(getFontInUse());
1647 menu.add(newLinkItem);
1648 menu.add(cloneItem);
1659 JMenuItem[] items =
new JMenuItem[3];
1660 final JMenuItem teleportItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_teleport"));
1661 final JMenuItem refreshItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_refresh"));
1664 final String newChildPreviousItemTitle;
1665 if (lastTypeCodeCreated != null) {
1666 Object[] transArgs = { ((AssetType) AssetManager.getAssetType(lastTypeCodeCreated)).getName() };
1667 newChildPreviousItemTitle = Matrix.translate(
"asset_map_menu_new_child_previous", transArgs);
1669 newChildPreviousItemTitle = Matrix.translate(
"asset_map_menu_no_previous_child");
1672 final JMenuItem newChildPreviousItem =
new JMenuItem(newChildPreviousItemTitle);
1674 if (lastTypeCodeCreated == null) {
1675 newChildPreviousItem.setEnabled(
false);
1678 ActionListener extrasListener =
new ActionListener() {
1679 public void actionPerformed(ActionEvent evt) {
1680 if (evt.getSource().equals(teleportItem)) {
1682 }
else if (evt.getSource().equals(refreshItem)) {
1684 AssetRefreshWorker worker =
new AssetRefreshWorker(assetids,
true);
1686 }
else if (evt.getSource().equals(newChildPreviousItem)) {
1699 teleportItem.addActionListener(extrasListener);
1701 teleportItem.setEnabled(
false);
1704 refreshItem.addActionListener(extrasListener);
1705 newChildPreviousItem.addActionListener(extrasListener);
1706 items[0] = teleportItem;
1707 items[1] = refreshItem;
1708 items[2] = newChildPreviousItem;
1719 implements DragGestureListener {
1721 protected Point dragOffset =
new Point(5, 5);
1722 protected TreePath[] dragPaths;
1723 private boolean dragImageSupport =
false;
1736 Point initPoint = dge.getDragOrigin();
1737 if (getPathForLocation(initPoint.x, initPoint.y) == null)
1740 dragPaths = getSelectionPaths();
1742 if (dragPaths != null) {
1745 Point topLeft =
new Point(getPathBounds(dragPaths).getLocation());
1746 Point origin = dge.getDragOrigin();
1747 dragOffset.setLocation(origin.getX() - topLeft.getX(), origin.getY() - topLeft.getY());
1750 DragImageExchange.setDragImage(dragImage, dragOffset);
1754 if (dge.getDragSource().isDragImageSupported()) {
1755 dragImageSupport =
true;
1757 new Cursor(Cursor.DEFAULT_CURSOR),
1765 new Cursor(Cursor.DEFAULT_CURSOR),
1773 public boolean isDragImageSupported() {
1774 return dragImageSupport;
1788 protected Point initMousePt;
1789 private Point lastMousePt = null;
1790 private BufferedImage dragImage;
1791 private Point mouseOffset =
new Point(5,5);
1807 dragImage = DragImageExchange.getDragImage();
1808 mouseOffset = DragImageExchange.getMouseOffset();
1818 if (dragHandler == null)
return;
1823 if (!dragHandler.isDragImageSupported())
1833 if (dragHandler == null)
return;
1835 if (lastMousePt != null && lastMousePt.equals(dtde.getLocation()))
1837 if (initMousePt == null) {
1838 initMousePt = dtde.getLocation();
1839 SwingUtilities.convertPointFromScreen(initMousePt,
MatrixTree.this);
1841 lastMousePt = dtde.getLocation();
1842 if (!dragHandler.isDragImageSupported())
1851 public void drop(DropTargetDropEvent dtde) {
1852 if (dragHandler == null)
return;
1854 Transferable transfer = dtde.getTransferable();
1855 java.util.List paths = null;
1857 paths = (java.util.List) transfer.getTransferData(
1859 }
catch (UnsupportedFlavorException ufe) {
1860 ufe.printStackTrace();
1861 }
catch (IOException ioe) {
1862 ioe.printStackTrace();
1865 Iterator iterator = paths.iterator();
1866 while (iterator.hasNext()) {
1867 TreePath path = (TreePath) iterator.next();
1870 GUIUtilities.error(Matrix.translate(
"asset_map_error_move_shadow_nodes"), Matrix.translate(
"asset_map_dialog_title_error"));
1873 if (!dragHandler.isDragImageSupported())
1879 DragImageExchange.completeExchange();
1883 if (!dragHandler.isDragImageSupported())
1885 startCueMode((TreePath[]) paths.toArray(
new TreePath[paths.size()]));
1886 Point p = dtde.getLocation();
1887 TreePath path = getClosestPathForLocation((
int) p.getX(),(int) p.getY());
1889 drawCueLine(path, (
int) p.getY());
1898 if (dragHandler == null)
return;
1900 if (dragImage == null || dragHandler.isDragImageSupported())
1903 int x = lastMousePt.x - mouseOffset.x;
1904 int y = lastMousePt.y - mouseOffset.y;
1906 g2d.drawImage(dragImage, x, y,
MatrixTree.this);
1934 java.util.List realSourcePaths =
new ArrayList();
1935 boolean chuck =
false;
1937 for (
int i = 0; i < sourcePaths.length; i++) {
1939 for (
int j = 0; j < sourcePaths.length; j++) {
1942 if (sourcePaths[j].isDescendant(sourcePaths[i]))
1946 realSourcePaths.add(sourcePaths[i]);
1948 return (TreePath[]) realSourcePaths.toArray(
new TreePath[realSourcePaths.size()]);
1960 return nodeIconContainsPoint(p);
1971 class MatrixTreeUI
extends CueTree.CueTreeUI {
1973 public MatrixTreeUI() {
1974 setCueLineColor(UIManager.getColor(
"CueLine.stroke"));
1981 protected MouseListener createMouseListener() {
1982 return new MatrixMouseHandler();
1991 implements MouseMotionListener {
1993 boolean isDragging =
false;
2027 int mouseX = evt.getX();
2028 int mouseY = evt.getY();
2033 TreePath path = getClosestPathForLocation(tree, mouseX, mouseY);
2034 boolean isControl = isLocationInExpandControl(path, mouseX, mouseY);
2035 if ((getPathForLocation(mouseX, mouseY) == null) && !isControl && !GUIUtilities.isRightMouseButton(evt))
2040 if ((!evt.isConsumed())) {
2041 handleSelection(evt);
2048 void handleSelection(MouseEvent e) {
2049 if(tree != null && tree.isEnabled()) {
2050 if (isEditing(tree) && tree.getInvokesStopCellEditing() && !stopEditing(tree)) {
2053 if (tree.isRequestFocusEnabled()) {
2054 tree.requestFocus();
2057 TreePath path = getClosestPathForLocation(tree, e.getX(), e.getY());
2059 Rectangle bounds = getPathBounds(tree, path);
2060 if(e.getY() > (bounds.y + bounds.height)) {
2066 if(SwingUtilities.isLeftMouseButton(e))
2067 checkForClickInExpandControl(path, e.getX(), e.getY());
2074 if (x <= (bounds.x + bounds.width) && !startEditing(path, e)) {
2075 selectPathForEvent(path, e);