From 5c791eadad949ff77ec3e832499e9a650eb01ce5 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 24 Dec 2014 21:39:31 -0800 Subject: [PATCH] Added component tree icons for the new mass types. --- core/resources/l10n/messages.properties | 7 + .../pix/componenticons/altimeter-small.png | Bin 0 -> 799 bytes .../pix/componenticons/battery-small.png | Bin 0 -> 842 bytes .../deployment-charge-small.png | Bin 0 -> 1106 bytes .../pix/componenticons/flight-comp-small.png | Bin 0 -> 871 bytes .../pix/componenticons/payload-small.png | Bin 0 -> 1088 bytes .../recovery-hardware-small.png | Bin 0 -> 1072 bytes .../pix/componenticons/tracker-small.png | Bin 0 -> 851 bytes .../openrocket/gui/main/ComponentIcons.java | 222 +++++++++++------- .../componenttree/ComponentTreeRenderer.java | 89 +++---- 10 files changed, 191 insertions(+), 127 deletions(-) create mode 100644 core/resources/pix/componenticons/altimeter-small.png create mode 100644 core/resources/pix/componenticons/battery-small.png create mode 100644 core/resources/pix/componenticons/deployment-charge-small.png create mode 100644 core/resources/pix/componenticons/flight-comp-small.png create mode 100644 core/resources/pix/componenticons/payload-small.png create mode 100644 core/resources/pix/componenticons/recovery-hardware-small.png create mode 100644 core/resources/pix/componenticons/tracker-small.png diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index d124867cf..cc33a99b6 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1401,6 +1401,13 @@ ComponentIcons.Streamer = Streamer ComponentIcons.Shockcord = Shock cord ComponentIcons.Masscomponent = Mass component ComponentIcons.disabled = (disabled) +ComponentIcons.Altimeter = Altimeter +ComponentIcons.Flightcomputer = Flight computer +ComponentIcons.Battery = Battery +ComponentIcons.Tracker = Tracker +ComponentIcons.Recoveryhardware = Recovery hardware +ComponentIcons.Payload = Payload +ComponentIcons.Deploymentcharge = Deployment charge ! StageAction StageAction.Stage = Stage diff --git a/core/resources/pix/componenticons/altimeter-small.png b/core/resources/pix/componenticons/altimeter-small.png new file mode 100644 index 0000000000000000000000000000000000000000..b64479d86373b2a5264f417d82384dbcf452a153 GIT binary patch literal 799 zcmeAS@N?(olHy`uVBq!ia0vp^azM<@!3HEVv~9b96id3JuOkD)#(wTUiL5}rLb6AY zF9SoB8UsT^3j@P1pisjL28L1t28LG&3=CE?7#PG0=Ijcz0ZMQdctjQh%@YP;Muu5) zBp4W&3^GF^N+NuHtdjF{^%7I^lT!66atnZ}85nFTtboki)RIJnirk#MVyg;UC9n!B zAR8pCucQE0Qj%?}6yY17;GAESs$i;TqGzCF$EBd4U{jQmW)z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^Omqy9o-U3d7J|tM5?Knmx^L}O^U{>ujW1k^cc?92XkzI$VI6x~ zWLDNI`w4jx^GhasTwvVtgwMxvQ|pOG29>ieo)DXy%o$ne)93o4%1zgeUvSn(P0m;D cQ+9AMczzc5Q$Kuf2`CwQy85}Sb4q9e0GbT%-~a#s literal 0 HcmV?d00001 diff --git a/core/resources/pix/componenticons/battery-small.png b/core/resources/pix/componenticons/battery-small.png new file mode 100644 index 0000000000000000000000000000000000000000..b972d12e67a5a099467a3e86bd9a4b53ebc9a85c GIT binary patch literal 842 zcmeAS@N?(olHy`uVBq!ia0vp^azM<@!3HEVv~9b96id3JuOkD)#(wTUiL5}rLb6AY zF9SoB8UsT^3j@P1pisjL28L1t28LG&3=CE?7#PG0=Ijcz0ZMQdctjQh%@YP;Muu5) zBp4W&3^GF^N+NuHtdjF{^%7I^lT!66atnZ}85nFTtboki)RIJnirk#MVyg;UC9n!B zAR8pCucQE0Qj%?}6yY17;GAESs$i;TqGzCF$EBd4U{jQmW)z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^Omqw_o-U3d7J|tM5;+RGx^KnJ%qME~o#mMzA*{!_;D@qI(UPuY zQ?}(t|Ns9VerQ>9NMTM|!;ylhGbc{`U|+^5v8OyCC+KM6uM3%T#1?B#aejPw$C9qY zUmkuljA8ASIP&XxvXz9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^OmvJro-U3d7J|tM5()=AbgM64y7cbMEK_e*kN-@wesXj?{rCUB z{l~-Y{Gv@wP4^p%a!!;@OfkF?Fr!XW;jyGZvo5358OD_V&7MMwHb%vShE6?l_;B!- z@9*Ou#_zBD`}gPPbdT`x>zqz)6P5ZC3!R;vJ6Ej8h>eJl&^PFim}gskY(vJyMgH>k zbzc}C{d73|R6->(;cSs}9Q)gm>AcrKJTta$s~&U+`h&!9+*%C%?bH zH=eE&86+J_3dr6x`(cgMx#%G0P|&r`%h0#|1TviUGHl2 zTF@XOv@t86`RJ1cj}#0m0+NpydIXl1mWpw6d+TazzphWPvHSVuWw2*@`g6qFN1uzI}Zi md&!011rjz(o1bj7z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^OmqwjJzX3_ECiDiBzhEdb>H%xiJh_`F-_sJ&j}f(97~nT6thVN zAAQ_Pmd>0xbN~N;e@{2*`SHzfZGC#bUg5#BXJ#*6zTDZA!`8;y)6?T)oPN$F%$akx zrmgMV#@=3E_6&}$qY{pPpP!fKG4#qgwsgAQw1mwv$}1YX{xLVRE5F;Asiwl#mApV| zS^WOGg)GL3wLDW&6jS!z(2?4(;Mg;XT^)=J({7n?^v9V2a{&W`r>mdKI;Vst0Fl!Y A#{d8T literal 0 HcmV?d00001 diff --git a/core/resources/pix/componenticons/payload-small.png b/core/resources/pix/componenticons/payload-small.png new file mode 100644 index 0000000000000000000000000000000000000000..5577ecd46c5d02c929918aa88f86879d5c599915 GIT binary patch literal 1088 zcmeAS@N?(olHy`uVBq!ia0vp^azM<@!3HEVv~9b96id3JuOkD)#(wTUiL5}rLb6AY zF9SoB8UsT^3j@P1pisjL28L1t28LG&3=CE?7#PG0=Ijcz0ZMQdctjQh%@YP;Muu5) zBp4W&3^GF^N+NuHtdjF{^%7I^lT!66atnZ}85nFTtboki)RIJnirk#MVyg;UC9n!B zAR8pCucQE0Qj%?}6yY17;GAESs$i;TqGzCF$EBd4U{jQmW)z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^OmvJ@o-U3d7J|tM5()=AdiJ)qwmRkHA$pDP6h9l8_Sk1eQFvb)Z1vTar)G$B@K})+HZu^ zetmUS-@g9e9*@9PZez9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^OmvJ{o-U3d7J|ts3W7_PF1^c`HSzGW+-qwhb8Z~j*lCy~%+h)F z>Q&L=!ot?S|NcgQ{Qv*|nH^US9+_`bsidN;{F(1adQ#G_vxg29eLp>2|8rDS)U!iZ z6fR4MwYRkyWoKmEdGhe##P06yWKnVP^n?@_jnykxCRTjs%dy*J$>ZeY#N*(7AnE_V zzsVIpKdBzxmV4WdNw#F+!i5JJT@B6nE-b&=EvEa6=Zk8ngS-22{sqaCFTPE35`XaI z2~SCB=~G8>_383rV#m&%JuBO?PX6$t{q_I7Iy*WRtX7__ucdX0fv3u}gxNrcO|>h0 zecVEz=>JDYxdW1RcjPg&9i4AqKaZ{FvHXE6J?o~W{Ogyum)Mqb^OGFMvc=hMD&ZLa{kdKuTUBVZT4KbADua_;pT`osCbK80M`zY&z*pR5>VLdb;|#taD0e0sw`N Bc^Uu! literal 0 HcmV?d00001 diff --git a/core/resources/pix/componenticons/tracker-small.png b/core/resources/pix/componenticons/tracker-small.png new file mode 100644 index 0000000000000000000000000000000000000000..a37ff46ae6273779bfe837b175eec67ec86e5f48 GIT binary patch literal 851 zcmeAS@N?(olHy`uVBq!ia0vp^azM<@!3HEVv~9b96id3JuOkD)#(wTUiL5}rLb6AY zF9SoB8UsT^3j@P1pisjL28L1t28LG&3=CE?7#PG0=Ijcz0ZMQdctjQh%@YP;Muu5) zBp4W&3^GF^N+NuHtdjF{^%7I^lT!66atnZ}85nFTtboki)RIJnirk#MVyg;UC9n!B zAR8pCucQE0Qj%?}6yY17;GAESs$i;TqGzCF$EBd4U{jQmW)z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLnOgw2D6bgmE1>`MD-sLz4fPE4v1uyFOhY&iMHfg0q7CdT zh-Egwps{i;N=+=uFAB-e&#`k%&M(SSC`&CW2D#8g&s5LIMju@f!m&0WQ>~oya|?=6 zi$PlKOl|Zr#L(482Bj9~=ahm1!Ok3LK3D^?Ai9PKY#NXSp&D%TL1Bs%#*hdEivnZN zjtl4)SZc82y3J$^Omqyro-U3d7J_es9Jv|{c!c@w4o}X%z4)8i-XA>vYMUI)yCR-> z>P*qgowY9c@CWHQg{50ARm&-_5zO1MQ+7+AJ9mZi-eZS~U8C(boR%(4G<`Bhe711d z-YaQGWY1O1eD&n@8Kw_MGK!B(-FQPN>I~bH9j&`PPph}(Usd22NxFV~QeK4ioduq1 g`xYiXu`94)yl^ji(xIfxN1&wZ>FVdQ&MBb@0J^phf&c&j literal 0 HcmV?d00001 diff --git a/swing/src/net/sf/openrocket/gui/main/ComponentIcons.java b/swing/src/net/sf/openrocket/gui/main/ComponentIcons.java index e952d59aa..a305a1140 100644 --- a/swing/src/net/sf/openrocket/gui/main/ComponentIcons.java +++ b/swing/src/net/sf/openrocket/gui/main/ComponentIcons.java @@ -19,6 +19,7 @@ import net.sf.openrocket.rocketcomponent.FreeformFinSet; import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.MassComponent; +import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.Parachute; import net.sf.openrocket.rocketcomponent.ShockCord; @@ -28,145 +29,194 @@ import net.sf.openrocket.rocketcomponent.TrapezoidFinSet; import net.sf.openrocket.rocketcomponent.TubeCoupler; import net.sf.openrocket.startup.Application; - public class ComponentIcons { private static final Translator trans = Application.getTranslator(); - + private static final String ICON_DIRECTORY = "pix/componenticons/"; private static final String SMALL_SUFFIX = "-small.png"; private static final String LARGE_SUFFIX = "-large.png"; - - private static final HashMap, ImageIcon> SMALL_ICONS = - new HashMap, ImageIcon>(); - private static final HashMap, ImageIcon> LARGE_ICONS = - new HashMap, ImageIcon>(); - private static final HashMap, ImageIcon> DISABLED_ICONS = - new HashMap, ImageIcon>(); - + + private static final HashMap, ImageIcon> SMALL_ICONS = new HashMap, ImageIcon>(); + private static final HashMap, ImageIcon> LARGE_ICONS = new HashMap, ImageIcon>(); + private static final HashMap, ImageIcon> DISABLED_ICONS = new HashMap, ImageIcon>(); + private static final HashMap MASS_COMPONENT_SMALL_ICONS = new HashMap(); static { - //// Nose cone + // // Nose cone load("nosecone", trans.get("ComponentIcons.Nosecone"), NoseCone.class); - //// Body tube + // // Body tube load("bodytube", trans.get("ComponentIcons.Bodytube"), BodyTube.class); - //// Transition - load("transition", trans.get("ComponentIcons.Transition"), Transition.class); - //// Trapezoidal fin set - load("trapezoidfin", trans.get("ComponentIcons.Trapezoidalfinset"), TrapezoidFinSet.class); - //// Elliptical fin set - load("ellipticalfin", trans.get("ComponentIcons.Ellipticalfinset"), EllipticalFinSet.class); - //// Freeform fin set - load("freeformfin", trans.get("ComponentIcons.Freeformfinset"), FreeformFinSet.class); - //// Launch lug - load("launchlug", trans.get("ComponentIcons.Launchlug"), LaunchLug.class); - //// Inner tube - load("innertube", trans.get("ComponentIcons.Innertube"), InnerTube.class); - //// Tube coupler - load("tubecoupler", trans.get("ComponentIcons.Tubecoupler"), TubeCoupler.class); - //// Centering ring - load("centeringring", trans.get("ComponentIcons.Centeringring"), CenteringRing.class); - //// Bulk head + // // Transition + load("transition", trans.get("ComponentIcons.Transition"), + Transition.class); + // // Trapezoidal fin set + load("trapezoidfin", trans.get("ComponentIcons.Trapezoidalfinset"), + TrapezoidFinSet.class); + // // Elliptical fin set + load("ellipticalfin", trans.get("ComponentIcons.Ellipticalfinset"), + EllipticalFinSet.class); + // // Freeform fin set + load("freeformfin", trans.get("ComponentIcons.Freeformfinset"), + FreeformFinSet.class); + // // Launch lug + load("launchlug", trans.get("ComponentIcons.Launchlug"), + LaunchLug.class); + // // Inner tube + load("innertube", trans.get("ComponentIcons.Innertube"), + InnerTube.class); + // // Tube coupler + load("tubecoupler", trans.get("ComponentIcons.Tubecoupler"), + TubeCoupler.class); + // // Centering ring + load("centeringring", trans.get("ComponentIcons.Centeringring"), + CenteringRing.class); + // // Bulk head load("bulkhead", trans.get("ComponentIcons.Bulkhead"), Bulkhead.class); - //// Engine block - load("engineblock", trans.get("ComponentIcons.Engineblock"), EngineBlock.class); - //// Parachute - load("parachute", trans.get("ComponentIcons.Parachute"), Parachute.class); - //// Streamer + // // Engine block + load("engineblock", trans.get("ComponentIcons.Engineblock"), + EngineBlock.class); + // // Parachute + load("parachute", trans.get("ComponentIcons.Parachute"), + Parachute.class); + // // Streamer load("streamer", trans.get("ComponentIcons.Streamer"), Streamer.class); - //// Shock cord - load("shockcord", trans.get("ComponentIcons.Shockcord"), ShockCord.class); - //// Mass component - load("mass", trans.get("ComponentIcons.Masscomponent"), MassComponent.class); + // // Shock cord + load("shockcord", trans.get("ComponentIcons.Shockcord"), + ShockCord.class); + load("mass", trans.get("ComponentIcons.Masscomponent"), + MassComponent.class); + // // Mass components + loadMassTypeIcon("mass", trans.get("ComponentIcons.Masscomponent"), + MassComponentType.MASSCOMPONENT); + loadMassTypeIcon("altimeter", trans.get("ComponentIcons.Altimeter"), + MassComponentType.ALTIMETER); + loadMassTypeIcon("battery", trans.get("ComponentIcons.Battery"), + MassComponentType.BATTERY); + loadMassTypeIcon("deployment-charge", + trans.get("ComponentIcons.Deploymentcharge"), + MassComponentType.DEPLOYMENTCHARGE); + loadMassTypeIcon("payload", trans.get("ComponentIcons.Payload"), + MassComponentType.PAYLOAD); + loadMassTypeIcon("flight-comp", + trans.get("ComponentIcons.Flightcomputer"), + MassComponentType.FLIGHTCOMPUTER); + loadMassTypeIcon("recovery-hardware", + trans.get("ComponentIcons.Recoveryhardware"), + MassComponentType.RECOVERYHARDWARE); + loadMassTypeIcon("tracker", trans.get("ComponentIcons.Tracker"), + MassComponentType.TRACKER); } - - private static void load(String filename, String name, Class componentClass) { - ImageIcon icon = loadSmall(ICON_DIRECTORY + filename + SMALL_SUFFIX, name); + + private static void load(String filename, String name, + Class componentClass) { + ImageIcon icon = loadSmall(ICON_DIRECTORY + filename + SMALL_SUFFIX, + name); SMALL_ICONS.put(componentClass, icon); - - ImageIcon[] icons = loadLarge(ICON_DIRECTORY + filename + LARGE_SUFFIX, name); + + ImageIcon[] icons = loadLarge(ICON_DIRECTORY + filename + LARGE_SUFFIX, + name); LARGE_ICONS.put(componentClass, icons[0]); DISABLED_ICONS.put(componentClass, icons[1]); } - - + + private static void loadMassTypeIcon(String filename, String name, + MassComponentType t) { + ImageIcon icon = loadSmall(ICON_DIRECTORY + filename + SMALL_SUFFIX, + name); + MASS_COMPONENT_SMALL_ICONS.put(t, icon); + } + /** * Return the small icon for a component type. * - * @param c the component class. - * @return the icon, or null if none available. + * @param c + * the component class. + * @return the icon, or null if none available. */ public static Icon getSmallIcon(Class c) { + if (c.isAssignableFrom(MassComponent.class)) { + } return SMALL_ICONS.get(c); } - + + public static Icon getSmallMassTypeIcon(MassComponentType t) { + return MASS_COMPONENT_SMALL_ICONS.get(t); + } + /** * Return the large icon for a component type. * - * @param c the component class. - * @return the icon, or null if none available. + * @param c + * the component class. + * @return the icon, or null if none available. */ public static Icon getLargeIcon(Class c) { return LARGE_ICONS.get(c); } - + /** * Return the large disabled icon for a component type. * - * @param c the component class. - * @return the icon, or null if none available. + * @param c + * the component class. + * @return the icon, or null if none available. */ public static Icon getLargeDisabledIcon(Class c) { return DISABLED_ICONS.get(c); } - - - private static ImageIcon loadSmall(String file, String desc) { URL url = ClassLoader.getSystemResource(file); if (url == null) { - Application.getExceptionHandler().handleErrorCondition("ERROR: Couldn't find file: " + file); + Application.getExceptionHandler().handleErrorCondition( + "ERROR: Couldn't find file: " + file); return null; } return new ImageIcon(url, desc); } - - + private static ImageIcon[] loadLarge(String file, String desc) { ImageIcon[] icons = new ImageIcon[2]; - + URL url = ClassLoader.getSystemResource(file); if (url != null) { BufferedImage bi, bi2; try { bi = ImageIO.read(url); - bi2 = ImageIO.read(url); // How the fsck can one duplicate a BufferedImage??? + bi2 = ImageIO.read(url); // How the fsck can one duplicate a + // BufferedImage??? } catch (IOException e) { - Application.getExceptionHandler().handleErrorCondition("ERROR: Couldn't read file: " + file, e); + Application.getExceptionHandler().handleErrorCondition( + "ERROR: Couldn't read file: " + file, e); return new ImageIcon[] { null, null }; } - + icons[0] = new ImageIcon(bi, desc); - + // Create disabled icon - boolean useAlphaFade = false; // don't use fade to alpha yet - if (useAlphaFade) { // Fade using alpha - - /* TODO This code to do fade using alpha had been dead code inside a "if (false) {" block. - * Eclipse would give a build warning about dead code, so this code has been commented out - * but left here for future use; am assuming it was dead code because it wasn't working correctly - * but that it will be useful in the future. + boolean useAlphaFade = false; // don't use fade to alpha yet + if (useAlphaFade) { // Fade using alpha + + /* + * TODO This code to do fade using alpha had been dead code + * inside a "if (false) {" block. Eclipse would give a build + * warning about dead code, so this code has been commented out + * but left here for future use; am assuming it was dead code + * because it wasn't working correctly but that it will be + * useful in the future. */ - // int rgb[] = bi2.getRGB(0, 0, bi2.getWidth(), bi2.getHeight(), null, 0, bi2.getWidth()); + // int rgb[] = bi2.getRGB(0, 0, bi2.getWidth(), bi2.getHeight(), + // null, 0, bi2.getWidth()); // for (int i = 0; i < rgb.length; i++) { - // final int alpha = (rgb[i] >> 24) & 0xFF; - // rgb[i] = (rgb[i] & 0xFFFFFF) | (alpha / 3) << 24; - // - // //rgb[i] = (rgb[i]&0xFFFFFF) | ((rgb[i]>>1)&0x3F000000); + // final int alpha = (rgb[i] >> 24) & 0xFF; + // rgb[i] = (rgb[i] & 0xFFFFFF) | (alpha / 3) << 24; + // + // //rgb[i] = (rgb[i]&0xFFFFFF) | ((rgb[i]>>1)&0x3F000000); // } - // bi2.setRGB(0, 0, bi2.getWidth(), bi2.getHeight(), rgb, 0, bi2.getWidth()); - + // bi2.setRGB(0, 0, bi2.getWidth(), bi2.getHeight(), rgb, 0, + // bi2.getWidth()); + } else { // Raster alpha - + for (int x = 0; x < bi.getWidth(); x++) { for (int y = 0; y < bi.getHeight(); y++) { if ((x + y) % 2 == 0) { @@ -174,15 +224,17 @@ public class ComponentIcons { } } } - + } - - //// (disabled) - icons[1] = new ImageIcon(bi2, desc + " " + trans.get("ComponentIcons.disabled")); - + + // // (disabled) + icons[1] = new ImageIcon(bi2, desc + " " + + trans.get("ComponentIcons.disabled")); + return icons; } else { - Application.getExceptionHandler().handleErrorCondition("ERROR: Couldn't find file: " + file); + Application.getExceptionHandler().handleErrorCondition( + "ERROR: Couldn't find file: " + file); return new ImageIcon[] { null, null }; } } diff --git a/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTreeRenderer.java b/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTreeRenderer.java index 2539cc4cb..b73f7cec1 100644 --- a/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTreeRenderer.java +++ b/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTreeRenderer.java @@ -1,7 +1,5 @@ package net.sf.openrocket.gui.main.componenttree; - - import java.awt.Component; import java.awt.FlowLayout; @@ -14,88 +12,95 @@ import javax.swing.tree.DefaultTreeCellRenderer; import net.sf.openrocket.gui.main.ComponentIcons; import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.l10n.Translator; +import net.sf.openrocket.rocketcomponent.MassComponent; +import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.TextUtil; public class ComponentTreeRenderer extends DefaultTreeCellRenderer { - + private static final Translator trans = Application.getTranslator(); @Override - public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, + public Component getTreeCellRendererComponent(JTree tree, Object value, + boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus1) { - - Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus1); - + + Component comp = super.getTreeCellRendererComponent(tree, value, sel, + expanded, leaf, row, hasFocus1); + // Set icon - setIcon(ComponentIcons.getSmallIcon(value.getClass())); - + RocketComponent c = (RocketComponent) value; - if ( c.isMassOverridden() || c.isCGOverridden()) { + if (c.getClass().isAssignableFrom(MassComponent.class)) { + MassComponentType t = ((MassComponent) c).getMassComponentType(); + setIcon(ComponentIcons.getSmallMassTypeIcon(t)); + } else { + setIcon(ComponentIcons.getSmallIcon(value.getClass())); + } + if (c.isMassOverridden() || c.isCGOverridden()) { JPanel p = new JPanel(); - p.setLayout( new FlowLayout( FlowLayout.LEFT, 1,1) ); - p.setBackground( UIManager.getColor("Tree.textBackground")); - p.setForeground( UIManager.getColor("Tree.textForeground")); - p.add(comp/*, BorderLayout.WEST*/); - if ( c.isMassOverridden() ) { - p.add( new JLabel( Icons.MASS_OVERRIDE ) ); + p.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1)); + p.setBackground(UIManager.getColor("Tree.textBackground")); + p.setForeground(UIManager.getColor("Tree.textForeground")); + p.add(comp/* , BorderLayout.WEST */); + if (c.isMassOverridden()) { + p.add(new JLabel(Icons.MASS_OVERRIDE)); } - if ( c.isCGOverridden() ) { - p.add( new JLabel(Icons.CG_OVERRIDE) ); + if (c.isCGOverridden()) { + p.add(new JLabel(Icons.CG_OVERRIDE)); } p.setToolTipText(getToolTip(c)); comp = p; } - + // Set tooltip this.setToolTipText(getToolTip(c)); - + return comp; } - - + private static String getToolTip(RocketComponent c) { StringBuilder sb = new StringBuilder(); sb.append(""); - + sb.append("").append(c.getName()).append(""); - if (c.isMassive() || c.isMassOverridden() ) { - sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getMass())); - if(c.getChildCount()>0){ - sb.append(" of ").append(UnitGroup.UNITS_MASS.toStringUnit(c.getSectionMass())).append( " total"); + if (c.isMassive() || c.isMassOverridden()) { + sb.append(" (").append( + UnitGroup.UNITS_MASS.toStringUnit(c.getMass())); + if (c.getChildCount() > 0) { + sb.append(" of ") + .append(UnitGroup.UNITS_MASS.toStringUnit(c + .getSectionMass())).append(" total"); } sb.append(")"); } else { - if((c.getChildCount()>0) && (c.getSectionMass()>0)){ - sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getSectionMass())).append( " total)"); + if ((c.getChildCount() > 0) && (c.getSectionMass() > 0)) { + sb.append(" (") + .append(UnitGroup.UNITS_MASS.toStringUnit(c + .getSectionMass())).append(" total)"); } } - - if ( c.isMassOverridden() ) { + + if (c.isMassOverridden()) { sb.append(" ").append(trans.get("ComponentTree.ttip.massoverride")); } - - if ( c.isCGOverridden() ) { + + if (c.isCGOverridden()) { sb.append(" ").append(trans.get("ComponentTree.ttip.cgoverride")); } - + String comment = c.getComment().trim(); if (comment.length() > 0) { comment = TextUtil.escapeXML(comment); comment = comment.replace("\n", "
"); sb.append("
").append(comment); } - + return sb.toString(); } - + }