List of usage examples for javax.swing JComponent setToolTipText
@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.") public void setToolTipText(String text)
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
private void markFieldInHistoricalView(CollectableGenericObjectWithDependants clctlowdCurrent, String sFieldName, CollectableField clctfShown) { if (clctlowdCurrent != null) { final CollectableField clctf = clctlowdCurrent.getField(sFieldName); if (!clctfShown.equals(clctf)) { final Collection<CollectableComponent> collclctcomp = layoutrootDetails .getCollectableComponentsFor(sFieldName); if (!collclctcomp.isEmpty()) { final CollectableComponent clctcomp = collclctcomp.iterator().next(); final JComponent compFocussable = clctcomp.getFocusableComponent(); String initialToolTip = (String) compFocussable.getClientProperty("initialToolTip"); if (initialToolTip == null) { initialToolTip = StringUtils.emptyIfNull(compFocussable.getToolTipText()); compFocussable.putClientProperty("initialToolTip", initialToolTip); }//w w w . j a va 2s .co m if (clctcomp instanceof CollectableComboBox) { CollectableComboBox clctcmbx = (CollectableComboBox) clctcomp; clctcmbx.getJComboBox().setRenderer(clctcmbx.new CollectableFieldRenderer() { @Override protected void paintComponent(Graphics g) { setBackground(colorHistoricalChanged); super.paintComponent(g); } }); } else compFocussable.setBackground(colorHistoricalChanged); final String sToolTip = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.4", "{0} [Ge\u00e4ndert; aktueller Wert: \"{1}\"]", initialToolTip, clctf.toString()); compFocussable.setToolTipText(sToolTip); clctcomp.getJComponent().setToolTipText(sToolTip); // todo: mark fields which are not tracked in logbook? } } } }
From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java
/** Initializes the components. */ private void initComponents() { sorter = new ViewerSorter(); cancelButton = new JButton("Cancel"); cancelButton.setToolTipText("Close the dialog."); cancelButton.setActionCommand("" + CANCEL); cancelButton.addActionListener(this); applyButton = new JButton("Run Script"); applyButton.setToolTipText("Run the selected script."); applyButton.setActionCommand("" + APPLY); applyButton.addActionListener(this); IconManager icons = IconManager.getInstance(); menuButton = new JButton(icons.getIcon(IconManager.FILTER_MENU)); menuButton.setText("Script"); menuButton.setHorizontalTextPosition(JButton.LEFT); menuButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { Object src = e.getSource(); if (src instanceof Component) { Point p = e.getPoint(); createOptionMenu().show((Component) src, p.x, p.y); }/* w w w .j a va 2 s. c o m*/ } }); components = new LinkedHashMap<String, ScriptComponent>(); componentsAll = new LinkedHashMap<String, ScriptComponent>(); Map<String, ParamData> types = script.getInputs(); if (types == null) return; List<ScriptComponent> results = new ArrayList<ScriptComponent>(); Entry<String, ParamData> entry; ParamData param; JComponent comp; ScriptComponent c; String name; Class<?> type; Object defValue; Iterator<Entry<String, ParamData>> i = types.entrySet().iterator(); List<Object> values; Number n; String details = ""; String text = ""; String grouping; String parent; Map<String, List<ScriptComponent>> childrenMap = new HashMap<String, List<ScriptComponent>>(); List<ScriptComponent> l; int length; boolean columnsSet; while (i.hasNext()) { text = ""; columnsSet = false; comp = null; entry = i.next(); param = entry.getValue(); name = entry.getKey(); type = param.getPrototype(); values = param.getValues(); defValue = param.getDefaultValue(); if (CollectionUtils.isNotEmpty(values)) { comp = createValuesBox(values, defValue); } if (Long.class.equals(type) || Integer.class.equals(type) || Float.class.equals(type) || Double.class.equals(type)) { if (comp == null) { if (script.isIdentifier(name)) { comp = new NumericalTextField(); ((NumericalTextField) comp).setNumberType(type); ((NumericalTextField) comp).setNegativeAccepted(false); if (CollectionUtils.isNotEmpty(refObjects)) { //support of image type DataObject object = refObjects.get(0); if (script.isSupportedType(object, name)) { defValue = object.getId(); } } } else { comp = new NumericalTextField(); ((NumericalTextField) comp).setNumberType(type); n = param.getMinValue(); if (n != null) { if (Long.class.equals(type)) { text += "Min: " + n.longValue() + " "; ((NumericalTextField) comp).setMinimum(n.longValue()); } else if (Integer.class.equals(type)) { text += "Min: " + n.intValue() + " "; ((NumericalTextField) comp).setMinimum(n.intValue()); } else if (Double.class.equals(type)) { text += "Min: " + n.doubleValue() + " "; ((NumericalTextField) comp).setMinimum(n.doubleValue()); } else if (Float.class.equals(type)) { text += "Min: " + n.floatValue() + " "; ((NumericalTextField) comp).setMinimum(n.floatValue()); } } else { ((NumericalTextField) comp).setNegativeAccepted(true); } n = param.getMaxValue(); if (n != null) { if (Long.class.equals(type)) { text += "Max: " + n.longValue() + " "; ((NumericalTextField) comp).setMaximum(n.longValue()); } else if (Integer.class.equals(type)) { text += "Max: " + n.intValue() + " "; ((NumericalTextField) comp).setMaximum(n.intValue()); } else if (Double.class.equals(type)) { text += "Max: " + n.doubleValue() + " "; ((NumericalTextField) comp).setMaximum(n.doubleValue()); } else if (Float.class.equals(type)) { text += "Max: " + n.floatValue() + " "; ((NumericalTextField) comp).setMaximum(n.floatValue()); } } } if (defValue != null) ((NumericalTextField) comp).setText("" + defValue); } } else if (String.class.equals(type)) { if (comp == null) { comp = new JTextField(); if (defValue != null) { length = defValue.toString().length(); String s = defValue.toString().trim(); ((JTextField) comp).setColumns(length); ((JTextField) comp).setText(s); columnsSet = s.length() > 0; } } } else if (Boolean.class.equals(type)) { if (comp == null) { comp = new JCheckBox(); if (defValue != null) ((JCheckBox) comp).setSelected((Boolean) defValue); } } else if (Map.class.equals(type)) { if (comp == null) comp = new ComplexParamPane(param.getKeyType(), param.getValueType()); else comp = new ComplexParamPane(param.getKeyType(), (JComboBox) comp); } else if (List.class.equals(type)) { if (script.isIdentifier(name)) { identifier = new IdentifierParamPane(Long.class); identifier.setValues(refObjects); identifier.addDocumentListener(this); comp = identifier; } else { if (comp == null) comp = new ComplexParamPane(param.getKeyType()); else comp = new ComplexParamPane((JComboBox) comp); } } if (comp != null) { if (comp instanceof JTextField) { if (!columnsSet) ((JTextField) comp).setColumns(ScriptComponent.COLUMNS); ((JTextField) comp).getDocument().addDocumentListener(this); } if (comp instanceof ComplexParamPane) comp.addPropertyChangeListener(this); comp.setToolTipText(param.getDescription()); c = new ScriptComponent(comp, name); if (text.trim().length() > 0) c.setUnit(text); if (!(comp instanceof JComboBox || comp instanceof JCheckBox)) c.setRequired(!param.isOptional()); if (details != null && details.trim().length() > 0) c.setInfo(details); if (comp instanceof JComboBox && script.isDataType(name)) { dataTypes = (JComboBox) comp; dataTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDataTypeChanges(); } }); } grouping = param.getGrouping(); parent = param.getParent(); c.setParentIndex(parent); if (parent.length() > 0) { l = childrenMap.get(parent); if (l == null) { l = new ArrayList<ScriptComponent>(); childrenMap.put(parent, l); } l.add(c); } if (grouping.length() > 0) { c.setGrouping(grouping); c.setNameLabel(grouping); } else { c.setNameLabel(name); } if (c.hasChildren() || parent.length() == 0) { results.add(c); } componentsAll.put(c.getParameterName(), c); } } ScriptComponent key; Iterator<ScriptComponent> k = results.iterator(); while (k.hasNext()) { key = k.next(); grouping = key.getGrouping(); l = childrenMap.get(grouping); childrenMap.remove(grouping); if (l != null) key.setChildren(sorter.sort(l)); } if (childrenMap != null && childrenMap.size() > 0) { Iterator<String> j = childrenMap.keySet().iterator(); ScriptComponent sc; while (j.hasNext()) { parent = j.next(); sc = new ScriptComponent(); sc.setGrouping(parent); sc.setNameLabel(parent); sc.setChildren(sorter.sort(childrenMap.get(parent))); results.add(sc); } } List<ScriptComponent> sortedKeys = sorter.sort(results); k = sortedKeys.iterator(); while (k.hasNext()) { key = k.next(); components.put(key.getParameterName(), key); } setSelectedDataType(); if (identifier != null) identifier.addPropertyChangeListener(this); canRunScript(); }
From source file:org.revager.tools.GUITools.java
/** * Creates a new standard table.// www .j a v a 2 s. c o m * * @param model * the table model * @param showHeader * true if the header of the table should be visible * * @return the newly created table */ @SuppressWarnings("serial") public static JTable newStandardTable(TableModel model, boolean showHeader) { /* * Prep. for rollover */ if (lastRolloverKey == Integer.MAX_VALUE) { lastRolloverKey = 0; } else { lastRolloverKey++; } final int keyIdx = lastRolloverKey; rollOverRowIndex.put(keyIdx, -1); final JTable table = new JTable(model) { @Override public boolean editCellAt(int row, int column, java.util.EventObject e) { boolean result = super.editCellAt(row, column, e); final Component editor = getEditorComponent(); TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer(); Font cellFont = null; if (renderer instanceof DefaultTableCellRenderer) { cellFont = ((DefaultTableCellRenderer) renderer).getFont(); } if (editor != null && editor instanceof JTextComponent) { JTextComponent jTextComponent = (JTextComponent) editor; if (e == null) { jTextComponent.selectAll(); } else { SwingUtilities.invokeLater(jTextComponent::selectAll); } jTextComponent.setBorder(UI.MARKED_BORDER_INLINE); if (cellFont != null) { jTextComponent.setFont(cellFont); } editor.requestFocusInWindow(); } return result; } @Override public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof DefaultTableCellRenderer) { ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3)); } return renderer; } @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { Component comp = super.prepareRenderer(renderer, row, col); // Rollover comp.setBackground(getBackground()); comp = super.prepareRenderer(renderer, row, col); if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) { comp.setForeground(getForeground()); comp.setBackground(UI.BLUE_BACKGROUND_COLOR); } // Tooltips JComponent jcomp = (JComponent) comp; if (renderer instanceof DefaultTableCellRenderer) { String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText(); if (!StringUtils.isEmpty(toolTip)) { jcomp.setToolTipText(toolTip); } } return comp; } }; // Table properties table.setRowHeight(UI.TABLE_ROW_HEIGHT); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowGrid(false); table.setShowHorizontalLines(true); table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // Rollover MouseInputAdapter rolloverListener = new MouseInputAdapter() { @Override public void mouseExited(MouseEvent e) { rollOverRowIndex.put(keyIdx, -1); table.repaint(); } @Override public void mouseMoved(MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (row != rollOverRowIndex.get(keyIdx)) { rollOverRowIndex.put(keyIdx, row); table.repaint(); } } }; table.addMouseMotionListener(rolloverListener); table.addMouseListener(rolloverListener); // Header if (!showHeader) { table.setTableHeader(null); } return table; }