001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.testapp.interactive.testscreen;
031:
032: import nextapp.echo2.app.Alignment;
033: import nextapp.echo2.app.Border;
034: import nextapp.echo2.app.Color;
035: import nextapp.echo2.app.Column;
036: import nextapp.echo2.app.Component;
037: import nextapp.echo2.app.Extent;
038: import nextapp.echo2.app.Insets;
039: import nextapp.echo2.app.Label;
040: import nextapp.echo2.app.SelectField;
041: import nextapp.echo2.app.SplitPane;
042: import nextapp.echo2.app.Table;
043: import nextapp.echo2.app.TextField;
044: import nextapp.echo2.app.event.ActionEvent;
045: import nextapp.echo2.app.event.ActionListener;
046: import nextapp.echo2.app.event.ChangeEvent;
047: import nextapp.echo2.app.event.ChangeListener;
048: import nextapp.echo2.app.layout.SplitPaneLayoutData;
049: import nextapp.echo2.app.layout.TableLayoutData;
050: import nextapp.echo2.app.list.AbstractListModel;
051: import nextapp.echo2.app.list.ListModel;
052: import nextapp.echo2.app.list.ListSelectionModel;
053: import nextapp.echo2.app.table.AbstractTableModel;
054: import nextapp.echo2.app.table.DefaultTableCellRenderer;
055: import nextapp.echo2.app.table.DefaultTableModel;
056: import nextapp.echo2.app.table.TableCellRenderer;
057: import nextapp.echo2.app.table.TableColumnModel;
058: import nextapp.echo2.app.table.TableModel;
059: import nextapp.echo2.testapp.interactive.ButtonColumn;
060: import nextapp.echo2.testapp.interactive.InteractiveApp;
061: import nextapp.echo2.testapp.interactive.StyleUtil;
062: import nextapp.echo2.testapp.interactive.Styles;
063:
064: /**
065: * A test for <code>Tables</code>s.
066: */
067: public class TableTest extends SplitPane {
068:
069: private static class PayGrade {
070:
071: public int payGrade;
072:
073: public PayGrade(int payGrade) {
074: this .payGrade = payGrade;
075: }
076:
077: public String toString() {
078: return "Level " + payGrade;
079: }
080: }
081:
082: public static TableModel createEmployeeTableModel() {
083: DefaultTableModel model = new DefaultTableModel();
084: model.setColumnCount(4);
085: model.insertRow(0, new Object[] { "Bob Johnson",
086: "bob.johnson@test.nextapp.com", "949.555.1234",
087: new PayGrade(10) });
088: model.insertRow(0, new Object[] { "Laura Smith",
089: "laura.smith@test.nextapp.com", "217.555.9343",
090: new PayGrade(6) });
091: model.insertRow(0, new Object[] { "Jenny Roberts",
092: "jenny.roberts@test.nextapp.com", "630.555.1987",
093: new PayGrade(6) });
094: model.insertRow(0, new Object[] { "Thomas Albertson",
095: "thomas.albertson@test.nextapp.com", "619.555.1233",
096: new PayGrade(3) });
097: model.insertRow(0, new Object[] { "Albert Thomas",
098: "albert.thomas@test.nextapp.com", "408.555.3232",
099: new PayGrade(11) });
100: model.insertRow(0, new Object[] { "Sheila Simmons",
101: "sheila.simmons@test.nextapp.com", "212.555.8700",
102: new PayGrade(6) });
103: model.insertRow(0, new Object[] { "Mark Atkinson",
104: "mark.atkinson@test.nextapp.com", "213.555.9456",
105: new PayGrade(3) });
106: model.insertRow(0, new Object[] { "Linda Jefferson",
107: "linda.jefferson@test.nextapp.com", "949.555.8925",
108: new PayGrade(4) });
109: model.insertRow(0, new Object[] { "Yvonne Adams",
110: "yvonne.adams@test.nextapp.com", "714.555.8543",
111: new PayGrade(5) });
112: return model;
113: }
114:
115: private class MultiplicationTableModel extends AbstractTableModel {
116:
117: /**
118: * @see nextapp.echo2.app.table.TableModel#getColumnCount()
119: */
120: public int getColumnCount() {
121: return 12;
122: }
123:
124: /**
125: * @see nextapp.echo2.app.table.TableModel#getRowCount()
126: */
127: public int getRowCount() {
128: return 12;
129: }
130:
131: /**
132: * @see nextapp.echo2.app.table.TableModel#getValueAt(int, int)
133: */
134: public Object getValueAt(int column, int row) {
135: return new Integer((column + 1) * (row + 1));
136: }
137: }
138:
139: private Table testTable;
140:
141: private TableCellRenderer editingTableCellRenderer = new TableCellRenderer() {
142:
143: /**
144: * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
145: * java.lang.Object, int, int)
146: */
147: public Component getTableCellRendererComponent(Table table,
148: Object value, int column, int row) {
149: if (value instanceof PayGrade) {
150: ListModel listModel = new AbstractListModel() {
151:
152: public Object get(int index) {
153: return new Integer(index + 3);
154: }
155:
156: public int size() {
157: return 10;
158: }
159: };
160: final SelectField selectField = new SelectField(
161: listModel);
162: selectField
163: .setSelectedIndex(((PayGrade) value).payGrade - 3);
164: selectField.addActionListener(new ActionListener() {
165:
166: public void actionPerformed(ActionEvent e) {
167: selectField.setBackground(StyleUtil
168: .randomBrightColor());
169: }
170: });
171: return selectField;
172: } else {
173: TextField textField = new TextField();
174: if (value != null) {
175: textField.setText(value.toString());
176: }
177: return textField;
178: }
179: }
180: };
181:
182: private TableCellRenderer randomizingCellRenderer = new TableCellRenderer() {
183:
184: /**
185: * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
186: * java.lang.Object, int, int)
187: */
188: public Component getTableCellRendererComponent(Table table,
189: Object value, int column, int row) {
190: Label label = new Label(value == null ? null : value
191: .toString());
192: TableLayoutData layoutData = new TableLayoutData();
193: layoutData.setBackground(StyleUtil.randomBrightColor());
194: layoutData.setInsets(new Insets(StyleUtil.randomExtent(12),
195: StyleUtil.randomExtent(12), StyleUtil
196: .randomExtent(12), StyleUtil
197: .randomExtent(12)));
198: layoutData.setAlignment(StyleUtil.randomAlignmentHV());
199: label.setLayoutData(layoutData);
200: return label;
201: }
202: };
203:
204: private TableCellRenderer backgroundImageCheckerCellRenderer = new TableCellRenderer() {
205:
206: /**
207: * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
208: * java.lang.Object, int, int)
209: */
210: public Component getTableCellRendererComponent(Table table,
211: Object value, int column, int row) {
212: Label label = new Label(value == null ? null : value
213: .toString());
214: TableLayoutData layoutData = new TableLayoutData();
215: layoutData.setInsets(new Insets(5));
216: if (row % 2 == column % 2) {
217: layoutData
218: .setBackgroundImage(Styles.BG_SHADOW_DARK_BLUE);
219: } else {
220: layoutData
221: .setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
222: }
223: label.setLayoutData(layoutData);
224: return label;
225: }
226: };
227:
228: private TableCellRenderer visibilityCheckerCellRenderer = new TableCellRenderer() {
229:
230: /**
231: * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
232: * java.lang.Object, int, int)
233: */
234: public Component getTableCellRendererComponent(Table table,
235: Object value, int column, int row) {
236: Label label = new Label(value == null ? null : value
237: .toString());
238: if (row % 2 == column % 2) {
239: label.setVisible(false);
240: }
241: return label;
242: }
243: };
244:
245: /**
246: * Writes <code>ActionEvent</code>s to console.
247: */
248: private ActionListener actionListener = new ActionListener() {
249:
250: /**
251: * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
252: */
253: public void actionPerformed(ActionEvent e) {
254: ((InteractiveApp) getApplicationInstance()).consoleWrite(e
255: .toString());
256: }
257: };
258:
259: /**
260: * Writes <code>ChangeEvent</code>s to console.
261: */
262: private ChangeListener changeListener = new ChangeListener() {
263:
264: /**
265: * @see nextapp.echo2.app.event.ChangeListener#stateChanged(nextapp.echo2.app.event.ChangeEvent)
266: */
267: public void stateChanged(ChangeEvent e) {
268: ((InteractiveApp) getApplicationInstance()).consoleWrite(e
269: .toString());
270: }
271: };
272:
273: public TableTest() {
274: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250,
275: Extent.PX));
276: setStyleName("DefaultResizable");
277:
278: Column groupContainerColumn = new Column();
279: groupContainerColumn.setCellSpacing(new Extent(5));
280: groupContainerColumn.setStyleName("TestControlsColumn");
281: add(groupContainerColumn);
282:
283: Column testColumn = new Column();
284: SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
285: splitPaneLayoutData.setInsets(new Insets(10, 5));
286: testColumn.setLayoutData(splitPaneLayoutData);
287: add(testColumn);
288:
289: ButtonColumn controlsColumn;
290:
291: controlsColumn = new ButtonColumn();
292: groupContainerColumn.add(controlsColumn);
293:
294: controlsColumn.add(new Label("TableModel"));
295:
296: controlsColumn.addButton("Multiplication Model",
297: new ActionListener() {
298: public void actionPerformed(ActionEvent e) {
299: testTable
300: .setModel(new MultiplicationTableModel());
301: }
302: });
303:
304: controlsColumn.addButton("DefaultTableModel (Empty)",
305: new ActionListener() {
306: public void actionPerformed(ActionEvent e) {
307: testTable.setModel(new DefaultTableModel());
308: }
309: });
310:
311: controlsColumn.addButton("DefaultTableModel (Employees)",
312: new ActionListener() {
313: public void actionPerformed(ActionEvent e) {
314: testTable.setModel(createEmployeeTableModel());
315: }
316: });
317:
318: testTable = new Table();
319: testTable.setBorder(new Border(new Extent(1), Color.BLUE,
320: Border.STYLE_SOLID));
321: testColumn.add(testTable);
322:
323: controlsColumn.add(new Label("Appearance"));
324:
325: controlsColumn.addButton("Change Foreground",
326: new ActionListener() {
327: public void actionPerformed(ActionEvent e) {
328: testTable
329: .setForeground(StyleUtil.randomColor());
330: }
331: });
332: controlsColumn.addButton("Change Background",
333: new ActionListener() {
334: public void actionPerformed(ActionEvent e) {
335: testTable
336: .setBackground(StyleUtil.randomColor());
337: }
338: });
339: controlsColumn.addButton("Change Border (All Attributes)",
340: new ActionListener() {
341: public void actionPerformed(ActionEvent e) {
342: testTable.setBorder(StyleUtil.randomBorder());
343: }
344: });
345: controlsColumn.addButton("Change Border Color",
346: new ActionListener() {
347: public void actionPerformed(ActionEvent e) {
348: Border border = testTable.getBorder();
349: testTable.setBorder(new Border(
350: border.getSize(), StyleUtil
351: .randomColor(), border
352: .getStyle()));
353: }
354: });
355: controlsColumn.addButton("Change Border Size",
356: new ActionListener() {
357: public void actionPerformed(ActionEvent e) {
358: testTable.setBorder(StyleUtil
359: .nextBorderSize(testTable.getBorder()));
360: }
361: });
362: controlsColumn.addButton("Change Border Style",
363: new ActionListener() {
364: public void actionPerformed(ActionEvent e) {
365: testTable
366: .setBorder(StyleUtil
367: .nextBorderStyle(testTable
368: .getBorder()));
369: }
370: });
371:
372: controlsColumn.addButton("Set Insets 0px",
373: new ActionListener() {
374: public void actionPerformed(ActionEvent e) {
375: testTable.setInsets(new Insets(0));
376: }
377: });
378: controlsColumn.addButton("Set Insets 2px",
379: new ActionListener() {
380: public void actionPerformed(ActionEvent e) {
381: testTable.setInsets(new Insets(2));
382: }
383: });
384: controlsColumn.addButton("Set Insets 10/5px",
385: new ActionListener() {
386: public void actionPerformed(ActionEvent e) {
387: testTable.setInsets(new Insets(10, 5));
388: }
389: });
390: controlsColumn.addButton("Set Insets 10/20/30/40px",
391: new ActionListener() {
392: public void actionPerformed(ActionEvent e) {
393: testTable.setInsets(new Insets(10, 20, 30, 40));
394: }
395: });
396: controlsColumn.addButton("Set Width = null",
397: new ActionListener() {
398: public void actionPerformed(ActionEvent e) {
399: testTable.setWidth(null);
400: }
401: });
402: controlsColumn.addButton("Set Width = 500px",
403: new ActionListener() {
404: public void actionPerformed(ActionEvent e) {
405: testTable.setWidth(new Extent(500));
406: }
407: });
408: controlsColumn.addButton("Set Width = 100%",
409: new ActionListener() {
410: public void actionPerformed(ActionEvent e) {
411: testTable.setWidth(new Extent(100,
412: Extent.PERCENT));
413: }
414: });
415: controlsColumn.addButton("Set ColumnWidths Equal",
416: new ActionListener() {
417: public void actionPerformed(ActionEvent e) {
418: TableColumnModel columnModel = testTable
419: .getColumnModel();
420: int columnCount = columnModel.getColumnCount();
421: if (columnCount > 0) {
422: Extent width = new Extent(
423: 100 / columnCount, Extent.PERCENT);
424: for (int i = 0; i < columnCount; ++i) {
425: columnModel.getColumn(i)
426: .setWidth(width);
427: }
428: }
429: }
430: });
431: controlsColumn.addButton("Toggle Header Visible",
432: new ActionListener() {
433: public void actionPerformed(ActionEvent e) {
434: testTable.setHeaderVisible(!testTable
435: .isHeaderVisible());
436: }
437: });
438: controlsColumn.addButton("Toggle Enabled State",
439: new ActionListener() {
440: public void actionPerformed(ActionEvent e) {
441: testTable.setEnabled(!testTable.isEnabled());
442: }
443: });
444:
445: // Rollover Effect Settings
446:
447: controlsColumn = new ButtonColumn();
448: groupContainerColumn.add(controlsColumn);
449:
450: controlsColumn.add(new Label("Rollover Effects"));
451:
452: controlsColumn.addButton("Enable Rollover Effects",
453: new ActionListener() {
454: public void actionPerformed(ActionEvent e) {
455: testTable.setRolloverEnabled(true);
456: }
457: });
458: controlsColumn.addButton("Disable Rollover Effects",
459: new ActionListener() {
460: public void actionPerformed(ActionEvent e) {
461: testTable.setRolloverEnabled(false);
462: }
463: });
464: controlsColumn.addButton("Set Rollover Foreground",
465: new ActionListener() {
466: public void actionPerformed(ActionEvent e) {
467: testTable.setRolloverForeground(StyleUtil
468: .randomColor());
469: }
470: });
471: controlsColumn.addButton("Clear Rollover Foreground",
472: new ActionListener() {
473: public void actionPerformed(ActionEvent e) {
474: testTable.setRolloverForeground(null);
475: }
476: });
477: controlsColumn.addButton("Set Rollover Background",
478: new ActionListener() {
479: public void actionPerformed(ActionEvent e) {
480: testTable.setRolloverBackground(StyleUtil
481: .randomColor());
482: }
483: });
484: controlsColumn.addButton("Clear Rollover Background",
485: new ActionListener() {
486: public void actionPerformed(ActionEvent e) {
487: testTable.setRolloverBackground(null);
488: }
489: });
490: controlsColumn.addButton("Set Rollover Font",
491: new ActionListener() {
492: public void actionPerformed(ActionEvent e) {
493: testTable.setRolloverFont(StyleUtil
494: .randomFont());
495: }
496: });
497: controlsColumn.addButton("Clear Rollover Font",
498: new ActionListener() {
499: public void actionPerformed(ActionEvent e) {
500: testTable.setRolloverFont(null);
501: }
502: });
503: controlsColumn.addButton("Set Rollover Background Image",
504: new ActionListener() {
505: public void actionPerformed(ActionEvent e) {
506: testTable
507: .setRolloverBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
508: }
509: });
510: controlsColumn.addButton("Clear Rollover Background Image",
511: new ActionListener() {
512: public void actionPerformed(ActionEvent e) {
513: testTable.setRolloverBackgroundImage(null);
514: }
515: });
516:
517: // Selection Settings
518:
519: controlsColumn = new ButtonColumn();
520: groupContainerColumn.add(controlsColumn);
521:
522: controlsColumn.add(new Label("Selection"));
523:
524: controlsColumn.addButton("Enable Selection",
525: new ActionListener() {
526: public void actionPerformed(ActionEvent e) {
527: testTable.setSelectionEnabled(true);
528: }
529: });
530: controlsColumn.addButton("Disable Selection",
531: new ActionListener() {
532: public void actionPerformed(ActionEvent e) {
533: testTable.setSelectionEnabled(false);
534: }
535: });
536: controlsColumn.addButton("Set SelectionMode = Single",
537: new ActionListener() {
538: public void actionPerformed(ActionEvent e) {
539: testTable.getSelectionModel().setSelectionMode(
540: ListSelectionModel.SINGLE_SELECTION);
541: }
542: });
543: controlsColumn.addButton("Set SelectionMode = Multiple",
544: new ActionListener() {
545: public void actionPerformed(ActionEvent e) {
546: testTable.getSelectionModel().setSelectionMode(
547: ListSelectionModel.MULTIPLE_SELECTION);
548: }
549: });
550: controlsColumn.addButton("Toggle Selection of Row #2",
551: new ActionListener() {
552: public void actionPerformed(ActionEvent e) {
553: ListSelectionModel selectionModel = testTable
554: .getSelectionModel();
555: selectionModel.setSelectedIndex(2,
556: !selectionModel.isSelectedIndex(2));
557: }
558: });
559: controlsColumn.addButton(
560: "Toggle Selection of Row #500 (there isn't one)",
561: new ActionListener() {
562: public void actionPerformed(ActionEvent e) {
563: ListSelectionModel selectionModel = testTable
564: .getSelectionModel();
565: selectionModel.setSelectedIndex(500,
566: !selectionModel.isSelectedIndex(500));
567: }
568: });
569: controlsColumn.addButton("Set Selection Foreground",
570: new ActionListener() {
571: public void actionPerformed(ActionEvent e) {
572: testTable.setSelectionForeground(StyleUtil
573: .randomColor());
574: }
575: });
576: controlsColumn.addButton("Clear Selection Foreground",
577: new ActionListener() {
578: public void actionPerformed(ActionEvent e) {
579: testTable.setSelectionForeground(null);
580: }
581: });
582: controlsColumn.addButton("Set Selection Background",
583: new ActionListener() {
584: public void actionPerformed(ActionEvent e) {
585: testTable.setSelectionBackground(StyleUtil
586: .randomColor());
587: }
588: });
589: controlsColumn.addButton("Clear Selection Background",
590: new ActionListener() {
591: public void actionPerformed(ActionEvent e) {
592: testTable.setSelectionBackground(null);
593: }
594: });
595: controlsColumn.addButton("Set Selection Font",
596: new ActionListener() {
597: public void actionPerformed(ActionEvent e) {
598: testTable.setSelectionFont(StyleUtil
599: .randomFont());
600: }
601: });
602: controlsColumn.addButton("Clear Selection Font",
603: new ActionListener() {
604: public void actionPerformed(ActionEvent e) {
605: testTable.setSelectionFont(null);
606: }
607: });
608: controlsColumn.addButton("Set Selection Background Image",
609: new ActionListener() {
610: public void actionPerformed(ActionEvent e) {
611: testTable
612: .setSelectionBackgroundImage(Styles.BUTTON_PRESSED_BACKGROUND_IMAGE);
613: }
614: });
615: controlsColumn.addButton("Clear Selection Background Image",
616: new ActionListener() {
617: public void actionPerformed(ActionEvent e) {
618: testTable.setSelectionBackgroundImage(null);
619: }
620: });
621:
622: // Listener Settings
623:
624: controlsColumn = new ButtonColumn();
625: groupContainerColumn.add(controlsColumn);
626:
627: controlsColumn.add(new Label("Listeners"));
628:
629: controlsColumn.addButton("Add ActionListener",
630: new ActionListener() {
631: public void actionPerformed(ActionEvent e) {
632: testTable.addActionListener(actionListener);
633: }
634: });
635: controlsColumn.addButton("Remove ActionListener",
636: new ActionListener() {
637: public void actionPerformed(ActionEvent e) {
638: testTable.removeActionListener(actionListener);
639: }
640: });
641: controlsColumn.addButton("Add ChangeListener",
642: new ActionListener() {
643: public void actionPerformed(ActionEvent e) {
644: testTable.getSelectionModel()
645: .addChangeListener(changeListener);
646: }
647: });
648: controlsColumn.addButton("Remove ChangeListener",
649: new ActionListener() {
650: public void actionPerformed(ActionEvent e) {
651: testTable.getSelectionModel()
652: .removeChangeListener(changeListener);
653: }
654: });
655:
656: // Cell Settings
657:
658: controlsColumn = new ButtonColumn();
659: groupContainerColumn.add(controlsColumn);
660:
661: controlsColumn.add(new Label("Cell Renderer"));
662:
663: controlsColumn.addButton("Default Cell Renderer",
664: new ActionListener() {
665: public void actionPerformed(ActionEvent e) {
666: testTable.setDefaultRenderer(Object.class,
667: new DefaultTableCellRenderer());
668: }
669: });
670: controlsColumn.addButton("Randomizing Cell Renderer",
671: new ActionListener() {
672: public void actionPerformed(ActionEvent e) {
673: testTable.setDefaultRenderer(Object.class,
674: randomizingCellRenderer);
675: }
676: });
677: controlsColumn.addButton(
678: "BackgroundImage Checker Cell Renderer",
679: new ActionListener() {
680: public void actionPerformed(ActionEvent e) {
681: testTable.setDefaultRenderer(Object.class,
682: backgroundImageCheckerCellRenderer);
683: }
684: });
685: controlsColumn.addButton("Visibility Checker Cell Renderer",
686: new ActionListener() {
687: public void actionPerformed(ActionEvent e) {
688: testTable.setDefaultRenderer(Object.class,
689: visibilityCheckerCellRenderer);
690: }
691: });
692: controlsColumn.addButton(
693: "Editing Cell Renderer (not bound to model)",
694: new ActionListener() {
695: public void actionPerformed(ActionEvent e) {
696: testTable.setDefaultRenderer(Object.class,
697: editingTableCellRenderer);
698: }
699: });
700: controlsColumn.addButton("Alignment = Leading/Top",
701: new ActionListener() {
702: public void actionPerformed(ActionEvent e) {
703: testTable.setDefaultRenderer(Object.class,
704: createTableCellRenderer(new Alignment(
705: Alignment.LEADING,
706: Alignment.TOP)));
707: }
708: });
709: controlsColumn.addButton("Alignment = Trailing/Bottom",
710: new ActionListener() {
711: public void actionPerformed(ActionEvent e) {
712: testTable.setDefaultRenderer(Object.class,
713: createTableCellRenderer(new Alignment(
714: Alignment.TRAILING,
715: Alignment.BOTTOM)));
716: }
717: });
718: controlsColumn.addButton("Alignment = Left/Top",
719: new ActionListener() {
720: public void actionPerformed(ActionEvent e) {
721: testTable
722: .setDefaultRenderer(
723: Object.class,
724: createTableCellRenderer(new Alignment(
725: Alignment.LEFT,
726: Alignment.TOP)));
727: }
728: });
729: controlsColumn.addButton("Alignment = Right/Bottom",
730: new ActionListener() {
731: public void actionPerformed(ActionEvent e) {
732: testTable.setDefaultRenderer(Object.class,
733: createTableCellRenderer(new Alignment(
734: Alignment.RIGHT,
735: Alignment.BOTTOM)));
736: }
737: });
738: }
739:
740: private TableCellRenderer createTableCellRenderer(
741: final Alignment alignment) {
742: return new TableCellRenderer() {
743:
744: /**
745: * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
746: * java.lang.Object, int, int)
747: */
748: public Component getTableCellRendererComponent(Table table,
749: Object value, int column, int row) {
750: Label label = new Label(value == null ? null : value
751: .toString());
752: TableLayoutData layoutData = new TableLayoutData();
753: layoutData.setAlignment(alignment);
754: label.setLayoutData(layoutData);
755: return label;
756: }
757: };
758: }
759:
760: }
|