001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 005 package graphlab.ui.components.gpropertyeditor.editors.inplace; 006 007 import graphlab.ui.components.gpropertyeditor.editors.GStringEditor; 008 009 import java.awt.*; 010 011 public class GDimensionEditor extends GStringEditor { 012 public Component getEditorComponent(Object value) { 013 if (value instanceof Dimension) { 014 Dimension d = (Dimension) value; 015 return super.getEditorComponent(d.width + "*" + d.height); 016 } 017 return null; 018 } 019 020 public Object getEditorValue() { 021 String s = super.getEditorValue() + ""; 022 if (s != null) { 023 try { 024 return new Dimension(Integer.parseInt(s.substring(0, s.indexOf('*'))), 025 Integer.parseInt(s.substring(s.indexOf('*') + 1))); 026 } catch (Exception e) { 027 return this.initVal; 028 } 029 } 030 return null; 031 } 032 033 }