~ubuntu-branches/debian/sid/java-gnome/sid

« back to all changes in this revision

Viewing changes to doc/examples/tooltip/ExampleTreeViewTooltips.java

  • Committer: Package Import Robot
  • Author(s): Guillaume Mazoyer
  • Date: 2014-05-19 17:39:50 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20140519173950-fnvrdx3b8fa94hj0
Tags: 4.1.3-1
* New upstream release.
* debian/control
  - Remove libunique dependency.
  - Remove DM-Upload-Allowed field.
  - Add dbus-x11 dependency to take doc screenshots.
  - Update Standards-Version to 3.9.4.
* debian/README.Maintainer
  - Add instructions for maintainers.
* debian/libjava-gnome-java.docs
  - Update documentation filenames.
* debian/libjava-gnome-java-doc.install
  - Fix HACKING file installation.
* debian/patches/02_unique_dependency.diff
  - Remove no longer needed patch (fixed upstream).
* debian/patches/02_build_python.diff
  - Add patch to fix build process (python2 env variable not found).
* debian/patches/03_build_doc_snapshots.diff (Closes: #748565)
  - Add patch to fix build process of the documentation (accessibilty bug).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * java-gnome, a UI library for writing GTK and GNOME programs from Java!
 
3
 *
 
4
 * Copyright © 2007-2013 Operational Dynamics Consulting, Pty Ltd and Others
 
5
 *
 
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.
 
10
 *
 
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.
 
14
 *
 
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/.
 
18
 */
 
19
package tooltip;
 
20
 
 
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;
 
37
 
 
38
/**
 
39
 * A tutorial example of using a TreeView with a tooltip per row.
 
40
 * 
 
41
 * @author Sarah Leibbrand
 
42
 */
 
43
public class ExampleTreeViewTooltips
 
44
{
 
45
 
 
46
    private TreeView view;
 
47
 
 
48
    private ListStore model;
 
49
 
 
50
    private DataColumnString name;
 
51
 
 
52
    private TreeViewColumn vertical;
 
53
 
 
54
    private DataColumnStock icon;
 
55
 
 
56
    public ExampleTreeViewTooltips() {
 
57
        final Window window;
 
58
 
 
59
        window = new Window();
 
60
 
 
61
        /*
 
62
         * First we create the TreeView
 
63
         */
 
64
        createTreeView();
 
65
 
 
66
        /*
 
67
         * Then we have to connect the QueryTooltip handler to the view so it
 
68
         * can display tooltips.
 
69
         */
 
70
        view.connect(new Widget.QueryTooltip() {
 
71
            public boolean onQueryTooltip(Widget source, int x, int y, boolean keyboardMode,
 
72
                    Tooltip tooltip) {
 
73
                TreeIter iter;
 
74
                TreePath path;
 
75
 
 
76
                /*
 
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
 
79
                 * tooltip shown.
 
80
                 */
 
81
                if (!view.hasTooltipContext(x, y, keyboardMode)) {
 
82
                    return false;
 
83
                }
 
84
 
 
85
                /*
 
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:
 
88
                 */
 
89
                iter = view.getTreeIterFromTooltipContext(x, y, keyboardMode, model);
 
90
 
 
91
                /*
 
92
                 * Now we can work with the tooltip and place any content we
 
93
                 * would want in it.
 
94
                 * 
 
95
                 * In this example a simple icon and text.
 
96
                 */
 
97
                tooltip.setMarkup(model.getValue(iter, name));
 
98
                tooltip.setStockIcon(model.getValue(iter, icon), IconSize.MENU);
 
99
 
 
100
                /*
 
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.
 
104
                 * 
 
105
                 * In this example we will bind it the row.
 
106
                 * 
 
107
                 * But for this we need the TreePath which we can also
 
108
                 * retrieve.
 
109
                 */
 
110
                path = view.getTreePathFromTooltipContext(x, y, keyboardMode);
 
111
                view.setTooltipRow(tooltip, path);
 
112
 
 
113
                /*
 
114
                 * Now it is time to show the tooltip by returning true;
 
115
                 */
 
116
                return true;
 
117
            }
 
118
        });
 
119
 
 
120
        /*
 
121
         * The rest of this file is the usual minimum wrapper to make this
 
122
         * presentable as a Window on the display.
 
123
         */
 
124
 
 
125
        window.add(view);
 
126
 
 
127
        window.setTitle("TreeView tooltips");
 
128
        window.showAll();
 
129
 
 
130
        window.connect(new Window.DeleteEvent() {
 
131
            public boolean onDeleteEvent(Widget source, Event event) {
 
132
                Gtk.mainQuit();
 
133
                return false;
 
134
            }
 
135
        });
 
136
    }
 
137
 
 
138
    public static void main(String[] args) {
 
139
        Gtk.init(args);
 
140
 
 
141
        new ExampleTreeViewTooltips();
 
142
 
 
143
        Gtk.main();
 
144
    }
 
145
 
 
146
    /*
 
147
     * Create a standard TreeView as shown in another example.
 
148
     */
 
149
    private void createTreeView() {
 
150
        DataColumnString index;
 
151
        CellRendererText renderer;
 
152
        TreeIter row;
 
153
 
 
154
        model = new ListStore(new DataColumn[] {
 
155
            name = new DataColumnString(),
 
156
            index = new DataColumnString(),
 
157
            icon = new DataColumnStock()
 
158
        });
 
159
 
 
160
        view = new TreeView(model);
 
161
 
 
162
        vertical = view.appendColumn();
 
163
        vertical.setTitle("Index");
 
164
        renderer = new CellRendererText(vertical);
 
165
        renderer.setText(index);
 
166
 
 
167
        vertical = view.appendColumn();
 
168
        vertical.setTitle("Name");
 
169
        renderer = new CellRendererText(vertical);
 
170
        renderer.setMarkup(name);
 
171
 
 
172
        vertical.setSortColumn(index);
 
173
 
 
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);
 
178
 
 
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);
 
183
 
 
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);
 
189
    }
 
190
}