Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

251
LINES

< > BotCompany Repo | #1008150 // CapabilitiesTest (Oracle Demo)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (251L/3K/7K).

1  
/*
2  
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
3  
 *
4  
 * Redistribution and use in source and binary forms, with or without
5  
 * modification, are permitted provided that the following conditions
6  
 * are met:
7  
 *
8  
 *   - Redistributions of source code must retain the above copyright
9  
 *     notice, this list of conditions and the following disclaimer.
10  
 *
11  
 *   - Redistributions in binary form must reproduce the above copyright
12  
 *     notice, this list of conditions and the following disclaimer in the
13  
 *     documentation and/or other materials provided with the distribution.
14  
 *
15  
 *   - Neither the name of Oracle or the names of its
16  
 *     contributors may be used to endorse or promote products derived
17  
 *     from this software without specific prior written permission.
18  
 *
19  
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20  
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  
 */
31  
 
32  
/**
33  
 * This test shows the different buffer capabilities for each
34  
 * GraphicsConfiguration on each GraphicsDevice.
35  
 */
36  
import java.applet.Applet;
37  
import java.awt.*;
38  
import java.awt.event.*;
39  
import javax.swing.*;
40  
 
41  
/**
42  
 * This class wraps a graphics configuration so that it can be
43  
 * displayed nicely in components.
44  
 */
45  
class GCWrapper {
46  
    private GraphicsConfiguration gc;
47  
    private int index;
48  
     
49  
    public GCWrapper(GraphicsConfiguration gc, int index) {
50  
        this.gc = gc;
51  
        this.index = index;
52  
    }
53  
     
54  
    public GraphicsConfiguration getGC() {
55  
        return gc;
56  
    }
57  
     
58  
    public String toString() {
59  
        return gc.toString();
60  
    }
61  
}
62  
 
63  
/**
64  
 * Main frame class.
65  
 */
