Update of /cvsroot/bprocessor//gl/src/net/sourceforge/bprocessor/gl
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28162/src/net/sourceforge/bprocessor/gl
Modified Files:
GLView.java
Log Message:
Made some minor changes and fixes to the factor chooser
Index: GLView.java
===================================================================
RCS file: /cvsroot/bprocessor//gl/src/net/sourceforge/bprocessor/gl/GLView.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** GLView.java 12 Jan 2007 17:52:27 -0000 1.47
--- GLView.java 14 Jan 2007 23:33:28 -0000 1.48
***************
*** 19,22 ****
--- 19,23 ----
import java.awt.Dimension;
import java.awt.BorderLayout;
+ import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
***************
*** 58,61 ****
--- 59,65 ----
private LengthField lengthField;
+ /** The label and combobox for the reality factor */
+ private FactorBox factor;
+
/**
* Constuctor
***************
*** 84,95 ****
lengthField = new LengthField();
lengthPanel.add(lengthField, BorderLayout.CENTER);
! String init = "-";
! String s1 = "1:1";
! String s2 = "1:10";
! String s3 = "1:100";
! String s4 = "1:250";
! String s5 = "1:500";
! String s6 = "1:1000";
! lengthPanel.add(new JComboBox(new Object[]{init, s1, s2, s3, s4, s5, s6}), BorderLayout.EAST);
jp.add(lengthPanel, BorderLayout.SOUTH);
GUI.getInstance().incrementPB();
--- 88,95 ----
lengthField = new LengthField();
lengthPanel.add(lengthField, BorderLayout.CENTER);
! factor = new FactorBox();
! disableFactor();
! lengthPanel.add(factor, BorderLayout.EAST);
!
jp.add(lengthPanel, BorderLayout.SOUTH);
GUI.getInstance().incrementPB();
***************
*** 263,266 ****
--- 263,288 ----
/**
+ * The factor
+ * @param i The size of the factor
+ */
+ public void setFactor(int i) {
+ factor.setFactor(i);
+ }
+
+ /**
+ * Disable the factor field
+ */
+ public void disableFactor() {
+ factor.disable();
+ }
+
+ /**
+ * Enable the factor field
+ */
+ public void enableFactor() {
+ factor.enable();
+ }
+
+ /**
* Displays the popup menu at the given coordinates
* @param pp the popup menu
***************
*** 275,278 ****
--- 297,388 ----
/**
+ * Panel for the label and JComboBox representing the size factor
+ */
+ class FactorBox extends JPanel implements ActionListener {
+ private JComboBox choices;
+ private JLabel label;
+ private String[] items;
+
+ /**
+ * The Constructor construct both the label and combobox
+ */
+ public FactorBox() {
+ super();
+ label = new JLabel("Factor:");
+ this.add(label);
+ items = new String[]{"1:1", "1:50", "1:100", "1:500", "1:1000"};
+ choices = new JComboBox(items);
+ choices.setEditable(true);
+ choices.addActionListener(this);
+ this.add(choices);
+ }
+
+ /**
+ * Set the factor
+ * @param i the value for the factor
+ */
+ public void setFactor(int i) {
+ String item = "1:" + i;
+ //Uncomment if the element should be inserted into menu
+ /*int where = contains(item);
+ if (where != -1) {
+ choices.insertItemAt(item, where);
+ }*/
+ choices.setSelectedItem(item);
+ }
+
+ /**
+ * Check if the item is allready there or it should be addded
+ * @param item The item to check for
+ * @return The position to add the element if it's not there otherwise -1
+ */
+ private int contains(String item) {
+ int val = choices.getItemCount();
+ int itemval = Integer.parseInt(item.substring(2));
+ for (int i = 0; i < choices.getItemCount(); i++) {
+ int cur = Integer.parseInt(((String)choices.getItemAt(i)).substring(2));
+ if (itemval == cur) {
+ return -1;
+ } else if (itemval > cur) {
+ val = i + 1;
+ } else {
+ return val;
+ }
+ }
+ return val;
+ }
+
+ /**
+ * Enable the box
+ */
+ public void disable() {
+ label.setEnabled(false);
+ choices.setEnabled(false);
+ }
+
+ /**
+ * Disable the box
+ */
+ public void enable() {
+ label.setEnabled(true);
+ choices.setEnabled(true);
+ }
+
+ /**
+ * Handle the event of the combobox
+ * @param The ActionEvent for the action
+ */
+ public void actionPerformed(ActionEvent event) {
+ String what = (String)choices.getSelectedItem();
+ if (what.matches("1:[\\d]+")) {
+ choices.setSelectedItem(what);
+ int fac = Integer.parseInt(what.substring(2));
+ Project.getInstance().getCurrentCamera().setFactor(fac);
+ Project.getInstance().changed(Project.getInstance().getCurrentCamera());
+ }
+ }
+ }
+
+ /**
* The length field class
*/
|