package com.ericsson.tic.vi; import javax.swing.JPanel; import javax.swing.JButton; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelListener; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseWheelEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JPopupMenu; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenuItem; import javax.swing.JMenu; import javax.swing.JSplitPane; import java.util.ListIterator; import javax.media.opengl.GLJPanel; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileFilter; import javax.swing.JFileChooser; import java.io.File; import java.util.LinkedList; // import javax.media.opengl.GLCanvas; // import com.sun.opengl.util.FPSAnimator; // import com.sun.opengl.util.Animator; /** * The view Panel is the most important GUI component. It creates an OpenGL * Canvas (or GLJPanel) and keeps track of view specific variables. * * @author Sami Matilainen * @version 1.0 (2008-12-03) */ public class ViewPanel extends JPanel implements MouseMotionListener, MouseWheelListener, MouseListener, ActionListener, KeyListener { /** The actual panel holding the OpenGL canvas. */ public GLJPanel canvas; /** The animator calls the canvas for graphics updates. */ public Animator animator; /** The eventlistener which listens to calls from the OpenGL engine. */ public Renderer renderer; /** The unique identifier for this view. */ public int id; /** The camera associated with this view. */ public Camera camera; /** A button. */ public JButton viewModeButton, texturesOnButton; /** The split view which is the gui parent of this ViewPanel. */ public SplitViewPanel splitParent; /** If true, the view is in a transitional state moving from one form to another. */ public boolean transitionStateOn; /** If true, the globe view is phasing in. */ public boolean globePhasingIn; /** If true, the globe view is phasing out. */ public boolean globePhasingOut; /** If true, the plane view is phasing in. */ public boolean planePhasingIn; /** If true, the plane view is phasing out.*/ public boolean planePhasingOut; /** If true, the nodes are moving to their targets in the plane view. */ public boolean nodesMovingToPlaneTarget; /** If true, the nodes are moving to their targets in the globe view. */ public boolean nodesMovingToGlobeTarget; /** If true, the globe view is currently on. */ public boolean globeViewOn; /** If true, the plane view is currently on. */ public boolean planeViewOn; /** If true, the nodes are set to visible. */ public boolean graphNodesOn; /** If true, the relations are set to visible. */ public boolean graphRelationsOn; /** If true, the bars are set to visible. */ public boolean barsOn; /** If true, the user has clicked the view and we have entered picking mode. */ public boolean picking; /** If true, brushing Markers will be drawn. */ public boolean brushingMarkersOn; /** If true, the textures will be drawn. */ public boolean texturesOn; /** determines which data set to use for nodes. */ public int nodeData; /** determines which data sets to use for bars. */ public int[] barData; /** determines which data sets to use for histograms. */ public int[] histData; /** determines which data set to use for relationships. */ public int relData; /** True if the view titles are turned on. */ public boolean viewTitleOn; /** Not used. */ public boolean[] nodeOfLevelOn; /** Determines which node types are visible. */ public boolean[] nodeOfTypeOn; /** An array of nodes. */ public GraphNode[] nodeArr; /** An array of relations. */ public GraphNodeRel[] nodeRelArr; /** An array of nodes. */ public GraphNode[] nodeArrFull; /** An array of relations. */ public GraphNodeRel[] nodeRelArrFull; /** An array of nodes. This is a subset of the full topology. */ public GraphNode[] nodeArrSubset; /** An array of relations. This is a subset of the full topology. */ public GraphNodeRel[] nodeRelArrSubset; /** A pop-up menu. */ private JPopupMenu popupMenu; /** A menu. */ private JMenu subMenuType, subMenuLevel, subMenuSubset; /** A menu item. */ private JMenuItem menuItem; /** A menu item. */ private JCheckBoxMenuItem cbMenuItem; /** A menu item. */ public JMenuItem closeMenuItem; /** A file chooser dialogue. */ private JFileChooser fileChooser; /** If true, rendering is limited. */ public boolean limitRendering; /** If true, labels are rendererd. */ public boolean labelsOn; /** If true, the subset is active. */ public boolean subsetOn; /** If true the subset is empty. */ public boolean subsetEmpty; /** Keeps track of the selected index in a combobox. */ public int nodeSelectedIndex, relSelectedIndex; /** Keeps track of the selected index in a combobox. */ public int[] barsSelectedIndex, histSelectedIndex; /** If true, the default colors are used for the nodes. */ public boolean defaultNodeColorsOn; /** If true, nodes will be shaded by their level. */ public boolean levelNodeShadingOn; /** * Creates a View Panel. * * @param id the id of this view. * @param splitParent the parent SplitViewPanel of this view. */ public ViewPanel(int id, SplitViewPanel splitParent) { this.splitParent = splitParent; this.nodeArrFull = VI.cloneNodeArr(); this.nodeRelArrFull = VI.cloneNodeRelArr(this.nodeArrFull); this.nodeArr = this.nodeArrFull; this.nodeRelArr = this.nodeRelArrFull; this.nodeArrSubset = this.nodeArrFull; this.nodeRelArrSubset = this.nodeRelArrFull; this.canvas = new GLJPanel(); this.id = id; this.camera = new Camera(this.id, this); transitionStateOn = false; globePhasingIn = false; globePhasingOut = false; planePhasingIn = false; planePhasingOut = false; nodesMovingToPlaneTarget = false; nodesMovingToGlobeTarget = false; globeViewOn = false; planeViewOn = true; graphNodesOn = true; graphRelationsOn = true; barsOn = true; picking = false; texturesOn = true; brushingMarkersOn = true; viewTitleOn = true; labelsOn = true; defaultNodeColorsOn = true; levelNodeShadingOn = false; limitRendering = false; subsetOn = false; subsetEmpty = true; nodeOfTypeOn = new boolean[VI.nodeTypeArr.length-1]; for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { nodeOfTypeOn[i] = true; } //System.out.println("nodeData " + VI.nodeSingularData[0].id); initComboBoxIndexes(); nodeData = VI.nodeSingularData[nodeSelectedIndex].id; relData = VI.relsData[relSelectedIndex].id; barData = new int[VI.nodeTypeArr.length-1]; histData = new int[VI.nodeTypeArr.length-1]; for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { barData[i] = VI.nodeMultiData[barsSelectedIndex[i]].id; histData[i] = VI.nodeMultiData[histSelectedIndex[i]].id; } this.renderer = new Renderer(this.id, this.camera, this); this.setLayout(new BorderLayout()); this.add(canvas, BorderLayout.CENTER); this.setPreferredSize(new Dimension(3000,3000)); this.setMaximumSize(new Dimension(3000,3000)); this.setMinimumSize(new Dimension(100,100)); canvas.addGLEventListener(renderer); canvas.addMouseMotionListener(this); canvas.addMouseWheelListener(this); canvas.addMouseListener(this); //animator = new FPSAnimator(canvas, VI.viewRefreshRate, false); animator = new Animator(canvas); fileChooser = new JFileChooser(); VI.viewList.add(this); popupMenu = new JPopupMenu(); subMenuType = new JMenu("Show Nodes by type:"); subMenuLevel = new JMenu("Show Nodes by Level:"); subMenuSubset = new JMenu("Manage Subsets:"); menuItem = new JMenuItem("Change View"); menuItem.setEnabled(true); menuItem.addActionListener(this); menuItem.setActionCommand("change view"); popupMenu.add(menuItem); popupMenu.addSeparator(); menuItem = new JMenuItem("Save Configuration..."); menuItem.addActionListener(this); menuItem.setActionCommand("save"); popupMenu.add(menuItem); menuItem = new JMenuItem("Load Configuration..."); menuItem.addActionListener(this); menuItem.setActionCommand("load"); popupMenu.add(menuItem); popupMenu.addSeparator(); popupMenu.add(subMenuSubset); popupMenu.addSeparator(); menuItem = new JMenuItem("Split Vertical"); menuItem.addActionListener(this); menuItem.setActionCommand("split vertical"); popupMenu.add(menuItem); menuItem = new JMenuItem("Split Horizontal"); menuItem.addActionListener(this); menuItem.setActionCommand("split horizontal"); popupMenu.add(menuItem); closeMenuItem = new JMenuItem("Close View"); closeMenuItem.setEnabled(false); closeMenuItem.addActionListener(this); closeMenuItem.setActionCommand("close view"); popupMenu.add(closeMenuItem); popupMenu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("Limit Rendering"); cbMenuItem.setState(limitRendering); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("limit render"); popupMenu.add(cbMenuItem); popupMenu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("Show Nodes"); cbMenuItem.setState(graphNodesOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show nodes"); popupMenu.add(cbMenuItem); popupMenu.add(subMenuType); //popupMenu.add(subMenuLevel); popupMenu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("Use Default Node Colors"); cbMenuItem.setState(defaultNodeColorsOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("default node colors"); popupMenu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Shade Nodes by Level"); cbMenuItem.setState(levelNodeShadingOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("level shading"); popupMenu.add(cbMenuItem); popupMenu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("Show Links"); cbMenuItem.setState(graphRelationsOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show links"); popupMenu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Show Bars"); cbMenuItem.setState(barsOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show bars"); popupMenu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Show Brushing Markers"); cbMenuItem.setState(brushingMarkersOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show brushing markers"); popupMenu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Show Textures"); cbMenuItem.setState(texturesOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show textures"); popupMenu.add(cbMenuItem); popupMenu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("Show Title"); cbMenuItem.setState(viewTitleOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show title"); popupMenu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Show Labels"); cbMenuItem.setState(true); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show labels"); popupMenu.add(cbMenuItem); /* cbMenuItem = new JCheckBoxMenuItem("Show Text Labels (not implemented)"); cbMenuItem.setState(true); cbMenuItem.setEnabled(false); popupMenu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Show Legend (not implemented)"); cbMenuItem.setState(true); cbMenuItem.setEnabled(false); popupMenu.add(cbMenuItem); */ /* popupMenu.addSeparator(); menuItem = new JMenuItem("View settings... (not implemented)"); menuItem.setEnabled(false); menuItem.addActionListener(this); menuItem.setActionCommand("view settings..."); popupMenu.add(menuItem); */ // type sub menu for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { cbMenuItem = new JCheckBoxMenuItem(VI.nodeTypeArr[i+1].name); cbMenuItem.setState(nodeOfTypeOn[i]); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show type " + VI.nodeTypeArr[i+1].name); subMenuType.add(cbMenuItem); } // level sub menu /* cbMenuItem = new JCheckBoxMenuItem("TEST2"); cbMenuItem.setState(barsOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show bars"); subMenuLevel.add(cbMenuItem); */ // subset sub menu menuItem = new JMenuItem("Create Subset From Selected Nodes"); menuItem.addActionListener(this); menuItem.setActionCommand("create subset"); subMenuSubset.add(menuItem); cbMenuItem = new JCheckBoxMenuItem("Show Only the Subset"); cbMenuItem.setState(subsetOn); cbMenuItem.setEnabled(true); cbMenuItem.addActionListener(this); cbMenuItem.setActionCommand("show subset"); subMenuSubset.add(cbMenuItem); WorldTimer wtimer = new WorldTimer(renderer, camera, this); AnimatorTimer atimer = new AnimatorTimer(animator); //animator = new AnimatorWorkaround(renderer, canvas); //animator.setRunAsFastAsPossible(true); //animator.start(); // start OpenGL rendering engine this.addKeyListener(this); this.setFocusable(true); } /** * Initializes the combo box indexes. Used for the GUI. */ public void initComboBoxIndexes() { this.nodeSelectedIndex = 0; this.relSelectedIndex = 0; this.barsSelectedIndex = new int[VI.nodeTypeArr.length-1]; this.histSelectedIndex = new int[VI.nodeTypeArr.length-1]; for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { this.barsSelectedIndex[i] = VI.nodeMultiData.length-1; //view.barData[i]; this.histSelectedIndex[i] = VI.nodeMultiData.length-1; //view.histData[i]; } for (int i = 0; i < VI.nodeSingularData.length; i++) { if (VI.nodeSingularData[i].id == this.nodeData-1) { this.nodeSelectedIndex = i; } } for (int i = 0; i < VI.relsData.length; i++) { if (VI.relsData[i].id == this.relData-1) { this.relSelectedIndex = i; } } for (int i = 0; i < VI.nodeMultiData.length; i++) { if (VI.nodeMultiData[i].nodeType.id != 0) { barsSelectedIndex[VI.nodeMultiData[i].nodeType.id-1] = i; histSelectedIndex[VI.nodeMultiData[i].nodeType.id-1] = i; } } } /** * Updates the targets of all nodes. */ public void updateNodeTargets() { if (this.nodesMovingToGlobeTarget) { for (int i = 0; i < this.nodeArr.length; i++) { this.nodeArr[i].setTargetOnGlobe(); } for (int i = 0; i < this.nodeRelArr.length; i++) { this.nodeRelArr[i].setTargetsOnGlobeCurved(); } } else if (this.nodesMovingToPlaneTarget) { for (int i = 0; i < this.nodeArr.length; i++) { this.nodeArr[i].setTargetOnPlane(); } for (int i = 0; i < this.nodeRelArr.length; i++) { this.nodeRelArr[i].setTargetsOnPlane(); } } } /** * Updates the targets of all labels. */ public void updateLabelTargets() { if (this.nodesMovingToGlobeTarget) { for (int i = 0; i < this.nodeArr.length; i++) { this.nodeArr[i].label.setTargetOnGlobe(); } } else if (this.nodesMovingToPlaneTarget) { for (int i = 0; i < this.nodeArr.length; i++) { this.nodeArr[i].label.setTargetOnPlane(); } } } /** * Renew the ID of this view. */ public void renewID() { id = VI.requestViewID(); } /** * Called when the mouse is dragged. * Calls the appropriate function in the camera. * * @param e The MouseEvent that was triggered. */ public void mouseDragged(MouseEvent e) { camera.mDragged(e.getX(), e.getY()); } /** * Called when the mouse is pressed. * Calls the appropriate function in the camera. * * @param e The MouseEvent that was triggered. */ public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) { popupMenu.show(e.getComponent(), e.getX()+5, e.getY()+5); } else { camera.mPressed(e.getX(), e.getY()); } } /** * Called when the mouse is released. * Calls the appropriate function in the camera. * * @param e The MouseEvent that was triggered. */ public void mouseReleased(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) { //popupMenu.setVisible(false); } else { camera.mReleased(); } } /** * Called when the mousewheel is scrolled. * Calls the appropriate function in the camera. * * @param e The MouseEvent that was triggered. */ public void mouseWheelMoved(MouseWheelEvent e) { camera.mWheelMoved(0 - e.getWheelRotation()); } /** * Called when a MouseEvent is triggered. * * @param e The MouseEvent which triggered the event. */ public void mouseClicked(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) { popupMenu.show(e.getComponent(), e.getX()+5, e.getY()+5); } else { picking = true; } this.requestFocusInWindow(); } /** * Called when a MouseEvent is triggered. * * @param e The MouseEvent which triggered the event. */ public void mouseMoved(MouseEvent e) { // do nothing } /** * Called when a MouseEvent is triggered. * * @param e The MouseEvent which triggered the event. */ public void mouseExited(MouseEvent e) { // do nothing } /** * Called when a MouseEvent is triggered. * * @param e The MouseEvent which triggered the event. */ public void mouseEntered(MouseEvent e) { // do nothing } /** * Called when a keyboard key is pressed. * * @param e The KeyEvent which was triggered. */ public void keyPressed(KeyEvent e) { float xMove = 0; float yMove = 0; if (e.getKeyCode() == KeyEvent.VK_SHIFT) { VI.shiftPressed = true; } else if (e.getKeyCode() == KeyEvent.VK_M) { VI.mPressed = true; } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { if (VI.shiftPressed) { xMove = -0.02f; } else { camera.speedX = -8; } } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { if (VI.shiftPressed) { xMove = 0.02f; } else { camera.speedX = 8; } } else if (e.getKeyCode() == KeyEvent.VK_UP) { if (VI.shiftPressed) { yMove = 0.02f; } else { camera.speedY = -8; } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (VI.shiftPressed) { yMove = -0.02f; } else { camera.speedY = 8; } } else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) { camera.mWheelMoved(1); } else if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) { camera.mWheelMoved(-1); } else if (e.getKeyCode() == KeyEvent.VK_Q) { camera.tilt(1.0f); } else if (e.getKeyCode() == KeyEvent.VK_A) { camera.tilt(-1.0f); } if (VI.shiftPressed) { for (int i = 0; i < nodeArr.length; i++) { if (nodeArr[i].label.highlighted) { if (planeViewOn) { nodeArr[i].label.xPlane = nodeArr[i].label.xPlane + xMove; nodeArr[i].label.yPlane = nodeArr[i].label.yPlane + yMove; nodeArr[i].label.setTargetOnPlane(); } else { nodeArr[i].label.yGlobe = nodeArr[i].label.yGlobe + yMove; nodeArr[i].label.xGlobe = nodeArr[i].label.xGlobe + xMove * (float)Math.cos(camera.rotAngle); nodeArr[i].label.zGlobe = nodeArr[i].label.zGlobe + xMove * (float)Math.sin(camera.rotAngle); nodeArr[i].label.setTargetOnGlobe(); } } } } } /** * Called when a keyboard key is released. * * @param e The KeyEvent which was triggered. */ public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SHIFT) { VI.shiftPressed = false; } else if (e.getKeyCode() == KeyEvent.VK_M) { VI.mPressed = false; } } /** * Called when a keyboard key is typed. * * @param e The KeyEvent which was triggered. */ public void keyTyped(KeyEvent e) { if (e.getKeyChar() == 'p') { VI.printServerMessages = !VI.printServerMessages; } else if (e.getKeyChar() == 'f') { VI.infiniteMoveDelayOn = !VI.infiniteMoveDelayOn; VI.tiltMoveDelayOn = !VI.tiltMoveDelayOn; VI.panMoveDelayOn = !VI.panMoveDelayOn; } else if (e.getKeyChar() == 'j') { VI.infiniteMoveDelayOn = !VI.infiniteMoveDelayOn; } else if (e.getKeyChar() == '0') { VI.barType = 0; } else if (e.getKeyChar() == '1') { VI.barType = 1; } else if (e.getKeyChar() == '2') { VI.barType = 2; } else if (e.getKeyChar() == '3') { VI.barType = 3; } else if (e.getKeyChar() == '4') { VI.barType = 4; } else if (e.getKeyChar() == '5') { VI.barType = 5; } else if (e.getKeyChar() == '6') { VI.barType = 6; } else if (e.getKeyChar() == '7') { VI.barType = 7; } else if (e.getKeyChar() == '8') { VI.barType = 8; } else if (e.getKeyChar() == '9') { VI.barType = 9; } } /** * Called when an ActionEvent is triggered. * * @param e The ActionEvent which triggered the event. */ public void actionPerformed(ActionEvent e) { if ("change view".equals(e.getActionCommand())) { if (transitionStateOn) { // do nothing } else { transitionStateOn = true; if (globeViewOn) { globePhasingOut = true; } else if (planeViewOn) { planePhasingOut = true; } globeViewOn = false; planeViewOn = false; } } else if ("split vertical".equals(e.getActionCommand())) { splitParent.splitVertical(); } else if ("split horizontal".equals(e.getActionCommand())) { splitParent.splitHorizontal(); } else if ("close view".equals(e.getActionCommand())) { splitParent.closeView(); } else if ("limit render".equals(e.getActionCommand())) { limitRendering = !limitRendering; } else if ("show nodes".equals(e.getActionCommand())) { graphNodesOn = !graphNodesOn; } else if ("default node colors".equals(e.getActionCommand())) { defaultNodeColorsOn = !defaultNodeColorsOn; } else if ("level shading".equals(e.getActionCommand())) { levelNodeShadingOn = !levelNodeShadingOn; } else if ("show links".equals(e.getActionCommand())) { graphRelationsOn = !graphRelationsOn; } else if ("show bars".equals(e.getActionCommand())) { barsOn = !barsOn; } else if ("show brushing markers".equals(e.getActionCommand())) { brushingMarkersOn = !brushingMarkersOn; } else if ("show textures".equals(e.getActionCommand())) { texturesOn = !texturesOn; } else if ("show labels".equals(e.getActionCommand())) { labelsOn = !labelsOn; } else if ("show title".equals(e.getActionCommand())) { viewTitleOn = !viewTitleOn; } else if ("save".equals(e.getActionCommand())) { int returnVal = fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); VI.writeSave(file, this); } } else if ("load".equals(e.getActionCommand())) { FileFilter filter = new FileNameExtensionFilter("View Configuration files", "vi"); fileChooser.addChoosableFileFilter(filter); int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); VI.readSave(file, this); } } else if ("create subset".equals(e.getActionCommand())) { createSubset(); } else if ("show subset".equals(e.getActionCommand())) { subsetOn = !subsetOn; if (subsetOn) { this.nodeArr = this.nodeArrSubset; this.nodeRelArr = this.nodeRelArrSubset; } else { this.nodeArr = this.nodeArrFull; this.nodeRelArr = this.nodeRelArrFull; } } for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { String ps = "show type " + VI.nodeTypeArr[i+1].name; if (ps.equals(e.getActionCommand())) { nodeOfTypeOn[i] = !nodeOfTypeOn[i]; } } } /** * Creates a subset of the selected nodes. */ private void createSubset() { LinkedList nodeList = new LinkedList(); for (int i = 0; i < nodeArr.length; i++) { if (nodeArr[i].highlighted) { nodeList.add(nodeArr[i]); } } if (nodeList.size() > 0) { nodeArrSubset = nodeList.toArray(new GraphNode[0]); subsetEmpty = false; LinkedList relList = new LinkedList(); for (int i = 0; i < nodeRelArrFull.length; i++) { for (int j = 0; j < nodeArrSubset.length; j++) { if (nodeArrSubset[j].id == nodeRelArrFull[i].a.id) { for (int k = 0; k < nodeArrSubset.length; k++) { if (nodeArrSubset[k].id == nodeRelArrFull[i].b.id) { relList.add(nodeRelArrFull[i]); } } } } } nodeRelArrSubset = relList.toArray(new GraphNodeRel[0]); } else { subsetEmpty = true; } } /** * Creates a subset from the array specified in a save file. */ public void createSubset(int[] save) { nodeArrSubset = new GraphNode[save.length]; for (int i = 0; i < save.length; i++) { for (int j = 0; j < nodeArr.length; j++) { if (save[i] == nodeArr[j].id) { nodeArrSubset[i] = nodeArr[j]; } } } if (save.length > 0) { subsetEmpty = false; LinkedList relList = new LinkedList(); for (int i = 0; i < nodeRelArrFull.length; i++) { for (int j = 0; j < nodeArrSubset.length; j++) { if (nodeArrSubset[j].id == nodeRelArrFull[i].a.id) { for (int k = 0; k < nodeArrSubset.length; k++) { if (nodeArrSubset[k].id == nodeRelArrFull[i].b.id) { relList.add(nodeRelArrFull[i]); } } } } } nodeRelArrSubset = relList.toArray(new GraphNodeRel[0]); } else { subsetEmpty = true; } } }