0031075: Application Framework - reading STEP file into TDocStd_Document leads to...
[occt.git] / samples / java / jniviewer / app / src / main / java / com / opencascade / jnisample / OcctJniLogger.java
1 // Copyright (c) 2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 package com.opencascade.jnisample;
15
16 import java.util.concurrent.locks.ReentrantLock;
17
18 import android.util.Log;
19 import android.widget.TextView;
20
21 //! Auxiliary class for logging messages
22 public class OcctJniLogger
23 {
24
25   //! Setup text view
26   public static void setTextView (TextView theTextView)
27   {
28     if (myTextView != null)
29     {
30       myLog = myTextView.getText().toString();
31     }
32
33     myTextView = theTextView;
34     if (myTextView != null)
35     {
36       myTextView.setText (myLog);
37       myLog = "";
38     }
39   }
40
41   //! Interface implementation
42   public static void postMessage (String theText)
43   {
44     final String aCopy = new String (theText);
45     Log.e (myTag, theText);
46
47     myMutex.lock();
48     final TextView aView = myTextView;
49     if (aView == null)
50     {
51       myLog += aCopy;
52       myMutex.unlock();
53       return;
54     }
55
56     aView.post (new Runnable()
57     {
58       public void run()
59       {
60         aView.setText (aView.getText() + aCopy + "\n");
61       }
62     });
63     myMutex.unlock();
64   }
65
66   private static final String        myTag      = "occtJniViewer";
67   private static final ReentrantLock myMutex    = new ReentrantLock (true);
68   private static TextView            myTextView = null;
69   private static String              myLog      = "";
70
71 }