You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StructureViewPanel.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * Helen Hawkins Converted to new interface (bug 148190)
  13. * ******************************************************************/
  14. package org.aspectj.ajde.ui.swing;
  15. import java.awt.BorderLayout;
  16. import java.awt.Color;
  17. import java.util.Iterator;
  18. import javax.swing.BorderFactory;
  19. import javax.swing.JPanel;
  20. import javax.swing.JScrollPane;
  21. import javax.swing.border.BevelBorder;
  22. import javax.swing.border.Border;
  23. import org.aspectj.ajde.Ajde;
  24. import org.aspectj.ajde.ui.FileStructureView;
  25. import org.aspectj.ajde.ui.IStructureViewNode;
  26. import org.aspectj.ajde.ui.StructureView;
  27. import org.aspectj.ajde.ui.StructureViewRenderer;
  28. import org.aspectj.asm.IProgramElement;
  29. import org.aspectj.bridge.IMessage;
  30. import org.aspectj.bridge.Message;
  31. /**
  32. * Represents the configuration of a structure view of the system, rendered
  33. * by the <CODE>StructureTreeManager</CODE>.
  34. *
  35. * @author Mik Kersten
  36. */
  37. public class StructureViewPanel extends JPanel implements StructureViewRenderer {
  38. private static final long serialVersionUID = 7549744200612883786L;
  39. protected StructureTreeManager treeManager = new StructureTreeManager();
  40. protected StructureView currentView = null;
  41. // private java.util.List structureViews = null;
  42. protected Border border1;
  43. protected Border border2;
  44. JScrollPane tree_ScrollPane = new JScrollPane();
  45. JPanel structureToolBar_panel = null;
  46. BorderLayout borderLayout1 = new BorderLayout();
  47. public StructureViewPanel(FileStructureView structureView) {
  48. currentView = structureView;
  49. initView(structureView);
  50. structureToolBar_panel = new SimpleStructureViewToolPanel(currentView);
  51. init();
  52. }
  53. public StructureViewPanel(java.util.List structureViews) {
  54. // this.structureViews = structureViews;
  55. for (Object structureView : structureViews) {
  56. initView((StructureView) structureView);
  57. }
  58. currentView = (StructureView)structureViews.get(0);
  59. structureToolBar_panel = new BrowserStructureViewToolPanel(structureViews, currentView, this);
  60. init();
  61. }
  62. private void init() {
  63. try {
  64. jbInit();
  65. } catch (Exception e) {
  66. Message msg = new Message("Could not initialize view panel.",IMessage.ERROR,e,null);
  67. Ajde.getDefault().getMessageHandler().handleMessage(msg);
  68. }
  69. updateView(currentView);
  70. }
  71. public void setCurrentView(StructureView view) {
  72. currentView = view;
  73. treeManager.updateTree(view);
  74. }
  75. public void updateView(StructureView structureView) {
  76. if (structureView == currentView) {
  77. treeManager.updateTree(structureView);
  78. }
  79. }
  80. private void initView(StructureView view) {
  81. view.setRenderer(this);
  82. }
  83. public void setActiveNode(IStructureViewNode node) {
  84. setActiveNode(node, 0);
  85. }
  86. public void setActiveNode(IStructureViewNode node, int lineOffset) {
  87. if (node == null) return;
  88. // if (!(node.getStructureNode() instanceof IProgramElement)) return;
  89. IProgramElement pNode = node.getStructureNode();
  90. treeManager.highlightNode(pNode);
  91. if (pNode.getSourceLocation() != null) {
  92. Ajde.getDefault().getEditorAdapter().showSourceLine(
  93. pNode.getSourceLocation().getSourceFile().getAbsolutePath(),
  94. pNode.getSourceLocation().getLine() + lineOffset,
  95. true
  96. );
  97. }
  98. }
  99. public void highlightActiveNode() {
  100. if (currentView.getActiveNode() == null) return;
  101. IProgramElement node = currentView.getActiveNode().getStructureNode();
  102. if (node!=null) {
  103. treeManager.highlightNode(node);
  104. }
  105. }
  106. protected void jbInit() {
  107. border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(156, 156, 158),new Color(109, 109, 110));
  108. border2 = BorderFactory.createEmptyBorder(0,1,0,0);
  109. this.setLayout(borderLayout1);
  110. this.add(tree_ScrollPane, BorderLayout.CENTER);
  111. this.add(structureToolBar_panel, BorderLayout.NORTH);
  112. tree_ScrollPane.getViewport().add(treeManager.getStructureTree(), null);
  113. }
  114. }