Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:com.entertailion.java.fling.FlingFrame.java

public FlingFrame(String appId) {
    super();//from w  w w  . ja  va2s  .com
    this.appId = appId;
    rampClient = new RampClient(this);

    addWindowListener(this);

    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    Locale locale = Locale.getDefault();
    resourceBundle = ResourceBundle.getBundle("com/entertailion/java/fling/resources/resources", locale);
    setTitle(MessageFormat.format(resourceBundle.getString("fling.title"), Fling.VERSION));

    JPanel listPane = new JPanel();
    // show list of ChromeCast devices detected on the local network
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    JPanel devicePane = new JPanel();
    devicePane.setLayout(new BoxLayout(devicePane, BoxLayout.LINE_AXIS));
    deviceList = new JComboBox();
    deviceList.addActionListener(this);
    devicePane.add(deviceList);
    URL url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/refresh.png");
    ImageIcon icon = new ImageIcon(url, resourceBundle.getString("button.refresh"));
    refreshButton = new JButton(icon);
    refreshButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // refresh the list of devices
            if (deviceList.getItemCount() > 0) {
                deviceList.setSelectedIndex(0);
            }
            discoverDevices();
        }
    });
    refreshButton.setToolTipText(resourceBundle.getString("button.refresh"));
    devicePane.add(refreshButton);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/settings.png");
    icon = new ImageIcon(url, resourceBundle.getString("settings.title"));
    settingsButton = new JButton(icon);
    settingsButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextField transcodingExtensions = new JTextField(50);
            transcodingExtensions.setText(transcodingExtensionValues);
            JTextField transcodingParameters = new JTextField(50);
            transcodingParameters.setText(transcodingParameterValues);

            JPanel myPanel = new JPanel(new BorderLayout());
            JPanel labelPanel = new JPanel(new GridLayout(3, 1));
            JPanel fieldPanel = new JPanel(new GridLayout(3, 1));
            myPanel.add(labelPanel, BorderLayout.WEST);
            myPanel.add(fieldPanel, BorderLayout.CENTER);
            labelPanel.add(new JLabel(resourceBundle.getString("transcoding.extensions"), JLabel.RIGHT));
            fieldPanel.add(transcodingExtensions);
            labelPanel.add(new JLabel(resourceBundle.getString("transcoding.parameters"), JLabel.RIGHT));
            fieldPanel.add(transcodingParameters);
            labelPanel.add(new JLabel(resourceBundle.getString("device.manual"), JLabel.RIGHT));
            JPanel devicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            final JComboBox manualDeviceList = new JComboBox();
            if (manualServers.size() == 0) {
                manualDeviceList.setVisible(false);
            } else {
                for (DialServer dialServer : manualServers) {
                    manualDeviceList.addItem(dialServer);
                }
            }
            devicePanel.add(manualDeviceList);
            JButton addButton = new JButton(resourceBundle.getString("device.manual.add"));
            addButton.setToolTipText(resourceBundle.getString("device.manual.add.tooltip"));
            addButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    JTextField name = new JTextField();
                    JTextField ipAddress = new JTextField();
                    Object[] message = { resourceBundle.getString("device.manual.name") + ":", name,
                            resourceBundle.getString("device.manual.ipaddress") + ":", ipAddress };

                    int option = JOptionPane.showConfirmDialog(null, message,
                            resourceBundle.getString("device.manual"), JOptionPane.OK_CANCEL_OPTION);
                    if (option == JOptionPane.OK_OPTION) {
                        try {
                            manualServers.add(
                                    new DialServer(name.getText(), InetAddress.getByName(ipAddress.getText())));

                            Object selected = deviceList.getSelectedItem();
                            int selectedIndex = deviceList.getSelectedIndex();
                            deviceList.removeAllItems();
                            deviceList.addItem(resourceBundle.getString("devices.select"));
                            for (DialServer dialServer : servers) {
                                deviceList.addItem(dialServer);
                            }
                            for (DialServer dialServer : manualServers) {
                                deviceList.addItem(dialServer);
                            }
                            deviceList.invalidate();
                            if (selectedIndex > 0) {
                                deviceList.setSelectedItem(selected);
                            } else {
                                if (deviceList.getItemCount() == 2) {
                                    // Automatically select single device
                                    deviceList.setSelectedIndex(1);
                                }
                            }

                            manualDeviceList.removeAllItems();
                            for (DialServer dialServer : manualServers) {
                                manualDeviceList.addItem(dialServer);
                            }
                            manualDeviceList.setVisible(true);
                            storeProperties();
                        } catch (UnknownHostException e1) {
                            Log.e(LOG_TAG, "manual IP address", e1);

                            JOptionPane.showMessageDialog(FlingFrame.this,
                                    resourceBundle.getString("device.manual.invalidip"));
                        }
                    }
                }
            });
            devicePanel.add(addButton);
            JButton removeButton = new JButton(resourceBundle.getString("device.manual.remove"));
            removeButton.setToolTipText(resourceBundle.getString("device.manual.remove.tooltip"));
            removeButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Object selected = manualDeviceList.getSelectedItem();
                    manualDeviceList.removeItem(selected);
                    if (manualDeviceList.getItemCount() == 0) {
                        manualDeviceList.setVisible(false);
                    }
                    deviceList.removeItem(selected);
                    deviceList.invalidate();
                    manualServers.remove(selected);
                    storeProperties();
                }
            });
            devicePanel.add(removeButton);
            fieldPanel.add(devicePanel);
            int result = JOptionPane.showConfirmDialog(FlingFrame.this, myPanel,
                    resourceBundle.getString("settings.title"), JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                transcodingParameterValues = transcodingParameters.getText();
                transcodingExtensionValues = transcodingExtensions.getText();
                storeProperties();
            }
        }
    });
    settingsButton.setToolTipText(resourceBundle.getString("settings.title"));
    devicePane.add(settingsButton);
    listPane.add(devicePane);

    // TODO
    volume = new JSlider(JSlider.VERTICAL, 0, 100, 0);
    volume.setUI(new MySliderUI(volume));
    volume.setMajorTickSpacing(25);
    // volume.setMinorTickSpacing(5);
    volume.setPaintTicks(true);
    volume.setEnabled(true);
    volume.setValue(100);
    volume.setToolTipText(resourceBundle.getString("volume.title"));
    volume.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int position = (int) source.getValue();
                rampClient.volume(position / 100.0f);
            }
        }

    });
    JPanel centerPanel = new JPanel(new BorderLayout());
    // centerPanel.add(volume, BorderLayout.WEST);

    centerPanel.add(DragHereIcon.makeUI(this), BorderLayout.CENTER);
    listPane.add(centerPanel);

    scrubber = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
    scrubber.addChangeListener(this);
    scrubber.setMajorTickSpacing(25);
    scrubber.setMinorTickSpacing(5);
    scrubber.setPaintTicks(true);
    scrubber.setEnabled(false);
    listPane.add(scrubber);

    // panel of playback buttons
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    label = new JLabel("00:00:00");
    buttonPane.add(label);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/play.png");
    icon = new ImageIcon(url, resourceBundle.getString("button.play"));
    playButton = new JButton(icon);
    playButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            rampClient.play();
        }
    });
    buttonPane.add(playButton);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/pause.png");
    icon = new ImageIcon(url, resourceBundle.getString("button.pause"));
    pauseButton = new JButton(icon);
    pauseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            rampClient.pause();
        }
    });
    buttonPane.add(pauseButton);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/stop.png");
    icon = new ImageIcon(url, resourceBundle.getString("button.stop"));
    stopButton = new JButton(icon);
    stopButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            rampClient.stop();
            setDuration(0);
            scrubber.setValue(0);
            scrubber.setEnabled(false);
        }
    });
    buttonPane.add(stopButton);
    listPane.add(buttonPane);
    getContentPane().add(listPane);

    createProgressDialog();
    startWebserver();
    discoverDevices();
}

