1 30 31 package com.jgoodies.looks.demo; 32 33 import java.awt.BorderLayout ; 34 import java.awt.Dimension ; 35 import java.awt.GridLayout ; 36 37 import javax.swing.*; 38 import javax.swing.border.Border ; 39 import javax.swing.border.EmptyBorder ; 40 41 import com.jgoodies.forms.factories.Borders; 42 import com.jgoodies.looks.LookUtils; 43 import com.jgoodies.looks.plastic.PlasticInternalFrameUI; 44 45 51 final class DesktopTab { 52 53 private static final float SIZE_FACTOR = LookUtils.IS_LOW_RESOLUTION ? 1f : 1.175f; 54 55 58 JComponent build() { 59 JPanel panel = new JPanel(new BorderLayout ()); 60 panel.setBorder(Borders.DIALOG_BORDER); 61 panel.add(new JScrollPane(buildDesktopPane())); 62 return panel; 63 } 64 65 private JComponent buildDesktopPane() { 66 int gap = (int) (10 * SIZE_FACTOR); 67 int originX1 = 10; 68 int extentX1 = (int) (193 * SIZE_FACTOR); 69 int originX2 = originX1 + extentX1 + gap; 70 int extentX2 = extentX1; 71 int originX3 = originX2 + extentX2 + gap; 72 int extentX3 = (int) (150 * SIZE_FACTOR); 73 74 JDesktopPane desktop = new JDesktopPane(); 75 JInternalFrame frame; 76 77 frame = new JInternalFrame("Navigation", true, true, true, true); 78 frame.setContentPane(buildFrame1ContentPane()); 79 frame.setBounds(originX1, 10, extentX1, 320); 80 desktop.add(frame); 81 frame.setVisible(true); 82 83 frame = new JInternalFrame("Properties", true, false, true, true); 84 frame.setContentPane(buildFrame2ContentPane()); 85 frame.setBounds(originX2, 10, extentX2, 320); 86 desktop.add(frame); 87 frame.setVisible(true); 88 89 JInternalFrame palette = 90 new JInternalFrame("Palette1", true, true, true, true); 91 palette.putClientProperty( 92 PlasticInternalFrameUI.IS_PALETTE, 93 Boolean.TRUE); 94 palette.setContentPane(buildPaletteContentPane()); 95 palette.setBounds(originX3, 10, extentX3, 150); 96 palette.setVisible(true); 97 desktop.add(palette, JLayeredPane.PALETTE_LAYER); 98 99 palette = new JInternalFrame("Palette2", true, true, true, true); 100 palette.putClientProperty( 101 PlasticInternalFrameUI.IS_PALETTE, 102 Boolean.TRUE); 103 palette.setContentPane(buildBackgroundTestContentPane()); 104 palette.setBounds(originX3, 170, extentX3, 160); 105 palette.setVisible(true); 106 desktop.add(palette, JLayeredPane.PALETTE_LAYER); 107 108 return desktop; 109 } 110 111 private JComponent buildFrame1ContentPane() { 112 JScrollPane scrollPane = new JScrollPane(new JTree()); 113 scrollPane.setPreferredSize(new Dimension (100, 140)); 114 return scrollPane; 115 } 116 117 private JComponent buildFrame2ContentPane() { 118 JScrollPane scrollPane = new JScrollPane(buildTable()); 119 scrollPane.setPreferredSize(new Dimension (100, 140)); 120 return scrollPane; 121 } 122 123 private JComponent buildPaletteContentPane() { 124 Border CARD_DIALOG_BORDER = new EmptyBorder (10, 6, 7, 6); 125 Box box = Box.createVerticalBox(); 126 box.add(new JCheckBox("be consistent", true)); 127 box.add(Box.createVerticalStrut(6)); 128 box.add(new JCheckBox("use less ink", true)); 129 130 JPanel generalTab = new JPanel(new BorderLayout ()); 131 generalTab.add(box); 132 generalTab.setBorder(CARD_DIALOG_BORDER); 133 134 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM); 135 tabbedPane.add(generalTab, "General"); 136 tabbedPane.add(new JLabel("Test1"), "Filter"); 137 return tabbedPane; 138 } 139 140 private JComponent buildBackgroundTestContentPane() { 141 JTextArea area1 = 142 new JTextArea("Background should be\nthe same as below."); 143 area1.setBackground(UIManager.getColor("control")); 144 JTextArea area2 = 145 new JTextArea("Background should be\nthe same as above."); 146 area2.setOpaque(false); 147 JPanel grid = new JPanel(new GridLayout (2, 1)); 148 grid.add(area1); 149 grid.add(area2); 150 grid.setOpaque(false); 151 return grid; 152 } 153 154 157 private JTable buildTable() { 158 JTable table = new JTable( 159 createSampleTableData(), 160 new String [] { "Key", "Value" }); 161 162 table.getColumnModel().getColumn(0).setPreferredWidth(95); 164 table.getColumnModel().getColumn(1).setPreferredWidth(95); 165 table.setRowSelectionInterval(2, 2); 166 return table; 167 } 168 169 172 private String [][] createSampleTableData() { 173 return new String [][] { 174 { "Name", "Karsten" }, 175 { "Sex", "Male" }, 176 { "Date of Birth", "5-Dec-1967" }, 177 { "Place of Birth", "Kiel" }, 178 { "Profession", "UI Designer"}, 179 { "Business", "Freelancer" }, 180 { "", "" }, 181 { "", "" }, 182 { "", "" }, 183 { "", "" }, 184 { "", "" }, 185 { "", "" }, 186 { "", "" }, 187 { "", "" }, 188 { "", "" }, 189 { "", "" }, 190 { "", "" }, 191 { "", "" }, 192 { "", "" }, 193 }; 194 } 195 196 } | Popular Tags |