From b086f57f56bf0eb9dab9cf321a0f69aaaae84347 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 May 2012 08:37:45 +0200 Subject: Initial Maven Conversion --- .../tabs/outcome/form/field/ArrayEditField.java | 173 -------------- .../tabs/outcome/form/field/ArrayTableModel.java | 113 --------- .../tabs/outcome/form/field/BooleanEditField.java | 75 ------ .../gui/tabs/outcome/form/field/ComboField.java | 144 ------------ .../tabs/outcome/form/field/DecimalEditField.java | 122 ---------- .../tabs/outcome/form/field/ImageEditField.java | 112 --------- .../tabs/outcome/form/field/IntegerEditField.java | 120 ---------- .../gui/tabs/outcome/form/field/ListOfValues.java | 31 --- .../outcome/form/field/LongStringEditField.java | 40 ---- .../tabs/outcome/form/field/StringEditField.java | 257 --------------------- 10 files changed, 1187 deletions(-) delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/ArrayEditField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/ArrayTableModel.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/BooleanEditField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/ComboField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/ImageEditField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/ListOfValues.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/LongStringEditField.java delete mode 100644 source/com/c2kernel/gui/tabs/outcome/form/field/StringEditField.java (limited to 'source/com/c2kernel/gui/tabs/outcome/form/field') diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/ArrayEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/ArrayEditField.java deleted file mode 100644 index 742d1b4..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/ArrayEditField.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.Box; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.text.JTextComponent; - -import org.exolab.castor.xml.schema.SimpleType; - -import com.c2kernel.utils.Language; - -/************************************************************************** - * - * $Revision: 1.7 $ - * $Date: 2006/05/24 07:51:51 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ - -public class ArrayEditField extends StringEditField implements ActionListener { - - Box arrayBox; - Box expandBox; - Box editBox; - JScrollPane arrayView; - JButton arrayButton; - JButton expandButton; - JButton contractButton; - JButton addButton; - JButton removeButton; - ArrayTableModel arrayModel; - JLabel arrayLabel = new JLabel("Array"); - boolean panelShown = false; - boolean readOnly = false; - - public ArrayEditField(SimpleType type) { - arrayBox = Box.createVerticalBox(); - arrayBox.add(arrayLabel); - arrayButton = new JButton(Language.translate("Show")); - arrayButton.addActionListener(this); - arrayButton.setActionCommand("toggle"); - arrayBox.add(arrayButton); - - expandBox = Box.createHorizontalBox(); - expandButton = new JButton(">>"); - expandButton.setToolTipText("Increase the number of columns displaying this array"); - expandButton.addActionListener(this); - expandButton.setActionCommand("extend"); - - contractButton = new JButton("<<"); - contractButton.setToolTipText("Decrease the number of columns displaying this array"); - contractButton.addActionListener(this); - contractButton.setActionCommand("contract"); - - expandBox.add(contractButton); - expandBox.add(Box.createHorizontalGlue()); - expandBox.add(expandButton); - - arrayModel = new ArrayTableModel(type); - if (arrayModel.getColumnCount() < 2) contractButton.setEnabled(false); - arrayView = new JScrollPane(new JTable(arrayModel)); - - editBox = Box.createHorizontalBox(); - addButton = new JButton("+"); - addButton.setToolTipText("Add a field to the end of this array"); - addButton.addActionListener(this); - addButton.setActionCommand("add"); - removeButton = new JButton("-"); - removeButton.setToolTipText("Remove the last field from this array"); - removeButton.addActionListener(this); - removeButton.setActionCommand("remove"); - editBox.add(addButton); - editBox.add(Box.createHorizontalGlue()); - editBox.add(removeButton); - } - /** - * - */ - @Override - public String getDefaultValue() { - return ""; - } - /** - * - */ - @Override - public String getText() { - return arrayModel.getData(); - } - /** - * - */ - @Override - public void setText(String text) { - arrayModel.setData(text); - arrayLabel.setText("Array ("+arrayModel.getArrayLength()+" values)"); - } - /** - * - */ - @Override - public Component getControl() { - return arrayBox; - } - /** - * - */ - @Override - public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals("toggle")) { - arrayBox.removeAll(); - if (panelShown) { - arrayBox.add(arrayLabel); - arrayBox.add(Box.createVerticalStrut(7)); - arrayBox.add(arrayButton); - arrayButton.setText("Show"); - } - else { - arrayBox.add(arrayLabel); - arrayBox.add(Box.createVerticalStrut(7)); - arrayBox.add(arrayButton); - arrayBox.add(Box.createVerticalStrut(7)); - arrayBox.add(expandBox); - arrayBox.add(Box.createVerticalStrut(7)); - arrayBox.add(arrayView); - if (!readOnly) arrayBox.add(editBox); - arrayButton.setText("Hide"); - } - panelShown = !panelShown; - arrayBox.validate(); - } - else if (e.getActionCommand().equals("add")) { - arrayModel.addField(); - arrayLabel.setText("Array ("+arrayModel.getArrayLength()+" values)"); - } - else if (e.getActionCommand().equals("remove")) { - arrayModel.removeField(); - arrayLabel.setText("Array ("+arrayModel.getArrayLength()+" values)"); - } - else { - int currentCols = arrayModel.getColumnCount(); - if (e.getActionCommand().equals("extend")) - currentCols++; - else if (e.getActionCommand().equals("contract")) - currentCols--; - arrayModel.setColumnCount(currentCols); - contractButton.setEnabled(currentCols > 1); - } - - } - - /** - * - */ - @Override - public JTextComponent makeTextField() { - // not used by array - return null; - } - @Override - public void setEditable(boolean editable) { - readOnly = !editable; - arrayModel.setReadOnly(!readOnly); - } - -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/ArrayTableModel.java b/source/com/c2kernel/gui/tabs/outcome/form/field/ArrayTableModel.java deleted file mode 100644 index 341c33a..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/ArrayTableModel.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.StringTokenizer; - -import javax.swing.table.AbstractTableModel; - -import org.exolab.castor.xml.schema.SimpleType; - -import com.c2kernel.gui.tabs.outcome.form.OutcomeStructure; -import com.c2kernel.utils.Language; - -/************************************************************************** - * - * $Revision: 1.2 $ - * $Date: 2006/05/24 07:51:53 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ - -public class ArrayTableModel extends AbstractTableModel { - - ArrayList contents = new ArrayList(); - Class type; - int numCols = 1; - boolean readOnly = false; - - public ArrayTableModel(SimpleType type) { - super(); - this.type = OutcomeStructure.getJavaClass(type.getTypeCode()); - } - - public void setReadOnly(boolean readOnly) { - this.readOnly = readOnly; - } - - public void setData(String data) { - contents.clear(); - StringTokenizer tok = new StringTokenizer(data); - while(tok.hasMoreTokens()) - contents.add(OutcomeStructure.getTypedValue(tok.nextToken(), type)); - fireTableStructureChanged(); - } - - public String getData() { - if (contents.size() == 0) return ""; - Iterator iter = contents.iterator(); - StringBuffer result = new StringBuffer(iter.next().toString()); - while (iter.hasNext()) - result.append(" ").append(iter.next().toString()); - return result.toString(); - } - - public void addField() { - contents.add(OutcomeStructure.getTypedValue("", type)); - fireTableStructureChanged(); - } - - public void removeField() { - contents.remove(contents.size()-1); - fireTableStructureChanged(); - } - - @Override - public Class getColumnClass(int columnIndex) { - return type; - } - - @Override - public int getColumnCount() { - return numCols; - } - - public int getArrayLength() { - return contents.size(); - } - - public void setColumnCount(int newCols) { - numCols = newCols; - fireTableStructureChanged(); - } - - @Override - public String getColumnName(int column) { - return Language.translate("Value"); - } - - @Override - public int getRowCount() { - return (contents.size()/numCols)+1; - } - - @Override - public Object getValueAt(int arg0, int arg1) { - int index = arg1+(arg0 * numCols); - if (index >= contents.size()) - return null; - return contents.get(arg1+(arg0 * numCols)); - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - if (columnIndex+(rowIndex*numCols) > contents.size()-1) return false; - return !readOnly; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - contents.set(columnIndex+(rowIndex*numCols), aValue); - } -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/BooleanEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/BooleanEditField.java deleted file mode 100644 index c831eb4..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/BooleanEditField.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Component; -import java.awt.event.FocusEvent; - -import javax.swing.JCheckBox; -import javax.swing.text.JTextComponent; - -import com.c2kernel.utils.Logger; - -/************************************************************************** - * - * $Revision: 1.7 $ - * $Date: 2005/08/16 13:59:56 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ -public class BooleanEditField extends StringEditField { - - JCheckBox checkbox; - - public BooleanEditField() { - checkbox = new JCheckBox(); - checkbox.setSelected(false); - checkbox.addFocusListener(this); - } - - @Override - public String getText() { - return String.valueOf(checkbox.isSelected()); - } - - @Override - public void setText(String text) { - boolean newState = false; - try { - newState = Boolean.valueOf(text).booleanValue(); - } catch (Exception ex) { - Logger.error("Invalid value for checkbox: "+text); - } - checkbox.setSelected(newState); - } - - @Override - public void setEditable(boolean editable) { - super.setEditable(editable); - checkbox.setEnabled(editable); - } - - @Override - public Component getControl() { - return checkbox; - } - - @Override - public String getDefaultValue() { - return "false"; - } - - /** don't reserve the item finder for a boolean */ - @Override - public void focusGained(FocusEvent e) { - helpPane.setHelp(name, helpText); - } - - /** - * - */ - @Override - public JTextComponent makeTextField() { - // not used by boolean - return null; - } -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/ComboField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/ComboField.java deleted file mode 100644 index 2c4ce05..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/ComboField.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Component; -import java.util.Enumeration; -import java.util.StringTokenizer; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.text.JTextComponent; - -import org.exolab.castor.types.AnyNode; -import org.exolab.castor.xml.schema.AttributeDecl; -import org.exolab.castor.xml.schema.ElementDecl; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; - -import com.c2kernel.gui.tabs.outcome.form.StructuralException; -import com.c2kernel.scripting.Script; -import com.c2kernel.utils.Logger; - -/******************************************************************************* - * - * $Revision: 1.4 $ $Date: 2005/08/16 13:59:56 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research All - * rights reserved. - ******************************************************************************/ - -public class ComboField extends StringEditField { - - JComboBox comboField; - ListOfValues vals; - DefaultComboBoxModel comboModel; - AnyNode listNode; - - public ComboField(SimpleType type, AnyNode listNode) { - super(); - comboField = new JComboBox(); - content = type; - this.listNode = listNode; - createLOV(); - } - - @Override - public String getDefaultValue() { - if (vals.getDefaultKey() != null) - return vals.get(vals.getDefaultKey()).toString(); - else - return ""; - } - - @Override - public String getText() { - return vals.get(comboModel.getSelectedItem()).toString(); - } - - @Override - public JTextComponent makeTextField() { - // not used by this control - return null; - } - - @Override - public void setText(String text) { - comboModel.setSelectedItem(text); - } - - @Override - public Component getControl() { - return comboField; - } - - private void createLOV() { - vals = new ListOfValues(); - - if (listNode != null) { // schema instructions for list building - String lovType = listNode.getLocalName(); - String param = listNode.getFirstChild().getStringValue(); - if (lovType.equals("ScriptList")) - populateLOVFromScript(param); - if (lovType.equals("PathList")) - populateLOVFromLDAP(param); - } - - // handle enumerations - // TODO: should be ANDed with above results - if (content.hasFacet(Facet.ENUMERATION)) { - //ListOfValues andList = new ListOfValues(); - Enumeration enums = content.getFacets(Facet.ENUMERATION); - while (enums.hasMoreElements()) { - Facet thisEnum = enums.nextElement(); - vals.put(thisEnum.getValue(), thisEnum.getValue(), false); - } - } - - String[] keyArray = new String[vals.keySet().size()]; - comboModel = new DefaultComboBoxModel(vals.keySet().toArray(keyArray)); - comboModel.setSelectedItem(vals.getDefaultKey()); - comboField.setModel(comboModel); - } - - /** - * @param param - */ - private void populateLOVFromLDAP(String param) { - // TODO List of Values from LDAP properties, eg '/root/path;prop=val;prop=val' - - - } - - private void populateLOVFromScript(String scriptName) { - try { - StringTokenizer tok = new StringTokenizer(scriptName, "_"); - if (tok.countTokens() != 2) - throw new Exception("Invalid LOVScript name"); - Script lovscript = new Script(tok.nextToken(), Integer.parseInt(tok.nextToken())); - lovscript.setInputParamValue("LOV", vals); - lovscript.execute(); - } catch (Exception ex) { - Logger.exceptionDialog(ex); - } - } - - @Override - public void setDecl(AttributeDecl model) throws StructuralException { - super.setDecl(model); - createLOV(); - } - - @Override - public void setDecl(ElementDecl model) throws StructuralException { - super.setDecl(model); - createLOV(); - } - - /** - * - */ - - @Override - public void setEditable(boolean editable) { - comboField.setEditable(editable); - } -} \ No newline at end of file diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java deleted file mode 100644 index fabaed8..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Toolkit; -import java.math.BigDecimal; - -import javax.swing.JTextField; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.PlainDocument; - -/************************************************************************** - * - * $Revision: 1.3 $ - * $Date: 2005/08/16 13:59:56 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ -public class DecimalEditField extends StringEditField { - - public DecimalEditField() { - super(); - field.addFocusListener(this); - field.setToolTipText("This field must contains a decimal number e.g. 3.14159265"); - } - - @Override - public String getText() { - return field.getText(); - } - - @Override - public void setText(String text) { - field.setText(text); - } - - @Override - public String getDefaultValue() { - return "0.0"; - } - - @Override - public JTextComponent makeTextField() { - return new DecimalTextField(); - } - - private class DecimalTextField extends JTextField { - - public DecimalTextField() { - super(); - setHorizontalAlignment(RIGHT); - } - @Override - protected Document createDefaultModel() { - return new Decimal(); - } - } - - private class Decimal extends PlainDocument { - - BigDecimal currentVal = new BigDecimal(0.0); - - - @Override - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - - if (str == null || str.equals("")) { - return; - } - - String proposedResult = null; - - if (getLength() == 0) { - proposedResult = str; - } else { - StringBuffer currentBuffer = new StringBuffer( this.getText(0, getLength()) ); - currentBuffer.insert(offs, str); - proposedResult = currentBuffer.toString(); - } - - try { - currentVal = parse(proposedResult); - super.insertString(offs, str, a); - } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); - } - - } - - @Override - public void remove(int offs, int len) throws BadLocationException { - - String currentText = this.getText(0, getLength()); - String beforeOffset = currentText.substring(0, offs); - String afterOffset = currentText.substring(len + offs, currentText.length()); - String proposedResult = beforeOffset + afterOffset; - - if (proposedResult.length() == 0) { // empty is ok - super.remove(offs, len); - return; - } - try { - currentVal = parse(proposedResult); - super.remove(offs, len); - } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); - } - - } - - public BigDecimal parse(String proposedResult) throws NumberFormatException { - - BigDecimal value = new BigDecimal(0); - if ( proposedResult.length() != 0) { - value = new BigDecimal(proposedResult); - } - return value; - } - } -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/ImageEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/ImageEditField.java deleted file mode 100644 index 716a073..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/ImageEditField.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Component; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.FileInputStream; -import java.lang.reflect.Array; - -import javax.swing.Box; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JLabel; - -import org.apache.xerces.impl.dv.util.Base64; - -import com.c2kernel.utils.Logger; - -public class ImageEditField extends StringEditField { - - JLabel imageLabel; - - Box imagePanel; - - JButton browseButton; - - String encodedImage; - - static JFileChooser chooser = new JFileChooser(); - static { - chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { - @Override - public String getDescription() { - return "Image Files"; - } - - @Override - public boolean accept(File f) { - return (f.isDirectory() || (f.isFile() && (f.getName() - .endsWith(".gif") - || f.getName().endsWith(".jpg") - || f.getName().endsWith(".jpeg") - || f.getName().endsWith(".png")))); - } - }); - } - - public ImageEditField() { - super(); - imageLabel = new JLabel(); - imagePanel = Box.createVerticalBox(); - browseButton = new JButton("Browse"); - browseButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - int returnVal = chooser.showOpenDialog(null); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = chooser.getSelectedFile(); - try { - FileInputStream fis = new FileInputStream(file); - byte[] bArray = (byte[]) Array.newInstance(byte.class, - (int) file.length()); - fis.read(bArray, 0, (int) file.length()); - fis.close(); - - ImageIcon newImage = new ImageIcon(Toolkit - .getDefaultToolkit().createImage(bArray)); - imageLabel.setIcon(newImage); - encodedImage = Base64.encode(bArray); - } catch (Exception ex) { - Logger.exceptionDialog(ex); - } - } - } - }); - imagePanel.add(imageLabel); - imagePanel.add(Box.createVerticalStrut(5)); - imagePanel.add(browseButton); - } - - @Override - public String getDefaultValue() { - return ""; - } - - @Override - public Component getControl() { - return imagePanel; - } - - @Override - public String getText() { - return encodedImage == null ? "" : encodedImage; - } - - @Override - public void setText(String text) { - encodedImage = text; - if (text != null && text.length() > 0) { - byte[] decodedImage = Base64.decode(encodedImage); - imageLabel.setIcon(new ImageIcon(Toolkit.getDefaultToolkit() - .createImage(decodedImage))); - } - } - - @Override - public void setEditable(boolean editable) { - browseButton.setVisible(false); - } -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java deleted file mode 100644 index e2c3df4..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Toolkit; -import java.math.BigInteger; - -import javax.swing.JTextField; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.PlainDocument; - -/************************************************************************** - * - * $Revision: 1.4 $ - * $Date: 2005/08/16 13:59:56 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ -public class IntegerEditField extends StringEditField { - - public IntegerEditField() { - super(); - field.setToolTipText("This field must contains a whole number e.g. 3"); - } - - @Override - public String getText() { - return field.getText(); - } - - @Override - public void setText(String text) { - field.setText(text); - } - - @Override - public String getDefaultValue() { - return "0"; - } - - @Override - public JTextComponent makeTextField() { - return new IntegerTextField(); - } - - private class IntegerTextField extends JTextField { - - public IntegerTextField() { - super(); - setHorizontalAlignment(RIGHT); - } - @Override - protected Document createDefaultModel() { - return new IntegerDocument(); - } - } - - private class IntegerDocument extends PlainDocument { - - BigInteger currentVal = new BigInteger("0"); - - @Override - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - - if (str == null || str.equals("")) { - return; - } - - String proposedResult = null; - - if (getLength() == 0) { - proposedResult = str; - } else { - StringBuffer currentBuffer = new StringBuffer( this.getText(0, getLength()) ); - currentBuffer.insert(offs, str); - proposedResult = currentBuffer.toString(); - } - - try { - currentVal = parse(proposedResult); - super.insertString(offs, str, a); - } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); - } - - } - - @Override - public void remove(int offs, int len) throws BadLocationException { - - String currentText = this.getText(0, getLength()); - String beforeOffset = currentText.substring(0, offs); - String afterOffset = currentText.substring(len + offs, currentText.length()); - String proposedResult = beforeOffset + afterOffset; - if (proposedResult.length() == 0) { // empty is ok - super.remove(offs, len); - return; - } - - try { - currentVal = parse(proposedResult); - super.remove(offs, len); - } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); - } - - } - - public BigInteger parse(String proposedResult) throws NumberFormatException { - - BigInteger value = new BigInteger("0"); - if ( proposedResult.length() != 0) { - value = new BigInteger(proposedResult); - } - return value; - } - } -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/ListOfValues.java b/source/com/c2kernel/gui/tabs/outcome/form/field/ListOfValues.java deleted file mode 100644 index f95c5c9..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/ListOfValues.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.util.HashMap; - -/************************************************************************** - * - * $Revision: 1.2 $ - * $Date: 2005/04/26 06:48:12 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ - -public class ListOfValues extends HashMap { - - String defaultKey = null; - - public ListOfValues() { - super(); - } - - public String put(String key, String value, boolean isDefaultKey) { - if (isDefaultKey) defaultKey = key; - return (String)super.put(key, value); - } - - public String getDefaultKey() { - return defaultKey; - } - -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/LongStringEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/LongStringEditField.java deleted file mode 100644 index 140d7f2..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/LongStringEditField.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; - -import java.awt.Component; - -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.text.JTextComponent; - -import com.c2kernel.utils.Language; - - -/************************************************************************** - * - * $Revision$ - * $Date$ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ -public class LongStringEditField extends StringEditField { - - JTextArea bigText; - JScrollPane bigScroller; - public LongStringEditField() { - super(); - field.setToolTipText(Language.translate("This field can contain any string.")); - } - - @Override - public JTextComponent makeTextField() { - return new JTextArea(); - } - @Override - public Component getControl() { - if (bigScroller == null) { - bigScroller = new JScrollPane(field); - } - return bigScroller; - } -} diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/StringEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/StringEditField.java deleted file mode 100644 index 0e5fee9..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/StringEditField.java +++ /dev/null @@ -1,257 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field; -import java.awt.Component; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Enumeration; - -import javax.swing.ImageIcon; -import javax.swing.JTextField; -import javax.swing.text.JTextComponent; - -import org.exolab.castor.types.AnyNode; -import org.exolab.castor.xml.schema.Annotation; -import org.exolab.castor.xml.schema.AppInfo; -import org.exolab.castor.xml.schema.AttributeDecl; -import org.exolab.castor.xml.schema.ElementDecl; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; -import org.exolab.castor.xml.schema.Structure; -import org.exolab.castor.xml.schema.XMLType; -import org.exolab.castor.xml.schema.simpletypes.ListType; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - -import com.c2kernel.gui.DomainKeyConsumer; -import com.c2kernel.gui.MainFrame; -import com.c2kernel.gui.tabs.outcome.OutcomeException; -import com.c2kernel.gui.tabs.outcome.form.HelpPane; -import com.c2kernel.gui.tabs.outcome.form.OutcomeStructure; -import com.c2kernel.gui.tabs.outcome.form.StructuralException; -import com.c2kernel.lookup.DomainPath; - -/** Superclass for the entry field for Field and AttributeList. - */ -public class StringEditField implements FocusListener, DomainKeyConsumer { - - Node data; - Structure model; - protected SimpleType content; - HelpPane helpPane; - String helpText; - protected JTextComponent field; - - boolean isValid = true; - boolean editable = true; - String name; - - - public StringEditField() { - field = makeTextField(); - if (field != null) - field.addFocusListener(this); - } - - private static StringEditField getFieldForType(SimpleType type) { - // handle lists special - if (type instanceof ListType) - return new ArrayEditField(type.getBuiltInBaseType()); - - // is a combobox - if (type.hasFacet(Facet.ENUMERATION)) - return new ComboField(type, null); - //find LOVscript TODO: Implement LOV - Enumeration e = type.getAnnotations(); - while (e.hasMoreElements()) { - Annotation note = e.nextElement(); - for (Enumeration f = note.getAppInfo(); f.hasMoreElements();) { - AppInfo thisAppInfo = f.nextElement(); - for (Enumeration g = thisAppInfo.getObjects(); g.hasMoreElements();) { - AnyNode appInfoNode = (AnyNode)g.nextElement(); - if (appInfoNode.getLocalName().equals("ScriptList") - || appInfoNode.getLocalName().equals("LDAPList")) { - return new ComboField(type, appInfoNode); - } - } - } - } - // find info on length before we go to the base type - long length = -1; - if (type.getLength()!=null) length = type.getLength().longValue(); - else if (type.getMaxLength()!=null) length = type.getMaxLength().longValue(); - else if (type.getMinLength()!=null) length = type.getMinLength().longValue(); - - // find base type if derived - if (!(type.isBuiltInType())) - type = type.getBuiltInBaseType(); - // else derive the class - Class contentClass = OutcomeStructure.getJavaClass(type.getTypeCode()); - // disable list edits for the moment - if (contentClass.equals(Boolean.class)) - return new BooleanEditField(); - else if (contentClass.equals(BigInteger.class)) - return new IntegerEditField(); - else if (contentClass.equals(BigDecimal.class)) - return new DecimalEditField(); - else if (contentClass.equals(ImageIcon.class)) - return new ImageEditField(); - else if (length > 60) - return new LongStringEditField(); - else return new StringEditField(); - } - - public static StringEditField getEditField(AttributeDecl model) throws StructuralException { - if (model.isReference()) model = model.getReference(); - StringEditField newField = getFieldForType(model.getSimpleType()); - newField.setDecl(model); - return newField; - } - - public static StringEditField getEditField(ElementDecl model) throws StructuralException { - try { - XMLType baseType = model.getType(); - while (!(baseType instanceof SimpleType)) - baseType = baseType.getBaseType(); - StringEditField newField = getFieldForType((SimpleType)baseType); - newField.setDecl(model); - return newField; - } catch (Exception ex) { - throw new StructuralException("No type defined in model"); - } - } - - public void setDecl(AttributeDecl model) throws StructuralException { - this.model=model; - this.content=model.getSimpleType(); - this.name = model.getName(); - if (model.isFixed()) setEditable(false); - } - - public void setDecl(ElementDecl model) throws StructuralException { - this.model=model; - this.name = model.getName(); - XMLType type = model.getType(); - - // derive base type - if (type.isSimpleType()) - this.content = (SimpleType)type; - else - this.content = (SimpleType)(type.getBaseType()); - - if (this.content == null) throw new StructuralException("No declared base type of element"); - - // - if (model.getFixedValue() != null) setEditable(false); - - } - - public void setData(Attr newData) throws StructuralException { - if (!(newData.getName().equals(name))) - throw new StructuralException("Tried to add a "+newData.getName()+" into a "+name+" attribute."); - - this.data = newData; - setText(newData.getValue()); - } - - public void setData(Text newData) { - String contents = newData.getData(); - this.data = newData; - setText(contents); - } - - public void setData(String newData) throws OutcomeException { - if (data == null) throw new OutcomeException("No node exists"); - setText(newData); - updateNode(); - - } - - public Structure getModel() { - return model; - } - - public String getName() { - return name; - } - - public Node getData() { - return data; - } - - public String getDefaultValue() { - return ""; - } - - public void setHelp(HelpPane helpPane, String helpText) { - this.helpPane = helpPane; - this.helpText = helpText; - } - - @Override - public void focusLost(FocusEvent e) { - if (MainFrame.itemFinder != null) - MainFrame.itemFinder.clearConsumer(this); - updateNode(); - } - - @Override - public void focusGained(FocusEvent e) { - helpPane.setHelp(name, helpText); - if (editable && MainFrame.itemFinder != null) - MainFrame.itemFinder.setConsumer(this, "Insert"); - } - - public void updateNode() { - if (data == null) return; - if (data instanceof Text) { - ((Text)data).setData(getText()); - } - else { //attribute - ((Attr)data).setValue(getText()); - } - } - - /** - * Read domkey from barcode input - */ - @Override - public void push(DomainPath key) { - setText(key.getName()); - } - - /** - * Read string from barcode input - */ - @Override - public void push(String key) { - setText(key); - } - - public void setEditable(boolean editable) { - this.editable = editable; - if (field != null) - field.setEditable(editable); - } - - public String getText() { - return field.getText(); - } - - public void setText(String text) { - field.setText(text); - } - - public JTextComponent makeTextField() { - return new JTextField(); - } - - public Component getControl() { - return field; - } - - public void grabFocus() { - getControl().requestFocus(); - } -} -- cgit v1.2.3