basic slit in multi module project
This commit is contained in:
parent
f79378dacb
commit
d6d77072d9
198 changed files with 25404 additions and 0 deletions
10
vasc-frontend-swing/.classpath
Normal file
10
vasc-frontend-swing/.classpath
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
vasc-frontend-swing/.project
Normal file
23
vasc-frontend-swing/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-frontend-swing</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
6
vasc-frontend-swing/.settings/org.eclipse.jdt.core.prefs
Normal file
6
vasc-frontend-swing/.settings/org.eclipse.jdt.core.prefs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#Mon Aug 30 21:56:01 CEST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#Mon Aug 30 21:56:00 CEST 2010
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
||||
32
vasc-frontend-swing/pom.xml
Normal file
32
vasc-frontend-swing/pom.xml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>vasc-base</artifactId>
|
||||
<groupId>com.idcanet.vasc</groupId>
|
||||
<version>0.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.idcanet.vasc</groupId>
|
||||
<artifactId>vasc-frontend-swing</artifactId>
|
||||
<version>0.3-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.idcanet.vasc</groupId>
|
||||
<artifactId>vasc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- FFF depency
|
||||
<dependency>
|
||||
<groupId>com.idcanet.fff</groupId>
|
||||
<artifactId>fff-main</artifactId>
|
||||
<version>0.8-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- Swing date editor depency -->
|
||||
<dependency>
|
||||
<groupId>com.michaelbaranov</groupId>
|
||||
<artifactId>microba</artifactId>
|
||||
<version>0.4.4.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,842 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.Spring;
|
||||
import javax.swing.SpringLayout;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascFrontend;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascFrontendData;
|
||||
import com.idcanet.vasc.core.actions.GlobalVascAction;
|
||||
import com.idcanet.vasc.core.actions.RowVascAction;
|
||||
import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener;
|
||||
import com.idcanet.vasc.core.entry.VascEntryExporter;
|
||||
import com.idcanet.vasc.core.ui.VascColumnValueModelListener;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingBoolean;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingButton;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingColorChooser;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingLabel;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingList;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingText;
|
||||
import com.idcanet.vasc.frontends.swing.ui.SwingTextArea;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2007
|
||||
*/
|
||||
public class SwingVascFrontend extends AbstractVascFrontend {
|
||||
|
||||
private Logger logger = null;
|
||||
private JComponent parent = null;
|
||||
|
||||
public SwingVascFrontend(JComponent parent) {
|
||||
logger = Logger.getLogger(SwingVascFrontend.class.getName());
|
||||
this.parent=parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add swing implmented ui components
|
||||
*/
|
||||
protected void addUiComponents() {
|
||||
VascFrontendData vfd = getVascEntry().getVascFrontendData();
|
||||
|
||||
// required UI components
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwingLabel.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwingText.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwingList.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwingButton.class.getName());
|
||||
|
||||
// optional UI components
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwingBoolean.class.getName());
|
||||
//vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwingDate.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwingTextArea.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwingColorChooser.class.getName());
|
||||
}
|
||||
|
||||
public ImageIcon getImageIcon(String imageResource) {
|
||||
/// TODO hack beter
|
||||
String key = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(imageResource);
|
||||
//logger.fine("KEY======================="+key);
|
||||
|
||||
if (key.startsWith("vasc.entry")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (key.indexOf("META-INF")>0 | key.indexOf("resource")>0) {
|
||||
return null;
|
||||
//return SwingImageHelper.getImageIcon(key);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascViewRenderer#renderEdit(com.idcanet.vasc.core.VascEntry, java.lang.Object)
|
||||
*/
|
||||
public void renderEdit() throws Exception {
|
||||
logger.fine("Rending Edit View");
|
||||
|
||||
Object rowBean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
|
||||
String beanValue = rowBean.toString();
|
||||
if (entry.getDisplayNameFieldId()!=null) {
|
||||
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
|
||||
|
||||
Object vv = v.getVascEntryFieldValue().getValue(v, rowBean);
|
||||
if (vv==null) {
|
||||
beanValue="";
|
||||
} else {
|
||||
beanValue=""+vv;
|
||||
}
|
||||
if (beanValue.length()>30) {
|
||||
beanValue=beanValue.substring(0, 30);
|
||||
}
|
||||
}
|
||||
SwingEditDialog dialog = new SwingEditDialog(parent,entry,rowBean,i18n("vasc.dialog.edit.title"),i18n("vasc.dialog.edit.message",beanValue));
|
||||
Object result = dialog.openDialog();
|
||||
logger.finest("OPEN closed : "+result);
|
||||
if(result==null) {
|
||||
return;
|
||||
}
|
||||
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(result);
|
||||
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry);
|
||||
}
|
||||
|
||||
public void renderDelete() throws Exception {
|
||||
Object rowBean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
|
||||
String beanValue = rowBean.toString();
|
||||
|
||||
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
|
||||
beanValue = ""+v.getVascEntryFieldValue().getValue(v, rowBean);
|
||||
if (beanValue.length()>30) {
|
||||
beanValue=beanValue.substring(0, 30);
|
||||
}
|
||||
|
||||
int response = JOptionPane.showOptionDialog(
|
||||
parent // Center in window.
|
||||
, i18n("vasc.dialog.delete.message",beanValue) // Message
|
||||
, i18n("vasc.dialog.delete.title") // Title in titlebar
|
||||
, JOptionPane.YES_NO_OPTION // Option type
|
||||
, JOptionPane.PLAIN_MESSAGE // messageType
|
||||
, null // Icon (none)
|
||||
, null // Button text as above.
|
||||
, null // Default button's label
|
||||
);
|
||||
if (response==JOptionPane.YES_OPTION) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SwingEditDialog extends JDialog {
|
||||
|
||||
private static final long serialVersionUID = 10L;
|
||||
private String headerText = null;
|
||||
private Object result = null;
|
||||
private Object bean = null;
|
||||
|
||||
public SwingEditDialog(JComponent parent,VascEntry entry,Object bean,String title,String headerText) throws Exception {
|
||||
super();
|
||||
this.headerText = headerText;
|
||||
this.bean = bean;
|
||||
|
||||
setTitle(i18n(title));
|
||||
setModal(true);
|
||||
|
||||
JPanel pane = new JPanel();
|
||||
pane.setLayout(new BorderLayout());
|
||||
|
||||
JPanel header = new JPanel();
|
||||
createHeader(header);
|
||||
pane.add(header,BorderLayout.NORTH);
|
||||
|
||||
JPanel body = new JPanel();
|
||||
createBody(body);
|
||||
pane.add(body,BorderLayout.CENTER);
|
||||
|
||||
JPanel footer = new JPanel();
|
||||
createFooter(footer);
|
||||
pane.add(footer,BorderLayout.SOUTH);
|
||||
|
||||
add(pane);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
//Ensure the text field always gets the first focus.
|
||||
//addComponentListener(new ComponentAdapter() {
|
||||
// public void componentShown(ComponentEvent ce) {
|
||||
// textField.requestFocusInWindow();
|
||||
// }
|
||||
/// });
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
|
||||
public Object openDialog() {
|
||||
setVisible(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void createHeader(JPanel header) {
|
||||
JLabel l = new JLabel();
|
||||
l.setText(i18n(headerText));
|
||||
l.setFont(new Font(null,Font.BOLD, 14));
|
||||
//l.setToolTipText(i18n(headerText));
|
||||
header.add(l);
|
||||
}
|
||||
|
||||
public void createBody(JPanel body) throws Exception {
|
||||
body.setLayout(new SpringLayout());
|
||||
int column = 0;
|
||||
for (VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (c.getEdit()==false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//if (c.isEditReadOnly()==true) {
|
||||
|
||||
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
|
||||
|
||||
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
|
||||
VascValueModel model = new VascValueModel();
|
||||
model.setValue(i18n(c.getName()));
|
||||
label.createComponent(entry,c,model,body);
|
||||
|
||||
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
|
||||
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
|
||||
model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
|
||||
model.addListener(new VascColumnValueModelListener(c,bean));
|
||||
Object g = editor.createComponent(entry,c,model,body);
|
||||
|
||||
column++;
|
||||
if (i==0) {
|
||||
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,g);
|
||||
}
|
||||
}
|
||||
}
|
||||
//JComponent, rows, cols, initX, initY ,xPad, yPad
|
||||
SpringUtilities.makeCompactGrid(body, column,2, 6,6, 6,6);
|
||||
|
||||
}
|
||||
public void createFooter(JPanel footer) {
|
||||
|
||||
JButton saveButton = new JButton();
|
||||
saveButton.setIcon(getImageIcon("vasc.dialog.save.image"));
|
||||
saveButton.setText(i18n("vasc.dialog.save.name"));
|
||||
saveButton.setToolTipText(i18n("vasc.dialog.save.tooltip"));
|
||||
saveButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
//if(entry.getVascFrontendData().getVascFrontendHelper().validateObject(entry, bean)) {
|
||||
// return;
|
||||
//}
|
||||
result = bean;
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
footer.add(saveButton);
|
||||
|
||||
JButton cancelButton = new JButton();
|
||||
cancelButton.setIcon(getImageIcon("vasc.dialog.cancel.image"));
|
||||
cancelButton.setText(i18n("vasc.dialog.cancel.name"));
|
||||
cancelButton.setToolTipText(i18n("vasc.dialog.cancel.tooltip"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
result = null;
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
footer.add(cancelButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascViewRenderer#renderExport(com.idcanet.vasc.core.VascEntry, com.idcanet.vasc.core.VascDataExporter)
|
||||
*/
|
||||
public void renderExport(VascEntryExporter exporter) throws Exception {
|
||||
|
||||
String fileName = null;
|
||||
JFileChooser c = new JFileChooser();
|
||||
int rVal = c.showSaveDialog(null);
|
||||
if (rVal == JFileChooser.APPROVE_OPTION) {
|
||||
fileName = c.getSelectedFile().getAbsolutePath();
|
||||
// filename.setText(c.getSelectedFile().getName());
|
||||
//dir.setText(c.getCurrentDirectory().toString());
|
||||
}
|
||||
if (rVal == JFileChooser.CANCEL_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.fine("FileName: "+fileName);
|
||||
if (fileName == null) {
|
||||
return;
|
||||
}
|
||||
OutputStream out = new FileOutputStream(fileName);
|
||||
try {
|
||||
exporter.doExport(out, entry);
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e);
|
||||
} finally {
|
||||
if (out!=null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascViewRenderer#renderView(com.idcanet.vasc.core.VascEntry)
|
||||
*/
|
||||
public void renderView() throws Exception {
|
||||
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new BorderLayout());
|
||||
//topPanel.setBackground(Color.PINK);
|
||||
|
||||
JPanel n = new JPanel();
|
||||
topPanel.add(n,BorderLayout.NORTH);
|
||||
renderHeader(n);
|
||||
|
||||
JPanel c = new JPanel();
|
||||
c.setLayout(new BorderLayout());
|
||||
topPanel.add(c,BorderLayout.CENTER);
|
||||
renderBody(c);
|
||||
|
||||
JPanel f = new JPanel();
|
||||
//f.setBackground(Color.BLUE);
|
||||
topPanel.add(f,BorderLayout.SOUTH);
|
||||
renderFooter(f);
|
||||
|
||||
//parent.setBackground(Color.CYAN);
|
||||
parent.setLayout(new BorderLayout());
|
||||
parent.add(topPanel);
|
||||
}
|
||||
|
||||
private void renderHeader(JComponent parent2) {
|
||||
|
||||
JPanel header = new JPanel();
|
||||
header.setLayout(new BorderLayout());
|
||||
header.setBackground(Color.WHITE);
|
||||
header.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
if(entry.getListImage()!=null) {
|
||||
JLabel l = new JLabel();
|
||||
// TODO: hack images working
|
||||
//l.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(entry.getHeaderImage())).getScaledInstance(32, 32, Image.SCALE_SMOOTH)));
|
||||
if (entry.getListDescription()!=null) {
|
||||
l.setToolTipText(i18n(entry.getListDescription()));
|
||||
}
|
||||
header.add(l,BorderLayout.WEST);
|
||||
}
|
||||
|
||||
if(entry.getName()!=null) {
|
||||
JLabel l = new JLabel(i18n(entry.getName()));
|
||||
l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
l.setFont(new Font(null,Font.BOLD, 18));
|
||||
if (entry.getListDescription()!=null) {
|
||||
l.setToolTipText(i18n(entry.getListDescription()));
|
||||
}
|
||||
header.add(l,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
JPanel top = new JPanel();
|
||||
//top.setBackground(Color.BLUE);
|
||||
for (GlobalVascAction action:entry.getGlobalActions()) {
|
||||
JButton but = new JButton();
|
||||
but.setText(i18n(action.getName()));
|
||||
but.setToolTipText(i18n(action.getDescription()));
|
||||
but.addActionListener(new GlobalActionListener(action));
|
||||
but.setIcon(getImageIcon(action.getImage()));
|
||||
top.add(but);
|
||||
}
|
||||
|
||||
// create options
|
||||
JPanel optionPanel = new JPanel();
|
||||
//top.setBackground(Color.GREEN);
|
||||
//for(VascUserOption option:entry.getUserOptions()) {
|
||||
// option.createUserOptionRenderer(entry);
|
||||
//}
|
||||
|
||||
//top.add(header,BorderLayout.NORTH);
|
||||
parent2.setLayout(new BorderLayout());
|
||||
parent2.add(header,BorderLayout.NORTH);
|
||||
parent2.add(optionPanel,BorderLayout.CENTER);
|
||||
parent2.add(top,BorderLayout.EAST);
|
||||
}
|
||||
|
||||
private void renderBody(JComponent parent2) {
|
||||
|
||||
VascColumnModel model = new VascColumnModel();
|
||||
//TODO: entry.getVascEntryController().addEventListener(model);
|
||||
|
||||
JTable table = new JTable();
|
||||
// this regs the listeners for the sorting
|
||||
//tableSorter.setTableHeader(table.getTableHeader());
|
||||
//tableSorter.setTableModel(model);
|
||||
|
||||
table.setModel(model);
|
||||
table.getTableHeader().setReorderingAllowed(false);
|
||||
|
||||
// remove auto columns :(
|
||||
int cols = table.getColumnModel().getColumnCount();
|
||||
for (int i=0;i<cols;i++) {
|
||||
TableColumn c = table.getColumnModel().getColumn(0); // idd, just remove index 0 every time
|
||||
table.removeColumn(c);
|
||||
}
|
||||
table.revalidate();
|
||||
|
||||
TableCellRenderer renderer = new JComponentTableHeaderCellRenderer();
|
||||
int counter=0;
|
||||
for(VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (c.getList()==false) {
|
||||
continue;
|
||||
}
|
||||
TableColumn t = new TableColumn();
|
||||
if (c.getSizeList()!=null) {
|
||||
t.setPreferredWidth(c.getSizeList());
|
||||
} else {
|
||||
t.setPreferredWidth(200);
|
||||
}
|
||||
t.setHeaderValue(c);
|
||||
t.setHeaderRenderer(renderer);
|
||||
t.setModelIndex(counter);
|
||||
table.addColumn(t);
|
||||
counter++;
|
||||
}
|
||||
table.getSelectionModel().addListSelectionListener(new EntrySectionListener(table));
|
||||
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
||||
table.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
Object o = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
|
||||
if (o==null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// todo: fix
|
||||
entry.getVascFrontendData().getVascFrontend().renderEdit();
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
parent2.add(scrollPane);
|
||||
}
|
||||
class EntrySectionListener implements ListSelectionListener {
|
||||
JTable table;
|
||||
EntrySectionListener(JTable table) {
|
||||
this.table = table;
|
||||
}
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (e.getValueIsAdjusting()) {
|
||||
return;
|
||||
}
|
||||
int rowIndex = table.getSelectedRow();
|
||||
if (rowIndex!=-1) {
|
||||
// temp; gets index by sorter
|
||||
//rowIndex = tableSorter.modelIndex(rowIndex);
|
||||
Object data = entry.getVascFrontendData().getVascEntryState().getEntryDataList().get(rowIndex);
|
||||
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(data);
|
||||
} else {
|
||||
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
class JComponentTableHeaderCellRenderer extends DefaultTableCellRenderer {
|
||||
private static final long serialVersionUID = 10L;
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column) {
|
||||
VascEntryField c = (VascEntryField)value;
|
||||
setText(i18n(c.getName()));
|
||||
setToolTipText(i18n(c.getDescription()));
|
||||
|
||||
if(c.getImage()!=null) {
|
||||
setIcon(getImageIcon(c.getImage()));
|
||||
} else {
|
||||
setIcon(null);
|
||||
}
|
||||
|
||||
if (entry != null) {
|
||||
JTableHeader header = table.getTableHeader();
|
||||
if (header != null) {
|
||||
setForeground(header.getForeground());
|
||||
setBackground(header.getBackground());
|
||||
setFont(header.getFont());
|
||||
}
|
||||
}
|
||||
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void renderFooter(JComponent parent2) {
|
||||
logger.finest("Creating footer");
|
||||
JPanel panel = new JPanel();
|
||||
for(RowVascAction action:entry.getRowActions()) {
|
||||
JButton but = new JButton();
|
||||
but.setText(i18n(action.getName()));
|
||||
but.setToolTipText(i18n(action.getDescription()));
|
||||
but.setIcon(getImageIcon(action.getImage()));
|
||||
but.addActionListener(new RowActionListener(action));
|
||||
panel.add(but);
|
||||
}
|
||||
parent2.setLayout(new BorderLayout());
|
||||
parent2.add(panel,BorderLayout.WEST);
|
||||
}
|
||||
|
||||
|
||||
class RowActionListener implements ActionListener {
|
||||
|
||||
private RowVascAction action = null;
|
||||
|
||||
public RowActionListener(RowVascAction action) {
|
||||
this.action=action;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
logger.fine("Row Action");
|
||||
try {
|
||||
action.doRowAction(entry, entry.getVascFrontendData().getVascEntryState().getEntryDataObject());
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalActionListener implements ActionListener {
|
||||
|
||||
private GlobalVascAction action = null;
|
||||
|
||||
public GlobalActionListener(GlobalVascAction action) {
|
||||
this.action=action;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
logger.fine("Global Action");
|
||||
try {
|
||||
action.doGlobalAction(entry);
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VascColumnModel extends AbstractTableModel implements VascEntryFrontendEventListener {
|
||||
private static final long serialVersionUID = 10L;
|
||||
|
||||
public void vascEvent(VascEntry entry,Object o) {
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.entry.entryModel#getColumnCount()
|
||||
*/
|
||||
public int getColumnCount() {
|
||||
int result = 0;
|
||||
for(VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (c.getList()==false) {
|
||||
continue;
|
||||
}
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.entry.entryModel#getRowCount()
|
||||
*/
|
||||
public int getRowCount() {
|
||||
if (entry.getVascFrontendData().getVascEntryState().getEntryDataList()==null) {
|
||||
return 0;
|
||||
}
|
||||
return entry.getVascFrontendData().getVascEntryState().getEntryDataList().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.entry.entryModel#getValueAt(int, int)
|
||||
*/
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
Object bean = entry.getVascFrontendData().getVascEntryState().getEntryDataList().get(rowIndex);
|
||||
logger.finer("Rending column; "+columnIndex+" bean: "+bean);
|
||||
|
||||
// TODO: this is slowing....
|
||||
List<VascEntryField> list = new ArrayList<VascEntryField>();
|
||||
for(VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (c.getList()==false) {
|
||||
continue;
|
||||
|
||||
}
|
||||
list.add(c);
|
||||
}
|
||||
|
||||
VascEntryField vtc = list.get(columnIndex);
|
||||
try {
|
||||
//if (vtc.getVascColumnRenderer()!=null) {
|
||||
// return vtc.getVascColumnRenderer().rendererColumn(vtc,bean);
|
||||
//} else {
|
||||
return ""+vtc.getVascEntryFieldValue().getValue(vtc,bean);
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
return "Error";
|
||||
}
|
||||
}
|
||||
|
||||
public VascFrontendEventType[] getEventTypes() {
|
||||
VascFrontendEventType[] result = {VascFrontendEventType.DATA_LIST_UPDATE};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A 1.4 file that provides utility methods for creating form- or grid-style
|
||||
* layouts with SpringLayout. These utilities are used by several programs, such
|
||||
* as SpringBox and SpringCompactGrid.
|
||||
*/
|
||||
|
||||
class SpringUtilities {
|
||||
|
||||
/**
|
||||
* Aligns the first <code>rows</code>*<code>cols</code> components of
|
||||
* <code>parent</code> in a grid. Each component is as big as the maximum
|
||||
* preferred width and height of the components. The parent is made just big
|
||||
* enough to fit them all.
|
||||
*
|
||||
* @param rows
|
||||
* number of rows
|
||||
* @param cols
|
||||
* number of columns
|
||||
* @param initialX
|
||||
* x location to start the grid at
|
||||
* @param initialY
|
||||
* y location to start the grid at
|
||||
* @param xPad
|
||||
* x padding between cells
|
||||
* @param yPad
|
||||
* y padding between cells
|
||||
*/
|
||||
public static void makeGrid(Container parent, int rows, int cols,
|
||||
int initialX, int initialY, int xPad, int yPad) {
|
||||
SpringLayout layout;
|
||||
try {
|
||||
layout = (SpringLayout) parent.getLayout();
|
||||
} catch (ClassCastException exc) {
|
||||
System.err
|
||||
.println("The first argument to makeGrid must use SpringLayout.");
|
||||
return;
|
||||
}
|
||||
|
||||
Spring xPadSpring = Spring.constant(xPad);
|
||||
Spring yPadSpring = Spring.constant(yPad);
|
||||
Spring initialXSpring = Spring.constant(initialX);
|
||||
Spring initialYSpring = Spring.constant(initialY);
|
||||
int max = rows * cols;
|
||||
|
||||
//Calculate Springs that are the max of the width/height so that all
|
||||
//cells have the same size.
|
||||
Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0))
|
||||
.getWidth();
|
||||
Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0))
|
||||
.getWidth();
|
||||
for (int i = 1; i < max; i++) {
|
||||
SpringLayout.Constraints cons = layout.getConstraints(parent
|
||||
.getComponent(i));
|
||||
|
||||
maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
|
||||
maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
|
||||
}
|
||||
|
||||
//Apply the new width/height Spring. This forces all the
|
||||
//components to have the same size.
|
||||
for (int i = 0; i < max; i++) {
|
||||
SpringLayout.Constraints cons = layout.getConstraints(parent
|
||||
.getComponent(i));
|
||||
|
||||
cons.setWidth(maxWidthSpring);
|
||||
cons.setHeight(maxHeightSpring);
|
||||
}
|
||||
|
||||
//Then adjust the x/y constraints of all the cells so that they
|
||||
//are aligned in a grid.
|
||||
SpringLayout.Constraints lastCons = null;
|
||||
SpringLayout.Constraints lastRowCons = null;
|
||||
for (int i = 0; i < max; i++) {
|
||||
SpringLayout.Constraints cons = layout.getConstraints(parent
|
||||
.getComponent(i));
|
||||
if (i % cols == 0) { //start of new row
|
||||
lastRowCons = lastCons;
|
||||
cons.setX(initialXSpring);
|
||||
} else { //x position depends on previous component
|
||||
cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST),
|
||||
xPadSpring));
|
||||
}
|
||||
|
||||
if (i / cols == 0) { //first row
|
||||
cons.setY(initialYSpring);
|
||||
} else { //y position depends on previous row
|
||||
cons.setY(Spring.sum(lastRowCons
|
||||
.getConstraint(SpringLayout.SOUTH), yPadSpring));
|
||||
}
|
||||
lastCons = cons;
|
||||
}
|
||||
|
||||
//Set the parent's size.
|
||||
SpringLayout.Constraints pCons = layout.getConstraints(parent);
|
||||
pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring
|
||||
.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
|
||||
pCons.setConstraint(SpringLayout.EAST, Spring.sum(
|
||||
Spring.constant(xPad), lastCons
|
||||
.getConstraint(SpringLayout.EAST)));
|
||||
}
|
||||
|
||||
/* Used by makeCompactGrid. */
|
||||
private static SpringLayout.Constraints getConstraintsForCell(int row,
|
||||
int col, Container parent, int cols) {
|
||||
SpringLayout layout = (SpringLayout) parent.getLayout();
|
||||
Component c = parent.getComponent(row * cols + col);
|
||||
return layout.getConstraints(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aligns the first <code>rows</code>*<code>cols</code> components of
|
||||
* <code>parent</code> in a grid. Each component in a column is as wide as
|
||||
* the maximum preferred width of the components in that column; height is
|
||||
* similarly determined for each row. The parent is made just big enough to
|
||||
* fit them all.
|
||||
*
|
||||
* @param rows
|
||||
* number of rows
|
||||
* @param cols
|
||||
* number of columns
|
||||
* @param initialX
|
||||
* x location to start the grid at
|
||||
* @param initialY
|
||||
* y location to start the grid at
|
||||
* @param xPad
|
||||
* x padding between cells
|
||||
* @param yPad
|
||||
* y padding between cells
|
||||
*/
|
||||
public static void makeCompactGrid(Container parent, int rows, int cols,
|
||||
int initialX, int initialY, int xPad, int yPad) {
|
||||
SpringLayout layout;
|
||||
try {
|
||||
layout = (SpringLayout) parent.getLayout();
|
||||
} catch (ClassCastException exc) {
|
||||
System.err
|
||||
.println("The first argument to makeCompactGrid must use SpringLayout.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Align all cells in each column and make them the same width.
|
||||
Spring x = Spring.constant(initialX);
|
||||
for (int c = 0; c < cols; c++) {
|
||||
Spring width = Spring.constant(0);
|
||||
for (int r = 0; r < rows; r++) {
|
||||
width = Spring.max(width, getConstraintsForCell(r, c, parent,
|
||||
cols).getWidth());
|
||||
}
|
||||
for (int r = 0; r < rows; r++) {
|
||||
SpringLayout.Constraints constraints = getConstraintsForCell(r,
|
||||
c, parent, cols);
|
||||
constraints.setX(x);
|
||||
constraints.setWidth(width);
|
||||
}
|
||||
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
|
||||
}
|
||||
|
||||
//Align all cells in each row and make them the same height.
|
||||
Spring y = Spring.constant(initialY);
|
||||
for (int r = 0; r < rows; r++) {
|
||||
Spring height = Spring.constant(0);
|
||||
for (int c = 0; c < cols; c++) {
|
||||
height = Spring.max(height, getConstraintsForCell(r, c, parent,
|
||||
cols).getHeight());
|
||||
}
|
||||
for (int c = 0; c < cols; c++) {
|
||||
SpringLayout.Constraints constraints = getConstraintsForCell(r,
|
||||
c, parent, cols);
|
||||
constraints.setY(y);
|
||||
constraints.setHeight(height);
|
||||
}
|
||||
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
|
||||
}
|
||||
|
||||
//Set the parent's size.
|
||||
SpringLayout.Constraints pCons = layout.getConstraints(parent);
|
||||
pCons.setConstraint(SpringLayout.SOUTH, y);
|
||||
pCons.setConstraint(SpringLayout.EAST, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Sep 21, 2007
|
||||
*/
|
||||
public class SwingBoolean implements VascUIComponent {
|
||||
|
||||
private JCheckBox checkBox = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
checkBox = new JCheckBox();
|
||||
orgBackgroundColor = checkBox.getBackground();
|
||||
checkBox.setSelected(new Boolean(model.getValue().toString()));
|
||||
((JComponent)gui).add(checkBox);
|
||||
checkBox.addActionListener(new SelectActionListener(model,table));
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (checkBox==null) {
|
||||
return null;
|
||||
}
|
||||
return checkBox.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (checkBox==null) {
|
||||
return;
|
||||
}
|
||||
checkBox.setToolTipText(text);
|
||||
if (text==null) {
|
||||
checkBox.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
checkBox.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !checkBox.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
checkBox.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return checkBox.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
checkBox.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
class SelectActionListener implements ActionListener {
|
||||
|
||||
private VascValueModel model;
|
||||
private VascEntry entry = null;
|
||||
public SelectActionListener(VascValueModel model,VascEntry entry) {
|
||||
this.model=model;
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
boolean value = ((JCheckBox)e.getSource()).isSelected();
|
||||
try {
|
||||
model.setValue(value);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Nov 18, 2008
|
||||
*/
|
||||
public class SwingButton implements VascUIComponent {
|
||||
|
||||
private JButton vascButton = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
vascButton = new JButton("Color");
|
||||
orgBackgroundColor = vascButton.getBackground();
|
||||
((JComponent)gui).add(vascButton);
|
||||
//vascButton.addActionListener(new SelectActionListener3(model,true,table));
|
||||
return vascButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (vascButton==null) {
|
||||
return null;
|
||||
}
|
||||
return vascButton.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (vascButton==null) {
|
||||
return;
|
||||
}
|
||||
vascButton.setToolTipText(text);
|
||||
if (text==null) {
|
||||
vascButton.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
vascButton.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !vascButton.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
vascButton.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return vascButton.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
vascButton.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Nov 25, 2007
|
||||
*/
|
||||
public class SwingColorChooser implements VascUIComponent {
|
||||
|
||||
private JButton colorButton = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
JButton colorButton = new JButton("Color");
|
||||
orgBackgroundColor = colorButton.getBackground();
|
||||
((JComponent)gui).add(colorButton);
|
||||
colorButton.addActionListener(new SelectActionListener3(model,true,table));
|
||||
return colorButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (colorButton==null) {
|
||||
return null;
|
||||
}
|
||||
return colorButton.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (colorButton==null) {
|
||||
return;
|
||||
}
|
||||
colorButton.setToolTipText(text);
|
||||
if (text==null) {
|
||||
colorButton.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
colorButton.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !colorButton.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
colorButton.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return colorButton.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
colorButton.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
class SelectActionListener3 implements ActionListener {
|
||||
|
||||
private VascValueModel model;
|
||||
private boolean hexEncoding = false;
|
||||
private VascEntry entry = null;
|
||||
public SelectActionListener3(VascValueModel model,boolean hexEncoding,VascEntry entry) {
|
||||
this.model=model;
|
||||
this.hexEncoding=hexEncoding;
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (hexEncoding==false) {
|
||||
Color cur=null;
|
||||
try {
|
||||
cur = (Color)model.getValue();
|
||||
} catch (VascException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (cur==null) {
|
||||
cur = Color.YELLOW;
|
||||
}
|
||||
Color newColor = JColorChooser.showDialog(null,"Choose a color...",cur);
|
||||
try {
|
||||
model.setValue(newColor);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
} else {
|
||||
String cur=null;
|
||||
try {
|
||||
cur = (String)model.getValue();
|
||||
} catch (VascException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
Color c = Color.YELLOW;
|
||||
try {
|
||||
if (cur!=null) {
|
||||
c = Color.decode(cur);
|
||||
}
|
||||
Color newColor = JColorChooser.showDialog(null,"Choose a color...",c);
|
||||
String newColorString = "#"+Integer.toHexString( newColor.getRGB() & 0x00ffffff );
|
||||
model.setValue(newColorString);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
import com.michaelbaranov.microba.calendar.DatePicker;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Sep 21, 2007
|
||||
*/
|
||||
public class SwingDate implements VascUIComponent {
|
||||
|
||||
private DatePicker datePicker = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
datePicker = new DatePicker();
|
||||
orgBackgroundColor = datePicker.getBackground();
|
||||
try {
|
||||
datePicker.setDate((Date)model.getValue());
|
||||
} catch (PropertyVetoException e) {
|
||||
throw new VascException(new VascException(e));
|
||||
}
|
||||
((JComponent)gui).add(datePicker);
|
||||
datePicker.addActionListener(new SelectActionListener2(model,table));
|
||||
return datePicker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (datePicker==null) {
|
||||
return null;
|
||||
}
|
||||
return datePicker.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (datePicker==null) {
|
||||
return;
|
||||
}
|
||||
datePicker.setToolTipText(text);
|
||||
if (text==null) {
|
||||
datePicker.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
datePicker.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !datePicker.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
datePicker.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return datePicker.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
datePicker.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
class SelectActionListener2 implements ActionListener {
|
||||
|
||||
private VascValueModel model;
|
||||
private VascEntry entry = null;
|
||||
public SelectActionListener2(VascValueModel model,VascEntry entry) {
|
||||
this.model=model;
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date value = ((DatePicker)e.getSource()).getDate();
|
||||
try {
|
||||
model.setValue(value);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Sep 21, 2008
|
||||
*/
|
||||
public class SwingLabel implements VascUIComponent {
|
||||
|
||||
private JLabel label = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
label = new JLabel();
|
||||
label.setHorizontalAlignment(JLabel.TRAILING);
|
||||
orgBackgroundColor = label.getBackground();
|
||||
label.setText(""+model.getValue());
|
||||
((JComponent)gui).add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (label==null) {
|
||||
return null;
|
||||
}
|
||||
return label.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (label==null) {
|
||||
return;
|
||||
}
|
||||
label.setToolTipText(text);
|
||||
if (text==null) {
|
||||
label.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
label.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !label.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
label.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return label.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
label.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.ListCellRenderer;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascSelectItem;
|
||||
import com.idcanet.vasc.core.ui.VascSelectItemModel;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 12, 2007
|
||||
*/
|
||||
public class SwingList implements VascUIComponent {
|
||||
|
||||
private JComboBox comboBox = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
|
||||
VascSelectItemModel items = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
|
||||
if (items==null) {
|
||||
comboBox = new JComboBox();
|
||||
} else {
|
||||
comboBox = new JComboBox(items.getVascSelectItems(entry).toArray());
|
||||
}
|
||||
orgBackgroundColor = comboBox.getBackground();
|
||||
((JComponent)gui).add(comboBox);
|
||||
comboBox.setRenderer(new MyCellRenderer());
|
||||
comboBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
VascSelectItem i = (VascSelectItem)((JComboBox)e.getSource()).getSelectedItem();
|
||||
try {
|
||||
model.setValue(i.getValue());
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// set default !!
|
||||
if (model.getValue()!=null) {
|
||||
for (int i=0;i<comboBox.getModel().getSize();i++) {
|
||||
Object o = comboBox.getModel().getElementAt(i);
|
||||
VascSelectItem i2 = (VascSelectItem)o;
|
||||
if ( model.getValue().equals(i2.getValue()) ) {
|
||||
comboBox.setSelectedItem(i2);
|
||||
return comboBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (comboBox.getModel().getSize()>0) {
|
||||
// else select the top one.
|
||||
comboBox.setSelectedIndex(0);
|
||||
}
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (comboBox==null) {
|
||||
return null;
|
||||
}
|
||||
return comboBox.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (comboBox==null) {
|
||||
return;
|
||||
}
|
||||
comboBox.setToolTipText(text);
|
||||
if (text==null) {
|
||||
comboBox.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
comboBox.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !comboBox.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
comboBox.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return comboBox.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
comboBox.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
||||
class MyCellRenderer extends JLabel implements ListCellRenderer {
|
||||
|
||||
private static final long serialVersionUID = 10L;
|
||||
|
||||
public MyCellRenderer() {
|
||||
setOpaque(true);
|
||||
}
|
||||
|
||||
public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) {
|
||||
VascSelectItem i = (VascSelectItem)value;
|
||||
if (i!=null) {
|
||||
setText(i.getLabel());
|
||||
} else {
|
||||
setText("Error");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 12, 2007
|
||||
*/
|
||||
public class SwingText implements VascUIComponent {
|
||||
|
||||
private JTextField textField = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
textField = new JTextField();
|
||||
orgBackgroundColor = textField.getBackground();
|
||||
textField.setText(""+model.getValue());
|
||||
((JComponent)gui).add(textField);
|
||||
textField.getDocument().addDocumentListener(new TextListener(model,table,this));
|
||||
return textField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (textField==null) {
|
||||
return null;
|
||||
}
|
||||
return textField.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (textField==null) {
|
||||
return;
|
||||
}
|
||||
textField.setToolTipText(text);
|
||||
if (text==null) {
|
||||
textField.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
textField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !textField.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
textField.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return textField.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
textField.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
||||
class TextListener implements DocumentListener {
|
||||
|
||||
private VascValueModel model = null;
|
||||
//private VascTable table = null;
|
||||
private SwingText textField = null;
|
||||
|
||||
public TextListener(VascValueModel model,VascEntry table,SwingText textField) {
|
||||
this.model=model;
|
||||
//this.table=table;
|
||||
this.textField=textField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
update(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
update(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
update(e);
|
||||
}
|
||||
|
||||
public void update(DocumentEvent event) {
|
||||
try {
|
||||
String value = event.getDocument().getText(0, event.getDocument().getLength());
|
||||
model.setValue(value);
|
||||
textField.setErrorText(null);
|
||||
} catch (Exception ee) {
|
||||
textField.setErrorText(ee.getLocalizedMessage());
|
||||
//table.getVascTableController().handleException(ee, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright 2004-2007 IDCA. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||||
* the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
||||
* and the following disclaimer in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the authors and
|
||||
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
||||
*/
|
||||
|
||||
package com.idcanet.vasc.frontends.swing.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Sep 21, 2008
|
||||
*/
|
||||
public class SwingTextArea implements VascUIComponent {
|
||||
|
||||
private JTextArea textArea = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
|
||||
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
textArea = new JTextArea();
|
||||
textArea.setBorder(BorderFactory.createEtchedBorder());
|
||||
textArea.setRows(8);
|
||||
|
||||
//entryField.getVascEntryFieldType().getProperty(name)
|
||||
|
||||
//textArea.setRows(rows);
|
||||
//textArea.setColumns(columns);
|
||||
|
||||
orgBackgroundColor = textArea.getBackground();
|
||||
textArea.setText(""+model.getValue());
|
||||
((JComponent)gui).add(textArea);
|
||||
textArea.getDocument().addDocumentListener(new TextAreaListener(model,entry,this));
|
||||
return textArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (textArea==null) {
|
||||
return null;
|
||||
}
|
||||
return textArea.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (textArea==null) {
|
||||
return;
|
||||
}
|
||||
textArea.setToolTipText(text);
|
||||
if (text==null) {
|
||||
textArea.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
textArea.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !textArea.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
textArea.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return textArea.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
textArea.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
||||
class TextAreaListener implements DocumentListener {
|
||||
|
||||
private VascValueModel model = null;
|
||||
private SwingTextArea textArea = null;
|
||||
|
||||
public TextAreaListener(VascValueModel model,VascEntry entry,SwingTextArea textArea) {
|
||||
this.model=model;
|
||||
this.textArea=textArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
update(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
update(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
update(e);
|
||||
}
|
||||
|
||||
public void update(DocumentEvent event) {
|
||||
try {
|
||||
String value = event.getDocument().getText(0, event.getDocument().getLength());
|
||||
model.setValue(value);
|
||||
textArea.setErrorText(null);
|
||||
} catch (Exception ee) {
|
||||
textArea.setErrorText(ee.getLocalizedMessage());
|
||||
//table.getVascTableController().handleException(ee, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue