- Replaced find field with a search button that displays a moveable, resizable non-modal search dialog.
Esse commit está contido em:
+28
-12
@@ -32,12 +32,12 @@ import org.protege.editor.owl.model.selection.OWLSelectionModelImpl;
|
||||
import org.protege.editor.owl.ui.OWLEntityCreationPanel;
|
||||
import org.protege.editor.owl.ui.OWLWorkspaceViewsTab;
|
||||
import org.protege.editor.owl.ui.action.ProtegeOWLAction;
|
||||
import org.protege.editor.owl.ui.find.EntityFinderField;
|
||||
import org.protege.editor.owl.ui.inference.*;
|
||||
import org.protege.editor.owl.ui.navigation.OWLEntityNavPanel;
|
||||
import org.protege.editor.owl.ui.ontology.OntologySourcesChangedHandlerUI;
|
||||
import org.protege.editor.owl.ui.preferences.AnnotationPreferences;
|
||||
import org.protege.editor.owl.ui.renderer.*;
|
||||
import org.protege.editor.owl.ui.search.SearchDialogPanel;
|
||||
import org.protege.editor.owl.ui.util.OWLComponentFactory;
|
||||
import org.protege.editor.owl.ui.util.OWLComponentFactoryImpl;
|
||||
import org.semanticweb.owlapi.model.*;
|
||||
@@ -135,11 +135,11 @@ public class OWLWorkspace extends TabbedWorkspace implements SendErrorReportHand
|
||||
return (OWLEditorKit) getEditorKit();
|
||||
}
|
||||
|
||||
|
||||
public OWLModelManager getOWLModelManager() {
|
||||
return getOWLEditorKit().getModelManager();
|
||||
}
|
||||
|
||||
private JDialog searchDialog;
|
||||
|
||||
public void initialise() {
|
||||
entityDisplayProviders = new ArrayList<>();
|
||||
@@ -634,7 +634,7 @@ public class OWLWorkspace extends TabbedWorkspace implements SendErrorReportHand
|
||||
100, 0,
|
||||
GridBagConstraints.BASELINE,
|
||||
GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 2, 0, 2),
|
||||
new Insets(0, 0, 0, 0),
|
||||
0, 0
|
||||
));
|
||||
|
||||
@@ -647,10 +647,13 @@ public class OWLWorkspace extends TabbedWorkspace implements SendErrorReportHand
|
||||
}
|
||||
});
|
||||
|
||||
final EntityFinderField entityFinderField = new EntityFinderField(this, getOWLEditorKit());
|
||||
entityFinderField.setPreferredSize(new Dimension(250, 30));
|
||||
entityFinderField.setMinimumSize(new Dimension(250, 30));
|
||||
topBarPanel.add(entityFinderField, new GridBagConstraints(
|
||||
JButton searchButton = new JButton(new AbstractAction("Search...") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showSearchDialog();
|
||||
}
|
||||
});
|
||||
topBarPanel.add(searchButton, new GridBagConstraints(
|
||||
2, 0,
|
||||
1, 1,
|
||||
0, 0,
|
||||
@@ -684,22 +687,35 @@ public class OWLWorkspace extends TabbedWorkspace implements SendErrorReportHand
|
||||
|
||||
add(topBarPanel, BorderLayout.NORTH);
|
||||
|
||||
// Find focus accelerator
|
||||
KeyStroke findKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(findKeyStroke, "FOCUS_FIND");
|
||||
getActionMap().put("FOCUS_FIND", new AbstractAction() {
|
||||
KeyStroke findKeyStroke = KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_F,
|
||||
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(findKeyStroke, "SHOW_SEARCH_DIALOG");
|
||||
getActionMap().put("SHOW_SEARCH_DIALOG", new AbstractAction() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2205711779338124168L;
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
entityFinderField.requestFocus();
|
||||
showSearchDialog();
|
||||
}
|
||||
});
|
||||
updateTitleBar();
|
||||
}
|
||||
|
||||
public void showSearchDialog() {
|
||||
if(searchDialog == null) {
|
||||
searchDialog = SearchDialogPanel.createDialog(this, getOWLEditorKit());
|
||||
Point workspaceLocation = getLocation();
|
||||
Dimension workspaceSize = getSize();
|
||||
SwingUtilities.convertPointToScreen(workspaceLocation, this);
|
||||
workspaceLocation.translate(workspaceSize.width - searchDialog.getWidth() - 10, 0);
|
||||
searchDialog.setLocation(workspaceLocation);
|
||||
}
|
||||
searchDialog.setVisible(true);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
altTitle = title;
|
||||
updateTitleBar();
|
||||
|
||||
+1
@@ -8,6 +8,7 @@ import java.beans.PropertyChangeListener;
|
||||
import javax.swing.FocusManager;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.protege.editor.owl.ui.search.SearchDialogPanel;
|
||||
import org.protege.editor.owl.ui.view.Findable;
|
||||
|
||||
|
||||
|
||||
+2
@@ -2,6 +2,7 @@ package org.protege.editor.owl.ui.find;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import org.protege.editor.core.ui.util.AugmentedJTextField;
|
||||
import org.protege.editor.core.ui.util.JOptionPaneEx;
|
||||
import org.protege.editor.owl.OWLEditorKit;
|
||||
import org.protege.editor.owl.model.find.OWLEntityFinderPreferences;
|
||||
import org.protege.editor.owl.model.search.SearchResult;
|
||||
@@ -186,4 +187,5 @@ public class EntityFinderField extends AugmentedJTextField {
|
||||
window.setVisible(true);
|
||||
window.validate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package org.protege.editor.owl.ui.search;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import org.protege.editor.core.ui.util.AugmentedJTextField;
|
||||
import org.protege.editor.owl.OWLEditorKit;
|
||||
import org.protege.editor.owl.model.search.SearchResult;
|
||||
import org.semanticweb.owlapi.model.OWLEntity;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Matthew Horridge
|
||||
* Stanford Center for Biomedical Informatics Research
|
||||
* 31/03/15
|
||||
*/
|
||||
public class SearchDialogPanel extends JPanel {
|
||||
|
||||
private final JTextField searchField;
|
||||
|
||||
private final SearchPanel searchPanel;
|
||||
|
||||
private final OWLEditorKit editorKit;
|
||||
|
||||
public SearchDialogPanel(OWLEditorKit editorKit) {
|
||||
this.editorKit = editorKit;
|
||||
setLayout(new BorderLayout());
|
||||
searchField = new AugmentedJTextField("Enter search string");
|
||||
searchPanel = new SearchPanel(editorKit);
|
||||
add(searchField, BorderLayout.NORTH);
|
||||
add(searchPanel, BorderLayout.CENTER);
|
||||
|
||||
searchField.addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
selectEntity();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
searchPanel.moveSelectionUp();
|
||||
e.consume();
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
searchPanel.moveSelectionDown();
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
}
|
||||
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
performSearch();
|
||||
}
|
||||
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
performSearch();
|
||||
}
|
||||
});
|
||||
searchPanel.setSearchResultClickedListener(new SearchResultClickedListener() {
|
||||
@Override
|
||||
public void handleSearchResultClicked(SearchResult searchResult, MouseEvent e) {
|
||||
if(e.getClickCount() == 2) {
|
||||
selectEntity();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void selectEntity() {
|
||||
Optional<OWLEntity> selectedEntity = searchPanel.getSelectedEntity();
|
||||
if (selectedEntity.isPresent()) {
|
||||
editorKit.getOWLWorkspace().getOWLSelectionModel().setSelectedEntity(selectedEntity.get());
|
||||
editorKit.getOWLWorkspace().displayOWLEntity(selectedEntity.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void performSearch() {
|
||||
searchPanel.setSearchString(searchField.getText().trim());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static JDialog createDialog(JComponent parent, OWLEditorKit editorKit) {
|
||||
JFrame parentFrame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, parent);
|
||||
final JDialog dialog = new JDialog(parentFrame, "Search", Dialog.ModalityType.MODELESS);
|
||||
|
||||
final SearchDialogPanel searchDialogPanel = new SearchDialogPanel(editorKit);
|
||||
searchDialogPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
||||
|
||||
searchDialogPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "CLOSE_DIALOG");
|
||||
searchDialogPanel.getActionMap().put("CLOSE_DIALOG", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
searchDialogPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "CLOSE_DIALOG_WITH_ENTER");
|
||||
searchDialogPanel.getActionMap().put("CLOSE_DIALOG_WITH_ENTER", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dialog.setVisible(false);
|
||||
searchDialogPanel.selectEntity();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
dialog.setContentPane(searchDialogPanel);
|
||||
dialog.setResizable(true);
|
||||
dialog.pack();
|
||||
dialog.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
searchDialogPanel.searchField.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
}
|
||||
Referência em uma Nova Issue
Bloquear um usuário