public int getTitleHeight(Component c) { int th = 21; int fh = getBorderInsets(c).top + getBorderInsets(c).bottom; if (c instanceof JDialog) { JDialog dialog = (JDialog) c; th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1; if (dialog.getJMenuBar() != null) { th -= dialog.getJMenuBar().getSize().height; } } else if (c instanceof JInternalFrame) { JInternalFrame frame = (JInternalFrame) c; th = frame.getSize().height - frame.getRootPane().getSize().height - fh - 1; if (frame.getJMenuBar() != null) { th -= frame.getJMenuBar().getSize().height; } } else if (c instanceof JRootPane) { JRootPane jp = (JRootPane) c; if (jp.getParent() instanceof JFrame) { JFrame frame = (JFrame) c.getParent(); th = frame.getSize().height - frame.getContentPane().getSize().height - fh - 1; if (frame.getJMenuBar() != null) { th -= frame.getJMenuBar().getSize().height; } } else if (jp.getParent() instanceof JDialog) { JDialog dialog = (JDialog) c.getParent(); th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1; if (dialog.getJMenuBar() != null) { th -= dialog.getJMenuBar().getSize().height; } } } return th; }
/** * Obtains the properties for the passed in object. This is a JBoss managed operation. * * @param objectName * @param objectType * @return an collection of managed properties (may be <code>null</code>) */ @ManagementOperation( description = "Obtains the properties for an object", impact = Impact.ReadOnly) public List<ManagedProperty> getProperties(String objectName, Component objectType) { if (!isRunning()) return Collections.emptyList(); // Get engine to use for the rest of the method (this is synchronized) // ... final JcrEngine engine = getEngine(); assert engine != null; List<ManagedProperty> managedProps = new ArrayList<ManagedProperty>(); if (objectType.equals(Component.CONNECTOR)) { RepositorySource repositorySource = engine.getRepositorySource(objectName); assert repositorySource != null : "Connection '" + objectName + "' does not exist"; managedProps = ManagedUtils.getProperties(objectType, repositorySource); } else if (objectType.equals(Component.CONNECTIONPOOL)) { RepositoryConnectionPool connectionPool = engine.getRepositoryService().getRepositoryLibrary().getConnectionPool(objectName); assert connectionPool != null : "Repository Connection Pool for repository '" + objectName + "' does not exist"; managedProps = ManagedUtils.getProperties(objectType, connectionPool); } return managedProps; }
/** * Paint to an offscreen graphic, e.g. a graphic for an image or svg file. * * @param g * @param rect */ public void paintOffscreen(Graphics2D g, Rectangle rect) { // Get the components of the sort by X position. Component[] components = getComponents(); Arrays.sort( components, new Comparator<Component>() { public int compare(Component component, Component component1) { return component.getX() - component1.getX(); } }); for (Component c : this.getComponents()) { if (c instanceof DataPanel) { Graphics2D g2d = (Graphics2D) g.create(); Rectangle clipRect = new Rectangle(c.getBounds()); clipRect.height = rect.height; g2d.setClip(clipRect); g2d.translate(c.getX(), 0); ((DataPanel) c).paintOffscreen(g2d, rect); } } // super.paintBorder(g); }
/** * Calculates the preferred size dimensions for the specified panel given the components in the * specified parent container. * * @param target The component to be laid out. * @return A size deemed suitable for laying out the container. * @see #minimumLayoutSize */ public Dimension preferredLayoutSize(Container target) { int count; Component component; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock()) { // get the the total height and maximum width component ret = new Dimension(0, 0); count = target.getComponentCount(); for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getPreferredSize(); ret.width = Math.max(ret.width, dimension.width); ret.height += dimension.height; } } insets = target.getInsets(); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } return (ret); }
private Insets getButtonInsets(SynthContext context, Insets insets) { // The following calculations are derived from gtkbutton.c // (GTK+ version 2.8.20), gtk_button_size_allocate() method. int CHILD_SPACING = 1; int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); int xThickness = getXThickness(); int yThickness = getYThickness(); int w = focusSize + focusPad + xThickness + CHILD_SPACING; int h = focusSize + focusPad + yThickness + CHILD_SPACING; insets.left = insets.right = w; insets.top = insets.bottom = h; Component component = context.getComponent(); if ((component instanceof JButton) && !(component.getParent() instanceof JToolBar) && ((JButton) component).isDefaultCapable()) { // Include the default border insets, but only for JButtons // that are default capable. Note that // JButton.getDefaultCapable() returns true by default, but // GtkToolButtons are never default capable, so we skip this // step if the button is contained in a toolbar. Insets defaultInsets = getClassSpecificInsetsValue(context, "default-border", BUTTON_DEFAULT_BORDER_INSETS); insets.left += defaultInsets.left; insets.right += defaultInsets.right; insets.top += defaultInsets.top; insets.bottom += defaultInsets.bottom; } return insets; }
/** * Changes the frame's location to a more central screen location * * @param frame the frame to be moved * @param X how far right to move the frame * @param Y how far down to move the frame */ public static void changeFrameLocation(Component frame, int X, int Y) { Point location = frame.getLocation(); // the window's current location // move the window over and down a certain amount of pixels location.translate(X, Y); // set the location frame.setLocation(location); }
public void acceptMinimumSize(Component c) { Dimension minimumSize = getMinimumSize(c); c.setMinimumSize( new Dimension( Math.max(minimumSize.width, c.getMinimumSize().width), Math.max(minimumSize.height, c.getMinimumSize().height))); }
private static void drawSelection(JTable table, int column, Graphics g, final int width) { int y = 0; final int[] rows = table.getSelectedRows(); final int height = table.getRowHeight(); for (int row : rows) { final TableCellRenderer renderer = table.getCellRenderer(row, column); final Component component = renderer.getTableCellRendererComponent( table, table.getValueAt(row, column), false, false, row, column); g.translate(0, y); component.setBounds(0, 0, width, height); boolean wasOpaque = false; if (component instanceof JComponent) { final JComponent j = (JComponent) component; if (j.isOpaque()) wasOpaque = true; j.setOpaque(false); } component.paint(g); if (wasOpaque) { ((JComponent) component).setOpaque(true); } y += height; g.translate(0, -y); } }
private static void drawSelection(JTree tree, Graphics g, final int width) { int y = 0; final int[] rows = tree.getSelectionRows(); final int height = tree.getRowHeight(); for (int row : rows) { final TreeCellRenderer renderer = tree.getCellRenderer(); final Object value = tree.getPathForRow(row).getLastPathComponent(); if (value == null) continue; final Component component = renderer.getTreeCellRendererComponent(tree, value, false, false, false, row, false); if (component.getFont() == null) { component.setFont(tree.getFont()); } g.translate(0, y); component.setBounds(0, 0, width, height); boolean wasOpaque = false; if (component instanceof JComponent) { final JComponent j = (JComponent) component; if (j.isOpaque()) wasOpaque = true; j.setOpaque(false); } component.paint(g); if (wasOpaque) { ((JComponent) component).setOpaque(true); } y += height; g.translate(0, -y); } }
/** * Rewires components. Used to rewire components in the CR if a cache has been stopped (moved to * state TERMINATED), which would (almost) empty the registry of components. Rewiring will * re-inject all dependencies so that the cache can be started again. * * <p> */ public void rewire() { // need to re-inject everything again. for (Component c : new HashSet<Component>(componentLookup.values())) { // inject dependencies for this component c.injectDependencies(); } }
/** * Internal MDI frames have offsets where a popup menu should be shown (in JDK 1.2). This method * sums up iteratively all x and y offsets of all parent compontents until the top parent * component is reached. */ private void adjustOffsets(Component comp, Point offsetPoint) { if (comp != null) { Point compLocation = comp.getLocation(); offsetPoint.translate(compLocation.x, compLocation.y); adjustOffsets(comp.getParent(), offsetPoint); } }
@SuppressWarnings({"HardCodedStringLiteral"}) private Element writePanel(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; final Element res = new Element("splitter"); res.setAttribute("split-orientation", splitter.getOrientation() ? "vertical" : "horizontal"); res.setAttribute("split-proportion", Float.toString(splitter.getProportion())); final Element first = new Element("split-first"); first.addContent(writePanel((JPanel) splitter.getFirstComponent())); final Element second = new Element("split-second"); second.addContent(writePanel((JPanel) splitter.getSecondComponent())); res.addContent(first); res.addContent(second); return res; } else if (comp instanceof JBTabs) { final Element res = new Element("leaf"); final EditorWindow window = findWindowWith(comp); writeWindow(res, window); return res; } else if (comp instanceof EditorWindow.TCompForTablessMode) { final EditorWithProviderComposite composite = ((EditorWindow.TCompForTablessMode) comp).myEditor; final Element res = new Element("leaf"); writeComposite(res, composite.getFile(), composite, false, composite); return res; } else { LOG.error(comp != null ? comp.getClass().getName() : null); return null; } }
private void recurseSetFromComponent(Component com, boolean onlyUnmapped) { if (com == null) { return; } List<StereotypeMetaData> metas = com.getMetaData(); for (StereotypeMetaData meta : metas) { if (!onlyUnmapped || !isMapped(meta, com)) { setValue(meta, com, meta.getComponentValue(com)); } } if (com.getSlots() != null) { for (Slot slot : com.getSlots()) { List<StereotypeMetaData> slotMetas = slot.getMetaData(); for (StereotypeMetaData meta : slotMetas) { if (!onlyUnmapped || !isMapped(meta, slot)) { setValue(meta, slot, meta.getComponentValue(slot)); } } if (slot.getContent() != null) { for (Component slotCom : slot.getContent()) { recurseSetFromComponent(slotCom, onlyUnmapped); } } } } }
/** @return the list of component typed type */ public List<Component> getComponentsByType(String type) { List<Component> matches = new ArrayList<Component>(); for (Component c : pComps.values()) { if (c.getType().equalsIgnoreCase(type)) matches.add(c); } return matches; }
@Override public void setBounds(int x, int y, int width, int height, int op) { super.setBounds(x, y, width, height, op); if (xtext != null) { /* * Fixed 6277332, 6198290: * the coordinates is coming (to peer): relatively to closest HW parent * the coordinates is setting (to textField): relatively to closest ANY parent * the parent of peer is target.getParent() * the parent of textField is the same * see 6277332, 6198290 for more information */ int childX = x; int childY = y; Component parent = target.getParent(); // we up to heavyweight parent in order to be sure // that the coordinates of the text pane is relatively to closest parent while (parent.isLightweight()) { childX -= parent.getX(); childY -= parent.getY(); parent = parent.getParent(); } xtext.setBounds(childX, childY, width, height); xtext.validate(); } }
@Override public void mouseMoved(MouseEvent e) { Component source = e.getComponent(); Point location = e.getPoint(); direction = 0; if (location.x < dragInsets.left) direction += WEST; if (location.x > source.getWidth() - dragInsets.right - 1) direction += EAST; if (location.y < dragInsets.top) direction += NORTH; if (location.y > source.getHeight() - dragInsets.bottom - 1) direction += SOUTH; // Mouse is no longer over a resizable border if (direction == 0) { source.setCursor(sourceCursor); } else // use the appropriate resizable cursor { int cursorType = cursors.get(direction); Cursor cursor = Cursor.getPredefinedCursor(cursorType); source.setCursor(cursor); } }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { // choose which colors we want to use Color bg = c.getBackground(); if (c.getParent() != null) { bg = c.getParent().getBackground(); } if (bg != null) { Color mid = bg.darker(); Color edge = average(mid, bg); g.setColor(bg); g.drawLine(0, h - 2, w, h - 2); g.drawLine(0, h - 1, w, h - 1); g.drawLine(w - 2, 0, w - 2, h); g.drawLine(w - 1, 0, w - 1, h); // draw the drop-shadow g.setColor(mid); g.drawLine(1, h - 2, w - 2, h - 2); g.drawLine(w - 2, 1, w - 2, h - 2); g.setColor(edge); g.drawLine(2, h - 1, w - 2, h - 1); g.drawLine(w - 1, 2, w - 1, h - 2); } }
@Override public void mouseExited(MouseEvent e) { if (!resizing) { Component source = e.getComponent(); source.setCursor(sourceCursor); } }
@Override public void onDisable() { if (componentManager != null) { int componentCount = componentManager.components.size(); for (Component component : componentManager.components) { component.dispose(); } componentManager.clear(); Log.info("Unloaded " + componentCount + " components."); } if (mapManager != null) { mapManager.stopRendering(); mapManager = null; } if (webServer != null) { webServer.shutdown(); webServer = null; } /* Clean up all registered handlers */ for (Event.Type t : event_handlers.keySet()) { List<Listener> ll = event_handlers.get(t); ll .clear(); /* Empty list - we use presence of list to remember that we've registered with Bukkit */ } playerfacemgr = null; /* Don't clean up markerAPI - other plugins may still be accessing it */ Debug.clearDebuggers(); }
@Override public void mousePressed(MouseEvent e) { // The mouseMoved event continually updates this variable if (direction == 0) return; // Setup for resizing. All future dragging calculations are done based // on the original bounds of the component and mouse pressed location. resizing = true; Component source = e.getComponent(); pressed = e.getPoint(); SwingUtilities.convertPointToScreen(pressed, source); bounds = source.getBounds(); // Making sure autoscrolls is false will allow for smoother resizing // of components if (source instanceof JComponent) { JComponent jc = (JComponent) source; autoscrolls = jc.getAutoscrolls(); jc.setAutoscrolls(false); } }
public void enableControlPanel() { boolean bVisible = false; int nmembers = buttonPane.getComponentCount(); for (int k = 0; k < nmembers; k++) { Component comp = buttonPane.getComponent(k); if (comp != null) { if (comp.isVisible() || comp.isEnabled()) { bVisible = true; break; } } } if (bVisible && !buttonPane.isVisible()) { Dimension dim = getSize(); Dimension dim1 = buttonPane.getPreferredSize(); int w = dim.width; int h = dim.height + dim1.height; if (dim1.width > w) w = dim1.width; if (w < 300) w = 300; if (h < 200) h = 200; setSize(w, h); } buttonPane.setVisible(bVisible); }
public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Insets insets = parent.getInsets(); int itop = insets.top; int ileft = insets.left; int ibottom = insets.bottom; int iright = insets.right; int rightWidth = right.getPreferredSize().width; int bottomHeight = bottom.getPreferredSize().height; int centerWidth = size.width - rightWidth - ileft - iright; int centerHeight = size.height - bottomHeight - itop - ibottom; center.setBounds(ileft, itop, centerWidth, centerHeight); right.setBounds(ileft + centerWidth, itop, rightWidth, centerHeight); // Lay out all status components, in order Enumeration status = leftOfScrollBar.elements(); while (status.hasMoreElements()) { Component comp = (Component) status.nextElement(); Dimension dim = comp.getPreferredSize(); comp.setBounds(ileft, itop + centerHeight, dim.width, bottomHeight); ileft += dim.width; } bottom.setBounds( ileft, itop + centerHeight, size.width - rightWidth - ileft - iright, bottomHeight); }
public void actionPerformed(ActionEvent e) { int selIndexBefore = getSelectedIndex(); myDefaultAction.actionPerformed(e); int selIndexCurrent = getSelectedIndex(); if (selIndexBefore != selIndexCurrent) { return; } if (myFocusNext && selIndexCurrent == 0) { return; } KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Container container = kfm.getCurrentFocusCycleRoot(); FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); if (policy == null) { policy = kfm.getDefaultFocusTraversalPolicy(); } Component next = myFocusNext ? policy.getComponentAfter(container, PaletteItemsComponent.this) : policy.getComponentBefore(container, PaletteItemsComponent.this); if (next instanceof PaletteGroupComponent) { clearSelection(); next.requestFocus(); ((PaletteGroupComponent) next).scrollRectToVisible(next.getBounds()); } }
@Override public DataResponse<Iterable<TestResult>> historySearch(String componentId, String jobName) { ObjectId cId = null; if (componentId != null && !componentId.isEmpty()) { cId = new ObjectId(componentId); } Component component = componentRepository.findOne(cId); if (!component.getCollectorItems().containsKey(CollectorType.Test)) { return new DataResponse<>(null, 0L); } List<TestResult> result = new ArrayList<>(); for (CollectorItem item : component.getCollectorItems().get(CollectorType.Test)) { QTestResult testResult = new QTestResult("testResult"); BooleanBuilder builder = new BooleanBuilder(); builder.and(testResult.collectorItemId.eq(item.getId())); if (jobName != null && !jobName.isEmpty()) { builder.and(testResult.jobName.eq(jobName)); } result.addAll( Lists.newArrayList( testResultRepository.findAll(builder.getValue(), testResult.timestamp.desc()))); } return new DataResponse<>(result, 0L); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Color color = UIUtil.getTableFocusCellBackground(); Component component; final Module module = value instanceof Module ? (Module) value : null; try { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground()); component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (module != null) { setText( module.getName() + " (" + FileUtil.toSystemDependentName(module.getModuleFilePath()) + ")"); } if (component instanceof JLabel) { ((JLabel) component).setBorder(noFocusBorder); } } finally { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color); } component.setEnabled(ProcessedModulesTable.this.isEnabled()); if (component instanceof JLabel) { final Icon icon = module != null ? ModuleType.get(module).getIcon() : null; JLabel label = (JLabel) component; label.setIcon(icon); label.setDisabledIcon(icon); } component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); return component; }
public static void bumpUpFontSize(Component widget, int bumps) { if (!UserPreferences.readLocalePref() .equals("ko")) { // HACK!!! refector with variable localeSupportsBold Font f = widget.getFont(); widget.setFont(new Font(f.getFamily(), f.getStyle(), f.getSize() + bumps)); } }
/** * Create component descriptors for the passed component implementation class and component role * class. There can be more than one descriptor if the component class has specified several * hints. * * @param componentClass the component implementation class * @param componentRoleClass the component role class * @return the component descriptors with resolved component dependencies */ public List<ComponentDescriptor> createComponentDescriptors( Class<?> componentClass, Class<?> componentRoleClass) { List<ComponentDescriptor> descriptors = new ArrayList<ComponentDescriptor>(); // If there's a @Named annotation, use it and ignore hints specified in the @Component // annotation. String[] hints; Named named = componentClass.getAnnotation(Named.class); if (named != null) { hints = new String[] {named.value()}; } else { // If the Component annotation has several hints specified ignore the default hint value and // for each // specified hint create a Component Descriptor Component component = componentClass.getAnnotation(Component.class); if (component != null && component.hints().length > 0) { hints = component.hints(); } else { if (component != null && component.value().trim().length() > 0) { hints = new String[] {component.value().trim()}; } else { hints = new String[] {"default"}; } } } // Create the descriptors for (String hint : hints) { descriptors.add(createComponentDescriptor(componentClass, hint, componentRoleClass)); } return descriptors; }
public void actionPerformed(ActionEvent e) { KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Container container = kfm.getCurrentFocusCycleRoot(); FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy(); Component next = moveDown ? policy.getComponentAfter(container, PaletteGroupHeader.this) : policy.getComponentBefore(container, PaletteGroupHeader.this); if (null != next && next instanceof PaletteComponentList) { final PaletteComponentList list = (PaletteComponentList) next; if (list.getModel().getSize() != 0) { list.takeFocusFrom(PaletteGroupHeader.this, list == myComponentList ? 0 : -1); return; } else { next = moveDown ? policy.getComponentAfter(container, next) : policy.getComponentBefore(container, next); } } if (null != next && next instanceof PaletteGroupHeader) { next.requestFocus(); } }
private void drawWinBorder(Component c, Graphics g, int x, int y, int w, int h) { if (!c.isEnabled()) { g.setColor(Theme.textBorderDisabledColor[Theme.style].getColor()); } else { g.setColor(Theme.textBorderColor[Theme.style].getColor()); } g.drawLine(x + 1, y + 1, x + w - 3, y + 1); g.drawLine(x + 1, y + 2, x + 1, y + h - 3); if (!c.isEnabled()) { g.setColor(Theme.textBorderDarkDisabledColor[Theme.style].getColor()); } else { g.setColor(Theme.textBorderDarkColor[Theme.style].getColor()); } g.drawLine(x, y, x + w - 2, y); g.drawLine(x, y + 1, x, y + h - 2); g.setColor(Theme.backColor[Theme.style].getColor()); g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2); g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2); if (!c.isEnabled()) { g.setColor(Theme.textBorderLightDisabledColor[Theme.style].getColor()); } else { g.setColor(Theme.textBorderLightColor[Theme.style].getColor()); } g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); }
public static void hidePopups(Component comp) { if (comp != null) { label0: for (Component c = comp; c != null; c = c.getParent()) { if (!(c instanceof ZPopupGallery)) continue; do { if (currShownList.size() <= 0) continue label0; if (currShownList.getLast() == c) return; ZPopupGallery jpg = (ZPopupGallery) currShownList.removeLast(); Popup popup = (Popup) popupGalleryHM.get(jpg); popup.hide(); popupGalleryHM.remove(jpg); } while (true); } } Iterator iterator = popupGalleryHM.keySet().iterator(); do { if (!iterator.hasNext()) break; ZPopupGallery gallery = (ZPopupGallery) iterator.next(); ((Popup) popupGalleryHM.get(gallery)).hide(); if (gallery.getActionListener() != null) gallery.getActionListener().actionPerformed(new ActionEvent(gallery, 1, "Hidden")); } while (true); popupGalleryHM.clear(); }