/** @return an image of the track (without its handle) */ public BufferedImage getImage() { BufferedImage image = new BufferedImage( graphicsPanel.getWidth(), graphicsPanel.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = image.createGraphics(); graphicsPanel.paint(g); return image; }
/** Create a solver instance and configures it with initial and goal state. */ private void constructPuzzleSolver() { pSolver = null; // this is the call to the actual implementation of PuzzleSolver if ("DFS".equals(solver)) pSolver = new DFSSolver(); if ("BFS".equals(solver)) pSolver = new BFSSolver(); if ("ASTAR".equals(solver)) pSolver = new AStarSolver(); if (null == pSolver) // default case, make sure we have a solver pSolver = new BFSSolver(); pSolver.configure(initalPuzzleGraphics.getPuzzle(), finalPuzzleGraphics.getPuzzle()); }
/** Updates the cursor displayed on the graphic panel */ public void updateGraphicCursor() { if (foregroundLayer.isCursorOverLegend()) { graphicsPanel.setCursor(TrackConstants.CURSOR_OVER_LEGEND); } else if ((activeLayer instanceof GeneLayer) && (((GeneLayer) activeLayer).getGeneUnderMouse() != null)) { graphicsPanel.setCursor(TrackConstants.CURSOR_OVER_GENE); } else { graphicsPanel.setCursor(TrackConstants.DEFAULT_CURSOR); } }
/** * Updates the list of drawers registered to the graphics panel. There are one drawer per layer * including the background and foreground layers that need to be registered. */ private void updateGraphicsPanelDrawers() { if (layers == null) { // case where there is no other layer than the foreground and the background Drawer[] drawers = {backgroundLayer, foregroundLayer}; graphicsPanel.setDrawers(drawers); } else { // case where there are other layers Drawer[] drawers = new Drawer[layers.size() + 2]; drawers[0] = backgroundLayer; int i = 1; // we want to draw the layers in reverse order because the first layers // of the list should be on top for (int j = layers.size() - 1; j >= 0; j--) { Drawer currentDrawer = layers.getLayers()[j]; drawers[i] = currentDrawer; i++; } drawers[i] = foregroundLayer; graphicsPanel.setDrawers(drawers); } }
/** * Sets the active layer of the track if the specified layer is one of the layers of the track. * Sets the active layer to null if the specified parameter is null. Does nothing if the specified * layer is not null and is not one of the layers of the track * * @param activeLayer the active layer to set */ public void setActiveLayer(Layer<?> activeLayer) { Layer<?> oldLayer = getActiveLayer(); if (activeLayer == null) { this.activeLayer = null; } else if (layers.contains(activeLayer)) { this.activeLayer = activeLayer; } // update the mouse listeners of the graphics panel if (oldLayer != activeLayer) { if (oldLayer != null) { if (oldLayer instanceof MouseMotionListener) { graphicsPanel.removeMouseMotionListener((MouseMotionListener) oldLayer); } if (oldLayer instanceof MouseListener) { graphicsPanel.removeMouseListener((MouseListener) oldLayer); } if (oldLayer instanceof MouseWheelListener) { graphicsPanel.removeMouseWheelListener((MouseWheelListener) oldLayer); } } if (activeLayer != null) { if (activeLayer instanceof MouseMotionListener) { graphicsPanel.addMouseMotionListener((MouseMotionListener) activeLayer); } if (activeLayer instanceof MouseListener) { graphicsPanel.addMouseListener((MouseListener) activeLayer); } if (activeLayer instanceof MouseWheelListener) { graphicsPanel.addMouseWheelListener((MouseWheelListener) activeLayer); } } } }
/** * Configures the puzzle solver by creating initial and goal states from a list of predefined * puzzles. It also draws the GUI panels after creation of puzzle states * * @param nPuzzle represents the size of the puzzle */ public void setConfiguration(final int nPuzzle) { initalPuzzleGraphics.setConfiguration(nPuzzle, PanelType.INITIALPANEL); intermediatePuzzleGraphics.setConfiguration(nPuzzle, PanelType.INTERMEDIATEPANEL); finalPuzzleGraphics.setConfiguration(nPuzzle, PanelType.GOALPANEL); initalPuzzleGraphics.repaint(); intermediatePuzzleGraphics.repaint(); finalPuzzleGraphics.repaint(); constructPuzzleSolver(); }
@Override public void genomeWindowChanged(GenomeWindowEvent evt) { // repaint the layers if the genome window changed graphicsPanel.repaint(); }
/** * Draws an animation in the middle of the track showing that the track is being loaded * * @param g graphics where to draw the animation */ public void drawLoadingAnimation(Graphics g) { Image image = Images.getLoadingImage(); int x = (graphicsPanel.getWidth() - image.getWidth(null)) / 2; int y = (graphicsPanel.getHeight() - image.getHeight(null)) / 2; g.drawImage(image, x, y, trackPanel); }
/** * update(). Called when a EventType.update has be received. * * @param letter */ public void update(char letter) { guess.setWord(guesser.getDisguisedWord()); graphics.setWrongs(guesser.getMissCount()); }