A
download CustomizedGUI.java
Language: Java
License: LGPL
Copyright: (C) 2002-2003 Renaud Pawlak, Laurent Martelli.
LOC: 295
Project Info
Java Aspect Components(jac)
Server: ObjectWeb Forge
Type: cvs
...\objectweb\jac\aspects\gui\
   ...CollectionItemView.java
   AbstractNode.java
   Actions.java
   AddEvent.java
   BehaviorGuiConf.java
   Border.java
   Callback.java
   ...sAppearenceGuiConf.java
   ClassChooser.java
   CollectionEvent.java
   CollectionItemView.java
   CollectionModel.java
   CollectionPosition.java
   CollectionUpdate.java
   CollectionView.java
   CollectionWrapper.java
   ComboBoxModel.java
   CommitException.java
   CompositeView.java
   Constants.java
   Currency.java
   CustomizedDisplay.java
   CustomizedGUI.java
   CustomizedView.java
   DateFormat.java
   DateHourFormat.java
   DialogView.java
   DisplayContext.java
   EditorContainer.java
   Event.java
   EventHandler.java
   ExpressionListener.java
   ExprWatcher.java
   ExprWatcherParser.java
   ExtendedTableModel.java
   ...dAppearenceGuiConf.java
   FieldEditor.java
   FieldItemView.java
   FieldUpdate.java
   FieldView.java
   FileEditorConfig.java
   FilterCriteria.java
   FloatFormat.java
   Format.java
   GenericFactory.java
   gui.acc
   GuiAC.java
   GuiConf.java
   HandlerResult.java
   ...tCanceledException.java
   InputSequence.java
   InputWrapper.java
   IntFormat.java
   InvokeEvent.java
   InvokeThread.java
   Length.java
   LessAbstractListModel.java
   LinkGenerator.java
   ListModel.java
   MatrixUtils.java
   MemberItemView.java
   Menu.java
   MenuView.java
   ...dAppearenceGuiConf.java
   MethodItemView.java
   MethodUpdate.java
   MethodView.java
   Model.java
   NumberFormat.java
   ObjectChooserModel.java
   ObjectNode.java
   ObjectUpdate.java
   ObjectView.java
   package.html
   PanelContent.java
   PanelView.java
   PercentFormat.java
   PointFormat.java
   ReferenceEditor.java
   RelationNode.java
   RemoveEvent.java
   Reports.java
   ResourceManager.java
   RootNode.java
   SortCriteria.java
   StatusView.java
   SubstanceEvent.java
   TableCellViewer.java
   TableFilter.java
   TableMap.java
   TableModel.java
   TableSorter.java
   TabsView.java
   Target.java
   Template.java
   TemplateReader.java
   TimeoutException.java
   Transfer.java
   TreeListener.java
   TreeModel.java
   TreeView.java
   Unit.java
   Utils.java
   View.java
   ViewControlWrapper.java
   ViewFactory.java
   ViewIdentity.java
   Views.java
   WaitWrapper.java
   WindowView.java
   WrappableList.java
   WrappableMap.java

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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
/*
  Copyright (C) 2002-2003 Renaud Pawlak, Laurent Martelli.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA */

package org.objectweb.jac.aspects.gui;

import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.objectweb.jac.core.rtti.AbstractMethodItem;
import org.objectweb.jac.core.rtti.ClassItem;
import org.objectweb.jac.core.rtti.MemberItem;
import org.objectweb.jac.core.rtti.MethodItem;

/**
 * This interface allows the programmer to create simple customized GUIs.
 *
 * <p>The idea is to define sub-panels that can contain views on the
 * objects of the application. The geometric placement of the
 * sub-panel is defined by the <code>setSubPanesGeometry</code> method
 * that has to be called at contruction-time.
 *
 * <p>Once the geometry is chosen, you can tell a pane to contain a
 * view on a given object by using the <code>addReferenceToPane</code>
 * method.
 *
 * <p>This class must be subclassed by the porgrammer of a JAC
 * application to provide a customized GUI.
 *
 * @see GuiAC
 * @see #setSubPanesGeometry(int,int,boolean[])
 * @see #addReferenceToPane(MemberItem,String,String[],String) */

