|
From: Johannes Z. <jza...@us...> - 2006-02-20 08:50:08
|
Update of /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/views In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13570/src/net/sf/magicmap/client/views Modified Files: MapView.java OutlineView.java Log Message: Changes to show maps in the outline view tree Refactorings Index: OutlineView.java =================================================================== RCS file: /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/views/OutlineView.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OutlineView.java 12 Oct 2005 21:44:17 -0000 1.5 --- OutlineView.java 20 Feb 2006 08:49:59 -0000 1.6 *************** *** 1,4 **** /* ! * Created on 26.11.2004 */ --- 1,4 ---- /* ! * Created on 26.11.2004 */ *************** *** 29,32 **** --- 29,33 ---- import net.sf.magicmap.client.gui.utils.RelativePanelBuilder; import net.sf.magicmap.client.interfaces.NodeModelListener; + import net.sf.magicmap.client.model.node.MapNode; import net.sf.magicmap.client.model.node.Node; import net.sf.magicmap.client.model.node.NodeModel; *************** *** 35,310 **** /** ! * @author thuebner */ ! public class OutlineView extends View implements NodeModelListener, TreeSelectionListener{ ! ! private NodeModel model; ! private JTree tree; ! private DefaultTreeModel treemodel; ! private DefaultMutableTreeNode treeroot; ! private OutlineNode nodeAccessPoints; ! private OutlineNode nodeClients; ! private OutlineNode nodeLocations; ! ! public OutlineView() { ! super(); ! this.setFrameIcon(GUIBuilder.getToolIcon(GUIConstants.ICON_OUTLINE)); ! } ! ! /* (non-Javadoc) ! * @see java.awt.Component#getName() ! */ ! public String getName(){ ! return GUIUtils.i18n("outline", false); ! } ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.views.View#buildViewComponent() ! */ ! protected JComponent buildViewComponent(){ ! RelativeLayout layout = new RelativeLayout(); ! RelativePanelBuilder builder = new RelativePanelBuilder(layout); ! treeroot = new OutlineNode("ROOT"); ! treemodel = new DefaultTreeModel(treeroot); ! nodeAccessPoints = new OutlineNode(GUIUtils.i18n("accesspoints")); ! nodeClients = new OutlineNode(GUIUtils.i18n("clients")); ! nodeLocations = new OutlineNode(GUIUtils.i18n("locations")); ! ! treeroot.add(nodeAccessPoints); ! treeroot.add(nodeClients); ! treeroot.add(nodeLocations); ! tree = new JTree(treemodel); ! tree.setRootVisible(false); ! tree.setCellRenderer(new OutlineRenderer()); ! tree.setBorder(new EmptyBorder(new Insets(3, 3, 3, 3))); ! tree.addTreeSelectionListener(this); ! JComponent pane = new JScrollPane(tree,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); ! pane.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0))); ! builder.add(pane, "tree"); ! builder.setTopTopDistance("tree", null, 0); ! builder.setBottomBottomDistance("tree", null, 0); ! builder.setLeftLeftDistance("tree", null, 0); ! builder.setRightRightDistance("tree", null, 0); ! JPanel panel = builder.getPanel(); ! panel.setMinimumSize(new Dimension(200, -1)); ! panel.setMaximumSize(new Dimension(-1,-1)); ! return panel; ! } ! public NodeModel getModel(){ ! return model; ! } - public void setModel(NodeModel model){ - this.model = model; - } ! /** ! * Erweiterter Knoten für einen Baum. Es wird Knoten aus dem NodeModel ! * von PACW aufgenommen. ! * @author thuebner ! */ ! private class OutlineNode extends DefaultMutableTreeNode { ! private Node node; ! /** ! * Konstruktor für Überschriften ! * @param title ! */ ! public OutlineNode(String title) { ! super(title); ! node = null; ! } - /** - * Konstruktur für Knoten aus dem NodeModel - * @param node - */ - public OutlineNode(Node node) { - this.node = node; - } ! public Node getNode(){ ! return this.node; ! } ! } ! private class OutlineRenderer extends DefaultTreeCellRenderer { ! /* (non-Javadoc) ! * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) ! */ ! public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, ! boolean leaf, int row, boolean hasFocus){ ! Node node = ((OutlineNode) value).getNode(); ! JLabel c; ! if (node == null){ ! c = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, false, row, hasFocus); ! // Dafür sorgen, dass Folder-Icons angezeigt werden, auch wenn keine Unterelemente ! if (!expanded){ ! c.setIcon(this.getDefaultClosedIcon()); ! } else{ ! c.setIcon(this.getDefaultOpenIcon()); ! } ! } else{ ! c = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); ! c.setText(node.getDisplayName()); ! Icon icon = Controller.getInstance().getMapView().getIconForNode(node); ! if (icon == null) icon = this.getDefaultLeafIcon(); ! c.setIcon(icon); ! } ! c.setPreferredSize(new Dimension(300, -1)); ! return c; ! } ! } ! ! private TreePath getOutlineNodePath(OutlineNode root, Node node){ ! int size = root.getChildCount(); ! for (int i = 0; i < size; i++){ ! OutlineNode on = (OutlineNode) root.getChildAt(i); ! if (on.getNode() == node){ ! return new TreePath((Object[])on.getPath()); ! } ! } ! return null; ! } ! private TreePath getOutlineNodePath(Node node){ ! switch (node.getType()) { ! case NodeModel.NODETYPE_ACCESSPOINT : ! return getOutlineNodePath(nodeAccessPoints, node); ! case NodeModel.NODETYPE_CLIENT : ! return getOutlineNodePath(nodeClients, node); ! case NodeModel.NODETYPE_LOCATION : ! return getOutlineNodePath(nodeLocations, node); ! default : ! return null; ! } ! } ! private OutlineNode findOutlineNode(OutlineNode root, Node node){ ! int size = root.getChildCount(); ! for (int i = 0; i < size; i++){ ! OutlineNode on = (OutlineNode) root.getChildAt(i); ! if (on.getNode() == node){ ! return on; ! } ! } ! return null; ! } ! ! private OutlineNode findOutlineNode(Node node){ ! switch (node.getType()) { ! case NodeModel.NODETYPE_ACCESSPOINT : ! return findOutlineNode(nodeAccessPoints, node); ! case NodeModel.NODETYPE_CLIENT : ! return findOutlineNode(nodeClients, node); ! case NodeModel.NODETYPE_LOCATION : ! return findOutlineNode(nodeLocations, node); ! default : ! return null; ! } ! } ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.interfaces.NodeModelListener#nodeAddedEvent(net.sf.magicmap.client.model.Node) ! */ ! public void nodeAddedEvent(Node node){ ! OutlineNode on = new OutlineNode(node); ! on.setAllowsChildren(false); ! int index = 0; ! switch (node.getType()) { ! case NodeModel.NODETYPE_ACCESSPOINT : ! index = getAlphabeticalIndex(nodeAccessPoints,on); ! treemodel.insertNodeInto(on,nodeAccessPoints,index); ! break; ! case NodeModel.NODETYPE_CLIENT : ! index = getAlphabeticalIndex(nodeClients,on); ! treemodel.insertNodeInto(on,nodeClients,index); ! break; ! case NodeModel.NODETYPE_LOCATION : ! index = getAlphabeticalIndex(nodeLocations,on); ! treemodel.insertNodeInto(on,nodeLocations,index); ! break; ! } ! for (int i=0; i<tree.getRowCount();i++) ! if(tree.isShowing()&& tree.isCollapsed(i)) ! tree.expandRow(i); ! } ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.interfaces.NodeModelListener#nodeUpdatedEvent(net.sf.magicmap.client.model.Node, int, java.lang.Object) ! */ ! public void nodeUpdatedEvent(Node node, int type, Object data){ ! if (type == NodeModel.UPDATE_LABELCHANGED || type == NodeModel.UPDATE_FIXSTATE){ ! OutlineNode on = findOutlineNode(node); ! if (on != null){ ! treemodel.reload(on); ! } else{ ! System.out.println("Node not found in tree view: " + node); ! } ! } else if (type == NodeModel.UPDATE_CLEAR){ ! this.nodeAccessPoints.removeAllChildren(); ! this.nodeClients.removeAllChildren(); ! this.nodeLocations.removeAllChildren(); ! treemodel.reload(); ! } ! } ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.interfaces.NodeModelListener#nodeRemovedEvent(net.sf.magicmap.client.model.Node) ! */ ! public void nodeRemovedEvent(Node node){ ! OutlineNode on = findOutlineNode(node); ! if (on != null){ ! treemodel.removeNodeFromParent(on); ! } ! } ! ! private int getAlphabeticalIndex(OutlineNode parent,OutlineNode node){ ! int index=0; ! while((parent.getChildCount() > index) && (node.getNode().getDisplayName().compareToIgnoreCase(((OutlineNode)(parent.getChildAt(index))).getNode().getDisplayName()) > 0)){ ! ++index; ! } ! return index; ! } ! public void setSelected(Node node){ ! setSelected(getOutlineNodePath(node)); ! } ! ! private void setSelected(TreePath outlineNodePath) { ! tree.setSelectionPath(outlineNodePath); ! } ! public void clearSelection(){ ! tree.clearSelection(); ! } ! public void valueChanged(TreeSelectionEvent e) { ! if(!((OutlineNode)e.getPath().getLastPathComponent()).getAllowsChildren()){ ! Node node = ((OutlineNode)e.getPath().getLastPathComponent()).getNode(); ! Controller.getInstance().getMapView().getPACWGraphDraw().setSelected(Controller.getInstance().getMapView().findVertex(node)); ! } else { ! Controller.getInstance().getMapView().getPACWGraphDraw().setSelected(null); } } - - - } \ No newline at end of file --- 36,444 ---- /** ! * View for the outline (left side list view of the application) ! * ! * @author thuebner */ ! public class OutlineView extends View implements NodeModelListener, TreeSelectionListener { + /** + * serial version id + */ + private static final long serialVersionUID = 5695610129194636842L; + + private NodeModel model; + private JTree tree; + private DefaultTreeModel treemodel; + private DefaultMutableTreeNode treeroot; + + /** + * The outline nodes + */ + private OutlineNode nodeMaps; + private OutlineNode nodeAccessPoints; + private OutlineNode nodeClients; + private OutlineNode nodeLocations; + + + /** + * Constructor + */ + public OutlineView() { + super(); + this.setFrameIcon(GUIBuilder.getToolIcon(GUIConstants.ICON_OUTLINE)); + } ! ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.views.View#buildViewComponent() ! */ ! protected JComponent buildViewComponent(){ ! RelativeLayout layout = new RelativeLayout(); ! RelativePanelBuilder builder = new RelativePanelBuilder(layout); ! treeroot = new OutlineNode("ROOT"); ! treemodel = new DefaultTreeModel(treeroot); ! nodeMaps = new OutlineNode(GUIUtils.i18n("outline_maps")); ! nodeAccessPoints = new OutlineNode(GUIUtils.i18n("accesspoints")); ! nodeClients = new OutlineNode(GUIUtils.i18n("clients")); ! nodeLocations = new OutlineNode(GUIUtils.i18n("locations")); ! ! treeroot.add(nodeMaps); ! treeroot.add(nodeAccessPoints); ! treeroot.add(nodeClients); ! treeroot.add(nodeLocations); ! tree = new JTree(treemodel); ! tree.setRootVisible(false); ! tree.setCellRenderer(new OutlineRenderer()); ! tree.setBorder(new EmptyBorder(new Insets(3, 3, 3, 3))); ! tree.addTreeSelectionListener(this); ! JComponent pane = new JScrollPane(tree,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); ! pane.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0))); ! builder.add(pane, "tree"); ! builder.setTopTopDistance("tree", null, 0); ! builder.setBottomBottomDistance("tree", null, 0); ! builder.setLeftLeftDistance("tree", null, 0); ! builder.setRightRightDistance("tree", null, 0); ! JPanel panel = builder.getPanel(); ! panel.setMinimumSize(new Dimension(200, -1)); ! panel.setMaximumSize(new Dimension(-1,-1)); ! return panel; ! } ! ! /** ! * Clear the selection of the JTree ! */ ! public void clearSelection(){ ! tree.clearSelection(); ! } ! ! ! /** ! * Getter for node model ! * @return the node model ! */ ! public NodeModel getModel(){ ! return model; ! } ! /* (non-Javadoc) ! * @see java.awt.Component#getName() ! */ ! public String getName(){ ! return GUIUtils.i18n("outline", false); ! } ! ! ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.interfaces.NodeModelListener#nodeAddedEvent(net.sf.magicmap.client.model.Node) ! */ ! public void nodeAddedEvent(Node node){ ! ! OutlineNode on = new OutlineNode(node); ! on.setAllowsChildren(false); ! int index = 0; ! ! switch (node.getType()) { ! case NodeModel.NODETYPE_MAP: ! index = getAlphabeticalIndex(nodeMaps, on); ! treemodel.insertNodeInto(on, nodeMaps, index); ! break; ! case NodeModel.NODETYPE_ACCESSPOINT : ! index = getAlphabeticalIndex(nodeAccessPoints,on); ! treemodel.insertNodeInto(on,nodeAccessPoints,index); ! break; ! case NodeModel.NODETYPE_CLIENT : ! index = getAlphabeticalIndex(nodeClients,on); ! treemodel.insertNodeInto(on,nodeClients,index); ! break; ! case NodeModel.NODETYPE_LOCATION : ! index = getAlphabeticalIndex(nodeLocations,on); ! treemodel.insertNodeInto(on,nodeLocations,index); ! break; ! } ! ! for (int i=0; i<tree.getRowCount(); i++) { ! if(tree.isShowing()&& tree.isCollapsed(i)) { ! tree.expandRow(i); ! } ! } ! } ! ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.interfaces.NodeModelListener#nodeRemovedEvent(net.sf.magicmap.client.model.Node) ! */ ! public void nodeRemovedEvent(Node node) { ! ! OutlineNode on = findOutlineNode(node); ! ! if (on != null) { ! treemodel.removeNodeFromParent(on); ! } ! } ! ! /* (non-Javadoc) ! * @see net.sf.magicmap.client.interfaces.NodeModelListener#nodeUpdatedEvent(net.sf.magicmap.client.model.Node, int, java.lang.Object) ! */ ! public void nodeUpdatedEvent(Node node, int type, Object data) { ! ! if (type == NodeModel.UPDATE_LABELCHANGED || type == NodeModel.UPDATE_FIXSTATE) { ! OutlineNode on = findOutlineNode(node); ! ! if (on != null){ ! treemodel.reload(on); ! } else{ ! System.out.println("Node not found in tree view: " + node); ! } ! } else if (type == NodeModel.UPDATE_CLEAR) { ! // this.nodeMaps.removeAllChildren(); ! this.nodeAccessPoints.removeAllChildren(); ! this.nodeClients.removeAllChildren(); ! this.nodeLocations.removeAllChildren(); ! treemodel.reload(); ! } ! } ! /** ! * Setter for node model ! * @param model - the node model ! */ ! public void setModel(NodeModel model){ ! this.model = model; ! } ! ! public void setSelected(Node node) { ! setSelected(getOutlineNodePath(node)); ! } ! ! /* (non-Javadoc) ! * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent) ! */ ! public void valueChanged(TreeSelectionEvent e) { ! if(!((OutlineNode)e.getPath().getLastPathComponent()).getAllowsChildren()) { ! Node node = ((OutlineNode)e.getPath().getLastPathComponent()).getNode(); ! if (node instanceof MapNode) { ! if (((MapNode)node).getMapInfo() != null) { ! Controller.getInstance().setCurrentMap(((MapNode)node).getMapInfo()); ! } ! } else { ! Controller.getInstance().getMapView().getPACWGraphDraw().setSelected(Controller.getInstance().getMapView().findVertex(node)); ! } ! } else { ! Controller.getInstance().getMapView().getPACWGraphDraw().setSelected(null); ! } ! } ! ! ! /* ! * # private methods ############################################ ! */ ! /** ! * Find OutlineNode for given Node and root OutlineNode ! * @param root - the root OutlineNode ! * @param node - the Node to find ! * @return the OutlineNode if exists, else null ! */ ! private OutlineNode findOutlineNode(OutlineNode root, Node node) { ! int size = root.getChildCount(); ! for (int i = 0; i < size; i++) { ! OutlineNode on = (OutlineNode) root.getChildAt(i); ! if (on.getNode() == node){ ! return on; ! } ! } ! return null; ! } ! ! ! /** ! * Find OutlineNode for given Node ! * @param node - the Node to find ! * @return the OutlineNode if exists, else null ! */ ! private OutlineNode findOutlineNode(Node node){ ! switch (node.getType()) { ! case NodeModel.NODETYPE_MAP: ! return findOutlineNode(nodeMaps, node); ! case NodeModel.NODETYPE_ACCESSPOINT : ! return findOutlineNode(nodeAccessPoints, node); ! case NodeModel.NODETYPE_CLIENT : ! return findOutlineNode(nodeClients, node); ! case NodeModel.NODETYPE_LOCATION : ! return findOutlineNode(nodeLocations, node); ! default : ! return null; ! } ! } ! ! ! /** ! * Get the alphabetical index for given OutlineNode in its parent ! * @param parent - the parent OutlineNode ! * @param node - the OutlineNode to find out the index ! * @return the index of node in parent ! */ ! private int getAlphabeticalIndex(OutlineNode parent, OutlineNode node) { ! int index=0; ! while((parent.getChildCount() > index) && (node.getNode().getDisplayName().compareToIgnoreCase(((OutlineNode)(parent.getChildAt(index))).getNode().getDisplayName()) > 0)) { ! ++index; ! } ! return index; ! } ! ! ! /** ! * Get the TreePath of a Node for a given root OutlineNode ! * @param root - the root OutlineNode ! * @param node - the Node to get the TreePath of ! * @return the path of node in root if exists, else null ! */ ! private TreePath getOutlineNodePath(OutlineNode root, Node node) { ! int size = root.getChildCount(); ! for (int i = 0; i < size; i++){ ! OutlineNode on = (OutlineNode) root.getChildAt(i); ! if (on.getNode() == node){ ! return new TreePath((Object[])on.getPath()); ! } ! } ! return null; ! } ! ! /** ! * Get the TreePath of a Node ! * @param node - the Node to get the TreePath of ! * @return the path of the node if exists, else null ! */ ! private TreePath getOutlineNodePath(Node node) { ! switch (node.getType()) { ! case NodeModel.NODETYPE_MAP : ! return getOutlineNodePath(nodeMaps, node); ! case NodeModel.NODETYPE_ACCESSPOINT : ! return getOutlineNodePath(nodeAccessPoints, node); ! case NodeModel.NODETYPE_CLIENT : ! return getOutlineNodePath(nodeClients, node); ! case NodeModel.NODETYPE_LOCATION : ! return getOutlineNodePath(nodeLocations, node); ! default : ! return null; ! } ! } ! ! /** ! * Sets the selection on a given TreePath ! * @param outlineNodePath - the TreePath to set the selection on ! */ ! private void setSelected(TreePath outlineNodePath) { ! tree.setSelectionPath(outlineNodePath); ! } ! ! ! /* ! * # private inner classes ####################################### ! */ ! /** ! * Erweiterter Knoten für einen Baum. Es wird Knoten aus dem NodeModel ! * von PACW aufgenommen. ! * @author thuebner ! */ ! private class OutlineNode extends DefaultMutableTreeNode { ! /** ! * serial version id ! */ ! private static final long serialVersionUID = 8604452363363204008L; ! ! /** ! * the outline node ! */ ! private Node node; ! /** ! * Konstruktor für Überschriften ! * @param title ! */ ! public OutlineNode(String title) { ! super(title); ! node = null; ! } ! /** ! * Konstruktur für Knoten aus dem NodeModel ! * @param node ! */ ! public OutlineNode(Node node) { ! this.node = node; ! } ! /** ! * Getter for the node ! * @return ! */ ! public Node getNode(){ ! return this.node; ! } ! } ! ! /** ! * Private class for the outline rendering ! * ! * @author (vermutlich) thuebner ! * @author Johannes Zapotoczky (joh...@za...) ! */ ! private class OutlineRenderer extends DefaultTreeCellRenderer { + /** + * serial version id + */ + private static final long serialVersionUID = 1516105045685167210L; ! /* (non-Javadoc) ! * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) ! */ ! public Component getTreeCellRendererComponent(JTree tree, ! Object value, boolean selected, boolean expanded, ! boolean leaf, int row, boolean hasFocus) { ! ! Node node = ((OutlineNode) value).getNode(); ! JLabel c; ! if (node == null) { ! c = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, false, row, hasFocus); ! // Dafür sorgen, dass Folder-Icons angezeigt werden, auch wenn keine Unterelemente ! if (!expanded) { ! c.setIcon(this.getDefaultClosedIcon()); ! } else{ ! c.setIcon(this.getDefaultOpenIcon()); ! } ! } else{ ! c = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); ! c.setText(node.getDisplayName()); ! Icon icon = Controller.getInstance().getMapView().getIconForNode(node); ! if (icon == null) icon = this.getDefaultLeafIcon(); ! c.setIcon(icon); ! } ! c.setPreferredSize(new Dimension(300, -1)); ! return c; ! } } } Index: MapView.java =================================================================== RCS file: /cvsroot/magicmap/magicmapclient/src/net/sf/magicmap/client/views/MapView.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MapView.java 12 Oct 2005 21:44:17 -0000 1.14 --- MapView.java 20 Feb 2006 08:49:58 -0000 1.15 *************** *** 69,73 **** public class MapView extends View implements VertexListener, NodeModelListener { ! private static final String NODE_KEY = "NODE"; private Icon clientIcon; --- 69,78 ---- public class MapView extends View implements VertexListener, NodeModelListener { ! /** ! * serial version id ! */ ! private static final long serialVersionUID = 6813465565034050923L; ! ! private static final String NODE_KEY = "NODE"; private Icon clientIcon; |