Java Code Examples for java.awt.event.KeyAdapter

The following are top voted examples for showing how to use java.awt.event.KeyAdapter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Cognizant-Intelligent-Test-Scripter   File: StyledEditor.java   View source code 7 votes vote down vote up
public KeyListener updateProviderOnSave() {
    return new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent ke) {
            if (isSave(ke)) {
                onSave();
            }
        }
    };
}
 
Example 2
Project: incubator-netbeans   File: OQLControllerUI.java   View source code 6 votes vote down vote up
public Presenter(final QueryUI queryUI) {
    super();
    setText(Bundle.OQLControllerUI_ControllerName());
    setToolTipText(Bundle.OQLControllerUI_ControllerDescr());
    setIcon(OQL_ICON);

    addKeyListener(new KeyAdapter() {
        public void keyTyped(final KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    queryUI.requestFocus();
                    queryUI.addToQuery(e.getKeyChar());
                }
            });
        }
    });
}
 
Example 3
Project: pong   File: DrawingPanel.java   View source code 6 votes vote down vote up
public DrawingPanel(){
    super();
    setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT));
    Random ran = new Random();
    ball = new Ball(300, 350, 10, 3, -5, Color.BLUE);
    paddle = new Paddle((SCREEN_WIDTH/2) - (Paddle.PADDLE_WIDTH/2), SCREEN_HEIGHT - 20, 40);
    Thread t = new Thread(new Repainter());
    t.start();
    setFocusable(true);
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            super.keyPressed(e);
            int key = e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT ? e.getKeyCode() : 0;
            if(key != 0){
                paddle.move(key);
            }
        }
    });
}
 
Example 4
Project: dead-code-detector   File: ParametersPanel.java   View source code 6 votes vote down vote up
private void init() {
	initTransferHandler();

	filesTable.addKeyListener(new KeyAdapter() {
		/** {@inheritDoc} */
		@Override
		public void keyPressed(KeyEvent event) {
			final int keyCode = event.getKeyCode();
			onKeyPressed(keyCode);
		}
	});

	setBorder(EMPTY_BORDER);
	setLayout(DcdUiHelper.createBorderLayout());
	setOpaque(false);

	add(getNorthPanel(), BorderLayout.NORTH);

	add(getCenterPanel(), BorderLayout.CENTER);
}
 
Example 5
Project: Hotel-Properties-Management-System   File: HotelPropertiesWindow.java   View source code 6 votes vote down vote up
private KeyListener listenToKeysListener() {
    final KeyAdapter adapter = new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            String word = nameField.getText();
            if (word.length() < 18) {
                hotelNameTitle.setText(word);
                hotelNameTitle.repaint();
            } else {
                JOptionPane.showMessageDialog(modalFrame, "Hotel name maximum 18 charachter allowed!",
                        JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
            }
            super.keyTyped(e);
        }
    };
    return adapter;
}
 
Example 6
Project: Hotel-Properties-Management-System   File: AddUserWindow.java   View source code 6 votes vote down vote up
private KeyListener validatorListener() {
	final KeyAdapter adapter = new KeyAdapter() {
		@Override
		public void keyTyped(KeyEvent e) {
			final EmailValidator validator = new EmailValidator();
			if(validator.validate(emailField.getText())) {
				markerLbl.setVisible(false);
				infoLabel.setText("");
				isValid = true;
			}
			else {
				markerLbl.setVisible(true);
				infoLabel.setText("Invalid email format!");
			}
		}
	};
	return adapter;
}
 
Example 7
Project: JavaGraph   File: PrologDisplay.java   View source code 6 votes vote down vote up
/**
 * Constructs and returns the query field.
 * Also initialises {@link #queryEdit}.
 */
