Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview MaterialAttribute.java,1.1,1.2 G
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nikolaj B. <nbr...@us...> - 2006-03-08 14:22:16
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12822/src/net/sourceforge/bprocessor/gui/attrview Modified Files: MaterialAttribute.java GenericPanel.java Log Message: Materials are now working Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GenericPanel.java 8 Mar 2006 11:57:05 -0000 1.11 --- GenericPanel.java 8 Mar 2006 14:22:05 -0000 1.12 *************** *** 26,35 **** import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Camera; import net.sourceforge.bprocessor.model.Description; import net.sourceforge.bprocessor.model.Entity; ! import net.sourceforge.bprocessor.model.Material; import net.sourceforge.bprocessor.model.Parametric; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; /** --- 26,37 ---- import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Camera; + import net.sourceforge.bprocessor.model.ConstructionSpace; import net.sourceforge.bprocessor.model.Description; import net.sourceforge.bprocessor.model.Entity; ! import net.sourceforge.bprocessor.model.FunctionalSpace; import net.sourceforge.bprocessor.model.Parametric; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; + import net.sourceforge.bprocessor.model.Surface; /** *************** *** 140,144 **** //da.addMouseListener(this); where.add(new AttributeRow(da)); ! } else if (a.getValue() instanceof Entity) { // Handles the links LinkAttribute la = new LinkAttribute(a); --- 142,147 ---- //da.addMouseListener(this); where.add(new AttributeRow(da)); ! } else if (a.getValue() instanceof Surface || a.getValue() instanceof FunctionalSpace ! || a.getValue() instanceof ConstructionSpace) { // Handles the links LinkAttribute la = new LinkAttribute(a); *************** *** 158,162 **** //da.addMouseListener(this); where.add(new AttributeRow(la)); ! } else if (a.getValue() instanceof Material) { // Handles the materials MaterialAttribute ma = new MaterialAttribute(a); --- 161,165 ---- //da.addMouseListener(this); where.add(new AttributeRow(la)); ! } else if (a.getName().equals("Front Material") || a.getName().equals("Back Material")) { // Handles the materials MaterialAttribute ma = new MaterialAttribute(a); Index: MaterialAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/MaterialAttribute.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MaterialAttribute.java 7 Mar 2006 23:03:58 -0000 1.1 --- MaterialAttribute.java 8 Mar 2006 14:22:05 -0000 1.2 *************** *** 8,12 **** package net.sourceforge.bprocessor.gui.attrview; ! import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; --- 8,12 ---- package net.sourceforge.bprocessor.gui.attrview; ! import java.awt.Color; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; *************** *** 15,25 **** import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JComponent; ! import javax.swing.JLabel; import javax.swing.JTextField; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Surface; --- 15,33 ---- import java.util.List; + import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; + import javax.swing.JColorChooser; import javax.swing.JComponent; ! import javax.swing.JPanel; import javax.swing.JTextField; + import javax.swing.border.Border; + import net.sourceforge.bprocessor.gui.Defaults; + import net.sourceforge.bprocessor.gui.GUI; import net.sourceforge.bprocessor.model.Attribute; + import net.sourceforge.bprocessor.model.Material; + import net.sourceforge.bprocessor.model.Project; + import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; *************** *** 38,43 **** private JComponent component; ! /** The Label */ ! private JLabel label; /** The editor, when this EditableAttribute is being edited */ --- 46,54 ---- private JComponent component; ! /** The current surface */ ! private Surface surface; ! ! /** The current side */ ! private boolean side; /** The editor, when this EditableAttribute is being edited */ *************** *** 56,96 **** this.attribute = attribute; this.listeners = new LinkedList(); ! ! label = createLabel(attribute.getName()); ! Box header = Box.createHorizontalBox(); ! Box column = Box.createVerticalBox(); ! header.add(Box.createHorizontalGlue()); ! header.add(label); ! //column.add(Box.createHorizontalStrut(60)); ! column.add(Box.createRigidArea(new Dimension(70, 3))); ! column.add(header); ! column.add(Box.createRigidArea(new Dimension(70, 3))); ! //column.add(Box.createHorizontalStrut(60)); ! column.setMaximumSize(new Dimension(60, Short.MAX_VALUE)); ! this.add(column); ! this.add(Box.createHorizontalStrut(7)); component = Box.createHorizontalBox(); ! component.add(createValueLabel(attribute.getValue())); this.add(component); - this.add(Box.createHorizontalGlue()); } /** - * Create a label for the - * @param key The key - * @return A JLabel - */ - private JLabel createLabel(String key) { - JLabel keyLabel = new JLabel(key + " :"); - keyLabel.setFont(AttributeView.FONT_BOLD); - return keyLabel; - } - - /** * Add a mouselisterner to the active elements in the MaterialAttribute * @param mouseListener the mouselistener */ public void addMouseListener(MouseListener mouseListener) { - label.addMouseListener(mouseListener); component.addMouseListener(mouseListener); } --- 67,82 ---- this.attribute = attribute; this.listeners = new LinkedList(); ! ! //this.add(Box.createHorizontalStrut(7)); component = Box.createHorizontalBox(); ! component.add(createValueLabel(attribute)); this.add(component); } /** * Add a mouselisterner to the active elements in the MaterialAttribute * @param mouseListener the mouselistener */ public void addMouseListener(MouseListener mouseListener) { component.addMouseListener(mouseListener); } *************** *** 101,105 **** */ public void removeMouseListener(MouseListener mouseListener) { - label.removeMouseListener(mouseListener); component.removeMouseListener(mouseListener); } --- 87,90 ---- *************** *** 134,166 **** /** * Create a value label ! * @param value The value * @return The label */ ! private JComponent createValueLabel(Object value) { ! String s = ""; ! s = ((Surface)value).getName(); ! JLabel valueLabel = new JLabel(s); ! if (attribute.isEditable()) { ! valueLabel.setFont(AttributeView.FONT_PLAIN); } else { ! valueLabel.setFont(AttributeView.FONT_ITALIC); } return valueLabel; } - /** - * Create a value editor - * @param value The value - * @return The editor - */ - private JComponent createValueEditor(Object value) { - String s = ""; - if (value instanceof String) { - s = (String)value; - } - JTextField valueEditor = new JTextField(s); - valueEditor.setFont(AttributeView.FONT_PLAIN); - return valueEditor; - } /** --- 119,146 ---- /** * Create a value label ! * @param a The attribute * @return The label */ ! private JComponent createValueLabel(Attribute a) { ! JPanel valueLabel = new JPanel(); ! surface = Project.getInstance().findSurfaceById(Long.parseLong(a.getValue().toString())); ! if (a.getName().equals("Front Material")) { ! side = true; ! float[] frontColor = getFrontColor(surface); ! valueLabel.setOpaque(true); ! Border blackline = BorderFactory.createLineBorder(Color.black); ! valueLabel.setBorder(blackline); ! valueLabel.setBackground(makeAWTColor(frontColor)); } else { ! side = false; ! float[] backColor = getBackColor(surface); ! valueLabel.setOpaque(true); ! Border blackline = BorderFactory.createLineBorder(Color.black); ! valueLabel.setBorder(blackline); ! valueLabel.setBackground(makeAWTColor(backColor)); } return valueLabel; } /** *************** *** 176,188 **** */ public void startEditing() { ! if (attribute.isEditable()) { ! if (editor == null) { ! component.remove(0); ! editor = (JTextField) createValueEditor(attribute.getValue()); ! component.add(editor); ! component.revalidate(); } - editor.requestFocus(); - editor.selectAll(); } } --- 156,190 ---- */ public void startEditing() { ! Color defaultColor = Color.white; ! Material newMaterial; ! ! if (side) { ! if (surface.getFrontDomain() != null) { ! 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.getBackDomain() != null) { ! 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(); ! } } } } *************** *** 200,204 **** component.remove(editor); editor = null; ! component.add(createValueLabel(attribute.getValue())); component.revalidate(); valueChanged(); --- 202,206 ---- component.remove(editor); editor = null; ! component.add(createValueLabel(attribute)); component.revalidate(); valueChanged(); *************** *** 214,221 **** component.remove(editor); editor = null; ! component.add(createValueLabel(attribute.getValue())); component.revalidate(); } } /** --- 216,293 ---- component.remove(editor); editor = null; ! component.add(createValueLabel(attribute)); component.revalidate(); } } + + /** + * Get AWT color for material + * @param material The material + * @return The AWT color + */ + private Color getMaterialColor(Material material) { + float[] rgb = material.getColor(); + return new Color(rgb[0], rgb[1], rgb[2]); + } + + /** + * Make AWT color from the components + * @param rgb Array of floats + * @return AWT Color + */ + private Color makeAWTColor(float[] rgb) { + return new Color(rgb[0], rgb[1], rgb[2]); + } + + + /** + * Return front color for surface + * @param surface The surface + * @return The color + */ + private float[] getFrontColor(Surface surface) { + if (surface.getFrontDomain() == null) { + return Defaults.getNoneColor(); + } else { + if (surface.getFrontMaterial() == null) { + Space space = surface.getFrontDomain(); + if (space.isConstructionSpace()) { + return Defaults.getFrontColor(); + } + if (space.isFunctionalSpace()) { + return Defaults.getBackColor(); + } + return Defaults.getNoneColor(); + } else { + return surface.getFrontMaterial().getColor(); + } + } + } + + + /** + * Return back color for surface + * @param surface The surface + * @return The color + */ + private float[] getBackColor(Surface surface) { + if (surface.getBackDomain() == null) { + return Defaults.getNoneColor(); + } else { + if (surface.getBackMaterial() == null) { + Space space = surface.getBackDomain(); + if (space.isConstructionSpace()) { + return Defaults.getFrontColor(); + } + if (space.isFunctionalSpace()) { + return Defaults.getBackColor(); + } + return Defaults.getNoneColor(); + } else { + return surface.getBackMaterial().getColor(); + } + } + } + /** |