1 26 27 package org.objectweb.openccm.explorer.CosTrading.gui; 28 29 30 import javax.swing.JComboBox ; 31 import javax.swing.JLabel ; 32 import javax.swing.Box ; 33 import javax.swing.BoxLayout ; 34 import javax.swing.SwingConstants ; 35 36 import java.awt.Component ; 37 import java.awt.Dimension ; 38 39 40 import org.omg.CosTrading.FollowOption; 41 42 50 public class FollowOptionBox extends Box { 51 52 58 59 protected JComboBox options_; 60 61 62 protected JLabel fieldLabel_; 63 64 70 75 public FollowOptionBox(String label) { 76 super(BoxLayout.X_AXIS); 77 add(Box.createHorizontalGlue()); 78 fieldLabel_ = new JLabel (label, SwingConstants.RIGHT); 79 fieldLabel_.setAlignmentX(Component.RIGHT_ALIGNMENT); 80 fieldLabel_.setAlignmentY(Component.CENTER_ALIGNMENT); 81 add(fieldLabel_); 82 add(Box.createHorizontalStrut(5)); 83 options_ = new JComboBox (new String [] {"local_only", "if_no_local", "always"}); 84 options_.setPreferredSize(new Dimension (225, 20)); 85 options_.setMaximumSize(new Dimension (225, 20)); 86 add(options_); 87 } 88 89 95 public FollowOptionBox(String label, FollowOption init) { 96 this(label); 97 options_.setSelectedIndex(optionToIndex(init)); 98 } 99 100 106 113 protected int optionToIndex(FollowOption o) { 114 if (o.value() == FollowOption._local_only) return 0; 115 if (o.value() == FollowOption._if_no_local) return 1; 116 return 2; 117 } 118 119 125 130 public FollowOption getOption() { 131 String option = (String )options_.getSelectedItem(); 132 if (option.equals("local_only")) return FollowOption.local_only; 133 if (option.equals("if_no_local")) return FollowOption.if_no_local; 134 return FollowOption.always; 135 } 136 137 142 public void addItemListener(java.awt.event.ItemListener listener) { 143 options_.addItemListener(listener); 144 } 145 146 152 157 public void setToolTipText(String text) { 158 options_.setToolTipText(text); 159 fieldLabel_.setToolTipText(text); 160 } 161 162 167 public String getToolTipText() { 168 return options_.getToolTipText(); 169 } 170 } 171 | Popular Tags |