List of usage examples for javax.swing JComponent WHEN_IN_FOCUSED_WINDOW
int WHEN_IN_FOCUSED_WINDOW
To view the source code for javax.swing JComponent WHEN_IN_FOCUSED_WINDOW.
Click Source Link
registerKeyboardAction
that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component. From source file:org.pmedv.blackboard.components.BoardEditor.java
/** * Creates a new board editor based on an existing model * /*w w w .j av a2s . c o m*/ * @param model */ public BoardEditor(final BoardEditorModel model) { super(null); setOpaque(false); listeners = new ArrayList<EditorChangedListener>(); this.model = model; model.setCurrentLayer(model.getLayer(BoardEditorModel.TOP_LAYER)); if (model.getType() != null && !model.getType().equals(BoardType.SCHEMATICS)) { if (model.getType().equals(BoardType.CUSTOM)) { setBackgroundImage(model.getBackgroundImage()); } else setBackgroundImage( BoardGen.generateBoard(model.getWidth(), model.getHeight(), model.getType(), false)); } // set initial states state = SelectionState.NOTHING_SELECTED; editorMode = EditorMode.SELECT; // init commands saveBoardCommand = ctx.getBean(SaveBoardCommand.class); deleteCommand = ctx.getBean(DeleteCommand.class); addItemCommand = new AddItemCommand(); // setup the editor view Dimension size = new Dimension(model.getWidth(), model.getHeight()); setSize(size); setBounds(new Rectangle(size)); setPreferredSize(size); initListeners(); initActions(); EditorUtils.initToolbar(); hookContextMenu(); updateStatusBar(); setTransferHandler(new BoardEditorSymbolTransferHandler()); EditorUtils.configureDropTarget(this, raster); undoManager = new UndoManager(); win.getViewLabel().setText(resources.getResourceByKey("BoardDesignerPerspective.topView")); addMouseMotionListener(this); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { cancelDrawing(); } }; KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); }
From source file:org.pmedv.blackboard.components.BoardEditor.java
/** * Wire needed actions with the keyboard *//*from w ww .ja va 2 s . c om*/ @SuppressWarnings("serial") private void initActions() { // keyboard associations ApplicationWindow window = AppContext.getBean(ApplicationWindow.class); // // window.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "upAction"); // window.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "downAction"); // window.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "leftAction"); // window.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "rightAction"); // // window.getRootPane().getActionMap().put("upAction", new AbstractAction() { // public void actionPerformed(ActionEvent event) { // moveItemByKey("up"); // } // }); // window.getRootPane().getActionMap().put("downAction", new AbstractAction() { // public void actionPerformed(ActionEvent event) { // moveItemByKey("down"); // } // }); // window.getRootPane().getActionMap().put("leftAction", new AbstractAction() { // public void actionPerformed(ActionEvent event) { // moveItemByKey("left"); // } // }); // window.getRootPane().getActionMap().put("rightAction", new AbstractAction() { // public void actionPerformed(ActionEvent event) { // moveItemByKey("right"); // } // }); registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent event) { moveItemByKey("up"); } }, KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent event) { moveItemByKey("down"); } }, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent event) { moveItemByKey("left"); } }, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent event) { moveItemByKey("right"); } }, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); }
From source file:org.rdv.ui.channel.LocalChannelDialog.java
/** * Initialize the UI components.//ww w .j ava 2s . c o m */ private void initComponents() { RDV rdv = RDV.getInstance(RDV.class); JPanel container = new JPanel(); setContentPane(container); container.setLayout(new GridBagLayout()); GridBagConstraints c = createDefaultGridBagConstraints(); JLabel nameLabel = new JLabel(); nameLabel.setName("nameLabel"); nameLabel.setText(PROPERTY_REPO.getValue(NAME_KEY)); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(10, 10, 10, 5); container.add(nameLabel, c); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(10, 0, 10, 10); container.add(nameTextField, c); if (isChannelUpdateOperation()) { nameTextField.setEnabled(false); } JLabel unitLabel = new JLabel(); unitLabel.setName("unitLabel"); unitLabel.setText(PROPERTY_REPO.getValue(UNIT_KEY)); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(unitLabel, c); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(unitTextField, c); JLabel variablesLabel = new JLabel(); variablesLabel.setName("variablesLabel"); variablesLabel.setText(PROPERTY_REPO.getValue(VARIABLES_KEY)); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(variablesLabel, c); JPanel variablesPanel = buildVariablesPanel(); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.gridx = 0; c.gridy = 4; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 10); c.weightx = 1; c.weighty = 1; container.add(variablesPanel, c); JLabel formulaLabel = new JLabel(); formulaLabel.setName("formulaLabel"); formulaLabel.setText(PROPERTY_REPO.getValue(FORMULA_KEY)); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(formulaLabel, c); JScrollPane formulaScrollPane = new JScrollPane(formulaTextArea); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridx = 0; c.gridy = 6; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(formulaScrollPane, c); JPanel footerPanel = buildFooterPanel(); c = createDefaultGridBagConstraints(); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 7; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(footerPanel, c); // bind keystrokes InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "addChannel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); // initially disable buttons removeVariableButton.setEnabled(false); pack(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.ChannelListPanel.java
/** * Create the UI panel that contains the controls to filter the channel list. * //w ww. ja v a 2 s . c o m * @return the UI component dealing with filtering */ private JComponent createFilterPanel() { JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BorderLayout(5, 5)); filterPanel.setBackground(Color.white); filterPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel filterIconLabel = new JLabel(DataViewer.getIcon("icons/filter.gif")); filterPanel.add(filterIconLabel, BorderLayout.WEST); filterTextField = new JTextField(); filterTextField.setToolTipText("Enter text here to filter the channel list"); filterTextField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { treeModel.setFilter(filterTextField.getText()); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void removeUpdate(DocumentEvent e) { changedUpdate(e); } }); filterPanel.add(filterTextField, BorderLayout.CENTER); Action focusFilterAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -2443410059209958411L; public void actionPerformed(ActionEvent e) { filterTextField.requestFocusInWindow(); filterTextField.selectAll(); } }; int modifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); filterTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_F, modifier), "focusFilter"); filterTextField.getActionMap().put("focusFilter", focusFilterAction); Action cancelFilterAction = new AbstractAction(null, DataViewer.getIcon("icons/cancel.gif")) { /** serialization version identifier */ private static final long serialVersionUID = 8913797349366699615L; public void actionPerformed(ActionEvent e) { treeModel.setFilter(null); } }; cancelFilterAction.putValue(Action.SHORT_DESCRIPTION, "Cancel filter"); filterTextField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancelFilter"); filterTextField.getActionMap().put("cancelFilter", cancelFilterAction); clearFilterButton = new JButton(cancelFilterAction); clearFilterButton.setBorderPainted(false); clearFilterButton.setVisible(false); filterPanel.add(clearFilterButton, BorderLayout.EAST); return filterPanel; }
From source file:org.rdv.ui.ConsoleDialog.java
public ConsoleDialog(JDialog owner) { super(owner); setName("consoleDialog"); setDefaultCloseOperation(AboutDialog.DISPOSE_ON_CLOSE); JPanel container = new JPanel(); container.setLayout(new BorderLayout()); container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); setContentPane(container);// w w w . j a v a2 s . co m InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); Action disposeAction = new AbstractAction() { /** serialized version identifier */ private static final long serialVersionUID = 4380189911762232261L; public void actionPerformed(ActionEvent ae) { dispose(); } }; Action copyAction = new AbstractAction() { /** serialized version identifier */ private static final long serialVersionUID = 2596081241883913660L; public void actionPerformed(ActionEvent e) { textArea.selectAll(); textArea.copy(); } }; // Action scrollLockAction = new AbstractAction() { // /** serialized version identifier */ // private static final long serialVersionUID = -8089076016097529064L; // // public void actionPerformed(ActionEvent e) { // //toggle scroll lock // scrollLock_=!scrollLock_; // } // }; disposeAction.putValue(Action.NAME, "OK"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "dispose"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "dispose"); actionMap.put("dispose", disposeAction); copyAction.putValue(Action.NAME, "Copy"); actionMap.put("copy", copyAction); // actionMap.put("scroll lock", scrollLockAction); // scrollLockAction.putValue(Action.NAME, "Scroll Lock"); textArea = new JTextArea(); textArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); textArea.setBackground(Color.WHITE); textArea.setForeground(Color.BLACK); textArea.setEditable(false); textArea.setLineWrap(false); Iterator<String> msgIt = messageBuffer.getMessages().iterator(); //add all the messages in the buffer to this point while (msgIt.hasNext()) { addMessage(msgIt.next()); } JScrollPane scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(640, 480)); container.add(scrollPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JButton okButton = new JButton(disposeAction); buttonPanel.add(okButton, BorderLayout.EAST); JPanel leftBtnsPanel = new JPanel(); leftBtnsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonPanel.add(leftBtnsPanel, BorderLayout.WEST); JButton copyButton = new JButton(copyAction); leftBtnsPanel.add(copyButton); // JButton scrollLockButton = new JButton(scrollLockAction); // leftBtnsPanel.add(scrollLockButton); container.add(buttonPanel, BorderLayout.SOUTH); // inject resources from the properties for this component ResourceMap resourceMap = RDV.getInstance().getContext().getResourceMap(getClass()); resourceMap.injectComponents(this); pack(); okButton.requestFocusInWindow(); setLocationByPlatform(true); setVisible(true); messageBuffer.addObserver(this); }
From source file:org.rdv.ui.ExportDialog.java
private void initComponents(List<String> channels, List<String> fileFormats) { channelModel = new DefaultListModel(); for (int i = 0; i < channels.size(); i++) { String channelName = (String) channels.get(i); Channel channel = RBNBController.getInstance().getChannel(channelName); String mime = channel.getMetadata("mime"); if (mime.equals("application/octet-stream")) { channelModel.addElement(new ExportChannel(channelName)); }// w ww . ja va2s .c om } JPanel container = new JPanel(); setContentPane(container); InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 0; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; JLabel headerLabel = new JLabel("Select the time range and data channels to export."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 0, 0, 0); container.add(headerLabel, c); JPanel timeButtonPanel = new JPanel(); timeButtonPanel.setLayout(new BorderLayout()); MouseListener hoverMouseListener = new MouseAdapter() { public void mouseEntered(MouseEvent e) { e.getComponent().setForeground(Color.red); } public void mouseExited(MouseEvent e) { e.getComponent().setForeground(Color.blue); } }; startTimeButton = new JButton(); startTimeButton.setBorder(null); startTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); startTimeButton.setForeground(Color.blue); startTimeButton.addMouseListener(hoverMouseListener); startTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double startTime = DateTimeDialog.showDialog(ExportDialog.this, timeSlider.getStart(), timeSlider.getMinimum(), timeSlider.getEnd()); if (startTime >= 0) { timeSlider.setStart(startTime); } } }); timeButtonPanel.add(startTimeButton, BorderLayout.WEST); durationLabel = new JLabel(); durationLabel.setHorizontalAlignment(JLabel.CENTER); timeButtonPanel.add(durationLabel, BorderLayout.CENTER); endTimeButton = new JButton(); endTimeButton.setBorder(null); endTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); endTimeButton.setForeground(Color.blue); endTimeButton.addMouseListener(hoverMouseListener); endTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double endTime = DateTimeDialog.showDialog(ExportDialog.this, timeSlider.getEnd(), timeSlider.getStart(), timeSlider.getMaximum()); if (endTime >= 0) { timeSlider.setEnd(endTime); } } }); timeButtonPanel.add(endTimeButton, BorderLayout.EAST); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(10, 10, 10, 10); container.add(timeButtonPanel, c); timeSlider = new TimeSlider(); timeSlider.setValueChangeable(false); timeSlider.setValueVisible(false); timeSlider.addTimeAdjustmentListener(new TimeAdjustmentListener() { public void timeChanged(TimeEvent event) { } public void rangeChanged(TimeEvent event) { updateTimeRangeLabel(); } public void boundsChanged(TimeEvent event) { } }); updateTimeRangeLabel(); updateTimeBounds(); List<EventMarker> markers = RBNBController.getInstance().getMarkerManager().getMarkers(); for (EventMarker marker : markers) { timeSlider.addMarker(marker); } c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(timeSlider, c); JLabel numericHeaderLabel = new JLabel("Data Channels:"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(numericHeaderLabel, c); numericChannelList = new JList(channelModel); numericChannelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); numericChannelList.setCellRenderer(new CheckListRenderer()); numericChannelList.setVisibleRowCount(10); numericChannelList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int index = numericChannelList.locationToIndex(e.getPoint()); ExportChannel item = (ExportChannel) numericChannelList.getModel().getElementAt(index); item.setSelected(!item.isSelected()); Rectangle rect = numericChannelList.getCellBounds(index, index); numericChannelList.repaint(rect); checkSelectedChannels(); updateTimeBounds(); } }); JScrollPane scrollPane = new JScrollPane(numericChannelList); c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.weighty = 1; c.gridx = 0; c.gridy = 4; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(scrollPane, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(new JLabel("Data file: "), c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; dataFileTextField = new JTextField(20); c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(dataFileTextField, c); dataFileTextField .setText(UIUtilities.getCurrentDirectory().getAbsolutePath() + File.separator + "data.dat"); dataFileButton = new JButton("Browse"); dataFileButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { File selectedFile = new File(dataFileTextField.getText()); selectedFile = UIUtilities.getFile("OK", "Select export file", selectedFile); if (selectedFile != null) { dataFileTextField.setText(selectedFile.getAbsolutePath()); } } }); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 2; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(dataFileButton, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 6; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(new JLabel("File format: "), c); fileFormatComboBox = new JComboBox(fileFormats.toArray()); fileFormatComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { fileFormatUpdated(); } }); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 6; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(fileFormatComboBox, c); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); Action exportAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -5356258138620428023L; public void actionPerformed(ActionEvent e) { ok(); } }; exportAction.putValue(Action.NAME, "Export"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "export"); actionMap.put("export", exportAction); exportButton = new JButton(exportAction); panel.add(exportButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -5868609501314154642L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); panel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.gridx = 0; c.gridy = 7; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(panel, c); pack(); if (getWidth() < 600) { setSize(600, getHeight()); } dataFileTextField.requestFocusInWindow(); setLocationByPlatform(true); }
From source file:org.rdv.ui.ExportVideoDialog.java
private void initComponents() { JPanel container = new JPanel(); setContentPane(container);//w ww . j a va 2 s. co m InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 0; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; JLabel headerLabel = new JLabel("Select the time range and video channels to export."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 0, 0, 0); container.add(headerLabel, c); JPanel timeButtonPanel = new JPanel(); timeButtonPanel.setLayout(new BorderLayout()); MouseListener hoverMouseListener = new MouseAdapter() { public void mouseEntered(MouseEvent e) { e.getComponent().setForeground(Color.red); } public void mouseExited(MouseEvent e) { e.getComponent().setForeground(Color.blue); } }; startTimeButton = new JButton(); startTimeButton.setBorder(null); startTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); startTimeButton.setForeground(Color.blue); startTimeButton.addMouseListener(hoverMouseListener); startTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double startTime = DateTimeDialog.showDialog(ExportVideoDialog.this, timeSlider.getStart(), timeSlider.getMinimum(), timeSlider.getEnd()); if (startTime >= 0) { timeSlider.setStart(startTime); } } }); timeButtonPanel.add(startTimeButton, BorderLayout.WEST); durationLabel = new JLabel(); durationLabel.setHorizontalAlignment(JLabel.CENTER); timeButtonPanel.add(durationLabel, BorderLayout.CENTER); endTimeButton = new JButton(); endTimeButton.setBorder(null); endTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); endTimeButton.setForeground(Color.blue); endTimeButton.addMouseListener(hoverMouseListener); endTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double endTime = DateTimeDialog.showDialog(ExportVideoDialog.this, timeSlider.getEnd(), timeSlider.getStart(), timeSlider.getMaximum()); if (endTime >= 0) { timeSlider.setEnd(endTime); } } }); timeButtonPanel.add(endTimeButton, BorderLayout.EAST); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(10, 10, 10, 10); container.add(timeButtonPanel, c); timeSlider = new TimeSlider(); timeSlider.setValueChangeable(false); timeSlider.setValueVisible(false); timeSlider.addTimeAdjustmentListener(new TimeAdjustmentListener() { public void timeChanged(TimeEvent event) { } public void rangeChanged(TimeEvent event) { updateTimeRangeLabel(); } public void boundsChanged(TimeEvent event) { } }); updateTimeRangeLabel(); updateTimeBounds(); List<EventMarker> markers = rbnb.getMarkerManager().getMarkers(); for (EventMarker marker : markers) { timeSlider.addMarker(marker); } c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(timeSlider, c); JLabel numericHeaderLabel = new JLabel("Video Channels:"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(numericHeaderLabel, c); videoChannelList = new JList(videoChannelModel); videoChannelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); videoChannelList.setCellRenderer(new CheckListRenderer()); videoChannelList.setVisibleRowCount(10); videoChannelList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int index = videoChannelList.locationToIndex(e.getPoint()); ExportChannel item = (ExportChannel) videoChannelList.getModel().getElementAt(index); item.setSelected(!item.isSelected()); Rectangle rect = videoChannelList.getCellBounds(index, index); videoChannelList.repaint(rect); updateTimeBounds(); } }); JScrollPane scrollPane = new JScrollPane(videoChannelList); c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.weighty = 1; c.gridx = 0; c.gridy = 4; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(scrollPane, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(new JLabel("Choose Directory: "), c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; directoryTextField = new JTextField(20); c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(directoryTextField, c); directoryTextField.setText(UIUtilities.getCurrentDirectory().getAbsolutePath()); directoryButton = new JButton("Browse"); directoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { File selectedDirectory = UIUtilities.getDirectory("Select export directory"); if (selectedDirectory != null) { directoryTextField.setText(selectedDirectory.getAbsolutePath()); } } }); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 2; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(directoryButton, c); exportProgressBar = new JProgressBar(0, 100000); exportProgressBar.setStringPainted(true); exportProgressBar.setValue(0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 0; c.gridy = 6; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.CENTER; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(exportProgressBar, c); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); Action exportAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 1547500154252213911L; public void actionPerformed(ActionEvent e) { exportVideo(); } }; exportAction.putValue(Action.NAME, "Export"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "export"); actionMap.put("export", exportAction); exportButton = new JButton(exportAction); panel.add(exportButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -7440298547807878651L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); panel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.gridx = 0; c.gridy = 7; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(panel, c); pack(); if (getWidth() < 600) { setSize(600, getHeight()); } directoryTextField.requestFocusInWindow(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.ImportDialog.java
private void initComponents() { JPanel container = new JPanel(); setContentPane(container);//from ww w. ja v a 2 s.co m InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; JLabel headerLabel = new JLabel("Please specify the desired source name for the data."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 0, 0, 0); container.add(headerLabel, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(10, 10, 10, 5); container.add(new JLabel("Source name: "), c); sourceNameTextField = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(10, 0, 10, 10); container.add(sourceNameTextField, c); importProgressBar = new JProgressBar(0, 100000); importProgressBar.setStringPainted(true); importProgressBar.setValue(0); importProgressBar.setVisible(false); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 0; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.CENTER; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(importProgressBar, c); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); Action importAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -4719316285523193555L; public void actionPerformed(ActionEvent e) { importData(); } }; importAction.putValue(Action.NAME, "Import"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "import"); actionMap.put("export", importAction); importButton = new JButton(importAction); getRootPane().setDefaultButton(importButton); panel.add(importButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 7909429022904810958L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); panel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(panel, c); pack(); sourceNameTextField.requestFocusInWindow(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.LoginDialog.java
public LoginDialog(JFrame owner) { super(owner, true); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle("Login to NEES"); JPanel container = new JPanel(); setContentPane(container);/*www. j a v a2s. c o m*/ InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; headerLabel = new JLabel("Please specify your NEES account information."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 0, 0, 0); container.add(headerLabel, c); errorLabel = new JLabel(); errorLabel.setVisible(false); errorLabel.setForeground(Color.RED); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.insets = new Insets(10, 10, 0, 10); container.add(errorLabel, c); c.gridwidth = 1; userNameLabel = new JLabel("Username:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(10, 10, 10, 5); container.add(userNameLabel, c); userNameTextField = new JTextField("", 25); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(10, 0, 10, 10); container.add(userNameTextField, c); userPasswordLabel = new JLabel("Password:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 10, 10, 5); container.add(userPasswordLabel, c); userPasswordField = new JPasswordField(16); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 3; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(0, 0, 10, 10); container.add(userPasswordField, c); JPanel buttonPanel = new JPanel(); Action loginAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -5591044023056646223L; public void actionPerformed(ActionEvent e) { login(); } }; loginAction.putValue(Action.NAME, "Login"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "login"); actionMap.put("login", loginAction); loginButton = new JButton(loginAction); buttonPanel.add(loginButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 6237115705468556255L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); buttonPanel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.anchor = GridBagConstraints.LINE_END; c.insets = new Insets(0, 10, 10, 5); container.add(buttonPanel, c); pack(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.RBNBConnectionDialog.java
public RBNBConnectionDialog(JFrame owner, RBNBController rbnbController, DataPanelManager dataPanelManager) { super(owner, true); this.rbnb = rbnbController; this.dataPanelManager = dataPanelManager; setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle("Connect to RBNB Server"); JPanel container = new JPanel(); setContentPane(container);/*from ww w . j a va2 s.co m*/ InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; headerLabel = new JLabel("Please specify the RBNB server connection information."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 0, 0, 0); container.add(headerLabel, c); c.gridwidth = 1; rbnbHostNameLabel = new JLabel("Host:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(10, 10, 10, 5); container.add(rbnbHostNameLabel, c); rbnbHostNameTextField = new JTextField(25); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(10, 0, 10, 10); container.add(rbnbHostNameTextField, c); rbnbPortLabel = new JLabel("Port:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 10, 10, 5); container.add(rbnbPortLabel, c); rbnbPortTextField = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(0, 0, 10, 10); rbnbPortTextField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent focusEvent) { rbnbPortTextField.setSelectionStart(0); rbnbPortTextField.setSelectionEnd(rbnbPortTextField.getText().length()); } public void focusLost(FocusEvent focusEvent) { } }); container.add(rbnbPortTextField, c); JPanel buttonPanel = new JPanel(); Action connectAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 5814028508027064335L; public void actionPerformed(ActionEvent e) { connect(); } }; connectAction.putValue(Action.NAME, "Connect"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "connect"); actionMap.put("connect", connectAction); connectButton = new JButton(connectAction); buttonPanel.add(connectButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -679192362775669088L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); buttonPanel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.anchor = GridBagConstraints.LINE_END; c.insets = new Insets(0, 10, 10, 5); container.add(buttonPanel, c); pack(); setLocationByPlatform(true); setVisible(true); }