public class CustomizedGUI { 
    static final Logger logger = Logger.getLogger("gui");

    //GuiAC guiAC = null;

    // paneID -> {viewType,args[]}
    Hashtable paneContents = new Hashtable();
    // paneID -> viewType
    Hashtable paneContainers = new Hashtable();
    // (Integer)splitterID -> (Integer)location
    Hashtable splitters = new Hashtable();
    // changed paneID -> invalid_paneID
    Hashtable invalidPanes = new Hashtable(); 

    // WARNING: the following order is very important
    /** The subpanes are separated by an horizontal splitter */
    public static final int HORIZONTAL = 0;
    /** The upper subpanes are separated by a vertical splitter */
    public static final int HORIZONTAL_UP = 1;
    /** The down subpanes are separated by a vertical splitter */
    public static final int HORIZONTAL_DOWN = 2;
    /** The subpanes are separated by a vertical splitter */
    public static final int VERTICAL = 3;
    /** The left subpanes are separated by an horizontal splitter */
    public static final int VERTICAL_LEFT = 4;
    /** The right subpanes are separated by an horizontal splitter */
    public static final int VERTICAL_RIGHT = 5;

    public static final String BOTTOM = "BOTTOM";
    public static final String TOP = "TOP";

    public void setInvalidPane(String changedPane, String invalidPane) {
        invalidPanes.put(changedPane,invalidPane);
    }

    public String getInvalidPane(String changedPane) {
        return (String)invalidPanes.get(changedPane);
    }

    /**
     * Gets the number of sub-panes in the main window of the GUI.
     *
     * @return the number of panels 
     */
    int subPanesCount= 1;
    public int getSubPanesCount() {
        return subPanesCount;
    }

    int geometry = 0;
    public int getGeometry() {
        return geometry;
    }

    boolean[] scrollings = new boolean[] {false};
    public boolean[] getScrollings() {
        return scrollings;
    }
   
    String application;
   
    /**
     * Get the value of application.
     * @return value of application.
     */
    public String getApplication() {
        return application;
    }
   
    /**
     * Set the value of application.
     * @param v  Value to assign to application.
     */
    public void setApplication(String  v) {
        this.application = v;
    }
   

    /**
     * Sets the geometric arrangement of the panes.
     *
     * <p><ul><li><code>subPanesCount == 4 && geometry == VERTICAL</code>:
     * <pre>
     *    +-------+
     *    | 0 | 2 |
     *    +---|---+
     *    | 1 | 3 |
     *    +-------+
     * </pre>
     * </li>
     * <li><code>subPanesCount == 4 && geometry == HORIZONTAL</code>:
     * <pre>
     *    +-------+
     *    | 0 | 1 |
     *    +-------+
     *    | 2 | 3 |
     *    +-------+
     * </pre>
     * </li>
     * <li><code>subPanesCount == 3 && geometry == HORIZONTAL_UP</code>:
     * <pre>
     *    +-------+
     *    | 0 | 1 |
     *    +-------+
     *    |   2   |
     *    +-------+
     * </pre>
     * </li>
     * </li>
     * <li><code>subPanesCount == 3 && geometry == HORIZONTAL_DOWN</code>:
     * <pre>
     *    +-------+
     *    |   2   |
     *    +-------+
     *    | 0 | 1 |
     *    +-------+
     * </pre>
     * </li>
     * <li><code>subPanesCount == 3 && geometry == VERTICAL_LEFT</code>:
     * <pre>
     *    +---+---+
     *    | 0 |   |
     *    +---| 2 |
     *    | 1 |   |
     *    +---+---+
     * </pre>
     * </li>
     * <li><code>subPanesCount == 3 && geometry == VERTICAL_RIGHT</code>:
     * <pre>
     *    +---+---+
     *    |   | 0 |
     *    | 2 |---+
     *    |   | 1 |
     *    +---+---+
     * </pre>
     * </li>
     * <li><code>subPanesCount == 2 && geometry == VERTICAL</code>:
     * <pre>
     *    +---+---+
     *    |   |   |
     *    | 0 | 1 |
     *    |   |   |
     *    +---+---+
     * </pre>
     * </li>
     * <li><code>subPanesCount == 2 && geometry == HORIZONTAL</code>:
     * <pre>
     *    +-------+
     *    |   0   |
     *    +-------+
     *    |   1   |
     *    +-------+
     * </pre>
     * </li>
     *
     * @param subPanesCount the number of subpanes in the window
     * @param geometry the geometry = <code>VERTICAL || HORIZONTAL ||
     * VERTICAL_LEFT || VERTICAL_RIGHT || HORIZONTAL_UP ||
     * HORIZONTAL_DOWN</code> (see above)
     * @param scrollings a set of string that tells if the sub-panes
     * must be srollable or not 
     */
    public void setSubPanesGeometry(int subPanesCount, int geometry, 
                                    boolean[] scrollings) {
        this.subPanesCount = subPanesCount;
        this.geometry = geometry;
        this.scrollings = scrollings;
    }