From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java

@Test
public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"));
    MailboxMessage pgpSignedMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
            propertyBuilder, MAILBOX_ID);
    pgpSignedMail.setModSeq(MOD_SEQ);//from   w ww.  ja  v a 2s.  c o m
    pgpSignedMail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(pgpSignedMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/pgpSignedMail.json")));
}

From source file:de.decoit.simu.cbor.xml.dictionary.DictionaryTest.java

@Test
public void testFindElementByPath_NotExistentNamespace() throws Exception {
    Path input = Paths.get(ClassLoader.getSystemResource("namespace-with-complex-elements.dict").toURI());

    Dictionary instance = new Dictionary();
    instance.extendDictionary(input);/*from   w ww.j  a  v  a2 s  .  com*/

    String dictPath = "<this-is-my-namespace>access-request+nested-element";

    DictionarySimpleElement result = instance.findElementByPath(dictPath);

    assertNull(result);
}

From source file:org.ldp4j.server.testing.ServerFrontendTestHelper.java

public static JavaArchive getServerArchive() {
    JavaArchive coreArchive = ShrinkWrap.create(JavaArchive.class, "ldp4j-server-core.jar")
            .addPackages(true, "org.ldp4j.server")
            .addAsResource(ClassLoader.getSystemResource("META-INF/web-fragment.xml"),
                    "META-INF/web-fragment.xml")
            .addAsResource(ClassLoader.getSystemResource("META-INF/ldp4j/beans.xml"),
                    "META-INF/ldp4j/beans.xml")
            .addAsResource(ClassLoader.getSystemResource("META-INF/ldp4j/frontend.cfg"),
                    "META-INF/ldp4j/frontend.cfg")
            .addAsServiceProvider(RuntimeDelegate.class, CoreRuntimeDelegate.class)
            .addAsServiceProvider(MediaTypeProvider.class, TurtleMediaTypeProvider.class,
                    RDFXMLMediaTypeProvider.class, JSONLDMediaTypeProvider.class);
    return coreArchive;
}

