/** * 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); }
public Dimension getAvailableSize() { Dimension availableSize = getSize(); if (!cc.opts.fullScreen) { Insets vpInsets = VncViewer.insets; availableSize.width -= vpInsets.left + vpInsets.right; availableSize.height -= vpInsets.top + vpInsets.bottom; } if (tb.isVisible()) availableSize.height -= tb.getHeight(); if (availableSize.width < 0) availableSize.width = 0; if (availableSize.height < 0) availableSize.height = 0; return availableSize; }
public void reshape(int x, int y, int w, int h) { if (inEditMode) { defLoc.x = x; defLoc.y = y; defDim.width = w; defDim.height = h; } curLoc.x = x; curLoc.y = y; curDim.width = w; curDim.height = h; super.reshape(x, y, w, h); }
/** Is called when the applet wants to be resized. */ @Override public void appletResize(int width, int height) { currentAppletSize.width = width; currentAppletSize.height = height; final Dimension currentSize = new Dimension(currentAppletSize.width, currentAppletSize.height); if (loader != null) { AppContext appCtxt = loader.getAppContext(); if (appCtxt != null) appEvtQ = (java.awt.EventQueue) appCtxt.get(AppContext.EVENT_QUEUE_KEY); } final AppletPanel ap = this; if (appEvtQ != null) { appEvtQ.postEvent( new InvocationEvent( Toolkit.getDefaultToolkit(), new Runnable() { @Override public void run() { if (ap != null) { ap.dispatchAppletEvent(APPLET_RESIZE, currentSize); } } })); } }
public HeaderPanel(String heading) { super(); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.setBackground(background); JLabel panelLabel = new JLabel(" " + heading, SwingConstants.LEFT); Font labelFont = new Font("Dialog", Font.BOLD, 18); panelLabel.setFont(labelFont); this.add(panelLabel); this.add(Box.createHorizontalGlue()); refresh = new JButton("Refresh"); refresh.addActionListener(this); this.add(refresh); this.add(Box.createHorizontalStrut(5)); root = new JComboBox(); Dimension d = root.getPreferredSize(); d.width = 90; root.setPreferredSize(d); root.setMaximumSize(d); File[] roots = directoryPane.getRoots(); for (int i = 0; i < roots.length; i++) root.addItem(roots[i].getAbsolutePath()); this.add(root); root.setSelectedIndex(directoryPane.getCurrentRootIndex()); root.addActionListener(this); this.add(Box.createHorizontalStrut(17)); }
public void reshape(int x, int y, int w, int h) { if (inEditMode) { defLoc.x = x; defLoc.y = y; defDim.width = w; defDim.height = h; } curLoc.x = x; curLoc.y = y; curDim.width = w; curDim.height = h; if (!inEditMode) { if ((h != nHeight) || (h < rHeight)) { adjustFont(w, h); } } super.reshape(x, y, w, h); }
protected void checkMinimumSize() { Dimension d = getDrawingSize(); if (fViewSize.height < d.height || fViewSize.width < d.width) { fViewSize.height = d.height + SCROLL_OFFSET; fViewSize.width = d.width + SCROLL_OFFSET; setSize(fViewSize); } }
/** * Return the size of the area occupied by the contained figures inside the drawing. This method * is called by checkMinimumSize(). */ protected Dimension getDrawingSize() { FigureEnumeration fe = drawing().figures(); Dimension d = new Dimension(0, 0); while (fe.hasNextFigure()) { Rectangle r = fe.nextFigure().displayBox(); d.width = Math.max(d.width, r.x + r.width); d.height = Math.max(d.height, r.y + r.height); } return d; }
public void setSizeRatio(double x, double y) { xRatio = x; yRatio = y; if (x > 1.0) xRatio = x - 1.0; if (y > 1.0) yRatio = y - 1.0; if (defDim.width <= 0) defDim = getPreferredSize(); curLoc.x = (int) ((double) defLoc.x * xRatio); curLoc.y = (int) ((double) defLoc.y * yRatio); curDim.width = (int) ((double) defDim.width * xRatio); curDim.height = (int) ((double) defDim.height * yRatio); if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height); }
/** * 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); }
public void setEditMode(boolean s) { twin.setEditMode(s); setOpaque(s); if (s) { addMouseListener(ml); curLoc.x = defLoc.x; curLoc.y = defLoc.y; defDim = getPreferredSize(); curDim.width = defDim.width; curDim.height = defDim.height; } else removeMouseListener(ml); inEditMode = s; }
public void setSizeRatio(double x, double y) { double rx = x; double ry = y; if (rx > 1.0) rx = x - 1.0; if (ry > 1.0) ry = y - 1.0; if (defDim.width <= 0) defDim = getPreferredSize(); curLoc.x = (int) ((double) defLoc.x * rx); curLoc.y = (int) ((double) defLoc.y * ry); curDim.width = (int) ((double) defDim.width * rx); curDim.height = (int) ((double) defDim.height * ry); if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height); twin.setSizeRatio(x, y); }
/** Construct an applet viewer and start the applet. */ public void init() { try { // Get the width (if any) defaultAppletSize.width = getWidth(); currentAppletSize.width = defaultAppletSize.width; // Get the height (if any) defaultAppletSize.height = getHeight(); currentAppletSize.height = defaultAppletSize.height; } catch (NumberFormatException e) { // Turn on the error flag and let TagAppletPanel // do the right thing. status = APPLET_ERROR; showAppletStatus("badattribute.exception"); showAppletLog("badattribute.exception"); showAppletException(e); } setLayout(new BorderLayout()); createAppletThread(); }
/** * Reads an image from an archived file and return it as ByteBuffer object. * * @author Mike Butler, Kiet Le */ private ByteBuffer readImage(String filename, Dimension dim) { if (dim == null) dim = new Dimension(0, 0); ByteBuffer bytes = null; try { DataInputStream dis = new DataInputStream(getClass().getClassLoader().getResourceAsStream(filename)); dim.width = dis.readInt(); dim.height = dis.readInt(); System.out.println("Creating buffer, width: " + dim.width + " height: " + dim.height); // byte[] buf = new byte[3 * dim.height * dim.width]; bytes = BufferUtil.newByteBuffer(3 * dim.width * dim.height); for (int i = 0; i < bytes.capacity(); i++) { bytes.put(dis.readByte()); } dis.close(); } catch (Exception e) { e.printStackTrace(); } bytes.rewind(); return bytes; }
public void setEditMode(boolean s) { if (s) { addMouseListener(ml); setOpaque(s); if (font != null) { setFont(font); fontH = font.getSize(); rHeight = fontH; } defDim = getPreferredSize(); curLoc.x = defLoc.x; curLoc.y = defLoc.y; curDim.width = defDim.width; curDim.height = defDim.height; xRatio = 1.0; yRatio = 1.0; } else { removeMouseListener(ml); if ((bg != null) || (isActive < 1)) setOpaque(true); else setOpaque(false); } inEditMode = s; }
/** * Lays out the container. * * @param target The container which needs to be laid out. */ public void layoutContainer(Container target) { Insets insets; int x; int y; int count; int width; Component component; Dimension dimension; synchronized (target.getTreeLock()) { insets = target.getInsets(); x = insets.left; y = insets.top; count = target.getComponentCount(); width = 0; for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getPreferredSize(); width = Math.max(width, dimension.width); component.setSize(dimension.width, dimension.height); component.setLocation(x, y); y += dimension.height; } } // now set them all to the same width for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getSize(); dimension.width = width; component.setSize(dimension.width, dimension.height); } } } }
/** * Open the config dialog, send the config update to the robot, save it for future, and refresh * the preview tab. */ public void UpdateConfig() { final JDialog driver = new JDialog(mainframe, "Configure Limits", true); driver.setLayout(new GridBagLayout()); final JTextField mtop = new JTextField(String.valueOf(limit_top)); final JTextField mbottom = new JTextField(String.valueOf(limit_bottom)); final JTextField mleft = new JTextField(String.valueOf(limit_left)); final JTextField mright = new JTextField(String.valueOf(limit_right)); final JTextField ptop = new JTextField(String.valueOf(paper_top)); final JTextField pbottom = new JTextField(String.valueOf(paper_bottom)); final JTextField pleft = new JTextField(String.valueOf(paper_left)); final JTextField pright = new JTextField(String.valueOf(paper_right)); final JButton cancel = new JButton("Cancel"); final JButton save = new JButton("Save"); GridBagConstraints c = new GridBagConstraints(); c.gridx = 3; c.gridy = 0; driver.add(mtop, c); c.gridx = 3; c.gridy = 5; driver.add(mbottom, c); c.gridx = 0; c.gridy = 3; driver.add(mleft, c); c.gridx = 5; c.gridy = 3; driver.add(mright, c); c.gridx = 3; c.gridy = 1; driver.add(ptop, c); c.gridx = 3; c.gridy = 4; driver.add(pbottom, c); c.gridx = 1; c.gridy = 3; driver.add(pleft, c); c.gridx = 4; c.gridy = 3; driver.add(pright, c); c.gridx = 4; c.gridy = 6; driver.add(save, c); c.gridx = 5; c.gridy = 6; driver.add(cancel, c); Dimension s = ptop.getPreferredSize(); s.width = 80; ptop.setPreferredSize(s); pbottom.setPreferredSize(s); pleft.setPreferredSize(s); pright.setPreferredSize(s); mtop.setPreferredSize(s); mbottom.setPreferredSize(s); mleft.setPreferredSize(s); mright.setPreferredSize(s); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == save) { paper_top = Float.valueOf(ptop.getText()); paper_bottom = Float.valueOf(pbottom.getText()); paper_right = Float.valueOf(pright.getText()); paper_left = Float.valueOf(pleft.getText()); limit_top = Float.valueOf(mtop.getText()); limit_bottom = Float.valueOf(mbottom.getText()); limit_right = Float.valueOf(mright.getText()); limit_left = Float.valueOf(mleft.getText()); previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right); previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right); SetRecentPaperSize(); SaveConfig(); SendConfig(); driver.dispose(); } if (subject == cancel) { driver.dispose(); } } }; save.addActionListener(driveButtons); cancel.addActionListener(driveButtons); SendLineToRobot("M114"); // "where" command driver.pack(); driver.setVisible(true); }
// // Build installer window // public static void showInstallerWindow() { _installerFrame = new JFrame(Config.getWindowTitle()); Container cont = _installerFrame.getContentPane(); cont.setLayout(new BorderLayout()); // North pane Box topPane = new Box(BoxLayout.X_AXIS); JLabel title = new JLabel(Config.getWindowHeading()); Font titleFont = new Font("SansSerif", Font.BOLD, 22); title.setFont(titleFont); title.setForeground(Color.black); // Create Sun logo URL urlLogo = Main.class.getResource(Config.getWindowLogo()); Image img = Toolkit.getDefaultToolkit().getImage(urlLogo); MediaTracker md = new MediaTracker(_installerFrame); md.addImage(img, 0); try { md.waitForAll(); } catch (Exception ioe) { Config.trace(ioe.toString()); } if (md.isErrorID(0)) Config.trace("Error loading image"); Icon sunLogo = new ImageIcon(img); JLabel logoLabel = new JLabel(sunLogo); logoLabel.setOpaque(true); topPane.add(topPane.createHorizontalStrut(5)); topPane.add(title); topPane.add(topPane.createHorizontalGlue()); topPane.add(logoLabel); topPane.add(topPane.createHorizontalStrut(5)); // West Pane Box westPane = new Box(BoxLayout.X_AXIS); westPane.add(westPane.createHorizontalStrut(10)); // South Pane Box bottomPane = new Box(BoxLayout.X_AXIS); bottomPane.add(bottomPane.createHorizontalGlue()); JButton abortButton = new JButton(Config.getWindowAbortButton()); abortButton.setMnemonic(Config.getWindowAbortMnemonic()); bottomPane.add(abortButton); bottomPane.add(bottomPane.createHorizontalGlue()); bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); // Center Pane Box centerPane = new Box(BoxLayout.Y_AXIS); JLabel hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); _stepLabels = new JLabel[5]; for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i] = new JLabel(Config.getWindowStep(i)); _stepLabels[i].setEnabled(false); centerPane.add(_stepLabels[i]); // install label's length will expand,so set a longer size. if (i == STEP_INSTALL) { Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize(); _stepLabels[i].setPreferredSize(dim); } } hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); // Setup box layout cont.add(topPane, "North"); cont.add(westPane, "West"); cont.add(bottomPane, "South"); cont.add(centerPane, "Center"); _installerFrame.pack(); Dimension dim = _installerFrame.getSize(); // hard code to ensure title is completely visible on Sol/lin. if (dim.width < 400) { dim.width = 400; _installerFrame.setSize(dim); } Rectangle size = _installerFrame.getBounds(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); size.width = Math.min(screenSize.width, size.width); size.height = Math.min(screenSize.height, size.height); // Put window at 1/4, 1/4 of screen resoluion _installerFrame.setBounds( (screenSize.width - size.width) / 4, (screenSize.height - size.height) / 4, size.width, size.height); // Setup event listners _installerFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { installFailed("Window closed", null); } }); abortButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { installFailed("Abort pressed", null); } }); // Show window _installerFrame.show(); }
@Override public void setBounds(int x, int y, int width, int height) { super.setBounds(x, y, width, height); currentAppletSize.width = width; currentAppletSize.height = height; }
/** Constructor (create and layout page) */ public SOAPMonitorPage(String host_name) { host = host_name; // Set up default filter (show all messages) filter = new SOAPMonitorFilter(); // Use borders to help improve appearance etched_border = new EtchedBorder(); // Build top portion of split (list panel) model = new SOAPMonitorTableModel(); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionInterval(0, 0); table.setPreferredScrollableViewportSize(new Dimension(600, 96)); table.getSelectionModel().addListSelectionListener(this); scroll = new JScrollPane(table); remove_button = new JButton("Remove"); remove_button.addActionListener(this); remove_button.setEnabled(false); remove_all_button = new JButton("Remove All"); remove_all_button.addActionListener(this); filter_button = new JButton("Filter ..."); filter_button.addActionListener(this); list_buttons = new JPanel(); list_buttons.setLayout(new FlowLayout()); list_buttons.add(remove_button); list_buttons.add(remove_all_button); list_buttons.add(filter_button); list_panel = new JPanel(); list_panel.setLayout(new BorderLayout()); list_panel.add(scroll, BorderLayout.CENTER); list_panel.add(list_buttons, BorderLayout.SOUTH); list_panel.setBorder(empty_border); // Build bottom portion of split (message details) details_time = new JLabel("Time: ", SwingConstants.RIGHT); details_target = new JLabel("Target Service: ", SwingConstants.RIGHT); details_status = new JLabel("Status: ", SwingConstants.RIGHT); details_time_value = new JLabel(); details_target_value = new JLabel(); details_status_value = new JLabel(); Dimension preferred_size = details_time.getPreferredSize(); preferred_size.width = 1; details_time.setPreferredSize(preferred_size); details_target.setPreferredSize(preferred_size); details_status.setPreferredSize(preferred_size); details_time_value.setPreferredSize(preferred_size); details_target_value.setPreferredSize(preferred_size); details_status_value.setPreferredSize(preferred_size); details_header = new JPanel(); details_header_layout = new GridBagLayout(); details_header.setLayout(details_header_layout); details_header_constraints = new GridBagConstraints(); details_header_constraints.fill = GridBagConstraints.BOTH; details_header_constraints.weightx = 0.5; details_header_layout.setConstraints(details_time, details_header_constraints); details_header.add(details_time); details_header_layout.setConstraints(details_time_value, details_header_constraints); details_header.add(details_time_value); details_header_layout.setConstraints(details_target, details_header_constraints); details_header.add(details_target); details_header_constraints.weightx = 1.0; details_header_layout.setConstraints(details_target_value, details_header_constraints); details_header.add(details_target_value); details_header_constraints.weightx = .5; details_header_layout.setConstraints(details_status, details_header_constraints); details_header.add(details_status); details_header_layout.setConstraints(details_status_value, details_header_constraints); details_header.add(details_status_value); details_header.setBorder(etched_border); request_label = new JLabel("SOAP Request", SwingConstants.CENTER); request_text = new SOAPMonitorTextArea(); request_text.setEditable(false); request_scroll = new JScrollPane(request_text); request_panel = new JPanel(); request_panel.setLayout(new BorderLayout()); request_panel.add(request_label, BorderLayout.NORTH); request_panel.add(request_scroll, BorderLayout.CENTER); response_label = new JLabel("SOAP Response", SwingConstants.CENTER); response_text = new SOAPMonitorTextArea(); response_text.setEditable(false); response_scroll = new JScrollPane(response_text); response_panel = new JPanel(); response_panel.setLayout(new BorderLayout()); response_panel.add(response_label, BorderLayout.NORTH); response_panel.add(response_scroll, BorderLayout.CENTER); details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); details_soap.setTopComponent(request_panel); details_soap.setRightComponent(response_panel); details_soap.setResizeWeight(.5); details_panel = new JPanel(); layout_button = new JButton("Switch Layout"); layout_button.addActionListener(this); reflow_xml = new JCheckBox("Reflow XML text"); reflow_xml.addActionListener(this); details_buttons = new JPanel(); details_buttons.setLayout(new FlowLayout()); details_buttons.add(reflow_xml); details_buttons.add(layout_button); details_panel.setLayout(new BorderLayout()); details_panel.add(details_header, BorderLayout.NORTH); details_panel.add(details_soap, BorderLayout.CENTER); details_panel.add(details_buttons, BorderLayout.SOUTH); details_panel.setBorder(empty_border); // Add the two parts to the age split pane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setTopComponent(list_panel); split.setRightComponent(details_panel); // Build status area start_button = new JButton("Start"); start_button.addActionListener(this); stop_button = new JButton("Stop"); stop_button.addActionListener(this); status_buttons = new JPanel(); status_buttons.setLayout(new FlowLayout()); status_buttons.add(start_button); status_buttons.add(stop_button); status_text = new JLabel(); status_text.setBorder(new BevelBorder(BevelBorder.LOWERED)); status_text_panel = new JPanel(); status_text_panel.setLayout(new BorderLayout()); status_text_panel.add(status_text, BorderLayout.CENTER); status_text_panel.setBorder(empty_border); status_area = new JPanel(); status_area.setLayout(new BorderLayout()); status_area.add(status_buttons, BorderLayout.WEST); status_area.add(status_text_panel, BorderLayout.CENTER); status_area.setBorder(etched_border); // Add the split and status area to page setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); add(status_area, BorderLayout.SOUTH); }