Sandbox-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 1825 discussions
Author: tchemit
Date: 2010-05-05 12:41:12 +0200 (Wed, 05 May 2010)
New Revision: 408
Url: http://nuiton.org/repositories/revision/sandbox/408
Log:
test
Added:
sandbox-test/
1
0
r407 - in testTopiaPostgresError/trunk: . src/main/java/org/nuiton/test/topia src/main/resources
by fdesbois@users.nuiton.org 21 Apr '10
by fdesbois@users.nuiton.org 21 Apr '10
21 Apr '10
Author: fdesbois
Date: 2010-04-21 18:06:34 +0200 (Wed, 21 Apr 2010)
New Revision: 407
Log:
Stop execution after 1 hour (not nbExecutions which is not efficient). Locks method is added but not used anymore -> error #546 in ToPIA resolve issue on ConcurrentModificationException.
Modified:
testTopiaPostgresError/trunk/pom.xml
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
Modified: testTopiaPostgresError/trunk/pom.xml
===================================================================
--- testTopiaPostgresError/trunk/pom.xml 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/pom.xml 2010-04-21 16:06:34 UTC (rev 407)
@@ -141,7 +141,7 @@
<!-- libraries version -->
<i18n.version>1.2.1</i18n.version>
<nuitonutils.version>1.2.2</nuitonutils.version>
- <topia.version>2.3.3-SNAPSHOT</topia.version>
+ <topia.version>2.4-SNAPSHOT</topia.version>
</properties>
<!-- ************************************************************* -->
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-21 16:06:34 UTC (rev 407)
@@ -1,9 +1,10 @@
package org.nuiton.test.topia;
+import java.util.ConcurrentModificationException;
import java.util.TimerTask;
-import java.util.logging.Level;
import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,18 +32,21 @@
protected String name;
- protected int currentExecution;
+ protected int nbHours;
- public int nbExecutions;
+// protected int currentExecution;
+// public int nbExecutions;
+
protected static long globalStart = System.currentTimeMillis();
protected static final Object lock = new Object();
protected static Boolean token = false;
- public AbstractThread(int nbExecutions, String name) {
+ public AbstractThread(String name) {
this.name = name;
- this.nbExecutions = nbExecutions * 1000;
+ this.nbHours = 1;
+// this.nbExecutions = nbExecutions * 1000;
}
@Override
@@ -51,54 +55,40 @@
startTime = System.currentTimeMillis();
if (logger.isInfoEnabled()) {
- logger.info("Start " + name + " for " + nbExecutions +
- " executions after " +
+ logger.info("Start " + name + " for " + nbHours + " hour(s) after " +
DurationFormatUtils.formatDurationHMS(
startTime - globalStart));
}
- for (currentExecution = 0; currentExecution < nbExecutions;
- currentExecution ++) {
+ while(true) {
if (!manager.isStopped()) {
try {
- synchronized (lock) {
- // Do not stop waiting until token is free
- while (token) {
- if (logger.isDebugEnabled()) {
- logger.debug(name + " waiting...");
- }
- lock.wait();
- if (logger.isDebugEnabled()) {
- logger.debug(name + " no longer waiting");
- }
+ // Execute
+ String message = execute();
+
+ // Check message to display it and may stop execution
+ // depends on current time
+ if (message != null) {
+ long duration = System.currentTimeMillis() - startTime;
+ if (logger.isInfoEnabled()) {
+ logger.info(name + " : " + message + " after " +
+ DurationFormatUtils.formatDurationHMS(duration));
}
- // Take the token to lock other thread
- if (logger.isDebugEnabled()) {
- logger.debug(name + " take the token");
+
+ int hour = Integer.parseInt(
+ DurationFormatUtils.formatDuration(duration, "H"));
+
+ if (hour == nbHours) {
+ break;
}
- token = true;
}
- if (logger.isDebugEnabled()) {
- logger.debug(name + " execute...");
+
+ } catch (ConcurrentModificationException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Concurrent error", eee);
}
- // Execute
- execute();
- synchronized (lock) {
- if (logger.isDebugEnabled()) {
- logger.debug(name + " release the token");
- }
- // Release the token and notify other that the token
- // is free
- token = false;
- lock.notifyAll();
- }
- // Sleep to permit the unlocked Thread to have time to take
- // the token
- if (logger.isDebugEnabled()) {
- logger.debug(name + " go to sleep a while");
- }
- Thread.sleep(200);
-
+ // Will stop the application
+ manager.stopTest();
} catch (InterruptedException eee) {
if (logger.isErrorEnabled()) {
logger.error("Interrupted during sleep or wait", eee);
@@ -121,6 +111,47 @@
}
}
- protected abstract void execute()
+ public void lock() throws InterruptedException {
+ synchronized (lock) {
+ // Do not stop waiting until token is free
+ while (token) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " waiting...");
+ }
+ lock.wait();
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " no longer waiting");
+ }
+ }
+ // Take the token to lock other thread
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " take the token");
+ }
+ token = true;
+ }
+ }
+
+ public void unlock() throws InterruptedException {
+ synchronized (lock) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " release the token");
+ }
+ // Release the token and notify other that the token
+ // is free
+ token = false;
+ lock.notifyAll();
+ }
+ }
+
+ public void pause() throws InterruptedException {
+ // Pause the thread a while (not essential but avoid doing lots of
+ // actions in a few time)
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " go to sleep a while");
+ }
+ Thread.sleep(200);
+ }
+
+ protected abstract String execute()
throws TopiaException, InterruptedException;
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-21 16:06:34 UTC (rev 407)
@@ -26,14 +26,14 @@
protected int tic;
public ReadThread() {
- // 15 executions during approximatively 1 hour
- super(15, ReadThread.class.getName());
+ super(ReadThread.class.getName());
}
@Override
- protected synchronized void execute()
+ protected synchronized String execute()
throws TopiaException, InterruptedException {
TopiaContext transaction = null;
+ String message = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -48,19 +48,15 @@
tic++;
- if ((tic % 300 == 0) && logger.isInfoEnabled()) {
- long stopTime = System.currentTimeMillis();
- long time = stopTime - startTime;
-
- logger.info(versions.size() + " values read after " +
- DurationFormatUtils.formatDurationHMS(time) +
- " (exec " + currentExecution + ")");
+ if (tic % 300 == 0) {
+ message = versions.size() + " values read";
}
} finally {
if (transaction != null) {
transaction.closeContext();
}
}
+ return message;
}
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-21 16:06:34 UTC (rev 407)
@@ -29,8 +29,7 @@
protected int tic;
public WriteThread() {
- // 15 executions during approximatively 1 hour
- super(15, WriteThread.class.getName());
+ super(WriteThread.class.getName());
}
/**
@@ -39,12 +38,14 @@
* The field version is used to save the increment global (total number
* of saved).
*
+ * @return message each 300 executions
* @throws TopiaException
* @throws InterruptedException
*/
@Override
- protected synchronized void execute()
+ protected synchronized String execute()
throws TopiaException, InterruptedException {
+ String message = null;
TopiaContext transaction = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -76,6 +77,7 @@
dao.delete(exist);
increment++;
transaction.commitTransaction();
+ pause();
}
// UPDATE if alea is divided by 20
} else if (alea % 20 == 0) {
@@ -98,10 +100,10 @@
exist.setVersion(String.valueOf(increment));
increment++;
transaction.commitTransaction();
+ pause();
}
// CREATE if alea is divided by 10
} else if (alea % 10 == 0) {
-
TMSVersion create = dao.create(TMSVersion.VERSION,
String.valueOf(increment));
@@ -109,26 +111,26 @@
logger.debug("create the " + increment + " entry id = "
+ create.getTopiaId());
}
-
increment ++;
transaction.commitTransaction();
+ pause();
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("do nothing");
+ }
}
tic++;
- if ((tic % 300 == 0) && logger.isInfoEnabled()) {
- long stopTime = System.currentTimeMillis();
- long time = stopTime - startTime;
-
- logger.info(increment + " create/update or delete actions" +
- " after " + DurationFormatUtils.formatDurationHMS(time) +
- " (exec " + currentExecution + ")");
+ if (tic % 300 == 0) {
+ message = increment + " create/update or delete actions";
}
} finally {
if (transaction != null) {
transaction.closeContext();
}
}
+ return message;
}
}
Modified: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-21 16:06:34 UTC (rev 407)
@@ -13,4 +13,6 @@
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
\ No newline at end of file
+log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
+
+log4j.logger.org.nuiton.test.topia=DEBUG
\ No newline at end of file
1
0
r406 - in testTopiaPostgresError/trunk/src/main: java/org/nuiton/test/topia resources
by fdesbois@users.nuiton.org 21 Apr '10
by fdesbois@users.nuiton.org 21 Apr '10
21 Apr '10
Author: fdesbois
Date: 2010-04-21 11:27:50 +0200 (Wed, 21 Apr 2010)
New Revision: 406
Log:
Third version :
- no more ConcurrentException (token + lock)
- use Timer and change superclass of Thread to TimerTask to use periodically execution (each 3 hours)
- The execution takes approximatively 1 hour, so 2 hours of inactivity before restarting the thread
Modified:
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -1,6 +1,8 @@
package org.nuiton.test.topia;
+import java.util.TimerTask;
+import java.util.logging.Level;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.nuiton.topia.TopiaException;
import org.slf4j.Logger;
@@ -17,7 +19,7 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public abstract class AbstractThread implements Runnable {
+public abstract class AbstractThread extends TimerTask {
private static final Logger logger =
LoggerFactory.getLogger(AbstractThread.class);
@@ -25,51 +27,92 @@
protected TestManager manager = TestManager.getInstance();
- protected volatile boolean stop;
-
protected long startTime;
-
- protected long startMilliseconds;
protected String name;
- public AbstractThread(long startMilliseconds, String name) {
- this.startMilliseconds = startMilliseconds;
+ protected int currentExecution;
+
+ public int nbExecutions;
+
+ protected static long globalStart = System.currentTimeMillis();
+
+ protected static final Object lock = new Object();
+ protected static Boolean token = false;
+
+ public AbstractThread(int nbExecutions, String name) {
this.name = name;
+ this.nbExecutions = nbExecutions * 1000;
}
- public synchronized void stop() {
- stop = true;
- }
-
@Override
public void run() {
+ startTime = System.currentTimeMillis();
+
if (logger.isInfoEnabled()) {
- logger.info("Start " + name + " in " + startMilliseconds + "ms");
+ logger.info("Start " + name + " for " + nbExecutions +
+ " executions after " +
+ DurationFormatUtils.formatDurationHMS(
+ startTime - globalStart));
}
- startTime = System.currentTimeMillis();
- try {
- Thread.sleep(startMilliseconds);
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
- }
+ for (currentExecution = 0; currentExecution < nbExecutions;
+ currentExecution ++) {
+ if (!manager.isStopped()) {
+ try {
+ synchronized (lock) {
+ // Do not stop waiting until token is free
+ while (token) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " waiting...");
+ }
+ lock.wait();
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " no longer waiting");
+ }
+ }
+ // Take the token to lock other thread
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " take the token");
+ }
+ token = true;
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " execute...");
+ }
+ // Execute
+ execute();
+ synchronized (lock) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " release the token");
+ }
+ // Release the token and notify other that the token
+ // is free
+ token = false;
+ lock.notifyAll();
+ }
+ // Sleep to permit the unlocked Thread to have time to take
+ // the token
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " go to sleep a while");
+ }
+ Thread.sleep(200);
- while(!stop) {
- try {
- execute();
- } catch (TopiaException eee) {
- long stopTime = System.currentTimeMillis();
- if (logger.isErrorEnabled()) {
- logger.error("ERROR after " +
- DurationFormatUtils.formatDurationHMS(
- stopTime - startTime), eee);
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Interrupted during sleep or wait", eee);
+ }
+ } catch (TopiaException eee) {
+ long stopTime = System.currentTimeMillis();
+ if (logger.isErrorEnabled()) {
+ logger.error("ERROR after " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime), eee);
+ }
+ // Will stop the application
+ manager.stopTest();
}
- // Will stop the application
- manager.stopTest();
}
}
@@ -78,5 +121,6 @@
}
}
- protected abstract void execute() throws TopiaException;
+ protected abstract void execute()
+ throws TopiaException, InterruptedException;
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -26,11 +26,13 @@
protected int tic;
public ReadThread() {
- super(1000, ReadThread.class.getName());
+ // 15 executions during approximatively 1 hour
+ super(15, ReadThread.class.getName());
}
@Override
- protected synchronized void execute() throws TopiaException {
+ protected synchronized void execute()
+ throws TopiaException, InterruptedException {
TopiaContext transaction = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -44,22 +46,16 @@
logger.debug("Reading " + versions.size() + " entries");
}
- Thread.sleep(500);
-
tic++;
- if ((tic % 100 == 0) && logger.isInfoEnabled()) {
+ if ((tic % 300 == 0) && logger.isInfoEnabled()) {
long stopTime = System.currentTimeMillis();
long time = stopTime - startTime;
logger.info(versions.size() + " values read after " +
- DurationFormatUtils.formatDurationHMS(time));
+ DurationFormatUtils.formatDurationHMS(time) +
+ " (exec " + currentExecution + ")");
}
-
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
} finally {
if (transaction != null) {
transaction.closeContext();
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -3,15 +3,12 @@
import java.util.Locale;
import java.util.Properties;
-import java.util.logging.Level;
+import java.util.Timer;
import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.migration.MigrationServiceDAOHelper;
-import org.nuiton.topia.migration.TMSVersion;
-import org.nuiton.topia.migration.TMSVersionDAO;
import org.nuiton.topia.migration.TMSVersionImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,8 +29,6 @@
private static final Logger logger =
LoggerFactory.getLogger(TestManager.class);
-// protected ApplicationConfig configuration;
-
protected static TestManager instance;
protected Properties configuration;
@@ -42,6 +37,16 @@
protected ReadThread readThread;
+ protected Timer readTimer;
+
+ protected Timer writeTimer;
+
+ private static final long THREE_HOURS_PERIOD = 10800000;
+
+ protected volatile boolean stop;
+
+ public static final Object waitForStop = new Object();
+
public static TestManager getInstance() {
if (instance == null) {
instance = new TestManager();
@@ -68,73 +73,44 @@
TMSVersionImpl.class.getName());
I18n.init(Locale.FRANCE);
-
- // Create first entry
-// TopiaContext transaction = null;
-// try {
-// if (logger.isInfoEnabled()) {
-// logger.info("Open first transaction to create main entry");
-// }
-// transaction = TopiaContextFactory.getContext(configuration).
-// beginTransaction();
-// TMSVersionDAO dao =
-// MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
-//
-// TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
-//
-// mainTopiaId = entry.getTopiaId();
-// if (logger.isInfoEnabled()) {
-// logger.info("Save the entry with id = " + mainTopiaId);
-// }
-// transaction.commitTransaction();
-//
-// } catch (TopiaException eee) {
-// if (logger.isErrorEnabled()) {
-// logger.error("Error when create the first entry : ", eee);
-// }
-// } finally {
-// if (transaction != null) {
-// try {
-// transaction.closeContext();
-// } catch (TopiaException eee) {
-// if (logger.isErrorEnabled()) {
-// logger.error("Error on closeContext : ", eee);
-// }
-// }
-// }
-// }
}
public TopiaContext getRootContext() throws TopiaNotFoundException {
return TopiaContextFactory.getContext(configuration);
}
+ public boolean isStopped() {
+ return stop;
+ }
+
public void startTest() {
- if (writeThread == null) {
- writeThread = new WriteThread();
- new Thread(writeThread).start();
+ // Execution of thread during 1 hour + 2 hours of inactivity
+ if (readTimer == null) {
+ readTimer = new Timer();
+ readTimer.schedule(new ReadThread(), 1000, THREE_HOURS_PERIOD);
}
- if (readThread == null) {
- readThread = new ReadThread();
- new Thread(readThread).start();
+ if (writeTimer == null) {
+ writeTimer = new Timer();
+ writeTimer.schedule(new WriteThread(), 0, THREE_HOURS_PERIOD);
}
}
public void stopTest() {
- if (writeThread != null) {
- writeThread.stop();
- writeThread = null;
- }
- if (readThread != null) {
- readThread.stop();
- readThread = null;
- }
- try {
- getRootContext().closeContext();
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error on close root context : ", eee);
+ if (!stop) {
+ stop = true;
+ if (readTimer != null) {
+ readTimer.cancel();
}
+ if (writeTimer != null) {
+ writeTimer.cancel();
+ }
+ try {
+ getRootContext().closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on close root context : ", eee);
+ }
+ }
}
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -29,7 +29,8 @@
protected int tic;
public WriteThread() {
- super(0, WriteThread.class.getName());
+ // 15 executions during approximatively 1 hour
+ super(15, WriteThread.class.getName());
}
/**
@@ -39,9 +40,11 @@
* of saved).
*
* @throws TopiaException
+ * @throws InterruptedException
*/
@Override
- protected synchronized void execute() throws TopiaException {
+ protected synchronized void execute()
+ throws TopiaException, InterruptedException {
TopiaContext transaction = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -53,8 +56,6 @@
// Create an alea between 0 and 1000
int alea = (int)(random.nextFloat() * 1000);
- boolean actionDone = false;
-
// DELETE if alea is divided by 100
if (alea % 100 == 0) {
// Alea number over number of existing entries
@@ -75,7 +76,6 @@
dao.delete(exist);
increment++;
transaction.commitTransaction();
- actionDone = true;
}
// UPDATE if alea is divided by 20
} else if (alea % 20 == 0) {
@@ -98,7 +98,6 @@
exist.setVersion(String.valueOf(increment));
increment++;
transaction.commitTransaction();
- actionDone = true;
}
// CREATE if alea is divided by 10
} else if (alea % 10 == 0) {
@@ -113,24 +112,18 @@
increment ++;
transaction.commitTransaction();
- actionDone = true;
}
- Thread.sleep(100);
-
tic++;
- if ((tic % 600 == 0) && logger.isInfoEnabled()) {
+ if ((tic % 300 == 0) && logger.isInfoEnabled()) {
long stopTime = System.currentTimeMillis();
long time = stopTime - startTime;
logger.info(increment + " create/update or delete actions" +
- " after " + DurationFormatUtils.formatDurationHMS(time));
+ " after " + DurationFormatUtils.formatDurationHMS(time) +
+ " (exec " + currentExecution + ")");
}
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
} finally {
if (transaction != null) {
transaction.closeContext();
Modified: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-21 09:27:50 UTC (rev 406)
@@ -13,7 +13,4 @@
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
-
-log4j.logger.org.nuiton.test.topia=DEBUG
-log4j.logger.org.nuiton.topia=INFO
\ No newline at end of file
+log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
\ No newline at end of file
1
0
r405 - in testTopiaPostgresError/trunk: . src/main/java/org/nuiton/test/topia src/main/resources
by fdesbois@users.nuiton.org 18 Apr '10
by fdesbois@users.nuiton.org 18 Apr '10
18 Apr '10
Author: fdesbois
Date: 2010-04-18 12:14:54 +0200 (Sun, 18 Apr 2010)
New Revision: 405
Log:
2nd version : two thread one read and one write.
Added:
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
Removed:
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
Modified:
testTopiaPostgresError/trunk/README.txt
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
Modified: testTopiaPostgresError/trunk/README.txt
===================================================================
--- testTopiaPostgresError/trunk/README.txt 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/README.txt 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,8 @@
+To run the test :
+mvn clean install tomcat:run -Dtopiatest.home=/home/fdesbois/.local/topiatest
+
+Then open a browser to start the appli :
+http://localhost:8080/test-topia-postgres-error/start
+
+To stop the appli :
+http://localhost:8080/test-topia-postgres-error/stop
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,82 @@
+
+package org.nuiton.test.topia;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AbstractThread
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public abstract class AbstractThread implements Runnable {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(AbstractThread.class);
+
+
+ protected TestManager manager = TestManager.getInstance();
+
+ protected volatile boolean stop;
+
+ protected long startTime;
+
+ protected long startMilliseconds;
+
+ protected String name;
+
+ public AbstractThread(long startMilliseconds, String name) {
+ this.startMilliseconds = startMilliseconds;
+ this.name = name;
+ }
+
+ public synchronized void stop() {
+ stop = true;
+ }
+
+ @Override
+ public void run() {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Start " + name + " in " + startMilliseconds + "ms");
+ }
+
+ startTime = System.currentTimeMillis();
+ try {
+ Thread.sleep(startMilliseconds);
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ }
+
+ while(!stop) {
+ try {
+ execute();
+ } catch (TopiaException eee) {
+ long stopTime = System.currentTimeMillis();
+ if (logger.isErrorEnabled()) {
+ logger.error("ERROR after " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime), eee);
+ }
+ // Will stop the application
+ manager.stopTest();
+ }
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Stop " + name);
+ }
+ }
+
+ protected abstract void execute() throws TopiaException;
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,70 @@
+
+package org.nuiton.test.topia;
+
+import java.util.List;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ThreadTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class ReadThread extends AbstractThread {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ReadThread.class);
+
+ protected int tic;
+
+ public ReadThread() {
+ super(1000, ReadThread.class.getName());
+ }
+
+ @Override
+ protected synchronized void execute() throws TopiaException {
+ TopiaContext transaction = null;
+ try {
+ transaction = manager.getRootContext().beginTransaction();
+
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ List<TMSVersion> versions = dao.findAll();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Reading " + versions.size() + " entries");
+ }
+
+ Thread.sleep(500);
+
+ tic++;
+
+ if ((tic % 100 == 0) && logger.isInfoEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ long time = stopTime - startTime;
+
+ logger.info(versions.size() + " values read after " +
+ DurationFormatUtils.formatDurationHMS(time));
+ }
+
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ transaction.closeContext();
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -50,7 +50,7 @@
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- TopiaManager.getInstance().startTest();
+ TestManager.getInstance().startTest();
}
/**
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -32,7 +32,7 @@
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- TopiaManager.getInstance().stopTest();
+ TestManager.getInstance().stopTest();
}
/**
Copied: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java (from rev 404, testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java)
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,141 @@
+
+package org.nuiton.test.topia;
+
+import java.util.Locale;
+import java.util.Properties;
+import java.util.logging.Level;
+import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.nuiton.topia.migration.TMSVersionImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TopiaManager
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class TestManager {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(TestManager.class);
+
+// protected ApplicationConfig configuration;
+
+ protected static TestManager instance;
+
+ protected Properties configuration;
+
+ protected WriteThread writeThread;
+
+ protected ReadThread readThread;
+
+ public static TestManager getInstance() {
+ if (instance == null) {
+ instance = new TestManager();
+ }
+ return instance;
+ }
+
+ private TestManager() {
+ configuration = new Properties();
+ // Config for Postgres
+ configuration.put("hibernate.hbm2ddl.auto", "create");
+ configuration.put("hibernate.show_sql", "false");
+ configuration.put("hibernate.dialect",
+ "org.hibernate.dialect.PostgreSQLDialect");
+ configuration.put("hibernate.connection.username","topia");
+ configuration.put("hibernate.connection.password","");
+ configuration.put("hibernate.connection.driver_class",
+ "org.postgresql.Driver");
+ configuration.put("hibernate.connection.url",
+ "jdbc:postgresql:topiatest");
+
+ // Config for Topia service Migration
+ configuration.put("topia.persistence.classes",
+ TMSVersionImpl.class.getName());
+
+ I18n.init(Locale.FRANCE);
+
+ // Create first entry
+// TopiaContext transaction = null;
+// try {
+// if (logger.isInfoEnabled()) {
+// logger.info("Open first transaction to create main entry");
+// }
+// transaction = TopiaContextFactory.getContext(configuration).
+// beginTransaction();
+// TMSVersionDAO dao =
+// MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+//
+// TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
+//
+// mainTopiaId = entry.getTopiaId();
+// if (logger.isInfoEnabled()) {
+// logger.info("Save the entry with id = " + mainTopiaId);
+// }
+// transaction.commitTransaction();
+//
+// } catch (TopiaException eee) {
+// if (logger.isErrorEnabled()) {
+// logger.error("Error when create the first entry : ", eee);
+// }
+// } finally {
+// if (transaction != null) {
+// try {
+// transaction.closeContext();
+// } catch (TopiaException eee) {
+// if (logger.isErrorEnabled()) {
+// logger.error("Error on closeContext : ", eee);
+// }
+// }
+// }
+// }
+ }
+
+ public TopiaContext getRootContext() throws TopiaNotFoundException {
+ return TopiaContextFactory.getContext(configuration);
+ }
+
+ public void startTest() {
+ if (writeThread == null) {
+ writeThread = new WriteThread();
+ new Thread(writeThread).start();
+ }
+ if (readThread == null) {
+ readThread = new ReadThread();
+ new Thread(readThread).start();
+ }
+ }
+
+ public void stopTest() {
+ if (writeThread != null) {
+ writeThread.stop();
+ writeThread = null;
+ }
+ if (readThread != null) {
+ readThread.stop();
+ readThread = null;
+ }
+ try {
+ getRootContext().closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on close root context : ", eee);
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Deleted: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -1,96 +0,0 @@
-
-package org.nuiton.test.topia;
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.migration.MigrationServiceDAOHelper;
-import org.nuiton.topia.migration.TMSVersion;
-import org.nuiton.topia.migration.TMSVersionDAO;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ThreadTest
- *
- * Created: 16 avr. 2010
- *
- * @author fdesbois
- */
-public class ThreadTest implements Runnable {
-
- private static final Logger logger =
- LoggerFactory.getLogger(ThreadTest.class);
-
- protected TopiaManager manager = TopiaManager.getInstance();
-
- protected volatile boolean stop;
-
- protected long startTime;
-
- public synchronized void stop() {
- stop = true;
- }
-
- @Override
- public void run() {
-
- if (logger.isInfoEnabled()) {
- logger.info("Start Thread");
- }
-
- startTime = System.currentTimeMillis();
-
- while(!stop) {
- try {
- execute();
- } catch (TopiaException eee) {
- long stopTime = System.currentTimeMillis();
- if (logger.isErrorEnabled()) {
- logger.error("ERROR after " +
- DurationFormatUtils.formatDurationHMS(
- stopTime - startTime), eee);
- }
- manager.stopTest();
- }
- }
-
- if (logger.isInfoEnabled()) {
- logger.info("Stop Thread");
- }
- }
-
- protected synchronized void execute() throws TopiaException {
- TopiaContext transaction = null;
- try {
- transaction = manager.getRootContext().beginTransaction();
-
- TMSVersionDAO dao =
- MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
-
- TMSVersion version = dao.findByTopiaId(manager.getMainTopiaId());
-
- Thread.sleep(100);
-
- int value = Integer.parseInt(version.getVersion());
- version.setVersion(String.valueOf(value + 1));
-
- if ((value % 500 == 0) && logger.isInfoEnabled()) {
- long stopTime = System.currentTimeMillis();
- logger.info("Value is " + version.getVersion() + " after " +
- DurationFormatUtils.formatDurationHMS(stopTime - startTime));
- }
-
- transaction.commitTransaction();
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
- } finally {
- if (transaction != null) {
- transaction.closeContext();
- }
- }
- }
-
-}
Deleted: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -1,136 +0,0 @@
-
-package org.nuiton.test.topia;
-
-import java.util.Locale;
-import java.util.Properties;
-import java.util.logging.Level;
-import org.nuiton.i18n.I18n;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.migration.MigrationServiceDAOHelper;
-import org.nuiton.topia.migration.TMSVersion;
-import org.nuiton.topia.migration.TMSVersionDAO;
-import org.nuiton.topia.migration.TMSVersionImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TopiaManager
- *
- * Created: 16 avr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class TopiaManager {
-
- private static final Logger logger =
- LoggerFactory.getLogger(TopiaManager.class);
-
-// protected ApplicationConfig configuration;
-
- protected static TopiaManager instance;
-
- protected Properties configuration;
-
- protected String mainTopiaId;
-
- protected ThreadTest thread;
-
- public static TopiaManager getInstance() {
- if (instance == null) {
- instance = new TopiaManager();
- }
- return instance;
- }
-
- private TopiaManager() {
- configuration = new Properties();
- // Config for Postgres
- configuration.put("hibernate.hbm2ddl.auto", "create");
- configuration.put("hibernate.show_sql", "false");
- configuration.put("hibernate.dialect",
- "org.hibernate.dialect.PostgreSQLDialect");
- configuration.put("hibernate.connection.username","topia");
- configuration.put("hibernate.connection.password","");
- configuration.put("hibernate.connection.driver_class",
- "org.postgresql.Driver");
- configuration.put("hibernate.connection.url",
- "jdbc:postgresql:topiatest");
-
- // Config for Topia service Migration
- configuration.put("topia.persistence.classes",
- TMSVersionImpl.class.getName());
-
- I18n.init(Locale.FRANCE);
-
- // Create first entry
- TopiaContext transaction = null;
- try {
- if (logger.isInfoEnabled()) {
- logger.info("Open first transaction to create main entry");
- }
- transaction = TopiaContextFactory.getContext(configuration).
- beginTransaction();
- TMSVersionDAO dao =
- MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
-
- TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
-
- mainTopiaId = entry.getTopiaId();
- if (logger.isInfoEnabled()) {
- logger.info("Save the entry with id = " + mainTopiaId);
- }
- transaction.commitTransaction();
-
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error when create the first entry : ", eee);
- }
- } finally {
- if (transaction != null) {
- try {
- transaction.closeContext();
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error on closeContext : ", eee);
- }
- }
- }
- }
- }
-
- public TopiaContext getRootContext() throws TopiaNotFoundException {
- return TopiaContextFactory.getContext(configuration);
- }
-
- public String getMainTopiaId() {
- return mainTopiaId;
- }
-
- public void startTest() {
- if (thread == null) {
- thread = new ThreadTest();
- new Thread(thread).start();
- }
- }
-
- public void stopTest() {
- if (thread != null) {
- thread.stop();
- try {
- getRootContext().closeContext();
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error on close root context : ", eee);
- }
- }
- }
- }
-
-}
Copied: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java (from rev 404, testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java)
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,141 @@
+
+package org.nuiton.test.topia;
+
+import java.util.Random;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ThreadTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class WriteThread extends AbstractThread {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(WriteThread.class);
+
+ protected int increment;
+
+ protected int tic;
+
+ public WriteThread() {
+ super(0, WriteThread.class.getName());
+ }
+
+ /**
+ * Create an entry at random over 10, update an existing one over 20
+ * and delete one over 100.
+ * The field version is used to save the increment global (total number
+ * of saved).
+ *
+ * @throws TopiaException
+ */
+ @Override
+ protected synchronized void execute() throws TopiaException {
+ TopiaContext transaction = null;
+ try {
+ transaction = manager.getRootContext().beginTransaction();
+
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ Random random = new Random();
+ // Create an alea between 0 and 1000
+ int alea = (int)(random.nextFloat() * 1000);
+
+ boolean actionDone = false;
+
+ // DELETE if alea is divided by 100
+ if (alea % 100 == 0) {
+ // Alea number over number of existing entries
+ int alea2 = (int)(random.nextFloat() * dao.size());
+
+ // Only one row will be return
+ TopiaQuery query = dao.createQuery().setLimit(alea2, alea2 + 1);
+ TMSVersion exist = dao.findByQuery(query);
+
+ if (exist == null && logger.isWarnEnabled()) {
+ logger.warn("the entry doesn't exist in position " +
+ alea2 + " ?!?");
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("delete the " + increment + " entry id = "
+ + exist.getTopiaId());
+ }
+ dao.delete(exist);
+ increment++;
+ transaction.commitTransaction();
+ actionDone = true;
+ }
+ // UPDATE if alea is divided by 20
+ } else if (alea % 20 == 0) {
+
+ // Alea number over number of existing entries
+ int alea2 = (int)(random.nextFloat() * dao.size());
+
+ // Only one row will be return
+ TopiaQuery query = dao.createQuery().setLimit(alea2, alea2 + 1);
+ TMSVersion exist = dao.findByQuery(query);
+
+ if (exist == null && logger.isWarnEnabled()) {
+ logger.warn("the entry doesn't exist in position " +
+ alea2 + " ?!?");
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("update the " + increment + " entry id = "
+ + exist.getTopiaId());
+ }
+ exist.setVersion(String.valueOf(increment));
+ increment++;
+ transaction.commitTransaction();
+ actionDone = true;
+ }
+ // CREATE if alea is divided by 10
+ } else if (alea % 10 == 0) {
+
+ TMSVersion create = dao.create(TMSVersion.VERSION,
+ String.valueOf(increment));
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("create the " + increment + " entry id = "
+ + create.getTopiaId());
+ }
+
+ increment ++;
+ transaction.commitTransaction();
+ actionDone = true;
+ }
+
+ Thread.sleep(100);
+
+ tic++;
+
+ if ((tic % 600 == 0) && logger.isInfoEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ long time = stopTime - startTime;
+
+ logger.info(increment + " create/update or delete actions" +
+ " after " + DurationFormatUtils.formatDurationHMS(time));
+ }
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ transaction.closeContext();
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Modified: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-18 10:14:54 UTC (rev 405)
@@ -1,12 +1,17 @@
# Global logging configuration
-log4j.rootLogger=INFO, stdout, file
+log4j.rootLogger=DEBUG, stdout, file
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%c:%L) %M - %m%n
-log4j.appender.file=org.apache.log4j.FileAppender
-log4j.appender.file.file=${topiatest.log.home}/topiatest.log
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.file=${topiatest.home}/topiatest.log
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.Append=true
+log4j.appender.file.Threshold=DEBUG
+log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
1
0
Author: fdesbois
Date: 2010-04-16 20:57:32 +0200 (Fri, 16 Apr 2010)
New Revision: 404
Log:
Create project for testing error on Topia and Postgres (Socket closed)
Added:
testTopiaPostgresError/
testTopiaPostgresError/trunk/
testTopiaPostgresError/trunk/LICENSE.txt
testTopiaPostgresError/trunk/README.txt
testTopiaPostgresError/trunk/changelog.txt
testTopiaPostgresError/trunk/pom.xml
testTopiaPostgresError/trunk/src/
testTopiaPostgresError/trunk/src/main/
testTopiaPostgresError/trunk/src/main/java/
testTopiaPostgresError/trunk/src/main/java/org/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
testTopiaPostgresError/trunk/src/main/resources/
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
testTopiaPostgresError/trunk/src/main/webapp/
testTopiaPostgresError/trunk/src/main/webapp/META-INF/
testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml
testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/
testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml
Property changes on: testTopiaPostgresError/trunk
___________________________________________________________________
Added: svn:ignore
+ target
nbactions.xml
Property changes on: testTopiaPostgresError/trunk/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Property changes on: testTopiaPostgresError/trunk/README.txt
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Property changes on: testTopiaPostgresError/trunk/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/pom.xml
===================================================================
--- testTopiaPostgresError/trunk/pom.xml (rev 0)
+++ testTopiaPostgresError/trunk/pom.xml 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>mavenpom4redmine</artifactId>
+ <version>2.1</version>
+ </parent>
+
+ <groupId>org.nuiton</groupId>
+ <artifactId>test-topia-postgres-error</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.5</version>
+ </dependency>
+<!-- <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.2</version>
+ </dependency>-->
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>${nuitonutils.version}</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- ToPIA -->
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${topia.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-service-migration</artifactId>
+ <version>${topia.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.10</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.10</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>8.4-701.jdbc4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>TEST Topia Postgres Error</name>
+ <description>Test to find the error with application using ToPIA and
+ Postgres (Socket closed after a long time execution).</description>
+ <inceptionYear>2010</inceptionYear>
+
+ <organization>
+ <name>Code Lutin</name>
+ <url>http://www.codelutin.com/</url>
+ </organization>
+
+ <!-- Developpers, contributors... -->
+ <developers>
+ <developer>
+ <id>fdesbois</id>
+ <name>Florian Desbois</name>
+ <email>fdesbois(a)codelutin.com</email>
+ <organization>CodeLutin</organization>
+ <organizationUrl>http://www.codelutin.com</organizationUrl>
+ <timezone>+1</timezone>
+ <roles>
+ <role>Chef de Projet</role>
+ <role>Analyste</role>
+ <role>Développeur</role>
+ </roles>
+ </developer>
+ <!--<developer>
+ <name>Tony Chemit</name>
+ <id>tchemit</id>
+ <email>chemit(a)codelutin.com</email>
+ <organization>CodeLutin</organization>
+ <organizationUrl>http://www.codelutin.com</organizationUrl>
+ <timezone>+2</timezone>
+ <roles>
+ <role>Développeur</role>
+ </roles>
+ </developer>-->
+ </developers>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>war</packaging>
+
+ <properties>
+ <!-- libraries version -->
+ <i18n.version>1.2.1</i18n.version>
+ <nuitonutils.version>1.2.2</nuitonutils.version>
+ <topia.version>2.3.3-SNAPSHOT</topia.version>
+ </properties>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+ <!-- Source control management. -->
+ <scm>
+ <connection>scm:svn:http://svn.nuiton.org/svn/sandbox/testTopiaPostgresError/trunk</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/sandbox/testTopiaPostgresError/trunk</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/sandbox/testTopiaPostgresError/tr…</url>
+ </scm>
+
+ <build>
+<!-- <resources>
+ <resource>
+ <directory>src/main/filters</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>-->
+
+ <plugins>
+
+ <!-- plugin site -->
+<!-- <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.jrst</groupId>
+ <artifactId>doxia-module-jrst</artifactId>
+ <version>${jrst.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>-->
+
+ <!--<plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>maven-eugene-plugin</artifactId>
+ <version>${eugene.version}</version>
+ <configuration>
+ <inputs>zargo</inputs>
+ <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${topia.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>-->
+
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <version>${i18n.version}</version>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+ <!-- No generation of reports for maven-site (will be generated for release) -->
+ <reporting>
+ <excludeDefaults>true</excludeDefaults>
+ </reporting>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+
+</project>
Property changes on: testTopiaPostgresError/trunk/pom.xml
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,78 @@
+/**
+ * *##% ChoReg
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>. ##%*
+ */
+
+package org.nuiton.test.topia;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * ViewServices.java
+ *
+ * Created on 2009-07-24
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author: fdesbois $
+ */
+public class StartTest extends HttpServlet {
+
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
+ /**
+ * Handles the HTTP <code>GET</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ TopiaManager.getInstance().startTest();
+ }
+
+ /**
+ * Handles the HTTP <code>POST</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// </editor-fold>
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,60 @@
+
+package org.nuiton.test.topia;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * StopTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class StopTest extends HttpServlet {
+
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
+ /**
+ * Handles the HTTP <code>GET</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ TopiaManager.getInstance().stopTest();
+ }
+
+ /**
+ * Handles the HTTP <code>POST</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// </editor-fold>
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,96 @@
+
+package org.nuiton.test.topia;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ThreadTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class ThreadTest implements Runnable {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ThreadTest.class);
+
+ protected TopiaManager manager = TopiaManager.getInstance();
+
+ protected volatile boolean stop;
+
+ protected long startTime;
+
+ public synchronized void stop() {
+ stop = true;
+ }
+
+ @Override
+ public void run() {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Start Thread");
+ }
+
+ startTime = System.currentTimeMillis();
+
+ while(!stop) {
+ try {
+ execute();
+ } catch (TopiaException eee) {
+ long stopTime = System.currentTimeMillis();
+ if (logger.isErrorEnabled()) {
+ logger.error("ERROR after " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime), eee);
+ }
+ manager.stopTest();
+ }
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Stop Thread");
+ }
+ }
+
+ protected synchronized void execute() throws TopiaException {
+ TopiaContext transaction = null;
+ try {
+ transaction = manager.getRootContext().beginTransaction();
+
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ TMSVersion version = dao.findByTopiaId(manager.getMainTopiaId());
+
+ Thread.sleep(100);
+
+ int value = Integer.parseInt(version.getVersion());
+ version.setVersion(String.valueOf(value + 1));
+
+ if ((value % 500 == 0) && logger.isInfoEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ logger.info("Value is " + version.getVersion() + " after " +
+ DurationFormatUtils.formatDurationHMS(stopTime - startTime));
+ }
+
+ transaction.commitTransaction();
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ transaction.closeContext();
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,136 @@
+
+package org.nuiton.test.topia;
+
+import java.util.Locale;
+import java.util.Properties;
+import java.util.logging.Level;
+import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.nuiton.topia.migration.TMSVersionImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TopiaManager
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class TopiaManager {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(TopiaManager.class);
+
+// protected ApplicationConfig configuration;
+
+ protected static TopiaManager instance;
+
+ protected Properties configuration;
+
+ protected String mainTopiaId;
+
+ protected ThreadTest thread;
+
+ public static TopiaManager getInstance() {
+ if (instance == null) {
+ instance = new TopiaManager();
+ }
+ return instance;
+ }
+
+ private TopiaManager() {
+ configuration = new Properties();
+ // Config for Postgres
+ configuration.put("hibernate.hbm2ddl.auto", "create");
+ configuration.put("hibernate.show_sql", "false");
+ configuration.put("hibernate.dialect",
+ "org.hibernate.dialect.PostgreSQLDialect");
+ configuration.put("hibernate.connection.username","topia");
+ configuration.put("hibernate.connection.password","");
+ configuration.put("hibernate.connection.driver_class",
+ "org.postgresql.Driver");
+ configuration.put("hibernate.connection.url",
+ "jdbc:postgresql:topiatest");
+
+ // Config for Topia service Migration
+ configuration.put("topia.persistence.classes",
+ TMSVersionImpl.class.getName());
+
+ I18n.init(Locale.FRANCE);
+
+ // Create first entry
+ TopiaContext transaction = null;
+ try {
+ if (logger.isInfoEnabled()) {
+ logger.info("Open first transaction to create main entry");
+ }
+ transaction = TopiaContextFactory.getContext(configuration).
+ beginTransaction();
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
+
+ mainTopiaId = entry.getTopiaId();
+ if (logger.isInfoEnabled()) {
+ logger.info("Save the entry with id = " + mainTopiaId);
+ }
+ transaction.commitTransaction();
+
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error when create the first entry : ", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ try {
+ transaction.closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on closeContext : ", eee);
+ }
+ }
+ }
+ }
+ }
+
+ public TopiaContext getRootContext() throws TopiaNotFoundException {
+ return TopiaContextFactory.getContext(configuration);
+ }
+
+ public String getMainTopiaId() {
+ return mainTopiaId;
+ }
+
+ public void startTest() {
+ if (thread == null) {
+ thread = new ThreadTest();
+ new Thread(thread).start();
+ }
+ }
+
+ public void stopTest() {
+ if (thread != null) {
+ thread.stop();
+ try {
+ getRootContext().closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on close root context : ", eee);
+ }
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties (rev 0)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,14 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout, file
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%c:%L) %M - %m%n
+
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.file=${topiatest.log.home}/topiatest.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
+
+log4j.logger.org.nuiton.test.topia=DEBUG
+log4j.logger.org.nuiton.topia=INFO
\ No newline at end of file
Property changes on: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml
===================================================================
--- testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml (rev 0)
+++ testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context antiJARLocking="true" path="/test-topia-postgres-error"/>
Property changes on: testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml
===================================================================
--- testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml (rev 0)
+++ testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <display-name>Test Topia Postgres Error</display-name>
+ <servlet>
+ <servlet-name>StartTest</servlet-name>
+ <servlet-class>org.nuiton.test.topia.StartTest</servlet-class>
+ </servlet>
+ <servlet>
+ <servlet-name>StopTest</servlet-name>
+ <servlet-class>org.nuiton.test.topia.StopTest</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>StartTest</servlet-name>
+ <url-pattern>/start</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>StopTest</servlet-name>
+ <url-pattern>/stop</url-pattern>
+ </servlet-mapping>
+</web-app>
Property changes on: testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
1
0
r403 - in misctestproject/trunk: . src/main src/main/java/org/nuiton/test
by fdesbois@users.nuiton.org 07 Apr '10
by fdesbois@users.nuiton.org 07 Apr '10
07 Apr '10
Author: fdesbois
Date: 2010-04-07 17:58:23 +0200 (Wed, 07 Apr 2010)
New Revision: 403
Log:
- Add ConcatAlgo to test different algorithms for string concatenation -> add the best algo in join method in StringUtil in nuiton-utils
- Add StringArray to test some different ways to use String... in argument
Added:
misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java
misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java
misctestproject/trunk/src/main/resources/
Modified:
misctestproject/trunk/pom.xml
Modified: misctestproject/trunk/pom.xml
===================================================================
--- misctestproject/trunk/pom.xml 2010-03-15 11:48:25 UTC (rev 402)
+++ misctestproject/trunk/pom.xml 2010-04-07 15:58:23 UTC (rev 403)
@@ -66,7 +66,7 @@
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
- <version>1.1.0</version>
+ <version>1.2.2-SNAPSHOT</version>
</dependency>
<dependency>
Added: misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java
===================================================================
--- misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java (rev 0)
+++ misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java 2010-04-07 15:58:23 UTC (rev 403)
@@ -0,0 +1,188 @@
+
+package org.nuiton.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.util.StringUtil;
+
+/**
+ *
+ * @author fdesbois
+ */
+public class ConcatAlgo {
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ final long NB_ELMTS = 1000;
+ final long ELMT_SIZE = 100;
+ final long NB_EXECUTIONS = 1000;
+ final long ALGO4_TRESHOLD = 1000;
+
+ List<String> list = new ArrayList<String>();
+ long i;
+ for (i = 0; i < NB_ELMTS; i++) {
+ StringBuffer buffer = new StringBuffer();
+ for (int k = 0; k < ELMT_SIZE; k++) {
+ buffer.append("e");
+ }
+ list.add(buffer.toString());
+ }
+
+ long tic1, tic2;
+ String result;
+ long time1 = 0, time2 = 0, time3 = 0, time4 = 0, time5 = 0, time6 = 0,
+ time7 = 0;
+
+ for (long j = 0; j < NB_EXECUTIONS; j++) {
+
+ tic1 = System.currentTimeMillis();
+ result = algo1(list);
+ tic2 = System.currentTimeMillis();
+ time1 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo2(list);
+ tic2 = System.currentTimeMillis();
+ time2 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo3(list);
+ tic2 = System.currentTimeMillis();
+ time3 += (tic2 - tic1);
+
+ if (i < ALGO4_TRESHOLD) {
+ tic1 = System.currentTimeMillis();
+ result = algo4(list);
+ tic2 = System.currentTimeMillis();
+ time4 += (tic2 - tic1);
+ }
+
+ tic1 = System.currentTimeMillis();
+ result = algo5(list);
+ tic2 = System.currentTimeMillis();
+ time5 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo6(list);
+ tic2 = System.currentTimeMillis();
+ time6 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo6(list);
+ tic2 = System.currentTimeMillis();
+ time7 += (tic2 - tic1);
+ }
+
+ System.out.println("Nb elements = " + NB_ELMTS);
+ System.out.println("Element size = " + ELMT_SIZE);
+ System.out.println("Nb executions = " + NB_EXECUTIONS);
+ System.out.println("Algo1 average time = " + (time1 / NB_EXECUTIONS) +
+ " _ cumul = " + time1);
+ System.out.println("Algo2 average time = " + (time2 / NB_EXECUTIONS) +
+ " _ cumul = " + time2);
+ System.out.println("Algo3 average time = " + (time3 / NB_EXECUTIONS) +
+ " _ cumul = " + time3);
+ if (i < ALGO4_TRESHOLD) {
+ System.out.println("Algo4 average time = " +
+ (time4 / NB_EXECUTIONS) + " _ cumul = " + time4);
+ }
+ System.out.println("Algo5 average time = " + (time5 / NB_EXECUTIONS) +
+ " _ cumul = " + time5);
+ System.out.println("Algo6 average time = " + (time6 / NB_EXECUTIONS) +
+ " _ cumul = " + time6);
+ System.out.println("Algo7 average time = " + (time7 / NB_EXECUTIONS) +
+ " _ cumul = " + time7);
+ }
+
+ // buffer + iterator (if inside the for)
+ public static String algo1(List<String> list) {
+ // 10 rows
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator<String> j = list.iterator(); j.hasNext();) {
+ String elmt = j.next();
+ buffer.append(elmt);
+ if (j.hasNext()) {
+ buffer.append(", ");
+ }
+ }
+ String result = buffer.toString();
+ buffer = null;
+ return result;
+ }
+
+ // buffer + foreach + substring
+ public static String algo2(List<String> list) {
+ // 10 rows
+ if (list.isEmpty()) {
+ return "";
+ }
+ StringBuffer buffer = new StringBuffer();
+ String separator = ", ";
+ for (String elmt : list) {
+ buffer.append(separator).append(elmt);
+ }
+ String result = buffer.substring(separator.length());
+ buffer = null;
+ return result;
+ }
+
+ // buffer + foreach + change separator param
+ public static String algo3(List<String> list) {
+ // 8 rows
+ StringBuffer buffer = new StringBuffer();
+ String separator = "";
+ for (String elmt : list) {
+ buffer.append(separator).append(elmt);
+ separator = ", ";
+ }
+ String result = buffer.toString();
+ buffer = null;
+ return result;
+ }
+
+ // no buffer + foreach + change separator param
+ public static String algo4(List<String> list) {
+ // 7 rows
+ String result = "";
+ String separator = "";
+ for (String elmt : list) {
+ result += separator + elmt;
+ separator = ", ";
+ }
+ return result;
+ }
+
+ // using stringUtils join
+ public static String algo5(List<String> list) {
+ // 2 rows
+ String result = StringUtils.join(list, ", ");
+ return result;
+ }
+
+ // algo3 with stringBuilder
+ public static String algo6(List<String> list) {
+ // 8 rows
+ StringBuilder builder = new StringBuilder();
+ String separator = "";
+ for (String elmt : list) {
+ builder.append(separator).append(elmt);
+ separator = ", ";
+ }
+ String result = builder.toString();
+ builder = null;
+ return result;
+ }
+
+ // algo6 using in StringUtil (nuiton-utils)
+ public static String algo7(List<String> list) {
+ // 2 rows
+ String result = StringUtil.join(list, ", ", false);
+ return result;
+ }
+
+}
Property changes on: misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java
===================================================================
--- misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java (rev 0)
+++ misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java 2010-04-07 15:58:23 UTC (rev 403)
@@ -0,0 +1,60 @@
+
+package org.nuiton.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ *
+ * @author fdesbois
+ */
+public class StringArray {
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ System.out.println("StringArray");
+ test2("Troulala", "Tartanpion", "Potiron");
+ test2("Troulala");
+ test3(new Object[]{ "Troubidou", "Wahou!"});
+ test3(new Object[]{ "Troubidou", "Wahou!"}, "Fouac");
+ Object[] params = new Object[2];
+ params[0] = "Troubidou";
+ params[1] = "Wahou!";
+ test3(params);
+ List<Object> plop = new ArrayList<Object>();
+ test3(plop.toArray());
+
+ plop.add("Troubidou");
+ test3(plop.toArray());
+ }
+
+ public static void test(String... param) {
+ String str = Arrays.toString(param);
+ System.out.println("toString : " + str.substring(1, str.length()-1));
+ }
+
+ public static void test2(String... param) {
+ StringBuilder result = new StringBuilder();
+ for (String value : param) {
+ result.append(", ").append(value);
+ }
+ String str = "";
+ if (result.length() > 0) {
+ str = result.substring(2);
+ }
+ System.out.println("toString : " + str);
+ }
+
+ public static void test3(Object... param) {
+ Object[] array = param;
+ System.out.println("toString : " + Arrays.toString(array));
+ for (Object o : param) {
+ System.out.println("elmt : " + o);
+ }
+ System.out.println("nbElmts : " + array.length);
+ }
+
+}
Property changes on: misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
1
0
r402 - testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree
by echatellier@users.nuiton.org 15 Mar '10
by echatellier@users.nuiton.org 15 Mar '10
15 Mar '10
Author: echatellier
Date: 2010-03-15 12:48:25 +0100 (Mon, 15 Mar 2010)
New Revision: 402
Log:
Remove dependency on swingx.
Modified:
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java 2010-03-15 11:00:06 UTC (rev 401)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java 2010-03-15 11:48:25 UTC (rev 402)
@@ -18,12 +18,15 @@
package org.nuiton.test.tree;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
-import org.jdesktop.swingx.tree.TreeModelSupport;
-
/**
* TODO add comment here.
*
@@ -37,7 +40,7 @@
*/
public class FilterTreeModel implements TreeModel {
- protected TreeModelSupport support;
+ protected Collection<TreeModelListener> treeModelListeners;
protected TreeModel delegateModel;
@@ -46,15 +49,29 @@
public FilterTreeModel(TreeModel delegateModel, TreeFilter filter) {
this.delegateModel = delegateModel;
this.treeFilter = filter;
- this.support = new TreeModelSupport(delegateModel);
+ treeModelListeners = new ArrayList<TreeModelListener>();
}
public void setFilter(TreeFilter treeFilter) {
this.treeFilter = treeFilter;
TreePath path = new TreePath(delegateModel.getRoot());
- support.fireTreeStructureChanged(path);
+ fireTreeStructureChanged(path);
}
+ /**
+ * @param path
+ */
+ protected void fireTreeStructureChanged(TreePath path) {
+
+ TreeModelEvent event = new TreeModelEvent(delegateModel, path);
+ Iterator<TreeModelListener> itTreeModelListener = treeModelListeners.iterator();
+ while(itTreeModelListener.hasNext()) {
+ TreeModelListener current = itTreeModelListener.next();
+ current.treeStructureChanged(event);
+ }
+
+ }
+
@Override
public int getChildCount(Object parent) {
int realCount = delegateModel.getChildCount(parent);
@@ -122,7 +139,7 @@
@Override
public void addTreeModelListener(TreeModelListener l) {
delegateModel.addTreeModelListener(l);
- support.addTreeModelListener(l);
+ treeModelListeners.add(l);
}
/*
@@ -131,6 +148,6 @@
@Override
public void removeTreeModelListener(TreeModelListener l) {
delegateModel.removeTreeModelListener(l);
- support.addTreeModelListener(l);
+ treeModelListeners.remove(l);
}
}
1
0
r401 - testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip
by echatellier@users.nuiton.org 15 Mar '10
by echatellier@users.nuiton.org 15 Mar '10
15 Mar '10
Author: echatellier
Date: 2010-03-15 12:00:06 +0100 (Mon, 15 Mar 2010)
New Revision: 401
Log:
Allow tooltip on all JComponent
Modified:
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java 2010-03-12 14:26:53 UTC (rev 400)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java 2010-03-15 11:00:06 UTC (rev 401)
@@ -60,7 +60,7 @@
private JComponent attachedComponent;
private TipWindow tipWindow;
private URL imageBase;
- private TextAreaListener textAreaListener;
+ private AttachedComponentListener attachedComponentListener;
private HyperlinkListener hyperlinkListener;
private String lastText;
@@ -82,7 +82,7 @@
public FocusableTip(JComponent attachedComponent, HyperlinkListener listener) {
setAttachedComponent(attachedComponent);
this.hyperlinkListener = listener;
- textAreaListener = new TextAreaListener();
+ attachedComponentListener = new AttachedComponentListener();
tipVisibleBounds = new Rectangle();
}
@@ -149,7 +149,7 @@
tipWindow.setVisible(true);
tipWindow.toFront();
computeTipVisibleBounds(); // Do after tip is visible
- textAreaListener.install(attachedComponent);
+ attachedComponentListener.install(attachedComponent);
lastText = text;
}
@@ -187,7 +187,7 @@
if (tipWindow != null) {
tipWindow.dispose();
tipWindow = null;
- textAreaListener.uninstall();
+ attachedComponentListener.uninstall();
tipVisibleBounds.setBounds(-1, -1, 0, 0);
lastText = null;
attachedComponent.requestFocus();
@@ -197,7 +197,7 @@
void removeListeners() {
//System.out.println("DEBUG: Removing text area listeners");
- textAreaListener.uninstall();
+ attachedComponentListener.uninstall();
}
@@ -236,7 +236,7 @@
}
- private class TextAreaListener extends MouseInputAdapter implements
+ private class AttachedComponentListener extends MouseInputAdapter implements
CaretListener, ComponentListener, FocusListener, KeyListener {
public void caretUpdate(CaretEvent e) {
1
0
r400 - in testTreeTooltipSession/trunk: . src/main/java/org/nuiton/test src/main/java/org/nuiton/test/focusabletip
by echatellier@users.nuiton.org 12 Mar '10
by echatellier@users.nuiton.org 12 Mar '10
12 Mar '10
Author: echatellier
Date: 2010-03-12 15:26:53 +0100 (Fri, 12 Mar 2010)
New Revision: 400
Log:
Add eclipse-like tooltip from rsynthaxtextarea
Added:
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.properties
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip_fr.properties
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/SizeGrip.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipUtil.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipWindow.java
Modified:
testTreeTooltipSession/trunk/pom.xml
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java
Modified: testTreeTooltipSession/trunk/pom.xml
===================================================================
--- testTreeTooltipSession/trunk/pom.xml 2010-03-11 15:13:06 UTC (rev 399)
+++ testTreeTooltipSession/trunk/pom.xml 2010-03-12 14:26:53 UTC (rev 400)
@@ -106,6 +106,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <!-- <dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>rsyntaxtextarea</artifactId>
+ <version>1.4.0</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency> -->
</dependencies>
<repositories>
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java 2010-03-11 15:13:06 UTC (rev 399)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java 2010-03-12 14:26:53 UTC (rev 400)
@@ -21,6 +21,7 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
+import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
@@ -29,15 +30,15 @@
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
+import javax.swing.JTextArea;
import javax.swing.JTextField;
-import javax.swing.PopupFactory;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.jdesktop.swingx.JXTree;
+import org.nuiton.test.focusabletip.FocusableTip;
import org.nuiton.test.table.BasicTableModel;
import org.nuiton.test.table.BasicTableRenderer;
-import org.nuiton.test.tooltip.BalloonPopupFactory;
import org.nuiton.test.tree.BasicTreeModel;
import org.nuiton.test.tree.BasicTreeRenderer;
import org.nuiton.test.tree.FilterTreeModel;
@@ -69,7 +70,7 @@
super(new BorderLayout());
- PopupFactory.setSharedInstance(new BalloonPopupFactory());
+ //PopupFactory.setSharedInstance(new BalloonPopupFactory());
// label filter
JPanel leftPanel = new JPanel(new GridBagLayout());
@@ -117,7 +118,23 @@
BasicTableModel tableModel = new BasicTableModel(new File(".").
getCanonicalFile().getParentFile());
- JTable table = new JTable(tableModel);
+ JTable table = new JTable(tableModel) {
+
+ protected FocusableTip focusableTip;
+ @Override
+ public String getToolTipText(MouseEvent e) {
+
+ System.out.println("called ?");
+ String text = super.getToolTipText(e);
+ if (focusableTip==null) {
+ focusableTip = new FocusableTip(this, null);
+ }
+ focusableTip.toolTipRequested(e, text);
+
+ return null;
+ }
+ };
+
table.setDefaultRenderer(String.class, new BasicTableRenderer());
table.setName("table");
rigthPanel.add(new JScrollPane(table), new GridBagConstraints(0, 1, 1,
@@ -131,7 +148,31 @@
} catch (IOException e1) {
e1.printStackTrace();
}
+
+
+ // text area tootip
+ JTextArea textareaTT = new JTextArea("Public java main blah blah blah") {
+ protected FocusableTip focusableTip;
+ @Override
+ public String getToolTipText(MouseEvent e) {
+
+ System.out.println("called ?");
+ String text = super.getToolTipText(e);
+ if (focusableTip==null) {
+ focusableTip = new FocusableTip(this, null);
+ }
+ //focusableTip.setImageBase(imageBase);
+ focusableTip.toolTipRequested(e, text);
+ return null;
+ }
+ };
+ textareaTT.setToolTipText("Balh");
+
+ rigthPanel.add(textareaTT, new GridBagConstraints(0, 2, 1, 1, 1, 1,
+ GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
+ 2, 2, 2, 2), 0, 0));
+
// end UI
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rigthPanel);
@@ -139,7 +180,10 @@
// OR
- /*Split modelRoot = new ColSplit(new RowSplit(new Leaf("left"), new Divider(), new Leaf("right")), new Divider(), new Leaf("bottom"));
+ /*Split modelRoot = new ColSplit(
+ new RowSplit(new Leaf("left"), new Divider(), new Leaf("right")),
+ new Divider(),
+ new Leaf("bottom"));
MultiSplitLayout mpLayout = new MultiSplitLayout(modelRoot);
mpLayout.setDividerSize(2);
JXMultiSplitPane pane = new JXMultiSplitPane(mpLayout);
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java 2010-03-12 14:26:53 UTC (rev 400)
@@ -0,0 +1,335 @@
+/*
+ * 07/29/2009
+ *
+ * FocusableTip.java - A focusable tool tip, like those in Eclipse.
+ * Copyright (C) 2009 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.nuiton.test.focusabletip;
+
+import java.awt.Component;
+import java.awt.ComponentOrientation;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.net.URL;
+import java.util.ResourceBundle;
+
+import javax.swing.JComponent;
+//import javax.swing.JTextArea;
+import javax.swing.SwingUtilities;
+import javax.swing.ToolTipManager;
+import javax.swing.event.CaretEvent;
+import javax.swing.event.CaretListener;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.event.MouseInputAdapter;
+
+
+/**
+ * A focusable tool tip, similar to those found in Eclipse. The user
+ * can click in the tip and it becomes a "real," resizable window.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+public class FocusableTip {
+
+ private JComponent attachedComponent;
+ private TipWindow tipWindow;
+ private URL imageBase;
+ private TextAreaListener textAreaListener;
+ private HyperlinkListener hyperlinkListener;
+ private String lastText;
+
+ /**
+ * The screen bounds in which the mouse has to stay for the currently
+ * displayed tip to stay visible.
+ */
+ private Rectangle tipVisibleBounds;
+
+ /**
+ * Margin from mouse cursor at which to draw focusable tip.
+ */
+ private static final int MARGIN = 10;
+
+ private static final String MSG = "org.nuiton.test.focusabletip.FocusableTip";
+ private static final ResourceBundle msg = ResourceBundle.getBundle(MSG);
+
+
+ public FocusableTip(JComponent attachedComponent, HyperlinkListener listener) {
+ setAttachedComponent(attachedComponent);
+ this.hyperlinkListener = listener;
+ textAreaListener = new TextAreaListener();
+ tipVisibleBounds = new Rectangle();
+ }
+
+
+ /**
+ * Compute the bounds in which the user can move the mouse without the
+ * tip window disappearing.
+ */
+ private void computeTipVisibleBounds() {
+ // Compute area that the mouse can move in without hiding the
+ // tip window. Note that Java 1.4 can only detect mouse events
+ // in Java windows, not globally.
+ Rectangle r = tipWindow.getBounds();
+ Point p = r.getLocation();
+ SwingUtilities.convertPointFromScreen(p, attachedComponent);
+ r.setLocation(p);
+ tipVisibleBounds.setBounds(r.x,r.y-15, r.width,r.height+15*2);
+ }
+
+
+ private void createAndShowTipWindow(final MouseEvent e, final String text) {
+
+ Window owner = SwingUtilities.getWindowAncestor(attachedComponent);
+ tipWindow = new TipWindow(owner, this, text);
+ tipWindow.setHyperlinkListener(hyperlinkListener);
+
+ // TODO: Position tip window better (handle RTL, edges of screen, etc.).
+ // Wrap in an invokeLater() to work around a JEditorPane issue where it
+ // doesn't return its proper preferred size until after it is displayed.
+ // See http://forums.sun.com/thread.jspa?forumID=57&threadID=574810
+ // for a discussion.
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+
+ // If a new FocusableTip is requested while another one is
+ // *focused* and visible, the focused tip (i.e. "tipWindow")
+ // will be disposed of. If this Runnable is run after the
+ // dispose(), tipWindow will be null. All of this is done on
+ // the EDT so no synchronization should be necessary.
+ if (tipWindow==null) {
+ return;
+ }
+
+ tipWindow.fixSize();
+ ComponentOrientation o = attachedComponent.getComponentOrientation();
+
+ Point p = e.getPoint();
+ SwingUtilities.convertPointToScreen(p, attachedComponent);
+ int x = o.isLeftToRight() ? (p.x-10) :
+ (p.x - tipWindow.getWidth() + MARGIN);
+ int y = p.y + MARGIN;
+
+ // Ensure tooltip is in the window bounds.
+ Dimension ss = tipWindow.getToolkit().getScreenSize();
+ x = Math.max(x, 0);
+ if (x+tipWindow.getWidth()>=ss.width) {
+ x = ss.width - tipWindow.getWidth();
+ }
+ if (y+tipWindow.getHeight()>=ss.height) { // Go above cursor
+ y = p.y - tipWindow.getHeight() - MARGIN;
+ }
+
+ tipWindow.setLocation(x, y);
+ tipWindow.setVisible(true);
+ tipWindow.toFront();
+ computeTipVisibleBounds(); // Do after tip is visible
+ textAreaListener.install(attachedComponent);
+ lastText = text;
+
+ }
+ });
+
+ }
+
+
+ /**
+ * Returns the base URL to use when loading images in this focusable tip.
+ *
+ * @return The base URL to use.
+ * @see #setImageBase(URL)
+ */
+ public URL getImageBase() {
+ return imageBase;
+ }
+
+
+ /**
+ * Returns localized text for the given key.
+ *
+ * @param key The key into the resource bundle.
+ * @return The localized text.
+ */
+ static String getString(String key) {
+ return msg.getString(key);
+ }
+
+
+ /**
+ * Disposes of the focusable tip currently displayed, if any.
+ */
+ public void possiblyDisposeOfTipWindow() {
+ if (tipWindow != null) {
+ tipWindow.dispose();
+ tipWindow = null;
+ textAreaListener.uninstall();
+ tipVisibleBounds.setBounds(-1, -1, 0, 0);
+ lastText = null;
+ attachedComponent.requestFocus();
+ }
+ }
+
+
+ void removeListeners() {
+ //System.out.println("DEBUG: Removing text area listeners");
+ textAreaListener.uninstall();
+ }
+
+
+ /**
+ * Sets the base URL to use when loading images in this focusable tip.
+ *
+ * @param url The base URL to use.
+ * @see #getImageBase()
+ */
+ public void setImageBase(URL url) {
+ imageBase = url;
+ }
+
+
+ private void setAttachedComponent(JComponent attachedComponent) {
+ this.attachedComponent = attachedComponent;
+ // Is okay to do multiple times.
+ ToolTipManager.sharedInstance().registerComponent(attachedComponent);
+ }
+
+
+ public void toolTipRequested(MouseEvent e, String text) {
+
+ if (text==null || text.length()==0) {
+ possiblyDisposeOfTipWindow();
+ lastText = text;
+ return;
+ }
+
+ if (lastText==null || text.length()!=lastText.length()
+ || !text.equals(lastText)) {
+ possiblyDisposeOfTipWindow();
+ createAndShowTipWindow(e, text);
+ }
+
+ }
+
+
+ private class TextAreaListener extends MouseInputAdapter implements
+ CaretListener, ComponentListener, FocusListener, KeyListener {
+
+ public void caretUpdate(CaretEvent e) {
+ Object source = e.getSource();
+ if (source == attachedComponent) {
+ possiblyDisposeOfTipWindow();
+ }
+ }
+
+ public void componentHidden(ComponentEvent e) {
+ handleComponentEvent(e);
+ }
+
+ public void componentMoved(ComponentEvent e) {
+ handleComponentEvent(e);
+ }
+
+ public void componentResized(ComponentEvent e) {
+ handleComponentEvent(e);
+ }
+
+ public void componentShown(ComponentEvent e) {
+ handleComponentEvent(e);
+ }
+
+ public void focusGained(FocusEvent e) {
+ }
+
+ public void focusLost(FocusEvent e) {
+ // Only dispose of tip if it wasn't the TipWindow that was clicked
+ // "c" can be null, at least on OS X, so we must check that before
+ // calling SwingUtilities.getWindowAncestor() to guard against an
+ // NPE.
+ Component c = e.getOppositeComponent();
+ boolean tipClicked = (c instanceof TipWindow) ||
+ (c!=null &&
+ SwingUtilities.getWindowAncestor(c) instanceof TipWindow);
+ if (!tipClicked) {
+ possiblyDisposeOfTipWindow();
+ }
+ }
+
+ private void handleComponentEvent(ComponentEvent e) {
+ possiblyDisposeOfTipWindow();
+ }
+
+ public void install(JComponent attachedComponent) {
+ //attachedComponent.addCaretListener(this);
+ attachedComponent.addComponentListener(this);
+ attachedComponent.addFocusListener(this);
+ attachedComponent.addKeyListener(this);
+ attachedComponent.addMouseListener(this);
+ attachedComponent.addMouseMotionListener(this);
+ }
+
+ public void keyPressed(KeyEvent e) {
+ if (e.getKeyCode()==KeyEvent.VK_ESCAPE) {
+ possiblyDisposeOfTipWindow();
+ }
+ else if (e.getKeyCode()==KeyEvent.VK_F2) {
+ if (tipWindow!=null && !tipWindow.getFocusableWindowState()) {
+ tipWindow.actionPerformed(null);
+ e.consume(); // Don't do bookmarking stuff
+ }
+ }
+ }
+
+ public void keyReleased(KeyEvent e) {
+ }
+
+ public void keyTyped(KeyEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ // possiblyDisposeOfTipWindow();
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ if (tipVisibleBounds==null ||
+ !tipVisibleBounds.contains(e.getPoint())) {
+ possiblyDisposeOfTipWindow();
+ }
+ }
+
+ public void uninstall() {
+ //attachedComponent.removeCaretListener(this);
+ attachedComponent.removeComponentListener(this);
+ attachedComponent.removeFocusListener(this);
+ attachedComponent.removeKeyListener(this);
+ attachedComponent.removeMouseListener(this);
+ attachedComponent.removeMouseMotionListener(this);
+ }
+
+ }
+
+}
\ No newline at end of file
Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.properties
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.properties (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip.properties 2010-03-12 14:26:53 UTC (rev 400)
@@ -0,0 +1 @@
+FocusHotkey=Press 'F2' for focus
\ No newline at end of file
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip_fr.properties
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip_fr.properties (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/FocusableTip_fr.properties 2010-03-12 14:26:53 UTC (rev 400)
@@ -0,0 +1 @@
+FocusHotkey=Appuyez sur 'F2' pour agrandir
\ No newline at end of file
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/SizeGrip.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/SizeGrip.java (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/SizeGrip.java 2010-03-12 14:26:53 UTC (rev 400)
@@ -0,0 +1,266 @@
+/*
+ * 12/23/2008
+ *
+ * SizeGrip.java - A size grip component that sits at the bottom of the window,
+ * allowing the user to easily resize that window.
+ * Copyright (C) 2008 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.nuiton.test.focusabletip;
+
+import java.awt.Color;
+import java.awt.ComponentOrientation;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.event.MouseInputAdapter;
+
+
+/**
+ * A component that allows its parent window to be resizable, similar to the
+ * size grip seen on status bars.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+class SizeGrip extends JPanel {
+
+ /**
+ * The size grip to use if we're on OS X.
+ */
+ private Image osxSizeGrip;
+
+
+ public SizeGrip() {
+ MouseHandler adapter = new MouseHandler();
+ addMouseListener(adapter);
+ addMouseMotionListener(adapter);
+ setPreferredSize(new Dimension(16, 16));
+ }
+
+
+ /**
+ * Overridden to ensure that the cursor for this component is appropriate
+ * for the orientation.
+ *
+ * @param o The new orientation.
+ */
+ public void applyComponentOrientation(ComponentOrientation o) {
+ possiblyFixCursor(o.isLeftToRight());
+ super.applyComponentOrientation(o);
+ }
+
+
+ /**
+ * Creates and returns the OS X size grip image.
+ *
+ * @return The OS X size grip.
+ */
+ private Image createOSXSizeGrip() {
+ ClassLoader cl = getClass().getClassLoader();
+ URL url = cl.getResource("org/fife/ui/autocomplete/osx_sizegrip.png");
+ if (url==null) {
+ // We're not running in a jar - we may be debugging in Eclipse,
+ // for example
+ File f = new File("../AutoComplete/src/org/fife/ui/autocomplete/osx_sizegrip.png");
+ if (f.isFile()) {
+ try {
+ url = f.toURI().toURL();
+ } catch (MalformedURLException mue) { // Never happens
+ mue.printStackTrace();
+ return null;
+ }
+ }
+ else {
+ return null; // Can't find resource or image file
+ }
+ }
+ Image image = null;
+ try {
+ image = ImageIO.read(url);
+ } catch (IOException ioe) { // Never happens
+ ioe.printStackTrace();
+ }
+ return image;
+ }
+
+
+ /**
+ * Paints this panel.
+ *
+ * @param g The graphics context.
+ */
+ protected void paintComponent(Graphics g) {
+
+ super.paintComponent(g);
+
+ Dimension dim = getSize();
+ Color c1 = UIManager.getColor("Label.disabledShadow");
+ Color c2 = UIManager.getColor("Label.disabledForeground");
+
+ if (osxSizeGrip!=null) {
+ g.drawImage(osxSizeGrip, dim.width-16, dim.height-16, null);
+ return;
+ }
+
+ ComponentOrientation orientation = getComponentOrientation();
+
+ if (orientation.isLeftToRight()) {
+ int width = dim.width -= 3;
+ int height = dim.height -= 3;
+ g.setColor(c1);
+ g.fillRect(width-9,height-1, 3,3);
+ g.fillRect(width-5,height-1, 3,3);
+ g.fillRect(width-1,height-1, 3,3);
+ g.fillRect(width-5,height-5, 3,3);
+ g.fillRect(width-1,height-5, 3,3);
+ g.fillRect(width-1,height-9, 3,3);
+ g.setColor(c2);
+ g.fillRect(width-9,height-1, 2,2);
+ g.fillRect(width-5,height-1, 2,2);
+ g.fillRect(width-1,height-1, 2,2);
+ g.fillRect(width-5,height-5, 2,2);
+ g.fillRect(width-1,height-5, 2,2);
+ g.fillRect(width-1,height-9, 2,2);
+ }
+ else {
+ int height = dim.height -= 3;
+ g.setColor(c1);
+ g.fillRect(10,height-1, 3,3);
+ g.fillRect(6,height-1, 3,3);
+ g.fillRect(2,height-1, 3,3);
+ g.fillRect(6,height-5, 3,3);
+ g.fillRect(2,height-5, 3,3);
+ g.fillRect(2,height-9, 3,3);
+ g.setColor(c2);
+ g.fillRect(10,height-1, 2,2);
+ g.fillRect(6,height-1, 2,2);
+ g.fillRect(2,height-1, 2,2);
+ g.fillRect(6,height-5, 2,2);
+ g.fillRect(2,height-5, 2,2);
+ g.fillRect(2,height-9, 2,2);
+ }
+
+ }
+
+
+ /**
+ * Ensures that the cursor for this component is appropriate for the
+ * orientation.
+ *
+ * @param ltr Whether the current component orientation is LTR.
+ */
+ protected void possiblyFixCursor(boolean ltr) {
+ int cursor = Cursor.NE_RESIZE_CURSOR;
+ if (ltr) {
+ cursor = Cursor.NW_RESIZE_CURSOR;
+ }
+ if (cursor!=getCursor().getType()) {
+ setCursor(Cursor.getPredefinedCursor(cursor));
+ }
+ }
+
+
+ public void updateUI() {
+ super.updateUI();
+ // TODO: Key off of Aqua LaF, not just OS X, as this size grip looks
+ // bad on other LaFs on Mac such as Nimbus.
+ if (System.getProperty("os.name").indexOf("OS X")>-1) {
+ if (osxSizeGrip==null) {
+ osxSizeGrip = createOSXSizeGrip();
+ }
+ }
+ else { // Clear memory in case of runtime LaF change.
+ osxSizeGrip = null;
+ }
+
+ }
+
+
+ /**
+ * Listens for mouse events on this panel and resizes the parent window
+ * appropriately.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+ /*
+ * NOTE: We use SwingUtilities.convertPointToScreen() instead of just using
+ * the locations relative to the corner component because the latter proved
+ * buggy - stretch the window too wide and some kind of arithmetic error
+ * started happening somewhere - our window would grow way too large.
+ */
+ private class MouseHandler extends MouseInputAdapter {
+
+ private Point origPos;
+
+ public void mouseDragged(MouseEvent e) {
+ Point newPos = e.getPoint();
+ SwingUtilities.convertPointToScreen(newPos, SizeGrip.this);
+ int xDelta = newPos.x - origPos.x;
+ int yDelta = newPos.y - origPos.y;
+ Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this);
+ if (wind!=null) { // Should always be true
+ if (getComponentOrientation().isLeftToRight()) {
+ int w = wind.getWidth();
+ if (newPos.x>=wind.getX()) {
+ w += xDelta;
+ }
+ int h = wind.getHeight();
+ if (newPos.y>=wind.getY()) {
+ h += yDelta;
+ }
+ wind.setSize(w,h);
+ }
+ else { // RTL
+ int newW = Math.max(1, wind.getWidth()-xDelta);
+ int newH = Math.max(1, wind.getHeight()+yDelta);
+ wind.setBounds(newPos.x, wind.getY(), newW, newH);
+ }
+ // invalidate()/validate() needed pre-1.6.
+ wind.invalidate();
+ wind.validate();
+ }
+ origPos.setLocation(newPos);
+ }
+
+ public void mousePressed(MouseEvent e) {
+ origPos = e.getPoint();
+ SwingUtilities.convertPointToScreen(origPos, SizeGrip.this);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ origPos = null;
+ }
+
+ }
+
+
+}
\ No newline at end of file
Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/SizeGrip.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipUtil.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipUtil.java (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipUtil.java 2010-03-12 14:26:53 UTC (rev 400)
@@ -0,0 +1,117 @@
+/*
+ * 08/13/2009
+ *
+ * TipUtil.java - Utility methods for homemade tool tips.
+ * Copyright (C) 2009 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.nuiton.test.focusabletip;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.SystemColor;
+import javax.swing.BorderFactory;
+import javax.swing.JEditorPane;
+import javax.swing.UIManager;
+import javax.swing.plaf.ColorUIResource;
+import javax.swing.text.html.HTMLDocument;
+
+
+/**
+ * Static utility methods for focusable tips.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+class TipUtil {
+
+
+ private TipUtil() {
+ }
+
+
+ /**
+ * Returns the default background color to use for tool tip windows.
+ *
+ * @return The default background color.
+ */
+ public static Color getToolTipBackground() {
+
+ Color c = UIManager.getColor("ToolTip.background");
+
+ // Tooltip.background is wrong color on Nimbus (!)
+ if (c==null || UIManager.getLookAndFeel().getName().equals("Nimbus")) {
+ c = UIManager.getColor("info"); // Used by Nimbus (and others)
+ if (c==null) {
+ c = SystemColor.info; // System default
+ }
+ }
+
+ // Workaround for a bug (?) with Nimbus - calling JLabel.setBackground()
+ // with a ColorUIResource does nothing, must be a normal Color
+ if (c instanceof ColorUIResource) {
+ c = new Color(c.getRGB());
+ }
+
+ return c;
+
+ }
+
+
+ /**
+ * Tweaks a <code>JEditorPane</code> so it can be used to render the
+ * content in a focusable pseudo-tool tip. It is assumed that the editor
+ * pane is using an <code>HTMLDocument</code>.
+ *
+ * @param textArea The editor pane to tweak.
+ */
+ public static void tweakTipEditorPane(JEditorPane textArea) {
+
+ // Jump through a few hoops to get things looking nice in Nimbus
+ if (UIManager.getLookAndFeel().getName().equals("Nimbus")) {
+ Color selBG = textArea.getSelectionColor();
+ Color selFG = textArea.getSelectedTextColor();
+ textArea.setUI(new javax.swing.plaf.basic.BasicEditorPaneUI());
+ textArea.setSelectedTextColor(selFG);
+ textArea.setSelectionColor(selBG);
+ }
+
+ textArea.setEditable(false); // Required for links to work!
+ textArea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+
+ // Make selection visible even though we are not (initially) focusable.
+ textArea.getCaret().setSelectionVisible(true);
+
+ // Make it use the "tool tip" background color.
+ textArea.setBackground(TipUtil.getToolTipBackground());
+
+ // Force JEditorPane to use a certain font even in HTML.
+ // All standard LookAndFeels, even Nimbus (!), define Label.font.
+ Font font = UIManager.getFont("Label.font");
+ if (font == null) { // Try to make a sensible default
+ font = new Font("SansSerif", Font.PLAIN, 12);
+ }
+ HTMLDocument doc = (HTMLDocument) textArea.getDocument();
+ doc.getStyleSheet().addRule(
+ "body { font-family: " + font.getFamily() + "; font-size: "
+ + font.getSize() + "pt; }");
+
+ }
+
+
+}
\ No newline at end of file
Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipWindow.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipWindow.java (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipWindow.java 2010-03-12 14:26:53 UTC (rev 400)
@@ -0,0 +1,328 @@
+/*
+ * 07/29/2009
+ *
+ * TipWindow.java - The actual window component representing the tool tip.
+ * Copyright (C) 2009 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.nuiton.test.focusabletip;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.swing.BorderFactory;
+import javax.swing.JEditorPane;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.JWindow;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.event.MouseInputAdapter;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.html.HTMLDocument;
+
+
+/**
+ * The actual tool tip component.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+class TipWindow extends JWindow implements ActionListener {
+
+ private FocusableTip ft;
+ private JEditorPane textArea;
+ private String text;
+ private TipListener tipListener;
+ private HyperlinkListener userHyperlinkListener;
+
+ private static TipWindow visibleInstance;
+
+
+ /**
+ * Constructor.
+ *
+ * @param owner The parent window.
+ * @param msg The text of the tool tip. This can be HTML.
+ */
+ public TipWindow(Window owner, FocusableTip ft, String msg) {
+
+ super(owner);
+ this.ft = ft;
+ this.text = msg;
+ tipListener = new TipListener();
+
+ JPanel cp = new JPanel(new BorderLayout());
+ cp.setBorder(BorderFactory.createCompoundBorder(BorderFactory
+ .createLineBorder(Color.BLACK), BorderFactory
+ .createEmptyBorder()));
+ cp.setBackground(TipUtil.getToolTipBackground());
+ textArea = new JEditorPane("text/html", msg);
+ TipUtil.tweakTipEditorPane(textArea);
+ if (ft.getImageBase()!=null) { // Base URL for images
+ ((HTMLDocument)textArea.getDocument()).setBase(ft.getImageBase());
+ }
+ textArea.addMouseListener(tipListener);
+ textArea.addHyperlinkListener(new HyperlinkListener() {
+ public void hyperlinkUpdate(HyperlinkEvent e) {
+ if (e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
+ TipWindow.this.ft.possiblyDisposeOfTipWindow();
+ }
+ }
+ });
+ cp.add(textArea);
+
+ setFocusableWindowState(false);
+ setContentPane(cp);
+ setBottomPanel(); // Must do after setContentPane()
+ pack();
+
+ // InputMap/ActionMap combo doesn't work for JWindows (even when
+ // using the JWindow's JRootPane), so we'll resort to KeyListener
+ KeyAdapter ka = new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ if (e.getKeyCode()==KeyEvent.VK_ESCAPE) {
+ TipWindow.this.ft.possiblyDisposeOfTipWindow();
+ }
+ }
+ };
+ addKeyListener(ka);
+ textArea.addKeyListener(ka);
+
+ // Ensure only 1 TipWindow is ever visible. If the caller does what
+ // they're supposed to and only creates these on the EDT, the
+ // synchronization isn't necessary, but we'll be extra safe.
+ synchronized (TipWindow.class) {
+ if (visibleInstance!=null) {
+ visibleInstance.dispose();
+ }
+ visibleInstance = this;
+ }
+
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+
+ if (!getFocusableWindowState()) {
+ setFocusableWindowState(true);
+ setBottomPanel();
+ textArea.removeMouseListener(tipListener);
+ pack();
+ addWindowFocusListener(new WindowAdapter() {
+ public void windowLostFocus(WindowEvent e) {
+ ft.possiblyDisposeOfTipWindow();
+ }
+ });
+ ft.removeListeners();
+ if (e==null) { // Didn't get here via our mouseover timer
+ requestFocus();
+ }
+ }
+
+ }
+
+
+ /**
+ * Disposes of this window.
+ */
+ public void dispose() {
+ //System.out.println("[DEBUG]: Disposing...");
+ Container cp = getContentPane();
+ for (int i=0; i<cp.getComponentCount(); i++) {
+ // Okay if listener is already removed
+ cp.getComponent(i).removeMouseListener(tipListener);
+ }
+ ft.removeListeners();
+ super.dispose();
+ }
+
+
+ /**
+ * Workaround for JEditorPane not returning its proper preferred size
+ * when rendering HTML until after layout already done. See
+ * http://forums.sun.com/thread.jspa?forumID=57&threadID=574810 for a
+ * discussion.
+ */
+ void fixSize() {
+
+ Dimension d = textArea.getPreferredSize();
+ Rectangle r = null;
+ try {
+
+ r = textArea.modelToView(textArea.getDocument().getLength()-1);
+ d.height = r.y + r.height;
+
+ // Ensure the text area doesn't start out too tall or wide.
+ d = textArea.getPreferredSize();
+ d.width = Math.min(d.width+25, 320);
+ d.height = Math.min(d.height, 150);
+
+ textArea.setPreferredSize(d);
+
+ } catch (BadLocationException ble) { // Never happens
+ ble.printStackTrace();
+ }
+
+ pack(); // Must re-pack to calculate proper size.
+
+ }
+
+
+ public String getText() {
+ return text;
+ }
+
+
+ private void setBottomPanel() {
+
+ final JPanel panel = new JPanel(new BorderLayout());
+ panel.add(new JSeparator(), BorderLayout.NORTH);
+
+ boolean focusable = getFocusableWindowState();
+ if (focusable) {
+ SizeGrip sg = new SizeGrip();
+ sg.applyComponentOrientation(sg.getComponentOrientation()); // Workaround
+ panel.add(sg, BorderLayout.LINE_END);
+ MouseInputAdapter adapter = new MouseInputAdapter() {
+ private Point lastPoint;
+ public void mouseDragged(MouseEvent e) {
+ Point p = e.getPoint();
+ SwingUtilities.convertPointToScreen(p, panel);
+ if (lastPoint==null) {
+ lastPoint = p;
+ }
+ else {
+ int dx = p.x - lastPoint.x;
+ int dy = p.y - lastPoint.y;
+ setLocation(getX()+dx, getY()+dy);
+ lastPoint = p;
+ }
+ }
+ public void mousePressed(MouseEvent e) {
+ lastPoint = e.getPoint();
+ SwingUtilities.convertPointToScreen(lastPoint, panel);
+ }
+ };
+ panel.addMouseListener(adapter);
+ panel.addMouseMotionListener(adapter);
+ // Don't add tipListener to the panel or SizeGrip
+ }
+ else {
+ panel.setOpaque(false);
+ JLabel label = new JLabel(FocusableTip.getString("FocusHotkey"));
+ Color fg = UIManager.getColor("Label.disabledForeground");
+ Font font = textArea.getFont();
+ font = font.deriveFont(font.getSize2D() - 1.0f);
+ label.setFont(font);
+ if (fg==null) { // Non BasicLookAndFeel-derived Looks
+ fg = Color.GRAY;
+ }
+ label.setOpaque(true);
+ Color bg = TipUtil.getToolTipBackground();
+ label.setBackground(bg);
+ label.setForeground(fg);
+ label.setHorizontalAlignment(SwingConstants.TRAILING);
+ label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
+ panel.add(label);
+ panel.addMouseListener(tipListener);
+ }
+
+ // Replace the previous SOUTH Component with the new one.
+ Container cp = getContentPane();
+ if (cp.getComponentCount()==2) { // Skip first time through
+ Component comp = cp.getComponent(0);
+ cp.remove(0);
+ JScrollPane sp = new JScrollPane(comp);
+ sp.setViewportBorder(BorderFactory.createEmptyBorder());
+ sp.setBackground(textArea.getBackground());
+ sp.getViewport().setBackground(textArea.getBackground());
+ cp.add(sp);
+ // What was component 1 is now 0.
+ cp.getComponent(0).removeMouseListener(tipListener);
+ cp.remove(0);
+ }
+
+ cp.add(panel, BorderLayout.SOUTH);
+
+ }
+
+
+ /**
+ * Sets the listener for hyperlink events in this tip window.
+ *
+ * @param listener The new listener. The old listener (if any) is
+ * removed. A value of <code>null</code> means "no listener."
+ */
+ public void setHyperlinkListener(HyperlinkListener listener) {
+ // We've added a separate listener, so remove only the user's.
+ if (userHyperlinkListener!=null) {
+ textArea.removeHyperlinkListener(userHyperlinkListener);
+ }
+ userHyperlinkListener = listener;
+ if (userHyperlinkListener!=null) {
+ textArea.addHyperlinkListener(userHyperlinkListener);
+ }
+ }
+
+
+ /**
+ * Listens for events in this window.
+ */
+ private class TipListener extends MouseAdapter {
+
+ public TipListener() {
+ }
+
+ public void mousePressed(MouseEvent e) {
+ actionPerformed(null); // Manually create "real" window
+ }
+
+ public void mouseExited(MouseEvent e) {
+ // Since we registered this listener on the child components of
+ // the JWindow, not the JWindow iteself, we have to be careful.
+ Component source = (Component)e.getSource();
+ Point p = e.getPoint();
+ SwingUtilities.convertPointToScreen(p, source);
+ if (!TipWindow.this.getBounds().contains(p)) {
+ ft.possiblyDisposeOfTipWindow();
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/focusabletip/TipWindow.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r399 - in testTreeTooltipSession/trunk/src/main/java/org/nuiton/test: . resources table tooltip tree
by echatellier@users.nuiton.org 11 Mar '10
by echatellier@users.nuiton.org 11 Mar '10
11 Mar '10
Author: echatellier
Date: 2010-03-11 16:13:06 +0100 (Thu, 11 Mar 2010)
New Revision: 399
Log:
Update persistent toolip display (need to be fixed for trees and tables)
Added:
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tooltip/BalloonPopupFactory.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeRenderer.java
Modified:
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MyApplication.properties
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableModel.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableRenderer.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeModel.java
testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java 2010-03-08 19:03:09 UTC (rev 398)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/MainPanel.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -18,12 +18,9 @@
package org.nuiton.test;
import java.awt.BorderLayout;
-import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
@@ -33,19 +30,16 @@
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
-import javax.swing.JToolTip;
-import javax.swing.JTree;
+import javax.swing.PopupFactory;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
-import net.java.balloontip.BalloonTip;
-import net.java.balloontip.styles.RoundedBalloonStyle;
-import net.java.balloontip.utils.ToolTipUtils;
-
+import org.jdesktop.swingx.JXTree;
import org.nuiton.test.table.BasicTableModel;
import org.nuiton.test.table.BasicTableRenderer;
-import org.nuiton.test.tooltip.ViewTooltips;
+import org.nuiton.test.tooltip.BalloonPopupFactory;
import org.nuiton.test.tree.BasicTreeModel;
+import org.nuiton.test.tree.BasicTreeRenderer;
import org.nuiton.test.tree.FilterTreeModel;
import org.nuiton.test.tree.MyFilter;
import org.slf4j.Logger;
@@ -75,6 +69,8 @@
super(new BorderLayout());
+ PopupFactory.setSharedInstance(new BalloonPopupFactory());
+
// label filter
JPanel leftPanel = new JPanel(new GridBagLayout());
JLabel filterLabel = new JLabel("Filtre : ");
@@ -95,7 +91,8 @@
.getCanonicalFile());
filterModel = new FilterTreeModel(treeModel, new MyFilter(""));
- JTree tree = new JTree(filterModel);
+ JXTree tree = new JXTree(filterModel);
+ tree.setCellRenderer(new BasicTreeRenderer());
tree.setName("tree");
leftPanel.add(new JScrollPane(tree), new GridBagConstraints(0, 1, 2, 1,
1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
@@ -108,57 +105,17 @@
JPanel rigthPanel = new JPanel(new GridBagLayout());
// label tootip
- JLabel testToottip = new JLabel("Over me !!!!!") {
- @Override
- public JToolTip createToolTip() {
- JToolTip tt = new JToolTip();
- /*BalloonTip bt = new BalloonTip(this, this.getToolTipText(), new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), false);
- bt.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
-
- BalloonTip source = (BalloonTip)e.getSource();
- source.closeBalloon();
-
- BalloonTip bt = new BalloonTip(source, source.getToolTipText(), new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), true);
- bt.setVisible(true);
- }
-
- });
- //ToolTipUtils.balloonToToolTip(bt, 500, 3000);
- tt.setComponent(this);*/
- return tt;
- }
- };
- testToottip.setToolTipText("Alors ?");
+ JLabel testToottip = new JLabel("Over me !!!!!");
+ testToottip.setToolTipText("Then click on Me !!!");
- BalloonTip bt = new BalloonTip(testToottip, testToottip
- .getToolTipText(), new RoundedBalloonStyle(5, 5, Color.WHITE,
- Color.BLACK), false);
- bt.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- logger.debug("Called");
- BalloonTip source = (BalloonTip) e.getSource();
- source.setVisible(false);
- source.setEnabled(false);
- BalloonTip bt = new BalloonTip(
- source.getAttachedComponent(),
- source.getAttachedComponent().getToolTipText(),
- new RoundedBalloonStyle(5, 5, Color.WHITE, Color.BLACK),
- true);
- bt.setVisible(true);
- }
- });
- ToolTipUtils.balloonToToolTip(bt, 500, 3000);
rigthPanel.add(testToottip, new GridBagConstraints(0, 0, 1, 1, 1, 0,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
2, 2, 2, 2), 0, 0));
// table
try {
- BasicTableModel tableModel = new BasicTableModel(new File(".")
- .getCanonicalFile());
+ BasicTableModel tableModel = new BasicTableModel(new File(".").
+ getCanonicalFile().getParentFile());
JTable table = new JTable(tableModel);
table.setDefaultRenderer(String.class, new BasicTableRenderer());
@@ -169,6 +126,8 @@
DataTipManager.get().register(table);
//ViewTooltips.register(table);
+
+ //table.addMouseMotionListener(new TableTooltipListener());
} catch (IOException e1) {
e1.printStackTrace();
}
@@ -178,6 +137,16 @@
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rigthPanel);
pane.setName("mainViewPane");
+ // OR
+
+ /*Split modelRoot = new ColSplit(new RowSplit(new Leaf("left"), new Divider(), new Leaf("right")), new Divider(), new Leaf("bottom"));
+ MultiSplitLayout mpLayout = new MultiSplitLayout(modelRoot);
+ mpLayout.setDividerSize(2);
+ JXMultiSplitPane pane = new JXMultiSplitPane(mpLayout);
+ pane.add(leftPanel, "left");
+ pane.add(rigthPanel, "right");
+ pane.add(new JLabel("Test bottom"), "bottom");*/
+
add(pane, BorderLayout.CENTER);
}
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MyApplication.properties
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MyApplication.properties 2010-03-08 19:03:09 UTC (rev 398)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MyApplication.properties 2010-03-11 15:13:06 UTC (rev 399)
@@ -2,3 +2,4 @@
Application.title = My frame title
Application.vendor = CodeLutin
Application.vendorId = codelutin
+Application.lookAndFeel = com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableModel.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableModel.java 2010-03-08 19:03:09 UTC (rev 398)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableModel.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -19,14 +19,10 @@
import java.io.File;
-import javax.swing.event.TreeModelListener;
import javax.swing.table.AbstractTableModel;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreePath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.w3c.dom.views.AbstractView;
/**
* BasicTableModel
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableRenderer.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableRenderer.java 2010-03-08 19:03:09 UTC (rev 398)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/table/BasicTableRenderer.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -19,8 +19,6 @@
package org.nuiton.test.table;
import java.awt.Component;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
import javax.swing.JComponent;
import javax.swing.JTable;
@@ -35,8 +33,11 @@
* Last update : $Date$
* By : $Author$
*/
-public class BasicTableRenderer extends DefaultTableCellRenderer implements MouseListener {
+public class BasicTableRenderer extends DefaultTableCellRenderer {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 6448391469600567754L;
+
/*
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
*/
@@ -46,77 +47,8 @@
JComponent c = (JComponent)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
- /*JLabel b = new JLabel(value.toString()) {
- @Override
- public JToolTip createToolTip() {
- JToolTip tt = super.createToolTip();
-
- //TablecellBalloonTip tip = new TablecellBalloonTip(table, "etst", row, column, new RoundedBalloonStyle(5,5
- // , Color.WHITE, Color.BLACK), Orientation.RIGHT_ABOVE, AttachLocation.ALIGNED, 5, 5, true);
- BalloonTip bt = new BalloonTip(this, this.getToolTipText(), new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), false);
- /*bt.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
-
- BalloonTip source = (BalloonTip)e.getSource();
- source.closeBalloon();
-
- BalloonTip bt = new BalloonTip(source, source.getToolTipText(), new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), true);
- bt.setVisible(true);
- }
-
- });
- ToolTipUtils.balloonToToolTip(bt, 500, 3000);
- tt.setComponent(bt);
-
- return tt;
- }
- };
- b.setToolTipText("Tooltip = " + value.toString());*/
+ c.setToolTipText("<html><body>Un test de texte Enorme, avec du <b>gras</b>, des saut<br />de lignes, etc...<p>un nouveau paragraphe...</p><p>et le contenu réel : " + value + "</p></body></html>");
- this.addMouseListener(new BasicTableRenderer());
-
return this;
}
-
- /*
- * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
- */
- @Override
- public void mouseClicked(MouseEvent e) {
- System.out.println("mouseClicked");
- }
-
- /*
- * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
- */
- @Override
- public void mousePressed(MouseEvent e) {
- System.out.println("mousePressed");
- }
-
- /*
- * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
- */
- @Override
- public void mouseReleased(MouseEvent e) {
- System.out.println("mouseReleased");
- }
-
- /*
- * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
- */
- @Override
- public void mouseEntered(MouseEvent e) {
- System.out.println("mouseEntered");
- }
-
- /*
- * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
- */
- @Override
- public void mouseExited(MouseEvent e) {
- System.out.println("mouseExited");
- }
-
}
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tooltip/BalloonPopupFactory.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tooltip/BalloonPopupFactory.java (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tooltip/BalloonPopupFactory.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -0,0 +1,273 @@
+/* *##%
+ * Copyright (C) 2010 Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.nuiton.test.tooltip;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.MouseInfo;
+import java.awt.Point;
+import java.awt.PointerInfo;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+import javax.swing.JComponent;
+import javax.swing.JLayeredPane;
+import javax.swing.JTable;
+import javax.swing.JToolTip;
+import javax.swing.JWindow;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.Timer;
+
+import net.java.balloontip.BalloonTip;
+import net.java.balloontip.TablecellBalloonTip;
+import net.java.balloontip.BalloonTip.AttachLocation;
+import net.java.balloontip.BalloonTip.Orientation;
+import net.java.balloontip.positioners.BalloonTipPositioner;
+import net.java.balloontip.styles.RoundedBalloonStyle;
+
+public class BalloonPopupFactory extends PopupFactory {
+
+ protected static BalloonTip bt;
+
+ @Override
+ public Popup getPopup(Component owner, Component contents, int x, int y)
+ throws IllegalArgumentException {
+ // A more complete implementation would cache and reuse
+ // popups
+ return new BalloonPopup(owner, contents, x, y);
+ }
+
+ private class BalloonPopup extends Popup implements MouseListener, MouseMotionListener {
+ protected JLayeredPane topLevelContainer = null; // The balloon is drawn on this pane
+ private JWindow popupWindow;
+ private boolean toFade = true;
+ private int currOpacity;
+ private Timer fadeInTimer;
+ private Timer fadeOutTimer;
+ private Component contents;
+ private Component owner;
+ private int ownerX, ownerY;
+
+
+ //Will need to keep track of the component... I only want JToolTips to behave in this strange way and combo-box drop-down lists and menus will be affected.
+
+ public BalloonPopup(Component owner, Component contents, int ownerX, int ownerY) {
+
+ /*Container parent = owner.getParent();
+ // Follow the path of parents of the attached component until you find the top level container
+ while (true) {
+ // If you're a top level container (JFrame, JDialog, JInternalFrame, JApplet or JWindow)
+ if (parent instanceof RootPaneContainer) {
+ topLevelContainer = ((RootPaneContainer)parent).getLayeredPane();
+ // Exit the infinite loop
+ break;
+ // If you're a tab
+ } else if (parent instanceof JTabbedPane) {
+
+ ((JTabbedPane)parent).addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ //checkVisibility();
+ }
+ });
+ }
+ parent = parent.getParent();
+ }*/
+
+ /*// We use the popup layer of the top level container (frame or dialog) to show the balloon tip
+ topLevelContainer.add(contents, JLayeredPane.POPUP_LAYER);
+ // If the attached component is moved/hidden/shown, the balloon tip should act accordingly
+ owner.addComponentListener(this);
+ // If the window is resized, we should check if the balloon still fits
+ topLevelContainer.addComponentListener(this);
+ // Don't allow to click 'through' the component; will also enable to close the balloon when it's clicked
+ topLevelContainer.addMouseListener(this);*/
+
+ // create a new heavyweight window
+ //this.popupWindow = new JWindow();
+ this.contents = contents;
+ this.owner = owner;
+ this.ownerX = ownerX;
+ this.ownerY = ownerY;
+ // determine the popup location
+ //popupWindow.setLocation(ownerX, ownerY);
+ // add the contents to the popup
+ //popupWindow.getContentPane().add(contents, BorderLayout.CENTER);
+ //contents.invalidate();
+ //JComponent parent = (JComponent) contents.getParent();
+
+ //popupWindow.setAlwaysOnTop(true); //Since the main frame is set to always be on top, I need to set this on the popupWindow... or it will stay behind the frame.
+ }
+
+ @Override
+ public void show() {
+
+ /*// We use the popup layer of the top level container (frame or dialog) to show the balloon tip
+ topLevelContainer.add(new JLabel("Hoho"), JLayeredPane.POPUP_LAYER);
+ // If the attached component is moved/hidden/shown, the balloon tip should act accordingly
+ topLevelContainer.addComponentListener(this);
+ // If the window is resized, we should check if the balloon still fits
+ topLevelContainer.addComponentListener(this);
+ // Don't allow to click 'through' the component; will also enable to close the balloon when it's clicked
+ topLevelContainer.addMouseListener(this);
+
+ topLevelContainer.setVisible(true);*/
+
+ if (bt != null && bt.isVisible()) {
+ bt.closeBalloon();
+ }
+
+ JToolTip contentTooltip = (JToolTip)contents;
+ //JComponent cc = contentTooltip.getComponent();
+
+ if (contentTooltip.getComponent() instanceof JTable) {
+ JTable srcTable = (JTable)contentTooltip.getComponent();
+
+ //Point p = new Point(ownerX - (int)srcTable.getLocation().getX(), ownerY - (int)srcTable.getLocation().getY());
+
+ Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
+ Point p = new Point((int)(mouseLocation.getX() - srcTable.getLocationOnScreen().getX()),
+ (int)(mouseLocation.getY() - srcTable.getLocationOnScreen().getY()));
+ int row = srcTable.rowAtPoint(p);
+ int column = srcTable.columnAtPoint(p);
+ if (row >= 0 && column >= 0 ) {
+ bt = new TablecellBalloonTip(srcTable, contentTooltip.getTipText(),
+ row, column, new RoundedBalloonStyle(5,5, Color.WHITE, Color.BLACK),
+ Orientation.LEFT_ABOVE, AttachLocation.CENTER, 0, 0, false);
+ //bt.setLocation(new Point((int)(ownerX - owner.getLocationOnScreen().getX()), (int)(ownerY - owner.getLocationOnScreen().getY())));
+ bt.addMouseListener(this);
+ }
+
+ }
+ else {
+ bt = new BalloonTip((JComponent)owner, contentTooltip.getTipText(),
+ new RoundedBalloonStyle(5,5, Color.WHITE, Color.BLACK), Orientation.LEFT_ABOVE, AttachLocation.ALIGNED, 5, 5, false);
+ //bt.setLocation(new Point((int)(ownerX - owner.getLocationOnScreen().getX()), (int)(ownerY - owner.getLocationOnScreen().getY())));
+
+ bt.addMouseListener(this);
+ }
+ }
+
+ @Override
+ public void hide() {
+
+ if (bt != null) {
+ fadeOutTimer = new Timer(500, new CloseBalloonTimer(bt));
+ fadeOutTimer.start();
+ }
+ }
+
+ class CloseBalloonTimer implements ActionListener {
+ public BalloonTip bt;
+
+ public CloseBalloonTimer(BalloonTip bt) {
+ this.bt = bt;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (bt.isVisible()) {
+ bt.closeBalloon();
+ }
+ }
+ }
+
+ /*
+ * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseClicked(MouseEvent e) {
+
+ /*BalloonTip btSource = (BalloonTip)e.getSource();
+ btSource.closeBalloon();
+ BalloonTip newBt = new BalloonTip((JComponent)owner, btSource.getText(),
+ new RoundedBalloonStyle(5,5, Color.WHITE, Color.BLACK), Orientation.LEFT_ABOVE, AttachLocation.ALIGNED, 0, 0, true);
+ newBt.addMouseMotionListener(this);*/
+
+ BalloonTip btSource = (BalloonTip)e.getSource();
+
+ BalloonTip newBt;
+ if (btSource.getAttachedComponent() instanceof JTable) {
+ JTable srcTable = (JTable)btSource.getAttachedComponent();
+
+ Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
+ Point p = new Point((int)(mouseLocation.getX() - srcTable.getLocationOnScreen().getX()),
+ (int)(mouseLocation.getY() - srcTable.getLocationOnScreen().getY()));
+ int row = srcTable.rowAtPoint(p);
+ int column = srcTable.columnAtPoint(p);
+ if (row >= 0 && column >= 0 ) {
+ newBt = new TablecellBalloonTip(srcTable, btSource.getText(),
+ row, column, new RoundedBalloonStyle(5,5, Color.WHITE, Color.BLACK),
+ Orientation.LEFT_ABOVE, AttachLocation.ALIGNED, 0,
+ 0, true);
+ newBt.addMouseMotionListener(this);
+ newBt.setLocation(new Point(ownerX, ownerY));
+ }
+ }
+ else {
+ newBt = new BalloonTip((JComponent)owner, btSource.getText(),
+ new RoundedBalloonStyle(5,5, Color.WHITE, Color.BLACK), Orientation.LEFT_ABOVE, AttachLocation.ALIGNED, 5, 5, true);
+ newBt.addMouseMotionListener(this);
+ }
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {}
+
+ @Override
+ public void mouseReleased(MouseEvent e) {}
+
+ @Override
+ public void mouseEntered(MouseEvent e) {}
+
+ @Override
+ public void mouseExited(MouseEvent e) {}
+
+ /*
+ * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseDragged(MouseEvent e) {
+
+ BalloonTip btSource = (BalloonTip)e.getSource();
+ BalloonTipPositioner positioner = btSource.getPositioner();
+ //positioner.determineAndSetLocation(
+ // new Rectangle((int)e.getPoint().getX(), (int)e.getPoint().getY(),
+ // btSource.getAttachedComponent().getWidth(), btSource.getAttachedComponent().getHeight()));
+
+ //Component attachedComponent = btSource.getAttachedComponent();
+ positioner.determineAndSetLocation(
+ new Rectangle((int)btSource.getLocation().getX() + (int)e.getPoint().getX(),
+ (int)btSource.getLocation().getY() + (int)e.getPoint().getY(),
+ btSource.getAttachedComponent().getWidth(), btSource.getAttachedComponent().getHeight()));
+ }
+
+ /*
+ * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
+ */
+ @Override
+ public void mouseMoved(MouseEvent e) {
+
+ }
+ }
+}
Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tooltip/BalloonPopupFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeModel.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeModel.java 2010-03-08 19:03:09 UTC (rev 398)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeModel.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -114,6 +114,4 @@
// TODO Auto-generated method stub
}
-
-
}
Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeRenderer.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeRenderer.java (rev 0)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeRenderer.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -0,0 +1,57 @@
+/* *##%
+ * Copyright (C) 2010 Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.nuiton.test.tree;
+
+import java.awt.Component;
+
+import javax.swing.JComponent;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+/**
+ * TODO add comment here.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class BasicTreeRenderer extends DefaultTreeCellRenderer {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 6448391469600567754L;
+
+ /*
+ * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
+ */
+ @Override
+ public Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean isSelected,
+ boolean expanded,
+ boolean leaf, int row,
+ boolean hasFocus) {
+
+ JComponent c = (JComponent)super.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, hasFocus);
+
+ c.setToolTipText("<html><body>Un test de texte Enorme, avec du <b>gras</b>, des saut<br />de lignes, etc...<p>un nouveau paragraphe...</p><p>et le contenu réel : " + value + "</p> (" + row + ")</body></html>");
+
+ return this;
+ }
+}
\ No newline at end of file
Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/BasicTreeRenderer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java
===================================================================
--- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java 2010-03-08 19:03:09 UTC (rev 398)
+++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/tree/FilterTreeModel.java 2010-03-11 15:13:06 UTC (rev 399)
@@ -18,9 +18,6 @@
package org.nuiton.test.tree;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
1
0