Fixes showing buttons in groups and handling button actions.

fix-message-formatting 5244
Damian Minkov 12 years ago
parent d31437db4d
commit 71812d432f

@ -603,17 +603,10 @@ && isMobile((MetaContact)contact.getDescriptor()))
+ V_GAP + V_GAP
+ ComponentUtils.getStringHeight(displayDetailsLabel); + ComponentUtils.getStringHeight(displayDetailsLabel);
// load button height, before button is even shown
// will be the same as the image
int buttonHeight = 27;
Image img = ImageLoader.getImage(ImageLoader.CHAT_BUTTON_SMALL);
if(img != null)
buttonHeight = img.getHeight(chatButton);
preferredSelectedContactNodeHeight = preferredSelectedContactNodeHeight =
preferredNotSelectedContactNodeHeight preferredNotSelectedContactNodeHeight
+ V_GAP + V_GAP
+ buttonHeight; + BUTTON_HEIGHT;
} }
} }
else if (value instanceof GroupNode) else if (value instanceof GroupNode)
@ -873,10 +866,11 @@ else if (treeNode instanceof GroupNode)
&& !customActionButtonsUIGroup.isEmpty()) && !customActionButtonsUIGroup.isEmpty())
{ {
if(preferredGroupNodeHeight != null) if(preferredGroupNodeHeight != null)
{
preferredSize.height = preferredGroupNodeHeight preferredSize.height = preferredGroupNodeHeight
+ customActionButtonsUIGroup.size() + V_GAP
* customActionButtonsUIGroup.get(0).getHeight() + BUTTON_HEIGHT;
+ V_GAP; }
else else
preferredSize.height = 70; preferredSize.height = 70;
} }
@ -941,19 +935,6 @@ private void addLabels(int nameLabelGridWidth)
constraints.gridwidth = nameLabelGridWidth; constraints.gridwidth = nameLabelGridWidth;
constraints.gridheight = 1; constraints.gridheight = 1;
add(displayDetailsLabel, constraints);
}
else if (treeNode != null && treeNode instanceof GroupNode)
{
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.NONE;
constraints.gridx = 1;
constraints.gridy = 1;
constraints.weightx = 1f;
constraints.weighty = 0f;
constraints.gridwidth = nameLabelGridWidth;
constraints.gridheight = 1;
add(displayDetailsLabel, constraints); add(displayDetailsLabel, constraints);
} }
} }
@ -1029,7 +1010,7 @@ private void initButtonsPanel(UIContact uiContact)
if (imContact != null) if (imContact != null)
{ {
x += addButton(chatButton, ++gridX, x, false); x += addButton(chatButton, ++gridX, x, false, true);
} }
UIContactDetail telephonyContact UIContactDetail telephonyContact
@ -1067,7 +1048,7 @@ private void initButtonsPanel(UIContact uiContact)
&& contactPhoneUtil.isCallEnabled(detailsListener) && contactPhoneUtil.isCallEnabled(detailsListener)
&& providers.size() > 0)) && providers.size() > 0))
{ {
x += addButton(callButton, ++gridX, x, false); x += addButton(callButton, ++gridX, x, false, true);
} }
UIContactDetail videoContact UIContactDetail videoContact
@ -1078,7 +1059,7 @@ private void initButtonsPanel(UIContact uiContact)
|| (contactPhoneUtil != null || (contactPhoneUtil != null
&& contactPhoneUtil.isVideoCallEnabled(detailsListener))) && contactPhoneUtil.isVideoCallEnabled(detailsListener)))
{ {
x += addButton(callVideoButton, ++gridX, x, false); x += addButton(callVideoButton, ++gridX, x, false, true);
} }
UIContactDetail desktopContact UIContactDetail desktopContact
@ -1089,7 +1070,7 @@ private void initButtonsPanel(UIContact uiContact)
|| (contactPhoneUtil != null || (contactPhoneUtil != null
&& contactPhoneUtil.isDesktopSharingEnabled(detailsListener))) && contactPhoneUtil.isDesktopSharingEnabled(detailsListener)))
{ {
x += addButton(desktopSharingButton, ++gridX, x, false); x += addButton(desktopSharingButton, ++gridX, x, false, true);
} }
// enable add contact button if contact source has indicated // enable add contact button if contact source has indicated
@ -1103,7 +1084,7 @@ private void initButtonsPanel(UIContact uiContact)
null).size() > 0 null).size() > 0
&& !ConfigurationUtils.isAddContactDisabled()) && !ConfigurationUtils.isAddContactDisabled())
{ {
x += addButton(addContactButton, ++gridX, x, false); x += addButton(addContactButton, ++gridX, x, false, true);
} }
//webButton //webButton
@ -1117,7 +1098,7 @@ private void initButtonsPanel(UIContact uiContact)
getURLDetails(uiContact, webDetailsListener, true); getURLDetails(uiContact, webDetailsListener, true);
if(dets != null && dets.size() > 0) if(dets != null && dets.size() > 0)
{ {
x += addButton(webButton, ++gridX, x, false); x += addButton(webButton, ++gridX, x, false, true);
webButton.setLinksFromURLDetail(dets); webButton.setLinksFromURLDetail(dets);
} }
@ -1135,7 +1116,7 @@ else if (uiContact.getDescriptor() instanceof SourceContact)
ContactDetail.Category.Web); ContactDetail.Category.Web);
if(dets != null && dets.size() > 0) if(dets != null && dets.size() > 0)
{ {
x += addButton(webButton, ++gridX, x, false); x += addButton(webButton, ++gridX, x, false, true);
webButton.setLinksFromContactDetail(dets); webButton.setLinksFromContactDetail(dets);
} }
@ -1265,7 +1246,7 @@ private int initGroupActionButtons(
customActionButtonsUIGroup.add(actionButton); customActionButtonsUIGroup.add(actionButton);
xBounds xBounds
+= addButton(actionButton, ++gridX, xBounds, false); += addButton(actionButton, ++gridX, xBounds, false, false);
} }
return gridX; return gridX;
@ -1305,7 +1286,7 @@ private int initContactActionButtons(
customActionButtons.add(actionButton); customActionButtons.add(actionButton);
xBounds xBounds
+= addButton(actionButton, ++gridX, xBounds, false); += addButton(actionButton, ++gridX, xBounds, false, true);
} }
return gridX; return gridX;
@ -2029,10 +2010,21 @@ public void run()
} }
} }
/**
* Adds button.
* @param button the button to add
* @param gridX the current x
* @param xBounds bounds
* @param isLast is it the last button
* @param isContact is contact or <tt>false</tt> if it is group node, that
* we are painting.
* @return the button width.
*/
private int addButton( SIPCommButton button, private int addButton( SIPCommButton button,
int gridX, int gridX,
int xBounds, int xBounds,
boolean isLast) boolean isLast,
boolean isContact)
{ {
lastAddedButton = button; lastAddedButton = button;
@ -2047,9 +2039,11 @@ private int addButton( SIPCommButton button,
constraints.weighty = 0f; constraints.weighty = 0f;
add(button, constraints); add(button, constraints);
int yBounds = TOP_BORDER + BOTTOM_BORDER + 2*V_GAP int yBounds = ComponentUtils.getStringSize(
+ ComponentUtils.getStringSize( nameLabel, nameLabel.getText()).height;
nameLabel, nameLabel.getText()).height
if(isContact)
yBounds += TOP_BORDER + BOTTOM_BORDER + 2*V_GAP
+ ComponentUtils.getStringSize( + ComponentUtils.getStringSize(
displayDetailsLabel, displayDetailsLabel.getText()).height; displayDetailsLabel, displayDetailsLabel.getText()).height;

@ -42,6 +42,7 @@ public class TreeContactList
MetaContactQueryListener, MetaContactQueryListener,
MouseListener, MouseListener,
MouseMotionListener, MouseMotionListener,
TreeWillExpandListener,
TreeExpansionListener, TreeExpansionListener,
TreeSelectionListener TreeSelectionListener
{ {
@ -173,6 +174,12 @@ public class TreeContactList
*/ */
private Boolean setAutoSelectionAllowed = false; private Boolean setAutoSelectionAllowed = false;
/**
* The previously selected node component. First nothing is selected so
* it is null.
*/
private Object previouslySelectedNode = null;
/** /**
* Creates the <tt>TreeContactList</tt>. * Creates the <tt>TreeContactList</tt>.
* *
@ -192,6 +199,7 @@ public TreeContactList(ContactListContainer clContainer)
this.addMouseListener(this); this.addMouseListener(this);
this.addMouseMotionListener(this); this.addMouseMotionListener(this);
this.addTreeExpansionListener(this); this.addTreeExpansionListener(this);
this.addTreeWillExpandListener(this);
this.addTreeSelectionListener(this); this.addTreeSelectionListener(this);
GuiActivator.getContactListService() GuiActivator.getContactListService()
@ -1644,6 +1652,66 @@ public void mouseMoved(MouseEvent e)
public void mouseDragged(MouseEvent e) {} public void mouseDragged(MouseEvent e) {}
/**
* Invoked whenever a node in the tree is about to be expanded.
*/
@Override
public void treeWillExpand(TreeExpansionEvent event)
throws ExpandVetoException
{
TreePath path = event.getPath();
if (path == null)
return;
// remember it as previously selected, or moving from other group
// to the collapsed group with custom action buttons, we will need an
// extra click to collapse it again
// keep it null, till something is selected (valueChanged method called)
if(previouslySelectedNode != null)
previouslySelectedNode = path.getLastPathComponent();
}
/**
* Invoked whenever a node in the tree is about to be collapsed.
*/
@Override
public void treeWillCollapse(TreeExpansionEvent event)
throws ExpandVetoException
{
TreePath path = event.getPath();
// If we didn't find any path for the given mouse location, we have
// nothing to do here.
if (path == null)
return;
Object lastComponent = path.getLastPathComponent();
if(lastComponent instanceof GroupNode)
{
GroupNode gn = (GroupNode)lastComponent;
UIGroupImpl uiGroup = gn.getGroupDescriptor();
// if the previous selection is not the group, do not collapse
// this way groups with custom buttons will only collapse
// when selected and clicked again (give a chance to the buttons
// to show)
if( (previouslySelectedNode != null
&& !previouslySelectedNode.equals(lastComponent)
|| previouslySelectedNode == null)
&& uiGroup.getCustomActionButtons() != null
&& uiGroup.getCustomActionButtons().size() > 0)
{
// the veto will not call valueChanged of TreeSelectionListener
previouslySelectedNode = lastComponent;
throw new ExpandVetoException(event);
}
}
}
/** /**
* Stores the state of the collapsed group. * Stores the state of the collapsed group.
* @param event the <tt>TreeExpansionEvent</tt> that notified us for about * @param event the <tt>TreeExpansionEvent</tt> that notified us for about
@ -1756,6 +1824,15 @@ private void dispatchEventToButtons(MouseEvent event)
((SIPCommButton) mouseComponent).getModel() ((SIPCommButton) mouseComponent).getModel()
.setRollover(event.getID() == MouseEvent.MOUSE_MOVED); .setRollover(event.getID() == MouseEvent.MOUSE_MOVED);
// when clicking on buttons, make sure we do not
// collapse group if it is a button in group
if(event.getID() == MouseEvent.MOUSE_RELEASED
&& event.getClickCount() < 2
&& previouslySelectedNode instanceof GroupNode)
{
previouslySelectedNode = null;
}
renderer.resetRolloverState(mouseComponent); renderer.resetRolloverState(mouseComponent);
mouseComponent.dispatchEvent(evt); mouseComponent.dispatchEvent(evt);
@ -2549,6 +2626,12 @@ public void removeSelection()
*/ */
public void valueChanged(TreeSelectionEvent e) public void valueChanged(TreeSelectionEvent e)
{ {
TreePath oldSelectionPath = e.getOldLeadSelectionPath();
if(oldSelectionPath != null)
{
previouslySelectedNode = oldSelectionPath.getLastPathComponent();
}
UIGroup selectedGroup = getSelectedGroup(); UIGroup selectedGroup = getSelectedGroup();
if (selectedGroup != null) if (selectedGroup != null)

Loading…
Cancel
Save