📄 jdfframe.java
字号:
*/
void initProcessView()
{
m_pArea.clear();
try
{
JDFElement jdfElement;
if (m_jdfTree != null && m_jdfDocument != null)
{
if (m_jdfTree.getSelectionPath() == null)
{
jdfElement = (JDFElement) ((Wrapper) ((JDFTreeNode) m_root.
getFirstChild()).getUserObject()).getElement();
final TreePath p = new TreePath(((JDFTreeNode) m_root.getFirstChild()).getPath());
m_jdfTree.setSelectionPath(p);
}
else
{
try
{
jdfElement = (JDFElement) ((Wrapper) ((JDFTreeNode)
m_jdfTree.getSelectionPath().getLastPathComponent()).getUserObject()).getElement();
}
catch (ClassCastException c)
{
jdfElement = (JDFElement) ((Wrapper) ((JDFTreeNode)
m_root.getFirstChild()).getUserObject()).getElement();
System.err.println(c);
}
}
m_pArea.removeAll();
m_vIn.clear();
m_vPaintedRes.clear();
if (jdfElement instanceof JDFNode)
{
drawProcessView(jdfElement);
}
else if (jdfElement instanceof JDFResource)
{
final JDFElement jdf = jdfElement.getParentJDF();
if (jdf instanceof JDFNode)
{
drawProcessView(jdf);
}
}
if (jdfElement.equals(((Wrapper) ((JDFTreeNode) m_root.getFirstChild()).getUserObject()).getElement()))
m_upOneLevelButton.setEnabled(false);
else
m_upOneLevelButton.setEnabled(true);
m_zoomInButton.setEnabled(true);
m_zoomOutButton.setEnabled(true);
m_zoomOrigButton.setEnabled(false);
m_zoomBestButton.setEnabled(true);
}
}
catch (Exception s)
{
s.printStackTrace();
System.out.println("Fel n�r man ska ta processvy i try-satsen");
}
}
/**
* Method drawTreeView.
* @param doc
*/
private void drawTreeView(JDFDoc doc)
{
this.setCursor(m_waitCursor);
m_root = new JDFTreeNode();
m_jdfTree = new JTree(m_root);
final PopupListener popupListener = new PopupListener();
m_jdfTree.addMouseListener(popupListener);
m_jdfTree.setRootVisible(false);
m_jdfTree.setEditable(false);
m_jdfTree.setExpandsSelectedPaths(true);
m_jdfTree.putClientProperty("JTree.lineStyle", "Angled");
ToolTipManager.sharedInstance().registerComponent(m_jdfTree);
m_renderer = new JDFTreeRenderer(m_iniFile);
m_jdfTree.setCellRenderer(m_renderer);
m_jdfTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
m_treeSelectionListener = new MyTreeSelectionListener();
m_jdfTree.addTreeSelectionListener(m_treeSelectionListener);
m_jdfTree.setModel(createModel(doc));
m_jdfTree.setRowHeight(18);
m_jdfTree.expandPath(new TreePath(((JDFTreeNode) m_root.getFirstChild()).getPath()));
new DropTarget(m_jdfTree, this);
m_treeView.setView(m_jdfTree);
m_jdfTree.setBackground(Color.white);
m_jdfTree.setShowsRootHandles(true);
this.setCursor(m_readyCursor);
}
/**
* Creates the popupmenu after a right mouse click on node in the Tree View.
* @param path - The path to the clicked node
* @return A JPopupMenu
*/
JPopupMenu drawMouseMenu(TreePath path)
{
final JPopupMenu rightMenu = new JPopupMenu();
final int menuKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
final JDFTreeNode node = (JDFTreeNode) path.getLastPathComponent();
JDFElement elem = null;
if (node.isElement())
elem = (JDFElement) ((Wrapper) node.getUserObject()).getElement();
final JMenu insertPopupMenu = new JMenu(m_littleBundle.getString("InsertElKey"));
insertPopupMenu.setEnabled(elem != null);
m_insertElemBeforePopupItem = new JMenuItem(m_littleBundle.getString("BeforeKey"));
m_insertElemBeforePopupItem.addActionListener(this);
insertPopupMenu.add(m_insertElemBeforePopupItem);
m_insertElemIntoPopupItem = new JMenuItem(m_littleBundle.getString("IntoKey"));
m_insertElemIntoPopupItem.addActionListener(this);
insertPopupMenu.add(m_insertElemIntoPopupItem);
m_insertElemAfterPopupItem = new JMenuItem(m_littleBundle.getString("AfterKey"));
m_insertElemAfterPopupItem.addActionListener(this);
insertPopupMenu.add(m_insertElemAfterPopupItem);
rightMenu.add(insertPopupMenu);
final JMenu resMenu = new JMenu(m_littleBundle.getString("InsertResKey"));
resMenu.setEnabled(elem != null && (elem instanceof JDFNode
|| elem.getNodeName().equals("ResourcePool")));
m_insertInResPopupItem = new JMenuItem(m_littleBundle.getString("InputResourceKey"));
m_insertInResPopupItem.addActionListener(this);
resMenu.add(m_insertInResPopupItem);
m_insertOutResPopupItem = new JMenuItem(m_littleBundle.getString("OutputResourceKey"));
m_insertOutResPopupItem.addActionListener(this);
resMenu.add(m_insertOutResPopupItem);
resMenu.add(new JSeparator());
m_insertResPopupItem = new JMenuItem(m_littleBundle.getString("ResourceKey"));
m_insertResPopupItem.addActionListener(this);
resMenu.add(m_insertResPopupItem);
rightMenu.add(resMenu);
final JMenu resLinkMenu = new JMenu(m_littleBundle.getString("InsertResLinkKey"));
resLinkMenu.setEnabled(elem != null && (elem instanceof JDFNode
|| elem.getNodeName().equals("ResourceLinkPool")));
m_insertInResLinkPopupItem = new JMenuItem(m_littleBundle.getString("ResourceInLinkKey"));
m_insertInResLinkPopupItem.addActionListener(this);
resLinkMenu.add(m_insertInResLinkPopupItem);
m_insertOutResLinkPopupItem = new JMenuItem(m_littleBundle.getString("ResourceOutLinkKey"));
m_insertOutResLinkPopupItem.addActionListener(this);
resLinkMenu.add(m_insertOutResLinkPopupItem);
rightMenu.add(resLinkMenu);
m_insertAttrPopupItem = new JMenuItem(m_littleBundle.getString("InsertAttKey"));
m_insertAttrPopupItem.addActionListener(this);
rightMenu.add(m_insertAttrPopupItem);
rightMenu.add(new JSeparator());
m_cutPopupItem = new JMenuItem(m_littleBundle.getString("CutKey"));
m_cutPopupItem.setAccelerator(KeyStroke.getKeyStroke('X', menuKeyMask));
m_cutPopupItem.addActionListener(this);
rightMenu.add(m_cutPopupItem);
m_copyPopupItem = new JMenuItem(m_littleBundle.getString("CopyKey"));
m_copyPopupItem.setAccelerator(KeyStroke.getKeyStroke('C', menuKeyMask));
m_copyPopupItem.addActionListener(this);
rightMenu.add(m_copyPopupItem);
m_pastePopupItem = new JMenuItem(m_littleBundle.getString("PasteKey"));
m_pastePopupItem.setAccelerator(KeyStroke.getKeyStroke('P', menuKeyMask));
m_pastePopupItem.addActionListener(this);
rightMenu.add(m_pastePopupItem);
m_deletePopupItem = new JMenuItem(m_littleBundle.getString("DeleteKey"));
m_deletePopupItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
m_deletePopupItem.addActionListener(this);
rightMenu.add(m_deletePopupItem);
rightMenu.add(new JSeparator());
m_renamePopupItem = new JMenuItem(m_littleBundle.getString("RenameKey"));
m_renamePopupItem.addActionListener(this);
rightMenu.add(m_renamePopupItem);
m_modifyAttrValuePopupItem = new JMenuItem(m_littleBundle.getString("ModifyAttValueKey"));
m_modifyAttrValuePopupItem.addActionListener(this);
rightMenu.add(m_modifyAttrValuePopupItem);
rightMenu.add(new JSeparator());
m_requiredAttrPopupItem = new JMenuItem(m_littleBundle.getString("AddRequiredAttKey"));
m_requiredAttrPopupItem.addActionListener(this);
rightMenu.add(m_requiredAttrPopupItem);
m_requiredElemPopupItem = new JMenuItem(m_littleBundle.getString("AddRequiredElKey"));
m_requiredElemPopupItem.addActionListener(this);
rightMenu.add(m_requiredElemPopupItem);
rightMenu.add(new JSeparator());
m_xpandPopupItem = new JMenuItem(m_littleBundle.getString("ExpandKey"));
m_xpandPopupItem.addActionListener(this);
rightMenu.add(m_xpandPopupItem);
m_collapsePopupItem = new JMenuItem(m_littleBundle.getString("CollapseKey"));
m_collapsePopupItem.addActionListener(this);
rightMenu.add(m_collapsePopupItem);
//20040913 MRE
m_copyToClipBoardPopupItem = new JMenuItem(m_littleBundle.getString("CopyNode"));
m_copyToClipBoardPopupItem.addActionListener(this);
rightMenu.add(m_copyToClipBoardPopupItem);
setEnabledInMouseMenu(node, elem);
return rightMenu;
}
/**
* Creates the popupmenu after a right mouse click on node in the DevCap Output View.
* @param path - The path to the clicked node
* @return A JPopupMenu
*/
JPopupMenu drawDevCapMouseMenu(TreePath path)
{
final JPopupMenu rightMenu = new JPopupMenu();
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
if (node == null)
return rightMenu;
final Object object = node.getUserObject();
if (object instanceof JDFWrapper)
{
JMenuItem spawnExecutable = new JMenuItem("Spawn...");
spawnExecutable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JDFWrapper baseElem = (JDFWrapper) object;
String p = baseElem.getXPath();
if (p != null)
{
findInNode(p);
spawn(false);
}
}
});
rightMenu.add(spawnExecutable);
spawnExecutable.setEnabled(true);
JMenuItem spawnInfExecutable = new JMenuItem("Spawn Informative...");
spawnInfExecutable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JDFWrapper baseElem = (JDFWrapper) object;
String p = baseElem.getXPath();
if (p != null)
{
findInNode(p);
spawn(true);
}
}
});
rightMenu.add(spawnInfExecutable);
spawnInfExecutable.setEnabled(true);
JDFTreeNode treeNode = (JDFTreeNode)m_jdfTree.getSelectionPath().getLastPathComponent();
if (treeNode!=null && treeNode.equals(m_root))
{
spawnExecutable.setEnabled(false);
spawnInfExecutable.setEnabled(false);
}
}
else if (!node.isLeaf())
{
JMenuItem xpandDevCapOutput = new JMenuItem(m_littleBundle.getString("ExpandKey"));
xpandDevCapOutput.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
final Enumeration e = node.postorderEnumeration();
while (e.hasMoreElements())
{
final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) e.nextElement();
m_reportTree.expandPath(new TreePath(treeNode.getPath()));
}
m_reportTree.expandPath(m_reportTree.getSelectionPath());
}
});
rightMenu.add(xpandDevCapOutput);
xpandDevCapOutput.setEnabled(true);
JMenuItem collapseDevCapOutput = new JMenuItem(m_littleBundle.getString("CollapseKey"));
collapseDevCapOutput.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
final Enumeration e = node.postorderEnumeration();
while (e.hasMoreElements())
{
final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) e.nextElement();
m_reportTree.collapsePath(new TreePath(treeNode.getPath()));
}
m_reportTree.collapsePath(m_reportTree.getSelectionPath());
}
});
rightMenu.add(collapseDevCapOutput);
collapseDevCapOutput.setEnabled(true);
}
return rightMenu;
}
/**
* Disables the MenuItems in the MouseMenu that isn't selectable for the selected
* JDFTreeNode.
* @param node - The selected node
* @param elem - The JDFElement for the selected node, can be null
*/
private void setEnabledInMouseMenu(JDFTreeNode node, JDFElement elem)
{
if (node.isElement() && elem != null)
{
if (!((JDFTreeNode) m_root.getFirstChild()).equals(node))
{
m_insertElemBeforePopupItem.setEnabled(true);
m_insertElemAfterPopupItem.setEnabled(true);
if (elem.getTagName().equals("Comment"))
m_insertElemIntoPopupItem.setEnabled(false);
else
m_insertElemIntoPopupItem.setEnabled(true);
}
else
{
m_insertElemBeforePopupItem.setEnabled(false);
m_insertElemAfterPopupItem.setEnabled(false);
m_insertElemIntoPopupItem.setEnabled(true);
}
final boolean bMayContainResources = elem instanceof JDFNode || elem.getNodeName().equals("ResourcePool");
m_insertInResPopupItem.setEnabled(bMayContainResources);
m_insertOutResPopupItem.setEnabled(bMayContainResources);
m_insertResPopupItem.setEnabled(bMayContainResources);
final boolean bNodeOK = (elem instanceof JDFNode &&
getResourcesAllowedToLink((JDFNode) elem).size() != 0);
final boolean bResLinkPoolOK = (elem.getNodeName().equals("ResourceLinkPool") &&
getResourcesAllowedToLink(elem.getParentJDF()).size() != 0);
m_insertInResLinkPopupItem.setEnabled(bNodeOK || bResLinkPoolOK);
m_insertOutResLinkPopupItem.setEnabled(bNodeOK || bResLinkPoolOK);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -