001 /*
002 * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003 *
004 * This file is part of the Java Data Mining Package (JDMP).
005 * See the NOTICE file distributed with this work for additional
006 * information regarding copyright ownership and licensing.
007 *
008 * JDMP is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation; either version 2
011 * of the License, or (at your option) any later version.
012 *
013 * JDMP is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public
019 * License along with JDMP; if not, write to the
020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021 * Boston, MA 02110-1301 USA
022 */
023
024 package org.jdmp.core.matrix.system;
025
026 import java.util.ArrayList;
027 import java.util.List;
028 import java.util.logging.LogRecord;
029
030 import org.ujmp.core.Matrix;
031 import org.ujmp.core.objectmatrix.stub.AbstractDenseObjectMatrix2D;
032
033 public class LogMatrix extends AbstractDenseObjectMatrix2D {
034 private static final long serialVersionUID = 4054005288748742516L;
035
036 private static LogMatrix matrix = null;
037
038 public static final LogMatrix getInstance() {
039 if (matrix == null) {
040 matrix = new LogMatrix();
041 matrix.setLabel("Log");
042 }
043 return matrix;
044 }
045
046 private LogMatrix() {
047 HandlerWrapper.getInstance().setMatrix(this);
048 }
049
050 public static class HandlerWrapper extends java.util.logging.Handler {
051
052 private static HandlerWrapper handler = null;
053
054 private final List<LogRecord> list = new ArrayList<LogRecord>();
055
056 private Matrix matrix = null;
057
058 private HandlerWrapper() {
059 }
060
061 public static HandlerWrapper getInstance() {
062 if (handler == null) {
063 handler = new HandlerWrapper();
064 }
065 return handler;
066 }
067
068 protected void setMatrix(Matrix matrix) {
069 this.matrix = matrix;
070 }
071
072 @Override
073 public void close() throws SecurityException {
074 }
075
076 @Override
077 public void flush() {
078 }
079
080 @Override
081 public void publish(LogRecord record) {
082 record.setParameters(new Object[] { Runtime.getRuntime().freeMemory(),
083 Runtime.getRuntime() });
084 list.add(record);
085 if (matrix != null) {
086 matrix.notifyGUIObject();
087 }
088 }
089
090 public List<LogRecord> getList() {
091 return list;
092 }
093
094 }
095
096 public long[] getSize() {
097 return new long[] { HandlerWrapper.getInstance().getList().size(), 7 };
098 }
099
100 @Override
101 public boolean isReadOnly() {
102 return true;
103 }
104
105 public Object getObject(long row, long column) {
106 return getObject((int) row, (int) column);
107 }
108
109 public Object getObject(int row, int column) {
110 LogRecord record = HandlerWrapper.getInstance().getList().get(row);
111 switch (column) {
112 case 0:
113 return record.getMillis();
114 case 1:
115 return record.getLevel();
116 case 2:
117 return record.getMessage();
118 case 3:
119 return record.getSourceClassName();
120 case 4:
121 return record.getSourceMethodName();
122 case 5:
123 return record.getParameters()[0];
124 case 6:
125 return record.getThrown();
126 }
127 return null;
128 }
129
130 public void setObject(Object o, long row, long column) {
131 }
132
133 public void setObject(Object o, int row, int column) {
134 }
135
136 }