@Override public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (source == authorMenuItem) { authorFrame.setVisible(true); } else if (source == problemMenuItem) { problemFrame.setVisible(true); } if (source instanceof JRadioButtonMenuItem) { if (ricartAgrawala.isSelected()) vizPanel.setMethod("ricart-agrawala"); else if (modRicartAgrawala.isSelected()) vizPanel.setMethod("modified ricart-agrawala"); else System.out.println("ERROR: Setting method: no recognized method."); } }
private ContainerLocation[] createLocations( Graphics g, steps.array.bucket.Container[] containers) { ContainerLocation[] locs = new ContainerLocation[containers.length]; ArrayList<ArrayList<steps.array.bucket.Container>> table = new ArrayList<ArrayList<steps.array.bucket.Container>>(); table.add(new ArrayList<steps.array.bucket.Container>()); int totalWidth = CONTAINER_SPACING; for (int i = 0; i < containers.length; i++) { totalWidth += getContainerDimensions(g, containers[i]).width + CONTAINER_SPACING; if (totalWidth > _panel.getWidth()) { totalWidth = getContainerDimensions(g, containers[i]).width + 2 * CONTAINER_SPACING; table.add(new ArrayList<steps.array.bucket.Container>()); } table.get(table.size() - 1).add(containers[i]); } int locsIndex = 0; int height = 0; int y = (_panel.getHeight() / 2 - (table.size() * (getContainerDimensions(g, table.get(0).get(0)).height + CONTAINER_HEIGHT_SPACING))) / 2; for (int i = 0; i < table.size(); i++) { int rowWidth = CONTAINER_SPACING; for (int j = 0; j < table.get(i).size(); j++) { Dimension dim = getContainerDimensions(g, table.get(i).get(j)); rowWidth += dim.width + CONTAINER_SPACING; if (dim.height > 0) height = dim.height; } int x = (_panel.getWidth() - rowWidth) / 2; for (int j = 0; j < table.get(i).size(); j++) { if (table.get(i).get(j).theValues.length > 0) { locs[locsIndex] = new ContainerLocation(x, y); x += getContainerDimensions(g, table.get(i).get(j)).width + CONTAINER_SPACING; } locsIndex++; } y += (height + CONTAINER_HEIGHT_SPACING); } return locs; }
private void drawContainers(Graphics g, int index1, int index2) { // calculate dimensions and starting points for drawing steps.array.bucket.Container[] containers = ((Containers) _steps[index1][index2]).getContainers(); int totalWidth = CONTAINER_SPACING; int totalHeight = 0; for (int i = 0; i < containers.length; i++) { totalWidth += getContainerDimensions(g, containers[i]).width + CONTAINER_SPACING; totalHeight = getContainerDimensions(g, containers[i]).height; } int x = (_panel.getWidth() - totalWidth) / 2, y = (_panel.getHeight() / 2 - totalHeight) / 2; // draw the containers g.setColor(Color.black); ContainerLocation[] locs = createLocations(g, containers); for (int i = 0; i < locs.length; i++) { if (containers[i].theValues.length > 0 && locs[i] != null) drawContainer(containers[i], g, locs[i].X, locs[i].Y); } }
@Override public void draw(Graphics g, int index1, int index2) { // draw containers if (hasContainers(index1, index2)) { System.out.println("Has containers"); Image buffer = _panel.createImage(_panel.getWidth() - 6, _panel.getHeight() / 2 - 6); Graphics2D bufferGraphics = (Graphics2D) buffer.getGraphics(); bufferGraphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); bufferGraphics.setColor(Color.white); bufferGraphics.fillRect(0, 0, _panel.getWidth(), _panel.getHeight() / 2); drawContainers(bufferGraphics, index1, index2); BAR_GRAPH.addImage(buffer); } BAR_GRAPH.drawBuckets(true); BAR_GRAPH.draw(g, index1, index2); BAR_GRAPH.addImage(null); }
private void initializeContainer(Container c) { System.out.println("Initializing the Container..."); c.setPreferredSize(MASTER_WINDOW_SIZE); virtualDesktop = new JDesktopPane(); virtualDesktop.setPreferredSize(MASTER_WINDOW_SIZE); algorithmFrame = new JInternalFrame("Algorithm Visualization", true, true, true, true); algorithmFrame.setResizable(false); algorithmFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); vizPanel = new VisualizationPanel(); algorithmFrame.setContentPane(vizPanel); vizPanel.setDisplayedThreads(); algorithmFrame.pack(); virtualDesktop.add(algorithmFrame); initAboutFrames(); c.add(virtualDesktop); algorithmFrame.setVisible(true); }