private JComboBox<String> getQueryField() {
    if (this.queryField == null) {
        this.queryField = new JComboBox<>(PREFS.get("queryHistory", "").split("\\n"));
        this.queryField.setFont(EDIT_FONT);
        this.queryField.setEditable(true);
        this.queryField.setEnabled(true);
        this.queryField.setPrototypeDisplayValue("groove+prolog");
        this.queryEdit = (JTextComponent) this.queryField.getEditor().getEditorComponent();
        this.queryEdit.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    executeQuery();
                    giveFocusToNextResultButton();
                }
            }
        });
    }
    return this.queryField;
}
 
Example 8
Project: gate-core   File: TextualDocumentView.java   View source code 6 votes vote down vote up
protected void initListeners() {
  // textView.addComponentListener(new ComponentAdapter(){
  // public void componentResized(ComponentEvent e){
  // try{
  // scroller.getViewport().setViewPosition(
  // textView.modelToView(0).getLocation());
  // scroller.paintImmediately(textView.getBounds());
  // }catch(BadLocationException ble){
  // //ignore
  // }
  // }
  // });

  // stop control+H from deleting text and transfers the key to the
  // parent
  textView.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_H && e.isControlDown()) {
        getGUI().dispatchEvent(e);
        e.consume();
      }
    }
  });
}
 
Example 9
Project: Equella   File: BusyGlassPane.java   View source code 6 votes vote down vote up
/**
 * GlassPane constructor comment.
 * 
 * @param Container a
 */
protected BusyGlassPane(Component activeComponent, boolean stopClosing)
{
	this.stopClosing = stopClosing;

	// add adapters that do nothing for keyboard and mouse actions
	addMouseListener(new MouseAdapter()
	{
		// We don't care about any events
	});

	addKeyListener(new KeyAdapter()
	{
		// We don't care about any events
	});

	setActiveComponent(activeComponent);
}
 
Example 10
Project: ramus   File: IconPreviewPanel.java   View source code 6 votes vote down vote up
private void init() {
    JScrollPane pane = new JScrollPane();
    list = new JList(dataModel);
    list.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F5) {
                try {
                    data = null;
                    loadImages();
                } catch (IOException e1) {
                    e1.printStackTrace();
                    JOptionPane.showMessageDialog(null, e1
                            .getLocalizedMessage());
                }
                list.setModel(dataModel);
                list.updateUI();
            }
        }
    });
    list.setCellRenderer(new IconRenderer());
    pane.setViewportView(list);
    for (int i = 0; i < data.size(); i++) {
    }
    this.add(pane, BorderLayout.CENTER);
}
 
Example 11
Project: AndroidSourceViewer   File: GlobalSearchDialog.java   View source code 6 votes vote down vote up
public GlobalSearchDialog(SearchFinishResult result) {
    setContentPane(contentPane);
    setModal(true);
    setTitle("Android Source Search");
    setSize(800, 500);
    this.setLocationRelativeTo(null);
    listView.setModel(dataSet);
    listView.setFixedCellHeight(25);
    listView.addListSelectionListener(this);
    listView.addMouseListener(new ListDoubleClickEvent<String>(this));
    searchBar.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            startSearch();
        }
    });
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.searchFinishResult = result;
}
 
Example 12
Project: enigma-vk   File: Gui.java   View source code 6 votes vote down vote up
private void startRename() {
	
	// init the text box
	final JTextField text = new JTextField();
	text.setText(m_reference.getNamableName());
	text.setPreferredSize(new Dimension(360, text.getPreferredSize().height));
	text.addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent event) {
			switch (event.getKeyCode()) {
				case KeyEvent.VK_ENTER:
					finishRename(text, true);
				break;
				
				case KeyEvent.VK_ESCAPE:
					finishRename(text, false);
				break;
			}
		}
	});
	
	// find the label with the name and replace it with the text box
	JPanel panel = (JPanel)m_infoPanel.getComponent(0);
	panel.remove(panel.getComponentCount() - 1);
	panel.add(text);
	text.grabFocus();
	text.selectAll();
	
	redraw();
}
 
