[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview AttributeView.java,1.20,1.21 MyM
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-01-13 11:03:44
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26468/src/net/sourceforge/bprocessor/gui/attrview Modified Files: AttributeView.java MyMouseListener.java Log Message: Some refactoring Index: AttributeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/AttributeView.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** AttributeView.java 13 Jan 2006 10:24:59 -0000 1.20 --- AttributeView.java 13 Jan 2006 11:03:35 -0000 1.21 *************** *** 15,22 **** import java.awt.Color; import java.awt.Dimension; - import java.awt.GridLayout; - import java.lang.reflect.Method; - import java.util.ArrayList; - import java.util.List; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; --- 15,18 ---- *************** *** 28,32 **** import javax.swing.JTextArea; import javax.swing.JTextField; - import javax.swing.JComboBox; import javax.swing.border.Border; --- 24,27 ---- *************** *** 64,81 **** if (object == selection) { if (selection.size() == 1) { ! Object target = selection.iterator().next(); ! if (target instanceof Space) { ! Space space = (Space) target; ! if (space.isConstructionSpace()) { ! ap.displayConsSpace(space); ! } ! if (space.isFunctionalSpace()) { ! ap.displayFuncSpace(space); ! } ! } else if (target instanceof Surface) { ! ap.displaySurface((Surface) target); ! } else { ! ap.display(null); ! } } else { ap.display(null); --- 59,63 ---- if (object == selection) { if (selection.size() == 1) { ! ap.display(selection.iterator().next()); } else { ap.display(null); *************** *** 105,148 **** current = null; } - - /** - * Display the functional space - * @param o The object - */ - void displayFuncSpace(Space o) { - removeAll(); - - GridBagLayout layout = new GridBagLayout(); - GridBagConstraints con = new GridBagConstraints(); - setLayout(layout); - - JLabel name = new JLabel("Name:"); - con.anchor = GridBagConstraints.NORTHEAST; - layout.setConstraints(name, con); - add(name); - - JTextField nameEdit = new JTextField(o.getName()); - con.gridwidth = GridBagConstraints.REMAINDER; - con.weightx = 1.0; - con.fill = GridBagConstraints.HORIZONTAL; - layout.setConstraints(nameEdit, con); - add(nameEdit); - nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); - - Object[] options = {"Arbejdsværelse", "Badeværelse", "Gang", "Køkken", "Stue", "Værelse"}; - JComboBox klassifikation = new JComboBox(options); - layout.setConstraints(klassifikation, con); - add(klassifikation); - - JTextArea funcSpaceDescripton = new JTextArea(o.getDescription()); - funcSpaceDescripton.setWrapStyleWord(true); - funcSpaceDescripton.setLineWrap(true); - con.weighty = 1.0; - con.fill = GridBagConstraints.BOTH; - layout.setConstraints(funcSpaceDescripton, con); - funcSpaceDescripton.addFocusListener(new MyFocusListener(o)); - add(funcSpaceDescripton); - revalidate(); - } /** --- 87,90 ---- *************** *** 150,156 **** * @param o The object */ ! void displayConsSpace(Space o) { ! removeAll(); ! GridBagLayout layout = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); --- 92,96 ---- * @param o The object */ ! void displaySpace(Space o) { GridBagLayout layout = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); *************** *** 161,167 **** con.weightx = 0; layout.setConstraints(name, con); ! add(name); ! ! JTextField nameEdit = new JTextField(o.getName()); --- 101,105 ---- con.weightx = 0; layout.setConstraints(name, con); ! add(name); JTextField nameEdit = new JTextField(o.getName()); *************** *** 173,192 **** nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); ! Object[] options = {"Arbejdsværelse", "Badeværelse", "Gang", "Køkken", "Stue", "Værelse"}; ! JComboBox klassifikation = new JComboBox(options); ! layout.setConstraints(klassifikation, con); ! add(klassifikation); ! ! JTextArea consSpaceDescripton = new JTextArea(o.getDescription()); ! consSpaceDescripton.setLineWrap(true); ! consSpaceDescripton.setWrapStyleWord(true); con.weighty = 1.0; con.fill = GridBagConstraints.BOTH; ! layout.setConstraints(consSpaceDescripton, con); ! consSpaceDescripton.addFocusListener(new MyFocusListener(o)); ! add(consSpaceDescripton); ! revalidate(); ! ! revalidate(); } --- 111,122 ---- nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); ! JTextArea descriptionEditor = new JTextArea(o.getDescription()); ! descriptionEditor.setLineWrap(true); ! descriptionEditor.setWrapStyleWord(true); con.weighty = 1.0; con.fill = GridBagConstraints.BOTH; ! layout.setConstraints(descriptionEditor, con); ! descriptionEditor.addFocusListener(new MyFocusListener(o)); ! add(descriptionEditor); } *************** *** 208,213 **** */ void displaySurface(Surface o) { - removeAll(); - GridBagLayout layout = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); --- 138,141 ---- *************** *** 307,311 **** layout.setConstraints(vfiller, con); add(vfiller); - revalidate(); } --- 235,238 ---- *************** *** 316,383 **** void display(Object o) { current = o; - - List names = new ArrayList(); - List components = new ArrayList(); - - if (current != null) { - Method[] methods = current.getClass().getMethods(); - for (int i = 0; i < methods.length; i++) { - Method m = methods[i]; - String name = m.getName(); - if (name.startsWith("get")) { - if (!name.endsWith("Id") && !name.endsWith("Class")) { - if (returnTypeSupported(m.getReturnType())) { - try { - components.add(new JLabel(m.invoke(current, (Object[])null).toString())); - if (name.length() > 4) { - names.add(new JLabel(name.substring(3, 4).toUpperCase() + name.substring(4))); - } else { - names.add(new JLabel(name.substring(3, 4).toUpperCase())); - } - } catch (Exception e) { - // Cant be accessed - } - } - } - } - } - } - removeAll(); ! ! setLayout(new GridLayout(names.size(), 2)); ! for (int i = 0; i < names.size(); i++) { ! add((JLabel)names.get(i)); ! add((JLabel)components.get(i)); } revalidate(); } - - /** - * Return type supported - * @param c The class for the return type - * @return True if supported; otherwise false - */ - private boolean returnTypeSupported(Class c) { - String n = c.getName(); - if (n.equals("java.lang.String") || - n.equals("java.lang.Integer") || - n.equals("java.lang.Double") || - n.equals("java.lang.Float") || - n.equals("java.lang.Short") || - n.equals("java.lang.Boolean") || - n.equals("java.lang.Byte") || - n.equals("java.lang.Long") || - n.equals(Integer.TYPE.getName()) || - n.equals(Double.TYPE.getName()) || - n.equals(Float.TYPE.getName()) || - n.equals(Short.TYPE.getName()) || - n.equals(Boolean.TYPE.getName()) || - n.equals(Byte.TYPE.getName()) || - n.equals(Long.TYPE.getName())) { - return true; - } - return false; - } } } --- 243,257 ---- void display(Object o) { current = o; removeAll(); ! if (current instanceof Space) { ! Space space = (Space) current; ! displaySpace(space); ! } else if (current instanceof Surface) { ! displaySurface((Surface) current); ! } else { ! log.info("display " + current); } revalidate(); } } } Index: MyMouseListener.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/MyMouseListener.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MyMouseListener.java 13 Jan 2006 10:24:59 -0000 1.4 --- MyMouseListener.java 13 Jan 2006 11:03:35 -0000 1.5 *************** *** 22,28 **** */ public class MyMouseListener implements MouseListener { - /** The current Surface */ ! private Surface currentSurface; /** The current Side */ --- 22,27 ---- */ public class MyMouseListener implements MouseListener { /** The current Surface */ ! private Surface surface; /** The current Side */ *************** *** 31,41 **** /** * The constructor ! * @param o the event * @param side shows if its the front or back of the surface. True = front, False = Back. */ ! public MyMouseListener (Surface o, boolean side) { ! currentSurface = o; currentSide = side; - } --- 30,39 ---- /** * The constructor ! * @param surface The surface * @param side shows if its the front or back of the surface. True = front, False = Back. */ ! public MyMouseListener (Surface surface, boolean side) { ! this.surface = surface; currentSide = side; } *************** *** 52,88 **** /** * Handles mouse event ! * @param arg0 the event */ ! public void mouseClicked(MouseEvent arg0) { Color defaultColor = Color.white; Material newMaterial; if (currentSide) { ! if (currentSurface.getFrontMaterial() != null) { ! defaultColor = getMaterialColor(currentSurface.getFrontMaterial()); } Color frontColor = JColorChooser.showDialog(GUI.getInstance(), ! "Constructor Line Color", defaultColor); if (frontColor != null) { newMaterial = new Material("temp", frontColor.getRGBColorComponents(null)); ! } else { ! newMaterial = new Material("temp", defaultColor.getRGBColorComponents(null)); } - currentSurface.setFrontMaterial(newMaterial); - currentSurface.changed(); } else { ! if (currentSurface.getBackMaterial() != null) { ! defaultColor = getMaterialColor(currentSurface.getBackMaterial()); } Color backColor = JColorChooser.showDialog(GUI.getInstance(), ! "Constructor Line Color", defaultColor); if (backColor != null) { newMaterial = new Material("temp", backColor.getRGBColorComponents(null)); ! } else { ! newMaterial = new Material("temp", defaultColor.getRGBColorComponents(null)); } - currentSurface.setBackMaterial(newMaterial); - currentSurface.changed(); } } --- 50,82 ---- /** * Handles mouse event ! * @param event the event */ ! public void mouseClicked(MouseEvent event) { Color defaultColor = Color.white; Material newMaterial; if (currentSide) { ! if (surface.getFrontMaterial() != null) { ! defaultColor = getMaterialColor(surface.getFrontMaterial()); } Color frontColor = JColorChooser.showDialog(GUI.getInstance(), ! "Surface Color", defaultColor); if (frontColor != null) { newMaterial = new Material("temp", frontColor.getRGBColorComponents(null)); ! surface.setFrontMaterial(newMaterial); ! surface.changed(); } } else { ! if (surface.getBackMaterial() != null) { ! defaultColor = getMaterialColor(surface.getBackMaterial()); } Color backColor = JColorChooser.showDialog(GUI.getInstance(), ! "Surface Color", defaultColor); if (backColor != null) { newMaterial = new Material("temp", backColor.getRGBColorComponents(null)); ! surface.setBackMaterial(newMaterial); ! surface.changed(); } } } *************** *** 90,126 **** /** * Handles mouse event ! * @param arg0 the event */ ! public void mouseEntered(MouseEvent arg0) { ! ! } /** * Handles mouse event ! * @param arg0 the event */ ! public void mouseExited(MouseEvent arg0) { ! ! } /** * Handles mouse event ! * @param arg0 the event */ ! public void mousePressed(MouseEvent arg0) { ! ! } /** * Handles mouse event ! * @param arg0 the event */ ! public void mouseReleased(MouseEvent arg0) { ! ! } ! ! ! ! } --- 84,108 ---- /** * Handles mouse event ! * @param event the event */ ! public void mouseEntered(MouseEvent event) { } /** * Handles mouse event ! * @param event the event */ ! public void mouseExited(MouseEvent event) { } /** * Handles mouse event ! * @param event the event */ ! public void mousePressed(MouseEvent event) { } /** * Handles mouse event ! * @param event the event */ ! public void mouseReleased(MouseEvent event) { } } |