• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 5665

Show
Ignore:
Timestamp:
10/09/08 12:12:17 (6 weeks ago)
Author:
will
Message:

Printing of Date-Time field

Location:
branches/ProtocolEditor/src
Files:
2 modified

  • ui/components/AlarmSetter.java (modified) (2 diffs)
  • util/DefaultExport.java (modified) (6 diffs)

Legend:

Unmodified
Added
Removed
  • branches/ProtocolEditor/src/ui/components/AlarmSetter.java

    r5385 r5665  
    189189                } 
    190190                 
     191                int timeUnit = getTimeUnits(secs); 
     192                int timeValue = getTimeValue(secs); 
     193                 
     194                setTimeUnitChooserIndex(timeUnit); 
     195                setTimeSpinnerValue(timeValue); 
     196        } 
     197         
     198        /** 
     199         * Returns the value needed to describe the alarm seconds in the  
     200         * units returned by {@link #getTimeUnits(int)}; 
     201         * eg If alarmSecs = 3600, this method will return 1, and  
     202         * {@link #getTimeUnits(int)} will return {@link HOURS}; 
     203         *  
     204         * @param alarmSecs             time in seconds 
     205         * @return int                  see above.  
     206         */ 
     207        public static int getTimeValue(int alarmSecs) { 
    191208                int timeUnit; 
    192209                int timeValue; 
    193210                 
     211                if (alarmSecs == 0) return 0; 
     212                 
    194213                // need to work out what the units are 
    195214                for (timeUnit = 0; timeUnit<timeUnits.length; timeUnit++) { 
    196                         timeValue = secs/secondsInTimeUnit[timeUnit]; 
     215                        timeValue = alarmSecs/secondsInTimeUnit[timeUnit]; 
    197216                        // if timeValue > 0 then this is the units you want 
    198217                        if (timeValue > 0) { 
    199218                                 
    200219                                // if it is an exact match  
    201                                 if (secs == timeValue * secondsInTimeUnit[timeUnit]) { 
    202                                         setTimeUnitChooserIndex(timeUnit); 
    203                                         setTimeSpinnerValue(timeValue); 
    204                                         return; 
     220                                if (alarmSecs == timeValue * secondsInTimeUnit[timeUnit]) { 
     221                                        return timeValue; 
    205222                                } else { 
    206223                                 
    … …  
    209226                                        if (timeUnit < timeUnits.length -1) { 
    210227                                                timeUnit++; 
    211                                                 timeValue = secs/secondsInTimeUnit[timeUnit]; 
    212                                                 setTimeUnitChooserIndex(timeUnit); 
    213                                                 setTimeSpinnerValue(timeValue); 
    214                                                 return; 
     228                                                timeValue = alarmSecs/secondsInTimeUnit[timeUnit]; 
     229                                                return timeValue; 
    215230                                        } 
     231                                } 
     232                        } 
     233                } 
     234                return 0; 
     235        } 
     236         
     237         
     238        public static String alarmSecsToString(String alarmSecs) { 
     239                 
     240                try { 
     241                        int secs = Integer.parseInt(alarmSecs); 
     242                         
     243                        boolean alarmBefore = false; 
     244                        if (secs < 0) {         // alarm before event 
     245                                alarmBefore = true; 
     246                                secs = secs * -1; 
     247                        } 
     248                         
     249                        if (secs == 0) return "No alarm"; 
     250                         
     251                        int value = getTimeValue(secs); 
     252                        String units = "No alarm"; 
     253                        if (getTimeUnits(secs) < timeUnits.length) { 
     254                                units = timeUnits[getTimeUnits(secs)]; 
     255                        } 
     256                         
     257                        return value + " " + units + (alarmBefore ? " Before" : " After"); 
     258                                          
     259                } catch (NumberFormatException ex) { 
     260                        ex.printStackTrace(); 
     261                        return ""; 
     262                } 
     263        } 
     264         
     265         
     266        /** 
     267         * Returns the units needed to describe the alarm seconds 
     268         * {@link DAYS}, {@link HOURS}, or {@link MINS}  
     269         *  
     270         * @param alarmSecs 
     271         * @return int  the units index {@link DAYS}, {@link HOURS}, or {@link MINS}  
     272         */ 
     273        public static int getTimeUnits(int alarmSecs) { 
     274                 
     275                int timeUnit; 
     276                int timeValue; 
     277                 
     278                // need to work out what the units are 
     279                for (timeUnit = 0; timeUnit<timeUnits.length; timeUnit++) { 
     280                        timeValue = alarmSecs/secondsInTimeUnit[timeUnit]; 
     281                        // if timeValue > 0 then this is the units you want 
     282                        if (timeValue > 0) { 
    216283                                 
     284                                // if it is an exact match  
     285                                if (alarmSecs == timeValue * secondsInTimeUnit[timeUnit]) { 
     286                                        return timeUnit; 
     287                                } else { 
     288                                 
     289                                // if any seconds are left over (eg user sets 90 minutes or 36 hours) 
     290                                        // try smaller units 
     291                                        if (timeUnit < timeUnits.length -1) { 
     292                                                return timeUnit + 1; 
     293                                        } 
    217294                                } 
    218                                  
    219295                        } 
    220296                } 
     297                return NO_ALARM; 
    221298        } 
    222299         
  • branches/ProtocolEditor/src/util/DefaultExport.java

    r5339 r5665  
    1 package util; 
    2  
    3 import java.awt.Color; 
    4 import java.io.File; 
    5 import java.io.FileWriter; 
    6 import java.io.PrintWriter; 
    7 import java.util.ArrayList; 
    8 import java.util.HashMap; 
    9 import java.util.Iterator; 
    10 import java.util.LinkedHashMap; 
    11 import java.util.List; 
    12 import java.util.Map; 
    13  
    14 import tree.DataField; 
    15 import tree.DataFieldConstants; 
    16 import tree.DataFieldNode; 
    17 import tree.IAttributeSaver; 
    18 import ui.formFields.FormField; 
    191 
    202/* 
    … …  
    4022 */ 
    4123 
     24package util; 
     25 
     26import java.awt.Color; 
     27import java.io.BufferedReader; 
     28import java.io.File; 
     29import java.io.FileNotFoundException; 
     30import java.io.FileReader; 
     31import java.io.FileWriter; 
     32import java.io.IOException; 
     33import java.io.PrintWriter; 
     34import java.text.SimpleDateFormat; 
     35import java.util.ArrayList; 
     36import java.util.HashMap; 
     37import java.util.Iterator; 
     38import java.util.List; 
     39import java.util.Map; 
     40 
     41import tree.DataField; 
     42import tree.DataFieldConstants; 
     43import tree.DataFieldNode; 
     44import tree.IAttributeSaver; 
     45import ui.components.AlarmSetter; 
     46import ui.formFields.FormField; 
     47 
    4248public class DefaultExport  
    4349        implements IExport { 
    … …  
    8187        public String TABLE_DATA_END = ""; 
    8288         
    83          
     89        /** 
     90         * Exports the given dataField nodes as a String.  
     91         * This method works by creating a temporary file, delegating the 
     92         * export to that file, using {@link #export(File, List)} and then  
     93         * converting the file to a String. The temp file is deleted before  
     94         * returning the String. 
     95         *  
     96         * @param rootNodes             A list of the nodes to export 
     97         * @return String               A string representation of the export.  
     98         */ 
     99        public String exportToString(List<DataFieldNode> rootNodes)  
     100        { 
     101                File tempFile = new File("temp"); 
     102                 
     103                export(tempFile, rootNodes); 
     104                 
     105                StringBuffer fileData = new StringBuffer(1000); 
     106                BufferedReader reader; 
     107                try { 
     108                        reader = new BufferedReader(new FileReader(tempFile)); 
     109                        char[] buf = new char[1024]; 
     110                        int numRead=0; 
     111                        while((numRead=reader.read(buf)) != -1){ 
     112                                String readData = String.valueOf(buf, 0, numRead); 
     113                                fileData.append(readData); 
     114                                buf = new char[1024]; 
     115                        } 
     116                        reader.close(); 
     117                } catch (FileNotFoundException e) { 
     118                        // TODO Auto-generated catch block 
     119                        e.printStackTrace(); 
     120                } catch (IOException e) { 
     121                        // TODO Auto-generated catch block 
     122                        e.printStackTrace(); 
     123                } 
     124                 
     125                String exportString = fileData.toString(); 
     126                 
     127                //tempFile.delete(); 
     128                 
     129                return exportString; 
     130        } 
    84131         
    85132        /** 
    … …  
    98145                exportPreferences.put(SHOW_URL, true); 
    99146                exportPreferences.put(SHOW_TABLE_DATA, true); 
    100                 exportPreferences.put(SHOW_OTHER_ATTRIBUTES, true); 
     147                exportPreferences.put(SHOW_OTHER_ATTRIBUTES, false); 
    101148                 
    102149                export(file, rootNodes, exportPreferences); 
    … …  
    214261        else divHeader = DIV; 
    215262         
    216         if (true) { 
    217                 String colour = dataField.getAttribute(DataFieldConstants.BACKGROUND_COLOUR); 
     263        String colour = dataField.getAttribute(DataFieldConstants.BACKGROUND_COLOUR); 
     264        if (colour != null) { 
    218265                Color bgColour = FormField.getColorFromString(colour); 
    219266                if (bgColour != null) { 
    … …  
    250297        outputStream.println(SPAN_END); 
    251298                 
     299        if (DataFieldConstants.DATE_TIME_FIELD.equals(inputType)) { 
     300                String date = "Date: "; 
     301                String UTCmillisecs = dataField.getAttribute(DataFieldConstants.UTC_MILLISECS); 
     302                        if (UTCmillisecs != null) { 
     303                                SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy"); 
     304                                date = date + sdf.format(new Long(UTCmillisecs)); 
     305                        } else { 
     306                                date = date + "none set."; 
     307                        } 
     308                         
     309                        String time = dataField.getAttribute(DataFieldConstants.SECONDS); 
     310                        if (time != null) { 
     311                                SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); 
     312                                date = date + " at " + sdf.format(new Long(time + "000")) + "."; 
     313                        } 
     314                         
     315                        String alarmSecs = dataField.getAttribute(DataFieldConstants.ALARM_SECONDS); 
     316                        if (alarmSecs != null) { 
     317                                date = date + " Alarm: " + AlarmSetter.alarmSecsToString(alarmSecs); 
     318                        } 
     319                        date = DIV_CLASS_ATTRIBUTE + date + DIV_END; 
     320                         
     321                        outputStream.print(date); 
     322        } 
     323         
    252324        if ((showDefaultValues) && (allAttributes.get(DataFieldConstants.DEFAULT) != null)) { 
    253325                outputStream.print(DIV_CLASS_ATTRIBUTE + "Default Value = " + 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/