/** * Adds the specified component to the container. * * @param c The component to add. */ private void addComponent(JComponent c) { Container container = window.getContentPane(); Component[] comps = container.getComponents(); boolean in = false; for (int i = 0; i < comps.length; i++) { if (comps[i].equals(c)) { in = true; break; } } if (!in) { container.add(c, BorderLayout.CENTER); window.repaint(); } }
/** Creates and sets the window and its content's borders. */ void makeBorders(int increment) { JRootPane rootPane = window.getRootPane(); rootPane.setBorder(BorderFactory.createLineBorder(BORDER_COLOR, BORDER_THICKNESS + increment)); if (canvas != null) { canvas.setBorder( BorderFactory.createBevelBorder( BevelBorder.LOWERED, INNER_BORDER_HIGHLIGHT, INNER_BORDER_SHADOW)); } }
/** * Sets the image to paint if the canvas is an instance of <code>ThumbnailCanvas</code>. * * @param image The image to paint. */ void setImage(BufferedImage image) { if (canvas instanceof ThumbnailCanvas) { makeComponentsSize(image.getWidth(), image.getHeight()); ((ThumbnailCanvas) canvas).setImage(image); // window.getContentPane().removeAll(); // buildUI(); window.pack(); } }
/** Repaints the window according to whether the window is currently collapsed or expanded. */ void updateCollapsedState() { SizeButton button = (SizeButton) titleBar.getButton(TitleBar.SIZE_BUTTON); if (window.isCollapsed()) { removeComponent(canvas); Dimension d = new Dimension(window.getWidth(), TitleBar.HEIGHT + 2 * BORDER_THICKNESS); titleBar.setPreferredSize(d); button.setActionType(SizeButton.EXPAND); window.setSize(d.width, d.height); } else { addComponent(canvas); button.setActionType(SizeButton.COLLAPSE); Dimension dT = titleBar.getPreferredSize(); Dimension dW = window.getRestoreSize(); window.setSize(dT.width, dW.height); } window.validate(); window.repaint(); }
/** * Sets the node's decoration. * * @param l The collection of <code>component</code>s to add to the <code>TitleBar</code>. */ void setDecoration(List l) { if (titleBar == null) return; titleBar.setDecoration(l, window.getButtonIndex()); }
/** Hides and disposes depending on the state of the window. */ void updateClosedState() { if (window.isClosed()) { window.setVisible(false); window.dispose(); } }
/** Updates and repaints the title bar. */ void updateTitleBar() { titleBar.update(window.getTitle()); }
/** * Sets the window and initializes the title bar. * * @param window The window to set. */ private void initialize(TinyDialog window) { if (window == null) throw new NullPointerException("No window."); this.window = window; titleBar = new TitleBar(window.getTitle(), window.getButtonIndex()); }
/** * Removes the specified component from the container. * * @param c The component to remove. */ private void removeComponent(JComponent c) { window.getContentPane().remove(c); }
/** Builds and lays out the UI. */ private void buildUI() { Container container = window.getContentPane(); container.add(titleBar, BorderLayout.NORTH); if (canvas != null) container.add(canvas, BorderLayout.CENTER); }