From ba02c799f4e9ee0e063607af7c8b233cb4967363 Mon Sep 17 00:00:00 2001 From: Preston Seay Date: Thu, 11 Feb 2021 11:25:58 -0800 Subject: [PATCH] updated navigator example --- .../HierarchyComponents/hswing/HFrame.class | Bin 1298 -> 1649 bytes .../hswing/Navigator.class | Bin 6292 -> 6312 bytes src/demo/NavigatorExample.java | 15 +++++++++++---- src/hswing/Navigator.java | 11 +++++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/out/production/HierarchyComponents/hswing/HFrame.class b/out/production/HierarchyComponents/hswing/HFrame.class index df58c3389289d7354d9f9ae37d49d47c58cc7d58..6becf760710f3065dc135a8fd563d473464df682 100644 GIT binary patch delta 661 zcmZuu&1w@-6#mZKNp2Yik)$o9=|WI39i^dv_TRRqYNOSvH3MzwV$`vuh9op;S86Eq z37VB}VL=SI@B!TWAg*+!es^XFBEoR*IcL6~bIv_;zPrxXU!T7Kn1_Gv99eA#HYQw5 zVoG4w8(~e5%9nOVeFqM1x|qSNV5k|k*1}i8QMFa9)|=sGBRmXRl{&$8z7%8UT`XWx z;1KIqnw96((ELr5Zn;>-3JZLyc{xZ~~202ySz#6)0G|`@D=???Rn3wov5hMD;AO{a9l@7~^mU zcbSoadswH6QR_2mogZpXik-53t!?lg_jDP4Lo2bQO#&rc*uAd)^D1m zHEfMX8jtx2K|gVW*ekedJcujsHr$l=5&a(+#O*4qwuk2SuyP8WM1v% z)F+JpJ8qe+`hSh9drfOR!BdJDv8hDtfZmFtSufYcv}boQH}W3Z+v{S-2D_M<#WN7(}1PkRqQj=Tf delta 294 zcmX|*yGnyW6okLMgcg8OdRacmz0=R zj%ne^UZ_rZxAjrfH?XWwV^=C>!iWFPA^RMNBhF%m=1_1A{Vhu}hjkn|26B{$KG_uQ dDr;%SO{rRs?Xu)=re>9dOMm%_6ZzMi{s7qEB&GlW diff --git a/out/production/HierarchyComponents/hswing/Navigator.class b/out/production/HierarchyComponents/hswing/Navigator.class index 0e4523067dbbe598d7cf5b7bc9d8117e87fa9e2e..2586ad6bd47979657f97f9db8a25c18203cb9637 100644 GIT binary patch delta 360 zcmX|*$xFg<6vRKjtW0fjDb0hlK!*|o@z5!P1c{){2-@gS2)3YfZ>0_$tV3U;Y&Rk8 zl9EtFw48#V8K<>et3p%$j$FDPfXErU)|42s4ZmAw-lgvuf1#;hGc0JT?}n zVv$ys2(U~SEA+CeqLs&5Oqr`5JzJvNrd;~9u!mpzbaKF;WQRBwzoa;%SQCDOQ>C-N zJI`^FrH&kKF7S~T_jCEYRC>pe;g(|VF!P|Yj<&LA^t@o=l?vX}rz4;xRC{&s8+8*; Ai2wiq delta 340 zcmX|*J4-@w7{-6cBs+95kLgiDBB-FmK^&T*L2wA7aEQvLz%CTl+D(d<8fx$_(!Em- z8Wsr-K@tr?&}Hlsw6-@j^j6UF^1RQDrx?zL%So61P7QWoNTpmcPnF zyU^8}t8-il?)h_)Wk){Au*W{yFDg*PMgvjKIG4^NVZFlqxC&hSYkAR5gw?TqVK``u zs0kygC6r}U0!iwaqMK>r%#dJ~N#;m0FJDS6x<3O;;#kJb3LaMJV~rST23cpA4Yk=~ zY1^v9^BBsAFG~|SdSzr(W)5(`D2LK^%z{ivW3eUrE_r2oKl~;9T++@JL9U5VmiCe) kE2`Bz)o-b#N;7xr!R&8*!of53yx` JButton) navigator.getSingleByClass("button1", JButton.class).addActionListener(e -> { - //gets all the JLabels - navigator.getListByClass(JLabel.class).forEach(jLabel -> { + //gets all the JLabels with name 'label' + navigator.getListByClass("label", JLabel.class).forEach(jLabel -> { jLabel.setText(jLabel.getText().repeat(2)); }); + navigator.getFrame().pack(); }); - //getting a list based on just the class + //getting a list of JComponents based on just the class navigator.getListByClass(JLabel.class).forEach(label -> { - label.setBackground(Color.blue); + label.setBorder(BorderFactory.createLineBorder(Color.blue, 5, true)); }); AtomicInteger aint = new AtomicInteger(10); diff --git a/src/hswing/Navigator.java b/src/hswing/Navigator.java index 7c4a900..c419329 100644 --- a/src/hswing/Navigator.java +++ b/src/hswing/Navigator.java @@ -62,11 +62,11 @@ public JComponent getSingle(String name) throws MoreThanOneComponentException { /** * Gets a single T according to the name - * @param name the name of the {@link JComponent} to get - * @param t the class to automatically cast it to + * @param name the name of the T to get + * @param t the class to find and return * @param the class type to be returned - * @return the {@link JComponent} with the name. If the {@link JComponent} does not exist, it will return null - * @throws MoreThanOneComponentException if there are multiple {@link JComponent}s with the same name + * @return the T with the name. If the T does not exist, it will return null + * @throws MoreThanOneComponentException if there are multiple Ts with the same name */ public T getSingleByClass(String name, Class t) throws MoreThanOneComponentException { List componentsWithName = components.get(name); @@ -79,6 +79,9 @@ public T getSingleByClass(String name, Class t) throws MoreThanOneCompone if (componentsWithName.size() == 1) { return (T)componentsWithName.get(0); } + if (componentsWithName.size() == 0) { + return null; + } throw new MoreThanOneComponentException(name); }