package textbender.o.awt; // Copyright 2005, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.awt.*; /** AWT utilities. */ public class AWT { private AWT() {} /** A shared colour-pair, for use in the AWT event dispatch thread. */ public static ColorPair colorPair() { assert java.awt.EventQueue.isDispatchThread(); return colorPair; } private static final ColorPair colorPair = new ColorPair(); /** A shared dimension, for use in the AWT event dispatch thread. */ public static Dimension dimension() { assert java.awt.EventQueue.isDispatchThread(); return dimension; } private static final Dimension dimension = new Dimension(); /** Returns a shared string builder, for use in the AWT event dispatch thread. * After using it for big jobs, consider emptying and trimming it * e.g. by calling {@linkplain #emptyStringBuilder() emptyStringBuilder}().trimToSize(). */ public static StringBuilder stringBuilder() { assert java.awt.EventQueue.isDispatchThread(); return stringBuilder; } private static final StringBuilder stringBuilder = new StringBuilder(); /** Empties and returns the {@linkplain #stringBuilder() shared string builder}. */ public static StringBuilder emptyStringBuilder() { assert java.awt.EventQueue.isDispatchThread(); stringBuilder.delete( 0, Integer.MAX_VALUE ); return stringBuilder; } /** A shared insets, for use in the AWT event dispatch thread. */ public static Insets insets() { assert java.awt.EventQueue.isDispatchThread(); return insets; } private static final Insets insets = new Insets( /*top*/0, /*left*/0, /*bottom*/0, /*right*/0 ); /** A shared point, for use in the AWT event dispatch thread. */ public static Point point() { assert java.awt.EventQueue.isDispatchThread(); return point; } private static final Point point = new Point(); /** A shared rectangle, for use in the AWT event dispatch thread. */ public static Rectangle rectangle() { assert java.awt.EventQueue.isDispatchThread(); return rectangle; } private static final Rectangle rectangle = new Rectangle(); }