PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/test/check/SampleFrame.java

https://github.com/jburel/substance
Java | 431 lines | 324 code | 52 blank | 55 comment | 9 complexity | 6ce1dd832da8509bb940aaefcfb093ae MD5 | raw file
  1. /*
  2. * Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * o Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. *
  10. * o Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * o Neither the name of Substance Kirill Grouchnikov nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  27. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  28. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. package test.check;
  31. import java.awt.*;
  32. import java.awt.event.*;
  33. import java.util.ArrayList;
  34. import java.util.List;
  35. import javax.swing.*;
  36. import javax.swing.border.EmptyBorder;
  37. import javax.swing.tree.DefaultMutableTreeNode;
  38. import org.pushingpixels.substance.api.*;
  39. import org.pushingpixels.substance.api.skin.GeminiSkin;
  40. import org.pushingpixels.substance.api.skin.SkinChangeListener;
  41. import test.Check;
  42. import test.SubstanceLogo;
  43. import com.jgoodies.forms.builder.PanelBuilder;
  44. import com.jgoodies.forms.layout.CellConstraints;
  45. import com.jgoodies.forms.layout.FormLayout;
  46. public class SampleFrame extends JFrame {
  47. protected JButton prev;
  48. private JTabbedPane tabbed;
  49. private JTree tree;
  50. private JList list;
  51. private static class MyListModel extends AbstractListModel {
  52. protected List<String> model;
  53. public MyListModel() {
  54. super();
  55. this.model = new ArrayList<String>();
  56. this.model.add("Ohio State [Buckeyes]");
  57. this.model.add("Auburn [Tigers]");
  58. this.model.add("University of South California [Trojans]");
  59. this.model.add("West Virginia [Mountaineers]");
  60. this.model.add("Florida [Gators]");
  61. this.model.add("Michigan [Wolverines]");
  62. this.model.add("Texas [Longhorns]");
  63. this.model.add("Louisville [Cardinals]");
  64. this.model.add("Louisiana State University [Tigers]");
  65. this.model.add("Georgia [Bulldogs]");
  66. this.model.add("Virginia Tech [Hokies]");
  67. this.model.add("Notre Dame [Fighting Irish]");
  68. this.model.add("Iowa [Hawkeyes]");
  69. this.model.add("Oregon [Ducks]");
  70. this.model.add("Tennessee [Volunteers]");
  71. this.model.add("Oklahoma [Sooners]");
  72. this.model.add("Texas Christian University [Horned Frogs]");
  73. }
  74. public Object getElementAt(int index) {
  75. return this.model.get(index);
  76. }
  77. public int getSize() {
  78. return this.model.size();
  79. }
  80. }
  81. public SampleFrame() {
  82. super("Test application");
  83. this.setLayout(new BorderLayout());
  84. this.tabbed = new JTabbedPane();
  85. this.add(Check.getToolbar("", 16, false), BorderLayout.NORTH);
  86. this.add(this.tabbed, BorderLayout.CENTER);
  87. // this.tabbed.putClientProperty(LafWidget.TABBED_PANE_PREVIEW_PAINTER,
  88. // new DefaultTabPreviewPainter());
  89. JPanel transPanel = new JPanel();
  90. transPanel.setLayout(new BorderLayout());
  91. JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 1, 0));
  92. transPanel.add(buttons, BorderLayout.SOUTH);
  93. // for the first movie, change the following line to
  94. // use the BorderLayout
  95. final JPanel mainPanel = new JPanel(new FlowLayout());
  96. final JPanel mainPanel2 = new JPanel(new FlowLayout());
  97. final JPanel centerPanel = new JPanel(new GridLayout(2, 1));
  98. centerPanel.add(mainPanel);
  99. centerPanel.add(mainPanel2);
  100. final JButton b1 = new JButton("1");
  101. final JButton b2 = new JButton("2");
  102. final JButton b3 = new JButton("3");
  103. final JButton b4 = new JButton("4");
  104. final JButton b5 = new JButton("5");
  105. final JButton b6 = new JButton("6");
  106. final JButton add1 = new JButton("add");
  107. final JButton add2 = new JButton("add");
  108. add1.addActionListener(new ActionListener() {
  109. public void actionPerformed(ActionEvent e) {
  110. SwingUtilities.invokeLater(new Runnable() {
  111. public void run() {
  112. mainPanel.add(b1);
  113. mainPanel.add(b2);
  114. mainPanel.add(b3);
  115. mainPanel.revalidate();
  116. add1.setVisible(false);
  117. }
  118. });
  119. }
  120. });
  121. add2.addActionListener(new ActionListener() {
  122. public void actionPerformed(ActionEvent e) {
  123. SwingUtilities.invokeLater(new Runnable() {
  124. public void run() {
  125. mainPanel2.add(b4);
  126. mainPanel2.add(b5);
  127. mainPanel2.add(b6);
  128. mainPanel2.revalidate();
  129. add2.setVisible(false);
  130. }
  131. });
  132. }
  133. });
  134. mainPanel.add(add1);
  135. mainPanel2.add(add2);
  136. final JCheckBox cb = new JCheckBox("border layout");
  137. cb.addActionListener(new ActionListener() {
  138. public void actionPerformed(ActionEvent e) {
  139. if (cb.isSelected()) {
  140. mainPanel.setLayout(new BorderLayout());
  141. mainPanel2.setLayout(new BorderLayout());
  142. } else {
  143. mainPanel.setLayout(new FlowLayout());
  144. mainPanel2.setLayout(new FlowLayout());
  145. }
  146. mainPanel.revalidate();
  147. mainPanel.doLayout();
  148. mainPanel.repaint();
  149. mainPanel2.revalidate();
  150. }
  151. });
  152. // buttons.add(cb);
  153. transPanel.add(centerPanel, BorderLayout.CENTER);
  154. final JCheckBox cb1 = new JCheckBox("1");
  155. cb1.setSelected(true);
  156. final JCheckBox cb2 = new JCheckBox("2");
  157. cb2.setSelected(true);
  158. final JCheckBox cb3 = new JCheckBox("3");
  159. cb3.setSelected(true);
  160. final JCheckBox cb4 = new JCheckBox("4");
  161. cb4.setSelected(true);
  162. final JCheckBox cb5 = new JCheckBox("5");
  163. cb5.setSelected(true);
  164. final JCheckBox cb6 = new JCheckBox("6");
  165. cb6.setSelected(true);
  166. buttons.add(cb1);
  167. buttons.add(cb2);
  168. buttons.add(cb3);
  169. buttons.add(cb4);
  170. buttons.add(cb5);
  171. buttons.add(cb6);
  172. JButton showHide = new JButton("Toggle");
  173. showHide.addActionListener(new ActionListener() {
  174. public void actionPerformed(ActionEvent e) {
  175. b1.setVisible(cb1.isSelected());
  176. b2.setVisible(cb2.isSelected());
  177. b3.setVisible(cb3.isSelected());
  178. b4.setVisible(cb4.isSelected());
  179. b5.setVisible(cb5.isSelected());
  180. b6.setVisible(cb6.isSelected());
  181. mainPanel.doLayout();
  182. mainPanel2.doLayout();
  183. }
  184. });
  185. buttons.add(showHide);
  186. this.tabbed.addTab("Regular", transPanel);
  187. JPanel samplePanel = new JPanel(new BorderLayout());
  188. FormLayout lm = new FormLayout("fill:default:grow(1), 2dlu,"
  189. + "fill:default:grow(1)",
  190. "pref, 3dlu, pref, 3dlu, pref, 3dlu, pref");
  191. PanelBuilder builder = new PanelBuilder(lm);
  192. builder.setBorder(new EmptyBorder(0, 2, 0, 2));
  193. CellConstraints cc = new CellConstraints();
  194. JCheckBox cbes = new JCheckBox("Enabled selected");
  195. cbes.setSelected(true);
  196. JCheckBox cbds = new JCheckBox("Disabled selected");
  197. cbds.setSelected(true);
  198. cbds.setEnabled(false);
  199. JCheckBox cbeu = new JCheckBox("Enabled unselected");
  200. JRadioButton rb1 = new JRadioButton("Enabled selected");
  201. rb1.setSelected(true);
  202. JRadioButton rb2 = new JRadioButton("Disabled selected");
  203. rb2.setSelected(true);
  204. rb2.setEnabled(false);
  205. JRadioButton rb3 = new JRadioButton("Enabled unselected");
  206. builder.add(cbes, cc.xy(1, 1));
  207. builder.add(rb1, cc.xy(3, 1));
  208. builder.add(cbds, cc.xy(1, 3));
  209. builder.add(rb2, cc.xy(3, 3));
  210. builder.add(cbeu, cc.xy(1, 5));
  211. builder.add(rb3, cc.xy(3, 5));
  212. JComboBox combo = new JComboBox(new Object[] { "item1" });
  213. combo.setSelectedIndex(0);
  214. JTextField text = new JTextField("Text field");
  215. // text.setEditable(false);
  216. builder.add(combo, cc.xy(1, 7));
  217. builder.add(text, cc.xy(3, 7));
  218. JPanel contentPanel = builder.getPanel();
  219. contentPanel.setPreferredSize(new Dimension(contentPanel
  220. .getPreferredSize().width,
  221. contentPanel.getPreferredSize().height + 100));
  222. // contentPanel.setBorder(null);
  223. contentPanel.setOpaque(false);
  224. final JScrollPane scroll = new JScrollPane(contentPanel,
  225. JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
  226. JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  227. scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
  228. scroll.setOpaque(false);
  229. scroll.getViewport().setOpaque(false);
  230. final JPanel buttons2 = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,
  231. 2));
  232. this.prev = new JButton("prev");
  233. JButton cancel = new JButton("cancel");
  234. cancel.setEnabled(false);
  235. final JButton ok = new JButton("OK");
  236. // ok.putClientProperty(SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
  237. // Boolean.TRUE);
  238. buttons2.add(this.prev);
  239. buttons2.add(cancel);
  240. buttons2.add(ok);
  241. this.getRootPane().setDefaultButton(ok);
  242. // ok.requestFocusInWindow();
  243. this.addWindowListener(new WindowAdapter() {
  244. @Override
  245. public void windowActivated(WindowEvent e) {
  246. ok.requestFocusInWindow();
  247. }
  248. });
  249. samplePanel.add(scroll, BorderLayout.CENTER);
  250. samplePanel.add(buttons2, BorderLayout.SOUTH);
  251. this.tabbed.addTab("Sample", samplePanel);
  252. JPanel samplePanel2 = new JPanel(new BorderLayout());
  253. DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
  254. DefaultMutableTreeNode son1 = new DefaultMutableTreeNode("son1");
  255. DefaultMutableTreeNode son2 = new DefaultMutableTreeNode("son2");
  256. DefaultMutableTreeNode son3 = new DefaultMutableTreeNode("son3");
  257. DefaultMutableTreeNode gson11 = new DefaultMutableTreeNode("gson11");
  258. DefaultMutableTreeNode gson12 = new DefaultMutableTreeNode("gson12");
  259. DefaultMutableTreeNode gson21 = new DefaultMutableTreeNode("gson21");
  260. DefaultMutableTreeNode gson22 = new DefaultMutableTreeNode("gson22");
  261. DefaultMutableTreeNode gson31 = new DefaultMutableTreeNode("gson31");
  262. DefaultMutableTreeNode gson32 = new DefaultMutableTreeNode("gson32");
  263. DefaultMutableTreeNode ggson111 = new DefaultMutableTreeNode("ggson111");
  264. DefaultMutableTreeNode ggson112 = new DefaultMutableTreeNode("ggson112");
  265. DefaultMutableTreeNode ggson113 = new DefaultMutableTreeNode("ggson113");
  266. gson11.add(ggson111);
  267. gson11.add(ggson112);
  268. gson11.add(ggson113);
  269. son1.add(gson11);
  270. son1.add(gson12);
  271. son2.add(gson21);
  272. son2.add(gson22);
  273. son3.add(gson31);
  274. son3.add(gson32);
  275. root.add(son1);
  276. root.add(son2);
  277. root.add(son3);
  278. this.tree = new JTree(root);
  279. this.tree.setBorder(new EmptyBorder(0, 0, 0, 0));
  280. JScrollPane jspTree = new JScrollPane(this.tree);
  281. // TransitionLayoutManager.getInstance().track(jspTree, true);
  282. // jspTree.setBorder(new EmptyBorder(0, 0, 0, 0));
  283. this.list = new JList(new MyListModel());
  284. this.list.setBorder(new EmptyBorder(0, 0, 0, 0));
  285. this.list
  286. .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  287. JScrollPane jspList = new JScrollPane(this.list);
  288. // jspList.setBorder(new EmptyBorder(0, 0, 0, 0));
  289. JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jspTree,
  290. jspList);
  291. split.setDividerLocation(130);
  292. samplePanel2.add(split, BorderLayout.CENTER);
  293. this.tabbed.add("Renderers", samplePanel2);
  294. this.tabbed.setSelectedComponent(samplePanel);
  295. this.tabbed.setOpaque(false);
  296. this.tabbed.setBorder(new EmptyBorder(0, 2, 2, 2));
  297. JMenuBar jmb = new JMenuBar();
  298. if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
  299. // jmb.add(SampleMenuFactory.getThemeMenu());
  300. jmb.add(SampleMenuFactory.getSkinMenu());
  301. }
  302. JMenu testMenu = SampleMenuFactory.getTestMenu();
  303. jmb.add(testMenu);
  304. this.setJMenuBar(jmb);
  305. this.setResizable(true);
  306. this.synchronize();
  307. SubstanceLookAndFeel
  308. .registerSkinChangeListener(new SkinChangeListener() {
  309. @Override
  310. public void skinChanged() {
  311. SampleFrame.this.synchronize();
  312. }
  313. });
  314. this.getRootPane().setDefaultButton(ok);
  315. }
  316. protected void synchronize() {
  317. SwingUtilities.invokeLater(new Runnable() {
  318. public void run() {
  319. if (SubstanceLookAndFeel.isCurrentLookAndFeel()) {
  320. SampleFrame.this
  321. .setIconImage(SubstanceLogo
  322. .getLogoImage(SubstanceLookAndFeel
  323. .getCurrentSkin(
  324. SampleFrame.this
  325. .getRootPane())
  326. .getColorScheme(
  327. DecorationAreaType.PRIMARY_TITLE_PANE,
  328. ColorSchemeAssociationKind.FILL,
  329. ComponentState.ENABLED)));
  330. }
  331. }
  332. });
  333. }
  334. public static void main(String... args) throws Exception {
  335. // UIDefaults uid = UIManager.getLookAndFeelDefaults();
  336. // Font segoe = new Font("Segoe UI", Font.PLAIN, 12);
  337. // for (Object key : uid.keySet()) {
  338. // if (key instanceof String) {
  339. // String skey = (String) key;
  340. // if (skey.endsWith(".font")) {
  341. // System.out.println(skey);
  342. // uid.put(skey, segoe);
  343. // }
  344. // }
  345. // }
  346. SwingUtilities.invokeLater(new Runnable() {
  347. public void run() {
  348. if (System.getProperty("swing.defaultlaf") == null) {
  349. SubstanceLookAndFeel.setSkin(new GeminiSkin());
  350. }
  351. JFrame.setDefaultLookAndFeelDecorated(true);
  352. SampleFrame sf = new SampleFrame();
  353. sf.setSize(338, 245);
  354. sf.setLocationRelativeTo(null);
  355. sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  356. sf.setVisible(true);
  357. }
  358. });
  359. // h(sf, 0);
  360. }
  361. public static void h(Component comp, int depth) {
  362. for (int i = 0; i < depth; i++)
  363. System.out.print(" ");
  364. Rectangle r = comp.getBounds();
  365. System.out.println(comp.getClass().getSimpleName() + " [" + r.x + ","
  366. + r.y + " : " + (r.x + r.width) + "," + (r.y + r.height) + "]");
  367. if (comp instanceof Container) {
  368. Container cont = (Container) comp;
  369. for (int i = 0; i < cont.getComponentCount(); i++) {
  370. h(cont.getComponent(i), depth + 1);
  371. }
  372. }
  373. }
  374. public void switchToLastTab() {
  375. this.tabbed.setSelectedIndex(2);
  376. this.list.setSelectedIndices(new int[] { 1, 4 });
  377. this.tree.setSelectionRow(1);
  378. }
  379. }