Example 13
Project: set-game   File: PlaySet.java   View source code 6 votes vote down vote up
@Override
public void run() {
    if (!streaming) {
        addMouseListener(panel);
    }
    JFrame window = ShowImages.showWindow(panel, PlaySet.class.getSimpleName(),true);
    window.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == 'x' && previousSet != null) {
                System.out.println("'Not a Set!'");
                ImageSuppliers.WebcamSaverImageSupplier.save(image);
            }
        }
    });

    if (streaming) {
        while (true) {
            image = imageSupplier.get();
            newImage(image);
        }
    }
}
 
Example 14
Project: jdk8u-jdk   File: DisplayChangeVITest.java   View source code 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 15
Project: openjdk-jdk10   File: DisplayChangeVITest.java   View source code 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 16
Project: openjdk-jdk10   File: bug6578666.java   View source code 6 votes vote down vote up
private static void createGui() {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tree = new JTree();
    frame.add(tree);

    tree.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            tree.updateUI();
        }
    });

    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 17
Project: openjdk9   File: DisplayChangeVITest.java   View source code 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 18
Project: openjdk9   File: bug6578666.java   View source code 6 votes vote down vote up
private static void createGui() {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tree = new JTree();
    frame.add(tree);

    tree.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            tree.updateUI();
        }
    });

    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 19
Project: semtool   File: RelationshipLoadingPlaySheet.java   View source code 6 votes vote down vote up
private void init() {
	JLabel lbl = new JLabel( "Relationship name:" );
	relationship.setText( defaultRelationship );

	JPanel pnl = new JPanel( new BorderLayout() );
	pnl.add( lbl, BorderLayout.WEST );
	pnl.add( relationship, BorderLayout.CENTER );

	add( pnl, BorderLayout.NORTH );

	relationship.addKeyListener( new KeyAdapter() {

		@Override
		public void keyReleased( KeyEvent e ) {
			LoadingSheetModel model = getLoadingModel();

			if ( model.isRealTimeChecking() ) {
				model.setRelationshipName( relationship.getText() );
				RelationshipLoadingPlaySheet.this.setErrorLabel();
			}

			lbl.setIcon( model.getModelErrorColumns().contains( -1 )
					? DbAction.getIcon( "error" ) : null );
		}
	} );
}
 
Example 20
Project: wiimote-paintboard   File: WiimoteCalibration.java   View source code 6 votes vote down vote up
public CalibrationFrame() {
			super("Calibration");
//			getRootPane().putClientProperty("Window.alpha", new Float(0.9));
			setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			setBackground(Color.WHITE);
			((JPanel)getContentPane()).setOpaque(true);
			setLayout(null);
			setUndecorated(true);
			setAlwaysOnTop(true);
			addKeyListener(new KeyAdapter() {
				@Override
				public void keyPressed(KeyEvent e) {
					if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
						state = CalibrationState.PENDING;
						if (screen.getFullScreenWindow() == calibrationFrame)
							screen.setFullScreenWindow(null);
						setVisible(false);
						notifyListener(CalibrationEvent.ABORTED);
					}
				}
			});
		}
 
Example 21
Project: wiimote-paintboard   File: CameraMonitor.java   View source code 6 votes vote down vote up
public CameraMonitor(WiimoteDataHandler dh) {
	super(Application.getInstance(WiimoteWhiteboard.class).getMainFrame(), Util.getResourceMap(CameraMonitor.class).getString("monitor.Action.text"));
	getRootPane().putClientProperty("Window.style", "small");
	setLayout(new MigLayout());
	
	dh.addWiimoteDataListener(this);

	canvas = new JPanel(null, true);
	canvas.setOpaque(true);
	canvas.setBorder(BorderFactory.createLineBorder(SystemColor.inactiveCaptionBorder));
	add(canvas, "w 50sp, h 50sp, grow, push");
	
	addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
				setVisible(false);
			}
		}
	});

	pack();
	setLocationRelativeTo(null);

	new Timer(true).schedule(new UpdateTask(), 0, REPAINT_FREQ);
}
 
