Revision: 1284
Author: mathiasbr
Date: 2006-08-08 07:00:11 -0700 (Tue, 08 Aug 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1284&view=rev
Log Message:
-----------
ListCellRenderer added which supports a Table like cells.
Usefull for ComboBox with a Table as a popup.
Added Paths:
-----------
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/BeanTableListModel.java
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/DefaultTableListModel.java
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListCellRenderer.java
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListModel.java
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/BeanTableListModel.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/BeanTableListModel.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/BeanTableListModel.java
2006-08-08 14:00:11 UTC (rev 1284)
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.springframework.richclient.list;
+
+import java.util.List;
+
+import org.springframework.context.MessageSource;
+import org.springframework.richclient.table.BeanTableModel;
+
+/**
+ * [EMAIL PROTECTED] TableListModel} implemetation for pojo based lists
+ *
+ * @author Mathias Broekelmann
+ *
+ */
+public abstract class BeanTableListModel extends BeanTableModel implements
TableListModel {
+
+ public BeanTableListModel(Class beanClass, List rows, MessageSource
messages) {
+ super(beanClass, rows, messages);
+ }
+
+ public BeanTableListModel(Class beanClass, List rows) {
+ super(beanClass, rows);
+ }
+
+ public BeanTableListModel(Class beanClass, MessageSource messages) {
+ super(beanClass, messages);
+ }
+
+ public BeanTableListModel(Class beanClass) {
+ super(beanClass);
+ }
+
+}
Property changes on:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/BeanTableListModel.java
___________________________________________________________________
Name: svn:keywords
+ URL Author Revision Date
Name: svn:eol-style
+ native
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/DefaultTableListModel.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/DefaultTableListModel.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/DefaultTableListModel.java
2006-08-08 14:00:11 UTC (rev 1284)
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.springframework.richclient.list;
+
+import java.util.Vector;
+
+import javax.swing.table.DefaultTableModel;
+
+/**
+ * Default implementation for [EMAIL PROTECTED] TableListModel}
+ *
+ * @author Mathias Broekelmann
+ *
+ */
+public class DefaultTableListModel extends DefaultTableModel implements
TableListModel {
+
+ public DefaultTableListModel() {
+ super();
+ }
+
+ public DefaultTableListModel(int rowCount, int columnCount) {
+ super(rowCount, columnCount);
+ }
+
+ public DefaultTableListModel(Object[] columnNames, int rowCount) {
+ super(columnNames, rowCount);
+ }
+
+ public DefaultTableListModel(Object[][] data, Object[] columnNames) {
+ super(data, columnNames);
+ }
+
+ public DefaultTableListModel(Vector columnNames, int rowCount) {
+ super(columnNames, rowCount);
+ }
+
+ public DefaultTableListModel(Vector data, Vector columnNames) {
+ super(data, columnNames);
+ }
+}
Property changes on:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/DefaultTableListModel.java
___________________________________________________________________
Name: svn:keywords
+ URL Author Revision Date
Name: svn:eol-style
+ native
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListCellRenderer.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListCellRenderer.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListCellRenderer.java
2006-08-08 14:00:11 UTC (rev 1284)
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.springframework.richclient.list;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JComboBox;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JTable;
+import javax.swing.ListCellRenderer;
+import javax.swing.ListSelectionModel;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.TableModelListener;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableModel;
+
+import org.springframework.util.Assert;
+
+/**
+ * ListCellRenderer which renders table cells in a list cell.
+ * <p>
+ * can be used in a [EMAIL PROTECTED] JComboBox} to render a table as a popup.
+ *
+ * @author Mathias Broekelmann
+ *
+ */
+public class TableListCellRenderer extends JTable implements ListCellRenderer {
+
+ protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
+
+ private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1,
1, 1);
+
+ private ListCellRenderer cellRenderer = new DefaultListCellRenderer();
+
+ private final JPanel headerPanel = new JPanel(new BorderLayout(0, 0));
+
+ private static class TableListCellRendererModel implements TableModel {
+
+ private int row;
+
+ private TableListModel listModel;
+
+ public TableListCellRendererModel(TableListModel model) {
+ listModel = model;
+ }
+
+ /**
+ * @return the listModel
+ */
+ public TableListModel getListModel() {
+ return listModel;
+ }
+
+ public void setListModel(TableListModel model) {
+ listModel = model;
+ }
+
+ public int getRowCount() {
+ return 1;
+ }
+
+ public void setRow(int row) {
+ this.row = row;
+ }
+
+ public Object getValueAt(int aRow, int aColumn) {
+ return listModel.getValueAt(row, aColumn);
+ }
+
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ }
+
+ public int getColumnCount() {
+ return listModel.getColumnCount();
+ }
+
+ public void addTableModelListener(TableModelListener l) {
+ }
+
+ public Class getColumnClass(int columnIndex) {
+ return listModel.getColumnClass(columnIndex);
+ }
+
+ public String getColumnName(int columnIndex) {
+ return listModel.getColumnName(columnIndex);
+ }
+
+ public void removeTableModelListener(TableModelListener l) {
+ }
+
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ }
+
+ }
+
+ public TableListCellRenderer() {
+ this(new DefaultTableListModel());
+ }
+
+ public TableListCellRenderer(TableListModel model) {
+ this(model, null);
+ }
+
+ public TableListCellRenderer(TableListModel model, TableColumnModel
columnModel) {
+ super(new TableListCellRendererModel(model), columnModel);
+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ setOpaque(true);
+ setBorder(getNoFocusBorder());
+ headerPanel.add(getTableHeader(), BorderLayout.NORTH);
+ }
+
+ public TableListModel getTableListModel() {
+ return getTableListCellRendererModel().getListModel();
+ }
+
+ public void setTableListModel(TableListModel model) {
+ getTableListCellRendererModel().setListModel(model);
+ }
+
+ public void setModel(TableModel dataModel) {
+ Assert.isInstanceOf(TableListCellRendererModel.class, dataModel);
+ super.setModel(dataModel);
+ }
+
+ private TableListCellRendererModel getTableListCellRendererModel() {
+ return (TableListCellRendererModel) super.getModel();
+ }
+
+ private static Border getNoFocusBorder() {
+ if (System.getSecurityManager() != null) {
+ return SAFE_NO_FOCUS_BORDER;
+ } else {
+ return noFocusBorder;
+ }
+ }
+
+ public void setTableHeader(JTableHeader tableHeader) {
+ super.setTableHeader(tableHeader);
+ if (headerPanel != null) {
+ if (tableHeader == null)
+ headerPanel.removeAll();
+ else
+ headerPanel.add(tableHeader, BorderLayout.NORTH);
+ }
+ }
+
+ public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected,
+ boolean cellHasFocus) {
+ if (index == -1) {
+ Component comp = cellRenderer.getListCellRendererComponent(list,
value, index, isSelected, cellHasFocus);
+ comp.setPreferredSize(getPreferredSize());
+ return comp;
+ }
+ getTableListCellRendererModel().setRow(index);
+
+ setComponentOrientation(list.getComponentOrientation());
+ if (isSelected) {
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
+ } else {
+ setBackground(list.getBackground());
+ setForeground(list.getForeground());
+ }
+
+ setEnabled(list.isEnabled());
+ setFont(list.getFont());
+
+ Border border = null;
+ if (cellHasFocus) {
+ if (isSelected) {
+ border =
UIManager.getBorder("List.focusSelectedCellHighlightBorder");
+ }
+ if (border == null) {
+ border = UIManager.getBorder("List.focusCellHighlightBorder");
+ }
+ } else {
+ border = getNoFocusBorder();
+ }
+ setBorder(border);
+
+ if (index == 0) {
+ headerPanel.add(this);
+ return headerPanel;
+ }
+
+ return this;
+ }
+
+}
Property changes on:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListCellRenderer.java
___________________________________________________________________
Name: svn:keywords
+ URL Author Revision Date
Name: svn:eol-style
+ native
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListModel.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListModel.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListModel.java
2006-08-08 14:00:11 UTC (rev 1284)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.springframework.richclient.list;
+
+import javax.swing.JComboBox;
+
+/**
+ * Model for [EMAIL PROTECTED] TableListCellRenderer} which is used to render
a table for [EMAIL PROTECTED] JComboBox}
+ *
+ * @author Mathias Broekelmann
+ */
+public interface TableListModel {
+ int getColumnCount();
+
+ String getColumnName(int columnIndex);
+
+ Class getColumnClass(int column);
+
+ Object getValueAt(int row, int column);
+
+}
Property changes on:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/list/TableListModel.java
___________________________________________________________________
Name: svn:keywords
+ URL Author Revision Date
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs