Esempio n. 1
0
  public About() {
    cl = ClassLoader.getSystemClassLoader();

    // ----------------------------------------CENTER--------------------------------//
    imgAbout = new ImageIcon(cl.getResource("om.png"));

    lblAbout = new JLabel(imgAbout);

    lblAbout.setBounds(0, 0, 450, 263);

    JPanel pnlCenter = new JPanel();
    pnlCenter.setLayout(null);
    pnlCenter.add(lblAbout);

    btnOk = new JButton(new ImageIcon(cl.getResource("ok.png")));
    btnOk.setBounds(390, 215, 40, 30);
    pnlCenter.add(btnOk);
    btnOk.addActionListener(this);

    // -----------------------------------CONTAINER----------------------------------//
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(pnlCenter, BorderLayout.CENTER);
    setSize(450, 280);
    setVisible(true);
    setResizable(false);
    setLocation(580, 280);
    // setDefaultCloseOperation(EXIT_ON_CLOSE);

  }
Esempio n. 2
0
 /**
  * Get the current thread's context class loader which is set to the CommonClassLoader by
  * ApplicationServer
  *
  * @return the thread's context classloader if it exists; else the system class loader.
  */
 public static ClassLoader getClassLoader() {
   if (Thread.currentThread().getContextClassLoader() != null) {
     return Thread.currentThread().getContextClassLoader();
   } else {
     return ClassLoader.getSystemClassLoader();
   }
 }
    public SidebarOption(String labelTxt, String rsc) {
      label = new JLabel(labelTxt);
      label.setForeground(Color.WHITE);
      label.setFont(font);
      add(label);
      setOpaque(false);
      setMaximumSize(new Dimension(1000, label.getPreferredSize().height + 5));

      this.rsc = ClassLoader.getSystemClassLoader().getResource(rsc);
    }
 public OperatorDiscoverer(String[] jars) {
   URL[] urls = new URL[jars.length];
   for (int i = 0; i < jars.length; i++) {
     pathsToScan.add(jars[i]);
     try {
       urls[i] = new URL("file://" + jars[i]);
     } catch (MalformedURLException ex) {
       throw new RuntimeException(ex);
     }
   }
   classLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
 }
    Sidebar() {
      super(BoxLayout.Y_AXIS);

      try {
        back =
            ImageIO.read(
                ClassLoader.getSystemClassLoader()
                    .getResource("org/madeirahs/editor/ui/help_sidebar.png"));
        scaleImage();
        setPreferredSize(new Dimension(back.getWidth(), back.getHeight()));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
Esempio n. 6
0
 private static boolean loadProviderFromProperty() {
   String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
   if (cn == null) return false;
   try {
     @SuppressWarnings("deprecation")
     Object o = Class.forName(cn, true, ClassLoader.getSystemClassLoader()).newInstance();
     provider = (HttpServerProvider) o;
     return true;
   } catch (ClassNotFoundException
       | IllegalAccessException
       | InstantiationException
       | SecurityException x) {
     throw new ServiceConfigurationError(null, x);
   }
 }
Esempio n. 7
0
 private static boolean loadProviderAsService() {
   Iterator<HttpServerProvider> i =
       ServiceLoader.load(HttpServerProvider.class, ClassLoader.getSystemClassLoader()).iterator();
   for (; ; ) {
     try {
       if (!i.hasNext()) return false;
       provider = i.next();
       return true;
     } catch (ServiceConfigurationError sce) {
       if (sce.getCause() instanceof SecurityException) {
         // Ignore the security exception, try the next provider
         continue;
       }
       throw sce;
     }
   }
 }
public class HelpUI extends JDialog {

  /** */
  private static final long serialVersionUID = -8355846190461698480L;

  private static final String UI_ROOT = "org/madeirahs/editor/ui/",
      HELP_ARTIFACTS_LOC = UI_ROOT + "help_artifacts.html",
      HELP_NET_LOC = UI_ROOT + "help_net.rtf",
      HELP_GENERAL_LOC = UI_ROOT + "help_general.rtf",
      HELP_GPL_LOC = UI_ROOT + "gpl.html";

  private static final URL BLANK_PAGE =
      ClassLoader.getSystemClassLoader().getResource(UI_ROOT + "blank.html");

  private static double scalex, scaley;

  static {
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    scalex = d.width / 1920.0;
    scaley = d.height / 1080.0;
    if (scalex > 1) scalex = 1;
    if (scaley > 1) scaley = 1;
  }

  private Sidebar sidebar;
  private SidebarOption general, artifact, net, gpl, sel;
  private JTextPane infoView;

  public HelpUI(Frame parent, String title) {
    sidebar = new Sidebar();
    sidebar.setBorder(new EmptyBorder(10, 10, 10, 10));
    infoView = new JTextPane();
    Dimension d1 = sidebar.getPreferredSize();
    infoView.setPreferredSize(new Dimension(d1.width * 3, d1.height - 5));
    infoView.setEditable(false);

    MouseAdapter ma =
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent me) {
            SidebarOption sopt = (SidebarOption) me.getComponent();
            if (sel != null) {
              sel.setSelected(false);
              sel.repaint();
            }
            sel = sopt;
            sel.setSelected(true);
            sel.repaint();
            renderInfo();
          }
        };

    general = new SidebarOption("General Info", HELP_GENERAL_LOC);
    general.addMouseListener(ma);
    sidebar.add(general);

    sidebar.add(Box.createVerticalStrut(scy(10)));

    artifact = new SidebarOption("Artifacts", HELP_ARTIFACTS_LOC);
    artifact.addMouseListener(ma);
    sidebar.add(artifact);

    sidebar.add(Box.createVerticalStrut(scy(10)));

    net = new SidebarOption("Networking", HELP_NET_LOC);
    net.addMouseListener(ma);
    sidebar.add(net);

    sidebar.add(Box.createVerticalStrut(scy(10)));

    gpl = new SidebarOption("License", HELP_GPL_LOC);
    gpl.addMouseListener(ma);
    sidebar.add(gpl);

    general.setSelected(true);
    sel = general;

    sidebar.add(Box.createVerticalGlue());

    add(BorderLayout.WEST, sidebar);
    add(BorderLayout.CENTER, new JScrollPane(infoView));
    setResizable(false);
    pack();
    setLocationRelativeTo(parent);
    setTitle(title);

    renderInfo();
  }

  private void renderInfo() {
    if (sel.rsc == null) {
      try {
        infoView.setPage(BLANK_PAGE);
      } catch (IOException e) {
        e.printStackTrace();
      }
      return;
    }

    try {
      infoView.setPage(sel.rsc);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  private int scx(int px) {
    return (int) Math.round(px * scalex);
  }

  private int scy(int py) {
    return (int) Math.round(py * scaley);
  }

  private class Sidebar extends Box {

    /** */
    private static final long serialVersionUID = -4636294888266555489L;

    BufferedImage back;

    Sidebar() {
      super(BoxLayout.Y_AXIS);

      try {
        back =
            ImageIO.read(
                ClassLoader.getSystemClassLoader()
                    .getResource("org/madeirahs/editor/ui/help_sidebar.png"));
        scaleImage();
        setPreferredSize(new Dimension(back.getWidth(), back.getHeight()));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    @Override
    public void paintComponent(Graphics g) {
      g.drawImage(back, 0, 0, null);
      super.paintComponent(g);
    }

    private void scaleImage() {
      Image img =
          back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
      back =
          new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
      Graphics g = back.getGraphics();
      g.drawImage(img, 0, 0, null);
      g.dispose();
    }
  }

  private class SidebarOption extends JPanel {

    /** */
    private static final long serialVersionUID = -3208144624932369119L;

    private final Font font = new Font("Arial", Font.BOLD, 16);
    private final Color selColor = new Color(0, 0, 255, 100);
    private boolean selected = false;

    JLabel label;
    URL rsc;

    public SidebarOption(String labelTxt, String rsc) {
      label = new JLabel(labelTxt);
      label.setForeground(Color.WHITE);
      label.setFont(font);
      add(label);
      setOpaque(false);
      setMaximumSize(new Dimension(1000, label.getPreferredSize().height + 5));

      this.rsc = ClassLoader.getSystemClassLoader().getResource(rsc);
    }

    @Override
    public void paintComponent(Graphics g) {
      if (selected) {
        g.setColor(selColor);
        g.fillRoundRect(0, 0, getWidth(), getHeight(), getWidth() / 10, getHeight() / 10);
        label.setForeground(Color.YELLOW);
      } else label.setForeground(Color.WHITE);
      super.paintComponent(g);
    }

    public void setSelected(boolean selected) {
      this.selected = selected;
    }
  }
}
 public OperatorDiscoverer() {
   classLoader = ClassLoader.getSystemClassLoader();
 }
 /**
  * This calls the external Moodle web service.
  *
  * <p>params String containing the parameters of the call.<br>
  * elements NodeList containing name/value pairs of returned XML data.
  *
  * @param params String
  * @return elements NodeList
  * @throws MoodleRestException
  */
 public static NodeList call(String params) throws MoodleRestException {
   NodeList elements = null;
   try {
     URL getUrl = new URL(url);
     HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
     connection.setRequestMethod("POST");
     connection.setRequestProperty("Accept", "application/xml");
     connection.setDoOutput(true);
     OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
     writer.write(params);
     writer.flush();
     writer.close();
     // Used for testing
     StringBuilder buffer = new StringBuilder();
     BufferedReader reader =
         new BufferedReader(new InputStreamReader(connection.getInputStream()));
     String line = reader.readLine();
     buffer.append(line).append('\n');
     // FindPath fp=new FindPath();
     InputStream resource =
         ClassLoader.getSystemClassLoader()
             .getResourceAsStream("net/beaconhillcott/moodlerest/EntityInjection.xml");
     BufferedReader entities = new BufferedReader(new InputStreamReader(/*fp.*/ resource));
     String entitiesLine = null;
     while ((entitiesLine = entities.readLine()) != null) {
       // System.out.println(entitiesLine);
       buffer.append(entitiesLine).append('\n');
     }
     entities.close();
     boolean error = false;
     while ((line = reader.readLine()) != null) {
       // System.out.println(line);
       if (error)
         throw new MoodleRestException(
             line.substring(line.indexOf('>') + 1, line.indexOf('<', line.indexOf('>') + 1)));
       if (line.contains("<EXCEPTION")) error = true;
       buffer.append(line).append('\n');
     }
     reader.close();
     if (debug) {
       System.out.println(buffer.toString());
     }
     XPath xpath = XPathFactory.newInstance().newXPath();
     // InputSource source=new InputSource(connection.getInputStream());
     InputSource source = new InputSource(new ByteArrayInputStream(buffer.toString().getBytes()));
     elements = (NodeList) xpath.evaluate("//VALUE", source, XPathConstants.NODESET);
     // Used for testing
     if (debug) {
       for (int i = 0; i < elements.getLength(); i++) {
         String parent =
             elements
                 .item(i)
                 .getParentNode()
                 .getParentNode()
                 .getParentNode()
                 .getParentNode()
                 .getNodeName();
         if (parent.equals("KEY"))
           parent =
               elements
                   .item(i)
                   .getParentNode()
                   .getParentNode()
                   .getParentNode()
                   .getParentNode()
                   .getAttributes()
                   .getNamedItem("name")
                   .getNodeValue();
         String content = elements.item(i).getTextContent();
         String nodeName =
             elements.item(i).getParentNode().getAttributes().getNamedItem("name").getNodeValue();
         System.out.println("parent=" + parent + " nodeName=" + nodeName + " content=" + content);
       }
     }
     connection.disconnect();
   } catch (XPathExpressionException ex) {
     Logger.getLogger(MoodleCallRestWebService.class.getName()).log(Level.SEVERE, null, ex);
   } catch (IOException ex) {
     Logger.getLogger(MoodleCallRestWebService.class.getName()).log(Level.SEVERE, null, ex);
   }
   return elements;
 }