66  
public class main extends JFrame implements ItemListener {
67  
     
68  
    private JComboBox gcSelection = new JComboBox();
69  
    private JCheckBox imageAccelerated = new JCheckBox("Accelerated", false);
70  
    private JCheckBox imageTrueVolatile = new JCheckBox("Volatile", false);
71  
    private JCheckBox flipping = new JCheckBox("Flipping", false);
72  
    private JLabel flippingMethod = new JLabel("");
73  
    private JCheckBox fullScreen = new JCheckBox("Full Screen Only", false);
74  
    private JCheckBox multiBuffer = new JCheckBox("Multi-Buffering", false);
75  
    private JCheckBox fbAccelerated = new JCheckBox("Accelerated", false);
76  
    private JCheckBox fbTrueVolatile = new JCheckBox("Volatile", false);
77  
    private JCheckBox bbAccelerated = new JCheckBox("Accelerated", false);
78  
    private JCheckBox bbTrueVolatile = new JCheckBox("Volatile", false);
79  
     
80  
    public main(GraphicsDevice dev) {
81  
        super(dev.getDefaultConfiguration());
82  
        addWindowListener(new WindowAdapter() {
83  
            public void windowClosing(WindowEvent ev) {
84  
                System.exit(0);
85  
            }
86  
        });
87  
        initComponents(getContentPane());
88  
        GraphicsConfiguration[] gcs = dev.getConfigurations();
89  
        for (int i = 0; i < gcs.length; i++) {
90  
            gcSelection.addItem(new GCWrapper(gcs[i], i));
91  
        }
92  
        gcSelection.addItemListener(this);
93  
        gcChanged();
94  
    }
95  
     
96  
    /**
97  
     * Creates and lays out components in the container.
98  
     * See the comments below for an organizational overview by panel.
99  
     */
100  
    private void initComponents(Container c) {
101  
        // +=c=====================================================+
102  
        // ++=gcPanel==============================================+
103  
        // ++                    [gcSelection]                     +
104  
        // ++=capsPanel============================================+
105  
        // +++=imageCapsPanel======================================+
106  
        // +++ [imageAccelerated]                                  +
107  
        // +++ [imageTrueVolatile]                                 +
108  
        // +++=bufferCapsPanel=====================================+
109  
        // ++++=bufferAccessCapsPanel==============================+
110  
        // +++++=flippingPanel=====================================+
111  
        // +++++ [flipping]                                        +
112  
        // +++++=fsPanel===========================================+
113  
        // +++++ [indentPanel][fullScreen]                         +
114  
        // +++++=mbPanel===========================================+
115  
        // +++++ [indentPanel][multiBuffer]                        +
116  
        // ++++=buffersPanel=======================================+
117  
        // +++++=fbPanel===============+=bbPanel===================+
118  
        // +++++                       +                           +
119  
        // +++++ [fbAccelerated]       + [bbAccelerated]           +
120  
        // +++++                       +                           +
121  
        // +++++ [fbTrueVolatile]      + [bbTrueVolatile]          +
122  
        // +++++                       +                           +
123  
        // +=======================================================+
124  
        c.setLayout(new BorderLayout());
125  
        // Graphics Config
126  
        JPanel gcPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
127  
        c.add(gcPanel, BorderLayout.NORTH);
128  
        gcSelection.setPreferredSize(new Dimension(400, 30));
129  
        gcPanel.add(gcSelection);
130  
        // Capabilities
131  
        JPanel capsPanel = new JPanel(new BorderLayout());
132  
        c.add(capsPanel, BorderLayout.CENTER);
133  
        // Image Capabilities
134  
        JPanel imageCapsPanel = new JPanel(new GridLayout(2, 1));
135  
        capsPanel.add(imageCapsPanel, BorderLayout.NORTH);
136  
        imageCapsPanel.setBorder(BorderFactory.createTitledBorder(
137  
            "Image Capabilities"));
138  
        imageAccelerated.setEnabled(false);
139  
        imageCapsPanel.add(imageAccelerated);
140  
        imageTrueVolatile.setEnabled(false);
141  
        imageCapsPanel.add(imageTrueVolatile);
142  
        // Buffer Capabilities
143  
        JPanel bufferCapsPanel = new JPanel(new BorderLayout());
144  
        capsPanel.add(bufferCapsPanel, BorderLayout.CENTER);
145  
        bufferCapsPanel.setBorder(BorderFactory.createTitledBorder(
146  
            "Buffer Capabilities"));
147  
        // Buffer Access
148  
        JPanel bufferAccessCapsPanel = new JPanel(new GridLayout(3, 1));
149  
        bufferAccessCapsPanel.setPreferredSize(new Dimension(300, 88));
150  
        bufferCapsPanel.add(bufferAccessCapsPanel, BorderLayout.NORTH);
151  
        // Flipping
152  
        JPanel flippingPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
153  
        bufferAccessCapsPanel.add(flippingPanel);
154  
        flippingPanel.add(flipping);
155  
        flipping.setEnabled(false);
156  
        flippingPanel.add(flippingMethod);
157  
        // Full-screen
158  
        JPanel fsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
159  
        bufferAccessCapsPanel.add(fsPanel);
160  
        JPanel indentPanel = new JPanel();
161  
        indentPanel.setPreferredSize(new Dimension(30, 30));
162  
        fsPanel.add(indentPanel);
163  
        fsPanel.add(fullScreen);
164  
        fullScreen.setEnabled(false);
165  
        // Multi-buffering
166  
        JPanel mbPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
167  
        bufferAccessCapsPanel.add(mbPanel);
168  
        indentPanel = new JPanel();
169  
        indentPanel.setPreferredSize(new Dimension(30, 30));
170  
        mbPanel.add(indentPanel);
171  
        mbPanel.add(multiBuffer);
172  
        multiBuffer.setEnabled(false);
173  
        // Front and Back Buffer Capabilities
174  
        JPanel buffersPanel = new JPanel(new GridLayout(1, 2));
175  
        bufferCapsPanel.add(buffersPanel, BorderLayout.CENTER);
176  
        // Front Buffer
177  
        JPanel fbPanel = new JPanel(new GridLayout(2, 1));
178  
        fbPanel.setBorder(BorderFactory.createTitledBorder(
179  
            "Front Buffer"));
180  
        buffersPanel.add(fbPanel);
181  
        fbPanel.add(fbAccelerated);
182  
        fbAccelerated.setEnabled(false);
183  
        fbPanel.add(fbTrueVolatile);
184  
        fbTrueVolatile.setEnabled(false);
185  
        // Back Buffer
186  
        JPanel bbPanel = new JPanel(new GridLayout(2, 1));
187  
        bbPanel.setPreferredSize(new Dimension(250, 80));
188  
        bbPanel.setBorder(BorderFactory.createTitledBorder(
189  
            "Back and Intermediate Buffers"));
190  
        buffersPanel.add(bbPanel);
191  
        bbPanel.add(bbAccelerated);
192  
        bbAccelerated.setEnabled(false);
193  
        bbPanel.add(bbTrueVolatile);
194  
        bbTrueVolatile.setEnabled(false);
195  
    }
196  
     
197  
    public void itemStateChanged(ItemEvent ev) {
198  
        gcChanged();
199  
    }
200  
     
201  
    private void gcChanged() {
202  
        GCWrapper wrap = (GCWrapper)gcSelection.getSelectedItem();
203  
        //assert wrap != null;
204  
        GraphicsConfiguration gc = wrap.getGC();
205  
        //assert gc != null;
206  
        //Image Caps
207  
        ImageCapabilities imageCaps = gc.getImageCapabilities();
208  
        imageAccelerated.setSelected(imageCaps.isAccelerated());
209  
        imageTrueVolatile.setSelected(imageCaps.isTrueVolatile());
210  
        // Buffer Caps
211  
        BufferCapabilities bufferCaps = gc.getBufferCapabilities();
212  
        flipping.setSelected(bufferCaps.isPageFlipping());
213  
        flippingMethod.setText(getFlipText(bufferCaps.getFlipContents()));
214  
        fullScreen.setSelected(bufferCaps.isFullScreenRequired());
215  
        multiBuffer.setSelected(bufferCaps.isMultiBufferAvailable());
216  
        // Front buffer caps
217  
        imageCaps = bufferCaps.getFrontBufferCapabilities();
218  
        fbAccelerated.setSelected(imageCaps.isAccelerated());
219  
        fbTrueVolatile.setSelected(imageCaps.isTrueVolatile());
220  
        imageCaps = bufferCaps.getFrontBufferCapabilities();
221  
        // Back buffer caps
222  
        imageCaps = bufferCaps.getBackBufferCapabilities();
223  
        bbAccelerated.setSelected(imageCaps.isAccelerated());
224  
        bbTrueVolatile.setSelected(imageCaps.isTrueVolatile());
225  
    }
226  
     
227  
    private static String getFlipText(BufferCapabilities.FlipContents flip) {
228  
        if (flip == null) {
229  
            return "";
230  
        } else if (flip == BufferCapabilities.FlipContents.UNDEFINED) {
231  
            return "Method Unspecified";
232  
        } else if (flip == BufferCapabilities.FlipContents.BACKGROUND) {
233  
            return "Cleared to Background";
234  
        } else if (flip == BufferCapabilities.FlipContents.PRIOR) {
235  
            return "Previous Front Buffer";
236  
        } else { // if (flip == BufferCapabilities.FlipContents.COPIED)
237  
            return "Copied";
238  
        }
239  
    }
240  
     
241  
    public static void main(String[] args) {
242  
        GraphicsEnvironment ge =
243  
            GraphicsEnvironment.getLocalGraphicsEnvironment();
244  
        GraphicsDevice[] devices = ge.getScreenDevices();
245  
        for (int i = 0; i < devices.length; i++) {
246  
            main tst = new main(devices[i]);
247  
            tst.pack();
248  
            tst.setVisible(true);
249  
        }
250  
    }
251  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008150
Snippet name: CapabilitiesTest (Oracle Demo)
Eternal ID of this version: #1008150/4
Text MD5: 5489e92313a8440b2006f37be0464241
Transpilation MD5: 5489e92313a8440b2006f37be0464241
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-28 00:47:48
Source code size: 11352 bytes / 251 lines
Pitched / IR pitched: No / No
Views / Downloads: 541 / 628
Version history: 3 change(s)
Referenced in: [show references]