Example 22
Project: intellij-ce-playground   File: StructureViewComponent.java   View source code 6 votes vote down vote up
private void addTreeKeyListener() {
  getTree().addKeyListener(
      new KeyAdapter() {
      @Override
      public void keyPressed(KeyEvent e) {
        if (KeyEvent.VK_ENTER == e.getKeyCode()) {
          DataContext dataContext = DataManager.getInstance().getDataContext(getTree());
          OpenSourceUtil.openSourcesFrom(dataContext, false);
        }
        else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
          if (e.isConsumed())
          {
            return;
          }
          PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
          boolean[] isCopied = new boolean[1];
          if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
            copyPasteManager.clear();
            e.consume();
          }
        }
      }
    });
}
 
Example 23
Project: PhET   File: TestDynamicJFreeChartNodeTree.java   View source code 6 votes vote down vote up
public TestDynamicJFreeChartNodeTree() {
    getPhetPCanvas().removeScreenChild( getDynamicJFreeChartNode() );
    root = new PhetPPath( new Rectangle( 0, 0, 10, 10 ), Color.blue );

    root.addChild( getDynamicJFreeChartNode() );

    getPhetPCanvas().addScreenChild( root );
    getPhetPCanvas().addKeyListener( new KeyAdapter() {
        public void keyPressed( KeyEvent e ) {
            if ( e.getKeyCode() == KeyEvent.VK_PAGE_UP ) {
                root.scale( 1.1 );
            }
            else if ( e.getKeyCode() == KeyEvent.VK_PAGE_DOWN ) {
                root.scale( 1.0 / 1.1 );
            }
        }
    } );
    constructed = true;

    text = new PText( "Page Up/Down to scale" );
    getPhetPCanvas().addScreenChild( text );
}
 
Example 24
Project: PhET   File: TestBufferedPNode.java   View source code 6 votes vote down vote up
public TestBufferedPNode() {
        frame = new JFrame();
        frame.setSize( 600, 600 );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        phetPCanvas = new PhetPCanvas();
        phetPCanvas.setPanEventHandler( new PPanEventHandler() );
        phetPCanvas.setZoomEventHandler( new PZoomEventHandler() );

        frame.setContentPane( phetPCanvas );
        final ExpensiveNode expensiveNode = new ExpensiveNode();
        final BufferedPNode bufferedPNode = new BufferedPNode( phetPCanvas, expensiveNode );
//        phetPCanvas.addWorldChild( expensiveNode );
        phetPCanvas.addWorldChild( bufferedPNode );

        phetPCanvas.addKeyListener( new KeyAdapter() {
            public void keyPressed( KeyEvent e ) {
                System.out.println( "TestBufferedPNode.keyPressed" );
                phetPCanvas.getCamera().scaleView( 1.1 );
                phetPCanvas.repaint();
            }
        } );
    }
 
Example 25
Project: scelight   File: XTextField.java   View source code 6 votes vote down vote up
/**
 * Creates a new {@link XTextField}.
 * 
 * @param text initial text of the text field
 * @param columns the number of columns to use to calculate the preferred width; if columns is set to zero, the preferred width will be whatever naturally
 *            results from the component implementation
 * @param clearByEsc tells if text field should be cleared when the ESC key is pressed
 */
public XTextField( final String text, final int columns, final boolean clearByEsc ) {
	super( text, columns );
	
	if ( clearByEsc )
		addKeyListener( new KeyAdapter() {
			@Override
			public void keyPressed( final KeyEvent event ) {
				if ( event.getKeyCode() == KeyEvent.VK_ESCAPE ) {
					if ( !getText().isEmpty() ) {
						setText( null );
						// ESC is also used to hide (close) dialogs, so consume event if we did clear search term
						event.consume();
					}
				}
			}
		} );
}
 
