2
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
4
* Copyright © 2007-2013 Operational Dynamics Consulting, Pty Ltd and Others
6
* The code in this file, and the program it is a part of, is made available
7
* to you by its authors as open source software: you can redistribute it
8
* and/or modify it under the terms of the GNU General Public License version
9
* 2 ("GPL") as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GPL for more details.
15
* You should have received a copy of the GPL along with this program. If not,
16
* see http://www.gnu.org/licenses/. The authors of this program may be
17
* contacted through http://java-gnome.sourceforge.net/.
21
import org.gnome.gdk.Event;
22
import org.gnome.gtk.CellRendererText;
23
import org.gnome.gtk.DataColumn;
24
import org.gnome.gtk.DataColumnStock;
25
import org.gnome.gtk.DataColumnString;
26
import org.gnome.gtk.Gtk;
27
import org.gnome.gtk.IconSize;
28
import org.gnome.gtk.ListStore;
29
import org.gnome.gtk.Stock;
30
import org.gnome.gtk.Tooltip;
31
import org.gnome.gtk.TreeIter;
32
import org.gnome.gtk.TreePath;
33
import org.gnome.gtk.TreeView;
34
import org.gnome.gtk.TreeViewColumn;
35
import org.gnome.gtk.Widget;
36
import org.gnome.gtk.Window;
39
* A tutorial example of using a TreeView with a tooltip per row.
41
* @author Sarah Leibbrand
43
public class ExampleTreeViewTooltips
46
private TreeView view;
48
private ListStore model;
50
private DataColumnString name;
52
private TreeViewColumn vertical;
54
private DataColumnStock icon;
56
public ExampleTreeViewTooltips() {
59
window = new Window();
62
* First we create the TreeView
67
* Then we have to connect the QueryTooltip handler to the view so it
68
* can display tooltips.
70
view.connect(new Widget.QueryTooltip() {
71
public boolean onQueryTooltip(Widget source, int x, int y, boolean keyboardMode,
77
* first we check whether there is anything to show a tooltip
78
* for, if not we return false so that there won't be any
81
if (!view.hasTooltipContext(x, y, keyboardMode)) {
86
* Now that we know that there can be a tooltip we retrieve
87
* the TreeIter so we can work with that to get the data:
89
iter = view.getTreeIterFromTooltipContext(x, y, keyboardMode, model);
92
* Now we can work with the tooltip and place any content we
95
* In this example a simple icon and text.
97
tooltip.setMarkup(model.getValue(iter, name));
98
tooltip.setStockIcon(model.getValue(iter, icon), IconSize.MENU);
101
* Now that we have setup the tooltip we need to set it the
102
* row or the cell. so it knows it is for that area. This will
103
* prevent it from continously trying to repaint the tooltip.
105
* In this example we will bind it the row.
107
* But for this we need the TreePath which we can also
110
path = view.getTreePathFromTooltipContext(x, y, keyboardMode);
111
view.setTooltipRow(tooltip, path);
114
* Now it is time to show the tooltip by returning true;
121
* The rest of this file is the usual minimum wrapper to make this
122
* presentable as a Window on the display.
127
window.setTitle("TreeView tooltips");
130
window.connect(new Window.DeleteEvent() {
131
public boolean onDeleteEvent(Widget source, Event event) {
138
public static void main(String[] args) {
141
new ExampleTreeViewTooltips();
147
* Create a standard TreeView as shown in another example.
149
private void createTreeView() {
150
DataColumnString index;
151
CellRendererText renderer;
154
model = new ListStore(new DataColumn[] {
155
name = new DataColumnString(),
156
index = new DataColumnString(),
157
icon = new DataColumnStock()
160
view = new TreeView(model);
162
vertical = view.appendColumn();
163
vertical.setTitle("Index");
164
renderer = new CellRendererText(vertical);
165
renderer.setText(index);
167
vertical = view.appendColumn();
168
vertical.setTitle("Name");
169
renderer = new CellRendererText(vertical);
170
renderer.setMarkup(name);
172
vertical.setSortColumn(index);
174
row = model.appendRow();
175
model.setValue(row, name, "The first row of the table\n<small>(with an edit icon)</small>");
176
model.setValue(row, index, "1.");
177
model.setValue(row, icon, Stock.EDIT);
179
row = model.appendRow();
180
model.setValue(row, name, "And now the second row\n<small>(with the apply icon)</small>");
181
model.setValue(row, index, "2.");
182
model.setValue(row, icon, Stock.APPLY);
184
row = model.appendRow();
185
model.setValue(row, name,
186
"Last but not least, the final row\n<small>(And the last one to convert)</small>");
187
model.setValue(row, index, "3.");
188
model.setValue(row, icon, Stock.CONVERT);