mirror of https://github.com/sipwise/jitsi.git
Implements an editor which allows the user to edit Jitsi's configuration properties from within the application. (Marin Dzhigarov)
parent
9105fe7a21
commit
b4c90af949
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.contactlist;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.text.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.main.call.*;
|
||||
import net.java.sip.communicator.plugin.desktoputil.plaf.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
import net.java.sip.communicator.util.skin.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
public class ContactSearchFieldUI
|
||||
extends SearchFieldUI
|
||||
implements Skinnable
|
||||
{
|
||||
/**
|
||||
* Creates a UI for a SearchFieldUI.
|
||||
*
|
||||
* @param c the text field
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c)
|
||||
{
|
||||
return new ContactSearchFieldUI();
|
||||
}
|
||||
|
||||
public ContactSearchFieldUI()
|
||||
{
|
||||
// Indicates if the big call button outside the search is enabled.
|
||||
String callButtonEnabledString
|
||||
= UtilActivator.getResources().getSettingsString(
|
||||
"impl.gui.CALL_BUTTON_ENABLED");
|
||||
|
||||
if ((callButtonEnabledString != null)
|
||||
&& (callButtonEnabledString.length() > 0))
|
||||
{
|
||||
// If the outside call button is enabled the call button in this
|
||||
// search field is disabled.
|
||||
isCallButtonEnabled
|
||||
= !Boolean.parseBoolean(callButtonEnabledString);
|
||||
}
|
||||
|
||||
loadSkin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the background of the associated component.
|
||||
*
|
||||
* @param g the <tt>Graphics</tt> object used for painting
|
||||
*/
|
||||
@Override
|
||||
protected void customPaintBackground(Graphics g)
|
||||
{
|
||||
isCallButtonEnabled = CallManager.getTelephonyProviders().size() > 0;
|
||||
super.customPaintBackground(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a call when the mouse is clicked on the call icon.
|
||||
*
|
||||
* @param ev the mouse event that has prompted us to create the call.
|
||||
*/
|
||||
@Override
|
||||
protected void updateCallIcon(MouseEvent ev)
|
||||
{
|
||||
super.updateCallIcon(ev);
|
||||
|
||||
|
||||
if ((ev.getID() == MouseEvent.MOUSE_CLICKED) && isCallIconVisible)
|
||||
{
|
||||
Rectangle callButtonRect = getCallButtonRect();
|
||||
int x = ev.getX();
|
||||
int y = ev.getY();
|
||||
|
||||
if (callButtonRect.contains(x, y))
|
||||
{
|
||||
JTextComponent c = getComponent();
|
||||
String searchText = c.getText();
|
||||
|
||||
if (searchText != null)
|
||||
CallManager.createCall(searchText, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
|
||||
import org.jitsi.service.configuration.*;
|
||||
import org.jitsi.service.resources.*;
|
||||
|
||||
/**
|
||||
* The panel containing all buttons for the <tt>PropertiesEditorPanel</tt>.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
public class ButtonsPanel
|
||||
extends TransparentPanel
|
||||
implements ActionListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ConfigurationService confService
|
||||
= PropertiesEditorActivator.getConfigurationService();
|
||||
|
||||
private ResourceManagementService resourceManagementService
|
||||
= PropertiesEditorActivator.getResourceManagementService();
|
||||
|
||||
/**
|
||||
* The delete button.
|
||||
*/
|
||||
private JButton deleteButton = new JButton(
|
||||
resourceManagementService.getI18NString("service.gui.DELETE"));
|
||||
|
||||
/**
|
||||
* The new button.
|
||||
*/
|
||||
private JButton newButton = new JButton(
|
||||
resourceManagementService.getI18NString("service.gui.NEW"));
|
||||
|
||||
/**
|
||||
* The panel, containing all buttons.
|
||||
*/
|
||||
private JPanel buttonsPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1, 8, 8));
|
||||
|
||||
/**
|
||||
* The props table.
|
||||
*/
|
||||
private JTable propsTable;
|
||||
|
||||
/**
|
||||
* Instance of the search box panel.
|
||||
*/
|
||||
private SearchField searchField;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ButtonsPanel</tt>.
|
||||
* @param propsTable the table containing all properties.
|
||||
* @param searchBox the search box panel containing the search box text
|
||||
* field.
|
||||
*/
|
||||
public ButtonsPanel(JTable propsTable, SearchField searchField)
|
||||
{
|
||||
this.propsTable = propsTable;
|
||||
|
||||
this.searchField = searchField;
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||
|
||||
this.newButton.setOpaque(false);
|
||||
this.deleteButton.setOpaque(false);
|
||||
|
||||
this.buttonsPanel.add(newButton);
|
||||
this.buttonsPanel.add(deleteButton);
|
||||
|
||||
this.add(buttonsPanel, BorderLayout.NORTH);
|
||||
|
||||
this.newButton.addActionListener(this);
|
||||
this.deleteButton.addActionListener(this);
|
||||
|
||||
//default as nothing is selected
|
||||
defaultButtonState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default state of buttons, as nothing is selected
|
||||
*/
|
||||
public void defaultButtonState()
|
||||
{
|
||||
enableDeleteButton(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the delete button.
|
||||
*
|
||||
* @param enable TRUE - to enable the delete button, FALSE - to disable it
|
||||
*/
|
||||
public void enableDeleteButton(boolean enable)
|
||||
{
|
||||
this.deleteButton.setEnabled(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs corresponding actions, when a button is pressed.
|
||||
* @param e the <tt>ActionEvent</tt> that notified us
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
JButton sourceButton = (JButton) e.getSource();
|
||||
|
||||
if (sourceButton.equals(newButton))
|
||||
{
|
||||
NewPropertyDialog dialog = new NewPropertyDialog();
|
||||
|
||||
dialog.pack();
|
||||
dialog.setLocation(
|
||||
Toolkit.getDefaultToolkit().getScreenSize().width/2
|
||||
- dialog.getWidth()/2,
|
||||
Toolkit.getDefaultToolkit().getScreenSize().height/2
|
||||
- dialog.getHeight()/2
|
||||
);
|
||||
|
||||
dialog.setVisible(true);
|
||||
|
||||
} else if (sourceButton.equals(deleteButton))
|
||||
{
|
||||
int viewRow = propsTable.getSelectedRow();
|
||||
int modelRow =
|
||||
propsTable.convertRowIndexToModel(viewRow);
|
||||
String selectedProperty
|
||||
= (String)propsTable.getModel().getValueAt(modelRow, 0);
|
||||
confService.removeProperty(selectedProperty);
|
||||
propsTable.clearSelection();
|
||||
defaultButtonState();
|
||||
/**
|
||||
* Resets the text in the search box text field in order to fire
|
||||
* a new value change event for the FilterRow to update the view.
|
||||
*/
|
||||
String text = searchField.getText();
|
||||
searchField.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
/**
|
||||
* The Constants of this package.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*
|
||||
*/
|
||||
public class Constants
|
||||
{
|
||||
/**
|
||||
* Property indicating whether or not to show the <tt>WarningPanel</tt>
|
||||
*/
|
||||
public static String SHOW_WARNING_MSG_PROP =
|
||||
"net.java.sip.communicator.plugin.propertieseditor.showWarningMsg";
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
|
||||
import org.jitsi.service.configuration.*;
|
||||
import org.jitsi.service.resources.*;
|
||||
|
||||
/**
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
public class NewPropertyDialog
|
||||
extends SIPCommDialog
|
||||
implements ActionListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ConfigurationService confService = PropertiesEditorActivator
|
||||
.getConfigurationService();
|
||||
|
||||
private ResourceManagementService resourceManagementService =
|
||||
PropertiesEditorActivator.getResourceManagementService();
|
||||
|
||||
/**
|
||||
* The ok button.
|
||||
*/
|
||||
private JButton okButton = new JButton(
|
||||
resourceManagementService.getI18NString("service.gui.OK"));
|
||||
|
||||
/**
|
||||
* The cancel button.
|
||||
*/
|
||||
private JButton cancelButton = new JButton(
|
||||
resourceManagementService.getI18NString("service.gui.CANCEL"));
|
||||
|
||||
/**
|
||||
* The property name text field.
|
||||
*/
|
||||
private JTextField propertyNameTextField = new JTextField();
|
||||
|
||||
/**
|
||||
* The property value text field.
|
||||
*/
|
||||
private JTextField propertyValueTextField = new JTextField();
|
||||
|
||||
/**
|
||||
* The property name label.
|
||||
*/
|
||||
private JLabel propertyNameLabel = new JLabel(
|
||||
resourceManagementService.getI18NString("service.gui.NAME") + ": ");
|
||||
|
||||
/**
|
||||
* The property value label.
|
||||
*/
|
||||
private JLabel propertyValueLabel = new JLabel(
|
||||
resourceManagementService.getI18NString("service.gui.VALUE") + ": ");
|
||||
|
||||
/**
|
||||
* The panel containing all buttons.
|
||||
*/
|
||||
private JPanel buttonsPanel = new TransparentPanel(new FlowLayout(
|
||||
FlowLayout.CENTER));
|
||||
|
||||
/**
|
||||
* The panel containing the property value and name panels.
|
||||
*/
|
||||
private JPanel dataPanel = new TransparentPanel(new GridBagLayout());
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>NewPropertyDialog</tt>.
|
||||
*/
|
||||
public NewPropertyDialog()
|
||||
{
|
||||
setTitle(resourceManagementService
|
||||
.getI18NString("plugin.propertieseditor.NEW_PROPERTY_TITLE"));
|
||||
JPanel fields = new TransparentPanel(new BorderLayout());
|
||||
fields.setPreferredSize(new Dimension(450, 150));
|
||||
|
||||
this.getContentPane().add(fields);
|
||||
|
||||
fields.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||
fields.add(dataPanel, BorderLayout.NORTH);
|
||||
fields.add(buttonsPanel, BorderLayout.SOUTH);
|
||||
|
||||
this.buttonsPanel.add(okButton);
|
||||
this.buttonsPanel.add(cancelButton);
|
||||
okButton.setEnabled(false);
|
||||
|
||||
this.okButton.addActionListener(this);
|
||||
this.cancelButton.addActionListener(this);
|
||||
|
||||
GridBagConstraints first = new GridBagConstraints();
|
||||
first.gridx = 0;
|
||||
first.gridy = 0;
|
||||
first.weightx = 0;
|
||||
first.anchor = GridBagConstraints.LINE_START;
|
||||
first.gridwidth = 1;
|
||||
first.insets = new Insets(2, 4, 2, 4);
|
||||
first.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
GridBagConstraints second = new GridBagConstraints();
|
||||
second.gridx = 1;
|
||||
second.gridy = 0;
|
||||
second.weightx = 2;
|
||||
second.anchor = GridBagConstraints.LINE_START;
|
||||
second.gridwidth = 1; // GridBagConstraints.REMAINDER;
|
||||
second.insets = first.insets;
|
||||
second.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
dataPanel.add(propertyNameLabel, first);
|
||||
dataPanel.add(propertyNameTextField, second);
|
||||
|
||||
first.gridy = ++second.gridy;
|
||||
|
||||
dataPanel.add(propertyValueLabel, first);
|
||||
dataPanel.add(propertyValueTextField, second);
|
||||
|
||||
propertyNameTextField.getDocument().addDocumentListener(
|
||||
new DocumentListener()
|
||||
{
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
okButton.setEnabled(true);
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
if (propertyNameTextField.getText().length() == 0)
|
||||
okButton.setEnabled(false);
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs corresponding actions, when a button is pressed.
|
||||
*
|
||||
* @param e the <tt>ActionEvent</tt> that notified us
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
JButton sourceButton = (JButton) e.getSource();
|
||||
|
||||
if (sourceButton.equals(okButton))
|
||||
{
|
||||
confService.setProperty(propertyNameTextField.getText(),
|
||||
propertyValueTextField.getText());
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Presses programmatically the cancel button, when Esc key is pressed.
|
||||
*
|
||||
* @param isEscaped indicates if the Esc button was pressed on close
|
||||
*/
|
||||
protected void close(boolean isEscaped)
|
||||
{
|
||||
cancelButton.doClick();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import org.jitsi.service.configuration.*;
|
||||
import org.jitsi.service.resources.ResourceManagementService;
|
||||
|
||||
import java.util.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The <tt>BundleActivator</tt> of the PropertiesEditor plugin.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
* @author Pawel Domas
|
||||
*/
|
||||
public class PropertiesEditorActivator
|
||||
implements BundleActivator
|
||||
{
|
||||
|
||||
/**
|
||||
* The bundle context.
|
||||
*/
|
||||
public static BundleContext bundleContext;
|
||||
|
||||
/**
|
||||
* Starts this bundle and adds the
|
||||
* <td>PropertiesEditorPanel</tt> contained in it to the configuration
|
||||
* window obtained from the <tt>UIService</tt>.
|
||||
* @param bc the <tt>BundleContext</tt>
|
||||
* @throws Exception if one of the operation executed in the start method
|
||||
* fails
|
||||
*/
|
||||
public void start(BundleContext bc) throws Exception
|
||||
{
|
||||
bundleContext = bc;
|
||||
Dictionary<String, String> properties = new Hashtable<String, String>();
|
||||
properties.put(ConfigurationForm.FORM_TYPE,
|
||||
ConfigurationForm.ADVANCED_TYPE);
|
||||
bundleContext.registerService(
|
||||
ConfigurationForm.class.getName(),
|
||||
new LazyConfigurationForm(
|
||||
StartingPanel.class.getName(),
|
||||
getClass().getClassLoader(),
|
||||
"",
|
||||
"plugin.propertieseditor.TITLE",
|
||||
1002, true),
|
||||
properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops this bundles.
|
||||
* @param bc the <tt>BundleContext</tt>
|
||||
* @throws Exception if one of the operation executed in the stop method
|
||||
* fails
|
||||
*/
|
||||
public void stop(BundleContext bc) throws Exception {}
|
||||
|
||||
/**
|
||||
* The ui service
|
||||
*/
|
||||
private static UIService uiService;
|
||||
|
||||
/**
|
||||
* Returns the <tt>UIService</tt> obtained from the bundle context.
|
||||
*
|
||||
* @return the <tt>UIService</tt> obtained from the bundle context.
|
||||
*/
|
||||
public static UIService getUIService()
|
||||
{
|
||||
if (uiService == null)
|
||||
{
|
||||
ServiceReference uiReference =
|
||||
bundleContext.getServiceReference(UIService.class.getName());
|
||||
|
||||
uiService =
|
||||
(UIService) bundleContext.getService(uiReference);
|
||||
}
|
||||
|
||||
return uiService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The configuration service.
|
||||
*/
|
||||
private static ConfigurationService configService;
|
||||
|
||||
/**
|
||||
* Returns the <tt>ConfigurationService</tt> obtained from the bundle context.
|
||||
*
|
||||
* @return the <tt>ConfigurationService</tt> obtained from the bundle context.
|
||||
*/
|
||||
public static ConfigurationService getConfigurationService()
|
||||
{
|
||||
if (configService == null)
|
||||
{
|
||||
configService = ServiceUtils.getService(
|
||||
bundleContext,
|
||||
ConfigurationService.class);
|
||||
}
|
||||
return configService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource management service.
|
||||
*/
|
||||
private static ResourceManagementService resourceManagementService;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <tt>ResourceManagementService</tt> obtained from the bundle context.
|
||||
*
|
||||
* @return the <tt>ResourceManagementService</tt> obtained from the bundle context.
|
||||
*/
|
||||
public static ResourceManagementService getResourceManagementService() {
|
||||
if (resourceManagementService == null) {
|
||||
resourceManagementService = ServiceUtils.getService(
|
||||
bundleContext,
|
||||
ResourceManagementService.class);
|
||||
}
|
||||
return resourceManagementService;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
|
||||
import org.jitsi.service.resources.*;
|
||||
|
||||
/**
|
||||
* @author Marin Dzhigarov
|
||||
* @author Pawel Domas
|
||||
*
|
||||
*/
|
||||
public class PropertiesEditorPanel
|
||||
extends TransparentPanel
|
||||
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ResourceManagementService resourceManagementService =
|
||||
PropertiesEditorActivator.getResourceManagementService();
|
||||
|
||||
/**
|
||||
* The panel containing the props table and the buttons panel
|
||||
*/
|
||||
private JPanel centerPanel;
|
||||
|
||||
/**
|
||||
* The props table.
|
||||
*/
|
||||
private JTable propsTable;
|
||||
|
||||
/**
|
||||
* The buttons panel.
|
||||
*/
|
||||
private ButtonsPanel buttonsPanel;
|
||||
|
||||
/**
|
||||
* Creates an instance <tt>PropertiesEditorPanel</tt>.
|
||||
*/
|
||||
public PropertiesEditorPanel()
|
||||
{
|
||||
super(new BorderLayout());
|
||||
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||
|
||||
/**
|
||||
* Instantiates the properties table and adds selection model and
|
||||
* listener and adds a row sorter to the table model
|
||||
*/
|
||||
propsTable = new JTable(getTableModel());
|
||||
propsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
PropsListSelectionListener selectionListener =
|
||||
new PropsListSelectionListener();
|
||||
propsTable.getSelectionModel().addListSelectionListener(
|
||||
selectionListener);
|
||||
propsTable.getColumnModel().getSelectionModel()
|
||||
.addListSelectionListener(selectionListener);
|
||||
TableRowSorter<TableModel> sorter =
|
||||
new TableRowSorter<TableModel>(propsTable.getModel());
|
||||
propsTable.setRowSorter(sorter);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(propsTable);
|
||||
|
||||
SearchField searchField = new SearchField("", sorter);
|
||||
buttonsPanel = new ButtonsPanel(propsTable, searchField);
|
||||
|
||||
centerPanel = new TransparentPanel(new BorderLayout());
|
||||
centerPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
centerPanel.add(buttonsPanel, BorderLayout.EAST);
|
||||
|
||||
JLabel needRestart =
|
||||
new JLabel(
|
||||
resourceManagementService
|
||||
.getI18NString("plugin.propertieseditor.NEED_RESTART"));
|
||||
needRestart.setForeground(Color.RED);
|
||||
|
||||
TransparentPanel searchPanel =
|
||||
new TransparentPanel(new BorderLayout(5, 0));
|
||||
searchPanel.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
|
||||
searchPanel.add(searchField, BorderLayout.CENTER);
|
||||
|
||||
add(searchPanel, BorderLayout.NORTH);
|
||||
add(centerPanel, BorderLayout.CENTER);
|
||||
add(needRestart, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* The table model of the props table.
|
||||
*/
|
||||
private PropsTableModel tableModel;
|
||||
|
||||
/**
|
||||
* Returns the table model of the props table.
|
||||
*
|
||||
* @return The <tt>PropsTableModel</tt> of the props table.
|
||||
*/
|
||||
private PropsTableModel getTableModel()
|
||||
{
|
||||
if (tableModel == null)
|
||||
tableModel = new PropsTableModel();
|
||||
return tableModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for events triggered when a selection is made in the props list.
|
||||
*/
|
||||
private class PropsListSelectionListener
|
||||
implements ListSelectionListener
|
||||
{
|
||||
|
||||
public void valueChanged(ListSelectionEvent e)
|
||||
{
|
||||
int selectedRow = propsTable.getSelectedRow();
|
||||
|
||||
if (selectedRow == -1)
|
||||
{
|
||||
buttonsPanel.defaultButtonState();
|
||||
return;
|
||||
}
|
||||
|
||||
buttonsPanel.enableDeleteButton(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.beans.*;
|
||||
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
import org.jitsi.service.configuration.*;
|
||||
|
||||
/**
|
||||
* @author Marin Dzhigarov
|
||||
* @author Pawel Domas
|
||||
*
|
||||
*/
|
||||
public class PropsTableModel
|
||||
implements TableModel,
|
||||
PropertyChangeListener
|
||||
{
|
||||
|
||||
/**
|
||||
* The configuration service.
|
||||
*/
|
||||
private ConfigurationService confService = PropertiesEditorActivator.getConfigurationService();
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>PropsTableModel</tt>.
|
||||
*/
|
||||
PropsTableModel() {}
|
||||
|
||||
public void Register()
|
||||
{
|
||||
confService.addPropertyChangeListener(this);
|
||||
}
|
||||
public void Unregister()
|
||||
{
|
||||
confService.removePropertyChangeListener(this);
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt)
|
||||
{
|
||||
for (TableModelListener l : listeners.getListeners(TableModelListener.class))
|
||||
{
|
||||
l.tableChanged(new TableModelEvent(this));
|
||||
}
|
||||
}
|
||||
|
||||
public int getRowCount()
|
||||
{
|
||||
return confService.getAllPropertyNames().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of table columns.
|
||||
* @return int the count of table columns
|
||||
*/
|
||||
public int getColumnCount()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column name given column index.
|
||||
* @param columnIndex The column index.
|
||||
* @return The column name.
|
||||
*/
|
||||
public String getColumnName(int columnIndex)
|
||||
{
|
||||
if(columnIndex == 0)
|
||||
{
|
||||
return "Property";
|
||||
} else
|
||||
{
|
||||
return "Value";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of the column given a column index
|
||||
*/
|
||||
public Class<?> getColumnClass(int columnIndex)
|
||||
{
|
||||
return String.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given cell is edittable.
|
||||
* Edittable cells in this model are cells with column index 1.
|
||||
* @param rowIndex The row index.
|
||||
* @param columnIndex The column index.
|
||||
* @return True if the column index is 1
|
||||
*/
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex)
|
||||
{
|
||||
return columnIndex == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value in the cell given by row and column.
|
||||
*/
|
||||
public Object getValueAt(int rowIndex, int columnIndex)
|
||||
{
|
||||
if (columnIndex == 0)
|
||||
{
|
||||
return confService.getAllPropertyNames().get(rowIndex);
|
||||
} else
|
||||
{
|
||||
return confService.getProperty(confService.getAllPropertyNames().get(rowIndex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets aValue at a cell with coordinates [rowIndex, columnIndex]
|
||||
* @param aValue The given value.
|
||||
* @param rowIndex The row index that the value will be set to.
|
||||
* @param columnIndex The column index that the value will be set to.
|
||||
*/
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
|
||||
{
|
||||
String property = confService.getAllPropertyNames().get(rowIndex);
|
||||
confService.setProperty(property, aValue);
|
||||
}
|
||||
|
||||
private EventListenerList listeners = new EventListenerList();
|
||||
|
||||
public void addTableModelListener(TableModelListener l)
|
||||
{
|
||||
listeners.add(TableModelListener.class, l);
|
||||
}
|
||||
|
||||
public void removeTableModelListener(TableModelListener l)
|
||||
{
|
||||
listeners.remove(TableModelListener.class, l);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.plugin.desktoputil.plaf.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
import net.java.sip.communicator.util.skin.*;
|
||||
|
||||
/**
|
||||
* The field used for searching in the properties table.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*
|
||||
*/
|
||||
public class SearchField
|
||||
extends SIPCommTextField
|
||||
implements Skinnable
|
||||
{
|
||||
|
||||
/**
|
||||
* Serial Version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Class id key used in UIDefaults.
|
||||
*/
|
||||
private static final String uiClassID = SearchField.class.getName()
|
||||
+ "FieldUI";
|
||||
|
||||
/**
|
||||
* The object used for logging.
|
||||
*/
|
||||
private Logger logger = Logger.getLogger(SearchField.class);
|
||||
|
||||
TableRowSorter<TableModel> sorter;
|
||||
|
||||
/**
|
||||
* Adds the ui class to UIDefaults.
|
||||
*/
|
||||
static
|
||||
{
|
||||
UIManager.getDefaults().put(uiClassID,
|
||||
SearchFieldUI.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance <tt>SearchField</tt>.
|
||||
*
|
||||
* @param text the text we would like to enter by default
|
||||
* @param sorter the sorter which will be used for filtering.
|
||||
*/
|
||||
public SearchField(String text, final TableRowSorter<TableModel> sorter)
|
||||
{
|
||||
super(text);
|
||||
|
||||
if (getUI() instanceof SearchFieldUI)
|
||||
{
|
||||
((SearchFieldUI) getUI()).setDeleteButtonEnabled(true);
|
||||
((SearchFieldUI) getUI()).setCallButtonEnabled(false);
|
||||
}
|
||||
|
||||
this.setBorder(null);
|
||||
this.setOpaque(false);
|
||||
this.setPreferredSize(new Dimension(100, 25));
|
||||
this.setDragEnabled(true);
|
||||
|
||||
InputMap imap =
|
||||
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
|
||||
ActionMap amap = getActionMap();
|
||||
amap.put("escape", new AbstractAction()
|
||||
{
|
||||
/**
|
||||
* Serial Version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
setText("");
|
||||
}
|
||||
});
|
||||
|
||||
getDocument().addDocumentListener(new DocumentListener()
|
||||
{
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
RowFilter<TableModel, Object> rf = null;
|
||||
try
|
||||
{
|
||||
rf = RowFilter.regexFilter(getText(), 0);
|
||||
}
|
||||
catch (java.util.regex.PatternSyntaxException exception)
|
||||
{
|
||||
logger.info("Failed to compile regex.", exception);
|
||||
return;
|
||||
}
|
||||
sorter.setRowFilter(rf);
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
RowFilter<TableModel, Object> rf = null;
|
||||
try
|
||||
{
|
||||
rf = RowFilter.regexFilter(getText(), 0);
|
||||
}
|
||||
catch (java.util.regex.PatternSyntaxException exception)
|
||||
{
|
||||
logger.info("Failed to compile regex.", exception);
|
||||
return;
|
||||
}
|
||||
sorter.setRowFilter(rf);
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
loadSkin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the L&F class that renders this component.
|
||||
*
|
||||
* @return the string "TreeUI"
|
||||
* @see JComponent#getUIClassID
|
||||
* @see UIDefaults#getUI
|
||||
*/
|
||||
public String getUIClassID()
|
||||
{
|
||||
return uiClassID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads text field UI defs.
|
||||
*/
|
||||
public void loadSkin()
|
||||
{
|
||||
if (getUI() instanceof SearchFieldUI)
|
||||
{
|
||||
((SearchFieldUI) getUI()).loadSkin();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
|
||||
import org.jitsi.service.configuration.*;
|
||||
|
||||
/**
|
||||
* The <tt>StartingPanel</tt> wraps the <tt>WarningPanel</tt> and
|
||||
* <tt>PropertiesEditorPanel</tt>. Its main purpose is to choose which one of
|
||||
* the panels to set visible.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
public class StartingPanel
|
||||
extends TransparentPanel
|
||||
{
|
||||
/**
|
||||
* Serial Version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ConfigurationService confService = PropertiesEditorActivator
|
||||
.getConfigurationService();
|
||||
|
||||
/*
|
||||
* The WarningPanel
|
||||
*/
|
||||
WarningPanel warningPanel = new WarningPanel(this);
|
||||
|
||||
/**
|
||||
* The PropertiesEditorPanel
|
||||
*/
|
||||
PropertiesEditorPanel propertiesEditorPanel = new PropertiesEditorPanel();
|
||||
|
||||
/**
|
||||
* Creates an instance <tt>StartingPanel</tt>
|
||||
*/
|
||||
public StartingPanel()
|
||||
{
|
||||
super(new BorderLayout());
|
||||
boolean showWarning =
|
||||
confService.getBoolean(Constants.SHOW_WARNING_MSG_PROP, true);
|
||||
|
||||
if (showWarning)
|
||||
{
|
||||
add(warningPanel, BorderLayout.CENTER);
|
||||
}
|
||||
else
|
||||
{
|
||||
add(propertiesEditorPanel, BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.propertieseditor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
|
||||
import org.jitsi.service.configuration.*;
|
||||
import org.jitsi.service.resources.*;
|
||||
|
||||
/**
|
||||
* The <tt>WarningPanel</tt> allows users to change Jitsi configuration
|
||||
* properties at runtime. It wraps the <tt>PropertiesEditorPanel</tt> in order
|
||||
* to provide some more explanations and make complex configurations available
|
||||
* only to advanced users.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
public class WarningPanel
|
||||
extends TransparentPanel
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ResourceManagementService resourceManagementService =
|
||||
PropertiesEditorActivator.getResourceManagementService();
|
||||
|
||||
private ConfigurationService confService = PropertiesEditorActivator
|
||||
.getConfigurationService();
|
||||
|
||||
private JCheckBox checkBox;
|
||||
|
||||
/**
|
||||
* Creates an instance <tt>WarningPanel</tt>
|
||||
*
|
||||
* @param startingPanel
|
||||
*/
|
||||
public WarningPanel(final StartingPanel startingPanel)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
JPanel mainPanel = new TransparentPanel(new BorderLayout(0, 10));
|
||||
add(mainPanel, BorderLayout.NORTH);
|
||||
|
||||
JTextPane warningMsg = new JTextPane();
|
||||
warningMsg.setEditable(false);
|
||||
warningMsg.setOpaque(false);
|
||||
warningMsg.setText(resourceManagementService
|
||||
.getI18NString("plugin.propertieseditor.DESCRIPTION"));
|
||||
|
||||
checkBox =
|
||||
new JCheckBox(
|
||||
resourceManagementService
|
||||
.getI18NString("plugin.propertieseditor.CHECK_BOX"));
|
||||
checkBox.setOpaque(false);
|
||||
checkBox.setSelected(true);
|
||||
|
||||
mainPanel.add(warningMsg, BorderLayout.NORTH);
|
||||
mainPanel.add(checkBox, BorderLayout.CENTER);
|
||||
|
||||
JButton btn =
|
||||
new JButton(
|
||||
resourceManagementService
|
||||
.getI18NString("plugin.propertieseditor.IM_AWARE"));
|
||||
btn.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
confService.setProperty(Constants.SHOW_WARNING_MSG_PROP,
|
||||
new Boolean(checkBox.isSelected()));
|
||||
|
||||
startingPanel.removeAll();
|
||||
startingPanel.add(startingPanel.propertiesEditorPanel,
|
||||
BorderLayout.CENTER);
|
||||
startingPanel.propertiesEditorPanel.setVisible(true);
|
||||
startingPanel.revalidate();
|
||||
startingPanel.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
JPanel buttonPanel =
|
||||
new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
buttonPanel.add(btn);
|
||||
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
Bundle-Activator: net.java.sip.communicator.plugin.propertieseditor.PropertiesEditorActivator
|
||||
Bundle-Description: A panel that allows users to configure properties
|
||||
Bundle-Vendor: jitsi.org
|
||||
Bundle-Version: 0.0.1
|
||||
System-Bundle: yes
|
||||
Import-Package: org.osgi.framework,
|
||||
org.jitsi.service.configuration,
|
||||
org.jitsi.service.resources,
|
||||
net.java.sip.communicator.service.resources,
|
||||
net.java.sip.communicator.service.gui,
|
||||
net.java.sip.communicator.service.gui.event,
|
||||
net.java.sip.communicator.util,
|
||||
net.java.sip.communicator.util.skin,
|
||||
net.java.sip.communicator.plugin.desktoputil,
|
||||
net.java.sip.communicator.plugin.desktoputil.event,
|
||||
net.java.sip.communicator.plugin.desktoputil.plaf,
|
||||
javax.swing,
|
||||
javax.swing.event,
|
||||
javax.swing.table,
|
||||
javax.swing.text,
|
||||
javax.swing.border,
|
||||
javax.swing.plaf
|
||||
Loading…
Reference in new issue