01: /*
02: * OptionPanelPage.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.settings;
13:
14: import java.awt.BorderLayout;
15: import java.awt.Color;
16: import java.awt.Font;
17: import javax.swing.JLabel;
18: import javax.swing.JPanel;
19: import javax.swing.border.CompoundBorder;
20: import javax.swing.border.EmptyBorder;
21: import javax.swing.border.EtchedBorder;
22: import workbench.gui.components.DividerBorder;
23: import workbench.interfaces.Restoreable;
24: import workbench.log.LogMgr;
25: import workbench.resource.ResourceMgr;
26:
27: /**
28: * @author support@sql-workbench.net
29: */
30: public class OptionPanelPage {
31: private String label;
32: private String pageClass;
33: private JPanel panel;
34: private Restoreable options;
35:
36: public OptionPanelPage(String clz, String key) {
37: this .label = ResourceMgr.getString(key);
38: this .pageClass = "workbench.gui.settings." + clz;
39: }
40:
41: public String toString() {
42: return this .label;
43: }
44:
45: public String getLabel() {
46: return label;
47: }
48:
49: public JPanel getPanel() {
50: if (this .panel == null) {
51: try {
52: Class clz = Class.forName(this .pageClass);
53: JPanel optionPanel = (JPanel) clz.newInstance();
54: this .options = (Restoreable) optionPanel;
55: this .options.restoreSettings();
56:
57: JLabel title = new JLabel(this .label);
58: title.setName("pagetitle");
59: title.setOpaque(true);
60: title.setBackground(Color.WHITE);
61: Font f = title.getFont();
62: Font f2 = f.deriveFont(Font.BOLD, 12.0f);
63: //title.setBorder();
64: title.setBorder(new CompoundBorder(
65: DividerBorder.BOTTOM_DIVIDER, new EmptyBorder(
66: 4, 6, 4, 6)));
67: title.setFont(f2);
68: panel = new JPanel(new BorderLayout());
69: panel.setBorder(new EtchedBorder());
70: panel.add(title, BorderLayout.NORTH);
71: panel.add(optionPanel, BorderLayout.CENTER);
72: } catch (Exception e) {
73: LogMgr.logError("OptionPanelPage.getPanel()",
74: "Could not create panel", e);
75: }
76: }
77: return this .panel;
78: }
79:
80: public void saveSettings() {
81: try {
82: if (this .options != null) {
83: options.saveSettings();
84: }
85: } catch (Exception e) {
86: LogMgr.logError("OptionPanelPage.restoreSettings()",
87: "Could not restore panel settings", e);
88: }
89: }
90:
91: }
|