/** * Arena consturctor. * * @param parent The component where the arena will be displayed in. */ public Arena(Component parent) { super(); this.parent = parent; this.isVisible = false; if (parent == null) { this.isVisible = false; } else { parent.addKeyListener(this); } FrictionBuffer get = frictionBufferCache.get(this.svgFileName); if (get == null) { // if not in cache, create new instance and frictionBuffer = new FrictionBuffer(this); frictionBufferCache.put(this.svgFileName, frictionBuffer); if (DEBUG_FRICTION_CACHE) { System.out.println( "Cached friction buffer not found, I have created new instance and cached it."); } } else { frictionBuffer = get; if (DEBUG_FRICTION_CACHE) { System.out.println("Cached friction buffer found."); } } }
public void setParent(Component parent) { this.parent = parent; this.isVisible = false; if (parent == null) { this.isVisible = false; } else { parent.addKeyListener(this); } }
/** * Registers a controller to an Active object. If the controller extends KeyboardVivaeController * it also registers it to the parent component as a new KeyListener. * * @param agent The Active the controller will control. * @param controller The controller specifing behavior of the Active object. */ public void registerController(IRobotInterface agent, VivaeController controller) { controller.setControlledObject(agent); controllers.add(controller); if (agent instanceof VivaeRobotRepresent && controller instanceof KeyboardVivaeController) { if (parent != null) { parent.addKeyListener((KeyboardVivaeController) controller); } this.addKeyListener((KeyboardVivaeController) controller); } }
/** * Adds default interactions to the specified component. * * @param comp component * @param win parent window */ public static void addInteraction(final Component comp, final Window win) { comp.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { focus(comp); } }); if (win instanceof BaseXDialog) { // add default keys final BaseXDialog d = (BaseXDialog) win; comp.addKeyListener( new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { final Object s = e.getSource(); if (s instanceof BaseXCombo && ((BaseXCombo) s).isPopupVisible()) return; // do not key close dialog if button or editor is focused if (ENTER.is(e) && !(s instanceof BaseXButton || s instanceof TextPanel)) { d.close(); } else if (ESCAPE.is(e)) { // do not cancel dialog if search bar is opened boolean close = true; if (s instanceof TextPanel) { final SearchBar bar = ((TextPanel) s).getSearch(); close = bar == null || !bar.deactivate(true); } if (close) d.cancel(); } } }); return; } if (win instanceof GUI) { comp.addKeyListener(globalShortcuts((GUI) win)); } else { throw Util.notExpected("Reference to main window expected."); } }