1 package net.logAnalyzer.gui; 2 3 import java.util.Hashtable; 4 5 import javax.swing.Icon; 6 import javax.swing.JPanel; 7 8 /*** 9 * This class is a template for views components based on a 10 * {@link javax.swing.JPanel}. 11 * 12 * @author Karim REFEYTON 13 * @version 0.1 14 */ 15 public abstract class LAView extends JPanel { 16 /*** 17 * Index of the first messageLabel selected in the view. 18 */ 19 private int currentFirstMessageIndex = -1; 20 21 /*** 22 * Index of the last messageLabel selected in the view. 23 */ 24 private int currentLastMessageIndex = -1; 25 26 /*** 27 * Container. 28 */ 29 private LAViewContainer viewContainer; 30 31 /*** 32 * View definition. 33 */ 34 private ViewDefinition definition; 35 36 /*** 37 * View attributes. 38 */ 39 private Hashtable attributes; 40 41 /*** 42 * Creates a new view with the specified attributes. 43 * 44 * @param attributes 45 * View attributes. 46 */ 47 public LAView(ViewDefinition definition, Hashtable attributes) { 48 this.definition = definition; 49 this.attributes = attributes; 50 } 51 52 /*** 53 * Returns a view attribute from the specified key. 54 * 55 * @param key 56 * Attribute key. 57 * @return Attribute value. 58 */ 59 protected Object getAttribute(String key) { 60 return attributes.get(key); 61 } 62 63 /*** 64 * Returns the view attributes. 65 * 66 * @return Attributes. 67 */ 68 protected Hashtable getAttributes() { 69 return attributes; 70 } 71 72 /*** 73 * Returns the view icon. 74 * 75 * @return View icon. 76 */ 77 public abstract Icon getIcon(); 78 79 /*** 80 * Returns the view label. 81 */ 82 public String getLabel() { 83 return definition.getLabel(); 84 } 85 86 /*** 87 * Returns the view name. 88 * 89 * @see java.awt.Component#getName() 90 */ 91 public String getName() { 92 return definition.getName(); 93 } 94 95 /*** 96 * Returns the view title. 97 * 98 * @return View title. 99 */ 100 public abstract String getTitle(); 101 102 /*** 103 * Sets the view container. 104 * 105 * @param viewContainer 106 * Container. 107 */ 108 public final void setViewContainer(LAViewContainer viewContainer) { 109 this.viewContainer = viewContainer; 110 addComponents(); 111 this.viewContainer.viewModified(); 112 } 113 114 /*** 115 * Gets the view container. 116 * 117 * @return View container. 118 */ 119 public final LAViewContainer getViewContainer() { 120 return this.viewContainer; 121 } 122 123 /*** 124 * Adds view components. Called by 125 * {@link #setViewContainer(LAViewContainer)}. 126 */ 127 protected abstract void addComponents(); 128 129 /*** 130 * Changes the current messages selection. Calls 131 * {@link #setCurrentMessage(int, int, int, int)} 132 * 133 * @param firstIndex 134 * First messageLabel index. 135 * @param lastIndex 136 * Last messageLabel index. 137 */ 138 protected final void setCurrentMessage(int firstIndex, int lastIndex) { 139 if (currentFirstMessageIndex != firstIndex 140 || currentLastMessageIndex != lastIndex) { 141 int oldFirstIndex = currentFirstMessageIndex; 142 int oldLastIndex = currentLastMessageIndex; 143 currentFirstMessageIndex = firstIndex; 144 currentLastMessageIndex = lastIndex; 145 setCurrentMessage(oldFirstIndex, oldLastIndex, 146 currentFirstMessageIndex, currentLastMessageIndex); 147 } 148 } 149 150 /*** 151 * Sets current messageLabel. 152 * 153 * @param oldFirstIndex 154 * Old first selected messageLabel index. 155 * @param oldLastIndex 156 * Old last selected messageLabel index. 157 * @param newFirstIndex 158 * New first selected messageLabel index. 159 * @param newLastIndex 160 * New last selected messageLabel index. 161 */ 162 protected abstract void setCurrentMessage(int oldFirstIndex, 163 int oldLastIndex, int newFirstIndex, int newLastIndex); 164 165 /*** 166 * Used to notify listeners when the current messages selection is changed. 167 * 168 * @param firstIndex 169 * First messageLabel index. 170 * @param lastIndex 171 * Last messageLabel index. 172 */ 173 public void messageChangedNotify(int firstIndex, int lastIndex) { 174 if (currentFirstMessageIndex != firstIndex 175 || currentLastMessageIndex != lastIndex) { 176 currentFirstMessageIndex = firstIndex; 177 currentLastMessageIndex = lastIndex; 178 this.viewContainer.messageChanged(currentFirstMessageIndex, 179 currentLastMessageIndex); 180 } 181 } 182 183 public JPanel getQuickBarComponent(){ 184 return null; 185 } 186 }