01: /*
02: * SplitPaneExpander.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.sql;
13:
14: import java.awt.EventQueue;
15: import javax.swing.JSplitPane;
16:
17: /**
18: * @author support@sql-workbench.net
19: */
20: public class SplitPaneExpander {
21: private JSplitPane contentPanel;
22: private int lastDivider = -1;
23: private boolean upperPartExpanded = false;
24: private boolean lowerPartExpanded = false;
25:
26: public SplitPaneExpander(JSplitPane client) {
27: this .contentPanel = client;
28: }
29:
30: public void undoExpand() {
31: if (lastDivider != -1) {
32: this .contentPanel.setDividerLocation(this .lastDivider);
33: } else {
34: int newLoc = (int) (this .contentPanel.getHeight() / 2);
35: this .contentPanel.setDividerLocation(newLoc);
36: }
37: this .lastDivider = -1;
38: repaintClient();
39: }
40:
41: public void toggleUpperComponentExpand() {
42: if (upperPartExpanded) {
43: undoExpand();
44: upperPartExpanded = false;
45: } else {
46: if (!lowerPartExpanded) {
47: lastDivider = this .contentPanel.getDividerLocation();
48: }
49: this .contentPanel.setDividerLocation(this .contentPanel
50: .getHeight());
51: upperPartExpanded = true;
52: }
53: this .lowerPartExpanded = false;
54: repaintClient();
55: }
56:
57: public void toggleLowerComponentExpand() {
58: if (this .lowerPartExpanded) {
59: undoExpand();
60: lowerPartExpanded = false;
61: } else {
62: if (!upperPartExpanded) {
63: lastDivider = this .contentPanel.getDividerLocation();
64: }
65: this .contentPanel.setDividerLocation(0);
66: this .lowerPartExpanded = true;
67: }
68: this .upperPartExpanded = false;
69: repaintClient();
70: }
71:
72: private void repaintClient() {
73: EventQueue.invokeLater(new Runnable() {
74: public void run() {
75: contentPanel.validate();
76: contentPanel.repaint();
77: }
78: });
79: }
80: }
|