/* * * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of Oracle nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ package java2d;
/** * DemoGroup handles multiple demos inside of a panel. Demos are loaded * from the demos[][] string as listed in J2Ddemo.java. * Demo groups can be loaded individually, for example : * java DemoGroup Fonts * Loads all the demos found in the demos/Fonts directory.
*/
@SuppressWarnings("serial") publicclass DemoGroup extends JPanel implements ChangeListener, ActionListener { privatefinal DemoInstVarsAccessor demoInstVars; publicint columns = 2; privatestaticfinal Font font = new Font(Font.SERIF, Font.PLAIN, 10); privatefinal EmptyBorder emptyB = new EmptyBorder(5, 5, 5, 5); privatefinal BevelBorder bevelB = new BevelBorder(BevelBorder.LOWERED); private String groupName; public JPanel[] clonePanels; public JTabbedPane tabbedPane;
public DemoGroup(String name, DemoInstVarsAccessor demoInstVars) {
JPanel p = new JPanel(new GridLayout(0, 2));
p.setBorder(new CompoundBorder(emptyB, bevelB));
// Find the named demo group in J2Ddemo.demos[]. int ind = -1; while (!name.equals(J2Ddemo.demos[++ind][0])) {
}
String[] demos = J2Ddemo.demos[ind];
// If there are an odd number of demos, use GridBagLayout. // Note that we don't use the first entry. int numDemos = demos.length - 1; if (numDemos % 2 == 1) {
p.setLayout(new GridBagLayout());
}
// For each demo in the group, prepare a DemoPanel. for (int i = 1; i <= numDemos; i++) {
DemoPanel dp = new DemoPanel("java2d.demos." + name + "." + demos[i], demoInstVars);
dp.setDemoBorder(p); if (dp.surface != null) {
dp.surface.addMouseListener(mouseListener);
dp.surface.setMonitor(demoInstVars.getPerformanceMonitor() != null);
} if (p.getLayout() instanceof GridBagLayout) { int x = p.getComponentCount() % 2; int y = p.getComponentCount() / 2; int w = (i == numDemos) ? 2 : 1;
J2Ddemo.addToGridBag(p, dp, x, y, w, 1, 1, 1);
} else {
p.add(dp);
}
}
public JPanel getPanel() { if (tabbedPane != null) { return (JPanel) tabbedPane.getSelectedComponent();
} else { return (JPanel) getComponent(0);
}
}
publicvoid setup(boolean issueRepaint) {
JPanel p = getPanel();
// Let PerformanceMonitor know which demos are running if (demoInstVars.getPerformanceMonitor() != null) {
demoInstVars.getPerformanceMonitor().surf.setPanel(p);
demoInstVars.getPerformanceMonitor().surf.setSurfaceState();
}
GlobalControls c = demoInstVars.getControls(); // .. tools check against global controls settings .. // .. & start demo & custom control thread if need be .. for (int i = 0; i < p.getComponentCount(); i++) {
DemoPanel dp = (DemoPanel) p.getComponent(i); if (dp.surface != null && c != null) {
Tools t = dp.tools;
t.setVisible(isValid());
t.issueRepaint = issueRepaint;
JToggleButton[] b = { t.toggleB, t.aliasB, t.renderB,
t.textureB, t.compositeB };
JCheckBox[] cb = { c.toolBarCB, c.aliasCB, c.renderCB,
c.textureCB, c.compositeCB }; for (int j = 0; j < b.length; j++) { if (c.obj != null && c.obj.equals(cb[j])) { if (b[j].isSelected() != cb[j].isSelected()) {
b[j].doClick();
}
} elseif (c.obj == null) { if (b[j].isSelected() != cb[j].isSelected()) {
b[j].doClick();
}
}
}
t.setVisible(true); if (c.screenCombo.getSelectedIndex()
!= t.screenCombo.getSelectedIndex()) {
t.screenCombo.setSelectedIndex(c.screenCombo.
getSelectedIndex());
} if (demoInstVars.getVerboseCB().isSelected()) {
dp.surface.verbose(c);
}
dp.surface.setSleepAmount(c.slider.getValue()); if (demoInstVars.getBackgroundColor() != null) {
dp.surface.setBackground(demoInstVars.getBackgroundColor());
}
t.issueRepaint = true;
}
dp.start();
}
revalidate();
}
publicvoid shutDown(JPanel p) { for (int i = 0; i < p.getComponentCount(); i++) {
((DemoPanel) p.getComponent(i)).stop();
}
System.gc();
}
publicvoid cloneDemo() {
JPanel panel = clonePanels[tabbedPane.getSelectedIndex() - 1]; if (panel.getComponentCount() == 1) {
panel.invalidate();
panel.setLayout(new GridLayout(0, columns, 5, 5));
panel.revalidate();
}
DemoPanel original = (DemoPanel) getPanel().getComponent(0);
DemoPanel clone = new DemoPanel(original.className, demoInstVars); if (columns == 2) {
clone.setDemoBorder(panel);
}
Image removeImg = DemoImages.getImage("remove.gif", this);
clone.tools.cloneB =
clone.tools.addTool(removeImg, "Remove the Surface", this);
Dimension d = clone.tools.toolbar.getPreferredSize();
clone.tools.toolbar.setPreferredSize( new Dimension(d.width + 27, d.height)); if (demoInstVars.getBackgroundColor() != null) {
clone.surface.setBackground(demoInstVars.getBackgroundColor());
} if (demoInstVars.getControls() != null) { if (clone.tools.isExpanded
!= demoInstVars.getControls().toolBarCB.isSelected()) {
clone.tools.toggleB.doClick();
}
}
clone.start();
clone.surface.setMonitor(demoInstVars.getPerformanceMonitor() != null);
panel.add(clone);
panel.repaint();
panel.revalidate();
}
publicvoid removeClone(Component theClone) {
JPanel panel = clonePanels[tabbedPane.getSelectedIndex() - 1]; if (panel.getComponentCount() == 2) {
Component cmp = panel.getComponent(0);
panel.removeAll();
panel.setLayout(new BorderLayout());
panel.revalidate();
panel.add(cmp);
} else {
panel.remove(theClone); int cmpCount = panel.getComponentCount(); for (int j = 1; j < cmpCount; j++) { int top = (j + 1 >= 3) ? 0 : 5; int left = ((j + 1) % 2) == 0 ? 0 : 5;
EmptyBorder eb = new EmptyBorder(top, left, 5, 5);
SoftBevelBorder sbb = new SoftBevelBorder(BevelBorder.RAISED);
JPanel p = (JPanel) panel.getComponent(j);
p.setBorder(new CompoundBorder(eb, sbb));
}
}
panel.repaint();
panel.revalidate();
}
@Override public JCheckBoxMenuItem getCcthreadCB() { return ccthreadCB;
}
}
DemoInstVarsAccessorImpl demoInstVars = new DemoInstVarsAccessorImpl(); final DemoGroup group = new DemoGroup(args[0], demoInstVars);
JFrame f = new JFrame("Java2D(TM) Demo - DemoGroup");
f.addWindowListener(new WindowAdapter() {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.