List of usage examples for java.awt Component getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Finds the components identified by the specified class contained in the * passed component. Returns a collection of found component or * <code>null</code> if none found. * /*w w w.j av a 2 s. c o m*/ * @param comp The component to visit. Mustn't be <code>null</code>. * @param c The class identifying the component to find. * @return See above. */ public static List<Component> findComponents(Component comp, Class c) { List<Component> l = null; if (c == null || comp == null) throw new IllegalArgumentException("The parameters cannot be " + "null"); if (c.isAssignableFrom(comp.getClass())) { l = new ArrayList<Component>(1); l.add(comp); return l; } if (comp instanceof Container) { Component[] comps = ((Container) comp).getComponents(); Component child; l = new ArrayList<Component>(comps.length); for (int i = 0; i < comps.length; i++) { child = findComponent(comps[i], c); if (child != null) l.add(child); } return l; } return null; }
From source file:com.jtstand.swing.StatsPanel.java
private void showStatisticsTable() { StatsTableModel tm = new StatsTableModel(this, allstat, catstats); jTable.setModel(tm);/* w w w. j a v a 2s . c o m*/ jTable.setBackground(Color.white); //... // resizeSeries(); //((ColumnHeaderRenderer) jTable.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER); jTable.addHighlighter(new Highlighter() { public Component highlight(Component c, ComponentAdapter ca) { if (JLabel.class.isAssignableFrom(c.getClass())) { ((JLabel) c).setHorizontalAlignment(SwingConstants.CENTER); int column = jTable.convertColumnIndexToModel(ca.column); if (column == StatsTableModel.StatsTableColumn.CATEGORY.ordinal()) { if (jTable.getRowCount() > 1) { int i = jTable.convertRowIndexToModel(ca.row); if (i > 0) { c.setForeground(ChartCategories.getColor(i - 1)); } } else { if (isCategorization() && !isMultipleCategorization()) { c.setForeground(ChartCategories.getColor(0)); } } } } return c; } public void addChangeListener(ChangeListener arg0) { } public void removeChangeListener(ChangeListener arg0) { } public ChangeListener[] getChangeListeners() { return new ChangeListener[0]; } }); DecimalFormat df = null; if (testStepInstances.getReferenceStep() != null) { String decFormatStr = testStepInstances.getReferenceStep() .getPropertyString(TestStepInstance.STR_DECIMAL_FORMAT, null); if (decFormatStr != null) { df = new DecimalFormat(decFormatStr); } } jTable.setDefaultRenderer(Double.class, new StatsTableRendererDouble(df)); //this.jTableSeries.invalidate(); Util.packColumns(jTable, 9); // jTableSeries.setVisibleRowCount(Math.min(3, jTableSeries.getRowCount())); Util.setVisibleRowCount(jTable, Math.min(3, jTable.getRowCount()), jSplitPane); // Util.getRowCount(jTable, jSplitPane); // Util.setDividerLocation(jSplitPane, jTable); jSplitPane.setDividerLocation(-1); // jScrollPaneTop.invalidate(); // validateTree(); }
From source file:tufts.vue.RichTextBox.java
/** * This is what triggers the final save of the new text value to the LWComponent, * and notify's the UndoManager that a user action was completed. *//*from ww w. j a v a 2s .c om*/ public void focusLost(FocusEvent e) { final java.awt.Component opposite = e.getOppositeComponent(); if (opposite != null) { if ((opposite.getName() != null && opposite.getName().equals(FontEditorPanel.SIZE_FIELD_NAME)) || opposite.getClass() == ColorMenuButton.class) return; else if (opposite.getClass() == FontEditorPanel.class || DockWindow.isDockWindow(opposite) || // todo: something more generic than this getName check: set a property on the JComponent tagging it as a tool/editor? opposite.getClass() == JComboBox.class || (opposite.getName() != null && opposite.getName().equals(tufts.vue.gui.ColorMenuButton.COLOR_POPUP_NAME)) || //quaqua makes this a bit awkard, this is for quaqua's color chooser. (opposite.getName() != null && opposite.getName().equals("dialog0"))) { //Earlier i was just returning here, but this creates a problem //because the component has already lost the focus...and so it doesn't //get another focusLost the next time....so re-request the focus if you've lost //it so that we get the event again when we really want to get rid of the focus //so we can properly remove the edit control. requestFocus(); return; } } else if (opposite == null) { if (DEBUG.FOCUS) outc("Focus not lost because opposite component = null"); requestFocus(); return; } //System.out.println(e.getComponent().toString()); //System.out.println(e.getOppositeComponent().toString()); if (TestDebug || DEBUG.FOCUS) outc("focusLost to " + e.getOppositeComponent() + " " + opposite.getName()); if (TestHarness == false && getParent() != null) { getParent().remove(this); // VUE.getFormattingPanel().getTextPropsPane().getFontEditorPanel().updateFormatControlsTB(this); } if (keyWasPressed || !keyWasPressed) { // TODO: as per VueTextField, need to handle drag & drop detect // only do this if they typed something (so we don't wind up with "label" // for the label on an accidental edit activation) if (TestDebug || DEBUG.FOCUS) out("key was pressed; setting label to: [" + getText() + "]"); String text = getText(); if (revert) { text = mUnchangedText; revert = false; // setText(text); } lwc.setLabel0(text, false); VUE.getUndoManager().mark(); } //// setSize(getPreferredSize()); // lwc.setSize(mBounds.width, mBounds.height); if (lwc.getParent() != null && lwc.getParent() instanceof LWNode) lwc.getParent().layout(); lwc.notify(this, LWKey.Repaint); }
From source file:com.diversityarrays.kdxplore.KDXploreFrame.java
private void initialiseKdxApps() throws IOException { String[] classNames = KdxploreConfig.getInstance().getMainPluginClassNames(); if (classNames != null && classNames.length > 0) { List<String> classNamesToLoad = new ArrayList<>(); Collections.addAll(classNamesToLoad, classNames); if (!classNamesToLoad.contains(OFFLINE_DATA_APP_SERVICE_CLASS_NAME)) { classNamesToLoad.add(0, OFFLINE_DATA_APP_SERVICE_CLASS_NAME); classNames = classNamesToLoad.toArray(new String[classNamesToLoad.size()]); }//from w ww . j ava 2s . c o m } Map<KdxApp, Component> componentByApp = collectKdxApps(classNames); appByComponent.clear(); for (KdxApp app : componentByApp.keySet()) { Component comp = componentByApp.get(app); if (comp != null) { appByComponent.put(comp, app); } } allKdxApps.clear(); allKdxApps.addAll(componentByApp.keySet()); // Initialise the apps in initialisation order. allKdxApps.sort(Comparator.comparing(KdxApp::getInitialisationOrder)); // And while we're initialising them we collect // those that can perform a databaseBackup (i.e. have a BackupProvider). backupProviders.clear(); List<KdxApp> wantedAppsWithUi = new ArrayList<>(); for (KdxApp app : allKdxApps) { BackupProvider bp = app.getBackupProvider(); if (bp != null) { backupProviders.add(bp); } /** * See {@link com.diversityarrays.kdxplore.prefs.KdxplorePreferences#SHOW_ALL_APPS} */ if (appIsWanted(app)) { try { app.initialiseAppBeforeUpdateCheck(appInitContext); } catch (Exception e) { String msg = Msg.MSG_KDXAPP_INIT_PROBLEM(app.getAppName()); Shared.Log.w(TAG, msg, e); messagesPanel.println(msg); messagesPanel.println(e.getMessage()); } } if (appIsWanted(app) && null != componentByApp.get(app)) { wantedAppsWithUi.add(app); } } // - - - - - - - - - - - - - - - - - - - - - // Display the apps in display order. wantedAppsWithUi.sort(Comparator.comparing(KdxApp::getDisplayOrder)); backupProviders.sort(Comparator.comparing(BackupProvider::getDisplayOrder)); switch (wantedAppsWithUi.size()) { case 0: JLabel label = new JLabel(Msg.MSG_NO_KDXPLORE_APPS_AVAILABLE()); label.setHorizontalAlignment(JLabel.CENTER); cardPanel.add(label, CARD_KDXAPPS); break; case 1: KdxApp kdxApp = wantedAppsWithUi.get(0); Component uiComponent = componentByApp.get(kdxApp); Component appComponent = makeComponentForTab(kdxApp, uiComponent); cardPanel.add(appComponent, CARD_KDXAPPS); getRootPane().setDefaultButton(kdxApp.getDefaultButton()); String msg = Msg.MSG_SHOWING_KDXAPP(kdxApp.getAppName()); messagesPanel.println(msg); System.err.println(msg + " uiClass=" //$NON-NLS-1$ + uiComponent.getClass().getName()); break; default: kdxAppTabs = new JTabbedPane(JTabbedPane.LEFT); cardPanel.add(kdxAppTabs, CARD_KDXAPPS); Bag<String> tabsSeen = new HashBag<>(); for (KdxApp app : wantedAppsWithUi) { Component ui = componentByApp.get(app); String tabName = app.getAppName(); DevelopmentState devState = app.getDevelopmentState(); switch (devState) { case ALPHA: tabName = tabName + " (\u03b1)"; // TODO move to UnicodeChars break; case BETA: tabName = tabName + " (\u03b2)"; // TODO move to UnicodeChars break; case PRODUCTION: break; default: tabName = tabName + " " + devState.name(); break; } tabsSeen.add(tabName); int count = tabsSeen.getCount(tabName); if (count > 1) { tabName = tabName + "_" + count; //$NON-NLS-1$ } Component tabComponent = makeComponentForTab(app, ui); kdxAppTabs.addTab(tabName, tabComponent); if (macapp == null) { int index = kdxAppTabs.indexOfTab(tabName); if (index >= 0) { JLabel tabLabel = new JLabel(tabName); tabLabel.setBorder(new EmptyBorder(2, 2, 2, 2)); tabLabel.setUI(new VerticalLabelUI(VerticalLabelUI.UPWARDS)); kdxAppTabs.setTabComponentAt(index, tabLabel); } } messagesPanel.println(Msg.MSG_SHOWING_KDXAPP(tabName)); } kdxAppTabs.addChangeListener(kdxAppTabsChangeListener); kdxAppTabs.setSelectedIndex(0); break; } }
From source file:it.cnr.icar.eric.client.ui.swing.AdhocQuerySearchPanel.java
private String getParameterValue(int paramPosition, Component component) { String paramValue = null;//w w w . j ava 2 s . c o m try { if (component instanceof JTextComponent) { paramValue = ((JTextComponent) component).getText(); } else if (component instanceof AbstractButton) { boolean selected = ((AbstractButton) component).isSelected(); if (selected) { paramValue = "1"; } else { paramValue = "0"; } } else if (component instanceof it.cnr.icar.eric.client.ui.swing.TreeCombo) { Object conceptsTreeNode = ((it.cnr.icar.eric.client.ui.swing.TreeCombo) component) .getSelectedItemsObject(); Object nodeInfo = ((DefaultMutableTreeNode) conceptsTreeNode).getUserObject(); if (nodeInfo instanceof it.cnr.icar.eric.client.ui.swing.NodeInfo) { Object obj = ((it.cnr.icar.eric.client.ui.swing.NodeInfo) nodeInfo).obj; if (obj instanceof ClassificationScheme) { paramValue = null; } else if (obj instanceof Concept) { paramValue = ((Concept) obj).getPath(); } } } else { RegistryBrowser.displayError( "Internal error: unsupported component class: " + component.getClass().getName()); } } catch (JAXRException e) { log.error(e); } return paramValue; }
From source file:com.projity.pm.graphic.frames.GraphicManager.java
/** determines the parent graphic manager for a component * * @param component/*from w w w. j a va2 s . c o m*/ * @return */ public static GraphicManager getInstance(Component component) { Component c = component; for (c = component; c != null; c = c.getParent()) { if (c instanceof FrameHolder) return ((FrameHolder) c).getGraphicManager(); else if (c.getName() != null && c.getName().endsWith("BootstrapApplet") && c.getClass().getName().endsWith("BootstrapApplet")) { System.out.println("applet: " + c.getClass().getName()); try { FrameHolder holder = (FrameHolder) Class.forName("com.projity.bootstrap.BootstrapApplet.class") .getMethod("getObject", null).invoke(c, null); return holder.getGraphicManager(); } catch (Exception e) { return null; } } } return lastGraphicManager; // if none found, use last used one }
From source file:edu.ku.brc.specify.datamodel.busrules.DeterminationBusRules.java
@Override public void afterFillForm(final Object dataObj) { isBlockingChange = false;/* w w w .ja v a 2 s .co m*/ determination = null; if (formViewObj != null && formViewObj.getDataObj() instanceof Determination) { determination = (Determination) formViewObj.getDataObj(); // if determination exists and is new (no key) then set current true if CO has no other dets Component currentComp = formViewObj.getControlByName("isCurrent"); if (determination != null && currentComp != null) { if (isNewObject) { // It should never be null, but, currently, it does happen. // Also, now with Batch ReIdentify is will always be NULL if (determination.getCollectionObject() != null) { if (currentComp instanceof ValCheckBox) { if (formViewObj.isCreatingNewObject()) { // Do this instead of setSelected because // this activates the DataChangeListener isBlockingChange = true; ((ValCheckBox) currentComp).doClick(); isBlockingChange = false; // Well, if it is already checked then we just checked it to the 'off' state, // so we need to re-check it so it is in the "checked state" // Note: As stated in the comment above the 'doClick' the easiest way to activate // all the change listeners is by simulating a mouse click. // Also keep in mind that the change listener is listening for ActionEvents for the // checkbox instead of ChangeEvents (ChangeEvents cause to many problems). if (!((ValCheckBox) currentComp).isSelected()) { ((ValCheckBox) currentComp).doClick(); } Set<Determination> detSet = determination.getCollectionObject().getDeterminations(); for (Determination d : detSet) { if (d != determination) { d.setIsCurrent(false); } } } } else { log.error("IsCurrent not set to true because form control is of unexpected type: " + currentComp.getClass().getName()); } } } else { ((ValCheckBox) currentComp).setValue(determination.getIsCurrent(), null); } } Component activeTax = formViewObj.getControlByName("preferredTaxon"); if (activeTax != null) { JTextField activeTaxTF = (JTextField) activeTax; activeTaxTF.setFocusable(false); if (determination != null && determination.getPreferredTaxon() != null) { activeTaxTF.setText(determination.getPreferredTaxon().getFullName()); } else { activeTaxTF.setText(""); } } if (formViewObj.getAltView().getMode() != CreationMode.EDIT) { // when we're not in edit mode, we don't need to setup any listeners since the user can't change anything //log.debug("form is not in edit mode: no special listeners will be attached"); return; } Component nameUsageComp = formViewObj.getControlByName("nameUsage"); if (nameUsageComp instanceof ValComboBox) { // XXX this is probably not necessary anymore... if (!checkedBlankUsageItem) { boolean fnd = false; if (nameUsageComp instanceof ValComboBox) { ValComboBox cbx = (ValComboBox) nameUsageComp; if (cbx.getComboBox().getModel() instanceof PickListDBAdapterIFace) { PickListDBAdapterIFace items = (PickListDBAdapterIFace) cbx.getComboBox().getModel(); for (PickListItemIFace item : items.getPickList().getItems()) { if (StringUtils.isBlank(item.getValue())) { fnd = true; break; } } if (!fnd) { boolean readOnly = items.getPickList().getReadOnly(); if (readOnly) { items.getPickList().setReadOnly(false); } items.addItem("", null); if (readOnly) { items.getPickList().setReadOnly(true); } } } } checkedBlankUsageItem = true; } nameUsageComp.setEnabled(true); } final Component altNameComp = formViewObj.getControlByName("alternateName"); if (altNameComp != null && determination != null) { altNameComp.setEnabled(determination.getTaxon() == null); } if (currentComp != null && chkbxCL == null) { chkbxCL = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { adjustIsCurrentCheckbox(); } }; isCurrentCheckbox = (ValCheckBox) currentComp; isCurrentCheckbox.addChangeListener(chkbxCL); } } isNewObject = false; }
From source file:self.philbrown.javaQuery.$.java
/** * Include the html string the selected views. If a view has a setText method, it is used. Otherwise, * a new TextView is created. This html can also handle image tags for both urls and local files. * Local files should be the name (for example, for R.id.ic_launcher, just use ic_launcher). * @param html the HTML String to include *//*from ww w. ja v a2 s .c o m*/ public $ html(String html) { for (Component view : this.views) { try { Method m = view.getClass().getMethod("setText", new Class<?>[] { String.class }); m.invoke(view, html); } catch (Throwable t) { if (view instanceof Container) { try { //no setText method. Try a TextView JLabel label = new JLabel(); int rgba = Color.HSBtoRGB(0, 0, 0); rgba |= (0 & 0xff); label.setBackground(new Color(rgba, true)); label.setBounds(label.getParent().getBounds()); ((Container) view).add(label); label.setText(html); } catch (Throwable t2) { //unable to set content Log.w("javaQuery", "unable to set HTML content"); } } else { //unable to set content Log.w("javaQuery", "unable to set textual content"); } } } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Includes the given text string inside of the selected views. If a view has a setText method, it is used * otherwise, if possible, a textview is added as a child to display the text. * @param text the text to include//from www.j av a 2 s . com */ public $ text(String text) { for (Component view : this.views) { try { Method m = view.getClass().getMethod("setText", new Class<?>[] { String.class }); m.invoke(view, text); } catch (Throwable t) { if (view instanceof Container) { try { //no setText method. Try a TextView JLabel label = new JLabel(); int rgba = Color.HSBtoRGB(0, 0, 0); rgba |= (0 & 0xff); label.setBackground(new Color(rgba, true)); label.setBounds(label.getParent().getBounds()); ((Container) view).add(label); label.setText(text); } catch (Throwable t2) { //unable to set content Log.w("javaQuery", "unable to set textual content"); } } else { //unable to set content Log.w("javaQuery", "unable to set textual content"); } } } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Sets the value of the given attribute on each view in the current selection. This is done * using reflection, and as such a <em>set-</em>prefixed method name for each view. * @param s the name of the attribute to set * @param o the value to set to the given attribute * @return this/* w w w . j a v a2 s. co m*/ */ public $ attr(String s, Object o) { for (Component view : this.views) { try { Class<?> objClass = o.getClass(); Class<?> simpleClass = PRIMITIVE_TYPE_MAP.get(objClass); if (simpleClass != null) { objClass = simpleClass; } try { Method m = view.getClass().getMethod("set" + capitalize(s), new Class<?>[] { objClass }); m.invoke(view, o); } catch (Throwable t) { //try using NineOldAndroids Log.w("javaQuery", view.getClass().getSimpleName() + ".set" + capitalize(s) + "(" + o.getClass().getSimpleName() + ") is not a method!"); } } catch (Throwable t) { Log.w("javaQuery", view.getClass().getSimpleName() + ".set" + capitalize(s) + "(" + o.getClass().getSimpleName() + ") is not a method!"); } } return this; }