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