    /**
     * Sets the object that should be opened in the given panel id.
     *
     * @param paneId the panel id (see the geometry to know its
     * placement)
     * @param viewType of the type of the view
     * @param args parameters to pass to the view type constructor
     *
     * @see #setSubPanesGeometry(int,int,boolean[]) 
     */
    public void setPaneContent(String paneId, 
                               String viewType, String[] args) {      
        paneContents.put(paneId,new PanelContent(viewType,args));
    }

    /**
     * Returns the type of the object to be displayed in a pane
     */
    public String getPaneContentType(String paneID) {
        return (String)((Object[])paneContents.get(paneID))[0];
    }

    public String[] getPaneContentArgs(String paneID) {
        return (String[])((Object[])paneContents.get(paneID))[1];
    }

    public Map getPaneContents() {
        return paneContents;
    }

    public void setPaneContainer(String paneId, String containerType) {
        paneContainers.put(paneId,containerType);
    }

    public String getPaneContainer(String paneId) {
        return (String)paneContainers.get(paneId);
    }

    public Map getPaneContainers() {
        return paneContainers;
    }

    Hashtable subPaneContents = new Hashtable();
   
    public Map getSubPaneContents() {
        return subPaneContents;
    }

    // PaneID -> Vector of FieldItem
    HashMap targetContainers = new HashMap();

    /**
     * Tells a referenced object to open in a given panel when a view
     * is asked by the user (instead of opening in a popup).
     *
     * @param reference the reference (can be a method's result)
     * @param viewType the type of the view that must be opened
     * @param paneId the panel id where the view must be opened */

    public void addReferenceToPane(MemberItem reference, 
                                   String viewType, String[] viewParams,
                                   String paneId) {
        Vector containers = (Vector)targetContainers.get(reference);
        if (containers==null) {
            containers = new Vector();
            targetContainers.put(reference,containers);
        }
        containers.add(new Target(paneId,viewType,viewParams));
    }

    public Map getTargetContainers() {
        return targetContainers;
    }

    public List getFieldTargets(MemberItem reference) {
        List result = null;
        MemberItem member = reference;
        while (result==null && member!=null) {
            result = (List)targetContainers.get(member);
            ClassItem superClass = member.getClassItem().getSuperclass();
            if (superClass!=null)
                member = superClass.getFieldNoError(member.getName());
            else 
                member = null;
        }
        if (reference!=null) {
            ClassItem[] interfaces = reference.getClassItem().getInterfaceItems();
            if (interfaces!=null) {
                SortedMap intfTargets = new TreeMap(new ClassItem.Comparator());
                for (int i=0; i<interfaces.length && result==null; i++) {
                    member = interfaces[i].getFieldNoError(reference.getName());
                    if (member!=null) {
                        Object value = targetContainers.get(member);
                        if (value!=null)
                            intfTargets.put(interfaces[i],value);
                    }
                }
                if (!intfTargets.isEmpty())
                    result = (List)intfTargets.get(intfTargets.firstKey());
            }
        }
        return result;
    }

