GEODE-37 Renamed some test directory. And fixed JGroupsMessengerJUnitTest unittest
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/06384849 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/06384849 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/06384849 Branch: refs/heads/develop Commit: 06384849c9f5c2ae4bac34d060f1c508886222c0 Parents: 9278d53 Author: Hitesh Khamesra <[email protected]> Authored: Tue Sep 13 16:20:52 2016 -0700 Committer: Hitesh Khamesra <[email protected]> Committed: Tue Sep 13 16:20:52 2016 -0700 ---------------------------------------------------------------------- .../com/gemstone/persistence/admin/Logger.java | 277 --------- .../gemstone/persistence/logging/Formatter.java | 41 -- .../gemstone/persistence/logging/Handler.java | 98 ---- .../com/gemstone/persistence/logging/Level.java | 128 ----- .../gemstone/persistence/logging/LogRecord.java | 185 ------ .../gemstone/persistence/logging/Logger.java | 566 ------------------- .../persistence/logging/SimpleFormatter.java | 77 --- .../persistence/logging/StreamHandler.java | 61 -- .../test/java/com/gemstone/sequence/Arrow.java | 124 ---- .../java/com/gemstone/sequence/Lifeline.java | 98 ---- .../com/gemstone/sequence/LifelineState.java | 114 ---- .../java/com/gemstone/sequence/LineMapper.java | 35 -- .../com/gemstone/sequence/SequenceDiagram.java | 315 ----------- .../com/gemstone/sequence/SequencePanel.java | 83 --- .../com/gemstone/sequence/StateColorMap.java | 66 --- .../java/com/gemstone/sequence/TimeAxis.java | 122 ---- .../com/gemstone/sequence/ZoomingPanel.java | 188 ------ .../sequence/gemfire/DefaultLineMapper.java | 41 -- .../gemfire/GemfireSequenceDisplay.java | 335 ----------- .../sequence/gemfire/HydraLineMapper.java | 134 ----- .../sequence/gemfire/SelectGraphDialog.java | 155 ----- .../messenger/JGroupsMessengerJUnitTest.java | 2 +- .../org/apache/persistence/admin/Logger.java | 277 +++++++++ .../apache/persistence/logging/Formatter.java | 41 ++ .../org/apache/persistence/logging/Handler.java | 98 ++++ .../org/apache/persistence/logging/Level.java | 128 +++++ .../apache/persistence/logging/LogRecord.java | 185 ++++++ .../org/apache/persistence/logging/Logger.java | 566 +++++++++++++++++++ .../persistence/logging/SimpleFormatter.java | 77 +++ .../persistence/logging/StreamHandler.java | 61 ++ .../test/java/org/apache/sequence/Arrow.java | 124 ++++ .../test/java/org/apache/sequence/Lifeline.java | 98 ++++ .../java/org/apache/sequence/LifelineState.java | 114 ++++ .../java/org/apache/sequence/LineMapper.java | 35 ++ .../org/apache/sequence/SequenceDiagram.java | 315 +++++++++++ .../java/org/apache/sequence/SequencePanel.java | 83 +++ .../java/org/apache/sequence/StateColorMap.java | 66 +++ .../test/java/org/apache/sequence/TimeAxis.java | 122 ++++ .../java/org/apache/sequence/ZoomingPanel.java | 188 ++++++ .../sequence/gemfire/DefaultLineMapper.java | 41 ++ .../gemfire/GemfireSequenceDisplay.java | 335 +++++++++++ .../sequence/gemfire/HydraLineMapper.java | 134 +++++ .../sequence/gemfire/SelectGraphDialog.java | 155 +++++ 43 files changed, 3244 insertions(+), 3244 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/admin/Logger.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/admin/Logger.java b/geode-core/src/test/java/com/gemstone/persistence/admin/Logger.java deleted file mode 100644 index c0a6de9..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/admin/Logger.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.admin; - -import java.util.*; -import java.io.PrintWriter; -import java.text.*; - -/** - * Provides single point for all log messages to written to. - * Currently this class only supports static methods and always - * writes to stdout. - * - */ -public class Logger -{ - private static final PrintWriter logWriter = new PrintWriter(System.out, true); - - // Set LOGWIDTH to maxint as a cheap way of turning off formatting - private static final int LOGWIDTH = Integer.MAX_VALUE; - private static final SimpleDateFormat timeFormatter; - static { - final String defaultFormatPattern = "MM/dd/yy HH:mm:ss.SSS z"; - final String resourceName = "org.apache.persistence.admin.LoggerResources"; - final String keyName = "logger.timeStampFormat"; - String formatPattern = defaultFormatPattern; - SimpleDateFormat sdf; - try { - ResourceBundle messageRB = - ResourceBundle.getBundle(resourceName); - try { - formatPattern = messageRB.getString(keyName); - } catch (MissingResourceException e) { - System.out.println("NOTICE: Logger using default timestamp format." - + " Could not get resource key \"" - + keyName - + "\" because: " + e); - } - } catch (MissingResourceException e) { - System.out.println("NOTICE: Logger using default timestamp format." - + " Could not load resource bundle \"" - + resourceName - + "\" because: " + e); - } - if (formatPattern.length() == 0) { - sdf = null; - } else { - try { - sdf = new SimpleDateFormat(formatPattern); - } catch (RuntimeException e) { - System.out.println("NOTICE: ignoring timestamp pattern \"" - + formatPattern - + "\" because: " + e.toString()); - System.out.println(" Using default pattern: \"" - + defaultFormatPattern + "\"."); - formatPattern = defaultFormatPattern; - sdf = new SimpleDateFormat(formatPattern); - } - } - timeFormatter = sdf; - } - - static private void formatText(PrintWriter writer, String target, - int maxLength, int initialLength) { - BreakIterator boundary = BreakIterator.getLineInstance(); - boundary.setText(target); - int start = boundary.first(); - int end = boundary.next(); - int lineLength = initialLength; - - while (end != BreakIterator.DONE) { - // Look at the end and only accept whitespace breaks - char endChar = target.charAt(end-1); - while (!Character.isWhitespace(endChar)) { - int lastEnd = end; - end = boundary.next(); - if (end == BreakIterator.DONE) { - // give up. We are at the end of the string - end = lastEnd; - break; - } - endChar = target.charAt(end-1); - } - int wordEnd = end; - if (endChar == '\n') { - // trim off the \n since println will do it for us - wordEnd--; - } else if (endChar == '\t') { - // figure tabs use 8 characters - lineLength += 7; - } - String word = target.substring(start, wordEnd); - if ((lineLength + word.length()) >= maxLength) { - if (lineLength != 0) { - writer.println(); - writer.print(" "); - lineLength = 2; - } - } - lineLength += word.length(); - writer.print(word); - if (endChar == '\n') { - // force end of line - writer.println(); - writer.print(" "); - lineLength = 2; - } - start = end; - end = boundary.next(); - } - if (lineLength != 0) { - writer.println(); - } - } - - /** - * Gets a String representation of the current time. - * @return a String representation of the current time. - */ - static public String getTimeStamp() { - return formatDate(new Date()); - } - /** - * Convert a Date to a timestamp String. - * @param d a Date to format as a timestamp String. - * @return a String representation of the current time. - */ - static public String formatDate(Date d) { - if (timeFormatter == null) { - try { - // very simple format that shows millisecond resolution - return Long.toString(d.getTime()); - } catch (Exception ignore) { - return "timestampFormatFailed"; - } - } - try { - synchronized (timeFormatter) { - // Need sync: see bug 21858 - return timeFormatter.format(d); - } - } catch (Exception e1) { - // Fix bug 21857 - try { - return d.toString(); - } catch (Exception e2) { - try { - return Long.toString(d.getTime()); - } catch (Exception e3) { - return "timestampFormatFailed"; - } - } - } - } - - /** - * Logs a message to the static log destination. - * @param msg the actual message to log - */ - static public void put(String msg) { - put(msg, (Throwable)null); - } - - /** - * Logs a message to the specified log destination. - * @param log the <code>PrintWriter</code> that the message will be written to. - * @param msg the actual message to log - */ - static public void put(PrintWriter log, String msg) { - put(log, msg, (Throwable)null); - } - - /** - * Logs an exception to the static log destination. - * @param exception the actual Exception to log - */ - static public void put(Throwable exception) { - put((String)null, exception); - } - /** - * Logs an exception to the specified log destination. - * @param log the <code>PrintWriter</code> that the message will be written to. - * @param exception the actual Exception to log - */ - static public void put(PrintWriter log, Throwable exception) { - put(log, (String)null, exception); - } - - /** - * Logs a message and an exception to the static log destination. - * @param msg the actual message to log - * @param exception the actual Exception to log - */ - static public void put(String msg, Throwable exception) { - put(logWriter, msg, exception); - } - - /** - * Logs a message and an exception to the specified log destination. - * @param log the <code>PrintWriter</code> that the message will be written to. If null then the default stdout writer is used. - * @param msg the actual message to log - * @param exception the actual Exception to log - */ - static public void put(PrintWriter log, String msg, Throwable exception) { - java.io.StringWriter sw = new java.io.StringWriter(); - String header; - PrintWriter pw = new PrintWriter(sw); - - pw.println(); - header = '[' + getTimeStamp() + ' ' + Thread.currentThread().getName() + "] "; - pw.print(header); - if (msg != null) { - try { - formatText(pw, msg, LOGWIDTH, header.length()); - } catch (RuntimeException e) { - pw.println(msg); - pw.println("Ignoring exception:"); - e.printStackTrace(pw); - } - } else { - pw.println(); - } - if (exception != null) { - exception.printStackTrace(pw); - } - pw.close(); - try { - sw.close(); - } catch (java.io.IOException ignore) {} - - if (log == null) { - log = logWriter; - } - log.print(sw.toString()); - log.flush(); - } - - /** - * Formats a message. Takes special care when invoking the - * toString() method of objects that might cause NPEs. - */ - public static String format(String format, Object[] objs) { - String[] strings = new String[objs.length]; - for (int i = 0; i < objs.length; i++) { - Object obj = objs[i]; - if (obj == null) { - strings[i] = "null"; - - } else { - try { - strings[i] = obj.toString(); - - } catch (Exception ex) { - strings[i] = obj.getClass().getName() + "@" + - System.identityHashCode(obj); - } - } - } - - return java.text.MessageFormat.format(format, (Object[])strings); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/Formatter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/Formatter.java b/geode-core/src/test/java/com/gemstone/persistence/logging/Formatter.java deleted file mode 100644 index 19b2319..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/Formatter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -/** - * Abstract class that formats LogRecords - */ -public abstract class Formatter { - - /** Should we print a stack trace along with logging messages */ - protected static boolean STACK_TRACE = - Boolean.getBoolean("org.apache.persistence.logging.StackTraces"); - - /** - * Formats the given log record as a String - */ - public abstract String format(LogRecord record); - - /** - * Formats the message string from a log record - */ - public String formatMessage(LogRecord record) { - // Simple - return(record.getMessage()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/Handler.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/Handler.java b/geode-core/src/test/java/com/gemstone/persistence/logging/Handler.java deleted file mode 100644 index a2e81ea..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/Handler.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -/** - * A Handler exports LogRecords to some destination. It can be - * configured to ignore log records that are below a given level. It - * can also a have formatter for formatting the log records before - * exporting the to the destination. - */ -public abstract class Handler { - - /** The minimum level for this handler. Any records below this - * level are ignored. */ - private Level level; - - /** Used to format the log records */ - private Formatter formatter; - - /** - * Creates a new <code>Handler</code> with Level.ALL and no - * formatter. - */ - protected Handler() { - this.level = Level.ALL; - this.formatter = null; - } - - /** - * Closes this Handler and frees all of its resources - */ - public abstract void close(); - - /** - * Flushes an buffered output - */ - public abstract void flush(); - - /** - * Returns the formatter for this handler - */ - public Formatter getFormatter() { - return(this.formatter); - } - - /** - * Sets the formatter for this handler - */ - public void setFormatter(Formatter formatter) { - this.formatter = formatter; - } - - /** - * Returns the level below which this handler ignores - */ - public Level getLevel() { - return(this.level); - } - - /** - * Sets the level below which this handler ignores - */ - public void setLevel(Level level) { - this.level = level; - } - - /** - * Returns <code>true</code> if a log record will be handled by this - * handler. - */ - public boolean isLoggable(LogRecord record) { - if(record.getLevel().intValue() >= this.getLevel().intValue()) { - return(true); - } else { - return(false); - } - } - - /** - * Publishes a log record to this handler - */ - public abstract void publish(LogRecord record); - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/Level.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/Level.java b/geode-core/src/test/java/com/gemstone/persistence/logging/Level.java deleted file mode 100644 index c5855e4..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/Level.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -/** - * A level measures the importance of a entry in a log file. - * - * The priorty of level from highest to lowest is: - * <OL> - * <LI>ALL</LI> - * <LI>SEVERE</LI> - * <LI>WARNING</LI> - * <LI>INFO</LI> - * <LI>CONFIG</LI> - * <LI>FINE</LI> - * <LI>FINER</LI> - * <LI>FINEST</LI> - * <LI>OFF</LI> - * </OL> - */ -public class Level { - - public static final Level OFF = new Level("OFF", 4); - public static final Level SEVERE = new Level("SEVERE", 3); - public static final Level WARNING = new Level("WARNING", 2); - public static final Level INFO = new Level("INFO", 1); - public static final Level CONFIG = new Level("CONFIG", 0); - public static final Level FINE = new Level("FINE", -1); - public static final Level FINER = new Level("FINER", -2); - public static final Level FINEST = new Level("FINEST", -3); - public static final Level ALL = new Level("ALL", -4); - - private String name; - private int value; - - /** - * Creates a new <code>Level</code> with a given name and integer - * value. - */ - protected Level(String name, int value) { - this.name = name; - this.value = value; - } - - /** - * Creates a new <code>Level</code> from a string. The string - * should be something like "FINER" or "42". - */ - public static Level parse(String name) { - if(name.equalsIgnoreCase("OFF")) { - return(OFF); - - } else if(name.equalsIgnoreCase("SEVERE")) { - return(SEVERE); - - } else if(name.equalsIgnoreCase("WARNING")) { - return(WARNING); - - } else if(name.equalsIgnoreCase("INFO")) { - return(INFO); - - } else if(name.equalsIgnoreCase("CONFIG")) { - return(CONFIG); - - } else if(name.equalsIgnoreCase("FINE")) { - return(FINE); - - } else if(name.equalsIgnoreCase("FINER")) { - return(FINER); - - } else if(name.equalsIgnoreCase("FINEST")) { - return(FINEST); - - } else if(name.equalsIgnoreCase("ALL")) { - return(ALL); - } - - try { - return(new Level(name, Integer.parseInt(name))); - - } catch(NumberFormatException ex) { - throw new IllegalArgumentException("Invalid level: " + name); - } - } - - /** - * Returns the integer value for this level - */ - public int intValue() { - return(this.value); - } - - /** - * Returns a textual representation of this level - */ - public String toString() { - return("Level " + this.name + " (" + this.value + ")"); - } - - /** - * Two levels are equal if they have the same integer value - */ - public boolean equals(Object o) { - if(o instanceof Level) { - Level l = (Level) o; - if(l.value == this.value) { - return(true); - } - } - - return(false); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/LogRecord.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/LogRecord.java b/geode-core/src/test/java/com/gemstone/persistence/logging/LogRecord.java deleted file mode 100644 index c2e8061..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/LogRecord.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -/** - * A <code>LogRecord</code> encapsulate an entry in a log. - */ -public class LogRecord { - - /** Global counter of sequence numbers */ - private static long nextSequenceNumber = 0; - - private Level level; - private String loggerName; - private String message; - private long millis; - private Object[] parameters; - private long sequenceNumber; - private String sourceClassName; - private String sourceMethodName; - private Throwable thrown; - - /** - * Creates a new <code>LogRecord</code> with the given level and - * message. - */ - public LogRecord(Level level, String message) { - this.level = level; - this.message = message; - this.sequenceNumber = nextSequenceNumber++; - this.millis = System.currentTimeMillis(); - } - - /** - * Sets the level at which the message id logged - */ - public void setLevel(Level level) { - this.level = level; - } - - /** - * Returns the level that the message should be logged at - */ - public Level getLevel() { - return(this.level); - } - - /** - * Sets the name of the logger to which this log record belongs - */ - public void setLoggerName(String loggerName) { - this.loggerName = loggerName; - } - - /** - * Returns the name of the logger to which this log record belongs - */ - public String getLoggerName() { - return(this.loggerName); - } - - /** - * Sets the message for this log entry - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * Returns the message for this log entry - */ - public String getMessage() { - return(this.message); - } - - /** - * Sets the event time - */ - public void setMillis(long millis) { - this.millis = millis; - } - - /** - * Returns the event time in milliseconds since 1970 - */ - public long getMillis() { - return(this.millis); - } - - /** - * Sets the parameters to this log entry - */ - public void setParameters(Object[] parameters) { - this.parameters = parameters; - } - - /** - * Returns the parameters to this log entry - */ - public Object[] getParameters() { - return(this.parameters); - } - - /** - * Sets the sequence number of this log entry - */ - public void setSequenceNumber(long sequenceNumber) { - this.sequenceNumber = sequenceNumber; - } - - /** - * Returns the sequence number of this log entry - */ - public long getSequenceNumber() { - return(this.sequenceNumber); - } - - /** - * Sets the name of the source class from which this log entry was - * issued - */ - public void setSourceClassName(String sourceClassName) { - this.sourceClassName = sourceClassName; - } - - /** - * Returns the name of the source class from which this log entry - * was issued - */ - public String getSourceClassName() { - return(this.sourceClassName); - } - - /** - * Sets the name of the source method from which this log entry was - * issued - */ - public void setSourceMethodName(String sourceMethodName) { - this.sourceMethodName = sourceMethodName; - } - - /** - * Returns the name of the source method from which this log entry - * was issued - */ - public String getSourceMethodName() { - return(this.sourceMethodName); - } - - /** - * Sets the throwable associated with this log entry - */ - public void setThrown(Throwable thrown) { - this.thrown = thrown; - } - - /** - * Returns the throwable associated with this log entry - */ - public Throwable getThrown() { - return(this.thrown); - } - - /** - * Returns a brief textual description of this - * <code>LogRecord</code> - */ - public String toString() { - return(this.message + " at " + this.level); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/Logger.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/Logger.java b/geode-core/src/test/java/com/gemstone/persistence/logging/Logger.java deleted file mode 100644 index 00e9fee..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/Logger.java +++ /dev/null @@ -1,566 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -import java.util.*; - -/** - * A logger is used to record messages and events. Each entry has a - * given level associated with it. There are a number of convenience - * methods for logging events. Events with a level above a certain - * are written to <code>System.err</code>. The default level is - * INFO - */ -public class Logger { - private static boolean DEBUG = Boolean.getBoolean("Logging.DEBUG"); - - /** Maps the names of Loggers to the Logger */ - private static Map loggers = new HashMap(); - - /** The name of this logger */ - private String name; - - /** The maximum level at which messages are logged. Message level - * lower than this value will be ignored. */ - private Level level; - - /** The Handlers to which this logger's records are sent */ - private Set handlers; - - /** - * Creates a new <code>Logger</code> with the given name - */ - protected Logger(String name) { - this.name = name; - - // Uses a system property to set the level - String prop = System.getProperty(name + ".LEVEL"); - if(prop != null) { - this.level = Level.parse(prop); - } else { - this.level = Level.INFO; - } - - this.handlers = new HashSet(); - - // By default, log to System.err - this.handlers.add(new StreamHandler(System.err, - new SimpleFormatter())); - } - - /** - * Returns the logger with the given name - */ - public synchronized static Logger getLogger(String name) { - Logger logger = (Logger) loggers.get(name); - if(logger == null) { - logger = new Logger(name); - loggers.put(name, logger); - } - -// Assert.assertTrue(logger != null); (cannot be null) - return(logger); - } - - /** - * Adds a Handler to receive logging messages - */ - public synchronized void addHandler(Handler handler) { - this.handlers.add(handler); - } - - /** - * Returns the Handlers associated with this logger - */ - public synchronized Handler[] getHandlers() { - return((Handler[]) this.handlers.toArray(new Handler[0])); - } - - /** - * Removes a Handler from this logger - */ - public synchronized void removeHandler(Handler handler) { - this.handlers.remove(handler); - } - - /** - * Returns the log level specifying which messages will be logged by - * this logger. - */ - public synchronized Level getLevel() { - return(this.level); - } - - /** - * Sets the log level specifying which messages will be logged by - * this logger. - */ - public synchronized void setLevel(Level level) { - this.level = level; - } - - /** - * Check if a message of the given level would actually be logged by - * this logger. - */ - public synchronized boolean isLoggable(Level msgLevel) { - if(msgLevel.equals(Level.ALL)) { - // Always log Level.ALL messages. Is this a logic error? - return(true); - } else { - return(msgLevel.intValue() >= this.level.intValue()); - } - } - - /** - * Prints the given log record to System.err - */ - public synchronized void log(LogRecord record) { - if(!isLoggable(record.getLevel())) { - // This record is beneath us - return; - } - - if(DEBUG) { - System.out.println("Logging " + record); - } - - // Publish the record to each handler - Iterator iter = this.handlers.iterator(); - while(iter.hasNext()) { - Handler handler = (Handler) iter.next(); - handler.publish(record); - handler.flush(); - } - } - - /** - * Logs a CONFIG message - */ - public synchronized void config(String msg) { - LogRecord record = new LogRecord(Level.CONFIG, msg); - log(record); - } - - /** - * Log a CONFIG message, with an array of object arguments. - */ - public synchronized void config(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.CONFIG, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a CONFIG message, specifying source class and method. - */ - public synchronized void config(String sourceClass, - String sourceMethod, String msg) { - LogRecord record = new LogRecord(Level.CONFIG, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a CONFIG message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void config(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.CONFIG, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Log a procedure entry. - */ - public synchronized void entering(String sourceClass, String sourceMethod) { - LogRecord record = new LogRecord(Level.CONFIG, "Entering method"); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a procedure entry, with parameters. - */ - public synchronized void entering(String sourceClass, String sourceMethod, - Object[] params) { - LogRecord record = new LogRecord(Level.CONFIG, "Entering method"); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Log a procedure return. - */ - public synchronized void exiting(String sourceClass, String sourceMethod) { - LogRecord record = new LogRecord(Level.CONFIG, "Exiting method"); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a procedure return, with parameters. - */ - public synchronized void exiting(String sourceClass, String sourceMethod, - Object[] params) { - LogRecord record = new LogRecord(Level.CONFIG, "Exiting method"); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Logs a FINE message - */ - public synchronized void fine(String msg) { - LogRecord record = new LogRecord(Level.FINE, msg); - log(record); - } - - /** - * Log a FINE message, with an array of object arguments. - */ - public synchronized void fine(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.FINE, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a FINE message, specifying source class and method. - */ - public synchronized void fine(String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(Level.FINE, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a FINE message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void fine(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.FINE, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Logs a FINER message - */ - public synchronized void finer(String msg) { - LogRecord record = new LogRecord(Level.FINER, msg); - log(record); - } - - /** - * Log a FINER message, with an array of object arguments. - */ - public synchronized void finer(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.FINER, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a FINER message, specifying source class and method. - */ - public synchronized void finer(String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(Level.FINER, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a FINER message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void finer(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.FINER, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Logs a FINEST message - */ - public synchronized void finest(String msg) { - LogRecord record = new LogRecord(Level.FINEST, msg); - log(record); - } - - /** - * Log a FINEST message, with an array of object arguments. - */ - public synchronized void finest(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.FINEST, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a FINEST message, specifying source class and method. - */ - public synchronized void finest(String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(Level.FINEST, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a FINEST message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void finest(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.FINEST, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Logs a INFO message - */ - public synchronized void info(String msg) { - LogRecord record = new LogRecord(Level.INFO, msg); - log(record); - } - - /** - * Log a INFO message, with an array of object arguments. - */ - public synchronized void info(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.INFO, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a INFO message, specifying source class and method. - */ - public synchronized void info(String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(Level.INFO, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a INFO message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void info(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.INFO, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Logs a message - */ - public synchronized void log(Level msgLevel, String msg) { - LogRecord record = new LogRecord(msgLevel, msg); - log(record); - } - - /** - * Log a message, with an array of object arguments. - */ - public synchronized void log(Level msgLevel, String msg, Object[] params) { - LogRecord record = new LogRecord(msgLevel, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a message, specifying source class and method. - */ - public synchronized void log(Level msgLevel, String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(msgLevel, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void log(Level msgLevel, String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(msgLevel, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Log a message, specifying source class and method, with - * associated Throwable information. - */ - public synchronized void log(Level msgLevel, String sourceClass, - String sourceMethod, String msg, Throwable thrown) { - LogRecord record = new LogRecord(msgLevel, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setThrown(thrown); - log(record); - } - - /** - * Log a message, with associated Throwable information. - */ - public synchronized void log(Level msgLevel, String msg, Throwable thrown) { - LogRecord record = new LogRecord(msgLevel, msg); - record.setThrown(thrown); - log(record); - } - - /** - * Logs a SEVERE message - */ - public synchronized void severe(String msg) { - LogRecord record = new LogRecord(Level.SEVERE, msg); - log(record); - } - - /** - * Log a SEVERE message, with an array of object arguments. - */ - public synchronized void severe(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.SEVERE, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a SEVERE message, specifying source class and method. - */ - public synchronized void severe(String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(Level.SEVERE, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a SEVERE message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void severe(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.SEVERE, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Log throwing an exception. The logging is done using the FINER - * level. - */ - public synchronized void throwing(String sourceClass, String sourceMethod, - Throwable thrown) { - LogRecord record = new LogRecord(Level.FINER, "THROWN"); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setThrown(thrown); - log(record); - } - - /** - * Logs a WARNING message - */ - public synchronized void warning(String msg) { - LogRecord record = new LogRecord(Level.WARNING, msg); - log(record); - } - - /** - * Log a WARNING message, with an array of object arguments. - */ - public synchronized void warning(String msg, Object[] params) { - LogRecord record = new LogRecord(Level.WARNING, msg); - record.setParameters(params); - log(record); - } - - /** - * Log a WARNING message, specifying source class and method. - */ - public synchronized void warning(String sourceClass, String sourceMethod, - String msg) { - LogRecord record = new LogRecord(Level.WARNING, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - log(record); - } - - /** - * Log a WARNING message, specifying source class and method, with an - * array of object arguments. - */ - public synchronized void warning(String sourceClass, String sourceMethod, - String msg, Object[] params) { - LogRecord record = new LogRecord(Level.WARNING, msg); - record.setSourceClassName(sourceClass); - record.setSourceMethodName(sourceMethod); - record.setParameters(params); - log(record); - } - - /** - * Formats a message. Takes special care when invoking the - * toString() method of objects that might cause NPEs. - */ - public static String format(String format, Object[] objs) { - return org.apache.persistence.admin.Logger.format( format, objs ); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/SimpleFormatter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/SimpleFormatter.java b/geode-core/src/test/java/com/gemstone/persistence/logging/SimpleFormatter.java deleted file mode 100644 index c4a7e58..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/SimpleFormatter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -import java.io.*; -//import java.text.*; -import java.util.*; - -/** - * A Formatter that returns a textual description of a LogRecord - */ -public class SimpleFormatter extends Formatter { - - public String format(LogRecord record) { - StringBuffer sb = new StringBuffer(); - sb.append('['); - sb.append(org.apache.persistence.admin.Logger.formatDate(new Date(record.getMillis()))); - sb.append(' '); - sb.append(Thread.currentThread().getName()); - sb.append("] "); - sb.append(record.getMessage()); - sb.append('\n'); - - if(record.getSourceClassName() != null) { - sb.append(" In "); - sb.append(record.getSourceClassName()); - if(record.getSourceMethodName() != null) { - sb.append("."); - sb.append(record.getSourceMethodName()); - } - sb.append('\n'); - } - - Object[] params = record.getParameters(); - if(params != null) { - for(int i = 0; i < params.length; i++) { - sb.append(params[i]); - sb.append('\n'); - } - } - - if(record.getThrown() != null) { - Throwable thr = record.getThrown(); - StringWriter sw = new StringWriter(); - thr.printStackTrace(new PrintWriter(sw, true)); - sb.append(sw.toString()); - sb.append('\n'); - } - - if (STACK_TRACE) { - Exception thr = new Exception("Stack Trace"); - StringWriter sw = new StringWriter(); - thr.printStackTrace(new PrintWriter(sw, true)); - sb.append(sw.toString()); - sb.append('\n'); - } - - sb.append('\n'); - - return(sb.toString()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/persistence/logging/StreamHandler.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/persistence/logging/StreamHandler.java b/geode-core/src/test/java/com/gemstone/persistence/logging/StreamHandler.java deleted file mode 100644 index a39f9e0..0000000 --- a/geode-core/src/test/java/com/gemstone/persistence/logging/StreamHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.persistence.logging; - -import java.io.*; - -/** - * A <code>StreamHandler</code> exports log records to an - * <code>OutputStream</code>. - */ -public class StreamHandler extends Handler { - - /** The destination PrintWriter */ - private PrintWriter pw; - - /** - * Creates a new <code>StreamHandler</code> that exports log records - * to an <code>OutputStream</code> in a given format. - */ - public StreamHandler(OutputStream stream, Formatter formatter) { - super(); - this.pw = new PrintWriter(stream, true); - this.setFormatter(formatter); - } - - public void close() { - this.pw.close(); - } - - public void flush() { - this.pw.flush(); - } - - public boolean isLoggable(LogRecord record) { - if(this.pw == null) { - return(false); - } else { - return(super.isLoggable(record)); - } - } - - public void publish(LogRecord record) { - Formatter formatter = this.getFormatter(); - pw.print(formatter.format(record)); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/Arrow.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/Arrow.java b/geode-core/src/test/java/com/gemstone/sequence/Arrow.java deleted file mode 100644 index 4274aa9..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/Arrow.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import java.awt.*; -import java.awt.geom.GeneralPath; - -/** - * Created by IntelliJ IDEA. - * User: dsmith - * Date: Nov 12, 2010 - * Time: 12:02:20 PM - * To change this template use File | Settings | File Templates. - */ -public class Arrow { - private static int ARROW_WIDTH=10; - private static int CIRCLE_WIDTH=6; - private static int LABEL_OFFSET=10; - - private final String label; - private final LifelineState startingState; - private final LifelineState endingState; - - public Arrow(String label, LifelineState startingState, LifelineState endingState) { - this.label = label; - this.startingState = startingState; - this.endingState = endingState; - } - - - public void paint(Graphics2D g) { - Rectangle boundary = g.getClipBounds(); - int y = endingState.getStartY(); - - //don't paint if we're not in the clip area - if(y + ARROW_WIDTH < boundary.getMinY() || y - ARROW_WIDTH > boundary.getMaxY()) { - return; - } - - //TODO - we need to clip by X coordinate as well. - - boolean isReflexsive = getStartingLine() == getEndingLine(); - if(isReflexsive) { - paintReflexive(g); - } else { - paintNormal(g); - } - } - - private Lifeline getStartingLine() { - return startingState.getLine(); - } - - private Lifeline getEndingLine() { - return endingState.getLine(); - } - - private void paintReflexive(Graphics2D g) { - Lifeline startingLine = getStartingLine(); - int x = startingLine.getX(); - int y = endingState.getStartY(); - - g.drawArc(x + startingLine.getWidth() - ARROW_WIDTH / 2, y - ARROW_WIDTH, ARROW_WIDTH, ARROW_WIDTH, 90, -180); - g.drawString(label, x + startingLine.getWidth() + LABEL_OFFSET, y); -// GeneralPath path = new GeneralPath(); -// path.moveTo(x, y - ARROW_WIDTH); -// path.quadTo(x, y - ARROW_WIDTH); - } - - private void paintNormal(Graphics2D g) { - Lifeline startingLine = getStartingLine(); - Lifeline endingLine = getEndingLine(); - int x1 = startingLine.getX(); - int x2 = endingLine.getX(); - int y = endingState.getStartY(); - - if(x2 > x1) { - int startX = x1 + startingLine.getWidth(); - int endX = x2; - - GeneralPath path = new GeneralPath(); - path.moveTo(startX, y); - path.lineTo(endX, y); - path.lineTo(endX - ARROW_WIDTH, y - ARROW_WIDTH); - path.moveTo(endX, y); - path.lineTo(endX - ARROW_WIDTH, y + ARROW_WIDTH); - g.draw(path); - g.fillArc(startX, y - CIRCLE_WIDTH/2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360); - g.drawString(label, startX + LABEL_OFFSET, y - LABEL_OFFSET); - } else { - int startX = x1; - int endX = x2 + endingLine.getWidth(); - - GeneralPath path = new GeneralPath(); - path.moveTo(startX, y); - path.lineTo(endX, y); - path.lineTo(endX + ARROW_WIDTH, y - ARROW_WIDTH); - path.moveTo(endX, y); - path.lineTo(endX + ARROW_WIDTH, y + ARROW_WIDTH); - g.draw(path); - int labelWidth = g.getFontMetrics().stringWidth(label); - g.fillArc(startX - CIRCLE_WIDTH/2, y - CIRCLE_WIDTH/2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360); - g.drawString(label, startX - LABEL_OFFSET - labelWidth, y - LABEL_OFFSET); - } - } - - public LifelineState getStartingState() { - return startingState; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/Lifeline.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/Lifeline.java b/geode-core/src/test/java/com/gemstone/sequence/Lifeline.java deleted file mode 100644 index f5de6ac..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/Lifeline.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import java.awt.*; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created by IntelliJ IDEA. - * User: dsmith - * Date: Oct 29, 2010 - * Time: 3:59:02 PM - * To change this template use File | Settings | File Templates. - */ -public class Lifeline { - private List<LifelineState> states; - private final String name; - private final Comparable diagramName; - private int x; - private int width; - - public String getName() { - return name; - } - - public int getX() { - return x; - } - - public int getWidth() { - return width; - } - - public void addState(LifelineState state) { - this.states.add(state); - } - - public Lifeline(Comparable diagramName, String name) { - this.name = name; - this.states = new ArrayList<LifelineState>(); - this.diagramName = diagramName; - } - - public void resize(int x, int lineWidth, long Ybase, double Yscale) { - for(LifelineState state : states) { - state.resize(Yscale, Ybase); - } - - this.x = x; - width = lineWidth; - } - - public void paint(Graphics2D g, StateColorMap colorMap) { - Rectangle boundary = g.getClipBounds(); - if(x > boundary.getMaxX() || x + width < boundary.getMinX()) { - //no need to paint if this line isn't displayed - return; - } - //TODO - we need to clip these to the visible states - for(LifelineState state : states) { - state.paint(g, colorMap); - } - } - - public List<LifelineState> getStates() { - return states; - } - - public LifelineState getStateAt(int y) { - for(LifelineState state : states) { - if(state.getStartY() < y && state.getStartY() + state.getHeight() > y) { - return state; - } - } - return null; - } - - public Comparable getDiagramName() { - return diagramName; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/LifelineState.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/LifelineState.java b/geode-core/src/test/java/com/gemstone/sequence/LifelineState.java deleted file mode 100644 index 2f39c46..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/LifelineState.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import javax.swing.JLabel; - -/** - * Created by IntelliJ IDEA. - * User: dsmith - * Date: Oct 29, 2010 - * Time: 3:45:07 PM - * To change this template use File | Settings | File Templates. - */ -public class LifelineState { - private final long startTime; - private final long endTime; - private final String stateName; - private int startY; - private int height; - private final Lifeline line; - private final Set<Arrow> inboundArrows = new HashSet<Arrow>(); - private static final int ARC_SIZE = 10; - - public int getStartY() { - return startY; - } - - public int getHeight() { - return height; - } - - - public LifelineState(Lifeline line, String stateName, long startTime, long endTime) { - this.line = line; - this.stateName = stateName; - this.startTime = startTime; - this.endTime = endTime; - } - - public void paint(Graphics2D g, StateColorMap colorMap) { - Rectangle bounds = g.getClipBounds(); - if(startY > bounds.getMaxY() || startY+height <bounds.getMinY()) { - return; - } - - int x = line.getX(); - int width = line.getWidth(); - - Color color = colorMap.getColor(stateName); - g.setColor(color); - g.fillRoundRect(x, startY, width, height, ARC_SIZE, ARC_SIZE); - g.setColor(Color.BLACK); - } - - public void highlight(Graphics2D g) { - Rectangle bounds = g.getClipBounds(); - if(startY > bounds.getMaxY() || startY+height <bounds.getMinY()) { - return; - } - - int x = line.getX(); - int width = line.getWidth(); - - g.drawRoundRect(x, startY, width, height, ARC_SIZE, ARC_SIZE); - } - - public void resize(double scale, long base) { - startY = (int) ((startTime - base) * scale); - height = (int) ((endTime - startTime) * scale); - } - - public Component getPopup() { - return new JLabel("<html>Object: " + line.getDiagramName() + "<br>Member: " + line.getName() + "<br>State: " + stateName + "<br>Time:" + new Date(startTime) + "</html>"); - } - - public Lifeline getLine() { - return line; - } - - public void addInboundArrow(Arrow arrow) { - inboundArrows.add(arrow); - } - - public Set<Arrow> getInboundArrows() { - return inboundArrows; - } - - @Override - public String toString() { - return line.getName() + "@" + startTime + ":" + stateName; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/LineMapper.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/LineMapper.java b/geode-core/src/test/java/com/gemstone/sequence/LineMapper.java deleted file mode 100644 index d9c7e08..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/LineMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -/** - * An interface for mapping a lifeline name to a shorter version of the same - * line. This could also consolodate multiple lifelines onto a single line. - * - * The most common case for this is that a lifeline represents a VM that is - * restarted several times. Eg time, the line name changes, but we want to put - * all of the states for that "logical" vm on the same line. - * - */ -public interface LineMapper { - - /** - * Return the short name for this lifeline. - */ - public String getShortNameForLine(String lineName); - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/SequenceDiagram.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/SequenceDiagram.java b/geode-core/src/test/java/com/gemstone/sequence/SequenceDiagram.java deleted file mode 100644 index 1663add..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/SequenceDiagram.java +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created by IntelliJ IDEA. - * User: dsmith - * Date: Oct 29, 2010 - * Time: 4:18:40 PM - * To change this template use File | Settings | File Templates. - */ -public class SequenceDiagram extends JPanel { - - /** - * - */ - private static final Color HIGHLIGHT_COLOR = Color.RED; - - private final List<String> lineNames; - private final Map<String, List<String>> shortLineNames; - private final SortedMap<Comparable, SubDiagram> subDiagrams = new TreeMap<Comparable, SubDiagram>(); - private final StateColorMap colorMap = new StateColorMap(); - private final long minTime; - private final long maxTime; - - private static int PADDING_BETWEEN_LINES = 100; - private static int Y_PADDING = 20; - private static final int STATE_WIDTH = 20; - private static final int LINE_LABEL_BOUNDARY = 5; - private static final int AXIS_SIZE=35; - - private int lineStep; - private int lineWidth; - private Popup mouseover; - private LifelineState mouseoverState; - private LifelineState selectedState; - - public SequenceDiagram(long minTime, long maxTime, List<String> lineNames, LineMapper lineMapper) { - this.lineNames = lineNames; - this.shortLineNames = parseShortNames(lineNames, lineMapper); - this.minTime = minTime; - this.maxTime = maxTime; - int width = getInitialWidth(); - int height = 500; - super.setPreferredSize(new Dimension(width, height)); - resizeMe(width, height); - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - Component source = (Component) e.getSource(); - resizeMe(source.getWidth(), source.getHeight()); - } - }); - setBackground(Color.WHITE); - } - - private Map<String, List<String>> parseShortNames(List<String> lineNames, LineMapper lineMapper) { - Map<String, List<String>> shortNames = new LinkedHashMap<String, List<String>>(lineNames.size()); - for(String name : lineNames) { - String shortName = lineMapper.getShortNameForLine(name); - List<String> list = shortNames.get(shortName); - if(list == null) { - list = new ArrayList<String>(); - shortNames.put(shortName, list); - } - list.add(name); - } - - return shortNames; - } - - public List<Comparable> getSubDiagramsNames() { - return new ArrayList<Comparable>(subDiagrams.keySet()); - - } - - public void addSubDiagram(Comparable name, Map<String, Lifeline> lines, List<Arrow> arrows) { - subDiagrams.put(name, new SubDiagram(name, lines, arrows)); - } - - public void removeSubDiagram(Comparable name) { - this.subDiagrams.remove(name); - } - - private int getInitialWidth() { - return (this.shortLineNames.size()) * PADDING_BETWEEN_LINES; - } - - public void resizeMe(int width, int height) { - this.setPreferredSize(new Dimension(width, height)); - float xZoom = width / (float) getInitialWidth(); - - - long elapsedTime = maxTime - minTime; - double yScale = height / (double) elapsedTime; -// long yBase = (long) (minTime - ((long) Y_PADDING / yScale)); - long yBase = minTime; - lineStep = (int) (PADDING_BETWEEN_LINES * xZoom); - lineWidth = (int) (STATE_WIDTH * xZoom); - - if(subDiagrams.size() <= 0) { - return; - } - - int sublineWidth = lineWidth / subDiagrams.size(); - int sublineIndex = 0; - for(SubDiagram diagram : subDiagrams.values()) { - int lineIndex = 0; - for(List<String> fullNames : shortLineNames.values()) { - for(String name : fullNames) { - Lifeline line = diagram.lifelines.get(name); - if(line != null) { - int lineX = lineIndex * lineStep + sublineIndex * sublineWidth; - line.resize(lineX, sublineWidth, yBase, yScale); - } - } - lineIndex++; - } - sublineIndex++; - } - } - - public void showPopupText(int x, int y, int xOnScreen, int yOnScreen) { - LifelineState state = getStateAt(x, y); - if(state == mouseoverState) { - return; - } - if(mouseover != null) { - mouseover.hide(); - } - if(state == null) { - mouseover = null; - mouseoverState = null; - } else { - Component popupContents = state.getPopup(); - mouseoverState = state; - mouseover = PopupFactory.getSharedInstance().getPopup(this, popupContents, xOnScreen + 20, yOnScreen); - mouseover.show(); - } - } - - public void selectState(int x, int y) { - LifelineState state = getStateAt(x, y); - if(state == selectedState) { - return; - } - - if(selectedState != null) { - fireRepaintOfDependencies(selectedState); - } - - selectedState = state; - - if(state != null) { - fireRepaintOfDependencies(state); - } - } - - private LifelineState getStateAt(int x, int y) { - //TODO - this needs some - //serious optimization to go straight to the right state - // I think we need a tree map of of lines, keyed by x offset - //and a keymap of states keyed by y offset. - //That could make painting faster as well. - List<String> reverseList = new ArrayList<String>(lineNames); - Collections.reverse(reverseList); - for(SubDiagram diagram : subDiagrams.values()) { - for(String name : reverseList) { - Lifeline line = diagram.lifelines.get(name); - if(line != null) { - if(line.getX() < x && line.getX() + line.getWidth() > x) { - LifelineState state = line.getStateAt(y); - if(state != null) { - return state; - } - } - } - } - } - return null; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D) g.create(); - //TODO - we should clip these to the visible lines - for(SubDiagram subDiagram : subDiagrams.values()) { - subDiagram.paintStates(g2, colorMap); - } - - for(SubDiagram subDiagram : subDiagrams.values()) { - subDiagram.paintArrows(g2, colorMap); - } - paintHighlightedComponents(g2, selectedState, new HashSet<LifelineState>()); - } - - private void fireRepaintOfDependencies(LifelineState state) { - //TODO - it might be more efficient to repaint just the changed - //areas, but right now this will do. - repaint(); - } - - private void paintHighlightedComponents(Graphics2D g2, LifelineState endingState, Set<LifelineState> visited) { - if(!visited.add(endingState)) { - //Prevent cycles - return; - } - g2.setColor(HIGHLIGHT_COLOR); - if(endingState != null) { - endingState.highlight(g2); - - for(Arrow arrow : endingState.getInboundArrows()) { - arrow.paint(g2); - paintHighlightedComponents(g2, arrow.getStartingState(), visited); - } - } - - - } - - public long getMinTime() { - return minTime; - } - - public long getMaxTime() { - return maxTime; - } - - public JComponent createMemberAxis() { - return new MemberAxis(); - } - - private class MemberAxis extends JComponent { - public MemberAxis() { - setPreferredSize(new Dimension(getWidth(), AXIS_SIZE)); - SequenceDiagram.this.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int newWidth = e.getComponent().getWidth(); - setPreferredSize(new Dimension(newWidth, AXIS_SIZE)); - revalidate(); - } - }); - } - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - Rectangle bounds = g.getClipBounds(); - int index = 0; - for(String name : shortLineNames.keySet()) { - int nameWidth = g.getFontMetrics().stringWidth(name); - int lineX = lineStep * index; - index++; - if(bounds.getMaxX() < lineX - || bounds.getMinX() > lineX + nameWidth) { - continue; - } - g.setClip(lineX + LINE_LABEL_BOUNDARY, 0, lineStep - + LINE_LABEL_BOUNDARY * 2, getHeight()); - g.drawString(name, lineX + LINE_LABEL_BOUNDARY, AXIS_SIZE / 3); - g.setClip(null); - } - } - } - - public static class SubDiagram { - private final Map<String, Lifeline> lifelines; - private final List<Arrow> arrows; - private final Comparable name; - - public SubDiagram(Comparable name, Map<String, Lifeline> lines, List<Arrow> arrows) { - this.name = name; - this.lifelines = lines; - this.arrows = arrows; - } - - public void paintStates(Graphics2D g2, StateColorMap colorMap) { - for(Lifeline line: lifelines.values()) { - line.paint(g2, colorMap); - } - } - public void paintArrows(Graphics2D g2, StateColorMap colorMap) { - Color lineColor = colorMap.getColor(name); - g2.setColor(lineColor); - for(Arrow arrow: arrows) { - arrow.paint(g2); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/SequencePanel.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/SequencePanel.java b/geode-core/src/test/java/com/gemstone/sequence/SequencePanel.java deleted file mode 100644 index 05a13e3..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/SequencePanel.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; - -/** - * Created by IntelliJ IDEA. - * User: dan - * Date: Oct 28, 2010 - * Time: 10:29:23 PM - * To change this template use File | Settings | File Templates. - */ -public class SequencePanel extends JPanel { - - public SequencePanel(SequenceDiagram sequenceDiagram) { - //Set up the drawing area. - ZoomingPanel drawingPane = new ZoomingPanel(); - drawingPane.setBackground(Color.white); - drawingPane.setSequenceDiagram(sequenceDiagram); - - //Put the drawing area in a scroll pane. - final JScrollPane scroller = new JScrollPane(drawingPane); - scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); - final TimeAxis timeAxis = new TimeAxis(TimeAxis.VERTICAL, - sequenceDiagram.getMinTime(), - sequenceDiagram.getMaxTime()); - timeAxis.setPreferredHeight(drawingPane.getHeight()); - scroller.setRowHeaderView(timeAxis); - scroller.setColumnHeaderView(sequenceDiagram.createMemberAxis()); - int preferredWidth = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 100); - int preferredHeight = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() - 100); - scroller.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); - scroller.setAutoscrolls(true); -// scroller.setPreferredSize(new Dimension(200,200)); - - sequenceDiagram.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int height = e.getComponent().getHeight(); - timeAxis.setPreferredHeight(height); - timeAxis.revalidate(); - } - }); - - BorderLayout layout = new BorderLayout(); -// layout.setHgap(0); -// layout.setVgap(0); - setLayout(layout); - //Lay out this demo. -// add(instructionPanel, BorderLayout.PAGE_START); - add(scroller, BorderLayout.CENTER); - - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - Component source =e.getComponent(); - scroller.setSize(source.getSize()); - scroller.revalidate(); - } - }); - - - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/StateColorMap.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/StateColorMap.java b/geode-core/src/test/java/com/gemstone/sequence/StateColorMap.java deleted file mode 100644 index 8248f27..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/StateColorMap.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import java.awt.*; -import java.util.HashMap; -import java.util.Map; - -import static java.lang.Math.random; - -/** - * Created by IntelliJ IDEA. - * User: dsmith - * Date: Nov 12, 2010 - * Time: 5:05:49 PM - * To change this template use File | Settings | File Templates. - */ -public class StateColorMap { - private Map<Object, Color> colors = new HashMap<Object, Color>(); - private static Color[] PREDEFINED_COLORS = new Color[] { Color.BLUE, Color.BLACK, Color.PINK, Color.CYAN, Color.ORANGE, Color.GREEN}; - - private ColorList colorList = new ColorList(); - - public StateColorMap() { - colors.put("created", Color.GREEN); - colors.put("destroyed", Color.WHITE); - colors.put("persisted", new Color(0, 150, 0)); - } - - - public Color getColor(Object state) { - Color color = colors.get(state); - if(color == null) { - color = colorList.nextColor(); - colors.put(state, color); - } - - return color; - } - - private static class ColorList { - int colorIndex; - - public Color nextColor() { - if(colorIndex < PREDEFINED_COLORS.length) { - return PREDEFINED_COLORS[colorIndex++]; - } else { - return Color.getHSBColor((float)random(), (float)random(), (float)random()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06384849/geode-core/src/test/java/com/gemstone/sequence/TimeAxis.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/sequence/TimeAxis.java b/geode-core/src/test/java/com/gemstone/sequence/TimeAxis.java deleted file mode 100644 index c0a1fac..0000000 --- a/geode-core/src/test/java/com/gemstone/sequence/TimeAxis.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sequence; - -import javax.swing.*; -import java.awt.*; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * Created by IntelliJ IDEA. - * User: dsmith - * Date: Oct 29, 2010 - * Time: 5:24:54 PM - * To change this template use File | Settings | File Templates. - */ -public class TimeAxis extends JComponent { - public static final int HORIZONTAL = 0; - public static final int VERTICAL = 1; - public static final int SIZE = 100; - private static final DateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS"); - - public int orientation; - private long minTime; - private long maxTime; - - public TimeAxis(int orientation, long minTime, long maxTime) { - this.orientation = orientation; - this.minTime = minTime; - this.maxTime = maxTime; - } - - public void setPreferredHeight(int ph) { - setPreferredSize(new Dimension(SIZE, ph)); - } - - public void setPreferredWidth(int pw) { - setPreferredSize(new Dimension(pw, SIZE)); - } - - protected void paintComponent(Graphics g) { - Rectangle drawHere = g.getClipBounds(); - - int height = getHeight(); - - double scale = (maxTime - minTime) / height; - int increment = 30; - // Fill clipping area with dirty brown/orange. - g.setColor(new Color(230, 163, 4)); - g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); - - // Do the ruler labels in a small font that's black. - g.setFont(new Font("SansSerif", Font.PLAIN, 10)); - g.setColor(Color.black); - - // Some vars we need. - int end = 0; - int start = 0; - int tickLength = 0; - String text = null; - - // Use clipping bounds to calculate first and last tick locations. - if (orientation == HORIZONTAL) { - start = (drawHere.x / increment) * increment; - end = (((drawHere.x + drawHere.width) / increment) + 1) - * increment; - } else { - start = (drawHere.y / increment) * increment; - end = (((drawHere.y + drawHere.height) / increment) + 1) - * increment; - } - - // Make a special case of 0 to display the number - // within the rule and draw a units label. - if (start == 0) { - text = DATE_FORMAT.format(new Date(minTime)); - tickLength = 10; - if (orientation == HORIZONTAL) { - g.drawLine(0, SIZE-1, 0, SIZE-tickLength-1); - g.drawString(text, 2, 21); - } else { - g.drawLine(SIZE-1, 0, SIZE-tickLength-1, 0); - g.drawString(text, 9, 10); - } - text = null; - start = increment; - } - - // ticks and labels - for (int i = start; i < end; i += increment) { - tickLength = 10; - text = DATE_FORMAT.format(new Date((long) (minTime + i * scale))); - - if (tickLength != 0) { - if (orientation == HORIZONTAL) { - g.drawLine(i, SIZE-1, i, SIZE-tickLength-1); - if (text != null) - g.drawString(text, i-3, 21); - } else { - g.drawLine(SIZE-1, i, SIZE-tickLength-1, i); - if (text != null) - g.drawString(text, 9, i+3); - } - } - } - } -}