From source file:org.jboss.pressgang.ccms.contentspec.client.commands.BuildCommandTest.java

@Before
public void setUp() {
    bindStdOut();//from w  w  w .  ja v  a2  s.c  om
    when(clientConfig.getDefaults()).thenReturn(defaults);
    command = spy(new BuildCommand(parser, cspConfig, clientConfig));

    // Authentication is tested in the base implementation so assume all users are valid
    TestUtil.setUpAuthorisedUser(command, userProvider, users, user, username);

    rootTestDirectory = FileUtils.toFile(ClassLoader.getSystemResource(""));
    when(cspConfig.getRootOutputDirectory()).thenReturn(rootTestDirectory.getAbsolutePath() + File.separator);

    when(contentSpecWrapper.getTranslationDetails()).thenReturn(translationDetailWrapper);

    // Make the book title directory
    bookDir = new File(rootTestDirectory, BOOK_TITLE);
    bookDir.mkdir();
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * System Tray Icon setup//from w w  w .j  a  v a 2s  .  co  m
 * @param frame owner JFrame
 */
private void setupTrayIcon(final JFrame frame) {

    // Idle Icon
    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_inactive.png"));

    // Active Icon
    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {

        // Set Icon
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Cluster", createTrayPopup());
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (!frame.isVisible()) {
                        frame.setVisible(true);
                    }

                    frame.setExtendedState(JFrame.NORMAL);
                    frame.requestFocus();
                    frame.toFront();
                }
            }

        });

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ae) {
            log.debug("[UI] Unable to Initialize Tray Icon");
            return;
        }

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowIconified(WindowEvent e) {
                // Hide (can be shown using tray icon)
                frame.setVisible(false);
            }

        });
    }

}

From source file:org.jboss.pressgang.ccms.contentspec.client.commands.StatusCommandTest.java

