PageRenderTime 74ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/prototypes/miglayout/net/miginfocom/demo/SwingDemo.java

http://github.com/graemeg/fpGUI
Java | 3668 lines | 3124 code | 425 blank | 119 comment | 191 complexity | a3f71b91768df5843694793296603017 MD5 | raw file
Possible License(s): LGPL-2.1
  1. package net.miginfocom.demo;
  2. import net.miginfocom.layout.*;
  3. import net.miginfocom.swing.MigLayout;
  4. import javax.swing.*;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.border.EtchedBorder;
  7. import javax.swing.border.LineBorder;
  8. import javax.swing.event.ListSelectionEvent;
  9. import javax.swing.event.ListSelectionListener;
  10. import java.awt.*;
  11. import java.awt.event.*;
  12. import java.io.FileWriter;
  13. import java.io.IOException;
  14. import java.io.PrintWriter;
  15. import java.io.StringWriter;
  16. import java.util.Random;
  17. /*
  18. * License (BSD):
  19. * ==============
  20. *
  21. * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without modification,
  25. * are permitted provided that the following conditions are met:
  26. * Redistributions of source code must retain the above copyright notice, this list
  27. * of conditions and the following disclaimer.
  28. * Redistributions in binary form must reproduce the above copyright notice, this
  29. * list of conditions and the following disclaimer in the documentation and/or other
  30. * materials provided with the distribution.
  31. * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
  32. * used to endorse or promote products derived from this software without specific
  33. * prior written permission.
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  36. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  37. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  38. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  39. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  40. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  42. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  44. * OF SUCH DAMAGE.
  45. *
  46. * @version 1.0
  47. * @author Mikael Grev, MiG InfoCom AB
  48. * Date: 2006-sep-08
  49. */
  50. public class SwingDemo extends JFrame
  51. {
  52. public static final int INITIAL_INDEX = 0;
  53. private static final boolean DEBUG = false;
  54. private static final boolean OPAQUE = false;
  55. private static final String[][] panels = new String[][] {
  56. // {"Test", "Test, disregard"},
  57. {"Welcome", "\n\n \"MigLayout makes complex layouts easy and normal layouts one-liners.\""},
  58. {"Quick Start", "This is an example of how to build a common dialog type. Note that there are no special components, nested panels or absolute references to cell positions. If you look at the source code you will see that the layout code is very simple to understand."},
  59. {"Plain", "A simple example on how simple it is to create normal forms. No builders needed since the whole layout manager works like a builder."},
  60. {"Alignments", "Shows how the alignment of components are specified. At the top/left is the alignment for the column/row. The components have no alignments specified.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
  61. {"Cell Alignments", "Shows how components are aligned when both column/row alignments and component constraints are specified. At the top/left are the alignment for the column/row and the text on the buttons is the component constraint that will override the column/row alignment if it is an alignment.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
  62. {"Basic Sizes", "A simple example that shows how to use the column or row min/preferred/max size to set the sizes of the contained components and also an example that shows how to do this directly in the component constraints."},
  63. {"Growing", "A simple example that shows how to use the growx and growy constraint to set the sizes and how they should grow to fit the available size. Both the column/row and the component grow/shrink constraints can be set, but the components will always be confined to the space given by its column/row."},
  64. {"Grow Shrink", "Demonstrates the very flexible grow and shrink constraints that can be set on a component.\nComponents can be divided into grow/shrink groups and also have grow/shrink weight within each of those groups.\n\nBy default " +
  65. "components shrink to their inherent (or specified) minimum size, but they don't grow."},
  66. {"Span", "This example shows the powerful spanning and splitting that can be specified in the component constraints. With spanning any number of cells can be merged with the additional option to split that space for more than one component. This makes layouts very flexible and reduces the number of times you will need nested panels to very few."},
  67. {"Flow Direction", "Shows the different flow directions. Flow direction for the layout specifies if the next cell will be in the x or y dimension. Note that it can be a different flow direction in the slit cell (the middle cell is slit in two). Wrap is set to 3 for all panels."},
  68. {"Grouping", "Sizes for both components and columns/rows can be grouped so they get the same size. For instance buttons in a button bar can be given a size-group so that they will all get " +
  69. "the same minimum and preferred size (the largest within the group). Size-groups can be set for the width, height or both."},
  70. {"Units", "Demonstrates the basic units that are understood by MigLayout. These units can be extended by the user by adding one or more UnitConverter(s)."},
  71. {"Component Sizes", "Minimum, preferred and maximum component sizes can be overridden in the component constraints using any unit type. The format to do this is short and simple to understand. You simply specify the " +
  72. "min, preferred and max sizes with a colon between.\n\nAbove are some examples of this. An exclamation mark means that the value will be used for all sizes."},
  73. {"Bound Sizes", "Shows how to create columns that are stable between tabs using minimum sizes."},
  74. {"Cell Position", "Even though MigLayout has automatic grid flow you can still specify the cell position explicitly. You can even combine absolute (x, y) and flow (skip, wrap and newline) constraints to build your layout."},
  75. {"Orientation", "MigLayout supports not only right-to-left orientation, but also bottom-to-top. You can even set the flow direction so that the flow is vertical instead of horizontal. It will automatically " +
  76. "pick up if right-to-left is to be used depending on the ComponentWrapper, but it can also be manually set for every layout."},
  77. {"Absolute Position", "Demonstrates the option to place any number of components using absolute coordinates. This can be just the position (if min/preferred size) using \"x y p p\" format or" +
  78. "the bounds using the \"x1 y1 x2 y2\" format. Any unit can be used and percent is relative to the parent.\nAbsolute components will not disturb the flow or occupy cells in the grid. " +
  79. "Absolute positioned components will be taken into account when calculating the container's preferred size."},
  80. {"Component Links", "Components can be linked to any side of any other component. It can be a forward, backward or cyclic link references, as long as it is stable and won't continue to change value over many iterations." +
  81. "Links are referencing the ID of another component. The ID can be overridden by the component's constrains or is provided by the ComponentWrapper. For instance it will use the component's 'name' on Swing.\n" +
  82. "Since the links can be combined with any expression (such as 'butt1.x+10' or 'max(button.x, 200)' the links are very customizable."},
  83. {"Docking", "Docking components can be added around the grid. The docked component will get the whole width/height on the docked side by default, however this can be overridden. When all docked components are laid out, whatever space " +
  84. "is left will be available for the normal grid laid out components. Docked components does not in any way affect the flow in the grid.\n\nSince the docking runs in the same code path " +
  85. "as the normal layout code the same properties can be specified for the docking components. You can for instance set the sizes and alignment or link other components to their docked component's bounds."},
  86. {"Button Bars", "Button order is very customizable and are by default different on the supported platforms. E.g. Gaps, button order and minimum button size are properties that are 'per platform'. MigLayout picks up the current platform automatically and adjusts the button order and minimum button size accordingly, all without using a button builder or any other special code construct."},
  87. {"Visual Bounds", "Human perceptible bounds may not be the same as the mathematical bounds for the component. This is for instance the case if there is a drop shadow painted by the component's border. MigLayout can compensate " +
  88. "for this in a simple way. Note the top middle tab-component, it is not aligned visually correct on Windows XP. For the second tab the bounds are corrected automatically on Windows XP."},
  89. {"Debug", "Demonstrates the non-intrusive way to get visual debugging aid. There is no need to use a special DebugPanel or anything that will need code changes. The user can simply turn on debug on the layout manager by using the \"debug\" constraint and it will " +
  90. "continuously repaint the panel with debug information on top. This means you don't have to change your code to debug!"},
  91. {"Layout Showdown", "This is an implementation of the Layout Showdown posted on java.net by John O'Conner. The first tab is a pure implemenetation of the showdown that follows all the rules. The second tab is a slightly fixed version that follows some improved layout guidelines." +
  92. "The source code is for bothe the first and for the fixed version. Note the simplification of the code for the fixed version. Writing better layouts with MiG Layout is reasier that writing bad.\n\nReference: http://weblogs.java.net/blog/joconner/archive/2006/10/more_informatio.html"},
  93. {"API Constraints1", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."},
  94. {"API Constraints2", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."}
  95. };
  96. private int lastIndex = -10;
  97. private JPanel contentPanel = DEBUG ? new JPanel(new BorderLayout()) : new JPanel(new MigLayout("wrap", "[]unrel[grow]", "[grow][pref]"));
  98. private JTabbedPane layoutPickerTabPane = new JTabbedPane();
  99. private JList pickerList = new JList(new DefaultListModel());
  100. private JTabbedPane southTabPane = new JTabbedPane();
  101. private JScrollPane descrTextAreaScroll = createTextAreaScroll("", 5, 80, true);
  102. private JTextArea descrTextArea = (JTextArea) descrTextAreaScroll.getViewport().getView();
  103. private JScrollPane sourceTextAreaScroll = null;
  104. private JTextArea sourceTextArea = null;
  105. private JPanel layoutDisplayPanel = new JPanel(new BorderLayout(0, 0));
  106. private static boolean buttonOpaque = true;
  107. private JFrame sourceFrame = null;
  108. private JTextArea sourceFrameTextArea = null;
  109. private static int benchRuns = 0;
  110. private static long startupMillis = 0;
  111. private static long timeToShowMillis = 0;
  112. private static long benchRunTime = 0;
  113. private static String benchOutFileName = null;
  114. private static boolean append = false;
  115. private static long lastRunTimeStart = 0;
  116. private static StringBuffer runTimeSB = null;
  117. public static void main(String args[])
  118. {
  119. try {
  120. System.setProperty("apple.laf.useScreenMenuBar", "true");
  121. System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MiGLayout Swing Demo");
  122. } catch(Throwable ex) {
  123. // Beacuse we did not have permissions.
  124. }
  125. startupMillis = System.currentTimeMillis();
  126. String laf = UIManager.getSystemLookAndFeelClassName();
  127. if (args.length > 0) {
  128. for (int i = 0; i <args.length; i++) {
  129. String arg = args[i].trim();
  130. if (arg.startsWith("-laf")) {
  131. laf = arg.substring(4);
  132. } else if (arg.startsWith("-bench")) {
  133. benchRuns = 10;
  134. try {
  135. benchRuns = Integer.parseInt(arg.substring(6));
  136. } catch(Exception ex) {}
  137. } else if (arg.startsWith("-bout")) {
  138. benchOutFileName = arg.substring(5);
  139. } else if (arg.startsWith("-append")) {
  140. append = true;
  141. } else if (arg.startsWith("-verbose")) {
  142. runTimeSB = new StringBuffer(256);
  143. } else if (arg.equals("-steel")) {
  144. laf = "javax.swing.plaf.metal.MetalLookAndFeel";
  145. System.setProperty("swing.metalTheme", "steel");
  146. } else if (arg.equals("-ocean")) {
  147. laf = "javax.swing.plaf.metal.MetalLookAndFeel";
  148. } else {
  149. System.out.println("Usage: [-laf[look_&_feel_class_name]] [-bench[#_of_runs]] [-bout[benchmark_results_filename]] [-append] [-steel] [-ocean]\n" +
  150. " -laf Set the Application Look&Feel. (Look and feel must be in Classpath)\n" +
  151. " -bench Run demo as benchmark. Run count can be appended. 10 is default.\n" +
  152. " -bout Benchmark results output filename.\n" +
  153. " -append Appends the result to the -bout file.\n" +
  154. " -verbose Print the times of every run.\n" +
  155. " -steel Sets the old Steel theme for Sun's Metal look&feel.\n" +
  156. " -ocean Sets the Ocean theme for Sun's Metal look&feel.\n" +
  157. "\nExamples:\n" +
  158. " java -jar swingdemoapp.jar -bench -boutC:/bench.txt -append\n" +
  159. " java -jar swingdemoapp.jar -ocean -bench20\n" +
  160. " java -cp c:\\looks-2.0.4.jar;.\\swingdemoapp.jar net.miginfocom.demo.SwingDemo -lafcom.jgoodies.looks.plastic.PlasticLookAndFeel -bench20 -boutC:/bench.txt");
  161. System.exit(0);
  162. }
  163. }
  164. }
  165. if (benchRuns > 0)
  166. LayoutUtil.setDesignTime(null, true); // So that the string constraints to create the UnitValues is saved and can be recreated exactly.
  167. // laf = "net.sourceforge.napkinlaf.NapkinLookAndFeel";
  168. // laf = "javax.swing.plaf.metal.MetalLookAndFeel";
  169. // System.setProperty("swing.metalTheme", "steel");
  170. // laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  171. // laf = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
  172. // laf = "com.jgoodies.looks.plastic.PlasticLookAndFeel";
  173. // laf = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel";
  174. // laf = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
  175. // laf = "com.jgoodies.looks.windows.WindowsLookAndFeel";
  176. if (laf.endsWith("WindowsLookAndFeel"))
  177. buttonOpaque = false;
  178. final String laff = laf;
  179. SwingUtilities.invokeLater(new Runnable() {
  180. public void run() {
  181. try {
  182. UIManager.setLookAndFeel(laff);
  183. } catch (Exception ex) {
  184. ex.printStackTrace();
  185. }
  186. SwingDemo demo = new SwingDemo();
  187. }
  188. });
  189. }
  190. public SwingDemo()
  191. {
  192. super("MigLayout Swing Demo v2.4 - Mig Layout v" + LayoutUtil.getVersion());
  193. // if (benchRuns > 0)
  194. // RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
  195. if (benchRuns == 0) {
  196. sourceTextAreaScroll = createTextAreaScroll("", 5, 80, true);
  197. sourceTextArea = (JTextArea) sourceTextAreaScroll.getViewport().getView();
  198. }
  199. if (DEBUG) {
  200. contentPanel.add(layoutDisplayPanel, BorderLayout.CENTER);
  201. // contentPanel.add(layoutPickerTabPane, BorderLayout.WEST);
  202. // contentPanel.add(descriptionTabPane, BorderLayout.SOUTH);
  203. } else {
  204. contentPanel.add(layoutPickerTabPane, "spany,grow");
  205. contentPanel.add(layoutDisplayPanel, "grow");
  206. contentPanel.add(southTabPane, "growx");
  207. }
  208. setContentPane(contentPanel);
  209. pickerList.setOpaque(OPAQUE);
  210. ((DefaultListCellRenderer) pickerList.getCellRenderer()).setOpaque(OPAQUE);
  211. pickerList.setSelectionForeground(new Color(0, 0, 220));
  212. pickerList.setBackground(null);
  213. pickerList.setBorder(new EmptyBorder(2, 5, 0, 4));
  214. pickerList.setFont(pickerList.getFont().deriveFont(Font.BOLD));
  215. layoutPickerTabPane.addTab("Example Browser", pickerList);
  216. descrTextAreaScroll.setBorder(null);
  217. descrTextAreaScroll.setOpaque(OPAQUE);
  218. descrTextAreaScroll.getViewport().setOpaque(OPAQUE);
  219. descrTextArea.setOpaque(OPAQUE);
  220. descrTextArea.setEditable(false);
  221. descrTextArea.setBorder(new EmptyBorder(0, 4, 0, 4));
  222. southTabPane.addTab("Description", descrTextAreaScroll);
  223. if (sourceTextArea != null) {
  224. sourceTextAreaScroll.setBorder(null);
  225. sourceTextAreaScroll.setOpaque(OPAQUE);
  226. sourceTextAreaScroll.getViewport().setOpaque(OPAQUE);
  227. sourceTextAreaScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  228. sourceTextArea.setOpaque(OPAQUE);
  229. sourceTextArea.setLineWrap(false);
  230. sourceTextArea.setWrapStyleWord(false);
  231. sourceTextArea.setEditable(false);
  232. sourceTextArea.setBorder(new EmptyBorder(0, 4, 0, 4));
  233. sourceTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
  234. southTabPane.addTab("Source Code", sourceTextAreaScroll);
  235. southTabPane.addMouseListener(new MouseAdapter() {
  236. public void mouseClicked(MouseEvent e)
  237. {
  238. if (e.getClickCount() == 2)
  239. showSourceInFrame();
  240. }
  241. });
  242. }
  243. for (int i = 0; i < panels.length; i++)
  244. ((DefaultListModel) pickerList.getModel()).addElement(panels[i][0]);
  245. try {
  246. setSize(900, 650);
  247. setLocationRelativeTo(null);
  248. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  249. setVisible(true);
  250. } catch(Throwable t) {
  251. t.printStackTrace();
  252. System.exit(1);
  253. }
  254. pickerList.addListSelectionListener(new ListSelectionListener() {
  255. public void valueChanged(ListSelectionEvent e)
  256. {
  257. int ix = pickerList.getSelectedIndex();
  258. if (ix == -1 || lastIndex == ix)
  259. return;
  260. lastIndex = ix;
  261. String methodName = "create" + panels[ix][0].replace(' ', '_');
  262. layoutDisplayPanel.removeAll();
  263. try {
  264. pickerList.requestFocusInWindow();
  265. final JComponent panel = (JComponent) SwingDemo.class.getMethod(methodName, new Class[0]).invoke(SwingDemo.this, new Object[0]);
  266. layoutDisplayPanel.add(panel);
  267. descrTextArea.setText(panels[ix][1]);
  268. descrTextArea.setCaretPosition(0);
  269. contentPanel.revalidate();
  270. } catch (Exception e1) {
  271. e1.printStackTrace(); // Should never happpen...
  272. }
  273. southTabPane.setSelectedIndex(0);
  274. }
  275. });
  276. pickerList.requestFocusInWindow();
  277. Toolkit.getDefaultToolkit().setDynamicLayout(true);
  278. if (benchRuns > 0) {
  279. doBenchmark();
  280. } else {
  281. pickerList.setSelectedIndex(INITIAL_INDEX);
  282. KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
  283. public boolean dispatchKeyEvent(KeyEvent e)
  284. {
  285. if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_B && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) {
  286. startupMillis = System.currentTimeMillis();
  287. timeToShowMillis = System.currentTimeMillis() - startupMillis;
  288. benchRuns = 1;
  289. doBenchmark();
  290. return true;
  291. }
  292. return false;
  293. }
  294. });
  295. }
  296. }
  297. private void doBenchmark()
  298. {
  299. Thread benchThread = new Thread() {
  300. public void run()
  301. {
  302. for (int j = 0; j < benchRuns; j++) {
  303. lastRunTimeStart = System.currentTimeMillis();
  304. for (int i = 0, iCnt = pickerList.getModel().getSize(); i < iCnt; i++) {
  305. if (benchRuns > 0 && panels[i][0].equals("Visual Bounds"))
  306. continue; // the SWT version does not have Visual bounds...
  307. final int ii = i;
  308. try {
  309. SwingUtilities.invokeAndWait(new Runnable() {
  310. public void run() {
  311. pickerList.setSelectedIndex(ii);
  312. Toolkit.getDefaultToolkit().sync();
  313. }
  314. });
  315. } catch (Exception e) {
  316. e.printStackTrace();
  317. }
  318. Component[] comps = layoutDisplayPanel.getComponents();
  319. for (int cIx = 0; cIx < comps.length; cIx++) {
  320. if (comps[cIx] instanceof JTabbedPane) {
  321. final JTabbedPane tp = (JTabbedPane) comps[cIx];
  322. for (int k = 0, kCnt = tp.getTabCount(); k < kCnt; k++) {
  323. final int kk = k;
  324. try {
  325. SwingUtilities.invokeAndWait(new Runnable() {
  326. public void run() {
  327. tp.setSelectedIndex(kk);
  328. Toolkit.getDefaultToolkit().sync();
  329. if (timeToShowMillis == 0)
  330. timeToShowMillis = System.currentTimeMillis() - startupMillis;
  331. }
  332. });
  333. } catch (Exception e) {
  334. e.printStackTrace();
  335. }
  336. }
  337. }
  338. }
  339. }
  340. if (runTimeSB != null) {
  341. runTimeSB.append("Run ").append(j).append(": ");
  342. runTimeSB.append(System.currentTimeMillis() - lastRunTimeStart).append(" millis.\n");
  343. }
  344. }
  345. benchRunTime = System.currentTimeMillis() - startupMillis - timeToShowMillis;
  346. final String message = "Java Version: " + System.getProperty("java.version") + "\n" +
  347. "Look & Feel: " + UIManager.getLookAndFeel().getDescription() + "\n" +
  348. "Time to Show: " + timeToShowMillis + " millis.\n" +
  349. (runTimeSB != null ? runTimeSB.toString() : "") +
  350. "Benchmark Run Time: " + benchRunTime + " millis.\n" +
  351. "Average Run Time: " + (benchRunTime / benchRuns) + " millis (" + benchRuns + " runs).\n\n";
  352. if (benchOutFileName == null) {
  353. JOptionPane.showMessageDialog(SwingDemo.this, message, "Results", JOptionPane.INFORMATION_MESSAGE);
  354. } else {
  355. FileWriter fw = null;
  356. try {
  357. fw = new FileWriter(benchOutFileName, append);
  358. fw.write(message);
  359. } catch(IOException ex) {
  360. ex.printStackTrace();
  361. } finally {
  362. if (fw != null)
  363. try {fw.close();} catch(IOException ex) {}
  364. }
  365. }
  366. System.out.println(message);
  367. }
  368. };
  369. benchThread.start();
  370. }
  371. private void setSource(String source)
  372. {
  373. if (benchRuns > 0 || sourceTextArea == null)
  374. return;
  375. if (source.length() > 0) {
  376. source = source.replaceAll("\t\t", "");
  377. source = "DOUBLE CLICK TAB TO SHOW SOURCE IN SEPARATE WINDOW!\n===================================================\n\n" + source;
  378. }
  379. sourceTextArea.setText(source);
  380. sourceTextArea.setCaretPosition(0);
  381. if (sourceFrame != null && sourceFrame.isVisible()) {
  382. sourceFrameTextArea.setText(source.length() > 105 ? source.substring(105) : "No Source Code Available!");
  383. sourceFrameTextArea.setCaretPosition(0);
  384. }
  385. }
  386. private void showSourceInFrame()
  387. {
  388. if (sourceTextArea == null)
  389. return;
  390. JScrollPane sourceFrameTextAreaScroll = createTextAreaScroll("", 5, 80, true);
  391. sourceFrameTextArea = (JTextArea) sourceFrameTextAreaScroll.getViewport().getView();
  392. sourceFrameTextAreaScroll.setBorder(null);
  393. sourceFrameTextAreaScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  394. sourceFrameTextArea.setLineWrap(false);
  395. sourceFrameTextArea.setWrapStyleWord(false);
  396. sourceFrameTextArea.setEditable(false);
  397. sourceFrameTextArea.setBorder(new EmptyBorder(10, 10, 10, 10));
  398. sourceFrameTextArea.setFont(new Font("monospaced", Font.PLAIN, 12));
  399. String source = this.sourceTextArea.getText();
  400. sourceFrameTextArea.setText(source.length() > 105 ? source.substring(105) : "No Source Code Available!");
  401. sourceFrameTextArea.setCaretPosition(0);
  402. sourceFrame = new JFrame("Source Code");
  403. sourceFrame.getContentPane().add(sourceFrameTextAreaScroll, BorderLayout.CENTER);
  404. sourceFrame.setSize(700, 800);
  405. sourceFrame.setLocationRelativeTo(this);
  406. sourceFrame.setVisible(true);
  407. }
  408. public JComponent createTest()
  409. {
  410. JComponent pane = new JPanel();
  411. pane.setLayout(new MigLayout("debug"));
  412. pane.add(new JLabel("Separator"), "gapbottom 1, ax r, spanx, split");
  413. pane.add(new JSeparator(), "gap rel, growx");
  414. JLabel label = new JLabel("<html><font color=red><b>some text in label</b></font></html>");
  415. pane.add(label, "wrap");
  416. pane.add(new JButton("Button1"));
  417. pane.add(new JButton("Button2"));
  418. pane.add(new JButton("Button3"));
  419. return pane;
  420. }
  421. public JComponent createAPI_Constraints1()
  422. {
  423. JTabbedPane tabbedPane = new JTabbedPane();
  424. LC layC = new LC().fill().wrap();
  425. AC colC = new AC().align("right", 1).fill(2, 4).grow(100, 2, 4).align("right", 3).gap("15", 2);
  426. AC rowC = new AC().align("top", 7).gap("15!", 6).grow(100, 8);
  427. JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient
  428. // References to text fields not stored to reduce code clutter.
  429. JScrollPane list2 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
  430. panel.add(list2, new CC().spanY().growY().minWidth("150").gapX(null, "10"));
  431. panel.add(new JLabel("Last Name"));
  432. panel.add(new JTextField());
  433. panel.add(new JLabel("First Name"));
  434. panel.add(new JTextField(), new CC().wrap().alignX("right"));
  435. panel.add(new JLabel("Phone"));
  436. panel.add(new JTextField());
  437. panel.add(new JLabel("Email"));
  438. panel.add(new JTextField());
  439. panel.add(new JLabel("Address 1"));
  440. panel.add(new JTextField(), new CC().spanX().growX());
  441. panel.add(new JLabel("Address 2"));
  442. panel.add(new JTextField(), new CC().spanX().growX());
  443. panel.add(new JLabel("City"));
  444. panel.add(new JTextField(), new CC().wrap());
  445. panel.add(new JLabel("State"));
  446. panel.add(new JTextField());
  447. panel.add(new JLabel("Postal Code"));
  448. panel.add(new JTextField(10), new CC().spanX(2).growX(0));
  449. panel.add(new JLabel("Country"));
  450. panel.add(new JTextField(), new CC().wrap());
  451. panel.add(new JButton("New"), new CC().spanX(5).split(5).tag("other"));
  452. panel.add(new JButton("Delete"), new CC().tag("other"));
  453. panel.add(new JButton("Edit"), new CC().tag("other"));
  454. panel.add(new JButton("Save"), new CC().tag("other"));
  455. panel.add(new JButton("Cancel"), new CC().tag("cancel"));
  456. tabbedPane.addTab("Layout Showdown (improved)", panel);
  457. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  458. "\n" +
  459. "LC layC = new LC().fill().wrap();\n" +
  460. "AC colC = new AC().align(\"right\", 1).fill(2, 4).grow(100, 2, 4).align(\"right\", 3).gap(\"15\", 2);\n" +
  461. "AC rowC = new AC().align(\"top\", 7).gap(\"15!\", 6).grow(100, 8);\n" +
  462. "\n" +
  463. "JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient\n" +
  464. "\n" +
  465. "// References to text fields not stored to reduce code clutter.\n" +
  466. "\n" +
  467. "JScrollPane list2 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
  468. "panel.add(list2, new CC().spanY().growY().minWidth(\"150\").gapX(null, \"10\"));\n" +
  469. "\n" +
  470. "panel.add(new JLabel(\"Last Name\"));\n" +
  471. "panel.add(new JTextField());\n" +
  472. "panel.add(new JLabel(\"First Name\"));\n" +
  473. "panel.add(new JTextField(), new CC().wrap().alignX(\"right\"));\n" +
  474. "panel.add(new JLabel(\"Phone\"));\n" +
  475. "panel.add(new JTextField());\n" +
  476. "panel.add(new JLabel(\"Email\"));\n" +
  477. "panel.add(new JTextField());\n" +
  478. "panel.add(new JLabel(\"Address 1\"));\n" +
  479. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  480. "panel.add(new JLabel(\"Address 2\"));\n" +
  481. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  482. "panel.add(new JLabel(\"City\"));\n" +
  483. "panel.add(new JTextField(), new CC().wrap());\n" +
  484. "panel.add(new JLabel(\"State\"));\n" +
  485. "panel.add(new JTextField());\n" +
  486. "panel.add(new JLabel(\"Postal Code\"));\n" +
  487. "panel.add(new JTextField(10), new CC().spanX(2).growX(0));\n" +
  488. "panel.add(new JLabel(\"Country\"));\n" +
  489. "panel.add(new JTextField(), new CC().wrap());\n" +
  490. "\n" +
  491. "panel.add(new JButton(\"New\"), new CC().spanX(5).split(5).tag(\"other\"));\n" +
  492. "panel.add(new JButton(\"Delete\"), new CC().tag(\"other\"));\n" +
  493. "panel.add(new JButton(\"Edit\"), new CC().tag(\"other\"));\n" +
  494. "panel.add(new JButton(\"Save\"), new CC().tag(\"other\"));\n" +
  495. "panel.add(new JButton(\"Cancel\"), new CC().tag(\"cancel\"));\n" +
  496. "\n" +
  497. "tabbedPane.addTab(\"Layout Showdown (improved)\", panel);");
  498. return tabbedPane;
  499. }
  500. public JComponent createAPI_Constraints2()
  501. {
  502. JTabbedPane tabbedPane = new JTabbedPane();
  503. LC layC = new LC().fill().wrap();
  504. AC colC = new AC().align("right", 0).fill(1, 3).grow(100, 1, 3).align("right", 2).gap("15", 1);
  505. AC rowC = new AC().index(6).gap("15!").align("top").grow(100, 8);
  506. JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient
  507. // References to text fields not stored to reduce code clutter.
  508. panel.add(new JLabel("Last Name"));
  509. panel.add(new JTextField());
  510. panel.add(new JLabel("First Name"));
  511. panel.add(new JTextField(), new CC().wrap());
  512. panel.add(new JLabel("Phone"));
  513. panel.add(new JTextField());
  514. panel.add(new JLabel("Email"));
  515. panel.add(new JTextField());
  516. panel.add(new JLabel("Address 1"));
  517. panel.add(new JTextField(), new CC().spanX().growX());
  518. panel.add(new JLabel("Address 2"));
  519. panel.add(new JTextField(), new CC().spanX().growX());
  520. panel.add(new JLabel("City"));
  521. panel.add(new JTextField(), new CC().wrap());
  522. panel.add(new JLabel("State"));
  523. panel.add(new JTextField());
  524. panel.add(new JLabel("Postal Code"));
  525. panel.add(new JTextField(10), new CC().spanX(2).growX(0));
  526. panel.add(new JLabel("Country"));
  527. panel.add(new JTextField(), new CC().wrap());
  528. panel.add(createButton("New"), new CC().spanX(5).split(5).tag("other"));
  529. panel.add(createButton("Delete"), new CC().tag("other"));
  530. panel.add(createButton("Edit"), new CC().tag("other"));
  531. panel.add(createButton("Save"), new CC().tag("other"));
  532. panel.add(createButton("Cancel"), new CC().tag("cancel"));
  533. tabbedPane.addTab("Layout Showdown (improved)", panel);
  534. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  535. "\n" +
  536. "LC layC = new LC().fill().wrap();\n" +
  537. "AC colC = new AC().align(\"right\", 0).fill(1, 3).grow(100, 1, 3).align(\"right\", 2).gap(\"15\", 1);\n" +
  538. "AC rowC = new AC().index(6).gap(\"15!\").align(\"top\").grow(100, 8);\n" +
  539. "\n" +
  540. "JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient\n" +
  541. "\n" +
  542. "// References to text fields not stored to reduce code clutter.\n" +
  543. "\n" +
  544. "panel.add(new JLabel(\"Last Name\"));\n" +
  545. "panel.add(new JTextField());\n" +
  546. "panel.add(new JLabel(\"First Name\"));\n" +
  547. "panel.add(new JTextField(), new CC().wrap());\n" +
  548. "panel.add(new JLabel(\"Phone\"));\n" +
  549. "panel.add(new JTextField());\n" +
  550. "panel.add(new JLabel(\"Email\"));\n" +
  551. "panel.add(new JTextField());\n" +
  552. "panel.add(new JLabel(\"Address 1\"));\n" +
  553. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  554. "panel.add(new JLabel(\"Address 2\"));\n" +
  555. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  556. "panel.add(new JLabel(\"City\"));\n" +
  557. "panel.add(new JTextField(), new CC().wrap());\n" +
  558. "panel.add(new JLabel(\"State\"));\n" +
  559. "panel.add(new JTextField());\n" +
  560. "panel.add(new JLabel(\"Postal Code\"));\n" +
  561. "panel.add(new JTextField(10), new CC().spanX(2).growX(0));\n" +
  562. "panel.add(new JLabel(\"Country\"));\n" +
  563. "panel.add(new JTextField(), new CC().wrap());\n" +
  564. "\n" +
  565. "panel.add(createButton(\"New\"), new CC().spanX(5).split(5).tag(\"other\"));\n" +
  566. "panel.add(createButton(\"Delete\"), new CC().tag(\"other\"));\n" +
  567. "panel.add(createButton(\"Edit\"), new CC().tag(\"other\"));\n" +
  568. "panel.add(createButton(\"Save\"), new CC().tag(\"other\"));\n" +
  569. "panel.add(createButton(\"Cancel\"), new CC().tag(\"cancel\"));\n" +
  570. "\n" +
  571. "tabbedPane.addTab(\"Layout Showdown (improved)\", panel);");
  572. return tabbedPane;
  573. }
  574. public JComponent createLayout_Showdown()
  575. {
  576. JTabbedPane tabbedPane = new JTabbedPane();
  577. JPanel p = createTabPanel(new MigLayout("", "[]15[][grow,fill]15[grow]"));
  578. JScrollPane list1 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
  579. p.add(list1, "spany, growy, wmin 150");
  580. p.add(new JLabel("Last Name"));
  581. p.add(new JTextField());
  582. p.add(new JLabel("First Name"), "split"); // split divides the cell
  583. p.add(new JTextField(), "growx, wrap");
  584. p.add(new JLabel("Phone"));
  585. p.add(new JTextField());
  586. p.add(new JLabel("Email"), "split");
  587. p.add(new JTextField(), "growx, wrap");
  588. p.add(new JLabel("Address 1"));
  589. p.add(new JTextField(), "span, growx"); // span merges cells
  590. p.add(new JLabel("Address 2"));
  591. p.add(new JTextField(), "span, growx");
  592. p.add(new JLabel("City"));
  593. p.add(new JTextField(), "wrap"); // wrap continues on next line
  594. p.add(new JLabel("State"));
  595. p.add(new JTextField());
  596. p.add(new JLabel("Postal Code"), "split");
  597. p.add(new JTextField(), "growx, wrap");
  598. p.add(new JLabel("Country"));
  599. p.add(new JTextField(), "wrap 15");
  600. p.add(createButton("New"), "span, split, align left");
  601. p.add(createButton("Delete"), "");
  602. p.add(createButton("Edit"), "");
  603. p.add(createButton("Save"), "");
  604. p.add(createButton("Cancel"), "wrap push");
  605. tabbedPane.addTab("Layout Showdown (pure)", p);
  606. // Fixed version *******************************************
  607. JPanel p2 = createTabPanel(new MigLayout("", "[]15[][grow,fill]15[][grow,fill]")); // Makes the background gradient
  608. // References to text fields not stored to reduce code clutter.
  609. JScrollPane list2 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
  610. p2.add(list2, "spany, growy, wmin 150");
  611. p2.add(new JLabel("Last Name"));
  612. p2.add(new JTextField());
  613. p2.add(new JLabel("First Name"));
  614. p2.add(new JTextField(), "wrap");
  615. p2.add(new JLabel("Phone"));
  616. p2.add(new JTextField());
  617. p2.add(new JLabel("Email"));
  618. p2.add(new JTextField(), "wrap");
  619. p2.add(new JLabel("Address 1"));
  620. p2.add(new JTextField(), "span");
  621. p2.add(new JLabel("Address 2"));
  622. p2.add(new JTextField(), "span");
  623. p2.add(new JLabel("City"));
  624. p2.add(new JTextField(), "wrap");
  625. p2.add(new JLabel("State"));
  626. p2.add(new JTextField());
  627. p2.add(new JLabel("Postal Code"));
  628. p2.add(new JTextField(10), "growx 0, wrap");
  629. p2.add(new JLabel("Country"));
  630. p2.add(new JTextField(), "wrap 15");
  631. p2.add(createButton("New"), "tag other, span, split");
  632. p2.add(createButton("Delete"), "tag other");
  633. p2.add(createButton("Edit"), "tag other");
  634. p2.add(createButton("Save"), "tag other");
  635. p2.add(createButton("Cancel"), "tag cancel, wrap push");
  636. tabbedPane.addTab("Layout Showdown (improved)", p2);
  637. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  638. "\n" +
  639. "JPanel p = createTabPanel(new MigLayout(\"\", \"[]15[][grow,fill]15[grow]\"));\n" +
  640. "\n" +
  641. "JScrollPane list1 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
  642. "\n" +
  643. "p.add(list1, \"spany, growy, wmin 150\");\n" +
  644. "p.add(new JLabel(\"Last Name\"));\n" +
  645. "p.add(new JTextField());\n" +
  646. "p.add(new JLabel(\"First Name\"), \"split\"); // split divides the cell\n" +
  647. "p.add(new JTextField(), \"growx, wrap\");\n" +
  648. "p.add(new JLabel(\"Phone\"));\n" +
  649. "p.add(new JTextField());\n" +
  650. "p.add(new JLabel(\"Email\"), \"split\");\n" +
  651. "p.add(new JTextField(), \"growx, wrap\");\n" +
  652. "p.add(new JLabel(\"Address 1\"));\n" +
  653. "p.add(new JTextField(), \"span, growx\"); // span merges cells\n" +
  654. "p.add(new JLabel(\"Address 2\"));\n" +
  655. "p.add(new JTextField(), \"span, growx\");\n" +
  656. "p.add(new JLabel(\"City\"));\n" +
  657. "p.add(new JTextField(), \"wrap\"); // wrap continues on next line\n" +
  658. "p.add(new JLabel(\"State\"));\n" +
  659. "p.add(new JTextField());\n" +
  660. "p.add(new JLabel(\"Postal Code\"), \"split\");\n" +
  661. "p.add(new JTextField(), \"growx, wrap\");\n" +
  662. "p.add(new JLabel(\"Country\"));\n" +
  663. "p.add(new JTextField(), \"wrap 15\");\n" +
  664. "\n" +
  665. "p.add(createButton(\"New\"), \"span, split, align left\");\n" +
  666. "p.add(createButton(\"Delete\"), \"\");\n" +
  667. "p.add(createButton(\"Edit\"), \"\");\n" +
  668. "p.add(createButton(\"Save\"), \"\");\n" +
  669. "p.add(createButton(\"Cancel\"), \"wrap push\");\n" +
  670. "\n" +
  671. "tabbedPane.addTab(\"Layout Showdown (pure)\", p);" +
  672. "\n" +
  673. "\t\t// Fixed version *******************************************\n" +
  674. "JPanel p2 = createTabPanel(new MigLayout(\"\", \"[]15[][grow,fill]15[][grow,fill]\")); // Makes the background gradient\n" +
  675. "\n" +
  676. "// References to text fields not stored to reduce code clutter.\n" +
  677. "\n" +
  678. "JScrollPane list2 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
  679. "p2.add(list2, \"spany, growy, wmin 150\");\n" +
  680. "p2.add(new JLabel(\"Last Name\"));\n" +
  681. "p2.add(new JTextField());\n" +
  682. "p2.add(new JLabel(\"First Name\"));\n" +
  683. "p2.add(new JTextField(), \"wrap\");\n" +
  684. "p2.add(new JLabel(\"Phone\"));\n" +
  685. "p2.add(new JTextField());\n" +
  686. "p2.add(new JLabel(\"Email\"));\n" +
  687. "p2.add(new JTextField(), \"wrap\");\n" +
  688. "p2.add(new JLabel(\"Address 1\"));\n" +
  689. "p2.add(new JTextField(), \"span\");\n" +
  690. "p2.add(new JLabel(\"Address 2\"));\n" +
  691. "p2.add(new JTextField(), \"span\");\n" +
  692. "p2.add(new JLabel(\"City\"));\n" +
  693. "p2.add(new JTextField(), \"wrap\");\n" +
  694. "p2.add(new JLabel(\"State\"));\n" +
  695. "p2.add(new JTextField());\n" +
  696. "p2.add(new JLabel(\"Postal Code\"));\n" +
  697. "p2.add(new JTextField(10), \"growx 0, wrap\");\n" +
  698. "p2.add(new JLabel(\"Country\"));\n" +
  699. "p2.add(new JTextField(), \"wrap 15\");\n" +
  700. "\n" +
  701. "p2.add(createButton(\"New\"), \"tag other, span, split\");\n" +
  702. "p2.add(createButton(\"Delete\"), \"tag other\");\n" +
  703. "p2.add(createButton(\"Edit\"), \"tag other\");\n" +
  704. "p2.add(createButton(\"Save\"), \"tag other\");\n" +
  705. "p2.add(createButton(\"Cancel\"), \"tag cancel, wrap push\");\n" +
  706. "\n" +
  707. "tabbedPane.addTab(\"Layout Showdown (improved)\", p2);");
  708. return tabbedPane;
  709. }
  710. public JComponent createWelcome()
  711. {
  712. JTabbedPane tabbedPane = new JTabbedPane();
  713. MigLayout lm = new MigLayout("ins 20, fill", "", "[grow]unrel[]");
  714. JPanel mainPanel = createTabPanel(lm);
  715. String s = "MigLayout's main purpose is to make layouts for SWT and Swing, and possibly other frameworks, much more powerful and a lot easier to create, especially for manual coding.\n\n" +
  716. "The motto is: \"MigLayout makes complex layouts easy and normal layouts one-liners.\"\n\n" +
  717. "The layout engine is very flexible and advanced, something that is needed to make it simple to use yet handle almost all layout use-cases.\n\n" +
  718. "MigLayout can handle all layouts that the commonly used Swing Layout Managers can handle and this with a lot of extra features. " +
  719. "It also incorporates most, if not all, of the open source alternatives FormLayout's and TableLayout's functionality." +
  720. "\n\n\nThanks to Karsten Lentzsch of JGoodies.com for allowing the reuse of the main demo application layout and for his inspiring talks that led to this layout Manager." +
  721. "\n\n\nMikael Grev\n" +
  722. "MiG InfoCom AB\n" +
  723. "miglayout@miginfocom.com";
  724. JTextArea textArea = new JTextArea(s);
  725. textArea.setEditable(false);
  726. textArea.setSize(400, 400);
  727. if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.WINDOWS_XP)
  728. textArea.setFont(new Font("tahoma", Font.BOLD, 11));
  729. textArea.setOpaque(OPAQUE);
  730. textArea.setWrapStyleWord(true);
  731. textArea.setLineWrap(true);
  732. JLabel label = new JLabel("You can Right Click any Component or Container to change the constraints for it!");
  733. label.setForeground(new Color(200, 0, 0));
  734. mainPanel.add(textArea, "w 500:pref,ay top,grow,wrap");
  735. mainPanel.add(label, "growx");
  736. label.setFont(label.getFont().deriveFont(Font.BOLD));
  737. tabbedPane.addTab("Welcome", mainPanel);
  738. setSource("");
  739. return tabbedPane;
  740. }
  741. public JComponent createVisual_Bounds()
  742. {
  743. JTabbedPane tabbedPane = new JTabbedPane();
  744. // "NON"-corrected bounds
  745. JPanel p1 = createTabPanel(new MigLayout("fill, ins 3, novisualpadding"));
  746. p1.setBorder(new LineBorder(Color.BLACK));
  747. JTabbedPane demoPane2 = new JTabbedPane();
  748. JPanel demoPanel2 = new JPanel();
  749. demoPanel2.setBackground(Color.WHITE);
  750. demoPane2.addTab("Demo Tab", demoPanel2);
  751. p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  752. p1.add(demoPane2, "grow, aligny bottom");
  753. p1.add(createTextField("A JTextField", 100), "grow, aligny bottom, wmin 100");
  754. p1.add(createTextArea("A JTextArea", 1, 100), "newline,grow, aligny bottom, wmin 100");
  755. p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  756. p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  757. JPanel p2 = createTabPanel(new MigLayout("center,center,fill,ins 3"));
  758. p2.setBorder(new LineBorder(Color.BLACK));
  759. JTabbedPane demoPane = new JTabbedPane();
  760. JPanel demoPanel = new JPanel();
  761. demoPanel.setBackground(Color.WHITE);
  762. demoPane.addTab("Demo Tab", demoPanel);
  763. p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  764. p2.add(demoPane, "grow, aligny bottom");
  765. p2.add(createTextField("A JTextField", 100), "grow, aligny bottom, wmin 100");
  766. p2.add(createTextArea("A JTextArea", 1, 100), "newline,grow, aligny bottom, wmin 100");
  767. p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  768. p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  769. tabbedPane.addTab("Visual Bounds (Not Corrected)", p1);
  770. tabbedPane.addTab("Visual Bounds (Corrected on XP)", p2);
  771. // Disregard. Just forgetting the source code text close to the source code.
  772. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  773. "\n" +
  774. "// \"NON\"-corrected bounds\n" +
  775. "JPanel p1 = createTabPanel(new MigLayout(\"fill, ins 3, novisualpadding\"));\n" +
  776. "p1.setBorder(new LineBorder(Color.BLACK));\n" +
  777. "\n" +
  778. "JTabbedPane demoPane2 = new JTabbedPane();\n" +
  779. "JPanel demoPanel2 = new JPanel();\n" +
  780. "demoPanel2.setBackground(Color.WHITE);\n" +
  781. "demoPane2.addTab(\"Demo Tab\", demoPanel2);\n" +
  782. "\n" +
  783. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  784. "p1.add(demoPane2, \"grow, aligny bottom\");\n" +
  785. "p1.add(createTextField(\"A JTextField\", 100), \"grow, aligny bottom, wmin 100\");\n" +
  786. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"newline,grow, aligny bottom, wmin 100\");\n" +
  787. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  788. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  789. "\n" +
  790. "JPanel p2 = createTabPanel(new MigLayout(\"center,center,fill,ins 3\"));\n" +
  791. "p2.setBorder(new LineBorder(Color.BLACK));\n" +
  792. "\n" +
  793. "JTabbedPane demoPane = new JTabbedPane();\n" +
  794. "JPanel demoPanel = new JPanel();\n" +
  795. "demoPanel.setBackground(Color.WHITE);\n" +
  796. "demoPane.addTab(\"Demo Tab\", demoPanel);\n" +
  797. "\n" +
  798. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  799. "p2.add(demoPane, \"grow, aligny bottom\");\n" +
  800. "p2.add(createTextField(\"A JTextField\", 100), \"grow, aligny bottom, wmin 100\");\n" +
  801. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"newline,grow, aligny bottom, wmin 100\");\n" +
  802. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  803. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  804. "\n" +
  805. "tabbedPane.addTab(\"Visual Bounds (Not Corrected)\", p1);\n" +
  806. "tabbedPane.addTab(\"Visual Bounds (Corrected on XP)\", p2);");
  807. return tabbedPane;
  808. }
  809. public JComponent createDocking()
  810. {
  811. JTabbedPane tabbedPane = new JTabbedPane();
  812. JPanel p1 = createTabPanel(new MigLayout("fill"));
  813. p1.add(createPanel("1. North"), "north");
  814. p1.add(createPanel("2. West"), "west");
  815. p1.add(createPanel("3. East"), "east");
  816. p1.add(createPanel("4. South"), "south");
  817. String[][] data = new String[20][6];
  818. for (int r = 0; r < data.length; r++) {
  819. data[r] = new String[6];
  820. for (int c = 0; c < data[r].length; c++)
  821. data[r][c] = "Cell " + (r + 1) + ", " + (c + 1);
  822. }
  823. JTable table = new JTable(data, new String[] {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6"});
  824. p1.add(new JScrollPane(table), "grow");
  825. JPanel p2 = createTabPanel(new MigLayout("fill", "[c]", ""));
  826. p2.add(createPanel("1. North"), "north");
  827. p2.add(createPanel("2. North"), "north");
  828. p2.add(createPanel("3. West"), "west");
  829. p2.add(createPanel("4. West"), "west");
  830. p2.add(createPanel("5. South"), "south");
  831. p2.add(createPanel("6. East"), "east");
  832. p2.add(createButton("7. Normal"));
  833. p2.add(createButton("8. Normal"));
  834. p2.add(createButton("9. Normal"));
  835. JPanel p3 = createTabPanel(new MigLayout());
  836. p3.add(createPanel("1. North"), "north");
  837. p3.add(createPanel("2. South"), "south");
  838. p3.add(createPanel("3. West"), "west");
  839. p3.add(createPanel("4. East"), "east");
  840. p3.add(createButton("5. Normal"));
  841. JPanel p4 = createTabPanel(new MigLayout());
  842. p4.add(createPanel("1. North"), "north");
  843. p4.add(createPanel("2. North"), "north");
  844. p4.add(createPanel("3. West"), "west");
  845. p4.add(createPanel("4. West"), "west");
  846. p4.add(createPanel("5. South"), "south");
  847. p4.add(createPanel("6. East"), "east");
  848. p4.add(createButton("7. Normal"));
  849. p4.add(createButton("8. Normal"));
  850. p4.add(createButton("9. Normal"));
  851. JPanel p5 = createTabPanel(new MigLayout("fillx", "[c]", ""));
  852. p5.add(createPanel("1. North"), "north");
  853. p5.add(createPanel("2. North"), "north");
  854. p5.add(createPanel("3. West"), "west");
  855. p5.add(createPanel("4. West"), "west");
  856. p5.add(createPanel("5. South"), "south");
  857. p5.add(createPanel("6. East"), "east");
  858. p5.add(createButton("7. Normal"));
  859. p5.add(createButton("8. Normal"));
  860. p5.add(createButton("9. Normal"));
  861. JPanel p6 = createTabPanel(new MigLayout("fill", "", ""));
  862. Random rand = new Random();
  863. String[] sides = {"north", "east", "south", "west"};
  864. for (int i = 0; i < 20; i++) {
  865. int side = rand.nextInt(4);
  866. p6.add(createPanel((i + 1) + " " + sides[side]), sides[side]);
  867. }
  868. p6.add(createPanel("I'm in the Center!"), "dock center");
  869. tabbedPane.addTab("Docking 1 (fill)", p1);
  870. tabbedPane.addTab("Docking 2 (fill)", p2);
  871. tabbedPane.addTab("Docking 3", p3);
  872. tabbedPane.addTab("Docking 4", p4);
  873. tabbedPane.addTab("Docking 5 (fillx)", p5);
  874. tabbedPane.addTab("Random Docking", new JScrollPane(p6));
  875. // Disregard. Just forgetting the source code text close to the source code.
  876. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  877. "\n" +
  878. "JPanel p1 = createTabPanel(new MigLayout(\"fill\"));\n" +
  879. "\n" +
  880. "p1.add(createPanel(\"1. North\"), \"north\");\n" +
  881. "p1.add(createPanel(\"2. West\"), \"west\");\n" +
  882. "p1.add(createPanel(\"3. East\"), \"east\");\n" +
  883. "p1.add(createPanel(\"4. South\"), \"south\");\n" +
  884. "\n" +
  885. "String[][] data = new String[20][6];\n" +
  886. "for (int r = 0; r < data.length; r++) {\n" +
  887. "\tdata[r] = new String[6];\n" +
  888. "\tfor (int c = 0; c < data[r].length; c++)\n" +
  889. "\t\tdata[r][c] = \"Cell \" + (r + 1) + \", \" + (c + 1);\n" +
  890. "}\n" +
  891. "JTable table = new JTable(data, new String[] {\"Column 1\", \"Column 2\", \"Column 3\", \"Column 4\", \"Column 5\", \"Column 6\"});\n" +
  892. "p1.add(new JScrollPane(table), \"grow\");\n" +
  893. "\n" +
  894. "JPanel p2 = createTabPanel(new MigLayout(\"fill\", \"[c]\", \"\"));\n" +
  895. "\n" +
  896. "p2.add(createPanel(\"1. North\"), \"north\");\n" +
  897. "p2.add(createPanel(\"2. North\"), \"north\");\n" +
  898. "p2.add(createPanel(\"3. West\"), \"west\");\n" +
  899. "p2.add(createPanel(\"4. West\"), \"west\");\n" +
  900. "p2.add(createPanel(\"5. South\"), \"south\");\n" +
  901. "p2.add(createPanel(\"6. East\"), \"east\");\n" +
  902. "p2.add(createButton(\"7. Normal\"));\n" +
  903. "p2.add(createButton(\"8. Normal\"));\n" +
  904. "p2.add(createButton(\"9. Normal\"));\n" +
  905. "\n" +
  906. "JPanel p3 = createTabPanel(new MigLayout());\n" +
  907. "\n" +
  908. "p3.add(createPanel(\"1. North\"), \"north\");\n" +
  909. "p3.add(createPanel(\"2. South\"), \"south\");\n" +
  910. "p3.add(createPanel(\"3. West\"), \"west\");\n" +
  911. "p3.add(createPanel(\"4. East\"), \"east\");\n" +
  912. "p3.add(createButton(\"5. Normal\"));\n" +
  913. "\n" +
  914. "JPanel p4 = createTabPanel(new MigLayout());\n" +
  915. "\n" +
  916. "p4.add(createPanel(\"1. North\"), \"north\");\n" +
  917. "p4.add(createPanel(\"2. North\"), \"north\");\n" +
  918. "p4.add(createPanel(\"3. West\"), \"west\");\n" +
  919. "p4.add(createPanel(\"4. West\"), \"west\");\n" +
  920. "p4.add(createPanel(\"5. South\"), \"south\");\n" +
  921. "p4.add(createPanel(\"6. East\"), \"east\");\n" +
  922. "p4.add(createButton(\"7. Normal\"));\n" +
  923. "p4.add(createButton(\"8. Normal\"));\n" +
  924. "p4.add(createButton(\"9. Normal\"));\n" +
  925. "\n" +
  926. "JPanel p5 = createTabPanel(new MigLayout(\"fillx\", \"[c]\", \"\"));\n" +
  927. "\n" +
  928. "p5.add(createPanel(\"1. North\"), \"north\");\n" +
  929. "p5.add(createPanel(\"2. North\"), \"north\");\n" +
  930. "p5.add(createPanel(\"3. West\"), \"west\");\n" +
  931. "p5.add(createPanel(\"4. West\"), \"west\");\n" +
  932. "p5.add(createPanel(\"5. South\"), \"south\");\n" +
  933. "p5.add(createPanel(\"6. East\"), \"east\");\n" +
  934. "p5.add(createButton(\"7. Normal\"));\n" +
  935. "p5.add(createButton(\"8. Normal\"));\n" +
  936. "p5.add(createButton(\"9. Normal\"));\n" +
  937. "\n" +
  938. "JPanel p6 = createTabPanel(new MigLayout(\"fill\", \"\", \"\"));\n" +
  939. "\n" +
  940. "Random rand = new Random();\n" +
  941. "String[] sides = {\"north\", \"east\", \"south\", \"west\"};\n" +
  942. "for (int i = 0; i < 20; i++) {\n" +
  943. "\tint side = rand.nextInt(4);\n" +
  944. "\tp6.add(createPanel((i + 1) + \" \" + sides[side]), sides[side]);\n" +
  945. "}\n" +
  946. "p6.add(createButton(\"I'm in the middle!\"), \"grow\");\n" +
  947. "\n" +
  948. "tabbedPane.addTab(\"Docking 1 (fill)\", p1);\n" +
  949. "tabbedPane.addTab(\"Docking 2 (fill)\", p2);\n" +
  950. "tabbedPane.addTab(\"Docking 3\", p3);\n" +
  951. "tabbedPane.addTab(\"Docking 4\", p4);\n" +
  952. "tabbedPane.addTab(\"Docking 5 (fillx)\", p5);\n" +
  953. "tabbedPane.addTab(\"Docking Spiral\", new JScrollPane(p6));");
  954. return tabbedPane;
  955. }
  956. public JComponent createAbsolute_Position()
  957. {
  958. JTabbedPane tabbedPane = new JTabbedPane();
  959. // Pos tab
  960. final JPanel posPanel = createTabPanel(new MigLayout());
  961. posPanel.add(createButton(), "pos 0.5al 0al");
  962. posPanel.add(createButton(), "pos 1al 0al");
  963. posPanel.add(createButton(), "pos 0.5al 0.5al");
  964. posPanel.add(createButton(), "pos 5in 45lp");
  965. posPanel.add(createButton(), "pos 0.5al 0.5al");
  966. posPanel.add(createButton(), "pos 0.5al 1.0al");
  967. posPanel.add(createButton(), "pos 1al .25al");
  968. posPanel.add(createButton(), "pos visual.x2-pref visual.y2-pref");
  969. posPanel.add(createButton(), "pos 1al -1in");
  970. posPanel.add(createButton(), "pos 100 100");
  971. posPanel.add(createButton(), "pos (10+(20*3lp)) 200");
  972. posPanel.add(createButton("Drag Window! (pos 500-container.xpos 500-container.ypos)"),
  973. "pos 500-container.xpos 500-container.ypos");
  974. // Bounds tab
  975. JPanel boundsPanel = createTabPanel(new MigLayout());
  976. String constr = "pos (visual.x+visual.w*0.1) visual.y2-40 (visual.x2-visual.w*0.1) visual.y2";
  977. JLabel southLabel = createLabel(constr, SwingConstants.CENTER);
  978. southLabel.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
  979. southLabel.setBackground(new Color(200, 200, 255, benchRuns == 0 ? 70 : 255));
  980. southLabel.setOpaque(true);
  981. southLabel.setFont(southLabel.getFont().deriveFont(Font.BOLD));
  982. boundsPanel.add(southLabel, constr);
  983. boundsPanel.add(createButton(), "pos 0 0 container.x2 n");
  984. boundsPanel.add(createButton(), "pos visual.x 40 visual.x2 70");
  985. boundsPanel.add(createButton(), "pos visual.x 100 visual.x2 p");
  986. boundsPanel.add(createButton(), "pos 0.1al 0.4al n (visual.y2 - 10)");
  987. boundsPanel.add(createButton(), "pos 0.9al 0.4al n visual.y2-10");
  988. boundsPanel.add(createButton(), "pos 0.5al 0.5al, pad 3 0 -3 0");
  989. boundsPanel.add(createButton(), "pos n n 50% 50%");
  990. boundsPanel.add(createButton(), "pos 50% 50% n n");
  991. boundsPanel.add(createButton(), "pos 50% n n 50%");
  992. boundsPanel.add(createButton(), "pos n 50% 50% n");
  993. tabbedPane.addTab("X Y Positions", posPanel);
  994. tabbedPane.addTab("X1 Y1 X2 Y2 Bounds", boundsPanel);
  995. // Glass pane tab
  996. if (benchRuns == 0) {
  997. final JPanel glassPanel = createTabPanel(new MigLayout("align c c, ins 0"));
  998. final JButton butt = createButton("Press me!!");
  999. glassPanel.add(butt);
  1000. butt.addActionListener(new ActionListener() {
  1001. public void actionPerformed(ActionEvent e)
  1002. {
  1003. butt.setEnabled(false);
  1004. final JPanel bg = new JPanel(new MigLayout("align c c,fill")) {
  1005. public void paint(Graphics g)
  1006. {
  1007. g.setColor(getBackground());
  1008. g.fillRect(0, 0, getWidth(), getHeight());
  1009. super.paint(g);
  1010. }
  1011. };
  1012. bg.setOpaque(OPAQUE);
  1013. configureActiveComponet(bg);
  1014. final JLabel label = createLabel("You don't need a GlassPane to be cool!");
  1015. label.setFont(label.getFont().deriveFont(30f));
  1016. label.setForeground(new Color(255, 255, 255, 0));
  1017. bg.add(label, "align 50% 30%");
  1018. glassPanel.add(bg, "pos visual.x visual.y visual.x2 visual.y2", 0);
  1019. final long startTime = System.nanoTime();
  1020. final long endTime = startTime + 500000000L;
  1021. glassPanel.revalidate();
  1022. final javax.swing.Timer timer = new Timer(25, null);
  1023. timer.addActionListener(new ActionListener() {
  1024. public void actionPerformed(ActionEvent e)
  1025. {
  1026. long now = System.nanoTime();
  1027. int alpha = (int) (((now - startTime) / (double) (endTime - startTime)) * 300);
  1028. if (alpha < 150)
  1029. bg.setBackground(new Color(100, 100, 100, alpha));
  1030. if (alpha > 150 && alpha < 405) {
  1031. label.setForeground(new Color(255, 255, 255, (alpha - 150)));
  1032. bg.repaint();
  1033. }
  1034. if (alpha > 405)
  1035. timer.stop();
  1036. }
  1037. });
  1038. timer.start();
  1039. }
  1040. });
  1041. tabbedPane.addTab("GlassPane Substitute", glassPanel);
  1042. addComponentListener(new ComponentAdapter() {
  1043. public void componentMoved(ComponentEvent e) {
  1044. if (posPanel.isDisplayable()) {
  1045. posPanel.revalidate();
  1046. } else {
  1047. removeComponentListener(this);
  1048. }
  1049. }
  1050. });
  1051. }
  1052. // Disregard. Just forgetting the source code text close to the source code.
  1053. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1054. "\n" +
  1055. "// Pos tab\n" +
  1056. "final JPanel posPanel = createTabPanel(new MigLayout());\n" +
  1057. "\n" +
  1058. "posPanel.add(createButton(), \"pos 0.5al 0al\");\n" +
  1059. "posPanel.add(createButton(), \"pos 1al 0al\");\n" +
  1060. "posPanel.add(createButton(), \"pos 0.5al 0.5al\");\n" +
  1061. "posPanel.add(createButton(), \"pos 5in 45lp\");\n" +
  1062. "posPanel.add(createButton(), \"pos 0.5al 0.5al\");\n" +
  1063. "posPanel.add(createButton(), \"pos 0.5al 1.0al\");\n" +
  1064. "posPanel.add(createButton(), \"pos 1al .25al\");\n" +
  1065. "posPanel.add(createButton(), \"pos visual.x2-pref visual.y2-pref\");\n" +
  1066. "posPanel.add(createButton(), \"pos 1al -1in\");\n" +
  1067. "posPanel.add(createButton(), \"pos 100 100\");\n" +
  1068. "posPanel.add(createButton(), \"pos (10+(20*3lp)) 200\");\n" +
  1069. "posPanel.add(createButton(\"Drag Window! (pos 500-container.xpos 500-container.ypos)\"),\n" +
  1070. " \"pos 500-container.xpos 500-container.ypos\");\n" +
  1071. "\n" +
  1072. "// Bounds tab\n" +
  1073. "JPanel boundsPanel = createTabPanel(new MigLayout());\n" +
  1074. "\n" +
  1075. "String constr = \"pos (visual.x+visual.w*0.1) visual.y2-40 (visual.x2-visual.w*0.1) visual.y2\";\n" +
  1076. "JLabel southLabel = createLabel(constr, SwingConstants.CENTER);\n" +
  1077. "southLabel.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));\n" +
  1078. "southLabel.setBackground(new Color(200, 200, 255, 70));\n" +
  1079. "southLabel.setOpaque(true);\n" +
  1080. "southLabel.setFont(southLabel.getFont().deriveFont(Font.BOLD));\n" +
  1081. "boundsPanel.add(southLabel, constr);\n" +
  1082. "\n" +
  1083. "boundsPanel.add(createButton(), \"pos 0 0 container.x2 n\");\n" +
  1084. "boundsPanel.add(createButton(), \"pos visual.x 40 visual.x2 70\");\n" +
  1085. "boundsPanel.add(createButton(), \"pos visual.x 100 visual.x2 p\");\n" +
  1086. "boundsPanel.add(createButton(), \"pos 0.1al 0.4al n visual.y2-10\");\n" +
  1087. "boundsPanel.add(createButton(), \"pos 0.9al 0.4al n visual.y2-10\");\n" +
  1088. "boundsPanel.add(createButton(), \"pos 0.5al 0.5al, pad 3 0 -3 0\");\n" +
  1089. "boundsPanel.add(createButton(), \"pos n n 50% 50%\");\n" +
  1090. "boundsPanel.add(createButton(), \"pos 50% 50% n n\");\n" +
  1091. "boundsPanel.add(createButton(), \"pos 50% n n 50%\");\n" +
  1092. "boundsPanel.add(createButton(), \"pos n 50% 50% n\");\n" +
  1093. "\n" +
  1094. "// Glass pane tab\n" +
  1095. "final JPanel glassPanel = createTabPanel(new MigLayout(\"align c c, ins 0\"));\n" +
  1096. "final JButton butt = createButton(\"Press me!!\");\n" +
  1097. "glassPanel.add(butt);\n" +
  1098. "\n" +
  1099. "butt.addActionListener(new ActionListener()\t\t{\n" +
  1100. "\tpublic void actionPerformed(ActionEvent e)\n" +
  1101. "\t{\n" +
  1102. "\t\tbutt.setEnabled(false);\n" +
  1103. "\t\tfinal JPanel bg = new JPanel(new MigLayout(\"align c c,fill\")) {\n" +
  1104. "\t\t\tpublic void paint(Graphics g)\n" +
  1105. "\t\t\t{\n" +
  1106. "\t\t\t\tg.setColor(getBackground());\n" +
  1107. "\t\t\t\tg.fillRect(0, 0, getWidth(), getHeight());\n" +
  1108. "\t\t\t\tsuper.paint(g);\n" +
  1109. "\t\t\t}\n" +
  1110. "\t\t};\n" +
  1111. "\t\tbg.setOpaque(OPAQUE);\n" +
  1112. "\t\tconfigureActiveComponet(bg);\n" +
  1113. "\n" +
  1114. "\t\tfinal JLabel label = createLabel(\"You don't need a GlassPane to be cool!\");\n" +
  1115. "\t\tlabel.setFont(label.getFont().deriveFont(30f));\n" +
  1116. "\t\tlabel.setForeground(new Color(255, 255, 255, 0));\n" +
  1117. "\t\tbg.add(label, \"align 50% 30%\");\n" +
  1118. "\n" +
  1119. "\t\tglassPanel.add(bg, \"pos visual.x visual.y visual.x2 visual.y2\", 0);\n" +
  1120. "\t\tfinal long startTime = System.nanoTime();\n" +
  1121. "\t\tfinal long endTime = startTime + 500000000L;\n" +
  1122. "\n" +
  1123. "\t\tglassPanel.revalidate();\n" +
  1124. "\n" +
  1125. "\t\tfinal javax.swing.Timer timer = new Timer(25, null);\n" +
  1126. "\n" +
  1127. "\t\ttimer.addActionListener(new ActionListener() {\n" +
  1128. "\t\t\tpublic void actionPerformed(ActionEvent e)\n" +
  1129. "\t\t\t{\n" +
  1130. "\t\t\t\tlong now = System.nanoTime();\n" +
  1131. "\t\t\t\tint alpha = (int) (((now - startTime) / (double) (endTime - startTime)) * 300);\n" +
  1132. "\t\t\t\tif (alpha < 150)\n" +
  1133. "\t\t\t\t\tbg.setBackground(new Color(100, 100, 100, alpha));\n" +
  1134. "\n" +
  1135. "\t\t\t\tif (alpha > 150 && alpha < 405) {\n" +
  1136. "\t\t\t\t\tlabel.setForeground(new Color(255, 255, 255, (alpha - 150)));\n" +
  1137. "\t\t\t\t\tbg.repaint();\n" +
  1138. "\t\t\t\t}\n" +
  1139. "\t\t\t\tif (alpha > 405)\n" +
  1140. "\t\t\t\t\ttimer.stop();\n" +
  1141. "\t\t\t}\n" +
  1142. "\t\t});\n" +
  1143. "\t\ttimer.start();\n" +
  1144. "\t}\n" +
  1145. "});\n" +
  1146. "\n" +
  1147. "tabbedPane.addTab(\"X Y Positions\", posPanel);\n" +
  1148. "tabbedPane.addTab(\"X1 Y1 X2 Y2 Bounds\", boundsPanel);\n" +
  1149. "tabbedPane.addTab(\"GlassPane Substitute\", glassPanel);\n" +
  1150. "\n" +
  1151. "addComponentListener(new ComponentAdapter() {\n" +
  1152. "\tpublic void componentMoved(ComponentEvent e) {\n" +
  1153. "\t\tif (posPanel.isDisplayable()) {\n" +
  1154. "\t\t\tposPanel.revalidate();\n" +
  1155. "\t\t} else {\n" +
  1156. "\t\t\tremoveComponentListener(this);\n" +
  1157. "\t\t}\n" +
  1158. "\t}\n" +
  1159. "});");
  1160. return tabbedPane;
  1161. }
  1162. public JComponent createComponent_Links()
  1163. {
  1164. JTabbedPane tabbedPane = new JTabbedPane();
  1165. JPanel linksPanel = createTabPanel(new MigLayout());
  1166. // Links tab
  1167. JButton mini = createButton("Mini");
  1168. mini.setMargin(new Insets(0, 1, 0, 1));
  1169. linksPanel.add(mini, "pos null ta.y ta.x2 null");
  1170. linksPanel.add(createTextArea("Components, Please Link to Me!\nMy ID is: 'ta'", 3, 30), "id ta, pos 0.5al 0.5al");
  1171. linksPanel.add(createButton(), "id b1,pos ta.x2 ta.y2");
  1172. linksPanel.add(createButton(), "pos b1.x2+rel b1.y visual.x2 null");
  1173. linksPanel.add(createButton(), "pos ta.x2+rel ta.y visual.x2 null");
  1174. linksPanel.add(createButton(), "pos null ta.y+(ta.h-pref)/2 ta.x-rel null");
  1175. linksPanel.add(createButton(), "pos ta.x ta.y2+100 ta.x2 null");
  1176. linksPanel.add(createCheck("pos (ta.x+indent) (ta.y2+rel)"),
  1177. "pos (ta.x+indent) (ta.y2+rel)");
  1178. // External tab
  1179. JPanel externalPanel = createTabPanel(new MigLayout());
  1180. JButton extButt = createButton("Bounds Externally Set!");
  1181. extButt.setBounds(250, 130, 200, 40);
  1182. externalPanel.add(extButt, "id ext, external");
  1183. externalPanel.add(createButton(), "pos ext.x2 ext.y2");
  1184. externalPanel.add(createButton(), "pos null null ext.x ext.y");
  1185. // Start/End Group tab
  1186. JPanel egPanel = createTabPanel(new MigLayout());
  1187. egPanel.add(createButton(), "id b1, endgroupx g1, pos 200 200");
  1188. egPanel.add(createButton(), "id b2, endgroupx g1, pos (b1.x+2ind) (b1.y2+rel)");
  1189. egPanel.add(createButton(), "id b3, endgroupx g1, pos (b1.x+4ind) (b2.y2+rel)");
  1190. egPanel.add(createButton(), "id b4, endgroupx g1, pos (b1.x+6ind) (b3.y2+rel)");
  1191. // Group Bounds tab
  1192. JPanel gpPanel = createTabPanel(new MigLayout());
  1193. gpPanel.add(createButton(), "id grp1.b1, pos n 0.5al 50% n");
  1194. gpPanel.add(createButton(), "id grp1.b2, pos 50% 0.5al n n");
  1195. gpPanel.add(createButton(), "id grp1.b3, pos 0.5al n n b1.y");
  1196. gpPanel.add(createButton(), "id grp1.b4, pos 0.5al b1.y2 n n");
  1197. gpPanel.add(createButton(), "pos n grp1.y2 grp1.x n");
  1198. gpPanel.add(createButton(), "pos n n grp1.x grp1.y");
  1199. gpPanel.add(createButton(), "pos grp1.x2 n n grp1.y");
  1200. gpPanel.add(createButton(), "pos grp1.x2 grp1.y2");
  1201. JPanel boundsPanel = new JPanel(null);
  1202. boundsPanel.setBackground(new Color(200, 200, 255));
  1203. gpPanel.add(boundsPanel, "pos grp1.x grp1.y grp1.x2 grp1.y2");
  1204. tabbedPane.addTab("Component Links", linksPanel);
  1205. tabbedPane.addTab("External Components", externalPanel);
  1206. tabbedPane.addTab("End Grouping", egPanel);
  1207. tabbedPane.addTab("Group Bounds", gpPanel);
  1208. // Disregard. Just forgetting the source code text close to the source code.
  1209. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1210. "\n" +
  1211. "JPanel linksPanel = createTabPanel(new MigLayout());\n" +
  1212. "\n" +
  1213. "// Links tab\n" +
  1214. "JButton mini = createButton(\"Mini\");\n" +
  1215. "mini.setMargin(new Insets(0, 1, 0, 1));\n" +
  1216. "linksPanel.add(mini, \"pos null ta.y ta.x2 null\");\n" +
  1217. "linksPanel.add(createTextArea(\"Components, Please Link to Me!\\nMy ID is: 'ta'\", 3, 30), \"id ta, pos 0.5al 0.5al\");\n" +
  1218. "linksPanel.add(createButton(), \"id b1,pos ta.x2 ta.y2\");\n" +
  1219. "linksPanel.add(createButton(), \"pos b1.x2+rel b1.y visual.x2 null\");\n" +
  1220. "linksPanel.add(createButton(), \"pos ta.x2+rel ta.y visual.x2 null\");\n" +
  1221. "linksPanel.add(createButton(), \"pos null ta.y+(ta.h-pref)/2 ta.x-rel null\");\n" +
  1222. "linksPanel.add(createButton(), \"pos ta.x ta.y2+100 ta.x2 null\");\n" +
  1223. "linksPanel.add(createCheck(\"pos (ta.x+indent) (ta.y2+rel)\"),\n" +
  1224. " \"pos (ta.x+indent) (ta.y2+rel)\");\n" +
  1225. "\n" +
  1226. "// External tab\n" +
  1227. "JPanel externalPanel = createTabPanel(new MigLayout());\n" +
  1228. "\n" +
  1229. "JButton extButt = createButton(\"Bounds Externally Set!\");\n" +
  1230. "extButt.setBounds(250, 130, 200, 40);\n" +
  1231. "externalPanel.add(extButt, \"id ext, external\");\n" +
  1232. "externalPanel.add(createButton(), \"pos ext.x2 ext.y2\");\n" +
  1233. "externalPanel.add(createButton(), \"pos null null ext.x ext.y\");\n" +
  1234. "\n" +
  1235. "// Start/End Group tab\n" +
  1236. "JPanel egPanel = createTabPanel(new MigLayout());\n" +
  1237. "\n" +
  1238. "egPanel.add(createButton(), \"id b1, endgroupx g1, pos 200 200\");\n" +
  1239. "egPanel.add(createButton(), \"id b2, endgroupx g1, pos (b1.x+2ind) (b1.y2+rel)\");\n" +
  1240. "egPanel.add(createButton(), \"id b3, endgroupx g1, pos (b1.x+4ind) (b2.y2+rel)\");\n" +
  1241. "egPanel.add(createButton(), \"id b4, endgroupx g1, pos (b1.x+6ind) (b3.y2+rel)\");\n" +
  1242. "\n" +
  1243. "// Group Bounds tab\n" +
  1244. "JPanel gpPanel = createTabPanel(new MigLayout());\n" +
  1245. "\n" +
  1246. "gpPanel.add(createButton(), \"id grp1.b1, pos n 0.5al 50% n\");\n" +
  1247. "gpPanel.add(createButton(), \"id grp1.b2, pos 50% 0.5al n n\");\n" +
  1248. "gpPanel.add(createButton(), \"id grp1.b3, pos 0.5al n n b1.y\");\n" +
  1249. "gpPanel.add(createButton(), \"id grp1.b4, pos 0.5al b1.y2 n n\");\n" +
  1250. "\n" +
  1251. "gpPanel.add(createButton(), \"pos n grp1.y2 grp1.x n\");\n" +
  1252. "gpPanel.add(createButton(), \"pos n n grp1.x grp1.y\");\n" +
  1253. "gpPanel.add(createButton(), \"pos grp1.x2 n n grp1.y\");\n" +
  1254. "gpPanel.add(createButton(), \"pos grp1.x2 grp1.y2\");\n" +
  1255. "\n" +
  1256. "JPanel boundsPanel = new JPanel(null);\n" +
  1257. "boundsPanel.setBackground(new Color(200, 200, 255));\n" +
  1258. "gpPanel.add(boundsPanel, \"pos grp1.x grp1.y grp1.x2 grp1.y2\");\n" +
  1259. "\n" +
  1260. "\n" +
  1261. "tabbedPane.addTab(\"Component Links\", linksPanel);\n" +
  1262. "tabbedPane.addTab(\"External Components\", externalPanel);\n" +
  1263. "tabbedPane.addTab(\"End Grouping\", egPanel);\n" +
  1264. "tabbedPane.addTab(\"Group Bounds\", gpPanel);");
  1265. return tabbedPane;
  1266. }
  1267. public JComponent createFlow_Direction()
  1268. {
  1269. JTabbedPane tabbedPane = new JTabbedPane();
  1270. tabbedPane.addTab("Layout: flowx, Cell: flowx", createFlowPanel("", "flowx"));
  1271. tabbedPane.addTab("Layout: flowx, Cell: flowy", createFlowPanel("", "flowy"));
  1272. tabbedPane.addTab("Layout: flowy, Cell: flowx", createFlowPanel("flowy", "flowx"));
  1273. tabbedPane.addTab("Layout: flowy, Cell: flowy", createFlowPanel("flowy", "flowy"));
  1274. // Disregard. Just forgetting the source code text close to the source code.
  1275. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1276. "\n" +
  1277. "tabbedPane.addTab(\"Layout: flowx, Cell: flowx\", createFlowPanel(\"\", \"flowx\"));\n" +
  1278. "tabbedPane.addTab(\"Layout: flowx, Cell: flowy\", createFlowPanel(\"\", \"flowy\"));\n" +
  1279. "tabbedPane.addTab(\"Layout: flowy, Cell: flowx\", createFlowPanel(\"flowy\", \"flowx\"));\n" +
  1280. "tabbedPane.addTab(\"Layout: flowy, Cell: flowy\", createFlowPanel(\"flowy\", \"flowy\"));" +
  1281. "\n\tpublic JPanel createFlowPanel(String gridFlow, String cellFlow)\n" +
  1282. "\t{\n" +
  1283. "MigLayout lm = new MigLayout(\"center, wrap 3,\" + gridFlow,\n" +
  1284. " \"[110,fill]\",\n" +
  1285. " \"[110,fill]\");\n" +
  1286. "JPanel panel = createTabPanel(lm);\n" +
  1287. "\n" +
  1288. "for (int i = 0; i < 9; i++) {\n" +
  1289. "\tJButton b = createButton(\"\" + (i + 1));\n" +
  1290. "\tb.setFont(b.getFont().deriveFont(20f));\n" +
  1291. "\tpanel.add(b, cellFlow);\n" +
  1292. "}\n" +
  1293. "\n" +
  1294. "JButton b = createButton(\"5:2\");\n" +
  1295. "b.setFont(b.getFont().deriveFont(20f));\n" +
  1296. "panel.add(b, cellFlow + \",cell 1 1\");\n" +
  1297. "\n" +
  1298. "return panel;\n" +
  1299. "\t}");
  1300. return tabbedPane;
  1301. }
  1302. public JPanel createFlowPanel(String gridFlow, String cellFlow)
  1303. {
  1304. MigLayout lm = new MigLayout("center, wrap 3," + gridFlow,
  1305. "[110,fill]",
  1306. "[110,fill]");
  1307. JPanel panel = createTabPanel(lm);
  1308. Font f = panel.getFont().deriveFont(20f);
  1309. for (int i = 0; i < 9; i++) {
  1310. JComponent b = createPanel("" + (i + 1));
  1311. b.setFont(f);
  1312. panel.add(b, cellFlow);
  1313. }
  1314. JComponent b = createPanel("5:2");
  1315. b.setFont(f);
  1316. panel.add(b, cellFlow + ",cell 1 1");
  1317. return panel;
  1318. }
  1319. public JComponent createDebug()
  1320. {
  1321. return createPlainImpl(true);
  1322. }
  1323. public JComponent createButton_Bars()
  1324. {
  1325. MigLayout lm = new MigLayout("ins 0 0 15lp 0",
  1326. "[grow]",
  1327. "[grow][baseline,nogrid]");
  1328. final JPanel mainPanel = new JPanel(lm);
  1329. final JLabel formatLabel = createLabel("");
  1330. formatLabel.setFont(formatLabel.getFont().deriveFont(Font.BOLD));
  1331. JTabbedPane tabbedPane = new JTabbedPane();
  1332. JToggleButton winButt = createToggleButton("Windows");
  1333. JToggleButton macButt = createToggleButton("Mac OS X");
  1334. JButton helpButt = createButton("Help");
  1335. if (benchRuns == 0) {
  1336. winButt.addActionListener(new ActionListener() {
  1337. public void actionPerformed(ActionEvent e) {
  1338. PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
  1339. formatLabel.setText("'" + PlatformDefaults.getButtonOrder() + "'");
  1340. ((JPanel) ((JFrame) Frame.getFrames()[0]).getContentPane()).revalidate();
  1341. }
  1342. });
  1343. macButt.addActionListener(new ActionListener() {
  1344. public void actionPerformed(ActionEvent e) {
  1345. PlatformDefaults.setPlatform(PlatformDefaults.MAC_OSX);
  1346. formatLabel.setText(PlatformDefaults.getButtonOrder());
  1347. ((JPanel) ((JFrame) Frame.getFrames()[0]).getContentPane()).revalidate();
  1348. }
  1349. });
  1350. helpButt.addActionListener(new ActionListener() {
  1351. public void actionPerformed(ActionEvent e) {
  1352. JOptionPane.showMessageDialog(mainPanel, "See JavaDoc for PlatformConverter.getButtonBarOrder(..) for details on the format string.");
  1353. }
  1354. });
  1355. }
  1356. ButtonGroup bg = new ButtonGroup();
  1357. bg.add(winButt);
  1358. bg.add(macButt);
  1359. if (benchRuns == 0) {
  1360. if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.MAC_OSX) {
  1361. macButt.doClick();
  1362. } else {
  1363. winButt.doClick();
  1364. }
  1365. }
  1366. tabbedPane.addTab("Buttons", createButtonBarsPanel("help", false));
  1367. tabbedPane.addTab("Buttons with Help2", createButtonBarsPanel("help2", false));
  1368. tabbedPane.addTab("Buttons (Same width)", createButtonBarsPanel("help", true));
  1369. mainPanel.add(tabbedPane, "grow,wrap");
  1370. mainPanel.add(createLabel("Button Order:"));
  1371. mainPanel.add(formatLabel, "growx");
  1372. mainPanel.add(winButt);
  1373. mainPanel.add(macButt);
  1374. mainPanel.add(helpButt, "gapbefore unrel");
  1375. // Disregard. Just forgetting the source code text close to the source code.
  1376. setSource("MigLayout lm = new MigLayout(\"ins 0 0 15lp 0\",\n" +
  1377. " \"[grow]\",\n" +
  1378. " \"[grow][baseline,nogrid,gap unrelated]\");\n" +
  1379. "\n" +
  1380. "final JPanel mainPanel = new JPanel(lm);\n" +
  1381. "final JLabel formatLabel = createLabel(\"\");\n" +
  1382. "formatLabel.setFont(formatLabel.getFont().deriveFont(Font.BOLD));\n" +
  1383. "JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1384. "\n" +
  1385. "JToggleButton winButt = createToggleButton(\"Windows\");\n" +
  1386. "\n" +
  1387. "winButt.addActionListener(new ActionListener() {\n" +
  1388. "\tpublic void actionPerformed(ActionEvent e) {\n" +
  1389. "\t\tPlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);\n" +
  1390. "\t\tformatLabel.setText(\"'\" + PlatformDefaults.getButtonOrder() + \"'\");\n" +
  1391. "\t\tSwingUtilities.updateComponentTreeUI(mainPanel);\n" +
  1392. "\t}\n" +
  1393. "});\n" +
  1394. "\n" +
  1395. "JToggleButton macButt = createToggleButton(\"Mac OS X\");\n" +
  1396. "macButt.addActionListener(new ActionListener() {\n" +
  1397. "\tpublic void actionPerformed(ActionEvent e) {\n" +
  1398. "\t\tPlatformDefaults.setPlatform(PlatformDefaults.MAC_OSX);\n" +
  1399. "\t\tformatLabel.setText(PlatformDefaults.getButtonOrder());\n" +
  1400. "\t\tSwingUtilities.updateComponentTreeUI(mainPanel);\n" +
  1401. "\t}\n" +
  1402. "});\n" +
  1403. "\n" +
  1404. "JButton helpButt = createButton(\"Help\");\n" +
  1405. "helpButt.addActionListener(new ActionListener() {\n" +
  1406. "\tpublic void actionPerformed(ActionEvent e) {\n" +
  1407. "\t\tJOptionPane.showMessageDialog(mainPanel, \"See JavaDoc for PlatformConverter.getButtonBarOrder(..) for details on the format string.\");\n" +
  1408. "\t}\n" +
  1409. "});\n" +
  1410. "\n" +
  1411. "ButtonGroup bg = new ButtonGroup();\n" +
  1412. "bg.add(winButt);\n" +
  1413. "bg.add(macButt);\n" +
  1414. "winButt.doClick();\n" +
  1415. "\n" +
  1416. "tabbedPane.addTab(\"Buttons\", createButtonBarsPanel(\"help\", false));\n" +
  1417. "tabbedPane.addTab(\"Buttons with Help2\", createButtonBarsPanel(\"help2\", false));\n" +
  1418. "tabbedPane.addTab(\"Buttons (Same width)\", createButtonBarsPanel(\"help\", true));\n" +
  1419. "\n" +
  1420. "mainPanel.add(tabbedPane, \"grow,wrap\");\n" +
  1421. "\n" +
  1422. "mainPanel.add(createLabel(\"Button Order:\"));\n" +
  1423. "mainPanel.add(formatLabel, \"growx\");\n" +
  1424. "mainPanel.add(winButt);\n" +
  1425. "mainPanel.add(macButt);\n" +
  1426. "mainPanel.add(helpButt, \"gapbefore unrel\");");
  1427. return mainPanel;
  1428. }
  1429. private JComponent createButtonBarsPanel(String helpTag, boolean sizeLocked)
  1430. {
  1431. MigLayout lm = new MigLayout("nogrid, fillx, aligny 100%, gapy unrel");
  1432. JPanel panel = createTabPanel(lm);
  1433. // Notice that the order in the rows below does not matter...
  1434. String[][] buttons = new String[][] {
  1435. {"OK"},
  1436. {"No", "Yes"},
  1437. {"Help", "Close"},
  1438. {"OK", "Help"},
  1439. {"OK", "Cancel", "Help"},
  1440. {"OK", "Cancel", "Apply", "Help"},
  1441. {"No", "Yes", "Cancel"},
  1442. {"Help", "< Back", "Forward >", "Cancel"},
  1443. {"Print...", "Cancel", "Help"}
  1444. };
  1445. for (int r = 0; r < buttons.length; r++) {
  1446. for (int i = 0; i < buttons[r].length; i++) {
  1447. String txt = buttons[r][i];
  1448. String tag = txt;
  1449. if (txt.equals("Help")) {
  1450. tag = helpTag;
  1451. } else if (txt.equals("< Back")) {
  1452. tag = "back";
  1453. } else if (txt.equals("Close")) {
  1454. tag = "cancel";
  1455. } else if (txt.equals("Forward >")) {
  1456. tag = "next";
  1457. } else if (txt.equals("Print...")) {
  1458. tag = "other";
  1459. }
  1460. String wrap = (i == buttons[r].length - 1) ? ",wrap" : "";
  1461. String sizeGroup = sizeLocked ? ("sgx " + r + ",") : "";
  1462. panel.add(createButton(txt), sizeGroup + "tag " + tag + wrap);
  1463. }
  1464. }
  1465. return panel;
  1466. }
  1467. public JComponent createOrientation()
  1468. {
  1469. JTabbedPane tabbedPane = new JTabbedPane();
  1470. MigLayout lm = new MigLayout("flowy", "[grow,fill]", "[]20[]20[]20[]");
  1471. JPanel mainPanel = createTabPanel(lm);
  1472. // Default orientation
  1473. MigLayout defLM = new MigLayout("", "[trailing][grow,fill]", "");
  1474. JPanel defPanel = createTabPanel(defLM);
  1475. addSeparator(defPanel, "Default Orientation");
  1476. defPanel.add(createLabel("Level of Trust"));
  1477. defPanel.add(createTextField(""), "span,growx");
  1478. defPanel.add(createLabel("Radar Presentation"));
  1479. defPanel.add(createTextField(""));
  1480. defPanel.add(createTextField(""));
  1481. // Right-to-left, Top-to-bottom
  1482. MigLayout rtlLM = new MigLayout("rtl,ttb",
  1483. "[trailing][grow,fill]",
  1484. "");
  1485. JPanel rtlPanel = createTabPanel(rtlLM);
  1486. addSeparator(rtlPanel, "Right to Left");
  1487. rtlPanel.add(createLabel("Level of Trust"));
  1488. rtlPanel.add(createTextField(""), "span,growx");
  1489. rtlPanel.add(createLabel("Radar Presentation"));
  1490. rtlPanel.add(createTextField(""));
  1491. rtlPanel.add(createTextField(""));
  1492. // Right-to-left, Bottom-to-top
  1493. MigLayout rtlbLM = new MigLayout("rtl,btt",
  1494. "[trailing][grow,fill]",
  1495. "");
  1496. JPanel rtlbPanel = createTabPanel(rtlbLM);
  1497. addSeparator(rtlbPanel, "Right to Left, Bottom to Top");
  1498. rtlbPanel.add(createLabel("Level of Trust"));
  1499. rtlbPanel.add(createTextField(""), "span,growx");
  1500. rtlbPanel.add(createLabel("Radar Presentation"));
  1501. rtlbPanel.add(createTextField(""));
  1502. rtlbPanel.add(createTextField(""));
  1503. // Left-to-right, Bottom-to-top
  1504. MigLayout ltrbLM = new MigLayout("ltr,btt",
  1505. "[trailing][grow,fill]",
  1506. "");
  1507. JPanel ltrbPanel = createTabPanel(ltrbLM);
  1508. addSeparator(ltrbPanel, "Left to Right, Bottom to Top");
  1509. ltrbPanel.add(createLabel("Level of Trust"));
  1510. ltrbPanel.add(createTextField(""), "span,growx");
  1511. ltrbPanel.add(createLabel("Radar Presentation"));
  1512. ltrbPanel.add(createTextField(""));
  1513. ltrbPanel.add(createTextField(""));
  1514. mainPanel.add(defPanel);
  1515. mainPanel.add(rtlPanel);
  1516. mainPanel.add(rtlbPanel);
  1517. mainPanel.add(ltrbPanel);
  1518. tabbedPane.addTab("Orientation", mainPanel);
  1519. // Disregard. Just forgetting the source code text close to the source code.
  1520. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1521. "\n" +
  1522. "MigLayout lm = new MigLayout(\"flowy\", \"[grow,fill]\", \"[]0[]15lp[]0[]\");\n" +
  1523. "JPanel mainPanel = createTabPanel(lm);\n" +
  1524. "\n" +
  1525. "// Default orientation\n" +
  1526. "MigLayout defLM = new MigLayout(\"\", \"[][grow,fill]\", \"\");\n" +
  1527. "\n" +
  1528. "JPanel defPanel = createTabPanel(defLM);\n" +
  1529. "addSeparator(defPanel, \"Default Orientation\");\n" +
  1530. "defPanel.add(createLabel(\"Level\"));\n" +
  1531. "defPanel.add(createTextField(\"\"), \"span,growx\");\n" +
  1532. "defPanel.add(createLabel(\"Radar\"));\n" +
  1533. "defPanel.add(createTextField(\"\"));\n" +
  1534. "defPanel.add(createTextField(\"\"));\n" +
  1535. "\n" +
  1536. "// Right-to-left, Top-to-bottom\n" +
  1537. "MigLayout rtlLM = new MigLayout(\"rtl,ttb\",\n" +
  1538. " \"[][grow,fill]\",\n" +
  1539. " \"\");\n" +
  1540. "JPanel rtlPanel = createTabPanel(rtlLM);\n" +
  1541. "addSeparator(rtlPanel, \"Right to Left\");\n" +
  1542. "rtlPanel.add(createLabel(\"Level\"));\n" +
  1543. "rtlPanel.add(createTextField(\"\"), \"span,growx\");\n" +
  1544. "rtlPanel.add(createLabel(\"Radar\"));\n" +
  1545. "rtlPanel.add(createTextField(\"\"));\n" +
  1546. "rtlPanel.add(createTextField(\"\"));\n" +
  1547. "\n" +
  1548. "// Right-to-left, Bottom-to-top\n" +
  1549. "MigLayout rtlbLM = new MigLayout(\"rtl,btt\",\n" +
  1550. " \"[][grow,fill]\",\n" +
  1551. " \"\");\n" +
  1552. "JPanel rtlbPanel = createTabPanel(rtlbLM);\n" +
  1553. "addSeparator(rtlbPanel, \"Right to Left, Bottom to Top\");\n" +
  1554. "rtlbPanel.add(createLabel(\"Level\"));\n" +
  1555. "rtlbPanel.add(createTextField(\"\"), \"span,growx\");\n" +
  1556. "rtlbPanel.add(createLabel(\"Radar\"));\n" +
  1557. "rtlbPanel.add(createTextField(\"\"));\n" +
  1558. "rtlbPanel.add(createTextField(\"\"));\n" +
  1559. "\n" +
  1560. "// Left-to-right, Bottom-to-top\n" +
  1561. "MigLayout ltrbLM = new MigLayout(\"ltr,btt\",\n" +
  1562. " \"[][grow,fill]\",\n" +
  1563. " \"\");\n" +
  1564. "JPanel ltrbPanel = createTabPanel(ltrbLM);\n" +
  1565. "addSeparator(ltrbPanel, \"Left to Right, Bottom to Top\");\n" +
  1566. "ltrbPanel.add(createLabel(\"Level\"));\n" +
  1567. "ltrbPanel.add(createTextField(\"\"), \"span,growx\");\n" +
  1568. "ltrbPanel.add(createLabel(\"Radar\"));\n" +
  1569. "ltrbPanel.add(createTextField(\"\"));\n" +
  1570. "ltrbPanel.add(createTextField(\"\"));\n" +
  1571. "\n" +
  1572. "mainPanel.add(defPanel);\n" +
  1573. "mainPanel.add(rtlPanel);\n" +
  1574. "mainPanel.add(rtlbPanel);\n" +
  1575. "mainPanel.add(ltrbPanel);\n" +
  1576. "\n" +
  1577. "tabbedPane.addTab(\"Orientation\", mainPanel);");
  1578. return tabbedPane;
  1579. }
  1580. public JComponent createCell_Position()
  1581. {
  1582. JTabbedPane tabbedPane = new JTabbedPane();
  1583. // Absolute grid position
  1584. MigLayout absLM = new MigLayout("",
  1585. "[100:pref,fill]",
  1586. "[100:pref,fill]");
  1587. JPanel absPanel = createTabPanel(absLM);
  1588. absPanel.add(createButton(), "cell 0 0");
  1589. absPanel.add(createButton(), "cell 2 0");
  1590. absPanel.add(createButton(), "cell 3 0");
  1591. absPanel.add(createButton(), "cell 1 1");
  1592. absPanel.add(createButton(), "cell 0 2");
  1593. absPanel.add(createButton(), "cell 2 2");
  1594. absPanel.add(createButton(), "cell 2 2");
  1595. // Relative grid position with wrap
  1596. MigLayout relAwLM = new MigLayout("wrap",
  1597. "[100:pref,fill][100:pref,fill][100:pref,fill][100:pref,fill]",
  1598. "[100:pref,fill]");
  1599. JPanel relAwPanel = createTabPanel(relAwLM);
  1600. relAwPanel.add(createButton());
  1601. relAwPanel.add(createButton(), "skip");
  1602. relAwPanel.add(createButton());
  1603. relAwPanel.add(createButton(), "skip,wrap");
  1604. relAwPanel.add(createButton());
  1605. relAwPanel.add(createButton(), "skip,split");
  1606. relAwPanel.add(createButton());
  1607. // Relative grid position with manual wrap
  1608. MigLayout relWLM = new MigLayout("",
  1609. "[100:pref,fill]",
  1610. "[100:pref,fill]");
  1611. JPanel relWPanel = createTabPanel(relWLM);
  1612. relWPanel.add(createButton());
  1613. relWPanel.add(createButton(), "skip");
  1614. relWPanel.add(createButton(), "wrap");
  1615. relWPanel.add(createButton(), "skip,wrap");
  1616. relWPanel.add(createButton());
  1617. relWPanel.add(createButton(), "skip,split");
  1618. relWPanel.add(createButton());
  1619. // Mixed relative and absolute grid position
  1620. MigLayout mixLM = new MigLayout("",
  1621. "[100:pref,fill]",
  1622. "[100:pref,fill]");
  1623. JPanel mixPanel = createTabPanel(mixLM);
  1624. mixPanel.add(createButton());
  1625. mixPanel.add(createButton(), "cell 2 0");
  1626. mixPanel.add(createButton());
  1627. mixPanel.add(createButton(), "cell 1 1,wrap");
  1628. mixPanel.add(createButton());
  1629. mixPanel.add(createButton(), "cell 2 2,split");
  1630. mixPanel.add(createButton());
  1631. tabbedPane.addTab("Absolute", absPanel);
  1632. tabbedPane.addTab("Relative + Wrap", relAwPanel);
  1633. tabbedPane.addTab("Relative", relWPanel);
  1634. tabbedPane.addTab("Mixed", mixPanel);
  1635. // Disregard. Just forgetting the source code text close to the source code.
  1636. setSource("\t\tJTabbedPane tabbedPane = new JTabbedPane();\n" +
  1637. "\n" +
  1638. "\t\t// Absolute grid position\n" +
  1639. "\t\tMigLayout absLM = new MigLayout(\"\",\n" +
  1640. "\t\t \"[100:pref,fill]\",\n" +
  1641. "\t\t \"[100:pref,fill]\");\n" +
  1642. "\t\tJPanel absPanel = createTabPanel(absLM);\n" +
  1643. "\t\tabsPanel.add(createPanel(), \"cell 0 0\");\n" +
  1644. "\t\tabsPanel.add(createPanel(), \"cell 2 0\");\n" +
  1645. "\t\tabsPanel.add(createPanel(), \"cell 3 0\");\n" +
  1646. "\t\tabsPanel.add(createPanel(), \"cell 1 1\");\n" +
  1647. "\t\tabsPanel.add(createPanel(), \"cell 0 2\");\n" +
  1648. "\t\tabsPanel.add(createPanel(), \"cell 2 2\");\n" +
  1649. "\t\tabsPanel.add(createPanel(), \"cell 2 2\");\n" +
  1650. "\n" +
  1651. "\n" +
  1652. "\t\t// Relative grid position with wrap\n" +
  1653. "\t\tMigLayout relAwLM = new MigLayout(\"wrap\",\n" +
  1654. "\t\t \"[100:pref,fill][100:pref,fill][100:pref,fill][100:pref,fill]\",\n" +
  1655. "\t\t \"[100:pref,fill]\");\n" +
  1656. "\t\tJPanel relAwPanel = createTabPanel(relAwLM);\n" +
  1657. "\t\trelAwPanel.add(createPanel());\n" +
  1658. "\t\trelAwPanel.add(createPanel(), \"skip\");\n" +
  1659. "\t\trelAwPanel.add(createPanel());\n" +
  1660. "\t\trelAwPanel.add(createPanel(), \"skip,wrap\");\n" +
  1661. "\t\trelAwPanel.add(createPanel());\n" +
  1662. "\t\trelAwPanel.add(createPanel(), \"skip,split\");\n" +
  1663. "\t\trelAwPanel.add(createPanel());\n" +
  1664. "\n" +
  1665. "\n" +
  1666. "\t\t// Relative grid position with manual wrap\n" +
  1667. "\t\tMigLayout relWLM = new MigLayout(\"\",\n" +
  1668. "\t\t \"[100:pref,fill]\",\n" +
  1669. "\t\t \"[100:pref,fill]\");\n" +
  1670. "\t\tJPanel relWPanel = createTabPanel(relWLM);\n" +
  1671. "\t\trelWPanel.add(createPanel());\n" +
  1672. "\t\trelWPanel.add(createPanel(), \"skip\");\n" +
  1673. "\t\trelWPanel.add(createPanel(), \"wrap\");\n" +
  1674. "\t\trelWPanel.add(createPanel(), \"skip,wrap\");\n" +
  1675. "\t\trelWPanel.add(createPanel());\n" +
  1676. "\t\trelWPanel.add(createPanel(), \"skip,split\");\n" +
  1677. "\n" +
  1678. "\t\trelWPanel.add(createPanel());\n" +
  1679. "\n" +
  1680. "\n" +
  1681. "\t\t// Mixed relative and absolute grid position\n" +
  1682. "\t\tMigLayout mixLM = new MigLayout(\"\",\n" +
  1683. "\t\t \"[100:pref,fill]\",\n" +
  1684. "\t\t \"[100:pref,fill]\");\n" +
  1685. "\t\tJPanel mixPanel = createTabPanel(mixLM);\n" +
  1686. "\t\tmixPanel.add(createPanel());\n" +
  1687. "\t\tmixPanel.add(createPanel(), \"cell 2 0\");\n" +
  1688. "\t\tmixPanel.add(createPanel());\n" +
  1689. "\t\tmixPanel.add(createPanel(), \"cell 1 1,wrap\");\n" +
  1690. "\t\tmixPanel.add(createPanel());\n" +
  1691. "\t\tmixPanel.add(createPanel(), \"cell 2 2,split\");\n" +
  1692. "\t\tmixPanel.add(createPanel());\n" +
  1693. "\n" +
  1694. "\t\ttabbedPane.addTab(\"Absolute\", absPanel);\n" +
  1695. "\t\ttabbedPane.addTab(\"Relative + Wrap\", relAwPanel);\n" +
  1696. "\t\ttabbedPane.addTab(\"Relative\", relWPanel);\n" +
  1697. "\t\ttabbedPane.addTab(\"Mixed\", mixPanel);");
  1698. return tabbedPane;
  1699. }
  1700. public JComponent createPlain()
  1701. {
  1702. return createPlainImpl(false);
  1703. }
  1704. private JComponent createPlainImpl(boolean debug)
  1705. {
  1706. JTabbedPane tabbedPane = new JTabbedPane();
  1707. MigLayout lm = new MigLayout((debug && benchRuns == 0 ? "debug, inset 20" : "ins 20"), "[para]0[][100lp, fill][60lp][95lp, fill]", "");
  1708. JPanel panel = createTabPanel(lm);
  1709. addSeparator(panel, "Manufacturer");
  1710. panel.add(createLabel("Company"), "skip");
  1711. panel.add(createTextField(""), "span, growx");
  1712. panel.add(createLabel("Contact"), "skip");
  1713. panel.add(createTextField(""), "span, growx");
  1714. panel.add(createLabel("Order No"), "skip");
  1715. panel.add(createTextField(15), "wrap para");
  1716. addSeparator(panel, "Inspector");
  1717. panel.add(createLabel("Name"), "skip");
  1718. panel.add(createTextField(""), "span, growx");
  1719. panel.add(createLabel("Reference No"), "skip");
  1720. panel.add(createTextField(""), "wrap");
  1721. panel.add(createLabel("Status"), "skip");
  1722. panel.add(createCombo(new String[] {"In Progress", "Finnished", "Released"}), "wrap para");
  1723. addSeparator(panel, "Ship");
  1724. panel.add(createLabel("Shipyard"), "skip");
  1725. panel.add(createTextField(""), "span, growx");
  1726. panel.add(createLabel("Register No"), "skip");
  1727. panel.add(createTextField(""));
  1728. panel.add(createLabel("Hull No"), "right");
  1729. panel.add(createTextField(15), "wrap");
  1730. panel.add(createLabel("Project Type"), "skip");
  1731. panel.add(createCombo(new String[] {"New Building", "Convention", "Repair"}));
  1732. if (debug)
  1733. panel.add(createLabel("Red is cell bounds. Blue is component bounds."), "newline,ax left,span,gaptop 40,");
  1734. tabbedPane.addTab("Plain", panel);
  1735. // Disregard. Just forgetting the source code text close to the source code.
  1736. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1737. "\n" +
  1738. "MigLayout lm = new MigLayout((debug && benchRuns == 0 ? \"debug, inset 20\" : \"ins 20\"), \"[para]0[][100lp, fill][60lp][95lp, fill]\", \"\");\n" +
  1739. "JPanel panel = createTabPanel(lm);\n" +
  1740. "\n" +
  1741. "addSeparator(panel, \"Manufacturer\");\n" +
  1742. "\n" +
  1743. "panel.add(createLabel(\"Company\"), \"skip\");\n" +
  1744. "panel.add(createTextField(\"\"), \"span, growx\");\n" +
  1745. "panel.add(createLabel(\"Contact\"), \"skip\");\n" +
  1746. "panel.add(createTextField(\"\"), \"span, growx\");\n" +
  1747. "panel.add(createLabel(\"Order No\"), \"skip\");\n" +
  1748. "panel.add(createTextField(15), \"wrap para\");\n" +
  1749. "\n" +
  1750. "addSeparator(panel, \"Inspector\");\n" +
  1751. "\n" +
  1752. "panel.add(createLabel(\"Name\"), \"skip\");\n" +
  1753. "panel.add(createTextField(\"\"), \"span, growx\");\n" +
  1754. "panel.add(createLabel(\"Reference No\"), \"skip\");\n" +
  1755. "panel.add(createTextField(\"\"), \"wrap\");\n" +
  1756. "panel.add(createLabel(\"Status\"), \"skip\");\n" +
  1757. "panel.add(createCombo(new String[] {\"In Progress\", \"Finnished\", \"Released\"}), \"wrap para\");\n" +
  1758. "\n" +
  1759. "addSeparator(panel, \"Ship\");\n" +
  1760. "\n" +
  1761. "panel.add(createLabel(\"Shipyard\"), \"skip\");\n" +
  1762. "panel.add(createTextField(\"\"), \"span, growx\");\n" +
  1763. "panel.add(createLabel(\"Register No\"), \"skip\");\n" +
  1764. "panel.add(createTextField(\"\"));\n" +
  1765. "panel.add(createLabel(\"Hull No\"), \"right\");\n" +
  1766. "panel.add(createTextField(15), \"wrap\");\n" +
  1767. "panel.add(createLabel(\"Project Type\"), \"skip\");\n" +
  1768. "panel.add(createCombo(new String[] {\"New Building\", \"Convention\", \"Repair\"}));\n" +
  1769. "\n" +
  1770. "if (debug)\n" +
  1771. "\tpanel.add(createLabel(\"Red is cell bounds. Blue is component bounds.\"), \"newline,ax left,span,gaptop 40,\");\n" +
  1772. "\n" +
  1773. "tabbedPane.addTab(\"Plain\", panel);");
  1774. return tabbedPane;
  1775. }
  1776. public JComponent createBound_Sizes()
  1777. {
  1778. JTabbedPane tabbedPane = new JTabbedPane();
  1779. for (int i = 0; i < 2; i++) { // Jumping for 0 and Stable for 1
  1780. String colConstr = i == 0 ? "[right][200]" : "[right, 75lp:pref][200]";
  1781. MigLayout LM1 = new MigLayout("wrap", colConstr, "");
  1782. JPanel panel1 = createTabPanel(LM1);
  1783. panel1.add(createLabel("File Number:"));
  1784. panel1.add(createTextField(""), "growx");
  1785. panel1.add(createLabel("RFQ Number:"));
  1786. panel1.add(createTextField(""), "growx");
  1787. panel1.add(createLabel("Entry Date:"));
  1788. panel1.add(createTextField(6));
  1789. panel1.add(createLabel("Sales Person:"));
  1790. panel1.add(createTextField(""), "growx");
  1791. MigLayout LM2 = new MigLayout("wrap", colConstr, "");
  1792. JPanel panel2 = createTabPanel(LM2);
  1793. panel2.add(createLabel("Shipper:"));
  1794. panel2.add(createTextField(6), "split 2");
  1795. panel2.add(createTextField(""), "growx");
  1796. panel2.add(createLabel("Consignee:"));
  1797. panel2.add(createTextField(6), "split 2");
  1798. panel2.add(createTextField(""), "growx");
  1799. panel2.add(createLabel("Departure:"));
  1800. panel2.add(createTextField(6), "split 2");
  1801. panel2.add(createTextField(""), "growx");
  1802. panel2.add(createLabel("Destination:"));
  1803. panel2.add(createTextField(6), "split 2");
  1804. panel2.add(createTextField(""), "growx");
  1805. tabbedPane.addTab(i == 0 ? "Jumping 1" : "Stable 1", panel1);
  1806. tabbedPane.addTab(i == 0 ? "Jumping 2" : "Stable 2", panel2);
  1807. }
  1808. // Disregard. Just forgetting the source code text close to the source code.
  1809. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1810. "\n" +
  1811. "for (int i = 0; i < 2; i++) { // Jumping for 0 and Stable for 1\n" +
  1812. "\tString colConstr = i == 0 ? \"[right][200]\" : \"[right, 75lp:pref][200]\";\n" +
  1813. "\n" +
  1814. "\tMigLayout LM1 = new MigLayout(\"wrap\", colConstr, \"\");\n" +
  1815. "\tJPanel panel1 = createTabPanel(LM1);\n" +
  1816. "\tpanel1.add(createLabel(\"File Number:\"));\n" +
  1817. "\tpanel1.add(createTextField(\"\"), \"growx\");\n" +
  1818. "\tpanel1.add(createLabel(\"RFQ Number:\"));\n" +
  1819. "\tpanel1.add(createTextField(\"\"), \"growx\");\n" +
  1820. "\tpanel1.add(createLabel(\"Entry Date:\"));\n" +
  1821. "\tpanel1.add(createTextField(6));\n" +
  1822. "\tpanel1.add(createLabel(\"Sales Person:\"));\n" +
  1823. "\tpanel1.add(createTextField(\"\"), \"growx\");\n" +
  1824. "\n" +
  1825. "\tMigLayout LM2 = new MigLayout(\"wrap\", colConstr, \"\");\n" +
  1826. "\tJPanel panel2 = createTabPanel(LM2);\n" +
  1827. "\tpanel2.add(createLabel(\"Shipper:\"));\n" +
  1828. "\tpanel2.add(createTextField(6), \"split 2\");\n" +
  1829. "\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
  1830. "\tpanel2.add(createLabel(\"Consignee:\"));\n" +
  1831. "\tpanel2.add(createTextField(6), \"split 2\");\n" +
  1832. "\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
  1833. "\tpanel2.add(createLabel(\"Departure:\"));\n" +
  1834. "\tpanel2.add(createTextField(6), \"split 2\");\n" +
  1835. "\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
  1836. "\tpanel2.add(createLabel(\"Destination:\"));\n" +
  1837. "\tpanel2.add(createTextField(6), \"split 2\");\n" +
  1838. "\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
  1839. "\n" +
  1840. "\ttabbedPane.addTab(i == 0 ? \"Jumping 1\" : \"Stable 2\", panel1);\n" +
  1841. "\ttabbedPane.addTab(i == 0 ? \"Jumping 2\" : \"Stable 2\", panel2);\n" +
  1842. "}");
  1843. return tabbedPane;
  1844. }
  1845. public JComponent createComponent_Sizes()
  1846. {
  1847. JTabbedPane tabbedPane = new JTabbedPane();
  1848. MigLayout LM = new MigLayout("wrap", "[right][0:pref,grow]", "");
  1849. JPanel panel = createTabPanel(LM);
  1850. JScrollPane descrText = createTextAreaScroll("Use slider to see how the components grow and shrink depending on the constraints set on them.", 0, 0, false);
  1851. descrText.setOpaque(OPAQUE);
  1852. descrText.setBorder(new EmptyBorder(10, 10, 10, 10));
  1853. ((JTextArea) descrText.getViewport().getView()).setOpaque(OPAQUE);
  1854. descrText.getViewport().setOpaque(OPAQUE);
  1855. JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, panel, descrText);
  1856. splitPane.setOpaque(OPAQUE);
  1857. splitPane.setBorder(null);
  1858. panel.add(createLabel("\"\""));
  1859. panel.add(createTextField("8"));
  1860. panel.add(createLabel("\"min!\""));
  1861. panel.add(createTextField("3", 3), "width min!");
  1862. panel.add(createLabel("\"pref!\""));
  1863. panel.add(createTextField("3", 3), "width pref!");
  1864. panel.add(createLabel("\"min:pref\""));
  1865. panel.add(createTextField("8", 8), "width min:pref");
  1866. panel.add(createLabel("\"min:100:150\""));
  1867. panel.add(createTextField("8", 8), "width min:100:150");
  1868. panel.add(createLabel("\"min:100:150, growx\""));
  1869. panel.add(createTextField("8", 8), "width min:100:150, growx");
  1870. panel.add(createLabel("\"min:100, growx\""));
  1871. panel.add(createTextField("8", 8), "width min:100, growx");
  1872. panel.add(createLabel("\"40!\""));
  1873. panel.add(createTextField("8", 8), "width 40!");
  1874. panel.add(createLabel("\"40:40:40\""));
  1875. panel.add(createTextField("8", 8), "width 40:40:40");
  1876. tabbedPane.addTab("Component Sizes", splitPane);
  1877. // Disregard. Just forgetting the source code text close to the source code.
  1878. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1879. "\n" +
  1880. "MigLayout LM = new MigLayout(\"wrap\", \"[right][0:pref,grow]\", \"\");\n" +
  1881. "\n" +
  1882. "JPanel panel = createTabPanel(LM);\n" +
  1883. "JScrollPane descrText = createTextAreaScroll(\"Use slider to see how the components grow and shrink depending on the constraints set on them.\", 0, 0, false);\n" +
  1884. "\n" +
  1885. "descrText.setOpaque(OPAQUE);\n" +
  1886. "descrText.setBorder(new EmptyBorder(10, 10, 10, 10));\n" +
  1887. "((JTextArea) descrText.getViewport().getView()).setOpaque(OPAQUE);\n" +
  1888. "descrText.getViewport().setOpaque(OPAQUE);\n" +
  1889. "\n" +
  1890. "JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, panel, descrText);\n" +
  1891. "splitPane.setOpaque(OPAQUE);\n" +
  1892. "splitPane.setBorder(null);\n" +
  1893. "\n" +
  1894. "panel.add(createLabel(\"\\\"\\\"\"));\n" +
  1895. "panel.add(createTextField(\"8\", 8));\n" +
  1896. "panel.add(createLabel(\"\\\"min!\\\"\"));\n" +
  1897. "panel.add(createTextField(\"3\", 3), \"width min!\");\n" +
  1898. "panel.add(createLabel(\"\\\"pref!\\\"\"));\n" +
  1899. "panel.add(createTextField(\"3\", 3), \"width pref!\");\n" +
  1900. "panel.add(createLabel(\"\\\"min:pref\\\"\"));\n" +
  1901. "panel.add(createTextField(\"8\", 8), \"width min:pref\");\n" +
  1902. "panel.add(createLabel(\"\\\"min:100:150\\\"\"));\n" +
  1903. "panel.add(createTextField(\"8\", 8), \"width min:100:150\");\n" +
  1904. "panel.add(createLabel(\"\\\"min:100:150, growx\\\"\"));\n" +
  1905. "panel.add(createTextField(\"8\", 8), \"width min:100:150, growx\");\n" +
  1906. "panel.add(createLabel(\"\\\"min:100, growx\\\"\"));\n" +
  1907. "panel.add(createTextField(\"8\", 8), \"width min:100, growx\");\n" +
  1908. "panel.add(createLabel(\"\\\"40!\\\"\"));\n" +
  1909. "panel.add(createTextField(\"8\", 8), \"width 40!\");\n" +
  1910. "panel.add(createLabel(\"\\\"40:40:40\\\"\"));\n" +
  1911. "panel.add(createTextField(\"8\", 8), \"width 40:40:40\");\n" +
  1912. "\n" +
  1913. "tabbedPane.addTab(\"Component Sizes\", splitPane);");
  1914. return tabbedPane;
  1915. }
  1916. public JComponent createCell_Alignments()
  1917. {
  1918. JTabbedPane tabbedPane = new JTabbedPane();
  1919. // Horizontal
  1920. MigLayout hLM = new MigLayout("wrap",
  1921. "[grow,left][grow,center][grow,right][grow,fill,center]",
  1922. "[]unrel[][]");
  1923. JPanel hPanel = createTabPanel(hLM);
  1924. String[] sizes = new String[] {"", "growx", "growx 0", "left", "center", "right", "leading", "trailing"};
  1925. hPanel.add(createLabel("[left]"), "c");
  1926. hPanel.add(createLabel("[center]"), "c");
  1927. hPanel.add(createLabel("[right]"), "c");
  1928. hPanel.add(createLabel("[fill,center]"), "c, growx 0");
  1929. for (int r = 0; r < sizes.length; r++) {
  1930. for (int c = 0; c < 4; c++) {
  1931. String text = sizes[r].length() > 0 ? sizes[r] : "default";
  1932. hPanel.add(createButton(text), sizes[r]);
  1933. }
  1934. }
  1935. // Vertical
  1936. MigLayout vLM = new MigLayout("wrap,flowy",
  1937. "[right][]",
  1938. "[grow,top][grow,center][grow,bottom][grow,fill,bottom][grow,fill,baseline]");
  1939. JPanel vPanel = createTabPanel(vLM);
  1940. String[] vSizes = new String[] {"", "growy", "growy 0", "top", "center", "bottom"};
  1941. vPanel.add(createLabel("[top]"), "center");
  1942. vPanel.add(createLabel("[center]"), "center");
  1943. vPanel.add(createLabel("[bottom]"), "center");
  1944. vPanel.add(createLabel("[fill, bottom]"), "center, growy 0");
  1945. vPanel.add(createLabel("[fill, baseline]"), "center");
  1946. for (int c = 0; c < vSizes.length; c++) {
  1947. for (int r = 0; r < 5; r++) {
  1948. String text = vSizes[c].length() > 0 ? vSizes[c] : "default";
  1949. JButton b = createButton(text);
  1950. if (r == 4 && c <= 1)
  1951. b.setFont(new Font("sansserif", Font.PLAIN, 16 + c * 5));
  1952. vPanel.add(b, vSizes[c]);
  1953. }
  1954. }
  1955. tabbedPane.addTab("Horizontal", hPanel);
  1956. tabbedPane.addTab("Vertical", vPanel);
  1957. // Disregard. Just forgetting the source code text close to the source code.
  1958. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  1959. "\n" +
  1960. "// Horizontal\n" +
  1961. "MigLayout hLM = new MigLayout(\"wrap\",\n" +
  1962. " \"[grow,left][grow,center][grow,right][grow,fill,center]\",\n" +
  1963. " \"[]unrel[][]\");\n" +
  1964. "JPanel hPanel = createTabPanel(hLM);\n" +
  1965. "String[] sizes = new String[] {\"\", \"growx\", \"growx 0\", \"left\", \"center\", \"right\", \"leading\", \"trailing\"};\n" +
  1966. "hPanel.add(createLabel(\"[left]\"), \"c\");\n" +
  1967. "hPanel.add(createLabel(\"[center]\"), \"c\");\n" +
  1968. "hPanel.add(createLabel(\"[right]\"), \"c\");\n" +
  1969. "hPanel.add(createLabel(\"[fill,center]\"), \"c, growx 0\");\n" +
  1970. "\n" +
  1971. "for (int r = 0; r < sizes.length; r++) {\n" +
  1972. "\tfor (int c = 0; c < 4; c++) {\n" +
  1973. "\t\tString text = sizes[r].length() > 0 ? sizes[r] : \"default\";\n" +
  1974. "\t\thPanel.add(createButton(text), sizes[r]);\n" +
  1975. "\t}\n" +
  1976. "}\n" +
  1977. "\n" +
  1978. "// Vertical\n" +
  1979. "MigLayout vLM = new MigLayout(\"wrap,flowy\",\n" +
  1980. " \"[right][]\",\n" +
  1981. " \"[grow,top][grow,center][grow,bottom][grow,fill,bottom][grow,fill,baseline]\");\n" +
  1982. "JPanel vPanel = createTabPanel(vLM);\n" +
  1983. "String[] vSizes = new String[] {\"\", \"growy\", \"growy 0\", \"top\", \"center\", \"bottom\"};\n" +
  1984. "vPanel.add(createLabel(\"[top]\"), \"center\");\n" +
  1985. "vPanel.add(createLabel(\"[center]\"), \"center\");\n" +
  1986. "vPanel.add(createLabel(\"[bottom]\"), \"center\");\n" +
  1987. "vPanel.add(createLabel(\"[fill, bottom]\"), \"center, growy 0\");\n" +
  1988. "vPanel.add(createLabel(\"[fill, baseline]\"), \"center\");\n" +
  1989. "\n" +
  1990. "for (int c = 0; c < vSizes.length; c++) {\n" +
  1991. "\tfor (int r = 0; r < 5; r++) {\n" +
  1992. "\t\tString text = vSizes[c].length() > 0 ? vSizes[c] : \"default\";\n" +
  1993. "\t\tJButton b = createButton(text);\n" +
  1994. "\t\tif (r == 4 && c <= 1)\n" +
  1995. "\t\t\tb.setFont(new Font(\"sansserif\", Font.PLAIN, 16 + c * 5));\n" +
  1996. "\t\tvPanel.add(b, vSizes[c]);\n" +
  1997. "\t}\n" +
  1998. "}\n" +
  1999. "\n" +
  2000. "tabbedPane.addTab(\"Horizontal\", hPanel);\n" +
  2001. "tabbedPane.addTab(\"Vertical\", vPanel);");
  2002. return tabbedPane;
  2003. }
  2004. public JComponent createUnits()
  2005. {
  2006. JTabbedPane tabbedPane = new JTabbedPane();
  2007. // Horizontal
  2008. MigLayout hLM = new MigLayout("wrap,nocache",
  2009. "[right][]",
  2010. "");
  2011. JPanel hPanel = createTabPanel(hLM);
  2012. String[] sizes = new String[] {"72pt", "25.4mm", "2.54cm", "1in", "72px", "96px", "120px", "25%", "20sp"};
  2013. for (int i = 0; i < sizes.length; i++) {
  2014. hPanel.add(createLabel(sizes[i]));
  2015. hPanel.add(createTextField(""), "width " + sizes[i] + "!");
  2016. }
  2017. // Horizontal lp
  2018. MigLayout hlpLM = new MigLayout("nocache", "[right][][]", "");
  2019. JPanel hlpPanel = createTabPanel(hlpLM);
  2020. hlpPanel.add(createLabel("9 cols"));
  2021. hlpPanel.add(createTextField(9));
  2022. String[] lpSizes = new String[] {"75lp", "75px", "88px", "100px"};
  2023. hlpPanel.add(createLabel("Width of createTextField(9)"), "wrap");
  2024. for (int i = 0; i < lpSizes.length; i++) {
  2025. hlpPanel.add(createLabel(lpSizes[i]));
  2026. hlpPanel.add(createTextField(""), "width " + lpSizes[i] + "!, wrap");
  2027. }
  2028. // Vertical
  2029. MigLayout vLM = new MigLayout("wrap,flowy,nocache",
  2030. "[c]",
  2031. "[top][top]");
  2032. JPanel vPanel = createTabPanel(vLM);
  2033. String[] vSizes = new String[] {"72pt", "25.4mm", "2.54cm", "1in", "72px", "96px", "120px", "25%", "20sp"};
  2034. for (int i = 0; i < sizes.length; i++) {
  2035. vPanel.add(createLabel(vSizes[i]));
  2036. vPanel.add(createTextArea("", 0, 5), "width 50!, height " + vSizes[i] + "!");
  2037. }
  2038. // Vertical lp
  2039. MigLayout vlpLM = new MigLayout("wrap,flowy,nocache",
  2040. "[c]",
  2041. "[top][top]40px[top][top]");
  2042. JPanel vlpPanel = createTabPanel(vlpLM);
  2043. vlpPanel.add(createLabel("4 rows"));
  2044. vlpPanel.add(createTextArea("", 4, 5), "width 50!");
  2045. vlpPanel.add(createLabel("field"));
  2046. vlpPanel.add(createTextField(5));
  2047. String[] vlpSizes1 = new String[] {"63lp", "57px", "63px", "68px", "25%"};
  2048. String[] vlpSizes2 = new String[] {"21lp", "21px", "23px", "24px", "10%"};
  2049. for (int i = 0; i < vlpSizes1.length; i++) {
  2050. vlpPanel.add(createLabel(vlpSizes1[i]));
  2051. vlpPanel.add(createTextArea("", 1, 5), "width 50!, height " + vlpSizes1[i] + "!");
  2052. vlpPanel.add(createLabel(vlpSizes2[i]));
  2053. vlpPanel.add(createTextField(5), "height " + vlpSizes2[i] + "!");
  2054. }
  2055. vlpPanel.add(createLabel("button"), "skip 2");
  2056. vlpPanel.add(createButton("..."));
  2057. tabbedPane.addTab("Horizontal", hPanel);
  2058. tabbedPane.addTab("Horizontal LP", hlpPanel);
  2059. tabbedPane.addTab("Vertical", vPanel);
  2060. tabbedPane.addTab("Vertical LP", vlpPanel);
  2061. // Disregard. Just forgetting the source code text close to the source code.
  2062. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2063. "\n" +
  2064. "// Horizontal\n" +
  2065. "MigLayout hLM = new MigLayout(\"wrap,nocache\",\n" +
  2066. "\t\t\t\t\t\t\t \"[right][]\",\n" +
  2067. "\t\t\t\t\t\t\t \"\");\n" +
  2068. "JPanel hPanel = createTabPanel(hLM);\n" +
  2069. "String[] sizes = new String[] {\"72pt\", \"25.4mm\", \"2.54cm\", \"1in\", \"72px\", \"96px\", \"120px\", \"25%\", \"20sp\"};\n" +
  2070. "for (int i = 0; i < sizes.length; i++) {\n" +
  2071. "\thPanel.add(createLabel(sizes[i]));\n" +
  2072. "\thPanel.add(createTextField(\"\"), \"width \" + sizes[i] + \"!\");\n" +
  2073. "}\n" +
  2074. "\n" +
  2075. "// Horizontal lp\n" +
  2076. "MigLayout hlpLM = new MigLayout(\"nocache\", \"[right][][]\", \"\");\n" +
  2077. "JPanel hlpPanel = createTabPanel(hlpLM);\n" +
  2078. "hlpPanel.add(createLabel(\"9 cols\"));\n" +
  2079. "hlpPanel.add(createTextField(9));\n" +
  2080. "String[] lpSizes = new String[] {\"75lp\", \"75px\", \"88px\", \"100px\"};\n" +
  2081. "hlpPanel.add(createLabel(\"Width of createTextField(9)\"), \"wrap\");\n" +
  2082. "for (int i = 0; i < lpSizes.length; i++) {\n" +
  2083. "\thlpPanel.add(createLabel(lpSizes[i]));\n" +
  2084. "\thlpPanel.add(createTextField(\"\"), \"width \" + lpSizes[i] + \"!, wrap\");\n" +
  2085. "}\n" +
  2086. "\n" +
  2087. "// Vertical\n" +
  2088. "MigLayout vLM = new MigLayout(\"wrap,flowy,nocache\",\n" +
  2089. "\t\t\t\t\t\t\t \"[c]\",\n" +
  2090. "\t\t\t\t\t\t\t \"[top][top]\");\n" +
  2091. "JPanel vPanel = createTabPanel(vLM);\n" +
  2092. "String[] vSizes = new String[] {\"72pt\", \"25.4mm\", \"2.54cm\", \"1in\", \"72px\", \"96px\", \"120px\", \"25%\", \"20sp\"};\n" +
  2093. "for (int i = 0; i < sizes.length; i++) {\n" +
  2094. "\tvPanel.add(createLabel(vSizes[i]));\n" +
  2095. "\tvPanel.add(createTextArea(\"\", 0, 5), \"width 50!, height \" + vSizes[i] + \"!\");\n" +
  2096. "}\n" +
  2097. "\n" +
  2098. "// Vertical lp\n" +
  2099. "MigLayout vlpLM = new MigLayout(\"wrap,flowy,nocache\",\n" +
  2100. "\t\t\t\t\t\t\t\t\"[c]\",\n" +
  2101. "\t\t\t\t\t\t\t\t\"[top][top]40px[top][top]\");\n" +
  2102. "JPanel vlpPanel = createTabPanel(vlpLM);\n" +
  2103. "vlpPanel.add(createLabel(\"4 rows\"));\n" +
  2104. "vlpPanel.add(createTextArea(\"\", 4, 5), \"width 50!\");\n" +
  2105. "vlpPanel.add(createLabel(\"field\"));\n" +
  2106. "vlpPanel.add(createTextField(5));\n" +
  2107. "\n" +
  2108. "String[] vlpSizes1 = new String[] {\"63lp\", \"57px\", \"63px\", \"68px\", \"25%\"};\n" +
  2109. "String[] vlpSizes2 = new String[] {\"21lp\", \"21px\", \"23px\", \"24px\", \"10%\"};\n" +
  2110. "for (int i = 0; i < vlpSizes1.length; i++) {\n" +
  2111. "\tvlpPanel.add(createLabel(vlpSizes1[i]));\n" +
  2112. "\tvlpPanel.add(createTextArea(\"\", 1, 5), \"width 50!, height \" + vlpSizes1[i] + \"!\");\n" +
  2113. "\tvlpPanel.add(createLabel(vlpSizes2[i]));\n" +
  2114. "\tvlpPanel.add(createTextField(5), \"height \" + vlpSizes2[i] + \"!\");\n" +
  2115. "}\n" +
  2116. "\n" +
  2117. "vlpPanel.add(createLabel(\"button\"), \"skip 2\");\n" +
  2118. "vlpPanel.add(createButton(\"...\"));\n" +
  2119. "\n" +
  2120. "tabbedPane.addTab(\"Horizontal\", hPanel);\n" +
  2121. "tabbedPane.addTab(\"Horizontal LP\", hlpPanel);\n" +
  2122. "tabbedPane.addTab(\"Vertical\", vPanel);\n" +
  2123. "tabbedPane.addTab(\"Vertical LP\", vlpPanel);");
  2124. return tabbedPane;
  2125. }
  2126. public JComponent createGrouping()
  2127. {
  2128. JTabbedPane tabbedPane = new JTabbedPane();
  2129. // Ungrouped
  2130. MigLayout ugM = new MigLayout("", "[]push[][][]", "");
  2131. JPanel ugPanel = createTabPanel(ugM);
  2132. ugPanel.add(createButton("Help"));
  2133. ugPanel.add(createButton("< Back"), "");
  2134. ugPanel.add(createButton("Forward >"), "gap push");
  2135. ugPanel.add(createButton("Apply"), "gap unrel");
  2136. ugPanel.add(createButton("Cancel"), "gap unrel");
  2137. // Grouped Components
  2138. MigLayout gM = new MigLayout("nogrid, fillx");
  2139. JPanel gPanel = createTabPanel(gM);
  2140. gPanel.add(createButton("Help"), "sg");
  2141. gPanel.add(createButton("< Back"), "sg,gap push");
  2142. gPanel.add(createButton("Forward >"), "sg");
  2143. gPanel.add(createButton("Apply"), "sg,gap unrel");
  2144. gPanel.add(createButton("Cancel"), "sg,gap unrel");
  2145. // Grouped Columns
  2146. MigLayout gcM = new MigLayout("", "[sg,fill]push[sg,fill][sg,fill]unrel[sg,fill]unrel[sg,fill]", "");
  2147. JPanel gcPanel = createTabPanel(gcM);
  2148. gcPanel.add(createButton("Help"));
  2149. gcPanel.add(createButton("< Back"));
  2150. gcPanel.add(createButton("Forward >"));
  2151. gcPanel.add(createButton("Apply"));
  2152. gcPanel.add(createButton("Cancel"));
  2153. // Ungrouped Rows
  2154. MigLayout ugrM = new MigLayout(); // no "sg" is the only difference to next panel
  2155. JPanel ugrPanel = createTabPanel(ugrM);
  2156. ugrPanel.add(createLabel("File Number:"));
  2157. ugrPanel.add(createTextField(30), "wrap");
  2158. ugrPanel.add(createLabel("BL/MBL number:"));
  2159. ugrPanel.add(createTextField(7), "split 2");
  2160. ugrPanel.add(createTextField(7), "wrap");
  2161. ugrPanel.add(createLabel("Entry Date:"));
  2162. ugrPanel.add(createTextField(7), "wrap");
  2163. ugrPanel.add(createLabel("RFQ Number:"));
  2164. ugrPanel.add(createTextField(30), "wrap");
  2165. ugrPanel.add(createLabel("Goods:"));
  2166. ugrPanel.add(createCheck("Dangerous"), "wrap");
  2167. ugrPanel.add(createLabel("Shipper:"));
  2168. ugrPanel.add(createTextField(30), "wrap");
  2169. ugrPanel.add(createLabel("Customer:"));
  2170. ugrPanel.add(createTextField(""), "split 2,growx");
  2171. ugrPanel.add(createButton("..."), "width 60px:pref,wrap");
  2172. ugrPanel.add(createLabel("Port of Loading:"));
  2173. ugrPanel.add(createTextField(30), "wrap");
  2174. ugrPanel.add(createLabel("Destination:"));
  2175. ugrPanel.add(createTextField(30), "wrap");
  2176. // Grouped Rows
  2177. MigLayout grM = new MigLayout("", "[]", "[sg]"); // "sg" is the only difference to previous panel
  2178. JPanel grPanel = createTabPanel(grM);
  2179. grPanel.add(createLabel("File Number:"));
  2180. grPanel.add(createTextField(30),"wrap");
  2181. grPanel.add(createLabel("BL/MBL number:"));
  2182. grPanel.add(createTextField(7),"split 2");
  2183. grPanel.add(createTextField(7), "wrap");
  2184. grPanel.add(createLabel("Entry Date:"));
  2185. grPanel.add(createTextField(7), "wrap");
  2186. grPanel.add(createLabel("RFQ Number:"));
  2187. grPanel.add(createTextField(30), "wrap");
  2188. grPanel.add(createLabel("Goods:"));
  2189. grPanel.add(createCheck("Dangerous"), "wrap");
  2190. grPanel.add(createLabel("Shipper:"));
  2191. grPanel.add(createTextField(30), "wrap");
  2192. grPanel.add(createLabel("Customer:"));
  2193. grPanel.add(createTextField(""), "split 2,growx");
  2194. grPanel.add(createButton("..."), "width 50px:pref,wrap");
  2195. grPanel.add(createLabel("Port of Loading:"));
  2196. grPanel.add(createTextField(30), "wrap");
  2197. grPanel.add(createLabel("Destination:"));
  2198. grPanel.add(createTextField(30), "wrap");
  2199. tabbedPane.addTab("Ungrouped", ugPanel);
  2200. tabbedPane.addTab("Grouped (Components)", gPanel);
  2201. tabbedPane.addTab("Grouped (Columns)", gcPanel);
  2202. tabbedPane.addTab("Ungrouped Rows", ugrPanel);
  2203. tabbedPane.addTab("Grouped Rows", grPanel);
  2204. // Disregard. Just forgetting the source code text close to the source code.
  2205. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2206. "\n" +
  2207. "// Ungrouped\n" +
  2208. "MigLayout ugM = new MigLayout(\"\", \"[]push[][][]\", \"\");\n" +
  2209. "JPanel ugPanel = createTabPanel(ugM);\n" +
  2210. "ugPanel.add(createButton(\"Help\"));\n" +
  2211. "ugPanel.add(createButton(\"< Back\"), \"\");\n" +
  2212. "ugPanel.add(createButton(\"Forward >\"), \"gap push\");\n" +
  2213. "ugPanel.add(createButton(\"Apply\"), \"gap unrel\");\n" +
  2214. "ugPanel.add(createButton(\"Cancel\"), \"gap unrel\");\n" +
  2215. "\n" +
  2216. "// Grouped Components\n" +
  2217. "MigLayout gM = new MigLayout(\"nogrid, fillx\");\n" +
  2218. "JPanel gPanel = createTabPanel(gM);\n" +
  2219. "gPanel.add(createButton(\"Help\"), \"sg\");\n" +
  2220. "gPanel.add(createButton(\"< Back\"), \"sg,gap push\");\n" +
  2221. "gPanel.add(createButton(\"Forward >\"), \"sg\");\n" +
  2222. "gPanel.add(createButton(\"Apply\"), \"sg,gap unrel\");\n" +
  2223. "gPanel.add(createButton(\"Cancel\"), \"sg,gap unrel\");\n" +
  2224. "\n" +
  2225. "// Grouped Columns\n" +
  2226. "MigLayout gcM = new MigLayout(\"\", \"[sg,fill]push[sg,fill][sg,fill]unrel[sg,fill]unrel[sg,fill]\", \"\");\n" +
  2227. "JPanel gcPanel = createTabPanel(gcM);\n" +
  2228. "gcPanel.add(createButton(\"Help\"));\n" +
  2229. "gcPanel.add(createButton(\"< Back\"));\n" +
  2230. "gcPanel.add(createButton(\"Forward >\"));\n" +
  2231. "gcPanel.add(createButton(\"Apply\"));\n" +
  2232. "gcPanel.add(createButton(\"Cancel\"));\n" +
  2233. "\n" +
  2234. "// Ungrouped Rows\n" +
  2235. "MigLayout ugrM = new MigLayout(); // no \"sg\" is the only difference to next panel\n" +
  2236. "JPanel ugrPanel = createTabPanel(ugrM);\n" +
  2237. "ugrPanel.add(createLabel(\"File Number:\"));\n" +
  2238. "ugrPanel.add(createTextField(30), \"wrap\");\n" +
  2239. "ugrPanel.add(createLabel(\"BL/MBL number:\"));\n" +
  2240. "ugrPanel.add(createTextField(7), \"split 2\");\n" +
  2241. "ugrPanel.add(createTextField(7), \"wrap\");\n" +
  2242. "ugrPanel.add(createLabel(\"Entry Date:\"));\n" +
  2243. "ugrPanel.add(createTextField(7), \"wrap\");\n" +
  2244. "ugrPanel.add(createLabel(\"RFQ Number:\"));\n" +
  2245. "ugrPanel.add(createTextField(30), \"wrap\");\n" +
  2246. "ugrPanel.add(createLabel(\"Goods:\"));\n" +
  2247. "ugrPanel.add(createCheck(\"Dangerous\"), \"wrap\");\n" +
  2248. "ugrPanel.add(createLabel(\"Shipper:\"));\n" +
  2249. "ugrPanel.add(createTextField(30), \"wrap\");\n" +
  2250. "ugrPanel.add(createLabel(\"Customer:\"));\n" +
  2251. "ugrPanel.add(createTextField(\"\"), \"split 2,growx\");\n" +
  2252. "ugrPanel.add(createButton(\"...\"), \"width 60px:pref,wrap\");\n" +
  2253. "ugrPanel.add(createLabel(\"Port of Loading:\"));\n" +
  2254. "ugrPanel.add(createTextField(30), \"wrap\");\n" +
  2255. "ugrPanel.add(createLabel(\"Destination:\"));\n" +
  2256. "ugrPanel.add(createTextField(30), \"wrap\");\n" +
  2257. "\n" +
  2258. "// Grouped Rows\n" +
  2259. "MigLayout grM = new MigLayout(\"\", \"[]\", \"[sg]\"); // \"sg\" is the only difference to previous panel\n" +
  2260. "JPanel grPanel = createTabPanel(grM);\n" +
  2261. "grPanel.add(createLabel(\"File Number:\"));\n" +
  2262. "grPanel.add(createTextField(30),\"wrap\");\n" +
  2263. "grPanel.add(createLabel(\"BL/MBL number:\"));\n" +
  2264. "grPanel.add(createTextField(7),\"split 2\");\n" +
  2265. "grPanel.add(createTextField(7), \"wrap\");\n" +
  2266. "grPanel.add(createLabel(\"Entry Date:\"));\n" +
  2267. "grPanel.add(createTextField(7), \"wrap\");\n" +
  2268. "grPanel.add(createLabel(\"RFQ Number:\"));\n" +
  2269. "grPanel.add(createTextField(30), \"wrap\");\n" +
  2270. "grPanel.add(createLabel(\"Goods:\"));\n" +
  2271. "grPanel.add(createCheck(\"Dangerous\"), \"wrap\");\n" +
  2272. "grPanel.add(createLabel(\"Shipper:\"));\n" +
  2273. "grPanel.add(createTextField(30), \"wrap\");\n" +
  2274. "grPanel.add(createLabel(\"Customer:\"));\n" +
  2275. "grPanel.add(createTextField(\"\"), \"split 2,growx\");\n" +
  2276. "grPanel.add(createButton(\"...\"), \"width 50px:pref,wrap\");\n" +
  2277. "grPanel.add(createLabel(\"Port of Loading:\"));\n" +
  2278. "grPanel.add(createTextField(30), \"wrap\");\n" +
  2279. "grPanel.add(createLabel(\"Destination:\"));\n" +
  2280. "grPanel.add(createTextField(30), \"wrap\");\n" +
  2281. "\n" +
  2282. "tabbedPane.addTab(\"Ungrouped\", ugPanel);\n" +
  2283. "tabbedPane.addTab(\"Grouped (Components)\", gPanel);\n" +
  2284. "tabbedPane.addTab(\"Grouped (Columns)\", gcPanel);\n" +
  2285. "tabbedPane.addTab(\"Ungrouped Rows\", ugrPanel);\n" +
  2286. "tabbedPane.addTab(\"Grouped Rows\", grPanel);");
  2287. return tabbedPane;
  2288. }
  2289. public JComponent createSpan()
  2290. {
  2291. JTabbedPane tabbedPane = new JTabbedPane();
  2292. // Horizontal span
  2293. MigLayout colLM = new MigLayout("nocache",
  2294. "[fill][25%!,fill][105lp!,fill][100px!,fill]",
  2295. "[]15[][]");
  2296. JPanel colPanel = createTabPanel(colLM);
  2297. colPanel.add(createTextField("Col1 [ ]"));
  2298. colPanel.add(createTextField("Col2 [25%!]"));
  2299. colPanel.add(createTextField("Col3 [105lp!]"));
  2300. colPanel.add(createTextField("Col4 [100px!]"), "wrap");
  2301. colPanel.add(createLabel("Full Name:"));
  2302. colPanel.add(createTextField("span, growx", 40), "span,growx");
  2303. colPanel.add(createLabel("Phone:"));
  2304. colPanel.add(createTextField(5), "span 3, split 5");
  2305. colPanel.add(createTextField(7));
  2306. colPanel.add(createTextField(7));
  2307. colPanel.add(createTextField(9));
  2308. colPanel.add(createLabel("(span 3, split 4)"), "wrap");
  2309. colPanel.add(createLabel("Zip/City:"));
  2310. colPanel.add(createTextField(5));
  2311. colPanel.add(createTextField("span 2, growx", 5), "span 2,growx");
  2312. // Vertical span
  2313. MigLayout rowLM = new MigLayout("wrap",
  2314. "[225lp]para[225lp]",
  2315. "[]3[]unrel[]3[]unrel[]3[]");
  2316. JPanel rowPanel = createTabPanel(rowLM);
  2317. rowPanel.add(createLabel("Name"));
  2318. rowPanel.add(createLabel("Notes"));
  2319. rowPanel.add(createTextField("growx"), "growx");
  2320. rowPanel.add(createTextArea("spany,grow", 5, 20), "spany,grow");
  2321. rowPanel.add(createLabel("Phone"));
  2322. rowPanel.add(createTextField("growx"), "growx");
  2323. rowPanel.add(createLabel("Fax"));
  2324. rowPanel.add(createTextField("growx"), "growx");
  2325. tabbedPane.addTab("Column Span/Split", colPanel);
  2326. tabbedPane.addTab("Row Span", rowPanel);
  2327. // Disregard. Just forgetting the source code text close to the source code.
  2328. setSource("\t\tJTabbedPane tabbedPane = new JTabbedPane();\n" +
  2329. "\n" +
  2330. "\t\t// Horizontal span\n" +
  2331. "\t\tMigLayout colLM = new MigLayout(\"\",\n" +
  2332. "\t\t \"[fill][25%!,fill][105lp!,fill][100px!,fill]\",\n" +
  2333. "\t\t \"[]15[][]\");\n" +
  2334. "\t\tJPanel colPanel = createTabPanel(colLM);\n" +
  2335. "\t\tcolPanel.add(createTextField(\"Col1 [ ]\"));\n" +
  2336. "\t\tcolPanel.add(createTextField(\"Col2 [25%!]\"));\n" +
  2337. "\t\tcolPanel.add(createTextField(\"Col3 [105lp!]\"));\n" +
  2338. "\t\tcolPanel.add(createTextField(\"Col4 [100px!]\"), \"wrap\");\n" +
  2339. "\n" +
  2340. "\t\tcolPanel.add(createLabel(\"Full Name:\"));\n" +
  2341. "\t\tcolPanel.add(createTextField(\"span, growx\", 40), \"span,growx\");\n" +
  2342. "\n" +
  2343. "\t\tcolPanel.add(createLabel(\"Phone:\"));\n" +
  2344. "\t\tcolPanel.add(createTextField(5), \"span 3, split 5\");\n" +
  2345. "\t\tcolPanel.add(createTextField(7));\n" +
  2346. "\t\tcolPanel.add(createTextField(7));\n" +
  2347. "\t\tcolPanel.add(createTextField(9));\n" +
  2348. "\t\tcolPanel.add(createLabel(\"(span 3, split 4)\"), \"wrap\");\n" +
  2349. "\n" +
  2350. "\t\tcolPanel.add(createLabel(\"Zip/City:\"));\n" +
  2351. "\t\tcolPanel.add(createTextField(5));\n" +
  2352. "\t\tcolPanel.add(createTextField(\"span 2, growx\", 5), \"span 2,growx\");\n" +
  2353. "\n" +
  2354. "\t\t// Vertical span\n" +
  2355. "\t\tMigLayout rowLM = new MigLayout(\"wrap\",\n" +
  2356. "\t\t \"[225lp]para[225lp]\",\n" +
  2357. "\t\t \"[]3[]unrel[]3[]unrel[]3[]\");\n" +
  2358. "\t\tJPanel rowPanel = createTabPanel(rowLM);\n" +
  2359. "\t\trowPanel.add(createLabel(\"Name\"));\n" +
  2360. "\t\trowPanel.add(createLabel(\"Notes\"));\n" +
  2361. "\t\trowPanel.add(createTextField(\"growx\"), \"growx\");\n" +
  2362. "\t\trowPanel.add(createTextArea(\"spany,grow\", 5, 20), \"spany,grow\");\n" +
  2363. "\t\trowPanel.add(createLabel(\"Phone\"));\n" +
  2364. "\t\trowPanel.add(createTextField(\"growx\"), \"growx\");\n" +
  2365. "\t\trowPanel.add(createLabel(\"Fax\"));\n" +
  2366. "\t\trowPanel.add(createTextField(\"growx\"), \"growx\");\n" +
  2367. "\n" +
  2368. "\t\ttabbedPane.addTab(\"Column Span/Split\", colPanel);\n" +
  2369. "\t\ttabbedPane.addTab(\"Row Span\", rowPanel);");
  2370. return tabbedPane;
  2371. }
  2372. public JComponent createGrowing()
  2373. {
  2374. JTabbedPane tabbedPane = new JTabbedPane();
  2375. // All tab
  2376. MigLayout allLM = new MigLayout("",
  2377. "[pref!][grow,fill]",
  2378. "[]15[]");
  2379. JPanel allTab = createTabPanel(allLM);
  2380. allTab.add(createLabel("Fixed"));
  2381. allTab.add(createLabel("Gets all extra space"), "wrap");
  2382. allTab.add(createTextField(5));
  2383. allTab.add(createTextField(5));
  2384. // Half tab
  2385. MigLayout halfLM = new MigLayout("",
  2386. "[pref!][grow,fill]",
  2387. "[]15[]");
  2388. JPanel halfTab = createTabPanel(halfLM);
  2389. halfTab.add(createLabel("Fixed"));
  2390. halfTab.add(createLabel("Gets half of extra space"));
  2391. halfTab.add(createLabel("Gets half of extra space"), "wrap");
  2392. halfTab.add(createTextField(5));
  2393. halfTab.add(createTextField(5));
  2394. halfTab.add(createTextField(5));
  2395. // Percent 1 tab
  2396. MigLayout p1LM = new MigLayout("",
  2397. "[pref!][0:0,grow 25,fill][0:0,grow 75,fill]",
  2398. "[]15[]");
  2399. JPanel p1Tab = createTabPanel(p1LM);
  2400. p1Tab.add(createLabel("Fixed"));
  2401. p1Tab.add(createLabel("Gets 25% of extra space"), "");
  2402. p1Tab.add(createLabel("Gets 75% of extra space"), "wrap");
  2403. p1Tab.add(createTextField(5));
  2404. p1Tab.add(createTextField(5));
  2405. p1Tab.add(createTextField(5));
  2406. // Percent 2 tab
  2407. MigLayout p2LM = new MigLayout("",
  2408. "[0:0,grow 33,fill][0:0,grow 67,fill]",
  2409. "[]15[]");
  2410. JPanel p2Tab = createTabPanel(p2LM);
  2411. p2Tab.add(createLabel("Gets 33% of extra space"), "");
  2412. p2Tab.add(createLabel("Gets 67% of extra space"), "wrap");
  2413. p2Tab.add(createTextField(5));
  2414. p2Tab.add(createTextField(5));
  2415. // Vertical 1 tab
  2416. MigLayout v1LM = new MigLayout("flowy",
  2417. "[]15[]",
  2418. "[][c,pref!][c,grow 25,fill][c,grow 75,fill]");
  2419. JPanel v1Tab = createTabPanel(v1LM);
  2420. v1Tab.add(createLabel("Fixed"), "skip");
  2421. v1Tab.add(createLabel("Gets 25% of extra space"));
  2422. v1Tab.add(createLabel("Gets 75% of extra space"), "wrap");
  2423. v1Tab.add(createLabel("new JTextArea(4, 30)"));
  2424. v1Tab.add(createTextAreaScroll("", 4, 30, false));
  2425. v1Tab.add(createTextAreaScroll("", 4, 30, false));
  2426. v1Tab.add(createTextAreaScroll("", 4, 30, false));
  2427. // Vertical 2 tab
  2428. MigLayout v2LM = new MigLayout("flowy",
  2429. "[]15[]",
  2430. "[][c,grow 33,fill][c,grow 67,fill]");
  2431. JPanel v2Tab = createTabPanel(v2LM);
  2432. v2Tab.add(createLabel("Gets 33% of extra space"), "skip");
  2433. v2Tab.add(createLabel("Gets 67% of extra space"), "wrap");
  2434. v2Tab.add(createLabel("new JTextArea(4, 30)"));
  2435. v2Tab.add(createTextAreaScroll("", 4, 30, false));
  2436. v2Tab.add(createTextAreaScroll("", 4, 30, false));
  2437. tabbedPane.addTab("All", allTab);
  2438. tabbedPane.addTab("Half", halfTab);
  2439. tabbedPane.addTab("Percent 1", p1Tab);
  2440. tabbedPane.addTab("Percent 2", p2Tab);
  2441. tabbedPane.addTab("Vertical 1", v1Tab);
  2442. tabbedPane.addTab("Vertical 2", v2Tab);
  2443. // Disregard. Just forgetting the source code text close to the source code.
  2444. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2445. "\n" +
  2446. "// All tab\n" +
  2447. "MigLayout allLM = new MigLayout(\"\",\n" +
  2448. " \"[pref!][grow,fill]\",\n" +
  2449. " \"[]15[]\");\n" +
  2450. "JPanel allTab = createTabPanel(allLM);\n" +
  2451. "allTab.add(createLabel(\"Fixed\"));\n" +
  2452. "allTab.add(createLabel(\"Gets all extra space\"), \"wrap\");\n" +
  2453. "allTab.add(createTextField(5));\n" +
  2454. "allTab.add(createTextField(5));\n" +
  2455. "\n" +
  2456. "// Half tab\n" +
  2457. "MigLayout halfLM = new MigLayout(\"\",\n" +
  2458. " \"[pref!][grow,fill]\",\n" +
  2459. " \"[]15[]\");\n" +
  2460. "JPanel halfTab = createTabPanel(halfLM);\n" +
  2461. "halfTab.add(createLabel(\"Fixed\"));\n" +
  2462. "halfTab.add(createLabel(\"Gets half of extra space\"));\n" +
  2463. "halfTab.add(createLabel(\"Gets half of extra space\"), \"wrap\");\n" +
  2464. "halfTab.add(createTextField(5));\n" +
  2465. "halfTab.add(createTextField(5));\n" +
  2466. "halfTab.add(createTextField(5));\n" +
  2467. "\n" +
  2468. "// Percent 1 tab\n" +
  2469. "MigLayout p1LM = new MigLayout(\"\",\n" +
  2470. " \"[pref!][0:0,grow 25,fill][0:0,grow 75,fill]\",\n" +
  2471. " \"[]15[]\");\n" +
  2472. "JPanel p1Tab = createTabPanel(p1LM);\n" +
  2473. "p1Tab.add(createLabel(\"Fixed\"));\n" +
  2474. "p1Tab.add(createLabel(\"Gets 25% of extra space\"), \"\");\n" +
  2475. "p1Tab.add(createLabel(\"Gets 75% of extra space\"), \"wrap\");\n" +
  2476. "p1Tab.add(createTextField(5));\n" +
  2477. "p1Tab.add(createTextField(5));\n" +
  2478. "p1Tab.add(createTextField(5));\n" +
  2479. "\n" +
  2480. "// Percent 2 tab\n" +
  2481. "MigLayout p2LM = new MigLayout(\"\",\n" +
  2482. " \"[0:0,grow 33,fill][0:0,grow 67,fill]\",\n" +
  2483. " \"[]15[]\");\n" +
  2484. "JPanel p2Tab = createTabPanel(p2LM);\n" +
  2485. "p2Tab.add(createLabel(\"Gets 33% of extra space\"), \"\");\n" +
  2486. "p2Tab.add(createLabel(\"Gets 67% of extra space\"), \"wrap\");\n" +
  2487. "p2Tab.add(createTextField(5));\n" +
  2488. "p2Tab.add(createTextField(5));\n" +
  2489. "\n" +
  2490. "// Vertical 1 tab\n" +
  2491. "MigLayout v1LM = new MigLayout(\"flowy\",\n" +
  2492. " \"[]15[]\",\n" +
  2493. " \"[][c,pref!][c,grow 25,fill][c,grow 75,fill]\");\n" +
  2494. "JPanel v1Tab = createTabPanel(v1LM);\n" +
  2495. "v1Tab.add(createLabel(\"Fixed\"), \"skip\");\n" +
  2496. "v1Tab.add(createLabel(\"Gets 25% of extra space\"));\n" +
  2497. "v1Tab.add(createLabel(\"Gets 75% of extra space\"), \"wrap\");\n" +
  2498. "v1Tab.add(createLabel(\"new JTextArea(4, 30)\"));\n" +
  2499. "v1Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
  2500. "v1Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
  2501. "v1Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
  2502. "\n" +
  2503. "// Vertical 2 tab\n" +
  2504. "MigLayout v2LM = new MigLayout(\"flowy\",\n" +
  2505. " \"[]15[]\",\n" +
  2506. " \"[][c,grow 33,fill][c,grow 67,fill]\");\n" +
  2507. "JPanel v2Tab = createTabPanel(v2LM);\n" +
  2508. "v2Tab.add(createLabel(\"Gets 33% of extra space\"), \"skip\");\n" +
  2509. "v2Tab.add(createLabel(\"Gets 67% of extra space\"), \"wrap\");\n" +
  2510. "v2Tab.add(createLabel(\"new JTextArea(4, 30)\"));\n" +
  2511. "v2Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
  2512. "v2Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
  2513. "\n" +
  2514. "tabbedPane.addTab(\"All\", allTab);\n" +
  2515. "tabbedPane.addTab(\"Half\", halfTab);\n" +
  2516. "tabbedPane.addTab(\"Percent 1\", p1Tab);\n" +
  2517. "tabbedPane.addTab(\"Percent 2\", p2Tab);\n" +
  2518. "tabbedPane.addTab(\"Vertical 1\", v1Tab);\n" +
  2519. "tabbedPane.addTab(\"Vertical 2\", v2Tab);");
  2520. return tabbedPane;
  2521. }
  2522. public JComponent createBasic_Sizes()
  2523. {
  2524. JTabbedPane tabbedPane = new JTabbedPane();
  2525. // Horizontal tab
  2526. MigLayout horLM = new MigLayout("",
  2527. "[]15[75px]25[min]25[]",
  2528. "[]15");
  2529. JPanel horTab = createTabPanel(horLM);
  2530. horTab.add(createLabel("75px"), "skip");
  2531. horTab.add(createLabel("Min"));
  2532. horTab.add(createLabel("Pref"), "wrap");
  2533. horTab.add(createLabel("new TextField(15)"));
  2534. horTab.add(createTextField(15));
  2535. horTab.add(createTextField(15));
  2536. horTab.add(createTextField(15));
  2537. // Vertical tab 1
  2538. MigLayout verLM = new MigLayout("flowy,wrap",
  2539. "[]15[]",
  2540. "[]15[c,45px]15[c,min]15[c,pref]");
  2541. JPanel verTab = createTabPanel(verLM);
  2542. verTab.add(createLabel("45px"), "skip");
  2543. verTab.add(createLabel("Min"));
  2544. verTab.add(createLabel("Pref"));
  2545. verTab.add(createLabel("new JTextArea(10, 40)"));
  2546. verTab.add(createTextArea("", 10, 40));
  2547. verTab.add(createTextArea("", 10, 40));
  2548. verTab.add(createTextArea("", 10, 40));
  2549. // Componentsized/Baseline 2
  2550. MigLayout verLM2 = new MigLayout("flowy,wrap",
  2551. "[]15[]",
  2552. "[]15[baseline]15[baseline]15[baseline]");
  2553. JPanel verTab2 = createTabPanel(verLM2);
  2554. verTab2.add(createLabel("45px"), "skip");
  2555. verTab2.add(createLabel("Min"));
  2556. verTab2.add(createLabel("Pref"));
  2557. verTab2.add(createLabel("new JTextArea(10, 40)"));
  2558. verTab2.add(createTextArea("", 10, 40), "height 45");
  2559. verTab2.add(createTextArea("", 10, 40), "height min");
  2560. verTab2.add(createTextArea("", 10, 40), "height pref");
  2561. tabbedPane.addTab("Horizontal - Column size set", horTab);
  2562. tabbedPane.addTab("Vertical - Row sized", verTab);
  2563. tabbedPane.addTab("Vertical - Component sized + Baseline", verTab2);
  2564. // Disregard. Just forgetting the source code text close to the source code.
  2565. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2566. "\n" +
  2567. "// Horizontal tab\n" +
  2568. "MigLayout horLM = new MigLayout(\"\",\n" +
  2569. " \"[]15[75px]25[min]25[]\",\n" +
  2570. " \"[]15\");\n" +
  2571. "JPanel horTab = createTabPanel(horLM);\n" +
  2572. "horTab.add(createLabel(\"75px\"), \"skip\");\n" +
  2573. "horTab.add(createLabel(\"Min\"));\n" +
  2574. "horTab.add(createLabel(\"Pref\"), \"wrap\");\n" +
  2575. "\n" +
  2576. "horTab.add(createLabel(\"new TextField(15)\"));\n" +
  2577. "horTab.add(createTextField(15));\n" +
  2578. "horTab.add(createTextField(15));\n" +
  2579. "horTab.add(createTextField(15));\n" +
  2580. "\n" +
  2581. "// Vertical tab 1\n" +
  2582. "MigLayout verLM = new MigLayout(\"flowy,wrap\",\n" +
  2583. " \"[]15[]\",\n" +
  2584. " \"[]15[c,45px]15[c,min]15[c,pref]\");\n" +
  2585. "JPanel verTab = createTabPanel(verLM);\n" +
  2586. "verTab.add(createLabel(\"45px\"), \"skip\");\n" +
  2587. "verTab.add(createLabel(\"Min\"));\n" +
  2588. "verTab.add(createLabel(\"Pref\"));\n" +
  2589. "\n" +
  2590. "verTab.add(createLabel(\"new JTextArea(10, 40)\"));\n" +
  2591. "verTab.add(createTextArea(\"\", 10, 40));\n" +
  2592. "verTab.add(createTextArea(\"\", 10, 40));\n" +
  2593. "verTab.add(createTextArea(\"\", 10, 40));\n" +
  2594. "\n" +
  2595. "// Componentsized/Baseline 2\n" +
  2596. "MigLayout verLM2 = new MigLayout(\"flowy,wrap\",\n" +
  2597. " \"[]15[]\",\n" +
  2598. " \"[]15[baseline]15[baseline]15[baseline]\");\n" +
  2599. "JPanel verTab2 = createTabPanel(verLM2);\n" +
  2600. "verTab2.add(createLabel(\"45px\"), \"skip\");\n" +
  2601. "verTab2.add(createLabel(\"Min\"));\n" +
  2602. "verTab2.add(createLabel(\"Pref\"));\n" +
  2603. "\n" +
  2604. "verTab2.add(createLabel(\"new JTextArea(10, 40)\"));\n" +
  2605. "verTab2.add(createTextArea(\"\", 10, 40), \"height 45\");\n" +
  2606. "verTab2.add(createTextArea(\"\", 10, 40), \"height min\");\n" +
  2607. "verTab2.add(createTextArea(\"\", 10, 40), \"height pref\");\n" +
  2608. "\n" +
  2609. "tabbedPane.addTab(\"Horizontal - Column size set\", horTab);\n" +
  2610. "tabbedPane.addTab(\"Vertical - Row sized\", verTab);\n" +
  2611. "tabbedPane.addTab(\"Vertical - Component sized + Baseline\", verTab2);");
  2612. return tabbedPane;
  2613. }
  2614. public JComponent createAlignments()
  2615. {
  2616. JTabbedPane tabbedPane = new JTabbedPane();
  2617. // Horizontal tab
  2618. MigLayout horLM = new MigLayout("wrap",
  2619. "[label]15[left]15[center]15[right]15[fill]15[]",
  2620. "[]15[]");
  2621. String[] horLabels = new String[] {"[label]", "[left]", "[center]", "[right]", "[fill]", "[] (Default)"};
  2622. JPanel horTab = createTabPanel(horLM);
  2623. String[] horNames = new String[] {"First Name", "Phone Number", "Facsmile", "Email", "Address", "Other"};
  2624. for (int c = 0; c < horLabels.length; c++)
  2625. horTab.add(createLabel(horLabels[c]));
  2626. for (int r = 0; r < horLabels.length; r++) {
  2627. for (int c = 0; c < horNames.length; c++)
  2628. horTab.add(c == 0 ? createLabel(horNames[r] + ":") : createButton(horNames[r]));
  2629. }
  2630. // Vertical tab
  2631. MigLayout verLM = new MigLayout("wrap,flowy",
  2632. "[]unrel[]rel[]",
  2633. "[top]15[center]15[bottom]15[fill]15[fill,baseline]15[baseline]15[]");
  2634. String[] verLabels = new String[] {"[top]", "[center]", "[bottom]", "[fill]", "[fill,baseline]", "[baseline]", "[] (Default)"};
  2635. JPanel verTab = createTabPanel(verLM);
  2636. String[] verNames = benchRuns == 0 ? new String[] {"<html>One</html>", "<html>One<br>Two</html>"} : new String[] {"One", "One/Two"};
  2637. for (int c = 0; c < verLabels.length; c++)
  2638. verTab.add(createLabel(verLabels[c]));
  2639. for (int r = 0; r < verNames.length; r++) {
  2640. for (int c = 0; c < verLabels.length; c++)
  2641. verTab.add(createButton(verNames[r]));
  2642. }
  2643. for (int c = 0; c < verLabels.length; c++)
  2644. verTab.add(createTextField("JTextFied"));
  2645. for (int c = 0; c < verLabels.length; c++)
  2646. verTab.add(createTextArea("JTextArea", 1, 8));
  2647. for (int c = 0; c < verLabels.length; c++)
  2648. verTab.add(createTextArea("JTextArea\nwith two lines", 1, 10));
  2649. for (int c = 0; c < verLabels.length; c++)
  2650. verTab.add(createTextAreaScroll("Scrolling JTextArea\nwith two lines", 1, 15, true));
  2651. tabbedPane.addTab("Horizontal", horTab);
  2652. tabbedPane.addTab("Vertical", verTab);
  2653. // Disregard. Just forgetting the source code text close to the source code.
  2654. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2655. "\n" +
  2656. "// Horizontal tab\n" +
  2657. "MigLayout horLM = new MigLayout(\"wrap\",\n" +
  2658. " \"[left]15[center]15[right]15[fill]15[]\",\n" +
  2659. " \"rel[]rel\");\n" +
  2660. "\n" +
  2661. "String[] horLabels = new String[] {\"[left]\", \"[center]\", \"[right]\", \"[fill]\", \"[] (Default)\"};\n" +
  2662. "JPanel horTab = createTabPanel(horLM);\n" +
  2663. "String[] horNames = new String[] {\"First Name\", \"Phone Number\", \"Facsmile\", \"Email\", \"Address\"};\n" +
  2664. "for (int c = 0; c < horLabels.length; c++)\n" +
  2665. "\thorTab.add(createLabel(horLabels[c]));\n" +
  2666. "\n" +
  2667. "for (int r = 0; r < horLabels.length; r++) {\n" +
  2668. "\tfor (int c = 0; c < horNames.length; c++)\n" +
  2669. "\t\thorTab.add(createButton(horNames[r]));\n" +
  2670. "}\n" +
  2671. "\n" +
  2672. "// Vertical tab\n" +
  2673. "MigLayout verLM = new MigLayout(\"wrap,flowy\",\n" +
  2674. " \"[]unrel[]rel[]\",\n" +
  2675. " \"[top]15[center]15[bottom]15[fill]15[fill,baseline]15[baseline]15[]\");\n" +
  2676. "\n" +
  2677. "String[] verLabels = new String[] {\"[top]\", \"[center]\", \"[bottom]\", \"[fill]\", \"[fill,baseline]\", \"[baseline]\", \"[] (Default)\"};\n" +
  2678. "JPanel verTab = createTabPanel(verLM);\n" +
  2679. "\n" +
  2680. "String[] verNames = new String[] {\"<html>One</html>\", \"<html>One<br>Two</html>\"};\n" +
  2681. "for (int c = 0; c < verLabels.length; c++)\n" +
  2682. "\tverTab.add(createLabel(verLabels[c]));\n" +
  2683. "\n" +
  2684. "for (int r = 0; r < verNames.length; r++) {\n" +
  2685. "\tfor (int c = 0; c < verLabels.length; c++)\n" +
  2686. "\t\tverTab.add(createButton(verNames[r]));\n" +
  2687. "}\n" +
  2688. "\n" +
  2689. "for (int c = 0; c < verLabels.length; c++)\n" +
  2690. "\tverTab.add(createTextField(\"JTextFied\"));\n" +
  2691. "\n" +
  2692. "for (int c = 0; c < verLabels.length; c++)\n" +
  2693. "\tverTab.add(createTextArea(\"JTextArea\", 1, 8));\n" +
  2694. "\n" +
  2695. "for (int c = 0; c < verLabels.length; c++)\n" +
  2696. "\tverTab.add(createTextArea(\"JTextArea\\nwith two lines\", 1, 10));\n" +
  2697. "\n" +
  2698. "for (int c = 0; c < verLabels.length; c++)\n" +
  2699. "\tverTab.add(createTextAreaScroll(\"Scrolling JTextArea\\nwith two lines\", 1, 15, true));\n" +
  2700. "\n" +
  2701. "tabbedPane.addTab(\"Horizontal\", horTab);\n" +
  2702. "tabbedPane.addTab(\"Vertical\", verTab);");
  2703. return tabbedPane;
  2704. }
  2705. public JComponent createQuick_Start()
  2706. {
  2707. JTabbedPane tabbedPane = new JTabbedPane();
  2708. JPanel p = createTabPanel(new MigLayout("inset 20"));
  2709. addSeparator(p, "General");
  2710. p.add(createLabel("Company"), "gap para");
  2711. p.add(createTextField(""), "span, growx");
  2712. p.add(createLabel("Contact"), "gap para");
  2713. p.add(createTextField(""), "span, growx, wrap para");
  2714. addSeparator(p, "Propeller");
  2715. p.add(createLabel("PTI/kW"), "gap para");
  2716. p.add(createTextField(10));
  2717. p.add(createLabel("Power/kW"),"gap para");
  2718. p.add(createTextField(10), "wrap");
  2719. p.add(createLabel("R/mm"), "gap para");
  2720. p.add(createTextField(10));
  2721. p.add(createLabel("D/mm"), "gap para");
  2722. p.add(createTextField(10));
  2723. tabbedPane.addTab("Quick Start", p);
  2724. // Disregard. Just forgetting the source code text close to the source code.
  2725. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2726. "\n" +
  2727. "JPanel p = createTabPanel(new MigLayout());\n" +
  2728. "\n" +
  2729. "addSeparator(p, \"General\");\n" +
  2730. "\n" +
  2731. "p.add(createLabel(\"Company\"), \"gap para\");\n" +
  2732. "p.add(createTextField(\"\"), \"span, growx, wrap\");\n" +
  2733. "p.add(createLabel(\"Contact\"), \"gap para\");\n" +
  2734. "p.add(createTextField(\"\"), \"span, growx, wrap para\");\n" +
  2735. "\n" +
  2736. "addSeparator(p, \"Propeller\");\n" +
  2737. "\n" +
  2738. "p.add(createLabel(\"PTI/kW\"), \"gap para\");\n" +
  2739. "p.add(createTextField(10));\n" +
  2740. "p.add(createLabel(\"Power/kW\"),\"gap para\");\n" +
  2741. "p.add(createTextField(10), \"wrap\");\n" +
  2742. "p.add(createLabel(\"R/mm\"), \"gap para\");\n" +
  2743. "p.add(createTextField(10));\n" +
  2744. "p.add(createLabel(\"D/mm\"), \"gap para\");\n" +
  2745. "p.add(createTextField(10));\n" +
  2746. "\n" +
  2747. "tabbedPane.addTab(\"Quick Start\", p);");
  2748. return tabbedPane;
  2749. }
  2750. public JComponent createGrow_Shrink()
  2751. {
  2752. JTabbedPane tabbedPane = new JTabbedPane();
  2753. // shrink tab
  2754. MigLayout slm = new MigLayout("nogrid");
  2755. JPanel sPanel = createTabPanel(slm);
  2756. JScrollPane sDescrText = createTextAreaScroll("Use the slider to see how the components shrink depending on the constraints set on them.\n\n'shp' means Shrink Priority. " +
  2757. "Lower values will be shrunk before higer ones and the default value is 100.\n\n'shrink' means Shrink Weight. " +
  2758. "Lower values relative to other's means they will shrink less when space is scarse. " +
  2759. "Shrink Weight is only relative to components with the same Shrink Priority. Default Shrink Weight is 100.\n\n" +
  2760. "The component's minimum size will always be honored.", 0, 0, true);
  2761. sDescrText.setOpaque(OPAQUE);
  2762. sDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));
  2763. ((JTextArea) sDescrText.getViewport().getView()).setOpaque(OPAQUE);
  2764. sDescrText.getViewport().setOpaque(OPAQUE);
  2765. JSplitPane sSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sPanel, sDescrText);
  2766. sSplitPane.setOpaque(OPAQUE);
  2767. sSplitPane.setBorder(null);
  2768. sPanel.add(createTextField("shp 110", 12), "shp 110");
  2769. sPanel.add(createTextField("Default (100)", 12), "");
  2770. sPanel.add(createTextField("shp 90", 12), "shp 90");
  2771. sPanel.add(createTextField("shrink 25", 20), "newline,shrink 25");
  2772. sPanel.add(createTextField("shrink 75", 20), "shrink 75");
  2773. sPanel.add(createTextField("Default", 20), "newline");
  2774. sPanel.add(createTextField("Default", 20), "");
  2775. sPanel.add(createTextField("shrink 0", 40), "newline,shrink 0");
  2776. sPanel.add(createTextField("shp 110", 12), "newline,shp 110");
  2777. sPanel.add(createTextField("shp 100,shrink 25", 12), "shp 100,shrink 25");
  2778. sPanel.add(createTextField("shp 100,shrink 75", 12), "shp 100,shrink 75");
  2779. tabbedPane.addTab("Shrink", sSplitPane);
  2780. // Grow tab
  2781. MigLayout glm = new MigLayout("nogrid", "[grow]", "");
  2782. JPanel gPanel = createTabPanel(glm);
  2783. JScrollPane gDescrText = createTextAreaScroll("'gp' means Grow Priority. " +
  2784. "Higher values will be grown before lower ones and the default value is 100.\n\n'grow' means Grow Weight. " +
  2785. "Higher values relative to other's means they will grow more when space is up for takes. " +
  2786. "Grow Weight is only relative to components with the same Grow Priority. Default Grow Weight is 0 which means " +
  2787. "components will normally not grow. \n\nNote that the buttons in the first and last row have max width set to 170 to " +
  2788. "emphasize Grow Priority.\n\nThe component's maximum size will always be honored.", 0, 0, true);
  2789. gDescrText.setOpaque(OPAQUE);
  2790. gDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));
  2791. ((JTextArea) gDescrText.getViewport().getView()).setOpaque(OPAQUE);
  2792. gDescrText.getViewport().setOpaque(OPAQUE);
  2793. JSplitPane gSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, gPanel, gDescrText);
  2794. gSplitPane.setOpaque(OPAQUE);
  2795. gSplitPane.setBorder(null);
  2796. gPanel.add(createButton("gp 110,grow"), "gp 110,grow,wmax 170");
  2797. gPanel.add(createButton("Default (100),grow"), "grow,wmax 170");
  2798. gPanel.add(createButton("gp 90,grow"), "gp 90,grow,wmax 170");
  2799. gPanel.add(createButton("Default Button"), "newline");
  2800. gPanel.add(createButton("growx"), "newline,growx,wrap");
  2801. gPanel.add(createButton("gp 110,grow"), "gp 110,grow,wmax 170");
  2802. gPanel.add(createButton("gp 100,grow 25"), "gp 100,grow 25,wmax 170");
  2803. gPanel.add(createButton("gp 100,grow 75"), "gp 100,grow 75,wmax 170");
  2804. tabbedPane.addTab("Grow", gSplitPane);
  2805. // Disregard. Just forgetting the source code text close to the source code.
  2806. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  2807. "\n" +
  2808. "// shrink tab\n" +
  2809. "MigLayout slm = new MigLayout(\"nogrid\");\n" +
  2810. "JPanel sPanel = createTabPanel(slm);\n" +
  2811. "\n" +
  2812. "JScrollPane sDescrText = createTextAreaScroll(\"Use the slider to see how the components shrink depending on the constraints set on them.\\n\\n'shp' means Shrink Priority. \" +\n" +
  2813. " \"Lower values will be shrunk before higer ones and the default value is 100.\\n\\n'shrink' means Shrink Weight. \" +\n" +
  2814. " \"Lower values relative to other's means they will shrink less when space is scarse. \" +\n" +
  2815. " \"Shrink Weight is only relative to components with the same Shrink Priority. Default Shrink Weight is 100.\\n\\n\" +\n" +
  2816. " \"The component's minimum size will always be honored.\", 0, 0, true);\n" +
  2817. "\n" +
  2818. "sDescrText.setOpaque(OPAQUE);\n" +
  2819. "sDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));\n" +
  2820. "((JTextArea) sDescrText.getViewport().getView()).setOpaque(OPAQUE);\n" +
  2821. "sDescrText.getViewport().setOpaque(OPAQUE);\n" +
  2822. "\n" +
  2823. "JSplitPane sSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sPanel, sDescrText);\n" +
  2824. "sSplitPane.setOpaque(OPAQUE);\n" +
  2825. "sSplitPane.setBorder(null);\n" +
  2826. "\n" +
  2827. "sPanel.add(createTextField(\"shp 110\", 12), \"shp 110\");\n" +
  2828. "sPanel.add(createTextField(\"Default (100)\", 12), \"\");\n" +
  2829. "sPanel.add(createTextField(\"shp 90\", 12), \"shp 90\");\n" +
  2830. "\n" +
  2831. "sPanel.add(createTextField(\"shrink 25\", 20), \"newline,shrink 25\");\n" +
  2832. "sPanel.add(createTextField(\"shrink 75\", 20), \"shrink 75\");\n" +
  2833. "\n" +
  2834. "sPanel.add(createTextField(\"Default\", 20), \"newline\");\n" +
  2835. "sPanel.add(createTextField(\"Default\", 20), \"\");\n" +
  2836. "\n" +
  2837. "sPanel.add(createTextField(\"shrink 0\", 40), \"newline,shrink 0\");\n" +
  2838. "\n" +
  2839. "sPanel.add(createTextField(\"shp 110\", 12), \"newline,shp 110\");\n" +
  2840. "sPanel.add(createTextField(\"shp 100,shrink 25\", 12), \"shp 100,shrink 25\");\n" +
  2841. "sPanel.add(createTextField(\"shp 100,shrink 75\", 12), \"shp 100,shrink 75\");\n" +
  2842. "tabbedPane.addTab(\"Shrink\", sSplitPane);\n" +
  2843. "\n" +
  2844. "// Grow tab\n" +
  2845. "MigLayout glm = new MigLayout(\"nogrid\", \"[grow]\", \"\");\n" +
  2846. "JPanel gPanel = createTabPanel(glm);\n" +
  2847. "\n" +
  2848. "JScrollPane gDescrText = createTextAreaScroll(\"'gp' means Grow Priority. \" +\n" +
  2849. " \"Higher values will be grown before lower ones and the default value is 100.\\n\\n'grow' means Grow Weight. \" +\n" +
  2850. " \"Higher values relative to other's means they will grow more when space is up for takes. \" +\n" +
  2851. " \"Grow Weight is only relative to components with the same Grow Priority. Default Grow Weight is 0 which means \" +\n" +
  2852. " \"components will normally not grow. \\n\\nNote that the buttons in the first and last row have max width set to 170 to \" +\n" +
  2853. " \"emphasize Grow Priority.\\n\\nThe component's maximum size will always be honored.\", 0, 0, true);\n" +
  2854. "\n" +
  2855. "gDescrText.setOpaque(OPAQUE);\n" +
  2856. "gDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));\n" +
  2857. "((JTextArea) gDescrText.getViewport().getView()).setOpaque(OPAQUE);\n" +
  2858. "gDescrText.getViewport().setOpaque(OPAQUE);\n" +
  2859. "\n" +
  2860. "JSplitPane gSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, gPanel, gDescrText);\n" +
  2861. "gSplitPane.setOpaque(OPAQUE);\n" +
  2862. "gSplitPane.setBorder(null);\n" +
  2863. "\n" +
  2864. "gPanel.add(createButton(\"gp 110,grow\"), \"gp 110,grow,wmax 170\");\n" +
  2865. "gPanel.add(createButton(\"Default (100),grow\"), \"grow,wmax 170\");\n" +
  2866. "gPanel.add(createButton(\"gp 90,grow\"), \"gp 90,grow,wmax 170\");\n" +
  2867. "\n" +
  2868. "gPanel.add(createButton(\"Default Button\"), \"newline\");\n" +
  2869. "\n" +
  2870. "gPanel.add(createButton(\"growx\"), \"newline,growx,wrap\");\n" +
  2871. "\n" +
  2872. "gPanel.add(createButton(\"gp 110,grow\"), \"gp 110,grow,wmax 170\");\n" +
  2873. "gPanel.add(createButton(\"gp 100,grow 25\"), \"gp 100,grow 25,wmax 170\");\n" +
  2874. "gPanel.add(createButton(\"gp 100,grow 75\"), \"gp 100,grow 75,wmax 170\");\n" +
  2875. "tabbedPane.addTab(\"Grow\", gSplitPane);");
  2876. return tabbedPane;
  2877. }
  2878. public JComponent createPlainApi()
  2879. {
  2880. JTabbedPane tabbedPane = new JTabbedPane();
  2881. MigLayout lm = new MigLayout(new LC(), null, null);
  2882. JPanel panel = createTabPanel(lm);
  2883. addSeparator(panel, "Manufacturer");
  2884. panel.add(createLabel("Company"));
  2885. panel.add(createTextField(""), "span,growx");
  2886. panel.add(createLabel("Contact"));
  2887. panel.add(createTextField(""), "span,growx");
  2888. panel.add(createLabel("Order No"));
  2889. panel.add(createTextField(15), "wrap");
  2890. addSeparator(panel, "Inspector");
  2891. panel.add(createLabel("Name"));
  2892. panel.add(createTextField(""), "span,growx");
  2893. panel.add(createLabel("Reference No"));
  2894. panel.add(createTextField(""), "wrap");
  2895. panel.add(createLabel("Status"));
  2896. panel.add(createCombo(new String[] {"In Progress", "Finnished", "Released"}), "wrap");
  2897. addSeparator(panel, "Ship");
  2898. panel.add(createLabel("Shipyard"));
  2899. panel.add(createTextField(""), "span,growx");
  2900. panel.add(createLabel("Register No"));
  2901. panel.add(createTextField(""));
  2902. panel.add(createLabel("Hull No"), "right");
  2903. panel.add(createTextField(15), "wrap");
  2904. panel.add(createLabel("Project Type"));
  2905. panel.add(createCombo(new String[] {"New Building", "Convention", "Repair"}));
  2906. tabbedPane.addTab("Plain", panel);
  2907. return tabbedPane;
  2908. }
  2909. // **********************************************************
  2910. // * Helper Methods
  2911. // **********************************************************
  2912. private final ToolTipListener toolTipListener = new ToolTipListener();
  2913. private final ConstraintListener constraintListener = new ConstraintListener();
  2914. private JLabel createLabel(String text)
  2915. {
  2916. return createLabel(text, SwingConstants.LEADING);
  2917. }
  2918. private JLabel createLabel(String text, int align)
  2919. {
  2920. final JLabel b = new JLabel(text, align);
  2921. configureActiveComponet(b);
  2922. return b;
  2923. }
  2924. public JComboBox createCombo(String[] items)
  2925. {
  2926. JComboBox combo = new JComboBox(items);
  2927. if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.MAC_OSX)
  2928. combo.setOpaque(false);
  2929. return combo;
  2930. }
  2931. private JTextField createTextField(int cols)
  2932. {
  2933. return createTextField("", cols);
  2934. }
  2935. private JTextField createTextField(String text)
  2936. {
  2937. return createTextField(text, 0);
  2938. }
  2939. private JTextField createTextField(String text, int cols)
  2940. {
  2941. final JTextField b = new JTextField(text, cols);
  2942. configureActiveComponet(b);
  2943. return b;
  2944. }
  2945. private static final Font BUTT_FONT = new Font("monospaced", Font.PLAIN, 12);
  2946. private JButton createButton()
  2947. {
  2948. return createButton("");
  2949. }
  2950. private JButton createButton(String text)
  2951. {
  2952. return createButton(text, false);
  2953. }
  2954. private JButton createButton(String text, boolean bold)
  2955. {
  2956. JButton b = new JButton(text) {
  2957. public void addNotify()
  2958. {
  2959. super.addNotify();
  2960. if (benchRuns == 0) { // Since this does not exist in the SWT version
  2961. if (getText().length() == 0) {
  2962. String lText = (String) ((MigLayout) getParent().getLayout()).getComponentConstraints(this);
  2963. setText(lText != null && lText.length() > 0 ? lText : "<Empty>");
  2964. }
  2965. } else {
  2966. setText("Benchmark Version");
  2967. }
  2968. }
  2969. };
  2970. if (bold)
  2971. b.setFont(b.getFont().deriveFont(Font.BOLD));
  2972. configureActiveComponet(b);
  2973. b.setOpaque(buttonOpaque); // Or window's buttons will have strange border
  2974. if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.MAC_OSX)
  2975. b.setContentAreaFilled(false);
  2976. return b;
  2977. }
  2978. private JToggleButton createToggleButton(String text)
  2979. {
  2980. JToggleButton b = new JToggleButton(text);
  2981. // configureActiveComponet(b);
  2982. b.setOpaque(buttonOpaque); // Or window's buttons will have strange border
  2983. return b;
  2984. }
  2985. private JCheckBox createCheck(String text)
  2986. {
  2987. JCheckBox b = new JCheckBox(text);
  2988. configureActiveComponet(b);
  2989. b.setOpaque(OPAQUE); // Or window's checkboxes will have strange border
  2990. return b;
  2991. }
  2992. private JPanel createTabPanel(LayoutManager lm)
  2993. {
  2994. JPanel panel = new JPanel(lm);
  2995. configureActiveComponet(panel);
  2996. panel.setOpaque(OPAQUE);
  2997. return panel;
  2998. }
  2999. private JComponent createPanel()
  3000. {
  3001. return createPanel("");
  3002. }
  3003. private JComponent createPanel(String s)
  3004. {
  3005. JLabel panel = new JLabel(s, SwingConstants.CENTER) {
  3006. public void addNotify()
  3007. {
  3008. super.addNotify();
  3009. if (benchRuns == 0) { // Since this does not exist in the SWT version
  3010. if (getText().length() == 0) {
  3011. String lText = (String) ((MigLayout) getParent().getLayout()).getComponentConstraints(this);
  3012. setText(lText != null && lText.length() > 0 ? lText : "<Empty>");
  3013. }
  3014. }
  3015. }
  3016. };
  3017. panel.setBorder(new EtchedBorder());
  3018. panel.setOpaque(true);
  3019. configureActiveComponet(panel);
  3020. return panel;
  3021. }
  3022. private JTextArea createTextArea(String text, int rows, int cols)
  3023. {
  3024. JTextArea ta = new JTextArea(text, rows, cols);
  3025. ta.setBorder(UIManager.getBorder("TextField.border"));
  3026. ta.setFont(UIManager.getFont("TextField.font"));
  3027. ta.setWrapStyleWord(true);
  3028. ta.setLineWrap(true);
  3029. configureActiveComponet(ta);
  3030. return ta;
  3031. }
  3032. private JScrollPane createTextAreaScroll(String text, int rows, int cols, boolean hasVerScroll)
  3033. {
  3034. JTextArea ta = new JTextArea(text, rows, cols);
  3035. ta.setFont(UIManager.getFont("TextField.font"));
  3036. ta.setWrapStyleWord(true);
  3037. ta.setLineWrap(true);
  3038. JScrollPane scroll = new JScrollPane(
  3039. ta,
  3040. hasVerScroll ? ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED : ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
  3041. ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  3042. return scroll;
  3043. }
  3044. private JComponent configureActiveComponet(JComponent c)
  3045. {
  3046. if (benchRuns == 0) {
  3047. c.addMouseMotionListener(toolTipListener);
  3048. c.addMouseListener(constraintListener);
  3049. }
  3050. return c;
  3051. }
  3052. static final Color LABEL_COLOR = new Color(0, 70, 213);
  3053. private void addSeparator(JPanel panel, String text)
  3054. {
  3055. JLabel l = createLabel(text);
  3056. l.setForeground(LABEL_COLOR);
  3057. panel.add(l, "gapbottom 1, span, split 2");
  3058. panel.add(configureActiveComponet(new JSeparator()), "gapleft rel, growx");
  3059. }
  3060. private class ConstraintListener extends MouseAdapter
  3061. {
  3062. public void mousePressed(MouseEvent e)
  3063. {
  3064. if (e.isPopupTrigger())
  3065. react(e);
  3066. }
  3067. public void mouseReleased(MouseEvent e)
  3068. {
  3069. if (e.isPopupTrigger())
  3070. react(e);
  3071. }
  3072. public void react(MouseEvent e)
  3073. {
  3074. JComponent c = (JComponent) e.getSource();
  3075. LayoutManager lm = c.getParent().getLayout();
  3076. if (lm instanceof MigLayout == false)
  3077. lm = c.getLayout();
  3078. if (lm instanceof MigLayout) {
  3079. MigLayout layout = (MigLayout) lm;
  3080. boolean isComp = layout.isManagingComponent(c);
  3081. Object compConstr = isComp ? layout.getComponentConstraints(c) : null;
  3082. if (isComp && compConstr == null)
  3083. compConstr = "";
  3084. Object rowsConstr = isComp ? null : layout.getRowConstraints();
  3085. Object colsConstr = isComp ? null : layout.getColumnConstraints();
  3086. Object layoutConstr = isComp ? null : layout.getLayoutConstraints();
  3087. ConstraintsDialog cDlg = new ConstraintsDialog(SwingDemo.this,
  3088. layoutConstr instanceof LC ? IDEUtil.getConstraintString((LC) layoutConstr, false) : (String) layoutConstr,
  3089. rowsConstr instanceof AC ? IDEUtil.getConstraintString((AC) rowsConstr, false, false) : (String) rowsConstr,
  3090. colsConstr instanceof AC ? IDEUtil.getConstraintString((AC) colsConstr, false, false) : (String) colsConstr,
  3091. compConstr instanceof CC ? IDEUtil.getConstraintString((CC) colsConstr, false) : (String) compConstr);
  3092. cDlg.pack();
  3093. cDlg.setLocationRelativeTo(c);
  3094. if (cDlg.showDialog()) {
  3095. try {
  3096. if (isComp) {
  3097. String constrStr = cDlg.componentConstrTF.getText().trim();
  3098. layout.setComponentConstraints(c, constrStr);
  3099. if (c instanceof JButton) {
  3100. c.setFont(BUTT_FONT);
  3101. ((JButton) c).setText(constrStr.length() == 0 ? "<Empty>" : constrStr);
  3102. }
  3103. } else {
  3104. layout.setLayoutConstraints(cDlg.layoutConstrTF.getText());
  3105. layout.setRowConstraints(cDlg.rowsConstrTF.getText());
  3106. layout.setColumnConstraints(cDlg.colsConstrTF.getText());
  3107. }
  3108. } catch(Exception ex) {
  3109. StringWriter sw = new StringWriter();
  3110. ex.printStackTrace(new PrintWriter(sw));
  3111. JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(c), sw.toString(), "Error parsing Constraint!", JOptionPane.ERROR_MESSAGE);
  3112. return;
  3113. }
  3114. c.invalidate();
  3115. c.getParent().validate();
  3116. }
  3117. }
  3118. }
  3119. }
  3120. private static class ToolTipListener extends MouseMotionAdapter
  3121. {
  3122. public void mouseMoved(MouseEvent e)
  3123. {
  3124. JComponent c = (JComponent) e.getSource();
  3125. LayoutManager lm = c.getParent().getLayout();
  3126. if (lm instanceof MigLayout) {
  3127. String constr = (String) ((MigLayout) lm).getComponentConstraints(c);
  3128. c.setToolTipText((constr != null ? ("\"" + constr + "\"") : "null"));
  3129. }
  3130. }
  3131. }
  3132. private static class ConstraintsDialog extends JDialog implements ActionListener, KeyEventDispatcher
  3133. {
  3134. private static final Color ERROR_COLOR = new Color(255, 180, 180);
  3135. private final JPanel mainPanel = new JPanel(new MigLayout("fillx,flowy,ins dialog",
  3136. "[fill]",
  3137. "2[]2"));
  3138. final JTextField layoutConstrTF;
  3139. final JTextField rowsConstrTF;
  3140. final JTextField colsConstrTF;
  3141. final JTextField componentConstrTF;
  3142. private final JButton okButt = new JButton("OK");
  3143. private final JButton cancelButt = new JButton("Cancel");
  3144. private boolean okPressed = false;
  3145. public ConstraintsDialog(Frame owner, String layoutConstr, String rowsConstr, String colsConstr, String compConstr)
  3146. {
  3147. super(owner, (compConstr != null ? "Edit Component Constraints" : "Edit Container Constraints"), true);
  3148. layoutConstrTF = createConstraintField(layoutConstr);
  3149. rowsConstrTF = createConstraintField(rowsConstr);
  3150. colsConstrTF = createConstraintField(colsConstr);
  3151. componentConstrTF = createConstraintField(compConstr);
  3152. if (componentConstrTF != null) {
  3153. mainPanel.add(new JLabel("Component Constraints"));
  3154. mainPanel.add(componentConstrTF);
  3155. }
  3156. if (layoutConstrTF != null) {
  3157. mainPanel.add(new JLabel("Layout Constraints"));
  3158. mainPanel.add(layoutConstrTF);
  3159. }
  3160. if (colsConstrTF != null) {
  3161. mainPanel.add(new JLabel("Column Constraints"), "gaptop unrel");
  3162. mainPanel.add(colsConstrTF);
  3163. }
  3164. if (rowsConstrTF != null) {
  3165. mainPanel.add(new JLabel("Row Constraints"), "gaptop unrel");
  3166. mainPanel.add(rowsConstrTF);
  3167. }
  3168. mainPanel.add(okButt, "tag ok,split,flowx,gaptop 15");
  3169. mainPanel.add(cancelButt, "tag cancel,gaptop 15");
  3170. setContentPane(mainPanel);
  3171. okButt.addActionListener(this);
  3172. cancelButt.addActionListener(this);
  3173. }
  3174. public void addNotify()
  3175. {
  3176. super.addNotify();
  3177. KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
  3178. }
  3179. public void removeNotify()
  3180. {
  3181. KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
  3182. super.removeNotify();
  3183. }
  3184. public boolean dispatchKeyEvent(KeyEvent e)
  3185. {
  3186. if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
  3187. dispose();
  3188. return false;
  3189. }
  3190. public void actionPerformed(ActionEvent e)
  3191. {
  3192. if (e.getSource() == okButt)
  3193. okPressed = true;
  3194. dispose();
  3195. }
  3196. private JTextField createConstraintField(String text)
  3197. {
  3198. if (text == null)
  3199. return null;
  3200. final JTextField tf = new JTextField(text, 50);
  3201. tf.setFont(new Font("monospaced", Font.PLAIN, 12));
  3202. tf.addKeyListener(new KeyAdapter() {
  3203. public void keyPressed(KeyEvent e)
  3204. {
  3205. if (e.getKeyCode() == KeyEvent.VK_ENTER) {
  3206. okButt.doClick();
  3207. return;
  3208. }
  3209. javax.swing.Timer timer = new Timer(50, new ActionListener() {
  3210. public void actionPerformed(ActionEvent e)
  3211. {
  3212. String constr = tf.getText();
  3213. try {
  3214. if (tf == layoutConstrTF) {
  3215. ConstraintParser.parseLayoutConstraint(constr);
  3216. } else if (tf == rowsConstrTF) {
  3217. ConstraintParser.parseRowConstraints(constr);
  3218. } else if (tf == colsConstrTF) {
  3219. ConstraintParser.parseColumnConstraints(constr);
  3220. } else if (tf == componentConstrTF) {
  3221. ConstraintParser.parseComponentConstraint(constr);
  3222. }
  3223. tf.setBackground(Color.WHITE);
  3224. okButt.setEnabled(true);
  3225. } catch(Exception ex) {
  3226. tf.setBackground(ERROR_COLOR);
  3227. okButt.setEnabled(false);
  3228. }
  3229. }
  3230. });
  3231. timer.setRepeats(false);
  3232. timer.start();
  3233. }
  3234. });
  3235. return tf;
  3236. }
  3237. private boolean showDialog()
  3238. {
  3239. setVisible(true);
  3240. return okPressed;
  3241. }
  3242. }
  3243. }