下面列出了javax.swing.AbstractButton#setToolTipText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void setIcon(AbstractButton button, String res, String alt) {
try {
URL url = GraphsPanel.class.getClassLoader().getResource(res);
if (url == null) {
button.setText(alt);
}
else {
BufferedImage icon = ImageIO.read(url);
button.setIcon(new ImageIcon(icon));
}
}
catch (Exception e) {
button.setText(alt);
}
button.setToolTipText(alt);
}
private JPanel createButtonPanel() {
final TableLayout tableLayout = new TableLayout(1);
tableLayout.setTablePadding(4, 4);
tableLayout.setRowPadding(0, new Insets(0, 4, 4, 4));
tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
tableLayout.setTableFill(TableLayout.Fill.HORIZONTAL);
tableLayout.setTableWeightX(1.0);
tableLayout.setTableWeightY(0.0);
JPanel buttonPanel = new JPanel(tableLayout);
AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"), false);
helpButton.addActionListener(e -> new HelpCtx(HELP_ID).display());
helpButton.setToolTipText("Help");
buttonPanel.add(matrixSizeSpinner);
buttonPanel.add(tableLayout.createVerticalSpacer());
buttonPanel.add(helpButton);
return buttonPanel;
}
@Override
protected void initComponents() {
final AbstractButton switchToChartButton = ToolButtonFactory.createButton(iconForSwitchToChartButton, false);
switchToChartButton.setToolTipText("Switch to Chart View");
switchToChartButton.setName("switchToChartButton");
switchToChartButton.setEnabled(hasAlternativeView());
switchToChartButton.addActionListener(e -> showAlternativeView());
final JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(switchToChartButton, BorderLayout.NORTH);
buttonPanel.add(getHelpButton(), BorderLayout.SOUTH);
add(buttonPanel, BorderLayout.EAST);
table = new JTable();
table.removeEditor();
table.setGridColor(Color.LIGHT_GRAY.brighter());
table.addMouseListener(new PagePanel.PopupHandler());
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
final JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
}
/** Updates the state of those pushbuttons in the left
* vertical tool box that need to indicate the special "ambiguous"
* state marking that some of the currently selected components
* have the respective property set while some do not.
*/
private void updateButton(AbstractButton button, boolean nonEmptySelection, boolean allSelectedUnambiguous, String iconWarning, String toolTipWarning, String iconNormal, String toolTipNormal) {
button.setSelected(allSelectedUnambiguous);
if(nonEmptySelection && !allSelectedUnambiguous) {
button.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/layoutsupport/griddesigner/resources/" + iconWarning, false)); // NOI18N
button.setToolTipText(NbBundle.getMessage(GridBagCustomizer.class, "GridBagCustomizer." + toolTipWarning)); // NOI18N
} else {
button.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/layoutsupport/griddesigner/resources/" + iconNormal, false)); // NOI18N
button.setToolTipText(NbBundle.getMessage(GridBagCustomizer.class, "GridBagCustomizer." + toolTipNormal)); // NOI18N
}
}
private Component createMoveVariableUpButton() {
AbstractButton moveVariableUpButton = createButton("icons/MoveUp24.gif", "moveVariableUp");
moveVariableUpButton.setToolTipText("Move up selected rows."); /*I18N*/
moveVariableUpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveRowsUp(variablesTable, variablesTable.getSelectedRows());
}
});
return moveVariableUpButton;
}
private Component createNewVariableButton() {
AbstractButton newVariableButton = createButton("icons/Plus24.gif", "newVariable");
newVariableButton.setToolTipText("Add new processing variable"); /*I18N*/
newVariableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final int rows = variablesTable.getRowCount();
addRow(variablesTable, new Object[]{"variable_" + rows, ""}); /*I18N*/
}
});
return newVariableButton;
}
private Component createRemoveConditionButton() {
AbstractButton removeConditionButton = createButton("icons/Minus24.gif", "removeCondition");
removeConditionButton.setToolTipText("Remove selected rows."); /*I18N*/
removeConditionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeRows(conditionsTable, conditionsTable.getSelectedRows());
}
});
return removeConditionButton;
}
private Component createNewConditionButton() {
AbstractButton newConditionsButton = createButton("icons/Plus24.gif", "newCondition");
newConditionsButton.setToolTipText("Add new processing condition"); /*I18N*/
newConditionsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final int rows = conditionsTable.getRowCount();
addRow(conditionsTable, new Object[]{"condition_" + rows, "", false}); /*I18N*/
}
});
return newConditionsButton;
}
private JPanel createAggregatorsPanel() {
final Grid grid = new Grid(6, false);
TableLayout gridLayout = grid.getLayout();
gridLayout.setTablePadding(4, 3);
gridLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
gridLayout.setColumnFill(2, TableLayout.Fill.HORIZONTAL);
gridLayout.setColumnFill(3, TableLayout.Fill.HORIZONTAL);
gridLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL);
gridLayout.setColumnWeightX(2, 1.0);
gridLayout.setColumnWeightX(3, 1.0);
gridLayout.setColumnWeightX(4, 1.0);
grid.setHeaderRow(
/*0*/ //selection column
/*1*/ new JLabel("<html><b>Aggregator</b>"),
/*2*/ new JLabel("<html><b>Source Bands</b>"),
/*3*/ new JLabel("<html><b>Parameters</b>"),
/*4*/ new JLabel("<html><b>Target Bands</b>"),
/*5*/ null // column for edit button
);
aggregatorTableController = new AggregatorTableController(grid, binningFormModel);
final ListControlBar gridControlBar = ListControlBar.create(ListControlBar.HORIZONTAL, grid, aggregatorTableController);
final AbstractButton sel = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ShowSelection16.png"), true);
sel.setToolTipText("Show/hide selection column");
sel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
grid.setShowSelectionColumn(sel.isSelected());
gridControlBar.updateState();
}
});
gridControlBar.add(sel, 0);
JPanel panel = new JPanel(new BorderLayout(4, 4));
panel.setBorder(new EmptyBorder(4, 4, 4, 4));
panel.add(gridControlBar, BorderLayout.NORTH);
panel.add(new JScrollPane(grid), BorderLayout.CENTER);
return panel;
}
/**
* @param m the button item to change the text, short description and mnemonic
* @param substitutes substitutes to use in a message format
* @param prop key bundle to use
*/
public static void name(AbstractButton m, String prop, Object... substitutes)
{
m.setText(getName(prop, substitutes));
String shortDesc = getShortDesc(prop, substitutes);
if (shortDesc != null && !shortDesc.isEmpty())
{
m.setToolTipText(shortDesc);
}
m.setMnemonic(getMnemonic(prop));
}
protected AbstractButton getHelpButton() {
if (helpId != null) {
final AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"),
false);
helpButton.setToolTipText("Help.");
helpButton.setName("helpButton");
helpButton.addActionListener(e -> parentComponent.getHelpCtx().display());
// HelpSys.enableHelpKey(getParentDialogContentPane(), helpId);
return helpButton;
}
return null;
}
private JPanel createVariablesPanel() {
final Grid grid = new Grid(5, false);
TableLayout gridLayout = grid.getLayout();
gridLayout.setTablePadding(4, 3);
gridLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
gridLayout.setColumnFill(2, TableLayout.Fill.HORIZONTAL);
gridLayout.setColumnWeightX(2, 1.0);
grid.setHeaderRow(
/*0*/ //selection column
/*1*/ new JLabel("<html><b>Name</b>"),
/*2*/ new JLabel("<html><b>Expression</b>"),
/*3*/ new JLabel("<html><b>Valid-Pixel Expression</b>"),
/*5*/ null // column for edit button
);
variableTableController = new VariableTableController(grid, binningFormModel);
final ListControlBar gridControlBar = ListControlBar.create(ListControlBar.HORIZONTAL, grid, variableTableController);
final AbstractButton sel = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ShowSelection16.png"), true);
sel.setToolTipText("Show/hide selection column");
sel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
grid.setShowSelectionColumn(sel.isSelected());
gridControlBar.updateState();
}
});
gridControlBar.add(sel, 0);
JPanel panel = new JPanel(new BorderLayout(4, 4));
panel.setBorder(new TitledBorder("Intermediate Source Bands (optional)"));
panel.add(gridControlBar, BorderLayout.NORTH);
panel.add(new JScrollPane(grid), BorderLayout.CENTER);
return panel;
}
private AbstractButton createMinusButton() {
final AbstractButton minusButton = ToolButtonFactory.createButton(minusIcon, false);
minusButton.setToolTipText("Decrease playing speed");
minusButton.addActionListener(e -> {
if (speedSlider.getValue() > speedSlider.getMinimum()) {
speedSlider.setValue(speedSlider.getValue() - 1);
}
});
return minusButton;
}
private Component createMoveVariableDownButton() {
AbstractButton moveVariableDownButton = createButton("icons/MoveDown24.gif", "moveVariableDown");
moveVariableDownButton.setToolTipText("Move down selected rows."); /*I18N*/
moveVariableDownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveRowsDown(variablesTable, variablesTable.getSelectedRows());
}
});
return moveVariableDownButton;
}
static AbstractButton createButton() {
final AbstractButton logDisplayButton = ImageInfoEditorSupport.createToggleButton("org/esa/snap/rcp/icons/LogDisplay24.png");
logDisplayButton.setName("logDisplayButton");
logDisplayButton.setToolTipText("Switch to logarithmic display"); /*I18N*/
return logDisplayButton;
}
private JPanel createChartBottomPanel(final ChartPanel chartPanel) {
final AbstractButton zoomAllButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/view-fullscreen.png"),
false);
zoomAllButton.setToolTipText("Zoom all.");
zoomAllButton.setName("zoomAllButton.");
zoomAllButton.addActionListener(e -> {
chartPanel.restoreAutoBounds();
chartPanel.repaint();
});
final AbstractButton propertiesButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/Edit24.gif"),
false);
propertiesButton.setToolTipText("Edit properties.");
propertiesButton.setName("propertiesButton.");
propertiesButton.addActionListener(e -> chartPanel.doEditChartProperties());
final AbstractButton saveButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/Export24.gif"),
false);
saveButton.setToolTipText("Save chart as image.");
saveButton.setName("saveButton.");
saveButton.addActionListener(e -> {
try {
chartPanel.doSaveAs();
} catch (IOException e1) {
AbstractDialog.showErrorDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error");
}
});
final AbstractButton printButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/Print24.gif"),
false);
printButton.setToolTipText("Print chart.");
printButton.setName("printButton.");
printButton.addActionListener(e -> chartPanel.createChartPrintJob());
final TableLayout tableLayout = new TableLayout(6);
tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL);
tableLayout.setColumnWeightX(4, 1.0);
JPanel buttonPanel = new JPanel(tableLayout);
tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
buttonPanel.add(zoomAllButton);
tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
buttonPanel.add(propertiesButton);
buttonPanel.add(saveButton);
buttonPanel.add(printButton);
buttonPanel.add(new JPanel());
buttonPanel.add(getHelpButton());
return buttonPanel;
}
private JPanel createButtonPanel(final String helpID) {
showTimeSeriesForSelectedPinsButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true);
showTimeSeriesForSelectedPinsButton.addActionListener(e -> {
if (graphModel.isShowingAllPins()) {
showTimeSeriesForAllPinsButton.setSelected(false);
graphModel.setIsShowingAllPins(false);
}
graphModel.setIsShowingSelectedPins(showTimeSeriesForSelectedPinsButton.isSelected());
});
showTimeSeriesForSelectedPinsButton.setName("showTimeSeriesForSelectedPinsButton");
showTimeSeriesForSelectedPinsButton.setToolTipText("Show time series for selected pin");
//////////////////////////////////////////
showTimeSeriesForAllPinsButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true);
showTimeSeriesForAllPinsButton.addActionListener(e -> {
if (graphModel.isShowingSelectedPins()) {
showTimeSeriesForSelectedPinsButton.setSelected(false);
graphModel.setIsShowingSelectedPins(false);
}
graphModel.setIsShowingAllPins(showTimeSeriesForAllPinsButton.isSelected());
});
showTimeSeriesForAllPinsButton.setName("showTimeSeriesForAllPinsButton");
showTimeSeriesForAllPinsButton.setToolTipText("Show time series for all pins");
//////////////////////////////////////////
showCursorTimeSeriesButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true);
showCursorTimeSeriesButton.addActionListener(e -> graphModel.setIsShowingCursorTimeSeries(showCursorTimeSeriesButton.isSelected()));
showCursorTimeSeriesButton.setToolTipText("Show time series for cursor");
showCursorTimeSeriesButton.setSelected(true);
//////////////////////////////////////////
exportTimeSeriesButton = ToolButtonFactory.createButton(
UIUtils.loadImageIcon("icons/Export24.gif"),
false);
exportTimeSeriesButton.addActionListener(e -> {
final ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView();
JOptionPane.showMessageDialog(view, "Not available in the current version.", "Export data", JOptionPane.INFORMATION_MESSAGE);
//@todo se remove message dialog and fix export that only the visible graph data will be exported
// if (view != null
// && view.getProduct() != null
// && view.getProduct().getProductType().equals(AbstractTimeSeries.TIME_SERIES_PRODUCT_TYPE)
// && TimeSeriesMapper.getInstance().getTimeSeries(view.getProduct()) != null) {
//
// AbstractTimeSeries timeSeries = TimeSeriesMapper.getInstance().getTimeSeries(view.getProduct());
// ExportTimeBasedText.export(mainPanel, timeSeries, helpID);
// }
});
exportTimeSeriesButton.setToolTipText("Export raster data time series of all pins");
exportTimeSeriesButton.setName("exportTimeSeriesButton");
final ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView();
if (sceneView != null) {
exportTimeSeriesButton.setEnabled(sceneView.getProduct().getPinGroup().getNodeCount() > 0);
} else {
exportTimeSeriesButton.setEnabled(false);
}
AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"), false);
helpButton.addActionListener(e -> new HelpCtx(helpID).display());
helpButton.setToolTipText("Help");
final TableLayout tableLayout = new TableLayout(1);
tableLayout.setTablePadding(4, 4);
tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
tableLayout.setTableFill(TableLayout.Fill.HORIZONTAL);
tableLayout.setTableWeightX(1.0);
tableLayout.setTableWeightY(0.0);
JPanel buttonPanel = new JPanel(tableLayout);
buttonPanel.add(showTimeSeriesForSelectedPinsButton);
buttonPanel.add(showTimeSeriesForAllPinsButton);
buttonPanel.add(showCursorTimeSeriesButton);
buttonPanel.add(exportTimeSeriesButton);
buttonPanel.add(tableLayout.createVerticalSpacer());
buttonPanel.add(helpButton);
return buttonPanel;
}
private AbstractButton createRepeatButton() {
final AbstractButton repeatButton = ToolButtonFactory.createButton(repeatIcon, true);
repeatButton.setToolTipText("Toggle repeat");
return repeatButton;
}
/**
* Shortcut function to translate a button type component.
* @param btn Button type component.
* @param key Key of the button text string.
* @param tooltipKey Key of the button tooltip string.
*/
public static void tButton(AbstractButton btn, String key, String tooltipKey) {
tButton(btn, key);
btn.setToolTipText(t(tooltipKey));
}
/**
* Shortcut function to translate a button type component.
* @param btn Button type component.
* @param key Key of the button text string.
* @param tooltipKey Key of the button tooltip string.
* @param textArgs Text string arguments values.
* @param tooltipArgs Tooltip string arguments values.
*/
public static void tButton(AbstractButton btn, String key, String tooltipKey, Object[] textArgs, Object[] tooltipArgs) {
tButton(btn, key, textArgs);
btn.setToolTipText(t(tooltipKey, tooltipArgs));
}