/** * Generate the xml top level element and start streaming the components. * * @param components * @param contentHandler * @throws SAXException */ protected static void generateXML( Components components, ContentHandler contentHandler, boolean isScrPrivateFile) throws SAXException { // detect namespace to use final String namespace; if (components.getSpecVersion() == Constants.VERSION_1_0) { namespace = NAMESPACE_URI_1_0; } else if (components.getSpecVersion() == Constants.VERSION_1_1) { namespace = NAMESPACE_URI_1_1; } else { namespace = NAMESPACE_URI_1_1_FELIX; } contentHandler.startDocument(); contentHandler.startPrefixMapping(PREFIX, namespace); // wrapper element to generate well formed xml contentHandler.startElement( "", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS, new AttributesImpl()); IOUtils.newline(contentHandler); for (final Component component : components.getComponents()) { if (component.isDs()) { generateXML(namespace, component, contentHandler, isScrPrivateFile); } } // end wrapper element contentHandler.endElement( "", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS); IOUtils.newline(contentHandler); contentHandler.endPrefixMapping(PREFIX); contentHandler.endDocument(); }
/** * Create possibly volatile scratch image for fast painting. A scratch image can become * invalidated, when this happens any actions involving it are ignored, and it needs to be * recreated. Use isScratchImageValid() to check this. */ public static Image createScratchImage(int width, int height) { try { Image img = (Image) tryMethod( output_comp, "createVolatileImage", new Object[] {new Integer(width), new Integer(height)}); if (img == null) { // no such method -> create regular image return output_comp.createImage(width, height); } // if (img.validate(output_comp.getGraphicsConfiguration()) // == VolatileImage.IMAGE_INCOMPATIBLE) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); Integer valid = (Integer) tryMethod(img, "validate", new Object[] {gc}); // output_comp.getGraphicsConfiguration() }); if (valid.intValue() == 2) { // I checked, IMAGE_INCOMPATIBLE=2 // Hmm, somehow it didn't work. Create regular image. return output_comp.createImage(width, height); } return img; } catch (java.security.AccessControlException e) { // we're not allowed to do this (we're probably an applet) return output_comp.createImage(width, height); } }
/* * Fix for BugTraq ID 4041703. * Set the focus to a reasonable default for an Applet. */ private void setDefaultFocus() { Component toFocus = null; Container parent = getParent(); if (parent != null) { if (parent instanceof Window) { toFocus = getMostRecentFocusOwnerForWindow((Window) parent); if (toFocus == parent || toFocus == null) { toFocus = parent.getFocusTraversalPolicy().getInitialComponent((Window) parent); } } else if (parent.isFocusCycleRoot()) { toFocus = parent.getFocusTraversalPolicy().getDefaultComponent(parent); } } if (toFocus != null) { if (parent instanceof EmbeddedFrame) { ((EmbeddedFrame) parent).synthesizeWindowActivation(true); } // EmbeddedFrame might have focus before the applet was added. // Thus after its activation the most recent focus owner will be // restored. We need the applet's initial focusabled component to // be focused here. toFocus.requestFocusInWindow(); } }
public void setColumnWidths() { // See // "http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#custom" int n = getModel().getColumnCount(); for (int j = 0; j < n; ++j) { TableColumn column = getColumnModel().getColumn(j); TableCellRenderer headerRenderer = column.getHeaderRenderer(); if (headerRenderer == null) headerRenderer = getTableHeader().getDefaultRenderer(); // the new 1.3 way Component columnComponent = headerRenderer.getTableCellRendererComponent( this, column.getHeaderValue(), false, false, -1, j); Component cellComponent = getDefaultRenderer(getColumnClass(j)) .getTableCellRendererComponent(this, getModel().getValueAt(0, j), false, false, 0, j); int wantWidth = Math.max( columnComponent.getPreferredSize().width + 10, // fudge factor ... seems to always be too small otherwise (on x86 Linux) cellComponent.getPreferredSize().width + 10 // fudge factor ... seems to always be too small otherwise (on Mac OS X) ); column.setPreferredWidth(wantWidth); } }
/** * 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 static void choosePaint(Component target, Graphics2D g, boolean paintOffscreen) { log.debug("Painting to target " + target + " , offscreen " + paintOffscreen); if (paintOffscreen) { ((Paintable) target).paintOffscreen(g, target.getBounds()); } else { target.paintAll(g); } }
private void hideDropDownButton() { for (Component component : this.getComponents()) { if (component instanceof AbstractButton && component.isVisible()) { component.setVisible(false); this.revalidate(); } } }
/** * Long operations need to display an hourglass. * * @param comp The <code>JComponent</code> on which to apply the hour glass cursor * @param on If true, we set the cursor on the hourglass */ public static void setCursorOnWait(Component comp, boolean on) { if (on) { if (comp instanceof AbstractEditorPanel) ((AbstractEditorPanel) comp).showWaitCursor(); else comp.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } else { if (comp instanceof AbstractEditorPanel) ((AbstractEditorPanel) comp).hideWaitCursor(); else comp.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }
public void paint(Graphics g) { if (comp != null) { width = comp.getWidth() / 6; height = comp.getHeight() * 2 / 3; } g.setColor(bgColor); g.fillRect(x, y, width, height); g.setColor(fgColor); g.setFont(font); g.drawString(strTray, x / 2 + width / 2, y + height + 10); super.paint(g); }
public static Frame getFrame(Component theComponent) { Component currParent = theComponent; Frame theFrame = null; while (currParent != null) { if (currParent instanceof Frame) { theFrame = (Frame) currParent; break; } currParent = currParent.getParent(); } return theFrame; }
/** * @param aContainer * @param aComponentClass * @return */ private static Component findComponent( final Container aContainer, final Class<? extends Component> aComponentClass) { Component result = null; final int cnt = aContainer.getComponentCount(); for (int i = 0; (result == null) && (i < cnt); i++) { final Component comp = aContainer.getComponent(i); if (aComponentClass.equals(comp.getClass())) { result = comp; } else if (comp instanceof Container) { result = findComponent((Container) comp, aComponentClass); } } return result; }
private static void exportScreenshotEpsGraphics( Component target, File selectedFile, boolean paintOffscreen) throws IOException { if (!SnapshotUtilities.canExportScreenshotEps()) { String msg = "ERROR: EPS output requires EPSGraphics library. See https://www.broadinstitute.org/software/igv/third_party_tools#epsgraphics"; log.error(msg); return; } Graphics2D g = null; FileOutputStream fos = null; try { Class colorModeClass = RuntimeUtils.loadClassForName(EPSColorModeClassName, null); Class graphicsClass = RuntimeUtils.loadClassForName(EPSClassName, null); Constructor constructor = graphicsClass.getConstructor( String.class, OutputStream.class, int.class, int.class, int.class, int.class, colorModeClass); Object colorModeValue = Enum.valueOf(colorModeClass, "COLOR_RGB"); // EpsGraphics stores directly in a file fos = new FileOutputStream(selectedFile); g = (Graphics2D) constructor.newInstance( "eps", fos, 0, 0, target.getWidth(), target.getHeight(), colorModeValue); choosePaint(target, g, paintOffscreen); graphicsClass.getMethod("close").invoke(g); } catch (Exception e) { log.error(e.getMessage(), e); } finally { if (fos != null) { fos.flush(); fos.close(); } } }
public void actionPerformed(ActionEvent evt) { Component parent = extensionButton.getParent(); while ((parent != null) && !(parent instanceof Frame)) parent = parent.getParent(); String newExtensions = JOptionPane.showInputDialog( parent, "Edit the extension list.\nSeparate extensions by commas.\n\n", filter.getExtensionString()); if ((newExtensions != null) && !newExtensions.trim().equals("")) { newExtensions = newExtensions.replaceAll("\\s", ""); filter.setExtensions(newExtensions); extensionButton.setText(filter.getDescription()); properties.setProperty("extensions", filter.getExtensionString()); directoryPane.reloadTree(); } }
/** * Load image from resource path (using getResource). Note that GIFs are loaded as _translucent_ * indexed images. Images are cached: loading an image with the same name twice will get the * cached image the second time. If you want to remove an image from the cache, use purgeImage. * Throws JGError when there was an error. */ @SuppressWarnings({"deprecation", "unchecked"}) public JGImage loadImage(String imgfile) { Image img = (Image) loadedimages.get(imgfile); if (img == null) { URL imgurl = getClass().getResource(imgfile); if (imgurl == null) { try { File imgf = new File(imgfile); if (imgf.canRead()) { imgurl = imgf.toURL(); } else { imgurl = new URL(imgfile); // throw new JGameError( // "File "+imgfile+" not found.",true); } } catch (MalformedURLException e) { // e.printStackTrace(); throw new JGameError("File not found or malformed path or URL '" + imgfile + "'.", true); } } img = output_comp.getToolkit().createImage(imgurl); loadedimages.put(imgfile, img); } try { ensureLoaded(img); } catch (Exception e) { // e.printStackTrace(); throw new JGameError("Error loading image " + imgfile); } return new JREImage(img); }
/** * Lays out the container. * * @param target The container which needs to be laid out. */ public void layoutContainer(Container target) { int count; Component component; Dimension dimension; synchronized (target.getTreeLock()) { count = target.getComponentCount(); for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getPreferredSize(); component.setSize(dimension.width, dimension.height); } } } }
public JGImage flip(boolean horiz, boolean vert) { @SuppressWarnings("unused") Image flipped = null; JGPoint size = getSize(); int[] buffer = getPixels(); int[] flipbuf = new int[size.x * size.y]; if (vert && !horiz) { for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { flipbuf[(size.y - y - 1) * size.x + x] = buffer[(y * size.x) + x]; } } } else if (horiz && !vert) { for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { flipbuf[y * size.x + (size.x - x - 1)] = buffer[(y * size.x) + x]; } } } else if (horiz && vert) { for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { flipbuf[(size.y - y - 1) * size.x + (size.x - x - 1)] = buffer[(y * size.x) + x]; } } } return new JREImage( output_comp.createImage(new MemoryImageSource(size.x, size.y, flipbuf, 0, size.x))); }
public JGImage crop(int x, int y, int width, int height) { @SuppressWarnings("unused") JGPoint size = getSize(); int[] buffer = getPixels(x, y, width, height); return new JREImage( output_comp.createImage(new MemoryImageSource(width, height, buffer, 0, width))); }
/** for angle, only increments of 90 are allowed */ public JGImage rotate(int angle) { @SuppressWarnings("unused") Image rot = null; JGPoint size = getSize(); int[] buffer = getPixels(); int[] rotate = new int[size.x * size.y]; int angletype = (angle / 90) & 3; if (angletype == 0) return this; if (angletype == 1) { /* 1 2 3 4 9 5 1 * 5 6 7 8 => a 6 2 * 9 a b c b 7 3 * c 8 4 */ for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { rotate[x * size.y + (size.y - 1 - y)] = buffer[(y * size.x) + x]; } } return new JREImage( output_comp.createImage(new MemoryImageSource(size.y, size.x, rotate, 0, size.y))); } if (angletype == 3) { /* 1 2 3 4 4 8 c * 5 6 7 8 => 3 7 b * 9 a b c 2 6 a * 1 5 9 */ for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { rotate[(size.x - x - 1) * size.y + y] = buffer[(y * size.x) + x]; } } return new JREImage( output_comp.createImage(new MemoryImageSource(size.y, size.x, rotate, 0, size.y))); } if (angletype == 2) { /* 1 2 3 4 c b a 9 * 5 6 7 8 => 8 7 6 5 * 9 a b c 4 3 2 1 */ for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { rotate[((size.y - y - 1) * size.x) + (size.x - x - 1)] = buffer[(y * size.x) + x]; } } } return new JREImage( output_comp.createImage(new MemoryImageSource(size.x, size.y, rotate, 0, size.x))); }
// These is some wierd problem such that sometimes, the vnmrj command // area gets the focus and these items in the login box do not get // the focus. Even clicking in these items does not bring focus to // them. Issuing requestFocus() does not bring focus to them. // I can however, determing if either the operator entry box or // the password box has focus and if neither does, I can unshow and // reshow the panel and that fixes the focus. So, I have added this // to the mouseClicked action. If neither has focus, it will // take focus with setVisible false then true. public void mouseClicked(MouseEvent e) { boolean pfocus = m_passwordField.hasFocus(); boolean ofocus = comboTextField.hasFocus(); if (!pfocus && !ofocus) { setVisible(false); setVisible(true); } }
protected void reflectPropertyChanges() { super.reflectPropertyChanges(); Component c; c = gui.getItemObj(GG_WARPMODDEPTH); if (c != null) { c.setEnabled(pr.bool[PR_WARPMOD]); } c = gui.getItemObj(GG_WARPENV); if (c != null) { c.setEnabled(pr.bool[PR_WARPMOD]); } c = gui.getItemObj(GG_OUTFREQ); if (c != null) { c.setEnabled(inRate != 0f); } }
/* * Create a BufferedImage for AWT components. * * @param component AWT component to create image from * @param fileName name of file to be created or null * @return image the image for the given region * @exception AWTException see Robot class constructors * @exception IOException if an error occurs during writing */ public static BufferedImage createImage(Component component, String fileName) throws AWTException, IOException { Point p = new Point(0, 0); SwingUtilities.convertPointToScreen(p, component); Rectangle region = component.getBounds(); region.x = p.x; region.y = p.y; return ScreenCapture.createImage(region, fileName); }
/** * Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using * the given alpha threshold and render-to-background colour, or display-compatible translucent * image. The alpha values in the image are set to either 0 (below threshold) or 255 (above * threshold). The render-to-background colour bg_col is used to determine how the pixels * overlapping transparent pixels should be rendered. The fast algorithm just sets the colour * behind the transparent pixels in the image (for bitmask source images); the slow algorithm * actually renders the image to a background of bg_col (for translucent sources). * * @param thresh alpha threshold between 0 and 255 * @param fast use fast algorithm (only set bg_col behind transp. pixels) * @param bitmask true=use bitmask, false=use translucent */ public JGImage toDisplayCompatible(int thresh, JGColor bg_col, boolean fast, boolean bitmask) { Color bgcol = new Color(bg_col.r, bg_col.g, bg_col.b); int bgcol_rgb = (bgcol.getRed() << 16) | (bgcol.getGreen() << 8) | bgcol.getBlue(); JGPoint size = getSize(); int[] buffer = getPixels(); // render image to bg depending on bgcol BufferedImage img_bg; if (bitmask) { img_bg = createCompatibleImage(size.x, size.y, Transparency.BITMASK); } else { img_bg = createCompatibleImage(size.x, size.y, Transparency.TRANSLUCENT); } int[] bg_buf; if (!fast) { Graphics g = img_bg.getGraphics(); g.setColor(bgcol); // the docs say I could use bgcol in the drawImage as an // equivalent to the following two lines, but this // doesn't handle translucency properly and is _slower_ g.fillRect(0, 0, size.x, size.y); g.drawImage(img, 0, 0, null); bg_buf = new JREImage(img_bg).getPixels(); } else { bg_buf = buffer; } // g.dispose(); // ColorModel rgb_bitmask = ColorModel.getRGBdefault(); // rgb_bitmask = new PackedColorModel( // rgb_bitmask.getColorSpace(),25,0xff0000,0x00ff00,0x0000ff, // 0x1000000, false, Transparency.BITMASK, DataBuffer.TYPE_INT); // ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean // isAlphaPremultiplied, int trans, int transferType) int[] thrsbuf = new int[size.x * size.y]; for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { if (((buffer[y * size.x + x] >> 24) & 0xff) >= thresh) { thrsbuf[y * size.x + x] = bg_buf[y * size.x + x] | (0xff << 24); } else { // explicitly set the colour of the transparent pixel. // This makes a difference when scaling! // thrsbuf[y*size.x+x]=bg_buf[y*size.x+x]&~(0xff<<24); thrsbuf[y * size.x + x] = bgcol_rgb; } } } return new JREImage( output_comp.createImage( new MemoryImageSource( size.x, size.y, // rgb_bitmask, img_bg.getColorModel(), // display compatible bitmask bitmask ? thrsbuf : bg_buf, 0, size.x))); }
/** * Adds default interactions to the specified component. * * @param comp component * @param win parent window */ public static void addInteraction(final Component comp, final Window win) { comp.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { focus(comp); } }); if (win instanceof BaseXDialog) { // add default keys final BaseXDialog d = (BaseXDialog) win; comp.addKeyListener( new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { final Object s = e.getSource(); if (s instanceof BaseXCombo && ((BaseXCombo) s).isPopupVisible()) return; // do not key close dialog if button or editor is focused if (ENTER.is(e) && !(s instanceof BaseXButton || s instanceof TextPanel)) { d.close(); } else if (ESCAPE.is(e)) { // do not cancel dialog if search bar is opened boolean close = true; if (s instanceof TextPanel) { final SearchBar bar = ((TextPanel) s).getSearch(); close = bar == null || !bar.deactivate(true); } if (close) d.cancel(); } } }); return; } if (win instanceof GUI) { comp.addKeyListener(globalShortcuts((GUI) win)); } else { throw Util.notExpected("Reference to main window expected."); } }
/** * Display a file chooser dialog box. * * @param owner <code>Component</code> which 'owns' the dialog * @param mode Can be either <code>OPEN</code>, <code>SCRIPT</code> or <code>SAVE</code> * @return The path to selected file, null otherwise */ public static String chooseFile(Component owner, int mode) { JFileChooser chooser = getFileChooser(owner, mode); chooser.setMultiSelectionEnabled(false); if (chooser.showDialog(owner, null) == JFileChooser.APPROVE_OPTION) { /*Jext*/ AbstractEditorPanel.setProperty( "lastdir." + mode, chooser.getSelectedFile().getParent()); return chooser.getSelectedFile().getAbsolutePath(); } else owner.repaint(); return null; }
/** * Calculates the preferred size dimensions for the specified panel given the components in the * specified parent container. * * @see #minimumLayoutSize * @param target The component to be laid out. * @return A size deemed suitable for laying out the container. */ public Dimension preferredLayoutSize(Container target) { int count; Container parent; Component component; Point point; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock()) { count = target.getComponentCount(); if (0 == count) { // be the same size unless we have a parent ret = target.getSize(); parent = target.getParent(); if (null != parent) { insets = parent.getInsets(); ret = parent.getSize(); ret.setSize( ret.width - insets.left - insets.right, ret.height - insets.top - insets.bottom); } } else { ret = new Dimension(0, 0); for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { point = component.getLocation(); dimension = component.getPreferredSize(); ret.width = Math.max(ret.width, point.x + dimension.width); ret.height = Math.max(ret.height, point.y + dimension.height); } } insets = target.getInsets(); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } } return (ret); }
protected void reflectPropertyChanges() { super.reflectPropertyChanges(); Component c; c = gui.getItemObj(GG_ENVINFILE); if (c != null) { c.setEnabled( (pr.intg[PR_ENVSOURCE] == SRC_ENVFILE) || (pr.intg[PR_ENVSOURCE] == SRC_SOUNDFILE)); } c = gui.getItemObj(GG_ENV); if (c != null) { c.setEnabled(pr.intg[PR_ENVSOURCE] == SRC_ENV); } c = gui.getItemObj(GG_RIGHTCHAN); if (c != null) { c.setEnabled(pr.intg[PR_ENVSOURCE] == SRC_ENV); } c = gui.getItemObj(GG_RIGHTCHANENV); if (c != null) { c.setEnabled((pr.intg[PR_ENVSOURCE] == SRC_ENV) && pr.bool[PR_RIGHTCHAN]); } // c = gui.getItemObj( GG_AVERAGE ); // if( c != null ) { // c.setEnabled( (pr.intg[ PR_ENVSOURCE ] == SRC_INPUT) || // (pr.intg[ PR_ENVSOURCE ] == SRC_SOUNDFILE) ); // } c = gui.getItemObj(GG_ENVOUTFILE); if (c != null) { c.setEnabled(pr.bool[PR_ENVOUTPUT]); } }
/** * Convenience method for searching above the given component in the component hierarchy and * returns the first object of the given type it finds, or <code>null</code> if no such parent was * found. * * <p>The reason this method exists is for tidyness of the calling code, as no longer a explicit * cast is needed. * * @param aType the type of the parent to find, cannot be <code>null</code>; * @param aComponent the component to search in the hierarchy, cannot be <code>null</code>. * @return the requested ancestor, or <code>null</code> if not found. * @see SwingUtilities#getAncestorOfClass(Class, Component) */ @SuppressWarnings("unchecked") public static <T> T getAncestorOfClass(final Class<T> aType, final Component aComponent) { if ((aComponent == null) || (aType == null)) { return null; } Container parent = aComponent.getParent(); while ((parent != null) && !(aType.isInstance(parent))) { parent = parent.getParent(); } return (T) parent; }
public void write(Writer out, Document doc, int pos, int len, Map<String, String> copiedImgs) throws IOException, BadLocationException { Debug.log(9, "SikuliEditorKit.write %d %d", pos, len); DefaultStyledDocument sdoc = (DefaultStyledDocument) doc; int i = pos; String absPath; while (i < pos + len) { Element e = sdoc.getCharacterElement(i); int start = e.getStartOffset(), end = e.getEndOffset(); if (e.getName().equals(StyleConstants.ComponentElementName)) { // A image argument to be filled AttributeSet attr = e.getAttributes(); Component com = StyleConstants.getComponent(attr); out.write(com.toString()); if (copiedImgs != null && (com instanceof EditorPatternButton || com instanceof EditorPatternLabel)) { if (com instanceof EditorPatternButton) { absPath = ((EditorPatternButton) com).getFilename(); } else { absPath = ((EditorPatternLabel) com).getFile(); } String fname = (new File(absPath)).getName(); copiedImgs.put(fname, absPath); Debug.log(3, "save image for copy&paste: " + fname + " -> " + absPath); } } else { if (start < pos) { start = pos; } if (end > pos + len) { end = pos + len; } out.write(doc.getText(start, end - start)); } i = end; } out.close(); }
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (image != null && showimage) { // TODO: add ability to scale maintaining aspect ratio fitting to size of parent // TODO: Need to add not zoom all the way, but zoom to a box of aspect ratio 4/3 Graphics2D g2 = (Graphics2D) g; AffineTransform tran = new AffineTransform(1f, 0f, 0f, 1f, 0, 0); float widthscale = (float) c.getWidth() / image.getWidth(); float heightscale = (float) c.getHeight() / image.getHeight(); switch (drawmode) { case DRAW_MODE_ASPECT: float scale; if (widthscale < heightscale) { scale = widthscale; } else { scale = heightscale; } tran.scale(scale, scale); g2.drawImage( image, new AffineTransformOp(tran, AffineTransformOp.TYPE_BILINEAR), (int) (c.getWidth() - image.getWidth() * scale) / 2, (int) (c.getHeight() - image.getHeight() * scale) / 2); break; case DRAW_MODE_WIDTH: tran.scale(widthscale, widthscale); g2.drawImage(image, tran, null); break; case DRAW_MODE_HEIGHT: tran.scale(heightscale, heightscale); g2.drawImage(image, tran, null); break; default: tran.scale(widthscale, heightscale); g2.drawImage(image, tran, null); break; } } }
public boolean actionControlReceived(Action action) { String actionName = action.getName(); boolean ret = false; if (actionName.equals("GetPower") == true) { String state = getPowerState(); Argument powerArg = action.getArgument("Power"); powerArg.setValue(state); ret = true; } if (actionName.equals("SetPower") == true) { Argument powerArg = action.getArgument("Power"); String state = powerArg.getValue(); setPowerState(state); state = getPowerState(); Argument resultArg = action.getArgument("Result"); resultArg.setValue(state); ret = true; } comp.repaint(); return ret; }