001/** 002 * jshred - Shred's Toolbox 003 * 004 * Copyright (C) 2009 Richard "Shred" Körber 005 * http://jshred.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License / GNU Lesser 009 * General Public License as published by the Free Software Foundation, 010 * either version 3 of the License, or (at your option) any later version. 011 * 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 018 * 019 */ 020package net.shredzone.jshred.swing; 021 022import javax.swing.event.TreeModelListener; 023import javax.swing.tree.TreeModel; 024import javax.swing.tree.TreePath; 025 026/** 027 * This is just a mere empty {@link TreeModel} which will never have any entries. 028 * 029 * @author Richard "Shred" Körber 030 * @since R7 031 */ 032public final class EmptyTreeModel implements TreeModel { 033 034 /** 035 * Gets the root node. It will return {@code null} since the tree has no nodes. 036 */ 037 @Override 038 public Object getRoot() { 039 return null; 040 } 041 042 /** 043 * Gets the child count, which is always 0. 044 */ 045 @Override 046 public int getChildCount(Object parent) { 047 return 0; 048 } 049 050 /** 051 * Checks if the node is a leaf. Should never be invoked since there are no nodes. 052 * Will always return {@code true}. 053 */ 054 @Override 055 public boolean isLeaf(Object node) { 056 return true; 057 } 058 059 /** 060 * Adds a {@link TreeModelListener}. Since the tree will never change, the listener is 061 * just ignored. 062 */ 063 @Override 064 public void addTreeModelListener(TreeModelListener l) {} 065 066 /** 067 * Removes a {@link TreeModelListener}. Since the tree will never change, the listener 068 * is just ignored. 069 */ 070 @Override 071 public void removeTreeModelListener(TreeModelListener l) {} 072 073 /** 074 * Gets a child. Should never be invoked since there are no childs. It will always 075 * return {@code null}. 076 */ 077 @Override 078 public Object getChild(Object parent, int index) { 079 return null; 080 } 081 082 /** 083 * Gets the index of a child. Should never be invoked since there are no childs. It 084 * will always return -1. 085 */ 086 @Override 087 public int getIndexOfChild(Object parent, Object child) { 088 return -1; 089 } 090 091 /** 092 * Value for path changed. Should never be invoked for an empty tree. It just does 093 * nothing. 094 */ 095 @Override 096 public void valueForPathChanged(TreePath path, Object newValue) { 097 // does nothing 098 } 099 100}