Skip to content

Commit 47a3837

Browse files
committed
Initial commit
1 parent cd78cf7 commit 47a3837

File tree

12 files changed

+1193
-28
lines changed

12 files changed

+1193
-28
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.settings
2+
/target
3+
/.classpath
4+
/.project

LICENSE

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
Copyright (c) 2016, javagl
2-
All rights reserved.
3-
4-
Redistribution and use in source and binary forms, with or without
5-
modification, are permitted provided that the following conditions are met:
6-
7-
* Redistributions of source code must retain the above copyright notice, this
8-
list of conditions and the following disclaimer.
9-
10-
* Redistributions in binary form must reproduce the above copyright notice,
11-
this list of conditions and the following disclaimer in the documentation
12-
and/or other materials provided with the distribution.
13-
14-
* Neither the name of JTreeTable nor the names of its
15-
contributors may be used to endorse or promote products derived from
16-
this software without specific prior written permission.
17-
18-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1+
This library is based on the code from the article "Creating TreeTables"
2+
by Sun Microsystems (now known as Oracle).
3+
4+
The original copyright notice:
5+
6+
Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions
10+
are met:
11+
12+
- Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
15+
- Redistributions in binary form must reproduce the above copyright
16+
notice, this list of conditions and the following disclaimer in the
17+
documentation and/or other materials provided with the distribution.
18+
19+
- Neither the name of Sun Microsystems nor the names of its
20+
contributors may be used to endorse or promote products derived
21+
from this software without specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# JTreeTable
2-
A JTreeTable implementation
2+
3+
A JTreeTable implementation.
4+
5+
This library is based on the code from the article "Creating TreeTables" by Sun
6+
Microsystems (now known as Oracle). The original link to this
7+
article was [http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html](http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html). It is
8+
not longer available, but may still be viewed in the [web archive](https://web.archive.org/web/20120626135631/http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html)
9+
10+
11+
12+
13+
14+

pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<parent>
5+
<groupId>org.sonatype.oss</groupId>
6+
<artifactId>oss-parent</artifactId>
7+
<version>9</version>
8+
</parent>
9+
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<groupId>de.javagl</groupId>
13+
<artifactId>treetable</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
16+
<name>treetable</name>
17+
<description>A JTreeTable</description>
18+
<url>https://github.com/javagl</url>
19+
20+
<developers>
21+
<developer>
22+
<name>Marco Hutter</name>
23+
<email>[email protected]</email>
24+
<roles>
25+
<role>developer</role>
26+
</roles>
27+
</developer>
28+
</developers>
29+
30+
<scm>
31+
<connection>scm:git:[email protected]:javagl/JTreeTable.git</connection>
32+
<developerConnection>scm:git:[email protected]:javagl/JTreeTable.git</developerConnection>
33+
<url>[email protected]:javagl/JTreeTable.git</url>
34+
</scm>
35+
36+
<licenses>
37+
<license>
38+
<name>MIT</name>
39+
<url>https://github.com/javagl/JTreeTable/blob/master/LICENSE</url>
40+
<distribution>repo</distribution>
41+
</license>
42+
</licenses>
43+
44+
<properties>
45+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
46+
</properties>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<artifactId>maven-compiler-plugin</artifactId>
52+
<version>2.3.2</version>
53+
<configuration>
54+
<source>1.6</source>
55+
<target>1.6</target>
56+
</configuration>
57+
</plugin>
58+
<plugin>
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-source-plugin</artifactId>
61+
<version>2.1.2</version>
62+
<executions>
63+
<execution>
64+
<id>attach-sources</id>
65+
<goals>
66+
<goal>jar</goal>
67+
</goals>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-javadoc-plugin</artifactId>
74+
<version>2.10.1</version>
75+
<executions>
76+
<execution>
77+
<id>attach-javadocs</id>
78+
<goals>
79+
<goal>jar</goal>
80+
</goals>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
</project>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* www.javagl.de - JTreeTable
3+
*
4+
* Copyright (c) 2016 Marco Hutter - http://www.javagl.de
5+
*
6+
* This library is based on the code from the article "Creating TreeTables"
7+
* by Sun Microsystems (now known as Oracle).
8+
*
9+
* The original copyright header:
10+
*
11+
* Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
12+
*
13+
* Redistribution and use in source and binary forms, with or without
14+
* modification, are permitted provided that the following conditions
15+
* are met:
16+
*
17+
* - Redistributions of source code must retain the above copyright
18+
* notice, this list of conditions and the following disclaimer.
19+
*
20+
* - Redistributions in binary form must reproduce the above copyright
21+
* notice, this list of conditions and the following disclaimer in the
22+
* documentation and/or other materials provided with the distribution.
23+
*
24+
* - Neither the name of Sun Microsystems nor the names of its
25+
* contributors may be used to endorse or promote products derived
26+
* from this software without specific prior written permission.
27+
*
28+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
29+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
32+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
35+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
36+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
*/
40+
package de.javagl.treetable;
41+
42+
import java.util.EventObject;
43+
44+
import javax.swing.CellEditor;
45+
import javax.swing.event.CellEditorListener;
46+
import javax.swing.event.ChangeEvent;
47+
import javax.swing.event.EventListenerList;
48+
49+
50+
/**
51+
* Abstract base implementation of a CellEditor for a {@link JTreeTable}.
52+
*/
53+
public class AbstractCellEditor implements CellEditor
54+
{
55+
/**
56+
* The list of CellEditorListeners
57+
*/
58+
private final EventListenerList listenerList = new EventListenerList();
59+
60+
@Override
61+
public Object getCellEditorValue()
62+
{
63+
return null;
64+
}
65+
66+
@Override
67+
public boolean isCellEditable(EventObject e)
68+
{
69+
return true;
70+
}
71+
72+
@Override
73+
public boolean shouldSelectCell(EventObject anEvent)
74+
{
75+
return false;
76+
}
77+
78+
@Override
79+
public boolean stopCellEditing()
80+
{
81+
return true;
82+
}
83+
84+
@Override
85+
public void cancelCellEditing()
86+
{
87+
// Empty default implementation
88+
}
89+
90+
@Override
91+
public final void addCellEditorListener(CellEditorListener l)
92+
{
93+
listenerList.add(CellEditorListener.class, l);
94+
}
95+
96+
@Override
97+
public final void removeCellEditorListener(CellEditorListener l)
98+
{
99+
listenerList.remove(CellEditorListener.class, l);
100+
}
101+
102+
/**
103+
* Notify all listeners that have registered interest for notification on
104+
* this event type.
105+
*/
106+
protected final void fireEditingStopped()
107+
{
108+
Object[] listeners = listenerList.getListenerList();
109+
for (int i = listeners.length - 2; i >= 0; i -= 2)
110+
{
111+
if (listeners[i] == CellEditorListener.class)
112+
{
113+
((CellEditorListener) listeners[i + 1])
114+
.editingStopped(new ChangeEvent(this));
115+
}
116+
}
117+
}
118+
119+
/**
120+
* Notify all listeners that have registered interest for notification on
121+
* this event type.
122+
*/
123+
protected final void fireEditingCanceled()
124+
{
125+
Object[] listeners = listenerList.getListenerList();
126+
for (int i = listeners.length - 2; i >= 0; i -= 2)
127+
{
128+
if (listeners[i] == CellEditorListener.class)
129+
{
130+
((CellEditorListener) listeners[i + 1])
131+
.editingCanceled(new ChangeEvent(this));
132+
}
133+
}
134+
}
135+
}

src/main/java/de/javagl/treetable/AbstractTreeTableModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* * www.javagl.de - JTreeTable * * Copyright (c) 2016 Marco Hutter - http://www.javagl.de * * This library is based on the code from the article "Creating TreeTables" * by Sun Microsystems (now known as Oracle). * * The original copyright header: * * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of Sun Microsystems nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package de.javagl.treetable;import javax.swing.tree.*;import javax.swing.event.*;/** * An abstract implementation of the TreeTableModel interface, handling the list * of listeners.<br> * <br> * <b>Note:</b> In order to actually display the JTree in one column of the * JTreeTable, implementors of this class have to return the * <code>TreeTableModel.class</code> as the respective column class * in their implementation of the {@link #getColumnClass(int)} method: * <pre><code> * public Class&lt;?&gt; getColumnClass(int column) * { * if (column == columnThatShouldContainTheTree) * { * return TreeTableModel.class; * } * // Return other types as desired: * return Object.class; * } * </code></pre> */public abstract class AbstractTreeTableModel implements TreeTableModel{ /** * The root node of the tree */ protected Object root; /** * The TreeModelListeners that will be notified about modifications */ private final EventListenerList listenerList = new EventListenerList(); /** * Default constructor * * @param root The root node of the tree */ protected AbstractTreeTableModel(Object root) { this.root = root; } @Override public Object getRoot() { return root; } @Override public boolean isLeaf(Object node) { return getChildCount(node) == 0; } @Override public void valueForPathChanged(TreePath path, Object newValue) { // Empty default implementation } @Override public int getIndexOfChild(Object parent, Object child) { for (int i = 0; i < getChildCount(parent); i++) { if (getChild(parent, i).equals(child)) { return i; } } return -1; } @Override public void addTreeModelListener(TreeModelListener l) { listenerList.add(TreeModelListener.class, l); } @Override public void removeTreeModelListener(TreeModelListener l) { listenerList.remove(TreeModelListener.class, l); } /** * Notify all listeners that have registered interest for notification on * this event type. The event instance is lazily created using the * parameters passed into the fire method. * * @param source The source of the event * @param path The tree path * @param childIndices The child indices * @param children The children */ protected final void fireTreeNodesChanged( Object source, Object[] path, int[] childIndices, Object[] children) { Object[] listeners = listenerList.getListenerList(); TreeModelEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == TreeModelListener.class) { if (e == null) { e = new TreeModelEvent( source, path, childIndices, children); } ((TreeModelListener) listeners[i + 1]).treeNodesChanged(e); } } } /** * Notify all listeners that have registered interest for notification on * this event type. The event instance is lazily created using the * parameters passed into the fire method. * * @param source The source of the event * @param path The tree path * @param childIndices The child indices * @param children The children */ protected final void fireTreeNodesInserted( Object source, Object[] path, int[] childIndices, Object[] children) { Object[] listeners = listenerList.getListenerList(); TreeModelEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == TreeModelListener.class) { if (e == null) { e = new TreeModelEvent( source, path, childIndices, children); } ((TreeModelListener) listeners[i + 1]).treeNodesInserted(e); } } } /** * Notify all listeners that have registered interest for notification on * this event type. The event instance is lazily created using the * parameters passed into the fire method. * * @param source The source of the event * @param path The tree path * @param childIndices The child indices * @param children The children */ protected final void fireTreeNodesRemoved( Object source, Object[] path, int[] childIndices, Object[] children) { Object[] listeners = listenerList.getListenerList(); TreeModelEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == TreeModelListener.class) { if (e == null) { e = new TreeModelEvent( source, path, childIndices, children); } ((TreeModelListener) listeners[i + 1]).treeNodesRemoved(e); } } } /** * Notify all listeners that have registered interest for notification on * this event type. The event instance is lazily created using the * parameters passed into the fire method. * * @param source The source of the event * @param path The tree path * @param childIndices The child indices * @param children The children */ protected final void fireTreeStructureChanged( Object source, Object[] path, int[] childIndices, Object[] children) { Object[] listeners = listenerList.getListenerList(); TreeModelEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == TreeModelListener.class) { if (e == null) { e = new TreeModelEvent( source, path, childIndices, children); } ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e); } } } @Override public boolean isCellEditable(Object node, int column) { return getColumnClass(column) == TreeTableModel.class; } @Override public void setValueAt(Object aValue, Object node, int column) { // Empty default implementation }}

0 commit comments

Comments
 (0)