mirror of https://github.com/sipwise/jitsi.git
cusax-fix
parent
3363acadf0
commit
2836fe726f
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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.sipaccregwizz;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
* Implements {@link TableModel} for encryption configuration (ZRTP, SDES and
|
||||
* MIKEY).
|
||||
*
|
||||
* @author Lyubomir Marinov
|
||||
* @author Vincent Lucas
|
||||
*/
|
||||
public class EncryptionConfigurationTableModel
|
||||
extends MoveableTableModel
|
||||
{
|
||||
/**
|
||||
* Serial version UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private boolean[] selectionList;
|
||||
private String[] labelList;
|
||||
|
||||
/**
|
||||
* Creates a new table model in order to manage the encryption protocols and
|
||||
* the corresponding priority.
|
||||
*
|
||||
* @param selectionList A list of boolean which is used to know of the
|
||||
* corresponding protocol (same index) from the labelList is enabled or
|
||||
* disabled.
|
||||
* @param labelList The list of encryption protocols in the priority
|
||||
* order.
|
||||
*/
|
||||
public EncryptionConfigurationTableModel(
|
||||
boolean[] selectionList,
|
||||
String[] labelList)
|
||||
{
|
||||
this.init(selectionList, labelList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int columnIndex)
|
||||
{
|
||||
return
|
||||
(columnIndex == 0)
|
||||
? Boolean.class
|
||||
: super.getColumnClass(columnIndex);
|
||||
}
|
||||
|
||||
public int getColumnCount()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int getRowCount()
|
||||
{
|
||||
//return getEncodings().length;
|
||||
return labelList.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex)
|
||||
{
|
||||
return (columnIndex == 0);
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex)
|
||||
{
|
||||
switch (columnIndex)
|
||||
{
|
||||
case 0:
|
||||
return selectionList[rowIndex];
|
||||
case 1:
|
||||
return labelList[rowIndex];
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object value, int rowIndex, int columnIndex)
|
||||
{
|
||||
if ((columnIndex == 0) && (value instanceof Boolean))
|
||||
{
|
||||
this.selectionList[rowIndex] = ((Boolean) value).booleanValue();
|
||||
|
||||
// We fire the update event before setting the configuration
|
||||
// property in order to have more reactive user interface.
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
|
||||
//encodingConfiguration.setPriorityConfig(encoding, priority);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the row.
|
||||
*
|
||||
* @param rowIndex index of the row
|
||||
* @param up true to move up, false to move down
|
||||
* @return the next row index
|
||||
*/
|
||||
public int move(int rowIndex, boolean up)
|
||||
{
|
||||
int toRowIndex;
|
||||
if (up)
|
||||
{
|
||||
toRowIndex = rowIndex - 1;
|
||||
if (toRowIndex < 0)
|
||||
throw new IllegalArgumentException("rowIndex");
|
||||
}
|
||||
else
|
||||
{
|
||||
toRowIndex = rowIndex + 1;
|
||||
if (toRowIndex >= getRowCount())
|
||||
throw new IllegalArgumentException("rowIndex");
|
||||
}
|
||||
|
||||
// Swaps the selection list.
|
||||
boolean tmpSelectionItem = this.selectionList[rowIndex];
|
||||
this.selectionList[rowIndex] = this.selectionList[toRowIndex];
|
||||
this.selectionList[toRowIndex] = tmpSelectionItem;
|
||||
|
||||
// Swaps the label list.
|
||||
String tmpLabel = this.labelList[rowIndex];
|
||||
this.labelList[rowIndex] = this.labelList[toRowIndex];
|
||||
this.labelList[toRowIndex] = tmpLabel;
|
||||
|
||||
fireTableRowsUpdated(rowIndex, toRowIndex);
|
||||
return toRowIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of the enabled or disabled label in the priority order.
|
||||
*
|
||||
* @param enabledLabels If true this function will return the enabled label
|
||||
* list. Otherwise, it will return the disabled list.
|
||||
*
|
||||
* @return the list of the enabled or disabled label in the priority order.
|
||||
*/
|
||||
public List<String> getLabels(boolean enabledLabels)
|
||||
{
|
||||
ArrayList<String> labels = new ArrayList<String>(this.labelList.length);
|
||||
for(int i = 0; i < this.labelList.length; ++i)
|
||||
{
|
||||
if(this.selectionList[i] == enabledLabels)
|
||||
{
|
||||
labels.add(this.labelList[i]);
|
||||
}
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the label is enabled or disabled.
|
||||
*
|
||||
* @param label The label to be determined as enabled or disabled.
|
||||
*
|
||||
* @return True if the label given in parameter is enabled. False,
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isEnabledLabel(String label)
|
||||
{
|
||||
for(int i = 0; i < this.labelList.length; ++i)
|
||||
{
|
||||
if(this.labelList[i].equals(label))
|
||||
{
|
||||
return this.selectionList[i];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates this table model in order to manage the encryption protocols and
|
||||
* the corresponding priority.
|
||||
*
|
||||
* @param selectionList A list of boolean which is used to know of the
|
||||
* corresponding protocol (same index) from the labelList is enabled or
|
||||
* disabled.
|
||||
* @param labelList The list of encryption protocols in the priority
|
||||
* order.
|
||||
*/
|
||||
public void init(boolean[] selectionList, String[] labelList)
|
||||
{
|
||||
this.selectionList = selectionList;
|
||||
this.labelList = labelList;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.util.swing;
|
||||
|
||||
import javax.swing.table.*;
|
||||
|
||||
/**
|
||||
* @author Vincent Lucas
|
||||
*/
|
||||
public abstract class MoveableTableModel
|
||||
extends AbstractTableModel
|
||||
{
|
||||
/**
|
||||
* Move the row.
|
||||
*
|
||||
* @param rowIndex index of the row
|
||||
* @param up true to move up, false to move down
|
||||
8
|
||||
* @return the next row index
|
||||
*/
|
||||
public abstract int move(int rowIndex, boolean up);
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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.util.swing;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.jitsi.service.resources.*;
|
||||
|
||||
/**
|
||||
* Creates a component containing a table and two buttons for the encodings of
|
||||
* type(AUDIO or VIDEO) or to sort the priority of the encryption protocols.
|
||||
*
|
||||
* @author Vincent Lucas
|
||||
*/
|
||||
public class PriorityTable
|
||||
extends TransparentPanel
|
||||
{
|
||||
/**
|
||||
* The table containing the different elements to sort by priority.
|
||||
*/
|
||||
private JTable table;
|
||||
|
||||
/**
|
||||
* The button to increase the priority of one item by moving it up in the
|
||||
* table.
|
||||
*/
|
||||
private JButton upButton;
|
||||
|
||||
/**
|
||||
* The button to decrease the priority of one item by moving it down in the
|
||||
* table.
|
||||
*/
|
||||
private JButton downButton;
|
||||
|
||||
/**
|
||||
* The preferred width of all panels.
|
||||
*/
|
||||
private final static int WIDTH = 350;
|
||||
|
||||
/**
|
||||
* Creates a component for the encodings of type(AUDIO or VIDEO) or to sort
|
||||
* the priority of the encryption protocols.
|
||||
* @param tableModel The table model to display encodings (AUDIO or VIDEO),
|
||||
* or to sort the priority of the encryption protocols.
|
||||
* @param height The height (preferred and maximum height) of the component.
|
||||
* @return the component.
|
||||
*/
|
||||
public PriorityTable(
|
||||
MoveableTableModel tableModel,
|
||||
int height)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
ResourceManagementService resources = UtilActivator.getResources();
|
||||
String key;
|
||||
String i18NresourcesKey;
|
||||
|
||||
table = new JTable();
|
||||
table.setShowGrid(false);
|
||||
table.setTableHeader(null);
|
||||
|
||||
key = "impl.media.configform.UP";
|
||||
upButton = new JButton(resources.getI18NString(key));
|
||||
upButton.setMnemonic(resources.getI18nMnemonic(key));
|
||||
upButton.setOpaque(false);
|
||||
|
||||
key = "impl.media.configform.DOWN";
|
||||
downButton = new JButton(resources.getI18NString(key));
|
||||
downButton.setMnemonic(resources.getI18nMnemonic(key));
|
||||
downButton.setOpaque(false);
|
||||
|
||||
Container buttonBar = new TransparentPanel(new GridLayout(0, 1));
|
||||
buttonBar.add(upButton);
|
||||
buttonBar.add(downButton);
|
||||
|
||||
Container parentButtonBar = new TransparentPanel(new BorderLayout());
|
||||
parentButtonBar.add(buttonBar, BorderLayout.NORTH);
|
||||
|
||||
//Container container = new TransparentPanel(new BorderLayout());
|
||||
this.setPreferredSize(new Dimension(WIDTH, height));
|
||||
this.setMaximumSize(new Dimension(WIDTH, height));
|
||||
|
||||
this.add(new JScrollPane(table), BorderLayout.CENTER);
|
||||
this.add(parentButtonBar, BorderLayout.EAST);
|
||||
|
||||
table.setModel(tableModel);
|
||||
|
||||
/*
|
||||
* The first column contains the check boxes which enable/disable their
|
||||
* associated encodings and it doesn't make sense to make it wider than
|
||||
* the check boxes.
|
||||
*/
|
||||
TableColumnModel tableColumnModel = table.getColumnModel();
|
||||
TableColumn tableColumn = tableColumnModel.getColumn(0);
|
||||
tableColumn.setMaxWidth(tableColumn.getMinWidth());
|
||||
|
||||
ListSelectionListener tableSelectionListener =
|
||||
new ListSelectionListener()
|
||||
{
|
||||
public void valueChanged(ListSelectionEvent event)
|
||||
{
|
||||
if (table.getSelectedRowCount() == 1)
|
||||
{
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (selectedRow > -1)
|
||||
{
|
||||
upButton.setEnabled(selectedRow > 0);
|
||||
downButton.setEnabled(selectedRow < (table
|
||||
.getRowCount() - 1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
upButton.setEnabled(false);
|
||||
downButton.setEnabled(false);
|
||||
}
|
||||
};
|
||||
table.getSelectionModel().addListSelectionListener(
|
||||
tableSelectionListener);
|
||||
tableSelectionListener.valueChanged(null);
|
||||
|
||||
ActionListener buttonListener = new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
Object source = event.getSource();
|
||||
boolean up;
|
||||
if (source == upButton)
|
||||
up = true;
|
||||
else if (source == downButton)
|
||||
up = false;
|
||||
else
|
||||
return;
|
||||
|
||||
move(up);
|
||||
}
|
||||
};
|
||||
upButton.addActionListener(buttonListener);
|
||||
downButton.addActionListener(buttonListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to move encoding options.
|
||||
* @param table the table with encodings
|
||||
* @param up move direction.
|
||||
*/
|
||||
private void move(boolean up)
|
||||
{
|
||||
int index =
|
||||
((MoveableTableModel) table.getModel()).move(table
|
||||
.getSelectedRow(), up);
|
||||
table.getSelectionModel().setSelectionInterval(index, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled)
|
||||
{
|
||||
this.table.setEnabled(enabled);
|
||||
this.upButton.setEnabled(enabled);
|
||||
this.downButton.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue