Mercurial > hg > de.mpg.mpiwg.itgroup.digilib.plugin
view src/de/mpg/mpiwg/itgroup/digilib/digiImage/DigiImageParameter.java @ 20:2f47c136b8a6
added property view
author | dwinter |
---|---|
date | Tue, 04 Jan 2011 16:35:41 +0100 |
parents | e63a64652f4d |
children | 643fa1daa70c |
line wrap: on
line source
package de.mpg.mpiwg.itgroup.digilib.digiImage; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.List; import java.util.Map; import com.sun.xml.xsom.impl.parser.DelayedRef.Type; import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorObservable; /** * Parameter which describe the state of an Digilib-Image, * settings and parameter names are described in @see {@link http://developer.berlios.de/docman/?group_id=251} * @author dwinter * */ public class DigiImageParameter { public String fn; public int pn=1; public int dw=-1; public int dh=-1; public float wx=0; public float wy=0; public float ww=1; public float wh=1; public float ws=1; public String mo="fit"; public float cont=0; public float brgt=0; public float rot=0; public String rgbm="0/0/0"; public String rgba="0/0/0"; public int ddpi=-1; public int ddpix=-1; public int ddpiy=-1; public DigiImageParameter(String fn){ this.fn = fn; } public DigiImageParameter(Map<String,String> params){ for(String key: params.keySet()){ Field f; try { f = this.getClass().getField(key); } catch (SecurityException e) { continue; } catch (NoSuchFieldException e) { continue; } if (f!=null){ try { Class<?> T = f.getType(); String name= T.getName(); String valueString = params.get(key); Object value = valueString; if (name.equals("float")){ value = Float.valueOf(valueString); } else if (name.equals("double")){ value = Double.valueOf(valueString); } else if (name.equals("int")){ value = Integer.valueOf(valueString); } else if (name.equals("Float")){ value = Float.valueOf(valueString); } else if (name.equals("Double")){ value = Double.valueOf(valueString); } else if (name.equals("Integer")){ value = Integer.valueOf(valueString); } f.set(this, value); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); continue; } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); continue; } } } } public String getFn() { return fn; } public void setFn(String fn) { this.fn = fn; } public int getPn() { return pn; } public void setPn(int pn) { this.pn = pn; } public int getDw() { return dw; } public void setDw(int dw) { this.dw = dw; } public int getDh() { return dh; } public void setDh(int dh) { this.dh = dh; } public float getWx() { return wx; } public void setWx(float wx) { this.wx = wx; } public float getWy() { return wy; } public void setWy(float wy) { this.wy = wy; } public float getWw() { return ww; } public void setWw(float ww) { this.ww = ww; } public float getWh() { return wh; } public void setWh(float wh) { this.wh = wh; } public float getWs() { return ws; } public void setWs(float ws) { this.ws = ws; } public String getMo() { return mo; } public void setMo(String mo) { this.mo = mo; } public float getCont() { return cont; } public void setCont(float cont) { this.cont = cont; } public float getBrgt() { return brgt; } public void setBrgt(float brgt) { this.brgt = brgt; } public float getRot() { return rot; } public void setRot(float rot) { this.rot = rot; } public String getRgbm() { return rgbm; } public void setRgbm(String rgbm) { this.rgbm = rgbm; } public String getRgba() { return rgba; } public void setRgba(String rgba) { this.rgba = rgba; } public int getDdpi() { return ddpi; } public void setDdpi(int ddpi) { this.ddpi = ddpi; } public int getDdpix() { return ddpix; } public void setDdpix(int ddpix) { this.ddpix = ddpix; } public int getDdpiy() { return ddpiy; } public void setDdpiy(int ddpiy) { this.ddpiy = ddpiy; } public Map<String, String> createMapFromParameters(List<String> omitIfNegative) { Map<String,String> qa= new HashMap<String,String>(); setPm(qa,"fn",getFn(),omitIfNegative); setPm(qa,"pn",getPn(),omitIfNegative); setPm(qa,"dw",getDw(),omitIfNegative); setPm(qa,"dh",getDh(),omitIfNegative); setPm(qa,"wx",getWx(),omitIfNegative); setPm(qa,"wy",getWy(),omitIfNegative); setPm(qa,"ws",getWs(),omitIfNegative); setPm(qa,"ww",getWw(),omitIfNegative); setPm(qa,"wh",getWh(),omitIfNegative); setPm(qa,"mo",getMo(),omitIfNegative); setPm(qa,"cont",getCont(),omitIfNegative); setPm(qa,"brgt",getBrgt(),omitIfNegative); setPm(qa,"rot",getRot(),omitIfNegative); setPm(qa,"rgba",getRgba(),omitIfNegative); setPm(qa,"rgbm",getRgbm(),omitIfNegative); setPm(qa,"ddpi",getDdpi(),omitIfNegative); setPm(qa,"ddpix",getDdpix(),omitIfNegative); setPm(qa,"ddpiy",getDdpiy(),omitIfNegative); return qa; } /** * Puts the parameter as key-value into the map repecting the setting in @see {@link #omitIfNegativeArray}. * @param qa * @param key * @param value * @param omitIfNegative */ private void setPm(Map<String, String> qa, String key, Object value, List<String> omitIfNegative){ String v; if (omitIfNegative==null){ qa.put(key, String.valueOf(value)); return; } if (String.class.isInstance(value)){ v=(String)value; qa.put(key, v); } else if (Integer.class.isInstance(value)){ if (!((Integer)value==-1 & omitIfNegative.indexOf(key)>-1)) { // nicht vernachlaessigen v=String.valueOf(value); qa.put(key, v); } } else { v=String.valueOf(value); qa.put(key, v); } } }