1d553e23a985cd3339fc0b7c63cdc6f563189708
[Mograsim.git] / net.mograsim.plugin.core / src / net / mograsim / plugin / memory / MemoryTableContentProvider.java
1 package net.mograsim.plugin.memory;
2
3 import org.eclipse.jface.viewers.IStructuredContentProvider;
4
5 import net.mograsim.machine.MainMemory;
6
7 public class MemoryTableContentProvider implements IStructuredContentProvider
8 {
9         private long lower;
10         private int amount;
11         public final static int limit = 128;
12
13         @Override
14         public Object[] getElements(Object arg0)
15         {
16                 if (arg0 == null)
17                         return new Object[0];
18                 MainMemory memory = (MainMemory) arg0;
19                 lower = Long.max(lower, memory.getDefinition().getMinimalAddress());
20                 Object[] rows = new Object[amount];
21                 for (int i = 0; i < amount; i++)
22                         rows[i] = new MemoryTableRow(lower + i, memory);
23                 return rows;
24         }
25
26         /**
27          * Sets the bounds for the addresses in memory to be provided to the table.
28          * 
29          * @param lower  lower bound for address (inclusive)
30          * @param amount amount of cells to show; limited to {@link MemoryTableContentProvider#limit}
31          */
32         public void setAddressRange(long lower, int amount)
33         {
34                 this.lower = lower;
35                 this.amount = Integer.min(Integer.max(amount, 0), limit);
36         }
37
38         public void setLowerBound(long lower)
39         {
40                 setAddressRange(lower, amount);
41         }
42
43         public void setAmount(int amount)
44         {
45                 setAddressRange(lower, amount);
46         }
47
48         public long getLowerBound()
49         {
50                 return lower;
51         }
52
53         public int getAmount()
54         {
55                 return amount;
56         }
57 }