Exemplo 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);

  }
Exemplo n.º 2
0
  /** Creates new form display window */
  public PZWindow(
      final PZManager manager,
      int screenX,
      int screenY,
      int width,
      int height,
      int drawX,
      int drawY) {
    this.manager = manager;
    java.net.URL url = ClassLoader.getSystemClassLoader().getResource("images/dgu.gif");
    if (url != null) setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(url));

    setBounds(screenX, screenY, width, height);
    setMySize(width, height, 1.0f);

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    // setup the canvas for the window to draw
    final Container cp = getContentPane();
    cp.setLayout(null);
    cp.add(lblCanvas);
    lblCanvas.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    lblCanvas.setDoubleBuffered(true);
    lblCanvas.setFocusable(true);

    initEventListeners();
    drawOffset.set(drawX, drawY);
  }
    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);
    }
    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();
      }
    }
Exemplo n.º 5
0
  public static ToolBox fromFile(
      String filename, Board board, int toolHeight, int toolReserveBarWidth, int toolTextWidth) {
    InputStream fis = null;
    try {
      fis = new FileInputStream(filename);
    } catch (FileNotFoundException e) {
      fis = ClassLoader.getSystemClassLoader().getResourceAsStream(filename);
    }

    ToolBox toolBox = fromStream(fis, board);
    toolBox.toolHeight = toolHeight;
    toolBox.toolReserveBarWidth = toolReserveBarWidth;
    toolBox.toolTextWidth = toolTextWidth;
    return toolBox;
  }
Exemplo n.º 6
0
  /**
   * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that
   * will be embedded within the composite. In order for the embedding to succeed, the composite
   * must have been created with the SWT.EMBEDDED style.
   *
   * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a
   * lightweight component is added as a child of the embedded frame, the cursor does not change. In
   * order to work around both these problems, it is strongly recommended that a heavyweight
   * component such as <code>java.awt.Panel</code> be added to the frame as the root of all
   * components.
   *
   * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code>
   * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style
   *     </ul>
   *
   * @since 3.0
   */
  public static Frame new_Frame(final Composite parent) {
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }

    final int /*long*/ handle = parent.view.id;

    Class clazz = null;
    try {
      String className =
          embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame";
      if (embeddedFrameClass == null) {
        clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader());
      } else {
        clazz = Class.forName(className);
      }
    } catch (ClassNotFoundException cne) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cne);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_UNSPECIFIED, e, " [Error while starting AWT]");
    }

    initializeSwing();
    Object value = null;
    Constructor constructor = null;
    try {
      constructor = clazz.getConstructor(new Class[] {long.class});
      value = constructor.newInstance(new Object[] {new Long(handle)});
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e);
    }
    final Frame frame = (Frame) value;
    frame.addNotify();

    parent.setData(EMBEDDED_FRAME_KEY, frame);

    /* Forward the iconify and deiconify events */
    final Listener shellListener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Deiconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED));
                      }
                    });
                break;
              case SWT.Iconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
                      }
                    });
                break;
            }
          }
        };
    Shell shell = parent.getShell();
    shell.addListener(SWT.Deiconify, shellListener);
    shell.addListener(SWT.Iconify, shellListener);

    /*
     * Generate the appropriate events to activate and deactivate
     * the embedded frame. This is needed in order to make keyboard
     * focus work properly for lightweights.
     */
    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Dispose:
                Shell shell = parent.getShell();
                shell.removeListener(SWT.Deiconify, shellListener);
                shell.removeListener(SWT.Iconify, shellListener);
                parent.setVisible(false);
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        try {
                          frame.dispose();
                        } catch (Throwable e) {
                        }
                      }
                    });
                break;
              case SWT.FocusIn:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(true)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
              case SWT.Deactivate:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (!frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(false)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
            }
          }
        };

    parent.addListener(SWT.FocusIn, listener);
    parent.addListener(SWT.Deactivate, listener);
    parent.addListener(SWT.Dispose, listener);

    parent
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (parent.isDisposed()) return;
                final Rectangle clientArea = parent.getClientArea();
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.setSize(clientArea.width, clientArea.height);
                        frame.validate();

                        // Bug in Cocoa AWT? For some reason the frame isn't showing up on first
                        // draw.
                        // Toggling visibility seems to be the only thing that works.
                        frame.setVisible(false);
                        frame.setVisible(true);
                      }
                    });
              }
            });

    return frame;
  }
