001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.table;
014:
015: import org.wings.SComponent;
016: import org.wings.SLabel;
017: import org.wings.SResourceIcon;
018: import org.wings.STable;
019: import javax.swing.*;
020:
021: /**
022: * Renderer responsible for the row selection column in cases where the table
023: * cannot distinguish clicks on cells as selection clicks or editing clicks.
024: *
025: * @author <a href="mailto:B.Schmid@eXXcellent.de">Benjamin Schmid</a>
026: */
027: public class SDefaultTableRowSelectionRenderer extends SLabel implements
028: STableCellRenderer {
029:
030: public static final SResourceIcon DEFAULT_MULTI_SELECTION_ICON = new SResourceIcon(
031: "org/wings/icons/SelectedCheckBox.gif");
032:
033: public static final SResourceIcon DEFAULT_MULTI_NOT_SELECTION_ICON = new SResourceIcon(
034: "org/wings/icons/NotSelectedCheckBox.gif");
035:
036: public static final SResourceIcon DEFAULT_SINGLE_SELECTION_ICON = new SResourceIcon(
037: "org/wings/icons/SelectedRadioButton.gif");
038:
039: public static final SResourceIcon DEFAULT_SINGLE_NOT_SELECTION_ICON = new SResourceIcon(
040: "org/wings/icons/NotSelectedRadioButton.gif");
041:
042: /**
043: * Style to use for the foreground for non-selected nodes.
044: */
045: protected String nonSelectionStyle;
046:
047: /**
048: * Style to use for the foreground for non-selected nodes.
049: */
050: protected String selectionStyle;
051:
052: protected SResourceIcon multiSelectionIcon = DEFAULT_MULTI_SELECTION_ICON;
053:
054: protected SResourceIcon multiNonSelectionIcon = DEFAULT_MULTI_NOT_SELECTION_ICON;
055:
056: protected SResourceIcon singleSelectionIcon = DEFAULT_SINGLE_SELECTION_ICON;
057:
058: protected SResourceIcon singleNonSelectionIcon = DEFAULT_SINGLE_NOT_SELECTION_ICON;
059:
060: /**
061: * If set to true render the row selection colum with icons, otherwise simple text.
062: */
063: protected boolean useIcons = false;
064:
065: public SDefaultTableRowSelectionRenderer() {
066: }
067:
068: public SComponent getTableCellRendererComponent(STable table,
069: Object value, boolean selected, int row, int col) {
070: if (useIcons) {
071: setText(null);
072: switch (table.getSelectionMode()) {
073: case ListSelectionModel.SINGLE_SELECTION:
074: setIcon(selected ? singleSelectionIcon
075: : singleNonSelectionIcon);
076: break;
077: default:
078: setIcon(selected ? multiSelectionIcon
079: : multiNonSelectionIcon);
080: break;
081: }
082: } else {
083: setIcon(null);
084: setText("" + (row + 1));
085: }
086: // style
087: if (selected) {
088: setStyle(selectionStyle);
089: } else {
090: setStyle(nonSelectionStyle);
091: }
092:
093: return this ;
094: }
095:
096: /**
097: * Sets the style the cell is drawn with when the cell isn't selected.
098: */
099: public void setNonSelectionStyle(String newStyle) {
100: nonSelectionStyle = newStyle;
101: }
102:
103: /**
104: * Returns the style the cell is drawn with when the cell isn't selected.
105: */
106: public String getNonSelectionStyle() {
107: return nonSelectionStyle;
108: }
109:
110: /**
111: * Sets the style the cell is drawn with when the cell isn't selected.
112: */
113: public void setSelectionStyle(String newStyle) {
114: selectionStyle = newStyle;
115: }
116:
117: /**
118: * Returns the style the cell is drawn with when the cell isn't selected.
119: */
120: public String getSelectionStyle() {
121: return selectionStyle;
122: }
123:
124: /**
125: * @return Icon used for selected rows in multi-selection mode for selected lines
126: */
127: public SResourceIcon getMultiSelectionIcon() {
128: return multiSelectionIcon;
129: }
130:
131: /**
132: * @param multiSelectionIcon Icon used for selected rows in multi-selection mode for selected lines
133: */
134: public void setMultiSelectionIcon(SResourceIcon multiSelectionIcon) {
135: this .multiSelectionIcon = multiSelectionIcon;
136: }
137:
138: /**
139: * @return Icon used for selected rows in multi-selection mode for unselected lines
140: */
141: public SResourceIcon getMultiNonSelectionIcon() {
142: return multiNonSelectionIcon;
143: }
144:
145: /**
146: * @param multiNonSelectionIcon Icon used for selected rows in multi-selection mode for unselected lines
147: */
148: public void setMultiNonSelectionIcon(
149: SResourceIcon multiNonSelectionIcon) {
150: this .multiNonSelectionIcon = multiNonSelectionIcon;
151: }
152:
153: /**
154: * @return Icon used for selected rows in single-selection mode tables for selected lines
155: */
156: public SResourceIcon getSingleSelectionIcon() {
157: return singleSelectionIcon;
158: }
159:
160: /**
161: * @param singleSelectionIcon Icon used for selected rows in single-selection mode tables for selected lines
162: */
163: public void setSingleSelectionIcon(SResourceIcon singleSelectionIcon) {
164: this .singleSelectionIcon = singleSelectionIcon;
165: }
166:
167: /**
168: * @return Icon used for selected rows in single-selection mode tables for unselected lines
169: */
170: public SResourceIcon getSingleNonSelectionIcon() {
171: return singleNonSelectionIcon;
172: }
173:
174: /**
175: * @param singleNonSelectionIcon Icon used for selected rows in single-selection mode tables for unselected lines
176: */
177: public void setSingleNonSelectionIcon(
178: SResourceIcon singleNonSelectionIcon) {
179: this .singleNonSelectionIcon = singleNonSelectionIcon;
180: }
181:
182: /**
183: * Returns if set to true render the row selection colum with icons, otherwise simple text.
184: *
185: * @return if set to true render the row selection colum with icons, otherwise simple text.
186: */
187: public boolean isUseIcons() {
188: return useIcons;
189: }
190:
191: /**
192: * Sets if set to true render the row selection colum with icons, otherwise simple text.
193: *
194: * @param useIcons if set to true render the row selection colum with icons, otherwise simple text.
195: */
196: public void setUseIcons(boolean useIcons) {
197: this.useIcons = useIcons;
198: }
199: }
|