diff options
Diffstat (limited to 'src/cppcheckplus/outlookpanel/MyOutlookPanel.java')
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookPanel.java | 405 |
1 files changed, 202 insertions, 203 deletions
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java index 139f62a..afa7392 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import java.awt.Color; | 5 | import java.awt.Color; |
6 | import java.awt.Component; | 6 | import java.awt.Component; |
@@ -9,214 +9,213 @@ import java.awt.Dimension; | |||
9 | import java.awt.Graphics; | 9 | import java.awt.Graphics; |
10 | import java.awt.Insets; | 10 | import java.awt.Insets; |
11 | import java.awt.event.ActionListener; | 11 | import java.awt.event.ActionListener; |
12 | import java.util.ArrayList; | ||
13 | import java.util.Hashtable; | 12 | import java.util.Hashtable; |
14 | import java.util.List; | ||
15 | import javax.swing.Icon; | 13 | import javax.swing.Icon; |
16 | import javax.swing.JButton; | ||
17 | import javax.swing.JComponent; | 14 | import javax.swing.JComponent; |
18 | import javax.swing.JPanel; | 15 | import javax.swing.JPanel; |
19 | import javax.swing.border.Border; | 16 | import javax.swing.border.Border; |
20 | import javax.swing.event.ListSelectionListener; | 17 | import javax.swing.event.ListSelectionListener; |
21 | |||
22 | import cppcheckplus.control.MyContorlUtil; | ||
23 | import layout.TableLayout; | 18 | import layout.TableLayout; |
24 | 19 | ||
25 | public class MyOutlookPanel extends JPanel | 20 | public class MyOutlookPanel extends JPanel { |
26 | { | 21 | //Header |
27 | //Header | 22 | private MyOutlookHeader header; |
28 | private MyOutlookHeader header; | 23 | //容器Panel |
29 | //容器Panel | 24 | private JPanel barPane; |
30 | private JPanel barPane;; | 25 | ; |
31 | //右边的分割滑动线条 | 26 | //右边的分割滑动线条 |
32 | private JPanel split; | 27 | private JPanel split; |
33 | private int splitWidth; | 28 | private int splitWidth; |
34 | private Color splitColor; | 29 | private Color splitColor; |
35 | private JPanel additionalPane; | 30 | private JPanel additionalPane; |
36 | private Hashtable componentLayoutRows; | 31 | private Hashtable componentLayoutRows; |
37 | private JPanel centerPane; | 32 | private JPanel centerPane; |
38 | private TableLayout barPaneLayout; | 33 | private TableLayout barPaneLayout; |
39 | private MyOutlookSplitListener splitListener; | 34 | private MyOutlookSplitListener splitListener; |
40 | private ListSelectionListener listSelectionListener; | 35 | private ListSelectionListener listSelectionListener; |
41 | 36 | ||
42 | /** | 37 | /** |
43 | * 构造MyOutlookPanel | 38 | * 构造MyOutlookPanel |
44 | * @param headerListener Header的监听器 | 39 | * |
45 | * @param listSelectionListener ListItemSelection的监听器 | 40 | * @param headerListener Header的监听器 |
46 | */ | 41 | * @param listSelectionListener ListItemSelection的监听器 |
47 | public MyOutlookPanel(ActionListener headerListener,ListSelectionListener listSelectionListener) | 42 | */ |
48 | { | 43 | public MyOutlookPanel(ActionListener headerListener, |
49 | super(); | 44 | ListSelectionListener listSelectionListener) { |
50 | //注册Header事件 | 45 | super(); |
51 | this.header = new MyOutlookHeader(headerListener){ | 46 | //注册Header事件 |
52 | public void setShrink(boolean shrinked) | 47 | this.header = new MyOutlookHeader(headerListener) { |
53 | { | 48 | public void setShrink(boolean shrinked) { |
54 | super.setShrink(shrinked); | 49 | super.setShrink(shrinked); |
55 | shrinkChanged(shrinked); | 50 | shrinkChanged(shrinked); |
56 | } | 51 | } |
57 | 52 | ||
58 | }; | 53 | }; |
59 | this.listSelectionListener = listSelectionListener; | 54 | this.listSelectionListener = listSelectionListener; |
60 | barPaneLayout = new TableLayout(); | 55 | barPaneLayout = new TableLayout(); |
61 | barPane = new JPanel(barPaneLayout); | 56 | barPane = new JPanel(barPaneLayout); |
62 | 57 | ||
63 | additionalPane = new JPanel(new BorderLayout()); | 58 | additionalPane = new JPanel(new BorderLayout()); |
64 | componentLayoutRows = new Hashtable(); | 59 | componentLayoutRows = new Hashtable(); |
65 | centerPane = new JPanel(new BorderLayout()); | 60 | centerPane = new JPanel(new BorderLayout()); |
66 | 61 | ||
67 | //分割条 | 62 | //分割条 |
68 | split = new JPanel(); | 63 | split = new JPanel(); |
69 | splitWidth = 1; | 64 | splitWidth = 1; |
70 | splitColor = new Color(166, 172, 174); | 65 | splitColor = new Color(166, 172, 174); |
71 | splitListener = new MyOutlookSplitListener(header); | 66 | splitListener = new MyOutlookSplitListener(header); |
72 | 67 | ||
73 | init(); | 68 | init(); |
74 | } | 69 | } |
75 | private void init() | 70 | |
76 | { | 71 | private void init() { |
77 | split.setPreferredSize(new Dimension(splitWidth, 0)); | 72 | split.setPreferredSize(new Dimension(splitWidth, 0)); |
78 | split.setOpaque(true); | 73 | split.setOpaque(true); |
79 | split.setBackground(splitColor); | 74 | split.setBackground(splitColor); |
80 | split.setCursor(Cursor.getPredefinedCursor(10)); | 75 | split.setCursor(Cursor.getPredefinedCursor(10)); |
81 | split.addMouseListener(splitListener); | 76 | split.addMouseListener(splitListener); |
82 | split.addMouseMotionListener(splitListener); | 77 | split.addMouseMotionListener(splitListener); |
83 | additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); | 78 | additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); |
84 | additionalPane.setPreferredSize(new Dimension(0, 0)); | 79 | additionalPane.setPreferredSize(new Dimension(0, 0)); |
85 | additionalPane.setBorder(new Border() { | 80 | additionalPane.setBorder(new Border() { |
86 | 81 | ||
87 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | 82 | public void paintBorder(Component c, Graphics g, int x, int y, |
88 | { | 83 | int width, int height) { |
89 | g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); | 84 | g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); |
90 | g.drawLine(0, 0, width, 0); | 85 | g.drawLine(0, 0, width, 0); |
91 | } | 86 | } |
92 | 87 | ||
93 | public Insets getBorderInsets(Component c) | 88 | public Insets getBorderInsets(Component c) { |
94 | { | 89 | return new Insets(1, 0, 0, 0); |
95 | return new Insets(1, 0, 0, 0); | 90 | } |
96 | } | 91 | |
97 | 92 | public boolean isBorderOpaque() { | |
98 | public boolean isBorderOpaque() | 93 | return true; |
99 | { | 94 | } |
100 | return true; | 95 | |
101 | } | 96 | }); |
102 | 97 | ||
103 | }); | 98 | centerPane.add(barPane, "North"); |
104 | 99 | centerPane.add(additionalPane, "Center"); | |
105 | centerPane.add(barPane, "North"); | 100 | barPaneLayout.insertColumn(0, -1D); |
106 | centerPane.add(additionalPane, "Center"); | 101 | setLayout(new BorderLayout()); |
107 | barPaneLayout.insertColumn(0, -1D); | 102 | add(header, "North"); |
108 | setLayout(new BorderLayout()); | 103 | add(centerPane, "Center"); |
109 | add(header, "North"); | 104 | add(split, "East"); |
110 | add(centerPane, "Center"); | 105 | } |
111 | add(split, "East"); | 106 | |
112 | } | 107 | public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon, |
113 | public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon,MyOutlookPanelListItem[] listItems) | 108 | MyOutlookPanelListItem[] listItems) { |
114 | { | 109 | MyOutlookBar bar = new MyOutlookBar(this); |
115 | MyOutlookBar bar = new MyOutlookBar(this); | 110 | MyOutlookListPanel listPanel = getListPanel(listItems, bar); |
116 | MyOutlookListPanel listPanel = getListPanel(listItems, bar); | 111 | //注册JList事件 |
117 | //注册JList事件 | 112 | listPanel.getOutlookList() |
118 | listPanel.getOutlookList().addListSelectionListener(listSelectionListener); | 113 | .addListSelectionListener(listSelectionListener); |
119 | bar.setOutlookListPanel(listPanel); | 114 | bar.setOutlookListPanel(listPanel); |
120 | bar.setSelected(false); | 115 | bar.setSelected(false); |
121 | bar.setTitle(title); | 116 | bar.setTitle(title); |
122 | bar.setIcon(icon); | 117 | bar.setIcon(icon); |
123 | bar.setSelectedIcon(selectedIcon); | 118 | bar.setSelectedIcon(selectedIcon); |
124 | int rowCount = barPaneLayout.getRow().length; | 119 | int rowCount = barPaneLayout.getRow().length; |
125 | barPaneLayout.insertRow(rowCount, -2D); | 120 | barPaneLayout.insertRow(rowCount, -2D); |
126 | barPane.add(bar, (new StringBuilder()).append("0,").append(rowCount).toString()); | 121 | barPane.add(bar, |
127 | componentLayoutRows.put(bar, Integer.valueOf(rowCount)); | 122 | (new StringBuilder()).append("0,").append(rowCount).toString()); |
128 | rowCount++; | 123 | componentLayoutRows.put(bar, Integer.valueOf(rowCount)); |
129 | barPaneLayout.insertRow(rowCount, -3D); | 124 | rowCount++; |
130 | //加载列表 | 125 | barPaneLayout.insertRow(rowCount, -3D); |
131 | barPane.add(listPanel,(new StringBuilder()).append("0,").append(rowCount).toString()); | 126 | //加载列表 |
132 | componentLayoutRows.put(bar.getContentComponent(), Integer.valueOf(rowCount)); | 127 | barPane.add(listPanel, |
133 | return bar; | 128 | (new StringBuilder()).append("0,").append(rowCount).toString()); |
134 | } | 129 | componentLayoutRows.put(bar.getContentComponent(), |
135 | private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | 130 | Integer.valueOf(rowCount)); |
136 | { | 131 | return bar; |
137 | MyOutlookList list = new MyOutlookList(listItems,bar); | 132 | } |
138 | MyOutlookListPanel listPanel = new MyOutlookListPanel(list); | 133 | |
139 | return listPanel; | 134 | private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems, |
140 | } | 135 | MyOutlookBar bar) { |
141 | public void updateLayoutConstraint(Component component, boolean selected) | 136 | MyOutlookList list = new MyOutlookList(listItems, bar); |
142 | { | 137 | MyOutlookListPanel listPanel = new MyOutlookListPanel(list); |
143 | int rowIndex = ((Integer)componentLayoutRows.get(component)).intValue(); | 138 | return listPanel; |
144 | double constraint = -1D; | 139 | } |
145 | if (!selected) | 140 | |
146 | constraint = -3D; | 141 | public void updateLayoutConstraint(Component component, boolean selected) { |
147 | barPaneLayout.setRow(rowIndex, constraint); | 142 | int rowIndex = |
148 | } | 143 | ((Integer) componentLayoutRows.get(component)).intValue(); |
149 | public JComponent getAdditionalPane() | 144 | double constraint = -1D; |
150 | { | 145 | if (!selected) { |
151 | return additionalPane; | 146 | constraint = -3D; |
152 | } | 147 | } |
153 | public void setAdditionalPaneVisible(boolean visible) | 148 | barPaneLayout.setRow(rowIndex, constraint); |
154 | { | 149 | } |
155 | centerPane.remove(barPane); | 150 | |
156 | centerPane.remove(additionalPane); | 151 | public JComponent getAdditionalPane() { |
157 | if (visible) | 152 | return additionalPane; |
158 | { | 153 | } |
159 | centerPane.add(barPane, "North"); | 154 | |
160 | centerPane.add(additionalPane, "Center"); | 155 | public void setAdditionalPaneVisible(boolean visible) { |
161 | } else | 156 | centerPane.remove(barPane); |
162 | { | 157 | centerPane.remove(additionalPane); |
163 | centerPane.add(barPane, "Center"); | 158 | if (visible) { |
164 | } | 159 | centerPane.add(barPane, "North"); |
165 | } | 160 | centerPane.add(additionalPane, "Center"); |
166 | public void closeAllBars() | 161 | } else { |
167 | { | 162 | centerPane.add(barPane, "Center"); |
168 | for (int i = 0; i < barPane.getComponentCount(); i++) | 163 | } |
169 | { | 164 | } |
170 | Component c = barPane.getComponent(i); | 165 | |
171 | if (!(c instanceof MyOutlookBar)) | 166 | public void closeAllBars() { |
172 | continue; | 167 | for (int i = 0; i < barPane.getComponentCount(); i++) { |
173 | MyOutlookBar bar = (MyOutlookBar)c; | 168 | Component c = barPane.getComponent(i); |
174 | if (bar.isSelected()) | 169 | if (!(c instanceof MyOutlookBar)) { |
175 | bar.setSelected(false); | 170 | continue; |
176 | } | 171 | } |
177 | } | 172 | MyOutlookBar bar = (MyOutlookBar) c; |
178 | public MyOutlookBar getSelectedBar() | 173 | if (bar.isSelected()) { |
179 | { | 174 | bar.setSelected(false); |
180 | for (int i = 0; i < barPane.getComponentCount(); i++) | 175 | } |
181 | { | 176 | } |
182 | Component c = barPane.getComponent(i); | 177 | } |
183 | if (!(c instanceof MyOutlookBar)) | 178 | |
184 | continue; | 179 | public MyOutlookBar getSelectedBar() { |
185 | MyOutlookBar bar = (MyOutlookBar)c; | 180 | for (int i = 0; i < barPane.getComponentCount(); i++) { |
186 | if (bar.isSelected()) | 181 | Component c = barPane.getComponent(i); |
187 | return bar; | 182 | if (!(c instanceof MyOutlookBar)) { |
188 | } | 183 | continue; |
189 | 184 | } | |
190 | return null; | 185 | MyOutlookBar bar = (MyOutlookBar) c; |
191 | } | 186 | if (bar.isSelected()) { |
192 | public void setShrink(boolean shrinked) | 187 | return bar; |
193 | { | 188 | } |
194 | header.setShrink(shrinked); | 189 | } |
195 | } | 190 | |
196 | 191 | return null; | |
197 | public boolean isShrinked() | 192 | } |
198 | { | 193 | |
199 | return header.isShrinked(); | 194 | public void setShrink(boolean shrinked) { |
200 | } | 195 | header.setShrink(shrinked); |
201 | private void shrinkChanged(boolean shrinked) | 196 | } |
202 | { | 197 | |
203 | if (shrinked) | 198 | public boolean isShrinked() { |
204 | split.setCursor(Cursor.getDefaultCursor()); | 199 | return header.isShrinked(); |
205 | else | 200 | } |
206 | split.setCursor(Cursor.getPredefinedCursor(10)); | 201 | |
207 | for (int i = 0; i < barPane.getComponentCount(); i++) | 202 | private void shrinkChanged(boolean shrinked) { |
208 | { | 203 | if (shrinked) { |
209 | Component c = barPane.getComponent(i); | 204 | split.setCursor(Cursor.getDefaultCursor()); |
210 | if (c instanceof MyOutlookBar) | 205 | } else { |
211 | { | 206 | split.setCursor(Cursor.getPredefinedCursor(10)); |
212 | MyOutlookBar bar = (MyOutlookBar)c; | 207 | } |
213 | bar.headerShrinkChanged(shrinked); | 208 | for (int i = 0; i < barPane.getComponentCount(); i++) { |
214 | 209 | Component c = barPane.getComponent(i); | |
215 | 210 | if (c instanceof MyOutlookBar) { | |
216 | //XOutlookList list = bar.getList(); | 211 | MyOutlookBar bar = (MyOutlookBar) c; |
217 | 212 | bar.headerShrinkChanged(shrinked); | |
218 | //list.firePropertyChange("layoutOrientation", true, false); | 213 | |
219 | } | 214 | |
220 | } | 215 | //XOutlookList list = bar.getList(); |
221 | } | 216 | |
217 | //list.firePropertyChange("layoutOrientation", true, false); | ||
218 | } | ||
219 | } | ||
220 | } | ||
222 | } | 221 | } |