Changeset 101 for java/main/src/main/java/com/framsticks/gui/Gui.java
- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/gui/Gui.java
r100 r101 7 7 import javax.swing.Box; 8 8 import javax.swing.BoxLayout; 9 import javax.swing.JComponent; 9 10 import javax.swing.JLabel; 10 11 import javax.swing.JPanel; 12 import javax.swing.border.TitledBorder; 11 13 12 14 import org.apache.logging.log4j.Logger; … … 24 26 import com.framsticks.params.CompositeParam; 25 27 import com.framsticks.params.Param; 28 import com.framsticks.params.ParamFlags; 26 29 import com.framsticks.params.PrimitiveParam; 27 30 import com.framsticks.params.types.BinaryParam; … … 101 104 } 102 105 103 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, Collection<P> params, Map<P, C> components, Class<C> controlType) {104 JPanel panel = owner.getPanelForControls();106 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, JPanel panel, Collection<P> params, Map<String, C> components, Class<C> controlType) { 107 panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); 105 108 for (P param : params) { 106 if (param. isUserHidden()) {109 if (param.hasFlag(ParamFlags.USERHIDDEN)) { 107 110 continue; 108 111 } … … 122 125 line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS)); 123 126 line.setAlignmentX(JPanel.LEFT_ALIGNMENT); 124 JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : (Strings.notEmpty(param.getId()) ? param.getId() : "?")); 125 label.setToolTipText(control.getToolTipText()); 126 label.setHorizontalAlignment(JLabel.RIGHT); 127 Dimension labelSize = new Dimension(150, 30); 128 label.setMaximumSize(labelSize); 129 label.setMinimumSize(labelSize); 130 label.setPreferredSize(labelSize); 131 line.add(label); 132 line.add(Box.createRigidArea(new Dimension(8, 0))); 127 133 128 line.add(control); 134 129 line.revalidate(); 135 130 panel.add(line); 136 131 panel.add(Box.createRigidArea(new Dimension(0, 8))); 132 components.put(param.getId(), control); 137 133 //component.setAlignmentX(LEFT_ALIGNMENT); 138 components.put(param, control);134 // components.put(param.getId(), control); 139 135 } 140 136 141 137 } 138 139 public static String getBestName(Param param) { 140 if (Strings.notEmpty(param.getName())) { 141 return param.getName(); 142 } 143 if (Strings.notEmpty(param.getId())) { 144 return param.getId(); 145 } 146 return "?"; 147 } 148 149 public static void setupTitledControl(Control control, JComponent... components) { 150 151 control.setLayout(new BoxLayout(control, BoxLayout.PAGE_AXIS)); 152 control.setBorder(new TitledBorder(Gui.getBestName(control.getParam()))); 153 for (JComponent c : components) { 154 // control.add(Box.createRigidArea(new Dimension(0, 4))); 155 control.add(c); 156 } 157 } 158 159 public static void layoutInRow(JPanel panel, JComponent first, JComponent... components) { 160 panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); 161 panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); 162 163 panel.add(first); 164 for (JComponent c : components) { 165 panel.add(Box.createRigidArea(new Dimension(8, 0))); 166 panel.add(c); 167 } 168 } 169 170 public static void addLeftToLabel(Control control, JComponent... components) { 171 172 JLabel label = new JLabel(getBestName(control.getParam())); 173 label.setToolTipText(control.getToolTipText()); 174 label.setHorizontalAlignment(JLabel.LEFT); 175 Dimension labelSize = new Dimension(150, 30); 176 label.setMaximumSize(labelSize); 177 label.setMinimumSize(labelSize); 178 label.setPreferredSize(labelSize); 179 180 layoutInRow(control, label, components); 181 182 } 142 183 }
Note: See TracChangeset
for help on using the changeset viewer.