Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f1e27b6237b4fdc045eb29a7d1177a7a4259dfd3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 *  Copyright (c) 2012 Christian Pontesegger 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:
 *     Christian Pontesegger - initial API and implementation
 *******************************************************************************/

package org.eclipse.pde.internal.ui.views.imagebrowser.filter;

import org.eclipse.pde.internal.ui.views.imagebrowser.ImageElement;

public class SizeFilter implements IFilter<ImageElement> {

	public static final int TYPE_EXACT = 0;
	public static final int TYPE_BIGGER_EQUALS = 1;
	public static final int TYPE_SMALLER_EQUALS = 2;
	private final int mWidth;
	private final int mWidthType;
	private final int mHeight;
	private final int mHeightType;

	public SizeFilter(final int width, final int widthType, final int height, final int heightType) {
		mWidth = width;
		mWidthType = widthType;
		mHeight = height;
		mHeightType = heightType;
	}

	public boolean accept(final ImageElement element) {
		boolean accept = true;

		switch (mWidthType) {
		case TYPE_EXACT:
			accept &= (element.getImageData().width == mWidth);
			break;
		case TYPE_BIGGER_EQUALS:
			accept &= (element.getImageData().width >= mWidth);
			break;
		case TYPE_SMALLER_EQUALS:
			accept &= (element.getImageData().width <= mWidth);
			break;
		}

		switch (mHeightType) {
		case TYPE_EXACT:
			accept &= (element.getImageData().height == mHeight);
			break;
		case TYPE_BIGGER_EQUALS:
			accept &= (element.getImageData().height >= mHeight);
			break;
		case TYPE_SMALLER_EQUALS:
			accept &= (element.getImageData().height <= mHeight);
			break;
		}

		return accept;
	}
}

Back to the top