From 6307ef7c557e866c33bcff28d5a49b0ffcd2f167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Sim=C3=A3o?= Date: Tue, 23 Sep 2008 13:35:58 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@746 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../SIPRPSoft/src/leaf/ui/LeafInputField.java | 77 ++++--------------- 1 file changed, 15 insertions(+), 62 deletions(-) diff --git a/trunk/SIPRPSoft/src/leaf/ui/LeafInputField.java b/trunk/SIPRPSoft/src/leaf/ui/LeafInputField.java index 5ac269f6..979696c4 100644 --- a/trunk/SIPRPSoft/src/leaf/ui/LeafInputField.java +++ b/trunk/SIPRPSoft/src/leaf/ui/LeafInputField.java @@ -52,14 +52,11 @@ public class LeafInputField extends JPanel implements F private Color hot = null; private Color cold = null; private Color background = null; - private Color startColor = null; private Color endColor = null; private Color highLightColor = new Color( 180, 255, 180 ); private Object selectedOption = null; - private boolean isError = false; - private boolean isEditable = false; private boolean isClickable = false; @@ -103,17 +100,6 @@ public class LeafInputField extends JPanel implements F collapseOptions = collapse; } - public void setText( String text ) - { - try - { - setObject( (ObjClass) text ); - } catch( ClassCastException ex ) - { - ex.printStackTrace(); - } - } - private String getStringFromUser() { LeafTextDialog textDialog = new LeafTextDialog( getParentWindow(), this, (String) object, true ); @@ -163,10 +149,8 @@ public class LeafInputField extends JPanel implements F protected void paintComponent( Graphics g ) { Graphics2D g2d = (Graphics2D) g; - int width = getWidth(); - int height = getHeight(); + int width = getWidth(), height = getHeight(); setColors( width, height ); - g2d.setPaint( outerReversedContour ); g2d.fillRect( 15, 0, width / 4, height ); g2d.setPaint( outerContour ); @@ -182,27 +166,12 @@ public class LeafInputField extends JPanel implements F private void setColors( int width, int height ) { - startColor = getGradientStartColor(); - endColor = getGradientEndColor( startColor ); + endColor = getGradientEndColor( background ); outerContour = new GradientPaint( width / 4, 0, Color.GRAY, width, 0, this.getParent().getBackground() ); outerReversedContour = new GradientPaint( 15, 0, this.getParent().getBackground(), width / 4, 0, Color.GRAY ); innerContour = new GradientPaint( width / 4, 0, Color.LIGHT_GRAY, width, 0, this.getParent().getBackground() ); innerReversedContour = new GradientPaint( 15, 0, this.getParent().getBackground(), width / 4, 0, Color.LIGHT_GRAY ); - gradient = new GradientPaint( 0, 0, startColor, width, height, endColor ); - } - - private Color getGradientStartColor() - { - Color result = background; - /* - * int red = result.getRed(), green = result.getGreen(), blue = - * result.getBlue(), alpha = result.getAlpha(); if( isError() ) { result = - * new Color( red, green > colorDec ? (green - colorDec) : 0, (blue > - * colorDec) ? (blue - colorDec) : 0, alpha ); } else if( isEditable() ) { - * result = new Color( red > colorDec ? (red - colorDec) : 0, green, - * blue > colorDec ? (blue - colorDec) : 0, alpha ); } - */ - return result; + gradient = new GradientPaint( 0, 0, background, width, height, endColor ); } private Color getGradientEndColor( Color startColor ) @@ -210,22 +179,6 @@ public class LeafInputField extends JPanel implements F return getParent() != null ? getParent().getBackground() : startColor; } - /** - * Sets the component to an error state appearance - * - * @param error - */ - public void setError( boolean error ) - { - isError = error; - repaint(); - } - - public boolean isError() - { - return isError; - } - public boolean getSelected() { return highLighted; @@ -244,15 +197,11 @@ public class LeafInputField extends JPanel implements F if( !editable ) { setMouseOver( false ); - removeBold(); } + setEnabled( editable ); + setObject( object, selectedOption ); repaint(); } - - private void removeBold() - { - - } public boolean isEditable() { @@ -378,23 +327,24 @@ public class LeafInputField extends JPanel implements F private void setSelectedObject( Object key ) { selectedOption = key; - if( object != null && thiz != null /*&& selectedOption != null */) + if( object != null && thiz != null ) { if( object instanceof Map ) { Object value = null; value = ((Map) object).get( selectedOption ); + String text = value == null ? " " : value.toString(); if( thiz instanceof JTextArea ) { - ((JTextArea) thiz).setText( value == null ? " " : value.toString() ); + ((JTextArea) thiz).setText( text ); } else if( thiz instanceof JTextField ) { - ((JTextField) thiz).setText( value == null ? " " : value.toString() ); + ((JTextField) thiz).setText( text ); } else if( thiz instanceof JLabel ) { - ((JLabel) thiz).setText( value == null ? " " : value.toString() ); + ((JLabel) thiz).setText( text ); } } else if( object instanceof OrderedMap ) @@ -430,12 +380,15 @@ public class LeafInputField extends JPanel implements F if( object instanceof Date ) { Date date = (Date) object; - thiz = new JTextArea( date.getTime() == 0 ? "" : sdf.format( object ) ); + String text = date.getTime() == 0 ? "" : sdf.format( object ); + thiz = isEditable ? new JLabel( text ) : new JTextArea( text ); + thiz.setEnabled( false ); } else if( object instanceof Map ) { - thiz = new JTextArea( " " ); + thiz = isEditable ? new JLabel( " " ) : new JTextArea( " " ); setSelectedObject( selectedOption ); + thiz.setEnabled( false ); } else if( object instanceof OrderedMap && collapseOptions ) {