Example 26
Project: intellij-ce-playground   File: EditSourceOnEnterKeyHandler.java   View source code 6 votes vote down vote up
public static void install(final JTree tree){
  tree.addKeyListener(
    new KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        if (KeyEvent.VK_ENTER == e.getKeyCode()) {
          DataContext dataContext = DataManager.getInstance().getDataContext(tree);

          Project project = CommonDataKeys.PROJECT.getData(dataContext);
          if (project == null) return;

          OpenSourceUtil.openSourcesFrom(dataContext, false);
        }
      }
    }
  );
}
 
Example 27
Project: intellij-ce-playground   File: ArrayTableCellEditor.java   View source code 6 votes vote down vote up
public MyTableEditor(Project project,
                     XDebuggerEditorsProvider debuggerEditorsProvider,
                     @Nullable @NonNls String historyId,
                     @Nullable XSourcePosition sourcePosition, @NotNull XExpression text, @NotNull final KeyAdapter actionAdapter) {
  super(project, debuggerEditorsProvider, EvaluationMode.CODE_FRAGMENT, historyId, sourcePosition);
  myExpression = XExpressionImpl.changeMode(text, getMode());
  myEditorTextField = new EditorTextField(createDocument(myExpression), project, debuggerEditorsProvider.getFileType()) {
    @Override
    protected EditorEx createEditor() {
      final EditorEx editor = super.createEditor();
      editor.setVerticalScrollbarVisible(false);
      editor.setOneLineMode(true);
      editor.getContentComponent().addKeyListener(actionAdapter);
      return editor;
    }

    @Override
    protected boolean isOneLineMode() {
      return true;
    }
  };
  myEditorTextField.setFontInheritedFromLAF(false);
}
 
Example 28
Project: bisis-v4   File: SveskePanel.java   View source code 6 votes vote down vote up
private void createSveskeTable() {    
  TableSorter tsorter = new TableSorter(sveskeTableModel);
  sveskeTable = new JTable(tsorter);    
  TableColumn columnInvBroj = sveskeTable.getColumnModel().getColumn(0);    
  tsorter.setTableHeader(sveskeTable.getTableHeader());  
  sveskeScrollPane = new JScrollPane(sveskeTable);    
  ListSelectionModel lSelModel = sveskeTable.getSelectionModel();
  lSelModel.addListSelectionListener(new ListSelectionListener(){
    public void valueChanged(ListSelectionEvent e) {
      handleListSelectionChanged();       
    }     
  });
  sveskeTable.addKeyListener(new KeyAdapter(){
    public void keyPressed(KeyEvent ke) {
      handleKeys(sveskeTable,ke);      
    }      
  });    
}
 
Example 29
Project: geoxygene   File: EditPostgisConnection.java   View source code 6 votes vote down vote up
JParamField(ParamType key, ConnectionParam param) {
    super(20);
    this.paramType = key;
    this.param = param;
    switch(paramType) {
        case DBTYPE : setValue(param.getDbtype());break;
        case DATABASE : setValue(param.getDatabase());break;
        case HOST : setValue(param.getHost());break;
        case PORT : setValue(param.getPort());break;
        case SCHEMA : setValue(param.getSchema());break;
        case USER : setValue(param.getUser());break;
        case PASSWD : setValue(param.getPasswd());break;
        default:;
    }
    
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            refresh();
        }
    });
    // setToolTipText(param.description.toString());
}
 
Example 30
Project: lookaside_java-1.8.0-openjdk   File: DisplayChangeVITest.java   View source code 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 31
Project: iSeleda   File: OutputSettingsPanel.java   View source code 6 votes vote down vote up
private void addAnimationLengthSelector(LayerUI<JTextField> tfLayerUI, GridBagHelper gbHelper) {
    gbHelper.addLabelWithControl("Number of Seconds:",
            new JLayer<>(nrSecondsTF, tfLayerUI));

    KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent keyEvent) {
            updateCalculations();
        }
    };
    nrSecondsTF.addKeyListener(keyListener);

    gbHelper.addLabelWithControl("Frames per Second:",
            new JLayer<>(fpsTF, tfLayerUI));
    fpsTF.addKeyListener(keyListener);

    nrFramesLabel = new JLabel();
    updateCalculations();
    gbHelper.addLabelWithControl("Number of Frames:", nrFramesLabel);
}
 
