/** * The internal controls will want to tell about their mouse events. No longer doing the outer * casing (ie this component itself) Also note that these mouse listeners are kept so they can be * re-applied later. */ public void addMouseListener(MouseListener l) { // MouseListener mouseListeners[] = getMouseListeners(); // Print.prArray( mouseListeners, "mouseListeners of <" + getName() + ">, ID: " + getId()); // Err.pr( "Adding new mouse listener: " + l); // super.addMouseListener( l); for (int i = 0; i < labels.length; i++) { JLabel label = labels[i]; label.addMouseListener(l); IconLabel iconLabel = getIconLabelAt(i, extras); if (iconLabel != null) { iconLabel.addMouseListener(l); } } mouseListeners.add(l); }
public void init( List<String> titles, int selected, String explanation, List<ExpanderControlTransObj> extras) { this.selected = selected; Err.pr(SdzNote.EXPANDER_IDX, "init on <" + getName() + ">, selected <" + selected + ">"); if (SdzNote.EXPANDER_IDX.isVisible() && "chkIntoExisting".equals(getName()) && selected == 0) { Err.pr("Selecting 0 not happening on DB (solution was to write toString())"); } removeAll(); ModernTableLayout modernTableLayout = new ModernTableLayout(); modernTableLayout.insertColumn(0, LEFT_EDGE_WIDTH); modernTableLayout.insertColumn(1, 25 - LEFT_EDGE_WIDTH); modernTableLayout.insertColumn(2, GAP_WIDTH); int count = NUM_LEAD_COLS; for (int i = 0; i < titles.size(); i++) { String title = titles.get(i); long labelWidth; if (sizeIncreasesWhenSelected) { labelWidth = WidgetUtils.calcPixelWidthOfStringOnComponent(title, TYPICAL_BIG_CONTAINER); } else { labelWidth = WidgetUtils.calcPixelWidthOfStringOnComponent(title, TYPICAL_SIZED_CONTAINER); } modernTableLayout.insertColumn(count, labelWidth); count++; IconLabel iconLabel = getIconLabelAt(i, extras); if (iconLabel != null) { Icon icon = iconLabel.getIcon(); if (icon != null) { modernTableLayout.insertColumn(count, icon.getIconWidth() + 7); count++; } else { Err.error("Expect there to always be an icon in an IconLabel"); } } modernTableLayout.insertColumn(count, GAP_WIDTH); count++; } modernTableLayout.insertRow(0, ModernTableLayout.FILL); setLayout(modernTableLayout); NoEdgedButton[] labels = new NoEdgedButton[titles.size()]; lShiftRight = new NoEdgedButton(); add(lShiftRight, "1,0"); count = NUM_LEAD_COLS; for (int i = 0; i < titles.size(); i++) { NoEdgedButton item = new NoEdgedButton(); addMouseListeners(item, mouseListeners); item.setActionListener(this); if (i == selected) { if (sizeIncreasesWhenSelected) { item.setFont(BIG_BOLD_FONT); } else { item.setFont(BOLD_FONT); } if (foregroundChangesWhenSelected) { item.setForeground(PURPLE); } } else { item.setFont(NORMAL_FONT); item.setForeground(null); } item.setName("lExpander control item number " + i); String title = titles.get(i); item.setText(title); item.setHorizontalAlignment(SwingConstants.LEADING); add(item, count + ", 0"); count++; IconLabel iconLabel = getIconLabelAt(i, extras); if (iconLabel != null) { addMouseListeners(iconLabel, mouseListeners); add(iconLabel, count + ", 0"); count++; } count++; labels[i] = item; if (extras != null && extras.size() > i) { if (extras.get(i).getBackground() != null) { labels[i].setOpaque(true); labels[i].setBackground(extras.get(i).getBackground()); } else { // Err.error( "Do we just setBackground() to null and opaque to false?"); labels[i].setOpaque(false); labels[i].setBackground(null); } if (selected == i && foregroundChangesWhenSelected) { /* * Never override the selected foreground being purple if * selected being purple is what has been specified. */ } else { if (extras.get(i).getForeground() != null) { labels[i].setForeground(extras.get(i).getForeground()); } else { labels[i].setForeground(null); } } if (extras.get(i).getToolTipText() != null) { labels[i].setToolTipText(extras.get(i).getToolTipText()); } else { labels[i].setToolTipText(null); } if (iconLabel != null) { if (extras.get(i).getIconToolTipText() != null) { iconLabel.setToolTipText(extras.get(i).getIconToolTipText()); } else { iconLabel.setToolTipText(null); } } } } lShiftRight.setName("lShiftRight"); lShiftRight.setToolTipText(explanation); lShiftRight.setActionListener(this); PortableImageIcon portableImageIcon = PortableImageIcon.createImageIcon( "images/control_end_blue.png", "Change View", PortableImageIcon.STDERR_MSG); if (portableImageIcon != null) { lShiftRight.setIcon(portableImageIcon); } setLShiftRight(lShiftRight); setName("ExpanderControl"); setLabels(labels); setExplanation(explanation); /* setBackgrounds( backgrounds); setForegrounds( foregrounds); setToolTipTexts( toolTipTexts); */ setExtras(extras); }