/** * Creates a new image title with the given image scaled to the given * width and height in the given location. * * @param image the image (<code>null</code> not permitted). * @param height the height used to draw the image. * @param width the width used to draw the image. * @param position the title position. * @param horizontalAlignment the horizontal alignment. * @param verticalAlignment the vertical alignment. * @param padding the amount of space to leave around the outside of the * title. */ public ImageTitle(Image image, int height, int width, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, RectangleInsets padding) { super(position, horizontalAlignment, verticalAlignment, padding); if (image == null) { throw new NullPointerException("Null 'image' argument."); } this.image = image; setHeight(height); setWidth(width); }
/** * Creates a new title. * * @param text the text for the title (<code>null</code> not permitted). * @param font the title font (<code>null</code> not permitted). * @param paint the title paint (<code>null</code> not permitted). * @param position the title position (<code>null</code> not permitted). * @param horizontalAlignment the horizontal alignment (<code>null</code> not permitted). * @param verticalAlignment the vertical alignment (<code>null</code> not permitted). * @param spacer the space to leave around the outside of the title. */ public TextTitle(String text, Font font, Paint paint, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Spacer spacer) { super(position, horizontalAlignment, verticalAlignment, spacer); if (text == null) { throw new NullPointerException("Null 'text' argument."); } if (font == null) { throw new NullPointerException("Null 'font' argument."); } if (paint == null) { throw new NullPointerException("Null 'paint' argument."); } this.text = text; this.font = font; this.paint = paint; this.backgroundPaint = null; }
/** * Some checks for the equals() method. */ public void testEquals() { // use the TextTitle class because it is a concrete subclass Title t1 = new TextTitle(); Title t2 = new TextTitle(); assertEquals(t1, t2); t1.setPosition(RectangleEdge.LEFT); assertFalse(t1.equals(t2)); t2.setPosition(RectangleEdge.LEFT); assertTrue(t1.equals(t2)); t1.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertFalse(t1.equals(t2)); t2.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertTrue(t1.equals(t2)); t1.setVerticalAlignment(VerticalAlignment.BOTTOM); assertFalse(t1.equals(t2)); t2.setVerticalAlignment(VerticalAlignment.BOTTOM); assertTrue(t1.equals(t2)); }
/** * Creates a new image title with the given image scaled to the given * width and height in the given location. * * @param image the image ({@code null} not permitted). * @param height the height used to draw the image. * @param width the width used to draw the image. * @param position the title position. * @param horizontalAlignment the horizontal alignment. * @param verticalAlignment the vertical alignment. * @param padding the amount of space to leave around the outside of the * title. */ public ImageTitle(Image image, int height, int width, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, RectangleInsets padding) { super(position, horizontalAlignment, verticalAlignment, padding); if (image == null) { throw new NullPointerException("Null 'image' argument."); } this.image = image; setHeight(height); setWidth(width); }
/** * Creates a new title. * * @param position the position of the title (<code>null</code> not * permitted). * @param horizontalAlignment the horizontal alignment of the title (LEFT, * CENTER or RIGHT, <code>null</code> not * permitted). * @param verticalAlignment the vertical alignment of the title (TOP, * MIDDLE or BOTTOM, <code>null</code> not * permitted). * @param padding the amount of space to leave around the outside of the * title (<code>null</code> not permitted). */ protected Title(RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, RectangleInsets padding) { ParamChecks.nullNotPermitted(position, "position"); ParamChecks.nullNotPermitted(horizontalAlignment, "horizontalAlignment"); ParamChecks.nullNotPermitted(verticalAlignment, "verticalAlignment"); ParamChecks.nullNotPermitted(padding, "padding"); this.visible = true; this.position = position; this.horizontalAlignment = horizontalAlignment; this.verticalAlignment = verticalAlignment; setPadding(padding); this.listenerList = new EventListenerList(); this.notify = true; }
/** * Creates a rectangle that is aligned to the frame. * * @param dimensions the dimensions for the rectangle. * @param frame the frame to align to. * @param hAlign the horizontal alignment. * @param vAlign the vertical alignment. * @return A rectangle. */ private Rectangle2D createAlignedRectangle2D(Size2D dimensions, Rectangle2D frame, HorizontalAlignment hAlign, VerticalAlignment vAlign) { double x = Double.NaN; double y = Double.NaN; if (hAlign == HorizontalAlignment.LEFT) { x = frame.getX(); } else if (hAlign == HorizontalAlignment.CENTER) { x = frame.getCenterX() - (dimensions.width / 2.0); } else if (hAlign == HorizontalAlignment.RIGHT) { x = frame.getMaxX() - dimensions.width; } if (vAlign == VerticalAlignment.TOP) { y = frame.getY(); } else if (vAlign == VerticalAlignment.CENTER) { y = frame.getCenterY() - (dimensions.height / 2.0); } else if (vAlign == VerticalAlignment.BOTTOM) { y = frame.getMaxY() - dimensions.height; } return new Rectangle2D.Double(x, y, dimensions.width, dimensions.height); }
/** * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D. * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same * {@link DimensionConfig} s. */ private List<LegendTitle> createLegendTitles() { List<LegendTitle> legendTitles = new LinkedList<LegendTitle>(); LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration(); LegendTitle legendTitle = new SmartLegendTitle(this, new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2), new ColumnArrangement( HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2)); legendTitle.setItemPaint(legendConfiguration.getLegendFontColor()); RectangleEdge position = legendConfiguration.getLegendPosition().getPosition(); if (position == null) { return legendTitles; } legendTitle.setPosition(position); if (legendConfiguration.isShowLegendFrame()) { legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor())); } ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor()); wrapper.add(legendTitle.getItemContainer()); wrapper.setPadding(3, 3, 3, 3); legendTitle.setWrapper(wrapper); legendTitles.add(legendTitle); return legendTitles; }
/** * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D. * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same * {@link DimensionConfig} s. */ private List<LegendTitle> createLegendTitles() { List<LegendTitle> legendTitles = new LinkedList<LegendTitle>(); LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration(); LegendTitle legendTitle = new SmartLegendTitle(this, new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2), new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2)); legendTitle.setItemPaint(legendConfiguration.getLegendFontColor()); RectangleEdge position = legendConfiguration.getLegendPosition().getPosition(); if (position == null) { return legendTitles; } legendTitle.setPosition(position); if (legendConfiguration.isShowLegendFrame()) { legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor())); } ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor()); wrapper.add(legendTitle.getItemContainer()); wrapper.setPadding(3, 3, 3, 3); legendTitle.setWrapper(wrapper); legendTitles.add(legendTitle); return legendTitles; }
/** * Creates a new image title. * * @param image the image. * @param position the title position. * @param horizontalAlignment the horizontal alignment. * @param verticalAlignment the vertical alignment. */ public ImageTitle(Image image, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { this(image, image.getHeight(null), image.getWidth(null), position, horizontalAlignment, verticalAlignment, Title.DEFAULT_SPACER); }
/** * Creates a new image title with the given image scaled to the given * width and height in the given location. * * @param image the image (not null). * @param height the height used to draw the image. * @param width the width used to draw the image. * @param position the title position. * @param horizontalAlignment the horizontal alignment. * @param verticalAlignment the vertical alignment. * @param spacer the amount of space to leave around the outside of the title. */ public ImageTitle(Image image, int height, int width, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Spacer spacer) { super(position, horizontalAlignment, verticalAlignment, spacer); if (image == null) { throw new NullPointerException("ImageTitle(..): Image argument is null."); } this.image = image; this.height = height; this.width = width; }
/** * Creates a new title, using default attributes where necessary. * * @param position the position of the title (<code>null</code> not permitted). * @param horizontalAlignment the horizontal alignment of the title * (<code>null</code> not permitted). * @param verticalAlignment the vertical alignment of the title * (<code>null</code> not permitted). */ protected Title(RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { this(position, horizontalAlignment, verticalAlignment, Title.DEFAULT_SPACER); }
/** * Creates a new title. * * @param position the position of the title (<code>null</code> not permitted). * @param horizontalAlignment the horizontal alignment of the title (LEFT, CENTER or RIGHT, * <code>null</code> not permitted). * @param verticalAlignment the vertical alignment of the title (TOP, MIDDLE or BOTTOM, * <code>null</code> not permitted). * @param spacer the amount of space to leave around the outside of the title * (<code>null</code> not permitted). */ protected Title(RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Spacer spacer) { // check arguments... if (position == null) { throw new IllegalArgumentException("Argument 'position' cannot be null."); } if (horizontalAlignment == null) { throw new IllegalArgumentException("Null 'horizontalAlignment' argument."); } if (verticalAlignment == null) { throw new IllegalArgumentException("Null 'verticalAlignment' argument."); } if (spacer == null) { throw new IllegalArgumentException("Argument 'spacer' cannot be null."); } // initialise... this.position = position; this.horizontalAlignment = horizontalAlignment; this.verticalAlignment = verticalAlignment; this.spacer = spacer; this.listenerList = new EventListenerList(); this.notify = true; }
/** * Sets the vertical alignment for the title, and notifies any registered * listeners of the change. * * @param alignment the new vertical alignment (TOP, MIDDLE or BOTTOM, * <code>null</code> not permitted). */ public void setVerticalAlignment(VerticalAlignment alignment) { if (alignment == null) { throw new IllegalArgumentException("Argument 'alignment' cannot be null."); } if (this.verticalAlignment != alignment) { this.verticalAlignment = alignment; notifyListeners(new TitleChangeEvent(this)); } }
/** * Problem that the equals(...) method distinguishes all fields. */ public void testEquals() { // use the TextTitle class because it is a concrete subclass Title t1 = new TextTitle(); Title t2 = new TextTitle(); assertEquals(t1, t2); t1.setPosition(RectangleEdge.LEFT); assertFalse(t1.equals(t2)); t2.setPosition(RectangleEdge.LEFT); assertTrue(t1.equals(t2)); t1.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertFalse(t1.equals(t2)); t2.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertTrue(t1.equals(t2)); t1.setVerticalAlignment(VerticalAlignment.BOTTOM); assertFalse(t1.equals(t2)); t2.setVerticalAlignment(VerticalAlignment.BOTTOM); assertTrue(t1.equals(t2)); t1.setSpacer(new Spacer(Spacer.ABSOLUTE, 5.0, 10.0, 15.0, 20.0)); assertFalse(t1.equals(t2)); t2.setSpacer(new Spacer(Spacer.ABSOLUTE, 5.0, 10.0, 15.0, 20.0)); assertTrue(t1.equals(t2)); }
/** * Creates a new image title. * * @param image the image (<code>null</code> not permitted). * @param position the title position. * @param horizontalAlignment the horizontal alignment. * @param verticalAlignment the vertical alignment. */ public ImageTitle(Image image, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { this(image, image.getHeight(null), image.getWidth(null), position, horizontalAlignment, verticalAlignment, Title.DEFAULT_PADDING); }
/** * Creates a new title. * * @param position the position of the title (<code>null</code> not * permitted). * @param horizontalAlignment the horizontal alignment of the title (LEFT, * CENTER or RIGHT, <code>null</code> not * permitted). * @param verticalAlignment the vertical alignment of the title (TOP, * MIDDLE or BOTTOM, <code>null</code> not * permitted). * @param padding the amount of space to leave around the outside of the * title (<code>null</code> not permitted). */ protected Title(RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, RectangleInsets padding) { // check arguments... if (position == null) { throw new IllegalArgumentException("Null 'position' argument."); } if (horizontalAlignment == null) { throw new IllegalArgumentException( "Null 'horizontalAlignment' argument."); } if (verticalAlignment == null) { throw new IllegalArgumentException( "Null 'verticalAlignment' argument."); } if (padding == null) { throw new IllegalArgumentException("Null 'spacer' argument."); } this.position = position; this.horizontalAlignment = horizontalAlignment; this.verticalAlignment = verticalAlignment; setPadding(padding); this.listenerList = new EventListenerList(); this.notify = true; }
/** * Sets the vertical alignment for the title, and notifies any registered * listeners of the change. * * @param alignment the new vertical alignment (TOP, MIDDLE or BOTTOM, * <code>null</code> not permitted). */ public void setVerticalAlignment(VerticalAlignment alignment) { if (alignment == null) { throw new IllegalArgumentException("Null 'alignment' argument."); } if (this.verticalAlignment != alignment) { this.verticalAlignment = alignment; notifyListeners(new TitleChangeEvent(this)); } }