    int left;
    int up;
    int width;
    int height;

    public int getLeft() {
        return left;
    }

    public int getUp() {
        return up;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    boolean geometrySet = false;

    /**
     * Returns true if the geometry of this GUI was set with
     * <code>setPosition</code>.
     *
     * @see #setPosition(int,int,int,int) 
     */
    public boolean isGeometrySet() {
        return geometrySet;
    }

    /**
     * Sets the dimensions and position of the window regarding to the
     * main screen.
     *
     * @param left left-border pixel
     * @param up upper-border pixel
     * @param width in percentage regarding the screen
     * @param height in percentage regarding the screen 
     * @see #isGeometrySet() 
     */

    public void setPosition(int left, int up, int width, int height) {
        this.up = up;
        this.left = left;
        this.width = width;
        this.height = height;
        geometrySet = true;
    }

    /**
     * Sets a splitter location.
     *
     * <p>The splitter is referenced by its index going from the
     * front-end splitter to the back-end splitters. For instance, in
     * the case of a 3 sub-panel window, the 0 index references the
     * splitter that splits the main window in two, the 1 index, the
     * one that splits the half-window in two other smaller parts.
     *
     * @param splitterId the splitter's index
     * @param location the position in pixel, regarding to the top/left
     * component, a negative value means that the splitter should be
     * set at the preferred sized of the inner components */

    public void setSplitterLocation(int splitterId, float location) {
        splitters.put(new Integer(splitterId), new Float(location));
    }

    public Map getSplitters() {
        return splitters;
    }

    boolean hasStatusBar=false;
    MethodItem statusBarMethod=null;
    String statusPosition = BOTTOM;

    public boolean hasStatusBar() {
        return hasStatusBar;
    }

    public String getStatusPosition() {
        return statusPosition;
    }

    public MethodItem getStatusBarMethod() {
        return statusBarMethod;
    }

    /**
     * Adds a status bar to the GUI.
     */

    public void addStatusBar(MethodItem method,String position) {
        hasStatusBar=true;
        statusBarMethod = method;
        statusPosition=position;
    }
    
    /*
      public void showStatus(String message) {
      if( statusBar == null ) {
      System.out.println(message);
      } else {
      ((JLabel)statusBar.getComponent(0)).setText(message);
      }
      }
    */

    /**
     * Creates a new customized GUI.
     *
     * <p>When subclassing, a typical implementation of the constructor is:
     *
     * <pre class=code>
     * super()
     * // initialization calls such as setSubPanesGeometry
     * // addReferenceToPane, setPosition
     * ...
     * show();
     * </pre>
     *
     * @see #setSubPanesGeometry(int,int,boolean[])
     * @see #addReferenceToPane(MemberItem,String,String[],String)
     * @see #setPosition(int,int,int,int)
     * @see #setSplitterLocation(int,float) 
     */   
    public CustomizedGUI(String id) {
        this.id = id;
    }

    String id;
    public String getId() {
        return id;
    }

    Hashtable menus = new Hashtable();

    public Hashtable getMenus() {
        return menus;
    }

    public Menu getMenus(String name) {
        Menu menu=(Menu)menus.get(name);
        if(menu==null) {
            menu=new Menu();
            menus.put(name,menu);
        }
        return menu;
    }

    public boolean hasMenuBar() {
        return menus.size()>0;
    }

    /**
     * Add an item in a menu
     *
     * @param menuPath the path of the menu where to add an item
     * @param callback the method to call when this item is selected
     *
     * @see #addMenuSeparator(String,String[])
     */
    public void addMenuItem(String menuName,
                            String[] menuPath, 
                            Callback callback) {
        String[] path = new String[menuPath.length-1];
        System.arraycopy(menuPath,0,path,0,menuPath.length-1);
        getMenu(menuName,path).put(
            menuPath[menuPath.length-1],callback);
    }

    /**
     * Add a separator in a menu
     *
     * @param menuName the name of the menu
     * @param menuPath the path of the menu where to add a separator
     *
     * @see #addMenuItem(String,String[],Callback)
     */
    public void addMenuSeparator(String menuName,String[] menuPath) {
        getMenu(menuName,menuPath).addSeparator();
    }

    Vector toolbar = new Vector();

    /**
     * Add a button in the toolbar
     *
     * @param method the static method to call when the button is pressed
     *
     * @see #addToolbarSeparator()
     * @see #addToolbarAction(String,AbstractMethodItem)
     */
    public void addToolbarAction(AbstractMethodItem method) {
        toolbar.add(new Callback(null,method, new Object [0]));
    }

    /**
     * Add a button in the toolbar
     *
     * @param objectName name of the object on which to invoke the method
     * @param method the method to call when the button is pressed
     *
     * @see #addToolbarSeparator()
     * @see #addToolbarAction(AbstractMethodItem)
     */
    public void addToolbarAction(String objectName, AbstractMethodItem method) {
        addToolbarAction(objectName,method,new Object[0]);
    }

    public void addToolbarAction(String objectName, AbstractMethodItem method, Object[] params) {
        toolbar.add(new Callback(objectName,method,params));
    }

    /**
     * Add a separator in the toolbar
     *
     * @see #addToolbarAction(AbstractMethodItem)
     */
    public void addToolbarSeparator() {
        toolbar.add(null);
    }

    /**
     * Returns the toolbar of the customized GUI.
     *
     * @return a collection representing the tool. It contains
     * AbstractMethodItem objects for buttons, and null for a
     * separator.
     */
    public Collection getToolbar() {
        return toolbar;
    }

    public boolean hasToolBar() {
        return toolbar.size()>0;
    }

    /**
     * Find a menu defined by its path
     */
    protected Menu getMenu(String menuName,String[] menuPath) {
        Menu menu = getMenus(menuName);
        for (int i=0; i<menuPath.length; i++) {
            if (menu.containsKey(menuPath[i])) {
                Object current = menu.get(menuPath[i]);
                if (current instanceof Menu) {
                    menu = (Menu)current;
                } else {
                    logger.warn("overriding menu item "+current);
                    Menu old = menu;
                    menu = new Menu();
                    old.put(menuPath[i],menu);
                }
            } else {
                Menu old = menu;
                menu = new Menu();
                old.put(menuPath[i],menu);
            }
        }
        return menu;
    }

    public void setMenuIcon(String menuName,
                            String[] menuPath, String icon) {
        getMenu(menuName,menuPath).setIcon(icon);
    }
   
    public void setMenuPosition(String menuName,String position) {
        getMenus(menuName).setPosition(position);
    }
   
    String welcomeTitle = "Welcome";
    String welcomeMessage = null;
    String welcomeIcon = null;

    public void setWelcomeMessage(String title,String message,String icon) {
        this.welcomeTitle = title;
        this.welcomeMessage = message;
        this.welcomeIcon = icon;
    }

    String title;
    public void setTitle(String title) {
        this.title=title;
    }
    public String getTitle() {
        return title;
    }

    Vector cssURLs=new Vector();
    public void addStyleSheetURL(String url) {
        cssURLs.add(url);
    }

    public Vector getStyleSheetURLs() {
        return cssURLs; 
    }

    AbstractMethodItem onCloseHandler;
    public void setOnCloseHandler(AbstractMethodItem handler) {
        onCloseHandler = handler;
    }
    public AbstractMethodItem getOnCloseHandler() {
        return onCloseHandler;
    }

    String icon;
    public String getIcon() {
        return icon;
    }
    public void setIcon(String icon) {
        this.icon = icon;
    }
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us