]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetNode.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / SheetNode.java
1 package org.simantics.spreadsheet.ui;
2
3 import java.awt.Graphics2D;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.FocusListener;
7 import java.awt.geom.Rectangle2D;
8
9 import javax.swing.JComponent;
10
11 import org.simantics.scenegraph.swing.ComponentNode;
12 import org.simantics.spreadsheet.Adaptable;
13 import org.simantics.spreadsheet.ClientModel;
14
15 public class SheetNode extends ComponentNode<JComponent> implements ActionListener, FocusListener {
16
17     private static final long serialVersionUID = -8212264868316567181L;
18
19     private SpreadsheetModel sm;
20
21     public void init(Adaptable serverInterface) {
22
23         scale = true;
24         sm = new SpreadsheetModel(serverInterface, null);
25         component =  sm.createComponent(this);
26         component.addFocusListener(this);
27         
28         super.init();
29
30     }
31     
32     public ClientModel getModifier() {
33         return sm.getClientInterface();
34     }
35
36     protected ActionListener actionListener = null;
37
38     public void setActionListener(ActionListener actionListener) {
39         this.actionListener = actionListener;
40     }
41
42     @ServerSide
43     @Override
44     public void actionPerformed(ActionEvent e) {
45         if(actionListener != null)
46             actionListener.actionPerformed(e);
47         if(container.getParent() != null)
48             container.getParent().requestFocusInWindow(); // Loose focus
49     }
50
51     @Override
52     @SyncField("bounds")
53     public void setBounds(Rectangle2D bounds) {
54         this.bounds = bounds;
55         container.setBounds(0, 0, (int)bounds.getWidth(), (int)bounds.getHeight());
56         container.setSize((int)bounds.getWidth(), (int)bounds.getHeight());
57         container.validate();
58     }
59     
60     @Override
61     public void render(Graphics2D g2d) {
62         
63         if(sm == null) return;
64         if(sm.getTable() == null) return;
65         
66         container.validate();
67
68         super.render(g2d);
69         
70     }
71
72 }