Example 32
Project: TypeTalk   File: ApplicationWindow.java   View source code 6 votes vote down vote up
private JTextField createSuggestField() {
   JSuggestField typingField = new JSuggestField(this, Suggestions.getInstance().getSuggestions());
   typingField.addKeyListener(new KeyAdapter() {

      @Override
      public void keyReleased(KeyEvent e) {
         if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            if (typingField.isSuggestionAccepted()) {
               typingField.setSuggestionAccepted(false);
            } else {
               speekTypingFieldContent(true);
               typingField.hideSuggest();
            }
         }
      }
   });
   new EditAdapter(typingField);
   return typingField;
}
 
Example 33
Project: ca-iris   File: R_NodeDetectorPanel.java   View source code 6 votes vote down vote up
/** Create Gui jobs */
private void createJobs() {
	ListSelectionModel s = det_table.getSelectionModel();
	s.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	s.addListSelectionListener(new IListSelectionAdapter() {
		@Override
		public void valueChanged() {
			selectDetector();
		}
	});
	det_txt.addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			if(e.getKeyCode() == KeyEvent.VK_ENTER)
				create_btn.doClick();
		}
		@Override
		public void keyReleased(KeyEvent ke) {
			det_table.clearSelection();
			lookupDetector();
		}
	});
}
 
Example 34
Project: intellij-ce-playground   File: TemplateLanguagePanel.java   View source code 6 votes vote down vote up
public TemplateLanguagePanel() {
  super(new BorderLayout());
  add(myMainPanel, BorderLayout.CENTER);
  myTemplatesFolderLabel.setLabelFor(myTemplatesFolder);
  FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  descriptor.withTreeRootVisible(true);
  descriptor.setShowFileSystemRoots(true);
  List<String> templateConfigurations = TemplatesService.getAllTemplateLanguages();
  for (String configuration : templateConfigurations) {
    if (!configuration.equals(TemplatesService.WEB2PY)) {
      myTemplateLanguage.addItem(configuration);
    }
  }
  myTemplatesFolder.setText(DEFAULT_TEMPLATES_FOLDER);
  myTemplatesFolder.addKeyListener(new KeyAdapter() {
    @Override
    public void keyTyped(KeyEvent e) {
      final int dot = myTemplatesFolder.getCaret().getDot();
      final int index = myTemplatesFolder.getText().indexOf(File.separator);
      if (index >= dot) {
        myTemplateFolderModified = true;
      }
    }
  });
}
 
Example 35
Project: yii2support   File: SettingsForm.java   View source code 5 votes vote down vote up
public SettingsForm(Project project) {
    settings = Yii2SupportSettings.getInstance(project);


    tablePrefixTextbox.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            super.keyReleased(e);
            adjustInputs();
        }
    });
}
 
Example 36
Project: incubator-netbeans   File: ListView.java   View source code 5 votes vote down vote up
private void setupSearch() {
    // Remove the default key listeners
    KeyListener[] keyListeners = getListeners(KeyListener.class);

    for (int i = 0; i < keyListeners.length; i++) {
        removeKeyListener(keyListeners[i]);
    }

    // Add new key listeners
    addKeyListener(
        new KeyAdapter() {
        @Override
            public void keyPressed(KeyEvent e) {
                int modifiers = e.getModifiers();
                int keyCode = e.getKeyCode();

                if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) {
                    return;
                }

                char c = e.getKeyChar();

                if (!Character.isISOControl(c) && (keyCode != KeyEvent.VK_SHIFT)) {
                    searchTextField.setText(String.valueOf(c));
                    displaySearchField();
                }
            }
        }
    );

    // Create a the "multi-event" listener for the text field. Instead of
    // adding separate instances of each needed listener, we're using a
    // class which implements them all. This approach is used in order
    // to avoid the creation of 4 instances which takes some time
    SearchFieldListener searchFieldListener = new SearchFieldListener();
    searchTextField.addKeyListener(searchFieldListener);
    searchTextField.addFocusListener(searchFieldListener);
    searchTextField.getDocument().addDocumentListener(searchFieldListener);
}
 
