alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.gef.internal.ui.palette.editparts;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;

import org.eclipse.gef.palette.PaletteSeparator;

/**
 * EditPart for the PaletteSeparator
 * 
 * @author Pratik Shah
 */
public class SeparatorEditPart extends PaletteEditPart {

/**
 * Constructor
 * 
 * @param separator The PaletteSeparator for which this EditPart is being
 * created
 */
public SeparatorEditPart(PaletteSeparator separator) {
	super(separator);
}

/**
 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
 */
protected IFigure createFigure() {
	return new SeparatorFigure();
}

/**
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#getToolTipText()
 */
protected String getToolTipText() {
	return null;
}

/**
 * Figure for the separator
 * 
 * @author Pratik Shah
 */
static class SeparatorFigure extends Figure {
	/**
	 * @see org.eclipse.draw2d.IFigure#getPreferredSize(int, int)
	 */
	public Dimension getPreferredSize(int wHint, int hHint) {
		if (getBackgroundColor() == ColorConstants.button)
			return new Dimension(wHint, 4);
		return new Dimension(wHint, 5);
	}
	
	private static final Insets CROP = new Insets(1, 3, 2, 4);

	/**
	 * 
	 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
	 */
	protected void paintFigure(Graphics g) {
		Rectangle r = getBounds().getCropped(CROP);
		if (getBackgroundColor() == ColorConstants.listBackground) {
			g.setForegroundColor(ColorConstants.buttonDarker);
			g.drawLine(r.getTopLeft(), r.getTopRight());
			g.drawLine(r.getBottomLeft(), r.getBottomRight());
		} else {
			g.setForegroundColor(ColorConstants.buttonDarker);
			g.drawLine(r.getBottomLeft(), r.getTopLeft());
			g.drawLine(r.getTopLeft(), r.getTopRight());

			g.setForegroundColor(ColorConstants.buttonLightest);
			g.drawLine(r.getBottomLeft(), r.getBottomRight());
			g.drawLine(r.getBottomRight(), r.getTopRight());
		}
	}
}

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.