]> git.mxchange.org Git - jaddressbook-share-lib.git/blob - Addressbook/src/org/mxchange/addressbook/model/BaseModel.java
Auto-formation and yes, it is better this way
[jaddressbook-share-lib.git] / Addressbook / src / org / mxchange / addressbook / model / BaseModel.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.model;
18
19 import java.text.MessageFormat;
20 import javax.swing.event.EventListenerList;
21 import javax.swing.event.ListDataListener;
22 import javax.swing.event.TableModelListener;
23 import org.mxchange.addressbook.BaseFrameworkSystem;
24
25 /**
26  *
27  * @author Roland Haeder
28  */
29 public class BaseModel extends BaseFrameworkSystem {
30
31         /**
32          * List of event listeners
33          */
34         private final EventListenerList eventListenerList;
35
36         /**
37          * Protected constructor
38          */
39         protected BaseModel () {
40                 // Init listener list
41                 this.eventListenerList = new EventListenerList();
42         }
43
44         /**
45          * Adds a lister of this type to the list
46          *
47          * @param listener Listener instance
48          */
49         public void addListDataListener (final ListDataListener listener) {
50                 // Debug message
51                 this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass()));
52
53                 // Remove listener
54                 this.eventListenerList.add(ListDataListener.class, listener);
55         }
56
57         /**
58          * Adds a TableModel listener instance to the event list.
59          *
60          * @param listener Lister instance
61          */
62         public void addTableModelListener (final TableModelListener listener) {
63                 // Debug message
64                 this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass()));
65
66                 // Add listener
67                 this.eventListenerList.add(TableModelListener.class, listener);
68         }
69
70         /**
71          * Removes given listener
72          *
73          * @param listener Listener instance
74          */
75         public void removeListDataListener (final ListDataListener listener) {
76                 // Debug message
77                 this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass()));
78
79                 // Remove listener
80                 this.eventListenerList.remove(ListDataListener.class, listener);
81         }
82
83         /**
84          * Removes a TableModel listener instance from the event list.
85          *
86          * @param listener Listener instance
87          */
88         public void removeTableModelListener (final TableModelListener listener) {
89                 // Debug message
90                 this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass()));
91
92                 // Remove listener
93                 this.eventListenerList.remove(TableModelListener.class, listener);
94         }
95 }