Example 37
Project: incubator-netbeans   File: Preview.java   View source code 5 votes vote down vote up
private Preview() {
    myPrinter = new Printer();
    myKeyListener = new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            char ch = event.getKeyChar();
            int modifiers = event.getModifiers();

            if (ch == '+' || ch == '=') {
                if (isCtrl(modifiers)) {
                    increaseZoom();
                    updated();
                }
                else {
                    myScale.increaseValue();
                }
            }
            else if (ch == '-' || ch == '_') {
                if (isCtrl(modifiers)) {
                    decreaseZoom();
                    updated();
                }
                else {
                    myScale.decreaseValue();
                }
            }
            else if (ch == '/') {
                myScale.normalValue();
            }
            else if (ch == '*') {
                showCustom(true);
            }
        }
    };
}
 
Example 38
Project: incubator-netbeans   File: FindPanel.java   View source code 5 votes vote down vote up
/** Creates new form FindPanel. */
public FindPanel() {
    initComponents ();
    initAccessibility ();
    findCombo.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
         public void keyTyped(KeyEvent evt) {
            if (evt.getKeyChar() == '\n') {
                findButton.doClick(20);
                evt.consume();
            }
        }
    });
}
 
Example 39
Project: rapidminer   File: AutoCompletionComboBox.java   View source code 5 votes vote down vote up
public AutoCompletionComboBoxEditor(ComboBoxEditor editor) {
	if ((editor.getEditorComponent() instanceof JTextField)) {
		this.editor = editor;
		editorComponent = (JTextField) editor.getEditorComponent();
		editorComponent.getDocument().addDocumentListener(docListener);
		editorComponent.addKeyListener(new KeyAdapter() {

			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					setSelectedItem(editorComponent.getText());
					actionPerformed(new ActionEvent(this, 0, "editingStoped"));
					e.consume();
				} else if (e.getKeyCode() == KeyEvent.VK_TAB) {
					if (isPopupVisible()) {
						hidePopup();
					} else {
						showPopup();
					}
					e.consume();
				} else {
					super.keyPressed(e);
				}
			}
		});
	} else {
		throw new IllegalArgumentException("Only JTextField allowed as editor component");
	}
}
 
Example 40
Project: routerapp   File: PropertyInteractionDialog.java   View source code 5 votes vote down vote up
/**
 * 
 */
private void buildFields() {
	Vector properties = component.getProperties().getAllProperties();
	GridLayout layout = new GridLayout(properties.size(),2,10,10);
	int cells = 0;
	
	Iterator i = properties.iterator();
	JPanel fieldsPane = new JPanel(layout);
	fieldsPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
	
	while (i.hasNext()) {
		try {
			InteractiveProperty property = (InteractiveProperty) i.next();
			
			final JTextField field = new JTextField(property.toString());
			field.addKeyListener(new KeyAdapter() {
				public void keyReleased(KeyEvent e) {
					if (e.getKeyCode() == KeyEvent.VK_ENTER) {
						applyChanges();
					}
					else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
						cancelChanges();
					}
				}
			});
			field.addFocusListener(new FocusAdapter() {
				
				public void focusGained(FocusEvent evt) {
					String text = field.getText();
					field.setSelectionStart(0);
					field.setSelectionEnd(text.length());
				}
			});
			field.setMaximumSize(new Dimension(150,30));
			fields.put(property,field);
			
			fieldsPane.add(new JLabel(property.getName()));
			fieldsPane.add(field);
			
			cells++;
		} catch (ClassCastException exc) {
			/* 
			 * caught to be ignored, so that non-interactive properties
			 * won't be shown in the GUI
			 */
		}
	}
	this.setSize(200,cells * CELL_HEIGHT);
	getContentPane().add(fieldsPane,BorderLayout.CENTER);
}