1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.util.swing; |
|
27 |
|
28 import javax.swing.event.*; |
|
29 |
|
30 /** |
|
31 * A {@code ListDataListenerAdapter} is a {@code TableModelListener} that |
|
32 * converts incoming {@code TableModelEvent}s to {@code ListDataEvent}s and |
|
33 * passes them on to a given {@code ListDataListener}. |
|
34 */ |
|
35 @SuppressWarnings({"serial"}) |
|
36 public class ListDataListenerAdapter implements TableModelListener { |
|
37 // |
|
38 // Instance data |
|
39 // |
|
40 |
|
41 private ListDataListener listener; |
|
42 |
|
43 // |
|
44 // Constructors |
|
45 // |
|
46 |
|
47 public ListDataListenerAdapter(ListDataListener listener) { |
|
48 this.listener = listener; |
|
49 } |
|
50 |
|
51 // |
|
52 // TableModelListener methods |
|
53 // |
|
54 |
|
55 @Override |
|
56 public void tableChanged(TableModelEvent e) { |
|
57 Object source = e.getSource(); |
|
58 int first = e.getFirstRow(); |
|
59 int last = e.getLastRow(); |
|
60 ListDataEvent listEvent; |
|
61 |
|
62 switch (e.getType()) { |
|
63 case TableModelEvent.DELETE: |
|
64 listEvent = new ListDataEvent( |
|
65 source, ListDataEvent.INTERVAL_REMOVED, first, last); |
|
66 listener.intervalRemoved(listEvent); |
|
67 break; |
|
68 |
|
69 case TableModelEvent.INSERT: |
|
70 listEvent = new ListDataEvent( |
|
71 source, ListDataEvent.INTERVAL_ADDED, first, last); |
|
72 listener.intervalAdded(listEvent); |
|
73 break; |
|
74 |
|
75 default: |
|
76 case TableModelEvent.UPDATE: |
|
77 listEvent = new ListDataEvent( |
|
78 source, ListDataEvent.CONTENTS_CHANGED, first, last); |
|
79 listener.contentsChanged(listEvent); |
|
80 break; |
|
81 } |
|
82 } |
|
83 |
|
84 // |
|
85 // ListDataListenerAdapter methods |
|
86 // |
|
87 |
|
88 public ListDataListener getListener() { |
|
89 return listener; |
|
90 } |
|
91 } |
|