use of java.awt.GraphicsEnvironment in project screenbird by adamhub.
the class ScreenUtilTest method testIsDualScreen.
/**
* Test of isMultipleScreen method, of class ScreenUtil.
*/
@Test
public void testIsDualScreen() {
log("isDualScreen");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();
boolean expResult = screens.length > 1;
boolean result = ScreenUtil.isMultipleScreen();
assertEquals(expResult, result);
}
use of java.awt.GraphicsEnvironment in project screenbird by adamhub.
the class ScreenUtilTest method testGetScreenDimension.
/**
* Test of getScreenDimension method, of class ScreenUtil.
*/
@Test
public void testGetScreenDimension() {
log("getScreenDimension");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gd = ge.getScreenDevices()[0].getDefaultConfiguration();
GraphicsDevice device = gd.getDevice();
Dimension result = ScreenUtil.getScreenDimension(device);
assertNotNull(result);
assertNotSame(0, result.height);
assertNotSame(0, result.width);
}
use of java.awt.GraphicsEnvironment in project jreversepro by akkumar.
the class FontSet method getFontObjects.
// Get Font Objects
private String[] getFontObjects() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
FontSet fontSet = new FontSet(ge.getAllFonts());
return fontSet.toArray(new String[ge.getAllFonts().length]);
}
use of java.awt.GraphicsEnvironment in project processing by processing.
the class PSurfaceJOGL method initDisplay.
protected void initDisplay() {
Display tmpDisplay = NewtFactory.createDisplay(null);
tmpDisplay.addReference();
Screen tmpScreen = NewtFactory.createScreen(tmpDisplay, 0);
tmpScreen.addReference();
monitors = new ArrayList<MonitorDevice>();
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] awtDevices = environment.getScreenDevices();
List<MonitorDevice> newtDevices = tmpScreen.getMonitorDevices();
// tries to address the differences.
if (PApplet.platform == PConstants.LINUX) {
for (GraphicsDevice device : awtDevices) {
String did = device.getIDstring();
String[] parts = did.split("\\.");
String id1 = "";
if (1 < parts.length) {
id1 = parts[1].trim();
}
MonitorDevice monitor = null;
int id0 = newtDevices.size() > 0 ? newtDevices.get(0).getId() : 0;
for (int i = 0; i < newtDevices.size(); i++) {
MonitorDevice mon = newtDevices.get(i);
String mid = String.valueOf(mon.getId() - id0);
if (id1.equals(mid)) {
monitor = mon;
break;
}
}
if (monitor != null) {
monitors.add(monitor);
}
}
} else if (PApplet.platform == PConstants.WINDOWS) {
// NEWT display id is == (adapterId << 8 | monitorId),
// should be in the same order as AWT
monitors.addAll(newtDevices);
} else {
// MAC OSX and others
for (GraphicsDevice device : awtDevices) {
String did = device.getIDstring();
String[] parts = did.split("Display");
String id1 = "";
if (1 < parts.length) {
id1 = parts[1].trim();
}
MonitorDevice monitor = null;
for (int i = 0; i < newtDevices.size(); i++) {
MonitorDevice mon = newtDevices.get(i);
String mid = String.valueOf(mon.getId());
if (id1.equals(mid)) {
monitor = mon;
break;
}
}
if (monitor == null) {
// Didn't find a matching monitor, try using less stringent id check
for (int i = 0; i < newtDevices.size(); i++) {
MonitorDevice mon = newtDevices.get(i);
String mid = String.valueOf(mon.getId());
if (-1 < did.indexOf(mid)) {
monitor = mon;
break;
}
}
}
if (monitor != null) {
monitors.add(monitor);
}
}
}
displayDevice = null;
int displayNum = sketch.sketchDisplay();
if (displayNum > 0) {
// if -1, use the default device
if (displayNum <= monitors.size()) {
displayDevice = monitors.get(displayNum - 1);
} else {
System.err.format("Display %d does not exist, " + "using the default display instead.%n", displayNum);
for (int i = 0; i < monitors.size(); i++) {
System.err.format("Display %d is %s%n", i + 1, monitors.get(i));
}
}
} else if (0 < monitors.size()) {
displayDevice = monitors.get(0);
}
if (displayDevice != null) {
screen = displayDevice.getScreen();
display = screen.getDisplay();
} else {
screen = tmpScreen;
display = tmpDisplay;
displayDevice = screen.getPrimaryMonitor();
}
}
use of java.awt.GraphicsEnvironment in project processing by processing.
the class CheckBoxList method init.
public void init(Base base) {
this.base = base;
Container paine = getContentPane();
//10, 10));
paine.setLayout(new BorderLayout());
JPanel pain = new JPanel();
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
paine.add(pain, BorderLayout.CENTER);
pain.setLayout(new BoxLayout(pain, BoxLayout.Y_AXIS));
String labelText = Language.text("create_font.label");
JTextArea textarea = new JTextArea(labelText);
textarea.setBorder(new EmptyBorder(10, 10, 20, 10));
textarea.setBackground(null);
textarea.setEditable(false);
textarea.setHighlighter(null);
textarea.setFont(new Font("Dialog", Font.PLAIN, 12));
pain.add(textarea);
// don't care about families starting with . or #
// also ignore dialog, dialoginput, monospaced, serif, sansserif
// getFontList is deprecated in 1.4, so this has to be used
//long t = System.currentTimeMillis();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts();
//System.out.println("font startup took " + (System.currentTimeMillis() - t) + " ms");
/*
if (false) {
ArrayList<Font> fontList = new ArrayList<Font>();
File folderList = new File("/Users/fry/coconut/sys/fonts/web");
for (File folder : folderList.listFiles()) {
if (folder.isDirectory()) {
File[] items = folder.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.charAt(0) == '.') return false;
return (name.toLowerCase().endsWith(".ttf") ||
name.toLowerCase().endsWith(".otf"));
}
});
for (File fontFile : items) {
try {
FileInputStream fis = new FileInputStream(fontFile);
BufferedInputStream input = new BufferedInputStream(fis);
Font font = Font.createFont(Font.TRUETYPE_FONT, input);
input.close();
fontList.add(font);
} catch (Exception e) {
System.out.println("Ignoring " + fontFile.getName());
}
}
}
}
// fonts = new Font[fontList.size()];
// fontList.toArray(fonts);
fonts = fontList.toArray(new Font[fontList.size()]);
}
*/
String[] fontList = new String[fonts.length];
table = new HashMap<String, Font>();
int index = 0;
for (int i = 0; i < fonts.length; i++) {
try {
fontList[index++] = fonts[i].getPSName();
table.put(fonts[i].getPSName(), fonts[i]);
// Checking into http://processing.org/bugs/bugzilla/407.html
// and https://github.com/processing/processing/issues/1727
// if (fonts[i].getPSName().contains("Helv")) {
// System.out.println(fonts[i].getPSName() + " -> " + fonts[i]);
// }
} catch (Exception e) {
// Sometimes fonts cause lots of trouble.
// http://code.google.com/p/processing/issues/detail?id=442
e.printStackTrace();
}
}
list = new String[index];
System.arraycopy(fontList, 0, list, 0, index);
fontSelector = new JList<String>(list);
fontSelector.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false) {
selection = fontSelector.getSelectedIndex();
okButton.setEnabled(true);
update();
}
}
});
fontSelector.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fontSelector.setVisibleRowCount(12);
JScrollPane fontScroller = new JScrollPane(fontSelector);
pain.add(fontScroller);
Dimension d1 = new Dimension(13, 13);
pain.add(new Box.Filler(d1, d1, d1));
sample = new SampleComponent(this);
// Seems that in some instances, no default font is set
// http://dev.processing.org/bugs/show_bug.cgi?id=777
sample.setFont(new Font("Dialog", Font.PLAIN, 12));
pain.add(sample);
Dimension d2 = new Dimension(6, 6);
pain.add(new Box.Filler(d2, d2, d2));
JPanel panel = new JPanel();
panel.add(new JLabel(Language.text("create_font.size") + ":"));
sizeSelector = new JTextField(" 48 ");
sizeSelector.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
update();
}
public void removeUpdate(DocumentEvent e) {
update();
}
public void changedUpdate(DocumentEvent e) {
}
});
panel.add(sizeSelector);
smoothBox = new JCheckBox(Language.text("create_font.smooth"));
smoothBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
smooth = smoothBox.isSelected();
update();
}
});
smoothBox.setSelected(smooth);
panel.add(smoothBox);
// allBox = new JCheckBox("All Characters");
// allBox.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// all = allBox.isSelected();
// }
// });
// allBox.setSelected(all);
// panel.add(allBox);
charsetButton = new JButton(Language.text("create_font.characters"));
charsetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//showCharacterList();
charSelector.setVisible(true);
}
});
panel.add(charsetButton);
pain.add(panel);
JPanel filestuff = new JPanel();
filestuff.add(new JLabel(Language.text("create_font.filename") + ":"));
filestuff.add(filenameField = new JTextField(20));
filestuff.add(new JLabel(".vlw"));
pain.add(filestuff);
JPanel buttons = new JPanel();
JButton cancelButton = new JButton(Language.text("prompt.cancel"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
okButton = new JButton(Language.text("prompt.ok"));
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
build();
}
});
okButton.setEnabled(false);
buttons.add(cancelButton);
buttons.add(okButton);
pain.add(buttons);
JRootPane root = getRootPane();
root.setDefaultButton(okButton);
ActionListener disposer = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
setVisible(false);
}
};
Toolkit.registerWindowCloseKeys(root, disposer);
Toolkit.setIcon(this);
pack();
setResizable(false);
//System.out.println(getPreferredSize());
// do this after pack so it doesn't affect layout
sample.setFont(new Font(list[0], Font.PLAIN, 48));
fontSelector.setSelectedIndex(0);
// Dimension screen = Toolkit.getScreenSize();
// windowSize = getSize();
// setLocation((screen.width - windowSize.width) / 2,
// (screen.height - windowSize.height) / 2);
setLocationRelativeTo(null);
// create this behind the scenes
charSelector = new CharacterSelector();
}
Aggregations