Revision 37573 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/gui/command/CommandStackDialog.java

View differences:

CommandStackDialog.java
32 32

  
33 33
public class CommandStackDialog extends DefaultBean implements SingletonWindow, IWindowListener,Observer{
34 34

  
35
	private JTable jTable = null;
36
	private JPanel jPanel = null;
35
	private JTable commandTable = null;
36
	private JPanel topPanel = null;
37 37
	private UndoRedoStack undoRedoStack;
38
	private JSlider jSlider = null;
39
	//private int itemCount;
38
	private JSlider commandSlider = null;
39
	
40 40
	private int lowLimit;
41
	private int currentValue=-1;
42
	private JPanel jPanel1 = null;
41
	private int currentValue = -1;
42
	private JPanel sliderPanel = null;
43 43
	protected boolean refreshing;
44
	private JPanel pCenter = null;
44
	private JPanel commandTablePanel = null;
45 45
	private JScrollPane jScrollPane = null;
46
	private static final ImageIcon imodify=PluginServices.getIconTheme()
46
	
47
	private static final ImageIcon imodify = PluginServices.getIconTheme()
47 48
		.get("edition-modify-command");
48
	private static final ImageIcon iadd= PluginServices.getIconTheme()
49
	private static final ImageIcon iadd = PluginServices.getIconTheme()
49 50
		.get("edition-add-command");
50

  
51 51
	private static final ImageIcon idel = PluginServices.getIconTheme()
52 52
		.get("edition-del-command");
53 53

  
54
	private MyModel mymodel = null;
54
	private CommandTableModel commandTableModel = null;
55 55
	/**
56 56
	 * This is the default constructor
57 57
	 */
......
59 59
		super();
60 60
		initialize();
61 61
	}
