Unnamed: 0
int64
0
2.05k
func
stringlengths
27
124k
target
bool
2 classes
project
stringlengths
39
117
100
public class FlatScrollBarUI extends BasicScrollBarUI { private Color foreground, background; public FlatScrollBarUI (Color fg, Color bg) { this.thumbColor = fg; this.thumbDarkShadowColor = fg; this.thumbHighlightColor = fg; this.thumbLightShadowColor = fg; this.trackColor = bg; foreground = fg; background = bg; } @Override protected void paintDecreaseHighlight(Graphics g) { } @Override protected void paintIncreaseHighlight(Graphics g) { } @Override protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { Graphics2D g2 = (Graphics2D) g; g2.setColor(foreground); g2.fill(thumbBounds); if (c instanceof JScrollBar) { int orientation = ((JScrollBar) c).getOrientation(); g2.setColor(background); // Center position int x = (thumbBounds.x)+ thumbBounds.width / 2; int y = (thumbBounds.y) + thumbBounds.height / 2; int w = thumbBounds.width / 4; int h = thumbBounds.height / 4; for (int i = -2; i <= 2; i += 2) { switch (orientation) { case JScrollBar.VERTICAL: g2.drawLine(x-w, y+i, x+w, y+i); break; case JScrollBar.HORIZONTAL: g2.drawLine(x+i, y-h, x+i, y+h); break; } } } } @Override protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { Graphics2D g2 = (Graphics2D) g; g2.setColor(background); g2.fill(trackBounds); g2.setColor(foreground); g2.draw(trackBounds); } @Override protected JButton createDecreaseButton(int orientation) { JButton b = new BasicArrowButton(orientation, background, foreground, foreground, foreground); b.setBorder(BorderFactory.createLineBorder(foreground, 1)); return b; } @Override protected JButton createIncreaseButton(int orientation) { // TODO Auto-generated method stub //return super.createIncreaseButton(orientation); JButton b = new BasicArrowButton(orientation, background, foreground, foreground, foreground); b.setBorder(BorderFactory.createLineBorder(foreground, 1)); return b; } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_FlatScrollBarUI.java
101
@SuppressWarnings("serial") public class Panel extends JPanel implements SelectionProvider, NamingContext { private static Color DEFAULT_COLOR = Color.LIGHT_GRAY; private static Insets TITLE_INSETS = new Insets(0, 5, 0, 0); private static final Logger LOGGER = LoggerFactory.getLogger(Panel.class); private JPanel titlePanel; private JLabel titleLabel; private JComponent titleManifestation; private final Rectangle titleBounds = new Rectangle(); // Bounds relative to the containing canvas manifestation private View wrappedManifestation; private PanelBorder panelBorder; private int panelId; private PanelFocusSelectionProvider panelSelectionProvider; private JScrollPane scrollPane; private boolean hasTitle; private final Rectangle iconBounds = new Rectangle(); // Bounds relative to the containing canvas manifestation private JComponent icon; private JPanel statusBar; private JLabel STALE_LABEL = new JLabel("*STALE*"); @SuppressWarnings("unused") // Used to register to the wrappedManifestation. private final PropertyChangeListener objectStaleListener = new PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { STALE_LABEL.setVisible((Boolean) evt.getNewValue()); } }; public Panel(View manifestation, PanelFocusSelectionProvider panelSelectionProvider) { this(manifestation, -1, panelSelectionProvider); } public Panel(View manifestation, int panelId, PanelFocusSelectionProvider panelSelectionProvider) { setLayout(new BorderLayout()); assert CanvasManifestation.getManifestationInfo(manifestation) != null : "manifestation info must be added"; this.wrappedManifestation = manifestation; this.panelId = panelId; this.panelSelectionProvider = panelSelectionProvider; setBorder(BorderFactory.createLineBorder(DEFAULT_COLOR, 1)); init(); manifestation.setAutoscrolls(true); scrollPane = new JScrollPane(manifestation, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setBorder(BorderFactory.createEmptyBorder()); add(scrollPane, BorderLayout.CENTER); add(titlePanel, BorderLayout.NORTH); hideTitle(CanvasManifestation.getManifestationInfo(wrappedManifestation).hasTitlePanel()); statusBar = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); add(statusBar, BorderLayout.SOUTH); statusBar.add(STALE_LABEL); statusBar.setOpaque(false); STALE_LABEL.setForeground(Color.red); STALE_LABEL.setVisible(false); addStatusWidgetsIfApplicable(); this.wrappedManifestation.getSelectionProvider().addSelectionChangeListener(selectionListener); } public void setScrollColor(Color scrollColor, Color bgColor) { scrollPane.getHorizontalScrollBar().setUI( new FlatScrollBarUI(scrollColor,bgColor) ); scrollPane.getVerticalScrollBar().setUI( new FlatScrollBarUI(scrollColor,bgColor) ); scrollPane.setBackground(bgColor); } public void setTitleBarColor(Color background, Color foreground) { if (background != null) { titlePanel.setBackground(background); titleManifestation.setBackground(background); } if (foreground != null) { titleLabel.setForeground(foreground); titleManifestation.setForeground(foreground); //...manifestation may not use this } } public void setDefaultBorderColor(Color borderColor) { panelBorder.setDefaultBorderColor(borderColor); } private void addStatusWidgetsIfApplicable() { List<? extends JComponent> statusWidgets = wrappedManifestation.getStatusWidgets(); if (!statusWidgets.isEmpty()) { for (JComponent widget : statusWidgets) { statusBar.add(widget); } } } private void setupTitlePanel() { MCTViewManifestationInfo manifestationInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); AbstractComponent wrappedComponent = wrappedManifestation.getManifestedComponent(); icon = new TransferableIcon(wrappedComponent, new TransferableIcon.ViewTransferCallback() { @Override public List<View> getViewsToTransfer() { return Collections.singletonList(getWrappedManifestation()); } }); titleLabel = new JLabel(); titleLabel.setOpaque(false); titlePanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.weightx = .01; titlePanel.add(icon); titleManifestation = wrappedComponent.getViewInfos(ViewType.TITLE).iterator().next().createView(wrappedComponent); titleManifestation.setBackground(DEFAULT_COLOR); titlePanel.setBackground(DEFAULT_COLOR); setTitleFromManifestation(manifestationInfo); } private void init() { MCTViewManifestationInfo manifestationInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); byte border = PanelBorder.ALL_BORDERS; String borderStr = manifestationInfo.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); if (borderStr != null) { border = Byte.parseByte(borderStr); } int borderStyle = manifestationInfo.getBorderStyle(); Color borderColor = manifestationInfo.getBorderColor(); this.panelBorder = new PanelBorder(border); panelBorder.setBorderStyle(borderStyle); panelBorder.setBorderColor(borderColor); setBorder(this.panelBorder); setupTitlePanel(); } public Rectangle marshalBound(Rectangle origBound) { Container c = getParent(); if (c != null) { LayoutManager layoutManager = c.getLayout(); assert layoutManager instanceof CanvasLayoutManager; origBound = CanvasLayoutManager.class.cast(layoutManager).marshalLocation(origBound); } return origBound; } @Override public void setBounds(int x, int y, int width, int height) { super.setBounds(x, y, width, height); revalidate(); MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setStartPoint(new Point(x, y)); manifestInfo.setDimension(new Dimension(width, height)); } @Override public void setBounds(Rectangle r) { super.setBounds(r); revalidate(); MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setStartPoint(r.getLocation()); manifestInfo.setDimension(r.getSize()); } public void setTitleBounds() { if (titlePanel.getParent() == this && titlePanel.isVisible()) { titleBounds.setLocation(getX() + titlePanel.getX(), getY() + titlePanel.getY()); titleBounds.setSize(titlePanel.getWidth(), titlePanel.getHeight()); iconBounds.setLocation(getX() + icon.getX() + titlePanel.getX(), getY() + icon.getY() + titlePanel.getY()); iconBounds.setSize(icon.getWidth(), icon.getHeight()); } else { titleBounds.setLocation(0, 0); titleBounds.setSize(0, 0); iconBounds.setLocation(0, 0); iconBounds.setSize(0, 0); } } public void setId(int panelId) { this.panelId = panelId; } public int getId() { assert panelId > 0 : "Panel ID must be set."; return panelId; } public void addPanelBorder(byte newBorderState) { this.panelBorder.addBorderState(newBorderState); MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.addInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY, String.valueOf(this.panelBorder.getBorders())); setBorder(null); setBorder(panelBorder); // We need to reset the border so that the border will repaint. } public void removePanelBorder(byte removeBorderState) { this.panelBorder.removeBorderState(removeBorderState); MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.addInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY, String.valueOf(this.panelBorder.getBorders())); setBorder(null); setBorder(panelBorder); // We need to reset the border so that the bord } public void setBorderStyle(int borderStyle) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setBorderStyle(borderStyle); this.panelBorder.setBorderStyle(borderStyle); setBorder(null); setBorder(panelBorder); // We need to reset the border so that the bord } public byte getBorderState() { return this.panelBorder.getBorders(); } public int getBorderStyle() { return this.panelBorder.getBorderStyle(); } public void setBorderColor(Color borderColor) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setBorderColor(borderColor); this.panelBorder.setBorderColor(borderColor); setBorder(null); setBorder(panelBorder); } public Color getBorderColor() { return this.panelBorder.getBorderColor(); } public View getWrappedManifestation() { return wrappedManifestation; } public boolean containsPoint(Point p) { Point locationOnScreen = getLocationOnScreen(); return (p.x >= locationOnScreen.x) && (p.x < locationOnScreen.x + getWidth()) && (p.y >= locationOnScreen.y) && (p.y < locationOnScreen.y + getHeight()); } public View changeToView(ViewInfo view, MCTViewManifestationInfo newInfo) { AbstractComponent comp = wrappedManifestation.getManifestedComponent(); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(wrappedManifestation); // Compare the list of owned view properties and determine if a new view needs to be created. if (viewChanged(wrappedManifestation.getInfo(), info, newInfo)) { View manifestation = CanvasViewStrategy.CANVAS_OWNED.createViewFromManifestInfo(view, comp, ((View) panelSelectionProvider).getManifestedComponent(), info); attachManifestationToPanel(manifestation); addStatusWidgetsIfApplicable(); return manifestation; } return wrappedManifestation; } public View changeToView(ViewInfo view) { AbstractComponent comp = wrappedManifestation.getManifestedComponent(); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(wrappedManifestation); View manifestation = CanvasViewStrategy.CANVAS_OWNED.createViewFromManifestInfo(view, comp, ((View) panelSelectionProvider).getManifestedComponent(), info); manifestation.setNamingContext(this); attachManifestationToPanel(manifestation); addStatusWidgetsIfApplicable(); panelSelectionProvider.fireManifestationChanged(); return manifestation; } private boolean viewChanged(ViewInfo viewInfo, MCTViewManifestationInfo oldManifestationInfo, MCTViewManifestationInfo newManifestationInfo) { ExtendedProperties oldExtProps = CanvasViewStrategy.CANVAS_OWNED.getExistingProperties(oldManifestationInfo, viewInfo); ExtendedProperties newExtProps = CanvasViewStrategy.CANVAS_OWNED.getExistingProperties(newManifestationInfo, viewInfo); byte[] existingMD5 = getMessageDigest(oldExtProps); byte[] newMD5 = getMessageDigest(newExtProps); if (existingMD5 == null || newExtProps == null) return true; return !Arrays.equals(existingMD5, newMD5); } private byte[] getMessageDigest(ExtendedProperties props) { try { MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(marshal(props)); byte messageDigest[] = algorithm.digest(); return messageDigest; } catch (UnsupportedEncodingException e) { LOGGER.debug(e.getMessage(), e); } catch (JAXBException e) { LOGGER.debug(e.getMessage(), e); } catch (NoSuchAlgorithmException e) { LOGGER.debug(e.getMessage(), e); } return null; } private byte[] marshal(ExtendedProperties toBeMarshalled) throws JAXBException, UnsupportedEncodingException { ByteArrayOutputStream out = new ByteArrayOutputStream(); JAXBContext ctxt = JAXBContext.newInstance(ExtendedProperties.class); Marshaller marshaller = ctxt.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "ASCII"); marshaller.marshal(toBeMarshalled, out); return out.toByteArray(); } private void attachManifestationToPanel(View manifestation) { manifestation.putClientProperty(CanvasManifestation.MANIFEST_INFO, CanvasManifestation.getManifestationInfo(wrappedManifestation)); wrappedManifestation = manifestation; MCTViewManifestationInfo manifestationInfo = CanvasManifestation.getManifestationInfo(wrappedManifestation); manifestationInfo.setManifestedViewType(wrappedManifestation.getInfo().getType()); scrollPane.setViewportView(wrappedManifestation); revalidate(); repaint(); // Update selection provider listeners. manifestation.getSelectionProvider().removeSelectionChangeListener(selectionListener); wrappedManifestation.getSelectionProvider().addSelectionChangeListener(selectionListener); } public void hideTitle(boolean flag) { this.hasTitle = flag; if (!flag) { remove(titlePanel); } else { add(titlePanel, BorderLayout.NORTH); } MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setHasTitlePanel(flag); if (!flag) { manifestInfo.setPanelTitle(""); } else { String title = titleLabel.getText(); if (!this.wrappedManifestation.getManifestedComponent().getDisplayName().equals(title)) { manifestInfo.setPanelTitle(titleLabel.getText()); } } revalidate(); notifyTitleChanged(); } /** * Notifies view roles for the manifested component that the panel title * display has changed. */ private void notifyTitleChanged() { AbstractComponent component = wrappedManifestation.getManifestedComponent(); PropertyChangeEvent event = new PropertyChangeEvent(component); event.setProperty(PropertyChangeEvent.DISPLAY_NAME, component.getDisplayName()); event.setProperty(PropertyChangeEvent.PANEL_TITLE, getTitle()); // Avoids refreshing other manifestations when changing the panel title of // one manifestation. wrappedManifestation.updateMonitoredGUI(event); } /** * Returns the panel title's bounds relative to its container. In this case, * the container is the containing <code>CanvasManifestation</code>. * @return bounds of the panel title relative to its container */ public Rectangle getTitleBounds() { return titleBounds; } /** * Returns whether the point is part of the title area * @param point to determine whether it is part of the title area, in screen coordinates * @return true if the point is part of the title area false otherwise */ public boolean pointInTitle(Point point) { Point adjustedPoint = (Point) point.clone(); SwingUtilities.convertPointFromScreen(adjustedPoint, titlePanel); return hasTitle() && titlePanel.contains(adjustedPoint); } /** * Returns whether the point is in the panel border (inside the panel but outside the wrapped manifestation) * @param point to determine whether it is part of the panel, in screen coordinates * @return true if the point is part of the panel false otherwise */ public boolean pointOnBorder(Point point) { Point panelAdjustedPoint = (Point) point.clone(); SwingUtilities.convertPointFromScreen(panelAdjustedPoint, this); Point paneAdjustedPoint = (Point) point.clone(); SwingUtilities.convertPointFromScreen(paneAdjustedPoint, scrollPane); return contains(panelAdjustedPoint) && !scrollPane.contains(paneAdjustedPoint); } /** * Returns the panel icon's bounds relative to its container. In this case, * the container is the containing <code>CanvasManifestation</code>. * @return bounds of the panel icon relative to its container */ public Rectangle getIconBounds() { return iconBounds; } public boolean hasTitle() { return hasTitle; } private void setTitleFromManifestation(MCTViewManifestationInfo manifestationInfo) { String panelTitle = manifestationInfo.getPanelTitle(); String panelTitleFont = manifestationInfo.getPanelTitleFont(); Integer panelTitleFontSize = manifestationInfo.getPanelTitleFontSize(); Integer panelTitleFontStyle = manifestationInfo.getPanelTitleFontStyle(); Integer panelTitleFontUnderline = manifestationInfo.getPanelTitleFontUnderline(); Integer panelTitleForegroundColor = manifestationInfo.getPanelTitleFontForegroundColor(); Integer panelTitleBackgroundColor = manifestationInfo.getPanelTitleFontBackgroundColor(); if (panelTitleFontSize == null) { panelTitleFontSize = 12; } if (panelTitleFontStyle == null) { panelTitleFontStyle = Font.PLAIN; } GridBagConstraints c = new GridBagConstraints(); c.gridx = 1; c.weightx = .99; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; c.insets = TITLE_INSETS; if (panelTitle == null || panelTitle.isEmpty()) { titleLabel.setText(wrappedManifestation.getManifestedComponent().getDisplayName()); } else { titleLabel.setText(panelTitle); } titlePanel.remove(titleManifestation); titlePanel.add(titleLabel, c); Font titleFont =new Font(panelTitleFont, panelTitleFontStyle.intValue(), panelTitleFontSize.intValue()); if (panelTitleFontUnderline != null && panelTitleFontUnderline.equals(TextAttribute.UNDERLINE_ON)) { titleFont = titleFont.deriveFont(ControlAreaFormattingConstants.underlineMap); } titleLabel.setFont(titleFont); if (panelTitleForegroundColor != null) { titleLabel.setForeground(new Color(panelTitleForegroundColor.intValue())); } if (panelTitleBackgroundColor != null) { titleLabel.setOpaque(true); titleLabel.setBackground(new Color(panelTitleBackgroundColor.intValue())); } else { titleLabel.setOpaque(false); } titleLabel.repaint(); } public void setTitle(String newTitle) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitle(newTitle); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } /** Set the panel title font from the manifestation info * @param newFont the string of the JVM Font Family to set */ public void setTitleFont(String newFont) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitleFont(newFont); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } /** Set the panel title font size from the manifestation info * @param newFontSize the new font size */ public void setTitleFontSize(Integer newFontSize) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitleFontSize(newFontSize); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } /** Set the panel title font style from the manifestation info * @param newFontStyle the new font style */ public void setTitleFontStyle(Integer newFontStyle) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitleFontStyle(newFontStyle); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } /** Set the panel title font underline from the manifestation info * @param newFontStyle the title font underline style */ public void setTitleFontUnderline(Integer newFontStyle) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitleFontUnderline(newFontStyle); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } /** Set the panel title font color from the manifestation info * @param newTitleFontForegroundColor */ public void setTitleFontForegroundColor(Integer newTitleFontForegroundColor) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitleFontForegroundColor(newTitleFontForegroundColor); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } /** Set the panel title background color from the manifestation info * @param newTitleFontBackgroundColor */ public void setTitleFontBackgroundColor(Integer newTitleFontBackgroundColor) { if (this.titlePanel.isVisible()) { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); manifestInfo.setPanelTitleFontBackgroundColor(newTitleFontBackgroundColor); setTitleFromManifestation(manifestInfo); revalidate(); notifyTitleChanged(); } } public String getTitle() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); if (manifestInfo.getPanelTitle() == null) { return wrappedManifestation.getManifestedComponent().getDisplayName(); } return manifestInfo.getPanelTitle(); } /** Get the panel title font from the manifestation info * @return the panel title font from the manifestation info */ public String getTitleFont() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); return manifestInfo.getPanelTitleFont(); } /** Get the panel title font size from the manifestation info * @return the panel title font size from the manifestation info */ public Integer getTitleFontSize() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); return manifestInfo.getPanelTitleFontSize(); } /** Get the panel title font style from the manifestation info * @return the panel title font style from the manifestation info */ public Integer getTitleFontStyle() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); return manifestInfo.getPanelTitleFontStyle(); } /** Get the panel title font underline style from the manifestation info * @return the panel title font underline style from the manifestation info */ public Integer getTitleFontUnderline() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); return manifestInfo.getPanelTitleFontUnderline(); } /** Get the panel title font color from the manifestation info * @return the panel title font color from the manifestation info */ public Integer getTitleFontForegroundColor() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); return manifestInfo.getPanelTitleFontForegroundColor(); } /** Get the panel title background color from the manifestation info * @return the panel title background color from the manifestation info */ public Integer getTitleFontBackgroundColor() { MCTViewManifestationInfo manifestInfo = CanvasManifestation.getManifestationInfo(this.wrappedManifestation); return manifestInfo.getPanelTitleFontBackgroundColor(); } public void bringToFront() { this.panelSelectionProvider.fireOrderChange(this, PANEL_ZORDER.FRONT); } public void sendToBack() { this.panelSelectionProvider.fireOrderChange(this, PANEL_ZORDER.BACK); } public PanelFocusSelectionProvider getPanelFocusSelectionProvider() { return this.panelSelectionProvider; } public void save() { this.panelSelectionProvider.fireFocusPersist(); } public void removeFromCanvas() { panelSelectionProvider.fireSelectionRemoved(this); getSelectionProvider().removeSelectionChangeListener(selectionListener); } public void update(MCTViewManifestationInfo manifestationInfo) { Rectangle existingBound = getBounds(); Point newLocation = manifestationInfo.getStartPoint(); Dimension newSize = manifestationInfo.getDimension(); if (!existingBound.getLocation().equals(newLocation) || !existingBound.getSize().equals(newSize)) { setBounds(new Rectangle(newLocation, newSize)); } String borderStr = manifestationInfo.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); if (borderStr != null) { byte border = Byte.parseByte(borderStr); this.panelBorder.setBorderState(border); } Color borderColor = manifestationInfo.getBorderColor(); int borderStyle = manifestationInfo.getBorderStyle(); this.panelBorder.setBorderStyle(borderStyle); this.panelBorder.setBorderColor(borderColor); setBorder(null); setBorder(panelBorder); titlePanel.setVisible(manifestationInfo.hasBorder()); setTitleFromManifestation(manifestationInfo); String manifestedViewType = manifestationInfo.getManifestedViewType(); AbstractComponent comp = wrappedManifestation.getManifestedComponent(); Collection<ViewInfo> embeddedViews = comp.getViewInfos(ViewType.EMBEDDED); ViewInfo matchedVi = null; for (ViewInfo vi : embeddedViews) { if (manifestedViewType.equals(vi.getType())) { matchedVi = vi; break; } } assert matchedVi != null : "unable to find view for manifestation info " + manifestedViewType; changeToView(matchedVi, manifestationInfo); wrappedManifestation.putClientProperty(CanvasManifestation.MANIFEST_INFO,manifestationInfo); } private final PropertyChangeListener selectionListener = new PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); } }; public SelectionProvider getSelectionProvider() { return this; } @Override public void addSelectionChangeListener(PropertyChangeListener listener) { addPropertyChangeListener(SelectionProvider.SELECTION_CHANGED_PROP, listener); } @Override public void removeSelectionChangeListener(PropertyChangeListener listener) { removePropertyChangeListener(SelectionProvider.SELECTION_CHANGED_PROP, listener); } @Override public Collection<View> getSelectedManifestations() { return wrappedManifestation.getSelectionProvider().getSelectedManifestations(); } @Override public void clearCurrentSelections() { wrappedManifestation.getSelectionProvider().clearCurrentSelections(); Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null && SwingUtilities.isDescendingFrom(focusOwner, wrappedManifestation)) { KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); } } @Override public NamingContext getParentContext() { if (titleManifestation instanceof NamingContext) { return (NamingContext) titleManifestation; } else { return null; } } @Override public String getContextualName() { if (!hasTitle) return null; if (!titleLabel.getText().isEmpty()) return titleLabel.getText(); if (getParentContext() != null) return getParentContext().getContextualName(); return null; } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_Panel.java
102
private final PropertyChangeListener objectStaleListener = new PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { STALE_LABEL.setVisible((Boolean) evt.getNewValue()); } };
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_Panel.java
103
icon = new TransferableIcon(wrappedComponent, new TransferableIcon.ViewTransferCallback() { @Override public List<View> getViewsToTransfer() { return Collections.singletonList(getWrappedManifestation()); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_Panel.java
104
private final PropertyChangeListener selectionListener = new PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); } };
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_Panel.java
105
public class PanelBorder extends AbstractBorder { private static final long serialVersionUID = -4591457942438896139L; public static final byte NO_BORDER = 0; public static final byte NORTH_BORDER = 0x1; public static final byte SOUTH_BORDER = 0x2; public static final byte EAST_BORDER = 0x4; public static final byte WEST_BORDER = 0x8; public static final byte ALL_BORDERS = NORTH_BORDER | SOUTH_BORDER | EAST_BORDER | WEST_BORDER; /** The border color. */ private Color borderColor = Color.BLACK; private Color defaultBorderColor = Color.DARK_GRAY; private static final int borderWidth = 1; private static final int borderInsetValue = 2; private byte borders; private BorderStyle borderStyle = BorderStyle.SINGLE; private int offset = 0; /** * Creates a new border with the default border color, black. Borders will * be hidden on all four sides. * * @param initialBorderState the initial border state. */ public PanelBorder(byte initialBorderState) { this(Color.BLACK); this.borders = initialBorderState; } /** * Creates a new border with the given border color. Borders will be shown * on all four sides. * * @param color * the border color to use */ public PanelBorder(Color color) { borderColor = color; borders = ALL_BORDERS; } /** * Gets a list of borders for all four sides. The list holds borders for the * top, bott, right, and left sides, in that order. * * @return a list of borders */ public byte getBorders() { return borders; } @Override public void paintBorder(Component c, Graphics gInit, int x, int y, int width, int height) { Graphics g = gInit.create(); g.setColor(visibleBorderColor(borderColor, c.getBackground())); if (hasNorthBorder(this.borders)) { drawBorder(g, x+offset, y, x + width - 1, y, this.borderStyle); } if (hasSouthBorder(this.borders)) { drawBorder(g, x+offset, y + height-1, x+width, y + height-1, this.borderStyle); } if (hasEastBorder(this.borders)) { drawBorder(g, x + width - 1, y, x + width - 1, y + height - 1, this.borderStyle); } if (hasWestBorder(this.borders)) { drawBorder(g, x, y + height, x, y, this.borderStyle); } g.dispose(); } private void drawBorder(Graphics gOrig, int x1, int y1, int x2, int y2, BorderStyle borderStyle) { float[] dashPattern; Graphics2D g = (Graphics2D) gOrig; g.setStroke(new BasicStroke(borderWidth)); switch (borderStyle) { case SINGLE: g.setStroke(new BasicStroke(0)); g.drawLine(x1, y1, x2, y2); break; case DOUBLE: g.setStroke(new BasicStroke(borderWidth*3)); g.drawLine(x1, y1, x2, y2); break; case DASHED: dashPattern = new float[] { 5, 5 }; g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); g.drawLine(x1, y1, x2, y2); break; case DOTS: dashPattern = new float[] { 2, 5 }; g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); g.drawLine(x1, y1, x2, y2); break; case MIXED: dashPattern = new float[] {10, 3, 3, 3 }; g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); g.drawLine(x1, y1, x2, y2); break; } } /** * Sets the style for drawing any borders that are shown. * * @param newStyle * the new border style */ public void setBorderStyle(int newStyle) { this.borderStyle = BorderStyle.getBorderStyle(newStyle); } public void setBorderStyle(BorderStyle newStyle) { this.borderStyle = newStyle; } /** * Sets the border drawing state for a specified border. * * @param borderState * the border state */ public void setBorderState(byte newBorderState) { removeAllBorders(); if (hasNorthBorder(newBorderState)) { this.addBorderState(NORTH_BORDER); } if (hasSouthBorder(newBorderState)) { this.addBorderState(SOUTH_BORDER); } if (hasEastBorder(newBorderState)) { this.addBorderState(EAST_BORDER); } if (hasWestBorder(newBorderState)) { this.addBorderState(WEST_BORDER); } } /** * Adds a border to the display. * * @param newBorder * the border to add */ public void addBorderState(byte newBorder) { this.borders = (byte) (this.borders | newBorder); } /** * Removes the border on a specified side. * * @param border * the border to remove */ public void removeBorderState(byte removeBorder) { this.borders = (byte) (this.borders & ~removeBorder); } /** * Removes all borders from view. */ public void removeAllBorders() { this.borders = 0; } @Override public Insets getBorderInsets(Component c) { int top = 0; int left = 0; int rite = 0; int bottom = 0; int addlOffset = borderInsetValue; if (borderStyle == BorderStyle.DOUBLE) { // have to give more room in // insets... addlOffset = (borderInsetValue * 2); } if (hasNorthBorder(this.borders)) { top = addlOffset; } if (hasSouthBorder(this.borders)) { bottom = addlOffset; } if (hasEastBorder(this.borders)) { rite = addlOffset; } if (hasWestBorder(this.borders)) { left = addlOffset; } return new Insets(top, left, bottom, rite); } @Override public boolean isBorderOpaque() { return false; } /** * Tests whether a particular border is active. * * @param fp * the border formatting property * @return true, if the border is active */ public boolean isBorderActive(byte border) { switch (border) { case NORTH_BORDER: return hasNorthBorder(this.borders); case EAST_BORDER: return hasEastBorder(this.borders); case WEST_BORDER: return hasWestBorder(this.borders); case SOUTH_BORDER: return hasSouthBorder(this.borders); case NO_BORDER: return this.borders == 0; case ALL_BORDERS: return this.borders == ALL_BORDERS; } return false; } /** * Gets the border style used for drawing all borders. * * @return the current border style */ public int getBorderStyle() { return this.borderStyle.ordinal(); } public Color getBorderColor() { return this.borderColor; } public void setBorderColor(Color borderColor) { this.borderColor = borderColor; } public static boolean hasNorthBorder(byte borders) { return (borders & NORTH_BORDER) != 0; } public static boolean hasEastBorder(byte borders) { return (borders & EAST_BORDER) != 0; } public static boolean hasSouthBorder(byte borders) { return (borders & SOUTH_BORDER) != 0; } public static boolean hasWestBorder(byte borders) { return (borders & WEST_BORDER) != 0; } public void setOffset(int offset) { this.offset = offset; } public void setDefaultBorderColor(Color defaultBorderColor) { this.defaultBorderColor = defaultBorderColor; } private Color visibleBorderColor(Color borderColor, Color backgroundColor) { if (borderColor != null && backgroundColor != null && borderColor.getRGB() == backgroundColor.getRGB()) { return defaultBorderColor; } else { return borderColor; } } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_PanelBorder.java
106
public class PanelBorderTest { @Mock private Component c; @Mock private Graphics2D g1,g2; @BeforeMethod public void setup() { MockitoAnnotations.initMocks(this); } @Test public void testGraphicsContextNotReset() { PanelBorder panelBorder = new PanelBorder(Color.BLUE); Mockito.when(g1.create()).thenReturn(g2); panelBorder.paintBorder(c, g1, 0, 0, 10, 10); Mockito.verify(g1).create(); Mockito.verify(g1, Mockito.times(0)).setColor((Color)Mockito.anyObject()); Mockito.verify(g2,Mockito.atLeastOnce()).setColor(Color.BLUE); Mockito.verify(g2, Mockito.times(1)).dispose(); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_panel_PanelBorderTest.java
107
public class TransferableIcon extends JLabel { private static final long serialVersionUID = -7380332900682920418L; /** * This method creates a new Transferable Icon. * @param referencedComponent component that is currently active in the view. * @param viewTransferCallback the callback to use during a drag and drop gesture to build the set of views available * in the transfer. */ @SuppressWarnings("serial") public TransferableIcon(final AbstractComponent referencedComponent, final ViewTransferCallback viewTransferCallback) { super(referencedComponent.getIcon()); final AtomicBoolean clicked = new AtomicBoolean(false); setTransferHandler(new TransferHandler() { @Override public int getSourceActions(JComponent c) { return canComponentBeContained()?COPY:NONE; } private boolean canComponentBeContained() { PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(),Collections.singleton(referencedComponent)); String policyCategoryKey = PolicyInfo.CategoryType.CAN_OBJECT_BE_CONTAINED_CATEGORY.getKey(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); ExecutionResult result = policyManager.execute(policyCategoryKey, context); return result.getStatus(); } @Override protected Transferable createTransferable(JComponent c) { return new ViewRoleSelection(viewTransferCallback.getViewsToTransfer().toArray(new View[0])); } @Override protected void exportDone(JComponent source, Transferable data, int action) { super.exportDone(source, data, action); clicked.set(false); } }); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { if (clicked.get()) { JComponent c = (JComponent) e.getSource(); TransferHandler th = c.getTransferHandler(); th.exportAsDrag(c, e, TransferHandler.COPY); } } }); addMouseListener(new MouseAdapter() { private void delegateMouseEvent(MouseEvent e) { Container container = getParent(); while (container != null && !(container instanceof View)) { container = container.getParent(); } if (container != null) { ((View) container).processMouseEvent(e); } } @Override public void mousePressed(MouseEvent e) { clicked.set(true); delegateMouseEvent(e); } @Override public void mouseClicked(MouseEvent e) { delegateMouseEvent(e); } @Override public void mouseReleased(MouseEvent e) { clicked.set(false); delegateMouseEvent(e); } }); setOpaque(false); } /** * This interface supports the ability to transfer the the currently showing views. This is expected to be dynamic * in most cases (the center pane for example) and this interface supports the ability to get the view to transfer. * */ public interface ViewTransferCallback { /** * Returns the ordered set of views to provide during a drag and drop. * @return the views to transfer. This method should not return null. */ List<View> getViewsToTransfer(); } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_TransferableIcon.java
108
setTransferHandler(new TransferHandler() { @Override public int getSourceActions(JComponent c) { return canComponentBeContained()?COPY:NONE; } private boolean canComponentBeContained() { PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(),Collections.singleton(referencedComponent)); String policyCategoryKey = PolicyInfo.CategoryType.CAN_OBJECT_BE_CONTAINED_CATEGORY.getKey(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); ExecutionResult result = policyManager.execute(policyCategoryKey, context); return result.getStatus(); } @Override protected Transferable createTransferable(JComponent c) { return new ViewRoleSelection(viewTransferCallback.getViewsToTransfer().toArray(new View[0])); } @Override protected void exportDone(JComponent source, Transferable data, int action) { super.exportDone(source, data, action); clicked.set(false); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_TransferableIcon.java
109
addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { if (clicked.get()) { JComponent c = (JComponent) e.getSource(); TransferHandler th = c.getTransferHandler(); th.exportAsDrag(c, e, TransferHandler.COPY); } } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_TransferableIcon.java
110
addMouseListener(new MouseAdapter() { private void delegateMouseEvent(MouseEvent e) { Container container = getParent(); while (container != null && !(container instanceof View)) { container = container.getParent(); } if (container != null) { ((View) container).processMouseEvent(e); } } @Override public void mousePressed(MouseEvent e) { clicked.set(true); delegateMouseEvent(e); } @Override public void mouseClicked(MouseEvent e) { delegateMouseEvent(e); } @Override public void mouseReleased(MouseEvent e) { clicked.set(false); delegateMouseEvent(e); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_TransferableIcon.java
111
public interface ViewTransferCallback { /** * Returns the ordered set of views to provide during a drag and drop. * @return the views to transfer. This method should not return null. */ List<View> getViewsToTransfer(); }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_panel_TransferableIcon.java
112
public class AbstractMCTViewManifestationInfoTest { @Test public void testContainsBorder() { MCTViewManifestationInfo info = new MCTViewManifestationInfo("TestName"); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_TOP)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_RIGHT)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_BOTTOM)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_LEFT)); List<Integer> borders = new ArrayList<Integer>(); borders.add(MCTViewManifestationInfo.BORDER_TOP); info.setBorders(borders); assertTrue(info.containsBorder(MCTViewManifestationInfo.BORDER_TOP)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_RIGHT)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_BOTTOM)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_LEFT)); } @Test public void testRemoveBorder() { MCTViewManifestationInfo info = new MCTViewManifestationInfo("TestName"); // Remove a border when no borders exist. info.removeBorder(MCTViewManifestationInfo.BORDER_TOP); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_TOP)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_RIGHT)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_BOTTOM)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_LEFT)); List<Integer> borders = new ArrayList<Integer>(); borders.add(MCTViewManifestationInfo.BORDER_TOP); info.setBorders(borders); // Remove a border that doesn't exist. info.removeBorder(MCTViewManifestationInfo.BORDER_BOTTOM); assertTrue(info.containsBorder(MCTViewManifestationInfo.BORDER_TOP)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_RIGHT)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_BOTTOM)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_LEFT)); // Remove a border that exists. info.removeBorder(MCTViewManifestationInfo.BORDER_TOP); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_TOP)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_RIGHT)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_BOTTOM)); assertFalse(info.containsBorder(MCTViewManifestationInfo.BORDER_LEFT)); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_persistence_AbstractMCTViewManifestationInfoTest.java
113
@XmlRootElement(name="extendedInfo") @XmlAccessorType(XmlAccessType.FIELD) public class CanvasPersistentState { private ViewRoleProperties viewRoleProperties = new ViewRoleProperties(); public ViewRoleProperties getViewRoleProperties() { return viewRoleProperties; } public List<MCTViewManifestationInfo> getInfos() { return getViewRoleProperties().getEntries().getInfos(); } @XmlAccessorType(XmlAccessType.FIELD) public static class ViewRoleProperties { private Entries entries = new Entries(); public Entries getEntries() { return entries; } } @XmlAccessorType(XmlAccessType.FIELD) public static class Entries { @XmlElement(name="ManifestInfo", type=MCTViewManifestationInfo.class) private List<MCTViewManifestationInfo> infos = new ArrayList<MCTViewManifestationInfo>(); public List<MCTViewManifestationInfo> getInfos() { return infos; } } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_persistence_CanvasPersistentState.java
114
@XmlAccessorType(XmlAccessType.FIELD) public static class Entries { @XmlElement(name="ManifestInfo", type=MCTViewManifestationInfo.class) private List<MCTViewManifestationInfo> infos = new ArrayList<MCTViewManifestationInfo>(); public List<MCTViewManifestationInfo> getInfos() { return infos; } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_persistence_CanvasPersistentState.java
115
@XmlAccessorType(XmlAccessType.FIELD) public static class ViewRoleProperties { private Entries entries = new Entries(); public Entries getEntries() { return entries; } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_persistence_CanvasPersistentState.java
116
@XmlType(name = "ManifestInfo") @XmlAccessorType(XmlAccessType.FIELD) public class MCTViewManifestationInfo implements NamingContext, Cloneable { private static final int DEFAULT_HEIGHT = 150; private static final int DEFAULT_WIDTH = 250; /** A sentinel value indicating that a point variable has not yet been set. */ public final static Point UNDEFINED_POINT = new Point(0, 0); /** A flag indicating the left border of a panel. */ public final static int BORDER_LEFT = 0; /** A flag indicating the right border of a panel. */ public final static int BORDER_RIGHT = 1; /** A flag indicating the top border of a panel. */ public final static int BORDER_TOP = 2; /** A flag indicating the bottom border of a panel. */ public final static int BORDER_BOTTOM = 3; /** A flag indicating that a border is a single-line border. */ public final static int BORDER_STYLE_SINGLE = 0; /** A flag indicating that a border is a double-line border. */ public final static int BORDER_STYLE_DOUBLE = 1; /** A flag indicating that a border is a dashed line border. */ public final static int BORDER_STYLE_DASHED = 2; /** A flag indicating that a border is a dotted line border. */ public final static int BORDER_STYLE_DOTS = 3; /** A flag indicating that a border is a mixed, dot-dash border. */ public final static int BORDER_STYLE_MIXED = 4; /** The width of the manifested view. */ protected int sizeWidth = DEFAULT_WIDTH; /** The height of the manifested view. */ protected int sizeHeight = DEFAULT_HEIGHT; /** The x location of the manifested view. */ protected int startPointX = UNDEFINED_POINT.x; /** The y location of the manifested view. */ protected int startPointY = UNDEFINED_POINT.y; /** Settings for all four borders. */ protected List<Integer> borders; /** The border style to use. */ protected Integer borderStyle; /** The color to use for the borders. */ protected int borderColorRGB; /** If true, the manifested view should be shown with a title bar. */ protected boolean hasTitlePanel = true; /** The title to show in the view title bar. */ protected String panelTitle; /** The view role type we are manifesting. */ protected String viewType; private boolean hasBorder = true; private String componentId; private Map<String, String> infoProperties = new HashMap<String, String>(); private transient boolean dirty = false; /** * For jaxb internal use only. */ public MCTViewManifestationInfo() { super(); } /** * Creates new view manifestation information for the given view role type. * * @param aViewType * the view type we will manifest */ public MCTViewManifestationInfo(String aViewType) { viewType = aViewType; } public Dimension getDimension() { return new Dimension(sizeWidth, sizeHeight); } public void setDimension(Dimension dimension) { this.sizeWidth = dimension.width; this.sizeHeight = dimension.height; } public void setStartPoint(Point p) { startPointX = p.x; startPointY = p.y; } public String getPanelTitle() { return panelTitle; } public void setPanelTitle(String s) { panelTitle = s; } @Override public String getContextualName() { return getPanelTitle(); } @Override public NamingContext getParentContext() { return null; } public Point getStartPoint() { return new Point(startPointX, startPointY); } public String getManifestedViewType() { return this.viewType; } public void setManifestedViewType(String viewType) { this.viewType = viewType; } public final static MCTViewManifestationInfo NULL_VIEW_MANIFESTATION_INFO = new MCTViewManifestationInfo(); public Object clone() throws CloneNotSupportedException { if (this == NULL_VIEW_MANIFESTATION_INFO) { return NULL_VIEW_MANIFESTATION_INFO; } MCTViewManifestationInfo clonedManifestationInfo = new MCTViewManifestationInfo(); clonedManifestationInfo.componentId = this.componentId; clonedManifestationInfo.viewType = this.viewType; clonedManifestationInfo.sizeWidth = this.sizeWidth; clonedManifestationInfo.sizeHeight = this.sizeHeight; clonedManifestationInfo.startPointX = startPointX; clonedManifestationInfo.startPointY = startPointY; clonedManifestationInfo.hasBorder = this.hasBorder(); clonedManifestationInfo.borderColorRGB = this.borderColorRGB; clonedManifestationInfo.hasTitlePanel = this.hasTitlePanel(); clonedManifestationInfo.panelTitle = this.panelTitle; clonedManifestationInfo.infoProperties.putAll(this.infoProperties); return clonedManifestationInfo; } public boolean hasBorder() { return hasBorder; } public void setHasBorder(boolean setting) { this.hasBorder = setting; } public boolean hasTitlePanel() { return hasTitlePanel; } public void setHasTitlePanel(boolean setting) { hasTitlePanel = setting; } public List<Integer> getBorders() { if (borders == null) { // not initialized yet... borders = new ArrayList<Integer>(); borders.add(BORDER_LEFT); borders.add(BORDER_RIGHT); borders.add(BORDER_TOP); borders.add(BORDER_BOTTOM); } return borders; } public void setBorders(List<Integer> borderList) { this.borders = borderList; } public boolean containsBorder(Integer border) { if (borders == null) { return false; } Iterator<Integer> iter = borders.iterator(); while (iter.hasNext()) { Integer aBorder = iter.next(); if (border.intValue() == aBorder.intValue()) { return true; } } return false; } public void removeBorder(Integer border) { if (borders != null) { while (borders.contains(border)) { borders.remove(border); } } } public void addBorder(Integer border) { if (borders == null) borders = new ArrayList<Integer>(); if (!containsBorder(border)) borders.add(border); setBorders(this.borders); } public Color getBorderColor() { return new Color(borderColorRGB); } public void setBorderColor(Color newColor) { this.borderColorRGB = newColor.getRGB(); } public int getBorderStyle() { if (borderStyle == null) borderStyle = BORDER_STYLE_SINGLE; return borderStyle; } public void setBorderStyle(int newStyle) { this.borderStyle = newStyle; } public String getComponentId() { return componentId; } public void setComponentId(String componentId) { this.componentId = componentId; } public void addInfoProperty(String property, String value) { this.infoProperties.put(property, value); } public String getInfoProperty(String property) { return infoProperties.get(property); } public boolean isDirty() { return dirty; } public void setDirty(boolean dirty) { this.dirty = dirty; } public Color getColor(String name) { return UIManager.getColor(name); } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_persistence_MCTViewManifestationInfo.java
117
public class RootCanvasClassTest { @Test public void testBackwardCompatibility() throws Exception { JAXBContext jc = JAXBContext.newInstance(CanvasPersistentState.class); Unmarshaller u = jc.createUnmarshaller(); InputStream is = getClass().getResourceAsStream("/JAXBTest.xml"); CanvasPersistentState info = (CanvasPersistentState) u.unmarshal(is); is.close(); List<MCTViewManifestationInfo> infos = info.getInfos(); Assert.assertEquals(infos.size(), 3); List<String> expected = Arrays.asList("1","2","0"); for (int i = 0; i < infos.size(); i++) { // verify panel order MCTViewManifestationInfo curInfo = infos.get(i); Assert.assertEquals(curInfo.getInfoProperty("PANEL_ORDER"),expected.get(i)); } } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_persistence_RootCanvasClassTest.java
118
public class CanvasFilterViewPolicy implements Policy { @Override public ExecutionResult execute(PolicyContext context) { ExecutionResult trueResult = new ExecutionResult(context, true, ""); AbstractComponent targetComponent = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class); ViewInfo viewInfo = context.getProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), ViewInfo.class); if (!viewInfo.getViewClass().equals(CanvasManifestation.class)) { return trueResult; } if (!targetComponent.isLeaf()) return trueResult; else return new ExecutionResult(context, false, CanvasManifestation.class.getName() + " is not applicable for component type " + targetComponent.getClass().getName()); } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_policy_CanvasFilterViewPolicy.java
119
public class EmbeddedCanvasViewsAreNotWriteable implements Policy { private static ResourceBundle bundle = ResourceBundle.getBundle("CanvasResourceBundle"); @Override public ExecutionResult execute(PolicyContext context) { AbstractComponent component = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class); return new ExecutionResult(context, component.getWorkUnitDelegate()==null, bundle.getString("CanvasOwnedViewsPolicyMessage")); } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_policy_EmbeddedCanvasViewsAreNotWriteable.java
120
public class TestEmbeddedViewsNotWriteable { private AbstractComponent mockedComponent = new AbstractComponent(){}; private Policy embeddedPolicy; private PolicyContext context; @BeforeMethod public void init() { MockitoAnnotations.initMocks(this); embeddedPolicy = new EmbeddedCanvasViewsAreNotWriteable(); context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockedComponent); } @Test public void testEmbeddedView() { Assert.assertTrue(embeddedPolicy.execute(context).getStatus(), "strategies which are not delegating should not trigger this policy"); AbstractComponent owningComponent = new AbstractComponent(){}; mockedComponent.getCapability(ComponentInitializer.class).setWorkUnitDelegate(owningComponent); Assert.assertFalse(embeddedPolicy.execute(context).getStatus(), "delegating dao strategies should not be writeable"); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_policy_TestEmbeddedViewsNotWriteable.java
121
private AbstractComponent mockedComponent = new AbstractComponent(){};
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_policy_TestEmbeddedViewsNotWriteable.java
122
AbstractComponent owningComponent = new AbstractComponent(){};
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_policy_TestEmbeddedViewsNotWriteable.java
123
public class CanvasComponentProvider extends AbstractComponentProvider { private static ResourceBundle bundle = ResourceBundle.getBundle("CanvasResourceBundle"); private static final Collection<ViewInfo> VIEW_INFOS = Arrays.asList( new ViewInfo(CanvasManifestation.class, bundle.getString("Canvas"), "gov.nasa.arc.mct.canvas.view.CanvasView", ViewType.OBJECT), new ViewInfo(CanvasManifestation.class, bundle.getString("Canvas"), "gov.nasa.arc.mct.canvas.view.CanvasView", ViewType.CENTER), new ViewInfo(CanvasManifestation.class, bundle.getString("Canvas"), "gov.nasa.arc.mct.canvas.view.CanvasView", ViewType.EMBEDDED, new ImageIcon(CanvasComponentProvider.class.getResource("/images/canvasViewButton-OFF.png")), new ImageIcon(CanvasComponentProvider.class.getResource("/images/canvasViewButton-ON.png"))), new ViewInfo(PanelInspector.class, "Panel Inspector", ViewType.CENTER_OWNED_INSPECTOR)); @Override public Collection<MenuItemInfo> getMenuItemInfos() { return Arrays.asList( new MenuItemInfo("/objects/view.ext", "OBJECTS_CHANGE_VIEWS", MenuItemType.RADIO_GROUP, ChangeViewAction.class), new MenuItemInfo("/objects/deletion.ext", "OBJECTS_REMOVE_MANIFESTATION", MenuItemType.NORMAL, RemovePanelAction.class), new MenuItemInfo("/objects/format.panel.ext", "OBJECTS_ALIGNMENT", AlignmentMenu.class), // alignment menu actions new MenuItemInfo(AlignmentMenu.OBJECTS_ALIGNMENT_ORIENTATION_EXT, AlignLeftAction.ACTION_KEY, MenuItemType.NORMAL, AlignLeftAction.class), new MenuItemInfo(AlignmentMenu.OBJECTS_ALIGNMENT_ORIENTATION_EXT, AlignRightAction.ACTION_KEY, MenuItemType.NORMAL, AlignRightAction.class), new MenuItemInfo(AlignmentMenu.OBJECTS_ALIGNMENT_ORIENTATION_EXT, AlignTopAction.ACTION_KEY, MenuItemType.NORMAL, AlignTopAction.class), new MenuItemInfo(AlignmentMenu.OBJECTS_ALIGNMENT_ORIENTATION_EXT, AlignBottomAction.ACTION_KEY, MenuItemType.NORMAL, AlignBottomAction.class), new MenuItemInfo(AlignmentMenu.OBJECTS_ALIGNMENT_ORIENTATION_EXT, AlignVerticalCenterAction.ACTION_KEY, MenuItemType.NORMAL, AlignVerticalCenterAction.class), new MenuItemInfo(AlignmentMenu.OBJECTS_ALIGNMENT_ORIENTATION_EXT, AlignHorizontalCenterAction.ACTION_KEY, MenuItemType.NORMAL, AlignHorizontalCenterAction.class), new MenuItemInfo("/objects/format.panel.ext", "OBJECTS_BORDERS", BordersMenu.class), new MenuItemInfo(BordersMenu.OBJECTS_BORDERS_SIDES_EXT, BordersBottomAction.ACTION_KEY, MenuItemType.CHECKBOX, BordersBottomAction.class), new MenuItemInfo(BordersMenu.OBJECTS_BORDERS_SIDES_EXT, BordersTopAction.ACTION_KEY, MenuItemType.CHECKBOX, BordersTopAction.class), new MenuItemInfo(BordersMenu.OBJECTS_BORDERS_SIDES_EXT, BordersLeftAction.ACTION_KEY, MenuItemType.CHECKBOX, BordersLeftAction.class), new MenuItemInfo(BordersMenu.OBJECTS_BORDERS_SIDES_EXT, BordersRightAction.ACTION_KEY, MenuItemType.CHECKBOX, BordersRightAction.class), new MenuItemInfo(BordersMenu.OBJECTS_BORDERS_ALLORNONE_EXT, BordersAllOrNoneAction.ACTION_KEY, MenuItemType.RADIO_GROUP, BordersAllOrNoneAction.class), new MenuItemInfo("/objects/format.panel.ext", "OBJECTS_PANEL_TITLE_BAR", MenuItemType.CHECKBOX, PanelTitleBarAction.class), new MenuItemInfo("/objects/format.zorder.ext", "OBJECTS_FORMATTING_BRING_TO_FRONT", MenuItemType.NORMAL, BringToFrontAction.class), new MenuItemInfo( "/objects/format.zorder.ext", "OBJECTS_FORMATTING_SEND_TO_BACK", MenuItemType.NORMAL, SendToBackAction.class), new MenuItemInfo("/objects/additions", // NOI18N "OBJECTS_VIEW_GRIDS", // NOI18N GridMenu.class), new MenuItemInfo("/objects/grid.size/sizes.ext", // NOI18N "PANEL_CHANGE_GRID_SIZE", // NOI18N MenuItemType.RADIO_GROUP, ChangeGridSizeAction.class), new MenuItemInfo("/objects/additions", // NOI18N "CHANGE_SNAP", // NOI18N MenuItemType.CHECKBOX, ChangeSnapAction.class), new MenuItemInfo("/objects/additions", // NOI18N "RETILE", // NOI18N MenuItemType.NORMAL, ReTileAction.class), new MenuItemInfo("/view/formatting.ext", // NOI18N "VIEW_GRIDS", // NOI18N WindowGridMenu.class), new MenuItemInfo(WindowGridMenu.VIEW_GRID_SIZE_SUBMENU_EXT, // NOI18N "PANEL_CHANGE_GRID_SIZE_WINDOW", // NOI18N MenuItemType.RADIO_GROUP, WindowChangeGridSizeAction.class), new MenuItemInfo("/view/formatting.ext", // NOI18N "VIEW_CHANGE_SNAP", // NOI18N MenuItemType.CHECKBOX, WindowChangeSnapAction.class), new MenuItemInfo("/view/formatting.ext", // NOI18N "VIEW_RETILE", // NOI18N MenuItemType.NORMAL, WindowReTileAction.class), new MenuItemInfo("/view/select.ext", // NOI18N "VIEW_SELECT_ALL", // NOI18N MenuItemType.NORMAL, SelectAllAction.class), new MenuItemInfo("/objects/format.panel.ext", "OBJECTS_BORDER_STYLES", BorderStylesMenu.class), new MenuItemInfo(BorderStylesMenu.OBJECTS_BORDERS_STYLES_EXT, BorderStylesAction.ACTION_KEY, MenuItemType.RADIO_GROUP, BorderStylesAction.class), new MenuItemInfo("/objects/format.panel.ext", "OBJECTS_PANEL_TITLE_BAR", MenuItemType.CHECKBOX, PanelTitleBarAction.class), new MenuItemInfo("/objects/format.zorder.ext", "OBJECTS_FORMATTING_BRING_TO_FRONT", MenuItemType.NORMAL, BringToFrontAction.class), new MenuItemInfo( "/objects/format.zorder.ext", "OBJECTS_FORMATTING_SEND_TO_BACK", MenuItemType.NORMAL, SendToBackAction.class)); } @Override public Collection<PolicyInfo> getPolicyInfos() { return Arrays.asList( new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), CanvasFilterViewPolicy.class), new PolicyInfo(PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey(), EmbeddedCanvasViewsAreNotWriteable.class)); } @Override public Collection<ViewInfo> getViews(String componentTypeId) { return VIEW_INFOS; } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_provider_CanvasComponentProvider.java
124
@SuppressWarnings("serial") public class Augmentation extends JComponent { private static final int d = 8; private static final int h = d / 2; private static final float s = h / 2; private Set<Panel> highlightedPanels = new LinkedHashSet<Panel>(); private static final Color ORIG_COLOR = UIManager.getColor("textHighlight").darker(); private static final Color HIGHLIGHT_COLOR = new Color(ORIG_COLOR.getRed(), ORIG_COLOR .getGreen(), ORIG_COLOR.getBlue(), 200); private CanvasManifestation canvasManifestation; private JPanel augmentedPanel; private boolean hasPanelChanged = false; private Component lastMouseEnteredWidget; /** * This variable represents the widget the mouse was pressed in. The matching mouse released and mouse dragged * must be dispatched to the same event. */ private Component mousePressedWidget; private Point oldLocation; private Point selectedPointIfNothingHappens; boolean spotlightMode = false; String spotlightText; public Augmentation(JPanel augmentedPanel, CanvasManifestation canvasManifestation) { this.augmentedPanel = augmentedPanel; this.canvasManifestation = canvasManifestation; addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { if (highlightedPanels.isEmpty()) { redispatchEvent(e); return; } if (Augmentation.this.canvasManifestation.isLocked()) { redispatchEvent(e); return; } selectedPointIfNothingHappens = null; Augmentation augmentation = (Augmentation) e.getSource(); int cursorType = augmentation.getCursor().getType(); Point newLocation = e.getPoint(); switch (cursorType) { case Cursor.MOVE_CURSOR: newLocation = marshalNewLocation(newLocation, e.getLocationOnScreen()); int diffX = newLocation.x - oldLocation.x, diffY = newLocation.y - oldLocation.y; for (Panel panel : highlightedPanels) { Rectangle panelOldBounds = panel.getBounds(); panel.setBounds(panelOldBounds.x + diffX, panelOldBounds.y + diffY, panelOldBounds.width, panelOldBounds.height); } oldLocation = newLocation; break; case Cursor.NE_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldNECornerX = panelOldBounds.x + panelOldBounds.width, oldNECornerY = panelOldBounds.y; int diffWidth = newLocation.x - oldNECornerX, diffHeight = newLocation.y - oldNECornerY; int newWidth = panelOldBounds.width + diffWidth; int newHeight = panelOldBounds.height - diffHeight; if (newWidth > 0 && newHeight > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y + diffHeight, newWidth, newHeight); } break; case Cursor.SE_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSECornerX = panelOldBounds.x + panelOldBounds.width, oldSECornerY = panelOldBounds.y + panelOldBounds.height; int diffWidth = newLocation.x - oldSECornerX, diffHeight = newLocation.y - oldSECornerY; int newWidth = panelOldBounds.width + diffWidth; int newHeight = panelOldBounds.height + diffHeight; if (newWidth > 0 && newHeight > 0) panel .setBounds(panelOldBounds.x, panelOldBounds.y, newWidth, newHeight); } break; case Cursor.SW_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSWCornerX = panelOldBounds.x, oldSWCornerY = panelOldBounds.y + panelOldBounds.height; int diffWidth = newLocation.x - oldSWCornerX, diffHeight = newLocation.y - oldSWCornerY; int newWidth = panelOldBounds.width - diffWidth; int newHeight = panelOldBounds.height + diffHeight; if (newWidth > 0 && newHeight > 0) panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y, newWidth, newHeight); } break; case Cursor.NW_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSWCornerX = panelOldBounds.x, oldSWCornerY = panelOldBounds.y; int diffWidth = newLocation.x - oldSWCornerX, diffHeight = newLocation.y - oldSWCornerY; int newWidth = panelOldBounds.width - diffWidth; int newHeight = panelOldBounds.height - diffHeight; if (newWidth > 0 && newHeight > 0) panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y + diffHeight, newWidth, newHeight); } break; case Cursor.E_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldEEdgeX = panelOldBounds.x + panelOldBounds.width; int diffWidth = newLocation.x - oldEEdgeX; int newWidth = panelOldBounds.width + diffWidth; if (newWidth > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y, newWidth, panelOldBounds.height); } break; case Cursor.S_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSEdgeY = panelOldBounds.y + panelOldBounds.height; int diffHeight = newLocation.y - oldSEdgeY; int newHeight = panelOldBounds.height + diffHeight; if (newHeight > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y, panelOldBounds.width, newHeight); } break; case Cursor.W_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldWEdgeX = panelOldBounds.x; int diffWidth = newLocation.x - oldWEdgeX; int newWidth = panelOldBounds.width - diffWidth; if (newWidth > 0) panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y, newWidth, panelOldBounds.height); } break; case Cursor.N_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldNEdgeY = panelOldBounds.y; int diffHeight = newLocation.y - oldNEdgeY; int newHeight = panelOldBounds.height - diffHeight; if (newHeight > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y + diffHeight, panelOldBounds.width, newHeight); } break; default: redispatchEvent(e); return; } redispatchEvent(e); hasPanelChanged = true; } private Point marshalNewLocation(Point mouseLocation, Point mouseLocationOnScreen) { if (highlightedPanels.isEmpty()) { return mouseLocation; } int smallestX; int smallestY; Iterator<Panel> it = highlightedPanels.iterator(); Panel panel = it.next(); Point bound = panel.getLocationOnScreen(); smallestX = bound.x; smallestY = bound.y; while (it.hasNext()) { panel = it.next(); bound = panel.getLocationOnScreen(); if (bound.x < smallestX) { smallestX = bound.x; } if (bound.y < smallestY) { smallestY = bound.y; } } Point smallestPoint = new Point(smallestX, smallestY); Point returnLocation = new Point(mouseLocation.x, mouseLocation.y); if (invalidHorizontalMovement(smallestPoint, mouseLocationOnScreen, Augmentation.this.canvasManifestation, mouseLocation.x < oldLocation.x)) { returnLocation.x = oldLocation.x + Augmentation.this.canvasManifestation.getLocationOnScreen().x - smallestX; } if (invalidVerticalMovement(smallestPoint, mouseLocationOnScreen, Augmentation.this.canvasManifestation, mouseLocation.y < oldLocation.y)) { returnLocation.y = oldLocation.y + Augmentation.this.canvasManifestation.getLocationOnScreen().y - smallestY; } return returnLocation; } private boolean invalidHorizontalMovement(Point checkPoint, Point mouseLocation, Container parent, boolean leftMoving) { Point parentLoc = parent.getLocationOnScreen(); if ((checkPoint.x <= parentLoc.x) && leftMoving) { return true; } return false; } private boolean invalidVerticalMovement(Point checkPoint, Point mouseLocation, Container parent, boolean upMoving) { Point parentLoc = parent.getLocationOnScreen(); if ((checkPoint.y <= parentLoc.y) && upMoving) { return true; } return false; } @Override public void mouseMoved(MouseEvent e) { Augmentation augmentation = (Augmentation) e.getSource(); for (Panel panel : highlightedPanels) { int currentCursorType = augmentation.getCursor().getType(); setCursorType(augmentation, panel, e.getPoint()); int newCursorType = augmentation.getCursor().getType(); oldLocation = e.getPoint(); if (currentCursorType != newCursorType) { return; } } redispatchEvent(e); } }); // if popup trigger is in title bar, then show popup otherwise redispatchEvent // addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { redispatchEvent(e); } @Override public void mouseExited(MouseEvent e) { redispatchEvent(e); } @Override public void mousePressed(MouseEvent e) { selectedPointIfNothingHappens = null; // point is not in title area, pass the underlying event to the contents of the panel Augmentation augmentation = (Augmentation) e.getSource(); Point p = e.getLocationOnScreen(); CanvasManifestation canvas = Augmentation.this.canvasManifestation; Panel panel = canvas.findImmediatePanel(p); // Detects if cursor is within the move or resize region. This region includes // d pixels (see field declaration) beyond a panel's width and height. if (panel == null && augmentation.getCursor().getType() != Cursor.DEFAULT_CURSOR) { redispatchEvent(e); return; } if (panel != null && !panel.pointOnBorder(p)) { redispatchEvent(e); return; } if (isPopupTrigger(e)) { showPopupMenu(e); return; } if (e.getClickCount() == 1) { oldLocation = e.getPoint(); if (isDiscontinuousMultiSelection(e)) { canvas.addSingleSelection(p); } else if(canvas.getSelectedPanels().contains(panel)) { canvas.addSingleSelection(p); selectedPointIfNothingHappens = p; } else { canvas.setSingleSelection(p); } if(panel != null) { panel.setTitleBounds(); setCursorType(augmentation, panel, e.getPoint()); } augmentation.repaint(); } else if (isDoubleClick(e)) { panel = augmentation.canvasManifestation.setSingleSelection(p); if (panel != null) { panel.getWrappedManifestation().getManifestedComponent().open(); } } redispatchEvent(e); } @Override public void mouseReleased(MouseEvent e) { if (isPopupTrigger(e)) { showPopupMenu(e); return; } for (Panel panel : highlightedPanels) { Rectangle r = panel.getBounds(); r = panel.marshalBound(r); panel.setBounds(r); } if(selectedPointIfNothingHappens != null) { Augmentation.this.canvasManifestation.setSingleSelection(selectedPointIfNothingHappens); hasPanelChanged = true; } if (hasPanelChanged) { Augmentation.this.canvasManifestation.fireFocusPersist(); Augmentation.this.repaint(); Augmentation.this.canvasManifestation.computePreferredSize(); hasPanelChanged = false; Augmentation.this.canvasManifestation.updateController(highlightedPanels); } redispatchEvent(e); } @Override public void mouseClicked(MouseEvent e) { redispatchEvent(e); } private boolean isDiscontinuousMultiSelection(MouseEvent e) { return e.isControlDown() || e.isMetaDown(); } private boolean isPopupTrigger(MouseEvent e) { return e.isPopupTrigger(); } private boolean isDoubleClick(MouseEvent e) { return (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)); } private void showPopupMenu(MouseEvent e) { Augmentation augmentation = (Augmentation) e.getSource(); Point p = e.getLocationOnScreen(); Panel panel = augmentation.canvasManifestation.findImmediatePanel(p); if (panel != null && !panel.pointInTitle(p)) { redispatchEvent(e); return; } if (!augmentation.canvasManifestation.getSelectedPanels().contains(panel)) { panel = augmentation.canvasManifestation.setSingleSelection(p); } // Don't show the popup if the canvas is in the inspector. // This is because the actions don't use the right canvas. // This causes bug MCT-2250. // This should be re-enabled once the actions use the correct canvas. View m = augmentation.canvasManifestation; while (m != null && m.getInfo() != null) { if (m.getInfo().getViewType() == ViewType.INSPECTOR || m.getInfo().getViewType() == ViewType.CENTER_OWNED_INSPECTOR) { return; } m = (View) SwingUtilities.getAncestorOfClass(View.class, m); } if (panel == null) { MenuManager menuManager = MenuManagerAccess.getMenuManager(); JPopupMenu popupMenu = menuManager.getViewPopupMenu(augmentation.canvasManifestation); if (popupMenu != null) popupMenu.show(augmentation.canvasManifestation, e.getX(), e.getY()); } else { Point panelPoint = panel.getLocationOnScreen(); JPopupMenu popupMenu = panel.getWrappedManifestation() .getManifestationPopupMenu(); if (popupMenu != null) popupMenu.show(panel, p.x - panelPoint.x, p.y - panelPoint.y); } augmentation.repaint(); } }); MarqueSelectionListener marqueSelectionListener = new MarqueSelectionListener( augmentedPanel, new MarqueSelectionListener.MultipleSelectionProvider() { @Override public void selectPanels(Collection<Panel> selection) { Augmentation.this.canvasManifestation.setSelection(selection); Augmentation.this.repaint(); } @Override public boolean pointInTopLevelPanel(Point p) { return !Augmentation.this.canvasManifestation .isPointinaPanel(p); } }); addMouseListener(marqueSelectionListener); addMouseMotionListener(marqueSelectionListener); } private void setCursorType(Augmentation augmentation, Panel panel, Point cursorPoint) { Point panelLocaion = panel.getLocation(); /* * (x0, y0) (x1, y0) (x2, y0) * (x0, y1) (x2, y1) * (x0, y2) (x1, y2) (x2, y2) */ int x0 = panelLocaion.x, x1 = panelLocaion.x + panel.getWidth() / 2, x2 = panelLocaion.x + panel.getWidth(); int y0 = panelLocaion.y, y1 = panelLocaion.y + panel.getHeight() / 2, y2 = panelLocaion.y + panel.getHeight(); // Check if cursorPoint falls on the highlight area. int x0_left = x0 - h; int x0_right = x0 + h; int x2_left = x2 - h; int x2_right = x2 + h; int y0_top = y0 - h; int y0_bottom = y0 + h; int y2_top = y2 - h; int y2_bottom = y2 + h; if (cursorPoint.x >= x0_left && cursorPoint.x <= x2_right && cursorPoint.y >= y0_top && cursorPoint.y <= y2_bottom && (!(cursorPoint.x >= x0_right && cursorPoint.x <= x2_left && cursorPoint.y >= y0_bottom && cursorPoint.y <= y2_top))) { if (cursorPoint.x >= x0_left && cursorPoint.x <= x0_right && cursorPoint.y >= y0_top && cursorPoint.y <= y0_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.NW_RESIZE_CURSOR)); } else { int y1_top = y1 - h; int y1_bottom = y1 + h; if (cursorPoint.x >= x0_left && cursorPoint.x <= x0_right && cursorPoint.y >= y1_top && cursorPoint.y <= y1_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); } else if (cursorPoint.x >= x0_left && cursorPoint.x <= x0_right && cursorPoint.y >= y2_top && cursorPoint.y <= y2_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.SW_RESIZE_CURSOR)); } else { int x1_left = x1 - h; int x1_right = x1 + h; if (cursorPoint.x >= x1_left && cursorPoint.x <= x1_right && cursorPoint.y >= y0_top && cursorPoint.y <= y0_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); } else if (cursorPoint.x >= x1_left && cursorPoint.x <= x1_right && cursorPoint.y >= y2_top && cursorPoint.y <= y2_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); } else if (cursorPoint.x >= x2_left && cursorPoint.x <= x2_right && cursorPoint.y >= y0_top && cursorPoint.y <= y0_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)); } else if (cursorPoint.x >= x2_left && cursorPoint.x <= x2_right && cursorPoint.y >= y1_top && cursorPoint.y <= y1_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); } else if (cursorPoint.x >= x2_left && cursorPoint.x <= x2_right && cursorPoint.y >= y2_top && cursorPoint.y <= y2_bottom) { augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); } else augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.MOVE_CURSOR)); } } } else augmentation.setAugmentationCursor(Cursor .getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // Check if cursor falls into the panel title area if (panel.getTitleBounds().contains(cursorPoint)) { if(panel.getIconBounds().contains(cursorPoint)) { augmentation.setAugmentationCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } else { augmentation.setAugmentationCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } } } private void redispatchEvent(MouseEvent e) { Component destination; if (e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_RELEASED) { destination = mousePressedWidget; } else { destination = getDeepestComponentWithMouseListeners(e); } if (destination != null) { if (e.getID() == MouseEvent.MOUSE_PRESSED) { mousePressedWidget = destination; } MouseEvent newEvent; MouseEvent parentNewEvent; Point newPoint = SwingUtilities.convertPoint(Augmentation.this.augmentedPanel, e.getPoint(), destination); if (destination != lastMouseEnteredWidget) { newEvent = new MouseEvent(destination, MouseEvent.MOUSE_ENTERED, e.getWhen(), e .getModifiers(), newPoint.x, newPoint.y, e.getXOnScreen(), e .getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e .getButton()); if (destination.getParent() != null) { newPoint = SwingUtilities.convertPoint(Augmentation.this.augmentedPanel, e.getPoint(), destination.getParent()); parentNewEvent = new MouseEvent(destination.getParent(), MouseEvent.MOUSE_ENTERED, e.getWhen(), e .getModifiers(), newPoint.x, newPoint.y, e.getXOnScreen(), e .getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e .getButton()); destination.getParent().dispatchEvent(parentNewEvent); } destination.dispatchEvent(newEvent); if (lastMouseEnteredWidget != null) { newPoint = SwingUtilities.convertPoint(Augmentation.this.augmentedPanel, e .getPoint(), lastMouseEnteredWidget); newEvent = new MouseEvent(lastMouseEnteredWidget, MouseEvent.MOUSE_EXITED, e .getWhen(), e.getModifiers(), newPoint.x, newPoint.y, e .getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e .isPopupTrigger(), e.getButton()); if (lastMouseEnteredWidget.getParent() != null) { parentNewEvent = new MouseEvent(lastMouseEnteredWidget.getParent(), MouseEvent.MOUSE_EXITED, e.getWhen(), e .getModifiers(), newPoint.x, newPoint.y, e.getXOnScreen(), e .getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e .getButton()); lastMouseEnteredWidget.getParent().dispatchEvent(parentNewEvent); } lastMouseEnteredWidget.dispatchEvent(newEvent); } lastMouseEnteredWidget = destination; } newEvent = new MouseEvent(destination, e.getID(), e.getWhen(), e.getModifiersEx(), newPoint.x, newPoint.y, e.getXOnScreen(), e.getYOnScreen(), e .getClickCount(), e.isPopupTrigger(), e.getButton()); if (destination.getParent() != null) { newPoint = SwingUtilities.convertPoint(Augmentation.this.augmentedPanel, e.getPoint(), destination.getParent()); parentNewEvent = new MouseEvent(destination.getParent(), e.getID(), e.getWhen(), e .getModifiersEx(), newPoint.x, newPoint.y, e.getXOnScreen(), e .getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e .getButton()); destination.getParent().dispatchEvent(parentNewEvent); } destination.dispatchEvent(newEvent); } } private Component getDeepestComponentWithMouseListeners(MouseEvent e) { Component widget = SwingUtilities.getDeepestComponentAt(Augmentation.this.augmentedPanel, e .getX(), e.getY()); while (widget != null && widget != Augmentation.this.augmentedPanel && widget.getMouseListeners().length == 0 && widget.getMouseMotionListeners().length == 0) widget = widget.getParent(); return widget; } public void addHighlights(Collection<Panel> panels) { for (Panel panel : panels) { highlightedPanels.add(panel); } } private Shape createSpotlight(Component c, Rectangle rect, String labelText, FontMetrics fontMetrics, int xOffset) { Point convertedPoint = SwingUtilities.convertPoint(c, rect.getLocation(), augmentedPanel); int x = convertedPoint.x; int y = convertedPoint.y; int substringStart = labelText.toLowerCase().indexOf(spotlightText.toLowerCase()); int substringEnd = substringStart + spotlightText.length(); RoundRectangle2D roundRectangle2D = new RoundRectangle2D.Double(xOffset + x + fontMetrics.charsWidth(labelText.substring(0, substringStart).toCharArray(), 0, substringStart), y, fontMetrics.charsWidth(labelText.substring(substringStart, substringEnd).toCharArray(), 0, spotlightText.length()), rect.getHeight(), rect.getHeight()/2, rect.getHeight()/2); return roundRectangle2D; } private void spotlightText(Container container, Area mask) { for (Component c : container.getComponents()) { if (c.isShowing() && c instanceof JLabel) { String labelText = ((JLabel) c).getText(); if (labelText != null && !labelText.isEmpty()) { if (labelText.toLowerCase().contains(spotlightText.toLowerCase())) { Shape spotlight = createSpotlight(c, new Rectangle(0, 0, c.getWidth(), c.getHeight()), labelText, c.getFontMetrics(c.getFont()), 0); mask.subtract(new Area(spotlight)); } } } else if (c instanceof JList) { JList list = (JList) c; ListModel listModel = list.getModel(); for (int i = 0; i < listModel.getSize(); i++) { Object elementAt = listModel.getElementAt(i); if (elementAt instanceof String) { if (((String) elementAt).toLowerCase().contains(spotlightText.toLowerCase())) { String labelText = (String) elementAt; Rectangle cellBounds = list.getCellBounds(i, i); JLabel label = (JLabel) list.getCellRenderer().getListCellRendererComponent(list, elementAt, i, false, false); Shape shape = createSpotlight(c, cellBounds, labelText, label.getFontMetrics(label.getFont()), label.getInsets().left); mask.subtract(new Area(shape)); } } } } else if (c instanceof Container) { spotlightText((Container) c, mask); } } } @Override protected void paintComponent(Graphics g) { if (isInSpotlightMode()) { spotlight((Graphics2D) g); return; } for (Panel panel : highlightedPanels) highlight(panel, (Graphics2D) g); } private void spotlight(Graphics2D g2) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.black); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); Rectangle2D screen = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); Area mask = new Area(screen); spotlightText(augmentedPanel, mask); g2.fill(mask); } private boolean isInSpotlightMode() { return spotlightText != null && !spotlightText.isEmpty(); } private void highlight(Panel panel, Graphics2D g) { highlightedPanels.add(panel); panel.setTitleBounds(); g.setColor(HIGHLIGHT_COLOR); g.setStroke(new BasicStroke(s)); Point location = panel.getLocation(); g.drawRect(location.x, location.y, panel.getWidth(), panel.getHeight()); /* * (x0, y0) (x1, y0) (x2, y0) (x0, y1) (x2, y1) (x0, y2) (x1, y2) (x2, * y2) */ int x0 = location.x, x1 = location.x + panel.getWidth() / 2, x2 = location.x + panel.getWidth(); int y0 = location.y, y1 = location.y + panel.getHeight() / 2, y2 = location.y + panel.getHeight(); g.drawRect(x0 - h, y0 - h, d, d); g.drawRect(x1 - h, y0 - h, d, d); g.drawRect(x2 - h, y0 - h, d, d); g.drawRect(x0 - h, y1 - h, d, d); g.drawRect(x2 - h, y1 - h, d, d); g.drawRect(x0 - h, y2 - h, d, d); g.drawRect(x1 - h, y2 - h, d, d); g.drawRect(x2 - h, y2 - h, d, d); g.setColor(HIGHLIGHT_COLOR.brighter()); g.fill3DRect(x0 - h, y0 - h, d, d, true); g.fill3DRect(x1 - h, y0 - h, d, d, true); g.fill3DRect(x2 - h, y0 - h, d, d, true); g.fill3DRect(x0 - h, y1 - h, d, d, true); g.fill3DRect(x2 - h, y1 - h, d, d, true); g.fill3DRect(x0 - h, y2 - h, d, d, true); g.fill3DRect(x1 - h, y2 - h, d, d, true); g.fill3DRect(x2 - h, y2 - h, d, d, true); } public void removeHighlights(Collection<Panel> panels) { for (Panel panel : panels) { highlightedPanels.remove(panel); Rectangle bounds = panel.getBounds(); repaint(new Rectangle(Math.max(bounds.x - h, 0), Math.max(bounds.y - h, 0), bounds.width + d, bounds.height + d)); } setAugmentationCursor(Cursor.getPredefinedCursor(Cursor.getDefaultCursor().getType())); } private void setAugmentationCursor(Cursor cursor) { // Get the top level Augmentation Augmentation augmentation = this, originator = this; Container parent = augmentation.getParent(); while (parent != null) { if (parent instanceof CanvasManifestation) augmentation = ((CanvasManifestation) parent).augmentation; parent = parent.getParent(); } originator.setCursor(cursor); augmentation.setCursor(cursor); } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_Augmentation.java
125
addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { if (highlightedPanels.isEmpty()) { redispatchEvent(e); return; } if (Augmentation.this.canvasManifestation.isLocked()) { redispatchEvent(e); return; } selectedPointIfNothingHappens = null; Augmentation augmentation = (Augmentation) e.getSource(); int cursorType = augmentation.getCursor().getType(); Point newLocation = e.getPoint(); switch (cursorType) { case Cursor.MOVE_CURSOR: newLocation = marshalNewLocation(newLocation, e.getLocationOnScreen()); int diffX = newLocation.x - oldLocation.x, diffY = newLocation.y - oldLocation.y; for (Panel panel : highlightedPanels) { Rectangle panelOldBounds = panel.getBounds(); panel.setBounds(panelOldBounds.x + diffX, panelOldBounds.y + diffY, panelOldBounds.width, panelOldBounds.height); } oldLocation = newLocation; break; case Cursor.NE_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldNECornerX = panelOldBounds.x + panelOldBounds.width, oldNECornerY = panelOldBounds.y; int diffWidth = newLocation.x - oldNECornerX, diffHeight = newLocation.y - oldNECornerY; int newWidth = panelOldBounds.width + diffWidth; int newHeight = panelOldBounds.height - diffHeight; if (newWidth > 0 && newHeight > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y + diffHeight, newWidth, newHeight); } break; case Cursor.SE_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSECornerX = panelOldBounds.x + panelOldBounds.width, oldSECornerY = panelOldBounds.y + panelOldBounds.height; int diffWidth = newLocation.x - oldSECornerX, diffHeight = newLocation.y - oldSECornerY; int newWidth = panelOldBounds.width + diffWidth; int newHeight = panelOldBounds.height + diffHeight; if (newWidth > 0 && newHeight > 0) panel .setBounds(panelOldBounds.x, panelOldBounds.y, newWidth, newHeight); } break; case Cursor.SW_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSWCornerX = panelOldBounds.x, oldSWCornerY = panelOldBounds.y + panelOldBounds.height; int diffWidth = newLocation.x - oldSWCornerX, diffHeight = newLocation.y - oldSWCornerY; int newWidth = panelOldBounds.width - diffWidth; int newHeight = panelOldBounds.height + diffHeight; if (newWidth > 0 && newHeight > 0) panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y, newWidth, newHeight); } break; case Cursor.NW_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSWCornerX = panelOldBounds.x, oldSWCornerY = panelOldBounds.y; int diffWidth = newLocation.x - oldSWCornerX, diffHeight = newLocation.y - oldSWCornerY; int newWidth = panelOldBounds.width - diffWidth; int newHeight = panelOldBounds.height - diffHeight; if (newWidth > 0 && newHeight > 0) panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y + diffHeight, newWidth, newHeight); } break; case Cursor.E_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldEEdgeX = panelOldBounds.x + panelOldBounds.width; int diffWidth = newLocation.x - oldEEdgeX; int newWidth = panelOldBounds.width + diffWidth; if (newWidth > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y, newWidth, panelOldBounds.height); } break; case Cursor.S_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldSEdgeY = panelOldBounds.y + panelOldBounds.height; int diffHeight = newLocation.y - oldSEdgeY; int newHeight = panelOldBounds.height + diffHeight; if (newHeight > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y, panelOldBounds.width, newHeight); } break; case Cursor.W_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldWEdgeX = panelOldBounds.x; int diffWidth = newLocation.x - oldWEdgeX; int newWidth = panelOldBounds.width - diffWidth; if (newWidth > 0) panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y, newWidth, panelOldBounds.height); } break; case Cursor.N_RESIZE_CURSOR: if (highlightedPanels.size() == 1) { Panel panel = highlightedPanels.iterator().next(); Rectangle panelOldBounds = panel.getBounds(); int oldNEdgeY = panelOldBounds.y; int diffHeight = newLocation.y - oldNEdgeY; int newHeight = panelOldBounds.height - diffHeight; if (newHeight > 0) panel.setBounds(panelOldBounds.x, panelOldBounds.y + diffHeight, panelOldBounds.width, newHeight); } break; default: redispatchEvent(e); return; } redispatchEvent(e); hasPanelChanged = true; } private Point marshalNewLocation(Point mouseLocation, Point mouseLocationOnScreen) { if (highlightedPanels.isEmpty()) { return mouseLocation; } int smallestX; int smallestY; Iterator<Panel> it = highlightedPanels.iterator(); Panel panel = it.next(); Point bound = panel.getLocationOnScreen(); smallestX = bound.x; smallestY = bound.y; while (it.hasNext()) { panel = it.next(); bound = panel.getLocationOnScreen(); if (bound.x < smallestX) { smallestX = bound.x; } if (bound.y < smallestY) { smallestY = bound.y; } } Point smallestPoint = new Point(smallestX, smallestY); Point returnLocation = new Point(mouseLocation.x, mouseLocation.y); if (invalidHorizontalMovement(smallestPoint, mouseLocationOnScreen, Augmentation.this.canvasManifestation, mouseLocation.x < oldLocation.x)) { returnLocation.x = oldLocation.x + Augmentation.this.canvasManifestation.getLocationOnScreen().x - smallestX; } if (invalidVerticalMovement(smallestPoint, mouseLocationOnScreen, Augmentation.this.canvasManifestation, mouseLocation.y < oldLocation.y)) { returnLocation.y = oldLocation.y + Augmentation.this.canvasManifestation.getLocationOnScreen().y - smallestY; } return returnLocation; } private boolean invalidHorizontalMovement(Point checkPoint, Point mouseLocation, Container parent, boolean leftMoving) { Point parentLoc = parent.getLocationOnScreen(); if ((checkPoint.x <= parentLoc.x) && leftMoving) { return true; } return false; } private boolean invalidVerticalMovement(Point checkPoint, Point mouseLocation, Container parent, boolean upMoving) { Point parentLoc = parent.getLocationOnScreen(); if ((checkPoint.y <= parentLoc.y) && upMoving) { return true; } return false; } @Override public void mouseMoved(MouseEvent e) { Augmentation augmentation = (Augmentation) e.getSource(); for (Panel panel : highlightedPanels) { int currentCursorType = augmentation.getCursor().getType(); setCursorType(augmentation, panel, e.getPoint()); int newCursorType = augmentation.getCursor().getType(); oldLocation = e.getPoint(); if (currentCursorType != newCursorType) { return; } } redispatchEvent(e); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_Augmentation.java
126
addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { redispatchEvent(e); } @Override public void mouseExited(MouseEvent e) { redispatchEvent(e); } @Override public void mousePressed(MouseEvent e) { selectedPointIfNothingHappens = null; // point is not in title area, pass the underlying event to the contents of the panel Augmentation augmentation = (Augmentation) e.getSource(); Point p = e.getLocationOnScreen(); CanvasManifestation canvas = Augmentation.this.canvasManifestation; Panel panel = canvas.findImmediatePanel(p); // Detects if cursor is within the move or resize region. This region includes // d pixels (see field declaration) beyond a panel's width and height. if (panel == null && augmentation.getCursor().getType() != Cursor.DEFAULT_CURSOR) { redispatchEvent(e); return; } if (panel != null && !panel.pointOnBorder(p)) { redispatchEvent(e); return; } if (isPopupTrigger(e)) { showPopupMenu(e); return; } if (e.getClickCount() == 1) { oldLocation = e.getPoint(); if (isDiscontinuousMultiSelection(e)) { canvas.addSingleSelection(p); } else if(canvas.getSelectedPanels().contains(panel)) { canvas.addSingleSelection(p); selectedPointIfNothingHappens = p; } else { canvas.setSingleSelection(p); } if(panel != null) { panel.setTitleBounds(); setCursorType(augmentation, panel, e.getPoint()); } augmentation.repaint(); } else if (isDoubleClick(e)) { panel = augmentation.canvasManifestation.setSingleSelection(p); if (panel != null) { panel.getWrappedManifestation().getManifestedComponent().open(); } } redispatchEvent(e); } @Override public void mouseReleased(MouseEvent e) { if (isPopupTrigger(e)) { showPopupMenu(e); return; } for (Panel panel : highlightedPanels) { Rectangle r = panel.getBounds(); r = panel.marshalBound(r); panel.setBounds(r); } if(selectedPointIfNothingHappens != null) { Augmentation.this.canvasManifestation.setSingleSelection(selectedPointIfNothingHappens); hasPanelChanged = true; } if (hasPanelChanged) { Augmentation.this.canvasManifestation.fireFocusPersist(); Augmentation.this.repaint(); Augmentation.this.canvasManifestation.computePreferredSize(); hasPanelChanged = false; Augmentation.this.canvasManifestation.updateController(highlightedPanels); } redispatchEvent(e); } @Override public void mouseClicked(MouseEvent e) { redispatchEvent(e); } private boolean isDiscontinuousMultiSelection(MouseEvent e) { return e.isControlDown() || e.isMetaDown(); } private boolean isPopupTrigger(MouseEvent e) { return e.isPopupTrigger(); } private boolean isDoubleClick(MouseEvent e) { return (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)); } private void showPopupMenu(MouseEvent e) { Augmentation augmentation = (Augmentation) e.getSource(); Point p = e.getLocationOnScreen(); Panel panel = augmentation.canvasManifestation.findImmediatePanel(p); if (panel != null && !panel.pointInTitle(p)) { redispatchEvent(e); return; } if (!augmentation.canvasManifestation.getSelectedPanels().contains(panel)) { panel = augmentation.canvasManifestation.setSingleSelection(p); } // Don't show the popup if the canvas is in the inspector. // This is because the actions don't use the right canvas. // This causes bug MCT-2250. // This should be re-enabled once the actions use the correct canvas. View m = augmentation.canvasManifestation; while (m != null && m.getInfo() != null) { if (m.getInfo().getViewType() == ViewType.INSPECTOR || m.getInfo().getViewType() == ViewType.CENTER_OWNED_INSPECTOR) { return; } m = (View) SwingUtilities.getAncestorOfClass(View.class, m); } if (panel == null) { MenuManager menuManager = MenuManagerAccess.getMenuManager(); JPopupMenu popupMenu = menuManager.getViewPopupMenu(augmentation.canvasManifestation); if (popupMenu != null) popupMenu.show(augmentation.canvasManifestation, e.getX(), e.getY()); } else { Point panelPoint = panel.getLocationOnScreen(); JPopupMenu popupMenu = panel.getWrappedManifestation() .getManifestationPopupMenu(); if (popupMenu != null) popupMenu.show(panel, p.x - panelPoint.x, p.y - panelPoint.y); } augmentation.repaint(); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_Augmentation.java
127
augmentedPanel, new MarqueSelectionListener.MultipleSelectionProvider() { @Override public void selectPanels(Collection<Panel> selection) { Augmentation.this.canvasManifestation.setSelection(selection); Augmentation.this.repaint(); } @Override public boolean pointInTopLevelPanel(Point p) { return !Augmentation.this.canvasManifestation .isPointinaPanel(p); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_Augmentation.java
128
public class CanvasFormattingControlPanelTest { private Robot robot; private static final ResourceBundle bundle = ResourceBundle.getBundle("CanvasResourceBundle"); //NOI18N @Mock private CanvasManifestation mockCanvasManifestation; @Mock private Panel mockPanel; private static final String TITLE = "Test Frame"; private CanvasFormattingControlsPanel controlPanel; private static Query PANEL_TITLE_FONT_SIZE_SPINNER = new Query().accessibleName(bundle.getString("PANEL_TITLE_FONT_SIZE_SPINNER")); @BeforeMethod public void setUp() { MockitoAnnotations.initMocks(this); robot = BasicRobot.robotWithCurrentAwtHierarchy(); Mockito.when(mockPanel.getBounds()).thenReturn(new Rectangle(0,0,50,50)); Mockito.when(mockPanel.getBorderColor()).thenReturn(Color.gray); GuiActionRunner.execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { controlPanel = new CanvasFormattingControlsPanel( mockCanvasManifestation); controlPanel.informOnePanelSelected(Collections.singletonList(mockPanel)); JFrame frame = new JFrame(TITLE); frame.setName(TITLE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); controlPanel.setOpaque(true); // content panes must be opaque frame.setContentPane(controlPanel); frame.pack(); frame.setVisible(true); } }); } @AfterMethod public void tearDown() { robot.cleanUp(); } public static class DerivedMock extends MockComponent { @Override public Set<ViewInfo> getViewInfos(ViewType type) { return Collections.emptySet(); } } @Test public void testClone() { AbstractComponent canvasComponent = Mockito.mock(AbstractComponent.class); AbstractComponent component = new DerivedMock(); ViewInfo viewInfo = new ViewInfo(CanvasManifestation.class, "", "", ViewType.OBJECT) { @Override public View createView(final AbstractComponent component) { View view = Mockito.mock(View.class); Mockito.when(view.getManifestedComponent()).thenReturn(component); return view; } }; PlatformAccess access = new PlatformAccess(); Platform mockPlatform = Mockito.mock(Platform.class); PersistenceProvider mockPersistenceProvider = Mockito.mock(PersistenceProvider.class); access.setPlatform(mockPlatform); Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider); Mockito.when(mockPersistenceProvider.getComponent(component.getComponentId())).thenReturn(component); MCTViewManifestationInfo manifInfo = Mockito.mock(MCTViewManifestationInfo.class); View view = CanvasViewStrategy.CANVAS_OWNED.createViewFromManifestInfo(viewInfo, component, canvasComponent, manifInfo); Assert.assertEquals(view.getManifestedComponent().getComponentId(), canvasComponent.getComponentId()); } @Test public void testPersistenceIsCalledDuringActions() { int persistentCount = 0; FrameFixture window = WindowFinder.findFrame(TITLE).using(robot); JCheckBoxFixture titleCheckBox = window.checkBox(new CheckBoxMatcher("Panel Title Bar")); titleCheckBox.click(); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); // check that both focus lost and enter will trigger focus for text fields JTextComponentFixture textFixture = window.textBox(new TextFieldMatcher("Panel Title:")); textFixture.enterText("abc").pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_ENTER)); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); titleCheckBox.focus(); // should not fire persistence event if the text hasn't changed Mockito.verify(mockCanvasManifestation,Mockito.times(persistentCount)).fireFocusPersist(); textFixture.focus(); textFixture.enterText("123"); titleCheckBox.focus(); Mockito.verify(mockCanvasManifestation,Mockito.times(persistentCount)).fireFocusPersist(); // check that selecting the border color call persistence JComboBoxFixture colorFixture = window.comboBox(new ComboBoxMatcher("Color:")); colorFixture.selectItem(2); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); window.toggleButton(new JToggleButtonMatcher("All borders")).click(); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); // check the no border button state window.toggleButton(new JToggleButtonMatcher("No borders")).click(); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); window.comboBox(new ComboBoxMatcher("panelTitleFontComboBox")).selectItem("Serif"); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); PANEL_TITLE_FONT_SIZE_SPINNER.spinnerIn(window).select(18); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); persistentCount++; window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleBold")).click(); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); persistentCount++; window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleItalic")).click(); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleUnderline")).click(); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); window.comboBox(new ComboBoxMatcher("panelTitleFontColorComboBox")).selectItem(2); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); window.comboBox(new ComboBoxMatcher("panelTitleBackgroundColorComboBox")).selectItem(2); Mockito.verify(mockCanvasManifestation,Mockito.times(++persistentCount)).fireFocusPersist(); controlPanel.informZeroPanelsSelected(); titleCheckBox.requireDisabled(); textFixture.requireDisabled(); window.toggleButton(new JToggleButtonMatcher("All borders")).requireDisabled(); window.button(new JButtonMatcher("Align to bottom edge")).requireDisabled(); window.comboBox(new ComboBoxMatcher("panelTitleFontComboBox")).requireDisabled(); PANEL_TITLE_FONT_SIZE_SPINNER.spinnerIn(window).requireDisabled(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleBold")).requireDisabled(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleItalic")).requireDisabled(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleUnderline")).requireDisabled(); window.comboBox(new ComboBoxMatcher("panelTitleFontColorComboBox")).requireDisabled(); window.comboBox(new ComboBoxMatcher("panelTitleBackgroundColorComboBox")).requireDisabled(); controlPanel.informMultipleViewPanelsSelected(Collections.<Panel>emptyList()); titleCheckBox.requireEnabled(); textFixture.requireDisabled(); window.toggleButton(new JToggleButtonMatcher("All borders")).requireEnabled(); window.button(new JButtonMatcher("Align to bottom edge")).requireEnabled(); window.comboBox(new ComboBoxMatcher("panelTitleFontComboBox")).requireEnabled(); PANEL_TITLE_FONT_SIZE_SPINNER.spinnerIn(window).requireEnabled(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleBold")).requireEnabled(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleItalic")).requireEnabled(); window.toggleButton(new JToggleButtonMatcher("panelTitleFontStyleUnderline")).requireEnabled(); window.comboBox(new ComboBoxMatcher("panelTitleFontColorComboBox")).requireEnabled(); window.comboBox(new ComboBoxMatcher("panelTitleBackgroundColorComboBox")).requireEnabled(); } private static class JButtonMatcher extends GenericTypeMatcher<JButton> { private final String label; public JButtonMatcher(String label) { super(JButton.class, true); this.label = label; } @Override protected boolean isMatching(JButton cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()) || label.equals(cb.getToolTipText()); } } private static class JToggleButtonMatcher extends GenericTypeMatcher<JToggleButton> { private final String label; public JToggleButtonMatcher(String label) { super(JToggleButton.class, true); this.label = label; } @Override protected boolean isMatching(JToggleButton cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()) || label.equals(cb.getToolTipText()); } } private static class ComboBoxMatcher extends GenericTypeMatcher<JComboBox> { private final String label; public ComboBoxMatcher(String label) { super(JComboBox.class, true); this.label = label; } @Override protected boolean isMatching(JComboBox cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()); } } private static class TextFieldMatcher extends GenericTypeMatcher<JTextField> { private final String label; public TextFieldMatcher(String label) { super(JTextField.class, true); this.label = label; } @Override protected boolean isMatching(JTextField cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()); } } private static class CheckBoxMatcher extends GenericTypeMatcher<JCheckBox> { private final String buttonLabel; public CheckBoxMatcher(String label) { super(JCheckBox.class, true); buttonLabel = label; } @Override protected boolean isMatching(JCheckBox cb) { return buttonLabel.equals(cb.getText()); } } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
129
GuiActionRunner.execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { controlPanel = new CanvasFormattingControlsPanel( mockCanvasManifestation); controlPanel.informOnePanelSelected(Collections.singletonList(mockPanel)); JFrame frame = new JFrame(TITLE); frame.setName(TITLE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); controlPanel.setOpaque(true); // content panes must be opaque frame.setContentPane(controlPanel); frame.pack(); frame.setVisible(true); } });
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
130
ViewInfo viewInfo = new ViewInfo(CanvasManifestation.class, "", "", ViewType.OBJECT) { @Override public View createView(final AbstractComponent component) { View view = Mockito.mock(View.class); Mockito.when(view.getManifestedComponent()).thenReturn(component); return view; } };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
131
private static class CheckBoxMatcher extends GenericTypeMatcher<JCheckBox> { private final String buttonLabel; public CheckBoxMatcher(String label) { super(JCheckBox.class, true); buttonLabel = label; } @Override protected boolean isMatching(JCheckBox cb) { return buttonLabel.equals(cb.getText()); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
132
private static class ComboBoxMatcher extends GenericTypeMatcher<JComboBox> { private final String label; public ComboBoxMatcher(String label) { super(JComboBox.class, true); this.label = label; } @Override protected boolean isMatching(JComboBox cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
133
public static class DerivedMock extends MockComponent { @Override public Set<ViewInfo> getViewInfos(ViewType type) { return Collections.emptySet(); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
134
private static class JButtonMatcher extends GenericTypeMatcher<JButton> { private final String label; public JButtonMatcher(String label) { super(JButton.class, true); this.label = label; } @Override protected boolean isMatching(JButton cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()) || label.equals(cb.getToolTipText()); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
135
private static class JToggleButtonMatcher extends GenericTypeMatcher<JToggleButton> { private final String label; public JToggleButtonMatcher(String label) { super(JToggleButton.class, true); this.label = label; } @Override protected boolean isMatching(JToggleButton cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()) || label.equals(cb.getToolTipText()); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
136
private static class TextFieldMatcher extends GenericTypeMatcher<JTextField> { private final String label; public TextFieldMatcher(String label) { super(JTextField.class, true); this.label = label; } @Override protected boolean isMatching(JTextField cb) { return label.equals(cb.getAccessibleContext().getAccessibleName()); } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlPanelTest.java
137
public class CanvasFormattingController { /** * Construct controller. * */ private CanvasFormattingController() { // } /* Handle notifications from viewer */ public static void notifyXPropertyChange(int newXValue, Panel selectedPanel) { Point existingLocation = selectedPanel.getLocation(); Dimension existingSize = selectedPanel.getBounds().getSize(); selectedPanel.setBounds(newXValue, existingLocation.y, existingSize.width, existingSize.height); } public static void notifyYPropertyChange(int newYValue, Panel selectedPanel) { Point existingLocation = selectedPanel.getLocation(); Dimension existingSize = selectedPanel.getBounds().getSize(); selectedPanel.setBounds(existingLocation.x, newYValue, existingSize.width, existingSize.height); } public static void notifyWidthPropertyChange(int newWdith, List<Panel> selectedPanels) { for (Panel selectedPanel : selectedPanels) { Point existingLocation = selectedPanel.getLocation(); Dimension existingSize = selectedPanel.getBounds().getSize(); selectedPanel.setBounds(existingLocation.x, existingLocation.y, newWdith, existingSize.height); } } public static void notifyHeightPropertyChange(int newHeight, List<Panel> selectedPanels) { for (Panel selectedPanel : selectedPanels) { Point existingLocation = selectedPanel.getLocation(); Dimension existingSize = selectedPanel.getBounds().getSize(); selectedPanel.setBounds(existingLocation.x, existingLocation.y, existingSize.width, newHeight); } } // Alignment public static void notifyAlignLeftSelected(List<Panel> selectedPanels) { int leftMostX = selectedPanels.get(0).getBounds().x; int numOfPanels = selectedPanels.size(); for (int i = 1; i < numOfPanels; i++) { Panel panel = selectedPanels.get(i); Rectangle bound = panel.getBounds(); int oldx = bound.getLocation().x; if (oldx < leftMostX) { leftMostX = oldx; } } for (Panel panel : selectedPanels) { Rectangle bound = panel.getBounds(); int oldy = bound.getLocation().y; int width = bound.getSize().width; int height = bound.getSize().height; panel.setBounds(leftMostX, oldy, width, height); } } public static void notifyAlignCenterHSelected(List<Panel> selectedPanels) { Rectangle firstBound = selectedPanels.get(0).getBounds(); int leftMostX = firstBound.x; int rightMostX = firstBound.x; int numOfPanels = selectedPanels.size(); for (int i = 0; i < numOfPanels; i++) { Panel panel = selectedPanels.get(i); Rectangle bound = panel.getBounds(); int oldx = bound.x; int width = bound.width; if (oldx < leftMostX) leftMostX = oldx; if (oldx + width > rightMostX) rightMostX = oldx + width; } for (Panel panel : selectedPanels) { Rectangle bound = panel.getBounds(); // // Algorithm: the bounding box is determined by finding the // rightmost edge // along with the left most edge. The difference between // these two points is the area lengthwise of the bounding box. // // distance = rightMostX - leftMostX; // // Thus, the center of the bounding area would be the would // be the x position that is midway between the bounding length // added to the leftmost edge: // // midwayPoint = leftMostX + (distance / 2); // // So, to center align each box in the bounding box, find that // component's midway point (x pos + (width / 2)). // move that component such that it's midway // point is equal to the bounding box midway point. Thus, // all items are aligned. int midwayPoint = leftMostX + ((rightMostX - leftMostX) / 2); int componentMidwayPoint = bound.x + (bound.width / 2); if (componentMidwayPoint > midwayPoint) { // it's to the right of // the center - move it // back int diff = componentMidwayPoint - midwayPoint; panel.setBounds(bound.x - diff, bound.y, bound.width, bound.height); } else { // it's to the left of center - move it towards the // center... int diff = midwayPoint - componentMidwayPoint; panel.setBounds(bound.x + diff, bound.y, bound.width, bound.height); } } } public static void notifyAlignRightSelected(List<Panel> selectedPanels) { int rightMostX = selectedPanels.get(0).getBounds().x+selectedPanels.get(0).getBounds().width; int numOfPanels = selectedPanels.size(); for (int i = 1; i < numOfPanels; i++) { Panel panel = selectedPanels.get(i); Rectangle bound = panel.getBounds(); int oldx = bound.x; int width = bound.width; if (oldx + width > rightMostX) rightMostX = oldx + width; } for (Panel panel : selectedPanels) { Rectangle bound = panel.getBounds(); int width = bound.width; panel.setBounds(rightMostX - width, bound.y, width, bound.height); } } public static void notifyAlignTopSelected(List<Panel> selectedPanels) { int topMostY = selectedPanels.get(0).getBounds().y; int numOfPanels = selectedPanels.size(); for (int i = 1; i < numOfPanels; i++) { Panel panel = selectedPanels.get(i); Rectangle bound = panel.getBounds(); int oldy = bound.y; if (oldy < topMostY) topMostY = oldy; } for (Panel panel : selectedPanels) { Rectangle bound = panel.getBounds(); panel.setBounds(bound.x, topMostY, bound.width, bound.height); } } public static void notifyAlignBottomSelected(List<Panel> selectedPanels) { int bottomMostY = selectedPanels.get(0).getBounds().y+selectedPanels.get(0).getBounds().height; int numOfPanels = selectedPanels.size(); for (int i = 1; i < numOfPanels; i++) { Panel panel = selectedPanels.get(i); Rectangle bound = panel.getBounds(); int oldy = bound.y; int height = bound.height; if (oldy + height > bottomMostY) bottomMostY = oldy + height; } for (Panel panel : selectedPanels) { Rectangle bound = panel.getBounds(); int height = bound.height; panel.setBounds(bound.x, bottomMostY - height, bound.width, height); } } public static void notifyAlignVCenterSelected(List<Panel> selectedPanels) { Rectangle firstBound = selectedPanels.get(0).getBounds(); int topMostY = firstBound.y; int bottomMostY = firstBound.y; int numOfPanels = selectedPanels.size(); for (int i = 0; i < numOfPanels; i++) { Panel panel = selectedPanels.get(i); Rectangle bound = panel.getBounds(); int oldy = bound.y; int height = bound.height; if (oldy < topMostY) topMostY = oldy; if (oldy + height > bottomMostY) bottomMostY = oldy + height; } for (Panel panel : selectedPanels) { Rectangle bound = panel.getBounds(); int midPoint = topMostY + ((bottomMostY - topMostY) / 2); int componentMidPoint = bound.y + (bound.height / 2); if (componentMidPoint > midPoint) { int diff = componentMidPoint - midPoint; panel.setBounds(bound.x, bound.y - diff, bound.width, bound.height); } else { // it's to the left of center - move it towards the // center... int diff = midPoint - componentMidPoint; panel.setBounds(bound.x, bound.y + diff, bound.width, bound.height); } } } // Borders public static void notifyWestBorderStatus(boolean status, List<Panel> selectedPanels) { if (status) { for (Panel panel : selectedPanels) { panel.addPanelBorder(PanelBorder.WEST_BORDER); } } else { for (Panel panel : selectedPanels) { panel.removePanelBorder(PanelBorder.WEST_BORDER); } } } public static void notifyEastBorderStatus(boolean status, List<Panel> selectedPanels) { if (status) { for (Panel panel : selectedPanels) { panel.addPanelBorder(PanelBorder.EAST_BORDER); } } else { for (Panel panel : selectedPanels) { panel.removePanelBorder(PanelBorder.EAST_BORDER); } } } public static void notifyNorthBorderStatus(boolean status, List<Panel> selectedPanels) { if (status) { for (Panel panel : selectedPanels) { panel.addPanelBorder(PanelBorder.NORTH_BORDER); } } else { for (Panel panel : selectedPanels) { panel.removePanelBorder(PanelBorder.NORTH_BORDER); } } } public static void notifySouthBorderStatus(boolean status, List<Panel> selectedPanels) { if (status) { for (Panel panel : selectedPanels) { panel.addPanelBorder(PanelBorder.SOUTH_BORDER); } } else { for (Panel panel : selectedPanels) { panel.removePanelBorder(PanelBorder.SOUTH_BORDER); } } } public static void notifyAllBorderStatus(boolean status, List<Panel> selectedPanels) { if (status) { for (Panel panel : selectedPanels) { panel.addPanelBorder(PanelBorder.ALL_BORDERS); } } else { for (Panel panel : selectedPanels) { panel.removePanelBorder(PanelBorder.ALL_BORDERS); } } } public static void notifyBorderColorSelected(Color selectedColor, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setBorderColor(selectedColor); } } public static void notifyBorderFormattingStyle(int style, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setBorderStyle(style); } } public static void notifyTitleBarStatus(boolean status, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.hideTitle(status); } } /** Set the title font in the panel * @param fontFamilyName * @param selectedPanels */ public static void notifyTitleBarFontSelected(String fontFamilyName, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitleFont(fontFamilyName); } } /** Set the the title font size for the panel * @param fontSize * @param selectedPanels */ public static void notifyTitleBarFontSizeSelected(Integer fontSize, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitleFontSize(fontSize); } } /** Set the Title font style for the panel * @param fontStyle * @param selectedPanels */ public static void notifyTitleBarFontStyleSelected(Integer fontStyle, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitleFontStyle(fontStyle); } } /** Set the Title font text attribute (underline) for the panel * @param fontStyle * @param selectedPanels */ public static void notifyTitleBarFontUnderlineSelected(Integer fontStyle, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitleFontUnderline(fontStyle); } } /** Set the title font color for the panel * @param fontForegroundColor * @param selectedPanels */ public static void notifyTitleBarFontForegroundColorSelected(Integer fontForegroundColor, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitleFontForegroundColor(fontForegroundColor); } } /** Set the title background color for the panel * @param fontBackgroundColor * @param selectedPanels */ public static void notifyTitleBarFontBackgroundColorSelected(Integer fontBackgroundColor, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitleFontBackgroundColor(fontBackgroundColor); } } static void notifyNewTitle(String newTitle, List<Panel> selectedPanels) { for (Panel panel : selectedPanels) { panel.setTitle(newTitle); } } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingController.java
138
public class CanvasFormattingControllerTest { private List<Panel> selectedPanels = new ArrayList<Panel>(); @Mock private AbstractComponent mockComponent; @Mock private PanelFocusSelectionProvider panelFocusSelectionProvider; @Mock private ViewInfo mockIconInfo; @Mock private ViewInfo mockTitleInfo; @Mock private View mockIconView; @Mock private View mockTitleView; private ViewInfo canvasViewInfo; @BeforeMethod public void setup() { MockitoAnnotations.initMocks(this); canvasViewInfo = new ViewInfo(CanvasManifestation.class, "", ViewType.OBJECT); Mockito.when(mockIconInfo.createView(Mockito.any(AbstractComponent.class))).thenReturn(mockIconView); Mockito.when(mockTitleInfo.createView(Mockito.any(AbstractComponent.class))).thenReturn(mockTitleView); Mockito.when(mockComponent.getViewInfos(ViewType.TITLE)).thenReturn(Collections.singleton(mockTitleInfo)); Mockito.when(mockComponent.getDisplayName()).thenReturn("test comp"); Mockito.when(mockComponent.getComponents()).thenReturn( Collections.<AbstractComponent> emptyList()); } @AfterMethod public void tearDown() { this.selectedPanels.clear(); } private View addManifestInfo(View v) { v.putClientProperty(CanvasManifestation.MANIFEST_INFO, new MCTViewManifestationInfoImpl()); return v; } @SuppressWarnings("serial") @Test public void notifyXPropertyChangeTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; Panel panel = new Panel(addManifestInfo(canvas1), panelFocusSelectionProvider); int origX = panel.getBounds().x; CanvasFormattingController.notifyXPropertyChange(origX + 1000, panel); int newX = panel.getBounds().x; Assert.assertFalse(origX == newX); Assert.assertEquals(newX, origX + 1000); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().x, newX); } @SuppressWarnings("serial") @Test public void notifyYPropertyChangeTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; Panel panel = new Panel(addManifestInfo(canvas1), panelFocusSelectionProvider); int origY = panel.getBounds().y; CanvasFormattingController.notifyYPropertyChange(origY + 1000, panel); int newY = panel.getBounds().y; Assert.assertFalse(origY == newY); Assert.assertEquals(newY, origY + 1000); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().y, newY); } @SuppressWarnings("serial") @Test public void notifyWidthPropertyChangeTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); selectedPanels.add(panel); CanvasFormattingController.notifyWidthPropertyChange(1000, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Rectangle origBound = panel.getOrigBound(); Assert.assertFalse(origBound.width == newBound.width); Assert.assertEquals(newBound.width, 1000); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getDimension().width, 1000); } } @SuppressWarnings("serial") @Test public void notifyHeightPropertyChangeTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); selectedPanels.add(panel); CanvasFormattingController.notifyHeightPropertyChange(2000, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Rectangle origBound = panel.getOrigBound(); Assert.assertFalse(origBound.height == newBound.height); Assert.assertEquals(newBound.height, 2000); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getDimension().height, 2000); } } @SuppressWarnings("serial") @Test public void notifyAlignLeftSelectedTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(150, 200, 100, 100); selectedPanels.add(panel); CanvasFormattingController.notifyAlignLeftSelected(selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Assert.assertEquals(newBound.x, 100); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().x, 100); } } @SuppressWarnings("serial") @Test public void notifyAlignCenterHSelectedTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(150, 100, 100, 100); selectedPanels.add(panel); CanvasFormattingController.notifyAlignCenterHSelected(selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Assert.assertEquals(newBound.x, 125); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().x, 125); } } @SuppressWarnings("serial") @Test public void notifyAlignRightSelectedTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyAlignRightSelected(selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Assert.assertEquals(newBound.x + newBound.width, 200); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().x + info.getDimension().width, 200); } // try a single panel CanvasManifestation canvas3 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas3), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); Rectangle orig = panel.getBounds(); selectedPanels.clear(); selectedPanels.add(panel); CanvasFormattingController.notifyAlignRightSelected(selectedPanels); Assert.assertEquals(panel.getBounds(), orig); } @SuppressWarnings("serial") @Test public void notifyAlignTopSelectedTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyAlignTopSelected(selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Assert.assertEquals(newBound.y, 100); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().y, 100); } } @SuppressWarnings("serial") @Test public void notifyAlignBottomSelectedTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvasManifestation1 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } }; TestPanel panel = new TestPanel(addManifestInfo(canvasManifestation1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvasManifestation2 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } }; panel = new TestPanel(addManifestInfo(canvasManifestation2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyAlignBottomSelected(selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Rectangle newBound = panel.getBounds(); Assert.assertEquals(newBound.y + newBound.height, 300); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().y + info.getDimension().height, 300); } // try a single panel selectedPanels.clear(); panel = new TestPanel(addManifestInfo(canvasManifestation2), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); Rectangle orig = panel.getBounds(); selectedPanels.add(panel); CanvasFormattingController.notifyAlignBottomSelected(selectedPanels); Assert.assertEquals(panel.getBounds(), orig); } @SuppressWarnings("serial") @Test public void notifyAlignVCenterSelected() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 50); selectedPanels.add(panel); CanvasFormattingController.notifyAlignVCenterSelected(selectedPanels); panel = (TestPanel) selectedPanels.get(0); Rectangle newBound = panel.getBounds(); Assert.assertEquals(newBound.y, 150); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().y, 150); panel = (TestPanel) selectedPanels.get(1); newBound = panel.getBounds(); Assert.assertEquals(newBound.y, 175); info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getStartPoint().y, 175); } @SuppressWarnings("serial") @Test public void notifyWestBorderStatusTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyWestBorderStatus(true, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertTrue(PanelBorder.hasWestBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertTrue(PanelBorder.hasWestBorder(Byte.parseByte(panelBorderStr))); } CanvasFormattingController.notifyWestBorderStatus(false, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertFalse(PanelBorder.hasWestBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertFalse(PanelBorder.hasWestBorder(Byte.parseByte(panelBorderStr))); } } @SuppressWarnings("serial") @Test public void notifyEastBorderStatusTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyEastBorderStatus(true, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertTrue(PanelBorder.hasEastBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertTrue(PanelBorder.hasEastBorder(Byte.parseByte(panelBorderStr))); } CanvasFormattingController.notifyEastBorderStatus(false, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertFalse(PanelBorder.hasEastBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertFalse(PanelBorder.hasEastBorder(Byte.parseByte(panelBorderStr))); } } @SuppressWarnings("serial") @Test public void notifyNorthBorderStatusTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyNorthBorderStatus(true, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertTrue(PanelBorder.hasNorthBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertTrue(PanelBorder.hasNorthBorder(Byte.parseByte(panelBorderStr))); } CanvasFormattingController.notifyNorthBorderStatus(false, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertFalse(PanelBorder.hasNorthBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertFalse(PanelBorder.hasNorthBorder(Byte.parseByte(panelBorderStr))); } } @SuppressWarnings("serial") @Test public void notifySouthBorderStatusTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifySouthBorderStatus(true, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertTrue(PanelBorder.hasSouthBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertTrue(PanelBorder.hasSouthBorder(Byte.parseByte(panelBorderStr))); } CanvasFormattingController.notifySouthBorderStatus(false, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertFalse(PanelBorder.hasSouthBorder(panelBorder)); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertFalse(PanelBorder.hasSouthBorder(Byte.parseByte(panelBorderStr))); } } @SuppressWarnings("serial") @Test public void notifyAllBorderStatusTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyAllBorderStatus(true, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertEquals(panelBorder, PanelBorder.ALL_BORDERS); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertEquals(Byte.parseByte(panelBorderStr), PanelBorder.ALL_BORDERS); } CanvasFormattingController.notifyAllBorderStatus(false, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; byte panelBorder = panel.getBorderState(); Assert.assertEquals(panelBorder, PanelBorder.NO_BORDER); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); String panelBorderStr = info.getInfoProperty(ControlAreaFormattingConstants.PANEL_BORDER_PROPERTY); Assert.assertEquals(Byte.parseByte(panelBorderStr), PanelBorder.NO_BORDER); } } @SuppressWarnings("serial") @Test public void notifyBorderColorSelectedTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyBorderColorSelected(Color.red, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Color borderColor = panel.getBorderColor(); Assert.assertEquals(borderColor, Color.red); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getBorderColor(), Color.red); } } @SuppressWarnings("serial") @Test public void notifyBorderFormattingStyleTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyBorderFormattingStyle(BorderStyle.MIXED.ordinal(), selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; int borderStyle = panel.getBorderStyle(); Assert.assertEquals(borderStyle, BorderStyle.MIXED.ordinal()); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getBorderStyle(), BorderStyle.MIXED.ordinal()); } } @SuppressWarnings("serial") @Test public void notifyTitleBarStatusTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarStatus(true, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertTrue(panel.hasTitle()); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertTrue(info.hasTitlePanel()); } CanvasFormattingController.notifyTitleBarStatus(false, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertFalse(panel.hasTitle()); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertFalse(info.hasTitlePanel()); } } @SuppressWarnings("serial") @Test public void notifyNewTitleTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyNewTitle("new Title", selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitle(), "new Title"); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitle(), "new Title"); } } @SuppressWarnings("serial") @Test public void notifyNewTitleFontTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarFontSelected("Monospaced", selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFont(), "Monospaced"); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFont(), "Monospaced"); } } @SuppressWarnings("serial") @Test public void notifyNewTitleFontSizeTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarFontSizeSelected(20, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontSize().intValue(), 20); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontSize().intValue(), 20); } } @SuppressWarnings("serial") @Test public void notifyNewTitleFontStyleTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarFontStyleSelected(Font.BOLD, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontStyle().intValue(), Font.BOLD); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontStyle().intValue(), Font.BOLD); } CanvasFormattingController.notifyTitleBarFontStyleSelected(Font.ITALIC, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontStyle().intValue(), Font.ITALIC); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontStyle().intValue(), Font.ITALIC); } CanvasFormattingController.notifyTitleBarFontStyleSelected(Font.BOLD + Font.ITALIC, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontStyle().intValue(), Font.BOLD+ Font.ITALIC); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontStyle().intValue(), Font.BOLD+ Font.ITALIC); } } @SuppressWarnings("serial") @Test public void notifyNewTitleFontUnderlineTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarFontUnderlineSelected(TextAttribute.UNDERLINE_ON, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontUnderline().intValue(), TextAttribute.UNDERLINE_ON.intValue()); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontUnderline().intValue(), TextAttribute.UNDERLINE_ON.intValue()); } CanvasFormattingController.notifyTitleBarFontUnderlineSelected(ControlAreaFormattingConstants.UNDERLINE_OFF, selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontUnderline().intValue(), ControlAreaFormattingConstants.UNDERLINE_OFF); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontUnderline().intValue(), ControlAreaFormattingConstants.UNDERLINE_OFF); } } @SuppressWarnings("serial") @Test public void notifyNewTitleFontForegroundColorTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarFontForegroundColorSelected(Color.decode("#0000FF").getRGB(), selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontForegroundColor().intValue(), Color.decode("#0000FF").getRGB()); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontForegroundColor().intValue(), Color.decode("#0000FF").getRGB()); } } @SuppressWarnings("serial") @Test public void notifyNewTitleFontBackgroundColorTest() { final ExtendedProperties viewProps = new ExtendedProperties(); CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; TestPanel panel = new TestPanel(addManifestInfo(canvas1), panelFocusSelectionProvider); panel.setBounds(100, 200, 100, 100); selectedPanels.add(panel); CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; }; panel = new TestPanel(addManifestInfo(canvas2), panelFocusSelectionProvider); panel.setBounds(100, 100, 50, 100); selectedPanels.add(panel); CanvasFormattingController.notifyTitleBarFontBackgroundColorSelected(Color.decode("#0000FF").getRGB(), selectedPanels); for (Panel p : selectedPanels) { panel = (TestPanel) p; Assert.assertEquals(panel.getTitleFontBackgroundColor().intValue(), Color.decode("#0000FF").getRGB()); MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation()); Assert.assertEquals(info.getPanelTitleFontBackgroundColor().intValue(), Color.decode("#0000FF").getRGB()); } } private static final class TestPanel extends Panel { private static final long serialVersionUID = 1L; private Rectangle origBound; public TestPanel(View manifestation, PanelFocusSelectionProvider panelSelectionProvider) { super(manifestation, panelSelectionProvider); this.origBound = getBounds(); } public Rectangle getOrigBound() { return this.origBound; } } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
139
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
140
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
141
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
142
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
143
CanvasManifestation canvas3 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
144
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
145
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
146
CanvasManifestation canvasManifestation1 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
147
CanvasManifestation canvasManifestation2 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
148
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
149
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
150
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
151
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
152
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
153
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
154
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
155
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
156
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
157
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
158
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
159
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
160
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
161
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
162
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
163
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
164
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
165
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
166
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
167
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
168
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
169
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
170
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
171
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
172
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
173
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
174
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
175
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
176
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
177
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
178
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
179
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
180
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
181
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
182
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
183
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
184
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
185
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
186
CanvasManifestation canvas2 = new CanvasManifestation(mockComponent,canvasViewInfo) { @Override public ExtendedProperties getViewProperties() { return viewProps; } };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
187
CanvasManifestation canvas1 = new CanvasManifestation(mockComponent,canvasViewInfo) { public ExtendedProperties getViewProperties() { return viewProps; }; };
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
188
private static final class TestPanel extends Panel { private static final long serialVersionUID = 1L; private Rectangle origBound; public TestPanel(View manifestation, PanelFocusSelectionProvider panelSelectionProvider) { super(manifestation, panelSelectionProvider); this.origBound = getBounds(); } public Rectangle getOrigBound() { return this.origBound; } }
false
canvas_src_test_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControllerTest.java
189
public class CanvasFormattingControlsPanel extends JPanel { private static final long serialVersionUID = 4964666916367162577L; // Canvas origin is -7,-7. use this constant to correctly display in // formatting to 0,0 private static final int CORRECTION_OFFSET = 0; // Row and column numbers on individual formatting panels. private static final int POSTION_PANEL_NUMBER_ROWS = 2; private static final int POSTION_PANEL_NUMBER_COLUMNS = 1; // Input field sizes. private static final int POS_AND_DIPANEL_XY_TEXT_FIELD_WIDTH = 2; private static final int MISCELLANEOUS_PANEL_PANEL_TITLE_FIELD_SIZE = 15; // Text appearing on pallet private static final String POSITION_AND_DIMENSION_TITLE = "Position & Dimensions"; private static final String BORDERS_TITLE = "Borders"; private static final String ALIGNMENT_TITLE = "Alignment"; private static final String MISCELLANEOUS_TITLE = "Miscellaneous"; private static final String BORDER_STYLE_CAPTION = "Style:"; private static final String BORDER_COLOR_CAPTION = "Color:"; private static final String PANEL_TITLE_BAR = "Panel Title Bar"; private static final String PANEL_TITLE = "Panel Title:"; private static final String POS_AND_DIPANEL_XY_LABEL = "(x,y): "; private static final String POS_AND_DIPANEL_XY_OPEN_BRACE = "("; private static final String POS_AND_DIPANEL_XY_CLOSE_BRACE = ")"; private static final String POS_AND_DIPANEL_XY_DELIMITER = ","; // GridBag constraint settings private static final double POS_AND_DIPANEL_WEIGHT_Y = 1.0; private static final double POS_AND_DIPANEL_WEIGHT_X = 0; private static final double BORDERS_PANEL_WEIGHT_Y = 1.0; private static final double BORDERS_PANEL_WEIGHT_X = 0; private static final double ALIGNMENT_PANEL_WEIGHT_Y = 1.0; private static final double ALIGNMENT_PANEL_WEIGHT_X = 0; private static final double MISCELLANEOUS_PANEL_WEIGHT_Y = 1.0; private static final double MISCELLANEOUS_PANEL_WEIGHT_X = 1.0; private static final double SEPARATOR_WEIGHT_Y = 1.0; private static final double SEPARATOR_WEIGHT_X = 0; private static final double MISC_PANEL_WEIGHT_Y = 0; // Small control buttons on Borders and Alignment panels private static final double SMALL_CONTROL_BUTTON_WEIGHT_Y = 1.0; private static final double SMALL_CONTROL_BUTTON_WEIGHT_X = 0; private static final int SMALL_CONTROL_BUTTON_IPAD_X = 5; // Button formatting. Provides the small tight square look for border and // alignment control buttons private static final int BUTTON_BORDER_STYLE_TOP = 1; private static final int BUTTON_BORDER_STYLE_LEFT = 0; private static final int BUTTON_BORDER_STYLE_BOTTOM = 0; private static final int BUTTON_BORDER_STYLE_RIGHT = 0; // Height/Width Spinner Constraints. private static final int SPINNER_INIT_VALUE = 0; private static final int SPINNER_MIN_VALUE = 0; private static final int SPINNER_MAX_VALUE = 10000; // upper bound on canvas // size. private static final int SPINNER_STEP_SIZE = 1; private static final int IPAD_X = 5; /** The resource bundle we should use for getting strings. */ private static final ResourceBundle bundle = ResourceBundle.getBundle("CanvasResourceBundle"); //NOI18N // Class visible GUI controls // Enables listeners to be disabled when updating panel state. private boolean listenersEnabled = true; // Position & Dimensions Panel private JSpinner positionXSpinner = null; private JSpinner positionYSpinner = null; private JSpinner dimensionVerticalSpinner = null; private JSpinner dimensionHorizontalSpinner = null; // Borders Panel private JToggleButton leftBorderButton = null; private JToggleButton rightBorderButton = null; private JToggleButton topBorderButton = null; private JToggleButton bottomBorderButton = null; private JToggleButton fullBorderButton = null; private JToggleButton noBorderButton = null; private JComboBox borderStyleComboBox = null; private JComboBox borderColorComboBox = null; // Panel Title Bar Formatting private JCheckBox miscPanelTitleBarCheckBox = null; private JFormattedTextField miscPanelTitleField = null; private JComboBox panelTitleFont = null; private JSpinner panelTitleFontSize; private JComboBox panelTitleFontColorComboBox; private JComboBox panelTitleBackgroundColorComboBox; private JToggleButton panelTitleFontStyleBold; private JToggleButton panelTitleFontStyleItalic; private JToggleButton panelTitleFontUnderline; private final CanvasManifestation managedCanvas; // alignment Panel private JButton alignTableLeftButton; private JButton alignTableRightButton; private JButton alignTableTopButton; private JButton alignTableBottomButton; private JButton alignTableCenterVerticleButton; private JButton alignTableCenterHorizontalButton; CanvasFormattingControlsPanel(CanvasManifestation managedCanvas) { this.managedCanvas = managedCanvas; setLayout(new BorderLayout()); createDefaultCanvasFormmatingControlsPanel(); // Nothing selected when first initialized, disable GUI controls this.setGUIControlsStatusForZeroSelect(); } private void enableBorderButtons(boolean enabled) { leftBorderButton.setEnabled(enabled); rightBorderButton.setEnabled(enabled); topBorderButton.setEnabled(enabled); bottomBorderButton.setEnabled(enabled); fullBorderButton.setEnabled(enabled); noBorderButton.setEnabled(enabled); } private void enableAlignmentButtons(boolean enabled) { alignTableLeftButton.setEnabled(enabled); alignTableRightButton.setEnabled(enabled); alignTableTopButton.setEnabled(enabled); alignTableBottomButton.setEnabled(enabled); alignTableCenterVerticleButton.setEnabled(enabled); alignTableCenterHorizontalButton.setEnabled(enabled); } private void createDefaultCanvasFormmatingControlsPanel() { JPanel controlPanel = new JPanel(new GridBagLayout()); // Create top-level panels JPanel positionAndDimensionsPanel = createPositionAndDimensionsPanel(); JPanel bordersPanel = createBordersPanel(); JPanel alignmentPanel = createAlignmentPanel(); JPanel miscellaneousPanel = createMiscellaneousPanel(); JPanel panelTitleFormattingPanel = createPanelTitleFormattingPanel(); GridBagConstraints positionAndDimensionsPanelConstraints = new GridBagConstraints(); // PositionAndDimensions Panel positionAndDimensionsPanelConstraints.fill = GridBagConstraints.NONE; positionAndDimensionsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; positionAndDimensionsPanelConstraints.weighty = POS_AND_DIPANEL_WEIGHT_Y; positionAndDimensionsPanelConstraints.weightx = POS_AND_DIPANEL_WEIGHT_X; positionAndDimensionsPanelConstraints.insets = new Insets(1, IPAD_X, 0, IPAD_X); controlPanel.add(positionAndDimensionsPanel, positionAndDimensionsPanelConstraints); // Separator JSeparator separator1 = new JSeparator(SwingConstants.VERTICAL); GridBagConstraints separatorConstraints = new GridBagConstraints(); separatorConstraints.fill = GridBagConstraints.BOTH; separatorConstraints.weighty = SEPARATOR_WEIGHT_Y; separatorConstraints.weightx = SEPARATOR_WEIGHT_X; separatorConstraints.insets = new Insets(1, 0, 0, 0); controlPanel.add(separator1, separatorConstraints); // Borders Panel GridBagConstraints bordersPanelConstraints = new GridBagConstraints(); bordersPanelConstraints.fill = GridBagConstraints.NONE; bordersPanelConstraints.anchor = GridBagConstraints.NORTHWEST; bordersPanelConstraints.weighty = BORDERS_PANEL_WEIGHT_Y; bordersPanelConstraints.weightx = BORDERS_PANEL_WEIGHT_X; bordersPanelConstraints.insets = new Insets(1, IPAD_X, 0, IPAD_X); controlPanel.add(bordersPanel, bordersPanelConstraints); // Separator JSeparator separator2 = new JSeparator(SwingConstants.VERTICAL); controlPanel.add(separator2, separatorConstraints); // Alignment Panel GridBagConstraints alignmentPanelConstraints = new GridBagConstraints(); alignmentPanelConstraints.fill = GridBagConstraints.NONE; alignmentPanelConstraints.anchor = GridBagConstraints.NORTHWEST; alignmentPanelConstraints.weighty = ALIGNMENT_PANEL_WEIGHT_Y; alignmentPanelConstraints.weightx = ALIGNMENT_PANEL_WEIGHT_X; alignmentPanelConstraints.insets = new Insets(1, IPAD_X, 0, IPAD_X); controlPanel.add(alignmentPanel, alignmentPanelConstraints); // Separator JSeparator separator3 = new JSeparator(SwingConstants.VERTICAL); controlPanel.add(separator3, separatorConstraints); // Panel Title Format Panel GridBagConstraints panelTitleFormatConstraints = new GridBagConstraints(); panelTitleFormatConstraints.fill = GridBagConstraints.NONE; panelTitleFormatConstraints.anchor = GridBagConstraints.NORTHWEST; panelTitleFormatConstraints.weighty = ALIGNMENT_PANEL_WEIGHT_Y; panelTitleFormatConstraints.weightx = ALIGNMENT_PANEL_WEIGHT_X; panelTitleFormatConstraints.insets = new Insets(1, IPAD_X, 0, IPAD_X); controlPanel.add(panelTitleFormattingPanel, panelTitleFormatConstraints); // Separator JSeparator separator4 = new JSeparator(SwingConstants.VERTICAL); controlPanel.add(separator4, separatorConstraints); // Miscellaneous Panel GridBagConstraints miscellaneousPanelConstraints = new GridBagConstraints(); miscellaneousPanelConstraints.fill = GridBagConstraints.HORIZONTAL; miscellaneousPanelConstraints.anchor = GridBagConstraints.NORTHWEST; miscellaneousPanelConstraints.weightx = MISCELLANEOUS_PANEL_WEIGHT_X; miscellaneousPanelConstraints.weighty = MISCELLANEOUS_PANEL_WEIGHT_Y; miscellaneousPanelConstraints.insets = new Insets(1, IPAD_X, 0, IPAD_X); controlPanel.add(miscellaneousPanel, miscellaneousPanelConstraints); // Layout top-level panel add(controlPanel); } private JPanel createPositionAndDimensionsPanel() { JPanel positionAndDimensionsPanel = new JPanel(); // Border layout - PAGE_START for panel title and CENTER for the // controls positionAndDimensionsPanel.setLayout(new BorderLayout()); // Add title. JLabel positionAndDimensionsTitleLabel = new JLabel(POSITION_AND_DIMENSION_TITLE); positionAndDimensionsPanel.add(positionAndDimensionsTitleLabel, BorderLayout.PAGE_START); // Inner panel to hold position and dimension controls. // These are divided over two subpanels and attached to this panel. JPanel positionInnerPanel = new JPanel(); positionInnerPanel.setLayout(new GridLayout(POSTION_PANEL_NUMBER_ROWS, POSTION_PANEL_NUMBER_COLUMNS)); positionAndDimensionsPanel.add(positionInnerPanel, BorderLayout.CENTER); // Position Controls JPanel positionControlsInnerPanel = new JPanel(); positionControlsInnerPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel xyLabel = new JLabel(POS_AND_DIPANEL_XY_LABEL); xyLabel.setToolTipText("X and Y positions"); SpinnerNumberModel xSpinnerModel = new SpinnerNumberModel(SPINNER_INIT_VALUE, SPINNER_MIN_VALUE, SPINNER_MAX_VALUE, SPINNER_STEP_SIZE); positionXSpinner = new JSpinner(xSpinnerModel); positionXSpinner.setToolTipText("X position"); JFormattedTextField xTextField = getTextField(positionXSpinner); positionXSpinner.setName("Position&DimensionsPanel_xTextField"); xTextField.setColumns(POS_AND_DIPANEL_XY_TEXT_FIELD_WIDTH); SpinnerNumberModel ySpinnerModel = new SpinnerNumberModel(SPINNER_INIT_VALUE, SPINNER_MIN_VALUE, SPINNER_MAX_VALUE, SPINNER_STEP_SIZE); positionYSpinner = new JSpinner(ySpinnerModel); positionYSpinner.setToolTipText("Y position"); JFormattedTextField yTextField = getTextField(positionYSpinner); positionYSpinner.setName("Position&DimensionsPanel_yTextField"); yTextField.setColumns(POS_AND_DIPANEL_XY_TEXT_FIELD_WIDTH); // Attach listeners positionXSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (selectedPanels != null && selectedPanels.size() == 1) { Panel selectedPanel = selectedPanels.get(0); int newXLocation = ((Integer) positionXSpinner.getValue()).intValue() - CORRECTION_OFFSET; if (selectedPanel.getLocation().x != newXLocation) { CanvasFormattingController.notifyXPropertyChange(newXLocation, selectedPanel); managedCanvas.fireFocusPersist(); } } } }); positionYSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (selectedPanels != null && selectedPanels.size() == 1) { Panel selectedPanel = selectedPanels.get(0); int newYLocation = ((Integer) positionYSpinner.getValue()).intValue() - CORRECTION_OFFSET; if (selectedPanel.getLocation().y != newYLocation) { CanvasFormattingController.notifyYPropertyChange(newYLocation, selectedPanel); managedCanvas.fireFocusPersist(); } } } }); xyLabel.setLabelFor(positionXSpinner); positionControlsInnerPanel.add(xyLabel); positionControlsInnerPanel.add(new JLabel(POS_AND_DIPANEL_XY_OPEN_BRACE)); positionControlsInnerPanel.add(positionXSpinner); positionControlsInnerPanel.add(new JLabel(POS_AND_DIPANEL_XY_DELIMITER)); positionControlsInnerPanel.add(positionYSpinner); positionControlsInnerPanel.add(new JLabel(POS_AND_DIPANEL_XY_CLOSE_BRACE)); // Dimension Controls JPanel dimensionsControlsInnerPanel = new JPanel(); dimensionsControlsInnerPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel horizontalLabel = new JLabel(CanvasIcons.getIcon(Icons.PANEL_WIDTH_ICON)); horizontalLabel.setToolTipText("Panel width"); SpinnerNumberModel horizontalModel = new SpinnerNumberModel(SPINNER_INIT_VALUE, SPINNER_MIN_VALUE, SPINNER_MAX_VALUE, SPINNER_STEP_SIZE); dimensionHorizontalSpinner = new JSpinner(horizontalModel); dimensionHorizontalSpinner.setName("Position&DimensionsPanel_horizotnalSpinner"); dimensionHorizontalSpinner.setToolTipText("Panel width"); JFormattedTextField horitontalTextField = getTextField(dimensionHorizontalSpinner); horitontalTextField.setColumns(POS_AND_DIPANEL_XY_TEXT_FIELD_WIDTH); JLabel verticalLabel = new JLabel(CanvasIcons.getIcon(Icons.PANEL_HEIGHT_ICON)); verticalLabel.setToolTipText("Panel height"); SpinnerNumberModel verticalModel = new SpinnerNumberModel(SPINNER_INIT_VALUE, SPINNER_MIN_VALUE, SPINNER_MAX_VALUE, SPINNER_STEP_SIZE); dimensionVerticalSpinner = new JSpinner(verticalModel); dimensionVerticalSpinner.setName("Position&DimensionsPanel_verticalSpinner"); dimensionVerticalSpinner.setToolTipText("Panel height"); JFormattedTextField verticleTextField = getTextField(dimensionVerticalSpinner); verticleTextField.setColumns(POS_AND_DIPANEL_XY_TEXT_FIELD_WIDTH); // Attach listeners dimensionHorizontalSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); int newWidth = ((Integer) dimensionHorizontalSpinner.getValue()).intValue(); CanvasFormattingController.notifyWidthPropertyChange(newWidth, selectedPanels); managedCanvas.fireFocusPersist(); } } }); dimensionVerticalSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); int newHeight = ((Integer) dimensionVerticalSpinner.getValue()).intValue(); CanvasFormattingController.notifyHeightPropertyChange(newHeight, selectedPanels); managedCanvas.fireFocusPersist(); } } }); dimensionsControlsInnerPanel.add(horizontalLabel); dimensionsControlsInnerPanel.add(dimensionHorizontalSpinner); dimensionsControlsInnerPanel.add(verticalLabel); dimensionsControlsInnerPanel.add(dimensionVerticalSpinner); // Place position and dimensions inner panels positionInnerPanel.add(positionControlsInnerPanel); positionInnerPanel.add(dimensionsControlsInnerPanel); return positionAndDimensionsPanel; } private JPanel createBordersPanel() { JPanel bordersPanel = new JPanel(); // Border layout - PAGE_START for panel title and CENTER for the // controls bordersPanel.setLayout(new BorderLayout()); JLabel borderPanelTitleLabel = new JLabel(BORDERS_TITLE); bordersPanel.add(borderPanelTitleLabel, BorderLayout.PAGE_START); JPanel centerBorderPanel = new JPanel(); bordersPanel.add(centerBorderPanel, BorderLayout.CENTER); centerBorderPanel.setLayout(new GridBagLayout()); // Build border control buttons. leftBorderButton = new JToggleButton(CanvasIcons.getIcon(Icons.JLS_LEFT_BORDER_ICON)); leftBorderButton.setToolTipText("Left border"); rightBorderButton = new JToggleButton(CanvasIcons.getIcon(Icons.JLS_RIGHT_BORDER_ICON)); rightBorderButton.setToolTipText("Right border"); topBorderButton = new JToggleButton(CanvasIcons.getIcon(Icons.JLS_TOP_BORDER_ICON)); topBorderButton.setToolTipText("Top border"); bottomBorderButton = new JToggleButton(CanvasIcons.getIcon(Icons.JLS_BOTTOM_BORDER_ICON)); bottomBorderButton.setToolTipText("Bottom border"); fullBorderButton = new JToggleButton(CanvasIcons.getIcon(Icons.JLS_ALL_BORDER_ICON)); fullBorderButton.setToolTipText("All borders"); noBorderButton = new JToggleButton(CanvasIcons.getIcon(Icons.JLS_NO_BORDER_ICON)); noBorderButton.setToolTipText("No borders"); leftBorderButton.setName("BorderPanel_LeftBorderButton"); rightBorderButton.setName("BorderPanel_rightBorderButton"); topBorderButton.setName("BorderPanel_topBorderButton"); bottomBorderButton.setName("BorderPanel_bottomBorderButton"); fullBorderButton.setName("BorderPanel_fullBorderButton"); noBorderButton.setName("BorderPanel_noBorderButton"); leftBorderButton.setSelectedIcon(CanvasIcons.getIcon(Icons.JLS_LEFT_BORDER_SELECTED_ICON)); rightBorderButton.setSelectedIcon(CanvasIcons.getIcon(Icons.JLS_RIGHT_BORDER_SELECTED_ICON)); topBorderButton.setSelectedIcon(CanvasIcons.getIcon(Icons.JLS_TOP_BORDER_SELECTED_ICON)); bottomBorderButton.setSelectedIcon(CanvasIcons.getIcon(Icons.JLS_BOTTOM_BORDER_SELECTED_ICON)); fullBorderButton.setSelectedIcon(CanvasIcons.getIcon(Icons.JLS_ALL_BORDER_SELECTED_ICON)); noBorderButton.setSelectedIcon(CanvasIcons.getIcon(Icons.JLS_NO_BORDER_SELECTED_ICON)); leftBorderButton.setOpaque(false); rightBorderButton.setOpaque(false); topBorderButton.setOpaque(false); bottomBorderButton.setOpaque(false); fullBorderButton.setOpaque(false); noBorderButton.setOpaque(false); leftBorderButton.setFocusPainted(false); rightBorderButton.setFocusPainted(false); topBorderButton.setFocusPainted(false); bottomBorderButton.setFocusPainted(false); fullBorderButton.setFocusPainted(false); noBorderButton.setFocusPainted(false); leftBorderButton.setSize(CanvasIcons.getIcon(Icons.JLS_LEFT_BORDER_SELECTED_ICON) .getIconWidth(), CanvasIcons.getIcon(Icons.JLS_LEFT_BORDER_SELECTED_ICON) .getIconHeight()); leftBorderButton.setContentAreaFilled(false); rightBorderButton.setSize(CanvasIcons.getIcon(Icons.JLS_RIGHT_BORDER_SELECTED_ICON) .getIconWidth(), CanvasIcons.getIcon(Icons.JLS_RIGHT_BORDER_SELECTED_ICON) .getIconHeight()); rightBorderButton.setContentAreaFilled(false); topBorderButton.setSize( CanvasIcons.getIcon(Icons.JLS_TOP_BORDER_SELECTED_ICON).getIconWidth(), CanvasIcons.getIcon(Icons.JLS_TOP_BORDER_SELECTED_ICON).getIconHeight()); topBorderButton.setContentAreaFilled(false); bottomBorderButton.setSize(CanvasIcons.getIcon(Icons.JLS_BOTTOM_BORDER_SELECTED_ICON) .getIconWidth(), CanvasIcons.getIcon(Icons.JLS_BOTTOM_BORDER_SELECTED_ICON) .getIconHeight()); bottomBorderButton.setContentAreaFilled(false); fullBorderButton.setSize(CanvasIcons.getIcon(Icons.JLS_ALL_BORDER_SELECTED_ICON) .getIconWidth(), CanvasIcons.getIcon(Icons.JLS_ALL_BORDER_SELECTED_ICON) .getIconHeight()); fullBorderButton.setContentAreaFilled(false); noBorderButton.setSize(CanvasIcons.getIcon(Icons.JLS_NO_BORDER_SELECTED_ICON).getIconWidth(), CanvasIcons.getIcon(Icons.JLS_NO_BORDER_SELECTED_ICON).getIconHeight()); noBorderButton.setContentAreaFilled(false); leftBorderButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); rightBorderButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); topBorderButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); bottomBorderButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); fullBorderButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); noBorderButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); // Attach listeners leftBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (listenersEnabled) { CanvasFormattingController .notifyWestBorderStatus(leftBorderButton.isSelected(), selectedPanels); setAllAndNoBorderButtonState(selectedPanels); managedCanvas.fireFocusPersist(); } } }); rightBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (listenersEnabled) { CanvasFormattingController.notifyEastBorderStatus(rightBorderButton.isSelected(), selectedPanels); setAllAndNoBorderButtonState(selectedPanels); managedCanvas.fireFocusPersist(); } } }); topBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (listenersEnabled) { CanvasFormattingController .notifyNorthBorderStatus(topBorderButton.isSelected(), selectedPanels); setAllAndNoBorderButtonState(selectedPanels); managedCanvas.fireFocusPersist(); } } }); bottomBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (listenersEnabled) { CanvasFormattingController.notifySouthBorderStatus(bottomBorderButton.isSelected(), selectedPanels); setAllAndNoBorderButtonState(selectedPanels); managedCanvas.fireFocusPersist(); } } }); fullBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean enabled = listenersEnabled; if (fullBorderButton.isSelected()) { listenersEnabled = false; leftBorderButton.setSelected(true); rightBorderButton.setSelected(true); topBorderButton.setSelected(true); bottomBorderButton.setSelected(true); noBorderButton.setSelected(false); listenersEnabled = enabled; if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAllBorderStatus(true, selectedPanels); managedCanvas.fireFocusPersist(); } } else { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); for (Panel p : selectedPanels) { if (p.getBorderState() != PanelBorder.ALL_BORDERS) { fullBorderButton.setSelected(true); return; } } } } }); noBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean enabled = listenersEnabled; // Once this button is pressed, the user cannot press it again. if (noBorderButton.isSelected()) { listenersEnabled = false; leftBorderButton.setSelected(false); rightBorderButton.setSelected(false); topBorderButton.setSelected(false); bottomBorderButton.setSelected(false); fullBorderButton.setSelected(false); listenersEnabled = enabled; if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAllBorderStatus(false, selectedPanels); managedCanvas.fireFocusPersist(); } } else { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); for (Panel p : selectedPanels) { if (p.getBorderState() != PanelBorder.NO_BORDER) { noBorderButton.setSelected(true); return; } } } } }); JLabel borderStyleLabel = new JLabel(BORDER_STYLE_CAPTION); borderStyleComboBox = new JComboBox(generateBorderStyles()); borderStyleComboBox.setToolTipText("Border style"); borderStyleComboBox.setName("BorderPanel_styleComboBox"); borderStyleComboBox.setRenderer(new LineComboBoxRenderer()); borderStyleComboBox.setPreferredSize(new Dimension(50, 20)); borderStyleComboBox.setSelectedIndex(0); // Attach listener to show border styles in combo box. borderStyleComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyBorderFormattingStyle(borderStyleComboBox.getSelectedIndex(), selectedPanels); managedCanvas.fireFocusPersist(); } } }); borderStyleLabel.setLabelFor(borderStyleComboBox); JLabel borderColorLabel = new JLabel(BORDER_COLOR_CAPTION); // Build Color chooser borderColorComboBox = new JComboBox(ControlAreaFormattingConstants.BorderColors); borderColorComboBox.setName("BorderPanel_colorComboBox"); borderColorComboBox.setToolTipText("Border color"); borderColorComboBox.setMaximumRowCount(5); borderColorComboBox.setPreferredSize(new Dimension(50, 20)); borderColorComboBox.setSelectedIndex(0); ColorComboBoxRenderer renderer = new ColorComboBoxRenderer(); borderColorComboBox.setRenderer(renderer); renderer.remap(managedCanvas.getBackground(), managedCanvas.getDefaultBorderColor()); borderColorLabel.setLabelFor(borderColorComboBox); // Attach listener to show border styles in combo box. borderColorComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyBorderColorSelected((Color) borderColorComboBox .getSelectedItem(), selectedPanels); managedCanvas.fireFocusPersist(); } } }); // Arrange components. GridBagConstraints leftBorderButtonConstraints = new GridBagConstraints(); leftBorderButtonConstraints.fill = GridBagConstraints.NONE; leftBorderButtonConstraints.anchor = GridBagConstraints.LINE_START; leftBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; leftBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; leftBorderButtonConstraints.gridx = 0; leftBorderButtonConstraints.gridy = 0; centerBorderPanel.add(leftBorderButton, leftBorderButtonConstraints); GridBagConstraints rightBorderButtonConstraints = new GridBagConstraints(); rightBorderButtonConstraints.fill = GridBagConstraints.NONE; rightBorderButtonConstraints.anchor = GridBagConstraints.LINE_START; rightBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; rightBorderButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; rightBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; rightBorderButtonConstraints.gridx = 1; rightBorderButtonConstraints.gridy = 0; centerBorderPanel.add(rightBorderButton, rightBorderButtonConstraints); GridBagConstraints topBorderButtonConstraints = new GridBagConstraints(); topBorderButtonConstraints.fill = GridBagConstraints.NONE; topBorderButtonConstraints.anchor = GridBagConstraints.LINE_START; topBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; topBorderButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; topBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; topBorderButtonConstraints.gridx = 2; topBorderButtonConstraints.gridy = 0; centerBorderPanel.add(topBorderButton, topBorderButtonConstraints); GridBagConstraints centerBorderButtonConstraints = new GridBagConstraints(); centerBorderButtonConstraints.fill = GridBagConstraints.NONE; centerBorderButtonConstraints.anchor = GridBagConstraints.LINE_START; centerBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; centerBorderButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; centerBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; centerBorderButtonConstraints.gridx = 3; centerBorderButtonConstraints.gridy = 0; centerBorderPanel.add(borderStyleLabel, centerBorderButtonConstraints); GridBagConstraints bottomBorderButtonConstraints = new GridBagConstraints(); bottomBorderButtonConstraints.fill = GridBagConstraints.BOTH; bottomBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; bottomBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; bottomBorderButtonConstraints.gridx = 0; bottomBorderButtonConstraints.gridy = 1; centerBorderPanel.add(bottomBorderButton, bottomBorderButtonConstraints); GridBagConstraints fullBorderButtonConstraints = new GridBagConstraints(); fullBorderButtonConstraints.fill = GridBagConstraints.BOTH; fullBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; fullBorderButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; fullBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; fullBorderButtonConstraints.gridx = 1; fullBorderButtonConstraints.gridy = 1; centerBorderPanel.add(fullBorderButton, fullBorderButtonConstraints); GridBagConstraints noBorderButtonConstraints = new GridBagConstraints(); noBorderButtonConstraints.fill = GridBagConstraints.BOTH; noBorderButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; noBorderButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; noBorderButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; noBorderButtonConstraints.gridx = 2; noBorderButtonConstraints.gridy = 1; centerBorderPanel.add(noBorderButton, noBorderButtonConstraints); GridBagConstraints borderColorLabelConstraints = new GridBagConstraints(); borderColorLabelConstraints.fill = GridBagConstraints.BOTH; borderColorLabelConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; borderColorLabelConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; borderColorLabelConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; borderColorLabelConstraints.gridx = 3; borderColorLabelConstraints.gridy = 1; centerBorderPanel.add(borderColorLabel, borderColorLabelConstraints); GridBagConstraints borderSytleComboBoxConstraints = new GridBagConstraints(); borderSytleComboBoxConstraints.insets = new Insets(0, IPAD_X, 0, 0); borderSytleComboBoxConstraints.fill = GridBagConstraints.NONE; borderSytleComboBoxConstraints.anchor = GridBagConstraints.LINE_START; borderSytleComboBoxConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; borderSytleComboBoxConstraints.weightx = 1; borderSytleComboBoxConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; borderSytleComboBoxConstraints.gridx = 4; borderSytleComboBoxConstraints.gridy = 0; centerBorderPanel.add(borderStyleComboBox, borderSytleComboBoxConstraints); GridBagConstraints borderColorChooserConstraints = new GridBagConstraints(); borderColorChooserConstraints.insets = new Insets(0, IPAD_X, 0, 0); borderColorChooserConstraints.fill = GridBagConstraints.NONE; borderColorChooserConstraints.anchor = GridBagConstraints.LINE_START; borderColorChooserConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; borderColorChooserConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; borderColorChooserConstraints.gridx = 4; borderColorChooserConstraints.gridy = 1; centerBorderPanel.add(borderColorComboBox, borderColorChooserConstraints); return bordersPanel; } private JPanel createSpotlightPanel() { JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new JLabel("Find:")); final JTextField field = new JTextField(MISCELLANEOUS_PANEL_PANEL_TITLE_FIELD_SIZE); panel.add(field, BorderLayout.CENTER); field.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { managedCanvas.augmentation.spotlightText = field.getText().trim(); managedCanvas.augmentation.repaint(); } @Override public void insertUpdate(DocumentEvent e) { managedCanvas.augmentation.spotlightText = field.getText().trim(); managedCanvas.augmentation.repaint(); } @Override public void changedUpdate(DocumentEvent e) { } }); return panel; } private void setAllAndNoBorderButtonState(List<Panel> selectedPanels) { boolean enabled = listenersEnabled; listenersEnabled = false; boolean noBorder = true; boolean allBorder = true; for (Panel p : selectedPanels) { if (p.getBorderState() == PanelBorder.NO_BORDER) { noBorder = true; allBorder = false; } else if (p.getBorderState() == PanelBorder.ALL_BORDERS) { allBorder = true; noBorder = false; } else { noBorder = false; allBorder = false; break; } } if (noBorder) { noBorderButton.setSelected(true); fullBorderButton.setSelected(false); } else if (allBorder) { noBorderButton.setSelected(false); fullBorderButton.setSelected(true); } else { noBorderButton.setSelected(false); fullBorderButton.setSelected(false); } listenersEnabled = enabled; } private JPanel createAlignmentPanel() { JPanel alignmentPanel = new JPanel(); // Border layout - PAGE_START for panel title and CENTER for the // controls alignmentPanel.setLayout(new BorderLayout()); JLabel alignmentPanelTitleLabel = new JLabel(ALIGNMENT_TITLE); alignmentPanel.add(alignmentPanelTitleLabel, BorderLayout.PAGE_START); JPanel alignmentCenterPanel = new JPanel(); alignmentPanel.add(alignmentCenterPanel, BorderLayout.CENTER); alignTableLeftButton = new JButton(CanvasIcons .getIcon(Icons.JLS_ALIGN_TABLE_LEFT_ICON)); alignTableLeftButton.setToolTipText("Align to left edge"); alignTableRightButton = new JButton(CanvasIcons .getIcon(Icons.JLS_ALIGN_TABLE_RIGHT_ICON)); alignTableRightButton.setToolTipText("Align to right edge"); alignTableTopButton = new JButton(CanvasIcons.getIcon(Icons.JLS_ALIGN_TABLE_TOP_ICON)); alignTableTopButton.setToolTipText("Align to top edge"); alignTableBottomButton = new JButton(CanvasIcons .getIcon(Icons.JLS_ALIGN_TABLE_BOTTOM_ICON)); alignTableBottomButton.setToolTipText("Align to bottom edge"); alignTableCenterVerticleButton = new JButton(CanvasIcons .getIcon(Icons.JLS_ALIGN_TABLE_VCENTER_ICON)); alignTableCenterVerticleButton.setToolTipText("Align to vertical center"); alignTableCenterHorizontalButton = new JButton(CanvasIcons .getIcon(Icons.JLS_ALIGN_TABLE_HCENTER_ICON)); alignTableCenterHorizontalButton.setToolTipText("Align to horizontal center"); alignTableLeftButton.setName("Alignment_alignLeft"); alignTableCenterHorizontalButton.setName("Alignment_alignCenterH"); alignTableRightButton.setName("Alignment_alignRight"); alignTableBottomButton.setName("Alignment_alignBottom"); alignTableTopButton.setName("Alignment_alignTop"); alignTableCenterVerticleButton.setName("Alignment_alignCenterV"); alignTableLeftButton.setContentAreaFilled(false); alignTableRightButton.setContentAreaFilled(false); alignTableTopButton.setContentAreaFilled(false); alignTableBottomButton.setContentAreaFilled(false); alignTableCenterVerticleButton.setContentAreaFilled(false); alignTableCenterHorizontalButton.setContentAreaFilled(false); alignTableLeftButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); alignTableRightButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); alignTableTopButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); alignTableBottomButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); alignTableCenterVerticleButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); alignTableCenterHorizontalButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_BORDER_STYLE_TOP, BUTTON_BORDER_STYLE_LEFT, BUTTON_BORDER_STYLE_BOTTOM, BUTTON_BORDER_STYLE_RIGHT)); // Attach listeners alignTableLeftButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignLeftSelected(selectedPanels); managedCanvas.fireFocusPersist(); } }); alignTableCenterHorizontalButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignCenterHSelected(selectedPanels); managedCanvas.fireFocusPersist(); } }); alignTableRightButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignRightSelected(selectedPanels); managedCanvas.fireFocusPersist(); } }); alignTableTopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignTopSelected(selectedPanels); managedCanvas.fireFocusPersist(); } }); alignTableBottomButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignBottomSelected(selectedPanels); managedCanvas.fireFocusPersist(); } }); alignTableCenterVerticleButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignVCenterSelected(selectedPanels); managedCanvas.fireFocusPersist(); } }); alignmentCenterPanel.setLayout(new GridBagLayout()); GridBagConstraints alignmentCenterButtonConstraints = new GridBagConstraints(); alignmentCenterButtonConstraints.fill = GridBagConstraints.NONE; alignmentCenterButtonConstraints.anchor = GridBagConstraints.LINE_START; alignmentCenterButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; alignmentCenterButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; alignmentCenterButtonConstraints.gridx = 0; alignmentCenterButtonConstraints.gridy = 0; alignmentCenterPanel.add(alignTableLeftButton, alignmentCenterButtonConstraints); GridBagConstraints alignCenterButtonConstraints = new GridBagConstraints(); alignCenterButtonConstraints.fill = GridBagConstraints.NONE; alignCenterButtonConstraints.anchor = GridBagConstraints.LINE_START; alignCenterButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; alignCenterButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; alignCenterButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; alignCenterButtonConstraints.gridx = 1; alignCenterButtonConstraints.gridy = 0; alignmentCenterPanel.add(alignTableRightButton, alignCenterButtonConstraints); GridBagConstraints alignTableTopButtonConstraints = new GridBagConstraints(); alignTableTopButtonConstraints.fill = GridBagConstraints.NONE; alignTableTopButtonConstraints.anchor = GridBagConstraints.LINE_START; alignTableTopButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; alignTableTopButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; alignTableTopButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; alignTableTopButtonConstraints.gridx = 2; alignTableTopButtonConstraints.gridy = 0; alignmentCenterPanel.add(alignTableTopButton, alignTableTopButtonConstraints); GridBagConstraints alignTableBottomButtonConstraints = new GridBagConstraints(); alignTableBottomButtonConstraints.fill = GridBagConstraints.BOTH; alignTableBottomButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; alignTableBottomButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; alignTableBottomButtonConstraints.gridx = 0; alignTableBottomButtonConstraints.gridy = 1; alignmentCenterPanel.add(alignTableBottomButton, alignTableBottomButtonConstraints); GridBagConstraints alignTableCenterVerticleButtonConstraints = new GridBagConstraints(); alignTableCenterVerticleButtonConstraints.fill = GridBagConstraints.BOTH; alignTableCenterVerticleButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; alignTableCenterVerticleButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; alignTableCenterVerticleButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; alignTableCenterVerticleButtonConstraints.gridx = 1; alignTableCenterVerticleButtonConstraints.gridy = 1; alignmentCenterPanel.add(alignTableCenterVerticleButton, alignTableCenterVerticleButtonConstraints); GridBagConstraints alignTableCenterHorizontalButtonConstraints = new GridBagConstraints(); alignTableCenterHorizontalButtonConstraints.fill = GridBagConstraints.NONE; alignTableCenterHorizontalButtonConstraints.anchor = GridBagConstraints.LINE_START; alignTableCenterHorizontalButtonConstraints.weighty = SMALL_CONTROL_BUTTON_WEIGHT_Y; alignTableCenterHorizontalButtonConstraints.weightx = SMALL_CONTROL_BUTTON_WEIGHT_X; alignTableCenterHorizontalButtonConstraints.ipadx = SMALL_CONTROL_BUTTON_IPAD_X; alignTableCenterHorizontalButtonConstraints.gridx = 2; alignTableCenterHorizontalButtonConstraints.gridy = 1; alignmentCenterPanel.add(alignTableCenterHorizontalButton, alignTableCenterHorizontalButtonConstraints); // return the completed alignment panel return alignmentPanel; } private JPanel createMiscellaneousPanel() { JPanel miscellaneousPanel = new JPanel(); // Border layout - PAGE_START for panel title and CENTER for the // controls miscellaneousPanel.setLayout(new BorderLayout()); JLabel miscellaneousPanelTitleLabel = new JLabel(MISCELLANEOUS_TITLE); // Inner panel holds the controls. JPanel miscellaneousInnerPanel = new JPanel(); miscellaneousInnerPanel.setLayout(new GridBagLayout()); // Arrange inner panel GridBagConstraints findConstraints = new GridBagConstraints(); findConstraints.anchor = GridBagConstraints.NORTHWEST; findConstraints.fill = GridBagConstraints.NONE; findConstraints.weighty = MISC_PANEL_WEIGHT_Y; findConstraints.weightx = 1; findConstraints.gridx = 0; findConstraints.gridy = 1; miscellaneousInnerPanel.add(createSpotlightPanel(), findConstraints); findConstraints = new GridBagConstraints(); findConstraints.anchor = GridBagConstraints.NORTHWEST; findConstraints.fill = GridBagConstraints.NONE; findConstraints.weighty = MISC_PANEL_WEIGHT_Y; findConstraints.weightx = 1; findConstraints.gridx = 0; findConstraints.gridy = 0; miscellaneousInnerPanel.add(miscellaneousPanelTitleLabel, findConstraints); // attach inner panel miscellaneousPanel.add(miscellaneousInnerPanel, BorderLayout.CENTER); // return completed misc. panel. return miscellaneousPanel; } private JPanel createPanelTitleFormattingPanel() { JPanel panelTitleFormattingPanel = new JPanel(); ConstraintBuilder builder = new ConstraintBuilder(panelTitleFormattingPanel); JLabel panelLabel = new JLabel("Panel Title Bar Formatting"); JLabel panelTitleLabel = new JLabel(PANEL_TITLE); miscPanelTitleField = new JFormattedTextField(); miscPanelTitleField.setName("MiscPanel_panelTitleField"); panelTitleLabel.setLabelFor(miscPanelTitleField); miscPanelTitleField.setColumns(MISCELLANEOUS_PANEL_PANEL_TITLE_FIELD_SIZE); miscPanelTitleBarCheckBox = new JCheckBox(PANEL_TITLE_BAR); miscPanelTitleBarCheckBox.setName("MiscPanel_xTitleBarCheckBox"); panelTitleFont = new JComboBox(ControlAreaFormattingConstants.JVMFontFamily.values()); panelTitleFont.getAccessibleContext().setAccessibleName("panelTitleFontComboBox"); panelTitleFont.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarFontSelected( ((JVMFontFamily) panelTitleFont.getSelectedItem()).toString(), selectedPanels); managedCanvas.fireFocusPersist(); } } }); // Attach Listeners miscPanelTitleBarCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarStatus(miscPanelTitleBarCheckBox.isSelected(), selectedPanels); managedCanvas.fireFocusPersist(); } miscPanelTitleField.setEditable(miscPanelTitleBarCheckBox.isSelected()); } }); miscPanelTitleField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyNewTitle(miscPanelTitleField.getText(), selectedPanels); managedCanvas.fireFocusPersist(); } } }); miscPanelTitleField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); boolean changed = false; for (Panel p : selectedPanels) { if (!p.getTitle().equals(miscPanelTitleField.getText())) { changed = true; } } if (changed) { CanvasFormattingController.notifyNewTitle(miscPanelTitleField.getText(), selectedPanels); managedCanvas.fireFocusPersist(); } } } @Override public void focusGained(FocusEvent e) { } }); SpinnerModel panelTitleFontSizeModel = new SpinnerNumberModel(12, 8, 36, 1); panelTitleFontSize = new JSpinner(panelTitleFontSizeModel); panelTitleFontSize.getAccessibleContext().setAccessibleName(bundle.getString("PANEL_TITLE_FONT_SIZE_SPINNER")); panelTitleFontSize.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarFontSizeSelected( Integer.class.cast(panelTitleFontSize.getValue()), selectedPanels); managedCanvas.fireFocusPersist(); } } }); panelTitleFontStyleBold = getIconRadioButton("bold_off.png","bold_on.png", bundle.getString("FONT_BOLD")); Insets boldButtonInsets = panelTitleFontStyleBold.getInsets(); boldButtonInsets.set(boldButtonInsets.top, 0, boldButtonInsets.bottom, boldButtonInsets.right); panelTitleFontStyleBold.setMargin(boldButtonInsets); panelTitleFontStyleBold.getAccessibleContext().setAccessibleName("panelTitleFontStyleBold"); panelTitleFontStyleItalic = getIconRadioButton("italics_off.png","italics_on.png", bundle.getString("FONT_ITALIC")); panelTitleFontStyleItalic.getAccessibleContext().setAccessibleName("panelTitleFontStyleItalic"); panelTitleFontUnderline = getIconRadioButton("underline_off.png","underline_on.png", bundle.getString("FONT_UNDERLINE")); panelTitleFontUnderline.getAccessibleContext().setAccessibleName("panelTitleFontStyleUnderline"); ActionListener panelTitleFontStyleListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (listenersEnabled) { int fontStyle = Font.PLAIN; if (panelTitleFontStyleBold.getModel().isSelected()) { fontStyle = Font.BOLD; if (panelTitleFontStyleItalic.getModel().isSelected()) { fontStyle += Font.ITALIC; } } else if (panelTitleFontStyleItalic.getModel().isSelected()) { fontStyle = Font.ITALIC; } List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarFontStyleSelected( Integer.valueOf(fontStyle), selectedPanels); managedCanvas.fireFocusPersist(); } } }; panelTitleFontStyleBold.addActionListener(panelTitleFontStyleListener); panelTitleFontStyleItalic.addActionListener(panelTitleFontStyleListener); ActionListener panelTitleFontTextAttributeListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (listenersEnabled) { int attribute = ControlAreaFormattingConstants.UNDERLINE_OFF; if (panelTitleFontUnderline.getModel().isSelected()) { attribute = TextAttribute.UNDERLINE_ON; } List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarFontUnderlineSelected( Integer.valueOf(attribute), selectedPanels); managedCanvas.fireFocusPersist(); } } }; panelTitleFontUnderline.addActionListener(panelTitleFontTextAttributeListener); panelTitleFontColorComboBox = new JComboBox(ControlAreaFormattingConstants.BorderColors); panelTitleFontColorComboBox.setName("Foreground_colorComboBox"); panelTitleFontColorComboBox.getAccessibleContext().setAccessibleName("panelTitleFontColorComboBox"); panelTitleFontColorComboBox.setToolTipText("Font color"); panelTitleFontColorComboBox.setMaximumRowCount(5); panelTitleFontColorComboBox.setPreferredSize(new Dimension(50, 20)); panelTitleFontColorComboBox.setSelectedIndex(0); // BackgroundColorComboBoxRenderer renderer = new BackgroundColorComboBoxRenderer(); panelTitleFontColorComboBox.setRenderer(new ListCellRenderer() { private ColorPanel myColorPanel = new ColorPanel(new Color(0)); @Override public Component getListCellRendererComponent(JList list, Object obj, int arg2, boolean arg3, boolean arg4) { if (obj instanceof Color) { myColorPanel.setColor((Color) obj); return myColorPanel; } return new JPanel(); } }); // Attach listener to show foreground colors in combo box. panelTitleFontColorComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarFontForegroundColorSelected( Integer.valueOf((Color.class.cast(panelTitleFontColorComboBox.getSelectedItem())).getRGB()), selectedPanels); managedCanvas.fireFocusPersist(); } } }); panelTitleFontStyleBold.addActionListener(panelTitleFontStyleListener); panelTitleFontStyleItalic.addActionListener(panelTitleFontStyleListener); panelTitleBackgroundColorComboBox = new JComboBox(ControlAreaFormattingConstants.BorderColors); panelTitleBackgroundColorComboBox.setName("Background_colorComboBox"); panelTitleBackgroundColorComboBox.getAccessibleContext().setAccessibleName("panelTitleBackgroundColorComboBox"); panelTitleBackgroundColorComboBox.setToolTipText("Background color"); panelTitleBackgroundColorComboBox.setMaximumRowCount(5); panelTitleBackgroundColorComboBox.setPreferredSize(new Dimension(50, 20)); panelTitleBackgroundColorComboBox.setSelectedIndex(0); // renderer = new BackgroundColorComboBoxRenderer(); panelTitleBackgroundColorComboBox.setRenderer(new ListCellRenderer() { private ColorPanel myColorPanel = new ColorPanel(new Color(0)); @Override public Component getListCellRendererComponent(JList list, Object obj, int arg2, boolean arg3, boolean arg4) { if (obj instanceof Color) { myColorPanel.setColor((Color) obj); return myColorPanel; } return new JPanel(); } }); // Attach listener to show foreground colors in combo box. panelTitleBackgroundColorComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyTitleBarFontBackgroundColorSelected( Integer.valueOf((Color.class.cast(panelTitleBackgroundColorComboBox.getSelectedItem())).getRGB()), selectedPanels); managedCanvas.fireFocusPersist(); } } }); builder.insets(0, 0, 3, 0).at(0, 0).span(1, 4).nw().add(panelLabel); builder.at(1, 0).nw().add(panelTitleLabel); builder.at(1, 1).nw().add(miscPanelTitleField); builder.at(1, 2).span(1, 2).nw().add(miscPanelTitleBarCheckBox); builder.at(2, 0).baseline_w().add(new JLabel(bundle.getString("FONT_NAME_LABEL")), hbox(5)); builder.at(2, 1).baseline_w().add(panelTitleFont); builder.at(2, 2).nw().add(new JLabel(bundle.getString("FONT_COLOR_LABEL"))); builder.at(2, 3).nw().add(panelTitleFontColorComboBox); builder.insets(5,0,0,0).at(3, 0).nw().add(new JLabel(bundle.getString("FONT_SIZE_LABEL"))); builder.insets(5,0,0,0).at(3, 1).nw().add(panelTitleFontSize); builder.at(3, 2).nw().add(new JLabel(bundle.getString("FONT_BACKGROUND_COLOR_LABEL"))); builder.at(3, 3).nw().add(panelTitleBackgroundColorComboBox); builder.insets(5,0,0,0).at(4, 0).nw().add(new JLabel(bundle.getString("FONT_STYLE_LABEL"))); builder.at(4, 1).nw().add(panelTitleFontStyleBold, panelTitleFontStyleItalic, panelTitleFontUnderline); return panelTitleFormattingPanel; } private JRadioButton getIconRadioButton(String offName, String onName, String description) { JRadioButton button = new JRadioButton(loadIcon(offName, description)); button.setSelectedIcon(loadIcon(onName, description)); return button; } private Icon loadIcon(String name, String description) { URL url = getClass().getClassLoader().getResource("images/" + name); return new ImageIcon(url, description); } private static class LineComboBoxRenderer extends JLabel implements ListCellRenderer { private static final long serialVersionUID = 2325113335574780392L; private final PanelBorder border = new PanelBorder(PanelBorder.NORTH_BORDER); public LineComboBoxRenderer() { setOpaque(true); setHorizontalAlignment(CENTER); setVerticalAlignment(CENTER); border.setBorderStyle(BorderStyle.SINGLE); setBorder(new CompoundBorder(new EmptyBorder(4, 4, 4, 4), border)); } /* * This method finds the image and text corresponding to the selected * value and returns the label, set up to display the text and image. */ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // Get the selected index. (The index param isn't // always valid, so just use the value.) int selectedIndex = ((Integer) value).intValue(); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } border.setBorderStyle(selectedIndex); setText(""); return this; } } private static class ColorComboBoxRenderer extends DefaultListCellRenderer implements ListCellRenderer { private static final long serialVersionUID = 4172995566305076422L; private Map<Object, Color> remapper; public ColorComboBoxRenderer() { setPreferredSize(new Dimension(70, 20)); remapper = new HashMap<Object, Color>(); } public void remap(Object object, Color color) { remapper.put(object, color); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); /* remap certain colors to different ones, in case our presentation differs from * the way colors are stored internally */ Color c = remapper.get(value); if (c == null) { c = (Color) value; } if (c != null) { setBorder(BorderFactory.createLineBorder(c, 4)); component.setText(""); } return component; } } /* State Setting methods */ private void setPositionAndDimensionsValues(int xLoc, int yLoc, int height, int width) { listenersEnabled = false; positionXSpinner.setValue(xLoc + CORRECTION_OFFSET); positionYSpinner.setValue(yLoc + CORRECTION_OFFSET); dimensionVerticalSpinner.setValue(height); dimensionHorizontalSpinner.setValue(width); listenersEnabled = true; } /** Set the control panel values for multiple selected panels * @param selectedPanels */ private void setPanelValuesForMultiSelect(Collection<Panel> selectedPanels) { listenersEnabled = false; String commonTitleFont = null; Integer commonTitleFontSize = null; Integer commonTitleFontStyleItalic = null; Integer commonTitleFontStyleBold = null; Integer commonTitleFontUnderline = null; Integer commonTitleFontColor = null; Integer commonTitleBackgroundColor = null; boolean hasCommonTitleFont = true; boolean hasCommonTitleFontSize = true; boolean hasCommonTitleFontStyleBold = true; boolean hasCommonTitleFontStyleItalic = true; boolean hasCommonTitleFontStyleUnderline = true; boolean hasCommonTitleFontColor = true; boolean hasCommonTitleBackgroundColor = true; for (Panel aPanel : selectedPanels) { String aTitleFont = aPanel.getTitleFont(); if (commonTitleFont !=null && !commonTitleFont.equals(aTitleFont)) { hasCommonTitleFont = false; } Integer aTitleFontSize = aPanel.getTitleFontSize(); if (commonTitleFontSize !=null && !commonTitleFontSize.equals(aTitleFontSize)) { hasCommonTitleFontSize = false; } Integer aTitleFontStyle = aPanel.getTitleFontStyle(); Integer aTitleFontStyleBold = Font.PLAIN; if (aTitleFontStyle != null) { if (aTitleFontStyle.equals(Font.BOLD) || aTitleFontStyle.equals(Font.ITALIC + Font.BOLD)) { aTitleFontStyleBold = Font.BOLD; } } else { aTitleFontStyleBold = null; } if (commonTitleFontStyleBold !=null && !commonTitleFontStyleBold.equals(aTitleFontStyleBold)) { hasCommonTitleFontStyleBold = false; } Integer aTitleFontStyleItalic = Font.PLAIN; if (aTitleFontStyle != null) { if (aTitleFontStyle.equals(Font.ITALIC) || aTitleFontStyle.equals(Font.ITALIC + Font.BOLD)) { aTitleFontStyleItalic = Font.ITALIC; } } else { aTitleFontStyleItalic = null; } if (commonTitleFontStyleItalic !=null && !commonTitleFontStyleItalic.equals(aTitleFontStyleItalic)) { hasCommonTitleFontStyleItalic = false; } Integer aTitleFontUnderline = aPanel.getTitleFontUnderline(); if (commonTitleFontUnderline !=null && !commonTitleFontUnderline.equals(aTitleFontUnderline)) { hasCommonTitleFontStyleUnderline = false; } Integer aForegroundColor = aPanel.getTitleFontForegroundColor(); if (commonTitleFontColor !=null && !commonTitleFontColor.equals(aForegroundColor)) { hasCommonTitleFontColor = false; } Integer aBackgroundColor = aPanel.getTitleFontBackgroundColor(); if (commonTitleBackgroundColor !=null && !commonTitleBackgroundColor.equals(aBackgroundColor)) { hasCommonTitleBackgroundColor = false; } commonTitleFont = aTitleFont; commonTitleFontSize = aTitleFontSize; commonTitleFontStyleBold = aTitleFontStyleBold; commonTitleFontStyleItalic = aTitleFontStyleItalic; commonTitleFontUnderline = aTitleFontUnderline; commonTitleFontColor = aForegroundColor; commonTitleBackgroundColor = aBackgroundColor; } if (hasCommonTitleFont && commonTitleFont != null) { panelTitleFont.setSelectedItem(Enum.valueOf(JVMFontFamily.class, commonTitleFont)); } else { panelTitleFont.setSelectedIndex(-1); } if (hasCommonTitleFontSize && commonTitleFontSize != null) { panelTitleFontSize.setValue(commonTitleFontSize.intValue()); } if (hasCommonTitleFontStyleBold && commonTitleFontStyleBold != null) { if (commonTitleFontStyleBold.equals(Font.BOLD)) { panelTitleFontStyleBold.setSelected(true); } else { panelTitleFontStyleBold.setSelected(false); } } if (hasCommonTitleFontStyleItalic && commonTitleFontStyleItalic != null) { if (commonTitleFontStyleItalic.equals(Font.BOLD)) { panelTitleFontStyleItalic.setSelected(true); } else { panelTitleFontStyleItalic.setSelected(false); } } if (hasCommonTitleFontStyleUnderline && commonTitleFontUnderline != null) { panelTitleFontUnderline.setSelected(true); } else { panelTitleFontUnderline.setSelected(false); } if (hasCommonTitleFontColor && commonTitleFontColor != null) { panelTitleFontColorComboBox.setSelectedItem( new Color(commonTitleFontColor)); } else { panelTitleFontColorComboBox.setSelectedIndex(0); } if (hasCommonTitleBackgroundColor && commonTitleBackgroundColor != null) { panelTitleBackgroundColorComboBox.setSelectedItem( new Color(commonTitleBackgroundColor)); } else { panelTitleBackgroundColorComboBox.setSelectedIndex(0); } miscPanelTitleField.setText(""); listenersEnabled = true; } /* Set panel title */ // For single panel select private void setPanelValues(Panel selectedPanel) { listenersEnabled = false; miscPanelTitleBarCheckBox.setSelected(selectedPanel.hasTitle()); String panelTitle = selectedPanel.getTitle(); if (selectedPanel.hasTitle()) { if (panelTitle == null) { miscPanelTitleField.setText(""); } else { miscPanelTitleField.setText(panelTitle); } } else { miscPanelTitleField.setText(""); } if (selectedPanel.hasTitle()) { if (selectedPanel.getTitleFont() != null) { panelTitleFont.setSelectedItem(Enum.valueOf(JVMFontFamily.class, selectedPanel.getTitleFont())); } else { panelTitleFont.setSelectedIndex(0); } if (selectedPanel.getTitleFontSize() != null) { panelTitleFontSize.setValue(selectedPanel.getTitleFontSize().intValue()); } if (selectedPanel.getTitleFontStyle() != null) { if (selectedPanel.getTitleFontStyle().equals(Font.BOLD)) { panelTitleFontStyleBold.setSelected(true); } else if (selectedPanel.getTitleFontStyle().equals(Font.ITALIC)) { panelTitleFontStyleItalic.setSelected(true); } else if (selectedPanel.getTitleFontStyle().equals(Font.BOLD+Font.ITALIC)) { panelTitleFontStyleBold.setSelected(true); panelTitleFontStyleItalic.setSelected(true); } else { panelTitleFontStyleBold.setSelected(false); panelTitleFontStyleItalic.setSelected(false); } } if (selectedPanel.getTitleFontUnderline() != null) { if (selectedPanel.getTitleFontUnderline().equals(TextAttribute.UNDERLINE_ON)) { panelTitleFontUnderline.setSelected(true); } else { panelTitleFontUnderline.setSelected(false); } } if (selectedPanel.getTitleFontForegroundColor() != null) { panelTitleFontColorComboBox.setSelectedItem( new Color(selectedPanel.getTitleFontForegroundColor())); } else { panelTitleFontColorComboBox.setSelectedIndex(0); } if (selectedPanel.getTitleFontBackgroundColor() != null) { panelTitleBackgroundColorComboBox.setSelectedItem( new Color(selectedPanel.getTitleFontBackgroundColor())); } else { panelTitleBackgroundColorComboBox.setSelectedIndex(0); } } listenersEnabled = true; } void setBorderValues(byte borderState, BorderStyle borderStyle, Color borderColor) { listenersEnabled = false; leftBorderButton.setSelected(PanelBorder.hasWestBorder(borderState)); rightBorderButton.setSelected(PanelBorder.hasEastBorder(borderState)); topBorderButton.setSelected(PanelBorder.hasNorthBorder(borderState)); bottomBorderButton.setSelected(PanelBorder.hasSouthBorder(borderState)); fullBorderButton.setSelected(borderState == PanelBorder.ALL_BORDERS); noBorderButton.setSelected(borderState == PanelBorder.NO_BORDER); borderStyleComboBox.setSelectedIndex(borderStyle.ordinal()); borderColorComboBox.setSelectedItem(borderColor); listenersEnabled = true; } /* Callbacks from controller */ void informZeroPanelsSelected() { setGUIControlsStatusForZeroSelect(); } void informOnePanelSelected(List<Panel> selectedPanels) { assert selectedPanels.size() == 1; setGUIControlsStatusForSingleSelect(selectedPanels.get(0)); } // Disable GUI components when multiple items are selected void informMultipleViewPanelsSelected(Collection<Panel> selectedPanels) { setGUIControlsStatusForMultiSelect(selectedPanels); } private void setGUIControlsStatusForZeroSelect() { // Turn off Position and Dimension controls */ listenersEnabled = false; positionXSpinner.setEnabled(false); positionYSpinner.setEnabled(false); dimensionVerticalSpinner.setEnabled(false); dimensionHorizontalSpinner.setEnabled(false); borderColorComboBox.setEnabled(false); borderStyleComboBox.setEnabled(false); panelTitleFont.setEnabled(false); panelTitleFontSize.setEnabled(false); panelTitleFontColorComboBox.setSelectedIndex(0); panelTitleFontColorComboBox.setEnabled(false); panelTitleBackgroundColorComboBox.setSelectedIndex(0); panelTitleBackgroundColorComboBox.setEnabled(false); panelTitleFontStyleBold.setSelected(false); panelTitleFontStyleBold.setEnabled(false); panelTitleFontStyleItalic.setSelected(false); panelTitleFontStyleItalic.setEnabled(false); panelTitleFontUnderline.setSelected(false); panelTitleFontUnderline.setEnabled(false); // Turn off Miscellaneous panel's Panel Title Bar and Panel title // controls miscPanelTitleBarCheckBox.setEnabled(false); miscPanelTitleField.setEnabled(false); miscPanelTitleField.setText(""); enableAlignmentButtons(false); enableBorderButtons(false); listenersEnabled = true; } private void setGUIControlsStatusForMultiSelect(Collection<Panel> selectedPanels) { // Turn off Position and Dimension controls */ positionXSpinner.setEnabled(false); positionYSpinner.setEnabled(false); dimensionVerticalSpinner.setEnabled(true); dimensionHorizontalSpinner.setEnabled(true); // Turn off Miscellaneous panel's Panel Title Bar and Panel title // controls miscPanelTitleBarCheckBox.setEnabled(true); miscPanelTitleField.setEnabled(false); panelTitleFont.setEnabled(true); panelTitleFontSize.setEnabled(true); panelTitleFontColorComboBox.setEnabled(true); panelTitleBackgroundColorComboBox.setEnabled(true); panelTitleFontStyleBold.setEnabled(true); panelTitleFontStyleItalic.setEnabled(true); panelTitleFontUnderline.setEnabled(true); borderColorComboBox.setEnabled(true); borderStyleComboBox.setEnabled(true); setSelectedBorderColor(selectedPanels); setSelectedBorderStyle(selectedPanels); enableAlignmentButtons(true); enableBorderButtons(true); setPanelValuesForMultiSelect(selectedPanels); } private void setSelectedBorderStyle(Collection<Panel> panels) { listenersEnabled = false; Integer style = panels.isEmpty() ? null : panels.iterator().next().getBorderStyle(); for (Panel p:panels) { if (p.getBorderStyle() != style) { style = null; break; } } if (style == null) { borderStyleComboBox.setSelectedIndex(0); } else { borderStyleComboBox.setSelectedItem(style); } listenersEnabled = true; } private void setSelectedBorderColor(Collection<Panel> panels) { listenersEnabled = false; Color c = panels.isEmpty() ? null : panels.iterator().next().getBorderColor(); for (Panel p:panels) { if (!p.getBorderColor().equals(c)) { c = null; break; } } if (c == null) { borderColorComboBox.setSelectedIndex(-1); } else { for (int i = 0; i < ControlAreaFormattingConstants.BorderColors.length; i++) { if (c.equals(ControlAreaFormattingConstants.BorderColors[i])) { borderColorComboBox.setSelectedItem(c); break; } } } listenersEnabled = true; } private void setGUIControlsStatusForSingleSelect(Panel selectedPanel) { // Turn off Position and Dimension controls */ positionXSpinner.setEnabled(true); positionYSpinner.setEnabled(true); dimensionVerticalSpinner.setEnabled(true); dimensionHorizontalSpinner.setEnabled(true); // Turn on Miscellaneous panel's Panel Title Bar and Panel title // controls miscPanelTitleBarCheckBox.setEnabled(true); miscPanelTitleField.setEnabled(true); panelTitleFont.setEnabled(true); panelTitleFontSize.setEnabled(true); panelTitleFontColorComboBox.setEnabled(true); panelTitleBackgroundColorComboBox.setEnabled(true); panelTitleFontStyleBold.setEnabled(true); panelTitleFontStyleItalic.setEnabled(true); panelTitleFontUnderline.setEnabled(true); borderColorComboBox.setEnabled(true); borderStyleComboBox.setEnabled(true); setSelectedBorderColor(Collections.singleton(selectedPanel)); Rectangle bound = selectedPanel.getBounds(); setPositionAndDimensionsValues(bound.getLocation().x, bound.getLocation().y, bound .getSize().height, bound.getSize().width); setBorderValues(selectedPanel.getBorderState(), BorderStyle.getBorderStyle(selectedPanel .getBorderStyle()), selectedPanel.getBorderColor()); setPanelValues(selectedPanel); enableAlignmentButtons(true); enableBorderButtons(true); } /* Utilities */ /** * Return a list of border styles. * * @return the list of border styles */ static Integer[] generateBorderStyles() { Integer[] borderStyles = new Integer[ControlAreaFormattingConstants.NUMBER_BORDER_STYLES]; for (int i = 0; i < ControlAreaFormattingConstants.NUMBER_BORDER_STYLES; i++) { borderStyles[i] = Integer.valueOf(i); } return borderStyles; } /** * Utility method extracts the JFormattedTextField from JSpinner controls * * @param spinner * the spinner for which we desire its text field * @return the text field associated with the spinner. * @throws IllegalARgumentExcpetion * if Spinner's textField is not a JSpinner.DefaultEditor. */ static JFormattedTextField getTextField(JSpinner spinner) { JComponent editor = spinner.getEditor(); if (editor instanceof JSpinner.DefaultEditor) { return ((JSpinner.DefaultEditor) editor).getTextField(); } else { throw new IllegalArgumentException(); } } /** * A JPanel that draws a color, for color dropdowns. * @author vwoeltje */ private static class ColorPanel extends JPanel { /** * */ private static final long serialVersionUID = 5931786628055358422L; private static final Dimension COMBO_BOX_DIMENSION = new Dimension(50, 20); Color color; public ColorPanel(Color c) { color = c; setBackground(c); this.setPreferredSize(COMBO_BOX_DIMENSION); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(color); g.fillRect(0, 0, getWidth(), getHeight()); } protected void setColor(Color aColor) { this.color = aColor; } } }
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
190
positionXSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); if (selectedPanels != null && selectedPanels.size() == 1) { Panel selectedPanel = selectedPanels.get(0); int newXLocation = ((Integer) positionXSpinner.getValue()).intValue() - CORRECTION_OFFSET; if (selectedPanel.getLocation().x != newXLocation) { CanvasFormattingController.notifyXPropertyChange(newXLocation, selectedPanel); managedCanvas.fireFocusPersist(); } } } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
191
noBorderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean enabled = listenersEnabled; // Once this button is pressed, the user cannot press it again. if (noBorderButton.isSelected()) { listenersEnabled = false; leftBorderButton.setSelected(false); rightBorderButton.setSelected(false); topBorderButton.setSelected(false); bottomBorderButton.setSelected(false); fullBorderButton.setSelected(false); listenersEnabled = enabled; if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAllBorderStatus(false, selectedPanels); managedCanvas.fireFocusPersist(); } } else { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); for (Panel p : selectedPanels) { if (p.getBorderState() != PanelBorder.NO_BORDER) { noBorderButton.setSelected(true); return; } } } } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
192
borderStyleComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyBorderFormattingStyle(borderStyleComboBox.getSelectedIndex(), selectedPanels); managedCanvas.fireFocusPersist(); } } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
193
borderColorComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (listenersEnabled) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyBorderColorSelected((Color) borderColorComboBox .getSelectedItem(), selectedPanels); managedCanvas.fireFocusPersist(); } } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
194
field.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { managedCanvas.augmentation.spotlightText = field.getText().trim(); managedCanvas.augmentation.repaint(); } @Override public void insertUpdate(DocumentEvent e) { managedCanvas.augmentation.spotlightText = field.getText().trim(); managedCanvas.augmentation.repaint(); } @Override public void changedUpdate(DocumentEvent e) { } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
195
alignTableLeftButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignLeftSelected(selectedPanels); managedCanvas.fireFocusPersist(); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
196
alignTableCenterHorizontalButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignCenterHSelected(selectedPanels); managedCanvas.fireFocusPersist(); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
197
alignTableRightButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignRightSelected(selectedPanels); managedCanvas.fireFocusPersist(); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
198
alignTableTopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignTopSelected(selectedPanels); managedCanvas.fireFocusPersist(); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java
199
alignTableBottomButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Panel> selectedPanels = managedCanvas.getSelectedPanels(); CanvasFormattingController.notifyAlignBottomSelected(selectedPanels); managedCanvas.fireFocusPersist(); } });
false
canvas_src_main_java_gov_nasa_arc_mct_canvas_view_CanvasFormattingControlsPanel.java