import org.springframework.core.io.support.PathMatchingResourcePatternResolver

// Watch out! reading resources inside the UI thread!!
ClassLoader classLoader = getClass().classLoader
String path = 'classpath*:/images/everaldo/*.png'
List icons = new PathMatchingResourcePatternResolver(classLoader)
                      .getResources(path).collect([]) { r ->
  def (m, icon) = (r.getURL().path =~ /.*\/([a-zA-Z0-9_\-]+)\.png/)[0]
  icon
}

panel(preferredSize: [800, 300]) {
  borderLayout()
  panel(constraints: CENTER) {
    stackLayout()
    gradientPanel(constraints: BOTTOM)
    imageFlow(id: "flow", constraints: TOP) {
      icons.each { icon ->
        imageFlowItem(resource: "/images/everaldo/${icon}.png",
                      label: icon[0].toUpperCase() + icon[1..-1])
      }
    }
    // change selection after children have been set
    noparent{ flow.selectedIndex = 0 }
  }
  panel(constraints: WEST) {
    gridLayout(cols: 1, rows: 2)
    button(crystalIcon(category: 'actions', size: 32, icon: '1leftarrow'),
           actionPerformed: {flow.previous()})
    button(crystalIcon(category: 'actions', size: 32, icon: '2leftarrow'),
           actionPerformed: {flow.selectedIndex = 0 })
  }
  panel(constraints: EAST) {
    gridLayout(cols: 1, rows: 2)
    button(crystalIcon(category: 'actions', size: 32, icon: '1rightarrow'),
           actionPerformed: {flow.next()})
    button(crystalIcon(category: 'actions', size: 32, icon: '2rightarrow'),
           actionPerformed: {flow.selectedIndex = (icons.size() - 1) })
  }
}
