List of usage examples for javax.swing JCheckBox setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:lcmc.gui.resources.ServiceInfo.java
/** Returns existing service manu item. */ private MyMenu getExistingServiceMenuItem(final String name, final boolean enableForNew, final boolean testOnly) { final ServiceInfo thisClass = this; return new MyMenu(name, new AccessMode(ConfigData.AccessType.ADMIN, false), new AccessMode(ConfigData.AccessType.OP, false)) { private static final long serialVersionUID = 1L; private final Lock mUpdateLock = new ReentrantLock(); @Override//from w ww .j a va2 s. c o m public String enablePredicate() { if (getBrowser().clStatusFailed()) { return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING; } else if (getService().isRemoved()) { return IS_BEING_REMOVED_STRING; } else if (getService().isOrphaned()) { return IS_ORPHANED_STRING; } else if (!enableForNew && getService().isNew()) { return IS_NEW_STRING; } if (getBrowser().getExistingServiceList(thisClass).size() == 0) { return "<<empty;>>"; } return null; } @Override public void update() { final Thread t = new Thread(new Runnable() { @Override public void run() { if (mUpdateLock.tryLock()) { try { updateThread(); } finally { mUpdateLock.unlock(); } } } }); t.start(); } private void updateThread() { final JCheckBox colocationWi = new JCheckBox("Colo", true); final JCheckBox orderWi = new JCheckBox("Order", true); colocationWi.setBackground(ClusterBrowser.STATUS_BACKGROUND); colocationWi.setPreferredSize(colocationWi.getMinimumSize()); orderWi.setBackground(ClusterBrowser.STATUS_BACKGROUND); orderWi.setPreferredSize(orderWi.getMinimumSize()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setEnabled(false); } }); Tools.invokeAndWait(new Runnable() { @Override public void run() { removeAll(); } }); final MyListModel<MyMenuItem> dlm = new MyListModel<MyMenuItem>(); final Map<MyMenuItem, ButtonCallback> callbackHash = new HashMap<MyMenuItem, ButtonCallback>(); final MyList<MyMenuItem> list = new MyList<MyMenuItem>(dlm, getBackground()); final List<JDialog> popups = new ArrayList<JDialog>(); for (final ServiceInfo asi : getBrowser().getExistingServiceList(thisClass)) { if (asi.isConstraintPH() && isConstraintPH()) { continue; } if (asi.getCloneInfo() != null || asi.getGroupInfo() != null) { /* skip services that are clones or in groups. */ continue; } addExistingServiceMenuItem(asi.toString(), asi, dlm, callbackHash, list, colocationWi, orderWi, popups, testOnly); asi.addExistingGroupServiceMenuItems(thisClass, dlm, callbackHash, list, colocationWi, orderWi, popups, testOnly); } final JPanel colOrdPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); colOrdPanel.setBackground(ClusterBrowser.STATUS_BACKGROUND); colOrdPanel.add(colocationWi); colOrdPanel.add(orderWi); final MyMenu thisM = this; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { final boolean ret = Tools.getScrollingMenu(name, colOrdPanel, thisM, dlm, list, thisClass, popups, callbackHash); if (!ret) { setEnabled(false); } } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } super.update(); } }; }
From source file:lcmc.gui.resources.ServiceInfo.java
/** Adds new Service and dependence. */ private MyMenu getAddServiceMenuItem(final boolean testOnly, final String name) { final ServiceInfo thisClass = this; return new MyMenu(name, new AccessMode(ConfigData.AccessType.ADMIN, false), new AccessMode(ConfigData.AccessType.OP, false)) { private static final long serialVersionUID = 1L; private final Lock mUpdateLock = new ReentrantLock(); @Override/*from w w w . jav a2 s .co m*/ public String enablePredicate() { if (getBrowser().clStatusFailed()) { return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING; } else if (getService().isRemoved()) { return IS_BEING_REMOVED_STRING; } else if (getService().isOrphaned()) { return IS_ORPHANED_STRING; } else if (getService().isNew()) { return IS_NEW_STRING; } return null; } @Override public void update() { final Thread t = new Thread(new Runnable() { @Override public void run() { if (mUpdateLock.tryLock()) { try { updateThread(); } finally { mUpdateLock.unlock(); } } } }); t.start(); } private void updateThread() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setEnabled(false); } }); Tools.invokeAndWait(new Runnable() { @Override public void run() { removeAll(); } }); final Point2D pos = getPos(); final CRMXML crmXML = getBrowser().getCRMXML(); final ResourceAgent fsService = crmXML.getResourceAgent("Filesystem", ResourceAgent.HEARTBEAT_PROVIDER, ResourceAgent.OCF_CLASS); final MyMenu thisMenu = this; if (crmXML.isLinbitDrbdPresent()) { /* just skip it, if it is not */ final ResourceAgent linbitDrbdService = crmXML.getHbLinbitDrbd(); /* Linbit:DRBD */ try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { addDrbdLinbitMenu(thisMenu, crmXML, pos, fsService, testOnly); } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } } if (crmXML.isDrbddiskPresent()) { /* just skip it, if it is not */ /* drbddisk */ try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { addDrbddiskMenu(thisMenu, crmXML, pos, fsService, testOnly); } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } } final ResourceAgent ipService = crmXML.getResourceAgent("IPaddr2", ResourceAgent.HEARTBEAT_PROVIDER, ResourceAgent.OCF_CLASS); if (ipService != null) { /* just skip it, if it is not*/ /* ipaddr */ try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { addIpMenu(thisMenu, pos, ipService, testOnly); } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } } if (fsService != null) { /* just skip it, if it is not*/ /* Filesystem */ try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { addFilesystemMenu(thisMenu, pos, fsService, testOnly); } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } } final List<JDialog> popups = new ArrayList<JDialog>(); for (final String cl : ClusterBrowser.HB_CLASSES) { final List<ResourceAgent> services = getAddServiceList(cl); if (services.size() == 0) { /* no services, don't show */ continue; } final JCheckBox colocationWi = new JCheckBox("Colo", true); final JCheckBox orderWi = new JCheckBox("Order", true); colocationWi.setBackground(ClusterBrowser.STATUS_BACKGROUND); colocationWi.setPreferredSize(colocationWi.getMinimumSize()); orderWi.setBackground(ClusterBrowser.STATUS_BACKGROUND); orderWi.setPreferredSize(orderWi.getMinimumSize()); final JPanel colOrdPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); colOrdPanel.setBackground(ClusterBrowser.STATUS_BACKGROUND); colOrdPanel.add(colocationWi); colOrdPanel.add(orderWi); boolean mode = !AccessMode.ADVANCED; if (ResourceAgent.UPSTART_CLASS.equals(cl) || ResourceAgent.SYSTEMD_CLASS.equals(cl)) { mode = AccessMode.ADVANCED; } if (ResourceAgent.LSB_CLASS.equals(cl) && !getAddServiceList(ResourceAgent.SERVICE_CLASS).isEmpty()) { mode = AccessMode.ADVANCED; } final MyMenu classItem = new MyMenu(ClusterBrowser.getClassMenu(cl), new AccessMode(ConfigData.AccessType.ADMIN, mode), new AccessMode(ConfigData.AccessType.OP, mode)); final MyListModel<MyMenuItem> dlm = new MyListModel<MyMenuItem>(); for (final ResourceAgent ra : services) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { addResourceAgentMenu(ra, dlm, pos, popups, colocationWi, orderWi, testOnly); } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } } try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { final boolean ret = Tools.getScrollingMenu(ClusterBrowser.getClassMenu(cl), colOrdPanel, classItem, dlm, new MyList<MyMenuItem>(dlm, getBackground()), thisClass, popups, null); if (!ret) { classItem.setEnabled(false); } thisMenu.add(classItem); } }); } catch (final InterruptedException ix) { Thread.currentThread().interrupt(); } catch (final InvocationTargetException x) { Tools.printStackTrace(); } } super.update(); } }; }
From source file:rita.ui.component.DialogSelectEnemies.java
/** * Recorre el directorio robots y agrega al panel a todos los robots * (.class) instalados//from w w w .j a v a 2s. c om * * @throws FileNotFoundException * si no hay .class en el dir File(Settings.getInstallPath(), * "robots") */ private void addRobotsToPanel(JPanel panel) throws FileNotFoundException { if (Settings.getInstallPath() == null) { throw new FileNotFoundException( "La carpeta de robots no pudo ser encontrara porque InstallPath no esta definido"); } File robotDir = new File(Settings.getInstallPath(), "robots"); if (!robotDir.isDirectory() || !robotDir.canRead()) { //otra carpeta posible MVN robotDir = new File(Settings.getInstallPath() + Settings.getMvnResourcesPath(), "robots"); if (!robotDir.isDirectory() || !robotDir.canRead()) throw new FileNotFoundException( "La carpeta de robots " + robotDir + " no existe o no tiene permisos de lectura"); } boolean robotFound = false; // recorrer directorio robots y traer todos los robots instalados JCheckBox cb; JButton buttonPos; /* * buscar recursivametne a todos los .class en InstallPath() + "robots", * excluyendo a las inner clases, porque asumimos que son clases de * implementacion. Las reconocemos porque tienen '$' en el nombre de la * clase. */ for (File f : FileUtils.listFiles(robotDir, new String[] { "class" }, true)) { if (f.getName().endsWith(".class") && f.getName().indexOf('$') == -1) { String[] splitPath = f.getParent().split(pattern); /* * si el path del robot tiene directorio/nombrerobot.class => el * nombre del robot es "directorio.nombrerobot", sino es solo * "nombrerobot" */ if (splitPath.length > 0) { cb = new JCheckBox(splitPath[splitPath.length - 1] + "." + f.getName().substring(0, f.getName().lastIndexOf('.')), false); } else { cb = new JCheckBox(f.getName().substring(0, f.getName().lastIndexOf('.')), false); } JPanel panelCheckButton = new JPanel(); buttonPos = new JButton(icon); buttonPos.addActionListener(new PosicionRobotAction(cb.getText())); buttonPos.setPreferredSize(new Dimension(30, 30)); positionComponents.add(buttonPos); cb.addActionListener(robotNameClicked); cb.setPreferredSize(new Dimension(160, 30)); panelCheckButton.add(cb); panelCheckButton.add(buttonPos); panel.add(panelCheckButton); robotFound = true; } } if (!robotFound) { throw new FileNotFoundException("La carpeta de robots no contiene robots"); } }