File: jitter_ui.c

package info (click to toggle)
ggobi 2.1.9~20091212-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,340 kB
  • ctags: 5,083
  • sloc: ansic: 57,242; xml: 30,604; cpp: 833; makefile: 355; java: 225; perl: 201; sh: 122; python: 23
file content (213 lines) | stat: -rw-r--r-- 6,993 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* jitter_ui.c */
/*
 * ggobi
 * Copyright (C) AT&T, Duncan Temple Lang, Dianne Cook 1999-2005
 *
 * ggobi is free software; you may use, redistribute, and/or modify it
 * under the terms of the Common Public License, which is distributed
 * with the source code and displayed on the ggobi web site, 
 * www.ggobi.org.  For more information, contact the authors:
 *
 *   Deborah F. Swayne   dfs@research.att.com
 *   Di Cook             dicook@iastate.edu
 *   Duncan Temple Lang  duncan@wald.ucdavis.edu
 *   Andreas Buja        andreas.buja@wharton.upenn.edu
*/

#include <gtk/gtk.h>
#include "vars.h"
#include "externs.h"

void
jitter_vars_init (GGobiData * d)
{
  d->jitter.type = UNIFORM;
  d->jitter.convex = true;
}

static void
jitter_cb (GtkButton * w, ggobid * gg)
{
  GtkWidget *tree_view =
    get_tree_view_from_object (G_OBJECT (gg->jitter_ui.window));
  GGobiData *d =
    (GGobiData *) g_object_get_data (G_OBJECT (tree_view), "datad");
  gint *vars;                   // = (gint *) g_malloc (d->ncols * sizeof(gint));
  gint nvars;

  vars = get_selections_from_tree_view (tree_view, &nvars);

  if (nvars) {
    rejitter (vars, nvars, d, gg);
    g_free (vars);
  }
}

/*
 * Set the degree of jittering
*/
static void
degree_cb (GtkAdjustment * adj, ggobid * gg)
{
  GtkWidget *tree_view =
    get_tree_view_from_object (G_OBJECT (gg->jitter_ui.window));
  GGobiData *d =
    (GGobiData *) g_object_get_data (G_OBJECT (tree_view), "datad");
  gint *vars;                   // = (gint *) g_malloc (d->ncols * sizeof(gint));
  gint nvars;

  vars = get_selections_from_tree_view (tree_view, &nvars);

  jitter_value_set (adj->value, d, gg);
  if (nvars) {
    rejitter (vars, nvars, d, gg);
    g_free (vars);
  }
}

/*-- called when closed from the close button --*/
static void
close_btn_cb (GtkWidget * w, ggobid * gg)
{
  gtk_widget_destroy (gg->jitter_ui.window);
  gg->jitter_ui.window = NULL;
}

/*-- called when closed from the window manager --*/
static void
close_wmgr_cb (GtkWidget * w, GdkEvent * event, ggobid * gg)
{
  gtk_widget_destroy (gg->jitter_ui.window);
  gg->jitter_ui.window = NULL;
}

static gchar *type_lbl[] = { "Uniform", "Normal" };

static void
type_cb (GtkWidget * w, ggobid * gg)
{
  gint indx = gtk_combo_box_get_active (GTK_COMBO_BOX (w));
  GtkWidget *tree_view =
    get_tree_view_from_object (G_OBJECT (gg->jitter_ui.window));
  GGobiData *d =
    (GGobiData *) g_object_get_data (G_OBJECT (tree_view), "datad");
  gint *vars;                   // = (gint *) g_malloc (d->ncols * sizeof(gint));
  gint nvars;

  vars = get_selections_from_tree_view (tree_view, &nvars);

  d->jitter.type = indx;

  if (nvars) {
    rejitter (vars, nvars, d, gg);
    g_free (vars);
  }
}

