private PluginForHost updatePanel(PluginForHost plugin) { try { if (content == null) { return null; } if (plugin == null) { LazyHostPlugin p = HostPluginController.getInstance().get(getPreselectedHoster()); if (p == null) { Iterator<LazyHostPlugin> it = HostPluginController.getInstance().list().iterator(); if (it.hasNext()) { p = it.next(); } } plugin = p.newInstance(cl); } link.setText(_GUI.T.gui_menu_action_premium_buy_name2(plugin.getHost())); header2.setText( _GUI.T.AddAccountDialog_layoutDialogContent_enterlogininfo2(plugin.getHost())); final AccountBuilderInterface accountFactory = plugin.getAccountFactory(this); if (accountBuilderUI != null) { defaultAccount = accountBuilderUI.getAccount(); content.remove(accountBuilderUI.getComponent()); } accountBuilderUI = accountFactory; final JComponent comp; content.add(comp = accountBuilderUI.getComponent(), "gapleft 32,spanx"); accountBuilderUI.setAccount(defaultAccount); final ArrayList<Component> focusOrder = new ArrayList<Component>(); focusOrder.add(filter); focusOrder.addAll(inputComponents = ListFocusTraversalPolicy.getFocusableComponents(comp)); focusOrder.add(okButton); focusOrder.add(cancelButton); dialog.setFocusTraversalPolicyProvider(true); dialog.setFocusTraversalPolicy(new ListFocusTraversalPolicy(focusOrder)); // content.setFocusTraversalPolicy(new FocusTraversalPolicy() { // // @Override // public Component getLastComponent(Container aContainer) { // return comp; // } // // @Override // public Component getFirstComponent(Container aContainer) { // return filter; // } // // @Override // public Component getDefaultComponent(Container aContainer) { // return filter; // } // // @Override // public Component getComponentBefore(Container aContainer, Component aComponent) { // // return null; // } // // @Override // public Component getComponentAfter(Container aContainer, Component aComponent) { // if (aComponent == filter) { // return hoster; // } else if (aComponent == hoster || aComponent instanceof JViewport) { // return comp.getComponent(0); // } // return filter; // } // }); onChangedInput(null); // getDialog().pack(); return plugin; } catch (UpdateRequiredClassNotFoundException e) { e.printStackTrace(); return null; } }
@Override public JComponent layoutDialogContent() { final Collection<LazyHostPlugin> allPLugins = HostPluginController.getInstance().list(); // Filter - only premium plugins should be here final java.util.List<LazyHostPlugin> plugins = new ArrayList<LazyHostPlugin>(); for (LazyHostPlugin lhp : allPLugins) { if (lhp.isPremium()) { plugins.add(lhp); } } if (plugins.size() == 0) { throw new RuntimeException("No Plugins Loaded Exception"); // final HostPluginWrapper[] array = plugins.toArray(new // HostPluginWrapper[plugins.size()]); } filter = new ExtTextField() { private static final long serialVersionUID = 1L; @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Composite comp = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f)); new AbstractIcon(IconKey.ICON_SEARCH, 16).paintIcon(this, g2, 3, 3); g2.setComposite(comp); } }; filter.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent e) {} @Override public void focusGained(FocusEvent e) { filter.selectAll(); } }); filter.setHelpText("Search Plugins"); filter.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) {} @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN) { hoster.onKeyDown(); } if (e.getKeyCode() == KeyEvent.VK_UP) { hoster.onKeyUp(); } } }); // filterText.setOpaque(false); // filterText.putClientProperty("Synthetica.opaque", Boolean.FALSE); // filterText.setBorder(null); filter.setBorder( BorderFactory.createCompoundBorder( filter.getBorder(), BorderFactory.createEmptyBorder(0, 20, 0, 0))); hoster = new HosterChooserTable(plugins) { @Override protected void processEvent(AWTEvent e) { if (e instanceof KeyEvent) { if (((KeyEvent) e).getKeyCode() == KeyEvent.VK_TAB) { content.dispatchEvent(e); return; } } super.processEvent(e); } @Override protected boolean processKeyBinding( KeyStroke stroke, KeyEvent evt, int condition, boolean pressed) { return super.processKeyBinding(stroke, evt, condition, pressed); } public void valueChanged(javax.swing.event.ListSelectionEvent e) { super.valueChanged(e); if (e.getValueIsAdjusting() || getModel().isTableSelectionClearing()) { return; } try { scrollToSelection(0); final PluginForHost plg = getSelectedPlugin().newInstance(cl); if (plg != null && (lazyHostPlugin == null || !lazyHostPlugin.equals(plg.getLazyP()))) { final PluginForHost ret = updatePanel(plg); if (ret != null) { lazyHostPlugin = ret.getLazyP(); } } } catch (UpdateRequiredClassNotFoundException e1) { e1.printStackTrace(); } } }; filter .getDocument() .addDocumentListener( new DocumentListener() { private DelayedRunnable delayedRefresh = new DelayedRunnable(200, 1000) { String lastText = null; @Override public String getID() { return "AddAccountDialog"; } @Override public void delayedrun() { new EDTRunner() { @Override protected void runInEDT() { final String text = filter.getText(); if (!StringUtils.equals(lastText, text)) { lastText = text; hoster.refresh(text); } } }.waitForEDT(); } }; @Override public void removeUpdate(DocumentEvent e) { delayedRefresh.resetAndStart(); } @Override public void insertUpdate(DocumentEvent e) { delayedRefresh.resetAndStart(); } @Override public void changedUpdate(DocumentEvent e) { delayedRefresh.resetAndStart(); } }); link = new JButton(new AbstractIcon(IconKey.ICON_MONEY, 16)); link.setText(_GUI.T.gui_menu_action_premium_buy_name()); link.setToolTipText(_GUI.T.gui_menu_action_premium_buy_name()); link.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { try { final PluginForHost plugin = hoster.getSelectedPlugin().newInstance(cl); if (plugin != null) { StatsManager.I().openAfflink(plugin, null, "accountmanager/table"); } } catch (UpdateRequiredClassNotFoundException e1) { e1.printStackTrace(); } } }); link.setFocusable(false); content = new JPanel(new MigLayout("ins 0, wrap 1", "[grow,fill]")); content.add( header(_GUI.T.AddAccountDialog_layoutDialogContent_choosehoster_()), "gapleft 15,spanx,pushx,growx"); content.add(filter, "gapleft 32,pushx,growx"); JScrollPane sp; content.add(sp = new JScrollPane(hoster), "gapleft 32,pushy,growy"); sp.setFocusable(false); sp.getVerticalScrollBar().setFocusable(false); sp.getViewport().setFocusable(false); content.add(link, "height 20!,gapleft 32"); content.add( header2 = header(_GUI.T.AddAccountDialog_layoutDialogContent_enterlogininfo()), "gapleft 15,spanx,pushx,growx,gaptop 15"); final LazyHostPlugin lazyp; if (this.plugin != null) { lazyp = plugin.getLazyP(); } else { lazyp = HostPluginController.getInstance().get(getPreselectedHoster()); } if (lazyp != null) { hoster.setSelectedPlugin(lazyp); } getDialog() .addWindowFocusListener( new WindowFocusListener() { @Override public void windowLostFocus(final WindowEvent windowevent) { // TODO Auto-generated method stub } @Override public void windowGainedFocus(final WindowEvent windowevent) { final Component focusOwner = getDialog().getFocusOwner(); if (focusOwner != null) { // dialog component has already focus... return; } /* we only want to force focus on first window open */ getDialog().removeWindowFocusListener(this); focusFirstInputComponent(); } }); getDialog().setMinimumSize(new Dimension(400, 300)); return content; }