Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
MatrixTreeCellRenderer.java
1 
16 package net.squiz.matrix.matrixtree;
17 
18 import net.squiz.matrix.core.*;
19 import java.awt.*;
20 import javax.swing.*;
21 import javax.swing.tree.*;
22 import net.squiz.matrix.ui.*;
23 import java.awt.event.*;
24 import net.squiz.matrix.plaf.*;
25 
35 public class MatrixTreeCellRenderer extends JLabel implements TreeCellRenderer, MatrixConstants
36 {
38  private Asset asset;
39 
41  private MatrixTreeNode node;
42 
44  private boolean selected = false;
45 
46  private boolean allSelected = false;
47 
48  public void flipSelection() {
49  allSelected = (allSelected) ? false : true;
50  }
51 
63  public Component getTreeCellRendererComponent(
64  JTree tree,
65  Object value,
66  boolean selected,
67  boolean expanded,
68  boolean leaf,
69  int row,
70  boolean hasFocus) {
71 
72  if (value instanceof MatrixTreeNode) {
73  node = (MatrixTreeNode) value;
74  Asset asset = node.getAsset();
75  this.asset = asset;
76 
77  setText(getNodeDisplayText(node));
78  setFont(((MatrixTree)tree).getFontInUse());
79 
80  if (!isNavNode(node)) {
81  setToolTipText(asset.getType().getName() + " [" + asset.getId() + "]");
82  this.selected = selected;
83  if (!(asset.isAccessible())) {
84  CompoundIcon icon = (CompoundIcon) GUIUtilities.getCompoundIconForTypeCode(
85  asset.getType().getTypeCode(), Matrix.getProperty("parameter.url.notaccessibleicon"), asset.getId());
86  setIcon(icon);
87  setDisabledIcon(icon.getDisabledIcon());
88  } else if (node.getLinkType() == LINK_TYPE_2) {
89  CompoundIcon icon = (CompoundIcon) GUIUtilities.getCompoundIconForTypeCode(
90  asset.getType().getTypeCode(), Matrix.getProperty("parameter.url.type2icon"), asset.getId());
91  setIcon(icon);
92  setDisabledIcon(icon.getDisabledIcon());
93  } else {
94  setDisabledIcon(null);
95  if (asset.getType() != null)
96  setIcon(asset.getType().getIcon());
97  }
98 
99  if (!MatrixTreeBus.typeIsRestricted(asset.getType())) {
100  setEnabled(false);
101  } else {
102  setEnabled(true);
103  }
104  } else if (node instanceof ExpandingNode) {
105  if (node instanceof ExpandingNextNode) {
106  setToolTipText(Matrix.translate("asset_map_tooltip_next_node"));
107  setIcon(GUIUtilities.getAssetMapIcon("down_arrows.png"));
108  } else {
109  setToolTipText(Matrix.translate("asset_map_tooltip_previous_node"));
110  setIcon(GUIUtilities.getAssetMapIcon("up_arrows.png"));
111 
112  }
113  setEnabled(true);
114  // If we are not in CueMode and we are using CueMode name then update the name
115  if (!((MatrixTree)tree).inCueMode() && ((ExpandingNode)node).usingCueModeName()) {
116  ((ExpandingNode)node).switchName();
117  ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
118  setText(((ExpandingNode)node).getAssetName());
119  }
120  } else if (node instanceof LoadingNode) {
121  setIcon(GUIUtilities.getAssetMapIcon("loading_node.png"));
122  }
123 
124  } else if (value instanceof DefaultMutableTreeNode) {
125  DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
126  if (node.getUserObject() instanceof String) {
127  setText((String) node.getUserObject());
128  }
129  }
130 
131 
132 
133  return this;
134  }
135 
136  private boolean isNavNode(MatrixTreeNode node) {
137  if (!(node instanceof LoadingNode) && !(node instanceof ExpandingNode)) {
138  return false;
139  }
140  return true;
141  }
142 
143  protected String getNodeDisplayText(MatrixTreeNode node) {
144  if ((node instanceof ExpandingNode)) {
145  return ((ExpandingNode)node).getAssetName();
146  }
147  return node.getName() + " ";
148  }
149 
156  public void paint(Graphics g) {
157  if (node instanceof ExpandingNode) {
158  ((ExpandingNode)node).setInitStrWidth(getWidth()+5);
159  int width = ((ExpandingNode)node).getInitStrWidth();
160  g.setColor(MatrixLookAndFeel.PANEL_COLOUR);
161  g.fillRoundRect(0, 0, width, getHeight(), 10, 10);
162  }
163 
164  if ((selected || allSelected) && !isNavNode(node)) {
165  int offset = getIcon().getIconWidth() + (getIconTextGap() / 2);
166  if (selected && allSelected) {
167  g.setColor(asset.getStatusColour().darker());
168  } else {
169  g.setColor(asset.getStatusColour());
170  }
171  g.fillRect(offset, 2, getWidth(), getHeight() - 4);
172  g.setColor(asset.getStatusColour().darker());
173  g.drawRect(offset, 2, getWidth() - offset - 1, getHeight() - 4);
174  }
175  super.paint(g);
176  }
177 
178 
179 
185  public void validate() {}
186 
192  public void revalidate() {}
193 
199  public void repaint(long tm, int x, int y, int width, int height) {}
200 
206  public void repaint(Rectangle r) {}
207 
213  protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
214  if (propertyName == "text") {
215  super.firePropertyChange(propertyName, oldValue, newValue);
216  }
217  }
218 
224  public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {}
225 
231  public void firePropertyChange(String propertyName, char oldValue, char newValue) {}
232 
238  public void firePropertyChange(String propertyName, short oldValue, short newValue) {}
239 
245  public void firePropertyChange(String propertyName, int oldValue, int newValue) {}
246 
252  public void firePropertyChange(String propertyName, long oldValue, long newValue) {}
253 
259  public void firePropertyChange(String propertyName, float oldValue, float newValue) {}
260 
266  public void firePropertyChange(String propertyName, double oldValue, double newValue) {}
267 
273  public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
274  }