Fixes show preview link for image/video replacement. Reorganize and fix configuration. Adds option to show configuration on right click over replaced images.

fix-message-formatting 5270
Damian Minkov 11 years ago
parent ee16e0b46f
commit fb3f68714c

@ -1700,8 +1700,11 @@ plugin.reconnectplugin.NETWORK_DOWN=Network connectivity lost!
plugin.chatconfig.TITLE=Chat
plugin.chatconfig.replacement.TITLE=Image/Video:
plugin.chatconfig.replacement.ENABLE_SMILEY_STATUS=Enable smiley replacement
plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS=Enable Image/Video replacement
plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL=Show proposals for Image/Video replacement
plugin.chatconfig.replacement.REPLACEMENT_TITLE=Image/Video replacement
plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS=Enable
plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL=Disable (show preview link)
plugin.chatconfig.replacement.DISABLE_REPLACEMENT=Disable
plugin.chatconfig.replacement.CONFIGURE_REPLACEMENT=Change Image/Video replacement settings
plugin.chatconfig.replacement.REPLACEMENT_SOURCES=Sources:
plugin.chatconfig.spellcheck.TITLE=SpellCheck

@ -28,6 +28,7 @@
import net.java.sip.communicator.impl.gui.main.chat.history.*;
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.plugin.desktoputil.SwingWorker;
import net.java.sip.communicator.service.gui.*;
@ -41,6 +42,8 @@
import net.java.sip.communicator.util.skin.*;
import org.jitsi.util.*;
import org.osgi.framework.*;
/**
* The <tt>ChatConversationPanel</tt> is the panel, where all sent and received
* messages appear. All data is stored in an HTML document. An external CSS file
@ -136,11 +139,26 @@ public class ChatConversationPanel
*/
private String currentHref;
/**
* The currently shown href, is it an img element.
*/
private boolean isCurrentHrefImg = false;
/**
* The copy link item, contained in the right mouse click menu.
*/
private final JMenuItem copyLinkItem;
/**
* The copy link item, contained in the right mouse click menu.
*/
private final JMenuItem configureReplacementItem;
/**
* The configure replacement item separator.
*/
private final JSeparator configureReplacementSeparator = new JSeparator();
/**
* The open link item, contained in the right mouse click menu.
*/
@ -310,6 +328,30 @@ public void actionPerformed(ActionEvent e)
GuiActivator.getResources().getI18nMnemonic(
"service.gui.COPY_LINK"));
configureReplacementItem = new JMenuItem(
GuiActivator.getResources().getI18NString(
"plugin.chatconfig.replacement.CONFIGURE_REPLACEMENT"),
GuiActivator.getResources().getImage(
"service.gui.icons.CONFIGURE_ICON"));
configureReplacementItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
final ConfigurationContainer configContainer
= GuiActivator.getUIService().getConfigurationContainer();
ConfigurationForm chatConfigForm = getChatConfigForm();
if (chatConfigForm != null)
{
configContainer.setSelected(chatConfigForm);
configContainer.setVisible(true);
}
}
});
this.isSimpleTheme = ConfigurationUtils.isChatSimpleThemeEnabled();
/*
@ -1171,11 +1213,14 @@ public void hyperlinkUpdate(HyperlinkEvent e)
{
String href = e.getDescription();
this.isCurrentHrefImg
= e.getSourceElement().getName().equals("img");
this.currentHref = href;
}
else if (e.getEventType() == HyperlinkEvent.EventType.EXITED)
{
this.currentHref = "";
this.isCurrentHrefImg = false;
}
}
@ -1228,7 +1273,7 @@ else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0
catch (URISyntaxException e1)
{
logger.error("Failed to open hyperlink in chat window. " +
"Error was: Invalid URL - " + currentHref);
"Error was: Invalid URL - " + currentHref);
return;
}
if("jitsi".equals(uri.getScheme()))
@ -1261,12 +1306,19 @@ private void openContextMenu(Point p)
rightButtonMenu.insert(openLinkItem, 0);
rightButtonMenu.insert(copyLinkItem, 1);
rightButtonMenu.insert(copyLinkSeparator, 2);
if(isCurrentHrefImg)
{
rightButtonMenu.insert(configureReplacementItem, 3);
rightButtonMenu.insert(configureReplacementSeparator, 4);
}
}
else
{
rightButtonMenu.remove(openLinkItem);
rightButtonMenu.remove(copyLinkItem);
rightButtonMenu.remove(copyLinkSeparator);
rightButtonMenu.remove(configureReplacementItem);
rightButtonMenu.remove(configureReplacementSeparator);
}
if (chatTextPane.getSelectedText() != null)
@ -1956,6 +2008,60 @@ private String getElementContent(String elementId, String message)
return null;
}
/**
* Returns the first available advanced configuration form.
*
* @return the first available advanced configuration form
*/
public static ConfigurationForm getChatConfigForm()
{
// General configuration forms only.
String osgiFilter = "("
+ ConfigurationForm.FORM_TYPE
+ "="+ConfigurationForm.GENERAL_TYPE+")";
ServiceReference[] confFormsRefs = null;
try
{
confFormsRefs = GuiActivator.bundleContext
.getServiceReferences(
ConfigurationForm.class.getName(),
osgiFilter);
}
catch (InvalidSyntaxException ex)
{}
String chatConfigFormClassName =
"net.java.sip.communicator.plugin.chatconfig.ChatConfigPanel";
if(confFormsRefs != null)
{
for (int i = 0; i < confFormsRefs.length; i++)
{
ConfigurationForm form
= (ConfigurationForm) GuiActivator.bundleContext
.getService(confFormsRefs[i]);
if (form instanceof LazyConfigurationForm)
{
LazyConfigurationForm lazyConfigForm
= (LazyConfigurationForm) form;
if (lazyConfigForm.getFormClassName()
.equals(chatConfigFormClassName))
return form;
}
else if (form.getClass().getName()
.equals(chatConfigFormClassName))
{
return form;
}
}
}
return null;
}
/**
* Extends SIPCommHTMLEditorKit to keeps track of created ImageView for
* the gif images in order to flush them whenever they are no longer visible
@ -2322,6 +2428,24 @@ private void processText(String plainText,
msgBuff.append(group);
}
}
else if (isProposalEnabled)
{
msgBuff.append(group);
msgBuff.append(
"</A> <A href=\"jitsi://"
+ showPreview.getClass().getName()
+ "/SHOWPREVIEW?" + messageID + "#"
+ linkCounter + "\">"
+ GuiActivator.getResources().
getI18NString("service.gui.SHOW_PREVIEW"));
showPreview.getMsgIDandPositionToLink()
.put(
messageID + "#" + linkCounter++, group);
showPreview.getLinkToReplacement()
.put(
group, temp);
}
else if (isEnabled && isEnabledForSource)
{
if (isDirectImage)
@ -2355,24 +2479,6 @@ else if (isEnabled && isEnabledForSource)
msgBuff.append("\"></IMG>");
}
}
else if (isProposalEnabled)
{
msgBuff.append(group);
msgBuff.append(
"</A> <A href=\"jitsi://"
+ showPreview.getClass().getName()
+ "/SHOWPREVIEW?" + messageID + "#"
+ linkCounter + "\">"
+ GuiActivator.getResources().
getI18NString("service.gui.SHOW_PREVIEW"));
showPreview.getMsgIDandPositionToLink()
.put(
messageID + "#" + linkCounter++, group);
showPreview.getLinkToReplacement()
.put(
group, temp);
}
else
{
msgBuff.append(group);

@ -38,9 +38,6 @@ public class ShowPreviewDialog
private static final Logger logger
= Logger.getLogger(ShowPreviewDialog.class);
ConfigurationService cfg
= GuiActivator.getConfigurationService();
/**
* The Ok button.
*/
@ -54,12 +51,7 @@ public class ShowPreviewDialog
/**
* Checkbox that indicates whether or not to show this dialog next time.
*/
private final JCheckBox enableReplacementProposal;
/**
* Checkbox that indicates whether or not to show previews automatically
*/
private final JCheckBox enableReplacement;
private final JCheckBox configureReplacement;
/**
* The <tt>ChatConversationPanel</tt> that this dialog is associated with.
@ -147,23 +139,14 @@ public class ShowPreviewDialog
warningPanel.add(Box.createHorizontalStrut(10));
warningPanel.add(descriptionMsg);
enableReplacement
= new JCheckBox(
GuiActivator.getResources().getI18NString(
"plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS"));
enableReplacement.setOpaque(false);
enableReplacement.setSelected(
cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true));
enableReplacementProposal
= new JCheckBox(
configureReplacement
= new SIPCommCheckBox(
GuiActivator.getResources().getI18NString(
"plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL"));
enableReplacementProposal.setOpaque(false);
"plugin.chatconfig.replacement.CONFIGURE_REPLACEMENT"));
JPanel checkBoxPanel = new TransparentPanel();
checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS));
checkBoxPanel.add(enableReplacement);
checkBoxPanel.add(enableReplacementProposal);
JPanel checkBoxPanel = new TransparentPanel(
new FlowLayout(FlowLayout.CENTER));
checkBoxPanel.add(configureReplacement);
JPanel buttonsPanel
= new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
@ -186,10 +169,6 @@ public void actionPerformed(ActionEvent arg0)
{
if (arg0.getSource().equals(okButton))
{
cfg.setProperty(ReplacementProperty.REPLACEMENT_ENABLE,
enableReplacement.isSelected());
cfg.setProperty(ReplacementProperty.REPLACEMENT_PROPOSAL
, enableReplacementProposal.isSelected());
SwingWorker worker = new SwingWorker()
{
/**
@ -275,6 +254,26 @@ else if (arg0.getSource().equals(cancelButton))
{
this.setVisible(false);
}
// Shows chat config panel
if(configureReplacement.isSelected())
{
ConfigurationContainer configContainer
= GuiActivator.getUIService().getConfigurationContainer();
ConfigurationForm chatConfigForm =
ChatConversationPanel.getChatConfigForm();
if(chatConfigForm != null)
{
configContainer.setSelected(chatConfigForm);
configContainer.setVisible(true);
}
// reset for next dialog appearance
configureReplacement.setSelected(false);
}
}
@Override
@ -283,11 +282,6 @@ public void chatLinkClicked(URI url)
String action = url.getPath();
if (action.equals("/SHOWPREVIEW"))
{
enableReplacement.setSelected(
cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true));
enableReplacementProposal.setSelected(
cfg.getBoolean(ReplacementProperty.REPLACEMENT_PROPOSAL, true));
currentMessageID = url.getQuery();
currentLinkPosition = url.getFragment();
@ -325,4 +319,16 @@ Map<String, String> getLinkToReplacement()
{
return linkToReplacement;
}
/**
* All functions implemented in this method will be invoked when user
* presses the Escape key.
*
* @param escaped <tt>true</tt> if this frame has been closed by pressing
* the Esc key; otherwise, <tt>false</tt>
*/
protected void close(boolean escaped)
{
cancelButton.doClick();
}
}

