summaryrefslogtreecommitdiff
path: root/java/src/IceGridGUI/EditorBase.java
blob: 6b045e6745402139c5a8aa7680fd5fc5797d724e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

package IceGridGUI;

import java.awt.BorderLayout;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.ScrollPaneConstants;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.util.LayoutStyle;

//
// Base class for all editors
//
public abstract class EditorBase
{
    public JComponent getProperties()
    {
        if(_propertiesPanel == null)
        {
            buildPropertiesPanel();
        }
        return _propertiesPanel;
    }

    public JToolBar getToolBar()
    {
        return null;
    }

    protected void appendProperties(DefaultFormBuilder builder)
    {
    }
    
    protected JComponent createPropertiesPanel()
    {
        return null;
    }

    protected void buildPropertiesPanel()
    {
        JComponent contents = createPropertiesPanel();
        
        if(contents == null)
        {
            FormLayout layout = new FormLayout("right:pref, 3dlu, fill:pref:grow, 3dlu, pref", "");

            DefaultFormBuilder builder = new DefaultFormBuilder(layout);
            builder.border(Borders.DLU2);
            builder.rowGroupingEnabled(true);
            builder.lineGapSize(LayoutStyle.getCurrent().getLinePad());

            appendProperties(builder);
            
            contents = builder.getPanel();
        }
        
        JScrollPane scrollPane =
            new JScrollPane(contents,
                            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        scrollPane.setBorder(Borders.DIALOG);

        if(_propertiesPanel == null)
        {
            _propertiesPanel = new JPanel(new BorderLayout());
        }
        else
        {
            _propertiesPanel.removeAll();
        }
        _propertiesPanel.add(scrollPane, BorderLayout.CENTER);
        _propertiesPanel.setBorder(Borders.EMPTY);
        _propertiesPanel.revalidate();
    }

    protected JPanel _propertiesPanel;
}