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:net.sf.jabref.gui.openoffice.OpenOfficePanel.java
private void initPanel() { connect.addActionListener(e -> connect(true)); manualConnect.addActionListener(e -> connect(false)); selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on")); selectDocument.addActionListener(e -> { try {//from w w w .jav a2s. c o m ooBase.selectDocument(); frame.output(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle().orElse("")); } catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException | NoSuchElementException | NoDocumentException ex) { JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Problem connecting", ex); } }); setStyleFile.addActionListener(event -> { if (styleDialog == null) { styleDialog = new StyleSelectDialog(frame, preferences, loader); } styleDialog.setVisible(true); styleDialog.getStyle().ifPresent(selectedStyle -> { style = selectedStyle; try { style.ensureUpToDate(); } catch (IOException e) { LOGGER.warn("Unable to reload style file '" + style.getPath() + "'", e); } frame.setStatus(Localization.lang("Current style is '%0'", style.getName())); }); }); pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis")); pushEntries.addActionListener(e -> pushEntries(true, true, false)); pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation")); pushEntriesInt.addActionListener(e -> pushEntries(false, true, false)); pushEntriesEmpty.setToolTipText( Localization.lang("Insert a citation without text (the entry will appear in the reference list)")); pushEntriesEmpty.addActionListener(e -> pushEntries(false, false, false)); pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information")); pushEntriesAdvanced.addActionListener(e -> pushEntries(false, true, true)); update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date")); Action updateAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { if (style == null) { style = loader.getUsedStyle(); } else { style.ensureUpToDate(); } ooBase.updateSortedReferenceMarks(); List<BibDatabase> databases = getBaseList(); List<String> unresolvedKeys = ooBase.refreshCiteMarkers(databases, style); ooBase.rebuildBibTextSection(databases, style); if (!unresolvedKeys.isEmpty()) { JOptionPane.showMessageDialog(frame, Localization.lang( "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current database.", unresolvedKeys.get(0)), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE); } } catch (UndefinedCharacterFormatException ex) { reportUndefinedCharacterFormat(ex); } catch (UndefinedParagraphFormatException ex) { reportUndefinedParagraphFormat(ex); } catch (ConnectionLostException ex) { showConnectionLostErrorMessage(); } catch (IOException ex) { JOptionPane.showMessageDialog(frame, Localization.lang( "You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Problem with style file", ex); } catch (BibEntryNotFoundException ex) { JOptionPane.showMessageDialog(frame, Localization.lang( "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current database.", ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE); LOGGER.debug("BibEntry not found", ex); } catch (Exception ex) { LOGGER.warn("Could not update bibliography", ex); } } }; update.addActionListener(updateAction); merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only")); merge.addActionListener(e -> { try { ooBase.combineCiteMarkers(getBaseList(), style); } catch (UndefinedCharacterFormatException ex) { reportUndefinedCharacterFormat(ex); } catch (Exception ex) { LOGGER.warn("Problem combining cite markers", ex); } }); settingsB.addActionListener(e -> showSettingsPopup()); manageCitations.addActionListener(e -> { try { CitationManager cm = new CitationManager(frame, ooBase); cm.showDialog(); } catch (NoSuchElementException | WrappedTargetException | UnknownPropertyException ex) { LOGGER.warn("Problem showing citation manager", ex); } }); selectDocument.setEnabled(false); pushEntries.setEnabled(false); pushEntriesInt.setEnabled(false); pushEntriesEmpty.setEnabled(false); pushEntriesAdvanced.setEnabled(false); update.setEnabled(false); merge.setEnabled(false); manageCitations.setEnabled(false); diag = new JDialog((JFrame) null, "OpenOffice/LibreOffice panel", false); FormBuilder mainBuilder = FormBuilder.create() .layout(new FormLayout("fill:pref:grow", "p,p,p,p,p,p,p,p,p,p")); FormBuilder topRowBuilder = FormBuilder.create() .layout(new FormLayout("fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, " + "1dlu, fill:pref:grow, 1dlu, fill:pref:grow", "pref")); topRowBuilder.add(connect).xy(1, 1); topRowBuilder.add(manualConnect).xy(3, 1); topRowBuilder.add(selectDocument).xy(5, 1); topRowBuilder.add(update).xy(7, 1); topRowBuilder.add(help).xy(9, 1); mainBuilder.add(topRowBuilder.getPanel()).xy(1, 1); mainBuilder.add(setStyleFile).xy(1, 2); mainBuilder.add(pushEntries).xy(1, 3); mainBuilder.add(pushEntriesInt).xy(1, 4); mainBuilder.add(pushEntriesAdvanced).xy(1, 5); mainBuilder.add(pushEntriesEmpty).xy(1, 6); mainBuilder.add(merge).xy(1, 7); mainBuilder.add(manageCitations).xy(1, 8); mainBuilder.add(settingsB).xy(1, 9); JPanel content = new JPanel(); comp.setContentContainer(content); content.setLayout(new BorderLayout()); content.add(mainBuilder.getPanel(), BorderLayout.CENTER); frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO"); frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java
/** * Sets the chat session to associate to this chat panel. * @param chatSession the chat session to associate to this chat panel *//*w ww .ja v a2 s .c o m*/ public void setChatSession(ChatSession chatSession) { if (this.chatSession != null) { // remove old listener this.chatSession.removeChatTransportChangeListener(this); } this.chatSession = chatSession; this.chatSession.addChatTransportChangeListener(this); if ((this.chatSession != null) && this.chatSession.isContactListSupported()) { topPanel.remove(conversationPanelContainer); TransparentPanel rightPanel = new TransparentPanel(new BorderLayout()); Dimension chatConferencesListsPanelSize = new Dimension(150, 25); Dimension chatContactsListsPanelSize = new Dimension(150, 175); Dimension rightPanelSize = new Dimension(150, 200); rightPanel.setMinimumSize(rightPanelSize); rightPanel.setPreferredSize(rightPanelSize); TransparentPanel contactsPanel = new TransparentPanel(new BorderLayout()); contactsPanel.setMinimumSize(chatContactsListsPanelSize); contactsPanel.setPreferredSize(chatContactsListsPanelSize); conferencePanel.setMinimumSize(chatConferencesListsPanelSize); conferencePanel.setPreferredSize(chatConferencesListsPanelSize); this.chatContactListPanel = new ChatRoomMemberListPanel(this); this.chatContactListPanel.setOpaque(false); topSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); topSplitPane.setBorder(null); // remove default borders topSplitPane.setOneTouchExpandable(true); topSplitPane.setOpaque(false); topSplitPane.setResizeWeight(1.0D); Color msgNameBackground = Color.decode(ChatHtmlUtils.MSG_NAME_BACKGROUND); // add border to the divider if (topSplitPane.getUI() instanceof BasicSplitPaneUI) { ((BasicSplitPaneUI) topSplitPane.getUI()).getDivider() .setBorder(BorderFactory.createLineBorder(msgNameBackground)); } ChatTransport chatTransport = chatSession.getCurrentChatTransport(); JPanel localUserLabelPanel = new JPanel(new BorderLayout()); JLabel localUserLabel = new JLabel(chatTransport.getProtocolProvider().getAccountID().getDisplayName()); localUserLabel.setFont(localUserLabel.getFont().deriveFont(Font.BOLD)); localUserLabel.setHorizontalAlignment(SwingConstants.CENTER); localUserLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 3, 0)); localUserLabel.setForeground(Color.decode(ChatHtmlUtils.MSG_IN_NAME_FOREGROUND)); localUserLabelPanel.add(localUserLabel, BorderLayout.CENTER); localUserLabelPanel.setBackground(msgNameBackground); JButton joinConference = new JButton( GuiActivator.getResources().getI18NString("service.gui.JOIN_VIDEO")); joinConference.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { showChatConferenceDialog(); } }); contactsPanel.add(localUserLabelPanel, BorderLayout.NORTH); contactsPanel.add(chatContactListPanel, BorderLayout.CENTER); conferencePanel.add(joinConference, BorderLayout.CENTER); rightPanel.add(conferencePanel, BorderLayout.NORTH); rightPanel.add(contactsPanel, BorderLayout.CENTER); topSplitPane.setLeftComponent(conversationPanelContainer); topSplitPane.setRightComponent(rightPanel); topPanel.add(topSplitPane); } else { if (topSplitPane != null) { if (chatContactListPanel != null) { topSplitPane.remove(chatContactListPanel); chatContactListPanel = null; } this.messagePane.remove(topSplitPane); topSplitPane = null; } topPanel.add(conversationPanelContainer); } if (chatSession instanceof MetaContactChatSession) { // The subject panel is added here, because it's specific for the // multi user chat and is not contained in the single chat chat panel. if (subjectPanel != null) { this.remove(subjectPanel); subjectPanel = null; this.revalidate(); this.repaint(); } writeMessagePanel.initPluginComponents(); writeMessagePanel.setTransportSelectorBoxVisible(true); //Enables to change the protocol provider by simply pressing the // CTRL-P key combination ActionMap amap = this.getActionMap(); amap.put("ChangeProtocol", new ChangeTransportAction()); InputMap imap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK), "ChangeProtocol"); } else if (chatSession instanceof ConferenceChatSession) { ConferenceChatSession confSession = (ConferenceChatSession) chatSession; writeMessagePanel.setTransportSelectorBoxVisible(false); confSession.addLocalUserRoleListener(this); confSession.addMemberRoleListener(this); ChatRoom room = ((ChatRoomWrapper) chatSession.getDescriptor()).getChatRoom(); room.addMemberPropertyChangeListener(this); setConferencesPanelVisible(room.getCachedConferenceDescriptionSize() > 0); subjectPanel = new ChatRoomSubjectPanel((ConferenceChatSession) chatSession); // The subject panel is added here, because it's specific for the // multi user chat and is not contained in the single chat chat panel. this.add(subjectPanel, BorderLayout.NORTH); this.revalidate(); this.repaint(); } if (chatContactListPanel != null) { // Initialize chat participants' panel. Iterator<ChatContact<?>> chatParticipants = chatSession.getParticipants(); while (chatParticipants.hasNext()) chatContactListPanel.addContact(chatParticipants.next()); } }
From source file:net.sf.jabref.openoffice.StyleSelectDialog.java
private void init(String inSelection) { this.initSelection = inSelection; ButtonGroup bg = new ButtonGroup(); bg.add(useDefaultAuthoryear);/*from www. j a va 2 s . co m*/ bg.add(useDefaultNumerical); bg.add(chooseDirectly); bg.add(setDirectory); if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE)) { useDefaultAuthoryear.setSelected(true); } else if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE)) { useDefaultNumerical.setSelected(true); } else { if (Globals.prefs.getBoolean(JabRefPreferences.OO_CHOOSE_STYLE_DIRECTLY)) { chooseDirectly.setSelected(true); } else { setDirectory.setSelected(true); } } directFile.setText(Globals.prefs.get(JabRefPreferences.OO_DIRECT_FILE)); styleDir.setText(Globals.prefs.get(JabRefPreferences.OO_STYLE_DIRECTORY)); directFile.setEditable(false); styleDir.setEditable(false); popup.add(edit); BrowseAction dfBrowse = BrowseAction.buildForFile(directFile, directFile); browseDirectFile.addActionListener(dfBrowse); BrowseAction sdBrowse = BrowseAction.buildForDir(styleDir, setDirectory); browseStyleDir.addActionListener(sdBrowse); showDefaultAuthoryearStyle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { displayDefaultStyle(true); } }); showDefaultNumericalStyle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { displayDefaultStyle(false); } }); // Add action listener to "Edit" menu item, which is supposed to open the style file in an external editor: edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { int i = table.getSelectedRow(); if (i == -1) { return; } ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("jstyle"); String link = tableModel.getElementAt(i).getFile().getPath(); try { if (type == null) { JabRefDesktop.openExternalFileUnknown(frame, new BibEntry(), new MetaData(), link, new UnknownExternalFileType("jstyle")); } else { JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type); } } catch (IOException e) { LOGGER.warn("Problem open style file editor", e); } } }); diag = new JDialog(frame, Localization.lang("Styles"), true); styles = new BasicEventList<>(); EventList<OOBibStyle> sortedStyles = new SortedList<>(styles); // Create a preview panel for previewing styles: preview = new PreviewPanel(null, new MetaData(), ""); // Use the test entry from the Preview settings tab in Preferences: preview.setEntry(prevEntry); tableModel = (DefaultEventTableModel<OOBibStyle>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedStyles, new StyleTableFormat()); table = new JTable(tableModel); TableColumnModel cm = table.getColumnModel(); cm.getColumn(0).setPreferredWidth(100); cm.getColumn(1).setPreferredWidth(200); cm.getColumn(2).setPreferredWidth(80); selectionModel = (DefaultEventSelectionModel<OOBibStyle>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedStyles); table.setSelectionModel(selectionModel); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { tablePopup(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { tablePopup(mouseEvent); } } }); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); styleDir.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { readStyles(); setDirectory.setSelected(true); } @Override public void removeUpdate(DocumentEvent documentEvent) { readStyles(); setDirectory.setSelected(true); } @Override public void changedUpdate(DocumentEvent documentEvent) { readStyles(); setDirectory.setSelected(true); } }); directFile.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { chooseDirectly.setSelected(true); } @Override public void removeUpdate(DocumentEvent documentEvent) { chooseDirectly.setSelected(true); } @Override public void changedUpdate(DocumentEvent documentEvent) { chooseDirectly.setSelected(true); } }); contentPane.setTopComponent(new JScrollPane(table)); contentPane.setBottomComponent(preview); readStyles(); DefaultFormBuilder b = new DefaultFormBuilder( new FormLayout("fill:pref,4dlu,fill:150dlu,4dlu,fill:pref", "")); b.append(useDefaultAuthoryear, 3); b.append(showDefaultAuthoryearStyle); b.nextLine(); b.append(useDefaultNumerical, 3); b.append(showDefaultNumericalStyle); b.nextLine(); b.append(chooseDirectly); b.append(directFile); b.append(browseDirectFile); b.nextLine(); b.append(setDirectory); b.append(styleDir); b.append(browseStyleDir); b.nextLine(); DefaultFormBuilder b2 = new DefaultFormBuilder( new FormLayout("fill:1dlu:grow", "fill:pref, fill:pref, fill:270dlu:grow")); b2.nextLine(); b2.append(new JLabel("<html>" + Localization.lang("This is the list of available styles. Select the one you want to use.") + "</html>")); b2.nextLine(); b2.append(contentPane); b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); b2.getPanel().setBorder(BorderFactory.createEmptyBorder(15, 5, 5, 5)); diag.add(b.getPanel(), BorderLayout.NORTH); diag.add(b2.getPanel(), BorderLayout.CENTER); AbstractAction okListener = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { if (!useDefaultAuthoryear.isSelected() && !useDefaultNumerical.isSelected()) { if (chooseDirectly.isSelected()) { File f = new File(directFile.getText()); if (!f.exists()) { JOptionPane.showMessageDialog(diag, Localization.lang( "You must select either a valid style file, or use a default style."), Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE); return; } } else { if ((table.getRowCount() == 0) || (table.getSelectedRowCount() == 0)) { JOptionPane.showMessageDialog(diag, Localization.lang( "You must select either a valid style file, or use a default style."), Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE); return; } } } okPressed = true; storeSettings(); diag.dispose(); } }; ok.addActionListener(okListener); Action cancelListener = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { diag.dispose(); } }; cancel.addActionListener(cancelListener); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diag.add(bb.getPanel(), BorderLayout.SOUTH); ActionMap am = bb.getPanel().getActionMap(); InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelListener); im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk"); am.put("enterOk", okListener); diag.pack(); diag.setLocationRelativeTo(frame); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { contentPane.setDividerLocation(contentPane.getSize().height - 150); } }); }
From source file:ch.epfl.lis.gnwgui.NetworkGraph.java
/** * Add a key listener to print the content of the JPanel in which the graph is drawn. * @param jp JPanel that contains the network graph. *///from w w w . j a v a 2 s . c o m @SuppressWarnings("serial") public void addPrintAction(JComponent jp) { KeyStroke k = KeyStroke.getKeyStroke("alt P"); jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(k, "printscreen"); jp.getActionMap().put("printscreen", new AbstractAction() { public void actionPerformed(ActionEvent arg0) { item_.getNetworkViewer().getControl().printGraph(); } }); }
From source file:net.sf.jabref.openoffice.OpenOfficePanel.java
private void initPanel() { useDefaultAuthoryearStyle = Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE); useDefaultNumericalStyle = Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE); connect.addActionListener(e -> connect(true)); manualConnect.addActionListener(e -> connect(false)); selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on")); selectDocument.addActionListener(e -> { try {/* w w w .java 2s. c o m*/ ooBase.selectDocument(); frame.output(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle().orElse("")); } catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException | NoSuchElementException | NoDocumentException ex) { JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Problem connecting", ex); } }); setStyleFile.addActionListener(e -> { if (styleDialog == null) { styleDialog = new StyleSelectDialog(frame, styleFile); } styleDialog.setVisible(true); if (styleDialog.isOkPressed()) { useDefaultAuthoryearStyle = Globals.prefs .getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE); useDefaultNumericalStyle = Globals.prefs .getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE); styleFile = Globals.prefs.get(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE); try { readStyleFile(); } catch (IOException ex) { LOGGER.warn("Could not read style file", ex); } } }); pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis")); pushEntries.addActionListener(e -> pushEntries(true, true, false)); pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation")); pushEntriesInt.addActionListener(e -> pushEntries(false, true, false)); pushEntriesEmpty.setToolTipText( Localization.lang("Insert a citation without text (the entry will appear in the reference list)")); pushEntriesEmpty.addActionListener(e -> pushEntries(false, false, false)); pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information")); pushEntriesAdvanced.addActionListener(e -> pushEntries(false, true, true)); update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date")); Action updateAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { if (style == null) { readStyleFile(); } else { style.ensureUpToDate(); } ooBase.updateSortedReferenceMarks(); List<BibDatabase> databases = getBaseList(); List<String> unresolvedKeys = ooBase.refreshCiteMarkers(databases, style); ooBase.rebuildBibTextSection(databases, style); if (!unresolvedKeys.isEmpty()) { JOptionPane.showMessageDialog(frame, Localization.lang( "Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.", unresolvedKeys.get(0)), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE); } } catch (UndefinedCharacterFormatException ex) { reportUndefinedCharacterFormat(ex); } catch (UndefinedParagraphFormatException ex) { reportUndefinedParagraphFormat(ex); } catch (ConnectionLostException ex) { showConnectionLostErrorMessage(); } catch (IOException ex) { JOptionPane.showMessageDialog(frame, Localization.lang( "You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Problem with style file", ex); return; } catch (BibEntryNotFoundException ex) { JOptionPane.showMessageDialog(frame, Localization.lang( "Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.", ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE); LOGGER.debug("BibEntry not found", ex); } catch (Exception ex) { LOGGER.warn("Could not update bibliography", ex); } } }; update.addActionListener(updateAction); merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only")); merge.addActionListener(e -> { try { ooBase.combineCiteMarkers(getBaseList(), style); } catch (UndefinedCharacterFormatException ex) { reportUndefinedCharacterFormat(ex); } catch (Exception ex) { LOGGER.warn("Problem combining cite markers", ex); } }); settingsB.addActionListener(e -> showSettingsPopup()); manageCitations.addActionListener(e -> { try { CitationManager cm = new CitationManager(frame, ooBase); cm.showDialog(); } catch (NoSuchElementException | WrappedTargetException | UnknownPropertyException ex) { LOGGER.warn("Problem showing citation manager", ex); } }); selectDocument.setEnabled(false); pushEntries.setEnabled(false); pushEntriesInt.setEnabled(false); pushEntriesEmpty.setEnabled(false); pushEntriesAdvanced.setEnabled(false); update.setEnabled(false); merge.setEnabled(false); manageCitations.setEnabled(false); diag = new JDialog((JFrame) null, "OpenOffice panel", false); DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("fill:pref:grow", //"p,0dlu,p,0dlu,p,0dlu,p,0dlu,p,0dlu,p,0dlu,p,0dlu,p,0dlu,p,0dlu,p,0dlu")); "p,p,p,p,p,p,p,p,p,p")); //ButtonBarBuilder bb = new ButtonBarBuilder(); DefaultFormBuilder bb = new DefaultFormBuilder( new FormLayout("fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, " + "1dlu, fill:pref:grow, 1dlu, fill:pref:grow", "")); bb.append(connect); bb.append(manualConnect); bb.append(selectDocument); bb.append(update); bb.append(help); b.append(bb.getPanel()); b.append(setStyleFile); b.append(pushEntries); b.append(pushEntriesInt); b.append(pushEntriesAdvanced); b.append(pushEntriesEmpty); b.append(merge); b.append(manageCitations); b.append(settingsB); JPanel content = new JPanel(); comp.setContentContainer(content); content.setLayout(new BorderLayout()); content.add(b.getPanel(), BorderLayout.CENTER); frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO"); frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction); }
From source file:net.sf.jabref.gui.ImportInspectionDialog.java
/** * Creates a dialog that displays the given list of fields in the table. The * dialog allows another process to add entries dynamically while the dialog * is shown./*from w w w. j a v a 2 s . c o m*/ * * @param frame * @param panel */ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoName, boolean newDatabase) { this.frame = frame; this.panel = panel; this.bibDatabaseContext = (panel == null) ? null : panel.getBibDatabaseContext(); this.undoName = undoName; this.newDatabase = newDatabase; setIconImage(new ImageIcon(IconTheme.getIconUrl("jabrefIcon48")).getImage()); preview = new PreviewPanel(null, bibDatabaseContext, Globals.prefs.get(JabRefPreferences.PREVIEW_0)); duplLabel.setToolTipText(Localization.lang("Possible duplicate of existing entry. Click to resolve.")); sortedList = new SortedList<>(entries); DefaultEventTableModel<BibEntry> tableModelGl = (DefaultEventTableModel<BibEntry>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedList, new EntryTableFormat()); glTable = new EntryTable(tableModelGl); GeneralRenderer renderer = new GeneralRenderer(Color.white); glTable.setDefaultRenderer(JLabel.class, renderer); glTable.setDefaultRenderer(String.class, renderer); glTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), "delete"); DeleteListener deleteListener = new DeleteListener(); glTable.getActionMap().put("delete", deleteListener); selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedList); glTable.setSelectionModel(selectionModel); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); comparatorChooser = TableComparatorChooser.install(glTable, sortedList, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); setupComparatorChooser(); glTable.addMouseListener(new TableClickListener()); setWidths(); getContentPane().setLayout(new BorderLayout()); progressBar.setIndeterminate(true); JPanel centerPan = new JPanel(); centerPan.setLayout(new BorderLayout()); contentPane.setTopComponent(new JScrollPane(glTable)); contentPane.setBottomComponent(preview); centerPan.add(contentPane, BorderLayout.CENTER); centerPan.add(progressBar, BorderLayout.SOUTH); popup.add(deleteListener); popup.addSeparator(); if (!newDatabase && (bibDatabaseContext != null)) { GroupTreeNode node = bibDatabaseContext.getMetaData().getGroups(); JMenu groupsAdd = new JMenu(Localization.lang("Add to group")); groupsAdd.setEnabled(false); // Will get enabled if there are groups that can be added to. insertNodes(groupsAdd, node); popup.add(groupsAdd); } // Add "Attach file" menu choices to right click menu: popup.add(new LinkLocalFile()); popup.add(new DownloadFile()); popup.add(new AutoSetLinks()); popup.add(new AttachUrl()); getContentPane().add(centerPan, BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(ok); bb.addButton(stop); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addRelatedGap(); JButton help = new HelpAction(HelpFile.IMPORT_INSPECTION).getHelpButton(); bb.addButton(help); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); ButtonStackBuilder builder = new ButtonStackBuilder(); JButton selectAll = new JButton(Localization.lang("Select all")); builder.addButton(selectAll); JButton deselectAll = new JButton(Localization.lang("Deselect all")); builder.addButton(deselectAll); builder.addButton(deselectAllDuplicates); builder.addRelatedGap(); JButton delete = new JButton(Localization.lang("Delete")); builder.addButton(delete); builder.addRelatedGap(); builder.addFixed(autoGenerate); builder.addButton(generate); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); centerPan.add(builder.getPanel(), BorderLayout.WEST); ok.setEnabled(false); generate.setEnabled(false); ok.addActionListener(new OkListener()); cancel.addActionListener(e -> { signalStopFetching(); dispose(); frame.output(Localization.lang("Import canceled by user")); }); generate.addActionListener(e -> { generate.setEnabled(false); generatedKeys = true; // To prevent the button from getting // enabled again. generateKeys(); // Generate the keys. }); stop.addActionListener(e -> { signalStopFetching(); entryListComplete(); }); selectAll.addActionListener(new SelectionButton(true)); deselectAll.addActionListener(new SelectionButton(false)); deselectAllDuplicates.addActionListener(e -> { for (int i = 0; i < glTable.getRowCount(); i++) { if (glTable.getValueAt(i, DUPL_COL) != null) { glTable.setValueAt(false, i, 0); } } glTable.repaint(); }); deselectAllDuplicates.setEnabled(false); delete.addActionListener(deleteListener); getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // Remember and default to last size: setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH), Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT))); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { contentPane.setDividerLocation(0.5f); } @Override public void windowClosed(WindowEvent e) { Globals.prefs.putInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH, getSize().width); Globals.prefs.putInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT, getSize().height); } }); // Key bindings: Action closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; ActionMap am = contentPane.getActionMap(); InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", closeAction); }
From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java
@Override protected JRootPane createRootPane() { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); JRootPane rp = super.createRootPane(); rp.registerKeyboardAction(new ActionListener() { @Override/*from w w w . j a va 2 s .co m*/ public void actionPerformed(final ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rp; }
From source file:com.osparking.attendant.AttListForm.java
/** * Creates new form AttListForm/*from ww w . j av a 2s . c o m*/ */ public AttListForm(IMainGUI mainGUI, String loginID, String loginPW, boolean isManager) { // Mark the first row as selected in default this.mainGUI = mainGUI; try { initComponents(); setLocation(0, 0); setIconImages(OSPiconList); // Reset search column combobox items searchCriteriaComboBox.removeAllItems(); searchCriteriaComboBox.addItem(new ConvComboBoxItem(LOGIN_ID_LABEL, LOGIN_ID_LABEL.getContent())); searchCriteriaComboBox.addItem(new ConvComboBoxItem(NAME_LABEL, NAME_LABEL.getContent())); // Make last 8 digits of the user ID visible on the user password label. String id = loginID; if (loginID.length() > 8) { id = ".." + loginID.substring(loginID.length() - 8); } userPWLabel.setText(id + " " + MY_PW_LABEL.getContent()); this.loginID = loginID; this.loginPW = loginPW; this.isManager = isManager; initComponentsUser(); // limit maximun allowed length of user IDa userIDText.setDocument(new JTextFieldLimit(20)); ListSelectionModel model = usersTable.getSelectionModel(); model.addListSelectionListener(new AttendantRowSelectionListener()); setFormMode(FormMode.NormalMode); loadAttendantTable(""); int selectIndex = searchRow(loginID); if (rowHidden(usersTable, selectIndex)) { usersTable.changeSelection(selectIndex, 0, false, false); } else { usersTable.setRowSelectionInterval(selectIndex, selectIndex); } usersTable.requestFocus(); usersTable.getRowSorter().addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(final RowSorterEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (e.getType() == RowSorterEvent.Type.SORTED) { if (usersTable.getSelectedRow() != -1) { usersTable.scrollRectToVisible( usersTable.getCellRect(usersTable.getSelectedRow(), 0, false)); } } } }); } }); } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(AttListForm Constructor ID: " + loginID + ")"); } JComponent pane = (JComponent) this.getContentPane(); pane.getInputMap().put(null, MUTEX_DEBUG_SEQ_VALUE); addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { searchText.requestFocus(); } }); attachEnterHandler(searchText); adminAuth2CheckBox.setSelected(isManager); KeyStroke controlF = KeyStroke.getKeyStroke("control F"); JRootPane rootPane = getRootPane(); rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(controlF, "myAction"); rootPane.getActionMap().put("myAction", new Ctrl_F_Action(searchText)); }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
@Override protected JRootPane createRootPane() { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); JRootPane rp = super.createRootPane(); rp.registerKeyboardAction(new ActionListener() { @Override/* ww w . j a v a2s.c om*/ public void actionPerformed(final ActionEvent e) { // reset and edit again when canceled editOrCancelLoadProfileEntity(); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rp; }
From source file:edu.umich.robot.GuiApplication.java
/** * Entry point./*w w w . j ava 2 s . c o m*/ * * @param args Args from command line. */ public GuiApplication(Config config) { // Heavyweight is not desirable but it is the only thing that will // render in front of the Viewer on all platforms. Blame OpenGL JPopupMenu.setDefaultLightWeightPopupEnabled(false); ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); // must have config //Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig(frame); if (config == null) System.exit(1); // Add more stuff to the config file that doesn't change between runs. Application.setupSimulatorConfig(config); setupViewerConfig(config); Configs.toLog(logger, config); controller = new Controller(config, new Gamepad()); controller.initializeGamepad(); viewer = new Viewer(config, frame); // This puts us in full 3d mode by default. The Viewer GUI doesn't // reflect this in its right click drop-down, a bug. viewer.getVisCanvas().getViewManager().setInterfaceMode(3); controller.addListener(RobotAddedEvent.class, listener); controller.addListener(RobotRemovedEvent.class, listener); controller.addListener(AfterResetEvent.class, listener); controller.addListener(ControllerActivatedEvent.class, listener); controller.addListener(ControllerDeactivatedEvent.class, listener); actionManager = new ActionManager(this); initActions(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { controller.shutdown(); System.exit(0); } }); frame.setLayout(new BorderLayout()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.add(actionManager.getAction(CreateSplinterRobotAction.class)); fileMenu.add(actionManager.getAction(CreateSuperdroidRobotAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ConnectSuperdroidAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ResetPreferencesAction.class)); /* fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(TextMessageAction.class)); */ fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(SaveMapAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ExitAction.class)); menuBar.add(fileMenu); JMenu cameraMenu = new JMenu("Camera"); cameraMenu.add(actionManager.getAction(DisableFollowAction.class)); cameraMenu.add(actionManager.getAction(FollowPositionAction.class)); cameraMenu.add(actionManager.getAction(FollowPositionAndThetaAction.class)); cameraMenu.add(new JSeparator()); cameraMenu.add(actionManager.getAction(MoveCameraBehindAction.class)); cameraMenu.add(actionManager.getAction(MoveCameraAboveAction.class)); menuBar.add(cameraMenu); JMenu objectMenu = new JMenu("Objects"); boolean added = false; for (String objectName : controller.getObjectNames()) { added = true; objectMenu.add(new AddObjectAction(this, objectName)); } if (!added) objectMenu.add(new JLabel("No objects available")); menuBar.add(objectMenu); menuBar.revalidate(); frame.setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); toolBar.add(actionManager.getAction(SoarParametersAction.class)); toolBar.add(actionManager.getAction(SoarDataAction.class)); toolBar.add(actionManager.getAction(ResetAction.class)); toolBar.add(actionManager.getAction(SoarToggleAction.class)); toolBar.add(actionManager.getAction(SoarStepAction.class)); toolBar.add(actionManager.getAction(SimSpeedAction.class)); frame.add(toolBar, BorderLayout.PAGE_START); viewerView = new ViewerView(viewer.getVisCanvas()); robotsView = new RobotsView(this, actionManager); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, viewerView, robotsView); splitPane.setDividerLocation(0.75); // TODO SoarApril /* viewer.addRobotSelectionChangedListener(robotsView); viewer.getVisCanvas().setDrawGround(true); */ viewer.getVisCanvas().addEventHandler(new VisCanvasEventAdapter() { public String getName() { return "Place Object"; } @Override public boolean mouseClicked(VisCanvas vc, GRay3D ray, MouseEvent e) { boolean ret = false; synchronized (GuiApplication.this) { if (objectToAdd != null && controller != null) { controller.addObject(objectToAdd, ray.intersectPlaneXY()); objectToAdd = null; ret = true; } else { double[] click = ray.intersectPlaneXY(); chatView.setClick(new Point2D.Double(click[0], click[1])); } } status.setMessage( String.format("%3.1f,%3.1f", ray.intersectPlaneXY()[0], ray.intersectPlaneXY()[1])); return ret; } }); consoleView = new ConsoleView(); chatView = new ChatView(this); controller.getRadio().addRadioHandler(chatView); final JSplitPane bottomPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, consoleView, chatView); bottomPane.setDividerLocation(200); final JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane, bottomPane); splitPane2.setDividerLocation(0.75); frame.add(splitPane2, BorderLayout.CENTER); status = new StatusBar(); frame.add(status, BorderLayout.SOUTH); /* frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { final Preferences windowPrefs = getWindowPreferences(); final Rectangle r = frame.getBounds(); if(frame.getExtendedState() == JFrame.NORMAL) { windowPrefs.putInt("x", r.x); windowPrefs.putInt("y", r.y); windowPrefs.putInt("width", r.width); windowPrefs.putInt("height", r.height); windowPrefs.putInt("divider", splitPane.getDividerLocation()); } exit(); }}); Preferences windowPrefs = getWindowPreferences(); if (windowPrefs.get("x", null) != null) { frame.setBounds( windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 1200), windowPrefs.getInt("height", 900)); splitPane.setDividerLocation(windowPrefs.getInt("divider", 500)); } else { frame.setBounds( windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 1200), windowPrefs.getInt("height", 900)); splitPane.setDividerLocation(0.75); frame.setLocationRelativeTo(null); // center } */ frame.getRootPane().setBounds(0, 0, 1600, 1200); frame.getRootPane().registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); frame.pack(); frame.setVisible(true); for (String s : config.getStrings("splinters", new String[0])) { double[] pos = config.getDoubles(s + ".position"); if (pos == null) { logger.error("Splinter indexed in config file but no position defined: " + s); continue; } Pose pose = new Pose(pos); String prods = config.getString(s + ".productions"); boolean collisions = config.getBoolean(s + ".wallCollisions", true); controller.createSplinterRobot(s, pose, collisions); boolean simulated = config.getBoolean(s + ".simulated", true); if (simulated) controller.createSimSplinter(s); else controller.createRealSplinter(s); controller.createSimLaser(s); if (prods != null) { controller.createSoarController(s, s, prods, config.getChild(s + ".properties")); PREFERENCES.put("lastProductions", prods); } } for (String s : config.getStrings("superdroids", new String[0])) { double[] pos = config.getDoubles(s + ".position"); if (pos == null) { logger.error("Superdroid indexed in config file but no position defined: " + s); continue; } Pose pose = new Pose(pos); String prods = config.getString(s + ".productions"); boolean collisions = config.getBoolean(s + ".wallCollisions", true); controller.createSuperdroidRobot(s, pose, collisions); boolean simulated = config.getBoolean(s + ".simulated", true); if (simulated) controller.createSimSuperdroid(s); else { try { controller.createRealSuperdroid(s, "192.168.1.165", 3192); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (SocketException e1) { e1.printStackTrace(); } } controller.createSimLaser(s); if (prods != null) { // wait a sec try { Thread.sleep(1000); } catch (InterruptedException ex) { } controller.createSoarController(s, s, prods, config.getChild(s + ".properties")); PREFERENCES.put("lastProductions", prods); } } }