/** * Returns the specified image. * * @param url image url * @return image */ public static Image get(final URL url) { try { return ImageIO.read(url); } catch (final IOException ex) { throw Util.notExpected(ex); } }
/** * 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."); } }