001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.vmd.midpnb.propertyeditors.table;
043:
044: import java.awt.Color;
045: import java.awt.Component;
046: import java.util.ArrayList;
047: import java.util.Arrays;
048: import java.util.List;
049: import java.util.Map;
050: import java.util.Vector;
051: import javax.swing.JComponent;
052: import javax.swing.JTable;
053: import javax.swing.event.TableModelEvent;
054: import javax.swing.event.TableModelListener;
055: import javax.swing.table.DefaultTableCellRenderer;
056: import javax.swing.table.TableCellRenderer;
057: import javax.swing.table.TableColumnModel;
058: import org.netbeans.modules.vmd.api.model.Debug;
059: import org.netbeans.modules.vmd.api.model.DesignComponent;
060: import org.netbeans.modules.vmd.api.model.PropertyValue;
061: import org.netbeans.modules.vmd.api.model.TypeID;
062: import org.netbeans.modules.vmd.midp.components.MidpTypes;
063: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.element.PropertyEditorResourceElement;
064: import org.netbeans.modules.vmd.midpnb.components.resources.SimpleTableModelCD;
065:
066: /**
067: *
068: * @author Anton Chechel
069: */
070: public class TableModelEditorElement extends
071: PropertyEditorResourceElement implements TableModelListener {
072:
073: private boolean doNotFireEvent;
074: private long componentID;
075: private CustomEditorTableModel tableModel;
076: private TableCellRenderer renderer;
077:
078: public TableModelEditorElement() {
079: tableModel = new CustomEditorTableModel();
080: tableModel.addTableModelListener(this );
081: initComponents();
082: renderer = new HeaderCellRenderer();
083: setTableCellRenderer();
084: }
085:
086: public JComponent getJComponent() {
087: return this ;
088: }
089:
090: public TypeID getTypeID() {
091: return SimpleTableModelCD.TYPEID;
092: }
093:
094: public List<String> getPropertyValueNames() {
095: return Arrays.asList(new String[] {
096: SimpleTableModelCD.PROP_COLUMN_NAMES,
097: SimpleTableModelCD.PROP_VALUES });
098: }
099:
100: @Override
101: public String getResourceNameSuggestion() {
102: return "tableModel"; // NOI18N
103: }
104:
105: public void setDesignComponentWrapper(
106: final DesignComponentWrapper wrapper) {
107: if (wrapper == null) {
108: // UI stuff
109: setTableValues(null, null);
110: setAllEnabled(false);
111: return;
112: }
113:
114: this .componentID = wrapper.getComponentID();
115: final PropertyValue[] columns = new PropertyValue[1];
116: final PropertyValue[] values = new PropertyValue[1];
117:
118: final DesignComponent component = wrapper.getComponent();
119: if (component != null) {
120: // existing component
121: if (!component.getType().equals(getTypeID())) {
122: throw new IllegalArgumentException(
123: "Passed component must have typeID "
124: + getTypeID() + " instead passed "
125: + component.getType()); // NOI18N
126: }
127:
128: this .componentID = component.getComponentID();
129: component.getDocument().getTransactionManager().readAccess(
130: new Runnable() {
131:
132: public void run() {
133: PropertyValue propertyValue = component
134: .readProperty(SimpleTableModelCD.PROP_COLUMN_NAMES);
135: if (!isPropertyValueAUserCodeType(propertyValue)) {
136: columns[0] = propertyValue;
137: }
138: PropertyValue propertyValue2 = component
139: .readProperty(SimpleTableModelCD.PROP_VALUES);
140: if (!isPropertyValueAUserCodeType(propertyValue2)) {
141: values[0] = propertyValue2;
142: }
143: }
144: });
145: }
146:
147: if (wrapper.hasChanges()) {
148: Map<String, PropertyValue> changes = wrapper.getChanges();
149: for (String propertyName : changes.keySet()) {
150: final PropertyValue propertyValue = changes
151: .get(propertyName);
152: if (SimpleTableModelCD.PROP_VALUES.equals(propertyName)) {
153: values[0] = propertyValue;
154: } else if (SimpleTableModelCD.PROP_COLUMN_NAMES
155: .equals(propertyName)) {
156: columns[0] = propertyValue;
157: }
158: }
159: }
160:
161: // UI stuff
162: setAllEnabled(true);
163: setTableValues(columns[0], values[0]);
164: checkButtons();
165: }
166:
167: public synchronized void tableChanged(TableModelEvent e) {
168: setTableCellRenderer();
169: // if (isShowing() && !doNotFireEvent) {
170: if (!doNotFireEvent) {
171: Vector dataVector = tableModel.getDataVector();
172: boolean useHeader = tableModel.hasHeader();
173:
174: // if (useHeader && dataVector.size() > 0 && ((Vector) dataVector.get(0)).size() != tableModel.getHeader().size()) {
175: // // TODO debug only
176: // Debug.illegalState("Headers size must be qual to column count!"); // NOI18N
177: // }
178: setTextFields(dataVector.size(), tableModel
179: .getColumnCount());
180: checkButtons();
181:
182: List<PropertyValue> propertyValueColumn = new ArrayList<PropertyValue>(
183: dataVector.size());
184: for (int i = 0; i < dataVector.size(); i++) {
185: Vector row = (Vector) dataVector.elementAt(i);
186: List<PropertyValue> propertyValueRow = new ArrayList<PropertyValue>(
187: row.size());
188: for (int j = 0; j < row.size(); j++) {
189: String str = (String) row.elementAt(j);
190: propertyValueRow.add(MidpTypes
191: .createStringValue(str != null ? str : "")); // NOI18N
192: }
193: propertyValueColumn.add(PropertyValue.createArray(
194: MidpTypes.TYPEID_JAVA_LANG_STRING,
195: propertyValueRow));
196: }
197:
198: PropertyValue values = PropertyValue.createArray(
199: MidpTypes.TYPEID_JAVA_LANG_STRING.getArrayType(),
200: propertyValueColumn);
201: fireElementChanged(componentID,
202: SimpleTableModelCD.PROP_VALUES, values);
203:
204: PropertyValue headers;
205: if (useHeader) {
206: Vector<String> header = tableModel.getHeader();
207: List<PropertyValue> propertyValueHeader = new ArrayList<PropertyValue>(
208: header.size());
209: for (int j = 0; j < header.size(); j++) {
210: String str = header.elementAt(j);
211: propertyValueHeader.add(MidpTypes
212: .createStringValue(str != null ? str : "")); // NOI18N
213: }
214: headers = PropertyValue.createArray(
215: MidpTypes.TYPEID_JAVA_LANG_STRING,
216: propertyValueHeader);
217: } else {
218: headers = PropertyValue.createNull();
219: }
220: fireElementChanged(componentID,
221: SimpleTableModelCD.PROP_COLUMN_NAMES, headers);
222: }
223: }
224:
225: private void setTableCellRenderer() {
226: TableColumnModel columnModel = table.getColumnModel();
227: for (int i = 0; i < columnModel.getColumnCount(); i++) {
228: columnModel.getColumn(i).setCellRenderer(renderer);
229: }
230: }
231:
232: private synchronized void setTableValues(PropertyValue columns,
233: PropertyValue values) {
234: doNotFireEvent = true;
235:
236: boolean useHeader = (columns != null)
237: && (columns.getArray() != null);
238: String[] header = null;
239: String[][] arrays = null;
240:
241: if (useHeader) {
242: List<PropertyValue> list = columns.getArray();
243: header = new String[list.size()];
244: for (int i = 0; i < list.size(); i++) {
245: header[i] = MidpTypes.getString(list.get(i));
246: }
247: }
248:
249: if (values == null) {
250: tableModel.clear();
251: setTextFields(0, 0);
252: } else {
253: List<PropertyValue> rows = values.getArray();
254: if (rows != null && rows.size() > 0) {
255: List<PropertyValue> cols = rows.get(0).getArray();
256: int rowCount = rows.size();
257: int columnCount = cols.size();
258: arrays = new String[rowCount][columnCount];
259:
260: for (int x = 0; x < rowCount; x++) {
261: cols = rows.get(x).getArray();
262: for (int y = 0; y < columnCount; y++) {
263: arrays[x][y] = MidpTypes.getString(cols.get(y));
264: }
265: }
266: setTextFields(rowCount, columnCount);
267: } else {
268: setTextFields(0, 0);
269: }
270: }
271:
272: tableModel.setUseHeader(useHeader);
273: headerCheckBox.setSelected(useHeader);
274: tableModel.setDataVector(arrays, header);
275:
276: doNotFireEvent = false;
277: }
278:
279: private void checkButtons() {
280: removeRowButton
281: .setEnabled(tableModel.getDataVector().size() > 0);
282: removeColButton.setEnabled(tableModel.getColumnCount() > 0);
283: addColButton.setEnabled(tableModel.hasHeader()
284: || tableModel.getRowCount() > 0);
285: }
286:
287: void setAllEnabled(boolean isEnabled) {
288: addColButton.setEnabled(isEnabled);
289: addRowButton.setEnabled(isEnabled);
290: removeColButton.setEnabled(isEnabled);
291: removeRowButton.setEnabled(isEnabled);
292: tableLabel.setEnabled(isEnabled);
293: table.setEnabled(isEnabled);
294: headerCheckBox.setEnabled(isEnabled);
295: rowsLabel.setEnabled(isEnabled);
296: columnsLabel.setEnabled(isEnabled);
297: rowsTextField.setEnabled(isEnabled);
298: columnsTextField.setEnabled(isEnabled);
299: }
300:
301: private void setTextFields(int row, int col) {
302: rowsTextField.setText(row > -1 ? String.valueOf(row) : "-"); // NOI18N
303: columnsTextField.setText(col > -1 ? String.valueOf(col) : "-"); // NOI18N
304: }
305:
306: private class HeaderCellRenderer extends DefaultTableCellRenderer {
307:
308: @Override
309: public Component getTableCellRendererComponent(JTable table,
310: Object value, boolean isSelected, boolean hasFocus,
311: int row, int column) {
312: Component renderer = super .getTableCellRendererComponent(
313: table, value, isSelected, hasFocus, row, column);
314: if (tableModel.hasHeader() && row == 0) {
315: renderer.setBackground(Color.LIGHT_GRAY);
316: } else {
317: renderer.setBackground(Color.WHITE);
318: }
319: renderer.setForeground(Color.BLACK);
320: return renderer;
321: }
322: }
323:
324: /** This method is called from within the constructor to
325: * initialize the form.
326: * WARNING: Do NOT modify this code. The content of this method is
327: * always regenerated by the Form Editor.
328: */
329: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
330: private void initComponents() {
331:
332: jTextField1 = new javax.swing.JTextField();
333: tableLabel = new javax.swing.JLabel();
334: jPanel1 = new javax.swing.JPanel();
335: jScrollPane1 = new javax.swing.JScrollPane();
336: table = new javax.swing.JTable();
337: addColButton = new javax.swing.JButton();
338: removeColButton = new javax.swing.JButton();
339: removeRowButton = new javax.swing.JButton();
340: addRowButton = new javax.swing.JButton();
341: headerCheckBox = new javax.swing.JCheckBox();
342: rowsLabel = new javax.swing.JLabel();
343: rowsTextField = new javax.swing.JTextField();
344: columnsLabel = new javax.swing.JLabel();
345: columnsTextField = new javax.swing.JTextField();
346:
347: jTextField1.setText(org.openide.util.NbBundle.getMessage(
348: TableModelEditorElement.class,
349: "TableModelEditorElement.jTextField1.text")); // NOI18N
350:
351: tableLabel.setLabelFor(table);
352: org.openide.awt.Mnemonics.setLocalizedText(tableLabel,
353: org.openide.util.NbBundle.getMessage(
354: TableModelEditorElement.class,
355: "TableModelEditorElement.tableLabel.text")); // NOI18N
356: tableLabel.setEnabled(false);
357:
358: table.setModel(tableModel);
359: table.setEnabled(false);
360: table.setTableHeader(null);
361: jScrollPane1.setViewportView(table);
362:
363: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
364: jPanel1);
365: jPanel1.setLayout(jPanel1Layout);
366: jPanel1Layout
367: .setHorizontalGroup(jPanel1Layout
368: .createParallelGroup(
369: org.jdesktop.layout.GroupLayout.LEADING)
370: .add(
371: jPanel1Layout
372: .createSequentialGroup()
373: .add(
374: jScrollPane1,
375: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
376: 400, Short.MAX_VALUE)
377: .addContainerGap()));
378: jPanel1Layout.setVerticalGroup(jPanel1Layout
379: .createParallelGroup(
380: org.jdesktop.layout.GroupLayout.LEADING).add(
381: jScrollPane1,
382: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
383: 239, Short.MAX_VALUE));
384:
385: org.openide.awt.Mnemonics.setLocalizedText(addColButton,
386: org.openide.util.NbBundle.getMessage(
387: TableModelEditorElement.class,
388: "TableModelEditorElement.addColButton.text")); // NOI18N
389: addColButton.setEnabled(false);
390: addColButton
391: .addActionListener(new java.awt.event.ActionListener() {
392: public void actionPerformed(
393: java.awt.event.ActionEvent evt) {
394: addColButtonActionPerformed(evt);
395: }
396: });
397:
398: org.openide.awt.Mnemonics
399: .setLocalizedText(
400: removeColButton,
401: org.openide.util.NbBundle
402: .getMessage(
403: TableModelEditorElement.class,
404: "TableModelEditorElement.removeColButton.text")); // NOI18N
405: removeColButton.setEnabled(false);
406: removeColButton
407: .addActionListener(new java.awt.event.ActionListener() {
408: public void actionPerformed(
409: java.awt.event.ActionEvent evt) {
410: removeColButtonActionPerformed(evt);
411: }
412: });
413:
414: org.openide.awt.Mnemonics
415: .setLocalizedText(
416: removeRowButton,
417: org.openide.util.NbBundle
418: .getMessage(
419: TableModelEditorElement.class,
420: "TableModelEditorElement.removeRowButton.text")); // NOI18N
421: removeRowButton.setEnabled(false);
422: removeRowButton
423: .addActionListener(new java.awt.event.ActionListener() {
424: public void actionPerformed(
425: java.awt.event.ActionEvent evt) {
426: removeRowButtonActionPerformed(evt);
427: }
428: });
429:
430: org.openide.awt.Mnemonics.setLocalizedText(addRowButton,
431: org.openide.util.NbBundle.getMessage(
432: TableModelEditorElement.class,
433: "TableModelEditorElement.addRowButton.text")); // NOI18N
434: addRowButton.setEnabled(false);
435: addRowButton
436: .addActionListener(new java.awt.event.ActionListener() {
437: public void actionPerformed(
438: java.awt.event.ActionEvent evt) {
439: addRowButtonActionPerformed(evt);
440: }
441: });
442:
443: org.openide.awt.Mnemonics.setLocalizedText(headerCheckBox,
444: org.openide.util.NbBundle.getMessage(
445: TableModelEditorElement.class,
446: "TableModelEditorElement.headerCheckBox.text")); // NOI18N
447: headerCheckBox.setBorder(javax.swing.BorderFactory
448: .createEmptyBorder(0, 0, 0, 0));
449: headerCheckBox.setEnabled(false);
450: headerCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
451: headerCheckBox
452: .addActionListener(new java.awt.event.ActionListener() {
453: public void actionPerformed(
454: java.awt.event.ActionEvent evt) {
455: headerCheckBoxActionPerformed(evt);
456: }
457: });
458:
459: rowsLabel.setLabelFor(rowsTextField);
460: rowsLabel.setText(org.openide.util.NbBundle.getMessage(
461: TableModelEditorElement.class,
462: "TableModelEditorElement.rowsLabel.text")); // NOI18N
463: rowsLabel.setEnabled(false);
464:
465: rowsTextField.setEditable(false);
466: rowsTextField.setEnabled(false);
467:
468: columnsLabel.setLabelFor(columnsTextField);
469: columnsLabel.setText(org.openide.util.NbBundle.getMessage(
470: TableModelEditorElement.class,
471: "TableModelEditorElement.columnsLabel.text")); // NOI18N
472: columnsLabel.setEnabled(false);
473:
474: columnsTextField.setEditable(false);
475: columnsTextField.setEnabled(false);
476:
477: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
478: this );
479: this .setLayout(layout);
480: layout
481: .setHorizontalGroup(layout
482: .createParallelGroup(
483: org.jdesktop.layout.GroupLayout.LEADING)
484: .add(
485: layout
486: .createSequentialGroup()
487: .add(
488: layout
489: .createParallelGroup(
490: org.jdesktop.layout.GroupLayout.LEADING)
491: .add(
492: jPanel1,
493: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
494: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
495: Short.MAX_VALUE)
496: .add(
497: layout
498: .createSequentialGroup()
499: .add(
500: tableLabel)
501: .addPreferredGap(
502: org.jdesktop.layout.LayoutStyle.RELATED,
503: 349,
504: Short.MAX_VALUE)))
505: .add(0, 0, 0)
506: .add(
507: layout
508: .createParallelGroup(
509: org.jdesktop.layout.GroupLayout.TRAILING,
510: false)
511: .add(
512: org.jdesktop.layout.GroupLayout.LEADING,
513: headerCheckBox)
514: .add(
515: org.jdesktop.layout.GroupLayout.LEADING,
516: layout
517: .createSequentialGroup()
518: .add(
519: columnsLabel)
520: .addPreferredGap(
521: org.jdesktop.layout.LayoutStyle.RELATED)
522: .add(
523: columnsTextField,
524: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
525: 71,
526: Short.MAX_VALUE))
527: .add(
528: org.jdesktop.layout.GroupLayout.LEADING,
529: layout
530: .createSequentialGroup()
531: .add(
532: rowsLabel)
533: .add(
534: 18,
535: 18,
536: 18)
537: .add(
538: rowsTextField,
539: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
540: 71,
541: Short.MAX_VALUE))
542: .add(
543: removeColButton,
544: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
545: 119,
546: Short.MAX_VALUE)
547: .add(
548: removeRowButton,
549: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
550: 119,
551: Short.MAX_VALUE)
552: .add(
553: addRowButton,
554: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
555: 119,
556: Short.MAX_VALUE)
557: .add(
558: addColButton,
559: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
560: 119,
561: Short.MAX_VALUE))));
562: layout
563: .setVerticalGroup(layout
564: .createParallelGroup(
565: org.jdesktop.layout.GroupLayout.LEADING)
566: .add(
567: layout
568: .createSequentialGroup()
569: .add(tableLabel)
570: .addPreferredGap(
571: org.jdesktop.layout.LayoutStyle.RELATED)
572: .add(
573: layout
574: .createParallelGroup(
575: org.jdesktop.layout.GroupLayout.LEADING)
576: .add(
577: layout
578: .createSequentialGroup()
579: .add(
580: headerCheckBox,
581: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
582: 15,
583: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
584: .addPreferredGap(
585: org.jdesktop.layout.LayoutStyle.UNRELATED)
586: .add(
587: layout
588: .createParallelGroup(
589: org.jdesktop.layout.GroupLayout.BASELINE)
590: .add(
591: rowsLabel)
592: .add(
593: rowsTextField,
594: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
595: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
596: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
597: .add(
598: 6,
599: 6,
600: 6)
601: .add(
602: layout
603: .createParallelGroup(
604: org.jdesktop.layout.GroupLayout.BASELINE)
605: .add(
606: columnsLabel)
607: .add(
608: columnsTextField,
609: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
610: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
611: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
612: .addPreferredGap(
613: org.jdesktop.layout.LayoutStyle.UNRELATED)
614: .add(
615: addRowButton)
616: .addPreferredGap(
617: org.jdesktop.layout.LayoutStyle.RELATED)
618: .add(
619: removeRowButton)
620: .addPreferredGap(
621: org.jdesktop.layout.LayoutStyle.RELATED)
622: .add(
623: addColButton)
624: .addPreferredGap(
625: org.jdesktop.layout.LayoutStyle.RELATED)
626: .add(
627: removeColButton)
628: .addContainerGap())
629: .add(
630: jPanel1,
631: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
632: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
633: Short.MAX_VALUE))));
634:
635: tableLabel
636: .getAccessibleContext()
637: .setAccessibleName(
638: org.openide.util.NbBundle
639: .getMessage(
640: TableModelEditorElement.class,
641: "TableModelEditorElement.tableLabel.accessible.name")); // NOI18N
642: tableLabel
643: .getAccessibleContext()
644: .setAccessibleDescription(
645: org.openide.util.NbBundle
646: .getMessage(
647: TableModelEditorElement.class,
648: "TableModelEditorElement.tableLabel.accessible.description")); // NOI18N
649: addColButton
650: .getAccessibleContext()
651: .setAccessibleName(
652: org.openide.util.NbBundle
653: .getMessage(
654: TableModelEditorElement.class,
655: "TableModelEditorElement.addColButton.accessible.name")); // NOI18N
656: addColButton
657: .getAccessibleContext()
658: .setAccessibleDescription(
659: org.openide.util.NbBundle
660: .getMessage(
661: TableModelEditorElement.class,
662: "TableModelEditorElement.addColButton.accessible.description")); // NOI18N
663: removeColButton
664: .getAccessibleContext()
665: .setAccessibleName(
666: org.openide.util.NbBundle
667: .getMessage(
668: TableModelEditorElement.class,
669: "TableModelEditorElement.removeColButton.accessible.name")); // NOI18N
670: removeColButton
671: .getAccessibleContext()
672: .setAccessibleDescription(
673: org.openide.util.NbBundle
674: .getMessage(
675: TableModelEditorElement.class,
676: "TableModelEditorElement.removeColButton.accessible.descriptions")); // NOI18N
677: removeRowButton
678: .getAccessibleContext()
679: .setAccessibleName(
680: org.openide.util.NbBundle
681: .getMessage(
682: TableModelEditorElement.class,
683: "TableModelEditorElement.removeRowButton.accessible.name")); // NOI18N
684: removeRowButton
685: .getAccessibleContext()
686: .setAccessibleDescription(
687: org.openide.util.NbBundle
688: .getMessage(
689: TableModelEditorElement.class,
690: "TableModelEditorElement.removeRowButton.accessible.description")); // NOI18N
691: addRowButton
692: .getAccessibleContext()
693: .setAccessibleName(
694: org.openide.util.NbBundle
695: .getMessage(
696: TableModelEditorElement.class,
697: "TableModelEditorElement.addRowButton.accessible.name")); // NOI18N
698: addRowButton
699: .getAccessibleContext()
700: .setAccessibleDescription(
701: org.openide.util.NbBundle
702: .getMessage(
703: TableModelEditorElement.class,
704: "TableModelEditorElement.addRowButton.accessible.description")); // NOI18N
705: headerCheckBox
706: .getAccessibleContext()
707: .setAccessibleName(
708: org.openide.util.NbBundle
709: .getMessage(
710: TableModelEditorElement.class,
711: "TableModelEditorElement.headerCheckBox.accessible.name")); // NOI18N
712: headerCheckBox
713: .getAccessibleContext()
714: .setAccessibleDescription(
715: org.openide.util.NbBundle
716: .getMessage(
717: TableModelEditorElement.class,
718: "TableModelEditorElement.headerCheckBox.accessible.description")); // NOI18N
719: rowsLabel
720: .getAccessibleContext()
721: .setAccessibleName(
722: org.openide.util.NbBundle
723: .getMessage(
724: TableModelEditorElement.class,
725: "TableModelEditorElement.rowsLabel.accessible.name")); // NOI18N
726: rowsLabel
727: .getAccessibleContext()
728: .setAccessibleDescription(
729: org.openide.util.NbBundle
730: .getMessage(
731: TableModelEditorElement.class,
732: "TableModelEditorElement.rowsLabel.accessible.description")); // NOI18N
733: columnsLabel
734: .getAccessibleContext()
735: .setAccessibleName(
736: org.openide.util.NbBundle
737: .getMessage(
738: TableModelEditorElement.class,
739: "TableModelEditorElement.columnsLabel.accessible.name")); // NOI18N
740: columnsLabel
741: .getAccessibleContext()
742: .setAccessibleDescription(
743: org.openide.util.NbBundle
744: .getMessage(
745: TableModelEditorElement.class,
746: "TableModelEditorElement.columnsLabel.accessible.description")); // NOI18N
747: }// </editor-fold>//GEN-END:initComponents
748:
749: private void addColButtonActionPerformed(
750: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addColButtonActionPerformed
751: tableModel.addColumn("", false); // NOI18N//GEN-LAST:event_addColButtonActionPerformed
752: }
753:
754: private void removeColButtonActionPerformed(
755: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeColButtonActionPerformed
756: tableModel.removeLastColumn();
757: }//GEN-LAST:event_removeColButtonActionPerformed
758:
759: private void removeRowButtonActionPerformed(
760: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeRowButtonActionPerformed
761: int rowCount = tableModel.getDataVector().size();
762: if (rowCount > 0) {
763: tableModel.removeRow(rowCount - 1);
764: }
765: }//GEN-LAST:event_removeRowButtonActionPerformed
766:
767: private void addRowButtonActionPerformed(
768: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRowButtonActionPerformed
769: int columnCount = tableModel.getColumnCount();
770: if (columnCount == 0) {
771: tableModel.addColumn("", true); // NOI18N
772: } else {
773: String[] row = new String[columnCount];
774: for (int i = 0; i < row.length; i++) {
775: row[i] = ""; // NOI18N
776: }
777: tableModel.addRow(row);
778: }
779: }//GEN-LAST:event_addRowButtonActionPerformed
780:
781: private void headerCheckBoxActionPerformed(
782: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_headerCheckBoxActionPerformed
783: tableModel.setUseHeader(headerCheckBox.isSelected());
784: }//GEN-LAST:event_headerCheckBoxActionPerformed
785:
786: // Variables declaration - do not modify//GEN-BEGIN:variables
787: private javax.swing.JButton addColButton;
788: private javax.swing.JButton addRowButton;
789: private javax.swing.JLabel columnsLabel;
790: private javax.swing.JTextField columnsTextField;
791: private javax.swing.JCheckBox headerCheckBox;
792: private javax.swing.JPanel jPanel1;
793: private javax.swing.JScrollPane jScrollPane1;
794: private javax.swing.JTextField jTextField1;
795: private javax.swing.JButton removeColButton;
796: private javax.swing.JButton removeRowButton;
797: private javax.swing.JLabel rowsLabel;
798: private javax.swing.JTextField rowsTextField;
799: private javax.swing.JTable table;
800: private javax.swing.JLabel tableLabel;
801: // End of variables declaration//GEN-END:variables
802: }
|