下面列出了javax.swing.JPanel#setToolTipText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void makePanel(WorldWindow wwd, Dimension size) {
// Make and fill the panel holding the layer titles.
this.layersPanel = new JPanel(new GridLayout(0, 1, 0, 4));
this.layersPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.fill(wwd);
// Must put the layer grid in a container to prevent scroll panel from stretching their vertical spacing.
final JPanel dummyPanel = new JPanel(new BorderLayout());
dummyPanel.add(this.layersPanel, BorderLayout.NORTH);
// Put the name panel in a scroll bar.
this.scrollPane = new JScrollPane(dummyPanel);
this.scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
if (size != null)
this.scrollPane.setPreferredSize(size);
// Add the scroll bar and name panel to a titled panel that will resize with the main window.
westPanel = new JPanel(new GridLayout(0, 1, 0, 10));
westPanel.setBorder(
new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Products")));
westPanel.setToolTipText("Products to Show");
westPanel.add(scrollPane);
this.add(westPanel, BorderLayout.CENTER);
}
@Override
public JPanel generateLongRTStats()
{
// Panel we will return with all information of this counter
JPanel panel = new JPanel();
// Layout for this panel
panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
// Color of background for this panel
panel.setBackground(new java.awt.Color(248, 248, 248));
// We add as a Tooltip the long description of this counter
panel.setToolTipText(template.complete);
// We add this html code as a JLabel in the panel
panel.add(new JLabel(generateLongStringHTML()));
// We return the panel
return panel;
}
@Override
public JPanel generateLongRTStats()
{
// Panel we will return with all information of this counter
JPanel panel = new JPanel();
// Layout for this panel
panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
// Color of background for this panel
panel.setBackground(new java.awt.Color(248, 248, 248));
// We add as a Tooltip the long description of this counter
panel.setToolTipText(template.complete);
// We add this html code as a JLabel in the panel
panel.add(new JLabel(generateLongStringHTML()));
// We return the panel
return panel;
}
private static JPanel createBox(final Color color, final Consumer<Color> consumer, final boolean alphaHidden)
{
final JPanel box = new JPanel();
String hex = alphaHidden ? ColorUtil.colorToHexCode(color) : ColorUtil.colorToAlphaHexCode(color);
box.setBackground(color);
box.setOpaque(true);
box.setPreferredSize(new Dimension(BOX_SIZE, BOX_SIZE));
box.setToolTipText("#" + hex.toUpperCase());
box.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
consumer.accept(color);
}
});
return box;
}
@Override
public Component getListCellRendererComponent(JList<? extends SpecialAttribute> list, SpecialAttribute item, int index, boolean isSelected, boolean cellHasFocus) {
JPanel panel = JPanelFactory.createBorderlessPanel();
panel.setToolTipText(item.getLongDescription());
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
JLabel lblItem = JLabelFactory.createJLabel(item.getDescription());
lblItem.setBounds(3, 13, 80, 20);
lblItem.setToolTipText(item.getLongDescription());
panel.add(lblItem);
JProgressBar itemProgressBar = JProgressBarFactory.createHorizontalJProgressBar(0, item.getMaxValue(), imageInfoReader);
itemProgressBar.setBounds(120, 13, 110, 20);
itemProgressBar.setValue(item.getCurrentValue());
itemProgressBar.setToolTipText(item.getLongDescription());
panel.add(itemProgressBar);
return panel;
}
public void setBackButtonActionListener(ActionListener a) {
buttonPanel = new JPanel();
buttonPanel.setLayout(new BorderLayout());
buttonPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
backButton = new JButton("Back");
backButton.setFont(new Font(Font.SERIF, Font.PLAIN, 24));
buttonPanel.add(backButton, BorderLayout.WEST);
this.add(buttonPanel, BorderLayout.NORTH);
backButton.addActionListener(a);
// Clock display
clockPanel = new JPanel();
clockPanel.setToolTipText("Click to change time settings.");
clockLabel = new JLabel();
clockLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
clockPanel.add(clockLabel);
clockPanel.setVisible(false);
buttonPanel.add(clockPanel, BorderLayout.EAST);
}
public void fillWithSummaryTitles(JPanel gridPanel, StatKey prefixKey, List<CounterReportTemplate> templateList) {
// Panel for titles of all cols
JPanel panelTmp = new JPanel();
// Color of this panel
panelTmp.setBackground(ModelTreeRTStats.instance().getColorByString("columnTitle"));
// We want a text alignment on the left
panelTmp.setLayout(new javax.swing.BoxLayout(panelTmp, javax.swing.BoxLayout.X_AXIS));
// First column
panelTmp.add(new JLabel("<html>Summary</html>"));
// We add this panel to the main panel for shorts stats
gridPanel.add(panelTmp);
// For each template
for (CounterReportTemplate template : templateList) {
// Others columns
JPanel panelTmp2 = new JPanel();
// Color of this panel
panelTmp2.setBackground(ModelTreeRTStats.instance().getColorByString("columnTitle"));
// We want a text alignment on the left
panelTmp2.setLayout(new javax.swing.BoxLayout(panelTmp2, javax.swing.BoxLayout.X_AXIS));
// We add to this panel short descr of each template
panelTmp2.add(new JLabel("<html>" + template.summary + "</html>"));
// We add a toolTip on head section
panelTmp2.setToolTipText(template.name);
// We add this panel to the main panel for shorts stats
gridPanel.add(panelTmp2);
}
}
@Override
public JPanel generateShortRTStats()
{
JPanel panel = new JPanel();
panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
panel.add(new JLabel(Utils.formatdouble(this.counter.globalDataset.getValue())));
panel.setToolTipText(generateRTStatsToolTip());
addMouseListenerForGraph(panel);
return panel;
}
@Override
public JPanel generateShortRTStats()
{
JPanel panel = new JPanel();
panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
panel.add(new JLabel(Utils.formatdouble(this.cumulated)));
panel.add(new JLabel(Utils.formatdouble(this.counter.globalDataset.getValue()) + "%"));
panel.setToolTipText(generateRTStatsToolTip());
addMouseListenerForGraph(panel);
return panel;
}
@Override
public JPanel generateShortRTStats()
{
JPanel panel = new JPanel();
panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
panel.add(new JLabel(this.counter.globalDataset.getText()));
panel.setToolTipText(generateRTStatsToolTip());
return panel;
}
@Override
public JPanel generateShortRTStats()
{
JPanel panel = new JPanel();
panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
panel.add(new JLabel(Utils.formatdouble(this.counter.globalDataset.getValue())));
panel.add(new JLabel(Utils.formatdouble((this.counter.globalDataset.getValue() * 1000 / this.reportEndTimestamp)) + "/s"));
panel.setToolTipText(generateRTStatsToolTip());
addMouseListenerForGraph(panel);
return panel;
}
void updateOffer(ItemDefinition offerItem, BufferedImage itemImage, @Nullable GrandExchangeOffer newOffer)
{
if (newOffer == null || newOffer.getState() == EMPTY)
{
return;
}
else
{
cardLayout.show(container, FACE_CARD);
itemName.setText(offerItem.getName());
itemIcon.setIcon(new ImageIcon(itemImage));
for (ActionListener al : geLink.getActionListeners())
{
geLink.removeActionListener(al);
}
geLink.addActionListener(actionEvent -> geLink(offerItem.getName(), offerItem.getId()));
boolean buying = newOffer.getState() == GrandExchangeOfferState.BOUGHT
|| newOffer.getState() == GrandExchangeOfferState.BUYING
|| newOffer.getState() == GrandExchangeOfferState.CANCELLED_BUY;
String offerState = (buying ? "Bought " : "Sold ")
+ QuantityFormatter.quantityToRSDecimalStack(newOffer.getQuantitySold()) + " / "
+ QuantityFormatter.quantityToRSDecimalStack(newOffer.getTotalQuantity());
offerInfo.setText(offerState);
itemPrice.setText(htmlLabel("Price each: ", QuantityFormatter.formatNumber(newOffer.getPrice())));
String action = buying ? "Spent: " : "Received: ";
offerSpent.setText(htmlLabel(action, QuantityFormatter.formatNumber(newOffer.getSpent()) + " / "
+ QuantityFormatter.formatNumber(newOffer.getPrice() * newOffer.getTotalQuantity())));
progressBar.setForeground(getProgressColor(newOffer));
progressBar.setMaximumValue(newOffer.getTotalQuantity());
progressBar.setValue(newOffer.getQuantitySold());
/* Couldn't set the tooltip for the container panel as the children override it, so I'm setting
* the tooltips on the children instead. */
for (Component c : container.getComponents())
{
if (c instanceof JPanel)
{
JPanel panel = (JPanel) c;
panel.setToolTipText(htmlTooltip(((int) progressBar.getPercentage()) + "%"));
}
}
}
revalidate();
repaint();
}
public ElevationModelManagerPanel(final WorldWindow wwd)
{
super(new BorderLayout(10, 10));
this.modelNamesPanel = new JPanel(new GridLayout(0, 1, 0, 5));
this.modelNamesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Add the panel to a titled panel.
JPanel titlePanel = new JPanel(new GridLayout(0, 1, 0, 10));
titlePanel.setBorder(
new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Elevations")));
titlePanel.setToolTipText("Elevation models to use");
titlePanel.add(this.modelNamesPanel);
this.add(titlePanel, BorderLayout.CENTER);
this.fill(wwd);
// Add a property change listener that causes this panel to be updated whenever the elevation model list
// changes.
wwd.addPropertyChangeListener(new PropertyChangeListener()
{
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent)
{
if (propertyChangeEvent.getPropertyName().equals(AVKey.ELEVATION_MODEL))
if (!SwingUtilities.isEventDispatchThread())
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
update(wwd);
}
});
}
});
else
update(wwd);
}
});
}
/**
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
* java.lang.Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
JPanel newPanel = new JPanel();
newPanel.setLayout(new OverlayLayout(newPanel));
Color bgColor;
if (isSelected)
bgColor = table.getSelectionBackground();
else
bgColor = table.getBackground();
newPanel.setBackground(bgColor);
if (hasFocus) {
Border border = null;
if (isSelected)
border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
if (border == null)
border = UIManager.getBorder("Table.focusCellHighlightBorder");
if (border != null)
newPanel.setBorder(border);
}
if (value != null) {
if (value instanceof JComponent) {
newPanel.add((JComponent) value);
} else {
JLabel newLabel = new JLabel();
if (value instanceof IIsotope) {
IIsotope is = (IIsotope) value;
newLabel.setText(is.getSymbol());
} else {
newLabel.setText(value.toString());
}
if (font != null)
newLabel.setFont(font);
else if (table.getFont() != null)
newLabel.setFont(table.getFont());
newPanel.add(newLabel);
}
if (createTooltips)
newPanel.setToolTipText(value.toString());
}
return newPanel;
}
@Override
protected JPanel assemble() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
JLabel appNameLabel = new JLabel(doc.getTitle(), SwingConstants.CENTER);
Font font = appNameLabel.getFont();
Font boldFont = new Font(font.getFontName(), Font.BOLD, font.getSize() + 2);
appNameLabel.setFont(boldFont);
appNameLabel.setToolTipText(doc.getTitle());
Dimension tmp = appNameLabel.getPreferredSize();
tmp.width = 150;
appNameLabel.setPreferredSize(tmp);
JLabel vendorNameLabel = new JLabel(doc.getCreator(), SwingConstants.CENTER);
tmp = vendorNameLabel.getPreferredSize();
tmp.width = 150;
vendorNameLabel.setPreferredSize(tmp);
vendorNameLabel.setToolTipText(doc.getCreator());
button = new JButton();
button.addActionListener(this);
button.setIcon(SPINNER);
globals.get(ImageLoaderService.class).request(this,
DocUtil.getAppIconUrl(doc));
JPanel stars = new StarPanel(5,
doc.getAggregateRating().getStarRating() / 5);
DecimalFormat df = new DecimalFormat("#.## \u2605");
stars.setToolTipText(df.format(doc.getAggregateRating().getStarRating()));
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets.bottom = 10;
panel.add(button, gbc);
gbc.insets.bottom = 0;
gbc.gridy++;
panel.add(appNameLabel, gbc);
gbc.gridy++;
panel.add(vendorNameLabel, gbc);
gbc.gridy++;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets.top = 10;
gbc.insets.left = 15;
gbc.insets.right = 15;
gbc.insets.bottom = 15;
panel.add(stars, gbc);
return panel;
}
public final void defineLayout (final String currentLang)
{
panel.removeAll();
final Set<String> relevant = new TreeSet<String>();
relevant.addAll(desired);
relevant.addAll(nonDesired);
final String gap = "$lcgap";
final StringBuilder columns = new StringBuilder();
for (int i = 0; i < relevant.size(); i++) {
if (columns.length() > 0) {
columns.append(",");
}
columns.append(gap)
.append(",")
.append("pref");
}
final CellConstraints cst = new CellConstraints();
final FormLayout layout = new FormLayout(
columns.toString(),
"center:16dlu");
final PanelBuilder builder = new PanelBuilder(layout, panel);
PanelBuilder.setOpaqueDefault(true);
builder.background(Color.WHITE);
int col = 2;
for (String lang : relevant) {
final FormLayout langLayout = new FormLayout(
"$lcgap,center:pref,$lcgap",
"center:12dlu");
final JPanel comp = new JPanel();
comp.setBackground(getBackground(lang, currentLang));
final PanelBuilder langBuilder = new PanelBuilder(
langLayout,
comp);
langBuilder.addROLabel(lang, CC.xy(2, 1));
comp.addMouseListener(createPopupListener(lang));
comp.setToolTipText("Use right-click to remove this language");
builder.add(comp, cst.xy(col, 1));
col += 2;
}
panel.revalidate();
panel.repaint();
}
/**
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
* java.lang.Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
JPanel newPanel = new JPanel();
newPanel.setLayout(new OverlayLayout(newPanel));
Color bgColor;
if (isSelected)
bgColor = table.getSelectionBackground();
else
bgColor = table.getBackground();
newPanel.setBackground(bgColor);
if (hasFocus) {
Border border = null;
if (isSelected)
border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
if (border == null)
border = UIManager.getBorder("Table.focusCellHighlightBorder");
/*
* The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
* otherwise setBorder() may throw a NullPointerException
*/
if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
newPanel.setBorder(border);
}
}
if (value != null) {
FeatureStatus status = (FeatureStatus) value;
switch (status) {
case DETECTED:
newPanel.add(greenCircle);
break;
case ESTIMATED:
newPanel.add(yellowCircle);
break;
case MANUAL:
newPanel.add(orangeCircle);
break;
default:
newPanel.add(redCircle);
break;
}
newPanel.setToolTipText(status.toString());
} else {
newPanel.add(redCircle);
}
return newPanel;
}
public LayerManagerPanel(final WorldWindow wwd)
{
super(new BorderLayout(10, 10));
this.layerNamesPanel = new JPanel(new GridLayout(0, 1, 0, 5));
this.layerNamesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Must put the layer grid in a container to prevent the scroll pane from stretching vertical spacing.
JPanel dummyPanel = new JPanel(new BorderLayout());
dummyPanel.add(this.layerNamesPanel, BorderLayout.NORTH);
// Put the layers panel in a scroll pane.
JScrollPane scrollPane = new JScrollPane(dummyPanel);
// Suppress the scroll pane's default border.
scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
// Add the scroll pane to a titled panel that will resize with the main window.
JPanel titlePanel = new JPanel(new GridLayout(0, 1, 0, 10));
titlePanel.setBorder(
new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Layers")));
titlePanel.setToolTipText("Layers to Show");
titlePanel.add(scrollPane);
titlePanel.setPreferredSize(new Dimension(200, 500));
this.add(titlePanel, BorderLayout.CENTER);
this.fill(wwd);
this.plainFont = this.getFont().deriveFont(Font.PLAIN);
this.boldFont = this.getFont().deriveFont(Font.BOLD);
// Register a rendering listener that updates the was-rendered state of each image layer.
wwd.addRenderingListener(new RenderingListener()
{
@Override
public void stageChanged(RenderingEvent event)
{
updateLayerActivity(wwd);
}
});
// Add a property change listener that causes this layer panel to be updated whenever the layer list changes.
wwd.getModel().getLayers().addPropertyChangeListener(new PropertyChangeListener()
{
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent)
{
if (propertyChangeEvent.getPropertyName().equals(AVKey.LAYERS))
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
update(wwd);
}
});
}
});
}
void updateOffer(ItemComposition offerItem, BufferedImage itemImage, @Nullable GrandExchangeOffer newOffer)
{
if (newOffer == null || newOffer.getState() == EMPTY)
{
return;
}
else
{
cardLayout.show(container, FACE_CARD);
itemName.setText(offerItem.getName());
itemIcon.setIcon(new ImageIcon(itemImage));
boolean buying = newOffer.getState() == GrandExchangeOfferState.BOUGHT
|| newOffer.getState() == GrandExchangeOfferState.BUYING
|| newOffer.getState() == GrandExchangeOfferState.CANCELLED_BUY;
String offerState = (buying ? "Bought " : "Sold ")
+ QuantityFormatter.quantityToRSDecimalStack(newOffer.getQuantitySold()) + " / "
+ QuantityFormatter.quantityToRSDecimalStack(newOffer.getTotalQuantity());
offerInfo.setText(offerState);
itemPrice.setText(htmlLabel("Price each: ", QuantityFormatter.formatNumber(newOffer.getPrice())));
String action = buying ? "Spent: " : "Received: ";
offerSpent.setText(htmlLabel(action, QuantityFormatter.formatNumber(newOffer.getSpent()) + " / "
+ QuantityFormatter.formatNumber(newOffer.getPrice() * newOffer.getTotalQuantity())));
progressBar.setForeground(getProgressColor(newOffer));
progressBar.setMaximumValue(newOffer.getTotalQuantity());
progressBar.setValue(newOffer.getQuantitySold());
/* Couldn't set the tooltip for the container panel as the children override it, so I'm setting
* the tooltips on the children instead. */
for (Component c : container.getComponents())
{
if (c instanceof JPanel)
{
JPanel panel = (JPanel) c;
panel.setToolTipText(htmlTooltip(((int) progressBar.getPercentage()) + "%"));
}
}
}
revalidate();
repaint();
}
private Component makeUpperPanel() {
JPanel ret = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
c.weighty = 0.0;
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
c.gridx += 1;
c.weightx = 0.0;
JPanel typePanel = new JPanel();
typePanel.add(new JLabel(getString(KEY_TYPE)));
typeChooser = new TypeChooser(true);
typePanel.add(typeChooser);
typePanel.setToolTipText(getString(KEY_TYPE_TOOLTIP));
typeChooser.setToolTipText(getString(KEY_TYPE_TOOLTIP));
ret.add(typePanel, c);
c.gridx += 1;
c.weightx = 0.0;
JPanel levelPanel = new JPanel();
levelPanel.add(new JLabel(getString(KEY_LEVEL)));
SpinnerNumberModel snm = new SpinnerNumberModel(0, 0, Species.MAX_LEVEL, 1);
levelSpinner = new JSpinner(snm);
levelPanel.add(levelSpinner);
levelPanel.setToolTipText(getString(KEY_LEVEL_TOOLTIP));
levelSpinner.setToolTipText(getString(KEY_LEVEL_TOOLTIP));
ret.add(levelPanel, c);
c.gridx += 1;
c.weightx = 1.0;
JPanel stringPanel = new JPanel(new GridBagLayout());
GridBagConstraints sc = new GridBagConstraints();
sc.fill = GridBagConstraints.HORIZONTAL;
sc.gridx = 1;
stringPanel.add(new JLabel(getString(KEY_NAME)), sc);
textField = new JTextField();
sc.gridx += 1;
sc.weightx = 1.0;
sc.insets = new Insets(0, 5, 0, 5);
stringPanel.add(textField, sc);
stringPanel.setToolTipText(getString(KEY_NAME_TOOLTIP));
textField.setToolTipText(getString(KEY_NAME_TOOLTIP));
ret.add(stringPanel, c);
c.gridx += 1;
c.weightx = 0.0;
megaFilter = new JCheckBox(getString(KEY_MEGA_FILTER));
megaFilter.setToolTipText(getString(KEY_MEGA_FILTER_TOOLTIP));;
ret.add(megaFilter, c);
c.gridx += 1;
c.weightx = 0.0;
effectFilter = new EffectChooser(false, EffectChooser.DefaultEntry.NO_FILTER);
effectFilter.setToolTipText(getString(KEY_EFFECT_FILTER_TOOLTIP));
ret.add(effectFilter, c);
c.gridx += 1;
c.weightx = 0.0;
@SuppressWarnings("serial")
JButton copyToLauncher = new JButton(new AbstractAction(getString(KEY_MAKE_DEFAULT)) {
@Override
public void actionPerformed(ActionEvent e) {
makeTeamDefault();
}
});
copyToLauncher.setToolTipText(getString(KEY_MAKE_DEFAULT_TOOLTIP));
ret.add(copyToLauncher, c);
getMinUpperPanel = new Supplier<Dimension>() {
@Override
public Dimension get() {
Dimension ret = new Dimension(10 + 50, 0);
for (Component c : new Component[] { typePanel, levelPanel, stringPanel, megaFilter, effectFilter,
copyToLauncher }) {
Dimension temp = c.getPreferredSize();
int width = temp.width + ret.width;
int height = Math.max(temp.height, ret.height);
ret.setSize(width, height);
}
return ret;
}
};
return ret;
}