Friday, October 8, 2010

How to Make a JTextPane / StyledDocument TRULY Transparent

It's been a long time since my last update; I wanted to share with you a solution that took me weeks to get:

Q: How can I make a Java Swing JTextPane component (including text background) transparent?

A: textPane.setBackground(new Color(255, 255, 255, 0)) ; <- Set a background Color with a 0 alpha value (a 100% transparent color).

In my case, using textPane.setOpaque(false) didn't work, and I tried EVERYTHING trying to understand why, and get around it. I blamed the StyledDocument believing the text or paragraph included a background color, I blamed the component layers and their blending, I browsed over a lot of forums and pages; no one gave me a working solution.

I tried overriding paintComponent and setting an Icon property for the text but both draw the image above the text.

I hope this is useful for people who, just like me, can't understand WHY IN THE WORLD the setOpaque method does not always work on a JTextPane with a styled text. I still don't know why.

If someone out there is as wise as to have the answer, it would be nice to know, for know there's the solution to make it work. ;-)

See you later!

Wednesday, September 15, 2010

Credo Mexican (Mexican Creed)

by Ricardo López Mendez

Just as the last year, I post this from 1940 that I think still reflects the essence and feelings of our Mexican culture. It makes me cry sometimes.

The essence of it is the patriotism expressed as FAITH; México, CREO EN TÍ (Mexico, I BELIEVE - IN YOU -):

¡QUE VIVA MÉXICO, CABRONEEES!

México, creo en ti,
como en el vértice de un juramento.
Tú hueles a tragedia, tierra mía,
y sin embargo ríes demasiado,
acaso porque sabes que la risa
es la envoltura de un dolor callado.

México, creo en ti,
sin que te represente en una forma
porque te llevo dentro, sin que sepa
lo que tú eres en mí; pero presiento
que mucho te pareces a mi alma,
que sé que existe, pero no la veo.

México, creo en ti,
en el vuelo sutil de tus canciones
que nacen porque sí, en la plegaria
que yo aprendí para llamarte Patria:
algo que es mío en mí como tu sombra,
que se tiende con vida sobre el mapa.

México, creo en ti,
en forma tal que tienes de mi amada
la promesa y el beso que son míos,
sin que sepa por qué se me entregaron:
no sé si por ser bueno o por ser malo
o porque del perdón nazca el milagro.

México, creo en ti
sin preocuparme el oro de tu entraña:
es bastante la vida de tu barro
que refresca lo claro de las aguas
en el jarro que llora por los poros
la opresión de la carne de tu raza.

México, creo en ti,
porque creyendo te me vuelves ansia
y castidad y celo y esperanza.
Si yo conozco el cielo, es por tu cielo,
si conozco el dolor, es por tus lágrimas
que están en mí aprendiendo a ser lloradas.

México, creo en ti,
en tus cosechas de milagrerías
que sólo son deseo en las palabras.
Te consagras de auroras que te cantan
¡y todo el bosque se te vuelve carne!,
¡y todo el hombre se te vuelve selva!

México, creo en ti,
porque nací de ti, como la flama
es compendio del fuego y de la brasa;
porque me puse a meditar que existes
en el sueño y materia que me forman
y en el delirio de escalar montañas.

México, creo en ti,
porque escribes tu nombre con la equis,
que algo tiene de cruz y de calvario;
porque el águila brava de tu escudo
se divierte jugando a los volados
con la vida y, a veces, con la muerte.

México, creo en ti,
como creo en los clavos que te sangran,
en las espinas que hay en tu corona,
y en el mar que te aprieta la cintura
para que tomes en la forma humana
hechura de sirena en las espumas.

México, creo en ti,
porque si no creyera que eres mío
el propio corazón me lo gritara
y te arrebataría con mis brazos
a todo intento de volverte ajeno
sintiendo que a mí mismo me salvava.

México, creo en ti,
porque eres el alto de mi marcha
y el punto de partida de mi impulso.
¡Mi credo, Patria, tiene que ser tuyo,
como la voz que salva y como el ancla...!

Wednesday, January 13, 2010

We Have To Improve Communication - Part II

