Actually the way it works is this.
From what I have learned in my games on sub-normal trough painful is that in all instances the Ai ONLY looks at other players's Millitary Rating, which is defined according to the manual as Attack+Defense+Hitpoints /10, and most definatly NOT at how big your military spending is. Figures, 'cause people (I anyway hehe) tend to build only constructors and such.
If your millitary rating falls below 20, (meaning your combined Att+Def+Hp figure ranks 20% of average compared to the other races) someone will surely attack you within a couple of turns.
The smarter the Ai, the quicker it will attack you. Sub-normals might tolerate you at 40, but a Bright one certainly won't.
Also, the AI will want to quickly keep pace with millitary rating, and to do that they all build fleets and ships that are quickly constructed. The downside is, their ships will often have slightly dated technologies and defences. This they do on all difficulty levels to some extend.
If you are winning the war ,and you get a messages saying 'the war is not going well, blabla' it means the AI has a massive fleet you just haven't encoutered yet. Doesn't matter, if you're winning with superior technology the amount of ships they have is totally irrelevant.
A good way to keep track of your likeliness of being attacked soon is to regularly check your race relations screen. It wil sometimes say ++Trading, -Ethical alignment, +Millitary strength, etc. If a strong neighbour starts to get sour for no obvious reason (you're trading and swapping techs, after all!) its because your millitary rating is too low and he figures he can subdue you.
The best solution I have found to this so far is to pick the most productive colonies you have, design a defender (small/medium vessel maxed out with your latest weapons and defences but no engines/other stuff), and let them crank these out as fast as they can.
If its enough, you'll see the relations starting to warm up again, and if you have a truly superior army, you'll see that everyone wants to stay friends with you, start paying tribute all by themselves, etc etc.
Good luck!