@Test
public void shouldShutdownWhenServerAndLocalHasBeenModified() throws URISyntaxException {
    URL specFileUrl = ClassLoader.getSystemResource("StatusCommand-post.contentspec");
    File specFile = new File(specFileUrl.toURI());
    String specFilePath = specFile.getParentFile().getAbsolutePath() + File.separator;
    // Given a valid csprocessor.cfg
    given(cspConfig.getContentSpecId()).willReturn(id);
    // and a valid id
    given(contentSpecProvider.getContentSpec(anyInt(), anyInt())).willReturn(contentSpecWrapper);
    given(contentSpecProvider.getContentSpecAsString(anyInt(), anyInt()))
            .willReturn("CHECKSUM=" + randomNumber + "\n");
    // and the file it should find is inn the resources folder
    given(contentSpecWrapper.getTitle()).willReturn("");
    // Note: this is a bypass since the command works on the current directory, however the actual file might be in a different
    // location for tests.
    PowerMockito.mockStatic(DocBookUtilities.class);
    when(DocBookUtilities.escapeTitle(anyString())).thenReturn(specFilePath + "StatusCommand");

    // When processing the command
    try {//from w  w w. jav a  2s. co m
        command.process();
        // Then an error is printed and the program is shut down
        fail(SYSTEM_EXIT_ERROR);
    } catch (CheckExitCalled e) {
        assertThat(e.getStatus(), is(9));
    }

    // Then make sure an error message is printed and the command shutdown
    assertThat(getStdOutLogs(), containsString(
            "The local copy and server copy of the Content Specification has been updated. Please use \"csprocessor pull\" to update "
                    + "your local copy. Your unsaved local changes will be saved as "
                    + specFile.getAbsolutePath() + ".backup."));
}

From source file:org.ldp4j.rdf.impl.query.SesameQueryProcessorTest.java

private String loadResource(String resource) throws IOException {
    return IOUtils.toString(ClassLoader.getSystemResource("org/ldp4j/rdf/query/" + resource));
}

From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    // ???//from   w  w  w. j a va 2  s  . c  o  m
    prop = new Properties();
    if (CONFIG_FILE.exists()) {
        try (InputStream in = new FileInputStream(CONFIG_FILE)) {
            prop.loadFromXML(in);
        } catch (IOException e) {
            throw new RuntimeException("????????", e);
        }
    }

    // ????????
    String saveDirectoryPath = prop.getProperty("saveDirectoryPath");
    if (saveDirectoryPath != null) {
        File tempSaveDirectory = new File(saveDirectoryPath);
        if (tempSaveDirectory.exists()) {
            saveDirectory.set(tempSaveDirectory);
        }
    }

    // ???
    saveDirectoryLabel.textProperty().bind(Bindings.createStringBinding(() -> {
        File sd = saveDirectory.get();
        return (sd == null) ? "" : sd.getName();
    }, saveDirectory));
    areaStartXLabel.textProperty().bind(Bindings.convert(areaStartX));
    areaStartYLabel.textProperty().bind(Bindings.convert(areaStartY));
    areaEndXLabel.textProperty().bind(Bindings.convert(areaEndX));
    areaEndYLabel.textProperty().bind(Bindings.convert(areaEndY));
    nextPointXLabel.textProperty().bind(Bindings.convert(nextPointX));
    nextPointYLabel.textProperty().bind(Bindings.convert(nextPointY));
    prevPointXLabel.textProperty().bind(Bindings.convert(prevPointX));
    prevPointYLabel.textProperty().bind(Bindings.convert(prevPointY));

    // ???
    stopButton.setDisable(true);

    // ????
    captureService = new CaptureService();
    captureTimeline = new Timeline(new KeyFrame(new Duration(CAPTURE_INTERVAL), e -> {
        captureService.restart();
    }));
    captureTimeline.setCycleCount(Timeline.INDEFINITE);
    try {
        robot = new Robot();
    } catch (AWTException e) {
        throw new RuntimeException("???????", e);
    }

    // ??
    clip = new AudioClip(ClassLoader.getSystemResource("ayashi.wav").toString());
}

From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java

@Test
public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
    MailboxMessage pgpSignedMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
            propertyBuilder, MAILBOX_ID);
    pgpSignedMail.setModSeq(MOD_SEQ);/*from w  w  w  .j  ava2s .  co  m*/
    pgpSignedMail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(pgpSignedMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/pgpSignedMail.json")));
}