So last time I talked about the use of the "I" pronoun instead of "one" or "they" when talking about opinions or feelings. It seems simple but is deeply rooted in the notion of taking ownership of my own feelings and thoughts.

It is hard to get used to it because it implies a deep transformation within myself: I am no longer justifying my actions in advance by deflecting my responsibilities on others.

But most importantly, it implies I acknowledge my own thoughts and feelings are as valid as others', and they can disagree with me; I'm starting to LISTEN. Because when I acknowledge my own feelings and thoughts are not the rest of the world's, I automatically open myself to different ideas.

Now let's talk about something that may sound rather trivial at first:

How to ask for things.

"Aaw come on, Juan! Are you saying I don't know how to ask for things? That's intuitive!"

Let's make a very simple exercise: take a piece of paper and something to write with. (a pen, pencil, etc...)

Ready?

Ok, now write down on that piece of paper how would you ask for someone to pick you up in the morning to drive you to the airport.

Now keep that piece of paper for later.

I as said on my previous post, communication has an structure, and that structure has a purpose.

The structure of a request.

A request has to contain the following:

- What needs to be done.
- What need will it satisfy? / Why should it be done? (objective, purpose of the request)
- How should it be done. (acceptance criteria)
- When should it be done. (timeline, deadline)

Now let's see: How would I write a request for John to pick me up in order to drive me to the airport?

"Hi John, could you please pick me up tomorrow at 7 am at my home and drive me to the Monterrey International Airport? I need to be there at 8 am as I have to take the 10 am flight to NYC, and am advised to be 2 hours in advance. I have an important meeting with a potential client at 14:00 hrs EST and can't miss it.

I will be waiting for you outside, please ring my cell if I'm not there: 555-555-5555

Thank you!"

A rather large e-mail for a simple request don't you think so? Well, let's see some common scenarios:

- "Hi John, please pick me up tomorrow morning at home. I need you to drive me to the airport. I have to be there at 8 am."

The next day John arrived to my home... at 7:15 am, as he thought that was a good time. John didn't know traffic from home is jammed at that time. I arrived at 8:30 am and was not admitted to the flight. I had to cancel the meeting as I couldn't reschedule it.

Is it John's fault? No! I missed the when it should be done, and why it should be done parts. If John knew how important this meeting was, maybe even if I didn't indicate the time for him to pick me up, he'd certainly have arrived the earliest.

- "Hi John, please pick me up tomorrow morning at 7 am. I have to take a flight at 8 am and can't miss it".

John arrived sharp... to the office! And he had no way to call me. I waited for John until 7:20 and had to take a cab. I arrived late.

Is it John's fault? No! I didn't tell him to pick me up at home, nor I gave him any contact number in case of emergency.

- "Hi John, tommorrow 7 am at home. You'll drive me to the airport."

"Clear enough" John thought. And he went into a party with some friends. "How important can it be? I do this almost every week." He arrived hungover at 7:10 am. He was driving so fast we crashed. I took a cab but I missed the flight.

Is it John's fault? Well, I didn't tell him to get drunk, but I certainly didn't tell him how important this meeting was. Had he known, he might not have gone to that party. I missed the why it should be done part.

The ideal scenario.

Enough tragedy, let's see what happened after I asked John properly:

John left his home at 6:00 to go pick me up, but he had a car accident at 6:45 am. He called my cellphone and I asked for a taxi cab. I called my office admin and told her about the situation to see what she could do. I informed my colleagues at NYC about the risk of me not arriving on time or not arriving at all.

Taxi arrived at 7:10 am and I roughly made it to the flight at 8:15 am, where the airline had been notified of my delay and security inspectors were waiting for me. I made it! I informed my colleagues and called John to see how he was doing: he was alright.

The importance of properly asking for things.

We have to remember we take decisions based on the information we have. Providing the proper information to people is then crucial if I want to rely on others to achieve a goal; it's not just about them doing it right, it's about me asking it right.

I bet you can think of several examples now, I bet you're thinking in your head about how you ask for things, and how not having asked them properly affected the results. This applies to both our professional and personal lives.

