@Override 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(); this.setVisible(true); this.setLocationRelativeTo(chatPanel); } }
/** * Creates an instance of <tt>ShowPreviewDialog</tt> * * @param chatPanel The <tt>ChatConversationPanel</tt> that is associated with this dialog. */ ShowPreviewDialog(final ChatConversationPanel chatPanel) { this.chatPanel = chatPanel; this.setTitle( GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_DIALOG_TITLE")); okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK")); cancelButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.CANCEL")); JPanel mainPanel = new TransparentPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // mainPanel.setPreferredSize(new Dimension(200, 150)); this.getContentPane().add(mainPanel); JTextPane descriptionMsg = new JTextPane(); descriptionMsg.setEditable(false); descriptionMsg.setOpaque(false); descriptionMsg.setText( GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_WARNING_DESCRIPTION")); Icon warningIcon = null; try { warningIcon = new ImageIcon( ImageIO.read( GuiActivator.getResources().getImageURL("service.gui.icons.WARNING_ICON"))); } catch (IOException e) { logger.debug("failed to load the warning icon"); } JLabel warningSign = new JLabel(warningIcon); JPanel warningPanel = new TransparentPanel(); warningPanel.setLayout(new BoxLayout(warningPanel, BoxLayout.X_AXIS)); warningPanel.add(warningSign); 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( GuiActivator.getResources() .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL")); enableReplacementProposal.setOpaque(false); JPanel checkBoxPanel = new TransparentPanel(); checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS)); checkBoxPanel.add(enableReplacement); checkBoxPanel.add(enableReplacementProposal); JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); mainPanel.add(warningPanel); mainPanel.add(Box.createVerticalStrut(10)); mainPanel.add(checkBoxPanel); mainPanel.add(buttonsPanel); okButton.addActionListener(this); cancelButton.addActionListener(this); this.setPreferredSize(new Dimension(390, 230)); }
/** * Saves all configuration settings when the "Save" button is pressed. * * @param e the <tt>ActionEvent</tt> that notified us of the button action */ public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); if (button.equals(saveButton)) { Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet(); while (configurationSet.hasNext()) { ChatRoomConfigurationFormField formField = configurationSet.next(); // If the field is of type fixed the user could not change it, // so we skip it. if (formField.getType().equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) continue; JComponent c = uiFieldsTable.get(formField.getName()); if (c instanceof JTextComponent) { String newValue = ((JTextComponent) c).getText(); if (formField.getType().equals(ChatRoomConfigurationFormField.TYPE_ID_MULTI)) { // extract values StringTokenizer idTokens = new StringTokenizer(newValue, System.getProperty("line.separator")); while (idTokens.hasMoreTokens()) { formField.addValue(idTokens.nextToken()); } } else formField.addValue(newValue); } else if (c instanceof AbstractButton) { boolean isSelected = ((AbstractButton) c).isSelected(); formField.addValue(isSelected); } else if (c instanceof JComboBox) { Object selectedObject = ((JComboBox) c).getSelectedItem(); formField.addValue(selectedObject); } else if (c instanceof JPanel) { Component[] components = c.getComponents(); for (Component comp : components) { if (!(comp instanceof JCheckBox)) continue; JCheckBox checkBox = (JCheckBox) comp; formField.addValue(checkBox.getText()); } } } new Thread() { @Override public void run() { try { configForm.submit(); } catch (Exception e) { new ErrorDialog( ChatRoomConfigurationWindow.this, GuiActivator.getResources().getI18NString("service.gui.ERROR"), GuiActivator.getResources() .getI18NString("service.gui.CHAT_ROOM_CONFIGURATION_SUBMIT_FAILED"), e) .showDialog(); } } }.start(); } this.dispose(); }
@Override 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() { /** * Called on the event dispatching thread (not on the worker thread) after the <code> * construct</code> method has returned. */ @Override public void finished() { String newChatString = (String) get(); if (newChatString != null) { try { Element elem = chatPanel.document.getElement(currentMessageID); chatPanel.document.setOuterHTML(elem, newChatString); msgIDToChatString.put(currentMessageID, newChatString); } catch (BadLocationException ex) { logger.error("Could not replace chat message", ex); } catch (IOException ex) { logger.error("Could not replace chat message", ex); } } } @Override protected Object construct() throws Exception { String newChatString = msgIDToChatString.get(currentMessageID); try { String originalLink = msgIDandPositionToLink.get(currentMessageID + "#" + currentLinkPosition); String replacementLink = linkToReplacement.get(originalLink); String replacement; DirectImageReplacementService source = GuiActivator.getDirectImageReplacementSource(); if (originalLink.equals(replacementLink) && (!source.isDirectImage(originalLink) || source.getImageSize(originalLink) == -1)) { replacement = originalLink; } else { replacement = "<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"" + replacementLink + "\" BORDER=\"0\" ALT=\"" + originalLink + "\"></IMG>"; } String old = originalLink + "</A> <A href=\"jitsi://" + ShowPreviewDialog.this.getClass().getName() + "/SHOWPREVIEW?" + currentMessageID + "#" + currentLinkPosition + "\">" + GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW"); newChatString = newChatString.replace(old, replacement); } catch (Exception ex) { logger.error("Could not replace chat message", ex); } return newChatString; } }; worker.start(); this.setVisible(false); } else if (arg0.getSource().equals(cancelButton)) { this.setVisible(false); } }
/** Loads the configuration form obtained from the chat room. */ protected void loadConfigurationForm() { Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet(); while (configurationSet.hasNext()) { ChatRoomConfigurationFormField formField = configurationSet.next(); Iterator<?> values = formField.getValues(); Iterator<String> options = formField.getOptions(); JComponent field; JLabel label = new JLabel("", JLabel.RIGHT); if (formField.getLabel() != null) label.setText(formField.getLabel() + ": "); String fieldType = formField.getType(); if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_BOOLEAN)) { // Create a check box when the field is of type boolean. field = new SIPCommCheckBox(formField.getLabel()); label.setText(""); if (values.hasNext()) { ((JCheckBox) field).setSelected((Boolean) values.next()); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) { field = new JLabel(); if (values.hasNext()) { String value = values.next().toString(); ((JLabel) field).setText(value); field.setFont(new Font(null, Font.ITALIC, 10)); field.setForeground(Color.GRAY); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_LIST_MULTI)) { field = new TransparentPanel(new GridLayout(0, 1)); field.setBorder(BorderFactory.createLineBorder(Color.GRAY)); Hashtable<Object, JCheckBox> optionCheckBoxes = new Hashtable<Object, JCheckBox>(); while (options.hasNext()) { Object option = options.next(); JCheckBox checkBox = new SIPCommCheckBox(option.toString()); field.add(checkBox); optionCheckBoxes.put(option, checkBox); } while (values.hasNext()) { Object value = values.next(); (optionCheckBoxes.get(value)).setSelected(true); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_LIST_SINGLE)) { field = new JComboBox(); while (options.hasNext()) { ((JComboBox) field).addItem(options.next()); } if (values.hasNext()) { ((JComboBox) field).setSelectedItem(values.next()); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_MULTI)) { field = new JEditorPane(); if (values.hasNext()) { String value = values.next().toString(); ((JEditorPane) field).setText(value); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_SINGLE) || fieldType.equals(ChatRoomConfigurationFormField.TYPE_ID_SINGLE)) { field = new JTextField(); if (values.hasNext()) { String value = values.next().toString(); ((JTextField) field).setText(value); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_PRIVATE)) { field = new JPasswordField(); if (values.hasNext()) { String value = values.next().toString(); ((JPasswordField) field).setText(value); } } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_ID_MULTI)) { StringBuffer buff = new StringBuffer(); while (values.hasNext()) { String value = values.next().toString(); buff.append(value); if (values.hasNext()) buff.append(System.getProperty("line.separator")); } field = new JTextArea(buff.toString()); } else { if (label.getText() == null) continue; field = new JTextField(); if (values.hasNext()) { String value = values.next().toString(); ((JTextField) field).setText(value); } } // If the field is not fixed (i.e. could be changed) we would like // to save it in a list in order to use it later when user saves // the configuration data. if (!fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) { uiFieldsTable.put(formField.getName(), field); } JPanel fieldPanel = new TransparentPanel(new GridLayout(1, 2)); fieldPanel.setOpaque(false); if (!(field instanceof JLabel)) fieldPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0)); else fieldPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0)); fieldPanel.add(label); fieldPanel.add(field); this.mainPanel.add(fieldPanel); } }