List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:org.mc.okapi.PieChart.java
public PieChart(String[] label, double[] value, String applicationTitle, String chartTitle) { super(applicationTitle); // This will create the dataset DefaultPieDataset result = new DefaultPieDataset(); for (int i = 0; i < label.length; i++) { result.setValue(label[i], value[i]); }//from www .ja v a 2s. com PieDataset dataset = result; // based on the dataset we create the chart JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart title dataset, // data true, // include legend true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); // we put the chart into a panel ChartPanel chartPanel = new ChartPanel(chart); setIconImage(Toolkit.getDefaultToolkit().getImage("images/ico/extra/science_32.png")); // default size chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add it to our application setContentPane(chartPanel); }
From source file:eu.planets_project.tb.impl.data.util.ImageThumbnail.java
/** * Create a reduced jpeg version of an image. The width/height ratio is * preserved./*from ww w.j a v a 2s. c om*/ * * @param data * raw data of the image * @param thumbWidth * maximum width of the reduced image * @param thumbHeight * maximum heigth of the reduced image * @param quality * jpeg quality of the reduced image * @param out * produce a reduced jpeg image if the image represented by data * is bigger than the maximum dimensions of the reduced image, * otherwise data is written to this stream */ public static void createThumb(byte[] data, int thumbWidth, int thumbHeight, OutputStream out) throws Exception { // NOTE that this support JPEG, PNG or GIF only. Image image = Toolkit.getDefaultToolkit().createImage(data); MediaTracker mediaTracker = new MediaTracker(new Frame()); int trackID = 0; mediaTracker.addImage(image, trackID); mediaTracker.waitForID(trackID); if (image.getWidth(null) <= thumbWidth && image.getHeight(null) <= thumbHeight) out.write(data); else createThumb(image, thumbWidth, thumbHeight, out); }
From source file:patientview.HistoryJFrame.java
/** * Creates new form HistoryJFrame/* ww w. j av a2 s .co m*/ */ public HistoryJFrame(int bedNum, int time, Patients patients) { initComponents(); //set window in the center of the screen //Get the size of the screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); //Determine the new location of the window int w = this.getSize().width; int h = this.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; //Move the window this.setLocation(x, y); //Load click sound try { AudioInputStream audioInputStream = AudioSystem .getAudioInputStream(new File("sounds/click.wav").getAbsoluteFile()); click = AudioSystem.getClip(); click.open(audioInputStream); } catch (Exception ex) { System.out.println(ex.toString()); } //Get patient this.patients = patients; this.bedNum = bedNum; thisPatient = patients.getPatient(bedNum); //Set background colour this.getContentPane().setBackground(new Color(240, 240, 240)); //fill titles wardNumField.setText("W001"); bedNumField.setText(String.valueOf(bedNum)); checkBoxes = new ArrayList<JCheckBox>() { { add(jCheckBox1); add(jCheckBox2); add(jCheckBox3); add(jCheckBox4); add(jCheckBox5); add(jCheckBox6); } }; genGraph(getGraphCode()); //set timer timerCSeconds = time; if (timer == null) { timer = new Timer(10, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // do it every 10 msecond Calendar cal = Calendar.getInstance(); cal.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); jLabel_systemTime.setText(sdf.format(cal.getTime())); // do it every 5 seconds if (timerCSeconds % 500 == 0) { //genGraph(getGraphCode()); //only useful for dispalying data up until the current moment } timerCSeconds++; } }); } if (timer.isRunning() == false) { timer.start(); } }
From source file:com.ln.gui.Notifylist.java
@SuppressWarnings("unchecked") public Notifylist() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setResizable(false);/*from w w w .j av a 2 s. c om*/ setIconImage(Toolkit.getDefaultToolkit().getImage(Configuration.mydir + "\\resources\\icons\\ln6464.png")); setTitle("Event list"); DateFormat dd = new SimpleDateFormat("dd"); DateFormat dh = new SimpleDateFormat("HH"); DateFormat dm = new SimpleDateFormat("mm"); Date day = new Date(); Date hour = new Date(); Date minute = new Date(); int dayd = Integer.parseInt(dd.format(day)); int hourh = Integer.parseInt(dh.format(hour)); int minutem = Integer.parseInt(dm.format(minute)); int daydiff = dayd - Main.dayd; int hourdiff = hourh - Main.hourh; int mindiff = minutem - Main.minutem; model.clear(); Events = new String[Main.events]; Events2 = new String[Main.events]; // Events = Main.Eventlist; for (int i = 0; i != Main.events; i++) { Events[i] = Main.Eventlist[i]; } for (int i = 0; i != Main.events; i++) { Events2[i] = Main.Eventlist[i]; } for (int i = 0; i != Events2.length; i++) { if (Events2[i] != null) { Events2[i] = Main.Eventlist[i]; Events2[i] = Events2[i].replace(StringUtils.substringBetween(Events2[i], "in: ", " Days"), Integer .toString(Integer.parseInt(StringUtils.substringBetween(Events2[i], "in: ", " Days")))); Events2[i] = Events2[i].replace(StringUtils.substringBetween(Events2[i], "Days ", " Hours"), Integer .toString(Integer.parseInt(StringUtils.substringBetween(Events2[i], "Days ", " Hours")))); Events2[i] = Events2[i].replace(StringUtils.substringBetween(Events2[i], "Hours ", " Minutes"), Integer.toString( Integer.parseInt(StringUtils.substringBetween(Events2[i], "Hours ", " Minutes")))); } if (Events[i] != null) { Events[i] = Main.Eventlist[i]; Events[i] = Events[i].replace(StringUtils.substringBetween(Events[i], "in: ", " Days"), Integer.toString(Integer.parseInt(StringUtils.substringBetween(Events[i], "in: ", " Days")) - daydiff)); Events[i] = Events[i].replace(StringUtils.substringBetween(Events[i], "Days ", " Hours"), Integer.toString( Integer.parseInt(StringUtils.substringBetween(Events[i], "Days ", " Hours")) - hourdiff)); Events[i] = Events[i].replace(StringUtils.substringBetween(Events[i], "Hours ", " Minutes"), Integer.toString( Integer.parseInt(StringUtils.substringBetween(Events[i], "Hours ", " Minutes")) - mindiff)); //Arrays.sort(Events); model.add(i, Events[i]); } } setBounds(100, 100, 671, 331); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton Remove = new JButton("Remove selected"); Remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (list.getSelectedIndices().length > 0) { int[] tmp = list.getSelectedIndices(); Main.events = Main.events - tmp.length; int[] selectedIndices = list.getSelectedIndices(); for (int i = tmp.length - 1; i >= 0; i--) { selectedIndices = list.getSelectedIndices(); model.removeElementAt(selectedIndices[i]); Events = ArrayUtils.remove(Events, selectedIndices[i]); Events2 = ArrayUtils.remove(Events2, selectedIndices[i]); Main.Eventlist = ArrayUtils.remove(Main.Eventlist, selectedIndices[i]); //http://i.imgur.com/lN2Fe.jpg } } } }); Remove.setBounds(382, 258, 130, 25); contentPane.add(Remove); JButton btnClose = new JButton("Close"); btnClose.setBounds(522, 258, 130, 25); contentPane.add(btnClose); btnClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); try { JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 11, 642, 236); contentPane.add(scrollPane); list.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); list.setBounds(10, 11, 642, 46); scrollPane.setViewportView(list); scrollPane.getVerticalScrollBar().setValue(0); } catch (NullPointerException e) { } }
From source file:vn.topmedia.monitor.form.MDIMain.java
/** * Creates new form MDIMain// w w w .j a v a 2 s .c o m */ public MDIMain() { initComponents(); initConfigure(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize((int) d.getWidth(), (int) d.getHeight()); }
From source file:BMPLoader.java
public Image getBMPImage(InputStream stream) throws Exception { read(stream); return Toolkit.getDefaultToolkit().createImage(getImageSource()); }
From source file:CTmousetrack.java
public static void main(String[] args) { String outLoc = new String("." + File.separator + "CTdata"); // Location of the base output data folder; only used when writing out CT data to a local folder String srcName = "CTmousetrack"; // name of the output CT source long blockPts = 10; // points per block flush long sampInterval = 10; // time between sampling updates, msec double trimTime = 0.0; // amount of data to keep (trim time), sec boolean debug = false; // turn on debug? // Specify the CT output connection CTWriteMode writeMode = CTWriteMode.LOCAL; // The selected mode for writing out CT data String serverHost = ""; // Server (FTP or HTTP/S) host:port String serverUser = ""; // Server (FTP or HTTPS) username String serverPassword = ""; // Server (FTP or HTTPS) password // For UDP output mode DatagramSocket udpServerSocket = null; InetAddress udpServerAddress = null; String udpHost = ""; int udpPort = -1; // Concatenate all of the CTWriteMode types String possibleWriteModes = ""; for (CTWriteMode wm : CTWriteMode.values()) { possibleWriteModes = possibleWriteModes + ", " + wm.name(); }//ww w. j ava2 s . c om // Remove ", " from start of string possibleWriteModes = possibleWriteModes.substring(2); // // Argument processing using Apache Commons CLI // // 1. Setup command line options Options options = new Options(); options.addOption("h", "help", false, "Print this message."); options.addOption(Option.builder("o").argName("base output dir").hasArg().desc( "Base output directory when writing data to local folder (i.e., this is the location of CTdata folder); default = \"" + outLoc + "\".") .build()); options.addOption(Option.builder("s").argName("source name").hasArg() .desc("Name of source to write data to; default = \"" + srcName + "\".").build()); options.addOption(Option.builder("b").argName("points per block").hasArg() .desc("Number of points per block; UDP output mode will use 1 point/block; default = " + Long.toString(blockPts) + ".") .build()); options.addOption(Option.builder("dt").argName("samp interval msec").hasArg() .desc("Sampling period in msec; default = " + Long.toString(sampInterval) + ".").build()); options.addOption(Option.builder("t").argName("trim time sec").hasArg().desc( "Trim (ring-buffer loop) time (sec); this is only used when writing data to local folder; specify 0 for indefinite; default = " + Double.toString(trimTime) + ".") .build()); options.addOption( Option.builder("w").argName("write mode").hasArg() .desc("Type of write connection; one of " + possibleWriteModes + "; all but UDP mode write out to CT; default = " + writeMode.name() + ".") .build()); options.addOption(Option.builder("host").argName("host[:port]").hasArg() .desc("Host:port when writing via FTP, HTTP, HTTPS, UDP.").build()); options.addOption(Option.builder("u").argName("username,password").hasArg() .desc("Comma-delimited username and password when writing to CT via FTP or HTTPS.").build()); options.addOption("x", "debug", false, "Enable CloudTurbine debug output."); // 2. Parse command line options CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // 3. Retrieve the command line values if (line.hasOption("help")) { // Display help message and quit HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp("CTmousetrack", "", options, "NOTE: UDP output is a special non-CT output mode where single x,y points are sent via UDP to the specified host:port."); return; } outLoc = line.getOptionValue("o", outLoc); if (!outLoc.endsWith("\\") && !outLoc.endsWith("/")) { outLoc = outLoc + File.separator; } // Make sure the base output folder location ends in "CTdata" if (!outLoc.endsWith("CTdata\\") && !outLoc.endsWith("CTdata/")) { outLoc = outLoc + "CTdata" + File.separator; } srcName = line.getOptionValue("s", srcName); blockPts = Long.parseLong(line.getOptionValue("b", Long.toString(blockPts))); sampInterval = Long.parseLong(line.getOptionValue("dt", Long.toString(sampInterval))); trimTime = Double.parseDouble(line.getOptionValue("t", Double.toString(trimTime))); // Type of output connection String writeModeStr = line.getOptionValue("w", writeMode.name()); boolean bMatch = false; for (CTWriteMode wm : CTWriteMode.values()) { if (wm.name().toLowerCase().equals(writeModeStr.toLowerCase())) { writeMode = wm; bMatch = true; } } if (!bMatch) { System.err.println("Unrecognized write mode, \"" + writeModeStr + "\"; write mode must be one of " + possibleWriteModes); System.exit(0); } if (writeMode != CTWriteMode.LOCAL) { // User must have specified the host // If FTP or HTTPS, they may also specify username/password serverHost = line.getOptionValue("host", serverHost); if (serverHost.isEmpty()) { System.err.println( "When using write mode \"" + writeModeStr + "\", you must specify the server host."); System.exit(0); } if (writeMode == CTWriteMode.UDP) { // Force blockPts to be 1 blockPts = 1; // User must have specified both host and port int colonIdx = serverHost.indexOf(':'); if ((colonIdx == -1) || (colonIdx >= serverHost.length() - 1)) { System.err.println( "For UDP output mode, both the host and port (<host>:<port>)) must be specified."); System.exit(0); } udpHost = serverHost.substring(0, colonIdx); String udpPortStr = serverHost.substring(colonIdx + 1); try { udpPort = Integer.parseInt(udpPortStr); } catch (NumberFormatException nfe) { System.err.println("The UDP port must be a positive integer."); System.exit(0); } } if ((writeMode == CTWriteMode.FTP) || (writeMode == CTWriteMode.HTTPS)) { String userpassStr = line.getOptionValue("u", ""); if (!userpassStr.isEmpty()) { // This string should be comma-delimited username and password String[] userpassCSV = userpassStr.split(","); if (userpassCSV.length != 2) { System.err.println("When specifying a username and password for write mode \"" + writeModeStr + "\", separate the username and password by a comma."); System.exit(0); } serverUser = userpassCSV[0]; serverPassword = userpassCSV[1]; } } } debug = line.hasOption("debug"); System.err.println("CTmousetrack parameters:"); System.err.println("\toutput mode = " + writeMode.name()); if (writeMode == CTWriteMode.UDP) { System.err.println("\twrite to " + udpHost + ":" + udpPort); } else { System.err.println("\tsource = " + srcName); System.err.println("\ttrim time = " + trimTime + " sec"); } System.err.println("\tpoints per block = " + blockPts); System.err.println("\tsample interval = " + sampInterval + " msec"); try { // // Setup CTwriter or UDP output // CTwriter ctw = null; CTinfo.setDebug(debug); if (writeMode == CTWriteMode.LOCAL) { ctw = new CTwriter(outLoc + srcName, trimTime); System.err.println("\tdata will be written to local folder \"" + outLoc + "\""); } else if (writeMode == CTWriteMode.FTP) { CTftp ctftp = new CTftp(srcName); try { ctftp.login(serverHost, serverUser, serverPassword); } catch (Exception e) { throw new IOException( new String("Error logging into FTP server \"" + serverHost + "\":\n" + e.getMessage())); } ctw = ctftp; // upcast to CTWriter System.err.println("\tdata will be written to FTP server at " + serverHost); } else if (writeMode == CTWriteMode.HTTP) { // Don't send username/pw in HTTP mode since they will be unencrypted CThttp cthttp = new CThttp(srcName, "http://" + serverHost); ctw = cthttp; // upcast to CTWriter System.err.println("\tdata will be written to HTTP server at " + serverHost); } else if (writeMode == CTWriteMode.HTTPS) { CThttp cthttp = new CThttp(srcName, "https://" + serverHost); // Username/pw are optional for HTTPS mode; only use them if username is not empty if (!serverUser.isEmpty()) { try { cthttp.login(serverUser, serverPassword); } catch (Exception e) { throw new IOException(new String( "Error logging into HTTP server \"" + serverHost + "\":\n" + e.getMessage())); } } ctw = cthttp; // upcast to CTWriter System.err.println("\tdata will be written to HTTPS server at " + serverHost); } else if (writeMode == CTWriteMode.UDP) { try { udpServerSocket = new DatagramSocket(); } catch (SocketException se) { System.err.println("Error creating socket for UDP:\n" + se); System.exit(0); } try { udpServerAddress = InetAddress.getByName(udpHost); } catch (UnknownHostException uhe) { System.err.println("Error getting UDP server host address:\n" + uhe); System.exit(0); } } if (writeMode != CTWriteMode.UDP) { ctw.setBlockMode(blockPts > 1, blockPts > 1); ctw.autoFlush(0); // no autoflush ctw.autoSegment(1000); } // screen dims Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize.getWidth(); double height = screenSize.getHeight(); // use Map for consolidated putData Map<String, Object> cmap = new LinkedHashMap<String, Object>(); // loop and write some output for (int i = 0; i < 1000000; i++) { // go until killed long currentTime = System.currentTimeMillis(); Point mousePos = MouseInfo.getPointerInfo().getLocation(); float x_pt = (float) (mousePos.getX() / width); // normalize float y_pt = (float) ((height - mousePos.getY()) / height); // flip Y (so bottom=0) if (writeMode != CTWriteMode.UDP) { // CT output mode ctw.setTime(currentTime); cmap.clear(); cmap.put("x", x_pt); cmap.put("y", y_pt); ctw.putData(cmap); if (((i + 1) % blockPts) == 0) { ctw.flush(); System.err.print("."); } } else { // UDP output mode // We force blockPts to be 1 for UDP output mode, i.e. we "flush" the data every time // Write the following data (21 bytes total): // header = "MOUSE", 5 bytes // current time, long, 8 bytes // 2 floats (x,y) 4 bytes each, 8 bytes int len = 21; ByteBuffer bb = ByteBuffer.allocate(len); String headerStr = "MOUSE"; bb.put(headerStr.getBytes("UTF-8")); bb.putLong(currentTime); bb.putFloat(x_pt); bb.putFloat(y_pt); // Might be able to use the following, but not sure: // byte[] sendData = bb.array(); byte[] sendData = new byte[len]; bb.position(0); bb.get(sendData, 0, len); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, udpServerAddress, udpPort); try { udpServerSocket.send(sendPacket); } catch (IOException e) { System.err.println("Test server caught exception trying to send data to UDP client:\n" + e); } System.err.print("."); } try { Thread.sleep(sampInterval); } catch (Exception e) { } ; } if (writeMode != CTWriteMode.UDP) { ctw.flush(); // wrap up } } catch (Exception e) { System.err.println("CTmousetrack exception: " + e); e.printStackTrace(); } }
From source file:components.InternalFrameDemo.java
public InternalFrameDemo() { super("InternalFrameDemo"); //Make the big window be indented 50 pixels from each edge //of the screen. int inset = 50; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2); //Set up the GUI. desktop = new JDesktopPane(); //a specialized layered pane createFrame(); //create first "window" setContentPane(desktop);//from w ww . ja va 2 s . c o m setJMenuBar(createMenuBar()); //Make dragging a little faster but perhaps uglier. desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); }
From source file:Main.java
/** * @param screen//from w w w.java 2s . co m * @return */ public static Rectangle getUsableScreenBounds(GraphicsDevice screen) { final Rectangle bounds = screen.getDefaultConfiguration().getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(screen.getDefaultConfiguration()); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; return bounds; }