When I went through this course, at this point I realized why people kept failing me: I was asking others to fix in themselves something I had to fix in myself!

If after requesting things properly people still don't comply, well, that's another story. I accomplished my responsibility of making a proper request.

So now go back to the piece of paper where you wrote a request as an exercise. Take a deeper look at it.

Is it really that easy to ask for things? Is it really that trivial?

Hope this helps you somehow. I'd like to read your thoughts at the comments section.

Regards!

Tuesday, January 12, 2010

It May be Happening to You

What is happenning to me? All is right in my life: I have a great job which I like a lot, my family and friends are ok, my sentimental life is ok, my health is ok.

Why is it I don't feel enthusiastic like before? I am not full of energy like before, I get headaches, bad mood. I'm not able to focus and I get sleepy too soon over the day.

Coffee doesn't work anymore and my attitude is turning all negative.

Why is it I know I have to change my attitude, and I try to do something about it, but I can't? It's frustrating!

I have been to a psychologist before, back when I was overloaded with work, with stress, but I am over it now. This new job has it's challenges, but it's not stressing at all.

I'm not depressed; my doctor said it. Nor I have any health problems.

Exercise! Yes that's the solution, I used to be very active and healthy. I wake up in all disposition to exercise, but my mid-day I loose all energy. I tried it for the first week, but it just got me more tired.

It's a vicious circle! Have I been cursed?

Then I heard comments from the friends I camped with last weekend. Hey man! You snore out loud!

I know, I snore, but only when I lay upside, I replied. Well, not anymore, and it seems it's becoming louder and louder according to my family.

Ok, let's read about it: snoring. A very common thing it seems, and it can be due to physical and fisiological reasons: air can be blocked on the nose, at the throat, it can be due to overweight, drinking...

Then I further read: sleep apnea. Sleep apnea is caused when air is completely blocked during sleep, and heart receives less oxygen. It usually causes a sense of asfixya that wakes up the person in order to breathe harder.

Result: no deep sleep, no real rest, possible cardiac attack, very low quality of life. Wow! May that be it?

I keep reading: this lack of rest causes sleepiness during the day, headaches, tiredness, lack of concentration, bad mood. Bingo!

I never thought something like this can cause so many problems. So many people out there snore, and they joke about it, and they learn to get along with it; their partners and family learn to get along with it.

Most of them suffer sleep apnea, and they don't know about it; they don't realize the health problems it implies.

People get divorced for it! People loose jobs because of it! People relationships get detrimented by it!

It is a serious problem. So I've decided to start doing something about it.

Interestingly, health insurance plans don't cover it: none of the hospitals and clinics and doctors I called are affiliated to any insurance company.

And everyone sells their own miraclous technique: a device with a mask you need to connect every night to your face, the newest laser treatment... it's like a joke, like they're merchandising with such an important disease.

And companies, well, they won't assess how much this tampers their people performance, their productivity. I have just been off my first performance review on December, and results were mediocre for myself. I had no way to explain and no will to excuse myself, I don't like excuses.

Now I know it's a health problem, a health problem few people know about. It changes your mood, your energy, your creativity, your intelligence.

You don't believe me? Try not sleeping for two days. Now imagine not sleeping for months. That's how serious it is. You can have an accident because of it.

It's a dissappointment it is not regarded the importance it should; or maybe it is such a sadly common problem, it will be costly cover it.

Anyway, I made my first trial: I bought myself nasal strips, they're know as "Breathe Right" in US, "Anti-Ronc" in Mexico. These strips attach to your nose and open up more space for air to come in, immediately relieving nasal congestion.

It might work or not, remember snoring has very different causes and so does sleep apnea.

I have been using it for 3 days. So far so good. Let's see what happens after this week; I don't think recovering for years of bad sleep happens in a day. I feel better with time, I feel rested.

Hopefully my problem is nasal. And it makes sense: I broke my nose when I was 5 years, maybe it's time to have a surgery, if I can assess this is the cause of my sleep apnea.

I hope this experience is helpful for anyone out there: beware of snoring, it seriously affects your life quality.

And any company CEO or insurance company boss out there: assess the seriousness of the problem, it is already costing you a lot.