~ubuntu-branches/ubuntu/utopic/freemind/utopic

« back to all changes in this revision

Viewing changes to freemind/freemind/modes/attributes/AttributeTableLayoutModel.java

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-01-03 14:19:19 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100103141919-m5az7dkicy21hqop
Tags: 0.9.0~rc6+dfsg-1ubuntu1
* Merge from Debian unstable (LP: #182927), remaining changes:
  - debian/copyright: add license/copyright for
    freemind/freemind/main/ExampleFileFilter.java

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*FreeMind - A Program for creating and viewing Mindmaps
 
2
*Copyright (C) 2000-2006 Joerg Mueller, Daniel Polansky, Christian Foltin, Dimitri Polivaev and others.
 
3
*
 
4
*See COPYING for Details
 
5
*
 
6
*This program is free software; you can redistribute it and/or
 
7
*modify it under the terms of the GNU General Public License
 
8
*as published by the Free Software Foundation; either version 2
 
9
*of the License, or (at your option) any later version.
 
10
*
 
11
*This program is distributed in the hope that it will be useful,
 
12
*but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
*GNU General Public License for more details.
 
15
*
 
16
*You should have received a copy of the GNU General Public License
 
17
*along with this program; if not, write to the Free Software
 
18
*Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
*/
 
20
/*
 
21
 * Created on 24.07.2005
 
22
 * Copyright (C) 2005 Dimitri Polivaev
 
23
 */
 
24
package freemind.modes.attributes;
 
25
 
 
26
import javax.swing.event.ChangeEvent;
 
27
import javax.swing.event.EventListenerList;
 
28
 
 
29
/**
 
30
 * @author Dimitri Polivaev
 
31
 * 24.07.2005
 
32
 */
 
33
public class AttributeTableLayoutModel {
 
34
    public static final String SHOW_SELECTED = "selected";
 
35
    public static final String SHOW_ALL = "extended"; 
 
36
    public static final String HIDE_ALL = "hide"; 
 
37
    public static final int DEFAULT_COLUMN_WIDTH = 75; 
 
38
    private int[] width  = {DEFAULT_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTH};
 
39
    
 
40
    private EventListenerList listenerList = null;
 
41
    ChangeEvent changeEvent = null;
 
42
    ColumnWidthChangeEvent[] layoutChangeEvent = {null, null};
 
43
    
 
44
    public AttributeTableLayoutModel() {
 
45
                super();
 
46
        }
 
47
        public int getColumnWidth(int col) {
 
48
        return width[col];
 
49
    }
 
50
    public void setColumnWidth(int col, int width) {
 
51
        if(this.width[col] != width){
 
52
            this.width[col] = width;
 
53
            fireColumnWidthChanged(col);
 
54
        }
 
55
    }
 
56
    /**
 
57
     * @param listenerList The listenerList to set.
 
58
     */
 
59
    private void setListenerList(EventListenerList listenerList) {
 
60
        this.listenerList = listenerList;
 
61
    }
 
62
    /**
 
63
     * @return Returns the listenerList.
 
64
     */
 
65
    private EventListenerList getListenerList() {
 
66
        if(listenerList == null)
 
67
            listenerList = new EventListenerList();
 
68
        return listenerList;
 
69
    }
 
70
   public void addColumnWidthChangeListener(ColumnWidthChangeListener l) {
 
71
        getListenerList().add(ColumnWidthChangeListener.class, l);
 
72
    }
 
73
 
 
74
   public void removeColumnWidthChangeListener(ColumnWidthChangeListener l) {
 
75
        getListenerList().remove(ColumnWidthChangeListener.class, l);
 
76
    }
 
77
 
 
78
 
 
79
    // Notify all listeners that have registered interest for
 
80
    // notification on this event type.  The event instance 
 
81
    // is lazily created using the parameters passed into 
 
82
    // the fire method.
 
83
 
 
84
    protected void fireColumnWidthChanged(int col) {
 
85
        // Guaranteed to return a non-null array
 
86
        Object[] listeners = getListenerList().getListenerList();
 
87
        // Process the listeners last to first, notifying
 
88
        // those that are interested in this event
 
89
        for (int i = listeners.length-2; i>=0; i-=2) {
 
90
            if (listeners[i]==ColumnWidthChangeListener.class) {
 
91
                // Lazily create the event:
 
92
                if (layoutChangeEvent[col] == null)
 
93
                    layoutChangeEvent[col] = new ColumnWidthChangeEvent(this, col);
 
94
                ((ColumnWidthChangeListener)listeners[i+1]).columnWidthChanged(layoutChangeEvent[col]);
 
95
            }
 
96
        }
 
97
    }
 
98
}