62
	public void setModel(UndoRedoStack cr1){
62
	
63
	public void setModel(UndoRedoStack cr1) {
63 64
        if (this.undoRedoStack != null) {
64 65
            if (this.undoRedoStack.equals(cr1)) {
65 66
                return;
......
67 68
                this.undoRedoStack.deleteObserver(this);
68 69
            }
69 70
		}
70
		this.undoRedoStack=cr1;
71
		this.undoRedoStack = cr1;
71 72
		this.undoRedoStack.addObserver(this);
72 73
		initTable();
73 74
		initSlider();
74
		currentValue=mymodel.getPos();
75
		currentValue = commandTableModel.getPos();
75 76
    	refreshControls();
76 77
		refreshScroll();
77 78
	}
79
	
78 80
	/**
79 81
	 * This method initializes this
80 82
	 *
......
93 95
	 * @return javax.swing.JList
94 96
	 */
95 97
	private JTable getTable() {
96
		if (jTable == null) {
97
			jTable = new JTable();
98
		if (commandTable == null) {
99
			commandTable = new JTable();
98 100
		}
99
		return jTable;
101
		return commandTable;
100 102
	}
103
	
101 104
	private void initTable(){
102
		mymodel=new MyModel(undoRedoStack);
103
		jTable.setModel(mymodel);
104
		jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
105
		jTable.setSelectionBackground(Color.orange);
106
		jTable.setSelectionForeground(Color.black);
107
		jTable.setShowGrid(false);
108
		jTable.getTableHeader().setBackground(Color.white);
109
		TableColumn tc = jTable.getColumnModel().getColumn(0);
105
		commandTableModel = new CommandTableModel(undoRedoStack);
106
		commandTable.setModel(commandTableModel);
107
		commandTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
108
		commandTable.setSelectionBackground(Color.orange);
109
		commandTable.setSelectionForeground(Color.black);
110
		commandTable.setShowGrid(false);
111
		commandTable.getTableHeader().setBackground(Color.white);
112
		TableColumn tc = commandTable.getColumnModel().getColumn(0);
110 113
		tc.setCellRenderer(new DefaultTableCellRenderer() {
111 114
			   public Component getTableCellRendererComponent(JTable table,
112 115
			                                               Object value,
......
129 132
                            default:
130 133
                                label.setIcon(imodify);
131 134
                        }
132
			         if (mymodel.getPos()<row){
135
			         if (commandTableModel.getPos()<row){
133 136
			        	 label.setBackground(Color.lightGray);
134 137
			         }else {
135 138
			       		 label.setBackground(Color.orange);
......
138 141
			      }
139 142
			});
140 143

  
141
		jTable.addMouseListener(new java.awt.event.MouseAdapter() {
144
		commandTable.addMouseListener(new java.awt.event.MouseAdapter() {
142 145
			public void mousePressed(java.awt.event.MouseEvent e) {
143
				int newpos=jTable.getSelectedRow();
144
				mymodel.setPos(newpos);
146
				int newpos=commandTable.getSelectedRow();
147
				commandTableModel.setPos(newpos);
145 148
				PluginServices.getMainFrame().enableControls();
146 149
			}
147 150
		});
......
152 155
	 * @return javax.swing.JPanel
153 156
	 */
154 157
	private JPanel getJPanel() {
155
		if (jPanel == null) {
156
			jPanel = new JPanel();
158
		if (topPanel == null) {
159
			topPanel = new JPanel();
157 160
		}
158
		return jPanel;
161
		return topPanel;
159 162
	}
160 163

  
161 164
	public WindowInfo getWindowInfo() {
......
167 170
	}
168 171

  
169 172
	public Object getWindowModel() {
170
		return mymodel.getClass().getName();
173
		return commandTableModel.getClass().getName();
171 174
	}
172 175

  
173 176
	public void windowActivated() {
......
183 186
	 * @see com.iver.cit.gvsig.fmap.edition.commands.CommandListener#executeCommand(com.iver.cit.gvsig.fmap.edition.commands.CommandEvent)
184 187
	 */
185 188
	public void commandRepaint() {
186
		setValue(mymodel.getPos()+1,true);
189
		setValue(commandTableModel.getPos()+1,true);
187 190
		refreshControls();
188 191
		refreshScroll();
189 192
	}
190 193
	private void refreshScroll(){
191
		Dimension size=new Dimension(jSlider.getPreferredSize().width,((mymodel.getRowCount())*getTable().getRowHeight()));
194
		Dimension size=new Dimension(commandSlider.getPreferredSize().width,((commandTableModel.getRowCount())*getTable().getRowHeight()));
192 195
		JScrollBar verticalScrollBar=getJScrollPane().getVerticalScrollBar();//ove(size.width,size.height);
193
		verticalScrollBar.setValue(mymodel.getPos()*getTable().getRowHeight());
194
		jSlider.setPreferredSize(size);
195
		jSlider.setSize(size);
196
		verticalScrollBar.setValue(commandTableModel.getPos()*getTable().getRowHeight());
197
		commandSlider.setPreferredSize(size);
198
		commandSlider.setSize(size);
196 199
		validateTree();
197 200
	}
201
	
198 202
	/**
199 203
	 * This method initializes jSlider
200 204
	 *
201 205
	 * @return javax.swing.JSlider
202 206
	 */
203 207
	private JSlider getJSlider() {
204
		if (jSlider == null) {
205
			jSlider = new JSlider();
208
		if (commandSlider == null) {
209
			commandSlider = new JSlider();
206 210
		}
207
		return jSlider;
211
		return commandSlider;
208 212
	}
213
	
209 214
	private void initSlider(){
210
		jSlider.setOrientation(SwingConstants.VERTICAL);
211
		jSlider.setPreferredSize(new Dimension(jSlider.getPreferredSize().width,((getTable().getRowCount())*getTable().getRowHeight())));
212
		jSlider.addMouseListener(new java.awt.event.MouseAdapter() {
215
		commandSlider.setOrientation(SwingConstants.VERTICAL);
216
		commandSlider.setPreferredSize(new Dimension(commandSlider.getPreferredSize().width,((getTable().getRowCount())*getTable().getRowHeight())));
217
		commandSlider.addMouseListener(new java.awt.event.MouseAdapter() {
213 218
                public void mouseReleased(java.awt.event.MouseEvent e) {
214 219

  
215 220
            	}
216 221
            });
217
    	jSlider.addChangeListener(new javax.swing.event.ChangeListener() {
218

  
219

  
222
    	commandSlider.addChangeListener(new javax.swing.event.ChangeListener() {
220 223
				public void stateChanged(javax.swing.event.ChangeEvent e) {
221
					int value = (int) (getJSlider().getValue() * mymodel.getRowCount() * 0.01);
224
					int value = (int) (getJSlider().getValue() * commandTableModel.getRowCount() * 0.01);
222 225
                   	if (!refreshing) {
223
						mymodel.setPos(mymodel.getRowCount()-1-value);
226
						commandTableModel.setPos(commandTableModel.getRowCount()-1-value);
224 227
						//System.out.println("setPos = "+(cr.getCommandCount()-1-value));
225 228
					}
226 229
			    }
227 230
    		});
228
    	setValue(mymodel.getRowCount()-1-mymodel.getPos(),true);
231
    	setValue(commandTableModel.getRowCount()-1-commandTableModel.getPos(),true);
229 232
	}
230 233
    public void setValue(int number, boolean fireEvent) {
231
        int rowCount=mymodel.getRowCount();
234
        int rowCount=commandTableModel.getRowCount();
232 235
        if (number < lowLimit) {
233 236
			number = lowLimit;
234 237
		}
......
253 256
     * Refreshes all the mutable controls in this component.
254 257
     */
255 258
    private void refreshControls() {
256
    	int normalizedValue = (int) (((mymodel.getRowCount()-currentValue) / (float) mymodel.getRowCount())*100);
259
    	int normalizedValue = (int) (((commandTableModel.getRowCount()-currentValue) / (float) commandTableModel.getRowCount())*100);
257 260
		refreshSlider(normalizedValue);
258
		jTable.repaint();
261
		commandTable.repaint();
259 262
	}
260 263
    /**
261 264
	 * Sets the slider to the correct (scaled) position.
......
273 276
	 * @return javax.swing.JPanel
274 277
	 */
275 278
	private JPanel getJPanel1() {
276
		if (jPanel1 == null) {
277
			jPanel1 = new JPanel();
278
			jPanel1.add(getJSlider());
279
		if (sliderPanel == null) {
280
			sliderPanel = new JPanel();
281
			sliderPanel.add(getJSlider());
279 282
		}
280
		return jPanel1;
283
		return sliderPanel;
281 284
	}
282 285

  
283 286

  
......
288 291
	 * @return javax.swing.JPanel
289 292
	 */
290 293
	private JPanel getPCenter() {
291
		if (pCenter == null) {
292
			pCenter = new JPanel();
293
			pCenter.setLayout(new BorderLayout());
294
			pCenter.add(getTable(), java.awt.BorderLayout.CENTER);
295
			pCenter.add(getJPanel1(), java.awt.BorderLayout.WEST);
294
		if (commandTablePanel == null) {
295
			commandTablePanel = new JPanel();
296
			commandTablePanel.setLayout(new BorderLayout());
297
			commandTablePanel.add(getTable(), java.awt.BorderLayout.CENTER);
298
			commandTablePanel.add(getJPanel1(), java.awt.BorderLayout.WEST);
296 299
		}
297
		return pCenter;
300
		return commandTablePanel;
298 301
	}
299 302

  
300 303
	/**

Also available in: Unified diff