Hi Chris, The snippet below shows an example of how to extend an icon to add a method for scaling.
> what i need to > extend to overide the printing functions so it rescales it as it prints. Can you please explain what you mean by "printing functions"? Thanks and regards, Janak ----------------------------------------- Janak Mulani email: [EMAIL PROTECTED] url: http://www.canoo.com Beyond AJAX - Java Rich Internet Applications http://www.canoo.com/ulc ----------------------------------------- > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:ulc-developer- > [EMAIL PROTECTED] On Behalf Of chris idr > Sent: Friday, January 11, 2008 7:31 PM > To: [email protected] > Subject: [ULC-developer] ULCIcon resizing > > i need to resize the ULCIcon via extending it, > as i need to add it to every seperate icon instance in a field, ie, > rollover/ noraml/ selected/ rolloverSelected etc etc > > so can someone please tell me how i extend a ULCIcon and what i need to > extend to overide the printing functions so it rescales it as it prints. > > thanks > > chris import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.ClientContext; import com.ulcjava.base.application.ULCBoxPane; import com.ulcjava.base.application.ULCButton; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCLabel; import com.ulcjava.base.application.event.ActionEvent; import com.ulcjava.base.application.event.IActionListener; import com.ulcjava.base.application.util.ULCIcon; import com.ulcjava.base.client.ClientEnvironmentAdapter; import com.ulcjava.base.client.UIIcon; import com.ulcjava.base.development.DevelopmentRunner; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.net.URL; public class ULCIconExtensionSnippet extends AbstractApplication { private ULCLabel fLabel1; private ULCLabel fLabel2; private ULCLabel fLabel3; private ULCLabel fLabel4; public void start() { fLabel1 = new ULCLabel("Label"); fLabel2 = new ULCLabel("Label"); final ULCMyIcon icon1 = new ULCMyIcon(ULCIconExtensionSnippet.class.getResource("/flag_red.gif")); final ULCMyIcon icon2 = new ULCMyIcon(ULCIconExtensionSnippet.class.getResource("/flag_red.gif")); fLabel1.setIcon(icon1); fLabel2.setIcon(icon2); ULCButton button = new ULCButton("Scale"); button.addActionListener(new IActionListener() { public void actionPerformed(ActionEvent event) { icon2.scale(20, 20); fLabel2.repaint(); } }); ULCBoxPane pane = new ULCBoxPane(true); pane.add(ULCBoxPane.BOX_EXPAND_CENTER, fLabel1); pane.add(ULCBoxPane.BOX_EXPAND_CENTER, fLabel2); pane.add(ULCBoxPane.BOX_CENTER_CENTER, button); ULCFrame frame = new ULCFrame(); frame.add(pane); frame.setSize(300, 300); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); frame.setVisible(true); } public static void main(String[] args) { DevelopmentRunner.setApplicationClass(ULCIconExtensionSnippet.class); DevelopmentRunner.run(); } public static class ULCMyIcon extends ULCIcon { public ULCMyIcon(URL location) { super(location); } protected String typeString() { return UIMyIcon.class.getName(); } public void scale(int w, int h) { invokeUI("scale", new Object[] { new Integer(w), new Integer(h) }); } } public static class UIMyIcon extends UIIcon { public void scale(int w, int h) { Image image = (Image)getBasicIcon().getImage(); Image scaledImage = image.getScaledInstance(w, h, Image.SCALE_DEFAULT); getBasicIcon().setImage(scaledImage); } } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
