X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fcomponents%2FStyledLabel.java;fp=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fcomponents%2FStyledLabel.java;h=cad8a25ab69fd55813fb8a0b177b8918783a4ab4;hb=d8776d61bfa934a68829d9971bb89311e55c67cf;hp=0000000000000000000000000000000000000000;hpb=b3c3c1071dfdca4c6b3eb9935dc461201abdaf60;p=debian%2Fopenrocket
diff --git a/src/net/sf/openrocket/gui/components/StyledLabel.java b/src/net/sf/openrocket/gui/components/StyledLabel.java
new file mode 100644
index 00000000..cad8a25a
--- /dev/null
+++ b/src/net/sf/openrocket/gui/components/StyledLabel.java
@@ -0,0 +1,111 @@
+package net.sf.openrocket.gui.components;
+
+import java.awt.Font;
+
+import javax.swing.JLabel;
+import javax.swing.SwingConstants;
+
+/**
+ * A resizeable and styleable JLabel. The method {@link #resizeFont(float)} changes the
+ * current font size by the given (positive or negative) amount. The change is relative
+ * to the current font size. The method {@link #setFontStyle(Style)} sets the style
+ * (bold/italic) of the font.
+ *
+ * A nice small text is achievable by new ResizeLabel("My text", -2);
+ *
+ * @author Sampo Niskanen
+ */
+
+public class StyledLabel extends JLabel {
+
+ public enum Style {
+ PLAIN(Font.PLAIN),
+ BOLD(Font.BOLD),
+ ITALIC(Font.ITALIC),
+ BOLD_ITALIC(Font.BOLD | Font.ITALIC);
+
+ private int style;
+ Style(int fontStyle) {
+ this.style = fontStyle;
+ }
+ public int getFontStyle() {
+ return style;
+ }
+ }
+
+
+
+ public StyledLabel() {
+ this("", SwingConstants.LEADING, 0f);
+ }
+
+ public StyledLabel(String text) {
+ this(text, SwingConstants.LEADING, 0f);
+ }
+
+ public StyledLabel(float size) {
+ this("", SwingConstants.LEADING, size);
+ }
+
+ public StyledLabel(String text, float size) {
+ this(text, SwingConstants.LEADING, size);
+ }
+
+ public StyledLabel(String text, int horizontalAlignment, float size) {
+ super(text, horizontalAlignment);
+ resizeFont(size);
+ checkPreferredSize(size, Style.PLAIN);
+ }
+
+
+
+ public StyledLabel(Style style) {
+ this("", SwingConstants.LEADING, 0f, style);
+ }
+
+ public StyledLabel(String text, Style style) {
+ this(text, SwingConstants.LEADING, 0f, style);
+ }
+
+ public StyledLabel(float size, Style style) {
+ this("", SwingConstants.LEADING, size, style);
+ }
+
+ public StyledLabel(String text, float size, Style style) {
+ this(text, SwingConstants.LEADING, size, style);
+ }
+
+ public StyledLabel(String text, int horizontalAlignment, float size, Style style) {
+ super(text, horizontalAlignment);
+ resizeFont(size);
+ setFontStyle(style);
+ checkPreferredSize(size, style);
+ }
+
+
+
+
+ private void checkPreferredSize(float size, Style style) {
+ String str = this.getText();
+ if (str.startsWith("") && str.indexOf("