Added package-info.java to eva2 base package.
Refactored GenericArrayEditor.java Added more meta data to pom.xml
This commit is contained in:
parent
25198b8249
commit
83b44f1d1a
14
pom.xml
14
pom.xml
@ -80,4 +80,18 @@
|
|||||||
<!-- Default file encoding is UTF-8 -->
|
<!-- Default file encoding is UTF-8 -->
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU LGPL v2.1</name>
|
||||||
|
<url>http://www.gnu.org/licenses/lgpl-2.1.txt</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
<comments>GNU Lesser General Public License, version 2.1</comments>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<organization>
|
||||||
|
<name>Department for Cognitive Systems, University of Tuebingen, Germany</name>
|
||||||
|
<url>http://www.cogsys.cs.uni-tuebingen.de/</url>
|
||||||
|
</organization>
|
||||||
</project>
|
</project>
|
||||||
|
@ -9,16 +9,39 @@ import java.util.Properties;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EvAInfo {
|
public class EvAInfo {
|
||||||
|
/**
|
||||||
|
* Product Name.
|
||||||
|
*/
|
||||||
public static final String productName = "EvA2";
|
public static final String productName = "EvA2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long product name.
|
||||||
|
*/
|
||||||
public static final String productLongName = "Evolutionary Algorithms Workbench 2";
|
public static final String productLongName = "Evolutionary Algorithms Workbench 2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Website URL of EvA2.
|
||||||
|
*/
|
||||||
public static final String url = "http://www.cogsys.cs.uni-tuebingen.de/software/EvA2";
|
public static final String url = "http://www.cogsys.cs.uni-tuebingen.de/software/EvA2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative path to default properties.
|
||||||
|
*/
|
||||||
public static final String propertyFile = "META-INF/EvA2.props";
|
public static final String propertyFile = "META-INF/EvA2.props";
|
||||||
|
|
||||||
public static final String LGPLFile = "lgpl-3.0.txt";
|
public static final String LGPLFile = "lgpl-3.0.txt";
|
||||||
public static final String GPLFile= "gpl-3.0.txt";
|
public static final String GPLFile= "gpl-3.0.txt";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative path to application icon.
|
||||||
|
*/
|
||||||
public static final String iconLocation = "images/icon4.gif";
|
public static final String iconLocation = "images/icon4.gif";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative path to splash screen image.
|
||||||
|
*/
|
||||||
public static final String splashLocation = "images/EvASplashScreen.png";
|
public static final String splashLocation = "images/EvASplashScreen.png";
|
||||||
|
|
||||||
public static final String infoTitle = productName+" Information";
|
public static final String infoTitle = productName+" Information";
|
||||||
public static final String copyrightYear = "2010-2012";
|
public static final String copyrightYear = "2010-2012";
|
||||||
|
|
||||||
@ -38,7 +61,6 @@ public class EvAInfo {
|
|||||||
InputStream istr = BasicResourceLoader.instance().getStreamFromResourceLocation(EvAInfo.iconLocation);
|
InputStream istr = BasicResourceLoader.instance().getStreamFromResourceLocation(EvAInfo.iconLocation);
|
||||||
if (istr==null) {
|
if (istr==null) {
|
||||||
throw new RuntimeException(resourceNotFoundErrorMessage(EvAInfo.iconLocation) + " (EvAInfo.static)");
|
throw new RuntimeException(resourceNotFoundErrorMessage(EvAInfo.iconLocation) + " (EvAInfo.static)");
|
||||||
// System.exit(2); // dont be as harsh right here - there will be plenty of exceptions later in the bad case...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
package eva2.gui;
|
package eva2.gui;
|
||||||
/*
|
|
||||||
* Title: EvA2 Description: Copyright: Copyright (c) 2003 Company: University of Tuebingen, Computer
|
|
||||||
* Architecture @author Holger Ulmer, Felix Streichert, Hannes Planatscher @version: $Revision: 235
|
|
||||||
* $ $Date: 2007-11-08 13:53:51 +0100 (Thu, 08 Nov 2007) $ $Author: mkron $
|
|
||||||
*/
|
|
||||||
|
|
||||||
import eva2.tools.EVAHELP;
|
import eva2.tools.EVAHELP;
|
||||||
import eva2.tools.SerializedObject;
|
import eva2.tools.SerializedObject;
|
||||||
@ -16,36 +11,39 @@ import java.beans.PropertyEditor;
|
|||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(eva2.EvAInfo.defaultLogger);
|
||||||
/**
|
/**
|
||||||
* Handles property change notification
|
* Handles property change notification
|
||||||
*/
|
*/
|
||||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
private PropertyChangeSupport propChangeSupport = new PropertyChangeSupport(this);
|
||||||
/**
|
/**
|
||||||
* The label for when we can't edit that type
|
* The label for when we can't edit that type
|
||||||
*/
|
*/
|
||||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
private JLabel cantEditLabel = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||||
/**
|
/**
|
||||||
* The list component displaying current values
|
* The list component displaying current values
|
||||||
*/
|
*/
|
||||||
private JList m_ElementList = new JList();
|
private JList elementList = new JList();
|
||||||
/**
|
/**
|
||||||
* The class of objects allowed in the array
|
* The class of objects allowed in the array
|
||||||
*/
|
*/
|
||||||
private Class m_ElementClass = String.class;
|
private Class elementClass = String.class;
|
||||||
/**
|
/**
|
||||||
* The defaultlistmodel holding our data
|
* The defaultlistmodel holding our data
|
||||||
*/
|
*/
|
||||||
private DefaultListModel m_ListModel;
|
private DefaultListModel listModel;
|
||||||
/**
|
/**
|
||||||
* The property editor for the class we are editing
|
* The property editor for the class we are editing
|
||||||
*/
|
*/
|
||||||
private PropertyEditor m_ElementEditor;
|
private PropertyEditor elementEditor;
|
||||||
/**
|
/**
|
||||||
* Cheat to handle selectable lists as well
|
* Cheat to handle selectable lists as well
|
||||||
*/
|
*/
|
||||||
@ -53,105 +51,104 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
/**
|
/**
|
||||||
* Click this to delete the selected array values
|
* Click this to delete the selected array values
|
||||||
*/
|
*/
|
||||||
private JButton m_DeleteBut = new JButton("Delete");
|
private JButton deleteButton = new JButton("Delete");
|
||||||
/**
|
/**
|
||||||
* list of additional buttons above the list
|
* list of additional buttons above the list
|
||||||
*/
|
*/
|
||||||
private List<JButton> m_AdditionalUpperButtonList = new LinkedList<JButton>();
|
private List<JButton> upperButtonList = new LinkedList<JButton>();
|
||||||
/**
|
/**
|
||||||
* list of additional buttons below the list
|
* list of additional buttons below the list
|
||||||
*/
|
*/
|
||||||
private List<JButton> m_AdditionalLowerButtonList = new LinkedList<JButton>();
|
private List<JButton> lowerButtonList = new LinkedList<JButton>();
|
||||||
private JComponent additionalCenterComp = null;
|
private JComponent additionalCenterComp = null;
|
||||||
private List<JMenuItem> m_popupItemList = new LinkedList<JMenuItem>();
|
private List<JMenuItem> m_popupItemList = new LinkedList<JMenuItem>();
|
||||||
private JButton m_AddBut = new JButton("Add");
|
private JButton addButton = new JButton("Add");
|
||||||
private JButton m_SetBut = new JButton("Set");
|
private JButton setButton = new JButton("Set");
|
||||||
private JButton m_SetAllBut = new JButton("Set all");
|
private JButton setAllButton = new JButton("Set all");
|
||||||
private boolean withAddButton = true;
|
private boolean withAddButton = true;
|
||||||
private boolean withSetButton = true;
|
private boolean withSetButton = true;
|
||||||
private boolean withDeleteButton = true;
|
private boolean withDeleteButton = true;
|
||||||
private Component m_View = null;
|
private Component view = null;
|
||||||
/**
|
/**
|
||||||
* Listens to buttons being pressed and taking the appropriate action
|
* Listens to buttons being pressed and taking the appropriate action
|
||||||
*/
|
*/
|
||||||
private ActionListener m_InnerActionListener =
|
private ActionListener innerActionListener = new ActionListener() {
|
||||||
new ActionListener() {
|
//
|
||||||
//
|
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
boolean consistentView = true; // be optimistic...
|
boolean consistentView = true; // be optimistic...
|
||||||
if (m_View instanceof PropertyText) { // check consistency!
|
if (view instanceof PropertyText) { // check consistency!
|
||||||
consistentView = ((PropertyText) m_View).checkConsistency();
|
consistentView = ((PropertyText) view).checkConsistency();
|
||||||
if (!consistentView) {
|
if (!consistentView) {
|
||||||
((PropertyText) m_View).updateFromEditor();
|
((PropertyText) view).updateFromEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getSource() == deleteButton) {
|
||||||
|
int[] selected = elementList.getSelectedIndices();
|
||||||
|
if (selected != null) {
|
||||||
|
for (int i = selected.length - 1; i >= 0; i--) {
|
||||||
|
int current = selected[i];
|
||||||
|
listModel.removeElementAt(current);
|
||||||
|
if (listModel.size() > current) {
|
||||||
|
elementList.setSelectedIndex(current);
|
||||||
}
|
}
|
||||||
|
elementList.setModel(listModel);
|
||||||
}
|
}
|
||||||
if (e.getSource() == m_DeleteBut) {
|
|
||||||
int[] selected = m_ElementList.getSelectedIndices();
|
|
||||||
if (selected != null) {
|
|
||||||
for (int i = selected.length - 1; i >= 0; i--) {
|
|
||||||
int current = selected[i];
|
|
||||||
m_ListModel.removeElementAt(current);
|
|
||||||
if (m_ListModel.size() > current) {
|
|
||||||
m_ElementList.setSelectedIndex(current);
|
|
||||||
}
|
|
||||||
m_ElementList.setModel(m_ListModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectableList != null) {
|
if (selectableList != null) {
|
||||||
selectableList.setObjects(modelToArray(selectableList.getObjects(), m_ListModel));
|
selectableList.setObjects(modelToArray(selectableList.getObjects(), listModel));
|
||||||
}
|
}
|
||||||
m_Support.firePropertyChange("", null, null);
|
propChangeSupport.firePropertyChange("", null, null);
|
||||||
}
|
}
|
||||||
if (m_ElementList.getSelectedIndex() == -1) {
|
if (elementList.getSelectedIndex() == -1) {
|
||||||
m_DeleteBut.setEnabled(false);
|
deleteButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == m_AddBut) {
|
} else if (e.getSource() == addButton) {
|
||||||
int selected = m_ElementList.getSelectedIndex();
|
int selected = elementList.getSelectedIndex();
|
||||||
Object addObj = m_ElementEditor.getValue();
|
Object addObj = elementEditor.getValue();
|
||||||
|
|
||||||
// Make a full copy of the object using serialization
|
// Make a full copy of the object using serialization
|
||||||
try {
|
try {
|
||||||
SerializedObject so = new SerializedObject(addObj);
|
SerializedObject so = new SerializedObject(addObj);
|
||||||
addObj = so.getObject();
|
addObj = so.getObject();
|
||||||
so = null;
|
so = null;
|
||||||
if (selected != -1) {
|
if (selected != -1) {
|
||||||
m_ListModel.insertElementAt(addObj, selected);
|
listModel.insertElementAt(addObj, selected);
|
||||||
} else {
|
} else {
|
||||||
m_ListModel.addElement(addObj);
|
listModel.addElement(addObj);
|
||||||
}
|
}
|
||||||
m_ElementList.setModel(m_ListModel);
|
elementList.setModel(listModel);
|
||||||
if (selectableList != null) {
|
if (selectableList != null) {
|
||||||
selectableList.setObjects(modelToArray(selectableList.getObjects(), m_ListModel));
|
selectableList.setObjects(modelToArray(selectableList.getObjects(), listModel));
|
||||||
}
|
}
|
||||||
m_Support.firePropertyChange("", null, null);
|
propChangeSupport.firePropertyChange("", null, null);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
JOptionPane.showMessageDialog(GenericArrayEditor.this, "Could not create an object copy", null, JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(GenericArrayEditor.this, "Could not create an object copy", null, JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == m_SetAllBut) {
|
} else if (e.getSource() == setAllButton) {
|
||||||
Object addObj = m_ElementEditor.getValue();
|
Object addObj = elementEditor.getValue();
|
||||||
for (int i = 0; i < m_ListModel.size(); i++) {
|
for (int i = 0; i < listModel.size(); i++) {
|
||||||
try {
|
try {
|
||||||
m_ListModel.setElementAt(new SerializedObject(addObj).getObject(), i);
|
listModel.setElementAt(new SerializedObject(addObj).getObject(), i);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
JOptionPane.showMessageDialog(GenericArrayEditor.this, "Could not create an object copy", null, JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(GenericArrayEditor.this, "Could not create an object copy", null, JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
|
||||||
}
|
|
||||||
m_Support.firePropertyChange("", null, null);
|
|
||||||
} else if (e.getSource() == m_SetBut) {
|
|
||||||
int selected = m_ElementList.getSelectedIndex();
|
|
||||||
Object addObj = m_ElementEditor.getValue();
|
|
||||||
if (selected >= 0 && (selected < m_ListModel.size())) {
|
|
||||||
try {
|
|
||||||
m_ListModel.setElementAt(new SerializedObject(addObj).getObject(), selected);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
JOptionPane.showMessageDialog(GenericArrayEditor.this, "Could not create an object copy", null, JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
m_Support.firePropertyChange("", null, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
propChangeSupport.firePropertyChange("", null, null);
|
||||||
|
} else if (e.getSource() == setButton) {
|
||||||
|
int selected = elementList.getSelectedIndex();
|
||||||
|
Object addObj = elementEditor.getValue();
|
||||||
|
if (selected >= 0 && (selected < listModel.size())) {
|
||||||
|
try {
|
||||||
|
listModel.setElementAt(new SerializedObject(addObj).getObject(), selected);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
JOptionPane.showMessageDialog(GenericArrayEditor.this, "Could not create an object copy", null, JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
propChangeSupport.firePropertyChange("", null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public void setAdditionalCenterPane(JComponent component) {
|
public void setAdditionalCenterPane(JComponent component) {
|
||||||
this.additionalCenterComp = component;
|
this.additionalCenterComp = component;
|
||||||
@ -161,28 +158,28 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
Class objClass = origArray.getClass().getComponentType();
|
Class objClass = origArray.getClass().getComponentType();
|
||||||
Object[] os = (Object[]) java.lang.reflect.Array.newInstance(objClass, listModel.size());
|
Object[] os = (Object[]) java.lang.reflect.Array.newInstance(objClass, listModel.size());
|
||||||
|
|
||||||
// Object[] os= new Object[listModel.size()];
|
|
||||||
for (int i = 0; i < listModel.size(); i++) {
|
for (int i = 0; i < listModel.size(); i++) {
|
||||||
os[i] = listModel.get(i);
|
os[i] = listModel.get(i);
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens to list items being selected and takes appropriate action
|
* Listens to list items being selected and takes appropriate action
|
||||||
*/
|
*/
|
||||||
private ListSelectionListener m_InnerSelectionListener =
|
private ListSelectionListener innerSelectionListener =
|
||||||
new ListSelectionListener() {
|
new ListSelectionListener() {
|
||||||
//
|
//
|
||||||
|
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
|
||||||
if (e.getSource() == m_ElementList) {
|
if (e.getSource() == elementList) {
|
||||||
// Enable the delete button
|
// Enable the delete button
|
||||||
if (m_ElementList.getSelectedIndex() != -1) {
|
if (elementList.getSelectedIndex() != -1) {
|
||||||
m_DeleteBut.setEnabled(true);
|
deleteButton.setEnabled(true);
|
||||||
m_ElementEditor.setValue(m_ElementList.getSelectedValue());
|
elementEditor.setValue(elementList.getSelectedValue());
|
||||||
if (m_View instanceof PropertyText) {
|
if (view instanceof PropertyText) {
|
||||||
((PropertyText) m_View).updateFromEditor();
|
((PropertyText) view).updateFromEditor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,26 +191,25 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
*/
|
*/
|
||||||
public GenericArrayEditor() {
|
public GenericArrayEditor() {
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
add(m_Label, BorderLayout.CENTER);
|
add(cantEditLabel, BorderLayout.CENTER);
|
||||||
m_DeleteBut.addActionListener(m_InnerActionListener);
|
deleteButton.addActionListener(innerActionListener);
|
||||||
m_AddBut.addActionListener(m_InnerActionListener);
|
addButton.addActionListener(innerActionListener);
|
||||||
m_SetAllBut.addActionListener(m_InnerActionListener);
|
setAllButton.addActionListener(innerActionListener);
|
||||||
m_SetBut.addActionListener(m_InnerActionListener);
|
setButton.addActionListener(innerActionListener);
|
||||||
m_ElementList.addListSelectionListener(m_InnerSelectionListener);
|
elementList.addListSelectionListener(innerSelectionListener);
|
||||||
m_AddBut.setToolTipText("Add the current item to the list");
|
addButton.setToolTipText("Add the current item to the list");
|
||||||
m_DeleteBut.setToolTipText("Delete the selected list item");
|
deleteButton.setToolTipText("Delete the selected list item");
|
||||||
m_ElementList.addMouseListener(new ActionJList(m_ElementList, this));
|
elementList.addMouseListener(new ActionJList(elementList, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getSelectedIndices() {
|
public int[] getSelectedIndices() {
|
||||||
return m_ElementList.getSelectedIndices();
|
return elementList.getSelectedIndices();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ActionJList extends MouseAdapter {
|
private class ActionJList extends MouseAdapter {
|
||||||
|
|
||||||
protected JList list;
|
protected JList list;
|
||||||
GenericArrayEditor gae = null;
|
GenericArrayEditor gae = null;
|
||||||
// PropertyPanel propPanel=null;
|
|
||||||
|
|
||||||
public ActionJList(JList l, GenericArrayEditor genAE) {
|
public ActionJList(JList l, GenericArrayEditor genAE) {
|
||||||
list = l;
|
list = l;
|
||||||
@ -226,7 +222,7 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
// Check if the index is valid and if the indexed cell really contains the clicked point
|
// Check if the index is valid and if the indexed cell really contains the clicked point
|
||||||
if (index >= 0 && (list.getCellBounds(index, index).contains(e.getPoint()))) {
|
if (index >= 0 && (list.getCellBounds(index, index).contains(e.getPoint()))) {
|
||||||
PropertyPanel propPanel = null;
|
PropertyPanel propPanel = null;
|
||||||
Component comp = gae.m_View;
|
Component comp = gae.view;
|
||||||
if (comp instanceof PropertyPanel) {
|
if (comp instanceof PropertyPanel) {
|
||||||
propPanel = (PropertyPanel) comp;
|
propPanel = (PropertyPanel) comp;
|
||||||
} else {
|
} else {
|
||||||
@ -251,11 +247,11 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
/**
|
/**
|
||||||
* The class of the property editor for array objects
|
* The class of the property editor for array objects
|
||||||
*/
|
*/
|
||||||
private Class m_EditorClass;
|
private Class editorClass;
|
||||||
/**
|
/**
|
||||||
* The class of the array values
|
* The class of the array values
|
||||||
*/
|
*/
|
||||||
private Class m_ValueClass;
|
private Class valueClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the list cell renderer.
|
* Creates the list cell renderer.
|
||||||
@ -264,8 +260,8 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
* @param valueClass The class of the array values
|
* @param valueClass The class of the array values
|
||||||
*/
|
*/
|
||||||
public EditorListCellRenderer(Class editorClass, Class valueClass) {
|
public EditorListCellRenderer(Class editorClass, Class valueClass) {
|
||||||
m_EditorClass = editorClass;
|
editorClass = editorClass;
|
||||||
m_ValueClass = valueClass;
|
valueClass = valueClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,10 +280,10 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
final boolean isSelected,
|
final boolean isSelected,
|
||||||
final boolean cellHasFocus) {
|
final boolean cellHasFocus) {
|
||||||
try {
|
try {
|
||||||
final PropertyEditor e = (PropertyEditor) m_EditorClass.newInstance();
|
final PropertyEditor e = (PropertyEditor) editorClass.newInstance();
|
||||||
if (e instanceof GenericObjectEditor) {
|
if (e instanceof GenericObjectEditor) {
|
||||||
// ((GenericObjectEditor) e).setDisplayOnly(true);
|
// ((GenericObjectEditor) e).setDisplayOnly(true);
|
||||||
((GenericObjectEditor) e).setClassType(m_ValueClass);
|
((GenericObjectEditor) e).setClassType(valueClass);
|
||||||
}
|
}
|
||||||
e.setValue(value);
|
e.setValue(value);
|
||||||
JPanel cellPanel = new JPanel() {
|
JPanel cellPanel = new JPanel() {
|
||||||
@ -327,9 +323,9 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
private void updateEditorType(Object obj) {
|
private void updateEditorType(Object obj) {
|
||||||
|
|
||||||
// Determine if the current object is an array
|
// Determine if the current object is an array
|
||||||
m_ElementEditor = null;
|
elementEditor = null;
|
||||||
m_ListModel = null;
|
listModel = null;
|
||||||
m_View = null;
|
view = null;
|
||||||
removeAll();
|
removeAll();
|
||||||
|
|
||||||
if ((obj != null) && (obj.getClass().isArray() || (obj instanceof PropertySelectableList))) {
|
if ((obj != null) && (obj.getClass().isArray() || (obj instanceof PropertySelectableList))) {
|
||||||
@ -345,7 +341,7 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
if (editor instanceof EnumEditor) {
|
if (editor instanceof EnumEditor) {
|
||||||
editor.setValue(obj);
|
editor.setValue(obj);
|
||||||
}
|
}
|
||||||
m_View = null;
|
view = null;
|
||||||
ListCellRenderer lcr = new DefaultListCellRenderer();
|
ListCellRenderer lcr = new DefaultListCellRenderer();
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
if (editor instanceof GenericObjectEditor) {
|
if (editor instanceof GenericObjectEditor) {
|
||||||
@ -353,67 +349,66 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
((GenericObjectEditor) editor).setClassType(elementClass);
|
((GenericObjectEditor) editor).setClassType(elementClass);
|
||||||
}
|
}
|
||||||
if (editor.isPaintable() && editor.supportsCustomEditor()) {
|
if (editor.isPaintable() && editor.supportsCustomEditor()) {
|
||||||
m_View = new PropertyPanel(editor);
|
view = new PropertyPanel(editor);
|
||||||
lcr = new EditorListCellRenderer(editor.getClass(), elementClass);
|
lcr = new EditorListCellRenderer(editor.getClass(), elementClass);
|
||||||
} else if (editor.getTags() != null) {
|
} else if (editor.getTags() != null) {
|
||||||
m_View = new PropertyValueSelector(editor);
|
view = new PropertyValueSelector(editor);
|
||||||
} else if (editor.getAsText() != null) {
|
} else if (editor.getAsText() != null) {
|
||||||
m_View = new PropertyText(editor);
|
view = new PropertyText(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_View == null) {
|
if (view == null) {
|
||||||
System.err.println("No property editor for class: "
|
LOGGER.log(Level.WARNING, "No property editor for class: {0}", elementClass.getName());
|
||||||
+ elementClass.getName());
|
|
||||||
} else {
|
} else {
|
||||||
m_ElementEditor = editor;
|
elementEditor = editor;
|
||||||
|
|
||||||
// Create the ListModel and populate it
|
// Create the ListModel and populate it
|
||||||
m_ListModel = new DefaultListModel();
|
listModel = new DefaultListModel();
|
||||||
m_ElementClass = elementClass;
|
elementClass = elementClass;
|
||||||
for (int i = 0; i < Array.getLength(arrayInstance); i++) {
|
for (int i = 0; i < Array.getLength(arrayInstance); i++) {
|
||||||
m_ListModel.addElement(Array.get(arrayInstance, i));
|
listModel.addElement(Array.get(arrayInstance, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ElementList.setCellRenderer(lcr);
|
elementList.setCellRenderer(lcr);
|
||||||
m_ElementList.setModel(m_ListModel);
|
elementList.setModel(listModel);
|
||||||
|
|
||||||
if (m_ListModel.getSize() > 0) {
|
if (listModel.getSize() > 0) {
|
||||||
m_ElementList.setSelectedIndex(0);
|
elementList.setSelectedIndex(0);
|
||||||
m_DeleteBut.setEnabled(true);
|
deleteButton.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
m_DeleteBut.setEnabled(false);
|
deleteButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (m_ListModel.getSize() > 0) {
|
if (listModel.getSize() > 0) {
|
||||||
m_ElementEditor.setValue(m_ListModel.getElementAt(0));
|
elementEditor.setValue(listModel.getElementAt(0));
|
||||||
} else {
|
} else {
|
||||||
if (m_ElementEditor instanceof GenericObjectEditor) {
|
if (elementEditor instanceof GenericObjectEditor) {
|
||||||
((GenericObjectEditor) m_ElementEditor).setDefaultValue();
|
((GenericObjectEditor) elementEditor).setDefaultValue();
|
||||||
} else {
|
} else {
|
||||||
if (m_ElementEditor.getValue() != null) {
|
if (elementEditor.getValue() != null) {
|
||||||
m_ElementEditor.setValue(m_ElementClass.newInstance());
|
elementEditor.setValue(elementClass.newInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//setPreferredSize(new Dimension(400,500));
|
//setPreferredSize(new Dimension(400,500));
|
||||||
|
|
||||||
if (withAddButton && !(m_AdditionalUpperButtonList.contains(m_AddBut))) {
|
if (withAddButton && !(upperButtonList.contains(addButton))) {
|
||||||
m_AdditionalUpperButtonList.add(m_AddBut);
|
upperButtonList.add(addButton);
|
||||||
}
|
}
|
||||||
if (withSetButton && !(m_AdditionalUpperButtonList.contains(m_SetBut))) {
|
if (withSetButton && !(upperButtonList.contains(setButton))) {
|
||||||
m_AdditionalUpperButtonList.add(m_SetBut);
|
upperButtonList.add(setButton);
|
||||||
}
|
}
|
||||||
if (withSetButton && !(m_AdditionalUpperButtonList.contains(m_SetAllBut))) {
|
if (withSetButton && !(upperButtonList.contains(setAllButton))) {
|
||||||
m_AdditionalUpperButtonList.add(m_SetAllBut);
|
upperButtonList.add(setAllButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upper Button Panel
|
// Upper Button Panel
|
||||||
JPanel combiUpperPanel = new JPanel(getButtonLayout(1, m_AdditionalUpperButtonList));
|
JPanel combiUpperPanel = new JPanel(getButtonLayout(1, upperButtonList));
|
||||||
combiUpperPanel.add(m_View);
|
combiUpperPanel.add(view);
|
||||||
|
|
||||||
for (JButton but : m_AdditionalUpperButtonList) {
|
for (JButton but : upperButtonList) {
|
||||||
combiUpperPanel.add(but);
|
combiUpperPanel.add(but);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,14 +425,14 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||||
gbConstraints.weightx = 1.0;
|
gbConstraints.weightx = 1.0;
|
||||||
gbConstraints.weighty = 1.0;
|
gbConstraints.weighty = 1.0;
|
||||||
add(new JScrollPane(m_ElementList), gbConstraints);
|
add(new JScrollPane(elementList), gbConstraints);
|
||||||
|
|
||||||
// Lower Button Panel
|
// Lower Button Panel
|
||||||
if (withDeleteButton && !m_AdditionalLowerButtonList.contains(m_DeleteBut)) {
|
if (withDeleteButton && !lowerButtonList.contains(deleteButton)) {
|
||||||
m_AdditionalLowerButtonList.add(m_DeleteBut);
|
lowerButtonList.add(deleteButton);
|
||||||
}
|
}
|
||||||
JPanel combiLowerPanel = new JPanel(getButtonLayout(0, m_AdditionalLowerButtonList));
|
JPanel combiLowerPanel = new JPanel(getButtonLayout(0, lowerButtonList));
|
||||||
for (JButton but : m_AdditionalLowerButtonList) {
|
for (JButton but : lowerButtonList) {
|
||||||
combiLowerPanel.add(but);
|
combiLowerPanel.add(but);
|
||||||
}
|
}
|
||||||
gbConstraints.gridy++;
|
gbConstraints.gridy++;
|
||||||
@ -455,9 +450,10 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
add(additionalCenterComp, gbConstraints);
|
add(additionalCenterComp, gbConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ElementEditor.addPropertyChangeListener(new PropertyChangeListener() {
|
elementEditor.addPropertyChangeListener(new PropertyChangeListener() {
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
@Override
|
||||||
|
public void propertyChange(final PropertyChangeEvent event) {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -466,14 +462,14 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println(ex.getMessage());
|
System.err.println(ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
m_ElementEditor = null;
|
elementEditor = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_ElementEditor == null) {
|
if (elementEditor == null) {
|
||||||
add(m_Label, BorderLayout.CENTER);
|
add(cantEditLabel, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
m_Support.firePropertyChange("", null, null);
|
propChangeSupport.firePropertyChange("", null, null);
|
||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,11 +488,11 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeUpperActionButton(String text) {
|
public void removeUpperActionButton(String text) {
|
||||||
removeActionButton(m_AdditionalUpperButtonList, text);
|
removeActionButton(upperButtonList, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeLowerActionButton(String text) {
|
public void removeLowerActionButton(String text) {
|
||||||
removeActionButton(m_AdditionalLowerButtonList, text);
|
removeActionButton(lowerButtonList, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeActionButton(List<JButton> bList, String text) {
|
protected void removeActionButton(List<JButton> bList, String text) {
|
||||||
@ -513,7 +509,7 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addUpperActionButton(String text, ActionListener al) {
|
public void addUpperActionButton(String text, ActionListener al) {
|
||||||
addActionButton(m_AdditionalUpperButtonList, text, al);
|
addActionButton(upperButtonList, text, al);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,7 +524,7 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (selectableList != null) {
|
if (selectableList != null) {
|
||||||
selectableList.setSelectionByIndices(m_ElementList.getSelectedIndices());
|
selectableList.setSelectionByIndices(elementList.getSelectedIndices());
|
||||||
}
|
}
|
||||||
al.actionPerformed(e);
|
al.actionPerformed(e);
|
||||||
}
|
}
|
||||||
@ -536,7 +532,7 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addLowerActionButton(String text, ActionListener al) {
|
public void addLowerActionButton(String text, ActionListener al) {
|
||||||
addActionButton(m_AdditionalLowerButtonList, text, al);
|
addActionButton(lowerButtonList, text, al);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addActionButton(List<JButton> bList, String text, ActionListener al) {
|
public void addActionButton(List<JButton> bList, String text, ActionListener al) {
|
||||||
@ -560,15 +556,15 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
*/
|
*/
|
||||||
public void selectDeselectAll() {
|
public void selectDeselectAll() {
|
||||||
if (areAllSelected()) {
|
if (areAllSelected()) {
|
||||||
m_ElementList.getSelectionModel().clearSelection();
|
elementList.getSelectionModel().clearSelection();
|
||||||
} else {
|
} else {
|
||||||
m_ElementList.setSelectionInterval(0, m_ElementList.getModel().getSize() - 1);
|
elementList.setSelectionInterval(0, elementList.getModel().getSize() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean areAllSelected() {
|
public boolean areAllSelected() {
|
||||||
for (int i = 0; i < m_ElementList.getModel().getSize(); i++) {
|
for (int i = 0; i < elementList.getModel().getSize(); i++) {
|
||||||
if (!m_ElementList.isSelectedIndex(i)) {
|
if (!elementList.isSelectedIndex(i)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -581,17 +577,17 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
* @return the current object array
|
* @return the current object array
|
||||||
*/
|
*/
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
if (m_ListModel == null) {
|
if (listModel == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (selectableList != null) {
|
if (selectableList != null) {
|
||||||
return selectableList;
|
return selectableList;
|
||||||
} else {
|
} else {
|
||||||
// Convert the listmodel to an array of strings and return it.
|
// Convert the listmodel to an array of strings and return it.
|
||||||
int length = m_ListModel.getSize();
|
int length = listModel.getSize();
|
||||||
Object result = Array.newInstance(m_ElementClass, length);
|
Object result = Array.newInstance(elementClass, length);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Array.set(result, i, m_ListModel.elementAt(i));
|
Array.set(result, i, listModel.elementAt(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -604,11 +600,11 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
|
|
||||||
public void addPopupMenu() {
|
public void addPopupMenu() {
|
||||||
if (m_popupItemList.size() > 0) {
|
if (m_popupItemList.size() > 0) {
|
||||||
m_ElementList.addMouseListener(new MouseAdapter() {
|
elementList.addMouseListener(new MouseAdapter() {
|
||||||
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if (selectableList != null) {
|
if (selectableList != null) {
|
||||||
selectableList.setSelectionByIndices(m_ElementList.getSelectedIndices());
|
selectableList.setSelectionByIndices(elementList.getSelectedIndices());
|
||||||
}
|
}
|
||||||
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
|
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
|
||||||
// do nothing
|
// do nothing
|
||||||
@ -674,11 +670,11 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
int vpad = (box.height - fm.getAscent()) / 2;
|
int vpad = (box.height - fm.getAscent()) / 2;
|
||||||
// System.out.println(m_ListModel + " --- " + m_ElementClass);
|
// System.out.println(m_ListModel + " --- " + m_ElementClass);
|
||||||
String rep;
|
String rep;
|
||||||
if (m_ListModel.getSize() == 0) {
|
if (listModel.getSize() == 0) {
|
||||||
rep = "Empty";
|
rep = "Empty";
|
||||||
} else {
|
} else {
|
||||||
rep = m_ListModel.getSize() + " of " + EVAHELP.cutClassName(m_ElementClass.getName());
|
rep = listModel.getSize() + " of " + EVAHELP.cutClassName(elementClass.getName());
|
||||||
Object maybeName = BeanInspector.callIfAvailable(m_ListModel.get(0), "getName", new Object[]{});
|
Object maybeName = BeanInspector.callIfAvailable(listModel.get(0), "getName", new Object[]{});
|
||||||
if (maybeName != null) {
|
if (maybeName != null) {
|
||||||
rep = rep + " (" + (String) maybeName + "...)";
|
rep = rep + " (" + (String) maybeName + "...)";
|
||||||
}
|
}
|
||||||
@ -722,17 +718,17 @@ public class GenericArrayEditor extends JPanel implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||||
if (m_Support == null) {
|
if (propChangeSupport == null) {
|
||||||
m_Support = new PropertyChangeSupport(this);
|
propChangeSupport = new PropertyChangeSupport(this);
|
||||||
}
|
}
|
||||||
m_Support.addPropertyChangeListener(l);
|
propChangeSupport.addPropertyChangeListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||||
if (m_Support == null) {
|
if (propChangeSupport == null) {
|
||||||
m_Support = new PropertyChangeSupport(this);
|
propChangeSupport = new PropertyChangeSupport(this);
|
||||||
}
|
}
|
||||||
m_Support.removePropertyChangeListener(l);
|
propChangeSupport.removePropertyChangeListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithAddButton() {
|
public boolean isWithAddButton() {
|
||||||
|
4
src/eva2/package-info.java
Normal file
4
src/eva2/package-info.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* Base package of the project that contains globally important classes.
|
||||||
|
*/
|
||||||
|
package eva2;
|
Loading…
x
Reference in New Issue
Block a user