use of javax.swing.ToolTipManager in project MassBank-web by MassBank.
the class SearchPage method createWindow.
/**
* �E�C���h�E����
*/
private void createWindow() {
// �c�[���`�b�v�}�l�[�W���[�ݒ�
ToolTipManager ttm = ToolTipManager.sharedInstance();
ttm.setInitialDelay(50);
ttm.setDismissDelay(8000);
// Search�p�l��
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
Border border = BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), new EmptyBorder(1, 1, 1, 1));
mainPanel.setBorder(border);
// *********************************************************************
// User File Query�^�u
// *********************************************************************
DefaultTableModel fileDm = new DefaultTableModel();
fileSorter = new TableSorter(fileDm, TABLE_QUERY_FILE);
queryFileTable = new JTable(fileSorter) {
@Override
public boolean isCellEditable(int row, int column) {
// �I�[�o�[���C�h�ŃZ���ҏW��s�Ƃ���
return false;
}
};
queryFileTable.addMouseListener(new TblMouseListener());
fileSorter.setTableHeader(queryFileTable.getTableHeader());
queryFileTable.setRowSelectionAllowed(true);
queryFileTable.setColumnSelectionAllowed(false);
queryFileTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
String[] col = { COL_LABEL_NO, COL_LABEL_NAME, COL_LABEL_ID };
((DefaultTableModel) fileSorter.getTableModel()).setColumnIdentifiers(col);
(queryFileTable.getColumn(queryFileTable.getColumnName(0))).setPreferredWidth(44);
(queryFileTable.getColumn(queryFileTable.getColumnName(1))).setPreferredWidth(LEFT_PANEL_WIDTH - 44);
(queryFileTable.getColumn(queryFileTable.getColumnName(2))).setPreferredWidth(70);
ListSelectionModel lm = queryFileTable.getSelectionModel();
lm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
lm.addListSelectionListener(new LmFileListener());
queryFilePane = new JScrollPane(queryFileTable);
queryFilePane.addMouseListener(new PaneMouseListener());
queryFilePane.setPreferredSize(new Dimension(300, 300));
// *********************************************************************
// Result�^�u
// *********************************************************************
DefaultTableModel resultDm = new DefaultTableModel();
resultSorter = new TableSorter(resultDm, TABLE_RESULT);
resultTable = new JTable(resultSorter) {
@Override
public String getToolTipText(MouseEvent me) {
// super.getToolTipText(me);
// �I�[�o�[���C�h�Ńc�[���`�b�v�̕������Ԃ�
Point pt = me.getPoint();
int row = rowAtPoint(pt);
if (row < 0) {
return null;
} else {
int nameCol = getColumnModel().getColumnIndex(COL_LABEL_NAME);
return " " + getValueAt(row, nameCol) + " ";
}
}
@Override
public boolean isCellEditable(int row, int column) {
// �I�[�o�[���C�h�ŃZ���ҏW��s�Ƃ���
return false;
}
};
resultTable.addMouseListener(new TblMouseListener());
resultSorter.setTableHeader(resultTable.getTableHeader());
JPanel dbPanel = new JPanel();
dbPanel.setLayout(new BorderLayout());
resultPane = new JScrollPane(resultTable);
resultPane.addMouseListener(new PaneMouseListener());
resultTable.setRowSelectionAllowed(true);
resultTable.setColumnSelectionAllowed(false);
resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
String[] col2 = { COL_LABEL_NAME, COL_LABEL_SCORE, COL_LABEL_HIT, COL_LABEL_ID, COL_LABEL_ION, COL_LABEL_CONTRIBUTOR, COL_LABEL_NO };
resultDm.setColumnIdentifiers(col2);
(resultTable.getColumn(resultTable.getColumnName(0))).setPreferredWidth(LEFT_PANEL_WIDTH - 180);
(resultTable.getColumn(resultTable.getColumnName(1))).setPreferredWidth(70);
(resultTable.getColumn(resultTable.getColumnName(2))).setPreferredWidth(20);
(resultTable.getColumn(resultTable.getColumnName(3))).setPreferredWidth(70);
(resultTable.getColumn(resultTable.getColumnName(4))).setPreferredWidth(20);
(resultTable.getColumn(resultTable.getColumnName(5))).setPreferredWidth(70);
(resultTable.getColumn(resultTable.getColumnName(6))).setPreferredWidth(50);
ListSelectionModel lm2 = resultTable.getSelectionModel();
lm2.addListSelectionListener(new LmResultListener());
resultPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH, 200));
dbPanel.add(resultPane, BorderLayout.CENTER);
// *********************************************************************
// DB Query�^�u
// *********************************************************************
DefaultTableModel dbDm = new DefaultTableModel();
querySorter = new TableSorter(dbDm, TABLE_QUERY_DB);
queryDbTable = new JTable(querySorter) {
@Override
public boolean isCellEditable(int row, int column) {
// �I�[�o�[���C�h�ŃZ���ҏW��s�Ƃ���
return false;
}
};
queryDbTable.addMouseListener(new TblMouseListener());
querySorter.setTableHeader(queryDbTable.getTableHeader());
queryDbPane = new JScrollPane(queryDbTable);
queryDbPane.addMouseListener(new PaneMouseListener());
int h = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
queryDbPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH, h));
queryDbTable.setRowSelectionAllowed(true);
queryDbTable.setColumnSelectionAllowed(false);
queryDbTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
String[] col3 = { COL_LABEL_ID, COL_LABEL_NAME, COL_LABEL_CONTRIBUTOR, COL_LABEL_NO };
DefaultTableModel model = (DefaultTableModel) querySorter.getTableModel();
model.setColumnIdentifiers(col3);
// �Z�b�g
queryDbTable.getColumn(queryDbTable.getColumnName(0)).setPreferredWidth(70);
queryDbTable.getColumn(queryDbTable.getColumnName(1)).setPreferredWidth(LEFT_PANEL_WIDTH - 70);
queryDbTable.getColumn(queryDbTable.getColumnName(2)).setPreferredWidth(70);
queryDbTable.getColumn(queryDbTable.getColumnName(3)).setPreferredWidth(50);
ListSelectionModel lm3 = queryDbTable.getSelectionModel();
lm3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
lm3.addListSelectionListener(new LmQueryDbListener());
// �{�^���p�l��
JPanel btnPanel = new JPanel();
btnName.addActionListener(new BtnSearchNameListener());
btnAll.addActionListener(new BtnAllListener());
btnPanel.add(btnName);
btnPanel.add(btnAll);
parentPanel2 = new JPanel();
parentPanel2.setLayout(new BoxLayout(parentPanel2, BoxLayout.PAGE_AXIS));
parentPanel2.add(btnPanel);
parentPanel2.add(queryDbPane);
// �I�v�V�����p�l��
JPanel dispModePanel = new JPanel();
isDispSelected = dispSelected.isSelected();
isDispRelated = dispRelated.isSelected();
if (isDispSelected) {
resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
} else if (isDispRelated) {
resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
Object[] retRadio = new Object[] { dispSelected, dispRelated };
for (int i = 0; i < retRadio.length; i++) {
((JRadioButton) retRadio[i]).addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (isDispSelected != dispSelected.isSelected() || isDispRelated != dispRelated.isSelected()) {
isDispSelected = dispSelected.isSelected();
isDispRelated = dispRelated.isSelected();
// ���ʃ��R�[�h�I����Ԃ�����
resultTable.clearSelection();
resultPlot.clear();
compPlot.setPeaks(null, 1);
resultPlot.setPeaks(null, 0);
setAllPlotAreaRange();
pkgView.initResultRecInfo();
if (isDispSelected) {
resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
} else if (isDispRelated) {
resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
}
}
});
}
ButtonGroup disGroup = new ButtonGroup();
disGroup.add(dispSelected);
disGroup.add(dispRelated);
dispModePanel.add(lbl2);
dispModePanel.add(dispSelected);
dispModePanel.add(dispRelated);
JPanel paramPanel = new JPanel();
paramPanel.add(etcPropertyButton);
etcPropertyButton.setMargin(new Insets(0, 10, 0, 10));
etcPropertyButton.addActionListener(new ActionListener() {
private ParameterSetWindow ps = null;
public void actionPerformed(ActionEvent e) {
// �q��ʂ��J���Ă��Ȃ���ΐ���
if (!isSubWindow) {
ps = new ParameterSetWindow();
} else {
ps.requestFocus();
}
}
});
JPanel optionPanel = new JPanel();
optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS));
optionPanel.add(dispModePanel);
optionPanel.add(paramPanel);
// PackageView�����y�сA������
pkgView = new PackageViewPanel();
pkgView.initAllRecInfo();
queryTabPane.addTab("DB", parentPanel2);
queryTabPane.setToolTipTextAt(TAB_ORDER_DB, "Query from DB.");
queryTabPane.addTab("File", queryFilePane);
queryTabPane.setToolTipTextAt(TAB_ORDER_FILE, "Query from user file.");
queryTabPane.setSelectedIndex(TAB_ORDER_DB);
queryTabPane.setFocusable(false);
queryTabPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
// �v���b�g�y�C��������
queryPlot.clear();
compPlot.clear();
resultPlot.clear();
queryPlot.setPeaks(null, 0);
compPlot.setPeaks(null, 1);
resultPlot.setPeaks(null, 0);
// PackageView������
pkgView.initAllRecInfo();
// DB Hit�^�u�֘A������
if (resultTabPane.getTabCount() > 0) {
resultTabPane.setSelectedIndex(0);
}
DefaultTableModel dataModel = (DefaultTableModel) resultSorter.getTableModel();
dataModel.setRowCount(0);
hitLabel.setText(" ");
// DB�^�u�AUser File�^�u�̑I���ς݃��R�[�h���f����
queryTabPane.update(queryTabPane.getGraphics());
if (queryTabPane.getSelectedIndex() == TAB_ORDER_DB) {
parentPanel2.update(parentPanel2.getGraphics());
updateSelectQueryTable(queryDbTable);
} else if (queryTabPane.getSelectedIndex() == TAB_ORDER_FILE) {
queryFilePane.update(queryFilePane.getGraphics());
updateSelectQueryTable(queryFileTable);
}
}
});
// ���C�A�E�g
JPanel queryPanel = new JPanel();
queryPanel.setLayout(new BorderLayout());
queryPanel.add(queryTabPane, BorderLayout.CENTER);
queryPanel.add(optionPanel, BorderLayout.SOUTH);
queryPanel.setMinimumSize(new Dimension(0, 170));
JPanel jtp2Panel = new JPanel();
jtp2Panel.setLayout(new BorderLayout());
jtp2Panel.add(dbPanel, BorderLayout.CENTER);
jtp2Panel.add(hitLabel, BorderLayout.SOUTH);
jtp2Panel.setMinimumSize(new Dimension(0, 70));
Color colorGreen = new Color(0, 128, 0);
hitLabel.setForeground(colorGreen);
resultTabPane.addTab("Result", jtp2Panel);
resultTabPane.setToolTipTextAt(TAB_RESULT_DB, "Result of DB hit.");
resultTabPane.setFocusable(false);
queryPlot.setMinimumSize(new Dimension(0, 100));
compPlot.setMinimumSize(new Dimension(0, 120));
resultPlot.setMinimumSize(new Dimension(0, 100));
int height = initAppletHight / 3;
JSplitPane jsp_cmp2db = new JSplitPane(JSplitPane.VERTICAL_SPLIT, compPlot, resultPlot);
JSplitPane jsp_qry2cmp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, queryPlot, jsp_cmp2db);
jsp_cmp2db.setDividerLocation(height);
jsp_qry2cmp.setDividerLocation(height - 25);
jsp_qry2cmp.setMinimumSize(new Dimension(190, 0));
viewTabPane.addTab("Compare View", jsp_qry2cmp);
viewTabPane.addTab("Package View", pkgView);
viewTabPane.setToolTipTextAt(TAB_VIEW_COMPARE, "Comparison of query and result spectrum.");
viewTabPane.setToolTipTextAt(TAB_VIEW_PACKAGE, "Package comparison of query and result spectrum.");
viewTabPane.setSelectedIndex(TAB_VIEW_COMPARE);
viewTabPane.setFocusable(false);
JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, queryPanel, resultTabPane);
jsp.setDividerLocation(310);
jsp.setMinimumSize(new Dimension(180, 0));
jsp.setOneTouchExpandable(true);
JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp, viewTabPane);
int divideSize = (int) (initAppletWidth * 0.4);
divideSize = (divideSize >= 180) ? divideSize : 180;
jsp2.setDividerLocation(divideSize);
jsp2.setOneTouchExpandable(true);
mainPanel.add(jsp2, BorderLayout.CENTER);
add(mainPanel);
queryPlot.setSearchPage(this);
compPlot.setSearchPage(this);
resultPlot.setSearchPage(this);
}
use of javax.swing.ToolTipManager in project MassBank-web by MassBank.
the class PackageView method init.
/**
* ���C���v���O����
*/
public void init() {
// �A�v���b�g�R���e�L�X�g�擾
context = getAppletContext();
// �A�v���b�g������ʃT�C�Y�擾
initAppletWidth = getWidth();
initAppletHight = getHeight();
// ���ݒ�t�@�C������A�g�T�C�g��URL���擾
String confPath = getCodeBase().toString();
confPath = confPath.replaceAll("/jsp", "");
GetConfig conf = new GetConfig(confPath);
baseUrl = conf.getServerUrl();
// �c�[���`�b�v�}�l�[�W���[�ݒ�
ToolTipManager ttm = ToolTipManager.sharedInstance();
ttm.setInitialDelay(50);
ttm.setDismissDelay(8000);
setLayout(new BorderLayout());
// ���C���p�l��
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
Border border = BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), new EmptyBorder(0, 5, 0, 5));
mainPanel.setBorder(border);
// PackageView�����y�сA������
pkgView = new PackageViewPanel();
pkgView.initAllRecInfo();
mainPanel.add(new HeaderPane(), BorderLayout.NORTH);
mainPanel.add(pkgView, BorderLayout.CENTER);
mainPanel.add(new FooterPane(), BorderLayout.SOUTH);
add(mainPanel);
// ���[�U�[�t�@�C���Ǎ���
if (getParameter("file") != null) {
loadFile(getParameter("file"));
}
}
use of javax.swing.ToolTipManager in project ACS by ACS-Community.
the class LoggingClient method initialize.
/**
* Initializes the object.
*
* @param logLevel The initial log level to set in the toolbar and in the table
* @param discardLevel The initial discard level to set in the toolbar and in the engine
* @param unlimited If <code>true</code> the number of logs in memory is unlimited,
* otherwise the default is used
*/
private void initialize(LogTypeHelper logLevel, LogTypeHelper discardLevel, boolean unlimited) {
try {
setName("LoggingClientPanel");
messageTextArea = new ExtendedTextArea();
// Set the glass pane showing errors and messages to be acknowledged
glassPane = new TransparentGlassPane(getContentPane());
setGlassPane(glassPane);
// We want to be notified when the user presses the Ok button
// of the MessageWidget
errorWidget.addAckListener(this);
// Set the tooltip manager
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
toolTipManager.setDismissDelay(60000);
Dimension d = new Dimension(750, 550);
setPreferredSize(d);
getContentPane().setLayout(new BorderLayout());
setJMenuBar(menuBar);
// Add the GUI in the center position
getContentPane().add(getJFrameContentPane(), BorderLayout.CENTER);
// The panel having the toolbars on top and the panel showing errors at the bottom
JPanel northPanel = new JPanel(new BorderLayout());
// Add the toolbars to the toolbarsPanel
JPanel toolbarsPanel = new JPanel();
BoxLayout toolbarLayout = new BoxLayout(toolbarsPanel, BoxLayout.Y_AXIS);
toolbarsPanel.setLayout(toolbarLayout);
toolBar = new LogToolBar(logLevel, discardLevel);
boolean zoomAvailable = zoom.isAvailable();
toolBar.setZoomable(zoomAvailable);
menuBar.getManualZoomMI().setEnabled(zoomAvailable);
toolbarsPanel.add(toolBar);
navigationToolbar = new LogNavigationBar(getLogEntryTable());
toolbarsPanel.add(navigationToolbar);
northPanel.add(toolbarsPanel, BorderLayout.NORTH);
northPanel.add(errorWidget, BorderLayout.SOUTH);
getContentPane().add(northPanel, BorderLayout.NORTH);
initConnections();
validate();
getLogEntryTable().setLogLevel((LogTypeHelper) toolBar.getLogLevelCB().getSelectedItem());
if (unlimited) {
userPreferences.setMaxLogs(0);
}
getLCModel1().setTimeFrame(userPreferences.getMillisecondsTimeFrame());
getLCModel1().setMaxLog(userPreferences.getMaxNumOfLogs());
archive = new ArchiveConnectionManager(this);
setTableFilterLbl();
setEngineFilterLbl();
setNumberOfLogsLbl();
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
getTableDetailsVrPane().setDividerLocation(getTableDetailsVrPane().getLastDividerLocation());
//getHeight() - 150);
getStatusAreaHrPane().setDividerLocation(350);
}
use of javax.swing.ToolTipManager in project cytoscape-impl by cytoscape.
the class GUIDefaults method setTooltip.
public static void setTooltip(String text, JComponent... components) {
if (text == null)
return;
text = text.trim();
if (text.isEmpty())
return;
final ToolTipManager tipManager = ToolTipManager.sharedInstance();
tipManager.setInitialDelay(1);
tipManager.setDismissDelay(7500);
for (final JComponent c : components) {
if (c != null)
c.setToolTipText(text);
}
}
use of javax.swing.ToolTipManager in project gate-core by GateNLP.
the class LuceneDataStoreSearchGUI method initGui.
/**
* Initialize the GUI.
*/
protected void initGui() {
// see the global layout schema at the end
setLayout(new BorderLayout());
stringCollator = java.text.Collator.getInstance();
stringCollator.setStrength(java.text.Collator.TERTIARY);
Comparator<String> lastWordComparator = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1 == null || o2 == null) {
return 0;
}
return stringCollator.compare(o1.substring(o1.trim().lastIndexOf(' ') + 1), o2.substring(o2.trim().lastIndexOf(' ') + 1));
}
};
integerComparator = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if (o1 == null || o2 == null) {
return 0;
}
return o1.compareTo(o2);
}
};
/**
********************************
* Stack view configuration frame *
*********************************
*/
configureStackViewFrame = new ConfigureStackViewFrame("Stack view configuration");
configureStackViewFrame.setIconImage(((ImageIcon) MainFrame.getIcon("WindowNew")).getImage());
configureStackViewFrame.setLocationRelativeTo(LuceneDataStoreSearchGUI.this);
configureStackViewFrame.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("ESCAPE"), "close row manager");
configureStackViewFrame.getRootPane().getActionMap().put("close row manager", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
configureStackViewFrame.setVisible(false);
}
});
configureStackViewFrame.validate();
configureStackViewFrame.setSize(200, 300);
configureStackViewFrame.pack();
// called when Gate is exited, in case the user doesn't close the
// datastore
MainFrame.getInstance().addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
// no parent so need to be disposed explicitly
configureStackViewFrame.dispose();
}
});
/**
***********
* Top panel *
************
*/
JPanel topPanel = new JPanel(new GridBagLayout());
topPanel.setOpaque(false);
topPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 3));
GridBagConstraints gbc = new GridBagConstraints();
// first column, three rows span
queryTextArea = new QueryTextArea();
queryTextArea.setToolTipText("<html>Enter a query to search the datastore." + "<br><small>'{' or '.' activate auto-completion." + "<br>Ctrl+Enter add a new line.</small></html>");
queryTextArea.setLineWrap(true);
gbc.gridheight = 3;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 0, 0, 4);
topPanel.add(new JScrollPane(queryTextArea), gbc);
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(0, 0, 0, 0);
// second column, first row
gbc.gridx = GridBagConstraints.RELATIVE;
topPanel.add(new JLabel("Corpus: "), gbc);
corpusToSearchIn = new JComboBox<String>();
corpusToSearchIn.addItem(Constants.ENTIRE_DATASTORE);
corpusToSearchIn.setPrototypeDisplayValue(Constants.ENTIRE_DATASTORE);
corpusToSearchIn.setToolTipText("Select the corpus to search in.");
if (target == null || target instanceof Searcher) {
corpusToSearchIn.setEnabled(false);
}
corpusToSearchIn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ie) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateAnnotationSetsList();
}
});
}
});
topPanel.add(corpusToSearchIn, gbc);
topPanel.add(Box.createHorizontalStrut(4), gbc);
topPanel.add(new JLabel("Annotation set: "), gbc);
annotationSetsToSearchIn = new JComboBox<String>();
annotationSetsToSearchIn.setPrototypeDisplayValue(Constants.COMBINED_SET);
annotationSetsToSearchIn.setToolTipText("Select the annotation set to search in.");
annotationSetsToSearchIn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ie) {
updateAnnotationTypesList();
}
});
topPanel.add(annotationSetsToSearchIn, gbc);
// refresh button
topPanel.add(Box.createHorizontalStrut(4), gbc);
RefreshAnnotationSetsAndFeaturesAction refreshAction = new RefreshAnnotationSetsAndFeaturesAction();
JButton refreshTF = new ButtonBorder(new Color(240, 240, 240), new Insets(4, 2, 4, 3), false);
refreshTF.setAction(refreshAction);
topPanel.add(refreshTF, gbc);
// second column, second row
gbc.gridy = 1;
JLabel noOfResultsLabel = new JLabel("Results: ");
topPanel.add(noOfResultsLabel, gbc);
numberOfResultsSlider = new JSlider(1, 1100, 50);
numberOfResultsSlider.setToolTipText("50 results per page");
numberOfResultsSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (numberOfResultsSlider.getValue() > (numberOfResultsSlider.getMaximum() - 100)) {
numberOfResultsSlider.setToolTipText("Retrieve all results.");
nextResults.setText("Retrieve all results.");
nextResultsAction.setEnabled(false);
} else {
numberOfResultsSlider.setToolTipText("Retrieve " + numberOfResultsSlider.getValue() + " results per page.");
nextResults.setText("Next page of " + numberOfResultsSlider.getValue() + " results");
if (searcher.getHits().length == noOfResults) {
nextResultsAction.setEnabled(true);
}
}
// show the tooltip each time the value change
ToolTipManager.sharedInstance().mouseMoved(new MouseEvent(numberOfResultsSlider, MouseEvent.MOUSE_MOVED, 0, 0, 0, 0, 0, false));
}
});
// always show the tooltip for this component
numberOfResultsSlider.addMouseListener(new MouseAdapter() {
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
int initialDelay, reshowDelay, dismissDelay;
boolean enabled;
@Override
public void mouseEntered(MouseEvent e) {
initialDelay = toolTipManager.getInitialDelay();
reshowDelay = toolTipManager.getReshowDelay();
dismissDelay = toolTipManager.getDismissDelay();
enabled = toolTipManager.isEnabled();
toolTipManager.setInitialDelay(0);
toolTipManager.setReshowDelay(0);
toolTipManager.setDismissDelay(Integer.MAX_VALUE);
toolTipManager.setEnabled(true);
}
@Override
public void mouseExited(MouseEvent e) {
toolTipManager.setInitialDelay(initialDelay);
toolTipManager.setReshowDelay(reshowDelay);
toolTipManager.setDismissDelay(dismissDelay);
toolTipManager.setEnabled(enabled);
}
});
gbc.insets = new Insets(5, 0, 0, 0);
topPanel.add(numberOfResultsSlider, gbc);
gbc.insets = new Insets(0, 0, 0, 0);
topPanel.add(Box.createHorizontalStrut(4), gbc);
JLabel contextWindowLabel = new JLabel("Context size: ");
topPanel.add(contextWindowLabel, gbc);
contextSizeSlider = new JSlider(1, 50, 5);
contextSizeSlider.setToolTipText("Display 5 tokens of context in the results.");
contextSizeSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
contextSizeSlider.setToolTipText("Display " + contextSizeSlider.getValue() + " tokens of context in the results.");
ToolTipManager.sharedInstance().mouseMoved(new MouseEvent(contextSizeSlider, MouseEvent.MOUSE_MOVED, 0, 0, 0, 0, 0, false));
}
});
// always show the tooltip for this component
contextSizeSlider.addMouseListener(new MouseAdapter() {
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
int initialDelay, reshowDelay, dismissDelay;
boolean enabled;
@Override
public void mouseEntered(MouseEvent e) {
initialDelay = toolTipManager.getInitialDelay();
reshowDelay = toolTipManager.getReshowDelay();
dismissDelay = toolTipManager.getDismissDelay();
enabled = toolTipManager.isEnabled();
toolTipManager.setInitialDelay(0);
toolTipManager.setReshowDelay(0);
toolTipManager.setDismissDelay(Integer.MAX_VALUE);
toolTipManager.setEnabled(true);
}
@Override
public void mouseExited(MouseEvent e) {
toolTipManager.setInitialDelay(initialDelay);
toolTipManager.setReshowDelay(reshowDelay);
toolTipManager.setDismissDelay(dismissDelay);
toolTipManager.setEnabled(enabled);
}
});
gbc.insets = new Insets(5, 0, 0, 0);
topPanel.add(contextSizeSlider, gbc);
gbc.insets = new Insets(0, 0, 0, 0);
// second column, third row
gbc.gridy = 2;
JPanel panel = new JPanel();
panel.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
executeQueryAction = new ExecuteQueryAction();
JButton executeQuery = new ButtonBorder(new Color(240, 240, 240), new Insets(0, 2, 0, 3), false);
executeQuery.setAction(executeQueryAction);
panel.add(executeQuery);
ClearQueryAction clearQueryAction = new ClearQueryAction();
JButton clearQueryTF = new ButtonBorder(new Color(240, 240, 240), new Insets(4, 2, 4, 3), false);
clearQueryTF.setAction(clearQueryAction);
panel.add(Box.createHorizontalStrut(5));
panel.add(clearQueryTF);
nextResultsAction = new NextResultsAction();
nextResultsAction.setEnabled(false);
nextResults = new ButtonBorder(new Color(240, 240, 240), new Insets(0, 0, 0, 3), false);
nextResults.setAction(nextResultsAction);
panel.add(Box.createHorizontalStrut(5));
panel.add(nextResults);
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = GridBagConstraints.REMAINDER;
topPanel.add(panel, gbc);
// will be added to the GUI via a split panel
/**
**************
* Center panel *
***************
*/
// these components will be used in updateStackView()
centerPanel = new AnnotationStack(150, 30);
configureStackViewButton = new ButtonBorder(new Color(250, 250, 250), new Insets(0, 0, 0, 3), true);
configureStackViewButton.setHorizontalAlignment(SwingConstants.LEFT);
configureStackViewButton.setAction(new ConfigureStackViewAction());
// will be added to the GUI via a split panel
/**
*******************
* Bottom left panel *
********************
*/
JPanel bottomLeftPanel = new JPanel(new GridBagLayout());
bottomLeftPanel.setOpaque(false);
gbc = new GridBagConstraints();
// title of the table, results options, export and next results
// button
gbc.gridy = 0;
panel = new JPanel();
panel.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
titleResults = new JLabel("Results");
titleResults.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
panel.add(titleResults);
panel.add(Box.createHorizontalStrut(5), gbc);
exportResultsAction = new ExportResultsAction();
exportResultsAction.setEnabled(false);
JButton exportToHTML = new ButtonBorder(new Color(240, 240, 240), new Insets(0, 0, 0, 3), false);
exportToHTML.setAction(exportResultsAction);
panel.add(exportToHTML, gbc);
bottomLeftPanel.add(panel, gbc);
// table of results
resultTableModel = new ResultTableModel();
resultTable = new XJTable(resultTableModel);
resultTable.setDefaultRenderer(String.class, new ResultTableCellRenderer());
resultTable.setEnableHidingColumns(true);
resultTable.addMouseListener(new MouseAdapter() {
private JPopupMenu mousePopup;
JMenuItem menuItem;
@Override
public void mousePressed(MouseEvent e) {
int row = resultTable.rowAtPoint(e.getPoint());
if (e.isPopupTrigger() && !resultTable.isRowSelected(row)) {
// if right click outside the selection then reset selection
resultTable.getSelectionModel().setSelectionInterval(row, row);
}
if (e.isPopupTrigger()) {
createPopup();
mousePopup.show(e.getComponent(), e.getX(), e.getY());
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
createPopup();
mousePopup.show(e.getComponent(), e.getX(), e.getY());
}
}
private void createPopup() {
mousePopup = new JPopupMenu();
menuItem = new JMenuItem("Remove the selected result" + (resultTable.getSelectedRowCount() > 1 ? "s" : ""));
mousePopup.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
int[] rows = resultTable.getSelectedRows();
for (int i = 0; i < rows.length; i++) {
rows[i] = resultTable.rowViewToModel(rows[i]);
}
Arrays.sort(rows);
for (int i = rows.length - 1; i >= 0; i--) {
results.remove(rows[i]);
}
resultTable.clearSelection();
resultTableModel.fireTableDataChanged();
mousePopup.setVisible(false);
}
});
if (target instanceof LuceneDataStoreImpl && SwingUtilities.getRoot(LuceneDataStoreSearchGUI.this) instanceof MainFrame) {
menuItem = new JMenuItem("Open the selected document" + (resultTable.getSelectedRowCount() > 1 ? "s" : ""));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
Set<Pattern> patterns = new HashSet<Pattern>();
Set<String> documentIds = new HashSet<String>();
for (int rowView : resultTable.getSelectedRows()) {
// create and display the document for this result
int rowModel = resultTable.rowViewToModel(rowView);
Pattern pattern = (Pattern) results.get(rowModel);
if (!documentIds.contains(pattern.getDocumentID())) {
patterns.add(pattern);
documentIds.add(pattern.getDocumentID());
}
}
if (patterns.size() > 10) {
Object[] possibleValues = { "Open the " + patterns.size() + " documents", "Don't open" };
int selectedValue = JOptionPane.showOptionDialog(LuceneDataStoreSearchGUI.this, "Do you want to open " + patterns.size() + " documents in the central tabbed pane ?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[1]);
if (selectedValue == 1 || selectedValue == JOptionPane.CLOSED_OPTION) {
return;
}
}
for (final Pattern pattern : patterns) {
// create and display the document for this result
FeatureMap features = Factory.newFeatureMap();
features.put(DataStore.DATASTORE_FEATURE_NAME, target);
features.put(DataStore.LR_ID_FEATURE_NAME, pattern.getDocumentID());
final Document doc;
try {
doc = (Document) Factory.createResource("gate.corpora.DocumentImpl", features);
} catch (gate.util.GateException e) {
e.printStackTrace();
return;
}
// show the expression in the document
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
MainFrame.getInstance().select(doc);
}
});
if (patterns.size() == 1) {
// wait some time for the document to be displayed
Date timeToRun = new Date(System.currentTimeMillis() + 2000);
Timer timer = new Timer("Annic show document timer", true);
timer.schedule(new TimerTask() {
@Override
public void run() {
showResultInDocument(doc, pattern);
}
}, timeToRun);
}
}
}
});
mousePopup.add(menuItem);
}
}
});
// resultTable.addMouseListener
// when selection change in the result table
// update the stack view and export button
resultTable.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {
@Override
public void valueChanged(javax.swing.event.ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
updateStackView();
}
}
});
resultTable.setColumnSelectionAllowed(false);
resultTable.setRowSelectionAllowed(true);
resultTable.setSortable(true);
resultTable.setComparator(ResultTableModel.LEFT_CONTEXT_COLUMN, lastWordComparator);
resultTable.setComparator(ResultTableModel.RESULT_COLUMN, stringCollator);
resultTable.setComparator(ResultTableModel.RIGHT_CONTEXT_COLUMN, stringCollator);
JScrollPane tableScrollPane = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.NORTH;
gbc.gridy = 1;
gbc.gridx = 0;
gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridheight = GridBagConstraints.REMAINDER;
gbc.weightx = 1;
gbc.weighty = 1;
bottomLeftPanel.add(tableScrollPane, gbc);
/**
************************
* Statistics tabbed pane *
*************************
*/
statisticsTabbedPane = new JTabbedPane();
globalStatisticsTable = new XJTable() {
@Override
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
}
};
globalStatisticsTableModel = new DefaultTableModel(new Object[] { "Annotation Type", "Count" }, 0);
globalStatisticsTable.setModel(globalStatisticsTableModel);
globalStatisticsTable.setComparator(0, stringCollator);
globalStatisticsTable.setComparator(1, integerComparator);
globalStatisticsTable.setSortedColumn(1);
globalStatisticsTable.setAscending(false);
globalStatisticsTable.addMouseListener(new MouseInputAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
updateQuery();
}
}
private void updateQuery() {
int caretPosition = queryTextArea.getCaretPosition();
String query = queryTextArea.getText();
String type = (String) globalStatisticsTable.getValueAt(globalStatisticsTable.getSelectedRow(), globalStatisticsTable.convertColumnIndexToView(0));
String queryMiddle = "{" + type + "}";
String queryLeft = (queryTextArea.getSelectionStart() == queryTextArea.getSelectionEnd()) ? query.substring(0, caretPosition) : query.substring(0, queryTextArea.getSelectionStart());
String queryRight = (queryTextArea.getSelectionStart() == queryTextArea.getSelectionEnd()) ? query.substring(caretPosition, query.length()) : query.substring(queryTextArea.getSelectionEnd(), query.length());
queryTextArea.setText(queryLeft + queryMiddle + queryRight);
}
});
statisticsTabbedPane.addTab("Global", null, new JScrollPane(globalStatisticsTable), "Global statistics on the Corpus and Annotation Set selected.");
statisticsTabbedPane.addMouseListener(new MouseAdapter() {
private JPopupMenu mousePopup;
JMenuItem menuItem;
@Override
public void mousePressed(MouseEvent e) {
int tabIndex = statisticsTabbedPane.indexAtLocation(e.getX(), e.getY());
if (e.isPopupTrigger() && tabIndex > 0) {
createPopup(tabIndex);
mousePopup.show(e.getComponent(), e.getX(), e.getY());
}
}
@Override
public void mouseReleased(MouseEvent e) {
int tabIndex = statisticsTabbedPane.indexAtLocation(e.getX(), e.getY());
if (e.isPopupTrigger() && tabIndex > 0) {
createPopup(tabIndex);
mousePopup.show(e.getComponent(), e.getX(), e.getY());
}
}
private void createPopup(final int tabIndex) {
mousePopup = new JPopupMenu();
if (tabIndex == 1) {
menuItem = new JMenuItem("Clear table");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ie) {
oneRowStatisticsTableModel.setRowCount(0);
}
});
} else {
menuItem = new JMenuItem("Close tab");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ie) {
statisticsTabbedPane.remove(tabIndex);
}
});
}
mousePopup.add(menuItem);
}
});
class RemoveCellEditorRenderer extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener {
private JButton button;
public RemoveCellEditorRenderer() {
button = new JButton();
button.setHorizontalAlignment(SwingConstants.CENTER);
button.setIcon(MainFrame.getIcon("Delete"));
button.setToolTipText("Remove this row.");
button.setContentAreaFilled(false);
button.setBorderPainted(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.addActionListener(this);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int col) {
button.setSelected(isSelected);
return button;
}
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return false;
}
@Override
public void actionPerformed(ActionEvent e) {
int editingRow = oneRowStatisticsTable.getEditingRow();
fireEditingStopped();
oneRowStatisticsTableModel.removeRow(oneRowStatisticsTable.rowViewToModel(editingRow));
}
@Override
public Object getCellEditorValue() {
return null;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
button.setSelected(isSelected);
return button;
}
}
oneRowStatisticsTable = new XJTable() {
@Override
public boolean isCellEditable(int rowIndex, int vColIndex) {
return vColIndex == 2;
}
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
Component c = super.prepareRenderer(renderer, row, col);
if (c instanceof JComponent && col != 2) {
// display a custom tooltip saved when adding statistics
((JComponent) c).setToolTipText("<html>" + oneRowStatisticsTableToolTips.get(rowViewToModel(row)) + "</html>");
}
return c;
}
};
oneRowStatisticsTableModel = new DefaultTableModel(new Object[] { "Annotation Type/Feature", "Count", "" }, 0);
oneRowStatisticsTable.setModel(oneRowStatisticsTableModel);
oneRowStatisticsTable.getColumnModel().getColumn(2).setCellEditor(new RemoveCellEditorRenderer());
oneRowStatisticsTable.getColumnModel().getColumn(2).setCellRenderer(new RemoveCellEditorRenderer());
oneRowStatisticsTable.setComparator(0, stringCollator);
oneRowStatisticsTable.setComparator(1, integerComparator);
statisticsTabbedPane.addTab("One item", null, new JScrollPane(oneRowStatisticsTable), "<html>One item statistics.<br>" + "Right-click on an annotation<br>" + "to add statistics here.");
oneRowStatisticsTableToolTips = new Vector<String>();
// will be added to the GUI via a split panel
/**
************************************************************
* Vertical splits between top, center panel and bottom panel *
*************************************************************
*/
/**
* ________________________________________
* | topPanel |
* |__________________3_____________________|
* | |
* | centerPanel |
* |________2________ __________2___________|
* | | |
* | bottomLeftPanel 1 statisticsTabbedPane |
* |_________________|______________________|
*
* 1 bottomSplitPane 2 centerBottomSplitPane 3 topBottomSplitPane
*/
bottomSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
Dimension minimumSize = new Dimension(0, 0);
bottomLeftPanel.setMinimumSize(minimumSize);
statisticsTabbedPane.setMinimumSize(minimumSize);
bottomSplitPane.add(bottomLeftPanel);
bottomSplitPane.add(statisticsTabbedPane);
bottomSplitPane.setOneTouchExpandable(true);
bottomSplitPane.setResizeWeight(0.75);
bottomSplitPane.setContinuousLayout(true);
JSplitPane centerBottomSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
centerBottomSplitPane.add(new JScrollPane(centerPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
centerBottomSplitPane.add(bottomSplitPane);
centerBottomSplitPane.setResizeWeight(0.5);
centerBottomSplitPane.setContinuousLayout(true);
JSplitPane topBottomSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
topBottomSplitPane.add(topPanel);
topBottomSplitPane.add(centerBottomSplitPane);
topBottomSplitPane.setContinuousLayout(true);
add(topBottomSplitPane, BorderLayout.CENTER);
}
Aggregations