1 /*
2 * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package p3j.gui.panels.matrices;
17
18 import net.sf.jeppers.grid.AbstractGridModel;
19 import net.sf.jeppers.grid.RulerModel;
20
21 /**
22 *
23 * A model implementation for grid headers. Applies to both row and column
24 * headers.
25 *
26 * Created on January 14, 2007
27 *
28 * @author Christina Bohk
29 * @author Roland Ewald
30 *
31 */
32 public class GridHeaderModel extends AbstractGridModel {
33
34 /** Prefix to be displayed in all columns. */
35 private String prefix;
36
37 /** Flag that indicates to start enumerating with one. */
38 private boolean startsWith1;
39
40 /** Flag that indicates that indices should be suppressed. */
41 private boolean surpressIndex;
42
43 /** True if this is a column header. */
44 private boolean isColumn = true;
45
46 /** Reference to ruler model. */
47 private RulerModel ruler;
48
49 /**
50 * Default constructor.
51 *
52 * @param columnModel
53 * column model
54 * @param pref
55 * prefix
56 * @param sw1
57 * flag to indicate whether enumeration starts with 1
58 * @param isCol
59 * true, if this header model is for a column
60 */
61 public GridHeaderModel(RulerModel columnModel, String pref, boolean sw1,
62 boolean isCol) {
63 ruler = columnModel;
64 this.prefix = pref;
65 this.surpressIndex = (this.prefix.length() == 0);
66 this.startsWith1 = sw1;
67 this.isColumn = isCol;
68 }
69
70 @Override
71 public Object getValueAt(int row, int column) {
72 return this.surpressIndex ? "" : prefix
73 + ((isColumn ? column : row) + (startsWith1 ? 1 : 0));
74 }
75
76 @Override
77 public boolean isCellEditable(int row, int column) {
78 return false;
79 }
80
81 @Override
82 public void setValueAt(Object value, int row, int column) {
83 }
84
85 @Override
86 public int getRowCount() {
87 return ruler.getCount();
88 }
89
90 @Override
91 public int getColumnCount() {
92 return ruler.getCount();
93 }
94 }