Skip to content
Snippets Groups Projects
Commit 1e743f90 authored by Daniel Felipe  GONZALEZ OBANDO's avatar Daniel Felipe GONZALEZ OBANDO
Browse files

Format correction an known risk-free warnings removal.

- Fix on value assignment on Spinner when JSpinner changes value.
parent ee45f347
No related branches found
No related tags found
No related merge requests found
......@@ -137,7 +137,7 @@ public abstract class EzVar<T> extends EzComponent implements VarListener<T>
* If no value is indicated, the target component will be visible as long as the
* source component is both visible and enabled
*/
public void addVisibilityTriggerTo(EzComponent targetComponent, T... values)
public void addVisibilityTriggerTo(EzComponent targetComponent, @SuppressWarnings("unchecked") T... values)
{
visibilityTriggers.put(targetComponent, values);
......
......@@ -9,7 +9,6 @@ import plugins.adufour.vars.lang.VarDoubleArray;
* @author Alexandre Dufour
*
*/
@SuppressWarnings("deprecation")
@Deprecated
public class EzVarDoubleArray extends EzVar<Double[]>
{
......
......@@ -7,9 +7,7 @@ import plugins.adufour.vars.lang.VarIntegerArray;
*
* @deprecated use {@link EzVarIntegerArrayNative} instead (optimized performances)
* @author Alexandre Dufour
*
*/
@SuppressWarnings("deprecation")
@Deprecated
public class EzVarIntegerArray extends EzVar<Integer[]>
{
......@@ -17,15 +15,16 @@ public class EzVarIntegerArray extends EzVar<Integer[]>
* Creates a new integer variable with a given array of possible values
*
* @param varName
* the name of the variable (as it will appear on the interface)
* the name of the variable (as it will appear on the interface)
* @param defaultValues
* the list of possible values the user may choose from
* the list of possible values the user may choose from
* @param allowUserInput
* set to true to allow the user to input its own value manually, false otherwise
* set to true to allow the user to input its own value manually, false otherwise
* @throws NullPointerException
* if the defaultValues parameter is null
* if the defaultValues parameter is null
*/
public EzVarIntegerArray(String varName, Integer[][] defaultValues, boolean allowUserInput) throws NullPointerException
public EzVarIntegerArray(String varName, Integer[][] defaultValues, boolean allowUserInput)
throws NullPointerException
{
this(varName, defaultValues, 0, allowUserInput);
}
......@@ -34,17 +33,18 @@ public class EzVarIntegerArray extends EzVar<Integer[]>
* Creates a new integer variable with a given array of possible values
*
* @param varName
* the name of the variable (as it will appear on the interface)
* the name of the variable (as it will appear on the interface)
* @param defaultValues
* the list of possible values the user may choose from
* the list of possible values the user may choose from
* @param defaultValueIndex
* the index of the default selected value
* the index of the default selected value
* @param allowUserInput
* set to true to allow the user to input its own value manually, false otherwise
* set to true to allow the user to input its own value manually, false otherwise
* @throws NullPointerException
* if the defaultValues parameter is null
* if the defaultValues parameter is null
*/
public EzVarIntegerArray(String varName, Integer[][] defaultValues, int defaultValueIndex, boolean allowUserInput) throws NullPointerException
public EzVarIntegerArray(String varName, Integer[][] defaultValues, int defaultValueIndex, boolean allowUserInput)
throws NullPointerException
{
super(new VarIntegerArray(varName, null), defaultValues, defaultValueIndex, allowUserInput);
}
......
......@@ -27,22 +27,22 @@ import plugins.adufour.vars.lang.Var;
public class ComboBox<T> extends SwingVarEditor<T>
{
private ActionListener actionListener;
/**
* Creates a new combo box component for the specified variable. Note that the specified
* variable must have a constraint of type {@link ValueSelectionModel}
*
* @param variable
* the variable to attach to this component
* the variable to attach to this component
* @throws IllegalArgumentException
* if the variable has no constraint, or if the constraint is not a
* {@link ValueSelectionModel}
* if the variable has no constraint, or if the constraint is not a
* {@link ValueSelectionModel}
*/
public ComboBox(Var<T> variable) throws IllegalArgumentException
{
super(variable);
}
private static String arrayToString(Object array)
{
String s;
......@@ -52,15 +52,16 @@ public class ComboBox<T> extends SwingVarEditor<T>
s += " " + Array.get(array, i).toString();
return s;
}
@SuppressWarnings("unchecked")
public JComponent createEditorComponent() throws IllegalArgumentException
{
VarEditorModel<T> cons = variable.getDefaultEditorModel();
List<T> defaultValues = null;
boolean freeInput = true;
T defaultValue = variable.getDefaultValue();
if (cons != null)
{
if (cons instanceof ValueSelectionModel)
......@@ -70,63 +71,77 @@ public class ComboBox<T> extends SwingVarEditor<T>
freeInput = constraint.isFreeInput();
defaultValue = constraint.getDefaultValue();
}
else throw new IllegalArgumentException("Variable " + variable.getName() + " must have a value-type constraint");
else
throw new IllegalArgumentException(
"Variable " + variable.getName() + " must have a value-type constraint");
}
final JComboBox<T> jComboBox;
if (defaultValues == null)
{
jComboBox = new JComboBox<T>();
}
else
{
jComboBox = new JComboBox<T>((T[]) defaultValues.toArray());
//jComboBox = new JComboBox<T>(defaultValues.toArray());
}
final JComboBox jComboBox = (defaultValues == null) ? new JComboBox() : new JComboBox(defaultValues.toArray());
jComboBox.setEditable(freeInput);
jComboBox.setSelectedItem(defaultValue);
actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (variable.getReference() == null) updateVariableValue();
if (variable.getReference() == null)
updateVariableValue();
}
};
// Override the default renderer to support array-type items
jComboBox.setRenderer(createRenderer());
// if the combo box allows user input, override the editor to support array-type items
if (jComboBox.isEditable()) jComboBox.setEditor(createEditor());
if (jComboBox.isEditable())
jComboBox.setEditor(createEditor());
return jComboBox;
}
protected ListCellRenderer<T> createRenderer()
{
return new ListCellRenderer<T>()
{
@Override
public Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean isSelected, boolean cellHasFocus)
public Component getListCellRendererComponent(JList<? extends T> list, T value, int index,
boolean isSelected, boolean cellHasFocus)
{
String s = "";
if (value != null)
{
if (value.getClass().isArray())
s = arrayToString(value);
else s = value.toString();
else
s = value.toString();
}
return new JLabel(s);
}
};
}
protected ComboBoxEditor createEditor()
{
return new ComboBoxEditor()
{
final JTextField jTextField = new JTextField();
final Color defaultColor = jTextField.getForeground();
final Color errorColor = Color.red;
final JTextField jTextField = new JTextField();
final Color defaultColor = jTextField.getForeground();
final Color errorColor = Color.red;
@Override
public void addActionListener(ActionListener l)
{
}
@Override
public Component getEditorComponent()
{
......@@ -136,12 +151,12 @@ public class ComboBox<T> extends SwingVarEditor<T>
jTextField.setPreferredSize(dim);
return jTextField;
}
@Override
public T getItem()
{
T item = null;
try
{
item = variable.parse(jTextField.getText());
......@@ -154,22 +169,22 @@ public class ComboBox<T> extends SwingVarEditor<T>
jTextField.setForeground(errorColor);
jTextField.setToolTipText("Cannot parse input into a " + getVariable().getClass().getSimpleName());
}
return item;
}
@Override
public void removeActionListener(ActionListener l)
{
}
@Override
public void selectAll()
{
jTextField.selectAll();
}
@Override
public void setItem(Object item)
{
......@@ -184,7 +199,7 @@ public class ComboBox<T> extends SwingVarEditor<T>
}
};
}
/**
* Replaces the list of values available in the combo box of this variable<br>
* NOTE: this method will replace the current constraint on the variable
......@@ -211,43 +226,43 @@ public class ComboBox<T> extends SwingVarEditor<T>
}
});
}
@SuppressWarnings("unchecked")
protected void updateVariableValue()
{
variable.setValue((T) getEditorComponent().getSelectedItem());
}
@Override
protected void updateInterfaceValue()
{
getEditorComponent().getModel().setSelectedItem(variable.getValue());
}
@Override
public void dispose()
{
super.dispose();
// replace custom instances by new empty ones for garbage collection
final JComboBox<T> jComboBox = getEditorComponent();
jComboBox.setRenderer(new DefaultListCellRenderer());
jComboBox.setModel(new DefaultComboBoxModel<T>());
}
@SuppressWarnings("unchecked")
@Override
public JComboBox<T> getEditorComponent()
{
return (JComboBox<T>) super.getEditorComponent();
}
@Override
protected void activateListeners()
{
getEditorComponent().addActionListener(actionListener);
}
@Override
protected void deactivateListeners()
{
......
......@@ -47,8 +47,7 @@ public class Spinner<N extends Number> extends SwingVarEditor<N>
public void setValue(Object value)
{
super.setValue(value);
if (variable.getReference() == null)
variable.setValue((N) value);
variable.setValue((N) value);
}
});
......
......@@ -15,9 +15,8 @@ import plugins.adufour.vars.util.VarListener;
* use the {@link VarArray} instead
*
* @author Alexandre Dufour
*
* @param <T>
* the inner type of the array
* the inner type of the array
*/
public class VarArray<T> extends VarGenericArray<T[]> implements Iterable<T>
{
......@@ -25,51 +24,51 @@ public class VarArray<T> extends VarGenericArray<T[]> implements Iterable<T>
* Creates a new array variable
*
* @param name
* the variable name
* the variable name
* @param type
* the data type of the array (including the <code>[]</code>)
* the data type of the array (including the <code>[]</code>)
* @param defaultValue
* the initial array
* the initial array
*/
public VarArray(String name, Class<T[]> type, T[] defaultValue)
{
super(name, type, defaultValue);
}
/**
* Creates a new array variable
*
* @param name
* the variable name
* the variable name
* @param type
* the data type of the array (including the <code>[]</code>)
* the data type of the array (including the <code>[]</code>)
* @param defaultValue
* the initial array
* the initial array
* @param defaultListener
* A listener to add to this variable immediately after creation
* A listener to add to this variable immediately after creation
*/
public VarArray(String name, Class<T[]> type, T[] defaultValue, VarListener<T[]> defaultListener)
{
super(name, type, defaultValue, defaultListener);
}
/**
* Inserts the specified elements at the end of this array. This methods acts similarly to
* {@link ArrayList#add(Object)}: a old array is replaced by a new array where the contents of
* the old array is copied and the specified element is added last
*
* @param elements
* the elements to add
* the elements to add
*/
public void add(T... elements)
public void add(@SuppressWarnings("unchecked") T... elements)
{
T[] oldArray = getValue();
ArrayList<T> newArray = new ArrayList<T>(size() + elements.length);
for (T oldElem : oldArray)
newArray.add(oldElem);
newArray.addAll(Arrays.asList(elements));
setValue(newArray.toArray(oldArray));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment