@ViewDescriptor( name ="Test GUI", rows =2, patterns = {"ZZZZZZZZZ","ZZZZZZZZA" }, cancelMove = {'Z','A'})publicclassTestViewimplementsView<Void> { @OverridepublicvoidrenderView(Void model,UIContext context) {ButtonFactory button =context.factory(ButtonFactory.class);RGBSelectorFactory rgbSelector =context.factory(RGBSelectorFactory.class);DateSelectorFactory dateSelector =context.factory(DateSelectorFactory.class);TimeSelectorFactory timeSelector =context.factory(TimeSelectorFactory.class);context.pattern('Z').components( rgbSelector.bindInput("testColor",Color.WHITE).label("&aColor Select: (shift to move color, click to +/-, middle to input)").create(), dateSelector.bindInput("testDate",LocalDate.now()).label("&aDate Select: (shift move unit, click to +/-, middle to input)").icon(Material.BEACON).create(), timeSelector.bindInput("testTime",LocalTime.now()).label("&aTime Select: (shift move unit, click to +/-, middle to input)").icon(Material.CLOCK).create() ).and().pattern('A').components(button.title("&aTest").icon(Material.DIAMOND_BLOCK).create() ); }}
從上述代碼中你可以發現,bindInput 所綁定的 屬性名稱 與 數據模型内的屬性名稱是一致的。
控制器代碼如下
@UIController("test")publicclassTestController { @PostConstructpublicvoidbeforeCreate(Player player){player.sendMessage("life cycle: before create for test controller"); }publicBukkitView<?,?> index(){returnnewBukkitView<>(TestView.class); } @ClickMapping(view =TestView.class, pattern ='A')publicvoidonClick(@ModelAttribute('Z') TestModel test,Player player){player.sendMessage(test.toString()); } @PreDestroypublicvoidbeforeDestroy(Player player){player.sendMessage("life cycle: before destroy for test controller"); }}
Pattern Z 内有三個組件,他們分別是 RGB顔色選擇器,日期選擇器和時間選擇器。於是,本框架會根據該組件所綁定的屬性和數值,為指定的 POJO 類型創建一個新實例並為該實例賦值。