@ -253,6 +253,7 @@ public void run()
this.configList.setSelectedIndex(0);
}
super.setVisible(isVisible);
super.toFront();
}
/**

@ -19,6 +19,7 @@
import net.java.sip.communicator.service.replacement.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.resources.*;
/**
* The <tt>ConfigurationForm</tt> that would be added in the chat configuration
@ -42,12 +43,17 @@ public class ReplacementConfigPanel
/**
* Checkbox to enable/disable replacements other than smileys.
*/
private JCheckBox enableReplacement;
private JRadioButton enableReplacement;
/**
* Checkbox to enable/disable proposal messages for image/video replacement.
*/
private JCheckBox enableReplacementProposal;
private JRadioButton enableReplacementProposal;
/**
* Checkbox to disable image/video replacement.
*/
private JRadioButton disableReplacement;
/**
* Jtable to list all the available replacement sources.
@ -77,16 +83,17 @@ public ReplacementConfigPanel()
*/
private Component createMainPanel()
{
JPanel mainPanel = new TransparentPanel(new BorderLayout());
JPanel mainPanel = new TransparentPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
ResourceManagementService R = ChatConfigActivator.getResources();
enableSmiley =
new SIPCommCheckBox(ChatConfigActivator.getResources()
.getI18NString(
new SIPCommCheckBox(R.getI18NString(
"plugin.chatconfig.replacement.ENABLE_SMILEY_STATUS"));
mainPanel.add(enableSmiley, BorderLayout.WEST);
mainPanel.add(enableSmiley);
enableSmiley.addActionListener(new ActionListener()
{
@ -99,32 +106,34 @@ public void actionPerformed(ActionEvent e)
mainPanel.add(Box.createVerticalStrut(10));
JPanel replacementPanel = new TransparentPanel();
replacementPanel.setLayout(new BoxLayout(replacementPanel, BoxLayout.Y_AXIS));
replacementPanel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(R.getI18NString(
"plugin.chatconfig.replacement.REPLACEMENT_TITLE")),
BorderFactory.createEmptyBorder(3, 3, 3, 3)));
enableReplacement =
new SIPCommCheckBox(ChatConfigActivator.getResources()
.getI18NString(
new SIPCommRadioButton(R.getI18NString(
"plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS"));
mainPanel.add(enableReplacement, BorderLayout.WEST);
replacementPanel.add(enableReplacement);
enableReplacement.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
saveData();
table.revalidate();
table.repaint();
}
});
mainPanel.add(Box.createVerticalStrut(10));
enableReplacementProposal =
new SIPCommCheckBox(ChatConfigActivator.getResources()
.getI18NString(
"plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL"));
new SIPCommRadioButton(R.getI18NString(
"plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL"
));
mainPanel.add(enableReplacementProposal, BorderLayout.WEST);
replacementPanel.add(enableReplacementProposal);
enableReplacementProposal.addActionListener(new ActionListener(){
@ -133,8 +142,25 @@ public void actionPerformed(ActionEvent arg0)
saveData();
}
});
disableReplacement = new SIPCommRadioButton(R.getI18NString(
"plugin.chatconfig.replacement.DISABLE_REPLACEMENT"));
replacementPanel.add(disableReplacement);
// the Jtable to list all the available sources
disableReplacement.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0)
{
saveData();
}
});
ButtonGroup replacementGroup = new ButtonGroup();
replacementGroup.add(enableReplacement);
replacementGroup.add(enableReplacementProposal);
replacementGroup.add(disableReplacement);
// the JTable to list all the available sources
table = new JTable();
table.setShowGrid(false);
table.setTableHeader(null);
@ -144,18 +170,19 @@ public void actionPerformed(ActionEvent arg0)
JScrollPane tablePane = new JScrollPane(table);
tablePane.setOpaque(false);
tablePane.setPreferredSize(new Dimension(mainPanel.getWidth(), 150));
tablePane.setPreferredSize(
new Dimension(replacementPanel.getWidth(), 150));
tablePane.setAlignmentX(LEFT_ALIGNMENT);
JPanel container = new TransparentPanel(new BorderLayout());
container.setPreferredSize(new Dimension(mainPanel.getWidth(), 200));
container.setPreferredSize(
new Dimension(replacementPanel.getWidth(), 200));
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
JLabel label =
new JLabel(ChatConfigActivator.getResources().getI18NString(
new JLabel(R.getI18NString(
"plugin.chatconfig.replacement.REPLACEMENT_SOURCES"));
label.setDisplayedMnemonic(ChatConfigActivator.getResources()
.getI18nMnemonic(
label.setDisplayedMnemonic(R.getI18nMnemonic(
"plugin.chatconfig.replacement.REPLACEMENT_SOURCES"));
label.setLabelFor(table);
@ -202,8 +229,10 @@ public void valueChanged(ListSelectionEvent e)
table.setDefaultRenderer(table.getColumnClass(1),
new FixedTableCellRenderer());
mainPanel.add(Box.createVerticalStrut(10));
mainPanel.add(container, BorderLayout.WEST);
replacementPanel.add(Box.createVerticalStrut(10));
replacementPanel.add(container);
mainPanel.add(replacementPanel);
return mainPanel;
}
@ -216,24 +245,25 @@ private void initValues()
ConfigurationService configService =
ChatConfigActivator.getConfigurationService();
boolean e =
configService.getBoolean(ReplacementProperty
.getPropertyName(ReplacementServiceSmileyImpl.SMILEY_SOURCE),
true);
this.enableSmiley.setSelected(e);
this.enableSmiley.setSelected(
configService.getBoolean(
ReplacementProperty.getPropertyName(
ReplacementServiceSmileyImpl.SMILEY_SOURCE),
true));
e =
configService.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE,
true);
this.enableReplacement.setSelected(e);
this.enableReplacement.setSelected(
configService.getBoolean(
ReplacementProperty.REPLACEMENT_ENABLE, true));
this.enableReplacementProposal.setEnabled(!e);
e =
configService.getBoolean(ReplacementProperty.REPLACEMENT_PROPOSAL,
true);
this.enableReplacementProposal.setSelected(e);
this.enableReplacementProposal.setSelected(
configService.getBoolean(
ReplacementProperty.REPLACEMENT_PROPOSAL, true));
this.table.setEnabled(e);
this.disableReplacement.setSelected(
!this.enableReplacement.isSelected()
&& !this.enableReplacementProposal.isSelected());
this.table.setEnabled(enableReplacement.isSelected());
}
/**
@ -251,15 +281,13 @@ private void saveData()
configService.setProperty(ReplacementProperty.REPLACEMENT_ENABLE,
Boolean.toString(enableReplacement.isSelected()));
boolean e = enableReplacement.isSelected();
enableReplacementProposal.setEnabled(!e);
configService.setProperty(
"plugin.chatconfig.replacement.proposal.enable"
, Boolean.toString(!e && enableReplacementProposal.isSelected()));
"plugin.chatconfig.replacement.proposal.enable",
Boolean.toString(enableReplacementProposal.isSelected()));
table.getSelectionModel().clearSelection();
table.setEnabled(e);
table.setEnabled(enableReplacement.isSelected()
|| enableReplacementProposal.isSelected());
}
/**

Loading…
Cancel
Save