void
jitter_window_open (ggobid * gg)
{

  GtkWidget *btn, *lbl;
  GtkWidget *vbox, *vb, *hb;
  GtkWidget *sbar, *opt;
  GtkObject *adj;
  GtkWidget *notebook;

  /*-- if used before we have data, bail out --*/
  if (gg->d == NULL || g_slist_length (gg->d) == 0)
    return;

  else {

    if (gg->jitter_ui.window == NULL) {

      gg->jitter_ui.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);


      gtk_window_set_transient_for(GTK_WINDOW(gg->jitter_ui.window), gg->main_window);
      gtk_window_set_destroy_with_parent(GTK_WINDOW(gg->jitter_ui.window), true);


      /*-- suggested by Gordon Deane --*/
      gtk_window_set_default_size (GTK_WINDOW (gg->jitter_ui.window), 200,
                                   400);
      /*-- 400 looks too big on the laptop, trying other numbers   --*/
      gtk_window_set_default_size (GTK_WINDOW (gg->jitter_ui.window), 200,
                                   250);
      /*--                           --*/

      g_signal_connect (G_OBJECT (gg->jitter_ui.window), "delete_event",
                        G_CALLBACK (close_wmgr_cb), (gpointer) gg);
      gtk_window_set_title (GTK_WINDOW (gg->jitter_ui.window), "Jitter Data");

      gtk_container_set_border_width (GTK_CONTAINER (gg->jitter_ui.window),
                                      10);

      vbox = gtk_vbox_new (false, 2);
      gtk_container_add (GTK_CONTAINER (gg->jitter_ui.window), vbox);

      /* Create a notebook, set the position of the tabs */
      notebook = create_variable_notebook (vbox,
                                           GTK_SELECTION_MULTIPLE,
                                           all_vartypes, all_datatypes,
                                           G_CALLBACK (NULL), NULL, gg);

      /*-- option menu --*/
      opt = gtk_combo_box_new_text ();
      gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), opt,
                            "The jittering is either distributed uniform or normal",
                            NULL);
      gtk_box_pack_start (GTK_BOX (vbox), opt, false, false, 0);
      populate_combo_box (opt, type_lbl, G_N_ELEMENTS (type_lbl),
                          G_CALLBACK (type_cb), gg);

      /*-- vbox for label and rangewidget --*/
      vb = gtk_vbox_new (true, 2);
      gtk_box_pack_start (GTK_BOX (vbox), vb, false, false, 1);

      lbl = gtk_label_new_with_mnemonic ("_Degree of jitter:");
      gtk_misc_set_alignment (GTK_MISC (lbl), 0, 0.5);
      gtk_box_pack_start (GTK_BOX (vb), lbl, false, false, 0);

      adj = gtk_adjustment_new (0.0, 0.0, 0.7, 0.01, .01, 0.0);
      g_signal_connect (G_OBJECT (adj), "value_changed",
                        G_CALLBACK (degree_cb), (gpointer) gg);

      sbar = gtk_hscale_new (GTK_ADJUSTMENT (adj));
      gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), sbar,
                            "Set the degree of jitter", NULL);
      gtk_scale_set_draw_value (GTK_SCALE (sbar), false);
      gtk_range_set_update_policy (GTK_RANGE (sbar), GTK_UPDATE_CONTINUOUS);
      gtk_scale_set_digits (GTK_SCALE (sbar), 2);
      gtk_scale_set_value_pos (GTK_SCALE (sbar), GTK_POS_BOTTOM);
      gtk_box_pack_start (GTK_BOX (vb), sbar, false, false, 0);

      gtk_label_set_mnemonic_widget (GTK_LABEL (lbl), sbar);

      /*-- Rejitter button --*/
      btn = gtk_button_new_with_mnemonic ("_Jitter");
      gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), btn,
                            "Rejitter the data", NULL);
      g_signal_connect (G_OBJECT (btn), "clicked",
                        G_CALLBACK (jitter_cb), (gpointer) gg);
      gtk_box_pack_start (GTK_BOX (vbox), btn, false, false, 3);

      /*-- Close button --*/
      gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), false, true,
                          2);
      hb = gtk_hbox_new (false, 2);
      gtk_box_pack_start (GTK_BOX (vbox), hb, false, false, 1);

      btn = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
      g_signal_connect (G_OBJECT (btn), "clicked",
                        G_CALLBACK (close_btn_cb), gg);
      gtk_box_pack_start (GTK_BOX (hb), btn, true, false, 0);

      g_object_set_data (G_OBJECT (gg->jitter_ui.window), "notebook", notebook);
      gtk_widget_show_all (gg->jitter_ui.window);
    }
  }

  gdk_window_raise (gg->jitter_ui.window->window);
}