List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:pipeline.parameter_cell_views.TextBox.java
public TextBox() { super();//from ww w.ja va2 s . com setLayout(new GridBagLayout()); parameterName = new JLabel(""); textField = new JTextArea(currentValue); textField.getDocument().addDocumentListener(new valueListener()); // textField.setMinimumSize(new Dimension(150,40)); textField.setLineWrap(true); textField.addMouseListener(this); textField.addKeyListener(new KeyAdapter() { // from http://www.java.net/node/650657 @Override public void keyPressed(KeyEvent evt) { int iKey = evt.getKeyCode(); JComponent component = (JTextArea) evt.getComponent(); DefaultFocusManager focusManager = new DefaultFocusManager(); if ((iKey == KeyEvent.VK_ENTER) || // (iKey == KeyEvent.VK_DOWN) || (iKey == KeyEvent.VK_PAGE_UP) || (iKey == KeyEvent.VK_PAGE_DOWN) || (iKey == KeyEvent.VK_TAB)) { evt.consume(); focusManager.focusNextComponent(component); } // if (iKey == KeyEvent.VK_UP) // focusManager.focusPreviousComponent(component); } }); c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridheight = 2; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 1; scrollPane = new JScrollPane(textField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); add(scrollPane, c); scrollPane.setPreferredSize(new Dimension(1000, 500)); scrollPane.setMinimumSize(new Dimension(10, 60)); c.weighty = 0; add(parameterName, c); parameterNameAdded = true; parameterName.setMinimumSize(new Dimension(100, 30)); }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
/** * Creates new form TestPanel// w w w . ja va 2 s. co m * * @param pListener */ public AttackTimePanel(SettingsChangedListener pListener) { initComponents(); mListener = pListener; dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(jLabel5, DnDConstants.ACTION_COPY_OR_MOVE, AttackTimePanel.this); dragSource.createDefaultDragGestureRecognizer(jLabel6, DnDConstants.ACTION_COPY_OR_MOVE, AttackTimePanel.this); DropTarget dropTarget = new DropTarget(this, this); jTimeFrameList.setDropTarget(dropTarget); jSendTimeFrame.addColorisationListener(new ColorisationListener() { @Override public void newColors(ColorisationEvent ColorisationEvent_Arg) { updatePreview(); } }); dateTimeField.setActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updatePreview(); } }); jTimeFrameList.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { deleteSelectedTimeSpan(); } } }); jArriveInPastLabel.setVisible(false); maxArriveTimeField.setActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TimeFrame currentFrame = getTimeFrame(); if (currentFrame != null) { jArriveInPastLabel .setVisible(currentFrame.getArriveRange().getMaximum() < System.currentTimeMillis()); } } }); reset(); updatePreview(); }
From source file:ve.zoonosis.controller.modulos.novdedades.NuevoClienteController.java
@Override public final void inicializar() { activeInput(false);//from w w w .j ava 2 s.c om cardNumber.setEnabled(true); buscar.setEnabled(false); if (entity == null) { entity = new Cliente(); } limpiar(); iniForm(); buscar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buscarPersona(); } }); limpiar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { limpiar(); } }); telefono.addKeyListener(formularioActionListener); cardNumber.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { buscar.setEnabled(validarCedula()); if (e.getKeyCode() == KeyEvent.VK_ENTER && buscar.isEnabled()) { buscarPersona(); } } }); BindObject bindObject2 = new BindObject(entity); Bindings.bind(correo, bindObject2.getBind("correo")); Bindings.bind(direccion, bindObject2.getBind("direccion")); Bindings.bind(telefono, bindObject2.getBind("telefono")); Bindings.bind(parroquia, bindObject2.getBind("parroquia"), true); nombre.setMaxLength(45); apellido.setMaxLength(45); cardNumber.setMaxLength(20); correo.setMaxLength(45); telefono.setMaxLength(12); direccion.setMaxLength(200); try { rb = new RequestBuilder("services/administracion/MunicipioWs/ListaMunicipios.php"); List<Municipio> municipios = rb.ejecutarJson(List.class, Municipio.class); if (municipios != null) { municipios.add(0, null); municipio.setModel(new ListComboBoxModel<>(municipios)); municipio.setSelectedIndex(-1); } } catch (URISyntaxException | RuntimeException ex) { LOG.LOGGER.log(Level.SEVERE, null, ex); } municipio.addActionListener(new MunicipioListener(parroquia)); parroquia.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { entity.setParroquia((Parroquia) parroquia.getSelectedItem()); aceptar.setEnabled(validar()); } }); autoCreateValidateForm(Persona.class, Cliente.class); iniciarDialogo(); cardNumber.requestFocus(); }
From source file:com.tascape.qa.th.android.tools.UiAutomatorViewer.java
private void start() throws Exception { SwingUtilities.invokeLater(() -> { jd = new ViewerParameterDialog("Launch Android App"); JPanel jpParameters = new JPanel(); jpParameters.setLayout(new BoxLayout(jpParameters, BoxLayout.PAGE_AXIS)); jd.setParameterPanel(jpParameters); {/*from w w w. ja v a2s . c om*/ JPanel jp = new JPanel(); jpParameters.add(jp); jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS)); jp.add(new JLabel("Devices")); jp.add(jcbDevices); } { JPanel jp = new JPanel(); jpParameters.add(jp); jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS)); jp.add(new JLabel("App Package Name")); jp.add(jtfApp); if (StringUtils.isNotEmpty(appPackageName)) { jtfApp.setText(appPackageName); } jtfApp.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { jbLaunch.doClick(); } } }); } { JPanel jp = new JPanel(); jpParameters.add(jp); jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS)); jp.add(new JLabel("Interaction time (minute)")); jsDebugMinutes.getEditor().setEnabled(false); jp.add(jsDebugMinutes); } { JPanel jp = new JPanel(); jpParameters.add(jp); jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS)); jp.add(Box.createRigidArea(new Dimension(518, 2))); } JPanel jpAction = new JPanel(); jd.setActionPanel(jpAction); jpAction.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS)); jbLaunch.setFont(jbLaunch.getFont().deriveFont(Font.BOLD)); jbLaunch.setBorder(BorderFactory.createEtchedBorder()); jbLaunch.setEnabled(false); jpAction.add(jbLaunch); jbLaunch.addActionListener(event -> { new Thread() { @Override public void run() { launchApp(); } }.start(); }); jd.showDialog(); new Thread() { @Override public void run() { try { detectDevices(); } catch (Exception ex) { throw new RuntimeException(ex); } } }.start(); }); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopFilterHelper.java
@Override public void addTextChangeListener(TextField textField, final TextChangeListener listener) { final JTextField dTextField = (JTextField) DesktopComponentsHelper.unwrap(textField); dTextField.addKeyListener(new KeyAdapter() { @Override/*from w w w . ja v a 2 s.co m*/ public void keyReleased(KeyEvent e) { listener.textChanged(dTextField.getText()); } }); }
From source file:com.nbt.TileCanvas.java
public TileCanvas(final World world) { Validate.notNull(world, "world must not be null"); this.world = world; setFocusable(true);// w w w . j av a 2 s .c om addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { int tileWidth = calculateWidth(); setTileWidth(tileWidth); int tileHeight = calculateHeight(); setTileHeight(tileHeight); save(); } }); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { TileCanvas.this.keyPressed(e); } }); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { Point point = e.getPoint(); int x = pixelsToTile(point.x); int z = pixelsToTile(point.y); int tileX = x + getTileX(); int tileZ = z + getTileZ(); int y = getAltitude(); Block block = world.getBlock(tileX, y, tileZ); blockClicked(block); } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int amount = e.getWheelRotation(); int altitude = getAltitude(); setAltitude(amount + altitude); updateXYZ(); doRepaint(); save(); } }); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { updateXYZ(); } }); new MouseDragAndDrop(this) { private int tileX, tileZ; @Override public void selected(MouseEvent e) { this.tileX = getTileX(); this.tileZ = getTileZ(); } @Override public void dragged(MouseEvent e) { MouseEvent startEvent = getStartEvent(); Point startPt = startEvent.getPoint(); Point releasePt = e.getPoint(); int x = tileX + (pixelsToTile(startPt.x) - pixelsToTile(releasePt.x)); int z = tileZ + (pixelsToTile(startPt.y) - pixelsToTile(releasePt.y)); setTileX(x); setTileZ(z); updateXYZ(); doRepaint(); } @Override public void dropped(MouseEvent press, MouseEvent release) { // Point startPt = press.getPoint(); // Point releasePt = release.getPoint(); // int x = getTileX() + pixelsToTile(startPt.x - releasePt.x); // int z = getTileZ() + pixelsToTile(startPt.y - releasePt.y); // setTileX(x); // setTileZ(z); // // updateXYZ(); // doRepaint(); save(); } }.install(); setLayout(null); hud = new HUD(); int width = 200, height = 200; hud.setSize(width, height); add(hud); }
From source file:com.googlecode.gmail4j.util.LoginDialog.java
/** * Creates the required listeners// www. java 2 s. com * * @param login Credentials object for filling the data */ private void createListeners(final Credentials login) { pass.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { setCredentials(login); dialog.setVisible(false); } } }); ok.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { setCredentials(login); dialog.setVisible(false); } }); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { log.warn("Login dialog closed, no username/password specified"); latch.countDown(); } }); }
From source file:org.squidy.designer.zoom.NavigationShape.java
/** * Default constructor required for JAXB. *//*from ww w.j a va2 s .c o m*/ public NavigationShape() { super(); addInputEventListener(new PBasicInputEventHandler() { private JTextField titleInput = new JTextField(getTitle()); { titleInputWrapper = new JComponentWrapper(titleInput); titleInput.setFont(fontBreadcrumb); addChild(titleInputWrapper); // titleInputWrapper.setScale(2); ShapeUtils.setApparent(titleInputWrapper, false); titleInput.addKeyListener(new KeyAdapter() { /** * @param e */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (ShapeUtils.isApparent(titleInputWrapper)) { prepareTitleIfNecessary(); } } } }); } /** * Prepare title if user did new input and title is different than * current title. */ void prepareTitleIfNecessary() { String oldTitle = getTitle(); String newTitle = titleInput.getText(); if (!oldTitle.equals(newTitle)) { if (changeTitle(oldTitle, newTitle)) { setTitle(titleInput.getText()); ShapeUtils.setApparent(titleInputWrapper, false); invalidateTitle(); invalidateBreadcrumb(); invalidatePaint(); } } else { ShapeUtils.setApparent(titleInputWrapper, false); } } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseClicked * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseClicked(PInputEvent event) { if (!event.isHandled()) { switch (event.getClickCount()) { case 1: if (!event.getPickedNode().equals(titleInputWrapper) && ShapeUtils.isApparent(titleInputWrapper)) { prepareTitleIfNecessary(); event.setHandled(true); } break; case 2: Point2D p = event.getPositionRelativeTo(NavigationShape.this); if (titleBounds != null && titleBounds.contains(p)) { if (!ShapeUtils.isApparent(titleInputWrapper)) { titleInputWrapper.setOffset(titleBounds.getX(), titleBounds.getY()); titleInput.setText(getTitle()); // titleInput.requestFocus(); ShapeUtils.setApparent(titleInputWrapper, true); } event.setHandled(true); } break; } } } }); }
From source file:vincent.DynamicDataDemo.java
/** * Constructs a new demonstration application. * //from www . j a va2 s. c o m * @param title the frame title. */ public DynamicDataDemo(final String title) { super(title); this.series = new TimeSeries("Random Data"); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(content); // Zone de saisie de commande vers le port srie : TextField zoneSaisie = new TextField(10); chartPanel.add(zoneSaisie); zoneSaisie.setLocation(100, 300); zoneSaisie.validate(); zoneSaisie.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { TextField textField = (TextField) e.getComponent(); try { BufferedWriter writer = tempSerialReader.getEcrivainPortSerie(); writer.write(textField.getText()); writer.write('\r'); writer.flush(); } catch (IOException l_ex) { LOG.error("erreur d'criture sur le port srie: ", l_ex); } } } }); temperatureCouranteLabel = new Label("XX.XC"); chartPanel.add(temperatureCouranteLabel); chartPanel.add(tempsDeChauffeEtRelicat); chartPanel.add(paramsPid); tempSerialReader = new TempSerialReader(this); }
From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidIconsImporter.java
public AndroidIconsImporter(@Nullable final Project project, Module module) { super(project, true); this.project = project; setTitle("Android Icons Importer"); setResizable(false);//from w w w . j a v a2 s . c o m AndroidResourcesHelper.initResourceBrowser(project, module, "Select res root", this.resRoot); assetRoot = SettingsHelper.getAssetPath(IconPack.ANDROID_ICONS); colorSpinner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { assetColor = (String) colorSpinner.getSelectedItem(); updateImage(); } }); AssetSpinnerRenderer renderer = new AssetSpinnerRenderer(); //noinspection GtkPreferredJComboBoxRenderer assetSpinner.setRenderer(renderer); assetSpinner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { assetName = (String) assetSpinner.getSelectedItem(); updateImage(); } }); fillComboBoxes(); resExportName.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent keyEvent) { super.keyTyped(keyEvent); if (!exportNameChanged && keyEvent != null && keyEvent.getKeyCode() > -1) { exportNameChanged = true; } } @Override public void keyPressed(KeyEvent keyEvent) { super.keyPressed(keyEvent); } @Override public void keyReleased(KeyEvent keyEvent) { super.keyReleased(keyEvent); } }); imageContainer.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { super.componentResized(e); updateImage(); } }); init(); }