/** Returns the value from the desktop. */ protected Object getValueFromDesktop() { if (this.toolkit == null) { this.toolkit = Toolkit.getDefaultToolkit(); } Object value = toolkit.getDesktopProperty(getKey()); pcl = new WeakPCL(this, toolkit, getKey(), UIManager.getLookAndFeel()); toolkit.addPropertyChangeListener(getKey(), pcl); return value; }
/** * Invalides the current value so that the next invocation of <code>createValue</code> will ask * for the property again. */ public void invalidate() { if (pcl != null) { toolkit.removePropertyChangeListener(getKey(), pcl); toolkit = null; pcl = null; value = null; } }
static Icon getOceanDisabledButtonIcon(Image image) { Object[] range = (Object[]) UIManager.get("Button.disabledGrayRange"); int min = 180; int max = 215; if (range != null) { min = ((Integer) range[0]).intValue(); max = ((Integer) range[1]).intValue(); } ImageProducer prod = new FilteredImageSource(image.getSource(), new OceanDisabledButtonImageFilter(min, max)); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); }
private Icon getStockIcon(SynthContext context, String key, int type) { TextDirection direction = TextDirection.LTR; if (context != null) { ComponentOrientation co = context.getComponent().getComponentOrientation(); if (co != null && !co.isLeftToRight()) { direction = TextDirection.RTL; } } // First try loading a theme-specific icon using the native // GTK libraries (native GTK handles the resizing for us). Icon icon = getStyleSpecificIcon(key, direction, type); if (icon != null) { return icon; } // In a failure case where native GTK (unexpectedly) returns a // null icon, we can try loading a default icon as a fallback. String propName = ICON_PROPERTY_PREFIX + key + '.' + type + '.' + (direction == TextDirection.RTL ? "rtl" : "ltr"); Image img = (Image) Toolkit.getDefaultToolkit().getDesktopProperty(propName); if (img != null) { return new ImageIcon(img); } // In an extreme failure situation, just return null (callers are // already prepared to handle a null icon, so the worst that can // happen is that an icon won't be included in the button/dialog). return null; }
public void mouseDragged(MouseEvent ev) { Window w = (Window) ev.getSource(); Point pt = ev.getPoint(); if (isMovingWindow) { Point windowPt; try { windowPt = (Point) AccessController.doPrivileged(getLocationAction); windowPt.x = windowPt.x - dragOffsetX; windowPt.y = windowPt.y - dragOffsetY; w.setLocation(windowPt); } catch (PrivilegedActionException e) { } } else if (dragCursor != 0) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust( r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust( r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust( r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust( r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if (!r.equals(startBounds)) { w.setBounds(r); // Defer repaint/validate on mouseReleased unless dynamic // layout is active. if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); getRootPane().repaint(); } } } }
private Icon getStyleSpecificIcon(String key, TextDirection direction, int type) { UNIXToolkit tk = (UNIXToolkit) Toolkit.getDefaultToolkit(); Image img = tk.getStockIcon(widgetType, key, type, direction.ordinal(), null); return (img != null) ? new ImageIcon(img) : null; }
void dispose() { kit.removePropertyChangeListener(key, this); }
public void actionPerformed(ActionEvent e) { if (isDirectorySelected()) { File dir = getDirectory(); if (dir != null) { try { // Strip trailing ".." dir = ShellFolder.getNormalizedFile(dir); } catch (IOException ex) { // Ok, use f as is } changeDirectory(dir); return; } } JFileChooser chooser = getFileChooser(); String filename = getFileName(); FileSystemView fs = chooser.getFileSystemView(); File dir = chooser.getCurrentDirectory(); if (filename != null) { // Remove whitespaces from end of filename int i = filename.length() - 1; while (i >= 0 && filename.charAt(i) <= ' ') { i--; } filename = filename.substring(0, i + 1); } if (filename == null || filename.length() == 0) { // no file selected, multiple selection off, therefore cancel the approve action resetGlobFilter(); return; } File selectedFile = null; File[] selectedFiles = null; // Unix: Resolve '~' to user's home directory if (File.separatorChar == '/') { if (filename.startsWith("~/")) { filename = System.getProperty("user.home") + filename.substring(1); } else if (filename.equals("~")) { filename = System.getProperty("user.home"); } } if (chooser.isMultiSelectionEnabled() && filename.length() > 1 && filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') { List<File> fList = new ArrayList<File>(); String[] files = filename.substring(1, filename.length() - 1).split("\" \""); // Optimize searching files by names in "children" array Arrays.sort(files); File[] children = null; int childIndex = 0; for (String str : files) { File file = fs.createFileObject(str); if (!file.isAbsolute()) { if (children == null) { children = fs.getFiles(dir, false); Arrays.sort(children); } for (int k = 0; k < children.length; k++) { int l = (childIndex + k) % children.length; if (children[l].getName().equals(str)) { file = children[l]; childIndex = l + 1; break; } } } fList.add(file); } if (!fList.isEmpty()) { selectedFiles = fList.toArray(new File[fList.size()]); } resetGlobFilter(); } else { selectedFile = fs.createFileObject(filename); if (!selectedFile.isAbsolute()) { selectedFile = fs.getChild(dir, filename); } // check for wildcard pattern FileFilter currentFilter = chooser.getFileFilter(); if (!selectedFile.exists() && isGlobPattern(filename)) { changeDirectory(selectedFile.getParentFile()); if (globFilter == null) { globFilter = new GlobFilter(); } try { globFilter.setPattern(selectedFile.getName()); if (!(currentFilter instanceof GlobFilter)) { actualFileFilter = currentFilter; } chooser.setFileFilter(null); chooser.setFileFilter(globFilter); return; } catch (PatternSyntaxException pse) { // Not a valid glob pattern. Abandon filter. } } resetGlobFilter(); // Check for directory change action boolean isDir = (selectedFile != null && selectedFile.isDirectory()); boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile)); boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled(); boolean isFileSelEnabled = chooser.isFileSelectionEnabled(); boolean isCtrl = (e != null && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0); if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) { changeDirectory(selectedFile); return; } else if ((isDir || !isFileSelEnabled) && (!isDir || !isDirSelEnabled) && (!isDirSelEnabled || selectedFile.exists())) { selectedFile = null; } } if (selectedFiles != null || selectedFile != null) { if (selectedFiles != null || chooser.isMultiSelectionEnabled()) { if (selectedFiles == null) { selectedFiles = new File[] {selectedFile}; } chooser.setSelectedFiles(selectedFiles); // Do it again. This is a fix for bug 4949273 to force the // selected value in case the ListSelectionModel clears it // for non-existing file names. chooser.setSelectedFiles(selectedFiles); } else { chooser.setSelectedFile(selectedFile); } chooser.approveSelection(); } else { if (chooser.isMultiSelectionEnabled()) { chooser.setSelectedFiles(null); } else { chooser.setSelectedFile(null); } chooser.cancelSelection(); } }
static Icon getOceanToolBarIcon(Image i) { ImageProducer prod = new FilteredImageSource(i.getSource(), new OceanToolBarImageFilter()); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); }
protected Image createImage(String location) { return Toolkit.getDefaultToolkit().createImage(getResource(location)); }
private static Image getImage(String name) { Toolkit tk = Toolkit.getDefaultToolkit(); name = "resources/" + name + ".png"; return tk.getImage(BorderedComponent.class.getResource(name)); }