Exemplo n.º 7
0
  /**
   * Instantiate a JavaBean.
   *
   * @param classLoader the class-loader from which we should create the bean. If this is null, then
   *     the system class-loader is used.
   * @param beanName the name of the bean within the class-loader. For example "sun.beanbox.foobah"
   * @exception java.lang.ClassNotFoundException if the class of a serialized object could not be
   *     found.
   * @exception java.io.IOException if an I/O error occurs.
   */
  public static Object instantiate(ClassLoader cls, String beanName)
      throws java.io.IOException, ClassNotFoundException {
    java.io.InputStream ins;
    java.io.ObjectInputStream oins = null;
    Object result = null;
    boolean serialized = false;
    java.io.IOException serex = null;
    // If the given classloader is null, we check if an
    // system classloader is available and (if so)
    // use that instead.
    // Note that calls on the system class loader will
    // look in the bootstrap class loader first.
    if (cls == null) {
      try {
        cls = ClassLoader.getSystemClassLoader();
      } catch (SecurityException ex) { // We're not allowed to access the system class loader.
        // Drop through.
      }
    }
    // Try to find a serialized object with this name
    final String serName = beanName.replace('.', '/').concat(".ser");
    final ClassLoader loader = cls;
    ins =
        (InputStream)
            java.security.AccessController.doPrivileged(
                new java.security.PrivilegedAction() {
                  public Object run() {
                    if (loader == null) return ClassLoader.getSystemResourceAsStream(serName);
                    else return loader.getResourceAsStream(serName);
                  }
                });
    if (ins != null) {
      try {
        if (cls == null) {
          oins = new ObjectInputStream(ins);
        } else {
          oins = new ObjectInputStreamWithLoader(ins, cls);
        }
        result = oins.readObject();
        serialized = true;
        oins.close();
      } catch (java.io.IOException ex) {
        ins.close();
        // Drop through and try opening the class.  But remember
        // the exception in case we can't find the class either.
        serex = ex;
      } catch (ClassNotFoundException ex) {
        ins.close();
        throw ex;
      }
    }
    if (result == null) {
      // No serialized object, try just instantiating the class
      Class cl;
      try {
        if (cls == null) {
          cl = Class.forName(beanName);
        } else {
          cl = cls.loadClass(beanName);
        }
      } catch (ClassNotFoundException ex) {
        // There is no appropriate class.  If we earlier tried to
        // deserialize an object and got an IO exception, throw that,
        // otherwise rethrow the ClassNotFoundException.
        if (serex != null) {
          throw serex;
        }
        throw ex;
      }
      /*
       * Try to instantiate the class.
       */

      try {
        result = cl.newInstance();
      } catch (Exception ex) {
        // We have to remap the exception to one in our signature.
        // But we pass extra information in the detail message.
        throw new ClassNotFoundException("" + cl + " : " + ex);
      }
    }
    if (result != null) { // Ok, if the result is an applet initialize it.
      AppletStub stub = null;

      if (result instanceof Applet) {
        Applet applet = (Applet) result;

        // Figure our the codebase and docbase URLs.  We do this
        // by locating the URL for a known resource, and then
        // massaging the URL.

        // First find the "resource name" corresponding to the bean
        // itself.  So a serialzied bean "a.b.c" would imply a
        // resource name of "a/b/c.ser" and a classname of "x.y"
        // would imply a resource name of "x/y.class".

        final String resourceName;

        if (serialized) {
          // Serialized bean
          resourceName = beanName.replace('.', '/').concat(".ser");
        } else {
          // Regular class
          resourceName = beanName.replace('.', '/').concat(".class");
        }

        URL objectUrl = null;
        URL codeBase = null;
        URL docBase = null;

        // Now get the URL correponding to the resource name.

        final ClassLoader cloader = cls;
        objectUrl =
            (URL)
                java.security.AccessController.doPrivileged(
                    new java.security.PrivilegedAction() {
                      public Object run() {
                        if (cloader == null) return ClassLoader.getSystemResource(resourceName);
                        else return cloader.getResource(resourceName);
                      }
                    });

        // If we found a URL, we try to locate the docbase by taking
        // of the final path name component, and the code base by taking
        // of the complete resourceName.
        // So if we had a resourceName of "a/b/c.class" and we got an
        // objectURL of "file://bert/classes/a/b/c.class" then we would
        // want to set the codebase to "file://bert/classes/" and the
        // docbase to "file://bert/classes/a/b/"

        if (objectUrl != null) {
          String s = objectUrl.toExternalForm();

          if (s.endsWith(resourceName)) {
            int ix = s.length() - resourceName.length();
            codeBase = new URL(s.substring(0, ix));
            docBase = codeBase;

            ix = s.lastIndexOf('/');

            if (ix >= 0) {
              docBase = new URL(s.substring(0, ix + 1));
            }
          }
        }

        // Setup a default context and stub.
        BeansAppletContext context = new BeansAppletContext(applet);

        stub = (AppletStub) new BeansAppletStub(applet, context, codeBase, docBase);
        applet.setStub(stub);

        // If it was deserialized then it was already init-ed.
        // Otherwise we need to initialize it.

        if (!serialized) {
          // We need to set a reasonable initial size, as many
          // applets are unhappy if they are started without
          // having been explicitly sized.
          applet.setSize(100, 100);
          applet.init();
        }
        ((BeansAppletStub) stub).active = true;
      }
    }
    return result;
  }
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;
    }
  }
}